Changeset 6817602 in nscp for include


Ignore:
Timestamp:
02/22/06 21:47:57 (7 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
1b7ae3d
Parents:
89f1a84
Message:

Lots of update (I really should checkin more often :)

Location:
include
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • include/EnumNtSrv.cpp

    re26cfe0 r6817602  
    177177} 
    178178 
     179#define SC_BUF_LEN 1024 
    179180TNtServiceInfo TNtServiceInfo::GetService(std::string name) 
    180181{ 
     
    187188  SC_HANDLE sh = ::OpenService(scman,name.c_str(),SERVICE_QUERY_STATUS); 
    188189  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    } 
    191206  } 
    192207  SERVICE_STATUS state; 
  • include/NSCHelper.cpp

    re26cfe0 r6817602  
    381381    throw NSCMHExcpetion("NSCore has not been initiated..."); 
    382382  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); 
    384385  len+=2; 
    385386  char *buf = new char[len+1]; 
    386   NSCAPI::errorReturn ret = fNSAPIEncrypt(algorithm, str.c_str(), str.size(), buf, &len); 
     387  NSCAPI::errorReturn ret = fNSAPIEncrypt(algorithm, str.c_str(), static_cast<unsigned int>(str.size()), buf, &len); 
    387388  if (ret == NSCAPI::isSuccess) { 
    388389    std::string ret = buf; 
     
    396397    throw NSCMHExcpetion("NSCore has not been initiated..."); 
    397398  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); 
    399401  len+=2; 
    400402  char *buf = new char[len+1]; 
    401   NSCAPI::errorReturn ret = fNSAPIDecrypt(algorithm, str.c_str(), str.size(), buf, &len); 
     403  NSCAPI::errorReturn ret = fNSAPIDecrypt(algorithm, str.c_str(), static_cast<unsigned int>(str.size()), buf, &len); 
    402404  if (ret == NSCAPI::isSuccess) { 
    403405    std::string ret = buf; 
  • include/NSCHelper.h

    re26cfe0 r6817602  
    8383  typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); 
    8484  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*); 
    8686  typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); 
    8787  typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const char*, unsigned int, char*, unsigned int *); 
     
    144144  extern int NSGetConfigurationMeta(int IN_retBufLen, char *OUT_retBuf) 
    145145 
     146#define NSC_WRAPPERS_CLI() \ 
     147  extern int NSCommandLineExec(const char*,const unsigned int,char**) 
    146148 
    147149 
     
    224226  } 
    225227 
     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 
    226233////////////////////////////////////////////////////////////////////////// 
    227234#define MODULE_SETTINGS_START(class, name, description) \ 
  • include/PDHCounter.h

    r75d5e70 r6817602  
    201201    } 
    202202 
    203     static DWORD lookupCounterByName(std::string count, std::string machine = "") { 
    204     } 
    205  
    206203    PDHCounter* addCounter(std::string name, PDHCounterListener *listener) { 
    207204      PDHCounter *counter = new PDHCounter(name, listener); 
  • include/ServiceCmd.cpp

    r75d5e70 r6817602  
    1616#include "stdafx.h" 
    1717#include "ServiceCmd.h" 
     18#include <strEx.h> 
    1819 
    1920namespace serviceControll { 
     
    3031   * 
    3132   */ 
    32   void Install(LPCTSTR szName, LPCTSTR szDisplayName, LPCTSTR szDependencies) { 
     33  void Install(LPCTSTR szName, LPCTSTR szDisplayName, LPCTSTR szDependencies, DWORD dwServiceType) { 
    3334    SC_HANDLE   schService; 
    3435    SC_HANDLE   schSCManager; 
     
    4647      TEXT(szDisplayName),     // name to display 
    4748      SERVICE_ALL_ACCESS,         // desired access 
    48       SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS ,  // service type 
     49      dwServiceType,        // service type 
    4950      SERVICE_AUTO_START,       // start type 
    5051      SERVICE_ERROR_NORMAL,       // error control type 
     
    5758 
    5859    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; 
    64128  } 
    65129 
     
    188252  } 
    189253 
     254 
     255  typedef BOOL (WINAPI*PFChangeServiceConfig2)(SC_HANDLE hService,DWORD dwInfoLevel,LPVOID lpInfo); 
     256 
    190257  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    } 
    191272    SERVICE_DESCRIPTION descr; 
    192273    SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); 
     
    195276    SC_HANDLE schService = OpenService(schSCManager, TEXT(name.c_str()), SERVICE_ALL_ACCESS); 
    196277    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]; 
    202284    strncpy(d, desc.c_str(), desc.length()); 
    203285    descr.lpDescription = d; 
    204     BOOL bResult = ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &descr); 
     286    BOOL bResult = FChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &descr); 
    205287    delete [] d; 
     288    FreeLibrary(ADVAPI); 
    206289    CloseServiceHandle(schService); 
    207290    CloseServiceHandle(schSCManager); 
  • include/ServiceCmd.h

    r75d5e70 r6817602  
    11#pragma once 
     2 
     3#include <sstream> 
    24 
    35namespace serviceControll { 
     
    79    SCException(std::string error) : error_(error) { 
    810    } 
     11    SCException(std::string error, int code) : error_(error) { 
     12      std::stringstream ss; 
     13      ss << ": "; 
     14      ss << code; 
     15      error += ss.str(); 
     16    } 
    917  }; 
    10   void Install(LPCTSTR,LPCTSTR,LPCTSTR); 
     18  void Install(LPCTSTR,LPCTSTR,LPCTSTR,DWORD=SERVICE_WIN32_OWN_PROCESS); 
     19  void ModifyServiceType(LPCTSTR szName, DWORD dwServiceType); 
    1120  void Uninstall(std::string); 
    1221  void Start(std::string); 
    1322  void Stop(std::string); 
    1423  void SetDescription(std::string,std::string); 
     24  DWORD GetServiceType(LPCTSTR szName); 
    1525} 
  • include/Settings.h

    r89f1a84 r6817602  
    22 
    33#include <Singleton.h> 
     4#include <string> 
     5#include <map> 
     6#include <windows.h> 
    47#define BUFF_LEN 4096 
    58 
     
    1013{ 
    1114private: 
     15  typedef std::map<std::string,std::string> saveKeyList; 
     16  typedef std::map<std::string,saveKeyList> saveSectionList; 
    1217  std::string file_; 
     18  saveSectionList data_; 
     19  bool bHasInternalData; 
    1320public: 
    1421  typedef std::list<std::string> sectionList; 
    15  
    16   SettingsT(void) 
     22  SettingsT(void) : bHasInternalData(false) 
    1723  { 
    1824  } 
     
    2935    file_ = file; 
    3036  } 
     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 
    3162  /** 
    3263   * Get all keys from a section as a list<string> 
     
    3465   * @return A list with all keys from the section 
    3566   */ 
    36   std::list<std::string> getSection(std::string section) { 
    37     std::list<std::string> ret; 
     67  sectionList getSection(std::string section) { 
     68    sectionList ret; 
    3869    char* buffer = new char[BUFF_LEN+1]; 
    3970    unsigned int count = GetPrivateProfileSection(section.c_str(), buffer, BUFF_LEN, file_.c_str()); 
     
    4980    } 
    5081    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(); 
    5192    return ret; 
    5293  } 
     
    59100   */ 
    60101  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    } 
    61111    char* buffer = new char[1024]; 
    62112    GetPrivateProfileString(section.c_str(), key.c_str(), defaultValue.c_str(), buffer, 1023, file_.c_str()); 
     
    65115    return ret; 
    66116  } 
     117 
     118  void setString(std::string section, std::string key, std::string value) { 
     119    bHasInternalData = true; 
     120    (data_[section])[key] = value; 
     121  } 
     122 
    67123  /** 
    68124   * Get an integer from the settings file 
  • include/Socket.h

    r1d9338a r6817602  
    100100      unsigned long NoBlock = 1; 
    101101      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; 
    102117    } 
    103118    virtual void readAll(DataBuffer &buffer, unsigned int tmpBufferLength = 1024); 
     
    397412  return 0; 
    398413} 
     414 
     415 
     416 
     417namespace 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  
    44#include <strEx.h> 
    55 
     6#define MAKE_PERFDATA(alias, value, unit, warn, crit) "'" + alias + "'=" + value + unit + ";" + warn + ";" + crit + "; " 
    67 
    78namespace checkHolders { 
     
    133134      return "Free: "; 
    134135    } 
     136    static std::string key_prefix() { 
     137      return ""; 
     138    } 
     139    static std::string key_postfix() { 
     140      return ""; 
     141    } 
     142 
    135143  }; 
    136144 
     
    154162      return strEx::itos(value); 
    155163    } 
     164    static std::string key_prefix() { 
     165      return ""; 
     166    } 
     167    static std::string key_postfix() { 
     168      return ""; 
     169    } 
     170 
    156171  }; 
    157172 
     
    174189      return strEx::itos(value) + "%"; 
    175190    } 
     191    static std::string key_prefix() { 
     192      return ""; 
     193    } 
     194    static std::string key_postfix() { 
     195      return ""; 
     196    } 
    176197  }; 
    177198  class int64_handler { 
     
    209230    static std::string print_percent(double value) { 
    210231      return strEx::itos(value) + "%"; 
     232    } 
     233    static std::string key_prefix() { 
     234      return ""; 
     235    } 
     236    static std::string key_postfix() { 
     237      return ""; 
    211238    } 
    212239  }; 
     
    268295 
    269296    static std::string toStringLong(TType value) { 
    270       return THandler::print(value); 
     297      return THandler::key_prefix() + THandler::print(value) + THandler::key_postfix(); 
    271298    } 
    272299    static std::string toStringShort(TType value) { 
     
    286313    } 
    287314    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)); 
    292316    } 
    293317 
     
    335359      } 
    336360      const InternalValue & operator=(std::string value) { 
    337         std::cout << "Setting value: " << value << std::endl; 
    338361        std::string::size_type p = value.find_first_of('%'); 
    339362        if (p != std::string::npos) { 
     
    372395    checkResultType check(TType value) const { 
    373396      if (type_ == percentage_lower) { 
    374         std::cout << "Checking: percentage_lower " << value.getLowerPercentage() << " < " << value_ << std::endl; 
    375397        if (value.getLowerPercentage() == value_) 
    376398          return same; 
     
    378400          return above; 
    379401      } else if (type_ == percentage_upper) { 
    380         std::cout << "Checking: percentage_upper " << value.getUpperPercentage() << " < " << value_ << std::endl; 
    381402        if (value.getUpperPercentage() == value_) 
    382403          return same; 
     
    384405          return above; 
    385406      } else if (type_ == value_lower) { 
    386         std::cout << "Checking: value_lower " << value.total << " < " << value_ << std::endl; 
    387407        if (value.value == value_) 
    388408          return same; 
     
    390410          return above; 
    391411      } else if (type_ == value_upper) { 
    392         std::cout << "Checking: value_upper " << (value.total-value.value) << " < " << value_ << std::endl; 
    393412        if ((value.total-value.value) == value_) 
    394413          return same; 
     
    421440    std::string gatherPerfData(std::string alias, TType &value, typename TType::TValueType warn, typename TType::TValueType crit) { 
    422441      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)); 
    427445      } 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)); 
    432449      } 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)); 
    437453      } 
    438454    } 
    439455  private: 
    440456    void setUpper(std::string s) { 
    441       std::cout << "Setting value:U " << s << std::endl; 
    442457      value_ = THandler::parse(s); 
    443458      type_ = value_upper; 
    444459    } 
    445460    void setLower(std::string s) { 
    446       std::cout << "Setting value:L " << s << std::endl; 
    447461      value_ = THandler::parse(s); 
    448462      type_ = value_lower; 
  • include/config.h

    r75d5e70 r6817602  
    55 
    66// Version 
    7 #define SZVERSION "0.2.0 2005-05-21" 
     7#define SZVERSION "0.2.5f 2006-02-14" 
    88 
    99// internal name of the service 
    10 #define SZSERVICENAME        "NSClient++" 
     10#define SZSERVICENAME        "NSClientpp" 
    1111 
    1212// Description of service 
  • include/filter_framework.hpp

    r89f1a84 r6817602  
    11#pragma once 
     2 
     3#include <strEx.h> 
    24 
    35namespace filters { 
     
    4042    struct numeric_equals_filter { 
    4143      static bool filter(TType filter, TType value) { 
    42         return value = filter; 
     44        return value == filter; 
    4345      } 
    4446    }; 
     
    4749      static bool filter(TType filter, TType value) { 
    4850        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; 
    4967      } 
    5068    }; 
     
    5775      static std::string parse(std::string str) { 
    5876        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; 
    5988      } 
    6089    }; 
     
    6998    }; 
    7099    struct eventtype_handler { 
    71  
    72100      static unsigned int parse(std::string str) { 
    73101        if (str == "error") 
     
    97125      }    
    98126    }; 
    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    };  } 
    100151 
    101152  template <typename TFilterType, typename TValueType, class THandler, class TFilter> 
     
    104155    bool hasFilter_; 
    105156    filter_one() : hasFilter_(false) {} 
     157    filter_one(const filter_one &other) : hasFilter_(other.hasFilter_), filter(other.filter) { 
     158    } 
    106159 
    107160    inline bool hasFilter() const { 
    108161      return hasFilter_; 
    109162    } 
    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); 
    112165    } 
    113166    const filter_one & operator=(std::string value) { 
     
    134187      return sub.hasFilter() || regexp.hasFilter(); 
    135188    } 
    136     bool matchFilter(std::string str) const { 
     189    bool matchFilter(const std::string str) const { 
    137190      if ((regexp.hasFilter())&&(regexp.matchFilter(str))) 
    138191        return true; 
     
    161214    filter_one<TType, TType, THandler, filter::numeric_equals_filter<TType> > eq; 
    162215    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    } 
    164226    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 { 
    168230      if ((max.hasFilter())&&(max.matchFilter(value))) 
    169231        return true; 
     
    173235        return true; 
    174236      else if ((neq.hasFilter())&&(neq.matchFilter(value))) 
     237        return true; 
     238      else if ((inList.hasFilter())&&(inList.matchFilter(value))) 
    175239        return true; 
    176240      return false; 
     
    185249      } else if (value.substr(0,2) == "!=") { 
    186250        neq = value.substr(2); 
     251      } else if (value.substr(0,3) == "in:") { 
     252        inList = value.substr(3); 
    187253      } else { 
    188254        throw parse_exception("Unknown filter key: " + value); 
     
    191257    } 
    192258  }; 
    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; 
    194260} 
  • include/strEx.h

    r75d5e70 r6817602  
    66#include <utility> 
    77#include <list> 
     8#include <functional> 
    89#ifdef _DEBUG 
    910#include <iostream> 
     
    260261  typedef std::basic_string<char, blind_traits<char>, std::allocator<char> >  blindstr; 
    261262 
     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  }; 
    262269#ifdef _DEBUG 
    263270  inline void test_getToken(std::string in1, char in2, std::string out1, std::string out2) { 
  • include/utils.h

    r75d5e70 r6817602  
    77unsigned long calculate_crc32(const char *buffer, int buffer_size); 
    88 
    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 } 
    319 
    3210#define MAP_OPTIONS_BEGIN(args) \ 
     
    5836      else if (p__.first == ("MinCrit" postfix)) { obj.crit.min = p__.second; } 
    5937 
     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); } 
    6040#define MAP_OPTIONS_PUSH(value, list) \ 
    6141      else if (p__.first == value) { list.push_back(p__.second); } 
     
    7454#define MAP_OPTIONS_BOOL_VALUE(value, obj, tStr) \ 
    7555      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; }  
    7658#define MAP_OPTIONS_BOOL_EX(value, obj, tStr, fStr) \ 
    7759      else if ((p__.first == value)&&(p__.second == tStr)) { obj = true; } \ 
     
    7961#define MAP_OPTIONS_MISSING(arg, str) \ 
    8062      else { arg = str + p__.first; return NSCAPI::returnUNKNOWN; } 
     63#define MAP_OPTIONS_FALLBACK(obj) \ 
     64      else { obj = p__.first;} 
    8165#define MAP_OPTIONS_FALLBACK_AND(obj, extra) \ 
    8266      else { obj = p__.first; extra;} 
Note: See TracChangeset for help on using the changeset viewer.