- Timestamp:
- 02/18/10 12:22:51 (3 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- b0e7ecf
- Parents:
- 60375ed
- Location:
- service
- Files:
-
- 9 edited
-
CMakeLists.txt (modified) (2 diffs)
-
NSCPlugin.cpp (modified) (9 diffs)
-
NSCPlugin.h (modified) (4 diffs)
-
NSClient++.cpp (modified) (11 diffs)
-
NSClient++.h (modified) (1 diff)
-
commands.hpp (modified) (5 diffs)
-
core_api.cpp (modified) (6 diffs)
-
core_api.h (modified) (1 diff)
-
simple_client.hpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
service/CMakeLists.txt
r40970de rcad08fb 19 19 settings_manager_impl.cpp 20 20 21 ${NSCP_ DEF_PLUGIN_CPP}21 ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.cpp 22 22 23 23 ${NSCP_INCLUDE_PATH}/simpleini/ConvertUTF.c 24 24 ${NSCP_INCLUDE_PATH}/b64/b64.c 25 ${NSCP_INCLUDE_PATH}/arrayBuffer.cpp 25 26 26 27 ) … … 62 63 ${NSCP_INCLUDE_PATH}/service/system_service.hpp 63 64 ${NSCP_INCLUDE_PATH}/service/win32_service.hpp 64 65 ${NSCP_DEF_PLUGIN_HPP} 65 ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.hpp 66 66 67 67 ) -
service/NSCPlugin.cpp
r60375ed rcad08fb 23 23 #include "core_api.h" 24 24 25 unsigned int NSCPlugin::last_plugin_id_ = 0;26 27 28 25 /** 29 26 * Default c-tor … … 33 30 * @param file The file (DLL) to load as a NSC plug in. 34 31 */ 35 NSCPlugin::NSCPlugin(const boost::filesystem::wpath file)32 NSCPlugin::NSCPlugin(const unsigned int id, const boost::filesystem::wpath file) 36 33 : module_(file.string()) 37 34 ,fLoadModule(NULL) … … 43 40 ,fDeleteBuffer(NULL) 44 41 ,fGetDescription(NULL) 45 ,fGetConfigurationMeta(NULL)46 42 ,fGetVersion(NULL) 47 43 ,fCommandLineExec(NULL) … … 53 49 ,lastIsMsgPlugin_(false) 54 50 ,broken_(false) 55 ,plugin_id_( 0)51 ,plugin_id_(id) 56 52 { 57 plugin_id_ = ++last_plugin_id_; 53 58 54 } 59 55 /* … … 67 63 ,fHandleMessage(NULL) 68 64 ,fGetDescription(NULL) 69 ,fGetConfigurationMeta(NULL)70 65 ,fGetVersion(NULL) 71 66 ,fCommandLineExec(NULL) … … 361 356 362 357 try { 363 fLoadModule = ( lpLoadModule)module_.load_proc("NSLoadModule");358 fLoadModule = (nscapi::plugin_api::lpLoadModule)module_.load_proc("NSLoadModule"); 364 359 if (!fLoadModule) 365 360 throw NSPluginException(module_, _T("Could not load NSLoadModule")); 366 361 367 fModuleHelperInit = ( lpModuleHelperInit)module_.load_proc("NSModuleHelperInit");362 fModuleHelperInit = (nscapi::plugin_api::lpModuleHelperInit)module_.load_proc("NSModuleHelperInit"); 368 363 if (!fModuleHelperInit) 369 364 throw NSPluginException(module_, _T("Could not load NSModuleHelperInit")); … … 375 370 } 376 371 377 fGetName = ( lpGetName)module_.load_proc("NSGetModuleName");372 fGetName = (nscapi::plugin_api::lpGetName)module_.load_proc("NSGetModuleName"); 378 373 if (!fGetName) 379 374 throw NSPluginException(module_, _T("Could not load NSGetModuleName")); 380 375 381 fGetVersion = ( lpGetVersion)module_.load_proc("NSGetModuleVersion");376 fGetVersion = (nscapi::plugin_api::lpGetVersion)module_.load_proc("NSGetModuleVersion"); 382 377 if (!fGetVersion) 383 378 throw NSPluginException(module_, _T("Could not load NSGetModuleVersion")); 384 379 385 fGetDescription = ( lpGetDescription)module_.load_proc("NSGetModuleDescription");380 fGetDescription = (nscapi::plugin_api::lpGetDescription)module_.load_proc("NSGetModuleDescription"); 386 381 if (!fGetDescription) 387 382 throw NSPluginException(module_, _T("Could not load NSGetModuleDescription")); 388 383 389 fHasCommandHandler = ( lpHasCommandHandler)module_.load_proc("NSHasCommandHandler");384 fHasCommandHandler = (nscapi::plugin_api::lpHasCommandHandler)module_.load_proc("NSHasCommandHandler"); 390 385 if (!fHasCommandHandler) 391 386 throw NSPluginException(module_, _T("Could not load NSHasCommandHandler")); 392 387 393 fHasMessageHandler = ( lpHasMessageHandler)module_.load_proc("NSHasMessageHandler");388 fHasMessageHandler = (nscapi::plugin_api::lpHasMessageHandler)module_.load_proc("NSHasMessageHandler"); 394 389 if (!fHasMessageHandler) 395 390 throw NSPluginException(module_, _T("Could not load NSHasMessageHandler")); 396 391 397 fHandleCommand = ( lpHandleCommand)module_.load_proc("NSHandleCommand");392 fHandleCommand = (nscapi::plugin_api::lpHandleCommand)module_.load_proc("NSHandleCommand"); 398 393 //if (!fHandleCommand) 399 394 // throw NSPluginException(module_, _T("Could not load NSHandleCommand")); 400 395 401 fDeleteBuffer = ( lpDeleteBuffer)module_.load_proc("NSDeleteBuffer");396 fDeleteBuffer = (nscapi::plugin_api::lpDeleteBuffer)module_.load_proc("NSDeleteBuffer"); 402 397 if (!fDeleteBuffer) 403 398 throw NSPluginException(module_, _T("Could not load NSDeleteBuffer")); 404 399 405 fHandleMessage = ( lpHandleMessage)module_.load_proc("NSHandleMessage");400 fHandleMessage = (nscapi::plugin_api::lpHandleMessage)module_.load_proc("NSHandleMessage"); 406 401 if (!fHandleMessage) 407 402 throw NSPluginException(module_, _T("Could not load NSHandleMessage")); 408 403 409 fUnLoadModule = ( lpUnLoadModule)module_.load_proc("NSUnloadModule");404 fUnLoadModule = (nscapi::plugin_api::lpUnLoadModule)module_.load_proc("NSUnloadModule"); 410 405 if (!fUnLoadModule) 411 406 throw NSPluginException(module_, _T("Could not load NSUnloadModule")); 412 407 413 fGetConfigurationMeta = (lpGetConfigurationMeta)module_.load_proc("NSGetConfigurationMeta"); 414 fCommandLineExec = (lpCommandLineExec)module_.load_proc("NSCommandLineExec"); 415 fHandleNotification = (lpHandleNotification)module_.load_proc("NSHandleNotification"); 416 fHasNotificationHandler = (lpHasNotificationHandler)module_.load_proc("NSHasNotificationHandler"); 408 fCommandLineExec = (nscapi::plugin_api::lpCommandLineExec)module_.load_proc("NSCommandLineExec"); 409 fHandleNotification = (nscapi::plugin_api::lpHandleNotification)module_.load_proc("NSHandleNotification"); 410 fHasNotificationHandler = (nscapi::plugin_api::lpHasNotificationHandler)module_.load_proc("NSHasNotificationHandler"); 417 411 418 fShowTray = ( lpShowTray)module_.load_proc("ShowIcon");419 fHideTray = ( lpHideTray)module_.load_proc("HideIcon");412 fShowTray = (nscapi::plugin_api::lpShowTray)module_.load_proc("ShowIcon"); 413 fHideTray = (nscapi::plugin_api::lpHideTray)module_.load_proc("HideIcon"); 420 414 421 415 } catch (NSPluginException &e) { … … 430 424 431 425 432 std::wstring NSCPlugin::getCongifurationMeta()433 {434 wchar_t *buffer = new wchar_t[4097];435 if (!getConfigurationMeta_(buffer, 4096)) {436 throw NSPluginException(module_, _T("Could not get metadata"));437 }438 std::wstring ret = buffer;439 delete [] buffer;440 return ret;441 }442 bool NSCPlugin::getConfigurationMeta_(wchar_t* buf, unsigned int buflen) {443 if (fGetConfigurationMeta == NULL)444 throw NSPluginException(module_, _T("Critical error (getCongifurationMeta)"));445 try {446 return fGetConfigurationMeta(buflen, buf)?true:false;447 } catch (...) {448 throw NSPluginException(module_, _T("Unhandled exception in getConfigurationMeta."));449 }450 }451 452 426 int NSCPlugin::commandLineExec(const unsigned int argLen, wchar_t **arguments) { 453 427 if (fCommandLineExec== NULL) … … 459 433 } 460 434 } 435 -
service/NSCPlugin.h
r40970de rcad08fb 25 25 #include <sstream> 26 26 #include <dll/dll.hpp> 27 #include <boost/noncopyable.hpp> 27 28 28 29 /** … … 103 104 * 104 105 */ 105 class NSCPlugin {106 class NSCPlugin : boost::noncopyable { 106 107 private: 107 108 bool bLoaded_; // Status of plug in 108 109 dll::dll module_; 109 110 bool broken_; 110 static unsigned int last_plugin_id_;111 111 unsigned int plugin_id_; 112 112 113 typedef int (*lpModuleHelperInit)(unsigned int, NSCModuleHelper::lpNSAPILoader f); 114 typedef int (*lpLoadModule)(int); 115 typedef int (*lpGetName)(wchar_t*,unsigned int); 116 typedef int (*lpGetDescription)(wchar_t*,unsigned int); 117 typedef int (*lpGetVersion)(int*,int*,int*); 118 typedef int (*lpHasCommandHandler)(); 119 typedef int (*lpHasMessageHandler)(); 120 typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const wchar_t*,const char*,const unsigned int,char**,unsigned int*); 121 typedef int (*lpDeleteBuffer)(char**); 122 typedef int (*lpCommandLineExec)(const unsigned int,wchar_t**); 123 typedef int (*lpHandleMessage)(int,const wchar_t*,const int,const wchar_t*); 124 typedef int (*lpUnLoadModule)(); 125 typedef int (*lpGetConfigurationMeta)(int, wchar_t*); 126 typedef void (*lpShowTray)(); 127 typedef void (*lpHideTray)(); 128 typedef int (*lpHasNotificationHandler)(); 129 typedef int (*lpHandleNotification)(const wchar_t *channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len); 130 131 132 lpModuleHelperInit fModuleHelperInit; 133 lpLoadModule fLoadModule; 134 lpGetName fGetName; 135 lpGetVersion fGetVersion; 136 lpGetDescription fGetDescription; 137 lpHasCommandHandler fHasCommandHandler; 138 lpHasMessageHandler fHasMessageHandler; 139 lpHandleCommand fHandleCommand; 140 lpDeleteBuffer fDeleteBuffer; 141 lpHandleMessage fHandleMessage; 142 lpUnLoadModule fUnLoadModule; 143 lpGetConfigurationMeta fGetConfigurationMeta; 144 lpCommandLineExec fCommandLineExec; 145 lpShowTray fShowTray; 146 lpHideTray fHideTray; 147 lpHasNotificationHandler fHasNotificationHandler; 148 lpHandleNotification fHandleNotification; 113 nscapi::plugin_api::lpModuleHelperInit fModuleHelperInit; 114 nscapi::plugin_api::lpLoadModule fLoadModule; 115 nscapi::plugin_api::lpGetName fGetName; 116 nscapi::plugin_api::lpGetVersion fGetVersion; 117 nscapi::plugin_api::lpGetDescription fGetDescription; 118 nscapi::plugin_api::lpHasCommandHandler fHasCommandHandler; 119 nscapi::plugin_api::lpHasMessageHandler fHasMessageHandler; 120 nscapi::plugin_api::lpHandleCommand fHandleCommand; 121 nscapi::plugin_api::lpDeleteBuffer fDeleteBuffer; 122 nscapi::plugin_api::lpHandleMessage fHandleMessage; 123 nscapi::plugin_api::lpUnLoadModule fUnLoadModule; 124 nscapi::plugin_api::lpCommandLineExec fCommandLineExec; 125 nscapi::plugin_api::lpShowTray fShowTray; 126 nscapi::plugin_api::lpHideTray fHideTray; 127 nscapi::plugin_api::lpHasNotificationHandler fHasNotificationHandler; 128 nscapi::plugin_api::lpHandleNotification fHandleNotification; 149 129 150 130 public: 151 NSCPlugin(const boost::filesystem::wpath file);152 NSCPlugin(NSCPlugin &other);131 NSCPlugin(const unsigned int id, const boost::filesystem::wpath file); 132 //NSCPlugin(NSCPlugin &other); 153 133 virtual ~NSCPlugin(void); 154 134 … … 192 172 return file; 193 173 } 174 static std::wstring get_plugin_file(std::wstring key) { 175 #ifdef WIN32 176 return key + _T(".dll"); 177 #else 178 return _T("lib") + key + _T(".so"); 179 #endif 180 } 194 181 bool getLastIsMsgPlugin() { 195 182 return lastIsMsgPlugin_; … … 205 192 bool getDescription_(wchar_t* buf, unsigned int buflen); 206 193 void loadRemoteProcs_(void); 207 bool getConfigurationMeta_(wchar_t* buf, unsigned int buflen);208 194 }; 209 195 -
service/NSClient++.cpp
r60375ed rcad08fb 35 35 #include "settings_manager_impl.h" 36 36 #include <settings/macros.h> 37 #include <NSCHelper.h>38 37 #include "simple_client.hpp" 39 38 #include "settings_client.hpp" 40 39 #include "service_manager.hpp" 40 #include <nscapi/nscapi_helper.hpp> 41 41 42 42 #include "../libs/protobuf/plugin.proto.h" … … 304 304 } else if ( wcscasecmp( _T("about"), argv[1]+1 ) == 0 ) { 305 305 try { 306 unsigned int next_plugin_id = 0; 306 307 g_bConsoleLog = true; 307 308 LOG_MESSAGE(SZAPPNAME _T(" (C) Michael Medin - michael<at>medin<dot>name")); … … 318 319 LOG_MESSAGE_STD(_T("Found: ") + file); 319 320 if (is_module(pluginPath / file)) { 320 NSCPlugin *plugin = new NSCPlugin( pluginPath / file);321 NSCPlugin *plugin = new NSCPlugin(next_plugin_id++, pluginPath / file); 321 322 std::wstring name = _T("<unknown>"); 322 323 std::wstring description = _T("<unknown>"); … … 459 460 try { 460 461 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 461 NSCPlugin plugin( pluginPath / file);462 NSCPlugin plugin(next_plugin_id_++, pluginPath / file); 462 463 plugin.load_dll(); 463 464 plugin.load_plugin(NSCAPI::dontStart); … … 490 491 try { 491 492 LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 492 NSCPlugin plugin( modPath / file);493 NSCPlugin plugin(next_plugin_id_++, modPath / file); 493 494 plugin.load_dll(); 494 495 plugin.load_plugin(mode); … … 504 505 std::wstring name = file.string(); 505 506 try { 506 NSCPlugin plugin( modPath / file);507 NSCPlugin plugin(next_plugin_id_++, modPath / file); 507 508 name = plugin.getModule(); 508 509 plugin.load_dll(); … … 626 627 Settings::string_list list = settings_manager::get_settings()->get_keys(MAIN_MODULES_SECTION); 627 628 for (Settings::string_list::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 628 LOG_DEBUG_STD(_T("Processing plugin: " + *cit)); 629 std::wstring file = NSCPlugin::get_plugin_file(*cit); 630 LOG_DEBUG_STD(_T("Processing plugin: " + *cit) + _T(" in ") + file); 629 631 try { 630 632 if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, *cit) == _T("disabled")) { 631 LOG_DEBUG_STD(_T("Not booting: ") + *cit+ _T(" since it is disabled."));633 LOG_DEBUG_STD(_T("Not booting: ") + file + _T(" since it is disabled.")); 632 634 continue; 633 635 } … … 636 638 } 637 639 try { 638 loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath( *cit));640 loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(file)); 639 641 } catch(const NSPluginException& e) { 640 642 LOG_ERROR_CORE_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); 641 643 //return false; 642 644 } catch (std::exception e) { 643 LOG_ERROR_CORE_STD(_T("exception loading plugin: ") + (*cit)+ strEx::string_to_wstring(e.what()));645 LOG_ERROR_CORE_STD(_T("exception loading plugin: ") + file + strEx::string_to_wstring(e.what())); 644 646 return false; 645 647 } catch (...) { 646 LOG_ERROR_CORE_STD(_T("Unknown exception loading plugin: ") + (*cit));648 LOG_ERROR_CORE_STD(_T("Unknown exception loading plugin: ") + file); 647 649 return false; 648 650 } … … 971 973 */ 972 974 NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file) { 973 plugin_type plugin(new NSCPlugin( file));975 plugin_type plugin(new NSCPlugin(next_plugin_id_++, file)); 974 976 return addPlugin(plugin); 975 977 } … … 1122 1124 } 1123 1125 NSCAPI::nagiosReturn c = plugin->handleCommand(command, request, response); 1124 LOG_DEBUG_STD(_T("Result ") + std::wstring(command) + _T(": ") + NSCHelper::translateReturn(c) + _T(" {{{") + strEx::strip_hex(to_wstring(response)) + _T("}}}"));1126 LOG_DEBUG_STD(_T("Result ") + std::wstring(command) + _T(": ") + nscapi::plugin_helper::translateReturn(c) + _T(" {{{") + strEx::strip_hex(to_wstring(response)) + _T("}}}")); 1125 1127 return c; 1126 1128 } catch (nsclient::commands::command_exception &e) { … … 1201 1203 OutputDebugString(msg.c_str()); 1202 1204 #else 1203 std::wcout << _T("--BROKEN MESSAGE: ") << msg << _T("--") << std::endl;1205 // std::wcout << _T("--BROKEN MESSAGE: ") << msg << _T("--") << std::endl; 1204 1206 #endif 1205 1207 } -
service/NSClient++.h
r40970de rcad08fb 123 123 nsclient::commands commands_; 124 124 nsclient::channels channels_; 125 unsigned int next_plugin_id_; 125 126 126 127 127 128 public: 128 129 // c-tor, d-tor 129 NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false), commands_(this), channels_(this) {}130 NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false), commands_(this), channels_(this), next_plugin_id_(0) {} 130 131 virtual ~NSClientT(void) {} 131 132 void enableDebug(bool debug = true) { -
service/commands.hpp
rc0d7e82 rcad08fb 5 5 #include "NSCPlugin.h" 6 6 #include "logger.hpp" 7 #include <strEx.h> 7 8 8 9 namespace nsclient { … … 40 41 41 42 void add_plugin(plugin_type plugin) { 42 if (!plugin || !plugin->hasCommandHandler()) 43 if (!plugin || !plugin->hasCommandHandler()) { 43 44 return; 45 } 44 46 plugins_[plugin->get_id()] = plugin; 45 47 … … 88 90 std::wstring lc = make_key(cmd); 89 91 if (!have_plugin(plugin_id)) 90 throw command_exception("Failed to find plugin: " + ::to_string(plugin_id) );92 throw command_exception("Failed to find plugin: " + ::to_string(plugin_id) + ": " + unsafe_get_all_plugin_ids()); 91 93 descriptions_[lc] = desc; 92 94 commands_[lc] = plugins_[plugin_id]; 93 95 } 96 private: 94 97 98 std::string unsafe_get_all_plugin_ids() { 99 std::string ret; 100 std::pair<unsigned long,plugin_type> cit; 101 BOOST_FOREACH(cit, plugins_) { 102 ret += ::to_string(cit.first) + ", "; 103 //lst.push_back(::to_wstring(cit.first) + _T("=") + cit.second->getName()); 104 //lst.push_back(::to_wstring(cit.first)); 105 } 106 return ret; 107 } 108 109 110 public: 95 111 std::wstring describe(std::wstring command) { 96 112 boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); … … 120 136 } 121 137 138 std::list<std::wstring> list_plugins() { 139 std::list<std::wstring> lst; 140 boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 141 if (!readLock.owns_lock()) { 142 log_error(__FILEW__, __LINE__, _T("Failed to get mutex")); 143 return lst; 144 } 145 std::pair<unsigned long,plugin_type> cit; 146 BOOST_FOREACH(cit, plugins_) { 147 //lst.push_back(::to_wstring(cit.first) + _T("=") + cit.second->getName()); 148 lst.push_back(::to_wstring(cit.first)); 149 } 150 return lst; 151 } 152 122 153 plugin_type get(std::wstring command) { 123 154 boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); … … 136 167 137 168 std::wstring to_wstring() { 138 std::wstring ret ;169 std::wstring ret = _T("commands {"); 139 170 BOOST_FOREACH(std::wstring str, list()) { 140 171 if (!ret.empty()) ret += _T(", "); 141 172 ret += str; 142 173 } 174 ret += _T("}, plugins {"); 175 BOOST_FOREACH(std::wstring str, list_plugins()) { 176 if (!ret.empty()) ret += _T(", "); 177 ret += str; 178 } 179 ret += _T("}"); 143 180 return ret; 144 181 } -
service/core_api.cpp
r40970de rcad08fb 19 19 #include <config.h> 20 20 #include <msvc_wrappers.h> 21 #include <arrayBuffer.h> 21 22 //#include <settings/settings_ini.hpp> 22 23 //#include <settings/settings_registry.hpp> … … 28 29 #include "settings_manager_impl.h" 29 30 #include <b64/b64.h> 30 #include < NSCHelper.h>31 #include <nscapi/nscapi_helper.hpp> 31 32 #ifdef _WIN32 32 33 #include <ServiceCmd.h> … … 34 35 35 36 #define LOG_ERROR_STD(msg) LOG_ERROR(((std::wstring)msg).c_str()) 36 #define LOG_ERROR(msg) \ 37 NSAPIMessage(NSCAPI::error, __FILEW__, __LINE__, msg) 38 37 #define LOG_ERROR(msg) LOG_ANY(msg, NSCAPI::error) 39 38 #define LOG_CRITICAL_STD(msg) LOG_CRITICAL(((std::wstring)msg).c_str()) 40 #define LOG_CRITICAL(msg) \ 41 NSAPIMessage(NSCAPI::critical, __FILEW__, __LINE__, msg) 39 #define LOG_CRITICAL(msg) LOG_ANY(msg, NSCAPI::critical) 42 40 #define LOG_MESSAGE_STD(msg) LOG_MESSAGE(((std::wstring)msg).c_str()) 43 #define LOG_MESSAGE(msg) \ 44 NSAPIMessage(NSCAPI::log, __FILEW__, __LINE__, msg) 45 41 #define LOG_MESSAGE(msg) LOG_ANY(msg, NSCAPI::log) 46 42 #define LOG_DEBUG_STD(msg) LOG_DEBUG(((std::wstring)msg).c_str()) 47 #define LOG_DEBUG(msg) \48 NSAPIMessage(NSCAPI::debug, __FILEW__, __LINE__, msg) 49 43 #define LOG_DEBUG(msg) LOG_ANY(msg, NSCAPI::debug) 44 45 #define LOG_ANY(msg, type) NSAPIMessage(type, __FILEW__, __LINE__, msg) 50 46 51 47 NSCAPI::errorReturn NSAPIGetSettingsString(const wchar_t* section, const wchar_t* key, const wchar_t* defaultValue, wchar_t* buffer, unsigned int bufLen) { 52 48 try { 53 return NSCHelper::wrapReturnString(buffer, bufLen, settings_manager::get_settings()->get_string(section, key, defaultValue), NSCAPI::isSuccess);49 return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, settings_manager::get_settings()->get_string(section, key, defaultValue), NSCAPI::isSuccess); 54 50 } catch (...) { 55 51 LOG_ERROR_STD(_T("Failed to getString: ") + key); … … 66 62 } 67 63 NSCAPI::errorReturn NSAPIGetBasePath(wchar_t*buffer, unsigned int bufLen) { 68 return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.getBasePath().string(), NSCAPI::isSuccess);64 return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, mainClient.getBasePath().string(), NSCAPI::isSuccess); 69 65 } 70 66 NSCAPI::errorReturn NSAPIGetApplicationName(wchar_t*buffer, unsigned int bufLen) { 71 return NSCHelper::wrapReturnString(buffer, bufLen, SZAPPNAME, NSCAPI::isSuccess);67 return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, SZAPPNAME, NSCAPI::isSuccess); 72 68 } 73 69 NSCAPI::errorReturn NSAPIGetApplicationVersionStr(wchar_t*buffer, unsigned int bufLen) { 74 return NSCHelper::wrapReturnString(buffer, bufLen, SZVERSION, NSCAPI::isSuccess);70 return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, SZVERSION, NSCAPI::isSuccess); 75 71 } 76 72 void NSAPIMessage(int msgType, const wchar_t* file, const int line, const wchar_t* message) { … … 262 258 } 263 259 NSCAPI::errorReturn NSAPIDescribeCommand(const wchar_t* command, wchar_t* buffer, unsigned int bufLen) { 264 return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.describeCommand(command), NSCAPI::isSuccess);260 return nscapi::plugin_helper::wrapReturnString(buffer, bufLen, mainClient.describeCommand(command), NSCAPI::isSuccess); 265 261 } 266 262 NSCAPI::errorReturn NSAPIGetAllCommandNames(arrayBuffer::arrayBuffer* aBuffer, unsigned int *bufLen) { … … 369 365 370 366 371 LPVOID NSAPILoader( wchar_t*buffer) {367 LPVOID NSAPILoader(const wchar_t*buffer) { 372 368 if (wcscasecmp(buffer, _T("NSAPIGetApplicationName")) == 0) 373 369 return reinterpret_cast<LPVOID>(&NSAPIGetApplicationName); -
service/core_api.h
r40970de rcad08fb 30 30 // 31 31 32 LPVOID NSAPILoader( wchar_t*buffer);32 LPVOID NSAPILoader(const wchar_t*buffer); 33 33 NSCAPI::errorReturn NSAPIGetApplicationName(wchar_t*buffer, unsigned int bufLen); 34 34 NSCAPI::errorReturn NSAPIGetBasePath(wchar_t*buffer, unsigned int bufLen); -
service/simple_client.hpp
rc0d7e82 rcad08fb 1 1 #pragma once 2 #include <nscapi/nscapi_helper.hpp> 2 3 3 4 class NSClientT; … … 25 26 */ 26 27 std::wstring s = _T(""); 27 std::wstring buff = _T(""); 28 28 29 while (true) { 29 std::wcin >> s; 30 std::wstring s; 31 std::getline(std::wcin, s); 30 32 if (s == _T("exit")) { 31 33 std::wcout << _T("Exiting...") << std::endl; … … 40 42 std::wcout << *cit << _T(": ") << core_->describeCommand(*cit) << std::endl; 41 43 std::wcout << _T("Listing commands...Done") << std::endl; 42 } else if (s == _T(" off") && buff == _T("debug")) {44 } else if (s == _T("debug off")) { 43 45 std::wcout << _T("Setting debug log off...") << std::endl; 44 46 core_->enableDebug(false); 45 } else if (s == _T(" on") && buff == _T("debug")) {47 } else if (s == _T("debug on")) { 46 48 std::wcout << _T("Setting debug log on...") << std::endl; 47 49 core_->enableDebug(true); … … 51 53 } else if (s == _T("assert")) { 52 54 throw "test"; 53 } else if (std::cin.peek() < 15) { 54 buff += s; 55 strEx::token t = strEx::getToken(buff, ' '); 55 } else { 56 strEx::token t = strEx::getToken(s, ' '); 56 57 std::wstring msg, perf; 57 58 NSCAPI::nagiosReturn ret = core_->inject(t.first, t.second, msg, perf); … … 59 60 std::wcout << _T("No handler for command: ") << t.first << std::endl; 60 61 } else { 61 std::wcout << NSCHelper::translateReturn(ret) << _T(":");62 std:: cout << strEx::wstring_to_string(msg);62 std::wcout << nscapi::plugin_helper::translateReturn(ret) << _T(":"); 63 std::wcout << msg; 63 64 if (!perf.empty()) 64 65 std::cout << "|" << strEx::wstring_to_string(perf); 65 66 std::wcout << std::endl; 66 67 } 67 buff = _T("");68 } else {69 buff += s + _T(" ");70 68 } 71 69 }
Note: See TracChangeset
for help on using the changeset viewer.








