Changeset 497b779 in nscp for include


Ignore:
Timestamp:
08/19/10 13:36:13 (3 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
de7ec29
Parents:
184d575
Message:

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

Location:
include
Files:
4 added
18 edited

Legend:

Unmodified
Added
Removed
  • include/NSCAPI.h

    rcad08fb r497b779  
    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); 
  • include/config.h.in

    r92c4b5b r497b779  
    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 
  • include/file_helpers.hpp

    r79e734f r497b779  
    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: 
  • include/nrpe/server/handler.hpp

    r294b37b r497b779  
    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    }; 
  • include/nrpe/server/server.cpp

    r184d575 r497b779  
    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(), 
  • include/nrpe/server/server.hpp

    r184d575 r497b779  
    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); 
  • include/nscapi/macros.hpp

    r294b37b r497b779  
    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  } \ 
  • include/nscapi/nscapi_core_wrapper.cpp

    r8988f9e r497b779  
    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; 
  • include/nscapi/nscapi_core_wrapper.hpp

    rb0e7ecf r497b779  
    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); 
  • include/nscapi/nscapi_plugin_wrapper.hpp

    r8988f9e r497b779  
    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 
  • include/nscapi/plugin.hpp

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

    r3080680 r497b779  
    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. 
  • include/settings/macros.h

    r294b37b r497b779  
    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  } 
  • include/settings/settings_ini.hpp

    r3080680 r497b779  
    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} 
  • include/settings/settings_old.hpp

    r3080680 r497b779  
    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} 
  • include/settings/settings_registry.hpp

    r3080680 r497b779  
    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} 
  • include/simple_timer.hpp

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

    r8988f9e r497b779  
    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> 
Note: See TracChangeset for help on using the changeset viewer.