- Timestamp:
- 11/15/09 17:20:03 (4 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 92c4b5b
- Parents:
- 3eedfa6
- Location:
- service
- Files:
-
- 9 edited
-
CMakeLists.txt (modified) (2 diffs)
-
NSCPlugin.cpp (modified) (4 diffs)
-
NSCPlugin.h (modified) (1 diff)
-
NSClient++.cpp (modified) (14 diffs)
-
NSClient++.h (modified) (4 diffs)
-
StdAfx.h (modified) (3 diffs)
-
core_api.cpp (modified) (1 diff)
-
settings_manager_impl.cpp (modified) (1 diff)
-
settings_manager_impl.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
service/CMakeLists.txt
r3eedfa6 rd05c3f0 1 1 cmake_minimum_required(VERSION 2.6) 2 3 PROJECT(NSCP)4 #SET(CMAKE_MODULE_PATH ${NSCP_SOURCE_DIR})5 2 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 3 PROJECT(service) 94 4 INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIRS}) 95 5 LINK_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}) 102 7 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) 8 ADD_DEFINITIONS(${NSCP_GLOBAL_DEFINES}) 108 9 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 10 SET(service_SRCS 124 11 NSClient++.cpp 125 12 NSCPlugin.cpp 126 13 core_api.cpp 127 14 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 133 19 ) 134 20 135 target_link_libraries(NSCP 21 IF(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 45 ENDIF(WIN32) 46 47 add_executable (nsclient++ ${service_SRCS}) 48 49 target_link_libraries(nsclient++ 136 50 ${Boost_FILESYSTEM_LIBRARY} 137 51 ${Boost_LIBRARIES} … … 140 54 ) 141 55 142 143 144 145 56 INSTALL(FILES ${PROJECT_SOURCE_DIR}/cmake/FindWt.cmake DESTINATION 146 57 ${CMAKE_INSTALL_PREFIX}/${WT_CMAKE_FINDER_INSTALL_DIR} ) -
service/NSCPlugin.cpp
r818b54e rd05c3f0 20 20 ***************************************************************************/ 21 21 #include "StdAfx.h" 22 #include "NSClient++.h" 23 #include <error.hpp> 22 #include "NSCPlugin.h" 24 23 #include "core_api.h" 25 24 /** … … 30 29 * @param file The file (DLL) to load as a NSC plug in. 31 30 */ 32 NSCPlugin::NSCPlugin(const std::wstringfile)33 : module_(file )31 NSCPlugin::NSCPlugin(const boost::filesystem::wpath file) 32 : module_(file.string()) 34 33 ,fLoadModule(NULL) 35 34 ,fGetName(NULL) … … 48 47 ,broken_(false) 49 48 { 49 50 50 } 51 51 /* … … 305 305 void NSCPlugin::loadRemoteProcs_(void) { 306 306 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 } 358 362 359 363 } -
service/NSCPlugin.h
r818b54e rd05c3f0 141 141 142 142 public: 143 NSCPlugin(const std::wstringfile);143 NSCPlugin(const boost::filesystem::wpath file); 144 144 NSCPlugin(NSCPlugin &other); 145 145 virtual ~NSCPlugin(void); -
service/NSClient++.cpp
r818b54e rd05c3f0 84 84 85 85 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); 90 89 } 91 90 … … 205 204 206 205 207 bool is_module( std::wstringfile )206 bool is_module(boost::filesystem::wpath file ) 208 207 { 209 return boost::ends_with(file , _T(".dll"));208 return boost::ends_with(file.string(), _T(".dll")) || boost::ends_with(file.string(), _T(".so")); 210 209 } 211 210 /** … … 390 389 return 0; 391 390 } 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 } 423 425 } 424 426 } 425 427 } 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: ")); 426 434 } 427 435 return false; … … 568 576 NSClientT::plugin_info_list NSClientT::get_all_plugins() { 569 577 plugin_info_list ret; 570 std::wstring pluginPath = getBasePath() + _T("modules\\");578 boost::filesystem::wpath pluginPath = getBasePath() / boost::filesystem::wpath(_T("modules")); 571 579 boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 572 580 for ( boost::filesystem::wdirectory_iterator itr( pluginPath ); itr != end_itr; ++itr ) { 573 581 if ( !is_directory(itr->status()) ) { 574 std::wstringfile= itr->leaf();575 if (is_module(pluginPath + _T("\\") +file)) {582 boost::filesystem::wpath file= itr->leaf(); 583 if (is_module(pluginPath / file)) { 576 584 plugin_info_type info; 577 585 info.dll = itr->leaf(); 578 586 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); 581 589 plugin.load_dll(); 582 590 plugin.load_plugin(NSCAPI::dontStart); … … 587 595 LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 588 596 } catch (...) { 589 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file );597 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 590 598 } 591 599 ret.push_back(info); … … 598 606 599 607 void NSClientT::load_all_plugins(int mode) { 600 std::wstring modPath = getBasePath() + _T("modules\\");608 boost::filesystem::wpath modPath = getBasePath() / boost::filesystem::wpath(_T("modules")); 601 609 602 610 boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 603 611 for ( boost::filesystem::wdirectory_iterator itr( modPath ); itr != end_itr; ++itr ) { 604 612 if ( !is_directory(itr->status()) ) { 605 std::wstringfile= 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")) { 609 617 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); 612 620 plugin.load_dll(); 613 621 plugin.load_plugin(mode); … … 616 624 LOG_CRITICAL_STD(_T("Error loading: ") + e.file_ + _T(" root cause: ") + e.error_); 617 625 } catch (...) { 618 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file );626 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 619 627 } 620 628 } … … 622 630 std::wstring desc; 623 631 try { 624 NSCPlugin plugin(modPath +file);632 NSCPlugin plugin(modPath / file); 625 633 plugin.load_dll(); 626 634 plugin.load_plugin(mode); … … 633 641 } catch (...) { 634 642 desc += _T("unknown module"); 635 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file );643 LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 636 644 } 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); 638 646 } 639 647 } … … 846 854 } 847 855 try { 848 loadPlugin(getBasePath() + _T("modules\\") +(*cit));856 loadPlugin(getBasePath() / boost::filesystem::wpath(_T("modules")) / boost::filesystem::wpath(*cit)); 849 857 } 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_); 851 859 //return false; 852 860 } catch (std::exception e) { … … 1068 1076 } 1069 1077 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)); 1079 1079 LOG_DEBUG_STD(_T("Loading plugin: ") + plugin->getName() + _T("...")); 1080 1080 plugin->load_plugin(NSCAPI::dontStart); … … 1208 1208 * @param file The DLL file 1209 1209 */ 1210 NSClientT::plugin_type NSClientT::loadPlugin(const std::wstringfile) {1210 NSClientT::plugin_type NSClientT::loadPlugin(const boost::filesystem::wpath file) { 1211 1211 return addPlugin(new NSCPlugin(file)); 1212 1212 } … … 1522 1522 } 1523 1523 } 1524 std::wstringNSClientT::getBasePath(void) {1524 boost::filesystem::wpath NSClientT::getBasePath(void) { 1525 1525 boost::unique_lock<boost::timed_mutex> lock(internalVariables, boost::get_system_time() + boost::posix_time::seconds(5)); 1526 1526 if (!lock.owns_lock()) { … … 1538 1538 basePath = path.substr(0, pos) + _T("\\"); 1539 1539 delete [] buffer; 1540 #else 1541 basePath = to_wstring(boost::filesystem::initial_path().string()); 1540 1542 #endif 1541 1543 try { -
service/NSClient++.h
r818b54e rd05c3f0 20 20 ***************************************************************************/ 21 21 #pragma once 22 #ifdef WIN32 23 #include <com_helpers.hpp> 24 #endif 25 22 26 #include <types.hpp> 23 27 #include <config.h> 24 28 #include <service/system_service.hpp> 25 29 #include "NSCPlugin.h" 26 //#include <Mutex.h>27 #include <NSCAPI.h>28 //#include <MutexRW.h>29 #include <map>30 #ifdef WIN3231 #include <com_helpers.hpp>32 #endif33 30 //#include <nsclient_session.hpp> 34 #include <boost/thread/thread.hpp>35 #include <boost/thread/locks.hpp>36 #include <boost/thread/shared_mutex.hpp>37 31 38 32 /** … … 101 95 pluginList commandHandlers_; 102 96 pluginList messageHandlers_; 103 std::wstringbasePath;97 boost::filesystem::wpath basePath; 104 98 boost::timed_mutex internalVariables; 105 99 boost::timed_mutex messageMutex; … … 145 139 146 140 // Member functions 147 std::wstringgetBasePath(void);141 boost::filesystem::wpath getBasePath(void); 148 142 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); 149 143 NSCAPI::nagiosReturn inject(std::wstring command, std::wstring arguments, wchar_t splitter, bool escape, std::wstring &msg, std::wstring & perf); … … 154 148 155 149 void addPlugins(const std::list<std::wstring> plugins); 156 plugin_type loadPlugin(const std::wstringplugin);150 plugin_type loadPlugin(const boost::filesystem::wpath plugin); 157 151 void loadPlugins(NSCAPI::moduleLoadMode mode); 158 152 void unloadPlugins(bool unloadLoggers); -
service/StdAfx.h
r818b54e rd05c3f0 21 21 #pragma once 22 22 #include <types.hpp> 23 23 /* 24 24 #ifdef WIN32 25 25 #define _WINSOCKAPI_ 26 //#include <WinSock2.h>27 26 #include <tchar.h> 28 29 #define _WIN32_DCOM30 #include <objbase.h>31 32 27 #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 33 28 #include <windows.h> … … 37 32 #define WANT_GETLONGPATHNAME_WRAPPER 38 33 //#include <NewAPIs.h> 39 34 */ 40 35 #include <iostream> 41 36 #include <string> … … 43 38 #include <sstream> 44 39 #include <vector> 40 #include <memory> 41 #include <map> 45 42 46 43 #include "config.h" 47 44 #include <Singleton.h> 48 45 #include <charEx.h> 49 #include <memory> 46 #include <error.hpp> 47 #include <NSCAPI.h> 50 48 49 #include <boost/thread/thread.hpp> 50 #include <boost/thread/locks.hpp> 51 #include <boost/thread/shared_mutex.hpp> 51 52 #include <boost/algorithm/string.hpp> 52 53 #include <boost/filesystem.hpp> 53 54 #ifdef MEMCHECK55 #include <vld.h>56 #endif -
service/core_api.cpp
r818b54e rd05c3f0 49 49 } 50 50 NSCAPI::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); 52 52 } 53 53 NSCAPI::errorReturn NSAPIGetApplicationName(wchar_t*buffer, unsigned int bufLen) { -
service/settings_manager_impl.cpp
r818b54e rd05c3f0 18 18 SettingsHandler::destroyInstance(); 19 19 } 20 bool init_settings( std::wstringpath) {20 bool init_settings(boost::filesystem::wpath path) { 21 21 try { 22 22 get_core()->set_logger(new settings_logger()); -
service/settings_manager_impl.h
r818b54e rd05c3f0 3 3 #include "settings_logger_impl.hpp" 4 4 #include <settings/Settings.h> 5 #include <settings/settings_ini.hpp> 5 6 #ifdef WIN32 6 #include <settings/settings_ini.hpp>7 7 #include <settings/settings_old.hpp> 8 8 #include <settings/settings_registry.hpp> … … 12 12 class NSCSettingsImpl : public Settings::SettingsHandlerImpl { 13 13 private: 14 std::wstringboot_;14 boost::filesystem::wpath boot_; 15 15 bool old_; 16 16 public: … … 28 28 #ifdef WIN32 29 29 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()); 31 31 std::wstring ret = buffer; 32 32 delete [] buffer; 33 33 return ret; 34 34 #else 35 return _T("ini");35 return def; 36 36 #endif 37 37 } … … 43 43 /// @author mickem 44 44 void boot(std::wstring file = _T("boot.ini")) { 45 boot_ = get_base() + _T("\\") + file; 45 boot_ = get_base() / file; 46 #ifdef WIN32 46 47 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()); 48 52 settings_type type = string_to_type(subsystem); 49 53 std::wstring context = get_boot_string(_T("settings"), _T("context"), subsystem); … … 72 76 if (type == SettingsCore::registry) 73 77 return new Settings::REGSettings(this, context); 78 #endif 74 79 if (type == SettingsCore::ini_file) 75 80 return new Settings::INISettings(this, context); 76 #endif77 81 throw SettingsException(_T("Undefined settings type: ") + SettingsCore::type_to_string(type)); 78 82 } … … 86 90 Settings::SettingsCore* get_core(); 87 91 void destroy_settings(); 88 bool init_settings( std::wstringpath);92 bool init_settings(boost::filesystem::wpath path); 89 93 }
Note: See TracChangeset
for help on using the changeset viewer.








