Changeset 257


Ignore:
Timestamp:
02/18/10 12:22:51 (2 years ago)
Author:
mickem
Message:

Major update with a new plugin glue that works better with *nix.
Everything should be the same but look tidier

Location:
trunk
Files:
43 edited

Legend:

Unmodified
Added
Removed
  • trunk/CMakeLists.txt

    r256 r257  
    167167 
    168168SET(NSCP_DEF_PLUGIN_CPP 
    169   ${NSCP_INCLUDE_PATH}/NSCHelper.cpp 
    170169  ${NSCP_INCLUDE_PATH}/arrayBuffer.cpp 
    171170  ${NSCP_INCLUDE_PATH}/simpleini/ConvertUTF.c 
    172171  ${NSCP_INCLUDE_PATH}/b64/b64.c 
    173172  ${NSCP_INCLUDE_PATH}/utils.cpp 
     173  ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.cpp 
     174  ${NSCP_INCLUDE_PATH}/nscapi/nscapi_plugin_wrapper.cpp 
     175  ${NSCP_INCLUDE_PATH}/nscapi/nscapi_core_wrapper.cpp 
    174176) 
    175177 
    176178SET(NSCP_DEF_PLUGIN_HPP 
    177   ${NSCP_INCLUDE_PATH}/NSCHelper.h 
    178179  ${NSCP_INCLUDE_PATH}/strEx.h 
    179180  ${NSCP_INCLUDE_PATH}/config.h 
    180181  ${NSCP_INCLUDE_PATH}/utils.h 
    181182  ${NSCP_INCLUDE_PATH}/NSCAPI.h 
    182   ${NSCP_INCLUDE_PATH}/NSCHelper.h 
    183   ${NSCP_INCLUDE_PATH}/nsc_module_wrapper.hpp 
     183  ${NSCP_INCLUDE_PATH}/nscapi/macros.hpp 
     184  ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.hpp 
     185  ${NSCP_INCLUDE_PATH}/nscapi/nscapi_plugin_wrapper.hpp  
     186  ${NSCP_INCLUDE_PATH}/nscapi/nscapi_core_wrapper.hpp 
    184187) 
    185188 
     
    244247endif() 
    245248 
    246 IF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") 
    247 SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC"  ) 
    248 SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -fPIC"  ) 
    249 ENDIF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") 
    250  
    251  
     249IF(CMAKE_COMPILER_IS_GNUCXX) 
     250  IF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE) 
     251    SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC"  ) 
     252    SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -fPIC"  ) 
     253  ENDIF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE) 
     254ENDIF(CMAKE_COMPILER_IS_GNUCXX) 
     255 
     256 
  • trunk/build.cmake

    r256 r257  
     1IF(WIN32) 
     2 
    13SET(Boost_DEBUG 1) 
    24 
    3 #set(Boost_USE_STATIC_LIBS   ON) 
     5set(Boost_USE_STATIC_LIBS   ON) 
    46set(BOOST_USE_MULTITHREADED ON) 
    57 
    6 SET(BOOST_INCLUDEDIR c:/src/include/boost-1_39) 
    7 SET(BOOST_LIBRARYDIR c:/src/lib/x86/) 
    8 SET(BOOST_LIB_SUFFIX vc80-mt) 
    9 #SET(BOOST_LIB_VERSION 1.40) 
     8SET(BOOST_INCLUDEDIR D:/source/include/) 
     9SET(BOOST_LIBRARYDIR D:/source/lib/x86) 
     10#SET(BOOST_LIB_SUFFIX vc80-mt) 
     11#SET(Boost_VERSION 1.40) 
    1012 
    1113 
    12 SET(OPENSSL_INCLUDE_DIR c:/src/include/) 
    13 SET(CMAKE_LIBRARY_PATH c:/src/lib/x86/) 
     14SET(OPENSSL_INCLUDE_DIR D:/source/include/) 
     15SET(CMAKE_LIBRARY_PATH D:/source/lib/x86/) 
    1416 
    15 #SET(PROTOBUF_INCLUDE_DIR C:/src/protobuf-2.3.0/src) 
    16 #SET(PROTOBUF_LIBRARYDIR C:/src/protobuf-2.3.0/vsprojects/Debug) 
    17 #SET(PROTOBUF_BINARYDIR C:/src/protobuf-2.3.0/vsprojects/Debug) 
     17SET(PROTOBUF_INCLUDE_DIR D:/source/protobuf-2.3.0/src) 
     18SET(PROTOBUF_LIBRARYDIR D:/source/protobuf-2.3.0/vsprojects/Debug) 
     19SET(PROTOBUF_BINARYDIR D:/source/protobuf-2.3.0/vsprojects/Debug) 
    1820 
    1921#SET(PROTOBUF_LIBRARYDIR C:/src/protobuf-2.3.0/vsprojects/Release) 
    2022#SET(PROTOBUF_BINARYDIR C:/src/protobuf-2.3.0/vsprojects/Release) 
    2123 
     24SET(CRYPTOPP_SOURCE d:/source/libs-c/crypto++-5.6.0) 
    2225 
    23 SET(CRYPTOPP_DIR C:/src/lib-src/Crypto++5.6.0) 
     26ELSE(WIN32) 
    2427 
     28ENDIF(WIN32) 
  • trunk/include/NSCAPI.h

    r245 r257  
    106106}; 
    107107 
    108 namespace NSCModuleHelper { 
    109   typedef void* (*lpNSAPILoader)(wchar_t*); 
     108namespace nscapi { 
     109 
     110 
     111  class nscapi_exception { 
     112  public: 
     113    std::wstring msg_; 
     114    nscapi_exception(std::wstring msg) : msg_(msg) {} 
     115  }; 
     116 
     117  namespace core_api { 
     118    typedef void* (*lpNSAPILoader)(const wchar_t*); 
     119 
     120    typedef NSCAPI::errorReturn (*lpNSAPIGetBasePath)(wchar_t*,unsigned int); 
     121    typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationName)(wchar_t*,unsigned int); 
     122    typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationVersionStr)(wchar_t*,unsigned int); 
     123    typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsString)(const wchar_t*,const wchar_t*,const wchar_t*,wchar_t*,unsigned int); 
     124    typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsInt)(const wchar_t*, const wchar_t*, int); 
     125    typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSection)(const wchar_t*, wchar_t***, unsigned int *); 
     126    typedef NSCAPI::errorReturn (*lpNSAPIReleaseSettingsSectionBuffer)(wchar_t***, unsigned int *); 
     127    typedef void (*lpNSAPIMessage)(int, const wchar_t*, const int, const wchar_t*); 
     128    typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); 
     129    typedef NSCAPI::errorReturn (*lpNSAPIExit)(void); 
     130    typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const wchar_t*, const char *, const unsigned int, char **, unsigned int *); 
     131    typedef void (*lpNSAPIDestroyBuffer)(char**); 
     132 
     133    typedef NSCAPI::errorReturn (*lpNSAPINotify)(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int); 
     134 
     135    typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); 
     136    typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const wchar_t*, unsigned int, wchar_t*, unsigned int *); 
     137    typedef NSCAPI::errorReturn (*lpNSAPIDecrypt)(unsigned int, const wchar_t*, unsigned int, wchar_t*, unsigned int *); 
     138    typedef NSCAPI::errorReturn (*lpNSAPISetSettingsString)(const wchar_t*, const wchar_t*, const wchar_t*); 
     139    typedef NSCAPI::errorReturn (*lpNSAPISetSettingsInt)(const wchar_t*, const wchar_t*, int); 
     140    typedef NSCAPI::errorReturn (*lpNSAPIWriteSettings)(int); 
     141    typedef NSCAPI::errorReturn (*lpNSAPIReadSettings)(int); 
     142    typedef NSCAPI::errorReturn (*lpNSAPIRehash)(int); 
     143    typedef NSCAPI::errorReturn (*lpNSAPIDescribeCommand)(const wchar_t*,wchar_t*,unsigned int); 
     144    typedef NSCAPI::errorReturn (*lpNSAPIGetAllCommandNames)(wchar_t***, unsigned int *); 
     145    typedef NSCAPI::errorReturn (*lpNSAPIReleaseAllCommandNamessBuffer)(wchar_t***, unsigned int *); 
     146    typedef NSCAPI::errorReturn (*lpNSAPIRegisterCommand)(unsigned int, const wchar_t*,const wchar_t*); 
     147    typedef NSCAPI::errorReturn (*lpNSAPISettingsRegKey)(const wchar_t*, const wchar_t*, int, const wchar_t*, const wchar_t*, const wchar_t*, int); 
     148    typedef NSCAPI::errorReturn (*lpNSAPISettingsRegPath)(const wchar_t*, const wchar_t*, const wchar_t*, int); 
     149    typedef NSCAPI::errorReturn (*lpNSAPIGetPluginList)(int *len, NSCAPI::plugin_info *list[]); 
     150    typedef NSCAPI::errorReturn (*lpNSAPIReleasePluginList)(int len, NSCAPI::plugin_info *list[]); 
     151    typedef NSCAPI::errorReturn (*lpNSAPISettingsSave)(void); 
     152  } 
     153 
     154  namespace plugin_api { 
     155    typedef int (*lpModuleHelperInit)(unsigned int, ::nscapi::core_api::lpNSAPILoader f); 
     156    typedef int (*lpLoadModule)(int); 
     157    typedef int (*lpGetName)(wchar_t*,unsigned int); 
     158    typedef int (*lpGetDescription)(wchar_t*,unsigned int); 
     159    typedef int (*lpGetVersion)(int*,int*,int*); 
     160    typedef int (*lpHasCommandHandler)(); 
     161    typedef int (*lpHasMessageHandler)(); 
     162    typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const wchar_t*,const char*,const unsigned int,char**,unsigned int*); 
     163    typedef int (*lpDeleteBuffer)(char**); 
     164    typedef int (*lpCommandLineExec)(const unsigned int,wchar_t**); 
     165    typedef int (*lpHandleMessage)(int,const wchar_t*,const int,const wchar_t*); 
     166    typedef int (*lpUnLoadModule)(); 
     167    typedef void (*lpShowTray)(); 
     168    typedef void (*lpHideTray)(); 
     169    typedef int (*lpHasNotificationHandler)(); 
     170    typedef int (*lpHandleNotification)(const wchar_t *channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len); 
     171  } 
    110172} 
  • trunk/include/service/unix_service.hpp

    r219 r257  
    6363    virtual ~unix_service() { 
    6464    } 
    65     inline void print_debug(std::wstring s) { 
     65    inline void print_debug(const std::wstring s) { 
    6666      std::wcout << s << std::endl; 
    6767    } 
    68     inline void print_debug(wchar_t *s) { 
     68    inline void print_debug(const wchar_t *s) { 
    6969      std::wcout << s << std::endl; 
    7070    } 
  • trunk/include/settings/macros.h

    r245 r257  
    103103    DEFINE_SETTING_S(SYSTRAY_EXE, DEFAULT_SECTION, "systray_exe", "nstray.exe"); 
    104104    DESCRIBE_SETTING(SYSTRAY_EXE, "TODO", "TODO"); 
    105  
    106  
    107105  } 
    108106 
  • trunk/modules/CheckExternalScripts/CheckExternalScripts.cpp

    r256 r257  
    4242  boost::filesystem::wpath path = str_path; 
    4343  if (path.has_relative_path()) 
    44     path = NSCModuleHelper::getBasePath() / path; 
     44    path = GET_CORE()->getBasePath() / path; 
    4545  file_helpers::patterns::pattern_type split_path = file_helpers::patterns::split_pattern(path); 
    4646  if (!boost::filesystem::is_directory(split_path.first)) 
     
    7272  allowNasty_ = SETTINGS_GET_BOOL(nrpe::ALLOW_NASTY); 
    7373  std::list<std::wstring>::const_iterator it; 
    74   std::list<std::wstring> commands = NSCModuleHelper::getSettingsSection(setting_keys::external_scripts::SCRIPT_SECTION_PATH); 
     74  std::list<std::wstring> commands = GET_CORE()->getSettingsSection(setting_keys::external_scripts::SCRIPT_SECTION_PATH); 
    7575  for (it = commands.begin(); it != commands.end(); ++it) { 
    7676    if ((*it).empty()) 
    7777      continue; 
    7878    NSC_DEBUG_MSG_STD(_T("Looking under: ") + setting_keys::external_scripts::SCRIPT_SECTION_PATH + _T(", ") + (*it)); 
    79     std::wstring s = NSCModuleHelper::getSettingsString(setting_keys::external_scripts::SCRIPT_SECTION_PATH, (*it), _T("")); 
     79    std::wstring s = GET_CORE()->getSettingsString(setting_keys::external_scripts::SCRIPT_SECTION_PATH, (*it), _T("")); 
    8080    if (s.empty()) { 
    8181      NSC_LOG_ERROR_STD(_T("Invalid command definition: ") + (*it)); 
     
    8686  } 
    8787 
    88   commands = NSCModuleHelper::getSettingsSection(setting_keys::external_scripts::ALIAS_SECTION_PATH); 
     88  commands = GET_CORE()->getSettingsSection(setting_keys::external_scripts::ALIAS_SECTION_PATH); 
    8989  for (it = commands.begin(); it != commands.end(); ++it) { 
    9090    if ((*it).empty()) 
    9191      continue; 
    92     std::wstring s = NSCModuleHelper::getSettingsString(setting_keys::external_scripts::ALIAS_SECTION_PATH, (*it), _T("")); 
     92    std::wstring s = GET_CORE()->getSettingsString(setting_keys::external_scripts::ALIAS_SECTION_PATH, (*it), _T("")); 
    9393    if (s.empty()) { 
    9494      NSC_LOG_ERROR_STD(_T("Invalid command definition: ") + (*it)); 
     
    102102    addAllScriptsFrom(scriptDirectory_); 
    103103  } 
    104   root_ = NSCModuleHelper::getBasePath(); 
     104  root_ = GET_CORE()->getBasePath(); 
    105105  return true; 
    106106} 
     
    145145  } 
    146146  if (isAlias) { 
    147     return NSCModuleHelper::InjectSplitAndCommand(cd.command, args, ' ', message, perf, true); 
     147    return GET_CORE()->InjectSplitAndCommand(cd.command, args, ' ', message, perf, true); 
    148148  } else { 
    149149    int result = process::executeProcess(process::exec_arguments(root_, cd.command + _T(" ") + args, timeout), message, perf); 
    150     if (!NSCHelper::isNagiosReturnCode(result)) { 
     150    if (!nscapi::plugin_helper::isNagiosReturnCode(result)) { 
    151151      NSC_LOG_ERROR_STD(_T("The command (") + cd.command + _T(") returned an invalid return code: ") + strEx::itos(result)); 
    152152      return NSCAPI::returnUNKNOWN; 
    153153    } 
    154     return NSCHelper::int2nagios(result); 
     154    return nscapi::plugin_helper::int2nagios(result); 
    155155    /* 
    156156  } else if (cd.type == script_dir) { 
     
    171171NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    172172NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckExternalScripts); 
    173 NSC_WRAPPERS_HANDLE_CONFIGURATION(gCheckExternalScripts); 
    174173 
    175  
    176 MODULE_SETTINGS_START(CheckExternalScripts, _T("NRPE Listener configuration"), _T("..."))  
    177  
    178 PAGE(_T("NRPE Listsner configuration"))  
    179  
    180 ITEM_EDIT_TEXT(_T("port"), _T("This is the port the CheckExternalScripts.dll will listen to."))  
    181 ITEM_MAP_TO(_T("basic_ini_text_mapper"))  
    182 OPTION(_T("section"), _T("NRPE"))  
    183 OPTION(_T("key"), _T("port"))  
    184 OPTION(_T("default"), _T("5666"))  
    185 ITEM_END() 
    186  
    187 ITEM_CHECK_BOOL(_T("allow_arguments"), _T("This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed."))  
    188 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))  
    189 OPTION(_T("section"), _T("NRPE"))  
    190 OPTION(_T("key"), _T("allow_arguments"))  
    191 OPTION(_T("default"), _T("false"))  
    192 OPTION(_T("true_value"), _T("1"))  
    193 OPTION(_T("false_value"), _T("0"))  
    194 ITEM_END() 
    195  
    196 ITEM_CHECK_BOOL(_T("allow_nasty_meta_chars"), _T("This might have security implications (depending on what you do with the options)"))  
    197 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))  
    198 OPTION(_T("section"), _T("NRPE"))  
    199 OPTION(_T("key"), _T("allow_nasty_meta_chars"))  
    200 OPTION(_T("default"), _T("false"))  
    201 OPTION(_T("true_value"), _T("1"))  
    202 OPTION(_T("false_value"), _T("0"))  
    203 ITEM_END() 
    204  
    205 ITEM_CHECK_BOOL(_T("use_ssl"), _T("This option will enable SSL encryption on the NRPE data socket (this increases security somwhat."))  
    206 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))  
    207 OPTION(_T("section"), _T("NRPE"))  
    208 OPTION(_T("key"), _T("use_ssl"))  
    209 OPTION(_T("default"), _T("true"))  
    210 OPTION(_T("true_value"), _T("1"))  
    211 OPTION(_T("false_value"), _T("0"))  
    212 ITEM_END() 
    213  
    214 PAGE_END() 
    215 ADVANCED_PAGE(_T("Access configuration"))  
    216  
    217 ITEM_EDIT_OPTIONAL_LIST(_T("Allow connection from:"), _T("This is the hosts that will be allowed to poll performance data from the NRPE server."))  
    218 OPTION(_T("disabledCaption"), _T("Use global settings (defined previously)"))  
    219 OPTION(_T("enabledCaption"), _T("Specify hosts for NRPE server"))  
    220 OPTION(_T("listCaption"), _T("Add all IP addresses (not hosts) which should be able to connect:"))  
    221 OPTION(_T("separator"), _T(","))  
    222 OPTION(_T("disabled"), _T(""))  
    223 ITEM_MAP_TO(_T("basic_ini_text_mapper"))  
    224 OPTION(_T("section"), _T("NRPE"))  
    225 OPTION(_T("key"), _T("allowed_hosts"))  
    226 OPTION(_T("default"), _T(""))  
    227 ITEM_END() 
    228  
    229 PAGE_END() 
    230 MODULE_SETTINGS_END() 
  • trunk/modules/CheckExternalScripts/CheckExternalScripts.def

    r244 r257  
    1111  NSHandleCommand 
    1212  NSUnloadModule 
    13   NSGetConfigurationMeta 
    1413  NSGetModuleDescription 
    1514  NSDeleteBuffer 
  • trunk/modules/CheckExternalScripts/CheckExternalScripts.h

    r245 r257  
    2525#include <execute_process.hpp> 
    2626 
    27 class CheckExternalScripts : public NSCModuleHelper::SimpleCommand { 
     27class CheckExternalScripts : public nscapi::impl::SimpleCommand { 
    2828private: 
    2929  struct command_data { 
     
    5656    return _T("Check External Scripts"); 
    5757  } 
    58   NSCModuleWrapper::module_version getModuleVersion() { 
    59     NSCModuleWrapper::module_version version = {0, 0, 1 }; 
     58  nscapi::plugin_wrapper::module_version getModuleVersion() { 
     59    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    6060    return version; 
    6161  } 
     
    8888    command_data cd = command_data(cmd, args); 
    8989    commands[key] = cd; 
    90     NSCModuleHelper::registerCommand(key, _T("Script: ") + cd.to_string()); 
     90    GET_CORE()->registerCommand(key, _T("Script: ") + cd.to_string()); 
    9191  } 
    9292  void addAlias(std::wstring key, std::wstring cmd, std::wstring args) { 
     
    9494    command_data cd = command_data(cmd, args); 
    9595    alias[key] = cd; 
    96     NSCModuleHelper::registerCommand(key, _T("Alias for: ") + cd.to_string()); 
     96    GET_CORE()->registerCommand(key, _T("Alias for: ") + cd.to_string()); 
    9797  } 
    9898}; 
  • trunk/modules/CheckExternalScripts/stdafx.h

    r226 r257  
    2929#include <types.hpp> 
    3030#include <NSCAPI.h> 
    31 #include <nsc_module_wrapper.hpp> 
    32 #include <NSCHelper.h> 
     31#include <nscapi/plugin.hpp> 
    3332 
    3433#ifdef MEMCHECK 
  • trunk/modules/CheckHelpers/CheckHelpers.cpp

    r250 r257  
    3535bool CheckHelpers::loadModule(NSCAPI::moduleLoadMode mode) { 
    3636  try { 
    37     NSCModuleHelper::registerCommand(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK.")); 
    38     NSCModuleHelper::registerCommand(_T("CheckAlwaysCRITICAL"), _T("Run another check and regardless of its return code return CRIT.")); 
    39     NSCModuleHelper::registerCommand(_T("CheckAlwaysWARNING"), _T("Run another check and regardless of its return code return WARN.")); 
    40     NSCModuleHelper::registerCommand(_T("CheckMultiple"), _T("Run more then one check and return the worst state.")); 
    41     NSCModuleHelper::registerCommand(_T("CheckOK"), _T("Just return OK (anything passed along will be used as a message).")); 
    42     NSCModuleHelper::registerCommand(_T("check_ok"), _T("Just return OK (anything passed along will be used as a message).")); 
    43     NSCModuleHelper::registerCommand(_T("CheckWARNING"), _T("Just return WARN (anything passed along will be used as a message).")); 
    44     NSCModuleHelper::registerCommand(_T("CheckCRITICAL"), _T("Just return CRIT (anything passed along will be used as a message).")); 
    45     NSCModuleHelper::registerCommand(_T("CheckVersion"), _T("Just return the nagios version (along with OK status).")); 
    46   } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     37    GET_CORE()->registerCommand(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK.")); 
     38    GET_CORE()->registerCommand(_T("CheckAlwaysCRITICAL"), _T("Run another check and regardless of its return code return CRIT.")); 
     39    GET_CORE()->registerCommand(_T("CheckAlwaysWARNING"), _T("Run another check and regardless of its return code return WARN.")); 
     40    GET_CORE()->registerCommand(_T("CheckMultiple"), _T("Run more then one check and return the worst state.")); 
     41    GET_CORE()->registerCommand(_T("CheckOK"), _T("Just return OK (anything passed along will be used as a message).")); 
     42    GET_CORE()->registerCommand(_T("check_ok"), _T("Just return OK (anything passed along will be used as a message).")); 
     43    GET_CORE()->registerCommand(_T("CheckWARNING"), _T("Just return WARN (anything passed along will be used as a message).")); 
     44    GET_CORE()->registerCommand(_T("CheckCRITICAL"), _T("Just return CRIT (anything passed along will be used as a message).")); 
     45    GET_CORE()->registerCommand(_T("CheckVersion"), _T("Just return the nagios version (along with OK status).")); 
     46  } catch (nscapi::nscapi_exception &e) { 
    4747    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
    4848  } catch (...) { 
     
    6565  NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 
    6666  if (arguments.empty()) { 
    67     message = NSCHelper::translateReturn(status) + _T(": Lets pretend everything is going to be ok."); 
     67    message = nscapi::plugin_helper::translateReturn(status) + _T(": Lets pretend everything is going to be ok."); 
    6868    return status; 
    6969  } 
     
    7676NSCAPI::nagiosReturn CheckHelpers::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 
    7777  if (command == _T("CheckVersion")) { 
    78     message = NSCModuleHelper::getApplicationVersionString(); 
     78    message = GET_CORE()->getApplicationVersionString(); 
    7979    return NSCAPI::returnOK; 
    8080  } else if (command == _T("CheckAlwaysOK")) { 
     
    8484    } 
    8585    std::wstring new_command = arguments.front(); arguments.pop_front(); 
    86     NSCModuleHelper::InjectSimpleCommand(new_command, arguments, message, perf); 
     86    GET_CORE()->InjectSimpleCommand(new_command, arguments, message, perf); 
    8787    return NSCAPI::returnOK; 
    88   } else if (command == _T("CheckVersion")) { 
    89     message = NSCModuleHelper::getApplicationVersionString(); 
    90     return NSCAPI::returnOK; 
    91   } else if (command == _T("CheckOK")) { 
    92     return checkSimpleStatus(NSCAPI::returnOK, arguments, message, perf); 
    93   } else if (command == _T("CheckWARNING")) { 
    94     return checkSimpleStatus(NSCAPI::returnWARN, arguments, message, perf); 
    95   } else if (command == _T("CheckCRITICAL")) { 
    96     return checkSimpleStatus(NSCAPI::returnCRIT, arguments, message, perf); 
    9788  } else if (command == _T("CheckAlwaysCRITICAL")) { 
    9889    if (arguments.size() < 1) { 
     
    10192    } 
    10293    std::wstring new_command = arguments.front(); arguments.pop_front(); 
    103     NSCModuleHelper::InjectSimpleCommand(new_command, arguments, message, perf); 
     94    GET_CORE()->InjectSimpleCommand(new_command, arguments, message, perf); 
    10495    return NSCAPI::returnCRIT; 
    10596  } else if (command == _T("CheckAlwaysWARNING")) { 
     
    109100    } 
    110101    std::wstring new_command = arguments.front(); arguments.pop_front(); 
    111     NSCModuleHelper::InjectSimpleCommand(new_command, arguments, message, perf); 
     102    GET_CORE()->InjectSimpleCommand(new_command, arguments, message, perf); 
    112103    return NSCAPI::returnWARN; 
    113104  } else if (command == _T("CheckOK")) { 
     
    153144    std::list<std::wstring> sub_args; 
    154145    std::wstring tMsg, tPerf; 
    155     NSCAPI::nagiosReturn tRet = NSCModuleHelper::InjectSimpleCommand((*cit2).first.c_str(), (*cit2).second, tMsg, tPerf); 
    156     returnCode = NSCHelper::maxState(returnCode, tRet); 
     146    NSCAPI::nagiosReturn tRet = GET_CORE()->InjectSimpleCommand((*cit2).first.c_str(), (*cit2).second, tMsg, tPerf); 
     147    returnCode = nscapi::plugin_helper::maxState(returnCode, tRet); 
    157148    if (!message.empty()) 
    158149      message += _T(", "); 
  • trunk/modules/CheckHelpers/CheckHelpers.h

    r250 r257  
    2323#include <strEx.h> 
    2424 
    25 class CheckHelpers : public NSCModuleHelper::SimpleCommand { 
     25class CheckHelpers : public nscapi::impl::SimpleCommand { 
    2626private: 
    2727 
     
    3737    return _T("Helper function"); 
    3838  } 
    39   NSCModuleWrapper::module_version getModuleVersion() { 
    40     NSCModuleWrapper::module_version version = {0, 3, 0 }; 
     39  nscapi::plugin_wrapper::module_version getModuleVersion() { 
     40    nscapi::plugin_wrapper::module_version version = {0, 3, 0 }; 
    4141    return version; 
    4242  } 
  • trunk/modules/CheckHelpers/stdafx.h

    r216 r257  
    2828 
    2929#include <NSCAPI.h> 
    30 #include <nsc_module_wrapper.hpp> 
    31 #include <NSCHelper.h> 
     30#include <nscapi/plugin.hpp> 
    3231 
  • trunk/modules/CheckSystem/CheckSystem.def

    r38 r257  
    1111  NSHandleCommand 
    1212  NSUnloadModule 
    13   NSGetConfigurationMeta 
    1413  NSGetModuleDescription 
    1514  NSCommandLineExec 
  • trunk/modules/DebugLogMetrics/DebugLogMetrics.def

    r201 r257  
    1111  NSHandleCommand 
    1212  NSUnloadModule 
    13   NSGetConfigurationMeta 
    1413  NSGetModuleDescription 
  • trunk/modules/FileLogger/FileLogger.cpp

    r256 r257  
    5454std::wstring getFolder(std::wstring key) { 
    5555  if (key == _T("exe")) { 
    56     return NSCModuleHelper::getBasePath(); 
     56    return GET_CORE()->getBasePath(); 
    5757  } else { 
    5858#ifdef WIN32 
     
    6464#endif 
    6565  } 
    66   return NSCModuleHelper::getBasePath(); 
     66  return GET_CORE()->getBasePath(); 
    6767} 
    6868std::string FileLogger::getFileName() { 
     
    9494    SETTINGS_REG_KEY_S(log::LOG_MASK); 
    9595 
    96   } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     96  } catch (nscapi::nscapi_exception &e) { 
    9797    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
    9898  } catch (...) { 
     
    103103  format_ = to_string(SETTINGS_GET_STRING(log::DATEMASK)); 
    104104  std::wstring log_mask = SETTINGS_GET_STRING(log::LOG_MASK); 
    105   log_mask_ = NSCHelper::logging::parse(log_mask); 
    106   NSC_LOG_MESSAGE_STD(_T("Using logmask: ") + NSCHelper::logging::to_string(log_mask_)); 
     105  log_mask_ = nscapi::logging::parse(log_mask); 
     106  NSC_LOG_MESSAGE_STD(_T("Using logmask: ") + nscapi::logging::to_string(log_mask_)); 
    107107  init_ = true; 
    108   std::wstring hello = _T("Starting to log for: ") + NSCModuleHelper::getApplicationName() + _T(" - ") + NSCModuleHelper::getApplicationVersionString(); 
     108  std::wstring hello = _T("Starting to log for: ") + GET_CORE()->getApplicationName() + _T(" - ") + GET_CORE()->getApplicationVersionString(); 
    109109  handleMessage(NSCAPI::log, __FILEW__, __LINE__, hello.c_str()); 
    110110  NSC_LOG_MESSAGE_STD(_T("Log path is: ") + to_wstring(file_)); 
     
    135135*/ 
    136136 
    137 void FileLogger::handleMessage(int msgType, TCHAR* file, int line, const TCHAR* message) { 
     137void FileLogger::handleMessage(int msgType, const wchar_t* file, int line, const TCHAR* message) { 
    138138  if (!init_) { 
    139139    std::wcout << _T("Discarding: ") << message << std::endl; 
    140140    return; 
    141141  } 
    142   if (!NSCHelper::logging::matches(log_mask_, msgType)) 
     142  if (!nscapi::logging::matches(log_mask_, msgType)) 
    143143    return; 
    144144 
     
    148148  } 
    149149  stream << to_string(get_formated_date())  
    150     << (": ") << to_string(NSCHelper::translateMessageType(msgType)) 
     150    << (": ") << to_string(nscapi::plugin_helper::translateMessageType(msgType)) 
    151151    << (":") << to_string(std::wstring(file)) 
    152152    <<(":") << to_string(line)  
     
    166166NSC_WRAPPERS_HANDLE_MSG_DEF(gFileLogger); 
    167167NSC_WRAPPERS_IGNORE_CMD_DEF(); 
    168 NSC_WRAPPERS_HANDLE_CONFIGURATION(gFileLogger); 
    169  
    170 MODULE_SETTINGS_START(FileLogger, _T("File logger configuration"),_T("...")) 
    171 MODULE_SETTINGS_END() 
  • trunk/modules/FileLogger/FileLogger.def

    r245 r257  
    1111  NSHandleCommand 
    1212  NSUnloadModule 
    13   NSGetConfigurationMeta 
    1413  NSGetModuleDescription 
    1514  NSDeleteBuffer 
  • trunk/modules/FileLogger/FileLogger.h

    r256 r257  
    4242    return _T("File logger"); 
    4343  } 
    44   NSCModuleWrapper::module_version getModuleVersion() { 
    45     NSCModuleWrapper::module_version version = {0, 0, 1 }; 
     44  nscapi::plugin_wrapper::module_version getModuleVersion() { 
     45    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    4646    return version; 
    4747  } 
     
    5252  bool hasCommandHandler(); 
    5353  bool hasMessageHandler(); 
    54   void handleMessage(int msgType, TCHAR* file, int line, const TCHAR* message); 
     54  void handleMessage(int msgType, const wchar_t* file, int line, const TCHAR* message); 
    5555  int handleCommand(TCHAR* command, TCHAR **argument, TCHAR *returnBuffer, int returnBufferLen); 
    5656  //void writeEntry(std::wstring line); 
  • trunk/modules/FileLogger/stdafx.h

    r245 r257  
    2727 
    2828#include <NSCAPI.h> 
    29 #include <NSCHelper.h> 
    30 #include <nsc_module_wrapper.hpp> 
    31  
     29#include <nscapi/plugin.hpp> 
    3230#include <config.h> 
    3331 
  • trunk/modules/NRPEClient/NRPEClient.cpp

    r256 r257  
    4545  try { 
    4646    SETTINGS_REG_PATH(nrpe::CH_SECTION); 
    47     commands = NSCModuleHelper::getSettingsSection(setting_keys::nrpe::CH_SECTION_PATH); 
    48   } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     47    commands = GET_CORE()->getSettingsSection(setting_keys::nrpe::CH_SECTION_PATH); 
     48  } catch (nscapi::nscapi_exception &e) { 
    4949    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
    5050  } catch (...) { 
     
    5252  } 
    5353 
    54   boost::filesystem::wpath p = NSCModuleHelper::getBasePath() + std::wstring(_T("security/nrpe_dh_512.pem")); 
     54  boost::filesystem::wpath p = GET_CORE()->getBasePath() + std::wstring(_T("security/nrpe_dh_512.pem")); 
    5555  cert_ = p.string(); 
    5656  if (boost::filesystem::is_regular(p)) { 
     
    6363  for (std::list<std::wstring>::const_iterator it = commands.begin(); it != commands.end(); ++it) { 
    6464    NSC_DEBUG_MSG_STD(*it); 
    65     std::wstring s = NSCModuleHelper::getSettingsString(setting_keys::nrpe::CH_SECTION_PATH, (*it), _T("")); 
     65    std::wstring s = GET_CORE()->getSettingsString(setting_keys::nrpe::CH_SECTION_PATH, (*it), _T("")); 
    6666    if (s.empty()) { 
    6767      NSC_LOG_ERROR_STD(_T("Invalid NRPE-client entry: ") + (*it)); 
     
    276276NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    277277NSC_WRAPPERS_HANDLE_CMD_DEF(gNRPEClient); 
    278 NSC_WRAPPERS_HANDLE_CONFIGURATION(gNRPEClient); 
    279278NSC_WRAPPERS_CLI_DEF(gNRPEClient); 
    280279 
    281  
    282 MODULE_SETTINGS_START(NRPEClient, _T("NRPE Listener configuration"), _T("..."))  
    283  
    284 PAGE(_T("NRPE Listsner configuration"))  
    285  
    286 ITEM_EDIT_TEXT(_T("port"), _T("This is the port the NRPEClient.dll will listen to."))  
    287 ITEM_MAP_TO(_T("basic_ini_text_mapper"))  
    288 OPTION(_T("section"), _T("NRPE"))  
    289 OPTION(_T("key"), _T("port"))  
    290 OPTION(_T("default"), _T("5666"))  
    291 ITEM_END() 
    292  
    293 ITEM_CHECK_BOOL(_T("allow_arguments"), _T("This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed."))  
    294 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))  
    295 OPTION(_T("section"), _T("NRPE"))  
    296 OPTION(_T("key"), _T("allow_arguments"))  
    297 OPTION(_T("default"), _T("false"))  
    298 OPTION(_T("true_value"), _T("1"))  
    299 OPTION(_T("false_value"), _T("0"))  
    300 ITEM_END() 
    301  
    302 ITEM_CHECK_BOOL(_T("allow_nasty_meta_chars"), _T("This might have security implications (depending on what you do with the options)"))  
    303 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))  
    304 OPTION(_T("section"), _T("NRPE"))  
    305 OPTION(_T("key"), _T("allow_nasty_meta_chars"))  
    306 OPTION(_T("default"), _T("false"))  
    307 OPTION(_T("true_value"), _T("1"))  
    308 OPTION(_T("false_value"), _T("0"))  
    309 ITEM_END() 
    310  
    311 ITEM_CHECK_BOOL(_T("use_ssl"), _T("This option will enable SSL encryption on the NRPE data socket (this increases security somwhat."))  
    312 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))  
    313 OPTION(_T("section"), _T("NRPE"))  
    314 OPTION(_T("key"), _T("use_ssl"))  
    315 OPTION(_T("default"), _T("true"))  
    316 OPTION(_T("true_value"), _T("1"))  
    317 OPTION(_T("false_value"), _T("0"))  
    318 ITEM_END() 
    319  
    320 PAGE_END() 
    321 ADVANCED_PAGE(_T("Access configuration"))  
    322  
    323 ITEM_EDIT_OPTIONAL_LIST(_T("Allow connection from:"), _T("This is the hosts that will be allowed to poll performance data from the NRPE server."))  
    324 OPTION(_T("disabledCaption"), _T("Use global settings (defined previously)"))  
    325 OPTION(_T("enabledCaption"), _T("Specify hosts for NRPE server"))  
    326 OPTION(_T("listCaption"), _T("Add all IP addresses (not hosts) which should be able to connect:"))  
    327 OPTION(_T("separator"), _T(","))  
    328 OPTION(_T("disabled"), _T(""))  
    329 ITEM_MAP_TO(_T("basic_ini_text_mapper"))  
    330 OPTION(_T("section"), _T("NRPE"))  
    331 OPTION(_T("key"), _T("allowed_hosts"))  
    332 OPTION(_T("default"), _T(""))  
    333 ITEM_END() 
    334  
    335 PAGE_END() 
    336 MODULE_SETTINGS_END() 
  • trunk/modules/NRPEClient/NRPEClient.def

    r244 r257  
    1111  NSHandleCommand 
    1212  NSUnloadModule 
    13   NSGetConfigurationMeta 
    1413  NSGetModuleDescription 
    1514  NSCommandLineExec 
  • trunk/modules/NRPEClient/NRPEClient.h

    r254 r257  
    2525 
    2626 
    27 class NRPEClient : public NSCModuleHelper::SimpleCommand { 
     27class NRPEClient : public nscapi::impl::SimpleCommand { 
    2828private: 
    2929  typedef enum { 
     
    104104#endif 
    105105  } 
    106   NSCModuleWrapper::module_version getModuleVersion() { 
    107     NSCModuleWrapper::module_version version = {0, 0, 1 }; 
     106  nscapi::plugin_wrapper::module_version getModuleVersion() { 
     107    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    108108    return version; 
    109109  } 
  • trunk/modules/NRPEClient/stdafx.h

    r229 r257  
    4040 
    4141#include <NSCAPI.h> 
    42 #include <NSCHelper.h> 
    43 #include <nsc_module_wrapper.hpp> 
     42#include <nscapi/plugin.hpp> 
    4443namespace po = boost::program_options; 
    4544 
  • trunk/modules/NRPEServer/NRPEServer.cpp

    r250 r257  
    100100    return false; 
    101101  } 
    102   root_ = NSCModuleHelper::getBasePath(); 
     102  root_ = GET_CORE()->getBasePath(); 
    103103  return true; 
    104104} 
     
    304304NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    305305NSC_WRAPPERS_IGNORE_CMD_DEF(); 
    306 NSC_WRAPPERS_HANDLE_CONFIGURATION(gNRPEListener); 
    307  
    308  
    309 MODULE_SETTINGS_START(NRPEListener, _T("NRPE Listener configuration"), _T("..."))  
    310  
    311 PAGE(_T("NRPE Listsner configuration"))  
    312  
    313 ITEM_EDIT_TEXT(_T("port"), _T("This is the port the NRPEListener.dll will listen to."))  
    314 ITEM_MAP_TO(_T("basic_ini_text_mapper"))  
    315 OPTION(_T("section"), _T("NRPE"))  
    316 OPTION(_T("key"), _T("port"))  
    317 OPTION(_T("default"), _T("5666"))  
    318 ITEM_END() 
    319  
    320 ITEM_CHECK_BOOL(_T("allow_arguments"), _T("This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed."))  
    321 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))  
    322 OPTION(_T("section"), _T("NRPE"))  
    323 OPTION(_T("key"), _T("allow_arguments"))  
    324 OPTION(_T("default"), _T("false"))  
    325 OPTION(_T("true_value"), _T("1"))  
    326 OPTION(_T("false_value"), _T("0"))  
    327 ITEM_END() 
    328  
    329 ITEM_CHECK_BOOL(_T("allow_nasty_meta_chars"), _T("This might have security implications (depending on what you do with the options)"))  
    330 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))  
    331 OPTION(_T("section"), _T("NRPE"))  
    332 OPTION(_T("key"), _T("allow_nasty_meta_chars"))  
    333 OPTION(_T("default"), _T("false"))  
    334 OPTION(_T("true_value"), _T("1"))  
    335 OPTION(_T("false_value"), _T("0"))  
    336 ITEM_END() 
    337  
    338 ITEM_CHECK_BOOL(_T("use_ssl"), _T("This option will enable SSL encryption on the NRPE data socket (this increases security somwhat."))  
    339 ITEM_MAP_TO(_T("basic_ini_bool_mapper"))  
    340 OPTION(_T("section"), _T("NRPE"))  
    341 OPTION(_T("key"), _T("use_ssl"))  
    342 OPTION(_T("default"), _T("true"))  
    343 OPTION(_T("true_value"), _T("1"))  
    344 OPTION(_T("false_value"), _T("0"))  
    345 ITEM_END() 
    346  
    347 PAGE_END() 
    348 ADVANCED_PAGE(_T("Access configuration"))  
    349  
    350 ITEM_EDIT_OPTIONAL_LIST(_T("Allow connection from:"), _T("This is the hosts that will be allowed to poll performance data from the NRPE server."))  
    351 OPTION(_T("disabledCaption"), _T("Use global settings (defined previously)"))  
    352 OPTION(_T("enabledCaption"), _T("Specify hosts for NRPE server"))  
    353 OPTION(_T("listCaption"), _T("Add all IP addresses (not hosts) which should be able to connect:"))  
    354 OPTION(_T("separator"), _T(","))  
    355 OPTION(_T("disabled"), _T(""))  
    356 ITEM_MAP_TO(_T("basic_ini_text_mapper"))  
    357 OPTION(_T("section"), _T("NRPE"))  
    358 OPTION(_T("key"), _T("allowed_hosts"))  
    359 OPTION(_T("default"), _T(""))  
    360 ITEM_END() 
    361  
    362 PAGE_END() 
    363 MODULE_SETTINGS_END() 
  • trunk/modules/NRPEServer/NRPEServer.def

    r244 r257  
    1111  NSHandleCommand 
    1212  NSUnloadModule 
    13   NSGetConfigurationMeta 
    1413  NSGetModuleDescription 
    1514  NSDeleteBuffer 
  • trunk/modules/NRPEServer/NRPEServer.h

    r238 r257  
    5959#endif 
    6060  } 
    61   NSCModuleWrapper::module_version getModuleVersion() { 
    62     NSCModuleWrapper::module_version version = {0, 0, 1 }; 
     61  nscapi::plugin_wrapper::module_version getModuleVersion() { 
     62    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    6363    return version; 
    6464  } 
  • trunk/modules/NRPEServer/nrpe_handler.cpp

    r226 r257  
    22#include <boost/asio.hpp> 
    33#include "nrpe_handler.hpp" 
    4 #include <NSCHelper.h> 
    54 
    65namespace nrpe { 
     
    98      strEx::token cmd = strEx::getToken(p.getPayload(), '!'); 
    109      if (cmd.first == _T("_NRPE_CHECK")) { 
    11         return nrpe::packet::create_response(NSCAPI::returnOK, _T("I (") + NSCModuleHelper::getApplicationVersionString() + _T(") seem to be doing fine..."), p.get_payload_length()); 
     10        return nrpe::packet::create_response(NSCAPI::returnOK, _T("I (") + nscapi::plugin_singleton->get_core()->getApplicationVersionString() + _T(") seem to be doing fine..."), p.get_payload_length()); 
    1211      } 
    1312      std::wstring msg, perf; 
     
    3433      NSCAPI::nagiosReturn ret = -3; 
    3534      try { 
    36         ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf); 
     35        ret = nscapi::plugin_singleton->get_core()->InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf); 
    3736      } catch (...) { 
    3837        return nrpe::packet::create_response(NSCAPI::returnUNKNOWN, _T("UNKNOWN: Internal exception"), p.get_payload_length()); 
  • trunk/modules/NRPEServer/stdafx.h

    r254 r257  
    4646#include <types.hpp> 
    4747#include <NSCAPI.h> 
    48 #include <NSCHelper.h> 
    49 #include <nsc_module_wrapper.hpp> 
     48#include <nscapi/plugin.hpp> 
    5049#include <nrpe/nrpe_packet.hpp> 
    5150 
  • trunk/modules/NSCAAgent/NSCAAgent.cpp

    r256 r257  
    7272 
    7373 
    74   } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     74  } catch (nscapi::nscapi_exception &e) { 
    7575    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
    7676  } catch (...) { 
     
    124124    socket.recv_iv(password_, encryption_method_, boost::posix_time::seconds(timeout_)); 
    125125    socket.send_nsca(packet, boost::posix_time::seconds(timeout_)); 
    126     return 1; 
     126    return NSCAPI::isSuccess; 
    127127  } catch (std::exception &e) { 
    128128    NSC_LOG_ERROR_STD(_T("Failed to send data: ") + to_wstring(e.what())); 
     129    return NSCAPI::hasFailed; 
    129130  } catch (...) { 
    130131    NSC_LOG_ERROR_STD(_T("Failed to send data: UNKNOWN")); 
     132    return NSCAPI::hasFailed; 
    131133  } 
    132134} 
  • trunk/modules/NSCAAgent/NSCAAgent.h

    r256 r257  
    2323NSC_WRAPPERS_MAIN(); 
    2424 
    25 class NSCAAgent : public NSCModuleHelper::SimpleNotificationHandler { 
     25class NSCAAgent : public nscapi::impl::SimpleNotificationHandler { 
    2626private: 
    2727 
     
    5959  * @return module version 
    6060  */ 
    61   NSCModuleWrapper::module_version getModuleVersion() { 
    62     NSCModuleWrapper::module_version version = {0, 3, 0 }; 
     61  nscapi::plugin_wrapper::module_version getModuleVersion() { 
     62    nscapi::plugin_wrapper::module_version version = {0, 3, 0 }; 
    6363    return version; 
    6464  } 
  • trunk/modules/NSCAAgent/stdafx.h

    r256 r257  
    3737 
    3838#include <NSCAPI.h> 
    39 #include <NSCHelper.h> 
    40 #include <nsc_module_wrapper.hpp> 
     39#include <nscapi/plugin.hpp> 
    4140#include <config.h> 
    4241#include <utils.h> 
  • trunk/modules/NSClientListener/NSClientListener.def

    r32 r257  
    1111  NSHandleCommand 
    1212  NSUnloadModule 
    13   NSGetConfigurationMeta 
    1413  NSGetModuleDescription 
    1514 
  • trunk/modules/Scheduler/Scheduler.cpp

    r254 r257  
    4040 
    4141    SETTINGS_REG_KEY_I(scheduler::THREADS); 
    42   } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     42  } catch (nscapi::nscapi_exception &e) { 
    4343    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
    4444  } catch (...) { 
     
    5959    bool found = false; 
    6060    scheduler::target def = read_defaut_schedule(setting_keys::scheduler::DEFAULT_SCHEDULE_SECTION_PATH); 
    61     std::list<std::wstring> items = NSCModuleHelper::getSettingsSection(setting_keys::scheduler::SCHEDULES_SECTION_PATH); 
     61    std::list<std::wstring> items = GET_CORE()->getSettingsSection(setting_keys::scheduler::SCHEDULES_SECTION_PATH); 
    6262 
    6363    for (std::list<std::wstring>::const_iterator cit = items.begin(); cit != items.end(); ++cit) { 
    6464      found = true; 
    65       add_schedule(*cit, NSCModuleHelper::getSettingsString(setting_keys::scheduler::SCHEDULES_SECTION_PATH, *cit, _T("")), def); 
     65      add_schedule(*cit, GET_CORE()->getSettingsString(setting_keys::scheduler::SCHEDULES_SECTION_PATH, *cit, _T("")), def); 
    6666    } 
    6767 
     
    7474 
    7575    } 
    76   } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     76  } catch (nscapi::nscapi_exception &e) { 
    7777    NSC_LOG_ERROR_STD(_T("Exception in module Scheduler: ") + e.msg_); 
    7878    return false; 
     
    8686scheduler::target Scheduler::read_defaut_schedule(std::wstring path) { 
    8787  scheduler::target item; 
    88   item.channel = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::CHANNEL_D, setting_keys::scheduler::CHANNEL_D_DEFAULT); 
    89   item.command = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::COMMAND_D, setting_keys::scheduler::COMMAND_D_DEFAULT); 
    90   std::wstring report = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::REPORT_MODE_D, setting_keys::scheduler::REPORT_MODE_D_DEFAULT); 
    91   item.report = NSCHelper::report::parse(report); 
    92   std::wstring duration = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::INTERVAL_D, setting_keys::scheduler::INTERVAL_D_DEFAULT); 
     88  item.channel = GET_CORE()->getSettingsString(path, setting_keys::scheduler::CHANNEL_D, setting_keys::scheduler::CHANNEL_D_DEFAULT); 
     89  item.command = GET_CORE()->getSettingsString(path, setting_keys::scheduler::COMMAND_D, setting_keys::scheduler::COMMAND_D_DEFAULT); 
     90  std::wstring report = GET_CORE()->getSettingsString(path, setting_keys::scheduler::REPORT_MODE_D, setting_keys::scheduler::REPORT_MODE_D_DEFAULT); 
     91  item.report = nscapi::report::parse(report); 
     92  std::wstring duration = GET_CORE()->getSettingsString(path, setting_keys::scheduler::INTERVAL_D, setting_keys::scheduler::INTERVAL_D_DEFAULT); 
    9393  item.duration = boost::posix_time::seconds(strEx::stoui_as_time_sec(duration, 1)); 
    9494  return item; 
     
    9999  item.alias = alias; 
    100100  item.command = command; 
    101   item.channel = NSCModuleHelper::getSettingsString(detail_path, setting_keys::scheduler::CHANNEL, def.channel); 
    102   item.command = NSCModuleHelper::getSettingsString(detail_path, setting_keys::scheduler::COMMAND, item.command); 
     101  item.channel = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::CHANNEL, def.channel); 
     102  item.command = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::COMMAND, item.command); 
    103103 
    104104  strEx::parse_command(item.command, item.command, item.arguments); 
    105105 
    106   std::wstring report = NSCModuleHelper::getSettingsString(detail_path, setting_keys::scheduler::REPORT_MODE, NSCHelper::report::to_string(def.report)); 
    107   item.report = NSCHelper::report::parse(report); 
    108   std::wstring duration = NSCModuleHelper::getSettingsString(detail_path, setting_keys::scheduler::INTERVAL, to_wstring(def.duration.total_seconds()) + _T("s")); 
     106  std::wstring report = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::REPORT_MODE, nscapi::report::to_string(def.report)); 
     107  item.report = nscapi::report::parse(report); 
     108  std::wstring duration = GET_CORE()->getSettingsString(detail_path, setting_keys::scheduler::INTERVAL, to_wstring(def.duration.total_seconds()) + _T("s")); 
    109109  item.duration = boost::posix_time::seconds(strEx::stoui_as_time_sec(duration, 1)); 
    110110  scheduler_.add_task(item); 
     
    124124  try { 
    125125    std::string response; 
    126     NSCAPI::nagiosReturn code = NSCModuleHelper::InjectCommand(item.command.c_str(), item.arguments, response); 
    127     if (NSCHelper::report::matches(item.report, code)) { 
    128       NSCModuleHelper::NotifyChannel(item.channel, item.alias, code, response); 
     126    NSCAPI::nagiosReturn code = GET_CORE()->InjectCommand(item.command.c_str(), item.arguments, response); 
     127    if (nscapi::report::matches(item.report, code)) { 
     128      GET_CORE()->NotifyChannel(item.channel, item.alias, code, response); 
    129129    } 
    130   } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     130  } catch (nscapi::nscapi_exception &e) { 
    131131    NSC_LOG_ERROR_STD(_T("Exception handling: ") + item.alias + _T(": ") + e.msg_); 
    132132    scheduler_.remove_task(item.id); 
  • trunk/modules/Scheduler/Scheduler.h

    r245 r257  
    4747    return _T("Scheduler"); 
    4848  } 
    49   NSCModuleWrapper::module_version getModuleVersion() { 
    50     NSCModuleWrapper::module_version version = {0, 3, 0 }; 
     49  nscapi::plugin_wrapper::module_version getModuleVersion() { 
     50    nscapi::plugin_wrapper::module_version version = {0, 3, 0 }; 
    5151    return version; 
    5252  } 
  • trunk/modules/Scheduler/stdafx.h

    r229 r257  
    3030 
    3131#include <NSCAPI.h> 
    32 #include <nsc_module_wrapper.hpp> 
    33 #include <NSCHelper.h> 
     32#include <nscapi/plugin.hpp> 
    3433 
  • trunk/service/CMakeLists.txt

    r254 r257  
    1919  settings_manager_impl.cpp 
    2020 
    21   ${NSCP_DEF_PLUGIN_CPP} 
     21  ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.cpp 
    2222 
    2323  ${NSCP_INCLUDE_PATH}/simpleini/ConvertUTF.c 
    2424  ${NSCP_INCLUDE_PATH}/b64/b64.c 
     25  ${NSCP_INCLUDE_PATH}/arrayBuffer.cpp 
    2526 
    2627) 
     
    6263    ${NSCP_INCLUDE_PATH}/service/system_service.hpp 
    6364    ${NSCP_INCLUDE_PATH}/service/win32_service.hpp 
    64  
    65     ${NSCP_DEF_PLUGIN_HPP} 
     65    ${NSCP_INCLUDE_PATH}/nscapi/nscapi_helper.hpp 
    6666 
    6767  ) 
  • trunk/service/NSCPlugin.cpp

    r256 r257  
    2323#include "core_api.h" 
    2424 
    25 unsigned int NSCPlugin::last_plugin_id_ = 0; 
    26  
    27  
    2825/** 
    2926 * Default c-tor 
     
    3330 * @param file The file (DLL) to load as a NSC plug in. 
    3431 */ 
    35 NSCPlugin::NSCPlugin(const boost::filesystem::wpath file) 
     32NSCPlugin::NSCPlugin(const unsigned int id, const boost::filesystem::wpath file) 
    3633  : module_(file.string()) 
    3734  ,fLoadModule(NULL) 
     
    4340  ,fDeleteBuffer(NULL) 
    4441  ,fGetDescription(NULL) 
    45   ,fGetConfigurationMeta(NULL) 
    4642  ,fGetVersion(NULL) 
    4743  ,fCommandLineExec(NULL) 
     
    5349  ,lastIsMsgPlugin_(false) 
    5450  ,broken_(false) 
    55   ,plugin_id_(0) 
     51  ,plugin_id_(id) 
    5652{ 
    57   plugin_id_ = ++last_plugin_id_; 
     53 
    5854} 
    5955/* 
     
    6763  ,fHandleMessage(NULL) 
    6864  ,fGetDescription(NULL) 
    69   ,fGetConfigurationMeta(NULL) 
    7065  ,fGetVersion(NULL) 
    7166  ,fCommandLineExec(NULL) 
     
    361356 
    362357  try { 
    363     fLoadModule = (lpLoadModule)module_.load_proc("NSLoadModule"); 
     358    fLoadModule = (nscapi::plugin_api::lpLoadModule)module_.load_proc("NSLoadModule"); 
    364359    if (!fLoadModule) 
    365360      throw NSPluginException(module_, _T("Could not load NSLoadModule")); 
    366361 
    367     fModuleHelperInit = (lpModuleHelperInit)module_.load_proc("NSModuleHelperInit"); 
     362    fModuleHelperInit = (nscapi::plugin_api::lpModuleHelperInit)module_.load_proc("NSModuleHelperInit"); 
    368363    if (!fModuleHelperInit) 
    369364      throw NSPluginException(module_, _T("Could not load NSModuleHelperInit")); 
     
    375370    } 
    376371 
    377     fGetName = (lpGetName)module_.load_proc("NSGetModuleName"); 
     372    fGetName = (nscapi::plugin_api::lpGetName)module_.load_proc("NSGetModuleName"); 
    378373    if (!fGetName) 
    379374      throw NSPluginException(module_, _T("Could not load NSGetModuleName")); 
    380375 
    381     fGetVersion = (lpGetVersion)module_.load_proc("NSGetModuleVersion"); 
     376    fGetVersion = (nscapi::plugin_api::lpGetVersion)module_.load_proc("NSGetModuleVersion"); 
    382377    if (!fGetVersion) 
    383378      throw NSPluginException(module_, _T("Could not load NSGetModuleVersion")); 
    384379 
    385     fGetDescription = (lpGetDescription)module_.load_proc("NSGetModuleDescription"); 
     380    fGetDescription = (nscapi::plugin_api::lpGetDescription)module_.load_proc("NSGetModuleDescription"); 
    386381    if (!fGetDescription) 
    387382      throw NSPluginException(module_, _T("Could not load NSGetModuleDescription")); 
    388383 
    389     fHasCommandHandler = (lpHasCommandHandler)module_.load_proc("NSHasCommandHandler"); 
     384    fHasCommandHandler = (nscapi::plugin_api::lpHasCommandHandler)module_.load_proc("NSHasCommandHandler"); 
    390385    if (!fHasCommandHandler) 
    391386      throw NSPluginException(module_, _T("Could not load NSHasCommandHandler")); 
    392387 
    393     fHasMessageHandler = (lpHasMessageHandler)module_.load_proc("NSHasMessageHandler"); 
     388    fHasMessageHandler = (nscapi::plugin_api::lpHasMessageHandler)module_.load_proc("NSHasMessageHandler"); 
    394389    if (!fHasMessageHandler) 
    395390      throw NSPluginException(module_, _T("Could not load NSHasMessageHandler")); 
    396391 
    397     fHandleCommand = (lpHandleCommand)module_.load_proc("NSHandleCommand"); 
     392    fHandleCommand = (nscapi::plugin_api::lpHandleCommand)module_.load_proc("NSHandleCommand"); 
    398393    //if (!fHandleCommand) 
    399394    //  throw NSPluginException(module_, _T("Could not load NSHandleCommand")); 
    400395 
    401     fDeleteBuffer = (lpDeleteBuffer)module_.load_proc("NSDeleteBuffer"); 
     396    fDeleteBuffer = (nscapi::plugin_api::lpDeleteBuffer)module_.load_proc("NSDeleteBuffer"); 
    402397    if (!fDeleteBuffer) 
    403398      throw NSPluginException(module_, _T("Could not load NSDeleteBuffer")); 
    404399 
    405     fHandleMessage = (lpHandleMessage)module_.load_proc("NSHandleMessage"); 
     400    fHandleMessage = (nscapi::plugin_api::lpHandleMessage)module_.load_proc("NSHandleMessage"); 
    406401    if (!fHandleMessage) 
    407402      throw NSPluginException(module_, _T("Could not load NSHandleMessage")); 
    408403 
    409     fUnLoadModule = (lpUnLoadModule)module_.load_proc("NSUnloadModule"); 
     404    fUnLoadModule = (nscapi::plugin_api::lpUnLoadModule)module_.load_proc("NSUnloadModule"); 
    410405    if (!fUnLoadModule) 
    411406      throw NSPluginException(module_, _T("Could not load NSUnloadModule")); 
    412407 
    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"); 
    417411     
    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"); 
    420414     
    421415  } catch (NSPluginException &e) { 
     
    430424 
    431425 
    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  
    452426int NSCPlugin::commandLineExec(const unsigned int argLen, wchar_t **arguments) { 
    453427  if (fCommandLineExec== NULL) 
     
    459433  } 
    460434} 
     435 
  • trunk/service/NSCPlugin.h

    r254 r257  
    2525#include <sstream> 
    2626#include <dll/dll.hpp> 
     27#include <boost/noncopyable.hpp> 
    2728 
    2829/** 
     
    103104 * 
    104105 */ 
    105 class NSCPlugin { 
     106class NSCPlugin : boost::noncopyable { 
    106107private: 
    107108  bool bLoaded_;      // Status of plug in 
    108109  dll::dll module_; 
    109110  bool broken_; 
    110   static unsigned int last_plugin_id_; 
    111111  unsigned int plugin_id_; 
    112112 
    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; 
    149129 
    150130public: 
    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); 
    153133  virtual ~NSCPlugin(void); 
    154134 
     
    192172    return file; 
    193173  } 
     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  } 
    194181  bool getLastIsMsgPlugin() { 
    195182    return lastIsMsgPlugin_; 
     
    205192  bool getDescription_(wchar_t* buf, unsigned int buflen); 
    206193  void loadRemoteProcs_(void); 
    207   bool getConfigurationMeta_(wchar_t* buf, unsigned int buflen); 
    208194}; 
    209195 
  • trunk/service/NSClient++.cpp

    r256 r257  
    3535#include "settings_manager_impl.h" 
    3636#include <settings/macros.h> 
    37 #include <NSCHelper.h> 
    3837#include "simple_client.hpp" 
    3938#include "settings_client.hpp" 
    4039#include "service_manager.hpp" 
     40#include <nscapi/nscapi_helper.hpp> 
    4141 
    4242#include "../libs/protobuf/plugin.proto.h" 
     
    304304    } else if ( wcscasecmp( _T("about"), argv[1]+1 ) == 0 ) { 
    305305      try { 
     306        unsigned int next_plugin_id = 0; 
    306307        g_bConsoleLog = true; 
    307308        LOG_MESSAGE(SZAPPNAME _T(" (C) Michael Medin - michael<at>medin<dot>name")); 
     
    318319            LOG_MESSAGE_STD(_T("Found: ") + file); 
    319320            if (is_module(pluginPath / file)) { 
    320               NSCPlugin *plugin = new NSCPlugin(pluginPath / file); 
     321              NSCPlugin *plugin = new NSCPlugin(next_plugin_id++, pluginPath / file); 
    321322              std::wstring name = _T("<unknown>"); 
    322323              std::wstring description = _T("<unknown>"); 
     
    459460        try { 
    460461          LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 
    461           NSCPlugin plugin(pluginPath / file); 
     462          NSCPlugin plugin(next_plugin_id_++, pluginPath / file); 
    462463          plugin.load_dll(); 
    463464          plugin.load_plugin(NSCAPI::dontStart); 
     
    490491            try { 
    491492              LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 
    492               NSCPlugin plugin(modPath / file); 
     493              NSCPlugin plugin(next_plugin_id_++, modPath / file); 
    493494              plugin.load_dll(); 
    494495              plugin.load_plugin(mode); 
     
    504505          std::wstring name = file.string(); 
    505506          try { 
    506             NSCPlugin plugin(modPath / file); 
     507            NSCPlugin plugin(next_plugin_id_++, modPath / file); 
    507508            name = plugin.getModule(); 
    508509            plugin.load_dll(); 
     
    626627      Settings::string_list list = settings_manager::get_settings()->get_keys(MAIN_MODULES_SECTION); 
    627628      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); 
    629631        try { 
    630632          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.")); 
    632634            continue; 
    633635          } 
     
    636638        } 
    637639        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)); 
    639641        } catch(const NSPluginException& e) { 
    640642          LOG_ERROR_CORE_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); 
    641643          //return false; 
    642644        } 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())); 
    644646          return false; 
    645647        } catch (...) { 
    646           LOG_ERROR_CORE_STD(_T("Unknown exception loading plugin: ") + (*cit)); 
     648          LOG_ERROR_CORE_STD(_T("Unknown exception loading plugin: ") + file); 
    647649          return false; 
    648650        } 
     
    971973 */ 
    972974NSClientT::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)); 
    974976  return addPlugin(plugin); 
    975977} 
     
    11221124      } 
    11231125      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("}}}")); 
    11251127      return c; 
    11261128    } catch (nsclient::commands::command_exception &e) { 
     
    12011203  OutputDebugString(msg.c_str()); 
    12021204#else 
    1203   std::wcout << _T("--BROKEN MESSAGE: ") << msg << _T("--") << std::endl; 
     1205//  std::wcout << _T("--BROKEN MESSAGE: ") << msg << _T("--") << std::endl; 
    12041206#endif 
    12051207} 
  • trunk/service/NSClient++.h

    r254 r257  
    123123  nsclient::commands commands_; 
    124124  nsclient::channels channels_; 
     125  unsigned int next_plugin_id_; 
    125126 
    126127 
    127128public: 
    128129  // 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) {} 
    130131  virtual ~NSClientT(void) {} 
    131132  void enableDebug(bool debug = true) { 
  • trunk/service/commands.hpp

    r245 r257  
    55#include "NSCPlugin.h" 
    66#include "logger.hpp" 
     7#include <strEx.h> 
    78 
    89namespace nsclient { 
     
    4041 
    4142    void add_plugin(plugin_type plugin) { 
    42       if (!plugin || !plugin->hasCommandHandler()) 
     43      if (!plugin || !plugin->hasCommandHandler()) { 
    4344        return; 
     45      } 
    4446      plugins_[plugin->get_id()] = plugin; 
    4547       
     
    8890      std::wstring lc = make_key(cmd); 
    8991      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()); 
    9193      descriptions_[lc] = desc; 
    9294      commands_[lc] = plugins_[plugin_id]; 
    9395    } 
     96private: 
    9497 
     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 
     110public: 
    95111    std::wstring describe(std::wstring command) { 
    96112      boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     
    120136    } 
    121137 
     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 
    122153    plugin_type get(std::wstring command) { 
    123154      boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     
    136167 
    137168    std::wstring to_wstring() { 
    138       std::wstring ret; 
     169      std::wstring ret = _T("commands {"); 
    139170      BOOST_FOREACH(std::wstring str, list()) { 
    140171        if (!ret.empty()) ret += _T(", "); 
    141172        ret += str; 
    142173      } 
     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("}"); 
    143180      return ret; 
    144181    } 
  • trunk/service/core_api.cpp

    r254 r257  
    1919#include <config.h> 
    2020#include <msvc_wrappers.h> 
     21#include <arrayBuffer.h> 
    2122//#include <settings/settings_ini.hpp> 
    2223//#include <settings/settings_registry.hpp> 
     
    2829#include "settings_manager_impl.h" 
    2930#include <b64/b64.h> 
    30 #include <NSCHelper.h> 
     31#include <nscapi/nscapi_helper.hpp> 
    3132#ifdef _WIN32 
    3233#include <ServiceCmd.h> 
     
    3435 
    3536#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) 
    3938#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) 
    4240#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) 
    4642#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) 
    5046 
    5147NSCAPI::errorReturn NSAPIGetSettingsString(const wchar_t* section, const wchar_t* key, const wchar_t* defaultValue, wchar_t* buffer, unsigned int bufLen) { 
    5248  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); 
    5450  } catch (...) { 
    5551    LOG_ERROR_STD(_T("Failed to getString: ") + key); 
     
    6662} 
    6763NSCAPI::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); 
    6965} 
    7066NSCAPI::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); 
    7268} 
    7369NSCAPI::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); 
    7571} 
    7672void NSAPIMessage(int msgType, const wchar_t* file, const int line, const wchar_t* message) { 
     
    262258} 
    263259NSCAPI::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); 
    265261} 
    266262NSCAPI::errorReturn NSAPIGetAllCommandNames(arrayBuffer::arrayBuffer* aBuffer, unsigned int *bufLen) { 
     
    369365 
    370366 
    371 LPVOID NSAPILoader(wchar_t*buffer) { 
     367LPVOID NSAPILoader(const wchar_t*buffer) { 
    372368  if (wcscasecmp(buffer, _T("NSAPIGetApplicationName")) == 0) 
    373369    return reinterpret_cast<LPVOID>(&NSAPIGetApplicationName); 
  • trunk/service/core_api.h

    r254 r257  
    3030// 
    3131 
    32 LPVOID NSAPILoader(wchar_t*buffer); 
     32LPVOID NSAPILoader(const wchar_t*buffer); 
    3333NSCAPI::errorReturn NSAPIGetApplicationName(wchar_t*buffer, unsigned int bufLen); 
    3434NSCAPI::errorReturn NSAPIGetBasePath(wchar_t*buffer, unsigned int bufLen); 
  • trunk/service/simple_client.hpp

    r245 r257  
    11#pragma once 
     2#include <nscapi/nscapi_helper.hpp> 
    23 
    34class NSClientT; 
     
    2526*/ 
    2627      std::wstring s = _T(""); 
    27       std::wstring buff = _T(""); 
     28 
    2829      while (true) { 
    29         std::wcin >> s; 
     30        std::wstring s; 
     31        std::getline(std::wcin, s); 
    3032        if (s == _T("exit")) { 
    3133          std::wcout << _T("Exiting...") << std::endl; 
     
    4042            std::wcout << *cit << _T(": ") << core_->describeCommand(*cit) << std::endl; 
    4143          std::wcout << _T("Listing commands...Done") << std::endl; 
    42         } else if (s == _T("off") && buff == _T("debug ")) { 
     44        } else if (s == _T("debug off")) { 
    4345          std::wcout << _T("Setting debug log off...") << std::endl; 
    4446          core_->enableDebug(false); 
    45         } else if (s == _T("on") && buff == _T("debug ")) { 
     47        } else if (s == _T("debug on")) { 
    4648          std::wcout << _T("Setting debug log on...") << std::endl; 
    4749          core_->enableDebug(true); 
     
    5153        } else if (s == _T("assert")) { 
    5254          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, ' '); 
    5657          std::wstring msg, perf; 
    5758          NSCAPI::nagiosReturn ret = core_->inject(t.first, t.second, msg, perf); 
     
    5960            std::wcout << _T("No handler for command: ") << t.first << std::endl; 
    6061          } 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; 
    6364            if (!perf.empty()) 
    6465              std::cout << "|" << strEx::wstring_to_string(perf); 
    6566            std::wcout << std::endl; 
    6667          } 
    67           buff = _T(""); 
    68         } else { 
    69           buff += s + _T(" "); 
    7068        } 
    7169      } 
Note: See TracChangeset for help on using the changeset viewer.