Changeset 3080680 in nscp


Ignore:
Timestamp:
01/31/10 22:54:36 (3 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
c0d7e82
Parents:
dad34ea
Message:

Updated all (currently ported) modules to build and use protocol buffers also fixed issues with the settings subsystem (now sets defaults and comments correctly on sections and such)

Files:
1 added
19 edited

Legend:

Unmodified
Added
Removed
  • build.cmake

    r2018659 r3080680  
    1313SET(CMAKE_LIBRARY_PATH c:/src/lib/x86/) 
    1414 
    15 SET(PROTOBUF_INCLUDE_DIR d:/source/protobuf-2.3.0/src) 
    16 SET(PROTOBUF_LIBRARYDIR d:/source/protobuf-2.3.0/vsprojects/Debug) 
    17 SET(PROTOBUF_BINARYDIR d:/source/protobuf-2.3.0/vsprojects/Debug) 
     15SET(PROTOBUF_INCLUDE_DIR C:/src/protobuf-2.3.0/src) 
     16SET(PROTOBUF_LIBRARYDIR C:/src/protobuf-2.3.0/vsprojects/Debug) 
     17SET(PROTOBUF_BINARYDIR C:/src/protobuf-2.3.0/vsprojects/Debug) 
    1818 
  • cmake/NSCPPBuffer.cmake

    r920626f r3080680  
    3232  ) 
    3333 
    34   FIND_LIBRARY(PROTOBUF_LIBRARY NAMES protobuf 
     34  FIND_LIBRARY(PROTOBUF_LIBRARY NAMES protobuf libprotobuf 
    3535    PATHS 
    3636    ${GNUWIN32_DIR}/lib 
  • include/service/win32_service.hpp

    r858ecc1 r3080680  
    185185        handle_error(__LINE__, __FILEW__, _T("Unknown service error!")); 
    186186      } 
     187      return 0; 
    187188    } 
    188189    static void WINAPI service_main_dispatch(DWORD dwArgc, LPTSTR *lpszArgv) { 
  • include/settings/Settings.h

    r753ea6d r3080680  
    2525#include <string> 
    2626#include <map> 
     27#include <set> 
    2728#include <boost/thread/thread.hpp> 
    2829#include <boost/thread/locks.hpp> 
     
    127128      key_description() : advanced(false), type(SettingsCore::key_string) {} 
    128129    }; 
     130    struct path_description { 
     131      std::wstring title; 
     132      std::wstring description; 
     133      bool advanced; 
     134      typedef std::map<std::wstring,key_description> keys_type; 
     135      keys_type keys; 
     136      path_description(std::wstring title_, std::wstring description_, bool advanced_) : title(title_), description(description_), advanced(advanced_) {} 
     137      path_description() : advanced(false) {} 
     138      void update(std::wstring title_, std::wstring description_, bool advanced_) { 
     139        title = title_; 
     140        description = description_; 
     141        advanced = advanced_; 
     142      } 
     143    }; 
     144 
    129145    struct mapped_key { 
    130146      mapped_key(key_path_type src_, key_path_type dst_) : src(src_), dst(dst_) {} 
     
    279295    virtual key_description get_registred_key(std::wstring path, std::wstring key) = 0; 
    280296 
     297    virtual SettingsCore::path_description get_registred_path(std::wstring path) = 0; 
    281298 
    282299    ////////////////////////////////////////////////////////////////////////// 
     
    550567    virtual bool has_key(std::wstring path, std::wstring key) = 0; 
    551568 
     569    virtual void add_path(std::wstring path) = 0; 
    552570    // Misc Functions 
    553571    ////////////////////////////////////////////////////////////////////////// 
     
    632650    }; 
    633651    */ 
    634     struct path_description { 
    635       std::wstring title; 
    636       std::wstring description; 
    637       bool advanced; 
    638       typedef std::map<std::wstring,key_description> keys_type; 
    639       keys_type keys; 
    640       path_description(std::wstring title_, std::wstring description_, bool advanced_) : title(title_), description(description_), advanced(advanced_) {} 
    641       path_description() : advanced(false) {} 
    642       void update(std::wstring title_, std::wstring description_, bool advanced_) { 
    643         title = title_; 
    644         description = description_; 
    645         advanced = advanced_; 
    646       } 
    647     }; 
    648652    class dummy_logger : public LoggerInterface { 
    649653      void err(std::wstring file, int line, std::wstring message) {} 
     
    657661    boost::filesystem::wpath base_path_; 
    658662    LoggerInterface *logger_; 
    659     typedef std::map<std::wstring,path_description> reg_paths_type; 
     663    typedef std::map<std::wstring,SettingsCore::path_description> reg_paths_type; 
    660664    reg_paths_type registred_paths_; 
    661665    typedef std::map<key_path_type,key_path_type> mapped_paths_type; 
     
    739743    void update_defaults() { 
    740744      get_logger()->warn(__FILEW__, __LINE__, _T("Updating settings with default values!")); 
    741       string_list s = get_reg_sections(); 
    742       for (string_list::const_iterator cit = s.begin(); cit != s.end(); ++cit) { 
    743         string_list k = get_reg_keys(*cit); 
    744         for (string_list::const_iterator citk = k.begin(); citk != k.end(); ++citk) { 
    745           SettingsCore::key_description desc = get_registred_key(*cit, *citk); 
     745      BOOST_FOREACH(std::wstring path, get_reg_sections()) { 
     746        get()->add_path(path); 
     747        BOOST_FOREACH(std::wstring key, get_reg_keys(path)) { 
     748          SettingsCore::key_description desc = get_registred_key(path, key); 
    746749          if (!desc.advanced) { 
    747             if (!get()->has_key(*cit, *citk)) { 
    748               get_logger()->debug(__FILEW__, __LINE__, _T("Adding: ") + *cit + _T(".") + *citk); 
     750            if (!get()->has_key(path, key)) { 
     751              get_logger()->debug(__FILEW__, __LINE__, _T("Adding: ") + path + _T(".") + key); 
    749752              if (desc.type == key_string) 
    750                 get()->set_string(*cit, *citk, desc.defValue); 
     753                get()->set_string(path, key, desc.defValue); 
    751754              else if (desc.type == key_bool) 
    752                 get()->set_bool(*cit, *citk, desc.defValue==_T("true")); 
     755                get()->set_bool(path, key, desc.defValue==_T("true")); 
    753756              else if (desc.type == key_integer) 
    754                 get()->set_int(*cit, *citk, strEx::stoi(desc.defValue)); 
     757                get()->set_int(path, key, strEx::stoi(desc.defValue)); 
    755758              else 
    756                 get_logger()->err(__FILEW__, __LINE__, _T("Unknown keytype for: ") + *cit + _T(".") + *citk); 
     759                get_logger()->err(__FILEW__, __LINE__, _T("Unknown keytype for: ") + path + _T(".") + key); 
    757760            } else { 
    758               std::wstring val = get()->get_string(*cit, *citk); 
    759               get_logger()->debug(__FILEW__, __LINE__, _T("Setting old (already exists): ") + *cit + _T(".") + *citk + _T(" = ") + val); 
     761              std::wstring val = get()->get_string(path, key); 
     762              get_logger()->debug(__FILEW__, __LINE__, _T("Setting old (already exists): ") + path + _T(".") + key + _T(" = ") + val); 
    760763              if (desc.type == key_string) 
    761                 get()->set_string(*cit, *citk, val); 
     764                get()->set_string(path, key, val); 
    762765              else if (desc.type == key_bool) 
    763                 get()->set_bool(*cit, *citk, val==_T("true")); 
     766                get()->set_bool(path, key, val==_T("true")); 
    764767              else if (desc.type == key_integer) 
    765                 get()->set_int(*cit, *citk, strEx::stoi(val)); 
     768                get()->set_int(path, key, strEx::stoi(val)); 
    766769              else 
    767                 get_logger()->err(__FILEW__, __LINE__, _T("Unknown keytype for: ") + *cit + _T(".") + *citk); 
     770                get_logger()->err(__FILEW__, __LINE__, _T("Unknown keytype for: ") + path + _T(".") + key); 
    768771            } 
    769772          } else { 
    770             get_logger()->debug(__FILEW__, __LINE__, _T("Skipping (advanced): ") + *cit + _T(".") + *citk); 
     773            get_logger()->debug(__FILEW__, __LINE__, _T("Skipping (advanced): ") + path + _T(".") + key); 
    771774          } 
    772775        } 
     
    11261129      throw KeyNotFoundException(path, key); 
    11271130    } 
     1131    SettingsCore::path_description get_registred_path(std::wstring path) { 
     1132      reg_paths_type::const_iterator cit = registred_paths_.find(path); 
     1133      if (cit != registred_paths_.end()) { 
     1134        return (*cit).second; 
     1135      } 
     1136      throw KeyNotFoundException(path); 
     1137    } 
    11281138 
    11291139 
     
    12821292    typedef SettingsCore::key_path_type cache_key_type; 
    12831293    typedef std::map<cache_key_type,conainer> cache_type; 
     1294    typedef std::set<std::wstring> path_cache_type; 
    12841295    cache_type settings_cache_; 
     1296    path_cache_type path_cache_; 
    12851297    std::wstring context_; 
    12861298 
     
    13761388    virtual void set_string(std::wstring path, std::wstring key, std::wstring value) { 
    13771389      settings_cache_[cache_key_type(path,key)] = value; 
     1390    } 
     1391 
     1392    virtual void add_path(std::wstring path) { 
     1393      path_cache_.insert(path); 
    13781394    } 
    13791395 
     
    16681684    /// @author mickem 
    16691685    virtual void save() { 
     1686      BOOST_FOREACH(std::wstring path, path_cache_) { 
     1687        set_real_path(path); 
     1688      } 
     1689      std::set<std::wstring> sections; 
    16701690      for (cache_type::const_iterator cit = settings_cache_.begin(); cit != settings_cache_.end(); ++cit) { 
    16711691        set_real_value((*cit).first, (*cit).second); 
     1692        sections.insert((*cit).first.first); 
     1693      } 
     1694      BOOST_FOREACH(std::wstring str, get_core()->get_reg_sections()) { 
     1695        set_real_path(str); 
    16721696      } 
    16731697    } 
     
    17571781    /// @author mickem 
    17581782    virtual void set_real_value(SettingsCore::key_path_type key, conainer value) = 0; 
     1783 
     1784    ////////////////////////////////////////////////////////////////////////// 
     1785    /// Write a value to the resulting context. 
     1786    /// 
     1787    /// @param key The key to write to 
     1788    /// @param value The value to write 
     1789    /// 
     1790    /// @author mickem 
     1791    virtual void set_real_path(std::wstring path) = 0; 
    17591792 
    17601793    ////////////////////////////////////////////////////////////////////////// 
  • include/settings/macros.h

    r753ea6d r3080680  
    251251    DEFINE_PATH(ALIAS_SECTION, EXTSCRIPT_ALIAS_SECTION); 
    252252    DESCRIBE_SETTING(ALIAS_SECTION, "EXTERNAL SCRIPT ALIAS SECTION", "Works like the \"inject\" concept of NRPE scripts module. But in short a list of aliases available. An alias is an internal command that has been \"wrapped\" (to add arguments). Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)"); 
     253 
    253254  } 
    254255 
  • include/settings/settings_ini.hpp

    r753ea6d r3080680  
    126126      } 
    127127    } 
     128 
     129    virtual void set_real_path(std::wstring path) { 
     130      try { 
     131        get_core()->get_logger()->quick_debug(_T("Setting path: ") + path); 
     132        const SettingsCore::path_description desc = get_core()->get_registred_path(path); 
     133        if (!desc.description.empty()) { 
     134          std::wstring comment = _T("; ") + desc.description; 
     135          ini.SetValue(path.c_str(), NULL, NULL, comment.c_str()); 
     136        } 
     137      } catch (KeyNotFoundException e) { 
     138        ini.SetValue(path.c_str(), NULL, NULL, _T("; Undocumented section")); 
     139      } catch (SettingsException e) { 
     140        get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Failed to write section: ") + e.getError())); 
     141      } catch (...) { 
     142        get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Unknown filure when writing section: ") + path)); 
     143      } 
     144    } 
     145 
    128146    ////////////////////////////////////////////////////////////////////////// 
    129147    /// Get all (sub) sections (given a path). 
  • include/settings/settings_old.hpp

    rd05c3f0 r3080680  
    298298      } 
    299299    } 
     300 
     301    virtual void set_real_path(std::wstring path) { 
     302      // NOT Supported (and not needed) so silently ignored! 
     303    } 
     304 
    300305    ////////////////////////////////////////////////////////////////////////// 
    301306    /// Get all (sub) sections (given a path). 
  • include/settings/settings_registry.hpp

    r7f9c823 r3080680  
    123123    } 
    124124  } 
     125  virtual void set_real_path(std::wstring path) { 
     126    // NOT Supported (and not needed) so silently ignored! 
     127  } 
     128 
    125129  ////////////////////////////////////////////////////////////////////////// 
    126130  /// Get all (sub) sections (given a path). 
  • include/simpleini/simpleini.h

    r3eedfa6 r3080680  
    17161716        iSection = i.first; 
    17171717        bInserted = true; 
    1718     } 
     1718  } else if (a_pComment && (!a_pKey || !a_pValue)) { 
     1719    Entry oKey(iSection->first.pItem, iSection->first.nOrder); 
     1720    oKey.pComment = a_pComment; 
     1721 
     1722    typename TSection::value_type oEntry(oKey, iSection->second); 
     1723    typedef typename TSection::iterator SectionIterator; 
     1724    m_data.erase(iSection); 
     1725    std::pair<SectionIterator,bool> i = m_data.insert(oEntry); 
     1726 
     1727 
     1728    iSection = i.first; 
     1729  } 
    17191730    if (!a_pKey || !a_pValue) { 
    17201731        // section only entries are specified with pItem and pVal as NULL 
     
    20192030            a_oOutput.Write(SI_NEWLINE_A); 
    20202031            bNeedNewLine = false; 
    2021         } 
     2032    } 
    20222033 
    20232034        if (bNeedNewLine) { 
     
    20742085                    return SI_FAIL; 
    20752086                } 
     2087        a_oOutput.Write("="); 
    20762088        if (iValue->pItem != NULL && !IsEmpty(iValue->pItem)) { 
    2077           a_oOutput.Write("="); 
    20782089          if (m_bAllowMultiLine && IsMultiLineData(iValue->pItem)) { 
    20792090            // multi-line data needs to be processed specially to ensure 
  • modules/CheckExternalScripts/CheckExternalScripts.cpp

    r79e734f r3080680  
    124124 
    125125 
    126 NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 
     126NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 
    127127  std::wstring cmd = command.c_str(); 
    128128  boost::to_lower(cmd); 
     
    139139  std::wstring args = cd.arguments; 
    140140  if (isAlias || allowArgs_) { 
    141     arrayBuffer::arrayList arr = arrayBuffer::arrayBuffer2list(argLen, char_args); 
    142     arrayBuffer::arrayList::const_iterator cit2 = arr.begin(); 
    143141    int i=1; 
    144  
    145     for (;cit2!=arr.end();cit2++,i++) { 
     142    BOOST_FOREACH(wstring str, arguments) { 
    146143      if (isAlias || allowNasty_) { 
    147         if ((*cit2).find_first_of(NASTY_METACHARS) != std::wstring::npos) { 
     144        if (str.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 
    148145          NSC_LOG_ERROR(_T("Request string contained illegal metachars!")); 
    149146          return NSCAPI::returnIgnored; 
    150147        } 
    151148      } 
    152       strEx::replace(args, _T("$ARG") + strEx::itos(i) + _T("$"), (*cit2)); 
     149      strEx::replace(args, _T("$ARG") + strEx::itos(i) + _T("$"), str); 
    153150    } 
    154151  } 
  • modules/CheckExternalScripts/CheckExternalScripts.def

    rc1d545e r3080680  
    1313  NSGetConfigurationMeta 
    1414  NSGetModuleDescription 
     15  NSDeleteBuffer 
  • modules/CheckExternalScripts/CheckExternalScripts.h

    r79e734f r3080680  
    2525#include <execute_process.hpp> 
    2626 
    27 class CheckExternalScripts { 
     27class CheckExternalScripts : public NSCModuleHelper::SimpleCommand { 
    2828private: 
    2929  struct command_data { 
     
    6363  bool hasCommandHandler(); 
    6464  bool hasMessageHandler(); 
    65   NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 
     65  NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 
    6666  std::wstring getConfigurationMeta(); 
    6767 
  • modules/CheckHelpers/CMakeLists.txt

    r920626f r3080680  
    11CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 
    22   
    3 PROJECT(CheckHelpers) 
     3SET(TARGET CheckHelpers) 
    44 
    5 # Workaround for bug 0003353 in cmake (aparently not fixed) 
    6 SET_SOURCE_FILES_PROPERTIES(${PB_PLUGIN} PROPERTIES GENERATED TRUE) 
     5PROJECT(${TARGET}) 
    76 
    8 SET(CheckHelpers_SRCS 
     7SET(SRCS 
    98  stdafx.cpp 
    10   CheckHelpers.cpp 
     9  "${TARGET}.cpp" 
    1110  ${NSCP_DEF_PLUGIN_CPP} 
    1211) 
     
    1514 
    1615IF(WIN32) 
    17   SET(CheckHelpers_SRCS ${CheckHelpers_SRCS} 
     16  SET(SRCS ${SRCS} 
    1817    stdafx.h 
    19     CheckHelpers.def 
     18    "${TARGET}.h" 
     19    "${TARGET}.def" 
     20 
    2021    ${NSCP_DEF_PLUGIN_HPP} 
    21  
    2222  ) 
    2323ENDIF(WIN32) 
    2424 
    25 add_library(CheckHelpers MODULE ${CheckHelpers_SRCS}) 
     25add_library(${TARGET} MODULE ${SRCS}) 
    2626 
    27 target_link_libraries(CheckHelpers 
     27target_link_libraries(${TARGET} 
    2828  ${Boost_FILESYSTEM_LIBRARY} 
    2929  ${NSCP_DEF_PLUGIN_LIB} 
  • modules/NRPEClient/CMakeLists.txt

    r920626f r3080680  
    44   
    55PROJECT(${TARGET}) 
    6  
    7 # Workaround for bug 0003353 in cmake (aparently not fixed) 
    8 SET_SOURCE_FILES_PROPERTIES(${PB_PLUGIN} PROPERTIES GENERATED TRUE) 
    96 
    107SET(SRCS 
     
    2219    stdafx.h 
    2320    "${TARGET}.h" 
     21    "${TARGET}.def" 
    2422    ${NSCP_INCLUDE_PATH}/nrpe/nrpepacket.hpp 
    2523    ${NSCP_INCLUDE_PATH}/socket_helpers.hpp 
    26     "${TARGET}.def" 
    2724 
    2825    ${NSCP_DEF_PLUGIN_HPP} 
  • modules/NRPEServer/CMakeLists.txt

    r920626f r3080680  
    2525    stdafx.h 
    2626    "${TARGET}.h" 
     27    "${TARGET}.def" 
    2728    nrpe_server.hpp 
    2829    nrpe_connection.hpp 
     
    3132    ${NSCP_INCLUDE_PATH}/nrpe/nrpepacket.hpp 
    3233    ${NSCP_INCLUDE_PATH}/socket_helpers.hpp 
    33     "${TARGET}.def" 
    3434 
    3535    ${NSCP_DEF_PLUGIN_HPP} 
  • modules/NRPEServer/NRPEServer.def

    r2018659 r3080680  
    1313  NSGetConfigurationMeta 
    1414  NSGetModuleDescription 
     15  NSDeleteBuffer 
  • modules/Scheduler/CMakeLists.txt

    r920626f r3080680  
    11CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 
    22   
    3 PROJECT(Scheduler) 
     3SET(TARGET Scheduler) 
    44 
    5 # Workaround for bug 0003353 in cmake (aparently not fixed) 
    6 SET_SOURCE_FILES_PROPERTIES(${PB_PLUGIN} PROPERTIES GENERATED TRUE) 
     5PROJECT(${TARGET}) 
    76 
    8 SET(Scheduler_SRCS 
     7SET(SRCS 
    98  stdafx.cpp 
    10   Scheduler.cpp 
     9  "${TARGET}.cpp" 
    1110  simple_scheduler.cpp 
     11 
    1212  ${NSCP_DEF_PLUGIN_CPP} 
    1313) 
     
    1616 
    1717IF(WIN32) 
    18   SET(Scheduler_SRCS ${Scheduler_SRCS} 
     18  SET(SRCS ${SRCS} 
    1919    stdafx.h 
     20    "${TARGET}.h" 
     21    "${TARGET}.def" 
    2022    simple_scheduler.hpp 
     23 
    2124    ${NSCP_DEF_PLUGIN_HPP} 
    2225  ) 
    2326ENDIF(WIN32) 
    2427 
    25 add_library(Scheduler MODULE ${Scheduler_SRCS}) 
     28add_library(Scheduler MODULE ${SRCS}) 
    2629 
    2730target_link_libraries(Scheduler 
  • service/NSCPlugin.cpp

    r2018659 r3080680  
    389389    fShowTray = (lpShowTray)module_.load_proc("ShowIcon"); 
    390390    fHideTray = (lpHideTray)module_.load_proc("HideIcon"); 
     391     
     392  } catch (NSPluginException &e) { 
     393    throw e; 
    391394  } catch (dll::dll_exception &e) { 
    392395    throw NSPluginException(module_, _T("Unhandled exception when loading proces: ") + e.what()); 
  • service/NSClient++.cpp

    r920626f r3080680  
    325325                name = plugin->getName(); 
    326326                description = plugin->getDescription(); 
    327               } catch(const NSPluginException& e) { 
     327              } catch(NSPluginException& e) { 
    328328                LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 
    329329              } catch (std::exception e) { 
Note: See TracChangeset for help on using the changeset viewer.