- Timestamp:
- 08/19/10 13:36:13 (3 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- de7ec29
- Parents:
- 184d575
- Location:
- include
- Files:
-
- 4 added
- 18 edited
-
NSCAPI.h (modified) (2 diffs)
-
config.h.in (modified) (1 diff)
-
file_helpers.hpp (modified) (2 diffs)
-
nrpe/server/handler.hpp (modified) (1 diff)
-
nrpe/server/server.cpp (modified) (4 diffs)
-
nrpe/server/server.hpp (modified) (1 diff)
-
nscapi/macros.hpp (modified) (2 diffs)
-
nscapi/nscapi_core_wrapper.cpp (modified) (2 diffs)
-
nscapi/nscapi_core_wrapper.hpp (modified) (3 diffs)
-
nscapi/nscapi_plugin_wrapper.hpp (modified) (3 diffs)
-
nscapi/plugin.hpp (modified) (1 diff)
-
nscapi/settings.cpp (added)
-
nscapi/settings.hpp (added)
-
settings/Settings.h (modified) (5 diffs)
-
settings/macros.h (modified) (4 diffs)
-
settings/settings_core.hpp (added)
-
settings/settings_core_impl.hpp (added)
-
settings/settings_ini.hpp (modified) (16 diffs)
-
settings/settings_old.hpp (modified) (21 diffs)
-
settings/settings_registry.hpp (modified) (13 diffs)
-
simple_timer.hpp (modified) (1 diff)
-
strEx.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
include/NSCAPI.h
rcad08fb r497b779 122 122 typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationVersionStr)(wchar_t*,unsigned int); 123 123 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); 124 125 typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsInt)(const wchar_t*, const wchar_t*, int); 125 126 typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSection)(const wchar_t*, wchar_t***, unsigned int *); … … 154 155 namespace plugin_api { 155 156 typedef int (*lpModuleHelperInit)(unsigned int, ::nscapi::core_api::lpNSAPILoader f); 156 typedef int (*lpLoadModule)( int);157 typedef int (*lpLoadModule)(const wchar_t*,int); 157 158 typedef int (*lpGetName)(wchar_t*,unsigned int); 158 159 typedef int (*lpGetDescription)(wchar_t*,unsigned int); -
include/config.h.in
r92c4b5b r497b779 72 72 73 73 #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 74 86 75 87 -
include/file_helpers.hpp
r79e734f r497b779 7 7 public: 8 8 static bool is_directory(std::wstring path) { 9 boost::filesystem::is_directory(path);9 return boost::filesystem::is_directory(path); 10 10 } 11 11 // static bool is_directory(DWORD dwAtt) { … … 37 37 }; 38 38 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 39 57 class patterns { 40 58 public: -
include/nrpe/server/handler.hpp
r294b37b r497b779 19 19 virtual unsigned int get_payload_length() = 0; 20 20 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; 21 24 22 25 }; -
include/nrpe/server/server.cpp
r184d575 r497b779 12 12 13 13 namespace ip = boost::asio::ip; 14 15 16 const int server::connection_info::backlog_default = 0; 14 17 15 18 server::server(connection_info info) … … 27 30 ip::tcp::resolver::iterator endpoint_iterator; 28 31 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())); 30 33 } 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)); 32 35 } 33 36 ip::tcp::resolver::iterator end; … … 39 42 SSL_CTX_set_cipher_list(context_.impl(), "ADH"); 40 43 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)); 42 45 context_.set_verify_mode(boost::asio::ssl::context::verify_none); 43 46 } … … 49 52 acceptor_.set_option(ip::tcp::acceptor::reuse_address(true)); 50 53 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); 52 58 53 59 acceptor_.async_accept(new_connection_->socket(), -
include/nrpe/server/server.hpp
r184d575 r497b779 36 36 public: 37 37 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) {} 39 40 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; 42 46 bool use_ssl; 47 bool allow_args; 48 bool allow_nasty; 49 unsigned int timeout; 43 50 boost::shared_ptr<nrpe::server::handler> request_handler; 44 std:: string certificate;51 std::wstring certificate; 45 52 std::wstring get_endpoint_str() { 46 53 return to_wstring(address) + _T(":") + to_wstring(port); -
include/nscapi/macros.hpp
r294b37b r497b779 6 6 #define NSC_WRAPPERS_MAIN() \ 7 7 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); \ 9 10 extern "C" void NSDeleteBuffer(char**buffer); \ 10 11 extern "C" int NSGetModuleName(wchar_t* buf, int buflen); \ … … 63 64 } \ 64 65 } \ 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)); \ 68 69 } 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; \ 74 86 } \ 75 87 } \ -
include/nscapi/nscapi_core_wrapper.cpp
r8988f9e r497b779 271 271 wchar_t *buffer = new wchar_t[buf_len+1]; 272 272 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 281 std::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) { 273 287 delete [] buffer; 274 288 throw nscapi::nscapi_exception(_T("Settings could not be retrieved.")); … … 575 589 576 590 fNSAPISettingsSave = (nscapi::core_api::lpNSAPISettingsSave)f(_T("NSAPISettingsSave")); 591 592 fNSAPIExpandPath = (nscapi::core_api::lpNSAPIExpandPath)f(_T("NSAPIExpandPath")); 577 593 578 594 return true; -
include/nscapi/nscapi_core_wrapper.hpp
rb0e7ecf r497b779 42 42 nscapi::core_api::lpNSAPIReleaseSettingsSectionBuffer fNSAPIReleaseSettingsSectionBuffer; 43 43 nscapi::core_api::lpNSAPIGetSettingsString fNSAPIGetSettingsString; 44 nscapi::core_api::lpNSAPIExpandPath fNSAPIExpandPath; 44 45 nscapi::core_api::lpNSAPIGetSettingsInt fNSAPIGetSettingsInt; 45 46 nscapi::core_api::lpNSAPIMessage fNSAPIMessage; … … 111 112 , fNSAPIReleasePluginList(NULL) 112 113 , fNSAPISettingsSave(NULL) 114 , fNSAPIExpandPath(NULL) 113 115 , buffer_length_(-1) 114 116 , id_(-1) … … 120 122 std::list<std::wstring> getSettingsSection(std::wstring section); 121 123 std::wstring getSettingsString(std::wstring section, std::wstring key, std::wstring defaultValue); 124 std::wstring expand_path(std::wstring value); 122 125 int getSettingsInt(std::wstring section, std::wstring key, int defaultValue); 123 126 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 170 170 namespace impl { 171 171 172 class simple_plugin { 173 public: 174 nscapi::core_wrapper* get_core() { 175 return nscapi::plugin_singleton->get_core(); 176 } 177 }; 178 172 179 class SimpleNotificationHandler { 173 180 public: … … 220 227 } 221 228 std::wstring msg, perf; 222 NSCAPI::nagiosReturn ret = handleCommand(command , args, msg, perf);229 NSCAPI::nagiosReturn ret = handleCommand(command.c_str(), args, msg, perf); 223 230 224 231 PluginCommand::ResponseMessage response_message; … … 239 246 } 240 247 241 virtual NSCAPI::nagiosReturn handleCommand(const st d::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; 242 249 }; 243 250 -
include/nscapi/plugin.hpp
rb0e7ecf r497b779 2 2 3 3 #include <nscapi/macros.hpp> 4 #include <nscapi/settings.hpp> 4 5 #include <nscapi/nscapi_helper.hpp> 5 6 #include <nscapi/nscapi_plugin_wrapper.hpp> -
include/settings/Settings.h
r3080680 r497b779 29 29 #include <boost/thread/locks.hpp> 30 30 #include <boost/filesystem/path.hpp> 31 #include <boost/regex.hpp> 31 32 #include <strEx.h> 32 33 #define BUFF_LEN 4096 … … 111 112 ini_file, 112 113 xml_file, 114 lua, 113 115 } settings_type; 114 116 typedef enum { … … 157 159 /// @author mickem 158 160 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)) 160 167 return ini_file; 161 if ( key == _T("registry"))168 if (boost::regex_match(key, reg)) 162 169 return registry; 163 if ( key == _T("xml"))164 return xml_file;170 if (boost::regex_match(key, re_lua)) 171 return lua; 165 172 return old_ini_file; 166 173 } … … 1296 1303 path_cache_type path_cache_; 1297 1304 std::wstring context_; 1305 net::url url_; 1298 1306 1299 1307 //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_)) {} 1301 1309 1302 1310 ////////////////////////////////////////////////////////////////////////// … … 1612 1620 return context_; 1613 1621 } 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 1614 1629 ////////////////////////////////////////////////////////////////////////// 1615 1630 /// Set the context. -
include/settings/macros.h
r294b37b r497b779 148 148 namespace nrpe { 149 149 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."); 151 151 152 152 … … 158 158 159 159 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."); 161 161 162 162 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."); 164 164 165 165 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."); 167 167 168 168 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 170 175 171 176 DEFINE_SETTING_B(CACHE_ALLOWED, NRPE_SECTION_PROTOCOL, GENERIC_KEY_SOCK_CACHE_ALLOWED, false); … … 173 178 174 179 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."); 176 181 177 182 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."); 179 184 180 185 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)."); 185 187 186 188 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."); 188 190 189 191 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."); 191 193 192 194 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."); 197 196 198 197 } … … 233 232 namespace external_scripts { 234 233 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)."); 236 235 237 236 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."); 239 238 240 239 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."); 242 241 243 242 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."); 245 244 246 245 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 :)"); 248 247 249 248 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:"); 251 250 252 251 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)"); 254 253 255 254 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", ""); 257 256 258 257 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", ""); 260 259 261 260 } -
include/settings/settings_ini.hpp
r3080680 r497b779 7 7 #include <boost/filesystem/operations.hpp> 8 8 9 #include <settings/Settings.h> 9 #include <settings/settings_core.hpp> 10 #include <settings/settings_core_impl.hpp> 10 11 #include <simpleini/simpleini.h> 11 12 #include <error.hpp> 12 13 13 namespace Settings {14 class INISettings : public Settings::SettingsInterfaceImpl {14 namespace settings { 15 class INISettings : public settings::SettingsInterfaceImpl { 15 16 private: 16 17 boost::filesystem::wpath filename_; … … 19 20 20 21 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 } 22 25 ////////////////////////////////////////////////////////////////////////// 23 26 /// Create a new settings interface of "this kind" … … 38 41 /// 39 42 /// @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) { 41 44 load_data(); 42 45 const wchar_t *val = ini.GetValue(key.first.c_str(), key.second.c_str(), NULL); … … 53 56 /// 54 57 /// @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) { 56 59 std::wstring str = get_real_string(key); 57 60 return strEx::stoi(str); … … 65 68 /// 66 69 /// @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) { 68 71 std::wstring str = get_real_string(key); 69 72 return SettingsInterfaceImpl::string_to_bool(str); … … 77 80 /// 78 81 /// @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) { 80 83 return ini.GetValue(key.first.c_str(), key.second.c_str()) != NULL; 81 84 } … … 86 89 /// 87 90 /// @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 // } 91 94 ////////////////////////////////////////////////////////////////////////// 92 95 /// Is this the active settings store … … 95 98 /// 96 99 /// @author mickem 97 virtual bool is_active() {98 return true;99 }100 // virtual bool is_active() { 101 // return true; 102 // } 100 103 ////////////////////////////////////////////////////////////////////////// 101 104 /// Write a value to the resulting context. … … 105 108 /// 106 109 /// @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) { 108 111 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); 110 113 std::wstring comment = _T("; "); 111 114 if (!desc.title.empty()) … … 120 123 } catch (KeyNotFoundException e) { 121 124 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) { 123 126 get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Failed to write key: ") + e.getError())); 124 127 } catch (...) { … … 130 133 try { 131 134 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); 133 136 if (!desc.description.empty()) { 134 137 std::wstring comment = _T("; ") + desc.description; … … 137 140 } catch (KeyNotFoundException e) { 138 141 ini.SetValue(path.c_str(), NULL, NULL, _T("; Undocumented section")); 139 } catch ( SettingsException e) {142 } catch (settings_exception e) { 140 143 get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Failed to write section: ") + e.getError())); 141 144 } catch (...) { … … 211 214 throw_SI_error(rc, _T("Failed to save file")); 212 215 } 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; 215 218 } 216 219 private: … … 225 228 if (rc < 0) 226 229 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 } 227 236 is_loaded_ = true; 228 237 } … … 235 244 if (err == SI_FILE) 236 245 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); 238 247 } 239 248 boost::filesystem::wpath get_file_name() { 240 249 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"))); 242 252 get_core()->get_logger()->debug(__FILEW__, __LINE__, _T("Reading INI settings from: ") + filename_.string()); 243 253 } … … 247 257 return boost::filesystem::is_regular(get_file_name()); 248 258 } 259 virtual std::wstring get_info() { 260 return _T("INI settings: (") + context_ + _T(", ") + get_file_name().string() + _T(")"); 261 } 262 249 263 }; 250 264 } -
include/settings/settings_old.hpp
r3080680 r497b779 3 3 #include <string> 4 4 #include <map> 5 #include <settings/ Settings.h>5 #include <settings/settings_core.hpp> 6 6 #include <simpleini/SimpleIni.h> 7 7 #include <settings/macros.h> … … 11 11 #define MAIN_STRING_LENGTH _T("string_length") 12 12 13 namespace Settings {14 class OLDSettings : public Settings::SettingsInterfaceImpl {13 namespace settings { 14 class OLDSettings : public settings::SettingsInterfaceImpl { 15 15 std::wstring filename_; 16 16 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) { 18 18 add_mapping(MAIN_MODULES_SECTION, MAIN_MODULES_SECTION_OLD); 19 19 add_mapping(setting_keys::settings_def::PAYLOAD_LEN_PATH, setting_keys::settings_def::PAYLOAD_LEN, MAIN_SECTION_TITLE, MAIN_STRING_LENGTH); … … 80 80 SETTINGS_MAP_KEY_A(nrpe::PAYLOAD_LENGTH,NRPE_SECTION_TITLE, NRPE_SETTINGS_STRLEN); 81 81 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);83 82 SETTINGS_MAP_KEY_A(nrpe::CMD_TIMEOUT, NRPE_SECTION_TITLE, NRPE_SETTINGS_TIMEOUT); 84 83 SETTINGS_MAP_KEY_A(nrpe::ALLOW_ARGS, NRPE_SECTION_TITLE, NRPE_SETTINGS_ALLOW_ARGUMENTS); 85 84 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 89 85 90 86 #define NSCA_AGENT_SECTION_TITLE _T("NSCA Agent") … … 126 122 } 127 123 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; 129 125 path_map sections_; 130 126 key_map keys_; … … 133 129 } 134 130 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); 137 133 keys_[new_key] = old_key; 138 134 } … … 144 140 return (*it).second; 145 141 } 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) { 147 143 key_map::iterator it1 = keys_.find(new_key); 148 144 if (it1 != keys_.end()) … … 150 146 path_map::iterator it2 = sections_.find(new_key.first); 151 147 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); 153 149 return new_key; 154 150 } … … 171 167 /// 172 168 /// @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) { 174 170 key = map_key(key); 175 171 get_core()->get_logger()->quick_debug(key.first + _T("//") + key.second); … … 182 178 TCHAR* buffer = new TCHAR[bufferSize+2]; 183 179 if (buffer == NULL) 184 throw SettingsException(_T("Out of memmory error!"));180 throw settings_exception(_T("Out of memmory error!")); 185 181 int retVal = GetPrivateProfileString(path.c_str(), key.c_str(), UNLIKELY_STRING, buffer, bufferSize, get_file_name().c_str()); 186 182 if (retVal == bufferSize-1) { … … 207 203 /// 208 204 /// @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) { 210 206 std::wstring str = get_real_string(key); 211 207 return strEx::stoi(str); … … 219 215 /// 220 216 /// @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) { 222 218 std::wstring str = get_real_string(key); 223 219 return SettingsInterfaceImpl::string_to_bool(str); … … 231 227 /// 232 228 /// @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) { 234 230 return has_key_int(key.first, key.second); 235 231 } … … 239 235 TCHAR* buffer = new TCHAR[bufferLength+1]; 240 236 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!")); 242 238 std::wstring mapped = map_path(path); 243 239 unsigned int count = ::GetPrivateProfileSection(mapped.c_str(), buffer, bufferLength-2, get_file_name().c_str()); … … 262 258 return false; 263 259 } 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 282 261 ////////////////////////////////////////////////////////////////////////// 283 262 /// Write a value to the resulting context. … … 287 266 /// 288 267 /// @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) { 290 269 try { 291 270 key = map_key(key); 292 271 get_core()->get_logger()->quick_debug(key.first + _T("//") + key.second + _T("//") + value.get_string()); 293 272 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) { 295 274 get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Failed to write key: ") + e.getError())); 296 275 } catch (...) { … … 375 354 TCHAR* buffer = new TCHAR[bufferLength+1]; 376 355 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!")); 378 357 unsigned int count = ::GetPrivateProfileSectionNames(buffer, BUFF_LEN, get_file_name().c_str()); 379 358 if (count == bufferLength-2) { … … 405 384 int_read_section(mapped_path, list); 406 385 /* 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) { 409 388 if (has_key((*cit).dst.first, (*cit).dst.second)) 410 389 list.push_back((*cit).src.second); … … 412 391 */ 413 392 } 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; 416 395 } 417 396 private: … … 428 407 TCHAR* buffer = new TCHAR[bufferLength+1]; 429 408 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!")); 431 410 unsigned int count = GetPrivateProfileSection(section.c_str(), buffer, bufferLength, get_file_name().c_str()); 432 411 if (count == bufferLength-2) { … … 452 431 inline std::wstring get_file_name() { 453 432 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(); 455 435 get_core()->get_logger()->debug(__FILEW__, __LINE__, _T("Reading old settings from: ") + filename_); 456 436 } … … 460 440 return boost::filesystem::is_regular_file(get_file_name()); 461 441 } 442 virtual std::wstring get_info() { 443 return _T("INI settings: (") + context_ + _T(", ") + get_file_name() + _T(")"); 444 } 462 445 }; 463 446 } -
include/settings/settings_registry.hpp
r3080680 r497b779 3 3 #include <string> 4 4 #include <windows.h> 5 #include <settings/ Settings.h>5 #include <settings/settings_core.hpp> 6 6 #include <msvc_wrappers.h> 7 7 #include <error.hpp> … … 10 10 11 11 12 namespace Settings {13 class REGSettings : public Settings::SettingsInterfaceImpl {12 namespace settings { 13 class REGSettings : public settings::SettingsInterfaceImpl { 14 14 private: 15 15 struct reg_key { … … 26 26 27 27 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) {} 29 29 30 30 virtual ~REGSettings(void) {} … … 48 48 /// 49 49 /// @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) { 51 51 return getString_(get_reg_key(key.first), key.second); 52 52 } … … 59 59 /// 60 60 /// @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) { 62 62 throw KeyNotFoundException(key); 63 63 } … … 70 70 /// 71 71 /// @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) { 73 73 throw KeyNotFoundException(key); 74 74 } … … 81 81 /// 82 82 /// @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) { 84 84 return false; 85 }86 //////////////////////////////////////////////////////////////////////////87 /// Get the type this settings store represent.88 ///89 /// @return the type of settings store90 ///91 /// @author mickem92 virtual SettingsCore::settings_type get_type() {93 return SettingsCore::registry;94 }95 //////////////////////////////////////////////////////////////////////////96 /// Is this the active settings store97 ///98 /// @return99 ///100 /// @author mickem101 virtual bool is_active() {102 return true;103 85 } 104 86 ////////////////////////////////////////////////////////////////////////// … … 109 91 /// 110 92 /// @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) { 113 95 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) { 116 98 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) { 119 101 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); 121 103 } else { 122 throw SettingsException(_T("Invalid settings type."));104 throw settings_exception(_T("Invalid settings type.")); 123 105 } 124 106 } … … 151 133 getValues_(get_reg_key(path), list); 152 134 } 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; 155 137 } 156 138 private: 157 reg_key get_reg_key( SettingsCore::key_path_type key) {139 reg_key get_reg_key(settings_core::key_path_type key) { 158 140 return get_reg_key(key.first); 159 141 } … … 217 199 return ret; 218 200 } 219 throw SettingsException(_T("String to long: ") + path.to_string());201 throw settings_exception(_T("String to long: ") + path.to_string()); 220 202 } else if (type == REG_DWORD) { 221 203 DWORD dw = *(reinterpret_cast<DWORD*>(bData)); 222 204 return strEx::itos(dw); 223 205 } 224 throw SettingsException(_T("Unsupported key type: ") + path.to_string());206 throw settings_exception(_T("Unsupported key type: ") + path.to_string()); 225 207 } else if (lRet == ERROR_FILE_NOT_FOUND) 226 208 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)); 228 210 } 229 211 static DWORD getInt_(HKEY hKey, LPCTSTR lpszPath, LPCTSTR lpszKey, DWORD def) { … … 266 248 if (bRet != ERROR_SUCCESS) { 267 249 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()); 269 251 } 270 252 list.push_back(std::wstring(lpValueName)); … … 290 272 if (bRet != ERROR_SUCCESS) { 291 273 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()); 293 275 } 294 276 list.push_back(std::wstring(lpValueName)); … … 297 279 } 298 280 } 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 } 304 284 }; 305 285 } -
include/simple_timer.hpp
r86632db r497b779 14 14 ~simple_timer() { 15 15 if (log) 16 std:: cout << text << stop() << std::endl;;16 std::wcout << text << stop() << std::endl;; 17 17 } 18 18 -
include/strEx.h
r8988f9e r497b779 33 33 #include <iostream> 34 34 35 #include <cctype> 36 35 37 #include <unicode_char.hpp> 36 38 … … 77 79 return result; 78 80 } 81 } 82 83 namespace 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 79 113 } 80 114 namespace strEx { … … 630 664 631 665 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 632 696 template<class _E> 633 697 struct blind_traits : public std::char_traits<_E>
Note: See TracChangeset
for help on using the changeset viewer.








