Changeset 216
- Timestamp:
- 11/15/09 17:20:03 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 25 edited
-
CMakeLists.txt (added)
-
include/NSCHelper.cpp (modified) (1 diff)
-
include/NSCHelper.h (modified) (1 diff)
-
include/arrayBuffer.cpp (modified) (1 diff)
-
include/charEx.h (modified) (1 diff)
-
include/com_helpers.hpp (modified) (1 diff)
-
include/dll/impl_unix.hpp (modified) (1 diff)
-
include/dll/impl_w32.hpp (modified) (2 diffs)
-
include/error_impl_unix.hpp (modified) (2 diffs)
-
include/nsc_module_wrapper.hpp (modified) (1 diff)
-
include/settings/Settings.h (modified) (6 diffs)
-
include/settings/settings_ini.hpp (modified) (5 diffs)
-
include/settings/settings_old.hpp (modified) (2 diffs)
-
include/strEx.h (modified) (5 diffs)
-
include/types.hpp (modified) (2 diffs)
-
modules/CheckHelpers/CMakeLists.txt (added)
-
modules/CheckHelpers/CheckHelpers.cpp (modified) (2 diffs)
-
modules/CheckHelpers/stdafx.h (modified) (2 diffs)
-
service/CMakeLists.txt (modified) (2 diffs)
-
service/NSCPlugin.cpp (modified) (4 diffs)
-
service/NSCPlugin.h (modified) (1 diff)
-
service/NSClient++.cpp (modified) (14 diffs)
-
service/NSClient++.h (modified) (4 diffs)
-
service/StdAfx.h (modified) (3 diffs)
-
service/core_api.cpp (modified) (1 diff)
-
service/settings_manager_impl.cpp (modified) (1 diff)
-
service/settings_manager_impl.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/NSCHelper.cpp
r214 r216 730 730 NSCModuleHelper::fNSAPIMessage = (NSCModuleHelper::lpNSAPIMessage)f(_T("NSAPIMessage")); 731 731 NSCModuleHelper::fNSAPIStopServer = (NSCModuleHelper::lpNSAPIStopServer)f(_T("NSAPIStopServer")); 732 NSCModuleHelper::fNSAPIExit = (NSCModuleHelper::lpNSAPIExit)f(_T("NSAPIExit"));732 //NSCModuleHelper::fNSAPIExit = (NSCModuleHelper::lpNSAPIExit)f(_T("NSAPIExit")); 733 733 NSCModuleHelper::fNSAPIInject = (NSCModuleHelper::lpNSAPIInject)f(_T("NSAPIInject")); 734 734 NSCModuleHelper::fNSAPIGetBasePath = (NSCModuleHelper::lpNSAPIGetBasePath)f(_T("NSAPIGetBasePath")); -
trunk/include/NSCHelper.h
r214 r216 23 23 #include <string> 24 24 #include <list> 25 #include <iostream> 26 25 27 #include <NSCAPI.h> 26 #include <iostream>27 28 #include <charEx.h> 28 29 #include <arrayBuffer.h> -
trunk/include/arrayBuffer.cpp
r207 r216 19 19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 20 20 ***************************************************************************/ 21 #include <types.hpp> 21 22 #include <arrayBuffer.h> 22 23 #include <msvc_wrappers.h> -
trunk/include/charEx.h
r207 r216 105 105 return token(std::wstring(buffer, p-buffer-1), p); 106 106 } 107 #ifdef _DEBUG108 inline void test_getToken(wchar_t* in1, wchar_t in2, std::wstring out1, wchar_t * out2) {109 token t = getToken(in1, in2);110 std::wcout << _T("charEx::test_getToken(") << in1 << _T(", ") << in2 << _T(") : ");111 if (t.first == out1) {112 if ((t.second == NULL) && (out2 == NULL))113 std::wcout << _T("Succeeded") << std::endl;114 else if (t.second == NULL)115 std::wcout << _T("Failed [NULL=") << out2 << _T("]") << std::endl;116 else if (out2 == NULL)117 std::wcout << _T("Failed [") << t.second << _T("=NULL]") << std::endl;118 else if (wcscmp(t.second, out2) == 0)119 std::wcout << _T("Succeeded") << std::endl;120 else121 std::wcout << _T("Failed") << std::endl;122 } else123 std::wcout << _T("Failed [") << out1 << _T("=") << t.first << _T("]") << std::endl;124 }125 inline void run_test_getToken() {126 test_getToken(_T(""), '&', _T(""), NULL);127 test_getToken(_T("&"), '&', _T(""), NULL);128 test_getToken(_T("&&"), '&', _T(""), _T("&"));129 test_getToken(_T("foo"), '&', _T("foo"), NULL);130 test_getToken(_T("foo&"), '&', _T("foo"), NULL);131 test_getToken(_T("foo&bar"), '&', _T("foo"), _T("bar"));132 test_getToken(_T("foo&bar&test"), '&', _T("foo"), _T("bar&test"));133 }134 #endif135 136 107 }; -
trunk/include/com_helpers.hpp
r130 r216 1 1 #pragma once 2 2 3 #define _WIN32_DCOM 4 #define _WIN32_WINNT 0x0400 5 3 6 #include <error.hpp> 4 /* 7 #include <windows.h> 8 #include <objbase.h> 5 9 #include <atlbase.h> 6 10 #include <atlsafe.h> 7 #include <windows.h> 8 */ 11 9 12 namespace com_helper { 10 13 -
trunk/include/dll/impl_unix.hpp
r207 r216 4 4 #include <boost/noncopyable.hpp> 5 5 #include <error.hpp> 6 7 #include <stdio.h> 8 #include <string.h> 9 #include <stdlib.h> 10 #if defined(AIX) 11 #include <dlfcn.h> 12 #elif defined(LINUX) || defined(SUN) || defined(CYGWIN) 13 #include <dlfcn.h> 14 #elif defined(HP) 15 #include <dl.h> 16 #endif 17 6 18 namespace dll { 7 19 namespace iunix { 8 9 20 class impl : public boost::noncopyable { 10 21 private: 11 std::wstring module_; 22 boost::filesystem::wpath module_; 23 void* handle_; 24 12 25 public: 13 impl(std::wstring module) : module_(module) {} 26 impl(boost::filesystem::wpath module) : module_(module), handle_(NULL) { 27 if (!boost::filesystem::is_regular(module)) { 28 module_ = fix_module_name(module_); 29 } 30 } 31 boost::filesystem::wpath fix_module_name( boost::filesystem::wpath module_ ) { 32 boost::filesystem::wpath mod = module_ / get_extension(); 33 if (boost::filesystem::is_regular(mod)) 34 return mod; 35 return module_; 36 } 37 static std::wstring get_extension() { 38 #if defined(CYGWIN) 39 return _T(".so"); 40 #elif defined(HP) 41 return _T(".so"); 42 #else 43 return _T(".so"); 44 #endif 45 } 46 47 static bool is_module(std::wstring file) { 48 return boost::ends_with(file, get_extension()); 49 } 14 50 15 51 void load_library() { 16 throw dll_exception(_T("Could not load library: ") + module_); 52 std::string dllname = to_string(module_.string()); 53 #if defined(LINUX) || defined(SUN) || defined(AIX) || defined(CYGWIN) 54 handle_ = dlopen(dllname.c_str(), RTLD_NOW); 55 if (handle_ == NULL) 56 throw dll_exception(_T("Could not load library: ") + to_wstring(dlerror()) + _T(": ") + module_.string()); 57 #elif defined(HP) 58 handle_ = shl_load(dllname.c_str(), BIND_DEFERRED|DYNAMIC_PATH, 0L); 59 if (handle_ == NULL) 60 throw dll_exception(_T("Could not load library: ") + error::lookup::last_error() + _T(": ") + module_.string()); 61 #else 62 /* This type of UNIX has no DLL support yet */ 63 throw dll_exception(_T("Unsupported Unix flavour (please report this): ") + module_.string()); 64 #endif 17 65 } 18 66 void* load_proc(std::string name) { 19 throw dll_exception(_T("Failed to load process from module: ") + module_); 67 if (handle_ == NULL) 68 throw dll_exception(_T("Failed to load process from module: ") + module_.string()); 69 void *ep = NULL; 70 #if defined(LINUX) || defined(SUN) || defined(AIX) || defined(CYGWIN) 71 ep = (void*) dlsym(handle_, name.c_str()); 72 if (ep == NULL) 73 throw dll_exception(_T("Failed to load process from module: ") + module_.string() + _T(" because: ") + to_wstring(dlerror())); 74 #elif defined(HP) 75 int rcode = shl_findsym((shl_t)&handle_, name.c_str(), TYPE_PROCEDURE, &ep); 76 if (rcode == -1) 77 return NULL; 78 //throw dll_exception(_T("Failed to load process from module: ") + module_.string()); 79 return ep; 80 #else 81 /* This type of UNIX has no DLL support yet */ 82 throw dll_exception(_T("Unsupported Unix flavour (please report this): ") + module_.string()); 83 #endif 20 84 } 21 85 22 86 void unload_library() { 87 #if defined(LINUX) || defined(SUN) || defined(AIX) || defined(CYGWIN) 88 dlclose(handle_); 89 #elif defined(HP) 90 shl_unload(handle_); 91 #else 92 /* This type of UNIX has no DLL support yet */ 93 throw dll_exception(_T("Unsupported Unix flavour (please report this): ") + module_.string()); 94 #endif 95 23 96 } 24 97 25 bool is_loaded() const { return false; }26 std::wstring get_file() const { return module_ ; }98 bool is_loaded() const { return handle_!=NULL; } 99 std::wstring get_file() const { return module_.string(); } 27 100 }; 28 101 } -
trunk/include/dll/impl_w32.hpp
r207 r216 9 9 private: 10 10 HMODULE handle_; 11 std::wstringmodule_;11 boost::filesystem::wpath module_; 12 12 public: 13 impl(std::wstring module) : module_(module), handle_(NULL) {} 13 impl(boost::filesystem::wpath module) : module_(module), handle_(NULL) { 14 if (!boost::filesystem::is_regular(module_)) { 15 module_ = fix_module_name(module_); 16 } 17 } 18 boost::filesystem::wpath fix_module_name( boost::filesystem::wpath module_ ) { 19 boost::filesystem::wpath mod = module_ / std::wstring(_T(".dll")); 20 if (boost::filesystem::is_regular(mod)) 21 return mod; 22 std::wstring tmp = module_.file_string() + _T(".dll"); 23 mod = tmp; 24 if (boost::filesystem::is_regular(mod)) 25 return mod; 26 return module_; 27 } 28 29 static bool is_module(std::wstring file) { 30 return boost::ends_with(file, _T(".dll")); 31 } 14 32 15 33 void load_library() { 16 34 if (handle_ != NULL) 17 35 unload_library(); 18 handle_ = LoadLibrary(module_. c_str());36 handle_ = LoadLibrary(module_.file_string().c_str()); 19 37 if (handle_ == NULL) 20 throw dll_exception(_T("Could not load library: ") + error::lookup::last_error() + _T(": ") + module_ );38 throw dll_exception(_T("Could not load library: ") + error::lookup::last_error() + _T(": ") + module_.file_string()); 21 39 } 22 40 LPVOID load_proc(std::string name) { 23 41 if (handle_ == NULL) 24 throw dll_exception(_T("Failed to load process from module: ") + module_); 25 return GetProcAddress(handle_, name.c_str()); 42 throw dll_exception(_T("Failed to load process since module is not loaded: ") + module_.file_string()); 43 LPVOID ep = GetProcAddress(handle_, name.c_str()); 44 return ep; 26 45 } 27 46 … … 32 51 handle_ = NULL; 33 52 } 34 35 53 bool is_loaded() const { return handle_ != NULL; } 36 std::wstring get_file() const { return module_ ; }54 std::wstring get_file() const { return module_.file_string(); } 37 55 }; 38 56 } -
trunk/include/error_impl_unix.hpp
r207 r216 6 6 class format { 7 7 public: 8 static std::wstring from_system(unsigned long dwError) { 9 return _T("ERROR TODO"); 8 static std::wstring from_system(int dwError) { 9 char buf [1024]; 10 return to_wstring(::strerror_r(dwError, buf, sizeof (buf))); 10 11 } 11 12 static std::wstring from_module(std::wstring module, unsigned long dwError) { … … 41 42 class lookup { 42 43 public: 43 static std::wstring last_error( unsigned longdwLastError = -1) {44 return _T("ERROR TODO");44 static std::wstring last_error(int dwLastError = -1) { 45 return ::error::format::from_system(dwLastError); 45 46 } 46 static std::string last_error_ansi( unsigned longdwLastError = -1) {47 return "ERROR TODO";47 static std::string last_error_ansi(int dwLastError = -1) { 48 return to_string(::error::format::from_system(dwLastError)); 48 49 } 49 50 }; -
trunk/include/nsc_module_wrapper.hpp
r214 r216 31 31 #define NSC_WRAPPERS_MAIN() \ 32 32 extern "C" int NSModuleHelperInit(NSCModuleHelper::lpNSAPILoader f); \ 33 extern int NSLoadModule(int mode); \34 extern int NSGetModuleName(wchar_t* buf, int buflen); \35 extern int NSGetModuleDescription(wchar_t* buf, int buflen); \36 extern int NSGetModuleVersion(int *major, int *minor, int *revision); \37 extern NSCAPI::boolReturn NSHasCommandHandler(); \38 extern NSCAPI::boolReturn NSHasMessageHandler(); \39 extern void NSHandleMessage(int msgType, wchar_t* file, int line, wchar_t* message); \40 extern NSCAPI::nagiosReturn NSHandleCommand(const wchar_t* IN_cmd, const unsigned int IN_argsLen, wchar_t **IN_args, \33 extern "C" int NSLoadModule(int mode); \ 34 extern "C" int NSGetModuleName(wchar_t* buf, int buflen); \ 35 extern "C" int NSGetModuleDescription(wchar_t* buf, int buflen); \ 36 extern "C" int NSGetModuleVersion(int *major, int *minor, int *revision); \ 37 extern "C" NSCAPI::boolReturn NSHasCommandHandler(); \ 38 extern "C" NSCAPI::boolReturn NSHasMessageHandler(); \ 39 extern "C" void NSHandleMessage(int msgType, wchar_t* file, int line, wchar_t* message); \ 40 extern "C" NSCAPI::nagiosReturn NSHandleCommand(const wchar_t* IN_cmd, const unsigned int IN_argsLen, wchar_t **IN_args, \ 41 41 wchar_t *OUT_retBufMessage, unsigned int IN_retBufMessageLen, wchar_t *OUT_retBufPerf, unsigned int IN_retBufPerfLen); \ 42 extern int NSUnloadModule(); \43 extern int NSGetConfigurationMeta(int IN_retBufLen, wchar_t *OUT_retBuf)42 extern "C" int NSUnloadModule(); \ 43 extern "C" int NSGetConfigurationMeta(int IN_retBufLen, wchar_t *OUT_retBuf) 44 44 45 45 #define NSC_WRAPPERS_CLI() \ 46 extern int NSCommandLineExec(const wchar_t*,const unsigned int,wchar_t**)46 extern "C" int NSCommandLineExec(const wchar_t*,const unsigned int,wchar_t**) 47 47 48 48 #ifdef DEBUG -
trunk/include/settings/Settings.h
r214 r216 27 27 #include <boost/thread/thread.hpp> 28 28 #include <boost/thread/locks.hpp> 29 #include <boost/filesystem/path.hpp> 29 30 #include <strEx.h> 30 31 #define BUFF_LEN 4096 … … 369 370 /// 370 371 /// @author mickem 371 virtual void set_base( std::wstringpath) = 0;372 virtual void set_base(boost::filesystem::wpath path) = 0; 372 373 373 374 ////////////////////////////////////////////////////////////////////////// … … 378 379 /// 379 380 /// @author mickem 380 virtual std::wstringget_base() = 0;381 virtual boost::filesystem::wpath get_base() = 0; 381 382 382 383 ////////////////////////////////////////////////////////////////////////// … … 654 655 //path_map path_mappings_; 655 656 //path_map reversed_path_mappings_; 656 std::wstringbase_path_;657 boost::filesystem::wpath base_path_; 657 658 LoggerInterface *logger_; 658 659 typedef std::map<std::wstring,path_description> reg_paths_type; … … 676 677 /// 677 678 /// @author mickem 678 void set_base( std::wstringpath) {679 void set_base(boost::filesystem::wpath path) { 679 680 base_path_ = path; 680 681 } … … 711 712 /// 712 713 /// @author mickem 713 std::wstringget_base() {714 boost::filesystem::wpath get_base() { 714 715 return base_path_; 715 716 } -
trunk/include/settings/settings_ini.hpp
r215 r216 3 3 #include <string> 4 4 #include <map> 5 6 #include <boost/filesystem/path.hpp> 7 #include <boost/filesystem/operations.hpp> 8 5 9 #include <settings/Settings.h> 6 7 10 #include <simpleini/simpleini.h> 8 11 #include <error.hpp> … … 11 14 class INISettings : public Settings::SettingsInterfaceImpl { 12 15 private: 13 std::wstringfilename_;16 boost::filesystem::wpath filename_; 14 17 bool is_loaded_; 15 18 CSimpleIni ini; … … 184 187 virtual void save() { 185 188 SettingsInterfaceImpl::save(); 186 SI_Error rc = ini.SaveFile(get_file_name(). c_str());189 SI_Error rc = ini.SaveFile(get_file_name().string().c_str()); 187 190 if (rc < 0) 188 191 throw_SI_error(rc, _T("Failed to save file")); … … 199 202 return; 200 203 } 201 SI_Error rc = ini.LoadFile(get_file_name(). c_str());204 SI_Error rc = ini.LoadFile(get_file_name().string().c_str()); 202 205 if (rc < 0) 203 206 throw_SI_error(rc, _T("Failed to load file")); … … 214 217 throw SettingsException(msg + _T(": ") + get_context() + _T(" - ") + error_str); 215 218 } 216 std::wstringget_file_name() {219 boost::filesystem::wpath get_file_name() { 217 220 if (filename_.empty()) { 218 filename_ = get_core()->get_base() + _T("\\") + get_core()->get_boot_string(get_context(), _T("file"), _T("nsclient.ini"));219 get_core()->get_logger()->debug(__FILEW__, __LINE__, _T("Reading INI settings from: ") + filename_ );221 filename_ = get_core()->get_base() / boost::filesystem::wpath(get_core()->get_boot_string(get_context(), _T("file"), _T("nsclient.ini"))); 222 get_core()->get_logger()->debug(__FILEW__, __LINE__, _T("Reading INI settings from: ") + filename_.string()); 220 223 } 221 224 return filename_; 222 225 } 223 226 bool file_exists() { 224 std::wstring filename = get_file_name(); 225 FILE * fp = NULL; 226 bool found = false; 227 #if __STDC_WANT_SECURE_LIB__ 228 if (_wfopen_s(&fp, filename.c_str(), L"rb") != 0) 229 return false; 230 #elif WIN32 231 fp = _wfopen(filename.c_str(), L"rb"); 232 #else 233 fp = fopen(to_string(filename).c_str(), "rb"); 234 #endif 235 if (!fp) 236 return false; 237 fclose(fp); 238 return true; 227 return boost::filesystem::is_regular(get_file_name()); 239 228 } 240 229 }; -
trunk/include/settings/settings_old.hpp
r208 r216 447 447 inline std::wstring get_file_name() { 448 448 if (filename_.empty()) { 449 filename_ = get_core()->get_base() + _T("\\") + get_core()->get_boot_string(get_context(), _T("file"), _T("nsc.ini"));449 filename_ = (get_core()->get_base() / get_core()->get_boot_string(get_context(), _T("file"), _T("nsc.ini"))).string(); 450 450 get_core()->get_logger()->debug(__FILEW__, __LINE__, _T("Reading old settings from: ") + filename_); 451 451 } … … 453 453 } 454 454 bool file_exists() { 455 std::wstring filename = get_file_name(); 456 FILE * fp = NULL; 457 bool found = false; 458 #if __STDC_WANT_SECURE_LIB__ 459 if (_wfopen_s(&fp, filename.c_str(), L"rb") != 0) 460 return false; 461 #else 462 fp = _wfopen(filename.c_str(), L"rb"); 463 #endif 464 if (!fp) 465 return false; 466 fclose(fp); 467 return true; 455 return boost::filesystem::is_regular_file(get_file_name()); 468 456 } 469 457 }; -
trunk/include/strEx.h
r214 r216 35 35 #include <boost/date_time.hpp> 36 36 #include <boost/lexical_cast.hpp> 37 #include <boost/algorithm/string.hpp> 37 38 //#include <boost/date_time/local_time/local_date_time.hpp> 38 39 //#include <boost/date_time/gregorian/conversion.hpp> … … 582 583 struct blind_traits : public std::char_traits<_E> 583 584 { 585 584 586 static bool eq(const _E& x, const _E& y) { 585 return tolower( x ) == tolower( y );587 return boost::algorithm::iequals(x,y); 586 588 } 587 589 static bool lt(const _E& x, const _E& y) { 588 return tolower( x ) < tolower( y );589 } 590 590 return ilexicographical_compare(x, y); 591 } 592 /* 591 593 static int compare(const _E *x, const _E *y, size_t n) { 594 return ilexicographical_compare(x, y); 592 595 return _wcsnicmp( x, y, n ); 593 596 } 594 597 595 598 // There's no memichr(), so we roll our own. It ain't rocket science. 596 static const _E * / *__cdecl*/ find(const _E *buf, size_t len, const _E& ch) {599 static const _E * / *__cdecl* / find(const _E *buf, size_t len, const _E& ch) { 597 600 // Jerry says that x86s have special mojo for memchr(), so the 598 601 // memchr() calls end up being reasonably efficient in practice. … … 613 616 return std::char_traits<_E>::eq_int_type( tolower( ch1 ), tolower( ch2 ) ); 614 617 } 618 */ 615 619 }; 616 620 … … 618 622 //typedef std::basic_string<char, blind_traits<char>, std::allocator<char> > blindstr; 619 623 typedef std::basic_string<wchar_t, blind_traits<wchar_t>, std::allocator<wchar_t> > blindstr; 620 624 /* 621 625 class StrICmp 622 626 { … … 665 669 } 666 670 }; 671 */ 667 672 668 673 #ifdef _DEBUG -
trunk/include/types.hpp
r214 r216 1 1 #pragma once 2 3 typedef wchar_t TCHAR; 2 4 3 5 … … 5 7 typedef unsigned long DWORD; 6 8 typedef void* LPVOID; 9 typedef int BOOL; 7 10 #endif 8 11 9 12 10 13 #ifdef WIN32 14 #include <windows.h> 11 15 #define wcscasecmp _wcsicmp 12 16 #endif -
trunk/modules/CheckHelpers/CheckHelpers.cpp
r201 r216 26 26 27 27 CheckHelpers gCheckHelpers; 28 28 #ifdef WIN32 29 29 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 30 30 { … … 32 32 return TRUE; 33 33 } 34 #endif 34 35 35 36 CheckHelpers::CheckHelpers() { -
trunk/modules/CheckHelpers/stdafx.h
r207 r216 21 21 #pragma once 22 22 23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 24 // Windows Header Files: 25 #include <windows.h> 23 #include <types.hpp> 24 #include <unicode_char.hpp> 26 25 27 26 #include <string> … … 32 31 #include <NSCHelper.h> 33 32 34 #ifdef MEMCHECK35 #include <vld.h>36 #endif -
trunk/service/CMakeLists.txt
r215 r216 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} ) -
trunk/service/NSCPlugin.cpp
r214 r216 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 } -
trunk/service/NSCPlugin.h
r214 r216 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); -
trunk/service/NSClient++.cpp
r214 r216 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 { -
trunk/service/NSClient++.h
r214 r216 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); -
trunk/service/StdAfx.h
r214 r216 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 -
trunk/service/core_api.cpp
r214 r216 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) { -
trunk/service/settings_manager_impl.cpp
r214 r216 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()); -
trunk/service/settings_manager_impl.h
r214 r216 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.







