- Timestamp:
- 02/22/06 21:47:57 (7 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 1b7ae3d
- Parents:
- 89f1a84
- Location:
- include
- Files:
-
- 13 edited
-
EnumNtSrv.cpp (modified) (2 diffs)
-
NSCHelper.cpp (modified) (2 diffs)
-
NSCHelper.h (modified) (3 diffs)
-
PDHCounter.h (modified) (1 diff)
-
ServiceCmd.cpp (modified) (6 diffs)
-
ServiceCmd.h (modified) (2 diffs)
-
Settings.h (modified) (7 diffs)
-
Socket.h (modified) (2 diffs)
-
checkHelpers.hpp (modified) (13 diffs)
-
config.h (modified) (1 diff)
-
filter_framework.hpp (modified) (12 diffs)
-
strEx.h (modified) (2 diffs)
-
utils.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
include/EnumNtSrv.cpp
re26cfe0 r6817602 177 177 } 178 178 179 #define SC_BUF_LEN 1024 179 180 TNtServiceInfo TNtServiceInfo::GetService(std::string name) 180 181 { … … 187 188 SC_HANDLE sh = ::OpenService(scman,name.c_str(),SERVICE_QUERY_STATUS); 188 189 if (!sh) { 189 throw NTServiceException(name, "Could not open Service", GetLastError()); 190 ::CloseServiceHandle(scman); 190 DWORD bufLen = SC_BUF_LEN; 191 TCHAR *buf = new TCHAR[bufLen]; 192 if (!GetServiceKeyName(scman, name.c_str(), buf, &bufLen)) { 193 throw NTServiceException(name, "Could not open Service", GetLastError()); 194 ::CloseServiceHandle(scman); 195 } 196 if (bufLen >= SC_BUF_LEN) { 197 throw NTServiceException(name, "Could not open Service", GetLastError()); 198 ::CloseServiceHandle(scman); 199 } 200 buf[bufLen] = 0; 201 SC_HANDLE sh = ::OpenService(scman,buf,SERVICE_QUERY_STATUS); 202 if (!sh) { 203 throw NTServiceException(name, "Could not open Service", GetLastError()); 204 ::CloseServiceHandle(scman); 205 } 191 206 } 192 207 SERVICE_STATUS state; -
include/NSCHelper.cpp
re26cfe0 r6817602 381 381 throw NSCMHExcpetion("NSCore has not been initiated..."); 382 382 unsigned int len = 0; 383 fNSAPIEncrypt(algorithm, str.c_str(), str.size(), NULL, &len); 383 // @todo investigate potential problems with static_cast<unsigned int> 384 fNSAPIEncrypt(algorithm, str.c_str(), static_cast<unsigned int>(str.size()), NULL, &len); 384 385 len+=2; 385 386 char *buf = new char[len+1]; 386 NSCAPI::errorReturn ret = fNSAPIEncrypt(algorithm, str.c_str(), st r.size(), buf, &len);387 NSCAPI::errorReturn ret = fNSAPIEncrypt(algorithm, str.c_str(), static_cast<unsigned int>(str.size()), buf, &len); 387 388 if (ret == NSCAPI::isSuccess) { 388 389 std::string ret = buf; … … 396 397 throw NSCMHExcpetion("NSCore has not been initiated..."); 397 398 unsigned int len = 0; 398 fNSAPIDecrypt(algorithm, str.c_str(), str.size(), NULL, &len); 399 // @todo investigate potential problems with: static_cast<unsigned int>(str.size()) 400 fNSAPIDecrypt(algorithm, str.c_str(), static_cast<unsigned int>(str.size()), NULL, &len); 399 401 len+=2; 400 402 char *buf = new char[len+1]; 401 NSCAPI::errorReturn ret = fNSAPIDecrypt(algorithm, str.c_str(), st r.size(), buf, &len);403 NSCAPI::errorReturn ret = fNSAPIDecrypt(algorithm, str.c_str(), static_cast<unsigned int>(str.size()), buf, &len); 402 404 if (ret == NSCAPI::isSuccess) { 403 405 std::string ret = buf; -
include/NSCHelper.h
re26cfe0 r6817602 83 83 typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); 84 84 typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const char*, const unsigned int, char **, char *, unsigned int, char *, unsigned int); 85 typedef LPVOID(*lpNSAPILoader)(char*);85 typedef void* (*lpNSAPILoader)(char*); 86 86 typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); 87 87 typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const char*, unsigned int, char*, unsigned int *); … … 144 144 extern int NSGetConfigurationMeta(int IN_retBufLen, char *OUT_retBuf) 145 145 146 #define NSC_WRAPPERS_CLI() \ 147 extern int NSCommandLineExec(const char*,const unsigned int,char**) 146 148 147 149 … … 224 226 } 225 227 228 #define NSC_WRAPPERS_CLI_DEF(toObject) \ 229 extern int NSCommandLineExec(const char* command,const unsigned int argLen,char** args) { \ 230 return toObject.commandLineExec(command, argLen, args); \ 231 } \ 232 226 233 ////////////////////////////////////////////////////////////////////////// 227 234 #define MODULE_SETTINGS_START(class, name, description) \ -
include/PDHCounter.h
r75d5e70 r6817602 201 201 } 202 202 203 static DWORD lookupCounterByName(std::string count, std::string machine = "") {204 }205 206 203 PDHCounter* addCounter(std::string name, PDHCounterListener *listener) { 207 204 PDHCounter *counter = new PDHCounter(name, listener); -
include/ServiceCmd.cpp
r75d5e70 r6817602 16 16 #include "stdafx.h" 17 17 #include "ServiceCmd.h" 18 #include <strEx.h> 18 19 19 20 namespace serviceControll { … … 30 31 * 31 32 */ 32 void Install(LPCTSTR szName, LPCTSTR szDisplayName, LPCTSTR szDependencies ) {33 void Install(LPCTSTR szName, LPCTSTR szDisplayName, LPCTSTR szDependencies, DWORD dwServiceType) { 33 34 SC_HANDLE schService; 34 35 SC_HANDLE schSCManager; … … 46 47 TEXT(szDisplayName), // name to display 47 48 SERVICE_ALL_ACCESS, // desired access 48 SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS ,// service type49 dwServiceType, // service type 49 50 SERVICE_AUTO_START, // start type 50 51 SERVICE_ERROR_NORMAL, // error control type … … 57 58 58 59 if (!schService) { 59 CloseServiceHandle(schSCManager); 60 throw SCException("Unable to install service."); 61 } 62 CloseServiceHandle(schService); 63 CloseServiceHandle(schSCManager); 60 DWORD err = GetLastError(); 61 CloseServiceHandle(schSCManager); 62 if (err==ERROR_SERVICE_EXISTS) { 63 throw SCException("Service already installed!"); 64 } 65 throw SCException("Unable to install service.", err); 66 } 67 CloseServiceHandle(schService); 68 CloseServiceHandle(schSCManager); 69 } 70 71 void ModifyServiceType(LPCTSTR szName, DWORD dwServiceType) { 72 SC_HANDLE schService; 73 SC_HANDLE schSCManager; 74 TCHAR szPath[512]; 75 76 if ( GetModuleFileName( NULL, szPath, 512 ) == 0 ) 77 throw SCException("Could not get module"); 78 79 schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); 80 if (!schSCManager) 81 throw SCException("OpenSCManager failed."); 82 schService = OpenService(schSCManager, TEXT(szName), SERVICE_ALL_ACCESS); 83 if (!schService) { 84 DWORD err = GetLastError(); 85 CloseServiceHandle(schSCManager); 86 throw SCException("Unable to open service.", err); 87 } 88 BOOL result = ChangeServiceConfig(schService, dwServiceType, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE , NULL, NULL, NULL, 89 NULL, NULL, NULL, NULL); 90 CloseServiceHandle(schService); 91 CloseServiceHandle(schSCManager); 92 if (result != TRUE) 93 throw SCException("Could not query service information"); 94 } 95 96 DWORD GetServiceType(LPCTSTR szName) { 97 LPQUERY_SERVICE_CONFIG lpqscBuf = (LPQUERY_SERVICE_CONFIG) LocalAlloc(LPTR, 4096); 98 if (lpqscBuf == NULL) { 99 throw SCException("Could not allocate memory"); 100 } 101 SC_HANDLE schService; 102 SC_HANDLE schSCManager; 103 TCHAR szPath[512]; 104 105 if ( GetModuleFileName( NULL, szPath, 512 ) == 0 ) 106 throw SCException("Could not get module"); 107 108 schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); 109 if (!schSCManager) 110 throw SCException("OpenSCManager failed."); 111 schService = OpenService(schSCManager, TEXT(szName), SERVICE_ALL_ACCESS); 112 if (!schService) { 113 DWORD err = GetLastError(); 114 CloseServiceHandle(schSCManager); 115 throw SCException("Unable to open service.", err); 116 } 117 118 119 DWORD dwBytesNeeded = 0; 120 BOOL success = QueryServiceConfig(schService, lpqscBuf, 4096, &dwBytesNeeded); 121 CloseServiceHandle(schService); 122 CloseServiceHandle(schSCManager); 123 if (success != TRUE) 124 throw SCException("Could not query service information"); 125 DWORD ret = lpqscBuf->dwServiceType; 126 LocalFree(lpqscBuf); 127 return ret; 64 128 } 65 129 … … 188 252 } 189 253 254 255 typedef BOOL (WINAPI*PFChangeServiceConfig2)(SC_HANDLE hService,DWORD dwInfoLevel,LPVOID lpInfo); 256 190 257 void SetDescription(std::string name, std::string desc) { 258 PFChangeServiceConfig2 FChangeServiceConfig2; 259 HMODULE ADVAPI= ::LoadLibrary(_TEXT("Advapi32")); 260 if (!ADVAPI) { 261 throw SCException("Couldn't set extended service info (ignore this on NT4)."); 262 } 263 #ifdef UNICODE 264 FChangeServiceConfig2 = (PFChangeServiceConfig2)::GetProcAddress(ADVAPI, _TEXT("ChangeServiceConfig2W")); 265 #else 266 FChangeServiceConfig2 = (PFChangeServiceConfig2)::GetProcAddress(ADVAPI, _TEXT("ChangeServiceConfig2A")); 267 #endif 268 if (!FChangeServiceConfig2) { 269 FreeLibrary(ADVAPI); 270 throw SCException("Couldn't set extended service info (ignore this on NT4)."); 271 } 191 272 SERVICE_DESCRIPTION descr; 192 273 SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); … … 195 276 SC_HANDLE schService = OpenService(schSCManager, TEXT(name.c_str()), SERVICE_ALL_ACCESS); 196 277 if (!schService) { 197 CloseServiceHandle(schSCManager); 198 throw SCException("OpenService failed."); 199 } 200 201 LPSTR d = new char[desc.length()+1]; 278 FreeLibrary(ADVAPI); 279 CloseServiceHandle(schSCManager); 280 throw SCException("OpenService failed."); 281 } 282 283 LPSTR d = new char[desc.length()+2]; 202 284 strncpy(d, desc.c_str(), desc.length()); 203 285 descr.lpDescription = d; 204 BOOL bResult = ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &descr);286 BOOL bResult = FChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &descr); 205 287 delete [] d; 288 FreeLibrary(ADVAPI); 206 289 CloseServiceHandle(schService); 207 290 CloseServiceHandle(schSCManager); -
include/ServiceCmd.h
r75d5e70 r6817602 1 1 #pragma once 2 3 #include <sstream> 2 4 3 5 namespace serviceControll { … … 7 9 SCException(std::string error) : error_(error) { 8 10 } 11 SCException(std::string error, int code) : error_(error) { 12 std::stringstream ss; 13 ss << ": "; 14 ss << code; 15 error += ss.str(); 16 } 9 17 }; 10 void Install(LPCTSTR,LPCTSTR,LPCTSTR); 18 void Install(LPCTSTR,LPCTSTR,LPCTSTR,DWORD=SERVICE_WIN32_OWN_PROCESS); 19 void ModifyServiceType(LPCTSTR szName, DWORD dwServiceType); 11 20 void Uninstall(std::string); 12 21 void Start(std::string); 13 22 void Stop(std::string); 14 23 void SetDescription(std::string,std::string); 24 DWORD GetServiceType(LPCTSTR szName); 15 25 } -
include/Settings.h
r89f1a84 r6817602 2 2 3 3 #include <Singleton.h> 4 #include <string> 5 #include <map> 6 #include <windows.h> 4 7 #define BUFF_LEN 4096 5 8 … … 10 13 { 11 14 private: 15 typedef std::map<std::string,std::string> saveKeyList; 16 typedef std::map<std::string,saveKeyList> saveSectionList; 12 17 std::string file_; 18 saveSectionList data_; 19 bool bHasInternalData; 13 20 public: 14 21 typedef std::list<std::string> sectionList; 15 16 SettingsT(void) 22 SettingsT(void) : bHasInternalData(false) 17 23 { 18 24 } … … 29 35 file_ = file; 30 36 } 37 38 sectionList getSections() { 39 sectionList ret; 40 char* buffer = new char[BUFF_LEN+1]; 41 unsigned int count = ::GetPrivateProfileSectionNames(buffer, BUFF_LEN, file_.c_str()); 42 if (count == BUFF_LEN-2) 43 throw "Fuck..."; 44 unsigned int last = 0; 45 for (unsigned int i=0;i<count;i++) { 46 if (buffer[i] == '\0') { 47 std::string s = &buffer[last]; 48 ret.push_back(s); 49 last = i+1; 50 } 51 } 52 delete [] buffer; 53 if (bHasInternalData) { 54 for (saveSectionList::const_iterator it = data_.begin(); it != data_.end(); ++it) { 55 } 56 } 57 ret.sort(); 58 ret.unique(); 59 return ret; 60 } 61 31 62 /** 32 63 * Get all keys from a section as a list<string> … … 34 65 * @return A list with all keys from the section 35 66 */ 36 s td::list<std::string>getSection(std::string section) {37 s td::list<std::string>ret;67 sectionList getSection(std::string section) { 68 sectionList ret; 38 69 char* buffer = new char[BUFF_LEN+1]; 39 70 unsigned int count = GetPrivateProfileSection(section.c_str(), buffer, BUFF_LEN, file_.c_str()); … … 49 80 } 50 81 delete [] buffer; 82 if (bHasInternalData) { 83 saveSectionList::const_iterator it = data_.find(section); 84 if (it != data_.end()) { 85 for (saveKeyList::const_iterator kit = it->second.begin(); kit != it->second.end(); ++kit) { 86 ret.push_back(kit->first); 87 } 88 } 89 } 90 ret.sort(); 91 ret.unique(); 51 92 return ret; 52 93 } … … 59 100 */ 60 101 std::string getString(std::string section, std::string key, std::string defaultValue = "") const { 102 if (bHasInternalData) { 103 saveSectionList::const_iterator it = data_.find(section); 104 if (it != data_.end()) { 105 saveKeyList::const_iterator kit = it->second.find(key); 106 if (kit != it->second.end()) { 107 return kit->second; 108 } 109 } 110 } 61 111 char* buffer = new char[1024]; 62 112 GetPrivateProfileString(section.c_str(), key.c_str(), defaultValue.c_str(), buffer, 1023, file_.c_str()); … … 65 115 return ret; 66 116 } 117 118 void setString(std::string section, std::string key, std::string value) { 119 bHasInternalData = true; 120 (data_[section])[key] = value; 121 } 122 67 123 /** 68 124 * Get an integer from the settings file -
include/Socket.h
r1d9338a r6817602 100 100 unsigned long NoBlock = 1; 101 101 this->ioctlsocket(FIONBIO, &NoBlock); 102 } 103 static std::string getHostByName(std::string ip) { 104 hostent* remoteHost; 105 remoteHost = gethostbyname(ip.c_str()); 106 if (remoteHost == NULL) 107 throw SocketException("gethostbyname failed for " + ip + ": ", ::WSAGetLastError()); 108 // @todo investigate it this is "correct" and dont use before! 109 return inet_ntoa(*reinterpret_cast<in_addr*>(remoteHost->h_addr)); 110 } 111 static std::string getHostByAddr(std::string ip) { 112 hostent* remoteHost; 113 remoteHost = gethostbyaddr(ip.c_str(), static_cast<int>(ip.length()), AF_INET); 114 if (remoteHost == NULL) 115 throw SocketException("gethostbyaddr failed for " + ip + ": ", ::WSAGetLastError()); 116 return remoteHost->h_name; 102 117 } 103 118 virtual void readAll(DataBuffer &buffer, unsigned int tmpBufferLength = 1024); … … 397 412 return 0; 398 413 } 414 415 416 417 namespace socketHelpers { 418 class allowedHosts { 419 public: 420 typedef std::list<std::string> host_list; 421 private: 422 host_list allowedHosts_; 423 public: 424 void setAllowedHosts(host_list allowedHosts) { 425 if ((!allowedHosts.empty()) && (allowedHosts.front() == "") ) 426 allowedHosts.pop_front(); 427 allowedHosts_ = allowedHosts; 428 for (host_list::iterator it = allowedHosts_.begin();it!=allowedHosts_.end();++it) { 429 if (((*it).length() > 0) && (std::isalpha((*it)[0]))) { 430 std::string s = (*it); 431 try { 432 *it = simpleSocket::Socket::getHostByName(s); 433 } catch (simpleSocket::SocketException e) { 434 e; 435 } 436 } 437 } 438 } 439 bool inAllowedHosts(std::string s) { 440 if (allowedHosts_.empty()) 441 return true; 442 host_list::const_iterator cit; 443 for (cit = allowedHosts_.begin();cit!=allowedHosts_.end();++cit) { 444 if ( (*cit) == s) 445 return true; 446 } 447 return false; 448 } 449 }; 450 } -
include/checkHelpers.hpp
r75d5e70 r6817602 4 4 #include <strEx.h> 5 5 6 #define MAKE_PERFDATA(alias, value, unit, warn, crit) "'" + alias + "'=" + value + unit + ";" + warn + ";" + crit + "; " 6 7 7 8 namespace checkHolders { … … 133 134 return "Free: "; 134 135 } 136 static std::string key_prefix() { 137 return ""; 138 } 139 static std::string key_postfix() { 140 return ""; 141 } 142 135 143 }; 136 144 … … 154 162 return strEx::itos(value); 155 163 } 164 static std::string key_prefix() { 165 return ""; 166 } 167 static std::string key_postfix() { 168 return ""; 169 } 170 156 171 }; 157 172 … … 174 189 return strEx::itos(value) + "%"; 175 190 } 191 static std::string key_prefix() { 192 return ""; 193 } 194 static std::string key_postfix() { 195 return ""; 196 } 176 197 }; 177 198 class int64_handler { … … 209 230 static std::string print_percent(double value) { 210 231 return strEx::itos(value) + "%"; 232 } 233 static std::string key_prefix() { 234 return ""; 235 } 236 static std::string key_postfix() { 237 return ""; 211 238 } 212 239 }; … … 268 295 269 296 static std::string toStringLong(TType value) { 270 return THandler:: print(value);297 return THandler::key_prefix() + THandler::print(value) + THandler::key_postfix(); 271 298 } 272 299 static std::string toStringShort(TType value) { … … 286 313 } 287 314 static std::string gatherPerfData(std::string alias, TType &value, TType warn, TType crit) { 288 return alias + ";" 289 + THandler::print_unformated(value) + ";" 290 + THandler::print_unformated(warn) + ";" 291 + THandler::print_unformated(crit) + "; "; 315 return MAKE_PERFDATA(alias, THandler::print_unformated(value), "", THandler::print_unformated(warn), THandler::print_unformated(crit)); 292 316 } 293 317 … … 335 359 } 336 360 const InternalValue & operator=(std::string value) { 337 std::cout << "Setting value: " << value << std::endl;338 361 std::string::size_type p = value.find_first_of('%'); 339 362 if (p != std::string::npos) { … … 372 395 checkResultType check(TType value) const { 373 396 if (type_ == percentage_lower) { 374 std::cout << "Checking: percentage_lower " << value.getLowerPercentage() << " < " << value_ << std::endl;375 397 if (value.getLowerPercentage() == value_) 376 398 return same; … … 378 400 return above; 379 401 } else if (type_ == percentage_upper) { 380 std::cout << "Checking: percentage_upper " << value.getUpperPercentage() << " < " << value_ << std::endl;381 402 if (value.getUpperPercentage() == value_) 382 403 return same; … … 384 405 return above; 385 406 } else if (type_ == value_lower) { 386 std::cout << "Checking: value_lower " << value.total << " < " << value_ << std::endl;387 407 if (value.value == value_) 388 408 return same; … … 390 410 return above; 391 411 } else if (type_ == value_upper) { 392 std::cout << "Checking: value_upper " << (value.total-value.value) << " < " << value_ << std::endl;393 412 if ((value.total-value.value) == value_) 394 413 return same; … … 421 440 std::string gatherPerfData(std::string alias, TType &value, typename TType::TValueType warn, typename TType::TValueType crit) { 422 441 if (type_ == percentage_upper) { 423 return alias + ";" 424 + THandler::print_unformated(value.getUpperPercentage()) + "%;" 425 + THandler::print_unformated(warn) + ";" 426 + THandler::print_unformated(crit) + "; "; 442 return 443 MAKE_PERFDATA(alias, THandler::print_unformated(value.getUpperPercentage()), "%", 444 THandler::print_unformated(warn), THandler::print_unformated(crit)); 427 445 } else if (type_ == percentage_lower) { 428 return alias + ";" 429 + THandler::print_unformated(value.getLowerPercentage()) + "%;" 430 + THandler::print_unformated(warn) + ";" 431 + THandler::print_unformated(crit) + "; "; 446 return 447 MAKE_PERFDATA(alias, THandler::print_unformated(value.getLowerPercentage()), "%", 448 THandler::print_unformated(warn), THandler::print_unformated(crit)); 432 449 } else { 433 return alias + ";" 434 + THandler::print_unformated(value.value) + ";" 435 + THandler::print_unformated(warn) + ";" 436 + THandler::print_unformated(crit) + "; "; 450 return 451 MAKE_PERFDATA(alias, THandler::print_unformated(value.value), "", 452 THandler::print_unformated(warn), THandler::print_unformated(crit)); 437 453 } 438 454 } 439 455 private: 440 456 void setUpper(std::string s) { 441 std::cout << "Setting value:U " << s << std::endl;442 457 value_ = THandler::parse(s); 443 458 type_ = value_upper; 444 459 } 445 460 void setLower(std::string s) { 446 std::cout << "Setting value:L " << s << std::endl;447 461 value_ = THandler::parse(s); 448 462 type_ = value_lower; -
include/config.h
r75d5e70 r6817602 5 5 6 6 // Version 7 #define SZVERSION "0.2. 0 2005-05-21"7 #define SZVERSION "0.2.5f 2006-02-14" 8 8 9 9 // internal name of the service 10 #define SZSERVICENAME "NSClient ++"10 #define SZSERVICENAME "NSClientpp" 11 11 12 12 // Description of service -
include/filter_framework.hpp
r89f1a84 r6817602 1 1 #pragma once 2 3 #include <strEx.h> 2 4 3 5 namespace filters { … … 40 42 struct numeric_equals_filter { 41 43 static bool filter(TType filter, TType value) { 42 return value = filter;44 return value == filter; 43 45 } 44 46 }; … … 47 49 static bool filter(TType filter, TType value) { 48 50 return value != filter; 51 } 52 }; 53 template <typename TType> 54 struct always_true_filter { 55 static bool filter(TType filter, TType value) { 56 return true; 57 } 58 }; 59 template <typename TListType, typename TType> 60 struct numeric_inlist_filter { 61 static bool filter(const TListType &filter, const TType value) { 62 for (TListType::const_iterator it = filter.begin(); it != filter.end(); ++it) { 63 if ((*it) == value) 64 return true; 65 } 66 return false; 49 67 } 50 68 }; … … 57 75 static std::string parse(std::string str) { 58 76 return str; 77 } 78 }; 79 template<class TType, class TSubHandler> 80 struct numeric_list_handler { 81 static std::list<TType> parse(std::string str) { 82 std::list<TType> ret; 83 std::list<std::string> tmp = strEx::splitEx(str, ","); 84 for (std::list<std::string>::const_iterator it = tmp.begin(); it != tmp.end(); ++it) { 85 ret.push_back(TSubHandler::parse(*it)); 86 } 87 return ret; 59 88 } 60 89 }; … … 69 98 }; 70 99 struct eventtype_handler { 71 72 100 static unsigned int parse(std::string str) { 73 101 if (str == "error") … … 97 125 } 98 126 }; 99 } 127 struct eventseverity_handler { 128 static unsigned int parse(std::string str) { 129 if (str == "success") 130 return 0; 131 if (str == "informational") 132 return 1; 133 if (str == "warning") 134 return 2; 135 if (str == "error") 136 return 3; 137 return strEx::stoi(str); 138 } 139 static std::string toString(unsigned int dwType) { 140 if (dwType == 0) 141 return "success"; 142 if (dwType == 1) 143 return "informational"; 144 if (dwType == 2) 145 return "warning"; 146 if (dwType == 3) 147 return "error"; 148 return strEx::itos(dwType); 149 } 150 }; } 100 151 101 152 template <typename TFilterType, typename TValueType, class THandler, class TFilter> … … 104 155 bool hasFilter_; 105 156 filter_one() : hasFilter_(false) {} 157 filter_one(const filter_one &other) : hasFilter_(other.hasFilter_), filter(other.filter) { 158 } 106 159 107 160 inline bool hasFilter() const { 108 161 return hasFilter_; 109 162 } 110 bool matchFilter( TValueType str) const {111 return TFilter::filter(filter, str);163 bool matchFilter(const TValueType value) const { 164 return TFilter::filter(filter, value); 112 165 } 113 166 const filter_one & operator=(std::string value) { … … 134 187 return sub.hasFilter() || regexp.hasFilter(); 135 188 } 136 bool matchFilter( std::string str) const {189 bool matchFilter(const std::string str) const { 137 190 if ((regexp.hasFilter())&&(regexp.matchFilter(str))) 138 191 return true; … … 161 214 filter_one<TType, TType, THandler, filter::numeric_equals_filter<TType> > eq; 162 215 filter_one<TType, TType, THandler, filter::numeric_nequals_filter<TType> > neq; 163 216 filter_one<std::list<TType>, TType, handlers::numeric_list_handler<TType, THandler>, filter::numeric_inlist_filter<std::list<TType>, TType> > inList; 217 218 filter_all_numeric() {} 219 filter_all_numeric(const filter_all_numeric &other) { 220 max = other.max; 221 min = other.min; 222 eq = other.eq; 223 neq = other.neq; 224 inList = other.inList; 225 } 164 226 inline bool hasFilter() const { 165 return max.hasFilter() || min.hasFilter() || eq.hasFilter() || neq.hasFilter() ;166 } 167 bool matchFilter( TType value) const {227 return max.hasFilter() || min.hasFilter() || eq.hasFilter() || neq.hasFilter() || inList.hasFilter(); 228 } 229 bool matchFilter(const TType value) const { 168 230 if ((max.hasFilter())&&(max.matchFilter(value))) 169 231 return true; … … 173 235 return true; 174 236 else if ((neq.hasFilter())&&(neq.matchFilter(value))) 237 return true; 238 else if ((inList.hasFilter())&&(inList.matchFilter(value))) 175 239 return true; 176 240 return false; … … 185 249 } else if (value.substr(0,2) == "!=") { 186 250 neq = value.substr(2); 251 } else if (value.substr(0,3) == "in:") { 252 inList = value.substr(3); 187 253 } else { 188 254 throw parse_exception("Unknown filter key: " + value); … … 191 257 } 192 258 }; 193 typedef filter_all_numeric<unsigned int, checkHolders::time_handler<unsigned int> > filter_all_times;259 typedef filter_all_numeric<unsigned long long, checkHolders::time_handler<unsigned long long> > filter_all_times; 194 260 } -
include/strEx.h
r75d5e70 r6817602 6 6 #include <utility> 7 7 #include <list> 8 #include <functional> 8 9 #ifdef _DEBUG 9 10 #include <iostream> … … 260 261 typedef std::basic_string<char, blind_traits<char>, std::allocator<char> > blindstr; 261 262 263 struct case_blind_string_compare : public std::binary_function<std::string, std::string, bool> 264 { 265 bool operator() (const std::string& x, const std::string& y) const { 266 return stricmp( x.c_str(), y.c_str() ) < 0; 267 } 268 }; 262 269 #ifdef _DEBUG 263 270 inline void test_getToken(std::string in1, char in2, std::string out1, std::string out2) { -
include/utils.h
r75d5e70 r6817602 7 7 unsigned long calculate_crc32(const char *buffer, int buffer_size); 8 8 9 namespace socketHelpers {10 class allowedHosts {11 private:12 strEx::splitList allowedHosts_;13 public:14 void setAllowedHosts(strEx::splitList allowedHosts) {15 if ((!allowedHosts.empty()) && (allowedHosts.front() == "") )16 allowedHosts.pop_front();17 allowedHosts_ = allowedHosts;18 }19 bool inAllowedHosts(std::string s) {20 if (allowedHosts_.empty())21 return true;22 strEx::splitList::const_iterator cit;23 for (cit = allowedHosts_.begin();cit!=allowedHosts_.end();++cit) {24 if ( (*cit) == s)25 return true;26 }27 return false;28 }29 };30 }31 9 32 10 #define MAP_OPTIONS_BEGIN(args) \ … … 58 36 else if (p__.first == ("MinCrit" postfix)) { obj.crit.min = p__.second; } 59 37 38 #define MAP_OPTIONS_PUSH_WTYPE(type, value, obj, list) \ 39 else if (p__.first == value) { type o; o.obj = p__.second; list.push_back(o); } 60 40 #define MAP_OPTIONS_PUSH(value, list) \ 61 41 else if (p__.first == value) { list.push_back(p__.second); } … … 74 54 #define MAP_OPTIONS_BOOL_VALUE(value, obj, tStr) \ 75 55 else if ((p__.first == value)&&(p__.second == tStr)) { obj = true; } 56 #define MAP_OPTIONS_MODE(value, tStr, obj, oVal) \ 57 else if ((p__.first == value)&&(p__.second == tStr)) { obj = oVal; } 76 58 #define MAP_OPTIONS_BOOL_EX(value, obj, tStr, fStr) \ 77 59 else if ((p__.first == value)&&(p__.second == tStr)) { obj = true; } \ … … 79 61 #define MAP_OPTIONS_MISSING(arg, str) \ 80 62 else { arg = str + p__.first; return NSCAPI::returnUNKNOWN; } 63 #define MAP_OPTIONS_FALLBACK(obj) \ 64 else { obj = p__.first;} 81 65 #define MAP_OPTIONS_FALLBACK_AND(obj, extra) \ 82 66 else { obj = p__.first; extra;}
Note: See TracChangeset
for help on using the changeset viewer.








