Changeset 81e29d8 in nscp
- Timestamp:
- 03/21/05 08:55:37 (8 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- d4f294a
- Parents:
- c6e008c
- Files:
-
- 5 edited
-
changelog (modified) (1 diff)
-
include/NSCAPI.h (modified) (3 diffs)
-
include/NSCHelper.cpp (modified) (6 diffs)
-
include/NSCHelper.h (modified) (3 diffs)
-
modules/NSClientListener/NSClientSocket.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r1eef1ee r81e29d8 1 2005-03-21 MickeM 2 * Fixed BUG in inject command (now things should "work" again, but far from stable) 3 1 4 2005-03-20 MickeM 2 5 * Fundamental API changes (due to NRPE compatibility) -
include/NSCAPI.h
r1eef1ee r81e29d8 3 3 namespace NSCAPI { 4 4 5 #ifdef DEBUG 5 6 typedef enum { 6 7 returnCRIT = 2, … … 11 12 returnIgnored = -1 12 13 } nagiosReturn; 13 14 14 typedef enum { 15 15 istrue = 1, 16 16 isfalse = 0 17 17 } boolReturn; 18 19 18 typedef enum { 20 19 isSuccess = 1, … … 22 21 isInvalidBufferLen = -2 23 22 } errorReturn; 24 25 26 27 // Various Nagios codes 28 /* 23 #else 29 24 const int returnCRIT = 2; 30 25 const int returnOK = 0; 31 26 const int returnWARN = 1; 32 27 const int returnUNKNOWN = 4; 33 */ 34 // Various NSCP extensions 28 const int returnInvalidBufferLen = -2; 29 const int returnIgnored = -1; 30 const int istrue = 1; 31 const int isfalse = 0; 32 const int isSuccess = 1; 33 const int hasFailed = 0; 34 const int isInvalidBufferLen = -2; 35 typedef int nagiosReturn; 36 typedef int boolReturn; 37 typedef int errorReturn; 38 #endif 35 39 36 // const int returnInvalidBufferLen = -2; // The return buffer was to small (might wanna call again with a larger one)37 38 39 // typedef int returnCodes;40 41 // Various function Return codes42 // const int isSuccess = 1; // Everything went fine43 // const int hasFailed = 0; // EVerything went to hell :)44 // const int isTrue = 1; // Should be interpreted as "true"45 // const int isFalse = 0; // Should be interpreted as "false"46 // const int isError = -1; // Should be interpreted as "ERROR"47 // const int handled = 2; // The command was handled by this module48 40 49 41 // Various message Types -
include/NSCHelper.cpp
r1eef1ee r81e29d8 15 15 * @return NSCAPI::success unless the buffer is to short then it will be NSCAPI::invalidBufferLen 16 16 */ 17 /* 17 #ifdef DEBUG 18 NSCAPI::nagiosReturn NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str, NSCAPI::nagiosReturn defaultReturnCode /* = NSCAPI::success */) { 19 if (str.length() >= bufLen) 20 return NSCAPI::returnInvalidBufferLen; 21 strncpy(buffer, str.c_str(), bufLen); 22 return defaultReturnCode; 23 } 24 NSCAPI::errorReturn NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str, NSCAPI::errorReturn defaultReturnCode /* = NSCAPI::success */) { 25 if (str.length() >= bufLen) 26 return NSCAPI::isInvalidBufferLen; 27 strncpy(buffer, str.c_str(), bufLen); 28 return defaultReturnCode; 29 } 30 #else 18 31 int NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str, int defaultReturnCode ) { 19 32 // @todo deprecate this … … 23 36 return defaultReturnCode; 24 37 } 25 */ 26 NSCAPI::nagiosReturn NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str, NSCAPI::nagiosReturn defaultReturnCode /* = NSCAPI::success */) { 27 if (str.length() >= bufLen) 28 return NSCAPI::returnInvalidBufferLen; 29 strncpy(buffer, str.c_str(), bufLen); 30 return defaultReturnCode; 31 } 32 NSCAPI::errorReturn NSCHelper::wrapReturnString(char *buffer, unsigned int bufLen, std::string str, NSCAPI::errorReturn defaultReturnCode /* = NSCAPI::success */) { 33 if (str.length() >= bufLen) 34 return NSCAPI::isInvalidBufferLen; 35 strncpy(buffer, str.c_str(), bufLen); 36 return defaultReturnCode; 37 } 38 #endif 38 39 /** 39 40 * Make a list out of a array of char arrays (arguments type) … … 119 120 for (unsigned int i=0;i<argLen;i++) { 120 121 char *q = strchr(p, (i<argLen-1)?splitChar:0); 121 unsigned int len = q-p;122 unsigned int len = static_cast<int>(q-p); 122 123 arrayBuffer[i] = new char[len+1]; 123 124 strncpy(arrayBuffer[i], p, len); … … 212 213 * @throws NSCMHExcpetion When core pointer set is unavailable or an unknown inject error occurs. 213 214 */ 214 NSCAPI::nagiosReturn NSCModuleHelper::InjectCommandRAW(const char* command, const unsigned int argLen, char **argument, char *return Buffer, unsigned int returnBufferLen)215 NSCAPI::nagiosReturn NSCModuleHelper::InjectCommandRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen) 215 216 { 216 217 if (!fNSAPIInject) 217 218 throw NSCMHExcpetion("NSCore has not been initiated..."); 218 return fNSAPIInject(command, argLen, argument, return Buffer, returnBufferLen);219 return fNSAPIInject(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 219 220 } 220 221 NSCAPI::nagiosReturn NSCModuleHelper::InjectCommand(const char* command, const unsigned int argLen, char **argument, std::string & message, std::string & perf) … … 222 223 if (!fNSAPIInject) 223 224 throw NSCMHExcpetion("NSCore has not been initiated..."); 224 char *buffer = new char[BUFF_LEN+1]; 225 buffer[0] = 0; 225 char *msgBuffer = new char[BUFF_LEN+1]; 226 char *perfBuffer = new char[BUFF_LEN+1]; 227 msgBuffer[0] = 0; 228 perfBuffer[0] = 0; 226 229 // @todo message here ! 227 NSCAPI::nagiosReturn retC = InjectCommandRAW(command, argLen, argument, buffer, BUFF_LEN);230 NSCAPI::nagiosReturn retC = InjectCommandRAW(command, argLen, argument, msgBuffer, BUFF_LEN, perfBuffer, BUFF_LEN); 228 231 switch (retC) { 229 232 case NSCAPI::returnIgnored: … … 237 240 case NSCAPI::returnWARN: 238 241 case NSCAPI::returnUNKNOWN: 239 message = buffer;240 // @todo perf data242 message = msgBuffer; 243 perf = perfBuffer; 241 244 break; 242 245 default: 243 246 throw NSCMHExcpetion("Unknown inject error."); 244 247 } 245 delete [] buffer; 248 delete [] msgBuffer; 249 delete [] perfBuffer; 246 250 return retC; 247 251 } -
include/NSCHelper.h
r1eef1ee r81e29d8 9 9 namespace NSCHelper 10 10 { 11 // int wrapReturnString(char *buffer, unsigned int bufLen, std::string str, int defaultReturnCode); 11 #ifdef DEBUG 12 12 NSCAPI::nagiosReturn wrapReturnString(char *buffer, unsigned int bufLen, std::string str, NSCAPI::nagiosReturn defaultReturnCode); 13 13 NSCAPI::errorReturn wrapReturnString(char *buffer, unsigned int bufLen, std::string str, NSCAPI::errorReturn defaultReturnCode); 14 #else 15 int wrapReturnString(char *buffer, unsigned int bufLen, std::string str, int defaultReturnCode); 16 #endif 14 17 15 18 std::list<std::string> arrayBuffer2list(const unsigned int argLen, char **argument); … … 87 90 typedef void (*lpNSAPIMessage)(int, const char*, const int, const char*); 88 91 typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); 89 typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const char*, const unsigned int, char **, char *, unsigned int );92 typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const char*, const unsigned int, char **, char *, unsigned int, char *, unsigned int); 90 93 typedef LPVOID (*lpNSAPILoader)(char*); 91 94 … … 96 99 int getSettingsInt(std::string section, std::string key, int defaultValue); 97 100 void Message(int msgType, std::string file, int line, std::string message); 98 NSCAPI::nagiosReturn InjectCommandRAW(const char* command, const unsigned int argLen, char **argument, char *return Buffer, unsigned int returnBufferLen);101 NSCAPI::nagiosReturn InjectCommandRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen); 99 102 NSCAPI::nagiosReturn InjectCommand(const char* command, const unsigned int argLen, char **argument, std::string & message, std::string & perf); 100 103 NSCAPI::nagiosReturn InjectSplitAndCommand(const char* command, char* buffer, char splitChar, std::string & message, std::string & perf); -
modules/NSClientListener/NSClientSocket.cpp
r1eef1ee r81e29d8 85 85 std::string message, perf; 86 86 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first.c_str(), cmd.second, '&', message, perf); 87 // @todo fix some way to interpret return code 88 return message; 87 return NSCHelper::translateReturn(ret) + "&" + message + "|" + perf; 89 88 } 90 89 … … 98 97 std::string response = parseRequest(buff); 99 98 NSC_DEBUG_MSG("Outgoing data: " + response); 100 send(client, response.c_str(), response.length(), 0);99 send(client, response.c_str(), static_cast<int>(response.length()), 0); 101 100 } else { 102 101 std::string str = "ERROR: Unknown socket error"; 103 send(client,str.c_str(),st r.length(),0);102 send(client,str.c_str(),static_cast<int>(str.length()),0); 104 103 } 105 104 delete [] buff;
Note: See TracChangeset
for help on using the changeset viewer.








