void devEthernet::listAllInterfaces(std::list<std::string>& ifaceNames) { ifaceNames.clear(); ACE_Dirent dir; if ( dir.open(topNetDir.c_str()) ) { throw nd_error("Could not open directory " + topNetDir + " for reading."); } struct stat docStat; ACE_DIRENT* entry; while ( (entry = dir.read()) != NULL ) { std::string entryName(entry->d_name); if ( entryName[0] != '.' && ! isProtected(entryName) ) { ifaceNames.push_back(entryName); } } dir.close(); ifaceNames.sort(); }
ChatChannelsEntry const* GetChannelEntryFor(const std::string& name) { // not sorted, numbering index from 0 for (uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i) { ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i); if (ch) { // need to remove %s from entryName if it exists before we match std::string entryName(ch->pattern[0]); std::size_t removeString = entryName.find("%s"); if (removeString != std::string::npos) entryName.replace(removeString, 2, ""); if (name.find(entryName) != std::string::npos) return ch; } } return nullptr; }
static void removeFileOrDirectory(const char* filename) { struct stat filetype; if (stat(filename, &filetype) != 0) return; if (S_ISDIR(filetype.st_mode)) { DIR* directory = opendir(filename); if (directory) { while (struct dirent* entry = readdir(directory)) { if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) continue; std::string entryName(filename); entryName.append("/"); entryName.append(entry->d_name); removeFileOrDirectory(entryName.c_str()); } closedir(directory); rmdir(filename); } return; } unlink(filename); }
int Gui::PrefColorButton::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = ColorButton::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QByteArray*>(_v) = entryName(); break; case 1: *reinterpret_cast< QByteArray*>(_v) = paramGrpPath(); break; } _id -= 2; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setEntryName(*reinterpret_cast< QByteArray*>(_v)); break; case 1: setParamGrpPath(*reinterpret_cast< QByteArray*>(_v)); break; } _id -= 2; } else if (_c == QMetaObject::ResetProperty) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 2; } #endif // QT_NO_PROPERTIES return _id; }
ChatChannelsEntry const* GetChannelEntryFor(const std::string& name) { // not sorted, numbering index from 0 for (uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i) { ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i); if (ch) { // need to remove %s from entryName if it exists before we match std::string entryName(ch->pattern[0]); std::size_t removeString = entryName.find("%s"); if (removeString != std::string::npos) entryName.replace(removeString, 2, ""); if (name.find(entryName) != std::string::npos) return ch; } } bool compare = true; // hack for world channel, TODO smth! std::string world = "world"; for (uint8 i = 0; i < name.length(); ++i) { if (tolower(name[i]) != world[i]) { compare = false; break; } } if (compare) return &worldCh; return NULL; }
ssize_t AaptAssets::slurpResourceZip(Bundle* bundle, const char* filename) { int count = 0; SortedVector<AaptGroupEntry> entries; ZipFile* zip = new ZipFile; status_t err = zip->open(filename, ZipFile::kOpenReadOnly); if (err != NO_ERROR) { fprintf(stderr, "error opening zip file %s\n", filename); count = err; delete zip; return -1; } const int N = zip->getNumEntries(); for (int i=0; i<N; i++) { ZipEntry* entry = zip->getEntryByIndex(i); if (entry->getDeleted()) { continue; } String8 entryName(entry->getFileName()); String8 dirName = entryName.getPathDir(); sp<AaptDir> dir = dirName == "" ? this : makeDir(dirName); String8 resType; AaptGroupEntry kind; String8 remain; if (entryName.walkPath(&remain) == kResourceDir) { // these are the resources, pull their type out of the directory name kind.initFromDirName(remain.walkPath().string(), &resType); } else { // these are untyped and don't have an AaptGroupEntry } if (entries.indexOf(kind) < 0) { entries.add(kind); mGroupEntries.add(kind); } // use the one from the zip file if they both exist. dir->removeFile(entryName.getPathLeaf()); sp<AaptFile> file = new AaptFile(entryName, kind, resType); status_t err = dir->addLeafFile(entryName.getPathLeaf(), file); if (err != NO_ERROR) { fprintf(stderr, "err=%s entryName=%s\n", strerror(err), entryName.string()); count = err; goto bail; } file->setCompressionMethod(entry->getCompressionMethod()); #if 0 if (entryName == "AndroidManifest.xml") { printf("AndroidManifest.xml\n"); } printf("\n\nfile: %s\n", entryName.string()); #endif size_t len = entry->getUncompressedLen(); void* data = zip->uncompress(entry); void* buf = file->editData(len); memcpy(buf, data, len); #if 0 const int OFF = 0; const unsigned char* p = (unsigned char*)data; const unsigned char* end = p+len; p += OFF; for (int i=0; i<32 && p < end; i++) { printf("0x%03x ", i*0x10 + OFF); for (int j=0; j<0x10 && p < end; j++) { printf(" %02x", *p); p++; } printf("\n"); } #endif free(data); count++; } bail: delete zip; return count; }
void testNullData() { CompoundDataPtr d = new CompoundData(); d->writable()["floatElement"] = new FloatData( 42.0f ); d->writable()["stringElement"] = new StringData( "cake" ); // sanity check first. try { CompoundDataPtr dd = d->copy(); } catch ( std::exception &e ) { BOOST_CHECK( !"Exception thrown during CompoundData copy." ); } CompoundDataPtr c = new CompoundData(); c->writable()["nullElement"] = 0; // copy try { CompoundDataPtr d = c->copy(); BOOST_CHECK( !"Exception not thrown during copy with invalid NULL data." ); } catch ( std::exception &e ) { } // save try { IndexedIOPtr io = new MemoryIndexedIO( NULL, IndexedIO::rootPath, IndexedIO::Write); IndexedIO::EntryID entryName( "test" ); c->Object::save( io, entryName ); BOOST_CHECK( !"Exception not thrown during save with invalid NULL data." ); } catch ( std::exception &e ) { } // memoryUsage try { c->Object::memoryUsage(); } catch ( std::exception &e ) { BOOST_CHECK( !"Exception thrown during memoryCopy with invalid NULL data." ); } // isEqual try { CompoundDataPtr c2 = new CompoundData(); c2->writable()["nullElement"] = 0; bool i = c->isEqualTo( c ); BOOST_CHECK( i ); i = c->isEqualTo( c2 ); BOOST_CHECK( i ); i = c2->isEqualTo( c ); BOOST_CHECK( i ); i = c->isEqualTo( d ); BOOST_CHECK( !i ); i = d->isEqualTo( c ); BOOST_CHECK( !i ); } catch ( std::exception &e ) { BOOST_CHECK( !"Exception thrown during isEqual with invalid NULL data." ); } // hash try { c->Object::hash(); BOOST_CHECK( !"Exception not thrown during hash with invalid NULL data." ); } catch ( std::exception &e ) { } }
/** Obtain the thread list. If aProcessId is negative, we obtain the entire system thread list. If aProcessId is positive we get the thread list for that process */ void CServerCrashDataSource::GetThreadListL( const TUint64 aProcessId, RThreadPointerList & aThreadList, TUint & aTotalThreadListDescSize ) { LOG_MSG2( "->CServerCrashDataSource::GetThreadListL(aProcessId=%Lu)\n", aProcessId); // Delete any objects in the array, since we will replace them. aThreadList.ResetAndDestroy(); aTotalThreadListDescSize = 0; if( iThreadListBuffer.Size() != iLastThreadListSize ) { LOG_MSG2("CServerCrashDataSource::GetThreadListL -> iThreadListBuffer.ReAlloc(%d)\n", iLastThreadListSize ); iThreadListBuffer.ReAllocL( iLastThreadListSize ); } LOG_MSG( "CServerCrashDataSource::GetThreadListL -> DoGetListL()\n" ); DoGetListL( EThreads, (TUint)-1, aProcessId, iThreadListBuffer, iLastThreadListSize ); iLastThreadListSize = iThreadListBuffer.Size(); CThreadInfo * threadInfoPtr; RThread thread; TThreadStackInfo stackInfo; TThreadListEntry * entry; TUint usrStackSize; TLinAddr usrStackAddr; TLinAddr svcStackPtr; TLinAddr svcStackBase; TUint svcStackSize; TUint priority; TUint8* ptr = (TUint8*)( iThreadListBuffer.Ptr() ); const TUint8* ptrEnd = ptr + iLastThreadListSize; //LOG_MSG3( " Data start,end=(0x%x, 0x%x)\n", ptr, ptrEnd ); while( ptr < ptrEnd ) { entry = (TThreadListEntry*)ptr; if( !entry ) { LOG_MSG( " ERROR !* : TThreadListEntry is NULL\n" ); User::Leave(KErrBadHandle); } if( entry->iNameLength == 0 ) { LOG_MSG4( " Skipping Thread 0x%X%X : entry->iNameLength=%d", I64HIGH(entry->iThreadId), I64LOW(entry->iThreadId), entry->iNameLength ); ptr += Align4( entry->GetSize() ); continue; } //LOG_MSG3( " entry &=0x%X, size=%d\n", &(entry->iThreadId), entry->GetSize() ); //LOG_MSG3( " entry->iThreadId= 0x%X%X\n", I64HIGH(entry->iThreadId), I64LOW(entry->iThreadId) ); //LOG_MSG3( " found tid=%d, pid=%d\n", I64LOW(entry->iThreadId), I64LOW(entry->iProcessId) ); if( entry->iSupervisorStackPtrValid ) { svcStackPtr = entry->iSupervisorStackPtr; } else { svcStackPtr = 0; } if( entry->iSupervisorStackBaseValid ) { svcStackBase = entry->iSupervisorStackBase; } else { svcStackBase = 0; } if( entry->iSupervisorStackSizeValid ) { svcStackSize = entry->iSupervisorStackSize; } else { svcStackSize = 0; } if( KErrNone == thread.Open( entry->iThreadId ) ) { priority = (TUint)(thread.Priority()); if( KErrNone == thread.StackInfo( stackInfo ) ) { usrStackAddr = stackInfo.iLimit; usrStackSize = stackInfo.iBase - stackInfo.iLimit; } else { usrStackSize = 0; usrStackAddr = 0; } thread.Close(); } else { usrStackSize = 0; usrStackAddr = 0; priority = 0; } /* LOG_MSG3( " entry->iNameLength=%d, &(entry->iName[0])=0x%X\n", entry->iNameLength, &(entry->iName[0]) ); */ TPtrC entryName( &(entry->iName[0]), entry->iNameLength ); //LOG_MSG2( " -> threadInfoPtr = CThreadInfo::NewL( name.Size()=%d)\n", entryName.Size() ); threadInfoPtr = CThreadInfo::NewL( entry->iThreadId, entryName, entry->iProcessId, (TUint)priority, svcStackPtr, svcStackBase, svcStackSize, usrStackAddr, usrStackSize ); /* LOG_MSG3( " threadInfoPtr->iSvcStackAddr=0x%X, threadInfoPtr->iSvcStackSize=0x%X\n", threadInfoPtr->SvcStackAddr(), threadInfoPtr->SvcStackSize() ); */ TInt err = aThreadList.Append( threadInfoPtr ); if( err != KErrNone ) { // We use this id so as not to use Push(), AppendL(), Pop() delete threadInfoPtr; User::Leave( err ); } aTotalThreadListDescSize += threadInfoPtr->Size(); /* LOG_MSG3( " aTotalThreadListDescSize = %d after adding %d\n", aTotalThreadListDescSize, threadInfoPtr->Size() ); RBuf rPrintBuf; rPrintBuf.Create( threadInfoPtr->Name()); RDebug::Printf( " <- rPrintBuf.Create(), rPrintBuf.Length()=%d\n", rPrintBuf.Length() ); char* cl = (char*) rPrintBuf.Collapse().PtrZ(); RDebug::Printf(" name=%s\n", cl ); rPrintBuf.Close(); */ ptr += Align4( entry->GetSize() ); //LOG_MSG2( " ptr += Align4(entry->GetSize()) = 0x%X\n", ptr ); } // while }
void CServerCrashDataSource::GetProcessListL( RProcessPointerList & aProcessList, TUint & aTotalProcessListDescSize ) { //LOG_MSG( "CServerCrashDataSource::GetProcessListL()\n" ); // Delete any objects in the array, since we will replace them. aProcessList.ResetAndDestroy(); aTotalProcessListDescSize = 0; if( iProcListBuffer.Size() != iLastProcListSize ) { LOG_MSG2( " iProcListBuffer.ReAlloc( %d)\n", iLastProcListSize ); iProcListBuffer.ReAllocL( iLastProcListSize ); } DoGetListL( EProcesses, (TUint)(-1), (TUint)(-1), iProcListBuffer, iLastProcListSize ); iLastProcListSize = iProcListBuffer.Size(); TUint8* ptr = (TUint8*)( iProcListBuffer.Ptr() ); const TUint8* ptrEnd = ptr + iLastProcListSize; //LOG_MSG3( " Data start,end=(0x%x, 0x%x)\n", ptr, ptrEnd ); while( ptr < ptrEnd ) { TProcessListEntry *entry = (TProcessListEntry*)ptr; if( !entry ) { LOG_MSG( " ERROR !* : TProcessListEntry is NULL\n" ); User::Leave(KErrBadHandle); } TUint64 id = entry->iProcessId; if( entry->iFileNameLength == 0 ) { LOG_MSG4( " Skipping process 0x%X%X : entry->iFileNameLength=%d", I64HIGH(entry->iProcessId), I64LOW(entry->iProcessId), entry->iFileNameLength ); ptr += Align4( entry->GetSize() ); continue; } /* LOG_MSG4( " process 0x%X%X has iFileNameLength=%d", I64HIGH(entry->iProcessId), I64LOW(entry->iProcessId), entry->iFileNameLength ); */ TPtrC entryName(&(entry->iNames[0]), entry->iFileNameLength); CProcessInfo *procInfoPtr = CProcessInfo::NewL(id, entryName ); TInt err = aProcessList.Append( procInfoPtr ); if(err != KErrNone) { delete procInfoPtr; User::Leave(err); } aTotalProcessListDescSize += procInfoPtr->Size(); ptr += Align4( entry->GetSize() ); } }