| 127 | | void |
|---|
| 128 | | CaptureSoapServer::loadClientPlugins() |
|---|
| 129 | | { |
|---|
| 130 | | WIN32_FIND_DATA FindFileData; |
|---|
| 131 | | HANDLE hFind = INVALID_HANDLE_VALUE; |
|---|
| 132 | | wchar_t pluginDirectoryPath[1024]; |
|---|
| 133 | | |
|---|
| 134 | | GetFullPathName(L"plugins\\Application_*.dll", 1024, pluginDirectoryPath, NULL); |
|---|
| 135 | | DebugPrint(L"Capture-SOAP Server: Plugin directory - %ls\n", pluginDirectoryPath); |
|---|
| 136 | | hFind = FindFirstFile(pluginDirectoryPath, &FindFileData); |
|---|
| 137 | | |
|---|
| 138 | | if (hFind != INVALID_HANDLE_VALUE) |
|---|
| 139 | | { |
|---|
| 140 | | typedef void (*AppPlugin)(void*); |
|---|
| 141 | | do |
|---|
| 142 | | { |
|---|
| 143 | | wstring pluginDir = L"plugins\\"; |
|---|
| 144 | | pluginDir += FindFileData.cFileName; |
|---|
| 145 | | HMODULE hPlugin = LoadLibrary(pluginDir.c_str()); |
|---|
| 146 | | |
|---|
| 147 | | if(hPlugin != NULL) |
|---|
| 148 | | { |
|---|
| 149 | | list<ApplicationPlugin*>* apps = new std::list<ApplicationPlugin*>(); |
|---|
| 150 | | applicationPlugins.insert(PluginPair(hPlugin, apps)); |
|---|
| 151 | | ApplicationPlugin* applicationPlugin = createApplicationPluginObject(hPlugin); |
|---|
| 152 | | if(applicationPlugin == NULL) { |
|---|
| 153 | | FreeLibrary(hPlugin); |
|---|
| 154 | | } else { |
|---|
| 155 | | printf("Loaded plugin: %ls\n", FindFileData.cFileName); |
|---|
| 156 | | unsigned int g = applicationPlugin->getPriority(); |
|---|
| 157 | | wchar_t** supportedApplications = applicationPlugin->getSupportedApplicationNames(); |
|---|
| 158 | | for(int i = 0; supportedApplications[i] != NULL; i++) |
|---|
| 159 | | { |
|---|
| 160 | | stdext::hash_map<wstring, ApplicationPlugin*>::iterator it; |
|---|
| 161 | | it = applicationMap.find(supportedApplications[i]); |
|---|
| 162 | | /* Check he application isn't already being handled by a plugin */ |
|---|
| 163 | | if(it != applicationMap.end()) |
|---|
| 164 | | { |
|---|
| 165 | | /* Check the priority of the existing application plugin */ |
|---|
| 166 | | unsigned int p = it->second->getPriority(); |
|---|
| 167 | | if(applicationPlugin->getPriority() > p) |
|---|
| 168 | | { |
|---|
| 169 | | /* Over ride the exisiting plugin if the priority of the loaded one |
|---|
| 170 | | is greater */ |
|---|
| 171 | | applicationMap.erase(supportedApplications[i]); |
|---|
| 172 | | printf("\toverride: added application: %ls\n", supportedApplications[i]); |
|---|
| 173 | | applicationMap.insert(ApplicationPair(supportedApplications[i], applicationPlugin)); |
|---|
| 174 | | } else { |
|---|
| 175 | | printf("\tplugin overridden: not adding application: %ls\n", supportedApplications[i]); |
|---|
| 176 | | } |
|---|
| 177 | | } else { |
|---|
| 178 | | printf("\tinserted: added application: %ls\n", supportedApplications[i]); |
|---|
| 179 | | applicationMap.insert(ApplicationPair(supportedApplications[i], applicationPlugin)); |
|---|
| 180 | | } |
|---|
| 181 | | } |
|---|
| 182 | | } |
|---|
| 183 | | } |
|---|
| 184 | | } while(FindNextFile(hFind, &FindFileData) != 0); |
|---|
| 185 | | FindClose(hFind); |
|---|
| 186 | | } |
|---|
| 187 | | |
|---|
| 188 | | } |
|---|
| 189 | | |
|---|
| 190 | | ApplicationPlugin* |
|---|
| 191 | | CaptureSoapServer::createApplicationPluginObject(HMODULE hPlugin) |
|---|
| 192 | | { |
|---|
| 193 | | typedef void (*PluginExportInterface)(void*); |
|---|
| 194 | | PluginExportInterface pluginCreateInstance = NULL; |
|---|
| 195 | | ApplicationPlugin* applicationPlugin = NULL; |
|---|
| 196 | | /* Get the function address to create a plugin object */ |
|---|
| 197 | | pluginCreateInstance = (PluginExportInterface)GetProcAddress(hPlugin,"New"); |
|---|
| 198 | | /* Create a new plugin object in the context of the plugin */ |
|---|
| 199 | | pluginCreateInstance(&applicationPlugin); |
|---|
| 200 | | /* If the object was created then add it to a list so we can track it */ |
|---|
| 201 | | if(applicationPlugin != NULL) |
|---|
| 202 | | { |
|---|
| 203 | | stdext::hash_map<HMODULE, std::list<ApplicationPlugin*>*>::iterator it; |
|---|
| 204 | | it = applicationPlugins.find(hPlugin); |
|---|
| 205 | | if(it != applicationPlugins.end()) |
|---|
| 206 | | { |
|---|
| 207 | | list<ApplicationPlugin*>* apps = it->second; |
|---|
| 208 | | apps->push_back(applicationPlugin); |
|---|
| 209 | | } |
|---|
| 210 | | } |
|---|
| 211 | | return applicationPlugin; |
|---|
| 212 | | } |
|---|
| 213 | | |
|---|
| 214 | | void |
|---|
| 215 | | CaptureSoapServer::onServerEvent(Element* pElement) |
|---|
| 216 | | { |
|---|
| 217 | | wstring applicationName = L"iexplore"; |
|---|
| 218 | | wstring url = L""; |
|---|
| 219 | | int time = 30; |
|---|
| 220 | | vector<Attribute>::iterator it; |
|---|
| 221 | | for(it = pElement->attributes.begin(); it != pElement->attributes.end(); it++) |
|---|
| 222 | | { |
|---|
| 223 | | if(it->name == L"url") { |
|---|
| 224 | | url = it->value; |
|---|
| 225 | | } else if(it->name == L"program") { |
|---|
| 226 | | applicationName = it->value; |
|---|
| 227 | | } else if(it->name == L"time") { |
|---|
| 228 | | time = boost::lexical_cast<int>(it->value); |
|---|
| 229 | | } |
|---|
| 230 | | } |
|---|
| 231 | | if(url != L"") |
|---|
| 232 | | { |
|---|
| 233 | | url = CaptureGlobal::urlDecode(url); |
|---|
| 234 | | stdext::hash_map<wstring, ApplicationPlugin*>::iterator vit; |
|---|
| 235 | | vit = applicationMap.find(applicationName); |
|---|
| 236 | | if(vit != applicationMap.end()) |
|---|
| 237 | | { |
|---|
| 238 | | ApplicationPlugin* applicationPlugin = vit->second; |
|---|
| 239 | | Url* visiturl = new Url(url, applicationName, time); |
|---|
| 240 | | DWORD minorErrorCode = 0; |
|---|
| 241 | | DWORD majorErrorCode = 0; |
|---|
| 242 | | printf("Visiting: %ls -> %ls\n", visiturl->getApplicationName().c_str(), visiturl->getUrl().c_str()); |
|---|
| 243 | | |
|---|
| 244 | | /* Pass the actual visitation process of to the application plugin */ |
|---|
| 245 | | majorErrorCode = applicationPlugin->visitUrl(visiturl, &minorErrorCode); |
|---|
| 246 | | ///toVisit.push(VisitPair(applicationPlugin, visiturl)); |
|---|
| 247 | | ///SetEvent(hQueueNotEmpty); |
|---|
| 248 | | } else { |
|---|
| 249 | | printf("CaptureSoapServer-onServerEvent: ERROR could not find client %ls path, url not queued for visitation\n", applicationName.c_str()); |
|---|
| 250 | | } |
|---|
| 251 | | } else { |
|---|
| 252 | | printf("CaptureSoapServer-onServerEvent: ERROR no url specified for visit event\n"); |
|---|
| 253 | | } |
|---|
| 254 | | } |
|---|