Changeset 281


Ignore:
Timestamp:
08/19/10 13:36:13 (18 months ago)
Author:
mickem
Message:

New settings client (c++ instead of c) which looks pretty sweet :P
Only NRPEServer and CHeckExternalScripts implements it as of yet...

Files:
20 added
57 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/modules/CheckDisk/CheckDisk.cpp

    r272 r281  
    3030CheckDisk gCheckDisk; 
    3131 
    32 BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) 
    33 { 
    34   NSCModuleWrapper::wrapDllMain(hModule, ul_reason_for_call); 
    35   return TRUE; 
    36 } 
    37  
    3832CheckDisk::CheckDisk() : show_errors_(false) { 
    3933} 
     
    4640 
    4741bool CheckDisk::loadModule() { 
     42  return false; 
     43} 
     44 
     45bool CheckDisk::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    4846  try { 
    49     NSCModuleHelper::registerCommand(_T("CheckFileSize"), _T("Check or directory a file and verify its size.")); 
    50     NSCModuleHelper::registerCommand(_T("CheckDriveSize"), _T("Check the size (free-space) of a drive or volume.")); 
    51     NSCModuleHelper::registerCommand(_T("CheckFile"), _T("Check various aspects of a file and/or folder.")); 
    52  
    53     show_errors_ = NSCModuleHelper::getSettingsInt(CHECK_DISK_SECTION_TITLE, CHECK_DISK_SHOW_ERRORS, CHECK_DISK_SHOW_ERRORS_DEFAULT)==1; 
    54   } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     47    GET_CORE()->registerCommand(_T("CheckFileSize"), _T("Check or directory a file and verify its size.")); 
     48    GET_CORE()->registerCommand(_T("CheckDriveSize"), _T("Check the size (free-space) of a drive or volume.")); 
     49    GET_CORE()->registerCommand(_T("CheckFile2"), _T("Check various aspects of a file and/or folder.")); 
     50 
     51    // TODO 
     52    SETTINGS_REG_KEY_I(check_disk::SHOW_ERRORS); 
     53    show_errors_ = SETTINGS_GET_BOOL(check_disk::SHOW_ERRORS); 
     54  } catch (nscapi::nscapi_exception &e) { 
    5555    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
    5656  } catch (...) { 
     
    162162 
    163163 
    164 NSCAPI::nagiosReturn CheckDisk::CheckDriveSize(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 
     164NSCAPI::nagiosReturn CheckDisk::CheckDriveSize(std::list<std::wstring> args, std::wstring &message, std::wstring &perf) { 
    165165  NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 
    166   std::list<std::wstring> args = arrayBuffer::arrayBuffer2list(argLen, char_args); 
    167166  if (args.empty()) { 
    168167    message = _T("Missing argument(s)."); 
     
    344343    message = _T("OK: All drives within bounds."); 
    345344  else if (!bNSClient) 
    346     message = NSCHelper::translateReturn(returnCode) + _T(": ") + message; 
     345    message = nscapi::plugin_helper::translateReturn(returnCode) + _T(": ") + message; 
    347346  return returnCode; 
    348347} 
     
    416415 
    417416 
    418 NSCAPI::nagiosReturn CheckDisk::CheckFileSize(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 
     417NSCAPI::nagiosReturn CheckDisk::CheckFileSize(std::list<std::wstring> args, std::wstring &message, std::wstring &perf) { 
    419418  NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 
    420   std::list<std::wstring> args = arrayBuffer::arrayBuffer2list(argLen, char_args); 
    421419  bool bPerfData = true; 
    422420  bool debug = false; 
     
    472470    message = _T("OK all file sizes are within bounds."); 
    473471  else 
    474     message = NSCHelper::translateReturn(returnCode) + _T(": ") + message; 
     472    message = nscapi::plugin_helper::translateReturn(returnCode) + _T(": ") + message; 
    475473  return returnCode; 
    476474} 
     
    985983 
    986984 
    987 NSCAPI::nagiosReturn CheckDisk::getFileAge(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 
     985NSCAPI::nagiosReturn CheckDisk::getFileAge(std::list<std::wstring> args, std::wstring &message, std::wstring &perf) { 
    988986  NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 
    989   std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 
    990987  typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsUInteger> CheckFileContainer; 
    991   if (stl_args.empty()) { 
     988  if (args.empty()) { 
    992989    message = _T("Missing argument(s)."); 
    993990    return NSCAPI::returnUNKNOWN; 
     
    996993  std::wstring path; 
    997994  bool debug = false; 
    998   MAP_OPTIONS_BEGIN(stl_args) 
     995  MAP_OPTIONS_BEGIN(args) 
    999996    MAP_OPTIONS_STR(_T("path"), path) 
    1000997    MAP_OPTIONS_STR(_T("date"), format) 
     
    10241021 
    10251022 
    1026 NSCAPI::nagiosReturn CheckDisk::CheckFile(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 
    1027   NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 
    1028   std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 
    1029   typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsUInteger> CheckFileContainer; 
    1030   if (stl_args.empty()) { 
    1031     message = _T("Missing argument(s)."); 
    1032     return NSCAPI::returnUNKNOWN; 
    1033   } 
    1034   file_filter_function finder; 
    1035   PathContainer tmpObject; 
    1036   std::list<std::wstring> paths; 
    1037   unsigned int truncate = 0; 
    1038   CheckFileContainer query; 
    1039   std::wstring syntax = _T("%filename%"); 
    1040   std::wstring alias; 
    1041   bool bPerfData = true; 
    1042   unsigned int max_dir_depth = -1; 
    1043   bool debug = false; 
    1044  
    1045   try { 
    1046     MAP_OPTIONS_BEGIN(stl_args) 
    1047       MAP_OPTIONS_NUMERIC_ALL(query, _T("")) 
    1048       MAP_OPTIONS_STR2INT(_T("truncate"), truncate) 
    1049       MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) 
    1050       MAP_OPTIONS_STR(_T("syntax"), syntax) 
    1051       MAP_OPTIONS_PUSH(_T("path"), paths) 
    1052       MAP_OPTIONS_STR(_T("alias"), alias) 
    1053       MAP_OPTIONS_STR2INT(_T("max-dir-depth"), max_dir_depth) 
    1054       MAP_OPTIONS_PUSH(_T("file"), paths) 
    1055       MAP_OPTIONS_BOOL_TRUE(_T("debug"), debug) 
    1056       MAP_OPTIONS_BOOL_EX(_T("filter"), finder.bFilterIn, _T("in"), _T("out")) 
    1057       MAP_OPTIONS_BOOL_EX(_T("filter"), finder.bFilterAll, _T("all"), _T("any")) 
    1058       MAP_OPTIONS_PUSH_WTYPE(file_filter, _T("filter-size"), size, finder.filter_chain) 
    1059       MAP_OPTIONS_PUSH_WTYPE(file_filter, _T("filter-creation"), creation, finder.filter_chain) 
    1060       MAP_OPTIONS_PUSH_WTYPE(file_filter, _T("filter-written"), written, finder.filter_chain) 
    1061       MAP_OPTIONS_PUSH_WTYPE(file_filter, _T("filter-accessed"), accessed, finder.filter_chain) 
    1062       MAP_OPTIONS_MISSING(message, _T("Unknown argument: ")) 
    1063       MAP_OPTIONS_END() 
    1064   } catch (filters::parse_exception e) { 
    1065     message = e.getMessage(); 
    1066     return NSCAPI::returnUNKNOWN; 
    1067   } catch (filters::filter_exception e) { 
    1068     message = e.getMessage(); 
    1069     return NSCAPI::returnUNKNOWN; 
    1070   } 
    1071   finder.syntax = syntax; 
    1072   NSC_error errors; 
    1073   for (std::list<std::wstring>::const_iterator pit = paths.begin(); pit != paths.end(); ++pit) { 
    1074     pattern_type path = split_pattern(*pit); 
    1075     recursive_scan<file_filter_function>(path.first, path.second, 0, max_dir_depth, finder, &errors, debug); 
    1076     if (errors.has_error()) { 
    1077       if (show_errors_) 
    1078         message = errors.get_error(); 
    1079       else 
    1080         message = _T("Check contains error. Check log for details (or enable show_errors in nsc.ini)"); 
    1081       return NSCAPI::returnUNKNOWN; 
    1082     } 
    1083   } 
    1084   message = finder.message; 
    1085   if (!alias.empty()) 
    1086     query.alias = alias; 
    1087   else 
    1088     query.alias = finder.alias; 
    1089   if (query.alias.empty()) 
    1090     query.alias = _T("no files found"); 
    1091   query.runCheck(finder.hit_count, returnCode, message, perf); 
    1092   if ((truncate > 0) && (message.length() > (truncate-4))) 
    1093     message = message.substr(0, truncate-4) + _T("..."); 
    1094   if (message.empty()) 
    1095     message = _T("CheckFile ok"); 
    1096   return returnCode; 
    1097 } 
    10981023 
    10991024#define MAP_FILTER(value, obj) \ 
     
    11051030      finder.filter_chain.push_back(filteritem_type(file_filter_function_ex::filter_normal, filter)); } 
    11061031 
    1107 NSCAPI::nagiosReturn CheckDisk::CheckFile2(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 
     1032NSCAPI::nagiosReturn CheckDisk::CheckFile2(std::list<std::wstring> args, std::wstring &message, std::wstring &perf) { 
    11081033  NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 
    1109   std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 
    11101034  typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsUInteger> CheckFileContainer; 
    11111035  typedef std::pair<int,file_filter> filteritem_type; 
    11121036  typedef std::list<filteritem_type > filterlist_type; 
    1113   if (stl_args.empty()) { 
     1037  if (args.empty()) { 
    11141038    message = _T("Missing argument(s)."); 
    11151039    return NSCAPI::returnUNKNOWN; 
     
    11301054 
    11311055  try { 
    1132     MAP_OPTIONS_BEGIN(stl_args) 
     1056    MAP_OPTIONS_BEGIN(args) 
    11331057      MAP_OPTIONS_NUMERIC_ALL(query, _T("")) 
    11341058      MAP_OPTIONS_STR2INT(_T("truncate"), truncate) 
     
    12881212 
    12891213 
    1290 NSCAPI::nagiosReturn CheckDisk::CheckSingleFile(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 
     1214NSCAPI::nagiosReturn CheckDisk::CheckSingleFile(std::list<std::wstring> args, std::wstring &message, std::wstring &perf) { 
    12911215  NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 
    1292   std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 
    12931216  check_file_multi checker; 
    12941217  typedef std::pair<int,file_filter> filteritem_type; 
    12951218  typedef std::list<filteritem_type > filterlist_type; 
    1296   if (stl_args.empty()) { 
     1219  if (args.empty()) { 
    12971220    message = _T("Missing argument(s)."); 
    12981221    return NSCAPI::returnUNKNOWN; 
     
    13051228 
    13061229  try { 
    1307     MAP_OPTIONS_BEGIN(stl_args) 
     1230    MAP_OPTIONS_BEGIN(args) 
    13081231      //MAP_OPTIONS_NUMERIC_ALL(query, _T("")) 
    13091232      MAP_OPTIONS_STR2INT(_T("truncate"), truncate) 
     
    13511274  return returnCode; 
    13521275} 
    1353 NSCAPI::nagiosReturn CheckDisk::handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &msg, std::wstring &perf) { 
     1276NSCAPI::nagiosReturn CheckDisk::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 
    13541277  if (command == _T("CheckFileSize")) { 
    1355     return CheckFileSize(argLen, char_args, msg, perf); 
     1278    return CheckFileSize(arguments, message, perf); 
    13561279  } else if (command == _T("CheckDriveSize")) { 
    1357     return CheckDriveSize(argLen, char_args, msg, perf); 
    1358   } else if (command == _T("CheckFile")) { 
    1359     return CheckFile(argLen, char_args, msg, perf); 
     1280    return CheckDriveSize(arguments, message, perf); 
    13601281  } else if (command == _T("CheckFile2")) { 
    1361     return CheckFile2(argLen, char_args, msg, perf); 
     1282    return CheckFile2(arguments, message, perf); 
    13621283  } else if (command == _T("CheckSingleFile")) { 
    1363     return CheckSingleFile(argLen, char_args, msg, perf); 
     1284    return CheckSingleFile(arguments, message, perf); 
    13641285  } else if (command == _T("getFileAge")) { 
    1365     return getFileAge(argLen, char_args, msg, perf); 
     1286    return getFileAge(arguments, message, perf); 
    13661287  }  
    13671288  return NSCAPI::returnIgnored; 
     
    13691290 
    13701291 
     1292NSC_WRAP_DLL(); 
    13711293NSC_WRAPPERS_MAIN_DEF(gCheckDisk); 
    13721294NSC_WRAPPERS_IGNORE_MSG_DEF(); 
  • branches/stable/modules/CheckDisk/CheckDisk.h

    r261 r281  
    2525#include <checkHelpers.hpp> 
    2626 
    27 class CheckDisk { 
     27class CheckDisk : public nscapi::impl::SimpleCommand { 
    2828private: 
    2929  bool show_errors_; 
     
    3434  // Module calls 
    3535  bool loadModule(); 
     36  bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 
    3637  bool unloadModule(); 
    3738 
     
    4243    return _T("CheckDisk can check various file and disk related things.\nThe current version has commands to check Size of hard drives and directories."); 
    4344  } 
    44   NSCModuleWrapper::module_version getModuleVersion() { 
    45     NSCModuleWrapper::module_version version = {0, 0, 1 }; 
     45  nscapi::plugin_wrapper::module_version getModuleVersion() { 
     46    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    4647    return version; 
    4748  } 
     
    5051  bool hasMessageHandler(); 
    5152  std::wstring get_filter(unsigned int drvType); 
    52   NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 
     53  NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 
    5354 
    5455  // Check commands 
    55   NSCAPI::nagiosReturn CheckFileSize(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 
    56   NSCAPI::nagiosReturn CheckDriveSize(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 
    57   NSCAPI::nagiosReturn CheckFile(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 
    58   NSCAPI::nagiosReturn CheckFile2(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 
    59   NSCAPI::nagiosReturn getFileAge(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 
    60   NSCAPI::nagiosReturn CheckSingleFile(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 
     56  NSCAPI::nagiosReturn CheckFileSize(std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf); 
     57  NSCAPI::nagiosReturn CheckDriveSize(std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf); 
     58  NSCAPI::nagiosReturn CheckFile2(std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf); 
     59  NSCAPI::nagiosReturn getFileAge(std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf); 
     60  NSCAPI::nagiosReturn CheckSingleFile(std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf); 
    6161 
    6262private: 
  • branches/stable/modules/CheckDisk/stdafx.h

    r75 r281  
    2121#pragma once 
    2222 
     23 
    2324#define WIN32_LEAN_AND_MEAN   // Exclude rarely-used stuff from Windows headers 
    2425// Windows Header Files: 
     
    2829#include <functional> 
    2930 
     31#include <boost/lexical_cast.hpp> 
     32 
     33#include <config.h> 
     34#include <unicode_char.hpp> 
     35#include <types.hpp> 
    3036#include <NSCAPI.h> 
    31 #include <NSCHelper.h> 
     37#include <nscapi/plugin.hpp> 
    3238 
    3339#ifdef MEMCHECK 
  • trunk/CMakeLists.txt

    r279 r281  
    201201  ${NSCP_INCLUDEDIR}/nscapi/nscapi_plugin_wrapper.cpp 
    202202  ${NSCP_INCLUDEDIR}/nscapi/nscapi_core_wrapper.cpp 
     203  ${NSCP_INCLUDEDIR}/nscapi/settings.cpp 
    203204) 
    204205 
     
    208209  ${NSCP_INCLUDEDIR}/utils.h 
    209210  ${NSCP_INCLUDEDIR}/NSCAPI.h 
    210   ${NSCP_INCLUDEDIR}/nscapi/macros.hpp 
     211# ${NSCP_INCLUDEDIR}/nscapi/macros.hpp 
    211212  ${NSCP_INCLUDEDIR}/nscapi/nscapi_helper.hpp 
    212213  ${NSCP_INCLUDEDIR}/nscapi/nscapi_plugin_wrapper.hpp  
    213214  ${NSCP_INCLUDEDIR}/nscapi/nscapi_core_wrapper.hpp 
     215  ${NSCP_INCLUDEDIR}/nscapi/settings.hpp 
    214216) 
    215217 
     
    254256 
    255257SET(ALL_MODULE_NAMES) 
    256 FILE(GLOB ALL_MODULES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "modules/*/CMakeLists.txt") 
     258SET(BUILD_MODULE 0) 
     259SET(BUILD_MODULE_SKIP_REASON "") 
     260FILE(GLOB ALL_MODULES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "modules/*/module.cmake") 
    257261foreach(CURRENT_MODULE ${ALL_MODULES}) 
    258262  get_filename_component(CURRENT_MODULE_PATH ${CURRENT_MODULE} PATH) 
    259263  get_filename_component(CURRENT_MODULE_NAME ${CURRENT_MODULE_PATH} NAME) 
    260   message(STATUS "Adding module: ${CURRENT_MODULE_PATH} (${CURRENT_MODULE_NAME})") 
    261   ADD_SUBDIRECTORY("${CURRENT_MODULE_PATH}") 
    262   SET(ALL_MODULE_NAMES ${ALL_MODULE_NAMES} ${CURRENT_MODULE_NAME}) 
     264  include(${CURRENT_MODULE}) 
     265  IF(BUILD_MODULE) 
     266    message(STATUS "+ Module ${CURRENT_MODULE_NAME}: Added") 
     267    ADD_SUBDIRECTORY("${CURRENT_MODULE_PATH}") 
     268    SET(ALL_MODULE_NAMES ${ALL_MODULE_NAMES} ${CURRENT_MODULE_NAME}) 
     269  ELSE(BUILD_MODULE) 
     270    message(STATUS "- Module ${CURRENT_MODULE_NAME}: Skipped ${BUILD_MODULE_SKIP_REASON}") 
     271  ENDIF(BUILD_MODULE) 
     272   
     273  #ADD_SUBDIRECTORY("${CURRENT_MODULE_PATH}") 
     274  #SET(ALL_MODULE_NAMES ${ALL_MODULE_NAMES} ${CURRENT_MODULE_NAME}) 
    263275endforeach(CURRENT_MODULE ${ALL_MODULES}) 
    264276 
  • trunk/include/NSCAPI.h

    r257 r281  
    122122    typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationVersionStr)(wchar_t*,unsigned int); 
    123123    typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsString)(const wchar_t*,const wchar_t*,const wchar_t*,wchar_t*,unsigned int); 
     124    typedef NSCAPI::errorReturn (*lpNSAPIExpandPath)(const wchar_t*,wchar_t*,unsigned int); 
    124125    typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsInt)(const wchar_t*, const wchar_t*, int); 
    125126    typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSection)(const wchar_t*, wchar_t***, unsigned int *); 
     
    154155  namespace plugin_api { 
    155156    typedef int (*lpModuleHelperInit)(unsigned int, ::nscapi::core_api::lpNSAPILoader f); 
    156     typedef int (*lpLoadModule)(int); 
     157    typedef int (*lpLoadModule)(const wchar_t*,int); 
    157158    typedef int (*lpGetName)(wchar_t*,unsigned int); 
    158159    typedef int (*lpGetDescription)(wchar_t*,unsigned int); 
  • trunk/include/config.h.in

    r217 r281  
    7272 
    7373#define DATE_FORMAT _T("%#c") 
     74 
     75 
     76#define DEFAULT_CONF_LOCATION _T("ini") 
     77#define DEFAULT_CONF_OLD_LOCATION _T("old://${exe-path}/nsc.ini") 
     78 
     79/* 
     80#;location=old://${exe-path}/nsc.ini 
     81#location=ini://${exe-path}/nsclient.ini 
     82#;location=ini://${base-path}/nsclient.ini 
     83#;location=registry://HKEY_LOCAL_MACHINE/software/NSClient++ 
     84*/ 
     85 
    7486 
    7587 
  • trunk/include/file_helpers.hpp

    r226 r281  
    77  public: 
    88    static bool is_directory(std::wstring path) { 
    9       boost::filesystem::is_directory(path); 
     9      return boost::filesystem::is_directory(path); 
    1010    } 
    1111//    static bool is_directory(DWORD dwAtt) { 
     
    3737  }; 
    3838 
     39  class meta { 
     40  public: 
     41    static boost::filesystem::wpath get_path(boost::filesystem::wpath path) { 
     42      return path.branch_path(); 
     43    } 
     44    static std::wstring get_filename(boost::filesystem::wpath path) { 
     45      return path.leaf(); 
     46    } 
     47    static std::wstring get_path(std::wstring file) { 
     48      boost::filesystem::wpath path = file; 
     49      return path.branch_path().string(); 
     50    } 
     51    static std::wstring get_filename(std::wstring file) { 
     52      boost::filesystem::wpath path = file; 
     53      return path.leaf(); 
     54    } 
     55  }; 
     56 
    3957  class patterns { 
    4058  public: 
  • trunk/include/nrpe/server/handler.hpp

    r278 r281  
    1919      virtual unsigned int get_payload_length() = 0; 
    2020      virtual void set_payload_length(unsigned int payload) = 0; 
     21      virtual void set_allow_arguments(bool) = 0; 
     22      virtual void set_allow_nasty_arguments(bool) = 0; 
     23      virtual void set_perf_data(bool) = 0; 
    2124 
    2225    }; 
  • trunk/include/nrpe/server/server.cpp

    r280 r281  
    1212 
    1313    namespace ip = boost::asio::ip; 
     14 
     15 
     16    const int server::connection_info::backlog_default = 0; 
    1417 
    1518    server::server(connection_info info) 
     
    2730      ip::tcp::resolver::iterator endpoint_iterator; 
    2831      if (info.address.empty()) { 
    29         endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info.port)); 
     32        endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info.get_port())); 
    3033      } else { 
    31         endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info.address, info.port)); 
     34        endpoint_iterator = resolver.resolve(ip::tcp::resolver::query(info.get_address(), info.port)); 
    3235      } 
    3336      ip::tcp::resolver::iterator end; 
     
    3942        SSL_CTX_set_cipher_list(context_.impl(), "ADH"); 
    4043        request_handler_->log_debug(__FILEW__, __LINE__, _T("Using cert: ") + to_wstring(info.certificate)); 
    41         context_.use_tmp_dh_file(info.certificate); 
     44        context_.use_tmp_dh_file(to_string(info.certificate)); 
    4245        context_.set_verify_mode(boost::asio::ssl::context::verify_none); 
    4346      } 
     
    4952      acceptor_.set_option(ip::tcp::acceptor::reuse_address(true)); 
    5053      acceptor_.bind(endpoint); 
    51       acceptor_.listen(); 
     54      if (info.back_log == connection_info::backlog_default) 
     55        acceptor_.listen(); 
     56      else 
     57        acceptor_.listen(info.back_log); 
    5258 
    5359      acceptor_.async_accept(new_connection_->socket(), 
  • trunk/include/nrpe/server/server.hpp

    r280 r281  
    3636    public: 
    3737      struct connection_info { 
    38         connection_info(boost::shared_ptr<nrpe::server::handler> request_handler_) : request_handler(request_handler_) {} 
     38        static const int backlog_default; 
     39        connection_info(boost::shared_ptr<nrpe::server::handler> request_handler_) : request_handler(request_handler_), back_log(backlog_default) {} 
    3940        std::string address; 
    40         std::string port; 
    41         std::size_t thread_pool_size; 
     41        unsigned int port; 
     42        std::string get_port() { return to_string(port); } 
     43        std::string get_address() { return to_string(address); } 
     44        unsigned int thread_pool_size; 
     45        int back_log; 
    4246        bool use_ssl; 
     47        bool allow_args; 
     48        bool allow_nasty; 
     49        unsigned int timeout; 
    4350        boost::shared_ptr<nrpe::server::handler> request_handler; 
    44         std::string certificate; 
     51        std::wstring certificate; 
    4552        std::wstring get_endpoint_str() { 
    4653          return to_wstring(address) + _T(":") + to_wstring(port); 
  • trunk/include/nscapi/macros.hpp

    r278 r281  
    66#define NSC_WRAPPERS_MAIN() \ 
    77  extern "C" int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f); \ 
    8   extern "C" int NSLoadModule(int mode); \ 
     8  extern "C" int NSLoadModule(); \ 
     9  extern "C" int NSLoadModuleEx(const wchar_t alias, int mode); \ 
    910  extern "C" void NSDeleteBuffer(char**buffer); \ 
    1011  extern "C" int NSGetModuleName(wchar_t* buf, int buflen); \ 
     
    6364    } \ 
    6465  } \ 
    65   extern int NSLoadModule(int mode) { \ 
    66     try { \ 
    67       return GET_PLUGIN()->wrapLoadModule(toObject.loadModule(mode)); \ 
     66  extern int NSLoadModuleEx(wchar_t* alias, int mode) { \ 
     67  try { \ 
     68  return GET_PLUGIN()->wrapLoadModule(toObject.loadModuleEx(alias, mode)); \ 
    6869    } catch (nscapi::nscapi_exception e) { \ 
    69       NSC_LOG_CRITICAL(_T("NSCMHE in: wrapLoadModule: " + e.msg_)); \ 
    70       return NSCAPI::hasFailed; \ 
    71     } catch (...) { \ 
    72       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ 
    73       return NSCAPI::hasFailed; \ 
     70    NSC_LOG_CRITICAL(_T("NSCMHE in: wrapLoadModule: " + e.msg_)); \ 
     71    return NSCAPI::hasFailed; \ 
     72    } catch (...) { \ 
     73    NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ 
     74    return NSCAPI::hasFailed; \ 
     75    } \ 
     76  } \ 
     77  extern int NSLoadModule() { \ 
     78  try { \ 
     79  return GET_PLUGIN()->wrapLoadModule(toObject.loadModule()); \ 
     80    } catch (nscapi::nscapi_exception e) { \ 
     81    NSC_LOG_CRITICAL(_T("NSCMHE in: wrapLoadModule: " + e.msg_)); \ 
     82    return NSCAPI::hasFailed; \ 
     83    } catch (...) { \ 
     84    NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ 
     85    return NSCAPI::hasFailed; \ 
    7486    } \ 
    7587  } \ 
  • trunk/include/nscapi/nscapi_core_wrapper.cpp

    r277 r281  
    271271  wchar_t *buffer = new wchar_t[buf_len+1]; 
    272272  if (fNSAPIGetSettingsString(section.c_str(), key.c_str(), defaultValue.c_str(), buffer, buf_len) != NSCAPI::isSuccess) { 
     273    delete [] buffer; 
     274    throw nscapi::nscapi_exception(_T("Settings could not be retrieved.")); 
     275  } 
     276  std::wstring ret = buffer; 
     277  delete [] buffer; 
     278  return ret; 
     279} 
     280 
     281std::wstring nscapi::core_wrapper::expand_path(std::wstring value) { 
     282  if (!fNSAPIExpandPath) 
     283    throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 
     284  unsigned int buf_len = getBufferLength(); 
     285  wchar_t *buffer = new wchar_t[buf_len+1]; 
     286  if (fNSAPIExpandPath(value.c_str(), buffer, buf_len) != NSCAPI::isSuccess) { 
    273287    delete [] buffer; 
    274288    throw nscapi::nscapi_exception(_T("Settings could not be retrieved.")); 
     
    575589 
    576590  fNSAPISettingsSave = (nscapi::core_api::lpNSAPISettingsSave)f(_T("NSAPISettingsSave")); 
     591 
     592  fNSAPIExpandPath = (nscapi::core_api::lpNSAPIExpandPath)f(_T("NSAPIExpandPath")); 
    577593   
    578594  return true; 
  • trunk/include/nscapi/nscapi_core_wrapper.hpp

    r258 r281  
    4242    nscapi::core_api::lpNSAPIReleaseSettingsSectionBuffer fNSAPIReleaseSettingsSectionBuffer; 
    4343    nscapi::core_api::lpNSAPIGetSettingsString fNSAPIGetSettingsString; 
     44    nscapi::core_api::lpNSAPIExpandPath fNSAPIExpandPath; 
    4445    nscapi::core_api::lpNSAPIGetSettingsInt fNSAPIGetSettingsInt; 
    4546    nscapi::core_api::lpNSAPIMessage fNSAPIMessage; 
     
    111112      , fNSAPIReleasePluginList(NULL) 
    112113      , fNSAPISettingsSave(NULL) 
     114      , fNSAPIExpandPath(NULL) 
    113115      , buffer_length_(-1) 
    114116      , id_(-1) 
     
    120122    std::list<std::wstring> getSettingsSection(std::wstring section); 
    121123    std::wstring getSettingsString(std::wstring section, std::wstring key, std::wstring defaultValue); 
     124    std::wstring expand_path(std::wstring value); 
    122125    int getSettingsInt(std::wstring section, std::wstring key, int defaultValue); 
    123126    void settings_register_key(std::wstring path, std::wstring key, NSCAPI::settings_type type, std::wstring title, std::wstring description, std::wstring defaultValue, bool advanced); 
  • trunk/include/nscapi/nscapi_plugin_wrapper.hpp

    r277 r281  
    170170  namespace impl { 
    171171 
     172    class simple_plugin { 
     173    public: 
     174      nscapi::core_wrapper* get_core() { 
     175        return nscapi::plugin_singleton->get_core(); 
     176      } 
     177    }; 
     178 
    172179    class SimpleNotificationHandler { 
    173180    public: 
     
    220227        } 
    221228        std::wstring msg, perf; 
    222         NSCAPI::nagiosReturn ret = handleCommand(command, args, msg, perf); 
     229        NSCAPI::nagiosReturn ret = handleCommand(command.c_str(), args, msg, perf); 
    223230 
    224231        PluginCommand::ResponseMessage response_message; 
     
    239246      } 
    240247 
    241       virtual NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) = 0; 
     248      virtual NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) = 0; 
    242249    }; 
    243250 
  • trunk/include/nscapi/plugin.hpp

    r258 r281  
    22 
    33#include <nscapi/macros.hpp> 
     4#include <nscapi/settings.hpp> 
    45#include <nscapi/nscapi_helper.hpp> 
    56#include <nscapi/nscapi_plugin_wrapper.hpp> 
  • trunk/include/settings/Settings.h

    r244 r281  
    2929#include <boost/thread/locks.hpp> 
    3030#include <boost/filesystem/path.hpp> 
     31#include <boost/regex.hpp> 
    3132#include <strEx.h> 
    3233#define BUFF_LEN 4096 
     
    111112      ini_file, 
    112113      xml_file, 
     114      lua, 
    113115    } settings_type; 
    114116    typedef enum { 
     
    157159    /// @author mickem 
    158160    static settings_type string_to_type(std::wstring key) { 
    159       if (key == _T("ini")) 
     161      // detect location here!! 
     162      boost::wregex old(_T("old://.*nsc\.ini$"), boost::regex::icase); 
     163      boost::wregex ini(_T("ini://.*\.ini$"), boost::regex::icase); 
     164      boost::wregex reg(_T("registry://.*/$"), boost::regex::icase); 
     165      boost::wregex re_lua(_T("lua://.*\.lua$"), boost::regex::icase); 
     166      if (boost::regex_match(key, ini)) 
    160167        return ini_file; 
    161       if (key == _T("registry")) 
     168      if (boost::regex_match(key, reg)) 
    162169        return registry; 
    163       if (key == _T("xml")) 
    164         return xml_file; 
     170      if (boost::regex_match(key, re_lua)) 
     171        return lua; 
    165172      return old_ini_file; 
    166173    } 
     
    12961303    path_cache_type path_cache_; 
    12971304    std::wstring context_; 
     1305    net::url url_; 
    12981306 
    12991307    //SettingsInterfaceImpl() : core_(NULL) {} 
    1300     SettingsInterfaceImpl(SettingsCore *core, std::wstring context) : core_(core), context_(context) {} 
     1308    SettingsInterfaceImpl(SettingsCore *core, std::wstring context) : core_(core), context_(context), url_(net::parse(context_)) {} 
    13011309 
    13021310    ////////////////////////////////////////////////////////////////////////// 
     
    16121620      return context_; 
    16131621    } 
     1622    virtual std::wstring get_file_name_from_context() { 
     1623      return url_.path; 
     1624    } 
     1625    virtual std::wstring find_file() { 
     1626      return core_->find_file(url_.path); 
     1627    } 
     1628 
    16141629    ////////////////////////////////////////////////////////////////////////// 
    16151630    /// Set the context. 
  • trunk/include/settings/macros.h

    r278 r281  
    148148  namespace nrpe { 
    149149    DEFINE_PATH(SECTION, NRPE_SECTION_PROTOCOL); 
    150     DESCRIBE_SETTING(SECTION, "NRPE SECTION", "Section for NRPE (NRPEListener.dll) (check_nrpe) protocol options."); 
     150    //DESCRIBE_SETTING(SECTION, "NRPE SECTION", "Section for NRPE (NRPEListener.dll) (check_nrpe) protocol options."); 
    151151 
    152152     
     
    158158 
    159159    DEFINE_SETTING_I(PORT, NRPE_SECTION_PROTOCOL, "port", 5666); 
    160     DESCRIBE_SETTING(PORT, "NSCLIENT PORT NUMBER", "This is the port the NSClientListener.dll will listen to."); 
     160    //DESCRIBE_SETTING(PORT, "NSCLIENT PORT NUMBER", "This is the port the NSClientListener.dll will listen to."); 
    161161 
    162162    DEFINE_SETTING_S(BINDADDR, NRPE_SECTION_PROTOCOL, GENERIC_KEY_BIND_TO, ""); 
    163     DESCRIBE_SETTING(BINDADDR, "BIND TO ADDRESS", "Allows you to bind server to a specific local address. This has to be a dotted ip adress not a hostname. Leaving this blank will bind to all avalible IP adresses."); 
     163    //DESCRIBE_SETTING(BINDADDR, "BIND TO ADDRESS", "Allows you to bind server to a specific local address. This has to be a dotted ip adress not a hostname. Leaving this blank will bind to all avalible IP adresses."); 
    164164 
    165165    DEFINE_SETTING_I(READ_TIMEOUT, NRPE_SECTION_PROTOCOL, GENERIC_KEY_SOCK_READ_TIMEOUT, 30); 
    166     DESCRIBE_SETTING(READ_TIMEOUT, "SOCKET TIMEOUT", "Timeout when reading packets on incoming sockets. If the data has not arrived withint this time we will bail out."); 
     166    //DESCRIBE_SETTING(READ_TIMEOUT, "SOCKET TIMEOUT", "Timeout when reading packets on incoming sockets. If the data has not arrived withint this time we will bail out."); 
    167167 
    168168    DEFINE_SETTING_I(LISTENQUE, NRPE_SECTION_PROTOCOL, GENERIC_KEY_SOCK_LISTENQUE, 0); 
    169     DESCRIBE_SETTING_ADVANCED(LISTENQUE, "LISTEN QUEUE", "Number of sockets to queue before starting to refuse new incoming connections. This can be used to tweak the amount of simultaneous sockets that the server accepts."); 
     169    //DESCRIBE_SETTING_ADVANCED(LISTENQUE, "LISTEN QUEUE", "Number of sockets to queue before starting to refuse new incoming connections. This can be used to tweak the amount of simultaneous sockets that the server accepts."); 
     170 
     171    DEFINE_SETTING_I(THREAD_POOL, NRPE_SECTION_PROTOCOL, "thread pool", 10); 
     172    //DESCRIBE_SETTING_ADVANCED(THREAD_POOL, "THREAD POOL", ""); 
     173 
     174     
    170175 
    171176    DEFINE_SETTING_B(CACHE_ALLOWED, NRPE_SECTION_PROTOCOL, GENERIC_KEY_SOCK_CACHE_ALLOWED, false); 
     
    173178 
    174179    DEFINE_SETTING_B(KEYUSE_SSL, NRPE_SECTION_PROTOCOL, GENERIC_KEY_USE_SSL, true); 
    175     DESCRIBE_SETTING(KEYUSE_SSL, "USE SSL SOCKET", "This option controls if SSL should be used on the socket."); 
     180    //DESCRIBE_SETTING(KEYUSE_SSL, "USE SSL SOCKET", "This option controls if SSL should be used on the socket."); 
    176181 
    177182    DEFINE_SETTING_I(PAYLOAD_LENGTH, NRPE_SECTION_PROTOCOL, "payload length", 1024); 
    178     DESCRIBE_SETTING_ADVANCED(PAYLOAD_LENGTH, "PAYLOAD LENGTH", "Length of payload to/from the NRPE agent. This is a hard specific value so you have to \"configure\" (read recompile) your NRPE agent to use the same value for it to work."); 
     183    //DESCRIBE_SETTING_ADVANCED(PAYLOAD_LENGTH, "PAYLOAD LENGTH", "Length of payload to/from the NRPE agent. This is a hard specific value so you have to \"configure\" (read recompile) your NRPE agent to use the same value for it to work."); 
    179184 
    180185    DEFINE_SETTING_B(ALLOW_PERFDATA, NRPE_SECTION, "performance data", true); 
    181     DESCRIBE_SETTING_ADVANCED(ALLOW_PERFDATA, "PERFORMANCE DATA", "Send performance data back to nagios (set this to 0 to remove all performance data)."); 
    182  
    183     DEFINE_SETTING_S(SCRIPT_PATH, NRPE_SECTION, "script path", ""); 
    184     DESCRIBE_SETTING_ADVANCED(SCRIPT_PATH, "SCRIPT DIRECTORY", "Load all scripts in a directory and use them as commands. Probably dangerous but usefull if you have loads of scripts :)"); 
     186    //DESCRIBE_SETTING_ADVANCED(ALLOW_PERFDATA, "PERFORMANCE DATA", "Send performance data back to nagios (set this to 0 to remove all performance data)."); 
    185187 
    186188    DEFINE_SETTING_I(CMD_TIMEOUT, NRPE_SECTION, "command timeout", 60); 
    187     DESCRIBE_SETTING(CMD_TIMEOUT, "COMMAND TIMEOUT", "This specifies the maximum number of seconds that the NRPE daemon will allow plug-ins to finish executing before killing them off."); 
     189    //DESCRIBE_SETTING(CMD_TIMEOUT, "COMMAND TIMEOUT", "This specifies the maximum number of seconds that the NRPE daemon will allow plug-ins to finish executing before killing them off."); 
    188190 
    189191    DEFINE_SETTING_B(ALLOW_ARGS, NRPE_SECTION, "allow arguments", false); 
    190     DESCRIBE_SETTING(ALLOW_ARGS, "COMMAND ARGUMENT PROCESSING", "This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed."); 
     192    //DESCRIBE_SETTING(ALLOW_ARGS, "COMMAND ARGUMENT PROCESSING", "This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed."); 
    191193 
    192194    DEFINE_SETTING_B(ALLOW_NASTY, NRPE_SECTION, "allow nasy characters", false); 
    193     DESCRIBE_SETTING(ALLOW_NASTY, "COMMAND ALLOW NASTY META CHARS", "This option determines whether or not the NRPE daemon will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments."); 
    194  
    195     DEFINE_PATH(SECTION_HANDLERS, NRPE_SECTION_HANDLERS); 
    196     DESCRIBE_SETTING(SECTION_HANDLERS, "NRPE COMMAND DEFINITIONS -- DEPRECATED", "Command definitions that this daemon will run (it will also run all internal commands such as those from ther ExternalScriptModule)."); 
     195    //DESCRIBE_SETTING(ALLOW_NASTY, "COMMAND ALLOW NASTY META CHARS", "This option determines whether or not the NRPE daemon will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments."); 
    197196 
    198197  } 
     
    233232  namespace external_scripts { 
    234233    DEFINE_PATH(SECTION, EXTSCRIPT_SECTION); 
    235     DESCRIBE_SETTING(SECTION, "EXTERNAL SCRIPT SECTION", "Section for external scripts (CheckExternalScripts.dll)."); 
     234    //DESCRIBE_SETTING(SECTION, "EXTERNAL SCRIPT SECTION", "Section for external scripts (CheckExternalScripts.dll)."); 
    236235 
    237236    DEFINE_SETTING_I(TIMEOUT, EXTSCRIPT_SECTION, "timeout", 60); 
    238     DESCRIBE_SETTING(TIMEOUT, "COMMAND TIMEOUT", "The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones."); 
     237    //DESCRIBE_SETTING(TIMEOUT, "COMMAND TIMEOUT", "The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones."); 
    239238 
    240239    DEFINE_SETTING_B(ALLOW_ARGS, EXTSCRIPT_SECTION, "allow arguments", false); 
    241     DESCRIBE_SETTING(ALLOW_ARGS, "COMMAND ARGUMENT PROCESSING", "This option determines whether or not the we will allow clients to specify arguments to commands that are executed."); 
     240    //DESCRIBE_SETTING(ALLOW_ARGS, "COMMAND ARGUMENT PROCESSING", "This option determines whether or not the we will allow clients to specify arguments to commands that are executed."); 
    242241 
    243242    DEFINE_SETTING_B(ALLOW_NASTY, EXTSCRIPT_SECTION, "allow nasy characters", false); 
    244     DESCRIBE_SETTING(ALLOW_NASTY, "COMMAND ALLOW NASTY META CHARS", "This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments."); 
     243    //DESCRIBE_SETTING(ALLOW_NASTY, "COMMAND ALLOW NASTY META CHARS", "This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments."); 
    245244 
    246245    DEFINE_SETTING_S(SCRIPT_PATH, EXTSCRIPT_SECTION, "script path", ""); 
    247     DESCRIBE_SETTING_ADVANCED(SCRIPT_PATH, "SCRIPT DIRECTORY", "Load all scripts in a directory and use them as commands. Probably dangerous but usefull if you have loads of scripts :)"); 
     246    //DESCRIBE_SETTING_ADVANCED(SCRIPT_PATH, "SCRIPT DIRECTORY", "Load all scripts in a directory and use them as commands. Probably dangerous but usefull if you have loads of scripts :)"); 
    248247 
    249248    DEFINE_PATH(SCRIPT_SECTION, EXTSCRIPT_SCRIPT_SECTION); 
    250     DESCRIBE_SETTING(SCRIPT_SECTION, "EXTERNAL SCRIPT SCRIPTS SECTION", "A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments> for instance:"); 
     249    //DESCRIBE_SETTING(SCRIPT_SECTION, "EXTERNAL SCRIPT SCRIPTS SECTION", "A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments> for instance:"); 
    251250 
    252251    DEFINE_PATH(ALIAS_SECTION, EXTSCRIPT_ALIAS_SECTION); 
    253     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)"); 
     252    //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)"); 
    254253 
    255254    DEFINE_PATH(WRAPPINGS_SECTION, EXTSCRIPT_WRAPPINGS_SECTION); 
    256     DESCRIBE_SETTING(WRAPPINGS_SECTION, "EXTERNAL SCRIPT WRAPPINGS SECTION", ""); 
     255    //DESCRIBE_SETTING(WRAPPINGS_SECTION, "EXTERNAL SCRIPT WRAPPINGS SECTION", ""); 
    257256 
    258257    DEFINE_PATH(WRAPPED_SCRIPT, EXTSCRIPT_WRAPPED_SCRIPT); 
    259     DESCRIBE_SETTING(WRAPPED_SCRIPT, "EXTERNAL SCRIPT WRAPPINGS SECTION", ""); 
     258    //DESCRIBE_SETTING(WRAPPED_SCRIPT, "EXTERNAL SCRIPT WRAPPINGS SECTION", ""); 
    260259 
    261260  } 
  • trunk/include/settings/settings_ini.hpp

    r244 r281  
    77#include <boost/filesystem/operations.hpp> 
    88 
    9 #include <settings/Settings.h> 
     9#include <settings/settings_core.hpp> 
     10#include <settings/settings_core_impl.hpp> 
    1011#include <simpleini/simpleini.h> 
    1112#include <error.hpp> 
    1213 
    13 namespace Settings { 
    14   class INISettings : public Settings::SettingsInterfaceImpl { 
     14namespace settings { 
     15  class INISettings : public settings::SettingsInterfaceImpl { 
    1516  private: 
    1617    boost::filesystem::wpath filename_; 
     
    1920 
    2021  public: 
    21     INISettings(Settings::SettingsCore *core, std::wstring context) : ini(false, false, false), is_loaded_(false), Settings::SettingsInterfaceImpl(core, context) {} 
     22    INISettings(settings::settings_core *core, std::wstring context) : ini(false, false, false), is_loaded_(false), settings::SettingsInterfaceImpl(core, context) { 
     23      load_data(); 
     24    } 
    2225    ////////////////////////////////////////////////////////////////////////// 
    2326    /// Create a new settings interface of "this kind" 
     
    3841    /// 
    3942    /// @author mickem 
    40     virtual std::wstring get_real_string(SettingsCore::key_path_type key) { 
     43    virtual std::wstring get_real_string(settings_core::key_path_type key) { 
    4144      load_data(); 
    4245      const wchar_t *val = ini.GetValue(key.first.c_str(), key.second.c_str(), NULL); 
     
    5356    /// 
    5457    /// @author mickem 
    55     virtual int get_real_int(SettingsCore::key_path_type key) { 
     58    virtual int get_real_int(settings_core::key_path_type key) { 
    5659      std::wstring str = get_real_string(key); 
    5760      return strEx::stoi(str); 
     
    6568    /// 
    6669    /// @author mickem 
    67     virtual bool get_real_bool(SettingsCore::key_path_type key) { 
     70    virtual bool get_real_bool(settings_core::key_path_type key) { 
    6871      std::wstring str = get_real_string(key); 
    6972      return SettingsInterfaceImpl::string_to_bool(str); 
     
    7780    /// 
    7881    /// @author mickem 
    79     virtual bool has_real_key(SettingsCore::key_path_type key) { 
     82    virtual bool has_real_key(settings_core::key_path_type key) { 
    8083      return ini.GetValue(key.first.c_str(), key.second.c_str()) != NULL; 
    8184    } 
     
    8689    /// 
    8790    /// @author mickem 
    88     virtual SettingsCore::settings_type get_type() { 
    89       return SettingsCore::ini_file; 
    90     } 
     91//    virtual settings_core::settings_type get_type() { 
     92//      return settings_core::ini_file; 
     93//    } 
    9194    ////////////////////////////////////////////////////////////////////////// 
    9295    /// Is this the active settings store 
     
    9598    /// 
    9699    /// @author mickem 
    97     virtual bool is_active() { 
    98       return true; 
    99     } 
     100//    virtual bool is_active() { 
     101//      return true; 
     102//    } 
    100103    ////////////////////////////////////////////////////////////////////////// 
    101104    /// Write a value to the resulting context. 
     
    105108    /// 
    106109    /// @author mickem 
    107     virtual void set_real_value(SettingsCore::key_path_type key, conainer value) { 
     110    virtual void set_real_value(settings_core::key_path_type key, conainer value) { 
    108111      try { 
    109         const SettingsCore::key_description desc = get_core()->get_registred_key(key.first, key.second); 
     112        const settings_core::key_description desc = get_core()->get_registred_key(key.first, key.second); 
    110113        std::wstring comment = _T("; "); 
    111114        if (!desc.title.empty()) 
     
    120123      } catch (KeyNotFoundException e) { 
    121124        ini.SetValue(key.first.c_str(), key.second.c_str(), value.get_string().c_str(), _T("; Undocumented key")); 
    122       } catch (SettingsException e) { 
     125      } catch (settings_exception e) { 
    123126        get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Failed to write key: ") + e.getError())); 
    124127      } catch (...) { 
     
    130133      try { 
    131134        get_core()->get_logger()->quick_debug(_T("Setting path: ") + path); 
    132         const SettingsCore::path_description desc = get_core()->get_registred_path(path); 
     135        const settings_core::path_description desc = get_core()->get_registred_path(path); 
    133136        if (!desc.description.empty()) { 
    134137          std::wstring comment = _T("; ") + desc.description; 
     
    137140      } catch (KeyNotFoundException e) { 
    138141        ini.SetValue(path.c_str(), NULL, NULL, _T("; Undocumented section")); 
    139       } catch (SettingsException e) { 
     142      } catch (settings_exception e) { 
    140143        get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Failed to write section: ") + e.getError())); 
    141144      } catch (...) { 
     
    211214        throw_SI_error(rc, _T("Failed to save file")); 
    212215    } 
    213     virtual SettingsCore::key_type get_key_type(std::wstring path, std::wstring key) { 
    214       return SettingsCore::key_string; 
     216    virtual settings_core::key_type get_key_type(std::wstring path, std::wstring key) { 
     217      return settings_core::key_string; 
    215218    } 
    216219  private: 
     
    225228      if (rc < 0) 
    226229        throw_SI_error(rc, _T("Failed to load file")); 
     230 
     231      CSimpleIni::TNamesDepend lst; 
     232      ini.GetAllKeys(_T("/includes"), lst); 
     233      for (CSimpleIni::TNamesDepend::const_iterator cit = lst.begin(); cit != lst.end(); ++cit) { 
     234        add_child(ini.GetValue(_T("/includes"), (*cit).pItem)); 
     235      } 
    227236      is_loaded_ = true; 
    228237    } 
     
    235244      if (err == SI_FILE) 
    236245        error_str = _T("I/O error: ") + error::lookup::last_error(); 
    237       throw SettingsException(msg + _T(": ") + get_context() + _T(" - ") + error_str); 
     246      throw settings_exception(msg + _T(": ") + get_context() + _T(" - ") + error_str); 
    238247    } 
    239248    boost::filesystem::wpath get_file_name() { 
    240249      if (filename_.empty()) { 
    241         filename_ = get_core()->get_base() / boost::filesystem::wpath(get_core()->get_boot_string(get_context(), _T("file"), _T("nsclient.ini"))); 
     250        filename_ = get_file_from_context(); 
     251        //filename_ = get_core()->get_base() / boost::filesystem::wpath(get_core()->get_boot_string(get_context(), _T("file"), _T("nsclient.ini"))); 
    242252        get_core()->get_logger()->debug(__FILEW__, __LINE__, _T("Reading INI settings from: ") + filename_.string()); 
    243253      } 
     
    247257      return boost::filesystem::is_regular(get_file_name()); 
    248258    } 
     259    virtual std::wstring get_info() { 
     260      return _T("INI settings: (") + context_ + _T(", ") + get_file_name().string() + _T(")"); 
     261    } 
     262 
    249263  }; 
    250264} 
  • trunk/include/settings/settings_old.hpp

    r244 r281  
    33#include <string> 
    44#include <map> 
    5 #include <settings/Settings.h> 
     5#include <settings/settings_core.hpp> 
    66#include <simpleini/SimpleIni.h> 
    77#include <settings/macros.h> 
     
    1111#define MAIN_STRING_LENGTH _T("string_length") 
    1212 
    13 namespace Settings { 
    14   class OLDSettings : public Settings::SettingsInterfaceImpl { 
     13namespace settings { 
     14  class OLDSettings : public settings::SettingsInterfaceImpl { 
    1515    std::wstring filename_; 
    1616  public: 
    17     OLDSettings(Settings::SettingsCore *core, std::wstring context) :Settings::SettingsInterfaceImpl(core, context) { 
     17    OLDSettings(settings::settings_core *core, std::wstring context) : settings::SettingsInterfaceImpl(core, context) { 
    1818      add_mapping(MAIN_MODULES_SECTION, MAIN_MODULES_SECTION_OLD); 
    1919      add_mapping(setting_keys::settings_def::PAYLOAD_LEN_PATH, setting_keys::settings_def::PAYLOAD_LEN, MAIN_SECTION_TITLE, MAIN_STRING_LENGTH); 
     
    8080      SETTINGS_MAP_KEY_A(nrpe::PAYLOAD_LENGTH,NRPE_SECTION_TITLE, NRPE_SETTINGS_STRLEN); 
    8181      SETTINGS_MAP_KEY_A(nrpe::ALLOW_PERFDATA,NRPE_SECTION_TITLE, NRPE_SETTINGS_PERFDATA); 
    82       SETTINGS_MAP_KEY_A(nrpe::SCRIPT_PATH, NRPE_SECTION_TITLE, NRPE_SETTINGS_SCRIPTDIR); 
    8382      SETTINGS_MAP_KEY_A(nrpe::CMD_TIMEOUT, NRPE_SECTION_TITLE, NRPE_SETTINGS_TIMEOUT); 
    8483      SETTINGS_MAP_KEY_A(nrpe::ALLOW_ARGS,  NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS); 
    8584      SETTINGS_MAP_KEY_A(nrpe::ALLOW_NASTY, NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_NASTY_META); 
    86  
    87       SETTINGS_MAP_SECTION_A(nrpe::SECTION_HANDLERS,NRPE_HANDLER_SECTION_TITLE); 
    88  
    8985 
    9086#define NSCA_AGENT_SECTION_TITLE _T("NSCA Agent") 
     
    126122    } 
    127123    typedef std::map<std::wstring,std::wstring> path_map; 
    128     typedef std::map<SettingsCore::key_path_type,SettingsCore::key_path_type> key_map; 
     124    typedef std::map<settings_core::key_path_type,settings_core::key_path_type> key_map; 
    129125    path_map sections_; 
    130126    key_map keys_; 
     
    133129    } 
    134130    void add_mapping(std::wstring path_new, std::wstring key_new, std::wstring path_old, std::wstring key_old) { 
    135       SettingsCore::key_path_type new_key(path_new, key_new); 
    136       SettingsCore::key_path_type old_key(path_old, key_old); 
     131      settings_core::key_path_type new_key(path_new, key_new); 
     132      settings_core::key_path_type old_key(path_old, key_old); 
    137133      keys_[new_key] = old_key; 
    138134    } 
     
    144140      return (*it).second; 
    145141    } 
    146     SettingsCore::key_path_type map_key(SettingsCore::key_path_type new_key) { 
     142    settings_core::key_path_type map_key(settings_core::key_path_type new_key) { 
    147143      key_map::iterator it1 = keys_.find(new_key); 
    148144      if (it1 != keys_.end()) 
     
    150146      path_map::iterator it2 = sections_.find(new_key.first); 
    151147      if (it2 != sections_.end()) 
    152         return SettingsCore::key_path_type((*it2).second, new_key.second); 
     148        return settings_core::key_path_type((*it2).second, new_key.second); 
    153149      return new_key; 
    154150    } 
     
    171167    /// 
    172168    /// @author mickem 
    173     virtual std::wstring get_real_string(SettingsCore::key_path_type key) { 
     169    virtual std::wstring get_real_string(settings_core::key_path_type key) { 
    174170      key = map_key(key); 
    175171      get_core()->get_logger()->quick_debug(key.first + _T("//") + key.second); 
     
    182178      TCHAR* buffer = new TCHAR[bufferSize+2]; 
    183179      if (buffer == NULL) 
    184         throw SettingsException(_T("Out of memmory error!")); 
     180        throw settings_exception(_T("Out of memmory error!")); 
    185181      int retVal = GetPrivateProfileString(path.c_str(), key.c_str(), UNLIKELY_STRING, buffer, bufferSize, get_file_name().c_str()); 
    186182      if (retVal == bufferSize-1) { 
     
    207203    /// 
    208204    /// @author mickem 
    209     virtual int get_real_int(SettingsCore::key_path_type key) { 
     205    virtual int get_real_int(settings_core::key_path_type key) { 
    210206      std::wstring str = get_real_string(key); 
    211207      return strEx::stoi(str); 
     
    219215    /// 
    220216    /// @author mickem 
    221     virtual bool get_real_bool(SettingsCore::key_path_type key) { 
     217    virtual bool get_real_bool(settings_core::key_path_type key) { 
    222218      std::wstring str = get_real_string(key); 
    223219      return SettingsInterfaceImpl::string_to_bool(str); 
     
    231227    /// 
    232228    /// @author mickem 
    233     virtual bool has_real_key(SettingsCore::key_path_type key) { 
     229    virtual bool has_real_key(settings_core::key_path_type key) { 
    234230      return has_key_int(key.first, key.second); 
    235231    } 
     
    239235      TCHAR* buffer = new TCHAR[bufferLength+1]; 
    240236      if (buffer == NULL) 
    241         throw SettingsException(_T("has_key_int:: Failed to allocate memory for buffer!")); 
     237        throw settings_exception(_T("has_key_int:: Failed to allocate memory for buffer!")); 
    242238      std::wstring mapped = map_path(path); 
    243239      unsigned int count = ::GetPrivateProfileSection(mapped.c_str(), buffer, bufferLength-2, get_file_name().c_str()); 
     
    262258      return false; 
    263259    } 
    264     ////////////////////////////////////////////////////////////////////////// 
    265     /// Get the type this settings store represent. 
    266     /// 
    267     /// @return the type of settings store 
    268     /// 
    269     /// @author mickem 
    270     virtual SettingsCore::settings_type get_type() { 
    271       return SettingsCore::old_ini_file; 
    272     } 
    273     ////////////////////////////////////////////////////////////////////////// 
    274     /// Is this the active settings store 
    275     /// 
    276     /// @return 
    277     /// 
    278     /// @author mickem 
    279     virtual bool is_active() { 
    280       return true; 
    281     } 
     260 
    282261    ////////////////////////////////////////////////////////////////////////// 
    283262    /// Write a value to the resulting context. 
     
    287266    /// 
    288267    /// @author mickem 
    289     virtual void set_real_value(SettingsCore::key_path_type key, conainer value) { 
     268    virtual void set_real_value(settings_core::key_path_type key, conainer value) { 
    290269      try { 
    291270        key = map_key(key); 
    292271        get_core()->get_logger()->quick_debug(key.first + _T("//") + key.second + _T("//") + value.get_string()); 
    293272        WritePrivateProfileString(key.first.c_str(), key.second.c_str(), value.get_string().c_str(), get_file_name().c_str()); 
    294       } catch (SettingsException e) { 
     273      } catch (settings_exception e) { 
    295274        get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Failed to write key: ") + e.getError())); 
    296275      } catch (...) { 
     
    375354      TCHAR* buffer = new TCHAR[bufferLength+1]; 
    376355      if (buffer == NULL) 
    377         throw SettingsException(_T("getSections:: Failed to allocate memory for buffer!")); 
     356        throw settings_exception(_T("getSections:: Failed to allocate memory for buffer!")); 
    378357      unsigned int count = ::GetPrivateProfileSectionNames(buffer, BUFF_LEN, get_file_name().c_str()); 
    379358      if (count == bufferLength-2) { 
     
    405384      int_read_section(mapped_path, list); 
    406385      /* 
    407       Settings::SettingsCore::mapped_key_list_type mapped_keys = get_core()->find_maped_keys(path); 
    408       for (Settings::SettingsCore::mapped_key_list_type::const_iterator cit = mapped_keys.begin(); cit != mapped_keys.end(); ++cit) { 
     386      settings::settings_core::mapped_key_list_type mapped_keys = get_core()->find_maped_keys(path); 
     387      for (settings::settings_core::mapped_key_list_type::const_iterator cit = mapped_keys.begin(); cit != mapped_keys.end(); ++cit) { 
    409388        if (has_key((*cit).dst.first, (*cit).dst.second)) 
    410389          list.push_back((*cit).src.second); 
     
    412391      */ 
    413392    } 
    414     virtual SettingsCore::key_type get_key_type(std::wstring path, std::wstring key) { 
    415       return SettingsCore::key_string; 
     393    virtual settings_core::key_type get_key_type(std::wstring path, std::wstring key) { 
     394      return settings_core::key_string; 
    416395    } 
    417396  private: 
     
    428407      TCHAR* buffer = new TCHAR[bufferLength+1]; 
    429408      if (buffer == NULL) 
    430         throw SettingsException(_T("getSections:: Failed to allocate memory for buffer!")); 
     409        throw settings_exception(_T("getSections:: Failed to allocate memory for buffer!")); 
    431410      unsigned int count = GetPrivateProfileSection(section.c_str(), buffer, bufferLength, get_file_name().c_str()); 
    432411      if (count == bufferLength-2) { 
     
    452431    inline std::wstring get_file_name() { 
    453432      if (filename_.empty()) { 
    454         filename_ = (get_core()->get_base() / get_core()->get_boot_string(get_context(), _T("file"), _T("nsc.ini"))).string(); 
     433        filename_ = get_file_from_context(); 
     434        //filename_ = (get_core()->get_base() / get_core()->get_boot_string(get_context(), _T("file"), _T("nsc.ini"))).string(); 
    455435        get_core()->get_logger()->debug(__FILEW__, __LINE__, _T("Reading old settings from: ") + filename_); 
    456436      } 
     
    460440      return boost::filesystem::is_regular_file(get_file_name()); 
    461441    } 
     442    virtual std::wstring get_info() { 
     443      return _T("INI settings: (") + context_ + _T(", ") + get_file_name() + _T(")"); 
     444    } 
    462445  }; 
    463446} 
  • trunk/include/settings/settings_registry.hpp

    r244 r281  
    33#include <string> 
    44#include <windows.h> 
    5 #include <settings/Settings.h> 
     5#include <settings/settings_core.hpp> 
    66#include <msvc_wrappers.h> 
    77#include <error.hpp> 
     
    1010 
    1111 
    12 namespace Settings { 
    13   class REGSettings : public Settings::SettingsInterfaceImpl { 
     12namespace settings { 
     13  class REGSettings : public settings::SettingsInterfaceImpl { 
    1414  private: 
    1515    struct reg_key { 
     
    2626 
    2727  public: 
    28   REGSettings(Settings::SettingsCore *core, std::wstring context) : Settings::SettingsInterfaceImpl(core, context) {} 
     28  REGSettings(settings::settings_core *core, std::wstring context) : settings::SettingsInterfaceImpl(core, context) {} 
    2929 
    3030  virtual ~REGSettings(void) {} 
     
    4848  /// 
    4949  /// @author mickem 
    50   virtual std::wstring get_real_string(SettingsCore::key_path_type key) { 
     50  virtual std::wstring get_real_string(settings_core::key_path_type key) { 
    5151    return getString_(get_reg_key(key.first), key.second); 
    5252  } 
     
    5959  /// 
    6060  /// @author mickem 
    61   virtual int get_real_int(SettingsCore::key_path_type key) { 
     61  virtual int get_real_int(settings_core::key_path_type key) { 
    6262    throw KeyNotFoundException(key); 
    6363  } 
     
    7070  /// 
    7171  /// @author mickem 
    72   virtual bool get_real_bool(SettingsCore::key_path_type key) { 
     72  virtual bool get_real_bool(settings_core::key_path_type key) { 
    7373    throw KeyNotFoundException(key); 
    7474  } 
     
    8181  /// 
    8282  /// @author mickem 
    83   virtual bool has_real_key(SettingsCore::key_path_type key) { 
     83  virtual bool has_real_key(settings_core::key_path_type key) { 
    8484    return false; 
    85   } 
    86   ////////////////////////////////////////////////////////////////////////// 
    87   /// Get the type this settings store represent. 
    88   /// 
    89   /// @return the type of settings store 
    90   /// 
    91   /// @author mickem 
    92   virtual SettingsCore::settings_type get_type() { 
    93     return SettingsCore::registry; 
    94   } 
    95   ////////////////////////////////////////////////////////////////////////// 
    96   /// Is this the active settings store 
    97   /// 
    98   /// @return 
    99   /// 
    100   /// @author mickem 
    101   virtual bool is_active() { 
    102     return true; 
    10385  } 
    10486  ////////////////////////////////////////////////////////////////////////// 
     
    10991  /// 
    11092  /// @author mickem 
    111   virtual void set_real_value(SettingsCore::key_path_type key, conainer value) { 
    112     if (value.type == SettingsCore::key_string) { 
     93  virtual void set_real_value(settings_core::key_path_type key, conainer value) { 
     94    if (value.type == settings_core::key_string) { 
    11395      if (!setString_(get_reg_key(key), key.second, value.get_string())) 
    114         throw SettingsException(_T("Failed to write key: ") + key.first + _T(".") + key.second); 
    115     } else if (value.type == SettingsCore::key_integer) { 
     96        throw settings_exception(_T("Failed to write key: ") + key.first + _T(".") + key.second); 
     97    } else if (value.type == settings_core::key_integer) { 
    11698      if (!setInt_(get_reg_key(key), key.second, value.get_int())) 
    117       throw SettingsException(_T("Failed to write key: ") + key.first + _T(".") + key.second); 
    118     } else if (value.type == SettingsCore::key_bool) { 
     99      throw settings_exception(_T("Failed to write key: ") + key.first + _T(".") + key.second); 
     100    } else if (value.type == settings_core::key_bool) { 
    119101      if (!setInt_(get_reg_key(key), key.second, value.get_bool()?1:0)) 
    120       throw SettingsException(_T("Failed to write key: ") + key.first + _T(".") + key.second); 
     102      throw settings_exception(_T("Failed to write key: ") + key.first + _T(".") + key.second); 
    121103    } else { 
    122       throw SettingsException(_T("Invalid settings type.")); 
     104      throw settings_exception(_T("Invalid settings type.")); 
    123105    } 
    124106  } 
     
    151133    getValues_(get_reg_key(path), list); 
    152134  } 
    153   virtual SettingsCore::key_type get_key_type(std::wstring path, std::wstring key) { 
    154     return SettingsCore::key_string; 
     135  virtual settings_core::key_type get_key_type(std::wstring path, std::wstring key) { 
     136    return settings_core::key_string; 
    155137  } 
    156138private: 
    157   reg_key get_reg_key(SettingsCore::key_path_type key) { 
     139  reg_key get_reg_key(settings_core::key_path_type key) { 
    158140    return get_reg_key(key.first); 
    159141  } 
     
    217199          return ret; 
    218200        } 
    219         throw SettingsException(_T("String to long: ") + path.to_string()); 
     201        throw settings_exception(_T("String to long: ") + path.to_string()); 
    220202      } else if (type == REG_DWORD) { 
    221203        DWORD dw = *(reinterpret_cast<DWORD*>(bData)); 
    222204        return strEx::itos(dw); 
    223205      } 
    224       throw SettingsException(_T("Unsupported key type: ") + path.to_string()); 
     206      throw settings_exception(_T("Unsupported key type: ") + path.to_string()); 
    225207    } else if (lRet == ERROR_FILE_NOT_FOUND) 
    226208      throw KeyNotFoundException(_T("Key not found: ") + path.to_string()); 
    227     throw SettingsException(_T("Failed to open key: ") + path.to_string() + _T(": ") + error::lookup::last_error(lRet)); 
     209    throw settings_exception(_T("Failed to open key: ") + path.to_string() + _T(": ") + error::lookup::last_error(lRet)); 
    228210  } 
    229211  static DWORD getInt_(HKEY hKey, LPCTSTR lpszPath, LPCTSTR lpszKey, DWORD def) { 
     
    266248        if (bRet != ERROR_SUCCESS) { 
    267249          delete [] lpValueName; 
    268           throw SettingsException(_T("Failed to enumerate: ") + path.to_string() + _T(": ") + error::lookup::last_error()); 
     250          throw settings_exception(_T("Failed to enumerate: ") + path.to_string() + _T(": ") + error::lookup::last_error()); 
    269251        } 
    270252        list.push_back(std::wstring(lpValueName)); 
     
    290272        if (bRet != ERROR_SUCCESS) { 
    291273          delete [] lpValueName; 
    292           throw SettingsException(_T("Failed to enumerate: ") + path.to_string() + _T(": ") + error::lookup::last_error()); 
     274          throw settings_exception(_T("Failed to enumerate: ") + path.to_string() + _T(": ") + error::lookup::last_error()); 
    293275        } 
    294276        list.push_back(std::wstring(lpValueName)); 
     
    297279    } 
    298280  } 
    299   /* 
    300   void setSection(std::wstring section, sectionList data)  { 
    301     std::wcout << _T("Unsupported function call") << std::endl; 
    302   } 
    303   */ 
     281  virtual std::wstring get_info() { 
     282    return _T("Registry settings: (") + context_ + _T(",TODO)"); 
     283  } 
    304284}; 
    305285} 
  • trunk/include/simple_timer.hpp

    r270 r281  
    1414  ~simple_timer() { 
    1515    if (log) 
    16       std::cout << text << stop() << std::endl;; 
     16      std::wcout << text << stop() << std::endl;; 
    1717  } 
    1818 
  • trunk/include/strEx.h

    r277 r281  
    3333#include <iostream> 
    3434 
     35#include <cctype> 
     36 
    3537#include <unicode_char.hpp> 
    3638 
     
    7779    return result; 
    7880  } 
     81} 
     82 
     83namespace net { 
     84 
     85  struct url { 
     86    std::wstring protocol; 
     87    std::wstring host; 
     88    std::wstring path; 
     89    std::wstring query; 
     90 
     91  }; 
     92  inline url parse(const std::wstring& url_s) { 
     93    url ret; 
     94    const std::wstring prot_end(_T("://")); 
     95    std::wstring::const_iterator prot_i = std::search(url_s.begin(), url_s.end(), prot_end.begin(), prot_end.end()); 
     96    ret.protocol.reserve(std::distance(url_s.begin(), prot_i)); 
     97    std::transform(url_s.begin(), prot_i, std::back_inserter(ret.protocol), std::ptr_fun<int,int>(std::tolower)); // protocol is icase 
     98    if( prot_i == url_s.end() ) 
     99      return ret; 
     100    std::advance(prot_i, prot_end.length()); 
     101    std::wstring::const_iterator path_i = std::find(prot_i, url_s.end(), L'/'); 
     102    ret.host.reserve(std::distance(prot_i, path_i)); 
     103    std::transform(prot_i, path_i, std::back_inserter(ret.host), std::ptr_fun<int,int>(std::tolower)); // host is icase 
     104    std::wstring::const_iterator query_i = std::find(path_i, url_s.end(), L'?'); 
     105    ret.path.assign(path_i, query_i); 
     106    if( query_i != url_s.end() ) 
     107      ++query_i; 
     108    ret.query.assign(query_i, url_s.end()); 
     109    return ret; 
     110  } 
     111 
     112 
    79113} 
    80114namespace strEx { 
     
    630664 
    631665 
     666 
     667  template<class char_type> 
     668  struct ci_char_traits : public std::char_traits<char_type> { 
     669    static bool eq( char_type c1, char_type c2 ) { 
     670      return toupper(c1) == toupper(c2);  
     671    } 
     672 
     673    static bool ne( char_type c1, char_type c2 ) {  
     674      return toupper(c1) != toupper(c2);  
     675    } 
     676 
     677    static bool lt( char_type c1, char_type c2 ) {  
     678      return toupper(c1) <  toupper(c2);  
     679    } 
     680 
     681    static int compare( const char_type* s1, const char_type* s2, size_t n ) { 
     682      return memicmp( s1, s2, n ); 
     683      // if available on your compiler, 
     684      //  otherwise you can roll your own 
     685    } 
     686 
     687    static const char* find( const char_type* s, int n, char_type a ) { 
     688      while( n-- > 0 && toupper(*s) != toupper(a) ) { 
     689        ++s; 
     690      } 
     691      return s; 
     692    } 
     693  }; 
     694  typedef std::basic_string<wchar_t, ci_char_traits<wchar_t> > wci_string; 
     695 
    632696  template<class _E> 
    633697  struct blind_traits : public std::char_traits<_E> 
  • trunk/modules/CheckEventLog/CheckEventLog.cpp

    r273 r281  
    3030#include <error.hpp> 
    3131#include <map> 
    32 <<<<<<< .working 
    3332#include <vector> 
    3433#include <config.h> 
    35 ======= 
    36 #include <vector> 
    37 >>>>>>> .merge-right.r272 
    3834 
    3935#include <boost/bind.hpp> 
     
    4945CheckEventLog gCheckEventLog; 
    5046 
    51  
    52  
    53  
    54 BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) 
    55 { 
    56   NSCModuleWrapper::wrapDllMain(hModule, ul_reason_for_call); 
    57   return TRUE; 
    58 } 
    59  
    6047CheckEventLog::CheckEventLog() { 
    6148} 
     
    7057#include <parsers/ast.cpp> 
    7158 
    72 <<<<<<< .working 
    73 bool CheckEventLog::loadModule(NSCAPI::moduleLoadMode mode) { 
    74   try { 
    75     SETTINGS_REG_PATH(event_log::SECTION); 
    76     SETTINGS_REG_KEY_B(event_log::DEBUG_KEY); 
    77     SETTINGS_REG_KEY_S(event_log::SYNTAX); 
    78  
    79     NSCModuleHelper::registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 
    80     debug_ = SETTINGS_GET_BOOL(event_log::DEBUG_KEY); 
    81     lookup_names_ = SETTINGS_GET_BOOL(event_log::LOOKUP_NAMES); 
    82     syntax_ = SETTINGS_GET_STRING(event_log::SYNTAX); 
    83     buffer_length_ = SETTINGS_GET_INT(event_log::BUFFER_SIZE); 
    84     buffer_length_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_BUFFER, EVENTLOG_BUFFER_DEFAULT); 
    85   } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
    86     NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
    87   } catch (...) { 
    88     NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
    89 ======= 
    9059namespace filter { 
    9160  namespace where { 
     
    226195      } 
    227196    }; 
    228 >>>>>>> .merge-right.r272 
    229   } 
    230 } 
    231  
    232  
    233 namespace simple_registry { 
    234   class registry_exception { 
    235     std::wstring what_; 
    236   public: 
    237     registry_exception(std::wstring what) : what_(what) {} 
    238     registry_exception(std::wstring path, std::wstring what) : what_(path + _T(" -- ") + what) {} 
    239     registry_exception(std::wstring path, std::wstring key, std::wstring what) : what_(path + _T(".") + key + _T(" -- ") + what) {} 
    240     std::wstring what() { 
    241       return what_; 
    242     } 
    243   }; 
    244   class registry_key { 
    245     HKEY hKey_; 
    246     std::wstring path_; 
    247     BYTE *bData_; 
    248     TCHAR *buffer_; 
    249   public: 
    250     registry_key(HKEY hRootKey, std::wstring path) : path_(path), hKey_(NULL), bData_(NULL), buffer_(NULL) { 
    251       LONG lRet = ERROR_SUCCESS; 
    252       if (lRet = RegOpenKeyEx(hRootKey, path.c_str(), 0, KEY_QUERY_VALUE|KEY_READ, &hKey_) != ERROR_SUCCESS) 
    253         throw registry_exception(path, _T("Failed to open key: ") + error::format::from_system(lRet)); 
    254     } 
    255     ~registry_key() { 
    256       if (hKey_ != NULL) 
    257         RegCloseKey(hKey_); 
    258       delete [] bData_; 
    259       delete [] buffer_; 
    260     } 
    261     std::wstring get_string(std::wstring key, DWORD buffer_length = 2048) { 
    262       DWORD type; 
    263       std::wstring ret; 
    264       DWORD cbData = buffer_length; 
    265       delete [] bData_; 
    266       bData_ = new BYTE[cbData+2]; 
    267       // TODO: add get size here ! 
    268       LONG lRet = RegQueryValueEx(hKey_, key.c_str(), NULL, &type, bData_, &cbData); 
    269       if (lRet != ERROR_SUCCESS) 
    270         throw registry_exception(path_, key, _T("Failed to get value: ") + error::format::from_system(lRet)); 
    271       if (cbData >= buffer_length || cbData < 0) 
    272         throw registry_exception(path_, key, _T("Failed to get value: buffer to small")); 
    273       bData_[cbData] = 0; 
    274       if (type == REG_SZ) { 
    275         ret = reinterpret_cast<LPCTSTR>(bData_); 
    276       } else if (type == REG_EXPAND_SZ) { 
    277         std::wstring s = reinterpret_cast<LPCTSTR>(bData_); 
    278         delete [] buffer_; 
    279         buffer_ = new TCHAR[buffer_length+1]; 
    280         DWORD expRet = ExpandEnvironmentStrings(s.c_str(), buffer_, buffer_length); 
    281         if (expRet >= buffer_length) 
    282           throw registry_exception(path_, key, _T("Buffer to small (expand)")); 
    283         else 
    284           ret = buffer_; 
    285       } else { 
    286         throw registry_exception(path_, key, _T("Unknown type (not a string)")); 
    287       } 
    288       return ret; 
    289     } 
    290     DWORD get_int(std::wstring key) { 
    291       DWORD type; 
    292       DWORD cbData = sizeof(DWORD); 
    293       DWORD ret = 0; 
    294       LONG lRet = RegQueryValueEx(hKey_, key.c_str(), NULL, &type, reinterpret_cast<LPBYTE>(&ret), &cbData); 
    295       if (lRet != ERROR_SUCCESS) 
    296         throw registry_exception(path_, key, _T("Failed to get value: ") + error::format::from_system(lRet)); 
    297       if (type != REG_DWORD) 
    298         throw registry_exception(path_, key, _T("Unknown type (not a DWORD)")); 
    299       return ret; 
    300     } 
    301  
    302 <<<<<<< .working 
    303     std::list<std::wstring> get_keys(DWORD buffer_length = 2048) { 
    304       std::list<std::wstring> ret; 
    305       DWORD cSubKeys=0; 
    306       DWORD cMaxKeyLen; 
    307       // Get the class name and the value count.  
    308       LONG lRet = RegQueryInfoKey(hKey_,NULL,NULL,NULL,&cSubKeys,&cMaxKeyLen,NULL,NULL,NULL,NULL,NULL,NULL); 
    309       if (lRet != ERROR_SUCCESS) 
    310         throw registry_exception(path_, _T("Failed to query key info: ") + error::format::from_system(lRet)); 
    311       if (cSubKeys == 0) 
    312         return ret; 
    313       delete [] buffer_; 
    314       buffer_ = new TCHAR[cMaxKeyLen+20]; 
    315       for (unsigned int i=0; i<cSubKeys; i++) { 
    316         lRet = RegEnumKey(hKey_, i, buffer_, cMaxKeyLen+10); 
    317         if (lRet != ERROR_SUCCESS) { 
    318           throw registry_exception(path_, _T("Failed to enumerate: ") + error::lookup::last_error(lRet)); 
    319         } 
    320         std::wstring str = buffer_; 
    321         ret.push_back(str); 
    322       } 
    323       return ret; 
    324     } 
    325  
    326   }; 
    327    
    328   std::wstring get_string(HKEY hKey, std::wstring path, std::wstring key) { 
    329     registry_key reg(hKey, path); 
    330     return reg.get_string(key); 
    331   } 
    332 } 
    333  
    334 std::wstring find_eventlog_name(std::wstring name) { 
    335   try { 
    336     simple_registry::registry_key key(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog")); 
    337     std::list<std::wstring> list = key.get_keys(); 
    338     for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 
    339       try { 
    340         simple_registry::registry_key sub_key(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\") + *cit); 
    341         std::wstring file = sub_key.get_string(_T("DisplayNameFile")); 
    342         int id = sub_key.get_int(_T("DisplayNameID")); 
    343         std::wstring real_name = error::format::message::from_module(file, id); 
    344         strEx::replace(real_name, _T("\n"), _T("")); 
    345         strEx::replace(real_name, _T("\r"), _T("")); 
    346         NSC_DEBUG_MSG(_T("Attempting to match: ") + real_name + _T(" with ") + name); 
    347         if (real_name == name) 
    348           return *cit; 
    349       } catch (simple_registry::registry_exception &e) {} 
    350     } 
    351     return name; 
    352   } catch (simple_registry::registry_exception &e) { 
    353     NSC_DEBUG_MSG(_T("Failed to get eventlog name (assuming shorthand): ") + e.what()); 
    354     return name; 
    355   } catch (...) { 
    356     NSC_DEBUG_MSG(_T("Failed to get eventlog name (assuming shorthand)")); 
    357     return name; 
    358   } 
    359 } 
    360  
    361 class EventLogRecord { 
    362   EVENTLOGRECORD *pevlr_; 
    363   __int64 currentTime_; 
    364   std::wstring file_; 
    365 public: 
    366   EventLogRecord(std::wstring file, EVENTLOGRECORD *pevlr, __int64 currentTime) : file_(file), pevlr_(pevlr), currentTime_(currentTime) { 
    367 ======= 
     197  } 
     198} 
     199 
     200 
     201 
    368202 
    369203struct filter_container { 
     
    412246    } 
    413247    return true; 
    414 >>>>>>> .merge-right.r272 
    415248  } 
    416249 
     
    439272 
    440273  } 
    441 <<<<<<< .working 
    442  
    443   std::wstring userSID() const { 
    444     if (pevlr_->UserSidOffset == 0) 
    445       return _T(""); 
    446     PSID p = reinterpret_cast<PSID>(reinterpret_cast<LPBYTE>(pevlr_) + + pevlr_->UserSidOffset); 
    447     DWORD userLen = 0; 
    448     DWORD domainLen = 0; 
    449     SID_NAME_USE sidName; 
    450  
    451     LookupAccountSid(NULL, p, NULL, &userLen, NULL, &domainLen, &sidName); 
    452     LPTSTR user = new TCHAR[userLen+10]; 
    453     LPTSTR domain = new TCHAR[domainLen+10]; 
    454  
    455     LookupAccountSid(NULL, p, user, &userLen, domain, &domainLen, &sidName); 
    456     user[userLen] = 0; 
    457     domain[domainLen] = 0; 
    458     std::wstring ustr = user; 
    459     std::wstring dstr = domain; 
    460     delete [] user; 
    461     delete [] domain; 
    462     if (!dstr.empty()) 
    463       dstr = dstr + _T("\\"); 
    464     if (ustr.empty() && dstr.empty()) 
    465       return _T("missing"); 
    466  
    467     return dstr + ustr; 
    468 ======= 
    469274  std::wstring get_name() { 
    470275    return _T("deprecated"); 
    471 >>>>>>> .merge-right.r272 
    472   } 
    473 <<<<<<< .working 
    474 ======= 
     276  } 
    475277  std::wstring get_subject() { return _T("TODO"); } 
    476 >>>>>>> .merge-right.r272 
    477278 
    478279}; 
     
    519320    return _T("old"); 
    520321  } 
    521 <<<<<<< .working 
    522   static DWORD translateType(std::wstring sType) { 
    523     if (sType == _T("error")) 
    524       return EVENTLOG_ERROR_TYPE; 
    525     if (sType == _T("warning")) 
    526       return EVENTLOG_WARNING_TYPE; 
    527     if (sType == _T("info")) 
    528       return EVENTLOG_INFORMATION_TYPE; 
    529     if (sType == _T("auditSuccess")) 
    530       return EVENTLOG_AUDIT_SUCCESS; 
    531     if (sType == _T("auditFailure")) 
    532       return EVENTLOG_AUDIT_FAILURE; 
    533     return strEx::stoi(sType); 
    534   } 
    535   static std::wstring translateType(DWORD dwType) { 
    536     if (dwType == EVENTLOG_ERROR_TYPE) 
    537       return _T("error"); 
    538     if (dwType == EVENTLOG_WARNING_TYPE) 
    539       return _T("warning"); 
    540     if (dwType == EVENTLOG_INFORMATION_TYPE) 
    541       return _T("info"); 
    542     if (dwType == EVENTLOG_AUDIT_SUCCESS) 
    543       return _T("auditSuccess"); 
    544     if (dwType == EVENTLOG_AUDIT_FAILURE) 
    545       return _T("auditFailure"); 
    546     return strEx::itos(dwType); 
    547   } 
    548   static DWORD translateSeverity(std::wstring sType) { 
    549     if (sType == _T("success")) 
    550       return 0; 
    551     if (sType == _T("informational")) 
    552       return 1; 
    553     if (sType == _T("warning")) 
    554       return 2; 
    555     if (sType == _T("error")) 
    556       return 3; 
    557     return strEx::stoi(sType); 
    558   } 
    559   static std::wstring translateSeverity(DWORD dwType) { 
    560     if (dwType == 0) 
    561       return _T("success"); 
    562     if (dwType == 1) 
    563       return _T("informational"); 
    564     if (dwType == 2) 
    565       return _T("warning"); 
    566     if (dwType == 3) 
    567       return _T("error"); 
    568     return strEx::itos(dwType); 
    569   } 
    570   std::wstring get_dll() { 
    571     try { 
    572       return simple_registry::get_string(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\") + file_ + (std::wstring)_T("\\") + eventSource(), _T("EventMessageFile")); 
    573     } catch (simple_registry::registry_exception &e) { 
    574       NSC_LOG_ERROR_STD(_T("Could not extract DLL for eventsource: ") + eventSource() + _T(": ") + e.what()); 
    575       return _T(""); 
    576 ======= 
    577322  std::wstring get_subject() { return _T("TODO"); } 
    578323}; 
     
    595340      message = _T("Parsing failed: ") + ast_parser.rest; 
    596341      return false; 
    597 >>>>>>> .merge-right.r272 
    598     } 
    599 <<<<<<< .working 
    600   } 
    601 ======= 
     342    } 
    602343    if (data.bDebug) 
    603344      NSC_DEBUG_MSG_STD(_T("Parsing succeeded: ") + ast_parser.result_as_tree()); 
     
    609350    if (data.bDebug) 
    610351      NSC_DEBUG_MSG_STD(_T("Type resolution succeeded: ") + ast_parser.result_as_tree()); 
    611 >>>>>>> .merge-right.r272 
    612  
    613 <<<<<<< .working 
    614   std::wstring render_message() { 
    615     std::vector<std::wstring> args; 
    616     TCHAR* *pArgs = new TCHAR*[pevlr_->NumStrings+1]; 
    617     TCHAR* p = reinterpret_cast<TCHAR*>(reinterpret_cast<LPBYTE>(pevlr_) + pevlr_->StringOffset); 
    618     for (unsigned int i =0;i<pevlr_->NumStrings;i++) { 
    619       args.push_back(p); 
    620       pArgs[i] = p; 
    621       DWORD len = wcslen(p); 
    622       p = &(p[len+1]); 
    623       //p += len+1; 
    624 ======= 
     352 
    625353    if (!ast_parser.bind(dummy) || dummy.has_error()) { 
    626354      message = _T("Variable and function binding failed: ") + dummy.get_error(); 
    627355      return false; 
    628 >>>>>>> .merge-right.r272 
    629356    } 
    630357    if (data.bDebug) 
    631358      NSC_DEBUG_MSG_STD(_T("Binding succeeded: ") + ast_parser.result_as_tree()); 
    632359 
    633 <<<<<<< .working 
    634     std::wstring ret; 
    635     strEx::splitList dlls = strEx::splitEx(get_dll(), _T(";")); 
    636     for (strEx::splitList::const_iterator cit = dlls.begin(); cit != dlls.end(); ++cit) { 
    637       //std::wstring msg = error::format::message::from_module((*cit), eventID(), _sz); 
    638       std::wstring msg; 
    639       try { 
    640         msg = error::format::message::from_module_x64((*cit), eventID(), pArgs, pevlr_->NumStrings); 
    641         if (msg.empty()) { 
    642           msg = error::format::message::from_module_x64((*cit), pevlr_->EventID, pArgs, pevlr_->NumStrings); 
    643         } 
    644       } catch (...) { 
    645         msg = _T("Unknown exception getting message"); 
    646       } 
    647       strEx::replace(msg, _T("\n"), _T(" ")); 
    648       strEx::replace(msg, _T("\t"), _T(" ")); 
    649       std::string::size_type pos = msg.find_last_not_of(_T("\n\t ")); 
    650       if (pos != std::string::npos) { 
    651         msg = msg.substr(0,pos); 
    652       } 
    653       if (!msg.empty()) { 
    654         if (!ret.empty()) 
    655           ret += _T(", "); 
    656         ret += msg; 
    657       } 
    658 ======= 
    659360    if (!ast_parser.static_eval(dummy) || dummy.has_error()) { 
    660361      message = _T("Static evaluation failed: ") + dummy.get_error(); 
     
    672373    if (obj.has_error()) { 
    673374      NSC_LOG_ERROR_STD(_T("Error: ") + obj.get_error()); 
    674 >>>>>>> .merge-right.r272 
    675     } 
    676 <<<<<<< .working 
    677     delete [] pArgs; 
    678 ======= 
    679 >>>>>>> .merge-right.r272 
     375    } 
    680376    return ret; 
    681377  } 
    682 <<<<<<< .working 
    683   // SYSTEMTIME  
    684   boost::posix_time::ptime get_time(DWORD time) { 
    685     FILETIME FileTime, LocalFileTime; 
    686     SYSTEMTIME SysTime; 
    687     __int64 lgTemp; 
    688     __int64 SecsTo1970 = 116444736000000000; 
    689 ======= 
    690378  std::wstring get_name() { 
    691379    return _T("where"); 
     
    693381  std::wstring get_subject() { return data.filter; } 
    694382}; 
    695 >>>>>>> .merge-right.r272 
    696  
    697  
    698  
    699 <<<<<<< .working 
    700     return boost::date_time::time_from_ftime<boost::posix_time::ptime>(FileTime); 
    701  
    702  
    703 /* 
    704     FileTimeToLocalFileTime(&FileTime, &LocalFileTime); 
    705     FileTimeToSystemTime(&LocalFileTime, &SysTime); 
    706     return SysTime; 
    707     */ 
    708   } 
    709 ======= 
     383 
     384 
     385 
    710386void CheckEventLog::parse(std::wstring expr) { 
    711387//return false; 
     
    717393  */ 
    718394} 
    719 >>>>>>> .merge-right.r272 
    720  
    721 <<<<<<< .working 
    722   boost::posix_time::ptime get_time_generated() { 
    723     return get_time(pevlr_->TimeGenerated); 
    724 ======= 
    725395bool CheckEventLog::loadModule() { 
     396  return false; 
     397} 
     398 
     399bool CheckEventLog::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    726400  try { 
    727     NSCModuleHelper::registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 
    728     debug_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_DEBUG, EVENTLOG_DEBUG_DEFAULT)==1; 
    729     lookup_names_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_LOOKUP_NAMES, EVENTLOG_LOOKUP_NAMES_DEFAULT)==1; 
    730     syntax_ = NSCModuleHelper::getSettingsString(EVENTLOG_SECTION_TITLE, EVENTLOG_SYNTAX, EVENTLOG_SYNTAX_DEFAULT); 
    731     buffer_length_ = NSCModuleHelper::getSettingsInt(EVENTLOG_SECTION_TITLE, EVENTLOG_BUFFER, EVENTLOG_BUFFER_DEFAULT); 
    732   } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     401    SETTINGS_REG_PATH(event_log::SECTION); 
     402    SETTINGS_REG_KEY_B(event_log::DEBUG_KEY); 
     403    SETTINGS_REG_KEY_S(event_log::SYNTAX); 
     404 
     405    GET_CORE()->registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 
     406 
     407    debug_ = SETTINGS_GET_BOOL(event_log::DEBUG_KEY); 
     408    lookup_names_ = SETTINGS_GET_BOOL(event_log::LOOKUP_NAMES); 
     409    syntax_ = SETTINGS_GET_STRING(event_log::SYNTAX); 
     410    buffer_length_ = SETTINGS_GET_INT(event_log::BUFFER_SIZE); 
     411  } catch (nscapi::nscapi_exception &e) { 
    733412    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
    734413  } catch (...) { 
    735414    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
    736 >>>>>>> .merge-right.r272 
    737   } 
    738 <<<<<<< .working 
    739   boost::posix_time::ptime get_time_written() { 
    740     return get_time(pevlr_->TimeWritten); 
    741   } 
    742 ======= 
     415  } 
    743416  /* 
    744417  parse(_T("321 = 123")); 
     
    746419  parse(_T("id = 123")); 
    747420  parse(_T("id = 321")); 
    748 >>>>>>> .merge-right.r272 
    749421 
    750422  parse(_T("id = '123'")); 
     
    815487      } catch (simple_registry::registry_exception &e) { e;} 
    816488    } 
    817 <<<<<<< .working 
    818  
    819     strEx::replace(syntax, _T("%source%"), eventSource()); 
    820     strEx::replace(syntax, _T("%generated%"), strEx::format_date(get_time_generated(), date_format)); 
    821     strEx::replace(syntax, _T("%written%"), strEx::format_date(get_time_written(), date_format)); 
    822     strEx::replace(syntax, _T("%type%"), translateType(eventType())); 
    823     strEx::replace(syntax, _T("%severity%"), translateSeverity(severity())); 
    824     strEx::replace(syntax, _T("%strings%"), enumStrings()); 
    825     strEx::replace(syntax, _T("%id%"), strEx::itos(eventID())); 
    826     strEx::replace(syntax, _T("%user%"), userSID()); 
    827     return syntax; 
    828 ======= 
    829489    return name; 
    830490  } catch (simple_registry::registry_exception &e) { 
     
    834494    NSC_DEBUG_MSG(_T("Failed to get eventlog name (assuming shorthand)")); 
    835495    return name; 
    836 >>>>>>> .merge-right.r272 
    837496  } 
    838497} 
     
    882541}; 
    883542 
    884 <<<<<<< .working 
    885  
    886 #define MAP_FILTER(value, obj, filtermode) \ 
    887       else if (p__.first == value) { eventlog_filter filter; filter.obj = p__.second; filter_chain.push_back(filteritem_type(filtermode, filter)); } 
    888  
    889 struct event_log_buffer { 
    890   BYTE *bBuffer; 
    891   DWORD bufferSize_; 
    892   event_log_buffer(DWORD bufferSize) : bufferSize_(bufferSize) { 
    893     bBuffer = new BYTE[bufferSize+10]; 
    894   } 
    895   ~event_log_buffer() { 
    896     delete [] bBuffer; 
    897   } 
    898   EVENTLOGRECORD* getBufferUnsafe() { 
    899     return reinterpret_cast<EVENTLOGRECORD*>(bBuffer); 
    900   } 
    901   DWORD getBufferSize() { 
    902     return bufferSize_; 
    903   } 
    904 }; 
    905  
    906 ======= 
    907 >>>>>>> .merge-right.r272 
    908 NSCAPI::nagiosReturn CheckEventLog::handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 
     543NSCAPI::nagiosReturn CheckEventLog::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 
    909544  if (command != _T("CheckEventLog")) 
    910545    return NSCAPI::returnIgnored; 
    911 <<<<<<< .working 
    912   typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsULongInteger> EventLogQuery1Container; 
    913   typedef checkHolders::CheckContainer<checkHolders::ExactBoundsULongInteger> EventLogQuery2Container; 
    914    
    915   typedef std::pair<int,eventlog_filter> filteritem_type; 
    916   typedef std::list<filteritem_type > filterlist_type; 
    917 ======= 
    918546  simple_timer time; 
    919547  typedef checkHolders::CheckContainer<checkHolders::MaxMinBoundsULongInteger> EventLogQuery1Container; 
    920548  typedef checkHolders::CheckContainer<checkHolders::ExactBoundsULongInteger> EventLogQuery2Container; 
    921    
    922 >>>>>>> .merge-right.r272 
     549 
    923550  NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 
    924   std::list<std::wstring> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 
    925551 
    926552  std::list<std::wstring> files; 
    927 <<<<<<< .working 
    928   filterlist_type filter_chain; 
    929553  EventLogQuery1Container query1; 
    930554  EventLogQuery2Container query2; 
    931 ======= 
    932   EventLogQuery1Container query1; 
    933   EventLogQuery2Container query2; 
    934 >>>>>>> .merge-right.r272 
    935555 
    936556 
     
    938558 
    939559  bool bPerfData = true; 
    940 <<<<<<< .working 
    941   bool bFilterIn = true; 
    942   bool bFilterAll = false; 
    943560  bool bFilterNew = true; 
    944   bool bShowDescriptions = false; 
    945 ======= 
    946   bool bFilterNew = true; 
    947 >>>>>>> .merge-right.r272 
    948561  bool unique = false; 
    949562  unsigned int truncate = 0; 
     
    959572  } 
    960573  */ 
    961   event_log_buffer buffer(buffer_length_); 
    962   /* 
     574 
    963575  try { 
    964     event_log_buffer buffer(buffer_length_); 
    965   } catch (std::exception e) { 
    966     message = std::wstring(_T("Failed to allocate memory: ")) + strEx::string_to_wstring(e.what()); 
    967     return NSCAPI::returnUNKNOWN; 
    968   } 
    969   */ 
    970  
    971   try { 
    972     MAP_OPTIONS_BEGIN(stl_args) 
     576    MAP_OPTIONS_BEGIN(arguments) 
    973577      MAP_OPTIONS_NUMERIC_ALL(query1, _T("")) 
    974578      MAP_OPTIONS_EXACT_NUMERIC_ALL(query2, _T("")) 
     
    1116720    //GetOldestEventLogRecord(hLog, &dwThisRecord); 
    1117721 
    1118 <<<<<<< .working 
    1119722    while (true) { 
    1120723      BOOL bStatus = ReadEventLog(hLog, EVENTLOG_FORWARDS_READ|EVENTLOG_SEQUENTIAL_READ, 
     
    1123726        DWORD err = GetLastError(); 
    1124727        if (err == ERROR_INSUFFICIENT_BUFFER) { 
    1125           if (!buffer_error_reported) { 
    1126             NSC_LOG_ERROR_STD(_T("EvenlogBuffer is too small change the value of ") + setting_keys::event_log::BUFFER_SIZE + _T("=") + strEx::itos(dwNeeded+1) + _T(" under [EventLog] in nsc.ini : ") + error::lookup::last_error(err)); 
    1127             buffer_error_reported = true; 
    1128           } 
     728          message = _T("EvenlogBuffer is too small change the value of ") + setting_keys::event_log::BUFFER_SIZE_PATH + _T("=") + strEx::itos(dwNeeded+1) + _T(": ") + error::lookup::last_error(err); 
     729          NSC_LOG_ERROR_STD(message); 
     730          CloseEventLog(hLog); 
     731          return NSCAPI::returnUNKNOWN; 
    1129732        } else if (err == ERROR_HANDLE_EOF) { 
    1130733          break; 
     
    1133736          message = _T("Failed to read from eventlog: ") + error::lookup::last_error(err); 
    1134737          CloseEventLog(hLog); 
    1135           return NSCAPI::returnUNKNOWN; 
    1136         } 
    1137       } 
    1138       EVENTLOGRECORD *pevlr = buffer.getBufferUnsafe();  
    1139       while (dwRead > 0) {  
    1140         //bool bMatch = bFilterAll; 
    1141         bool bMatch = !bFilterIn; 
    1142         EventLogRecord record((*cit2), pevlr, ltime); 
    1143  
    1144         if (filter_chain.empty()) { 
    1145           message = _T("No filters specified try adding: filter+generated=>2d"); 
    1146 ======= 
    1147     while (true) { 
    1148       BOOL bStatus = ReadEventLog(hLog, EVENTLOG_FORWARDS_READ|EVENTLOG_SEQUENTIAL_READ, 
    1149         0, buffer.getBufferUnsafe(), buffer.getBufferSize(), &dwRead, &dwNeeded); 
    1150       if (bStatus == FALSE) { 
    1151         DWORD err = GetLastError(); 
    1152         if (err == ERROR_INSUFFICIENT_BUFFER) { 
    1153           if (!buffer_error_reported) { 
    1154             NSC_LOG_ERROR_STD(_T("EvenlogBuffer is too small change the value of ") + EVENTLOG_BUFFER + _T("=") + strEx::itos(dwNeeded+1) + _T(" under [EventLog] in nsc.ini : ") + error::lookup::last_error(err)); 
    1155             buffer_error_reported = true; 
    1156           } 
    1157         } else if (err == ERROR_HANDLE_EOF) { 
    1158           break; 
    1159         } else { 
    1160           NSC_LOG_ERROR_STD(_T("Failed to read from eventlog: ") + error::lookup::last_error(err)); 
    1161           message = _T("Failed to read from eventlog: ") + error::lookup::last_error(err); 
    1162           CloseEventLog(hLog); 
    1163 >>>>>>> .merge-right.r272 
    1164738          return NSCAPI::returnUNKNOWN; 
    1165739        } 
     
    1208782        pevlr = reinterpret_cast<EVENTLOGRECORD*>((LPBYTE)pevlr + pevlr->Length);  
    1209783      }  
    1210 <<<<<<< .working 
    1211     }  
    1212 ======= 
    1213     } 
    1214 >>>>>>> .merge-right.r272 
    1215     DWORD err = GetLastError(); 
    1216     if (err == ERROR_INSUFFICIENT_BUFFER) { 
    1217       NSC_LOG_ERROR_STD(_T("EvenlogBuffer is too small (set the value of ") + setting_keys::event_log::BUFFER_SIZE_TITLE + _T("): ") + error::lookup::last_error(err)); 
    1218       message = std::wstring(_T("EvenlogBuffer is too small (set the value of ")) + setting_keys::event_log::BUFFER_SIZE_TITLE + _T("): ") + error::lookup::last_error(err); 
    1219       return NSCAPI::returnUNKNOWN; 
    1220     } else if (err != ERROR_HANDLE_EOF) { 
    1221       NSC_LOG_ERROR_STD(_T("Failed to read from eventlog: ") + error::lookup::last_error(err)); 
    1222       message = _T("Failed to read from eventlog: ") + error::lookup::last_error(err); 
    1223       return NSCAPI::returnUNKNOWN; 
    1224784    } 
    1225785    CloseEventLog(hLog); 
     
    1256816 
    1257817 
     818NSC_WRAP_DLL(); 
    1258819NSC_WRAPPERS_MAIN_DEF(gCheckEventLog); 
    1259820NSC_WRAPPERS_IGNORE_MSG_DEF(); 
  • trunk/modules/CheckEventLog/CheckEventLog.h

    r273 r281  
    2727 
    2828 
    29 class CheckEventLog { 
     29class CheckEventLog  : public nscapi::impl::SimpleCommand { 
    3030private: 
    3131  bool debug_; 
     
    3838  virtual ~CheckEventLog(); 
    3939  // Module calls 
    40   bool loadModule(NSCAPI::moduleLoadMode mode); 
     40  bool loadModule(); 
     41  bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 
    4142  bool unloadModule(); 
    4243 
     
    4445    return _T("Event log Checker."); 
    4546  } 
    46   NSCModuleWrapper::module_version getModuleVersion() { 
    47     NSCModuleWrapper::module_version version = {0, 0, 1 }; 
     47  nscapi::plugin_wrapper::module_version getModuleVersion() { 
     48    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    4849    return version; 
    4950  } 
     
    5657  bool hasCommandHandler(); 
    5758  bool hasMessageHandler(); 
    58   NSCAPI::nagiosReturn handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 
     59  NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 
    5960}; 
  • trunk/modules/CheckEventLog/eventlog_record.hpp

    r274 r281  
    200200  } 
    201201 
     202  inline boost::posix_time::ptime systemtime_to_time(const SYSTEMTIME &time) { 
     203    struct tm tmTime; 
     204    memset(&tmTime, 0, sizeof(tmTime)); 
     205 
     206    tmTime.tm_sec = time.wSecond; // seconds after the minute - [0,59] 
     207    tmTime.tm_min = time.wMinute; // minutes after the hour - [0,59] 
     208    tmTime.tm_hour = time.wHour;  // hours since midnight - [0,23] 
     209    tmTime.tm_mday = time.wDay;  // day of the month - [1,31] 
     210    tmTime.tm_mon = time.wMonth-1; // months since January - [0,11] 
     211    tmTime.tm_year = time.wYear-1900; // years since 1900 
     212    tmTime.tm_wday = time.wDayOfWeek; // days since Sunday - [0,6] 
     213 
     214    return boost::posix_time::ptime_from_tm(tmTime); 
     215  } 
     216 
    202217  std::wstring render(bool propper, std::wstring syntax, std::wstring date_format = DATE_FORMAT) { 
    203218    if (propper) { 
     
    209224 
    210225    strEx::replace(syntax, _T("%source%"), eventSource()); 
    211     strEx::replace(syntax, _T("%generated%"), strEx::format_date(get_time_generated(), date_format)); 
    212     strEx::replace(syntax, _T("%written%"), strEx::format_date(get_time_written(), date_format)); 
     226    strEx::replace(syntax, _T("%generated%"), strEx::format_date(systemtime_to_time(get_time_generated()), date_format)); 
     227    strEx::replace(syntax, _T("%written%"), strEx::format_date(systemtime_to_time(get_time_written()), date_format)); 
    213228    strEx::replace(syntax, _T("%generated-raw%"), strEx::itos(pevlr_->TimeGenerated)); 
    214229    strEx::replace(syntax, _T("%written-raw%"), strEx::itos(pevlr_->TimeWritten)); 
  • trunk/modules/CheckEventLog/stdafx.h

    r207 r281  
    3333#include <functional> 
    3434 
     35#include <boost/lexical_cast.hpp> 
     36 
     37#include <config.h> 
     38#include <unicode_char.hpp> 
     39#include <types.hpp> 
    3540#include <NSCAPI.h> 
    36 #include <nsc_module_wrapper.hpp> 
    37 #include <NSCHelper.h> 
     41#include <nscapi/plugin.hpp> 
    3842 
    3943#ifdef MEMCHECK 
  • trunk/modules/CheckExternalScripts/CheckExternalScripts.cpp

    r279 r281  
    2424#include <string> 
    2525 
    26 #include <settings/macros.h> 
    2726#include <msvc_wrappers.h> 
    28 #include <config.h> 
    2927#include <strEx.h> 
    30 #include <file_helpers.hpp> 
    3128#include <file_helpers.hpp> 
    3229 
    3330#include <boost/regex.hpp> 
    3431#include <boost/filesystem.hpp> 
     32 
     33namespace sh = nscapi::settings_helper; 
    3534 
    3635 
     
    4342  boost::filesystem::wpath path = str_path; 
    4443  if (path.has_relative_path()) 
    45     path = GET_CORE()->getBasePath() / path; 
     44    path = get_core()->getBasePath() / path; 
    4645  file_helpers::patterns::pattern_type split_path = file_helpers::patterns::split_pattern(path); 
    4746  if (!boost::filesystem::is_directory(split_path.first)) 
     
    5453      std::wstring name = itr->path().leaf(); 
    5554      if (regex_match(name, pattern)) 
    56         addCommand(name, (split_path.first / name).string(), _T("")); 
     55        add_command(name.c_str(), (split_path.first / name).string()); 
    5756    } 
    5857  } 
     
    6059 
    6160 
    62 std::wstring CheckExternalScripts::getWrapping(std::wstring val) { 
    63   strEx::token tok = strEx::getToken(val, ' ', true); 
    64   std::wstring::size_type pos = tok.first.find_last_of(_T(".")); 
    65   if (pos == std::wstring::npos) 
    66     return _T(""); 
    67   return tok.first.substr(pos+1); 
     61/** 
     62 * Load (initiate) module. 
     63 * Start the background collector thread and let it run until unloadModule() is called. 
     64 * @return true 
     65 */ 
     66bool CheckExternalScripts::loadModule() { 
     67  return false; 
    6868} 
    6969 
    70 void CheckExternalScripts::addWrappedCommand(std::wstring key, std::wstring tpl, std::wstring command ) { 
    71   strEx::token tok = strEx::getToken(command, ' ', true); 
    72   strEx::replace(tpl, _T("%SCRIPT%"), tok.first); 
    73   strEx::replace(tpl, _T("%ARGS%"), tok.second); 
    74   tok = strEx::getToken(tpl, ' ', true); 
    75   addCommand(key.c_str(),tok.first, tok.second); 
    76 } 
    7770 
    78 bool CheckExternalScripts::loadModule(NSCAPI::moduleLoadMode mode) { 
    79   SETTINGS_REG_PATH(external_scripts::SECTION); 
    80   SETTINGS_REG_PATH(external_scripts::SCRIPT_SECTION); 
    81   SETTINGS_REG_PATH(external_scripts::ALIAS_SECTION); 
    82   SETTINGS_REG_KEY_I(external_scripts::TIMEOUT); 
    83   SETTINGS_REG_KEY_S(external_scripts::SCRIPT_PATH); 
    84   SETTINGS_REG_KEY_B(external_scripts::ALLOW_ARGS); 
    85   SETTINGS_REG_KEY_B(external_scripts::ALLOW_NASTY); 
    8671 
    87   timeout = SETTINGS_GET_INT(external_scripts::TIMEOUT); 
    88   scriptDirectory_ = SETTINGS_GET_STRING(external_scripts::SCRIPT_PATH); 
    89   allowArgs_ = SETTINGS_GET_BOOL(nrpe::ALLOW_ARGS); 
    90   allowNasty_ = SETTINGS_GET_BOOL(nrpe::ALLOW_NASTY); 
    91   std::list<std::wstring>::const_iterator it; 
    92   std::list<std::wstring> commands = GET_CORE()->getSettingsSection(setting_keys::external_scripts::SCRIPT_SECTION_PATH); 
    93   for (it = commands.begin(); it != commands.end(); ++it) { 
    94     if ((*it).empty()) 
    95       continue; 
    96     NSC_DEBUG_MSG_STD(_T("Looking under: ") + setting_keys::external_scripts::SCRIPT_SECTION_PATH + _T(", ") + (*it)); 
    97     std::wstring s = GET_CORE()->getSettingsString(setting_keys::external_scripts::SCRIPT_SECTION_PATH, (*it), _T("")); 
    98     if (s.empty()) { 
    99       NSC_LOG_ERROR_STD(_T("Invalid command definition: ") + (*it)); 
    100     } else { 
    101       strEx::token tok = strEx::getToken(s, ' ', true); 
    102       addCommand((*it).c_str(), tok.first, tok.second); 
     72bool CheckExternalScripts::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
     73  try { 
     74 
     75    sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     76    settings.set_alias(alias, _T("external scripts")); 
     77 
     78    settings.add_path_to_settings() 
     79      (_T("EXTERNAL SCRIPT SECTION"), _T("Section for external scripts configuration options (CheckExternalScripts).")) 
     80 
     81      (_T("scripts"), sh::fun_values_path(boost::bind(&CheckExternalScripts::add_command, this, _1, _2)),  
     82      _T("EXTERNAL SCRIPT SCRIPT SECTION"), _T("A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments>")) 
     83 
     84      (_T("alias"), sh::fun_values_path(boost::bind(&CheckExternalScripts::add_alias, this, _1, _2)),  
     85      _T("EXTERNAL SCRIPT ALIAS SECTION"), _T("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)")) 
     86 
     87      (_T("wrappings"), sh::wstring_map_path(&wrappings_) 
     88      , _T("EXTERNAL SCRIPT WRAPPINGS SECTION"), _T("")) 
     89 
     90      (_T("wrapped scripts"), sh::fun_values_path(boost::bind(&CheckExternalScripts::add_wrapping, this, _1, _2)),  
     91      _T("EXTERNAL SCRIPT WRAPPED SCRIPTS SECTION"), _T("")) 
     92      ; 
     93 
     94    settings.add_key_to_settings() 
     95      (_T("timeout"), sh::uint_key(&timeout, 60), 
     96      _T("COMMAND TIMEOUT"), _T("The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones.")) 
     97 
     98      (_T("allow arguments"), sh::bool_key(&allowArgs_, false), 
     99      _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed.")) 
     100 
     101      (_T("allow nasty characters"), sh::bool_key(&allowNasty_, false), 
     102      _T("COMMAND ALLOW NASTY META CHARS"), _T("This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments.")) 
     103 
     104      (_T("script path"), sh::wstring_key(&scriptDirectory_), 
     105      _T("SCRIPT DIRECTORY"), _T("Load all scripts in a directory and use them as commands. Probably dangerous but useful if you have loads of scripts :)")) 
     106      ; 
     107 
     108    settings.register_all(); 
     109    settings.notify(); 
     110 
     111    if (!scriptDirectory_.empty()) { 
     112      addAllScriptsFrom(scriptDirectory_); 
    103113    } 
     114    root_ = get_core()->getBasePath(); 
     115 
     116//  } catch (nrpe::server::nrpe_exception &e) { 
     117//    NSC_LOG_ERROR_STD(_T("Exception caught: ") + e.what()); 
     118//    return false; 
     119  } catch (...) { 
     120    NSC_LOG_ERROR_STD(_T("Exception caught: <UNKNOWN EXCEPTION>")); 
     121    return false; 
    104122  } 
    105  
    106   commands = GET_CORE()->getSettingsSection(setting_keys::external_scripts::ALIAS_SECTION_PATH); 
    107   for (it = commands.begin(); it != commands.end(); ++it) { 
    108     if ((*it).empty()) 
    109       continue; 
    110     std::wstring s = GET_CORE()->getSettingsString(setting_keys::external_scripts::ALIAS_SECTION_PATH, (*it), _T("")); 
    111     if (s.empty()) { 
    112       NSC_LOG_ERROR_STD(_T("Invalid command definition: ") + (*it)); 
    113     } else { 
    114       strEx::token tok = strEx::getToken(s, ' ', true); 
    115       addAlias((*it).c_str(), tok.first, tok.second); 
    116     } 
    117   } 
    118  
    119   std::map<std::wstring,std::wstring> wrappers; 
    120   std::list<std::wstring> wrappings = GET_CORE()->getSettingsSection(setting_keys::external_scripts::WRAPPINGS_SECTION_PATH); 
    121   for (it = wrappings.begin(); it != wrappings.end(); ++it) { 
    122     std::wstring val = GET_CORE()->getSettingsString(setting_keys::external_scripts::WRAPPINGS_SECTION_PATH, *it, _T("")); 
    123     if (!(*it).empty() && !val.empty()) { 
    124       wrappers[(*it)] = val; 
    125     } 
    126   } 
    127   std::list<std::wstring> wscript = GET_CORE()->getSettingsSection(setting_keys::external_scripts::WRAPPED_SCRIPT_PATH); 
    128   for (it = wscript.begin(); it != wscript.end(); ++it) { 
    129     std::wstring val = GET_CORE()->getSettingsString(setting_keys::external_scripts::WRAPPED_SCRIPT_PATH, *it, _T("")); 
    130     if (!(*it).empty() && !val.empty()) { 
    131       std::wstring type = getWrapping(val); 
    132       std::map<std::wstring,std::wstring>::const_iterator cit = wrappers.find(type); 
    133       if (cit == wrappers.end()) { 
    134         NSC_LOG_ERROR_STD(_T("Failed to find wrappings for: ") + type + _T(" (") + (*it) + _T(")")); 
    135       } else { 
    136         addWrappedCommand((*it), (*cit).second, val); 
    137       } 
    138     } 
    139   } 
    140  
    141   if (!scriptDirectory_.empty()) { 
    142     addAllScriptsFrom(scriptDirectory_); 
    143   } 
    144   root_ = GET_CORE()->getBasePath(); 
    145123  return true; 
    146124} 
     
    158136 
    159137 
    160 NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 
    161   std::wstring cmd = command.c_str(); 
    162   boost::to_lower(cmd); 
    163   command_list::const_iterator cit = commands.find(cmd); 
     138NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 
     139  command_list::const_iterator cit = commands.find(command); 
    164140  bool isAlias = false; 
    165141  if (cit == commands.end()) { 
    166     cit = alias.find(cmd); 
     142    cit = alias.find(command); 
    167143    if (cit == alias.end()) 
    168144      return NSCAPI::returnIgnored; 
     
    193169    } 
    194170    return nscapi::plugin_helper::int2nagios(result); 
    195     /* 
    196   } else if (cd.type == script_dir) { 
    197     std::wstring args = arrayBuffer::arrayBuffer2string(char_args, argLen, _T(" ")); 
    198     std::wstring cmd = scriptDirectory_ + command.c_str() + _T(" ") +args; 
    199     return executeNRPECommand(cmd, message, perf); 
    200   } else { 
    201     NSC_LOG_ERROR_STD(_T("Unknown script type: ") + command.c_str()); 
    202     return NSCAPI::critical; 
    203     */ 
    204171  } 
    205172 
  • trunk/modules/CheckExternalScripts/CheckExternalScripts.def

    r257 r281  
    44  NSModuleHelperInit 
    55  NSLoadModule 
     6  NSLoadModuleEx 
    67  NSGetModuleName 
    78  NSGetModuleVersion 
  • trunk/modules/CheckExternalScripts/CheckExternalScripts.h

    r273 r281  
    2525#include <execute_process.hpp> 
    2626 
    27 class CheckExternalScripts : public nscapi::impl::SimpleCommand { 
     27class CheckExternalScripts : public nscapi::impl::SimpleCommand, nscapi::impl::simple_plugin { 
    2828private: 
    2929  struct command_data { 
     
    3636    } 
    3737  }; 
    38   typedef std::map<std::wstring, command_data> command_list; 
     38  typedef std::map<strEx::wci_string, command_data> command_list; 
    3939  command_list commands; 
    4040  command_list alias; 
     
    4444  bool allowArgs_; 
    4545  bool allowNasty_; 
     46  std::map<std::wstring,std::wstring> wrappings_; 
    4647 
    4748public: 
     
    4950  virtual ~CheckExternalScripts(); 
    5051  // Module calls 
    51   bool loadModule(NSCAPI::moduleLoadMode mode); 
     52  bool loadModule(); 
     53  bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 
    5254  bool unloadModule(); 
    5355 
     
    6668  bool hasCommandHandler(); 
    6769  bool hasMessageHandler(); 
    68   NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 
     70  NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 
    6971  std::wstring getConfigurationMeta(); 
    7072 
     
    8486private: 
    8587  void addAllScriptsFrom(std::wstring path); 
    86   void addCommand(std::wstring key, std::wstring cmd, std::wstring args) { 
     88  void add_command(std::wstring key, std::wstring command) { 
     89    strEx::token tok = strEx::getToken(command, ' ', true); 
    8790    boost::to_lower(key); 
    88     command_data cd = command_data(cmd, args); 
    89     commands[key] = cd; 
    90     GET_CORE()->registerCommand(key, _T("Script: ") + cd.to_string()); 
     91    command_data cd = command_data(tok.first, tok.second); 
     92    commands[key.c_str()] = cd; 
     93    get_core()->registerCommand(key.c_str(), _T("Script: ") + cd.to_string()); 
    9194  } 
    92   void addAlias(std::wstring key, std::wstring cmd, std::wstring args) { 
     95  void add_alias(std::wstring key, std::wstring command) { 
     96    strEx::token tok = strEx::getToken(command, ' ', true); 
    9397    boost::to_lower(key); 
    94     command_data cd = command_data(cmd, args); 
    95     alias[key] = cd; 
    96     GET_CORE()->registerCommand(key, _T("Alias for: ") + cd.to_string()); 
     98    command_data cd = command_data(tok.first, tok.second); 
     99    alias[key.c_str()] = cd; 
     100    get_core()->registerCommand(key.c_str(), _T("Alias for: ") + cd.to_string()); 
    97101  } 
    98   std::wstring getWrapping( std::wstring val ); 
    99   void addWrappedCommand( std::wstring key, std::wstring tpl, std::wstring command ); 
     102  void add_wrapping(std::wstring key, std::wstring command) { 
     103    strEx::token tok = strEx::getToken(command, ' ', true); 
     104    std::wstring::size_type pos = tok.first.find_last_of(_T(".")); 
     105    std::wstring type; 
     106    if (pos != std::wstring::npos) 
     107      type = tok.first.substr(pos+1); 
     108 
     109    std::wstring tpl = wrappings_[type]; 
     110 
     111    strEx::replace(tpl, _T("%SCRIPT%"), tok.first); 
     112    strEx::replace(tpl, _T("%ARGS%"), tok.second); 
     113 
     114    add_command(key,tpl); 
     115  } 
    100116}; 
    101117 
  • trunk/modules/CheckHelpers/CheckHelpers.cpp

    r275 r281  
    3232} 
    3333 
     34bool CheckHelpers::loadModule() { 
     35  return false; 
     36} 
    3437 
    35 bool CheckHelpers::loadModule(NSCAPI::moduleLoadMode mode) { 
     38bool CheckHelpers::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    3639  try { 
    3740    GET_CORE()->registerCommand(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK.")); 
     
    7477} 
    7578 
    76 NSCAPI::nagiosReturn CheckHelpers::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 
     79NSCAPI::nagiosReturn CheckHelpers::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 
    7780  if (command == _T("checkversion")) { 
    7881    message = GET_CORE()->getApplicationVersionString(); 
  • trunk/modules/CheckHelpers/CheckHelpers.h

    r257 r281  
    3030  virtual ~CheckHelpers(); 
    3131  // Module calls 
    32   bool loadModule(NSCAPI::moduleLoadMode mode); 
     32  bool loadModule(); 
     33  bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 
    3334  bool unloadModule(); 
    3435 
     
    4748  bool hasCommandHandler(); 
    4849  bool hasMessageHandler(); 
    49   NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 
     50  NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 
    5051 
    5152  // Check commands 
  • trunk/modules/CheckSystem/CheckSystem.cpp

    r278 r281  
    4949 */ 
    5050CheckSystem::~CheckSystem() {} 
     51 
    5152/** 
    5253 * Load (initiate) module. 
     
    5455 * @return true 
    5556 */ 
    56  
    57 bool CheckSystem::loadModule(NSCAPI::moduleLoadMode mode) { 
     57bool CheckSystem::loadModule() { 
     58  return loadModuleEx(_T(""), NSCAPI::normalStart); 
     59} 
     60 
     61/** 
     62 * New version of the load call. 
     63 * Start the background collector thread and let it run until unloadModule() is called. 
     64 * @return true 
     65 */ 
     66 
     67bool CheckSystem::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    5868  if (mode == NSCAPI::normalStart) { 
    5969    pdhThread.createThread(); 
     
    318328 * @return  
    319329 */ 
    320 NSCAPI::nagiosReturn CheckSystem::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) { 
     330NSCAPI::nagiosReturn CheckSystem::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) { 
    321331  CheckSystem::returnBundle rb; 
    322   if (command == _T("checkcpu")) { 
     332  if (command == _T("checkCPU")) { 
    323333    return checkCPU(arguments, msg, perf); 
    324   } else if (command == _T("checkuptime")) { 
     334  } else if (command == _T("checkUpTime")) { 
    325335    return checkUpTime(arguments, msg, perf); 
    326   } else if (command == _T("checkservicestate")) { 
     336  } else if (command == _T("checkServiceState")) { 
    327337    return checkServiceState(arguments, msg, perf); 
    328   } else if (command == _T("checkprocstate")) { 
     338  } else if (command == _T("checkProcState")) { 
    329339    return checkProcState(arguments, msg, perf); 
    330   } else if (command == _T("checkmem")) { 
     340  } else if (command == _T("checkMem")) { 
    331341    return checkMem(arguments, msg, perf); 
    332   } else if (command == _T("checkcounter")) { 
     342  } else if (command == _T("checkCounter")) { 
    333343    return checkCounter(arguments, msg, perf); 
    334   } else if (command == _T("listcounterinstances")) { 
     344  } else if (command == _T("listCounterInstances")) { 
    335345    return listCounterInstances(arguments, msg, perf); 
    336   } else if (command == _T("checksingleregentry")) { 
     346  } else if (command == _T("checkSingleRegEntry")) { 
    337347    return checkSingleRegEntry(arguments, msg, perf); 
    338348  } 
     
    11411151        msg += _T(", "); 
    11421152      msg += (*it); 
     1153    } 
     1154    if (msg.empty()) { 
     1155      msg = _T("ERROR: No instances found"); 
     1156      return NSCAPI::returnUNKNOWN; 
    11431157    } 
    11441158  } catch (const PDH::PDHException e) { 
  • trunk/modules/CheckSystem/CheckSystem.h

    r278 r281  
    4747  virtual ~CheckSystem(); 
    4848  // Module calls 
    49   bool loadModule(NSCAPI::moduleLoadMode mode); 
     49  bool loadModule(); 
     50  bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 
    5051  bool unloadModule(); 
    5152  std::wstring getConfigurationMeta(); 
     
    7273  bool hasCommandHandler(); 
    7374  bool hasMessageHandler(); 
    74   NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 
     75  NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 
    7576  int commandLineExec(const TCHAR* command,const unsigned int argLen,TCHAR** args); 
    7677 
  • trunk/modules/FileLogger/FileLogger.cpp

    r273 r281  
    8383} 
    8484 
    85 bool FileLogger::loadModule(NSCAPI::moduleLoadMode mode) { 
     85bool FileLogger::loadModule() { 
     86  return false; 
     87} 
     88 
     89bool FileLogger::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    8690  //_tzset(); 
    8791  getFileName(); 
  • trunk/modules/FileLogger/FileLogger.h

    r257 r281  
    3434  virtual ~FileLogger(); 
    3535  // Module calls 
    36   bool loadModule(NSCAPI::moduleLoadMode mode); 
     36  bool loadModule(); 
     37  bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 
    3738  bool unloadModule(); 
    3839  std::wstring getConfigurationMeta(); 
  • trunk/modules/NRPEClient/NRPEClient.cpp

    r278 r281  
    4040} 
    4141 
    42 bool NRPEClient::loadModule(NSCAPI::moduleLoadMode mode) { 
     42bool NRPEClient::loadModule() { 
     43  return false; 
     44} 
     45 
     46bool NRPEClient::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    4347  std::list<std::wstring> commands; 
    4448  buffer_length_ = SETTINGS_GET_INT(nrpe::PAYLOAD_LENGTH); 
     
    5256  } 
    5357 
    54   boost::filesystem::wpath p = GET_CORE()->getBasePath() + std::wstring(_T("security/nrpe_dh_512.pem")); 
     58  boost::filesystem::wpath p = GET_CORE()->getBasePath() + std::wstring(_T("/security/nrpe_dh_512.pem")); 
    5559  cert_ = p.string(); 
    5660  if (boost::filesystem::is_regular(p)) { 
     
    136140  return false; 
    137141} 
    138 NSCAPI::nagiosReturn NRPEClient::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) 
     142NSCAPI::nagiosReturn NRPEClient::handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) 
    139143{ 
    140144  command_list::const_iterator cit = commands.find(strEx::blindstr(command.c_str())); 
  • trunk/modules/NRPEClient/NRPEClient.h

    r278 r281  
    9393  virtual ~NRPEClient(); 
    9494  // Module calls 
    95   bool loadModule(NSCAPI::moduleLoadMode mode); 
     95  bool loadModule(); 
     96  bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 
    9697  bool unloadModule(); 
    9798 
     
    121122  bool hasCommandHandler(); 
    122123  bool hasMessageHandler(); 
    123   NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 
     124  NSCAPI::nagiosReturn handleCommand(const strEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 
    124125  int commandLineExec(const unsigned int argLen,TCHAR** args); 
    125126  std::wstring getConfigurationMeta(); 
  • trunk/modules/NRPEServer/NRPEServer.cpp

    r280 r281  
    2727#include "handler_impl.hpp" 
    2828 
     29namespace sh = nscapi::settings_helper; 
     30 
    2931NRPEListener gNRPEListener; 
    3032 
    31 NRPEListener::NRPEListener() : noPerfData_(false), info_(boost::shared_ptr<nrpe::server::handler>(new handler_impl(0))) { 
    32 } 
    33 NRPEListener::~NRPEListener() { 
    34   std::cout << "TERMINATING TERMINATING!!!" << std::endl; 
    35 } 
     33NRPEListener::NRPEListener() : info_(boost::shared_ptr<nrpe::server::handler>(new handler_impl(1024))) { 
     34} 
     35NRPEListener::~NRPEListener() {} 
    3636 
    3737std::wstring getAllowedHosts() { 
     
    4444 
    4545 
    46 bool NRPEListener::loadModule(NSCAPI::moduleLoadMode mode) { 
    47   SETTINGS_REG_KEY_I(nrpe::PORT); 
    48   SETTINGS_REG_KEY_S(nrpe::BINDADDR); 
    49   SETTINGS_REG_KEY_I(nrpe::LISTENQUE); 
    50   SETTINGS_REG_KEY_I(nrpe::READ_TIMEOUT); 
    51   SETTINGS_REG_KEY_B(nrpe::KEYUSE_SSL); 
    52   SETTINGS_REG_KEY_I(nrpe::PAYLOAD_LENGTH); 
    53   SETTINGS_REG_KEY_B(nrpe::ALLOW_PERFDATA); 
    54   SETTINGS_REG_KEY_S(nrpe::SCRIPT_PATH); 
    55   SETTINGS_REG_KEY_I(nrpe::CMD_TIMEOUT); 
    56   SETTINGS_REG_KEY_B(nrpe::ALLOW_ARGS); 
    57   SETTINGS_REG_KEY_B(nrpe::ALLOW_NASTY); 
    58  
    59   SETTINGS_REG_PATH(nrpe::SECTION); 
    60   SETTINGS_REG_PATH(nrpe::SECTION_HANDLERS); 
    61  
    62   info_.use_ssl = SETTINGS_GET_BOOL(nrpe::KEYUSE_SSL)==1; 
     46bool NRPEListener::loadModule() { 
     47  return false; 
     48} 
     49 
     50bool NRPEListener::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
     51 
     52/* 
     53DEFINE_SETTING_S(ALLOWED_HOSTS, NRPE_SECTION_PROTOCOL, GENERIC_KEY_ALLOWED_HOSTS, ""); 
     54DESCRIBE_SETTING(ALLOWED_HOSTS, "ALLOWED HOST ADDRESSES", "This is a comma-delimited list of IP address of hosts that are allowed to talk to NSClient deamon. If you leave this blank the global version will be used instead."); 
     55 
     56DEFINE_SETTING_B(CACHE_ALLOWED, NRPE_SECTION_PROTOCOL, GENERIC_KEY_SOCK_CACHE_ALLOWED, false); 
     57DESCRIBE_SETTING_ADVANCED(CACHE_ALLOWED, "ALLOWED HOSTS CACHING", "Used to cache looked up hosts if you check dynamic/changing hosts set this to false."); 
     58*/ 
     59  try { 
     60 
     61    sh::settings_registry settings(nscapi::plugin_singleton->get_core()); 
     62    settings.set_alias(alias, _T("NRPE/server")); 
     63 
     64    settings.add_path_to_settings() 
     65      (_T("NRPE SERVER SECTION"), _T("Section for NRPE (NRPEListener.dll) (check_nrpe) protocol options.")) 
     66      ; 
     67 
     68    settings.add_key_to_settings() 
     69      (_T("port"), sh::uint_key(&info_.port, 5666), 
     70      _T("PORT NUMBER"), _T("Port to use for NRPE.")) 
     71 
     72      (_T("bind to"), sh::string_key(&info_.address), 
     73      _T("BIND TO ADDRESS"), _T("Allows you to bind server to a specific local address. This has to be a dotted ip address not a host name. Leaving this blank will bind to all available IP addresses.")) 
     74 
     75      (_T("socket queue size"), sh::int_key(&info_.back_log, 0), 
     76      _T("LISTEN QUEUE"), _T("Number of sockets to queue before starting to refuse new incoming connections. This can be used to tweak the amount of simultaneous sockets that the server accepts.")) 
     77 
     78      (_T("thread pool"), sh::uint_key(&info_.thread_pool_size, 10), 
     79      _T("THREAD POOL"), _T("")) 
     80 
     81      (_T("timeout"), sh::uint_key(&info_.timeout, 30), 
     82      _T("TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.")) 
     83 
     84      (_T("use ssl"), sh::bool_key(&info_.use_ssl, true), 
     85      _T("ENABLE SSL ENCRYPTION"), _T("This option controls if SSL should be enabled.")) 
     86 
     87      (_T("payload length"), sh::int_fun_key<unsigned int>(boost::bind(&nrpe::server::handler::set_payload_length, info_.request_handler, _1), 1024), 
     88      _T("PAYLOAD LENGTH"), _T("Length of payload to/from the NRPE agent. This is a hard specific value so you have to \"configure\" (read recompile) your NRPE agent to use the same value for it to work.")) 
     89 
     90      (_T("allow arguments"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_arguments, info_.request_handler, _1), false), 
     91      _T("COMMAND ARGUMENT PROCESSING"), _T("This option determines whether or not the we will allow clients to specify arguments to commands that are executed.")) 
     92 
     93      (_T("allow nasty characters"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_allow_nasty_arguments, info_.request_handler, _1), false), 
     94      _T("COMMAND ALLOW NASTY META CHARS"), _T("This option determines whether or not the we will allow clients to specify nasty (as in |`&><'\"\\[]{}) characters in arguments.")) 
     95 
     96      (_T("performance data"), sh::bool_fun_key<bool>(boost::bind(&nrpe::server::handler::set_perf_data, info_.request_handler, _1), true), 
     97      _T("PERFORMANCE DATA"), _T("Send performance data back to nagios (set this to 0 to remove all performance data).")) 
     98 
     99      (_T("certificate"), sh::wpath_key(&info_.certificate, _T("${certificate-path}/nrpe_dh_512.pem")), 
     100      _T("SSL CERTIFICATE"), _T("")) 
     101      ; 
     102 
     103    settings.register_all(); 
     104    settings.notify(); 
     105 
    63106 
    64107#ifndef USE_SSL 
    65   if (bUseSSL_) { 
    66     NSC_LOG_ERROR_STD(_T("SSL not avalible! (not compiled with openssl support)")); 
    67   } 
     108    if (info_.use_ssl) { 
     109      NSC_LOG_ERROR_STD(_T("SSL not avalible! (not compiled with openssl support)")); 
     110    } 
    68111#endif 
    69  
    70   noPerfData_ = SETTINGS_GET_INT(nrpe::ALLOW_PERFDATA)==0; 
    71   timeout = SETTINGS_GET_INT(nrpe::READ_TIMEOUT); 
    72   info_.request_handler->set_payload_length(SETTINGS_GET_INT(nrpe::PAYLOAD_LENGTH)); 
    73   if (info_.request_handler->get_payload_length() != 1024) 
    74     NSC_DEBUG_MSG_STD(_T("Non-standard buffer length (hope you have recompiled check_nrpe changing #define MAX_PACKETBUFFER_LENGTH = ") + strEx::itos(info_.request_handler->get_payload_length())); 
    75  
    76   boost::asio::io_service io_service_; 
    77   allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts(), io_service_); 
    78   NSC_DEBUG_MSG_STD(_T("Allowed hosts: ") + allowedHosts.to_string()); 
    79   try { 
    80  
    81     boost::filesystem::wpath p = GET_CORE()->getBasePath() + std::wstring(_T("security/nrpe_dh_512.pem")); 
    82     info_.certificate = to_string(p.string()); 
    83     if (boost::filesystem::is_regular(p)) { 
    84       NSC_LOG_ERROR_STD(_T("Certificate not found: ") + p.string()); 
    85     } 
    86     info_.port = to_string(SETTINGS_GET_INT(nrpe::PORT)); 
    87     info_.address = to_string(SETTINGS_GET_STRING(nrpe::BINDADDR)); 
    88     unsigned int backLog = SETTINGS_GET_INT(nrpe::LISTENQUE); // @todo: add to info block 
    89     info_.thread_pool_size = 10; // @todo Add as option 
     112    if (info_.request_handler->get_payload_length() != 1024) 
     113      NSC_DEBUG_MSG_STD(_T("Non-standard buffer length (hope you have recompiled check_nrpe changing #define MAX_PACKETBUFFER_LENGTH = ") + strEx::itos(info_.request_handler->get_payload_length())); 
     114    if (!boost::filesystem::is_regular(info_.certificate)) 
     115      NSC_LOG_ERROR_STD(_T("Certificate not found: ") + info_.certificate); 
     116 
     117    boost::asio::io_service io_service_; 
     118 
     119    allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), _T(",")), getCacheAllowedHosts(), io_service_); 
     120    NSC_DEBUG_MSG_STD(_T("Allowed hosts: ") + allowedHosts.to_string()); 
     121 
    90122    if (mode == NSCAPI::normalStart) { 
    91123      if (info_.use_ssl) { 
    92124#ifdef USE_SSL 
    93125        server_.reset(new nrpe::server::server(info_)); 
    94 //        NSC_LOG_ERROR_STD(_T("SSL not implemented")); 
    95 //        return false; 
    96126#else 
    97127        NSC_LOG_ERROR_STD(_T("SSL is not supported (not compiled with openssl)")); 
     
    114144    return false; 
    115145  } 
     146 
     147 
    116148  return true; 
    117149} 
  • trunk/modules/NRPEServer/NRPEServer.def

    r257 r281  
    44  NSModuleHelperInit 
    55  NSLoadModule 
     6  NSLoadModuleEx 
    67  NSGetModuleName 
    78  NSGetModuleVersion 
  • trunk/modules/NRPEServer/NRPEServer.h

    r278 r281  
    3737  }; 
    3838 
    39   unsigned int timeout; 
    4039  socketHelpers::allowedHosts allowedHosts; 
    41   bool noPerfData_; 
    4240  nrpe::server::server::connection_info info_; 
    4341 
     
    4644  virtual ~NRPEListener(); 
    4745  // Module calls 
    48   bool loadModule(NSCAPI::moduleLoadMode mode); 
     46  bool loadModule(); 
     47  bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 
    4948  bool unloadModule(); 
    5049 
  • trunk/modules/NRPEServer/handler_impl.hpp

    r278 r281  
    1111  bool noPerfData_; 
    1212public: 
    13   handler_impl(unsigned int payload_length) : payload_length_(payload_length), noPerfData_(false) {} 
     13  handler_impl(unsigned int payload_length) : payload_length_(payload_length), noPerfData_(false), allowNasty_(false), allowArgs_(false) {} 
    1414 
    1515  unsigned int get_payload_length() { 
     
    2626  } 
    2727 
     28  virtual void set_allow_arguments(bool v)  { 
     29    allowArgs_ = v; 
     30  } 
     31  virtual void set_allow_nasty_arguments(bool v) { 
     32    allowNasty_ = v; 
     33  } 
     34  virtual void set_perf_data(bool v) { 
     35    noPerfData_ = !v; 
     36  } 
     37 
    2838  void log_debug(std::wstring file, int line, std::wstring msg) { 
    2939    GET_CORE()->Message(NSCAPI::debug, file, line, msg); 
  • trunk/modules/NSCAAgent/NSCAAgent.cpp

    r279 r281  
    4646 * @return true 
    4747 */ 
    48 bool NSCAAgent::loadModule(NSCAPI::moduleLoadMode mode) { 
     48bool NSCAAgent::loadModule() { 
     49  return false; 
     50} 
     51 
     52bool NSCAAgent::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    4953  try { 
    5054 
  • trunk/modules/NSCAAgent/NSCAAgent.h

    r273 r281  
    4141  virtual ~NSCAAgent(); 
    4242  // Module calls 
    43   bool loadModule(NSCAPI::moduleLoadMode mode); 
     43  bool loadModule(); 
     44  bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 
    4445  bool unloadModule(); 
    4546  std::wstring getConfigurationMeta(); 
  • trunk/modules/Scheduler/Scheduler.cpp

    r257 r281  
    2828Scheduler gInstance; 
    2929 
    30 bool Scheduler::loadModule(NSCAPI::moduleLoadMode mode) { 
     30bool Scheduler::loadModule() { 
     31  return false; 
     32} 
     33 
     34bool Scheduler::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 
    3135  try { 
    3236    SETTINGS_REG_PATH(scheduler::SECTION); 
  • trunk/modules/Scheduler/Scheduler.h

    r257 r281  
    3535  virtual ~Scheduler() {} 
    3636  // Module calls 
    37   bool loadModule(NSCAPI::moduleLoadMode mode); 
     37  bool loadModule(); 
     38  bool loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode); 
    3839  bool unloadModule(); 
    3940 
  • trunk/service/CMakeLists.txt

    r270 r281  
    5454    ${NSCP_INCLUDEDIR}/settings/settings_old.hpp 
    5555    ${NSCP_INCLUDEDIR}/settings/settings_registry.hpp 
    56     ${NSCP_INCLUDEDIR}/settings/Settings.h 
     56    ${NSCP_INCLUDEDIR}/settings/settings_core.hpp 
     57    ${NSCP_INCLUDEDIR}/settings/settings_core_impl.hpp 
    5758    ${NSCP_INCLUDEDIR}/com_helpers.hpp 
    5859    ${NSCP_INCLUDEDIR}/dll/dll.hpp 
  • trunk/service/NSCPlugin.cpp

    r257 r281  
    3030 * @param file The file (DLL) to load as a NSC plug in. 
    3131 */ 
    32 NSCPlugin::NSCPlugin(const unsigned int id, const boost::filesystem::wpath file) 
     32NSCPlugin::NSCPlugin(const unsigned int id, const boost::filesystem::wpath file, std::wstring alias) 
    3333  : module_(file.string()) 
    3434  ,fLoadModule(NULL) 
     
    5050  ,broken_(false) 
    5151  ,plugin_id_(id) 
     52  ,alias_(alias) 
    5253{ 
    5354 
     
    137138  if (!fLoadModule) 
    138139    throw NSPluginException(module_, _T("Critical error (fLoadModule)")); 
    139   return fLoadModule(mode); 
     140  return fLoadModule(alias_.c_str(), mode); 
    140141} 
    141142 
     
    356357 
    357358  try { 
    358     fLoadModule = (nscapi::plugin_api::lpLoadModule)module_.load_proc("NSLoadModule"); 
     359    fLoadModule = (nscapi::plugin_api::lpLoadModule)module_.load_proc("NSLoadModuleEx"); 
    359360    if (!fLoadModule) 
    360361      throw NSPluginException(module_, _T("Could not load NSLoadModule")); 
  • trunk/service/NSCPlugin.h

    r257 r281  
    110110  bool broken_; 
    111111  unsigned int plugin_id_; 
     112  std::wstring alias_; 
    112113 
    113114  nscapi::plugin_api::lpModuleHelperInit fModuleHelperInit; 
     
    129130 
    130131public: 
    131   NSCPlugin(const unsigned int id, const boost::filesystem::wpath file); 
     132  NSCPlugin(const unsigned int id, const boost::filesystem::wpath file, std::wstring alias); 
    132133  //NSCPlugin(NSCPlugin &other); 
    133134  virtual ~NSCPlugin(void); 
     
    135136  std::wstring getName(void); 
    136137  std::wstring getDescription(); 
    137   void load_dll(void); 
     138  void load_dll(); 
    138139  bool load_plugin(NSCAPI::moduleLoadMode mode); 
    139140  void setBroken(bool broken); 
  • trunk/service/NSClient++.cpp

    r278 r281  
    1515#include "StdAfx.h" 
    1616#include "NSClient++.h" 
    17 #include <settings/Settings.h> 
     17#include <settings/settings_core.hpp> 
    1818#include <charEx.h> 
    1919//#include <Socket.h> 
     
    3939#include "service_manager.hpp" 
    4040#include <nscapi/nscapi_helper.hpp> 
     41#include "cli_parser.hpp" 
    4142 
    4243#include "../libs/protobuf/plugin.proto.h" 
     
    7778/* 
    7879#define SETTINGS_SET_STRING_CORE(key, value) \ 
    79   Settings::get_settings()->set_string(setting_keys::key ## _PATH, setting_keys::key, value); 
     80  settings::get_settings()->set_string(setting_keys::key ## _PATH, setting_keys::key, value); 
    8081*/ 
    8182/** 
     
    236237bool is_module(boost::filesystem::wpath file )  
    237238{ 
    238   return boost::ends_with(file.string(), _T(".dll")) || boost::ends_with(file.string(), _T(".so")); 
     239#ifdef WIN32 
     240  return boost::ends_with(file.string(), _T(".dll")); 
     241#else 
     242  return boost::ends_with(file.string(), _T(".so")); 
     243#endif 
    239244} 
    240245/** 
     
    268273{ 
    269274  srand( (unsigned)time( NULL ) ); 
     275 
     276  cli_parser parser(&mainClient); 
     277  g_bConsoleLog = true; 
     278 
     279  parser.parse(argc, argv); 
     280 
     281  return -1; 
     282 
    270283  int nRetCode = 0; 
    271284  if ( (argc > 1) && ((*argv[1] == '-') || (*argv[1] == '/')) ) { 
     
    289302      g_bConsoleLog = true; 
    290303      std::wstring password; 
    291       if (!settings_manager::init_settings(mainClient.getBasePath())) { 
     304      if (!settings_manager::init_settings()) { 
    292305        std::wcout << _T("Could not find settings") << std::endl;; 
    293306        return 1; 
     
    319332            LOG_MESSAGE_STD(_T("Found: ") + file); 
    320333            if (is_module(pluginPath / file)) { 
    321               NSCPlugin *plugin = new NSCPlugin(next_plugin_id++, pluginPath / file); 
     334              NSCPlugin *plugin = new NSCPlugin(next_plugin_id++, pluginPath / file, _T("")); 
    322335              std::wstring name = _T("<unknown>"); 
    323336              std::wstring description = _T("<unknown>"); 
     
    400413      client.start(); 
    401414      return 0; 
    402     } else if ( wcscasecmp( _T("settings"), argv[1]+1 ) == 0 ) { 
    403       nsclient::settings_client client(&mainClient); 
    404       g_bConsoleLog = true; 
    405       if (argc > 2) 
    406         client.parse(argv[2], argc-3, argv+3); 
    407       else 
    408         client.help(); 
    409       return 0; 
    410415    } else { 
    411416      std::wcerr << _T("Usage: -version, -about, -install, -uninstall, -start, -stop, -encrypt -settings") << std::endl; 
     
    442447} 
    443448 
    444 void migrate() {} 
    445  
    446449std::list<std::wstring> NSClientT::list_commands() { 
    447450  return commands_.list(); 
     
    459462        info.dll = itr->leaf(); 
    460463        try { 
    461           LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 
    462           NSCPlugin plugin(next_plugin_id_++, pluginPath / file); 
     464          std::wstring alias = settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file.string()); 
     465          LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string() + _T(" as ") + alias); 
     466          NSCPlugin plugin(next_plugin_id_++, pluginPath / file, alias); 
    463467          plugin.load_dll(); 
    464468          plugin.load_plugin(NSCAPI::dontStart); 
     
    488492      if (is_module(modPath / file)) { 
    489493        if (settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, file.string())) { 
    490           if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file.string()) == _T("disabled")) { 
     494          std::wstring alias = settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file.string()); 
     495          if (alias == _T("disabled")) { 
    491496            try { 
    492497              LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 
    493               NSCPlugin plugin(next_plugin_id_++, modPath / file); 
     498              NSCPlugin plugin(next_plugin_id_++, modPath / file, alias); 
    494499              plugin.load_dll(); 
    495500              plugin.load_plugin(mode); 
     
    505510          std::wstring name = file.string(); 
    506511          try { 
    507             NSCPlugin plugin(next_plugin_id_++, modPath / file); 
     512            NSCPlugin plugin(next_plugin_id_++, modPath / file, _T("")); 
    508513            name = plugin.getModule(); 
    509514            plugin.load_dll(); 
     
    519524            LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 
    520525          } 
    521           settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, name, Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false); 
     526          settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, name, settings::settings_core::key_string, desc, desc, _T("disabled"), false); 
    522527        } 
    523528      } 
     
    549554bool NSClientT::initCore(bool boot) { 
    550555  LOG_MESSAGE(_T("Attempting to start NSCLient++ - ") SZVERSION); 
    551   if (!settings_manager::init_settings(getBasePath())) { 
     556  if (!settings_manager::init_settings()) { 
    552557    return false; 
    553558  } 
     
    558563      settings_manager::get_settings()->set_int(_T("Settings"), _T("shared_Session"), 1); 
    559564    enable_shared_session_ = SETTINGS_GET_BOOL_CORE(settings_def::SHARED_SESSION); 
    560   } catch (SettingsException e) { 
     565  } catch (settings_exception e) { 
    561566    LOG_ERROR_CORE_STD(_T("Could not find settings: ") + e.getMessage()); 
    562567  } 
     
    625630  if (boot) { 
    626631    try { 
    627       Settings::string_list list = settings_manager::get_settings()->get_keys(MAIN_MODULES_SECTION); 
    628       for (Settings::string_list::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 
     632      settings::string_list list = settings_manager::get_settings()->get_keys(MAIN_MODULES_SECTION); 
     633      for (settings::string_list::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 
    629634        std::wstring file = NSCPlugin::get_plugin_file(*cit); 
    630         LOG_DEBUG_STD(_T("Processing plugin: " + *cit) + _T(" in ") + file); 
     635        std::wstring alias; 
    631636        try { 
    632           if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, *cit) == _T("disabled")) { 
     637          alias = settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, *cit); 
     638          if (alias == _T("disabled")) { 
    633639            LOG_DEBUG_STD(_T("Not booting: ") + file + _T(" since it is disabled.")); 
    634640            continue; 
    635           } 
     641          } else if (alias == _T("enabled")) 
     642            alias = _T(""); 
     643 
    636644        } catch (...) { 
    637645          // If we except we load the plugin in as-is 
    638646        } 
     647        LOG_DEBUG_STD(_T("Processing plugin: " + *cit) + _T(" in ") + file + _T(" as ") + alias); 
    639648        try { 
    640           loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(file)); 
     649          loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(file), alias); 
    641650        } catch(const NSPluginException& e) { 
    642651          LOG_ERROR_CORE_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); 
     
    650659        } 
    651660      } 
    652     } catch (SettingsException e) { 
     661    } catch (settings_exception e) { 
    653662      LOG_ERROR_CORE_STD(_T("Failed to set settings file") + e.getMessage()); 
    654663    } catch (...) { 
     
    838847  } 
    839848  try { 
    840     plugin_type plugin = loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(module)); 
     849    plugin_type plugin = loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(module), _T("")); 
    841850    LOG_DEBUG_STD(_T("Loading plugin: ") + plugin->getName() + _T("...")); 
    842851    plugin->load_plugin(NSCAPI::dontStart); 
     
    853862 * @param plugins A list with plug-ins (DLL files) to load 
    854863 */ 
    855 void NSClientT::addPlugins(const std::list<std::wstring> plugins) { 
    856   boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(10)); 
    857   if (!readLock.owns_lock()) { 
    858     LOG_ERROR_CORE(_T("FATAL ERROR: Could not get read-mutex.")); 
    859     return; 
    860   } 
    861   std::list<std::wstring>::const_iterator it; 
    862   for (it = plugins.begin(); it != plugins.end(); ++it) { 
    863     loadPlugin(*it); 
    864   } 
    865 } 
     864// void NSClientT::addPlugins(const std::list<std::wstring> plugins) { 
     865// boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(10)); 
     866// if (!readLock.owns_lock()) { 
     867//    LOG_ERROR_CORE(_T("FATAL ERROR: Could not get read-mutex.")); 
     868//    return; 
     869// } 
     870// std::list<std::wstring>::const_iterator it; 
     871// for (it = plugins.begin(); it != plugins.end(); ++it) { 
     872//    loadPlugin(*it); 
     873// } 
     874// } 
    866875/** 
    867876 * Unload all plug-ins (in reversed order) 
     
    935944    } 
    936945    for (pluginList::iterator it=plugins_.begin(); it != plugins_.end();) { 
    937       LOG_DEBUG_STD(_T("Loading plugin: ") + (*it)->getName() + _T("...")); 
     946      LOG_DEBUG_STD(_T(" * * * (FIX THIS) Loading plugin: ") + (*it)->getName() + _T("...")); 
    938947      try { 
    939948        if (!(*it)->load_plugin(NSCAPI::normalStart)) { 
     
    972981 * @param file The DLL file 
    973982 */ 
    974 NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file) { 
    975   plugin_type plugin(new NSCPlugin(next_plugin_id_++, file)); 
     983NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file, std::wstring alias) { 
     984  plugin_type plugin(new NSCPlugin(next_plugin_id_++, file, alias)); 
    976985  return addPlugin(plugin); 
    977986} 
     
    9961005    if (plugin->hasMessageHandler()) 
    9971006      messageHandlers_.insert(messageHandlers_.end(), plugin); 
    998     settings_manager::get_core()->register_key(_T("/modules"), plugin->getModule(), Settings::SettingsCore::key_string, plugin->getName(), plugin->getDescription(), _T(""), false); 
     1007    settings_manager::get_core()->register_key(_T("/modules"), plugin->getModule(), settings::settings_core::key_string, plugin->getName(), plugin->getDescription(), _T(""), false); 
    9991008  } 
    10001009  return plugin; 
     
    10171026    try { 
    10181027      len = settings_manager::get_settings()->get_int(SETTINGS_KEY(settings_def::PAYLOAD_LEN)); 
    1019     } catch (SettingsException &e) { 
     1028    } catch (settings_exception &e) { 
    10201029      LOG_DEBUG_STD(_T("Failed to get length: ") + e.getMessage()); 
    10211030      return setting_keys::settings_def::PAYLOAD_LEN_DEFAULT; 
     
    11921201      else 
    11931202        debug_ = log_nodebug; 
    1194     } catch (SettingsException e) { 
     1203    } catch (settings_exception e) { 
    11951204      return true; 
    11961205    } 
     
    13261335  try { 
    13271336    settings_manager::get_core()->set_base(basePath); 
    1328   } catch (SettingsException e) { 
     1337  } catch (settings_exception e) { 
    13291338    LOG_ERROR_CORE_STD(_T("Failed to set settings file: ") + e.getMessage()); 
    13301339  } catch (...) { 
     
    13851394  exitCore(true); 
    13861395} 
     1396 
     1397 
     1398std::wstring NSClientT::expand_path(std::wstring file) { 
     1399  strEx::replace(file, _T("${certificate-path}"), _T("${shared-path}/security")); 
     1400  strEx::replace(file, _T("${base-path}"), getBasePath().string()); 
     1401#ifdef WIN32 
     1402  strEx::replace(file, _T("${shared-path}"), getBasePath().string()); 
     1403#else 
     1404  strEx::replace(file, _T("${shared-path}"), _T("/usr/shared/nsclient++")); 
     1405#endif 
     1406  strEx::replace(file, _T("${exe-path}"), getBasePath().string()); 
     1407  strEx::replace(file, _T("${etc}"), _T("/etc")); 
     1408  return file; 
     1409} 
     1410 
    13871411#ifdef _WIN32 
    13881412void NSClientT::handle_session_change(unsigned long dwSessionId, bool logon) { 
  • trunk/service/NSClient++.h

    r257 r281  
     1 
    12/************************************************************************** 
    23*   Copyright (C) 2004-2007 by Michael Medin <michael@medin.name>         * 
     
    173174  int commandLineExec(const wchar_t* module, const unsigned int argLen, wchar_t** args); 
    174175 
    175   void addPlugins(const std::list<std::wstring> plugins); 
    176   plugin_type loadPlugin(const boost::filesystem::wpath plugin); 
     176  plugin_type loadPlugin(const boost::filesystem::wpath plugin, std::wstring alias); 
    177177  void loadPlugins(NSCAPI::moduleLoadMode mode); 
    178178  void unloadPlugins(bool unloadLoggers); 
     
    202202  } 
    203203 
     204  std::wstring expand_path(std::wstring file); 
     205 
    204206 
    205207  public: 
  • trunk/service/core_api.cpp

    r271 r281  
    2323//#include <settings/settings_registry.hpp> 
    2424//#include <settings/settings_old.hpp> 
    25 #ifdef WIN32x 
    26 #include <Userenv.h> 
    27 #endif 
    28 #include <settings/Settings.h> 
     25#include <settings/settings_core.hpp> 
    2926#include "settings_manager_impl.h" 
    3027#include <b64/b64.h> 
     
    4744#define LOG_ANY(msg, type) NSAPIMessage(type, __FILEW__, __LINE__, msg) 
    4845 
     46NSCAPI::errorReturn NSAPIExpandPath(const wchar_t* key, wchar_t* buffer,unsigned int bufLen) { 
     47  try { 
     48    return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, mainClient.expand_path(key), NSCAPI::isSuccess); 
     49  } catch (...) { 
     50    LOG_ERROR_STD(_T("Failed to getString: ") + key); 
     51    return NSCAPI::hasFailed; 
     52  } 
     53} 
     54 
    4955NSCAPI::errorReturn NSAPIGetSettingsString(const wchar_t* section, const wchar_t* key, const wchar_t* defaultValue, wchar_t* buffer, unsigned int bufLen) { 
    5056  try { 
     
    5864  try { 
    5965    return settings_manager::get_settings()->get_int(section, key, defaultValue); 
    60   } catch (SettingsException e) { 
     66  } catch (settings_exception e) { 
    6167    LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 
    6268    return defaultValue; 
     
    98104    *bufLen = len; 
    99105    return NSCAPI::isSuccess; 
    100   } catch (SettingsException e) { 
     106  } catch (settings_exception e) { 
    101107    LOG_ERROR_STD(_T("Failed to get section: ") + e.getMessage()); 
    102108  } catch (...) { 
     
    222228  return NSCAPI::isSuccess; 
    223229} 
    224 NSCAPI::errorReturn NSAPIWriteSettings(int type) { 
    225   try { 
    226     if (type == NSCAPI::settings_registry) 
    227       settings_manager::get_core()->migrate_to(Settings::SettingsCore::registry); 
    228     else if (type == NSCAPI::settings_inifile) 
    229       settings_manager::get_core()->migrate_to(Settings::SettingsCore::ini_file); 
    230     else 
    231       settings_manager::get_settings()->save(); 
    232   } catch (SettingsException e) { 
     230NSCAPI::errorReturn NSAPIWriteSettings(const wchar_t* key) { 
     231  try { 
     232    settings::instance_ptr inst = settings_manager::get_core()->create_instance(key); 
     233    if (!inst) { 
     234      LOG_ERROR_STD(_T("Failed to create settings: ") + key); 
     235      return NSCAPI::hasFailed; 
     236    } 
     237    settings_manager::get_core()->migrate_to(inst); 
     238  } catch (settings_exception e) { 
    233239    LOG_ERROR_STD(_T("Failed to write settings: ") + e.getMessage()); 
    234240    return NSCAPI::hasFailed; 
     
    239245  return NSCAPI::isSuccess; 
    240246} 
    241 NSCAPI::errorReturn NSAPIReadSettings(int type) { 
    242   try { 
    243     if (type == NSCAPI::settings_registry) 
    244       settings_manager::get_core()->migrate_from(Settings::SettingsCore::registry); 
    245     else if (type == NSCAPI::settings_inifile) 
    246       settings_manager::get_core()->migrate_from(Settings::SettingsCore::ini_file); 
    247     else 
    248       settings_manager::get_settings()->reload(); 
    249   } catch (SettingsException e) { 
     247NSCAPI::errorReturn NSAPIReadSettings(const wchar_t* key) { 
     248  try { 
     249    settings::instance_ptr inst = settings_manager::get_core()->create_instance(key); 
     250    if (!inst) { 
     251      LOG_ERROR_STD(_T("Failed to create settings: ") + key); 
     252      return NSCAPI::hasFailed; 
     253    } 
     254    settings_manager::get_core()->migrate_from(inst); 
     255    settings_manager::get_settings()->reload(); 
     256  } catch (settings_exception e) { 
    250257    LOG_ERROR_STD(_T("Failed to read settings: ") + e.getMessage()); 
    251258    return NSCAPI::hasFailed; 
     
    289296  try { 
    290297    if (type == NSCAPI::key_string) 
    291       settings_manager::get_core()->register_key(path, key, Settings::SettingsCore::key_string, title, description, defVal, advanced); 
     298      settings_manager::get_core()->register_key(path, key, settings::settings_core::key_string, title, description, defVal, advanced); 
    292299    if (type == NSCAPI::key_bool) 
    293       settings_manager::get_core()->register_key(path, key, Settings::SettingsCore::key_bool, title, description, defVal, advanced); 
     300      settings_manager::get_core()->register_key(path, key, settings::settings_core::key_bool, title, description, defVal, advanced); 
    294301    if (type == NSCAPI::key_integer) 
    295       settings_manager::get_core()->register_key(path, key, Settings::SettingsCore::key_integer, title, description, defVal, advanced); 
    296     return NSCAPI::hasFailed; 
    297   } catch (SettingsException e) { 
     302      settings_manager::get_core()->register_key(path, key, settings::settings_core::key_integer, title, description, defVal, advanced); 
     303    return NSCAPI::hasFailed; 
     304  } catch (settings_exception e) { 
    298305    LOG_ERROR_STD(_T("Failed register key: ") + e.getMessage()); 
    299306    return NSCAPI::hasFailed; 
     
    309316  try { 
    310317    settings_manager::get_core()->register_path(path, title, description, advanced); 
    311   } catch (SettingsException e) { 
     318  } catch (settings_exception e) { 
    312319    LOG_ERROR_STD(_T("Failed register path: ") + e.getMessage()); 
    313320    return NSCAPI::hasFailed; 
     
    355362  try { 
    356363    settings_manager::get_settings()->save(); 
    357   } catch (SettingsException e) { 
     364  } catch (settings_exception e) { 
    358365    LOG_ERROR_STD(_T("Failed to save: ") + e.getMessage()); 
    359366    return NSCAPI::hasFailed; 
     
    426433  if (wcscasecmp(buffer, _T("NSAPIDestroyBuffer")) == 0) 
    427434    return reinterpret_cast<LPVOID>(&NSAPIDestroyBuffer); 
     435  if (wcscasecmp(buffer, _T("NSAPIExpandPath")) == 0) 
     436    return reinterpret_cast<LPVOID>(&NSAPIExpandPath); 
    428437 
    429438  LOG_ERROR_STD(_T("Function not found: ") + buffer); 
  • trunk/service/core_api.h

    r257 r281  
    4646NSCAPI::errorReturn NSAPISetSettingsString(const wchar_t* section, const wchar_t* key, const wchar_t* value); 
    4747NSCAPI::errorReturn NSAPISetSettingsInt(const wchar_t* section, const wchar_t* key, int value); 
    48 NSCAPI::errorReturn NSAPIWriteSettings(int type); 
    49 NSCAPI::errorReturn NSAPIReadSettings(int type); 
     48NSCAPI::errorReturn NSAPIWriteSettings(const wchar_t* key); 
     49NSCAPI::errorReturn NSAPIReadSettings(const wchar_t* key); 
    5050NSCAPI::errorReturn NSAPIRehash(int flag); 
    5151NSCAPI::errorReturn NSAPIDescribeCommand(const wchar_t*,wchar_t*,unsigned int); 
     
    6060NSCAPI::errorReturn NSAPINotify(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, char*, unsigned int); 
    6161void NSAPIDestroyBuffer(char**); 
     62NSCAPI::errorReturn NSAPIExpandPath(const wchar_t*,wchar_t*,unsigned int); 
  • trunk/service/settings_client.hpp

    r230 r281  
    77    NSClient* core_; 
    88  public: 
    9     settings_client(NSClient* core) : core_(core) { 
     9    settings_client(NSClient* core) : core_(core) {} 
    1010 
     11    std::wstring get_source() { 
     12      settings_manager::get_core()->get()->get_context(); 
    1113    } 
    12     void parse(std::wstring sarg, int argc, wchar_t* argv[]) { 
    13       core_->enableDebug(true); 
    14       if (!core_->initCore(false)) { 
     14 
     15    void boot() { 
     16      if (!core_->initCore(true)) { 
    1517        std::wcout << _T("Service *NOT* started!") << std::endl; 
    1618        return; 
    1719      } 
    18       std::wcout << _T("Using settings from: ") << settings_manager::get_core()->get_settings_type_desc() << std::endl; 
     20    } 
    1921 
     22    void migrate_from(std::wstring src, std::wstring target, bool def) { 
    2023      try { 
    21         if (sarg == _T("migrate")) { 
    22           if (argc == 0) { 
    23             error_msg(_T("In correct syntax: nsclient++ -settings migrate <to>")); 
    24             return; 
    25           } 
    26           std::wstring to = argv[0]; 
    27           debug_msg(_T("Migrating to: ") + to); 
    28           try { 
    29             settings_manager::get_core()->migrate_to(Settings::SettingsCore::string_to_type(to)); 
    30           } catch (SettingsException e) { 
    31             error_msg(_T("Failed to migrate settings: ") + e.getError()); 
    32           } 
    33         } else if (sarg == _T("generate")) { 
    34           if (argc == 0) { 
    35             error_msg(_T("In correct syntax: nsclient++ -settings generate <what>")); 
    36             error_msg(_T("     where <what> is one of ths following:")); 
    37             error_msg(_T("      trac")); 
    38             error_msg(_T("      default")); 
    39             error_msg(_T("      <type>")); 
    40             return; 
    41           } 
    42           std::wstring arg1 = argv[0]; 
    43           if (arg1 == _T("default")) { 
    44             try { 
    45               core_->load_all_plugins(NSCAPI::dontStart); 
    46               settings_manager::get_core()->update_defaults(); 
    47               settings_manager::get_core()->get()->save(); 
    48             } catch (SettingsException e) { 
    49               error_msg(_T("Failed to migrate settings: ") + e.getError()); 
    50             } 
    51           } else if (arg1 == _T("trac")) { 
    52             try { 
    53               core_->load_all_plugins(NSCAPI::dontStart); 
    54  
    55               Settings::string_list s = settings_manager::get_core()->get_reg_sections(); 
    56               for (Settings::string_list::const_iterator cit = s.begin(); cit != s.end(); ++cit) { 
    57                 std::wcout << _T("== ") << (*cit) << _T(" ==") << std::endl; 
    58                 Settings::string_list k = settings_manager::get_core()->get_reg_keys(*cit); 
    59                 bool first = true; 
    60                 for (Settings::string_list::const_iterator citk = k.begin(); citk != k.end(); ++citk) { 
    61                   Settings::SettingsCore::key_description desc = settings_manager::get_core()->get_registred_key(*cit, *citk); 
    62                   if (!desc.advanced) { 
    63                     if (first) 
    64                       std::wcout << _T("'''Normal settings'''") << std::endl; 
    65                     first = false; 
    66                     std::wcout << _T("||") << (*citk) << _T("||") << desc.defValue << _T("||") << desc.title << _T(": ") << desc.description 
    67                       << std::endl; 
    68                   } 
    69                 } 
    70                 first = true; 
    71                 for (Settings::string_list::const_iterator citk = k.begin(); citk != k.end(); ++citk) { 
    72                   Settings::SettingsCore::key_description desc = settings_manager::get_core()->get_registred_key(*cit, *citk); 
    73                   if (desc.advanced) { 
    74                     if (first) 
    75                       std::wcout << _T("'''Advanced settings'''") << std::endl; 
    76                     first = false; 
    77                     std::wcout << _T("||") << (*citk) << _T("||") << desc.defValue << _T("||") << desc.title << _T(": ") << desc.description 
    78                       << std::endl; 
    79                   } 
    80                 } 
    81               } 
    82             } catch (SettingsException e) { 
    83               error_msg(_T("Failed to migrate settings: ") + e.getError()); 
    84             } 
    85           } else { 
    86             try { 
    87               Settings::SettingsCore::settings_type type = settings_manager::get_core()->string_to_type(arg1); 
    88               core_->load_all_plugins(NSCAPI::dontStart); 
    89               settings_manager::get_core()->update_defaults(); 
    90               settings_manager::get_core()->get(type)->save(); 
    91             } catch (SettingsException e) { 
    92               error_msg(_T("Failed to migrate settings: ") + e.getError()); 
    93             } 
    94           } 
     24        if (def) 
     25          settings_manager::get_core()->update_defaults(); 
     26        if (!src.empty() && !target.empty()) { 
     27          debug_msg(_T("Migrating ") + src + _T(" to ") + target); 
     28          settings_manager::get_core()->migrate(src, target); 
    9529        } else { 
    96           std::wcout << _T("Unknown keyword: ") << sarg << std::endl; 
    97           help(); 
     30          debug_msg(_T("Migrating ") + src + _T(" to ") + target); 
     31          settings_manager::get_core()->migrate_from(src); 
    9832        } 
    99  
    100  
    101       } catch (SettingsException e) { 
     33        core_->exitCore(true); 
     34      } catch (settings_exception e) { 
    10235        error_msg(_T("Failed to initialize settings: ") + e.getError()); 
    10336      } catch (...) { 
    10437        error_msg(_T("FATAL ERROR IN SETTINGS SUBSYTEM")); 
    10538      } 
     39    } 
     40    void migrate_to(std::wstring src, std::wstring target, bool def) { 
     41      try { 
     42        if (def) 
     43          settings_manager::get_core()->update_defaults(); 
     44        if (!src.empty() && !target.empty()) { 
     45          debug_msg(_T("Migrating ") + src + _T(" to ") + target); 
     46          settings_manager::get_core()->migrate(src, target); 
     47        } else { 
     48          debug_msg(_T("Migrating ") + src + _T(" to ") + target); 
     49          settings_manager::get_core()->migrate_to(target); 
     50        } 
     51        core_->exitCore(true); 
     52      } catch (settings_exception e) { 
     53        error_msg(_T("Failed to initialize settings: ") + e.getError()); 
     54      } catch (...) { 
     55        error_msg(_T("FATAL ERROR IN SETTINGS SUBSYTEM")); 
     56      } 
     57    } 
    10658 
     59    void generate(std::wstring target) { 
     60      try { 
     61        core_->load_all_plugins(NSCAPI::dontStart); 
     62        if (target == _T("default") || target.empty()) { 
     63          settings_manager::get_core()->update_defaults(); 
     64          settings_manager::get_core()->get()->save(); 
     65        } else if (target == _T("trac")) { 
     66          settings::string_list s = settings_manager::get_core()->get_reg_sections(); 
     67          for (settings::string_list::const_iterator cit = s.begin(); cit != s.end(); ++cit) { 
     68            std::wcout << _T("== ") << (*cit) << _T(" ==") << std::endl; 
     69            settings::string_list k = settings_manager::get_core()->get_reg_keys(*cit); 
     70            bool first = true; 
     71            for (settings::string_list::const_iterator citk = k.begin(); citk != k.end(); ++citk) { 
     72              settings::settings_core::key_description desc = settings_manager::get_core()->get_registred_key(*cit, *citk); 
     73              if (!desc.advanced) { 
     74                if (first) 
     75                  std::wcout << _T("'''Normal settings'''") << std::endl; 
     76                first = false; 
     77                std::wcout << _T("||") << (*citk) << _T("||") << desc.defValue << _T("||") << desc.title << _T(": ") << desc.description << std::endl; 
     78              } 
     79            } 
     80            first = true; 
     81            for (settings::string_list::const_iterator citk = k.begin(); citk != k.end(); ++citk) { 
     82              settings::settings_core::key_description desc = settings_manager::get_core()->get_registred_key(*cit, *citk); 
     83              if (desc.advanced) { 
     84                if (first) 
     85                  std::wcout << _T("'''Advanced settings'''") << std::endl; 
     86                first = false; 
     87                std::wcout << _T("||") << (*citk) << _T("||") << desc.defValue << _T("||") << desc.title << _T(": ") << desc.description << std::endl; 
     88              } 
     89            } 
     90          } 
     91        } else { 
     92          settings_manager::get_core()->update_defaults(); 
     93          settings_manager::get_core()->get()->save_to(target); 
     94        } 
     95      } catch (settings_exception e) { 
     96        error_msg(_T("Failed to initialize settings: ") + e.getError()); 
     97      } catch (...) { 
     98        error_msg(_T("FATAL ERROR IN SETTINGS SUBSYTEM")); 
     99      } 
    107100      core_->exitCore(true); 
    108101    } 
    109  
    110102    void error_msg(std::wstring msg) { 
    111103      core_->reportMessage(NSCAPI::error, __FILEW__, __LINE__, msg.c_str()); 
     
    114106      core_->reportMessage(NSCAPI::debug, __FILEW__, __LINE__, msg.c_str()); 
    115107    } 
    116  
    117     void help() { 
    118       std::wcout << _T("Usage: nsclient++ -settings <key>") << std::endl; 
    119       std::wcout << _T("In correct syntax: nsclient++ -settings <keyword>") << std::endl; 
    120       std::wcout << _T(" <keyword> : ") << std::endl; 
    121       std::wcout << _T("   migrate - migrate to a new setings subsystem") << std::endl; 
    122       std::wcout << _T("   copy    - copy settings from one subsystem to another") << std::endl; 
    123       std::wcout << _T("   set     - Set a setting system as the default store") << std::endl; 
    124     } 
    125  
    126108  }; 
    127109} 
  • trunk/service/settings_logger_impl.hpp

    r205 r281  
    22 
    33#include "core_api.h" 
    4 #include <settings/Settings.h> 
     4#include <settings/settings_core.hpp> 
    55 
    6 class settings_logger : public Settings::LoggerInterface { 
     6class settings_logger : public settings::logger_interface { 
    77public: 
    88  ////////////////////////////////////////////////////////////////////////// 
  • trunk/service/settings_manager_impl.cpp

    r216 r281  
    22 
    33#include "settings_manager_impl.h" 
     4#include <config.h> 
     5#include "NSClient++.h" 
    46 
    57#define LOG_CRITICAL_STD(msg) LOG_CRITICAL(((std::wstring)msg).c_str()) 
     
    79  NSAPIMessage(NSCAPI::critical, __FILEW__, __LINE__, msg) 
    810 
     11extern NSClient mainClient; 
     12 
    913namespace settings_manager { 
    1014  // Alias to make handling "compatible" with old syntax 
    11   Settings::SettingsInterface* get_settings() { 
     15  boost::shared_ptr<settings::settings_interface> get_settings() { 
    1216    return SettingsHandler::getInstance()->get(); 
    1317  } 
    14   Settings::SettingsCore* get_core() { 
     18  settings::settings_core* get_core() { 
    1519    return SettingsHandler::getInstance(); 
    1620  } 
     
    1822    SettingsHandler::destroyInstance(); 
    1923  } 
    20   bool init_settings(boost::filesystem::wpath path) { 
     24 
     25  std::wstring NSCSettingsImpl::find_file(std::wstring file, std::wstring fallback) { 
     26    // @todo: replace this with a proper parser! 
     27    if (file.size() == 0) 
     28      file = fallback; 
     29    return mainClient.expand_path(file); 
     30  } 
     31 
     32  ////////////////////////////////////////////////////////////////////////// 
     33  /// Create an instance of a given type. 
     34  /// Used internally to create instances of various settings types. 
     35  /// 
     36  /// @param type the type to create 
     37  /// @param context the context to use 
     38  /// @return a new instance of given type. 
     39  /// 
     40  /// @author mickem 
     41  settings::instance_ptr NSCSettingsImpl::create_instance(std::wstring key) { 
     42    net::url url = net::parse(key); 
     43    get_logger()->debug(__FILEW__, __LINE__, _T("Trying to create: ") + url.protocol + _T(": ") + key); 
     44#ifdef WIN32 
     45    if (url.protocol == _T("old")) { 
     46      old_ = true; 
     47      return settings::instance_ptr(new settings::OLDSettings(this, key)); 
     48    }  
     49    if (url.protocol == _T("registry")) 
     50      return settings::instance_ptr(new settings::REGSettings(this, key)); 
     51#endif 
     52    if (url.protocol == _T("ini")) 
     53      return settings::instance_ptr(new settings::INISettings(this, key)); 
     54    throw settings_exception(_T("Undefined settings protocol: ") + url.protocol); 
     55  } 
     56 
     57  ////////////////////////////////////////////////////////////////////////// 
     58  /// Boot the settings subsystem from the given file (boot.ini). 
     59  /// 
     60  /// @param file the file to use when booting. 
     61  /// 
     62  /// @author mickem 
     63  void NSCSettingsImpl::boot(std::wstring file) { 
     64    boot_ = get_base() / file; 
     65    std::wstring key = get_boot_string(_T("settings"), _T("location"), DEFAULT_CONF_LOCATION); 
     66    get_logger()->debug(__FILEW__, __LINE__, _T("Trying to boot: ") + key + _T(" from base: ") + boot_.string()); 
     67    set_instance(key); 
     68  } 
     69 
     70  bool init_settings() { 
    2171    try { 
    2272      get_core()->set_logger(new settings_logger()); 
    23       get_core()->set_base(path); 
     73      get_core()->set_base(mainClient.expand_path(_T("${base-path}"))); 
    2474      get_core()->boot(_T("boot.ini")); 
    25       get_core()->register_key(SETTINGS_REG_KEY_I_GEN(settings_def::PAYLOAD_LEN, Settings::SettingsCore::key_integer)); 
    26       get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::ALLOWED_HOSTS, Settings::SettingsCore::key_string)); 
    27       get_core()->register_key(SETTINGS_REG_KEY_B_GEN(protocol_def::CACHE_ALLOWED, Settings::SettingsCore::key_bool)); 
    28       get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::MASTER_KEY, Settings::SettingsCore::key_string)); 
    29       get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::PWD, Settings::SettingsCore::key_string)); 
    30       get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::OBFUSCATED_PWD, Settings::SettingsCore::key_string)); 
     75      get_core()->register_key(SETTINGS_REG_KEY_I_GEN(settings_def::PAYLOAD_LEN, settings::settings_core::key_integer)); 
     76      get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::ALLOWED_HOSTS, settings::settings_core::key_string)); 
     77      get_core()->register_key(SETTINGS_REG_KEY_B_GEN(protocol_def::CACHE_ALLOWED, settings::settings_core::key_bool)); 
     78      get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::MASTER_KEY, settings::settings_core::key_string)); 
     79      get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::PWD, settings::settings_core::key_string)); 
     80      get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::OBFUSCATED_PWD, settings::settings_core::key_string)); 
     81      LOG_CRITICAL_STD(_T("Loaded: ") + get_core()->to_string()); 
    3182 
    32     } catch (SettingsException e) { 
     83    } catch (settings_exception e) { 
    3384      LOG_CRITICAL_STD(_T("Failed to initialize settings: ") + e.getError()); 
    3485      return false; 
  • trunk/service/settings_manager_impl.h

    r216 r281  
    22 
    33#include "settings_logger_impl.hpp" 
    4 #include <settings/Settings.h> 
     4#include <settings/settings_core.hpp> 
    55#include <settings/settings_ini.hpp> 
    66#ifdef WIN32 
     
    1010 
    1111namespace settings_manager { 
    12   class NSCSettingsImpl : public Settings::SettingsHandlerImpl { 
     12  class NSCSettingsImpl : public settings::settings_handler_impl { 
    1313  private: 
    1414    boost::filesystem::wpath boot_; 
     
    3636#endif 
    3737    } 
    38     ////////////////////////////////////////////////////////////////////////// 
    39     /// Boot the settings subsystem from the given file (boot.ini). 
    40     /// 
    41     /// @param file the file to use when booting. 
    42     /// 
    43     /// @author mickem 
    44     void boot(std::wstring file = _T("boot.ini")) { 
    45       boot_ = get_base() / file; 
    46 #ifdef WIN32 
    47       std::wstring subsystem = get_boot_string(_T("settings"), _T("type"), _T("old")); 
    48 #else 
    49       std::wstring subsystem = get_boot_string(_T("settings"), _T("type"), _T("ini")); 
    50 #endif 
    51       get_logger()->debug(__FILEW__, __LINE__, _T("Trying to boot: ") + subsystem + _T(" from base: ") + boot_.string()); 
    52       settings_type type = string_to_type(subsystem); 
    53       std::wstring context = get_boot_string(_T("settings"), _T("context"), subsystem); 
    54       Settings::SettingsInterface *impl = create_instance(type, context); 
    55       if (impl == NULL) 
    56         throw Settings::SettingsException(_T("Could not create settings instance: ") + subsystem); 
    57       add_type_impl(type, impl); 
    58       set_type(type); 
    59     } 
    60     ////////////////////////////////////////////////////////////////////////// 
    61     /// Create an instance of a given type. 
    62     /// Used internally to create instances of various settings types. 
    63     /// 
    64     /// @param type the type to create 
    65     /// @param context the context to use 
    66     /// @return a new instance of given type. 
    67     /// 
    68     /// @author mickem 
    69     Settings::SettingsInterface* create_instance(settings_type type, std::wstring context) { 
    70       get_logger()->debug(__FILEW__, __LINE__, _T("Trying to create: ") + SettingsCore::type_to_string(type) + _T(": ") + context); 
    71 #ifdef WIN32 
    72       if (type == SettingsCore::old_ini_file) { 
    73         old_ = true; 
    74         return new Settings::OLDSettings(this, context); 
    75       }  
    76       if (type == SettingsCore::registry) 
    77         return new Settings::REGSettings(this, context); 
    78 #endif 
    79       if (type == SettingsCore::ini_file) 
    80         return new Settings::INISettings(this, context); 
    81       throw SettingsException(_T("Undefined settings type: ") + SettingsCore::type_to_string(type)); 
    82     } 
    8338 
     39    void boot(std::wstring file = _T("boot.ini")); 
     40    std::wstring find_file(std::wstring file, std::wstring fallback = _T("")); 
     41    std::wstring expand_path(std::wstring file); 
     42    settings::instance_ptr create_instance(std::wstring key); 
    8443  }; 
    8544 
     
    8746 
    8847  // Alias to make handling "compatible" with old syntax 
    89   Settings::SettingsInterface* get_settings(); 
    90   Settings::SettingsCore* get_core(); 
     48  settings::instance_ptr get_settings(); 
     49  settings::settings_core* get_core(); 
    9150  void destroy_settings(); 
    92   bool init_settings(boost::filesystem::wpath path); 
     51  bool init_settings(); 
    9352} 
  • trunk/service/simple_client.hpp

    r257 r281  
    1414        return; 
    1515      } 
    16       std::wcout << _T("Using settings from: ") << settings_manager::get_core()->get_settings_type_desc() << std::endl; 
     16      //std::wcout << _T("Using settings from: ") << settings_manager::get_core()->get_settings_type_desc() << std::endl; 
    1717      std::wcout << _T("Enter command to inject or exit to terminate...") << std::endl; 
    1818/* 
Note: See TracChangeset for help on using the changeset viewer.