int Test_Begin_Net_HTTP() { int ok = 1; { Msg_Net_HTTP_Connected msg; msg.Hook(MODULE_NAME, (ApCallback) Test_Net_HTTP_OnConnected, 0, 0); } { Msg_Net_HTTP_Header msg; msg.Hook(MODULE_NAME, (ApCallback) Test_Net_HTTP_OnHeader, 0, 0); } { Msg_Net_HTTP_DataIn msg; msg.Hook(MODULE_NAME, (ApCallback) Test_Net_HTTP_OnDataIn, 0, 0); } { Msg_Net_HTTP_Failed msg; msg.Hook(MODULE_NAME, (ApCallback) Test_Net_HTTP_OnFailed, 0, 0); } { Msg_Net_HTTP_Closed msg; msg.Hook(MODULE_NAME, (ApCallback) Test_Net_HTTP_OnClosed, 0, 0); } lTest_Net_HTTP_DataList.AddLast(new Test_Net_HTTP_Data(Apollo::newHandle(), "http://www.heise.de/")); lTest_Net_HTTP_DataList.AddLast(new Test_Net_HTTP_Data(Apollo::newHandle(), "http://www.heise.de/_vpi.xml")); lTest_Net_HTTP_DataList.AddLast(new Test_Net_HTTP_Data(Apollo::newHandle(), "http://www.virtual-presence.org/")); lTest_Net_HTTP_DataList.AddLast(new Test_Net_HTTP_Data(Apollo::newHandle(), "http://blog.wolfspelz.de/")); lTest_Net_HTTP_DataList.AddLast(new Test_Net_HTTP_Data(Apollo::newHandle(), "https://ssl.google-analytics.com/urchin.js")); // sometimes google does a redirect to https based on my cookie //lTest_Net_HTTP_DataList.AddLast(new Test_Net_HTTP_Data(Apollo::newHandle(), "http://www.google.de/ig?hl=de")); for (Test_Net_HTTP_Data* e = 0; (e = (Test_Net_HTTP_Data*) lTest_Net_HTTP_DataList.Next(e)) != 0; ) { Msg_Net_HTTP_Request msg; msg.hClient = e->apHandle(); msg.sUrl = e->sUrl_; msg.Request(); } //Msg_Net_HTTP_CancelAll msg; //msg.Request(); return ok; }
String ApLib::ExpandConfigAppTokens(const char* szConfigValue) { String sValue = szConfigValue; String sAppBasePath = Apollo::getAppBasePath(); String sAppResourcePath = Apollo::getAppResourcePath(); String sAppLibraryPath = Apollo::getAppLibraryPath(); String sAppModulePath = Apollo::getAppModulePath(); sValue.replace(String::filenamePathSeparator(), "/"); { List lReplace; lReplace.AddLast(AppBasePathToken() + "/", sAppBasePath); lReplace.AddLast(AppResourcePathToken() + "/", sAppResourcePath); lReplace.AddLast(AppLibraryPathToken() + "/", sAppLibraryPath); lReplace.AddLast(AppModulePathToken() + "/", sAppModulePath); if (sValue.replace(lReplace)) { // Config value is a path, bring back to native form and return replaced sValue.replace("/", String::filenamePathSeparator()); return sValue; } else {} // Not a (known to be) path, leave untouched } return szConfigValue; }
String ApLib::InsertConfigAppTokens(const char* szConfigValue) { String sValue = szConfigValue; String sAppBasePath = Apollo::getAppBasePath(); String sAppResourcePath = Apollo::getAppResourcePath(); String sAppLibraryPath = Apollo::getAppLibraryPath(); String sAppModulePath = Apollo::getAppModulePath(); { List lReplace; lReplace.AddLast(String::filenamePathSeparator(), "/"); sValue.replace(lReplace); sAppBasePath.replace(lReplace); sAppResourcePath.replace(lReplace); sAppLibraryPath.replace(lReplace); sAppModulePath.replace(lReplace); } { List lReplace; lReplace.AddLast(sAppBasePath, AppBasePathToken() + "/"); lReplace.AddLast(sAppResourcePath, AppResourcePathToken() + "/"); lReplace.AddLast(sAppLibraryPath, AppLibraryPathToken() + "/"); lReplace.AddLast(sAppModulePath, AppModulePathToken() + "/"); if (sValue.replace(lReplace)) { return sValue; } // Config value is a path, return replaced and normalized else {} // Not a (known to be) path, leave untouched } return szConfigValue; }
void RF_SysMem::GetNotDispatchedFunctions(List<RF_Type::String>& Result) { if(GetPageSize == GetPageSize_SystemAPIDispatcher || GetPageSize == 0) Result.AddLast(RF_Type::String("GetPageSize", sizeof("GetPageSize"))); if(EnableTerminationOnHeapCorruption == EnableTerminationOnHeapCorruption_SystemAPIDispatcher || EnableTerminationOnHeapCorruption == 0) Result.AddLast(RF_Type::String("EnableTerminationOnHeapCorruption", sizeof("EnableTerminationOnHeapCorruption"))); if(Allocate == Allocate_SystemAPIDispatcher || Allocate == 0) Result.AddLast(RF_Type::String("Allocate", sizeof("Allocate"))); if(Free == Free_SystemAPIDispatcher || Free == 0) Result.AddLast(RF_Type::String("Free", sizeof("Free"))); }
int main() { List l; l.AddNode(1); l.AddNode(6); l.AddNode(2); l.AddNode(9); //l.PrintList(); //l.DeleteNode(1); //l.PrintList(); l.AddFirst(99); l.AddFirst(91); l.AddFirst(64); l.AddLast(3203); l.InsertAfter(234, 2); l.InsertAfter(2, 64); l.PrintList(); l.GetListSize(); system("pause"); return 0; }
static VPI_UNUSED_FUNCTION void vpi_strlist_to_ListKey(char** strlist, List& lList) { char** p = strlist; while (*p != 0) { String sKey = *p; p++; lList.AddLast(sKey); } }
int Test_HTTPClient::OnHeader(int nStatus, Apollo::KeyValueList& kvHeaders) { nStatus_ = nStatus; for (Apollo::KeyValueElem* e = 0; (e = kvHeaders.nextElem(e)) != 0; ) { lHeader_.AddLast(String::toLower(e->getKey()), e->getString()); } return 1; }
void UnitTest::Register(const char* szName) { UnitTestItem* e = new UnitTestItem(szName); if (e != 0) { lTests_.AddLast(e); } #if defined(WIN32) if (Dialog() != 0) { Dialog()->SetRange(lTests_.length()); } #endif }
void Apollo::KeyValueList::toList(List& l) { for (Apollo::KeyValueElem* e = 0; (e = nextElem(e)) != 0; ) { Elem* f = new Elem(e->getKey()); if (f != 0) { if (0) { } else if (e->getType() == Apollo::KeyValueElem::TypeInt) { *f = e->getInt(); } else if (e->getType() == Apollo::KeyValueElem::TypeString) { *f = e->getString(); } l.AddLast(f); } } }
int Test_Begin_Net_TCP() { int ok = 1; { Msg_Net_TCP_Connected msg; msg.Hook(MODULE_NAME, (ApCallback) Test_Net_TCP_On_TCP_Connected, 0, 0); } { Msg_Net_TCP_DataIn msg; msg.Hook(MODULE_NAME, (ApCallback) Test_Net_TCP_On_TCP_DataIn, 0, 0); } { Msg_Net_TCP_Closed msg; msg.Hook(MODULE_NAME, (ApCallback) Test_Net_TCP_On_TCP_Closed, 0, 0); } lTest_Net_TCP_On_DataList.AddLast(new Test_Net_TCP_On_Data(Apollo::newHandle(), "www.heise.de", 80)); lTest_Net_TCP_On_DataList.AddLast(new Test_Net_TCP_On_Data(Apollo::newHandle(), "www.virtual-presence.org", 80)); lTest_Net_TCP_On_DataList.AddLast(new Test_Net_TCP_On_Data(Apollo::newHandle(), "blog.wolfspelz.de", 80)); lTest_Net_TCP_On_DataList.AddLast(new Test_Net_TCP_On_Data(Apollo::newHandle(), "www.google.de", 80)); //lTest_Net_TCP_On_DataList.AddLast(new Test_Net_TCP_On_Data(Apollo::newHandle(), "localhost", 80)); for (Test_Net_TCP_On_Data* e = 0; (e = (Test_Net_TCP_On_Data*) lTest_Net_TCP_On_DataList.Next(e)) != 0; ) { Msg_Net_TCP_Connect msg; msg.sHost = e->sAddress_; msg.nPort = e->nPort_; msg.hConnection = e->apHandle(); msg.Request(); } return ok; }
AutoPointerArray<String> DirectoryContent(const String& Path) { AutoPointerArray<String> result; List<String> list; WIN32_FIND_DATA findFileData; HANDLE hFind; String winPath=Path+"\\*";// search for everything hFind=FindFirstFile(winPath.c_str(),&findFileData); if (hFind!=INVALID_HANDLE_VALUE) { do { if (strcmp(findFileData.cFileName,".")!=0 && strcmp(findFileData.cFileName,"..")!=0) list.AddLast(String(findFileData.cFileName, MAX_PATH)); }while(FindNextFile(hFind,&findFileData)!=0); FindClose(hFind); result = AutoPointerArray<String>(new String[list.Count()], list.Count()); for (UInt32 i=0;i<result.Count();++i) result[i].Swap(list[i]); } return result; }
int main() { // Demo the use of our LinkedList class. LinkedList<int> l; // TData is int.... l.AddFirst(1); // ... so all the Add methods take ints. l.AddFirst(2); l.AddFirst(3); l.AddLast(4); l.AddLast(5); // Use the .Get method to access individual elements. // How efficient is this loop? Not as efficient. // The loop takes too long to walk through all elements of linked lists // if the size of linked list is large. for (int i = 0; i < l.Size(); i++) { cout << l.Get(i) << endl; } cout << "Remove: " << endl; // The .RemoveFirst/Last/At methods return the data removed. while (l.Size() > 0) { cout << l.RemoveFirst() << endl; } cout << endl; // It is easy to get the "border" cases wrong in a linked structure. Let's // test to see what happens when adding to a list that had just been emptied. l.AddFirst(1); l.AddFirst(2); l.AddFirst(3); l.AddLast(4); l.AddLast(5); cout << "After adding back to the emptied list:" << endl; for (int i = 0; i < l.Size(); i++) { cout << l.Get(i) << endl; } // Does that look correct? cout << endl; cout << "Contains 14? " << endl; // Demo the Contains method. Will this be true or false? cout << l.Contains(14) << endl; cout << endl; // So far we have used the LinkedList directly, so the List base class // doesn't seem necessary. Through polymorphism, we can declare a List // pointer to a LinkedList object. List<int> *p = new LinkedList<int>(); // We can now only call List<int> methods on p... which, fortunately, is all // of our important functions. p->AddLast(4); p->AddLast(8); p->AddLast(15); p->AddLast(16); p->AddLast(23); p->AddLast(42); cout << "Pointer to a List contains 16? " << p->Contains(16) << endl; // So far we don't have much of a reason to do this type of polymorphism. // But we will... // Lecture part 2: iterators! // Picture the normal iterator loop: // for (_____::iterator itr = _____.begin(); itr != _____.end(); itr++) { // do something with *itr or itr-> /* If we want our LinkedList to follow this trend, what do we need to implement? 1. An inner class named iterator, so our full scoped name will be LinkedList<TData>::iterator 2. Operators ++, ==, !=, *, and -> in the iterator class. 3. Member methods .begin() and .end() in LinkedList. When those are implemented, we can then... */ cout << endl << "ITERATORS!!!" << endl; for (LinkedList<int>::iterator itr = l.begin(); itr != l.end(); itr++) { cout << *itr << endl; } }
String ApLib::getMachineId() { String sData; #if defined(WIN32) String sVolumeSerialNumber; if (Apollo::getConfig("System/MachineIdUseVolumeSerialNumber", 1)) { DWORD dwVolumeSerialNumber = 0; String sRootPathName = "C:\\"; if (::GetVolumeInformation( sRootPathName, // LPCTSTR lpRootPathName, 0,// LPTSTR lpVolumeNameBuffer, 0,// DWORD nVolumeNameSize, &dwVolumeSerialNumber, // LPDWORD lpVolumeSerialNumber, 0,// LPDWORD lpMaximumComponentLength, 0,// LPDWORD lpFileSystemFlags, 0,// LPTSTR lpFileSystemNameBuffer, 0 // DWORD nFileSystemNameSize )) { sVolumeSerialNumber = String::from(dwVolumeSerialNumber); } } String sComputerName; if (Apollo::getConfig("System/MachineIdUseComputerName", 1)) { WCHAR pNameBuffer[10240+1]; DWORD nNameBufferSize = 10240; if (::GetComputerName(pNameBuffer, &nNameBufferSize)) { pNameBuffer[nNameBufferSize] = 0; sComputerName = pNameBuffer; } } String sMacAddress; if (Apollo::getConfig("System/MachineIdUseMacAddress", 1)) { List lAddress; DWORD dwBufLen = 0; if (::GetAdaptersInfo(0, &dwBufLen) == ERROR_BUFFER_OVERFLOW) { PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO) malloc(dwBufLen); if (pAdapterInfo != 0) { if (GetAdaptersInfo(pAdapterInfo, &dwBufLen) == ERROR_SUCCESS) { PIP_ADAPTER_INFO ppAdapterInfo = pAdapterInfo; do { String sIpAddress = (char*) & (ppAdapterInfo->IpAddressList.IpAddress); if ( sIpAddress != "0.0.0.0" && sIpAddress != "127.0.0.1" //&& !sIpAddress.startsWith("10.") //&& !sIpAddress.startsWith("169.254.") //&& !sIpAddress.startsWith("192.168.") //&& !sIpAddress.startsWith("192.0.2.") ) { String sMac; sMac.appendf("%02X%02X%02X%02X%02X%02X" , ppAdapterInfo->Address[0] , ppAdapterInfo->Address[1] , ppAdapterInfo->Address[2] , ppAdapterInfo->Address[3] , ppAdapterInfo->Address[4] , ppAdapterInfo->Address[5] ); lAddress.AddLast(sMac, (long) ppAdapterInfo->DhcpEnabled); } ppAdapterInfo = ppAdapterInfo->Next; } while (ppAdapterInfo != 0); } ::free(pAdapterInfo); pAdapterInfo = 0; } } for (Elem* e = 0; (e = lAddress.Next(e)) != 0; ) { if (e->getInt()) { sMacAddress += e->getName(); } } if (sMacAddress.empty() && lAddress.length() > 0) { sMacAddress = lAddress.First()->getName(); } } if (sVolumeSerialNumber.isset()) { sData += sVolumeSerialNumber; } if (sComputerName.isset()) { sData += sComputerName; } if (sMacAddress.isset()) { sData += sMacAddress; } #endif String sMachineId; if (sData != "") { //sMachineId = sData; Apollo::MessageDigest digest((unsigned char *) sData.c_str(), sData.bytes()); sMachineId = digest.getSHA1Hex(); } return sMachineId; }