Changeset f705d34 in nscp
- Timestamp:
- 03/26/05 23:29:52 (8 years ago)
- Children:
- ebcb766
- Parents:
- 091d894
- Location:
- trunk
- Files:
-
- 26 edited
-
NSClient++.cpp (modified) (3 diffs)
-
NSClient++.h (modified) (1 diff)
-
NSClient++.vcproj (modified) (2 diffs)
-
changelog (modified) (2 diffs)
-
include/NSCHelper.cpp (modified) (4 diffs)
-
include/NSCHelper.h (modified) (5 diffs)
-
include/Socket.cpp (modified) (5 diffs)
-
include/Socket.h (modified) (1 diff)
-
include/arrayBuffer.cpp (modified) (3 diffs)
-
include/arrayBuffer.h (modified) (1 diff)
-
include/strEx.h (modified) (2 diffs)
-
modules/CheckDisk/CheckDisk.cpp (modified) (1 diff)
-
modules/CheckDisk/CheckDisk.vcproj (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (2 diffs)
-
modules/CheckEventLog/CheckEventLog.vcproj (modified) (1 diff)
-
modules/FileLogger/FileLogger.vcproj (modified) (1 diff)
-
modules/NRPEListener/NRPEListener.cpp (modified) (2 diffs)
-
modules/NRPEListener/NRPEListener.h (modified) (2 diffs)
-
modules/NRPEListener/NRPEListener.vcproj (modified) (1 diff)
-
modules/NRPEListener/NRPESocket.cpp (modified) (4 diffs)
-
modules/NRPEListener/NRPESocket.h (modified) (3 diffs)
-
modules/NSClientListener/NSClientListener.cpp (modified) (1 diff)
-
modules/NSClientListener/NSClientListener.h (modified) (1 diff)
-
modules/NSClientListener/NSClientSocket.cpp (modified) (2 diffs)
-
modules/NSClientListener/NSClientSocket.h (modified) (3 diffs)
-
modules/SysTray/SysTray.vcproj (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/NSClient++.cpp
r091d894 rf705d34 70 70 #ifdef _DEBUG 71 71 strEx::run_test_getToken(); 72 strEx::run_test_replace(); 72 73 charEx::run_test_getToken(); 73 74 arrayBuffer::run_testArrayBuffer(); 74 75 #endif 76 75 77 g_bConsoleLog = true; 76 78 mainClient.InitiateService(); … … 406 408 return mainClient.injectRAW(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 407 409 } 410 NSCAPI::errorReturn NSAPIGetSettingsSection(const char* section, char*** aBuffer, unsigned int * bufLen) { 411 unsigned int len = 0; 412 *aBuffer = arrayBuffer::list2arrayBuffer(Settings::getInstance()->getSection(section), len); 413 *bufLen = len; 414 return NSCAPI::isSuccess; 415 } 416 408 417 409 418 LPVOID NSAPILoader(char*buffer) { … … 412 421 if (stricmp(buffer, "NSAPIGetApplicationVersionStr") == 0) 413 422 return &NSAPIGetApplicationVersionStr; 423 if (stricmp(buffer, "NSAPIGetSettingsSection") == 0) 424 return &NSAPIGetSettingsSection; 414 425 if (stricmp(buffer, "NSAPIGetSettingsString") == 0) 415 426 return &NSAPIGetSettingsString; -
trunk/NSClient++.h
rc515660 rf705d34 91 91 void NSAPIStopServer(void); 92 92 NSCAPI::nagiosReturn NSAPIInject(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen); 93 93 NSCAPI::errorReturn NSAPIGetSettingsSection(const char*, char***, unsigned int *); 94 94 ////////////////////////////////////////////////////////////////////////// 95 95 // Log macros to simplify logging -
trunk/NSClient++.vcproj
r4f2e807 rf705d34 151 151 Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"> 152 152 <File 153 RelativePath=".\include\arrayBuffer.cpp"> 154 </File> 155 <File 153 156 RelativePath=".\include\NSCHelper.cpp"> 154 157 </File> … … 190 193 Filter="h;hpp;hxx;hm;inl"> 191 194 <File 195 RelativePath=".\include\arrayBuffer.h"> 196 </File> 197 <File 192 198 RelativePath=".\include\charEx.h"> 193 199 </File> -
trunk/changelog
r091d894 rf705d34 1 2005-03-26 MickeM 2 + NRPE Support (very basic, no encryption, and nothing fancy) 3 * Socket classes rewritten 4 + Added NSCModuleHelper::getSettingsSection to the API 5 1 6 2005-03-22 MickeM 2 7 * Fixed NSClientListener return codes for basic commands … … 8 13 * Fixed BUG in inject command (now things should "work" again, but far from stable) 9 14 + Added NRPE return code 10 * Fixed some return states to NSClientListener (not verified yet, but soon they wil lbe back in order :)15 * Fixed some return states to NSClientListener (not verified yet, but soon they will be back in order :) 11 16 12 17 2005-03-20 MickeM -
trunk/include/NSCHelper.cpp
r091d894 rf705d34 77 77 lpNSAPIGetApplicationName fNSAPIGetApplicationName = NULL; 78 78 lpNSAPIGetApplicationVersionStr fNSAPIGetApplicationVersionStr = NULL; 79 lpNSAPIGetSettingsSection fNSAPIGetSettingsSection = NULL; 79 80 lpNSAPIGetSettingsString fNSAPIGetSettingsString = NULL; 80 81 lpNSAPIGetSettingsInt fNSAPIGetSettingsInt = NULL; … … 212 213 return ret; 213 214 } 215 std::list<std::string> NSCModuleHelper::getSettingsSection(std::string section) { 216 if (!fNSAPIGetSettingsSection) 217 throw NSCMHExcpetion("NSCore has not been initiated..."); 218 char ** aBuffer = NULL; 219 unsigned int argLen = 0; 220 if (fNSAPIGetSettingsSection(section.c_str(), &aBuffer, &argLen) != NSCAPI::isSuccess) { 221 throw NSCMHExcpetion("Settings could not be retrieved."); 222 } 223 std::list<std::string> ret = arrayBuffer::arrayBuffer2list(argLen, aBuffer); 224 arrayBuffer::destroyArrayBuffer(aBuffer, argLen); 225 return ret; 226 } 214 227 /** 215 228 * Retrieve an int from the settings subsystem (INI-file) … … 227 240 return fNSAPIGetSettingsInt(section.c_str(), key.c_str(), defaultValue); 228 241 } 242 243 244 /*************************************************************************** 245 * max_state(STATE_x, STATE_y) 246 * compares STATE_x to STATE_y and returns result based on the following 247 * STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL 248 * 249 * Note that numerically the above does not hold 250 ****************************************************************************/ 251 NSCAPI::nagiosReturn NSCHelper::maxState(NSCAPI::nagiosReturn a, NSCAPI::nagiosReturn b) 252 { 253 if (a == NSCAPI::returnCRIT || b == NSCAPI::returnCRIT) 254 return NSCAPI::returnCRIT; 255 else if (a == NSCAPI::returnWARN || b == NSCAPI::returnWARN) 256 return NSCAPI::returnWARN; 257 else if (a == NSCAPI::returnOK || b == NSCAPI::returnOK) 258 return NSCAPI::returnOK; 259 else if (a == NSCAPI::returnUNKNOWN || b == NSCAPI::returnUNKNOWN) 260 return NSCAPI::returnUNKNOWN; 261 /* 262 else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT) 263 return STATE_DEPENDENT; 264 */ 265 // else 266 throw "undefined state"; 267 // return max (a, b); 268 } 269 270 229 271 /** 230 272 * Retrieve the application name (in human readable format) from the core. … … 321 363 NSCModuleHelper::fNSAPIGetSettingsInt = (NSCModuleHelper::lpNSAPIGetSettingsInt)f("NSAPIGetSettingsInt"); 322 364 NSCModuleHelper::fNSAPIGetSettingsString = (NSCModuleHelper::lpNSAPIGetSettingsString)f("NSAPIGetSettingsString"); 365 NSCModuleHelper::fNSAPIGetSettingsSection = (NSCModuleHelper::lpNSAPIGetSettingsSection)f("NSAPIGetSettingsSection"); 323 366 NSCModuleHelper::fNSAPIMessage = (NSCModuleHelper::lpNSAPIMessage)f("NSAPIMessage"); 324 367 NSCModuleHelper::fNSAPIStopServer = (NSCModuleHelper::lpNSAPIStopServer)f("NSAPIStopServer"); -
trunk/include/NSCHelper.h
r091d894 rf705d34 18 18 std::string translateMessageType(NSCAPI::messageTypes msgType); 19 19 std::string translateReturn(NSCAPI::nagiosReturn returnCode); 20 21 /* 22 / * ************************************************************************** 23 * max_state(STATE_x, STATE_y) 24 * compares STATE_x to STATE_y and returns result based on the following 25 * STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL 26 * 27 * Note that numerically the above does not hold 28 **************************************************************************** / 29 30 int 31 max_state (int a, int b) 32 { 33 if (a == STATE_CRITICAL || b == STATE_CRITICAL) 34 return STATE_CRITICAL; 35 else if (a == STATE_WARNING || b == STATE_WARNING) 36 return STATE_WARNING; 37 else if (a == STATE_OK || b == STATE_OK) 38 return STATE_OK; 39 else if (a == STATE_UNKNOWN || b == STATE_UNKNOWN) 40 return STATE_UNKNOWN; 41 else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT) 42 return STATE_DEPENDENT; 43 else 44 return max (a, b); 45 } 46 @bug Use this scheme instead!! 47 */ 48 49 20 NSCAPI::nagiosReturn maxState(NSCAPI::nagiosReturn a, NSCAPI::nagiosReturn b); 21 22 #ifdef DEBUG 23 inline NSCAPI::nagiosReturn int2nagios(int code) { 24 if (code == 0) 25 return NSCAPI::returnOK; 26 if (code == 1) 27 return NSCAPI::returnWARN; 28 if (code == 2) 29 return NSCAPI::returnCRIT; 30 if (code == 4) 31 return NSCAPI::returnUNKNOWN; 32 throw "@fixme bad code"; 33 } 34 inline int nagios2int(NSCAPI::nagiosReturn code) { 35 if (code == NSCAPI::returnOK) 36 return 0; 37 if (code == NSCAPI::returnWARN) 38 return 1; 39 if (code == NSCAPI::returnCRIT) 40 return 2; 41 if (code == NSCAPI::returnUNKNOWN) 42 return 4; 43 throw "@fixme bad code"; 44 } 45 #else 46 inline NSCAPI::nagiosReturn int2nagios(int code) { 47 return code; 48 } 49 inline int nagios2int(NSCAPI::nagiosReturn code) { 50 return code; 51 } 52 #endif 53 54 /* 50 55 inline void escalteReturnCode(NSCAPI::nagiosReturn ¤tReturnCode, NSCAPI::nagiosReturn newReturnCode) { 51 56 if (newReturnCode == NSCAPI::returnCRIT) … … 58 63 currentReturnCode = NSCAPI::returnUNKNOWN; 59 64 } 65 */ 60 66 inline void escalteReturnCodeToCRIT(NSCAPI::nagiosReturn ¤tReturnCode) { 61 67 currentReturnCode = NSCAPI::returnCRIT; … … 65 71 currentReturnCode = NSCAPI::returnWARN; 66 72 } 67 68 73 }; 69 74 … … 81 86 typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsString)(const char*,const char*,const char*,char*,unsigned int); 82 87 typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsInt)(const char*, const char*, int); 88 typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSection)(const char*, char***, unsigned int *); 83 89 typedef void (*lpNSAPIMessage)(int, const char*, const int, const char*); 84 90 typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); … … 89 95 std::string getApplicationName(void); 90 96 std::string getApplicationVersionString(void); 97 std::list<std::string> getSettingsSection(std::string section); 91 98 std::string getSettingsString(std::string section, std::string key, std::string defaultValue); 92 99 int getSettingsInt(std::string section, std::string key, int defaultValue); -
trunk/include/Socket.cpp
r6db9fb2 rf705d34 3 3 4 4 5 SimpleSocketListsner::~SimpleSocketListsner() {5 simpleSocket::Listener::~Listener() { 6 6 // @todo: Force cleanup here 7 7 } … … 14 14 * @todo This needs to be reworked, possibly completely redone ? 15 15 */ 16 DWORD SimpleSocketListsner::threadProc(LPVOID lpParameter)16 DWORD simpleSocket::Listener::ListenerThread::threadProc(LPVOID lpParameter) 17 17 { 18 unsigned long NoBlock = 1; 19 Listener *core = reinterpret_cast<Listener*>(lpParameter); 20 18 21 hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 19 22 if (!hStopEvent) { … … 22 25 } 23 26 24 WSADATA wsaData; 25 sockaddr_in local; 26 int wsaret=WSAStartup(0x101,&wsaData); 27 if(wsaret!=0) { 28 NSC_LOG_ERROR_STD("WSA Startup failed: " + strEx::itos(wsaret)); 29 return 0; 27 try { 28 core->socket(AF_INET,SOCK_STREAM,0); 29 core->setAddr(AF_INET, INADDR_ANY, htons(core->port_)); 30 core->bind(); 31 core->listen(10); 32 core->ioctlsocket(FIONBIO, &NoBlock); 33 34 NSC_DEBUG_MSG_STD("Currently listeneing to: " + strEx::itos(core->port_)); 35 36 while (!(WaitForSingleObject(hStopEvent, 100) == WAIT_OBJECT_0)) { 37 Socket client; 38 if (core->accept(client)) 39 core->onAccept(client); 40 } 41 } catch (SocketException e) { 42 NSC_LOG_ERROR_STD(e.getMessage()); 30 43 } 31 44 32 local.sin_family=AF_INET; 33 local.sin_addr.s_addr=INADDR_ANY; 34 local.sin_port=htons(port_); 35 server=socket(AF_INET,SOCK_STREAM,0); 36 if(server==INVALID_SOCKET) { 37 WSACleanup(); 38 NSC_LOG_ERROR_STD("Could not create listening socket: " + strEx::itos(GetLastError())); 39 return 0; 40 } 41 42 if(bind(server,(sockaddr*)&local,sizeof(local))!=0) { 43 closesocket(server); 44 WSACleanup(); 45 NSC_LOG_ERROR_STD("Could not bind socket: " + strEx::itos(GetLastError())); 46 return 0; 47 } 48 49 if(listen(server,10)!=0) { 50 closesocket(server); 51 WSACleanup(); 52 NSC_LOG_ERROR_STD("Could not open socket: " + strEx::itos(GetLastError())); 53 return 0; 54 } 55 56 SOCKET client; 57 sockaddr_in from; 58 int fromlen=sizeof(from); 59 while (!(WaitForSingleObject(hStopEvent, 100) == WAIT_OBJECT_0)) { 60 client=accept(server, (struct sockaddr*)&from,&fromlen); 61 if (client != INVALID_SOCKET) 62 onAccept(client); 63 } 64 closesocket(server); 65 WSACleanup(); 45 CloseHandle(hStopEvent); 66 46 NSC_DEBUG_MSG("Socket closed!"); 67 47 return 0; … … 73 53 * The thread manager is responsible for waiting for the actual termination of the thread. 74 54 */ 75 void SimpleSocketListsner::exitThread(void) {55 void simpleSocket::Listener::ListenerThread::exitThread(void) { 76 56 NSC_DEBUG_MSG("Requesting Socket shutdown!"); 77 57 if (!SetEvent(hStopEvent)) { … … 80 60 } 81 61 62 void simpleSocket::Socket::readAll(DataBuffer &buffer, unsigned int tmpBufferLength /* = 1024*/) { 63 // @todo this could be optimized a bit if we want to 64 // If only one buffer is needed we could "reuse" the buffer instead of copying it. 65 char *tmpBuffer = new char[tmpBufferLength+1]; 66 int n=recv(socket_,tmpBuffer,tmpBufferLength,0); 67 while ((n!=SOCKET_ERROR )||(n!=0)) { 68 if (n == tmpBufferLength) { 69 // We filled the buffer (There is more to get) 70 buffer.append(tmpBuffer, n); 71 n=recv(socket_,tmpBuffer,tmpBufferLength,0); 72 73 } else { 74 // Buffer not full, we got it "all" 75 buffer.append(tmpBuffer, n); 76 break; 77 } 78 } 79 delete [] tmpBuffer; 80 } 81 82 void simpleSocket::Listener::StartListen(int port) { 83 port_ = port; 84 threadManager_.createThread(this); 85 } 86 void simpleSocket::Listener::close() { 87 threadManager_.exitThread(); 88 Socket::close(); 89 } 82 90 83 91 84 92 85 93 86 -
trunk/include/Socket.h
r091d894 rf705d34 4 4 #include <Mutex.h> 5 5 #include <WinSock2.h> 6 /**7 * @ingroup NSClient++8 * Socket responder class.9 * This is a background thread that listens to the socket and executes incoming commands.10 *11 * @version 1.012 * first version13 *14 * @date 02-12-200515 *16 * @author mickem17 *18 * @par license19 * This code is absolutely free to use and modify. The code is provided "as is" with20 * no expressed or implied warranty. The author accepts no liability if it causes21 * any damage to your computer, causes your pet to fall ill, increases baldness22 * or makes your car start emitting strange noises when you start it up.23 * This code has no bugs, just undocumented features!24 *25 * @todo This is not very well written and should probably be reworked.26 *27 * @bug28 *29 */30 class SimpleSocketListsner {31 private:32 MutexHandler mutexHandler;33 SOCKET server;34 HANDLE hStopEvent;35 u_short port_;36 6 37 public: 38 SimpleSocketListsner(u_short port) : port_(port), hStopEvent(NULL) {}; 39 virtual ~SimpleSocketListsner(); 40 DWORD threadProc(LPVOID lpParameter); 41 void exitThread(void); 42 #define RECV_BUFFER_LEN 1024 43 typedef std::pair<char*,unsigned int> readAllDataBlock; 44 static readAllDataBlock readAll(SOCKET socket) { 45 // @bug Is this even working ? 46 // @todo Nedds *alot* more work... 47 unsigned int buffLen = RECV_BUFFER_LEN; 48 char *retBuf = NULL; 49 char *buff = new char[buffLen]; 50 int n=recv(socket,buff,RECV_BUFFER_LEN,0); 51 while ((n!=SOCKET_ERROR )||(n!=0)) { 52 if (n == RECV_BUFFER_LEN) { 53 char* newBuf = new char[buffLen+RECV_BUFFER_LEN]; 54 memcpy(newBuf, buff, buffLen); 55 n = recv(socket, buff, RECV_BUFFER_LEN, 0); 56 if ((n!=SOCKET_ERROR )&&(n!=0)) { 57 memcpy(&newBuf[buffLen], buff, n); 58 buffLen += n; 59 } 60 if (retBuf) 61 delete [] retBuf; 62 retBuf = newBuf; 63 } else { 64 buffLen = n; 65 break; 7 namespace simpleSocket { 8 class SocketException { 9 private: 10 std::string error_; 11 public: 12 SocketException(std::string error) : error_(error) {} 13 SocketException(std::string error, int errorCode) : error_(error) { 14 error_ += strEx::itos(errorCode); 15 } 16 std::string getMessage() const { 17 return error_; 18 } 19 20 }; 21 class DataBuffer { 22 private: 23 char *buffer_; 24 unsigned int length_; 25 public: 26 DataBuffer() : buffer_(NULL), length_(0){ 27 } 28 DataBuffer(const DataBuffer &other) { 29 buffer_ = new char[other.getLength()]; 30 memcpy(buffer_, other.getBuffer(), other.getLength()); 31 length_ = other.getLength(); 32 } 33 virtual ~DataBuffer() { 34 delete [] buffer_; 35 length_ = 0; 36 } 37 void append(const char* buffer, const unsigned int length) { 38 char *tBuf = new char[length_+length+1]; 39 memcpy(tBuf, buffer_, length_); 40 memcpy(&tBuf[length_], buffer, length); 41 delete [] buffer_; 42 buffer_ = tBuf; 43 length_ += length; 44 } 45 const char * getBuffer() const { 46 return buffer_; 47 } 48 unsigned int getLength() const { 49 return length_; 50 } 51 }; 52 53 class Socket { 54 private: 55 SOCKET socket_; 56 sockaddr_in from_; 57 58 public: 59 Socket() : socket_(NULL) { 60 } 61 Socket(SOCKET socket) : socket_(socket) { 62 } 63 Socket(Socket &other) { 64 socket_ = other.socket_; 65 other.socket_ = NULL; 66 } 67 virtual ~Socket() { 68 if (socket_) 69 closesocket(socket_); 70 socket_ = NULL; 71 } 72 SOCKET getSocket() const { 73 return socket_; 74 } 75 virtual void close() { 76 assert(socket_); 77 closesocket(socket_); 78 socket_ = NULL; 79 } 80 void readAll(DataBuffer &buffer, unsigned int tmpBufferLength = 1024); 81 82 void socket(int af, int type, int protocol ) { 83 socket_ = ::socket(af, type, protocol); 84 assert(socket_ != INVALID_SOCKET); 85 } 86 void bind() { 87 int fromlen=sizeof(from_); 88 if (::bind(socket_, (sockaddr*)&from_, fromlen) == SOCKET_ERROR) 89 throw SocketException("bind failed: ", ::WSAGetLastError()); 90 } 91 void listen(int backlog = 0) { 92 if (::listen(socket_, backlog) == SOCKET_ERROR) 93 throw SocketException("listen failed: ", ::WSAGetLastError()); 94 } 95 bool accept(Socket &client) { 96 int fromlen=sizeof(client.from_); 97 client.socket_ = ::accept(socket_, (sockaddr*)&client.from_, &fromlen); 98 if(client.socket_ == INVALID_SOCKET) { 99 int err = ::WSAGetLastError(); 100 if (err == WSAEWOULDBLOCK) 101 return false; 102 throw SocketException("accept failed: ", ::WSAGetLastError()); 66 103 } 104 return true; 67 105 } 68 if (retBuf) { 69 delete [] buff; 70 return readAllDataBlock(retBuf,buffLen); 106 void setAddr(short family, u_long addr, u_short port) { 107 from_.sin_family=family; 108 from_.sin_addr.s_addr=addr; 109 from_.sin_port=port; 71 110 } 72 return readAllDataBlock(buff,buffLen); 73 } 111 int send(const char * buf, unsigned int len, int flags ) { 112 return ::send(socket_, buf, len, flags); 113 } 114 void ioctlsocket(long cmd, u_long *argp) { 115 if (::ioctlsocket(socket_, cmd, argp) == SOCKET_ERROR) 116 throw SocketException("ioctlsocket failed: ", ::WSAGetLastError()); 117 } 118 119 static WSADATA WSAStartup(WORD wVersionRequested = 0x202) { 120 WSADATA wsaData; 121 int wsaret=::WSAStartup(wVersionRequested,&wsaData); 122 if(wsaret != 0) 123 throw SocketException("WSAStartup failed: " + strEx::itos(wsaret)); 124 return wsaData; 125 } 126 static void WSACleanup() { 127 if (::WSACleanup() != 0) 128 throw SocketException("WSACleanup failed: ", ::WSAGetLastError()); 129 } 74 130 75 131 76 private: 77 virtual void onAccept(SOCKET client) {} 78 }; 132 133 }; 79 134 80 135 136 /** 137 * @ingroup NSClient++ 138 * Socket responder class. 139 * This is a background thread that listens to the socket and executes incoming commands. 140 * 141 * @version 1.0 142 * first version 143 * 144 * @date 02-12-2005 145 * 146 * @author mickem 147 * 148 * @par license 149 * This code is absolutely free to use and modify. The code is provided "as is" with 150 * no expressed or implied warranty. The author accepts no liability if it causes 151 * any damage to your computer, causes your pet to fall ill, increases baldness 152 * or makes your car start emitting strange noises when you start it up. 153 * This code has no bugs, just undocumented features! 154 * 155 * @todo This is not very well written and should probably be reworked. 156 * 157 * @bug 158 * 159 */ 160 class Listener : public Socket { 161 public: 162 class ListenerThread { 163 private: 164 HANDLE hStopEvent; 165 public: 166 ListenerThread() : hStopEvent(NULL) { 167 } 168 DWORD threadProc(LPVOID lpParameter); 169 void exitThread(void); 170 }; 171 172 private: 173 MutexHandler mutexHandler; 174 u_short port_; 175 typedef Thread<ListenerThread> listenThreadManager; 176 listenThreadManager threadManager_; 177 178 public: 179 Listener() {}; 180 virtual ~Listener(); 181 182 void StartListen(int port); 183 virtual void close(); 184 185 private: 186 virtual void onAccept(Socket client) = 0; 187 188 }; 189 } 190 -
trunk/include/arrayBuffer.cpp
r091d894 rf705d34 9 9 * @return Argument wrapped as a list 10 10 */ 11 std::list<std::string>arrayBuffer::arrayBuffer2list(const unsigned int argLen, char *argument[]) {12 std::list<std::string>ret;11 arrayBuffer::arrayList arrayBuffer::arrayBuffer2list(const unsigned int argLen, char *argument[]) { 12 arrayList ret; 13 13 int i=0; 14 14 for (unsigned int i=0;i<argLen;i++) { … … 27 27 * @return A pointer that is managed by the caller. 28 28 */ 29 char ** arrayBuffer::list2arrayBuffer(const std::list<std::string>lst, unsigned int &argLen) {29 char ** arrayBuffer::list2arrayBuffer(const arrayList lst, unsigned int &argLen) { 30 30 argLen = static_cast<unsigned int>(lst.size()); 31 31 char **arrayBuffer = new char*[argLen]; 32 std::list<std::string>::const_iterator it = lst.begin();32 arrayList::const_iterator it = lst.begin(); 33 33 for (int i=0;it!=lst.end();++it,i++) { 34 34 std::string::size_type alen = (*it).size(); … … 121 121 strncpy(arrayBuffer[i], inBuf.substr(l,p).c_str(), len); 122 122 arrayBuffer[i][len] = 0; 123 l = ++p; 123 124 p = inBuf.find(splitChar, p); 124 125 } -
trunk/include/arrayBuffer.h
r091d894 rf705d34 4 4 namespace arrayBuffer { 5 5 6 typedef std::list<std::string> arrayList; 6 7 7 std::list<std::string>arrayBuffer2list(const unsigned int argLen, char **argument);8 char ** list2arrayBuffer(const std::list<std::string>lst, unsigned int &argLen);8 arrayList arrayBuffer2list(const unsigned int argLen, char **argument); 9 char ** list2arrayBuffer(const arrayList lst, unsigned int &argLen); 9 10 char ** split2arrayBuffer(const char* buffer, char splitChar, unsigned int &argLen); 10 11 char ** split2arrayBuffer(const std::string buffer, char splitChar, unsigned int &argLen); -
trunk/include/strEx.h
r091d894 rf705d34 7 7 namespace strEx { 8 8 9 inline void replace(std::string &string, std::string replace, std::string with) { 10 std::string::size_type pos = string.find(replace); 11 std::string::size_type len = replace.length(); 12 while (pos != std::string::npos) { 13 string = string.substr(0,pos)+with+string.substr(pos+len); 14 pos = string.find(replace, pos+1); 15 } 16 } 17 inline std::string itos(unsigned int i) { 18 std::stringstream ss; 19 ss << i; 20 return ss.str(); 21 } 9 22 inline std::string itos(int i) { 10 23 std::stringstream ss; … … 82 95 test_getToken("foo&bar&test", '&', "foo", "bar&test"); 83 96 } 97 98 inline void test_replace(std::string source, std::string replace, std::string with, std::string out) { 99 std::cout << "strEx::test_replace(" << source << ", " << replace << ", " << with << ") : "; 100 std::string s = source; 101 strEx::replace(s, replace, with); 102 if (s == out) 103 std::cout << "Succeeded" << std::endl; 104 else 105 std::cout << "Failed [" << s << "=" << out << "]" << std::endl; 106 } 107 inline void run_test_replace() { 108 test_replace("", "", "", ""); 109 test_replace("foo", "", "", "foo"); 110 test_replace("foobar", "foo", "", "bar"); 111 test_replace("foobar", "foo", "bar", "barbar"); 112 } 113 84 114 #endif 85 115 } -
trunk/modules/CheckDisk/CheckDisk.cpp
rc515660 rf705d34 109 109 NSC_DEBUG_MSG("CheckFileSize"); 110 110 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 111 std::list<std::string> args = NSCHelper::arrayBuffer2list(argLen, char_args);111 std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args); 112 112 if (args.empty()) { 113 113 message = "Missing argument(s)."; -
trunk/modules/CheckDisk/CheckDisk.vcproj
rf7f536b rf705d34 219 219 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" 220 220 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> 221 <File 222 RelativePath="..\..\include\arrayBuffer.cpp"> 223 </File> 221 224 <File 222 225 RelativePath=".\CheckDisk.cpp"> -
trunk/modules/CheckEventLog/CheckEventLog.cpp
rc515660 rf705d34 300 300 return NSCAPI::returnIgnored; 301 301 NSCAPI::nagiosReturn rCode = NSCAPI::returnOK; 302 std::list<std::string> args = NSCHelper::arrayBuffer2list(argLen, char_args);302 std::list<std::string> args = arrayBuffer::arrayBuffer2list(argLen, char_args); 303 303 if (args.size() < 2) { 304 304 message = "Missing argument"; 305 305 return NSCAPI::returnCRIT; 306 } 307 308 std::list<std::string>::iterator it = args.begin(); 309 for (;it != args.end();it++) { 310 NSC_DEBUG_MSG_STD("Arguments: " + (*it)); 306 311 } 307 312 std::string ret; … … 400 405 401 406 CloseEventLog(hLog); 402 if (critical) 407 if (critical) { 403 408 ret = "CRITICAL: " + ret; 404 else if (!ret.empty()) 409 rCode = NSCAPI::returnCRIT; 410 } 411 else if (!ret.empty()) { 405 412 ret = "WARNING: " + ret; 406 else 413 rCode = NSCAPI::returnWARN; 414 } else 407 415 ret = "OK: No errors/warnings in event log."; 408 416 if (query.truncate != 0) -
trunk/modules/CheckEventLog/CheckEventLog.vcproj
r4f2e807 rf705d34 122 122 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> 123 123 <File 124 RelativePath="..\..\include\arrayBuffer.cpp"> 125 </File> 126 <File 124 127 RelativePath=".\CheckEventLog.cpp"> 125 128 </File> -
trunk/modules/FileLogger/FileLogger.vcproj
r4f2e807 rf705d34 120 120 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> 121 121 <File 122 RelativePath="..\..\include\arrayBuffer.cpp"> 123 </File> 124 <File 122 125 RelativePath=".\FileLogger.cpp"> 123 126 </File> -
trunk/modules/NRPEListener/NRPEListener.cpp
rc515660 rf705d34 20 20 } 21 21 22 #define DEFAULT_NRPE_PORT 5666 23 22 24 23 25 bool NRPEListener::loadModule() { 24 socketThreadManager.createThread(NULL); 26 timeout = NSCModuleHelper::getSettingsInt("NRPE", "commandTimeout", 60); 27 std::list<std::string> commands = NSCModuleHelper::getSettingsSection("NRPE Handlers"); 28 std::list<std::string>::iterator it; 29 for (it = commands.begin(); it != commands.end(); it++) { 30 strEx::token t = strEx::getToken(*it, '='); 31 if (t.first.substr(0,7) == "command") { 32 strEx::token t2 = strEx::getToken(t.first, '['); 33 t2 = strEx::getToken(t2.second, ']'); 34 t.first = t2.first; 35 } 36 if (t.first.empty() || t.second.empty()) { 37 NSC_LOG_ERROR_STD("Invalid command definition: " + (*it)); 38 } else 39 addCommand(t.first, t.second); 40 } 41 42 simpleSocket::Socket::WSAStartup(); 43 socket.StartListen(NSCModuleHelper::getSettingsInt("NRPE", "port", DEFAULT_NRPE_PORT)); 25 44 return true; 26 45 } 27 46 bool NRPEListener::unloadModule() { 28 socketThreadManager.exitThread(); 47 socket.close(); 48 simpleSocket::Socket::WSACleanup(); 29 49 return true; 30 50 } 31 51 32 52 std::string NRPEListener::getModuleName() { 33 return " CheckDisk Various Disk related checks.";53 return "NRPE module."; 34 54 } 35 55 NSCModuleWrapper::module_version NRPEListener::getModuleVersion() { … … 47 67 48 68 NSCAPI::nagiosReturn NRPEListener::handleCommand(const std::string command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf) { 49 return NSCAPI::returnIgnored; 69 commandList::iterator it = commands.find(command); 70 if (it == commands.end()) 71 return NSCAPI::returnIgnored; 72 73 std::string str = (*it).second; 74 if (NSCModuleHelper::getSettingsInt("NRPE", "AllowArguments", 0) == 0) { 75 arrayBuffer::arrayList arr = arrayBuffer::arrayBuffer2list(argLen, char_args); 76 arrayBuffer::arrayList::const_iterator cit = arr.begin(); 77 int i=0; 78 79 for (;cit!=arr.end();it++,i++) { 80 strEx::replace(str, "ARG" + strEx::itos(i), (*cit)); 81 } 82 } 83 84 if (NSCModuleHelper::getSettingsInt("NRPE", "AllowNastyMetaChars", 0) == 0) { 85 if (str.find_first_of(NASTY_METACHARS) != std::string::npos) { 86 NSC_LOG_ERROR("Request command contained illegal metachars!"); 87 return NSCAPI::returnIgnored; 88 } 89 } 90 91 return executeNRPECommand(str, message, perf); 92 } 93 #define MAX_INPUT_BUFFER 1024 94 95 int NRPEListener::executeNRPECommand(std::string command, std::string &msg, std::string &perf) 96 { 97 NSCAPI::nagiosReturn result; 98 PROCESS_INFORMATION pi; 99 STARTUPINFO si; 100 HANDLE hChildOutR, hChildOutW, hChildInR, hChildInW; 101 SECURITY_ATTRIBUTES sec; 102 DWORD dwstate, dwexitcode; 103 int retval; 104 105 106 // Set up members of SECURITY_ATTRIBUTES structure. 107 108 sec.nLength = sizeof(SECURITY_ATTRIBUTES); 109 sec.bInheritHandle = TRUE; 110 sec.lpSecurityDescriptor = NULL; 111 112 // Create Pipes 113 CreatePipe(&hChildInR, &hChildInW, &sec, 0); 114 CreatePipe(&hChildOutR, &hChildOutW, &sec, 0); 115 116 // Set up members of STARTUPINFO structure. 117 118 ZeroMemory(&si, sizeof(STARTUPINFO)); 119 si.cb = sizeof(STARTUPINFO); 120 si.dwFlags = STARTF_USESTDHANDLES; 121 si.hStdInput = hChildInR; 122 si.hStdOutput = hChildOutW; 123 si.hStdError = hChildOutW; 124 125 126 // CreateProcess doesn't work with a const command 127 char *cmd = new char[command.length()+1]; 128 strncpy(cmd, command.c_str(), command.length()); 129 cmd[command.length()] = 0; 130 131 // Create the child process. 132 BOOL processOK = CreateProcess(NULL, cmd, // command line 133 NULL, // process security attributes 134 NULL, // primary thread security attributes 135 TRUE, // handles are inherited 136 0, // creation flags 137 NULL, // use parent's environment 138 NULL, // use parent's current directory 139 &si, // STARTUPINFO pointer 140 &pi); // receives PROCESS_INFORMATION 141 delete [] cmd; 142 143 if (processOK) { 144 dwstate = WaitForSingleObject(pi.hProcess, 1000*timeout); 145 CloseHandle(hChildInR); 146 CloseHandle(hChildInW); 147 CloseHandle(hChildOutW); 148 149 if (dwstate == WAIT_TIMEOUT) { 150 TerminateProcess(pi.hProcess, 5); 151 msg = "The check didn't respond within the timeout period!"; 152 result = NSCAPI::returnUNKNOWN; 153 } else { 154 DWORD dwread; 155 char *buf = new char[MAX_INPUT_BUFFER+1]; 156 retval = ReadFile(hChildOutR, buf, MAX_INPUT_BUFFER, &dwread, NULL); 157 if (!retval || dwread == 0) { 158 msg = "No output available from command..."; 159 } else { 160 buf[dwread] = 0; 161 msg = buf; 162 strEx::token t = strEx::getToken(msg, '\n'); 163 t = strEx::getToken(t.first, '|'); 164 msg = t.first; 165 perf = t.second; 166 } 167 delete [] buf; 168 result = NSCHelper::int2nagios(GetExitCodeProcess(pi.hProcess, &dwexitcode)); 169 } 170 CloseHandle(pi.hThread); 171 CloseHandle(pi.hProcess); 172 CloseHandle(hChildOutR); 173 } 174 else { 175 msg = "NRPE_NT failed to create process, exiting..."; 176 result = NSCAPI::returnUNKNOWN; 177 CloseHandle(hChildInR); 178 CloseHandle(hChildInW); 179 CloseHandle(hChildOutW); 180 CloseHandle(pi.hThread); 181 CloseHandle(pi.hProcess); 182 CloseHandle(hChildOutR); 183 } 184 return result; 50 185 } 51 186 -
trunk/modules/NRPEListener/NRPEListener.h
rc515660 rf705d34 4 4 #include "NRPESocket.h" 5 5 #include <Socket.h> 6 #include <map> 6 7 7 8 class NRPEListener { 8 9 private: 9 NRPESocketThread socketThreadManager; 10 NRPESocket socket; 11 typedef std::map<std::string, std::string> commandList; 12 commandList commands; 13 unsigned int timeout; 10 14 11 15 public: … … 20 24 bool hasMessageHandler(); 21 25 NSCAPI::nagiosReturn handleCommand(const std::string command, const unsigned int argLen, char **char_args, std::string &message, std::string &perf); 26 27 private: 28 int executeNRPECommand(std::string command, std::string &msg, std::string &perf); 29 void addCommand(std::string key, std::string args) { 30 commands[key] = args; 31 } 22 32 }; 23 33 -
trunk/modules/NRPEListener/NRPEListener.vcproj
rc515660 rf705d34 122 122 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> 123 123 <File 124 RelativePath="..\..\include\arrayBuffer.cpp"> 125 </File> 126 <File 124 127 RelativePath=".\NRPEListener.cpp"> 125 128 </File> -
trunk/modules/NRPEListener/NRPESocket.cpp
r5d8cb39 rf705d34 6 6 * Default c-tor 7 7 */ 8 NRPESocket::NRPESocket() : SimpleSocketListsner(DEFAULT_NRPE_PORT){8 NRPESocket::NRPESocket() { 9 9 } 10 10 … … 12 12 } 13 13 14 15 14 16 typedef short int16_t; 15 17 typedef unsigned long u_int32_t; 16 18 17 typedef struct packet_struct{18 int16_t packet_version;19 int16_t packet_type;20 u_int32_t crc32_value;21 int16_t result_code;22 char buffer[1024];23 }packet;24 25 19 static unsigned long crc32_table[256]; 26 27 /* build the crc table - must be called before calculating the crc value */ 20 static bool hascrc32 = false; 28 21 void generate_crc32_table(void){ 29 22 unsigned long crc, poly; 30 23 int i, j; 31 32 24 poly=0xEDB88320L; 33 25 for(i=0;i<256;i++){ … … 41 33 crc32_table[i]=crc; 42 34 } 43 44 return; 35 hascrc32 = true; 45 36 } 46 47 /* calculates the CRC 32 value for a buffer */ 48 unsigned long calculate_crc32(char *buffer, int buffer_size){ 37 unsigned long calculate_crc32(const char *buffer, int buffer_size){ 38 if (!hascrc32) 39 generate_crc32_table(); 49 40 register unsigned long crc; 50 41 int this_char; … … 61 52 } 62 53 63 void NRPESocket::onAccept(SOCKET client) {64 NSC_DEBUG_MSG("Accepting connection from remote host");65 54 66 SimpleSocketListsner::readAllDataBlock block = SimpleSocketListsner::readAll(client); 67 packet *p = reinterpret_cast<packet*>(block.first); 68 // @todo Verify versions and stuff, and ofcource add SSL (but thats in the future :) 69 NSC_DEBUG_MSG_STD("Incoming data: " + p->buffer); 55 class NRPEPacket { 56 public: 57 static const short queryPacket = 1; 58 static const short responsePacket = 2; 59 static const short version2 = 2; 60 private: 61 typedef struct packet { 62 int16_t packet_version; 63 int16_t packet_type; 64 u_int32_t crc32_value; 65 int16_t result_code; 66 char buffer[1024]; 67 } packet; 68 std::string payload_; 69 short type_; 70 short version_; 71 NSCAPI::nagiosReturn result_; 72 unsigned int crc32_; 73 unsigned int calculatedCRC32_; 74 char *tmpBuffer; 75 public: 76 NRPEPacket(const char *buffer) : tmpBuffer(NULL) { 77 const packet *p = reinterpret_cast<const packet*>(buffer); 78 type_ = ntohs(p->packet_type); 79 assert( (type_ == queryPacket)||(type_ == responsePacket)); 80 version_ = ntohs(p->packet_version); 81 assert(version_ == version2); 82 crc32_ = ntohl(p->crc32_value); 83 // Verify CRC32 84 // @todo Fix this, currently we need a const buffer so we cannot change the crc to 0. 85 char * tb = new char[getBufferLength()]; 86 memcpy(tb, buffer, getBufferLength()); 87 packet *p2 = reinterpret_cast<packet*>(tb); 88 p2->crc32_value = 0; 89 calculatedCRC32_ = calculate_crc32(tb, getBufferLength()); 90 delete [] tb; 91 // Verify CRC32 end 92 result_ = NSCHelper::int2nagios(ntohs(p->result_code)); 93 payload_ = std::string(p->buffer); 94 } 95 NRPEPacket(short type, short version, NSCAPI::nagiosReturn result, std::string payLoad) 96 : tmpBuffer(NULL) 97 ,type_(type) 98 ,version_(version) 99 ,result_(result) 100 ,payload_(payLoad) 101 { 102 } 103 ~NRPEPacket() { 104 delete [] tmpBuffer; 105 } 106 unsigned short getVersion() const { return version_; } 107 unsigned short getType() const { return type_; } 108 unsigned short getResult() const { return result_; } 109 std::string getPayload() const { return payload_; } 110 const char* getBuffer() { 111 delete [] tmpBuffer; 112 tmpBuffer = new char[getBufferLength()]; 113 packet *p = reinterpret_cast<packet*>(tmpBuffer); 114 p->result_code = htons(NSCHelper::nagios2int(result_)); 115 p->packet_type = htons(type_); 116 p->packet_version = htons(version_); 117 p->crc32_value = 0; 118 strncpy(p->buffer, payload_.c_str(), 1023); 119 p->buffer[1024] = 0; 120 p->crc32_value = htonl(calculate_crc32(tmpBuffer, getBufferLength())); 121 return tmpBuffer; 122 } 123 bool verifyCRC() { 124 return calculatedCRC32_ == crc32_; 125 } 126 const unsigned int getBufferLength() const { 127 return sizeof(packet); 128 } 129 }; 70 130 71 charEx::token cmd = charEx::getToken(p->buffer, '!'); 131 void NRPESocket::onAccept(simpleSocket::Socket client) { 132 simpleSocket::DataBuffer block; 133 client.readAll(block); 134 NRPEPacket p(block.getBuffer()); 135 if (p.getType() != NRPEPacket::queryPacket) { 136 NSC_LOG_ERROR("Request is not a query."); 137 client.close(); 138 return; 139 } 140 if (p.getVersion() != NRPEPacket::version2) { 141 NSC_LOG_ERROR("Request had unsupported version."); 142 client.close(); 143 return; 144 } 145 if (!p.verifyCRC()) { 146 NSC_LOG_ERROR("Request had invalid checksum."); 147 client.close(); 148 return; 149 } 150 strEx::token cmd = strEx::getToken(p.getPayload(), '!'); 72 151 std::string msg, perf; 73 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first.c_str(), cmd.second, '!', msg, perf); 74 //QUERY_PACKET 75 packet p2; 76 strncpy(p2.buffer, (msg+"|"+perf).c_str(), 1023); 77 p2.buffer[1023] = 0; 78 p2.packet_type = htons(2); 79 p2.packet_version = htons(2); 80 p2.result_code = htons(static_cast<int>(ret)); 152 NSC_DEBUG_MSG_STD("Command: " + cmd.first); 153 NSC_DEBUG_MSG_STD("Arguments: " + cmd.second); 81 154 82 generate_crc32_table(); 83 p2.crc32_value = 0; 84 p2.crc32_value = htonl(calculate_crc32(reinterpret_cast<char*>(&p2),sizeof(p2))); 85 send(client, reinterpret_cast<char*>(&p2), sizeof(p2), 0); 155 if (NSCModuleHelper::getSettingsInt("NRPE", "AllowArguments", 0) == 0) { 156 if (!cmd.second.empty()) { 157 NSC_LOG_ERROR("Request contained arguments (not currently allowed)."); 158 client.close(); 159 return; 160 } 161 } 162 if (NSCModuleHelper::getSettingsInt("NRPE", "AllowNastyMetaChars", 0) == 0) { 163 if (cmd.first.find_first_of(NASTY_METACHARS) != std::string::npos) { 164 NSC_LOG_ERROR("Request command contained illegal metachars!"); 165 client.close(); 166 return; 167 } 168 if (cmd.second.find_first_of(NASTY_METACHARS) != std::string::npos) { 169 NSC_LOG_ERROR("Request arguments contained illegal metachars!"); 170 client.close(); 171 return; 172 } 173 } 86 174 87 delete [] block.first; 88 closesocket(client); 175 NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf); 176 if (perf.empty()) { 177 NRPEPacket p2(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg); 178 client.send(p2.getBuffer(), p2.getBufferLength(), 0); 179 } else { 180 NRPEPacket p2(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg + "|" + perf); 181 client.send(p2.getBuffer(), p2.getBufferLength(), 0); 182 } 183 client.close(); 89 184 } 90 185 -
trunk/modules/NRPEListener/NRPESocket.h
rc515660 rf705d34 5 5 #include <WinSock2.h> 6 6 #include <Socket.h> 7 #include <string.h> 7 8 /** 8 9 * @ingroup NSClient++ … … 30 31 */ 31 32 32 #define DEFAULT_NRPE_PORT 566633 33 34 #define NASTY_METACHARS "|`&><'\"\\[]{}" /* This may need to be modified for windows directory seperator */ 34 35 35 class NRPESocket : public SimpleSocketListsner {36 class NRPESocket : public simpleSocket::Listener { 36 37 private: 37 38 … … 41 42 42 43 private: 43 virtual void onAccept( SOCKETclient);44 virtual void onAccept(simpleSocket::Socket client); 44 45 }; 45 46 46 47 47 typedef Thread<NRPESocket> NRPESocketThread; // Thread manager48 48 49 49 -
trunk/modules/NSClientListener/NSClientListener.cpp
r4f2e807 rf705d34 20 20 } 21 21 22 #define DEFAULT_TCP_PORT 12489 22 23 23 24 bool NSClientListener::loadModule() { 24 socket ThreadManager.createThread(NULL);25 socket.StartListen(NSCModuleHelper::getSettingsInt("NSClient", "port", DEFAULT_TCP_PORT)); 25 26 return true; 26 27 } 27 28 bool NSClientListener::unloadModule() { 28 socket ThreadManager.exitThread();29 socket.close(); 29 30 return true; 30 31 } -
trunk/modules/NSClientListener/NSClientListener.h
r4f2e807 rf705d34 5 5 class NSClientListener { 6 6 private: 7 NSClientSocket Thread socketThreadManager;7 NSClientSocket socket; 8 8 9 9 public: -
trunk/modules/NSClientListener/NSClientSocket.cpp
r091d894 rf705d34 6 6 * Default c-tor 7 7 */ 8 NSClientSocket::NSClientSocket() : SimpleSocketListsner(DEFAULT_TCP_PORT){8 NSClientSocket::NSClientSocket() { 9 9 } 10 10 … … 48 48 } 49 49 50 void NSClientSocket::onAccept( SOCKETclient) {51 52 readAllDataBlock rdb = readAll(client);53 if ( rdb.second> 0) {54 NSC_DEBUG_MSG_STD("Incoming data length: " + strEx::itos( (int)rdb.second));55 std::string incoming( (char*)rdb.first, (unsigned int)rdb.second);50 void NSClientSocket::onAccept(simpleSocket::Socket client) { 51 simpleSocket::DataBuffer db; 52 client.readAll(db); 53 if (db.getLength() > 0) { 54 NSC_DEBUG_MSG_STD("Incoming data length: " + strEx::itos(db.getLength())); 55 std::string incoming(db.getBuffer(), db.getLength()); 56 56 NSC_DEBUG_MSG_STD("Incoming data: " + incoming); 57 57 std::string response = parseRequest(incoming); 58 58 NSC_DEBUG_MSG("Outgoing data: " + response); 59 send(client,response.c_str(), static_cast<int>(response.length()), 0);59 client.send(response.c_str(), static_cast<int>(response.length()), 0); 60 60 } 61 delete [] rdb.first; 62 closesocket(client); 61 client.close(); 63 62 } -
trunk/modules/NSClientListener/NSClientSocket.h
r091d894 rf705d34 31 31 * 32 32 */ 33 class NSClientSocket : public SimpleSocketListsner {33 class NSClientSocket : public simpleSocket::Listener { 34 34 private: 35 35 … … 39 39 40 40 private: 41 virtual void onAccept( SOCKETclient);41 virtual void onAccept(simpleSocket::Socket client); 42 42 std::string parseRequest(std::string buffer); 43 43 }; 44 44 45 #define DEFAULT_TCP_PORT 1248946 45 47 46 #define REQ_CLIENTVERSION 1 // Works fine! … … 57 56 58 57 59 typedef Thread<NSClientSocket> NSClientSocketThread; // Thread manager60 61 -
trunk/modules/SysTray/SysTray.vcproj
r4f2e807 rf705d34 117 117 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> 118 118 <File 119 RelativePath="..\..\include\arrayBuffer.cpp"> 120 </File> 121 <File 119 122 RelativePath="..\..\include\NSCHelper.cpp"> 120 123 </File>
Note: See TracChangeset
for help on using the changeset viewer.








