Changeset d05c3f0 in nscp for service


Ignore:
Timestamp:
11/15/09 17:20:03 (4 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
92c4b5b
Parents:
3eedfa6
Message:

Next major "milestone" we now have one working plugin (CheckHelpers) which loads and works both on Linux and Windows.
This is (as always) a broken build which many many features disabled and non functional...

Location:
service
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • service/CMakeLists.txt

    r3eedfa6 rd05c3f0  
    11cmake_minimum_required(VERSION 2.6) 
    2    
    3 PROJECT(NSCP) 
    4 #SET(CMAKE_MODULE_PATH ${NSCP_SOURCE_DIR}) 
    52 
    6 SET(VERSION_SERIES 0) 
    7 SET(VERSION_MAJOR 4) 
    8 SET(VERSION_MINOR 0) 
    9  
    10 IF(NOT SHARED_LIBS) 
    11   IF(WIN32) 
    12     OPTION(SHARED_LIBS "Compile shared libraries" OFF) 
    13   ELSE(WIN32) 
    14     OPTION(SHARED_LIBS "Compile shared libraries" ON) 
    15   ENDIF(WIN32) 
    16 ENDIF(NOT SHARED_LIBS) 
    17  
    18 IF(NOT SHARED_LIBS) 
    19   SET(NSCP_STATIC true) 
    20 ENDIF(NOT SHARED_LIBS) 
    21  
    22 IF(NOT MULTI_THREADED) 
    23   OPTION(MULTI_THREADED "Build multi-threaded httpd deamon (if possible)" ON) 
    24 ENDIF(NOT MULTI_THREADED) 
    25  
    26 SET(BUILD_SHARED_LIBS ${SHARED_LIBS}) 
    27  
    28 SET(NSCP_LOCAL_INCLUDE_PATH "${PROJECT_BINARY_DIR}/../include" CACHE PATH "directory containing NSCP specific includes") 
    29  
    30  
    31 set(Boost_USE_STATIC_LIBS   ON) 
    32 set(Boost_USE_MULTITHREADED ON) 
    33  
    34  
    35 IF(WIN32) 
    36   #SET(USERLIB_ROOT "c:/libraries" CACHE PATH "directory containing the dependency libraries") 
    37   SET(LIB_INSTALL_DIR "lib" CACHE STRING "Default path for libraries within ${CMAKE_INSTALL_PREFIX}") 
    38   SET(RUNDIR "c:/nscp" CACHE PATH "Not really used in WIN32") 
    39   #SET(CONFIGURATION c:/witty/wt_config.xml CACHE PATH "Path for the wt configuration file") 
    40   #SET(DEPLOYROOT c:/nscp/ CACHE PATH "Path to deploy examples into") 
    41   #SET(BOOST_DIR ${USERLIB_ROOT} CACHE PATH "Use boost in directory") 
    42   SET(BOOST_LIBRARYDIR c:/src/lib/x86 CACHE PATH "") 
    43   SET(BOOST_INCLUDEDIR c:/src/include/boost-1_39 CACHE PATH "") 
    44    
    45   SET(BOOST_LIB_PREFIX lib CACHE STRING "Look for Boost libraries prefixed with this") 
    46   SET(BOOST_LIB_SUFFIX vc80-mt CACHE STRING "Look for Boost libraries ending with this") 
    47  
    48   #SET(BOOST_VERSION "1_34_1" CACHE STRING "Use boost version in BOOST_DIR") 
    49   #OPTION(BOOST_DYNAMIC "Link to boost DLLs (OFF means static link)" OFF) 
    50  
    51 ELSE(WIN32) 
    52  
    53   SET(USERLIB_ROOT /usr CACHE PATH "Other installation prefix for dependent libraries") 
    54   SET(LIB_INSTALL_DIR "lib" CACHE STRING "Default path for libraries within ${CMAKE_INSTALL_PREFIX}") 
    55   SET(RUNDIR "/usr/wt/run" CACHE PATH "Default path for wt session management (only used by FCGI connector; not relative to CMAKE_INSTALL_PREFIX)") 
    56   SET(CONFIGURATION /etc/nscp/boot.ini CACHE PATH "Path to the boot configuration file") 
    57   SET(MAIN_CONFIGURATION /etc/nscp/nscp.xml CACHE PATH "Path for the client configurtion file") 
    58   SET(DEPLOYROOT /usr/bin CACHE PATH "Path to deploy examples into)") 
    59   SET(BOOST_DIR /usr CACHE PATH "Boost installation path prefix") 
    60   SET(BOOST_COMPILER gcc CACHE STRING "Boost libraries compiler signature") 
    61   SET(BOOST_VERSION "1_34_1" CACHE STRING "Boost libraries version signature") 
    62 ENDIF(WIN32) 
    63  
    64 #SET(CMAKE_MODULE_PATH "../cmake/") 
    65 FIND_PACKAGE(Boost COMPONENTS system filesystem thread REQUIRED) 
    66  
    67 #INCLUDE(../cmake/WtFindBoost.txt) 
    68 #INCLUDE(../cmake/WtFindAsio.txt) 
    69 INCLUDE(../cmake/WtFindSsl.txt) 
    70 #INCLUDE(../cmake/FindICU.cmake) 
    71  
    72 #IF(NOT WIN32) 
    73 # FIND_PACKAGE(ICU REQUIRED) 
    74 # IF(NOT ICU_FOUND) 
    75 #   MESSAGE(FATAL_ERROR "ICU package not found..") 
    76 # ELSE(NOT ICU_FOUND) 
    77 #   ADD_DEFINITIONS( -DSI_CONVERT_ICU ) 
    78 # ENDIF(NOT ICU_FOUND) 
    79 #ENDIF(NOT WIN32) 
    80  
    81 IF(NOT WIN32) 
    82   FIND_PACKAGE(Threads REQUIRED) 
    83   IF (NOT CMAKE_USE_PTHREADS_INIT) 
    84     message(FATAL_ERROR "Could not find POSIX threads") 
    85   ELSE (NOT CMAKE_USE_PTHREADS_INIT) 
    86     #add_definitions(-D_REENTRANT) 
    87   ENDIF (NOT CMAKE_USE_PTHREADS_INIT) 
    88   FIND_PACKAGE(Threads REQUIRED) 
    89 ENDIF(NOT WIN32) 
    90  
    91  
    92  
    93 # Boost is used nearly everywhere, so we can put these here 
     3PROJECT(service) 
    944INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIRS}) 
    955LINK_DIRECTORIES(${BOOST_LIB_DIRS}) 
    96 IF(WIN32) 
    97   IF(BOOST_DYNAMIC) 
    98     ADD_DEFINITIONS(-DBOOST_ALL_DYN_LINK) 
    99   ENDIF(BOOST_DYNAMIC) 
    100   set (EXTRA_LIBS ${EXTRA_LIBS} Userenv ole32) 
    101 ENDIF(WIN32) 
     6#INCLUDE_DIRECTORIES(${NSCP_INCLUDE_PATH}) 
    1027 
    103 IF(NOT CMAKE_BUILD_TYPE) 
    104   SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING 
    105       "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." 
    106       FORCE) 
    107 ENDIF(NOT CMAKE_BUILD_TYPE) 
     8ADD_DEFINITIONS(${NSCP_GLOBAL_DEFINES}) 
    1089 
    109 # Compile time constants & make sure our build finds it 
    110 CONFIGURE_FILE( 
    111   config.h.in 
    112   xconfig.h 
    113 ) 
    114 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) 
    115 INCLUDE_DIRECTORIES(${NSCP_LOCAL_INCLUDE_PATH}) 
    116 INSTALL_FILES(/include FILES ${WCONFIG_H_PATH}) 
    117  
    118 add_definitions(-DUNICODE -D_UNICODE) 
    119  
    120 include_directories("${PROJECT_BINARY_DIR}") 
    121  
    122  
    123 add_executable (NSCP  
     10SET(service_SRCS 
    12411  NSClient++.cpp 
    12512  NSCPlugin.cpp 
    12613  core_api.cpp 
    12714  settings_manager_impl.cpp 
    128   ../include/NSCHelper.cpp 
    129   ../include/arrayBuffer.cpp 
    130   ../include/simpleini/ConvertUTF.c 
    131 # ../include/ServiceCmd.cpp 
    132   ../include/b64/b64.c 
     15  ${NSCP_INCLUDE_PATH}/NSCHelper.cpp 
     16  ${NSCP_INCLUDE_PATH}/arrayBuffer.cpp 
     17  ${NSCP_INCLUDE_PATH}/simpleini/ConvertUTF.c 
     18  ${NSCP_INCLUDE_PATH}/b64/b64.c 
    13319) 
    13420 
    135 target_link_libraries(NSCP  
     21IF(WIN32) 
     22  SET(service_SRCS ${service_SRCS} 
     23    ${NSCP_INCLUDE_PATH}/ServiceCmd.cpp 
     24  ) 
     25  SET(service_SRCS ${service_SRCS} 
     26    ${NSCP_INCLUDE_PATH}/settings/Settings.h 
     27    ${NSCP_INCLUDE_PATH}/charEx.h 
     28    ${NSCP_INCLUDE_PATH}/config.h 
     29    ${NSCP_INCLUDE_PATH}/msvc_wrappers.h 
     30    ${NSCP_INCLUDE_PATH}/settings/macros.h 
     31    ${NSCP_INCLUDE_PATH}/settings/settings_ini.hpp 
     32    ${NSCP_INCLUDE_PATH}/settings/settings_old.hpp 
     33    ${NSCP_INCLUDE_PATH}/settings/settings_registry.hpp 
     34    ${NSCP_INCLUDE_PATH}/settings/Settings.h 
     35    ${NSCP_INCLUDE_PATH}/NSCHelper.h 
     36    ${NSCP_INCLUDE_PATH}/com_helpers.hpp 
     37    ${NSCP_INCLUDE_PATH}/dll/dll.hpp 
     38    ${NSCP_INCLUDE_PATH}/dll/impl_unix.hpp 
     39    ${NSCP_INCLUDE_PATH}/dll/impl_w32.hpp 
     40    core_api.h 
     41    settings_manager_impl.h 
     42  ) 
     43  ADD_DEFINITIONS(-D_WIN32_DCOM) 
     44 
     45ENDIF(WIN32) 
     46 
     47add_executable (nsclient++ ${service_SRCS}) 
     48 
     49target_link_libraries(nsclient++  
    13650  ${Boost_FILESYSTEM_LIBRARY} 
    13751  ${Boost_LIBRARIES} 
     
    14054) 
    14155 
    142  
    143  
    144  
    14556INSTALL(FILES ${PROJECT_SOURCE_DIR}/cmake/FindWt.cmake DESTINATION 
    14657    ${CMAKE_INSTALL_PREFIX}/${WT_CMAKE_FINDER_INSTALL_DIR} ) 
  • service/NSCPlugin.cpp

    r818b54e rd05c3f0  
    2020***************************************************************************/ 
    2121#include "StdAfx.h" 
    22 #include "NSClient++.h" 
    23 #include <error.hpp> 
     22#include "NSCPlugin.h" 
    2423#include "core_api.h" 
    2524/** 
     
    3029 * @param file The file (DLL) to load as a NSC plug in. 
    3130 */ 
    32 NSCPlugin::NSCPlugin(const std::wstring file) 
    33   : module_(file) 
     31NSCPlugin::NSCPlugin(const boost::filesystem::wpath file) 
     32  : module_(file.string()) 
    3433  ,fLoadModule(NULL) 
    3534  ,fGetName(NULL) 
     
    4847  ,broken_(false) 
    4948{ 
     49 
    5050} 
    5151/* 
     
    305305void NSCPlugin::loadRemoteProcs_(void) { 
    306306 
    307   fLoadModule = (lpLoadModule)module_.load_proc("NSLoadModule"); 
    308   if (!fLoadModule) 
    309     throw NSPluginException(module_, _T("Could not load NSLoadModule")); 
    310  
    311   fModuleHelperInit = (lpModuleHelperInit)module_.load_proc("NSModuleHelperInit"); 
    312   if (!fModuleHelperInit) 
    313     throw NSPluginException(module_, _T("Could not load NSModuleHelperInit")); 
    314  
    315   try { 
    316     fModuleHelperInit(NSAPILoader); 
    317   } catch (...) { 
    318     throw NSPluginException(module_, _T("Unhandled exception in getDescription.")); 
    319   } 
    320    
    321   fGetName = (lpGetName)module_.load_proc("NSGetModuleName"); 
    322   if (!fGetName) 
    323     throw NSPluginException(module_, _T("Could not load NSGetModuleName")); 
    324  
    325   fGetVersion = (lpGetVersion)module_.load_proc("NSGetModuleVersion"); 
    326   if (!fGetVersion) 
    327     throw NSPluginException(module_, _T("Could not load NSGetModuleVersion")); 
    328  
    329   fGetDescription = (lpGetDescription)module_.load_proc("NSGetModuleDescription"); 
    330   if (!fGetDescription) 
    331     throw NSPluginException(module_, _T("Could not load NSGetModuleDescription")); 
    332  
    333   fHasCommandHandler = (lpHasCommandHandler)module_.load_proc("NSHasCommandHandler"); 
    334   if (!fHasCommandHandler) 
    335     throw NSPluginException(module_, _T("Could not load NSHasCommandHandler")); 
    336  
    337   fHasMessageHandler = (lpHasMessageHandler)module_.load_proc("NSHasMessageHandler"); 
    338   if (!fHasMessageHandler) 
    339     throw NSPluginException(module_, _T("Could not load NSHasMessageHandler")); 
    340  
    341   fHandleCommand = (lpHandleCommand)module_.load_proc("NSHandleCommand"); 
    342   if (!fHandleCommand) 
    343     throw NSPluginException(module_, _T("Could not load NSHandleCommand")); 
    344  
    345   fHandleMessage = (lpHandleMessage)module_.load_proc("NSHandleMessage"); 
    346   if (!fHandleMessage) 
    347     throw NSPluginException(module_, _T("Could not load NSHandleMessage")); 
    348  
    349   fUnLoadModule = (lpUnLoadModule)module_.load_proc("NSUnloadModule"); 
    350   if (!fUnLoadModule) 
    351     throw NSPluginException(module_, _T("Could not load NSUnloadModule")); 
    352  
    353   fGetConfigurationMeta = (lpGetConfigurationMeta)module_.load_proc("NSGetConfigurationMeta"); 
    354   fCommandLineExec = (lpCommandLineExec)module_.load_proc("NSCommandLineExec"); 
    355  
    356   fShowTray = (lpShowTray)module_.load_proc("ShowIcon"); 
    357   fHideTray = (lpHideTray)module_.load_proc("HideIcon"); 
     307  try { 
     308    fLoadModule = (lpLoadModule)module_.load_proc("NSLoadModule"); 
     309    if (!fLoadModule) 
     310      throw NSPluginException(module_, _T("Could not load NSLoadModule")); 
     311 
     312    fModuleHelperInit = (lpModuleHelperInit)module_.load_proc("NSModuleHelperInit"); 
     313    if (!fModuleHelperInit) 
     314      throw NSPluginException(module_, _T("Could not load NSModuleHelperInit")); 
     315 
     316    try { 
     317      fModuleHelperInit(NSAPILoader); 
     318    } catch (...) { 
     319      throw NSPluginException(module_, _T("Unhandled exception in getDescription.")); 
     320    } 
     321 
     322    fGetName = (lpGetName)module_.load_proc("NSGetModuleName"); 
     323    if (!fGetName) 
     324      throw NSPluginException(module_, _T("Could not load NSGetModuleName")); 
     325 
     326    fGetVersion = (lpGetVersion)module_.load_proc("NSGetModuleVersion"); 
     327    if (!fGetVersion) 
     328      throw NSPluginException(module_, _T("Could not load NSGetModuleVersion")); 
     329 
     330    fGetDescription = (lpGetDescription)module_.load_proc("NSGetModuleDescription"); 
     331    if (!fGetDescription) 
     332      throw NSPluginException(module_, _T("Could not load NSGetModuleDescription")); 
     333 
     334    fHasCommandHandler = (lpHasCommandHandler)module_.load_proc("NSHasCommandHandler"); 
     335    if (!fHasCommandHandler) 
     336      throw NSPluginException(module_, _T("Could not load NSHasCommandHandler")); 
     337 
     338    fHasMessageHandler = (lpHasMessageHandler)module_.load_proc("NSHasMessageHandler"); 
     339    if (!fHasMessageHandler) 
     340      throw NSPluginException(module_, _T("Could not load NSHasMessageHandler")); 
     341 
     342    fHandleCommand = (lpHandleCommand)module_.load_proc("NSHandleCommand"); 
     343    if (!fHandleCommand) 
     344      throw NSPluginException(module_, _T("Could not load NSHandleCommand")); 
     345 
     346    fHandleMessage = (lpHandleMessage)module_.load_proc("NSHandleMessage"); 
     347    if (!fHandleMessage) 
     348      throw NSPluginException(module_, _T("Could not load NSHandleMessage")); 
     349 
     350    fUnLoadModule = (lpUnLoadModule)module_.load_proc("NSUnloadModule"); 
     351    if (!fUnLoadModule) 
     352      throw NSPluginException(module_, _T("Could not load NSUnloadModule")); 
     353 
     354    fGetConfigurationMeta = (lpGetConfigurationMeta)module_.load_proc("NSGetConfigurationMeta"); 
     355    fCommandLineExec = (lpCommandLineExec)module_.load_proc("NSCommandLineExec"); 
     356 
     357    fShowTray = (lpShowTray)module_.load_proc("ShowIcon"); 
     358    fHideTray = (lpHideTray)module_.load_proc("HideIcon"); 
     359  } catch (dll::dll_exception &e) { 
     360    throw NSPluginException(module_, _T("Unhandled exception when loading proces: ") + e.what()); 
     361  } 
    358362 
    359363} 
  • service/NSCPlugin.h

    r818b54e rd05c3f0  
    141141 
    142142public: 
    143   NSCPlugin(const std::wstring file); 
     143  NSCPlugin(const boost::filesystem::wpath file); 
    144144  NSCPlugin(NSCPlugin &other); 
    145145  virtual ~NSCPlugin(void); 
  • service/NSClient++.cpp

    r818b54e rd05c3f0  
    8484 
    8585  static bool start(unsigned long  dwSessionId) { 
    86     std::wstring program = mainClient.getBasePath() +  _T("\\") +  
    87       SETTINGS_GET_STRING_CORE(settings_def::SYSTRAY_EXE); 
    88     std::wstring cmdln = _T("\"") + program + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 
    89     return tray_starter::startTrayHelper(dwSessionId, program, cmdln); 
     86    boost::filesystem::wpath program = mainClient.getBasePath() / SETTINGS_GET_STRING_CORE(settings_def::SYSTRAY_EXE); 
     87    std::wstring cmdln = _T("\"") + program.string() + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 
     88    return tray_starter::startTrayHelper(dwSessionId, program.string(), cmdln); 
    9089  } 
    9190 
     
    205204 
    206205 
    207 bool is_module( std::wstring file )  
     206bool is_module(boost::filesystem::wpath file )  
    208207{ 
    209   return boost::ends_with(file, _T(".dll")); 
     208  return boost::ends_with(file.string(), _T(".dll")) || boost::ends_with(file.string(), _T(".so")); 
    210209} 
    211210/** 
     
    390389      return 0; 
    391390    } else if ( wcscasecmp( _T("about"), argv[1]+1 ) == 0 ) { 
    392       g_bConsoleLog = true; 
    393       LOG_MESSAGE(SZAPPNAME _T(" (C) Michael Medin - michael<at>medin<dot>name")); 
    394       LOG_MESSAGE(_T("Version: ") SZVERSION); 
    395       LOG_MESSAGE(_T("Architecture: ") SZARCH); 
    396  
    397       std::wstring pluginPath = mainClient.getBasePath() + _T("modules\\"); 
    398       LOG_MESSAGE_STD(_T("Looking at plugins in: ") + pluginPath); 
    399  
    400       boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 
    401       for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 
    402         if ( !is_directory(itr->status()) ) { 
    403           std::wstring file= itr->leaf(); 
    404           if (is_module(pluginPath + _T("\\") + file)) { 
    405             NSCPlugin *plugin = new NSCPlugin(pluginPath + _T("\\") + file); 
    406             std::wstring name = _T("<unknown>"); 
    407             std::wstring description = _T("<unknown>"); 
    408             try { 
    409               plugin->load_dll(); 
    410               name = plugin->getName(); 
    411               description = plugin->getDescription(); 
    412             } catch(const NSPluginException& e) { 
    413               LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 
    414             } catch (std::exception e) { 
    415               LOG_ERROR_STD(_T("exception loading plugin: ") + strEx::string_to_wstring(e.what())); 
    416             } catch (...) { 
    417               LOG_ERROR_STD(_T("Unknown exception loading plugin")); 
    418             } 
    419             LOG_MESSAGE_STD(_T("* ") + name + _T(" (") + file + _T(")")); 
    420             std::list<std::wstring> list = strEx::splitEx(description, _T("\n")); 
    421             for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 
    422               LOG_MESSAGE_STD(_T("    ") + *cit); 
     391      try { 
     392        g_bConsoleLog = true; 
     393        LOG_MESSAGE(SZAPPNAME _T(" (C) Michael Medin - michael<at>medin<dot>name")); 
     394        LOG_MESSAGE(_T("Version: ") SZVERSION); 
     395        LOG_MESSAGE(_T("Architecture: ") SZARCH); 
     396 
     397        boost::filesystem::wpath pluginPath = (boost::filesystem::wpath)mainClient.getBasePath() / _T("modules"); 
     398        LOG_MESSAGE_STD(_T("Looking at plugins in: ") + pluginPath.string()); 
     399 
     400        boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 
     401        for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 
     402          if ( !is_directory(itr->status()) ) { 
     403            std::wstring file= itr->leaf(); 
     404            LOG_MESSAGE_STD(_T("Found: ") + file); 
     405            if (is_module(pluginPath / file)) { 
     406              NSCPlugin *plugin = new NSCPlugin(pluginPath / file); 
     407              std::wstring name = _T("<unknown>"); 
     408              std::wstring description = _T("<unknown>"); 
     409              try { 
     410                plugin->load_dll(); 
     411                name = plugin->getName(); 
     412                description = plugin->getDescription(); 
     413              } catch(const NSPluginException& e) { 
     414                LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 
     415              } catch (std::exception e) { 
     416                LOG_ERROR_STD(_T("exception loading plugin: ") + strEx::string_to_wstring(e.what())); 
     417              } catch (...) { 
     418                LOG_ERROR_STD(_T("Unknown exception loading plugin")); 
     419              } 
     420              LOG_MESSAGE_STD(_T("* ") + name + _T(" (") + file + _T(")")); 
     421              std::list<std::wstring> list = strEx::splitEx(description, _T("\n")); 
     422              for (std::list<std::wstring>::const_iterator cit = list.begin(); cit != list.end(); ++cit) { 
     423                LOG_MESSAGE_STD(_T("    ") + *cit); 
     424              } 
    423425            } 
    424426          } 
    425427        } 
     428        LOG_MESSAGE_STD(_T("Done listing plugins from: ") + pluginPath.string()); 
     429        return true; 
     430      } catch (std::exception &e) { 
     431        LOG_ERROR_STD(_T("Exception: ") + to_wstring(e.what())); 
     432      } catch (...) { 
     433        LOG_ERROR_STD(_T("Unknown Exception: ")); 
    426434      } 
    427435      return false; 
     
    568576NSClientT::plugin_info_list NSClientT::get_all_plugins() { 
    569577  plugin_info_list ret; 
    570   std::wstring pluginPath = getBasePath() + _T("modules\\"); 
     578  boost::filesystem::wpath pluginPath = getBasePath() / boost::filesystem::wpath(_T("modules")); 
    571579  boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 
    572580  for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 
    573581    if ( !is_directory(itr->status()) ) { 
    574       std::wstring file= itr->leaf(); 
    575       if (is_module(pluginPath + _T("\\") + file)) { 
     582      boost::filesystem::wpath file= itr->leaf(); 
     583      if (is_module(pluginPath  / file)) { 
    576584        plugin_info_type info; 
    577585        info.dll = itr->leaf(); 
    578586        try { 
    579           LOG_DEBUG_STD(_T("Attempting to fake load: ") + file); 
    580           NSCPlugin plugin(pluginPath + _T("\\") + file); 
     587          LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 
     588          NSCPlugin plugin(pluginPath / file); 
    581589          plugin.load_dll(); 
    582590          plugin.load_plugin(NSCAPI::dontStart); 
     
    587595          LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 
    588596        } catch (...) { 
    589           LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file); 
     597          LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 
    590598        } 
    591599        ret.push_back(info); 
     
    598606 
    599607void NSClientT::load_all_plugins(int mode) { 
    600   std::wstring modPath = getBasePath() + _T("modules\\"); 
     608  boost::filesystem::wpath modPath = getBasePath() / boost::filesystem::wpath(_T("modules")); 
    601609 
    602610  boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 
    603611  for ( boost::filesystem::wdirectory_iterator itr( modPath ); itr != end_itr; ++itr ) { 
    604612    if ( !is_directory(itr->status()) ) { 
    605       std::wstring file= itr->leaf(); 
    606       if (is_module(modPath + _T("\\") + file)) { 
    607         if (settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, file)) { 
    608           if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file) == _T("disabled")) { 
     613      boost::filesystem::wpath file= itr->leaf(); 
     614      if (is_module(modPath / file)) { 
     615        if (settings_manager::get_settings()->has_key(MAIN_MODULES_SECTION, file.string())) { 
     616          if (settings_manager::get_settings()->get_string(MAIN_MODULES_SECTION, file.string()) == _T("disabled")) { 
    609617            try { 
    610               LOG_DEBUG_STD(_T("Attempting to fake load: ") + file); 
    611               NSCPlugin plugin(modPath + file); 
     618              LOG_DEBUG_STD(_T("Attempting to fake load: ") + file.string()); 
     619              NSCPlugin plugin(modPath / file); 
    612620              plugin.load_dll(); 
    613621              plugin.load_plugin(mode); 
     
    616624              LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 
    617625            } catch (...) { 
    618               LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file); 
     626              LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 
    619627            } 
    620628          } 
     
    622630          std::wstring desc; 
    623631          try { 
    624             NSCPlugin plugin(modPath + file); 
     632            NSCPlugin plugin(modPath / file); 
    625633            plugin.load_dll(); 
    626634            plugin.load_plugin(mode); 
     
    633641          } catch (...) { 
    634642            desc += _T("unknown module"); 
    635             LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file); 
     643            LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 
    636644          } 
    637           settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, file, Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false); 
     645          settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, file.string(), Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false); 
    638646        } 
    639647      } 
     
    846854        } 
    847855        try { 
    848           loadPlugin(getBasePath() + _T("modules\\") + (*cit)); 
     856          loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(*cit)); 
    849857        } catch(const NSPluginException& e) { 
    850           LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 
     858          LOG_ERROR_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); 
    851859          //return false; 
    852860        } catch (std::exception e) { 
     
    10681076  } 
    10691077  try { 
    1070     plugin_type plugin = loadPlugin(getBasePath() + _T("modules\\") + module); 
    1071     LOG_DEBUG_STD(_T("Loading plugin: ") + plugin->getName() + _T("...")); 
    1072     plugin->load_plugin(NSCAPI::dontStart); 
    1073     return plugin->commandLineExec(command, argLen, args); 
    1074   } catch (NSPluginException e) { 
    1075     LOG_MESSAGE_STD(_T("Module (") + e.file_ + _T(") was not found: ") + e.error_); 
    1076   } 
    1077   try { 
    1078     plugin_type plugin = loadPlugin(getBasePath() + _T("modules\\") + module + _T(".dll")); 
     1078    plugin_type plugin = loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(module)); 
    10791079    LOG_DEBUG_STD(_T("Loading plugin: ") + plugin->getName() + _T("...")); 
    10801080    plugin->load_plugin(NSCAPI::dontStart); 
     
    12081208 * @param file The DLL file 
    12091209 */ 
    1210 NSClientT::plugin_type NSClientT::loadPlugin(const std::wstring file) { 
     1210NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file) { 
    12111211  return addPlugin(new NSCPlugin(file)); 
    12121212} 
     
    15221522  } 
    15231523} 
    1524 std::wstring NSClientT::getBasePath(void) { 
     1524boost::filesystem::wpath NSClientT::getBasePath(void) { 
    15251525  boost::unique_lock<boost::timed_mutex> lock(internalVariables, boost::get_system_time() + boost::posix_time::seconds(5)); 
    15261526  if (!lock.owns_lock()) { 
     
    15381538  basePath = path.substr(0, pos) + _T("\\"); 
    15391539  delete [] buffer; 
     1540#else  
     1541  basePath = to_wstring(boost::filesystem::initial_path().string()); 
    15401542#endif 
    15411543  try { 
  • service/NSClient++.h

    r818b54e rd05c3f0  
    2020***************************************************************************/ 
    2121#pragma once 
     22#ifdef WIN32 
     23#include <com_helpers.hpp> 
     24#endif 
     25 
    2226#include <types.hpp> 
    2327#include <config.h> 
    2428#include <service/system_service.hpp> 
    2529#include "NSCPlugin.h" 
    26 //#include <Mutex.h> 
    27 #include <NSCAPI.h> 
    28 //#include <MutexRW.h> 
    29 #include <map> 
    30 #ifdef WIN32 
    31 #include <com_helpers.hpp> 
    32 #endif 
    3330//#include <nsclient_session.hpp> 
    34 #include <boost/thread/thread.hpp> 
    35 #include <boost/thread/locks.hpp> 
    36 #include <boost/thread/shared_mutex.hpp> 
    3731 
    3832/** 
     
    10195  pluginList commandHandlers_; 
    10296  pluginList messageHandlers_; 
    103   std::wstring basePath; 
     97  boost::filesystem::wpath basePath; 
    10498  boost::timed_mutex internalVariables; 
    10599  boost::timed_mutex messageMutex; 
     
    145139 
    146140  // Member functions 
    147   std::wstring getBasePath(void); 
     141  boost::filesystem::wpath getBasePath(void); 
    148142  NSCAPI::nagiosReturn injectRAW(const wchar_t* command, const unsigned int argLen, wchar_t **argument, wchar_t *returnMessageBuffer, unsigned int returnMessageBufferLen, wchar_t *returnPerfBuffer, unsigned int returnPerfBufferLen); 
    149143  NSCAPI::nagiosReturn inject(std::wstring command, std::wstring arguments, wchar_t splitter, bool escape, std::wstring &msg, std::wstring & perf); 
     
    154148 
    155149  void addPlugins(const std::list<std::wstring> plugins); 
    156   plugin_type loadPlugin(const std::wstring plugin); 
     150  plugin_type loadPlugin(const boost::filesystem::wpath plugin); 
    157151  void loadPlugins(NSCAPI::moduleLoadMode mode); 
    158152  void unloadPlugins(bool unloadLoggers); 
  • service/StdAfx.h

    r818b54e rd05c3f0  
    2121#pragma once 
    2222#include <types.hpp> 
    23  
     23/* 
    2424#ifdef WIN32 
    2525#define _WINSOCKAPI_ 
    26 //#include <WinSock2.h> 
    2726#include <tchar.h> 
    28  
    29 #define _WIN32_DCOM 
    30 #include <objbase.h> 
    31  
    3227#define VC_EXTRALEAN    // Exclude rarely-used stuff from Windows headers 
    3328#include <windows.h> 
     
    3732#define WANT_GETLONGPATHNAME_WRAPPER 
    3833//#include <NewAPIs.h> 
    39  
     34*/ 
    4035#include <iostream> 
    4136#include <string> 
     
    4338#include <sstream> 
    4439#include <vector> 
     40#include <memory> 
     41#include <map> 
    4542 
    4643#include "config.h" 
    4744#include <Singleton.h> 
    4845#include <charEx.h> 
    49 #include <memory> 
     46#include <error.hpp> 
     47#include <NSCAPI.h> 
    5048 
     49#include <boost/thread/thread.hpp> 
     50#include <boost/thread/locks.hpp> 
     51#include <boost/thread/shared_mutex.hpp> 
    5152#include <boost/algorithm/string.hpp> 
    5253#include <boost/filesystem.hpp> 
    53  
    54 #ifdef MEMCHECK 
    55 #include <vld.h> 
    56 #endif 
  • service/core_api.cpp

    r818b54e rd05c3f0  
    4949} 
    5050NSCAPI::errorReturn NSAPIGetBasePath(wchar_t*buffer, unsigned int bufLen) { 
    51   return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.getBasePath(), NSCAPI::isSuccess); 
     51  return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.getBasePath().string(), NSCAPI::isSuccess); 
    5252} 
    5353NSCAPI::errorReturn NSAPIGetApplicationName(wchar_t*buffer, unsigned int bufLen) { 
  • service/settings_manager_impl.cpp

    r818b54e rd05c3f0  
    1818    SettingsHandler::destroyInstance(); 
    1919  } 
    20   bool init_settings(std::wstring path) { 
     20  bool init_settings(boost::filesystem::wpath path) { 
    2121    try { 
    2222      get_core()->set_logger(new settings_logger()); 
  • service/settings_manager_impl.h

    r818b54e rd05c3f0  
    33#include "settings_logger_impl.hpp" 
    44#include <settings/Settings.h> 
     5#include <settings/settings_ini.hpp> 
    56#ifdef WIN32 
    6 #include <settings/settings_ini.hpp> 
    77#include <settings/settings_old.hpp> 
    88#include <settings/settings_registry.hpp> 
     
    1212  class NSCSettingsImpl : public Settings::SettingsHandlerImpl { 
    1313  private: 
    14     std::wstring boot_; 
     14    boost::filesystem::wpath boot_; 
    1515    bool old_; 
    1616  public: 
     
    2828#ifdef WIN32 
    2929      wchar_t* buffer = new wchar_t[1024]; 
    30       GetPrivateProfileString(section.c_str(), key.c_str(), def.c_str(), buffer, 1023, boot_.c_str()); 
     30      GetPrivateProfileString(section.c_str(), key.c_str(), def.c_str(), buffer, 1023, boot_.string().c_str()); 
    3131      std::wstring ret = buffer; 
    3232      delete [] buffer; 
    3333      return ret; 
    3434#else 
    35       return _T("ini"); 
     35      return def; 
    3636#endif 
    3737    } 
     
    4343    /// @author mickem 
    4444    void boot(std::wstring file = _T("boot.ini")) { 
    45       boot_ = get_base() + _T("\\") + file; 
     45      boot_ = get_base() / file; 
     46#ifdef WIN32 
    4647      std::wstring subsystem = get_boot_string(_T("settings"), _T("type"), _T("old")); 
    47       get_logger()->debug(__FILEW__, __LINE__, _T("Trying to boot: ") + subsystem + _T(" from base: ") + boot_); 
     48#else 
     49      std::wstring subsystem = get_boot_string(_T("settings"), _T("type"), _T("ini")); 
     50#endif 
     51      get_logger()->debug(__FILEW__, __LINE__, _T("Trying to boot: ") + subsystem + _T(" from base: ") + boot_.string()); 
    4852      settings_type type = string_to_type(subsystem); 
    4953      std::wstring context = get_boot_string(_T("settings"), _T("context"), subsystem); 
     
    7276      if (type == SettingsCore::registry) 
    7377        return new Settings::REGSettings(this, context); 
     78#endif 
    7479      if (type == SettingsCore::ini_file) 
    7580        return new Settings::INISettings(this, context); 
    76 #endif 
    7781      throw SettingsException(_T("Undefined settings type: ") + SettingsCore::type_to_string(type)); 
    7882    } 
     
    8690  Settings::SettingsCore* get_core(); 
    8791  void destroy_settings(); 
    88   bool init_settings(std::wstring path); 
     92  bool init_settings(boost::filesystem::wpath path); 
    8993} 
Note: See TracChangeset for help on using the changeset viewer.