Changeset 8223547 in nscp
- Timestamp:
- 03/01/05 22:42:27 (8 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 2a94f3f
- Parents:
- 36c340d
- Files:
-
- 11 edited
-
NSClient++.cpp (modified) (9 diffs)
-
NSClient++.vcproj (modified) (1 diff)
-
changelog (modified) (1 diff)
-
config.h (modified) (2 diffs)
-
include/Mutex.h (modified) (1 diff)
-
include/NSCHelper.cpp (modified) (10 diffs)
-
include/NSCHelper.h (modified) (2 diffs)
-
modules/CheckDisk/CheckDisk.cpp (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (3 diffs)
-
modules/CheckEventLog/CheckEventLog.vcproj (modified) (1 diff)
-
modules/NSClientCompat/NSClientCompat.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
NSClient++.cpp
r36c340d r8223547 115 115 LOG_DEBUG("Plugins unloaded..."); 116 116 } catch(NSPluginException *e) { 117 LOG_ERROR_STD("Exception raised: " + e->error_ + " in module: " + e->file_);117 std::cout << "Exception raised: " << e->error_ << " in module: " << e->file_ << std::endl;; 118 118 } 119 119 Settings::destroyInstance(); … … 159 159 */ 160 160 void NSClientT::unloadPlugins() { 161 MutexLock lock(pluginMutex );161 MutexLock lock(pluginMutex,20000); 162 162 if (!lock.hasMutex()) { 163 163 LOG_ERROR("FATAL ERROR: Could not get mutex."); … … 169 169 std::cout << "Unloading plugin: " << (*it)->getName() << "..."; 170 170 #endif 171 (*it)->unload();171 (*it)->unload(); 172 172 #ifdef _DEBUG 173 173 std::cout << "OK" << std::endl; 174 174 #endif 175 175 } 176 messageHandlers_.clear(); 176 { 177 MutexLock lock2(messageMutex,20000); 178 if (!lock2.hasMutex()) { 179 LOG_ERROR("FATAL ERROR: Could not get mutex (we will now crash BTW)."); 180 } else { 181 messageHandlers_.clear(); 182 } 183 } 177 184 commandHandlers_.clear(); 178 185 for (it = plugins_.rbegin(); it != plugins_.rend(); ++it) { … … 215 222 std::string NSClientT::inject(const std::string buffer) { 216 223 std::list<std::string> args = charEx::split(buffer.c_str(), '&'); 224 if (args.empty()) 225 return ""; 217 226 std::string command = args.front(); args.pop_front(); 218 227 LOG_MESSAGE_STD("Injecting: " + command); … … 244 253 MutexLock lock(pluginMutex); 245 254 if (!lock.hasMutex()) { 246 LOG_ERROR("FATAL ERROR: Could not get mutex.");247 return " FATAL ERROR";255 LOG_ERROR("FATAL ERROR: Could not execute command with a reasonable timeframe. (could not get mutex so core is most likely locked down)."); 256 return "ERROR: Core was locked down"; 248 257 } 249 258 static unsigned int bufferSize = 0; … … 252 261 253 262 if (password != getPassword()) 254 return "INVALID PASSWORD"; 255 256 // Pack the argument as a char** buffer 263 return "ERROR: Authorization denied."; 264 257 265 std::string ret; 258 int len = args.size(); 259 char **arguments = new char*[len]; 260 std::list<std::string>::iterator it = args.begin(); 261 for (int i=0;it!=args.end();++it,i++) { 262 int alen = (*it).size(); 263 arguments[i] = new char[alen+2]; 264 strncpy(arguments[i], (*it).c_str(), alen+1); 265 } 266 unsigned int len; 267 char **arguments = NSCHelper::list2arrayBuffer(args, len); 266 268 // Allocate return buffer 267 269 char* returnbuffer = new char[bufferSize+1]; … … 286 288 // delete buffers 287 289 delete [] returnbuffer; 288 for (int i=0;i<len;i++) { 289 delete [] arguments[i]; 290 } 291 delete [] arguments; 290 NSCHelper::destroyArrayBuffer(arguments, len); 292 291 return ret; 293 292 } … … 303 302 MutexLock lock(messageMutex); 304 303 if (!lock.hasMutex()) { 305 LOG_ERROR("FATAL ERROR: Could not get mutex."); 304 std::cout << "Message was lost as the core was locked..." << std::endl; 305 std::cout << message << std::endl; 306 306 return; 307 307 } … … 324 324 } catch(const NSPluginException& e) { 325 325 // Here we are pretty much fucked! (as logging this might cause a loop :) 326 std::cout << "Caught: " << e.error_ << " when trying to log a message..." << std::endl; 326 327 std::cout << "This is *really really* bad, now the world is about to end..." << std::endl; 327 328 } -
NSClient++.vcproj
r36c340d r8223547 457 457 Filter=""> 458 458 <File 459 RelativePath=".\changelog"> 460 </File> 461 <File 459 462 RelativePath=".\Doxyfile"> 460 463 <FileConfiguration -
changelog
ra0528c4 r8223547 1 2005-03-01 MickeM 2 * Improved thread safety in Core 3 + Added exception handling and logging in PDH code 4 * Various fixes all over the place 5 + New module for check size of files/directories 6 * Changed build to Dynamic link 7 * Added regular expression support for EventLog checker 8 9 2005-02-22 MickeM 10 + Added documentation 11 12 2005-02-17 MickeM 13 * NSClient issues fixed 14 * Systray issues fixed 15 1 16 2005-02-14 MickeM 2 * Initial sourceforge rel ase17 * Initial sourceforge release -
config.h
r167a5dd r8223547 7 7 8 8 // Version 9 #define SZVERSION "0. 1.0 2005-01-23"9 #define SZVERSION "0.0.1 RC4 2005-03-01" 10 10 11 11 // internal name of the service … … 18 18 #define SZDEPENDENCIES "" 19 19 20 21 // PDH Check interval (Check every x second)22 //#define CHECK_INTERVAL 123 24 // PDH CPU check backlog (x minutes)25 //#define BACK_INTERVAL 200026 27 20 // Buffer size of incoming data (noteice this is the maximum request length!) 28 21 #define RECV_BUFFER_LEN 1024 29 22 30 31 32 #define DEFAULT_TCP_PORT 1234 23 #define DEFAULT_TCP_PORT 12489 -
include/Mutex.h
ra0528c4 r8223547 99 99 * @param hMutex The mutex to use 100 100 */ 101 MutexLock(HANDLE hMutex ) : bHasMutex(false), hMutex_(hMutex) {101 MutexLock(HANDLE hMutex, DWORD timeout = 5000L) : bHasMutex(false), hMutex_(hMutex) { 102 102 assert(hMutex_ != NULL); 103 dwWaitResult = WaitForSingleObject(hMutex_, 5000L);103 dwWaitResult = WaitForSingleObject(hMutex_, timeout); 104 104 switch (dwWaitResult) { 105 105 // The thread got mutex ownership. -
include/NSCHelper.cpp
r36c340d r8223547 1 1 #include "stdafx.h" 2 2 #include <NSCHelper.h> 3 #include <assert.h> 3 4 4 5 #define BUFF_LEN 4096 … … 15 16 */ 16 17 int NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str, int defaultReturnCode /* = NSCAPI::success */) { 17 if (str.length() > bufLen)18 if (str.length() >= bufLen) 18 19 return NSCAPI::invalidBufferLen; 19 20 strncpy(buffer, str.c_str(), bufLen); … … 26 27 * @return Argument wrapped as a list 27 28 */ 28 std::list<std::string> NSCHelper:: makelist(const unsigned int argLen, char *argument[]) {29 std::list<std::string> NSCHelper::arrayBuffer2list(const unsigned int argLen, char *argument[]) { 29 30 std::list<std::string> ret; 30 31 int i=0; … … 35 36 return ret; 36 37 } 38 /** 39 * Create an arrayBuffer from a list. 40 * This is the reverse of arrayBuffer2list. 41 * <b>Notice</b> it is up to the caller to free the memory allocated in the returned buffer. 42 * 43 * @param lst A list to convert. 44 * @param &argLen Write the length to this argument. 45 * @return A pointer that is managed by the caller. 46 */ 47 char ** NSCHelper::list2arrayBuffer(const std::list<std::string> lst, unsigned int &argLen) { 48 std::string ret; 49 argLen = static_cast<unsigned int>(lst.size()); 50 char **arrayBuffer = new char*[argLen]; 51 std::list<std::string>::const_iterator it = lst.begin(); 52 for (int i=0;it!=lst.end();++it,i++) { 53 std::string::size_type alen = (*it).size(); 54 arrayBuffer[i] = new char[alen+2]; 55 strncpy(arrayBuffer[i], (*it).c_str(), alen+1); 56 } 57 assert(i == argLen); 58 return arrayBuffer; 59 } 60 /** 61 * Destroy an arrayBuffer. 62 * The buffer should have been created with list2arrayBuffer. 63 * 64 * @param **argument 65 * @param argLen 66 */ 67 void NSCHelper::destroyArrayBuffer(char **argument, const unsigned int argLen) { 68 for (unsigned int i=0;i<argLen;i++) { 69 delete [] argument[i]; 70 } 71 delete [] argument; 72 } 73 74 37 75 /** 38 76 * Translate a message type into a human readable string. … … 91 129 * @param line Line where message was generated (__LINE__) 92 130 * @param message Message in human readable format 131 * @throws NSCMHExcpetion When core pointer set is unavailable. 93 132 */ 94 133 void NSCModuleHelper::Message(int msgType, std::string file, int line, std::string message) { 95 134 if (!fNSAPIMessage) 96 throw "NSCore has not been initiated...";135 throw NSCMHExcpetion("NSCore has not been initiated..."); 97 136 return fNSAPIMessage(msgType, file.c_str(), line, message.c_str()); 98 137 } … … 101 140 * @param command Command to inject (password should not be included. 102 141 * @return The result (if any) of the command. 142 * @throws NSCMHExcpetion When core pointer set is unavailable or an unknown inject error occures. 103 143 */ 104 144 std::string NSCModuleHelper::InjectCommand(std::string command) { 105 145 if (!fNSAPIInject) 106 return "NSCore has not been initiated..."; 107 char *buffer = new char[BUFF_LEN+1]; 108 if (fNSAPIInject(command.c_str(), buffer, BUFF_LEN) != NSCAPI::success) 109 throw "Application name could not be retrieved"; 110 std::string ret = buffer; 146 throw NSCMHExcpetion("NSCore has not been initiated..."); 147 char *buffer = new char[BUFF_LEN+1]; 148 std::string ret; 149 int err; 150 if ((err = fNSAPIInject(command.c_str(), buffer, BUFF_LEN)) != NSCAPI::success) { 151 if (err == NSCAPI::invalidBufferLen) 152 NSC_LOG_ERROR("Inject command resulted in an invalid buffer size."); 153 else 154 throw NSCMHExcpetion("Unknown inject error."); 155 } else { 156 ret = buffer; 157 } 111 158 delete [] buffer; 112 159 return ret; … … 128 175 * @param defaultValue A default value (if no value is set in the settings file) 129 176 * @return the current value or defaultValue if no value is set. 177 * @throws NSCMHExcpetion When core pointer set is unavailable or an error occurs. 130 178 */ 131 179 std::string NSCModuleHelper::getSettingsString(std::string section, std::string key, std::string defaultValue) { 132 180 if (!fNSAPIGetSettingsString) 133 throw "NSCore has not been initiated..."; 134 char *buffer = new char[BUFF_LEN+1]; 135 int x = fNSAPIGetSettingsString(section.c_str(), key.c_str(), defaultValue.c_str(), buffer, BUFF_LEN); 181 throw NSCMHExcpetion("NSCore has not been initiated..."); 182 char *buffer = new char[BUFF_LEN+1]; 183 if (fNSAPIGetSettingsString(section.c_str(), key.c_str(), defaultValue.c_str(), buffer, BUFF_LEN) != NSCAPI::success) { 184 delete [] buffer; 185 throw NSCMHExcpetion("Settings could not be retrieved."); 186 } 136 187 std::string ret = buffer; 137 188 delete [] buffer; … … 146 197 * @param defaultValue A default value (if no value is set in the settings file) 147 198 * @return the current value or defaultValue if no value is set. 199 * @throws NSCMHExcpetion When core pointer set is unavailable. 148 200 */ 149 201 int NSCModuleHelper::getSettingsInt(std::string section, std::string key, int defaultValue) { 150 202 if (!fNSAPIGetSettingsInt) 151 throw "NSCore has not been initiated...";203 throw NSCMHExcpetion("NSCore has not been initiated..."); 152 204 return fNSAPIGetSettingsInt(section.c_str(), key.c_str(), defaultValue); 153 205 } 154 206 /** 155 * Retrieve the application name (in human readable format) from the core. 156 * @return A string representing the application name. 157 */ 207 * Retrieve the application name (in human readable format) from the core. 208 * @return A string representing the application name. 209 * @throws NSCMHExcpetion When core pointer set is unavailable or an unexpected error occurs. 210 */ 158 211 std::string NSCModuleHelper::getApplicationName() { 159 212 if (!fNSAPIGetApplicationName) 160 return "NSCore has not been initiated..."; 161 char *buffer = new char[BUFF_LEN+1]; 162 if (fNSAPIGetApplicationName(buffer, BUFF_LEN) != NSCAPI::success) 163 throw "Application name could not be retrieved"; 213 throw NSCMHExcpetion("NSCore has not been initiated..."); 214 char *buffer = new char[BUFF_LEN+1]; 215 if (fNSAPIGetApplicationName(buffer, BUFF_LEN) != NSCAPI::success) { 216 delete [] buffer; 217 throw NSCMHExcpetion("Application name could not be retrieved"); 218 } 164 219 std::string ret = buffer; 165 220 delete [] buffer; … … 169 224 * Retrieve the directory root of the application from the core. 170 225 * @return A string representing the base path. 226 * @throws NSCMHExcpetion When core pointer set is unavailable or an unexpected error occurs. 171 227 */ 172 228 std::string NSCModuleHelper::getBasePath() { 173 229 if (!fNSAPIGetBasePath) 174 return "NSCore has not been initiated..."; 175 char *buffer = new char[BUFF_LEN+1]; 176 if (fNSAPIGetBasePath(buffer, BUFF_LEN) != NSCAPI::success) 177 throw "Base path could not be retrieved"; 230 throw NSCMHExcpetion("NSCore has not been initiated..."); 231 char *buffer = new char[BUFF_LEN+1]; 232 if (fNSAPIGetBasePath(buffer, BUFF_LEN) != NSCAPI::success) { 233 delete [] buffer; 234 throw NSCMHExcpetion("Base path could not be retrieved"); 235 } 178 236 std::string ret = buffer; 179 237 delete [] buffer; … … 183 241 * Retrieve the application version as a string (in human readable format) from the core. 184 242 * @return A string representing the application version. 243 * @throws NSCMHExcpetion When core pointer set is unavailable. 185 244 */ 186 245 std::string NSCModuleHelper::getApplicationVersionString() { 187 246 if (!fNSAPIGetApplicationVersionStr) 188 return "NSCore has not been initiated...";247 throw NSCMHExcpetion("NSCore has not been initiated..."); 189 248 char *buffer = new char[BUFF_LEN+1]; 190 249 int x = fNSAPIGetApplicationVersionStr(buffer, BUFF_LEN); -
include/NSCHelper.h
r36c340d r8223547 8 8 { 9 9 int wrapReturnString(char *buffer, unsigned int bufLen, std::string str, int defaultReturnCode = NSCAPI::success); 10 std::list<std::string> makelist(const unsigned int argLen, char **argument); 10 11 std::list<std::string> arrayBuffer2list(const unsigned int argLen, char **argument); 12 char ** list2arrayBuffer(const std::list<std::string> lst, unsigned int &argLen); 13 void destroyArrayBuffer(char **argument, const unsigned int argLen); 14 11 15 std::string translateMessageType(NSCAPI::messageTypes msgType); 12 16 std::string translateReturn(NSCAPI::returnCodes returnCode); … … 66 70 namespace NSCModuleHelper 67 71 { 72 class NSCMHExcpetion { 73 public: 74 std::string msg_; 75 NSCMHExcpetion(std::string msg) : msg_(msg) {} 76 }; 68 77 // Types for the Callbacks into the main program 69 78 typedef int (*lpNSAPIGetBasePath)(char*,unsigned int); -
modules/CheckDisk/CheckDisk.cpp
r36c340d r8223547 111 111 std::string ret; 112 112 NSCAPI::returnCodes returnCode = NSCAPI::returnOK; 113 std::list<std::string> args = NSCHelper:: makelist(argLen, char_args);113 std::list<std::string> args = NSCHelper::arrayBuffer2list(argLen, char_args); 114 114 if (args.empty()) 115 115 return "Missing argument(s)."; -
modules/CheckEventLog/CheckEventLog.cpp
r36c340d r8223547 225 225 try { 226 226 std::string s = p.second; 227 NSC_DEBUG_MSG_STD("Attempting to make regexp from: " + s);228 227 item.eventSourceRegExp_ = s; 229 NSC_DEBUG_MSG_STD("success...");230 228 } catch (const boost::bad_expression e) { 231 229 item.eventSourceRegExp_ = ""; … … 250 248 } else 251 249 throw (std::string)"Invalid argument: " + p.first; 250 252 251 } 253 252 void addToQueryBundle(searchQuery::searchQueryBundle &bundle, std::string arg) { … … 301 300 return ""; 302 301 NSCAPI::returnCodes rCode = NSCAPI::returnOK; 303 std::list<std::string> args = NSCHelper:: makelist(argLen, char_args);302 std::list<std::string> args = NSCHelper::arrayBuffer2list(argLen, char_args); 304 303 if (args.size() < 2) 305 304 return "Missing argument"; -
modules/CheckEventLog/CheckEventLog.vcproj
r36c340d r8223547 120 120 Name="VCCLCompilerTool" 121 121 AdditionalIncludeDirectories="../include;../../include" 122 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS; _STLP_USE_STATIC_LIB;SYSTRAY_EXPORTS"123 RuntimeLibrary=" 0"122 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;BOOST_REGEX_DYN_LINK" 123 RuntimeLibrary="2" 124 124 UsePrecompiledHeader="3" 125 125 WarningLevel="3" -
modules/NSClientCompat/NSClientCompat.cpp
r36c340d r8223547 125 125 case REQ_CPULOAD: 126 126 { 127 stl_args = NSCHelper:: makelist(argLen, args);127 stl_args = NSCHelper::arrayBuffer2list(argLen, args); 128 128 if (stl_args.empty()) 129 129 return "ERROR: Missing argument exception."; … … 141 141 } 142 142 case REQ_SERVICESTATE: 143 return NSCommands::serviceState(NSCHelper:: makelist(argLen, args));143 return NSCommands::serviceState(NSCHelper::arrayBuffer2list(argLen, args)); 144 144 145 145 case REQ_PROCSTATE: 146 return NSCommands::procState(NSCHelper:: makelist(argLen, args));146 return NSCommands::procState(NSCHelper::arrayBuffer2list(argLen, args)); 147 147 148 148 case REQ_MEMUSE: … … 151 151 152 152 case REQ_USEDDISKSPACE: 153 return NSCommands::usedDiskSpace(NSCHelper:: makelist(argLen, args));153 return NSCommands::usedDiskSpace(NSCHelper::arrayBuffer2list(argLen, args)); 154 154 } 155 155 return "";
Note: See TracChangeset
for help on using the changeset viewer.








