Changeset ea8a900 in nscp
- Timestamp:
- 02/16/05 23:27:49 (8 years ago)
- Children:
- c67f92f
- Parents:
- 0a84a74
- Location:
- trunk
- Files:
-
- 4 edited
-
NSCPlugin.cpp (modified) (1 diff)
-
NSCPlugin.h (modified) (1 diff)
-
NSClient++.cpp (modified) (9 diffs)
-
NSClient++.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/NSCPlugin.cpp
re0705d4 rea8a900 154 154 } 155 155 /** 156 * Helper function to create a plug in for a third party.157 * <b>Notice</b> though the name might suggest it the plug in is <b>not</b> actually loaded.158 *159 * @deprecated160 * @param file The file (DLL) of the plug in module161 * @return A pointer to a new instance of the plug in wrapper class.162 */163 NSCPlugin* NSCPlugin::loadPlugin(std::string file) {164 return new NSCPlugin(file);165 }166 /**167 156 * Load all remote function pointers from the loaded module. 168 157 * These pointers are cached for "speed" which might (?) be dangerous if something changes. -
trunk/NSCPlugin.h
re0705d4 rea8a900 119 119 void unload(void); 120 120 121 static NSCPlugin* loadPlugin(std::string file);122 123 121 private: 124 122 bool isLoaded() const { -
trunk/NSClient++.cpp
re0705d4 rea8a900 65 65 LOG_MESSAGE("Enter command to inject or exit to terminate..."); 66 66 std::string s = ""; 67 std::cin >> s; 67 68 while (s != "exit") { 69 mainClient.inject(s); 68 70 std::cin >> s; 69 mainClient.inject(s);70 71 } 71 72 mainClient.TerminateService(); 73 LOG_MESSAGE("DONE!"); 72 74 return 0; 73 75 } else { … … 88 90 */ 89 91 void NSClientT::InitiateService(void) { 90 char* buffer = new char[1024]; 91 GetModuleFileName(NULL, buffer, 1023); 92 std::string path = buffer; 93 std::string::size_type pos = path.rfind('\\'); 94 basePath = path.substr(0, pos) + "\\"; 95 LOG_DEBUG_STD("Base path is: " + basePath); 96 delete [] buffer; 97 Settings::getInstance()->setFile(basePath + "NSC.ini"); 92 Settings::getInstance()->setFile(getBasePath() + "NSC.ini"); 98 93 99 94 SettingsT::sectionList list = Settings::getInstance()->getSection("modules"); 100 95 for (SettingsT::sectionList::iterator it = list.begin(); it != list.end(); it++) { 101 96 try { 102 LOG_DEBUG_STD("Loading: " + basePath+ "modules\\" + (*it));103 loadPlugin( basePath+ "modules\\" + (*it));97 LOG_DEBUG_STD("Loading: " + getBasePath() + "modules\\" + (*it)); 98 loadPlugin(getBasePath() + "modules\\" + (*it)); 104 99 } catch(const NSPluginException& e) { 105 100 LOG_ERROR_STD("Exception raised: " + e.error_ + " in module: " + e.file_); … … 116 111 LOG_ERROR("Could not exit socket listener thread"); 117 112 try { 113 LOG_DEBUG("Socket closed, unloading plugins..."); 118 114 mainClient.unloadPlugins(); 115 LOG_DEBUG("Plugins unloaded..."); 119 116 } catch(NSPluginException *e) { 120 117 LOG_ERROR_STD("Exception raised: " + e->error_ + " in module: " + e->file_); … … 157 154 */ 158 155 void NSClientT::unloadPlugins() { 156 pluginList::reverse_iterator it; 157 for (it = plugins_.rbegin(); it != plugins_.rend(); ++it) { 158 #ifdef _DEBUG 159 std::cout << "Unloading plugin: " << (*it)->getName() << "..."; 160 #endif 161 (*it)->unload(); 162 #ifdef _DEBUG 163 std::cout << "OK" << std::endl; 164 #endif 165 } 159 166 messageHandlers_.clear(); 160 167 commandHandlers_.clear(); 161 pluginList::reverse_iterator it;162 168 for (it = plugins_.rbegin(); it != plugins_.rend(); ++it) { 163 LOG_DEBUG_STD("---\n\n\nUnloading: " + (*it)->getName());164 (*it)->unload();165 169 delete (*it); 166 170 } … … 172 176 */ 173 177 void NSClientT::loadPlugin(std::string file) { 174 addPlugin( NSCPlugin::loadPlugin(file));178 addPlugin(new NSCPlugin(file)); 175 179 } 176 180 /** … … 178 182 * @param *plugin The plug-ininstance to load. The pointer is managed by the 179 183 */ 180 void NSClientT::addPlugin( NSCPlugin *plugin) {184 void NSClientT::addPlugin(plugin_type plugin) { 181 185 plugin->load(); 182 186 LOG_DEBUG_STD("Loading: " + plugin->getName()); … … 290 294 } 291 295 } 296 std::string NSClientT::getBasePath(void) { 297 if (!basePath.empty()) 298 return basePath; 299 char* buffer = new char[1024]; 300 GetModuleFileName(NULL, buffer, 1023); 301 std::string path = buffer; 302 std::string::size_type pos = path.rfind('\\'); 303 basePath = path.substr(0, pos) + "\\"; 304 delete [] buffer; 305 Settings::getInstance()->setFile(basePath + "NSC.ini"); 306 return basePath; 307 } 308 292 309 293 310 int NSAPIGetSettingsString(const char* section, const char* key, const char* defaultValue, char* buffer, unsigned int bufLen) { … … 298 315 } 299 316 317 318 int NSAPIGetBasePath(char*buffer, unsigned int bufLen) { 319 return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.getBasePath()); 320 } 300 321 int NSAPIGetApplicationName(char*buffer, unsigned int bufLen) { 301 322 return NSCHelper::wrapReturnString(buffer, bufLen, SZAPPNAME); … … 329 350 if (stricmp(buffer, "NSAPIInject") == 0) 330 351 return &NSAPIInject; 352 if (stricmp(buffer, "NSAPIGetBasePath") == 0) 353 return &NSAPIGetBasePath; 331 354 return NULL; 332 355 } -
trunk/NSClient++.h
re0705d4 rea8a900 37 37 class NSClientT { 38 38 private: 39 typedef std::list<NSCPlugin*> pluginList; 39 typedef NSCPlugin* plugin_type; 40 typedef std::list<plugin_type> pluginList; 40 41 pluginList plugins_; 41 42 pluginList commandHandlers_; … … 58 59 // Member functions 59 60 static std::string getPassword(void); 61 std::string getBasePath(void); 60 62 std::string inject(std::string buffer); 61 63 std::string execute(std::string password, std::string cmd, std::list<std::string> args); … … 68 70 69 71 private: 70 void addPlugin( NSCPlugin *plugin);72 void addPlugin(plugin_type plugin); 71 73 72 74 }; … … 82 84 LPVOID NSAPILoader(char*buffer); 83 85 int NSAPIGetApplicationName(char*buffer, unsigned int bufLen); 86 int NSAPIGetBasePath(char*buffer, unsigned int bufLen); 84 87 int NSAPIGetApplicationVersionStr(char*buffer, unsigned int bufLen); 85 88 int NSAPIGetSettingsString(const char* section, const char* key, const char* defaultValue, char* buffer, unsigned int bufLen);
Note: See TracChangeset
for help on using the changeset viewer.








