Changeset 207


Ignore:
Timestamp:
11/08/09 23:24:31 (2 years ago)
Author:
mickem
Message:

First attempt at serious boostification.
NOTICE! This is NOT a complete edition, it build and runs but many features are disabled and/or broken.
But we have working, sockets and mutexes and conversion functions from boost inside now and more to come...
Also started to build with CMake since it works better then boost.build

Location:
trunk
Files:
14 added
46 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        1111build.log 
        1212AutoBuild.h.bak 
         13stage_cmake 
  • trunk/NSClient++-2005.sln

    r205 r207  
    237237    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    238238    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|Win32.ActiveCfg = Debug|Win32 
    239     {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|Win32.Build.0 = Debug|Win32 
    240239    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|x64.ActiveCfg = Debug|x64 
    241240    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|x64.Build.0 = Debug|x64 
     
    321320    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    322321    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|Win32.ActiveCfg = Debug|Win32 
    323     {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|Win32.Build.0 = Debug|Win32 
    324322    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|x64.ActiveCfg = Debug|x64 
    325323    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|x64.Build.0 = Debug|x64 
     
    342340    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    343341    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|Win32.ActiveCfg = Debug|Win32 
    344     {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|Win32.Build.0 = Debug|Win32 
    345342    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|x64.ActiveCfg = Debug|x64 
    346343    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|x64.Build.0 = Debug|x64 
     
    426423    {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    427424    {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|Win32.ActiveCfg = Debug|Win32 
    428     {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|Win32.Build.0 = Debug|Win32 
    429425    {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|x64.ActiveCfg = Debug|x64 
    430426    {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|x64.Build.0 = Debug|x64 
     
    503499    {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    504500    {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Win32.ActiveCfg = Debug|Win32 
    505     {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Win32.Build.0 = Debug|Win32 
    506501    {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|x64.ActiveCfg = Debug|x64 
    507502    {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|x64.Build.0 = Debug|x64 
     
    545540    {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Debug|Mixed Platforms.Build.0 = Debug|x64 
    546541    {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Debug|Win32.ActiveCfg = Debug|Win32 
    547     {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Debug|Win32.Build.0 = Debug|Win32 
    548542    {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Debug|x64.ActiveCfg = Debug|x64 
    549543    {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Debug|x64.Build.0 = Debug|x64 
     
    566560    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Mixed Platforms.Build.0 = Debug|Win32 
    567561    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Win32.ActiveCfg = Debug|Win32 
    568     {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Win32.Build.0 = Debug|Win32 
    569562    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|x64.ActiveCfg = Debug|x64 
    570563    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|x64.Build.0 = Debug|x64 
     
    675668    {B6A2BD0C-9633-4DD4-A350-D98ACE660937}.Debug|Mixed Platforms.Build.0 = Debug 
    676669    {B6A2BD0C-9633-4DD4-A350-D98ACE660937}.Debug|Win32.ActiveCfg = Debug 
    677     {B6A2BD0C-9633-4DD4-A350-D98ACE660937}.Debug|Win32.Build.0 = Debug 
    678670    {B6A2BD0C-9633-4DD4-A350-D98ACE660937}.Debug|x64.ActiveCfg = Debug 
    679671    {B6A2BD0C-9633-4DD4-A350-D98ACE660937}.Debug|x64.Build.0 = Debug 
     
    696688    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Mixed Platforms.ActiveCfg = Release|x64 
    697689    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Mixed Platforms.Build.0 = Release|x64 
    698     {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Win32.ActiveCfg = Release|Win32 
    699     {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Win32.Build.0 = Release|Win32 
     690    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Win32.ActiveCfg = Debug|Win32 
     691    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Win32.Build.0 = Debug|Win32 
    700692    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|x64.ActiveCfg = Release|x64 
    701693    {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|x64.Build.0 = Release|x64 
     
    761753    {743B2362-DF6A-4C28-A6C9-0F970D8E1B66} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 
    762754    {DF1DB6FB-0448-46D6-AE82-9901495E5F1A} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 
     755    {2286162D-7571-4735-BAC8-4A8D33A4F42D} = {CADF69A1-D324-4FA4-A33D-2CDE22C3BB96} 
     756    {43718644-173B-42D8-8AD1-E359BFB2BB20} = {CADF69A1-D324-4FA4-A33D-2CDE22C3BB96} 
    763757    {D367E76D-9485-4DCB-A9D0-3D3C0E190648} = {BBE9A5E7-A16B-443C-A349-823DED5A9FF3} 
    764758    {1D9DEE38-BBDC-49DE-A6F3-BAC26E114C1D} = {BBE9A5E7-A16B-443C-A349-823DED5A9FF3} 
    765759    {B6A2BD0C-9633-4DD4-A350-D98ACE660937} = {FC917E21-188A-44EE-9EF2-7C1274C2D719} 
    766     {2286162D-7571-4735-BAC8-4A8D33A4F42D} = {CADF69A1-D324-4FA4-A33D-2CDE22C3BB96} 
    767     {43718644-173B-42D8-8AD1-E359BFB2BB20} = {CADF69A1-D324-4FA4-A33D-2CDE22C3BB96} 
    768760  EndGlobalSection 
    769761  GlobalSection(DPCodeReviewSolutionGUID) = preSolution 
  • trunk/include/NSCAPI.h

    r138 r207  
    2222 
    2323 
    24 #include <tchar.h> 
     24#include <unicode_char.hpp> 
    2525 
    2626namespace NSCAPI { 
     
    7979#endif 
    8080 
    81   const int xor = 1; 
     81  const int encryption_xor = 1; 
    8282 
    8383  // Settings types 
     
    9696 
    9797  struct plugin_info { 
    98     TCHAR *dll; 
    99     TCHAR *name; 
    100     TCHAR *description; 
    101     TCHAR *version; 
     98    wchar_t *dll; 
     99    wchar_t *name; 
     100    wchar_t *description; 
     101    wchar_t *version; 
    102102  }; 
    103103  typedef plugin_info* plugin_info_list; 
     
    105105 
    106106}; 
     107 
     108namespace NSCModuleHelper { 
     109  typedef void* (*lpNSAPILoader)(wchar_t*); 
     110} 
  • trunk/include/NSCHelper.cpp

    r202 r207  
    2121 
    2222#include <NSCHelper.h> 
     23#include <nsc_module_wrapper.hpp> 
    2324#include <msvc_wrappers.h> 
    24 #include <config.h> 
     25#include <settings/macros.h> 
     26#include <arrayBuffer.h> 
     27//#include <config.h> 
    2528#include <strEx.h> 
    2629 
     
    6770* @return NSCAPI::success unless the buffer is to short then it will be NSCAPI::invalidBufferLen 
    6871*/ 
    69 int NSCHelper::wrapReturnString(TCHAR *buffer, unsigned int bufLen, std::wstring str, int defaultReturnCode ) { 
     72int NSCHelper::wrapReturnString(wchar_t *buffer, unsigned int bufLen, std::wstring str, int defaultReturnCode ) { 
    7073  // @todo deprecate this 
    7174  if (str.length() >= bufLen) { 
     
    215218 * @return The returned status of the command 
    216219 */ 
    217 NSCAPI::nagiosReturn NSCModuleHelper::InjectCommandRAW(const TCHAR* command, const unsigned int argLen, TCHAR **argument, TCHAR *returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR *returnPerfBuffer, unsigned int returnPerfBufferLen)  
     220NSCAPI::nagiosReturn NSCModuleHelper::InjectCommandRAW(const wchar_t* command, const unsigned int argLen, TCHAR **argument, TCHAR *returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR *returnPerfBuffer, unsigned int returnPerfBufferLen)  
    218221{ 
    219222  if (!fNSAPIInject) 
  • trunk/include/NSCHelper.h

    r205 r207  
    2727#include <charEx.h> 
    2828#include <arrayBuffer.h> 
    29 #include <windows.h> 
     29#ifdef WIN32 
     30//#include <windows.h> 
     31#endif 
    3032 
    3133 
     
    3335{ 
    3436#ifdef DEBUG 
    35   NSCAPI::nagiosReturn wrapReturnString(TCHAR *buffer, unsigned int bufLen, std::wstring str, NSCAPI::nagiosReturn defaultReturnCode); 
    36   NSCAPI::errorReturn wrapReturnString(TCHAR *buffer, unsigned int bufLen, std::wstring str, NSCAPI::errorReturn defaultReturnCode); 
     37  NSCAPI::nagiosReturn wrapReturnString(wchar_t *buffer, unsigned int bufLen, std::wstring str, NSCAPI::nagiosReturn defaultReturnCode); 
     38  NSCAPI::errorReturn wrapReturnString(wchar_t *buffer, unsigned int bufLen, std::wstring str, NSCAPI::errorReturn defaultReturnCode); 
    3739#else 
    38   int wrapReturnString(TCHAR *buffer, unsigned int bufLen, std::wstring str, int defaultReturnCode); 
     40  int wrapReturnString(wchar_t *buffer, unsigned int bufLen, std::wstring str, int defaultReturnCode); 
    3941#endif 
    4042  std::wstring translateMessageType(NSCAPI::messageTypes msgType); 
     
    108110  typedef std::list<plugin_info_type> plugin_info_list; 
    109111  // Types for the Callbacks into the main program 
    110   typedef NSCAPI::errorReturn (*lpNSAPIGetBasePath)(TCHAR*,unsigned int); 
    111   typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationName)(TCHAR*,unsigned int); 
    112   typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationVersionStr)(TCHAR*,unsigned int); 
    113   typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsString)(const TCHAR*,const TCHAR*,const TCHAR*,TCHAR*,unsigned int); 
    114   typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsInt)(const TCHAR*, const TCHAR*, int); 
    115   typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSection)(const TCHAR*, arrayBuffer::arrayBuffer*, unsigned int *); 
     112   
     113  typedef NSCAPI::errorReturn (*lpNSAPIGetBasePath)(wchar_t*,unsigned int); 
     114  typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationName)(wchar_t*,unsigned int); 
     115  typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationVersionStr)(wchar_t*,unsigned int); 
     116  typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsString)(const wchar_t*,const wchar_t*,const wchar_t*,wchar_t*,unsigned int); 
     117  typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsInt)(const wchar_t*, const wchar_t*, int); 
     118  typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSection)(const wchar_t*, arrayBuffer::arrayBuffer*, unsigned int *); 
    116119  typedef NSCAPI::errorReturn (*lpNSAPIReleaseSettingsSectionBuffer)(arrayBuffer::arrayBuffer*, unsigned int *); 
    117   typedef void (*lpNSAPIMessage)(int, const TCHAR*, const int, const TCHAR*); 
     120  typedef void (*lpNSAPIMessage)(int, const wchar_t*, const int, const wchar_t*); 
    118121  typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); 
    119122  typedef NSCAPI::errorReturn (*lpNSAPIExit)(void); 
    120   typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const TCHAR*, const unsigned int, TCHAR **, TCHAR *, unsigned int, TCHAR *, unsigned int); 
    121   typedef void* (*lpNSAPILoader)(TCHAR*); 
     123  typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const wchar_t*, const unsigned int, wchar_t **, wchar_t *, unsigned int, wchar_t *, unsigned int); 
     124   
    122125  typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); 
    123   typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const TCHAR*, unsigned int, TCHAR*, unsigned int *); 
    124   typedef NSCAPI::errorReturn (*lpNSAPIDecrypt)(unsigned int, const TCHAR*, unsigned int, TCHAR*, unsigned int *); 
    125   typedef NSCAPI::errorReturn (*lpNSAPISetSettingsString)(const TCHAR*, const TCHAR*, const TCHAR*); 
    126   typedef NSCAPI::errorReturn (*lpNSAPISetSettingsInt)(const TCHAR*, const TCHAR*, int); 
     126  typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const wchar_t*, unsigned int, wchar_t*, unsigned int *); 
     127  typedef NSCAPI::errorReturn (*lpNSAPIDecrypt)(unsigned int, const wchar_t*, unsigned int, wchar_t*, unsigned int *); 
     128  typedef NSCAPI::errorReturn (*lpNSAPISetSettingsString)(const wchar_t*, const wchar_t*, const wchar_t*); 
     129  typedef NSCAPI::errorReturn (*lpNSAPISetSettingsInt)(const wchar_t*, const wchar_t*, int); 
    127130  typedef NSCAPI::errorReturn (*lpNSAPIWriteSettings)(int); 
    128131  typedef NSCAPI::errorReturn (*lpNSAPIReadSettings)(int); 
    129132  typedef NSCAPI::errorReturn (*lpNSAPIRehash)(int); 
    130   typedef NSCAPI::errorReturn (*lpNSAPIDescribeCommand)(const TCHAR*,TCHAR*,unsigned int); 
     133  typedef NSCAPI::errorReturn (*lpNSAPIDescribeCommand)(const wchar_t*,wchar_t*,unsigned int); 
    131134  typedef NSCAPI::errorReturn (*lpNSAPIGetAllCommandNames)(arrayBuffer::arrayBuffer*, unsigned int *); 
    132135  typedef NSCAPI::errorReturn (*lpNSAPIReleaseAllCommandNamessBuffer)(arrayBuffer::arrayBuffer*, unsigned int *); 
    133   typedef NSCAPI::errorReturn (*lpNSAPIRegisterCommand)(const TCHAR*,const TCHAR*); 
    134   typedef NSCAPI::errorReturn (*lpNSAPISettingsRegKey)(const TCHAR*, const TCHAR*, int, const TCHAR*, const TCHAR*, const TCHAR*, int); 
    135   typedef NSCAPI::errorReturn (*lpNSAPISettingsRegPath)(const TCHAR*, const TCHAR*, const TCHAR*, int); 
     136  typedef NSCAPI::errorReturn (*lpNSAPIRegisterCommand)(const wchar_t*,const wchar_t*); 
     137  typedef NSCAPI::errorReturn (*lpNSAPISettingsRegKey)(const wchar_t*, const wchar_t*, int, const wchar_t*, const wchar_t*, const wchar_t*, int); 
     138  typedef NSCAPI::errorReturn (*lpNSAPISettingsRegPath)(const wchar_t*, const wchar_t*, const wchar_t*, int); 
    136139  typedef NSCAPI::errorReturn (*lpNSAPIGetPluginList)(int *len, NSCAPI::plugin_info *list[]); 
    137140  typedef NSCAPI::errorReturn (*lpNSAPIReleasePluginList)(int len, NSCAPI::plugin_info *list[]); 
     
    150153 
    151154  void Message(int msgType, std::wstring file, int line, std::wstring message); 
    152   NSCAPI::nagiosReturn InjectCommandRAW(const TCHAR* command, const unsigned int argLen, TCHAR **argument, TCHAR *returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR *returnPerfBuffer, unsigned int returnPerfBufferLen); 
    153   NSCAPI::nagiosReturn InjectCommand(const TCHAR* command, const unsigned int argLen, TCHAR **argument, std::wstring & message, std::wstring & perf); 
    154   NSCAPI::nagiosReturn InjectCommand(const TCHAR* command, std::list<std::wstring> argument, std::wstring & message, std::wstring & perf); 
    155   NSCAPI::nagiosReturn InjectSplitAndCommand(const TCHAR* command, TCHAR* buffer, TCHAR splitChar, std::wstring & message, std::wstring & perf); 
    156   NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, TCHAR splitChar, std::wstring & message, std::wstring & perf, bool escape = false); 
     155  NSCAPI::nagiosReturn InjectCommandRAW(const wchar_t* command, const unsigned int argLen, wchar_t **argument, wchar_t *returnMessageBuffer, unsigned int returnMessageBufferLen, wchar_t *returnPerfBuffer, unsigned int returnPerfBufferLen); 
     156  NSCAPI::nagiosReturn InjectCommand(const wchar_t* command, const unsigned int argLen, wchar_t **argument, std::wstring & message, std::wstring & perf); 
     157  NSCAPI::nagiosReturn InjectCommand(const wchar_t* command, std::list<std::wstring> argument, std::wstring & message, std::wstring & perf); 
     158  NSCAPI::nagiosReturn InjectSplitAndCommand(const wchar_t* command, wchar_t* buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf); 
     159  NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf, bool escape = false); 
    157160  void StopService(void); 
    158161  void Exit(void); 
     
    160163  bool logDebug(); 
    161164  bool checkLogMessages(int type); 
    162   std::wstring Encrypt(std::wstring str, unsigned int algorithm = NSCAPI::xor); 
    163   std::wstring Decrypt(std::wstring str, unsigned int algorithm = NSCAPI::xor); 
     165  std::wstring Encrypt(std::wstring str, unsigned int algorithm = NSCAPI::encryption_xor); 
     166  std::wstring Decrypt(std::wstring str, unsigned int algorithm = NSCAPI::encryption_xor); 
    164167  NSCAPI::errorReturn SetSettingsString(std::wstring section, std::wstring key, std::wstring value); 
    165168  NSCAPI::errorReturn SetSettingsInt(std::wstring section, std::wstring key, int value); 
     
    175178}; 
    176179 
    177 namespace NSCModuleWrapper { 
    178   struct module_version { 
    179     int major; 
    180     int minor; 
    181     int revision; 
    182   }; 
    183  
    184   BOOL wrapDllMain(HANDLE hModule, DWORD ul_reason_for_call); 
    185   HINSTANCE getModule(); 
    186  
    187   int wrapModuleHelperInit(NSCModuleHelper::lpNSAPILoader f);; 
    188   NSCAPI::errorReturn wrapGetModuleName(TCHAR* buf, unsigned int buflen, std::wstring str); 
    189   NSCAPI::errorReturn wrapGetConfigurationMeta(TCHAR* buf, unsigned int buflen, std::wstring str); 
    190   int wrapLoadModule(bool success); 
    191   NSCAPI::errorReturn wrapGetModuleVersion(int *major, int *minor, int *revision, module_version version); 
    192   NSCAPI::boolReturn wrapHasCommandHandler(bool has); 
    193   NSCAPI::boolReturn wrapHasMessageHandler(bool has); 
    194   int wrapUnloadModule(bool success); 
    195   NSCAPI::nagiosReturn wrapHandleCommand(NSCAPI::nagiosReturn retResult, const std::wstring retMessage, const std::wstring retPerformance, TCHAR *returnBufferMessage, unsigned int returnBufferMessageLen, TCHAR *returnBufferPerf, unsigned int returnBufferPerfLen); 
    196 } 
    197  
    198 ////////////////////////////////////////////////////////////////////////// 
    199 // Module wrappers (definitions) 
    200 #define NSC_WRAPPERS_MAIN() \ 
    201   extern "C" int NSModuleHelperInit(NSCModuleHelper::lpNSAPILoader f); \ 
    202   extern int NSLoadModule(int mode); \ 
    203   extern int NSGetModuleName(TCHAR* buf, int buflen); \ 
    204   extern int NSGetModuleDescription(TCHAR* buf, int buflen); \ 
    205   extern int NSGetModuleVersion(int *major, int *minor, int *revision); \ 
    206   extern NSCAPI::boolReturn NSHasCommandHandler(); \ 
    207   extern NSCAPI::boolReturn NSHasMessageHandler(); \ 
    208   extern void NSHandleMessage(int msgType, TCHAR* file, int line, TCHAR* message); \ 
    209   extern NSCAPI::nagiosReturn NSHandleCommand(const TCHAR* IN_cmd, const unsigned int IN_argsLen, TCHAR **IN_args, \ 
    210     TCHAR *OUT_retBufMessage, unsigned int IN_retBufMessageLen, TCHAR *OUT_retBufPerf, unsigned int IN_retBufPerfLen); \ 
    211   extern int NSUnloadModule(); \ 
    212   extern int NSGetConfigurationMeta(int IN_retBufLen, TCHAR *OUT_retBuf) 
    213  
    214 #define NSC_WRAPPERS_CLI() \ 
    215   extern int NSCommandLineExec(const TCHAR*,const unsigned int,TCHAR**) 
    216  
    217 #ifdef DEBUG 
    218 #define NSC_LOG_ERROR_STD_C(msg) NSC_LOG_ERROR(((std::wstring)msg).c_str()) 
    219 #define NSC_LOG_ERROR_C(msg) { \ 
    220   NSCModuleHelper::Message(NSCAPI::error, _T(__FILE__), __LINE__, msg) \ 
    221   std::wcerr << msg << std::endl; } 
    222 #else 
    223 #define NSC_LOG_ERROR_STD_C(msg) NSC_LOG_ERROR_STD(msg) 
    224 #define NSC_LOG_ERROR_C(msg) NSC_LOG_ERROR(msg) 
    225 #endif 
    226  
    227  
    228 #define NSC_LOG_ERROR_STD(msg) NSC_LOG_ERROR(((std::wstring)msg).c_str()) 
    229 #define NSC_LOG_ERROR(msg) \ 
    230   NSCModuleHelper::Message(NSCAPI::error, _T(__FILE__), __LINE__, msg) 
    231  
    232 #define NSC_LOG_CRITICAL_STD(msg) NSC_LOG_CRITICAL(((std::wstring)msg).c_str()) 
    233 #define NSC_LOG_CRITICAL(msg) \ 
    234   NSCModuleHelper::Message(NSCAPI::critical, _T(__FILE__), __LINE__, msg) 
    235  
    236 #define NSC_LOG_MESSAGE_STD(msg) NSC_LOG_MESSAGE(((std::wstring)msg).c_str()) 
    237 #define NSC_LOG_MESSAGE(msg) \ 
    238   NSCModuleHelper::Message(NSCAPI::log, _T(__FILE__), __LINE__, msg) 
    239  
    240 //#define NSC_DEBUG_MSG_STD(msg) NSC_DEBUG_MSG(((std::wstring)msg).c_str()) 
    241 #define NSC_DEBUG_MSG_STD(msg) NSC_DEBUG_MSG((std::wstring)msg) 
    242 #define NSC_DEBUG_MSG(msg) \ 
    243   NSCModuleHelper::Message(NSCAPI::debug, _T(__FILE__), __LINE__, msg) 
    244  
    245 /* 
    246 #define NSC_DEBUG_MSG_STD(msg) 
    247 #define NSC_DEBUG_MSG(msg) 
    248 */ 
    249 ////////////////////////////////////////////////////////////////////////// 
    250 // Message wrappers below this point 
    251  
    252 #define NSC_WRAPPERS_MAIN_DEF(toObject) \ 
    253   extern int NSModuleHelperInit(NSCModuleHelper::lpNSAPILoader f) { \ 
    254     try { \ 
    255       return NSCModuleWrapper::wrapModuleHelperInit(f); \ 
    256     } catch (...) { \ 
    257       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapModuleHelperInit(...)")); \ 
    258       return NSCAPI::hasFailed; \ 
    259     } \ 
    260   } \ 
    261   extern int NSLoadModule(int mode) { \ 
    262     try { \ 
    263       return NSCModuleWrapper::wrapLoadModule(toObject.loadModule(mode)); \ 
    264     } catch (NSCModuleHelper::NSCMHExcpetion e) { \ 
    265       NSC_LOG_CRITICAL(_T("NSCMHE in: wrapLoadModule: " + e.msg_)); \ 
    266       return NSCAPI::hasFailed; \ 
    267     } catch (...) { \ 
    268       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ 
    269       return NSCAPI::hasFailed; \ 
    270     } \ 
    271   } \ 
    272   extern int NSGetModuleName(TCHAR* buf, int buflen) { \ 
    273     try { \ 
    274       return NSCModuleWrapper::wrapGetModuleName(buf, buflen, toObject.getModuleName()); \ 
    275     } catch (...) { \ 
    276       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleName(...)")); \ 
    277       return NSCAPI::hasFailed; \ 
    278     } \ 
    279   } \ 
    280   extern int NSGetModuleDescription(TCHAR* buf, int buflen) { \ 
    281     try { \ 
    282       return NSCModuleWrapper::wrapGetModuleName(buf, buflen, toObject.getModuleDescription()); \ 
    283     } catch (...) { \ 
    284       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleName(...)")); \ 
    285       return NSCAPI::hasFailed; \ 
    286     } \ 
    287   } \ 
    288   extern int NSGetModuleVersion(int *major, int *minor, int *revision) { \ 
    289     try { \ 
    290       return NSCModuleWrapper::wrapGetModuleVersion(major, minor, revision, toObject.getModuleVersion()); \ 
    291     } catch (...) { \ 
    292       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleVersion(...)")); \ 
    293       return NSCAPI::hasFailed; \ 
    294     } \ 
    295   } \ 
    296   extern int NSUnloadModule() { \ 
    297     try { \ 
    298       return NSCModuleWrapper::wrapUnloadModule(toObject.unloadModule()); \ 
    299     } catch (...) { \ 
    300       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleVersion(...)")); \ 
    301       return NSCAPI::hasFailed; \ 
    302     } \ 
    303   } 
    304 #define NSC_WRAPPERS_HANDLE_MSG_DEF(toObject) \ 
    305   extern void NSHandleMessage(int msgType, TCHAR* file, int line, TCHAR* message) { \ 
    306     try { \ 
    307       toObject.handleMessage(msgType, file, line, message); \ 
    308     } catch (...) { \ 
    309       NSC_LOG_CRITICAL(_T("Unknown exception in: handleMessage(...)")); \ 
    310     } \ 
    311   } \ 
    312   extern NSCAPI::boolReturn NSHasMessageHandler() { \ 
    313     try { \ 
    314       return NSCModuleWrapper::wrapHasMessageHandler(toObject.hasMessageHandler()); \ 
    315     } catch (...) { \ 
    316       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasMessageHandler(...)")); \ 
    317       return NSCAPI::isfalse; \ 
    318     } \ 
    319   } 
    320 #define NSC_WRAPPERS_IGNORE_MSG_DEF() \ 
    321   extern void NSHandleMessage(int msgType, TCHAR* file, int line, TCHAR* message) {} \ 
    322   extern NSCAPI::boolReturn NSHasMessageHandler() { return NSCAPI::isfalse; } 
    323 #define NSC_WRAPPERS_HANDLE_CMD_DEF(toObject) \ 
    324   extern NSCAPI::nagiosReturn NSHandleCommand(const TCHAR* IN_cmd, const unsigned int IN_argsLen, TCHAR **IN_args, \ 
    325                   TCHAR *OUT_retBufMessage, unsigned int IN_retBufMessageLen, TCHAR *OUT_retBufPerf, unsigned int IN_retBufPerfLen) \ 
    326   { \ 
    327     try { \ 
    328       std::wstring message, perf; \ 
    329       NSCAPI::nagiosReturn retCode = toObject.handleCommand(IN_cmd, IN_argsLen, IN_args, message, perf); \ 
    330       return NSCModuleWrapper::wrapHandleCommand(retCode, message, perf, OUT_retBufMessage, IN_retBufMessageLen, OUT_retBufPerf, IN_retBufPerfLen); \ 
    331     } catch (...) { \ 
    332       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHandleCommand(...)")); \ 
    333       return NSCAPI::returnIgnored; \ 
    334     } \ 
    335   } \ 
    336   extern NSCAPI::boolReturn NSHasCommandHandler() { \ 
    337     try { \ 
    338       return NSCModuleWrapper::wrapHasCommandHandler(toObject.hasCommandHandler()); \ 
    339     } catch (...) { \ 
    340       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasCommandHandler(...)")); \ 
    341       return NSCAPI::isfalse; \ 
    342     } \ 
    343   } 
    344 #define NSC_WRAPPERS_IGNORE_CMD_DEF() \ 
    345   extern NSCAPI::nagiosReturn NSHandleCommand(const TCHAR* IN_cmd, const unsigned int IN_argsLen, TCHAR **IN_args, \ 
    346                   TCHAR *OUT_retBufMessage, unsigned int IN_retBufMessageLen, TCHAR *OUT_retBufPerf, unsigned int IN_retBufPerfLen) { \ 
    347     return NSCAPI::returnIgnored; \ 
    348   } \ 
    349   extern NSCAPI::boolReturn NSHasCommandHandler() { return NSCAPI::isfalse; } 
    350  
    351  
    352 #define NSC_WRAPPERS_HANDLE_CONFIGURATION(toObject) \ 
    353   extern int NSGetConfigurationMeta(int IN_retBufLen, TCHAR *OUT_retBuf) \ 
    354   { \ 
    355     try { \ 
    356       return NSCModuleWrapper::wrapGetConfigurationMeta(OUT_retBuf, IN_retBufLen, toObject.getConfigurationMeta()); \ 
    357     } catch (...) { \ 
    358       NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetConfigurationMeta(...)")); \ 
    359       return NSCAPI::hasFailed; \ 
    360     } \ 
    361   } 
    362  
    363 #define NSC_WRAPPERS_CLI_DEF(toObject) \ 
    364   extern int NSCommandLineExec(const TCHAR* command,const unsigned int argLen,TCHAR** args) { \ 
    365     try { \ 
    366       return toObject.commandLineExec(command, argLen, args); \ 
    367     } catch (...) { \ 
    368       NSC_LOG_CRITICAL(_T("Unknown exception in: commandLineExec(...)")); \ 
    369       std::wcerr << _T("Unknown exception in: commandLineExec(...)") << std::endl; \ 
    370       return NSCAPI::hasFailed; \ 
    371     } \ 
    372   } \ 
    373  
    374 ////////////////////////////////////////////////////////////////////////// 
    375 #define MODULE_SETTINGS_START(class, name, description) \ 
    376   std::wstring class::getConfigurationMeta() { \ 
    377   return (std::wstring)_T("<module name=\"") + name + _T("\" description=\"") + description + _T("\">") \ 
    378   _T("<pages>") 
    379  
    380  
    381 #define ADVANCED_PAGE(title) \ 
    382   _T("<page title=\"") title _T("\" advanced=\"true\">") \ 
    383   _T("<items>") 
    384  
    385 #define PAGE(title) \ 
    386   _T("<page title=\"") title _T("\">") \ 
    387   _T("<items>") 
    388  
    389 #define ITEM_EDIT_TEXT(caption, description) \ 
    390   _T("<item type=\"text\" caption=\"") caption _T("\" description=\"") description _T("\"><options>") 
    391  
    392 #define ITEM_EDIT_OPTIONAL_LIST(caption, description) \ 
    393   _T("<item type=\"optional_list\" caption=\"") caption _T("\" description=\"") description _T("\"><options>") 
    394  
    395 #define ITEM_CHECK_BOOL(caption, description) \ 
    396   _T("<item type=\"bool\" caption=\"") caption _T("\" description=\"") description _T("\"><options>") 
    397  
    398 #define ITEM_MAP_TO(type) \ 
    399   _T("</options><mapper type=\"") type _T("\">") \ 
    400   _T("<options>") 
    401  
    402 #define OPTION(key, value) \ 
    403   _T("<option key=\"") key _T("\" value=\"") value _T("\"/>") 
    404  
    405 #define ITEM_END() \ 
    406   _T("</options>") \ 
    407   _T("</mapper>") \ 
    408   _T("</item>") 
    409  
    410 #define PAGE_END() \ 
    411   _T("</items>") \ 
    412   _T("</page>") 
    413  
    414 #define MODULE_SETTINGS_END() \ 
    415       _T("</pages>") \ 
    416     _T("</module>"); \ 
    417   } 
    418180 
    419181#define SETTINGS_MAKE_NAME(key) \ 
     
    437199  NSCModuleHelper::settings_register_key(setting_keys::key ## _PATH, setting_keys::key, NSCAPI::key_string, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, setting_keys::key ## _DEFAULT, setting_keys::key ## _ADVANCED); 
    438200#define SETTINGS_REG_KEY_I(key) \ 
    439   NSCModuleHelper::settings_register_key(setting_keys::key ## _PATH, setting_keys::key, NSCAPI::key_integer, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, strEx::itos(setting_keys::key ## _DEFAULT), setting_keys::key ## _ADVANCED); 
     201  NSCModuleHelper::settings_register_key(setting_keys::key ## _PATH, setting_keys::key, NSCAPI::key_integer, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, boost::lexical_cast<std::wstring>(setting_keys::key ## _DEFAULT), setting_keys::key ## _ADVANCED); 
    440202#define SETTINGS_REG_KEY_B(key) \ 
    441203  NSCModuleHelper::settings_register_key(setting_keys::key ## _PATH, setting_keys::key, NSCAPI::key_integer, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, setting_keys::key ## _DEFAULT==1?_T("1"):_T("0"), setting_keys::key ## _ADVANCED); 
  • trunk/include/NTService.h

    r169 r207  
    2424#include <sysinfo.h> 
    2525 
    26 namespace service_helper { 
     26namespace service_helper_impl { 
    2727  class service_exception { 
    2828    std::wstring what_; 
  • trunk/include/arrayBuffer.cpp

    r169 r207  
    2828 * @return Argument wrapped as a list 
    2929 */ 
    30 arrayBuffer::arrayList arrayBuffer::arrayBuffer2list(const unsigned int argLen, TCHAR *argument[]) { 
     30arrayBuffer::arrayList arrayBuffer::arrayBuffer2list(const unsigned int argLen, wchar_t *argument[]) { 
    3131  arrayList ret; 
    3232  int i=0; 
     
    5353  for (i=0;it!=lst.end();++it,i++) { 
    5454    std::wstring::size_type alen = (*it).size(); 
    55     arrayBuffer[i] = new TCHAR[alen+2]; 
     55    arrayBuffer[i] = new wchar_t[alen+2]; 
    5656    wcsncpy_s(arrayBuffer[i], alen+2, (*it).c_str(), alen+1); 
    5757  } 
     
    107107* @return The arrayBuffer 
    108108*/ 
    109 arrayBuffer::arrayBuffer arrayBuffer::split2arrayBuffer(const TCHAR* buffer, TCHAR splitChar, unsigned int &argLen) { 
     109arrayBuffer::arrayBuffer arrayBuffer::split2arrayBuffer(const wchar_t* buffer, wchar_t splitChar, unsigned int &argLen) { 
    110110  if (!buffer) 
    111111    throw ArrayBufferException(_T("Invalid buffer specified!")); 
    112112  argLen = 0; 
    113   const TCHAR *p = buffer; 
     113  const wchar_t *p = buffer; 
    114114  if (!p[0]) { 
    115115    return createEmptyArrayBuffer(argLen); 
     
    121121  } 
    122122  argLen++; 
    123   TCHAR **arrayBuffer = new TCHAR*[argLen]; 
     123  wchar_t **arrayBuffer = new wchar_t*[argLen]; 
    124124  p = buffer; 
    125125  for (unsigned int i=0;i<argLen;i++) { 
    126     const TCHAR *q = wcschr(p, (i<argLen-1)?splitChar:0); 
     126    const wchar_t *q = wcschr(p, (i<argLen-1)?splitChar:0); 
    127127    unsigned int len = static_cast<int>(q-p); 
    128     arrayBuffer[i] = new TCHAR[len+1]; 
     128    arrayBuffer[i] = new wchar_t[len+1]; 
    129129    wcsncpy_s(arrayBuffer[i], len+1, p, len); 
    130130    arrayBuffer[i][len] = 0; 
     
    140140  delete [] arrayBuffer[position]; 
    141141  size_t len = argument.length(); 
    142   arrayBuffer[position] = new TCHAR[len+2]; 
     142  arrayBuffer[position] = new wchar_t[len+2]; 
    143143  wcsncpy_s(arrayBuffer[position], len+1, argument.c_str(), len); 
    144144  arrayBuffer[position][len] = 0; 
     
    153153 * @return The arrayBuffer 
    154154 */ 
    155 arrayBuffer::arrayBuffer arrayBuffer::split2arrayBuffer(const std::wstring inBuf, TCHAR splitChar, unsigned int &argLen, bool escape) { 
     155arrayBuffer::arrayBuffer arrayBuffer::split2arrayBuffer(const std::wstring inBuf, wchar_t splitChar, unsigned int &argLen, bool escape) { 
    156156  if (inBuf.empty()) 
    157157    return createEmptyArrayBuffer(argLen); 
     
    197197  for (std::list<std::wstring>::const_iterator cit=token_list.begin();cit!=token_list.end();++cit) { 
    198198    size_t len = (*cit).size(); 
    199     TCHAR* token = new TCHAR[len+1]; 
     199    wchar_t* token = new wchar_t[len+1]; 
    200200    wcsncpy_s(token, len+1, (*cit).c_str(), len); 
    201201    arrayBuffer[argLen++] = token; 
     
    289289  std::wcout << "arrayBuffer::test_createEmptyArrayBuffer() : "; 
    290290  unsigned int argLen; 
    291   TCHAR ** c = createEmptyArrayBuffer(argLen); 
     291  wchar_t ** c = createEmptyArrayBuffer(argLen); 
    292292  if ((c) && (argLen == 0)) 
    293293    std::wcout << "Succeeded" << std::endl; 
     
    302302 * @param OUT_argLen  
    303303 */ 
    304 void arrayBuffer::test_split2arrayBuffer_str(std::wstring buffer, TCHAR splitter, int OUT_argLen) { 
     304void arrayBuffer::test_split2arrayBuffer_str(std::wstring buffer, wchar_t splitter, int OUT_argLen) { 
    305305  std::wcout << _T("arrayBuffer::test_split2arrayBuffer(") << buffer << _T(", ...) : "); 
    306306  unsigned int argLen = 0; 
    307   TCHAR ** c = split2arrayBuffer(buffer, splitter, argLen); 
     307  wchar_t ** c = split2arrayBuffer(buffer, splitter, argLen); 
    308308  if ((c) && (argLen == OUT_argLen)) 
    309309    std::wcout << _T("Succeeded") << std::endl; 
     
    318318 * @param OUT_argLen  
    319319 */ 
    320 void arrayBuffer::test_split2arrayBuffer_char(TCHAR* buffer, TCHAR splitter, int OUT_argLen) { 
     320void arrayBuffer::test_split2arrayBuffer_char(wchar_t* buffer, wchar_t splitter, int OUT_argLen) { 
    321321  std::wcout << _T("arrayBuffer::test_split2arrayBuffer(") << buffer << _T(", ...) : "); 
    322322  unsigned int argLen = 0; 
    323   TCHAR ** c = split2arrayBuffer(buffer, splitter, argLen); 
     323  wchar_t ** c = split2arrayBuffer(buffer, splitter, argLen); 
    324324  if ((c) && (argLen == OUT_argLen)) 
    325325    std::wcout << _T("Succeeded") << std::endl; 
  • trunk/include/arrayBuffer.h

    r169 r207  
    2020***************************************************************************/ 
    2121#pragma once 
    22  
    23 #include <tchar.h> 
     22#include <unicode_char.hpp> 
    2423#include <string> 
    2524#include <list> 
     
    5453    ArrayBufferException(std::wstring error) {} 
    5554  }; 
    56   typedef TCHAR* arrayBufferItem; 
     55  typedef wchar_t* arrayBufferItem; 
    5756  typedef arrayBufferItem* arrayBuffer; 
    5857  typedef std::list<std::wstring> arrayList; 
    5958  void set(arrayBuffer arrayBuffer, const unsigned int argLen, const unsigned int position, std::wstring argument); 
    60   arrayList arrayBuffer2list(const unsigned int argLen, TCHAR **argument); 
     59  arrayList arrayBuffer2list(const unsigned int argLen, wchar_t **argument); 
    6160  arrayBuffer list2arrayBuffer(const arrayList lst, unsigned int &argLen); 
    62   arrayBuffer split2arrayBuffer(const TCHAR* buffer, TCHAR splitChar, unsigned int &argLen); 
    63   arrayBuffer split2arrayBuffer(const std::wstring inBuf, TCHAR splitChar, unsigned int &argLen, bool escape = false); 
    64   std::wstring arrayBuffer2string(TCHAR **argument, const unsigned int argLen, std::wstring join); 
     61  arrayBuffer split2arrayBuffer(const wchar_t* buffer, wchar_t splitChar, unsigned int &argLen); 
     62  arrayBuffer split2arrayBuffer(const std::wstring inBuf, wchar_t splitChar, unsigned int &argLen, bool escape = false); 
     63  std::wstring arrayBuffer2string(wchar_t **argument, const unsigned int argLen, std::wstring join); 
    6564  arrayBuffer createEmptyArrayBuffer(unsigned int &argLen); 
    6665  arrayBuffer createArrayBuffer(unsigned int &argLen); 
     
    7069    for (unsigned int i=0; i<argLen; i++) { 
    7170      size_t s = wcslen(other[i]); 
    72       ret[i] = new TCHAR[s+2]; 
     71      ret[i] = new wchar_t[s+2]; 
    7372      wcsncpy_s(ret[i], s+2, other[i], s); 
    7473    } 
     
    7877#ifdef _DEBUG 
    7978  void test_createEmptyArrayBuffer(); 
    80   void test_split2arrayBuffer_str(std::wstring buffer, TCHAR splitter, int OUT_argLen); 
    81   void test_split2arrayBuffer_char(TCHAR* buffer, TCHAR splitter, int OUT_argLen); 
     79  void test_split2arrayBuffer_str(std::wstring buffer, wchar_t splitter, int OUT_argLen); 
     80  void test_split2arrayBuffer_char(wchar_t* buffer, wchar_t splitter, int OUT_argLen); 
    8281  void run_testArrayBuffer(); 
    8382#endif 
  • trunk/include/charEx.h

    r169 r207  
    2020***************************************************************************/ 
    2121#pragma once 
     22#ifdef WIN32 
    2223#include <windows.h> 
    2324#include <tchar.h> 
     25#endif 
    2426 
    2527namespace charEx { 
     
    3032   * @return a list with strings 
    3133   */ 
    32   inline std::list<std::wstring> split(const TCHAR* buffer, TCHAR split) { 
     34  inline std::list<std::wstring> split(const wchar_t* buffer, wchar_t split) { 
    3335    std::list<std::wstring> ret; 
    34     const TCHAR *start = buffer; 
    35     for (const TCHAR *p = buffer;*p!='\0';p++) { 
     36    const wchar_t *start = buffer; 
     37    for (const wchar_t *p = buffer;*p!='\0';p++) { 
    3638      if (*p==split) { 
    3739        std::wstring str(start, p-start); 
     
    4446  } 
    4547 
    46  
     48/* 
    4749  inline char* tchar_to_char( const wchar_t* pStr, int len, int &nChars) { 
    4850    if (pStr == NULL) 
     
    7880      --nChars; 
    7981    if (nChars == 0) { 
    80       TCHAR *ret = new TCHAR[1]; 
     82      wchar_t *ret = new wchar_t[1]; 
    8183      ret[0] = 0; 
    8284      return ret; 
     
    8486 
    8587    // convert the narrow string to a wide string  
    86     TCHAR *ret = new TCHAR[nChars+1]; 
     88    wchar_t *ret = new wchar_t[nChars+1]; 
    8789    MultiByteToWideChar(CP_ACP, 0 ,pStr ,len, const_cast<wchar_t*>(ret), nChars); 
    8890    return ret; 
    8991  } 
     92*/ 
    9093 
    9194 
    92  
    93   typedef std::pair<std::wstring,TCHAR*> token; 
    94   inline token getToken(TCHAR *buffer, TCHAR split) { 
     95  typedef std::pair<std::wstring,wchar_t*> token; 
     96  inline token getToken(wchar_t *buffer, wchar_t split) { 
    9597    if (buffer == NULL) 
    9698      throw std::exception(); 
    97     TCHAR *p = wcschr(buffer, split); 
     99    wchar_t *p = wcschr(buffer, split); 
    98100    if (!p) 
    99101      return token(buffer, NULL); 
     
    104106  } 
    105107#ifdef _DEBUG 
    106   inline void test_getToken(TCHAR* in1, TCHAR in2, std::wstring out1, TCHAR * out2) { 
     108  inline void test_getToken(wchar_t* in1, wchar_t in2, std::wstring out1, wchar_t * out2) { 
    107109    token t = getToken(in1, in2); 
    108110    std::wcout << _T("charEx::test_getToken(") << in1 << _T(", ") << in2 << _T(") : "); 
  • trunk/include/checkHelpers.hpp

    r201 r207  
    277277    } 
    278278    static std::wstring print(__int64 value) { 
    279       return strEx::itos(value); 
     279      return boost::lexical_cast<std::wstring>(value); 
    280280    } 
    281281    static std::wstring get_perf_unit(__int64 value) { 
     
    283283    } 
    284284    static std::wstring print_perf(__int64 value, std::wstring unit) { 
    285       return strEx::itos(value); 
     285      return boost::lexical_cast<std::wstring>(value); 
    286286    } 
    287287    static std::wstring print_unformated(__int64 value) { 
    288       return strEx::itos(value); 
     288      return boost::lexical_cast<std::wstring>(value); 
    289289    } 
    290290    static std::wstring print_percent(__int64 value) { 
    291       return strEx::itos(value) + _T("%"); 
     291      return boost::lexical_cast<std::wstring>(value) + _T("%"); 
    292292    } 
    293293    static std::wstring key_prefix() { 
  • trunk/include/config.h

    r205 r207  
    2222 
    2323#include "../AutoBuild.h" 
     24/* 
    2425#include <tchar.h>  
     26*/ 
    2527#include <string> 
    2628#include <settings/macros.h> 
     
    197199#define LUA_SCRIPT_SECTION_TITLE _T("LUA Scripts") 
    198200*/ 
    199  
    200 // Main Registry ROOT 
    201 #define NS_HKEY_ROOT HKEY_LOCAL_MACHINE 
    202 #define NS_REG_ROOT _T("SOFTWARE\\NSClient++") 
  • trunk/include/error.hpp

    r201 r207  
    11#pragma once 
    2 #include <tchar.h> 
     2#include <unicode_char.hpp> 
    33#include <string> 
    4 #include <windows.h> 
    54#include <strEx.h> 
    65#include <vector> 
    76 
    8 namespace error { 
    9   class format { 
    10   public: 
    11     static std::wstring from_system(unsigned long dwError) { 
    12       LPVOID lpMsgBuf = NULL; 
    13       unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,NULL,dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,NULL); 
    14       if (dwRet == 0) { 
    15         return _T("failed to lookup error code: ") + strEx::itos(dwError) + _T("( reson: ") + strEx::itos(GetLastError()) + _T(")"); 
    16       } 
    17       TCHAR *szBuf = new TCHAR[dwRet + 100]; 
    18       wsprintf(szBuf, _T("%d: %s"), dwError, lpMsgBuf);  
    19       std::wstring str = szBuf; 
    20       delete [] szBuf; 
    21       LocalFree(lpMsgBuf); 
    22       return str; 
    23     } 
    24     static std::wstring from_module(std::wstring module, unsigned long dwError) { 
    25       LPVOID lpMsgBuf; 
    26       unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_IGNORE_INSERTS, 
    27         GetModuleHandle(module.c_str()),dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,NULL); 
    28       if (dwRet == 0) { 
    29         return _T("failed to lookup error code: ") + strEx::itos(dwError) + _T("( reson: ") + strEx::itos(GetLastError()) + _T(")"); 
    30       } 
    31       TCHAR *szBuf = new TCHAR[dwRet + 100]; 
    32       wsprintf(szBuf, _T("%d: %s"), dwError, lpMsgBuf);  
    33       std::wstring str = szBuf; 
    34       delete [] szBuf; 
    35       LocalFree(lpMsgBuf); 
    36       return str; 
    37     } 
    38     static std::wstring from_module(std::wstring module, unsigned long dwError, DWORD *arguments) { 
    39       LPVOID lpMsgBuf; 
    40       HMODULE hevt = LoadLibraryEx(module.c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES); 
    41       if (hevt == NULL) { 
    42         return _T("failed to load: ") + module + _T("( reson: ") + strEx::itos(GetLastError()) + _T(")"); 
    43       } 
    44       unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ARGUMENT_ARRAY,hevt, 
    45         dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(arguments)); 
    46       if (dwRet == 0) { 
    47         FreeLibrary(hevt); 
    48         return _T("failed to lookup error code: ") + strEx::itos(dwError) + _T(" from DLL: ") + module + _T("( reson: ") + strEx::itos(GetLastError()) + _T(")"); 
    49       } 
    50       TCHAR *szBuf = new TCHAR[dwRet + 100]; 
    51       wsprintf(szBuf, _T("%d: %s"), dwError, lpMsgBuf);  
    52       std::wstring str = szBuf; 
    53       delete [] szBuf; 
    54       LocalFree(lpMsgBuf); 
    55       FreeLibrary(hevt); 
    56       return str; 
    57     } 
    58     class message { 
    59     public: 
    60       static std::wstring from_module(std::wstring module, unsigned long dwError) { 
    61         HMODULE hDLL = LoadLibraryEx(module.c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES); 
    62         if (hDLL == NULL) { 
    63           return _T("failed to load: ") + module + _T("( reson: ") + strEx::itos(GetLastError()) + _T(")"); 
    64         } 
    65         LPVOID lpMsgBuf; 
    66         unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_IGNORE_INSERTS,hDLL, 
    67           dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,NULL); 
    68         if (dwRet == 0) { 
    69           FreeLibrary(hDLL); 
    70           DWORD err = GetLastError(); 
    71           if (err == 317) { 
    72             return _T(""); 
    73           } 
    74           return _T("failed to lookup error code: ") + strEx::itos(dwError) + _T(" from DLL: ") + module + _T("( reson: ") + strEx::itos(err) + _T(")"); 
    75         } 
    76         std::wstring str = reinterpret_cast<TCHAR*>(lpMsgBuf); 
    77         LocalFree(lpMsgBuf); 
    78         FreeLibrary(hDLL); 
    79         return str; 
    80       } 
    81  
    82       static std::wstring from_module_x64(std::wstring module, unsigned long dwError, TCHAR* argList[], DWORD argCount) { 
    83         if (argCount == 0) 
    84           return from_module_wrapper(module, dwError); 
    85         if (argCount == 1) 
    86           return from_module_wrapper(module, dwError, argList[0]); 
    87         if (argCount == 2) 
    88           return from_module_wrapper(module, dwError, argList[0], argList[1]); 
    89         if (argCount == 3) 
    90           return from_module_wrapper(module, dwError, argList[0], argList[1], argList[2]); 
    91         if (argCount == 4) 
    92           return from_module_wrapper(module, dwError, argList[0], argList[1], argList[2], argList[3]); 
    93         if (argCount == 5) 
    94           return from_module_wrapper(module, dwError, argList[0], argList[1], argList[2], argList[3], argList[4]); 
    95         if (argCount == 6) 
    96           return from_module_wrapper(module, dwError, argList[0], argList[1], argList[2], argList[3], argList[4], argList[5]); 
    97         if (argCount == 7) 
    98           return from_module_wrapper(module, dwError, argList[0], argList[1], argList[2], argList[3], argList[4], argList[5], argList[6]); 
    99         if (argCount == 8) 
    100           return from_module_wrapper(module, dwError, argList[0], argList[1], argList[2], argList[3], argList[4], argList[5], argList[6], argList[7]); 
    101         if (argCount == 9) 
    102           return from_module_wrapper(module, dwError, argList[0], argList[1], argList[2], argList[3], argList[4], argList[5], argList[6], argList[7], argList[8]); 
    103         if (argCount == 10) 
    104           return from_module_wrapper(module, dwError, argList[0], argList[1], argList[2], argList[3], argList[4], argList[5], argList[6], argList[7], argList[8], argList[9]); 
    105         if (argCount == 11) 
    106           return from_module_wrapper(module, dwError, argList[0], argList[1], argList[2], argList[3], argList[4], argList[5], argList[6], argList[7], argList[8], argList[9], argList[10]); 
    107         return _T("We cant handle ") + strEx::itos(argCount) + _T(" arguments so you wont get argList here"); 
    108       } 
    109     private: 
    110  
    111       static std::wstring from_module_wrapper(std::wstring module, unsigned long dwError, ...) { 
    112         va_list Ellipsis; 
    113         va_start(Ellipsis, dwError); 
    114         std::wstring ret = __from_module(module, dwError, &Ellipsis); 
    115         va_end(Ellipsis); 
    116         return ret; 
    117       } 
    118  
    119       static std::wstring __from_module(std::wstring module, unsigned long dwError, va_list *arguments) { 
    120         HMODULE hDLL = LoadLibraryEx(module.c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES); 
    121         if (hDLL == NULL) { 
    122           return _T("failed to load: ") + module + _T("( reson: ") + strEx::itos(GetLastError()) + _T(")"); 
    123         } 
    124         LPVOID lpMsgBuf; 
    125  
    126         //unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ARGUMENT_ARRAY,hDLL, 
    127         //  dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(arguments)); 
    128         unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE,hDLL, 
    129           dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(arguments)); 
    130         if (dwRet == 0) { 
    131           FreeLibrary(hDLL); 
    132           DWORD err = GetLastError(); 
    133           if (err == 317) { 
    134             return _T(""); 
    135           } 
    136           return _T("failed to lookup error code: ") + strEx::itos(dwError) + _T(" from DLL: ") + module + _T("( reson: ") + strEx::itos(err) + _T(")"); 
    137         } 
    138         std::wstring str = reinterpret_cast<TCHAR*>(lpMsgBuf); 
    139         LocalFree(lpMsgBuf); 
    140         FreeLibrary(hDLL); 
    141         return str; 
    142       } 
    143     public: 
    144       static std::wstring from_system(unsigned long dwError, DWORD *arguments) { 
    145         LPVOID lpMsgBuf; 
    146         unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ARGUMENT_ARRAY,NULL, 
    147           dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(arguments)); 
    148         if (dwRet == 0) { 
    149           DWORD err = GetLastError(); 
    150           if (err == 317) { 
    151             return _T(""); 
    152           } 
    153           return _T("failed to lookup error code: ") + strEx::itos(dwError) + _T(" from system ( reson: ") + strEx::itos(err) + _T(")"); 
    154         } 
    155         std::wstring str = reinterpret_cast<TCHAR*>(lpMsgBuf); 
    156         LocalFree(lpMsgBuf); 
    157         return str; 
    158       } 
    159     }; 
    160   }; 
    161   class lookup { 
    162   public: 
    163     static std::wstring last_error(unsigned long dwLastError = -1) { 
    164       if (dwLastError == -1) { 
    165         dwLastError = GetLastError(); 
    166       } 
    167       return ::error::format::from_system(dwLastError); 
    168     } 
    169     static std::string last_error_ansi(unsigned long dwLastError = -1) { 
    170       if (dwLastError == -1) { 
    171         dwLastError = GetLastError(); 
    172       } 
    173       return strEx::wstring_to_string(::error::format::from_system(dwLastError)); 
    174     } 
    175   }; 
    176 } 
     7#ifdef WIN32 
     8#include <error_impl_w32.hpp> 
     9#else 
     10#include <error_impl_unix.hpp> 
     11#endif 
  • trunk/include/nrpe/nrpepacket.hpp

    r169 r207  
    148148  unsigned int getBufferLength() const { return getBufferLength(buffer_length_); } 
    149149  static unsigned int getBufferLength(unsigned int buffer_length) { return sizeof(packet)+buffer_length*sizeof(char); } 
     150  unsigned int getInternalBufferLength() const { return buffer_length_; } 
    150151 
    151152 
  • trunk/include/settings/macros.h

    r205 r207  
    11#pragma once 
    22 
    3  
     3#include <unicode_char.hpp> 
    44 
    55#define DEFINE_SETTING_S(name, path, key, value) \ 
     
    3939  setting_keys::key ## _PATH, setting_keys::key, type, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, setting_keys::key ## _DEFAULT, setting_keys::key ## _ADVANCED 
    4040#define SETTINGS_REG_KEY_I_GEN(key, type) \ 
    41   setting_keys::key ## _PATH, setting_keys::key, type, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, strEx::itos(setting_keys::key ## _DEFAULT), setting_keys::key ## _ADVANCED 
     41  setting_keys::key ## _PATH, setting_keys::key, type, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, boost::lexical_cast<std::wstring>(setting_keys::key ## _DEFAULT), setting_keys::key ## _ADVANCED 
    4242#define SETTINGS_REG_KEY_B_GEN(key, type) \ 
    4343  setting_keys::key ## _PATH, setting_keys::key, type, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, setting_keys::key ## _DEFAULT==1?_T("1"):_T("0"), setting_keys::key ## _ADVANCED 
     
    5757#define GENERIC_KEY_OBFUSCATED_PWD "obfuscated password" 
    5858#define GENERIC_KEY_USE_SSL "use ssl" 
     59 
     60 
     61// Main Registry ROOT 
     62#define NS_HKEY_ROOT HKEY_LOCAL_MACHINE 
     63#define NS_REG_ROOT _T("SOFTWARE\\NSClient++") 
    5964 
    6065 
     
    217222    DESCRIBE_SETTING(SYNTAX, "SYNTAX", "Set this to use a specific syntax string for all commands (that don't specify one)."); 
    218223 
    219     DEFINE_SETTING_I(BUFFER_SIZE, EVENT_LOG_SECTION, "buffer_size", 4096); 
     224    DEFINE_SETTING_I(BUFFER_SIZE, EVENT_LOG_SECTION, "buffer_size", 65535); 
    220225    DESCRIBE_SETTING(BUFFER_SIZE, "BUFFER SIZE", "The size of the bugfer to use when getting messages this affects the speed and maximum size of messages you can recieve."); 
    221226  } 
  • trunk/include/settings/settings_old.hpp

    r205 r207  
    55#include <settings/Settings.h> 
    66#include <simpleini/SimpleIni.h> 
     7#include <settings/macros.h> 
    78 
    89#define MAIN_MODULES_SECTION_OLD _T("modules") 
  • trunk/include/settings/settings_registry.hpp

    r202 r207  
    66#include <msvc_wrappers.h> 
    77#include <error.hpp> 
     8#include <settings/macros.h> 
    89#define BUFF_LEN 4096 
    910 
  • trunk/include/strEx.h

    r205 r207  
    2020***************************************************************************/ 
    2121#pragma once 
    22  
    23 #include <tchar.h> 
    24 #include <windows.h> 
     22#include <unicode_char.hpp> 
    2523#include <sstream> 
    2624#include <iomanip> 
     
    3230#include <algorithm> 
    3331#include <locale> 
     32#include <iostream> 
     33#include <string> 
     34#include <locale>  
     35#include <boost/lexical_cast.hpp> 
     36#include <boost/date_time.hpp> 
     37#include <boost/lexical_cast.hpp> 
     38//#include <boost/date_time/local_time/local_date_time.hpp> 
     39//#include <boost/date_time/gregorian/conversion.hpp> 
     40//boost::local_time::local_date_time  
    3441 
    3542 
     
    3845#endif 
    3946 
     47 
     48 
     49 
     50#include <string> 
     51#include <locale> 
     52 
     53namespace boost 
     54{ 
     55  template<> 
     56  inline std::wstring lexical_cast<std::wstring, std::string>(const std::string& arg) 
     57  { 
     58    std::wstring result; 
     59    std::locale loc; 
     60    for(unsigned int i= 0; i < arg.size(); ++i) 
     61    { 
     62      result += std::use_facet<std::ctype<wchar_t> >(loc).widen(arg[i]); 
     63    } 
     64    return result; 
     65  } 
     66 
     67  template<> 
     68  inline std::string lexical_cast<std::string, std::wstring>(const std::wstring& arg) 
     69  { 
     70    std::string result; 
     71    std::locale loc; 
     72    for(unsigned int i= 0; i < arg.size(); ++i) 
     73    { 
     74      result += std::use_facet<std::ctype<wchar_t> >(loc).narrow(arg[i]); 
     75    } 
     76    return result; 
     77  } 
     78} 
    4079namespace strEx { 
    4180  class string_exception : public std::exception { 
     
    4685      return _what; 
    4786    } 
     87    virtual ~string_exception() throw(); 
    4888  }; 
    4989  namespace s { 
     
    72112    lst += append; 
    73113  } 
    74  
     114/* 
    75115  inline std::string wstring_to_string( const wchar_t* pStr, int len) { 
    76116    if (pStr == NULL) 
     
    95135    return buf ;  
    96136  } 
     137  */ 
    97138  inline std::string wstring_to_string( const std::wstring& str ) { 
    98     return wstring_to_string(str.c_str(), static_cast<int>(str.length())); 
    99   } 
    100  
     139    return boost::lexical_cast<std::string>(str) ; 
     140    //return wstring_to_string(str.c_str(), static_cast<int>(str.length())); 
     141  } 
     142/* 
    101143  inline std::wstring string_to_wstring( const char* pStr , int len ) { 
    102144    if (pStr == NULL) 
     
    120162    return buf ; 
    121163  } 
     164  */ 
    122165  inline std::wstring string_to_wstring( const std::string& str ) { 
    123     return string_to_wstring(str.c_str(), static_cast<int>(str.length())) ; 
     166    return boost::lexical_cast<std::wstring>(str) ; 
     167    //return string_to_wstring(str.c_str(), static_cast<int>(str.length())) ; 
    124168  } 
    125169 
     
    164208    return ss.str(); 
    165209  } 
    166  
    167   inline std::wstring format_date(time_t time, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 
    168     TCHAR buf[51]; 
     210  inline std::wstring format_date(boost::posix_time::ptime date, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 
     211    std::locale locale_local (""); 
     212 
     213    boost::gregorian::wdate_facet *date_output = new boost::gregorian::wdate_facet(); 
     214    std::locale locale_adjusted (locale_local, date_output); 
     215 
     216    std::wstringstream date_ss; 
     217    date_ss.imbue(locale_adjusted); 
     218 
     219    date_output->format(format.c_str()); 
     220    date_ss << date; 
     221 
     222    std::wstring ss = date_ss.str(); 
     223    return ss; 
     224  } 
     225 
     226 
     227  inline std::wstring format_date(std::time_t time, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 
     228    return format_date(boost::posix_time::from_time_t(time), format); 
     229    /* 
     230    wchar_t buf[51]; 
    169231    struct tm nt; // = new struct tm; 
    170232#if (_MSC_VER > 1300)  // 1300 == VC++ 7.0 
     
    172234      return _T(""); 
    173235#else 
     236    struct tm nt; // = new struct tm; 
    174237    nt = gmtime(&time); 
    175238    if (nt == NULL) 
     
    181244    buf[l] = 0; 
    182245    return buf; 
    183   } 
     246    */ 
     247  } 
     248  /* 
    184249  inline std::wstring format_date(const SYSTEMTIME &time, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 
    185     TCHAR buf[51]; 
    186  
    187250    struct tm tmTime; 
    188251    memset(&tmTime, 0, sizeof(tmTime)); 
     
    205268  static const __int64 SECS_BETWEEN_EPOCHS = 11644473600; 
    206269  static const __int64 SECS_TO_100NS = 10000000; 
     270  inline std::wstring format_filetime(unsigned long long filetime, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 
     271    filetime -= (SECS_BETWEEN_EPOCHS * SECS_TO_100NS); 
     272    filetime /= SECS_TO_100NS; 
     273    return format_date(static_cast<time_t>(filetime), format); 
     274  } 
     275*/ 
     276  static const __int64 SECS_BETWEEN_EPOCHS = 11644473600; 
     277  static const __int64 SECS_TO_100NS = 10000000; 
     278 
    207279  inline std::wstring format_filetime(unsigned long long filetime, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 
    208280    filetime -= (SECS_BETWEEN_EPOCHS * SECS_TO_100NS); 
     
    222294    } 
    223295  } 
    224   inline std::wstring ctos(TCHAR c) { 
     296  inline std::wstring ctos(wchar_t c) { 
    225297    return std::wstring(1, c); 
    226298  } 
    227   inline TCHAR stoc(std::wstring str) { 
     299  inline wchar_t stoc(std::wstring str) { 
    228300    if (str.length() == 0) 
    229301      return L' '; 
     
    245317    return ss.str(); 
    246318  } 
     319  /* 
    247320  inline std::wstring itos(__int64 i) { 
    248321    std::wstringstream ss; 
     
    250323    return ss.str(); 
    251324  } 
     325  */ 
    252326  inline std::wstring itos(unsigned long i) { 
    253327    std::wstringstream ss; 
     
    284358  } 
    285359  inline int stoi(std::wstring s) { 
    286     return _wtoi(s.c_str()); 
     360    return boost::lexical_cast<int>(s.c_str()); 
    287361  } 
    288362  inline double stod(std::wstring s) { 
    289     return _wtof(s.c_str()); 
     363    return boost::lexical_cast<double>(s.c_str()); 
    290364  } 
    291365  inline long long stoi64(std::wstring s) { 
    292     return _wtoi64(s.c_str()); 
     366    return boost::lexical_cast<long long>(s.c_str()); 
    293367  } 
    294368  inline unsigned stoui_as_time(std::wstring time, unsigned int smallest_unit = 1000) { 
    295369    std::wstring::size_type p = time.find_first_of(_T("sSmMhHdDwW")); 
    296     unsigned int value = _wtoi(time.c_str()); 
     370    unsigned int value = boost::lexical_cast<unsigned int>(time.c_str()); 
    297371    if (p == std::wstring::npos) 
    298372      return value * smallest_unit; 
     
    312386  inline unsigned long long stoi64_as_time(std::wstring time, unsigned int smallest_unit = 1000) { 
    313387    std::wstring::size_type p = time.find_first_of(_T("sSmMhHdDwW")); 
    314     unsigned long long value = _wtoi64(time.c_str()); 
    315388    if (p == std::wstring::npos) 
    316       return value * smallest_unit; 
    317     else if ( (time[p] == 's') || (time[p] == 'S') ) 
     389      return boost::lexical_cast<long long>(time) * smallest_unit; 
     390    unsigned long long value = boost::lexical_cast<long long>(time.substr(0, p)); 
     391    if ( (time[p] == 's') || (time[p] == 'S') ) 
    318392      return value * 1000; 
    319393    else if ( (time[p] == 'm') || (time[p] == 'M') ) 
     
    378452    std::wstring::size_type p = s.find_first_of(_T("BMKGT")); 
    379453    if (p == std::wstring::npos) 
    380       return _wtoi64(s.c_str()); 
     454      return boost::lexical_cast<long long>(s.c_str()); 
    381455    else if (s[p] == 'B')  
    382       return _wtoi64(s.c_str()); 
     456      return boost::lexical_cast<long long>(s.c_str()); 
    383457    else if (s[p] == 'K')  
    384       return _wtoi64(s.c_str())*1024; 
     458      return boost::lexical_cast<long long>(s.c_str())*1024; 
    385459    else if (s[p] == 'M')  
    386       return _wtoi64(s.c_str())*1024*1024; 
     460      return boost::lexical_cast<long long>(s.c_str())*1024*1024; 
    387461    else if (s[p] == 'G')  
    388       return _wtoi64(s.c_str())*1024*1024*1024; 
     462      return boost::lexical_cast<long long>(s.c_str())*1024*1024*1024; 
    389463    else if (s[p] == 'T')  
    390       return _wtoi64(s.c_str())*1024*1024*1024*1024; 
     464      return boost::lexical_cast<long long>(s.c_str())*1024*1024*1024*1024; 
    391465    else 
    392       return _wtoi64(s.c_str()); 
    393   } 
    394 #define BKMG_RANGE "BKMGTP" 
     466      return boost::lexical_cast<long long>(s.c_str()); 
     467  } 
     468#define BKMG_RANGE _T("BKMGTP") 
    395469#define BKMG_SIZE 5 
    396470 
    397   inline std::wstring itos_as_BKMG(unsigned __int64 i) { 
     471  inline std::wstring itos_as_BKMG(unsigned long long i) { 
    398472    double cpy = static_cast<double>(i); 
    399     TCHAR postfix[] = _T(BKMG_RANGE); 
     473    wchar_t postfix[] = BKMG_RANGE; 
    400474    int idx = 0; 
    401475    while ((cpy > 999)&&(idx<BKMG_SIZE)) { 
     
    410484    return ret; 
    411485  } 
    412   inline std::wstring format_BKMG(unsigned __int64 i, std::wstring unit) { 
     486  inline std::wstring format_BKMG(unsigned long long i, std::wstring unit) { 
    413487    double cpy = static_cast<double>(i); 
    414     TCHAR postfix[] = _T(BKMG_RANGE); 
     488    wchar_t postfix[] = BKMG_RANGE; 
    415489    if (unit.length() != 1) 
    416490      return itos(cpy); 
     
    430504    return itos(cpy); 
    431505  } 
    432   inline std::wstring find_proper_unit_BKMG(unsigned __int64 i) { 
     506  inline std::wstring find_proper_unit_BKMG(unsigned long long i) { 
    433507    double cpy = static_cast<double>(i); 
    434     TCHAR postfix[] = _T(BKMG_RANGE); 
     508    wchar_t postfix[] = BKMG_RANGE; 
    435509    int idx = 0; 
    436510    while ((cpy > 999)&&(idx<BKMG_SIZE)) { 
     
    523597 
    524598    //  There's no memichr(), so we roll our own.  It ain't rocket science. 
    525     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) { 
    526600      //  Jerry says that x86s have special mojo for memchr(), so the  
    527601      //  memchr() calls end up being reasonably efficient in practice. 
     
    539613 
    540614    //  I'm reasonably sure that this is eq() for wide characters.  Maybe. 
    541     static bool eq_int_type(const int_type& ch1, const int_type& ch2) {  
    542       return char_traits<_E>::eq_int_type( tolower( ch1 ), tolower( ch2 ) );  
     615    static bool eq_int_type(const long& ch1, const long& ch2) {  
     616      return std::char_traits<_E>::eq_int_type( tolower( ch1 ), tolower( ch2 ) );  
    543617    } 
    544618  }; 
     
    547621  //typedef std::basic_string<char, blind_traits<char>, std::allocator<char> >  blindstr; 
    548622  typedef std::basic_string<wchar_t, blind_traits<wchar_t>, std::allocator<wchar_t> >  blindstr; 
    549  
    550   struct case_blind_string_compare : public std::binary_function<std::wstring, std::wstring, bool> 
    551   { 
    552     bool operator() (const std::wstring& x, const std::wstring& y) const { 
    553       return _wcsicmp( x.c_str(), y.c_str() ) < 0; 
    554     } 
    555   }; 
    556  
    557  
    558623 
    559624  class StrICmp 
     
    596661  } 
    597662 
     663  struct case_blind_string_compare : public std::binary_function<std::wstring, std::wstring, bool> 
     664  { 
     665    bool operator() (const std::wstring& x, const std::wstring& y) const { 
     666      return StrCmpI<std::wstring>(x,y); 
     667      //return _wcsicmp( x.c_str(), y.c_str() ) < 0; 
     668    } 
     669  }; 
    598670 
    599671#ifdef _DEBUG 
     
    635707} 
    636708 
    637  
    638 #include <string> 
    639 #include <locale> 
    640  
    641 #include <boost/lexical_cast.hpp> 
    642  
    643 namespace boost 
    644 { 
    645   template<> 
    646   inline std::wstring lexical_cast<std::wstring, std::string>(const std::string& arg) 
    647   { 
    648     std::wstring result; 
    649     std::locale loc; 
    650     for(unsigned int i= 0; i < arg.size(); ++i) 
    651     { 
    652       result += std::use_facet<std::ctype<wchar_t> >(loc).widen(arg[i]); 
    653     } 
    654     return result; 
    655   } 
    656  
    657   template<> 
    658   inline std::string lexical_cast<std::string, std::wstring>(const std::wstring& arg) 
    659   { 
    660     std::string result; 
    661     std::locale loc; 
    662     for(unsigned int i= 0; i < arg.size(); ++i) 
    663     { 
    664       result += std::use_facet<std::ctype<wchar_t> >(loc).narrow(arg[i]); 
    665     } 
    666     return result; 
     709template <typename T> std::string to_string(const T& arg) { 
     710  try { 
     711    return boost::lexical_cast<std::string>(arg) ; 
     712  } 
     713  catch(boost::bad_lexical_cast& e) { 
     714    return ""; 
    667715  } 
    668716} 
    669  
     717template <typename T> std::wstring to_wstring(const T& arg) { 
     718  try { 
     719    return boost::lexical_cast<std::wstring>(arg) ; 
     720  } 
     721  catch(boost::bad_lexical_cast& e) { 
     722    return _T(""); 
     723  } 
     724} 
  • trunk/modules/CheckDisk/CheckDisk.cpp

    r202 r207  
    680680  unsigned long long now = ((now_.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now_.dwLowDateTime); 
    681681  time_t value = (now-finder.info.ullLastWriteTime)/10000000; 
    682   message = strEx::itos(value/60) + _T("&") + strEx::format_time_delta(gmtime(&value), format); 
     682  message = to_wstring(value/60) + _T("&") + strEx::format_time_delta(gmtime(&value), format); 
    683683  return NSCAPI::returnOK; 
    684684} 
  • trunk/modules/CheckDisk/stdafx.h

    r75 r207  
    3030#include <NSCAPI.h> 
    3131#include <NSCHelper.h> 
     32#include <nsc_module_wrapper.hpp> 
    3233 
    3334#ifdef MEMCHECK 
  • trunk/modules/CheckEventLog/CheckEventLog.cpp

    r205 r207  
    361361    return ret; 
    362362  } 
    363   SYSTEMTIME get_time(DWORD time) { 
     363  // SYSTEMTIME  
     364  boost::posix_time::ptime get_time(DWORD time) { 
    364365    FILETIME FileTime, LocalFileTime; 
    365366    SYSTEMTIME SysTime; 
     
    372373    FileTime.dwHighDateTime = (DWORD)(lgTemp >> 32); 
    373374 
     375    return boost::date_time::time_from_ftime<boost::posix_time::ptime>(FileTime); 
     376 
     377 
     378/* 
    374379    FileTimeToLocalFileTime(&FileTime, &LocalFileTime); 
    375380    FileTimeToSystemTime(&LocalFileTime, &SysTime); 
    376381    return SysTime; 
    377   } 
    378  
    379   SYSTEMTIME get_time_generated() { 
     382    */ 
     383  } 
     384 
     385  boost::posix_time::ptime get_time_generated() { 
    380386    return get_time(pevlr_->TimeGenerated); 
    381387  } 
    382   SYSTEMTIME get_time_written() { 
     388  boost::posix_time::ptime get_time_written() { 
    383389    return get_time(pevlr_->TimeWritten); 
    384390  } 
  • trunk/modules/CheckEventLog/stdafx.h

    r75 r207  
    3434 
    3535#include <NSCAPI.h> 
     36#include <nsc_module_wrapper.hpp> 
    3637#include <NSCHelper.h> 
    3738 
  • trunk/modules/CheckExternalScripts

    • Property svn:ignore
      •  

        old new  
        11*.user 
         2Debug 
  • trunk/modules/CheckExternalScripts/CheckExternalScripts-2005.vcproj

    r202 r207  
    4949        Name="VCCLCompilerTool" 
    5050        AdditionalIncludeDirectories="../include;../../include" 
     51        PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1;USE_BOOST" 
    5152      /> 
    5253      <Tool 
     
    114115        Name="VCCLCompilerTool" 
    115116        AdditionalIncludeDirectories="../include;../../include" 
     117        PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1;USE_BOOST" 
    116118      /> 
    117119      <Tool 
     
    127129        Name="VCLinkerTool" 
    128130        AdditionalDependencies="ws2_32.lib ssleay32.lib libeay32.lib" 
     131      /> 
     132      <Tool 
     133        Name="VCALinkTool" 
     134      /> 
     135      <Tool 
     136        Name="VCManifestTool" 
     137      /> 
     138      <Tool 
     139        Name="VCXDCMakeTool" 
     140      /> 
     141      <Tool 
     142        Name="VCBscMakeTool" 
     143      /> 
     144      <Tool 
     145        Name="VCFxCopTool" 
     146      /> 
     147      <Tool 
     148        Name="VCAppVerifierTool" 
     149      /> 
     150      <Tool 
     151        Name="VCWebDeploymentTool" 
     152      /> 
     153      <Tool 
     154        Name="VCPostBuildEventTool" 
     155      /> 
     156    </Configuration> 
     157    <Configuration 
     158      Name="Debug|Win32" 
     159      OutputDirectory="$(SolutionDir)$(ConfigurationName)" 
     160      IntermediateDirectory="$(ConfigurationName)" 
     161      ConfigurationType="2" 
     162      CharacterSet="1" 
     163      > 
     164      <Tool 
     165        Name="VCPreBuildEventTool" 
     166      /> 
     167      <Tool 
     168        Name="VCCustomBuildTool" 
     169      /> 
     170      <Tool 
     171        Name="VCXMLDataGeneratorTool" 
     172      /> 
     173      <Tool 
     174        Name="VCWebServiceProxyGeneratorTool" 
     175      /> 
     176      <Tool 
     177        Name="VCMIDLTool" 
     178      /> 
     179      <Tool 
     180        Name="VCCLCompilerTool" 
     181        AdditionalIncludeDirectories="../include;../../include" 
     182        PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1;USE_BOOST" 
     183      /> 
     184      <Tool 
     185        Name="VCManagedResourceCompilerTool" 
     186      /> 
     187      <Tool 
     188        Name="VCResourceCompilerTool" 
     189      /> 
     190      <Tool 
     191        Name="VCPreLinkEventTool" 
     192      /> 
     193      <Tool 
     194        Name="VCLinkerTool" 
     195      /> 
     196      <Tool 
     197        Name="VCALinkTool" 
     198      /> 
     199      <Tool 
     200        Name="VCManifestTool" 
     201      /> 
     202      <Tool 
     203        Name="VCXDCMakeTool" 
     204      /> 
     205      <Tool 
     206        Name="VCBscMakeTool" 
     207      /> 
     208      <Tool 
     209        Name="VCFxCopTool" 
     210      /> 
     211      <Tool 
     212        Name="VCAppVerifierTool" 
     213      /> 
     214      <Tool 
     215        Name="VCWebDeploymentTool" 
     216      /> 
     217      <Tool 
     218        Name="VCPostBuildEventTool" 
     219      /> 
     220    </Configuration> 
     221    <Configuration 
     222      Name="Debug|x64" 
     223      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)" 
     224      IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     225      ConfigurationType="2" 
     226      CharacterSet="1" 
     227      > 
     228      <Tool 
     229        Name="VCPreBuildEventTool" 
     230      /> 
     231      <Tool 
     232        Name="VCCustomBuildTool" 
     233      /> 
     234      <Tool 
     235        Name="VCXMLDataGeneratorTool" 
     236      /> 
     237      <Tool 
     238        Name="VCWebServiceProxyGeneratorTool" 
     239      /> 
     240      <Tool 
     241        Name="VCMIDLTool" 
     242      /> 
     243      <Tool 
     244        Name="VCCLCompilerTool" 
     245        AdditionalIncludeDirectories="../include;../../include" 
     246        PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1;USE_BOOST" 
     247      /> 
     248      <Tool 
     249        Name="VCManagedResourceCompilerTool" 
     250      /> 
     251      <Tool 
     252        Name="VCResourceCompilerTool" 
     253      /> 
     254      <Tool 
     255        Name="VCPreLinkEventTool" 
     256      /> 
     257      <Tool 
     258        Name="VCLinkerTool" 
    129259      /> 
    130260      <Tool 
  • trunk/modules/CheckExternalScripts/stdafx.h

    r205 r207  
    3030#include <utils.h> 
    3131 
     32#include <boost/lexical_cast.hpp> 
     33 
    3234#include <NSCAPI.h> 
     35#include <nsc_module_wrapper.hpp> 
    3336#include <NSCHelper.h> 
    3437 
  • trunk/modules/CheckHelpers/stdafx.h

    r75 r207  
    2929 
    3030#include <NSCAPI.h> 
     31#include <nsc_module_wrapper.hpp> 
    3132#include <NSCHelper.h> 
    3233 
  • trunk/modules/CheckSystem/CheckSystem.cpp

    r202 r207  
    365365  } 
    366366  static std::wstring print_perf(__int64 value, std::wstring unit) { 
    367     return strEx::itos(value); 
     367    return to_wstring(value); 
    368368  } 
    369369  static std::wstring print_percent(int value) { 
    370     return strEx::itos(value) + _T("%"); 
     370    return to_wstring(value) + _T("%"); 
    371371  } 
    372372  static std::wstring key_prefix() { 
  • trunk/modules/CheckSystem/stdafx.h

    r75 r207  
    3535#include <list> 
    3636#include <NSCAPI.h> 
     37#include <nsc_module_wrapper.hpp> 
    3738#include <NSCHelper.h> 
    3839#include <config.h> 
  • trunk/modules/CheckTaskSched/stdafx.h

    r130 r207  
    3535#include <NSCAPI.h> 
    3636#include <NSCHelper.h> 
     37#include <nsc_module_wrapper.hpp> 
    3738#include <checkHelpers.hpp> 
    3839#include <filter_framework.hpp> 
  • trunk/modules/CheckWMI/WMIQuery.h

    r201 r207  
    101101    void setString(std::wstring a, std::wstring s) { 
    102102      string = s; 
    103       numeric = strEx::stoi64(s); 
     103      numeric = boost::lexical_cast<long long>(s); 
    104104      alias = a; 
    105105    } 
    106106    void setNumeric(std::wstring a, long long n) { 
    107107      numeric = n; 
    108       string = strEx::itos(n); 
     108      string = to_wstring(n); 
    109109      alias = a; 
    110110    } 
  • trunk/modules/CheckWMI/stdafx.h

    r75 r207  
    3535#include <NSCAPI.h> 
    3636#include <NSCHelper.h> 
     37#include <nsc_module_wrapper.hpp> 
    3738#include <checkHelpers.hpp> 
    3839#include <filter_framework.hpp> 
  • trunk/modules/DebugLogMetrics/stdafx.h

    r201 r207  
    3333#include <NSCAPI.h> 
    3434#include <NSCHelper.h> 
     35#include <nsc_module_wrapper.hpp> 
    3536 
    3637#ifdef MEMCHECK 
  • trunk/modules/FileLogger/stdafx.h

    r75 r207  
    2727#include <NSCAPI.h> 
    2828#include <NSCHelper.h> 
     29#include <nsc_module_wrapper.hpp> 
    2930#include <string> 
    3031#include <iostream> 
  • trunk/modules/LUAScript/stdafx.h

    r88 r207  
    3030#include <NSCAPI.h> 
    3131#include <NSCHelper.h> 
     32#include <nsc_module_wrapper.hpp> 
    3233 
    3334#ifdef MEMCHECK 
  • trunk/modules/NRPEClient/NRPEClient.cpp

    r206 r207  
    186186#endif 
    187187 
    188 using boost::asio::ip::tcp; 
    189188 
    190189int NRPEClient::commandLineExec(const TCHAR* command, const unsigned int argLen, TCHAR** args) { 
     
    246245  } 
    247246} 
     247/* 
    248248NRPEPacket NRPEClient::send_ssl(std::wstring host, int port, int timeout, NRPEPacket packet) 
    249249{ 
     
    251251  return send_nossl(host, port, timeout, packet); 
    252252#else 
     253   
    253254  initSSL(); 
    254255  simpleSSL::Socket socket(true); 
     
    261262  packet.readFrom(buffer.getBuffer(), buffer.getLength()); 
    262263  return packet; 
    263 #endif 
    264 } 
    265  
     264   
     265 
     266  boost::asio::ssl::context ctx(io_service, boost::asio::ssl::context::sslv23); 
     267  ctx.use_tmp_dh_file("d:\\nrpe_512.pem"); 
     268  ctx.set_verify_mode(boost::asio::ssl::context::verify_peer); 
     269  nrpe_ssl_socket socket(io_service, ctx, host, port); 
     270  //socket. 
     271 
     272#endif 
     273} 
     274*/ 
     275using boost::asio::ip::tcp; 
    266276 
    267277void set_result(boost::optional<boost::system::error_code>* a, boost::system::error_code b) 
     
    269279  a->reset(b); 
    270280}  
    271 template <typename MutableBufferSequence> 
    272 void read_with_timeout(tcp::socket& sock, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) 
     281template <typename AsyncReadStream, typename RawSocket, typename MutableBufferSequence> 
     282void read_with_timeout(AsyncReadStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) 
    273283{ 
    274284  boost::optional<boost::system::error_code> timer_result; 
     
    286296      timer.cancel(); 
    287297    else if (timer_result) 
    288       sock.close(); 
     298      rawSocket.close(); 
    289299  } 
    290300 
     
    293303}  
    294304 
     305template <typename AsyncWriteStream, typename RawSocket, typename MutableBufferSequence> 
     306void write_with_timeout(AsyncWriteStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) 
     307{ 
     308  boost::optional<boost::system::error_code> timer_result; 
     309  boost::asio::deadline_timer timer(sock.io_service()); 
     310  timer.expires_from_now(duration); 
     311  timer.async_wait(boost::bind(set_result, &timer_result, _1)); 
     312 
     313  boost::optional<boost::system::error_code> read_result; 
     314  async_write(sock, buffers, boost::bind(set_result, &read_result, _1)); 
     315 
     316  sock.io_service().reset(); 
     317  while (sock.io_service().run_one()) 
     318  { 
     319    if (read_result) 
     320      timer.cancel(); 
     321    else if (timer_result) 
     322      rawSocket.close(); 
     323  } 
     324 
     325  if (*read_result) 
     326    throw boost::system::system_error(*read_result); 
     327} 
     328 
     329class nrpe_socket : public boost::noncopyable { 
     330public: 
     331  tcp::socket socket_; 
     332 
     333public: 
     334  nrpe_socket(boost::asio::io_service &io_service, std::wstring host, int port) : socket_(io_service) { 
     335    NSC_LOG_CRITICAL(_T("Looking up...")); 
     336    tcp::resolver resolver(io_service); 
     337    tcp::resolver::query query(to_string(host), to_string(port)); 
     338    //tcp::resolver::query query("www.medin.name", "80"); 
     339    //tcp::resolver::query query("test_server", "80"); 
     340 
     341    tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); 
     342    tcp::resolver::iterator end; 
     343 
     344    NSC_LOG_CRITICAL(_T("connecting...")); 
     345    boost::system::error_code error = boost::asio::error::host_not_found; 
     346    while (error && endpoint_iterator != end) 
     347    { 
     348      tcp::resolver::endpoint_type ep = *endpoint_iterator; 
     349      NSC_DEBUG_MSG_STD(_T("Attempting to connect to: ") + to_wstring(ep.address().to_string()) + _T(":") + to_wstring(ep.port())); 
     350      socket_.close(); 
     351      socket_.connect(*endpoint_iterator++, error); 
     352    } 
     353    NSC_LOG_CRITICAL(_T("Connected...")); 
     354    if (error) 
     355      throw boost::system::system_error(error); 
     356  } 
     357  ~nrpe_socket() { 
     358    socket_.close(); 
     359  } 
     360 
     361  void send(NRPEPacket &packet, boost::posix_time::seconds timeout) { 
     362    std::vector<char> buf(packet.getBufferLength()); 
     363    write_with_timeout(socket_, socket_, boost::asio::buffer(packet.getBuffer(), packet.getBufferLength()), timeout); 
     364  } 
     365  NRPEPacket recv(const NRPEPacket &packet, boost::posix_time::seconds timeout) { 
     366    std::vector<char> buf(packet.getBufferLength()); 
     367    read_with_timeout(socket_, socket_, boost::asio::buffer(buf), timeout); 
     368    return NRPEPacket(&buf[0], buf.size(), packet.getInternalBufferLength()); 
     369  } 
     370}; 
     371 
     372class nrpe_ssl_socket { 
     373 
     374private: 
     375  boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_; 
     376public: 
     377  nrpe_ssl_socket(boost::asio::io_service &io_service, boost::asio::ssl::context &ctx, std::wstring host, int port) : socket_(io_service, ctx) { 
     378    NSC_LOG_CRITICAL(_T("Looking up...")); 
     379    tcp::resolver resolver(io_service); 
     380    //tcp::resolver::query query(to_string(host), to_string(port)); 
     381    tcp::resolver::query query("www.medin.name", "80"); 
     382    //tcp::resolver::query query("test_server", "80"); 
     383 
     384    tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); 
     385    tcp::resolver::iterator end; 
     386 
     387    boost::system::error_code error = boost::asio::error::host_not_found; 
     388    NSC_LOG_CRITICAL(_T("Connecting...")); 
     389    while (error && endpoint_iterator != end) 
     390    { 
     391      tcp::resolver::endpoint_type ep = *endpoint_iterator; 
     392      NSC_DEBUG_MSG_STD(_T("Attempting to connect to: ") + to_wstring(ep.address().to_string()) + _T(":") + to_wstring(ep.port())); 
     393      socket_.lowest_layer().close(); 
     394      socket_.lowest_layer().connect(*endpoint_iterator++, error); 
     395    } 
     396    if (error) 
     397      throw boost::system::system_error(error); 
     398    NSC_LOG_CRITICAL(_T("Connected...")); 
     399 
     400    NSC_LOG_CRITICAL(_T("Handshaking...")); 
     401    //socket_.handshake(boost::asio::ssl::stream_base::client); 
     402    socket_.handshake(boost::asio::ssl::stream_base::client); 
     403    NSC_LOG_CRITICAL(_T("Handshook...") + strEx::itos(error.value())); 
     404 
     405  } 
     406 
     407  void send(NRPEPacket &packet, boost::posix_time::seconds timeout) { 
     408    NSC_LOG_CRITICAL(_T("Writing...")); 
     409    std::vector<char> buf(packet.getBufferLength()); 
     410    write_with_timeout(socket_, socket_.lowest_layer(), boost::asio::buffer(packet.getBuffer(), packet.getBufferLength()), timeout); 
     411    NSC_LOG_CRITICAL(_T("Written...")); 
     412  } 
     413  NRPEPacket recv(const NRPEPacket &packet, boost::posix_time::seconds timeout) { 
     414    NSC_LOG_CRITICAL(_T("Reading...")); 
     415    std::vector<char> buf(packet.getBufferLength()); 
     416    read_with_timeout(socket_, socket_.lowest_layer(), boost::asio::buffer(buf), timeout); 
     417    return NRPEPacket(&buf[0], buf.size(), packet.getInternalBufferLength()); 
     418    NSC_LOG_CRITICAL(_T("Read...")); 
     419  } 
     420}; 
     421 
    295422NRPEPacket NRPEClient::send_nossl(std::wstring host, int port, int timeout, NRPEPacket packet) 
    296423{ 
    297424  boost::asio::io_service io_service; 
    298   tcp::resolver resolver(io_service); 
    299 //  tcp::resolver::query query("127.0.0.1", boost::lexical_cast<std::string>(port)); 
    300   tcp::resolver::query query("www.medin.name", "80"); 
    301  
    302   tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); 
    303   tcp::resolver::iterator end; 
    304  
    305   tcp::socket socket(io_service); 
    306   boost::system::error_code error = boost::asio::error::host_not_found; 
    307   while (error && endpoint_iterator != end) 
    308   { 
    309     tcp::resolver::endpoint_type ep = *endpoint_iterator; 
    310     NSC_DEBUG_MSG_STD(_T("Connectiing to: ") + boost::lexical_cast<std::wstring>(ep.address().to_string()) + _T(":") + boost::lexical_cast<std::wstring>(ep.port())); 
    311     socket.close(); 
    312     socket.connect(*endpoint_iterator++, error); 
    313   } 
    314   if (error) 
    315     throw boost::system::system_error(error); 
    316  
    317   //for (;;) 
    318   { 
    319     std::vector<char> buf(packet.getBufferLength()); 
    320     boost::system::error_code error; 
    321  
    322     size_t len = socket.write_some(boost::asio::buffer(packet.getBuffer(), packet.getBufferLength()), error); 
    323     NSC_DEBUG_MSG_STD(_T("Error: ") + strEx::itos(error.value()) + _T(" wrote: ") + strEx::itos(len)); 
    324  
    325     read_with_timeout(socket, boost::asio::buffer(buf), boost::posix_time::seconds(5) ); 
    326     //len = socket.read_some(boost::asio::buffer(buf), error); 
    327     NSC_DEBUG_MSG_STD(_T("Error: ") + strEx::itos(error.value()) + _T(" read: ") + strEx::itos(len)); 
    328  
    329     if (error == boost::asio::error::eof) 
    330       ;//break; // Connection closed cleanly by peer. 
    331     else if (error) 
    332       throw boost::system::system_error(error); // Some other error. 
    333     packet.readFrom(&buf[0], buf.size()); 
    334   } 
    335  
    336  
    337  
     425  nrpe_socket socket(io_service, host, port); 
     426  socket.send(packet, boost::posix_time::seconds(timeout)); 
     427  return socket.recv(packet, boost::posix_time::seconds(timeout)); 
     428} 
     429 
     430NRPEPacket NRPEClient::send_ssl(std::wstring host, int port, int timeout, NRPEPacket packet) 
     431{ 
     432  boost::asio::io_service io_service; 
     433  boost::asio::ssl::context ctx(io_service, boost::asio::ssl::context::sslv23); 
     434  SSL_CTX_set_cipher_list(ctx.impl(), "ADH"); 
     435  ctx.use_tmp_dh_file("d:\\nrpe_512.pem"); 
     436  ctx.set_verify_mode(boost::asio::ssl::context::verify_none); 
     437  nrpe_ssl_socket socket(io_service, ctx, host, port); 
     438  socket.send(packet, boost::posix_time::seconds(timeout)); 
     439  return socket.recv(packet, boost::posix_time::seconds(timeout)); 
     440} 
    338441/* 
    339   simpleSocket::Socket socket(true); 
    340   socket.connect(host, port); 
    341   socket.sendAll(packet.getBuffer(), packet.getBufferLength()); 
    342   simpleSocket::DataBuffer buffer; 
    343   socket.readAll(buffer); 
    344   packet.readFrom(buffer.getBuffer(), buffer.getLength()); 
    345   */ 
    346   return packet; 
    347 } 
    348  
     442NRPEPacket NRPEClient::send_nossl(std::wstring host, int port, int timeout, NRPEPacket packet) 
     443{ 
     444  unsigned char dh512_p[] = { 
     445    0xCF, 0xFF, 0x65, 0xC2, 0xC8, 0xB4, 0xD2, 0x68, 0x8C, 0xC1, 0x80, 0xB1, 
     446    0x7B, 0xD6, 0xE8, 0xB3, 0x62, 0x59, 0x62, 0xED, 0xA7, 0x45, 0x6A, 0xF8, 
     447    0xE9, 0xD8, 0xBE, 0x3F, 0x38, 0x42, 0x5F, 0xB2, 0xA5, 0x36, 0x03, 0xD3, 
     448    0x06, 0x27, 0x81, 0xC8, 0x9B, 0x88, 0x50, 0x3B, 0x82, 0x3D, 0x31, 0x45, 
     449    0x2C, 0xB4, 0xC5, 0xA5, 0xBE, 0x6A, 0xE3, 0x2E, 0xA6, 0x86, 0xFD, 0x6A, 
     450    0x7E, 0x1E, 0x6A, 0x73, 
     451  }; 
     452  unsigned char dh512_g[] = { 0x02, }; 
     453 
     454  DH *dh_2 = DH_new(); 
     455  dh_2->p = BN_bin2bn(dh512_p, sizeof(dh512_p), NULL); 
     456  dh_2->g = BN_bin2bn(dh512_g, sizeof(dh512_g), NULL); 
     457 
     458  FILE *outfile = fopen("d:\\nrpe_512.pem", "w"); 
     459  PEM_write_DHparams(outfile, dh_2); 
     460  PEM_write_DHparams(stdout, dh_2); 
     461  fclose(outfile); 
     462 
     463  nrpe_socket socket(host, port); 
     464  socket.send(packet, boost::posix_time::seconds(timeout)); 
     465  return socket.recv(packet, boost::posix_time::seconds(timeout)); 
     466} 
     467*/ 
    349468 
    350469 
  • trunk/modules/NRPEClient/stdafx.h

    r206 r207  
    3636#include <NSCAPI.h> 
    3737#include <NSCHelper.h> 
     38#include <nsc_module_wrapper.hpp> 
    3839 
    3940#include <boost/array.hpp> 
    40 #include <boost/date_time/posix_time/posix_time.hpp> 
    4141#include <boost/asio.hpp> 
     42#include <boost/optional.hpp> 
    4243#include <boost/bind.hpp> 
     44#include <boost/asio/ssl.hpp> 
    4345 
    4446#ifdef MEMCHECK 
  • trunk/modules/NRPEListener/stdafx.h

    r75 r207  
    3333#include <NSCAPI.h> 
    3434#include <NSCHelper.h> 
     35#include <nsc_module_wrapper.hpp> 
    3536 
    3637#ifdef MEMCHECK 
  • trunk/modules/NSCAAgent/stdafx.h

    r87 r207  
    3636#include <NSCAPI.h> 
    3737#include <NSCHelper.h> 
     38#include <nsc_module_wrapper.hpp> 
    3839#include <config.h> 
    3940#include <utils.h> 
  • trunk/modules/NSClientListener/stdafx.h

    r75 r207  
    3030#include <NSCAPI.h> 
    3131#include <NSCHelper.h> 
     32#include <nsc_module_wrapper.hpp> 
    3233 
    3334#ifdef MEMCHECK 
  • trunk/modules/SysTray/stdafx.h

    r75 r207  
    2727#include <string> 
    2828#include <NSCHelper.h> 
     29#include <nsc_module_wrapper.hpp> 
    2930#include <assert.h> 
    3031 
  • trunk/service/NSCPlugin.cpp

    r205 r207  
    3131 */ 
    3232NSCPlugin::NSCPlugin(const std::wstring file) 
    33   : file_(file) 
    34   ,hModule_(NULL) 
     33  : module_(file) 
    3534  ,fLoadModule(NULL) 
    3635  ,fGetName(NULL) 
     
    5049{ 
    5150} 
    52  
     51/* 
    5352NSCPlugin::NSCPlugin(NSCPlugin &other) 
    54   :hModule_(NULL) 
     53  :module_() 
    5554  ,fLoadModule(NULL) 
    5655  ,fGetName(NULL) 
     
    8079  } 
    8180} 
    82  
     81*/ 
    8382/** 
    8483 * Default d-tor 
     
    9695 */ 
    9796std::wstring NSCPlugin::getName() { 
    98   TCHAR *buffer = new TCHAR[1024]; 
     97  wchar_t *buffer = new wchar_t[1024]; 
    9998  if (!getName_(buffer, 1023)) { 
    10099    return _T("Could not get name"); 
     
    105104} 
    106105std::wstring NSCPlugin::getDescription() { 
    107   TCHAR *buffer = new TCHAR[4096]; 
     106  wchar_t *buffer = new wchar_t[4096]; 
    108107  if (!getDescription_(buffer, 4095)) { 
    109     throw NSPluginException(file_, _T("Could not get description")); 
     108    throw NSPluginException(module_, _T("Could not get description")); 
    110109  } 
    111110  std::wstring ret = buffer; 
     
    121120 */ 
    122121void NSCPlugin::load_dll() { 
    123   if (isLoaded()) 
    124     throw NSPluginException(file_, _T("Module already loaded")); 
    125   hModule_ = LoadLibrary(file_.c_str()); 
    126   if (!hModule_) 
    127     throw NSPluginException(file_, _T("Could not load library: ") + error::lookup::last_error() + _T(" for file: ") + file_); 
     122  if (module_.is_loaded()) 
     123    throw NSPluginException(module_, _T("Module already loaded")); 
     124  try { 
     125    module_.load_library(); 
     126  } catch (dll::dll_exception &e) { 
     127    throw NSPluginException(module_, e.what()); 
     128  } 
    128129  loadRemoteProcs_(); 
    129130  bLoaded_ = true; 
     
    132133bool NSCPlugin::load_plugin(NSCAPI::moduleLoadMode mode) { 
    133134  if (!fLoadModule) 
    134     throw NSPluginException(file_, _T("Critical error (fLoadModule)")); 
     135    throw NSPluginException(module_, _T("Critical error (fLoadModule)")); 
    135136  return fLoadModule(mode); 
    136137} 
     
    156157bool NSCPlugin::getVersion(int *major, int *minor, int *revision) { 
    157158  if (!isLoaded()) 
    158     throw NSPluginException(file_, _T("Library is not loaded")); 
     159    throw NSPluginException(module_, _T("Library is not loaded")); 
    159160  if (!fGetVersion) 
    160     throw NSPluginException(file_, _T("Critical error (fGetVersion)")); 
     161    throw NSPluginException(module_, _T("Critical error (fGetVersion)")); 
    161162  try { 
    162163    return fGetVersion(major, minor, revision)?true:false; 
    163164  } catch (...) { 
    164     throw NSPluginException(file_, _T("Unhandled exception in getVersion.")); 
     165    throw NSPluginException(module_, _T("Unhandled exception in getVersion.")); 
    165166  } 
    166167} 
     
    172173bool NSCPlugin::hasCommandHandler() { 
    173174  if (!isLoaded()) 
    174     throw NSPluginException(file_, _T("Module not loaded")); 
     175    throw NSPluginException(module_, _T("Module not loaded")); 
    175176  try { 
    176177    if (fHasCommandHandler()) 
     
    178179    return false; 
    179180  } catch (...) { 
    180     throw NSPluginException(file_, _T("Unhandled exception in hasCommandHandler.")); 
     181    throw NSPluginException(module_, _T("Unhandled exception in hasCommandHandler.")); 
    181182  } 
    182183} 
     
    188189bool NSCPlugin::hasMessageHandler() { 
    189190  if (!isLoaded()) 
    190     throw NSPluginException(file_, _T("Module not loaded")); 
     191    throw NSPluginException(module_, _T("Module not loaded")); 
    191192  try { 
    192193    if (fHasMessageHandler()) { 
     
    196197    return false; 
    197198  } catch (...) { 
    198     throw NSPluginException(file_, _T("Unhandled exception in hasMessageHandler.")); 
     199    throw NSPluginException(module_, _T("Unhandled exception in hasMessageHandler.")); 
    199200  } 
    200201} 
     
    214215 * @throws NSPluginException if the module is not loaded. 
    215216 */ 
    216 NSCAPI::nagiosReturn NSCPlugin::handleCommand(const TCHAR* command, const unsigned int argLen, TCHAR **arguments, TCHAR* returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR* returnPerfBuffer, unsigned int returnPerfBufferLen) { 
    217   if (!isLoaded()) 
    218     throw NSPluginException(file_, _T("Library is not loaded")); 
     217NSCAPI::nagiosReturn NSCPlugin::handleCommand(const wchar_t* command, const unsigned int argLen, wchar_t **arguments, wchar_t* returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR* returnPerfBuffer, unsigned int returnPerfBufferLen) { 
     218  if (!isLoaded()) 
     219    throw NSPluginException(module_, _T("Library is not loaded")); 
    219220  try { 
    220221    return fHandleCommand(command, argLen, arguments, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 
    221222  } catch (...) { 
    222     throw NSPluginException(file_, _T("Unhandled exception in handleCommand.")); 
     223    throw NSPluginException(module_, _T("Unhandled exception in handleCommand.")); 
    223224  } 
    224225} 
     
    232233 * @throws NSPluginException if the module is not loaded. 
    233234 */ 
    234 void NSCPlugin::handleMessage(int msgType, const TCHAR* file, const int line, const TCHAR *message) { 
     235void NSCPlugin::handleMessage(int msgType, const wchar_t* file, const int line, const wchar_t *message) { 
    235236  if (!fHandleMessage) 
    236     throw NSPluginException(file_, _T("Library is not loaded")); 
     237    throw NSPluginException(module_, _T("Library is not loaded")); 
    237238  try { 
    238239    fHandleMessage(msgType, file, line, message); 
    239240  } catch (...) { 
    240     throw NSPluginException(file_, _T("Unhandled exception in handleMessage.")); 
     241    throw NSPluginException(module_, _T("Unhandled exception in handleMessage.")); 
    241242  } 
    242243} 
     
    247248void NSCPlugin::unload() { 
    248249  if (!isLoaded()) 
    249     throw NSPluginException(file_, _T("Library is not loaded")); 
     250    throw NSPluginException(module_, _T("Library is not loaded")); 
     251  bLoaded_ = false; 
    250252  if (!fUnLoadModule) 
    251     throw NSPluginException(file_, _T("Critical error (fUnLoadModule)")); 
     253    throw NSPluginException(module_, _T("Critical error (fUnLoadModule)")); 
    252254  try { 
    253255    fUnLoadModule(); 
    254256  } catch (...) { 
    255     throw NSPluginException(file_, _T("Unhandled exception in handleMessage.")); 
    256   } 
    257   FreeLibrary(hModule_); 
    258   hModule_ = NULL; 
    259   bLoaded_ = false; 
    260 } 
    261 bool NSCPlugin::getName_(TCHAR* buf, unsigned int buflen) { 
     257    throw NSPluginException(module_, _T("Unhandled exception in handleMessage.")); 
     258  } 
     259  module_.unload_library(); 
     260} 
     261bool NSCPlugin::getName_(wchar_t* buf, unsigned int buflen) { 
    262262  if (fGetName == NULL) 
    263     return false;//throw NSPluginException(file_, _T("Critical error (fGetName)")); 
     263    return false;//throw NSPluginException(module_, _T("Critical error (fGetName)")); 
    264264  try { 
    265265    return fGetName(buf, buflen)?true:false; 
    266266  } catch (...) { 
    267     return false; //throw NSPluginException(file_, _T("Unhandled exception in getName.")); 
    268   } 
    269 } 
    270 bool NSCPlugin::getDescription_(TCHAR* buf, unsigned int buflen) { 
     267    return false; //throw NSPluginException(module_, _T("Unhandled exception in getName.")); 
     268  } 
     269} 
     270bool NSCPlugin::getDescription_(wchar_t* buf, unsigned int buflen) { 
    271271  if (fGetDescription == NULL) 
    272     throw NSPluginException(file_, _T("Critical error (fGetDescription)")); 
     272    throw NSPluginException(module_, _T("Critical error (fGetDescription)")); 
    273273  try { 
    274274    return fGetDescription(buf, buflen)?true:false; 
    275275  } catch (...) { 
    276     throw NSPluginException(file_, _T("Unhandled exception in getDescription.")); 
     276    throw NSPluginException(module_, _T("Unhandled exception in getDescription.")); 
    277277  } 
    278278} 
     
    280280void NSCPlugin::showTray() { 
    281281  if (fShowTray == NULL) 
    282     throw NSPluginException(file_, _T("Critical error (ShowTray)")); 
     282    throw NSPluginException(module_, _T("Critical error (ShowTray)")); 
    283283  try { 
    284284    fShowTray(); 
    285285  } catch (...) { 
    286     throw NSPluginException(file_, _T("Unhandled exception in ShowTray.")); 
     286    throw NSPluginException(module_, _T("Unhandled exception in ShowTray.")); 
    287287  } 
    288288} 
    289289void NSCPlugin::hideTray() { 
    290290  if (fHideTray == NULL) 
    291     throw NSPluginException(file_, _T("Critical error (HideTray)")); 
     291    throw NSPluginException(module_, _T("Critical error (HideTray)")); 
    292292  try { 
    293293    fHideTray(); 
    294294  } catch (...) { 
    295     throw NSPluginException(file_, _T("Unhandled exception in HideTray.")); 
     295    throw NSPluginException(module_, _T("Unhandled exception in HideTray.")); 
    296296  } 
    297297} 
     
    305305void NSCPlugin::loadRemoteProcs_(void) { 
    306306 
    307   fLoadModule = (lpLoadModule)GetProcAddress(hModule_, "NSLoadModule"); 
     307  fLoadModule = (lpLoadModule)module_.load_proc("NSLoadModule"); 
    308308  if (!fLoadModule) 
    309     throw NSPluginException(file_, _T("Could not load NSLoadModule")); 
    310  
    311   fModuleHelperInit = (lpModuleHelperInit)GetProcAddress(hModule_, "NSModuleHelperInit"); 
     309    throw NSPluginException(module_, _T("Could not load NSLoadModule")); 
     310 
     311  fModuleHelperInit = (lpModuleHelperInit)module_.load_proc("NSModuleHelperInit"); 
    312312  if (!fModuleHelperInit) 
    313     throw NSPluginException(file_, _T("Could not load NSModuleHelperInit")); 
     313    throw NSPluginException(module_, _T("Could not load NSModuleHelperInit")); 
    314314 
    315315  try { 
    316316    fModuleHelperInit(NSAPILoader); 
    317317  } catch (...) { 
    318     throw NSPluginException(file_, _T("Unhandled exception in getDescription.")); 
     318    throw NSPluginException(module_, _T("Unhandled exception in getDescription.")); 
    319319  } 
    320320   
    321   fGetName = (lpGetName)GetProcAddress(hModule_, "NSGetModuleName"); 
     321  fGetName = (lpGetName)module_.load_proc("NSGetModuleName"); 
    322322  if (!fGetName) 
    323     throw NSPluginException(file_, _T("Could not load NSGetModuleName")); 
    324  
    325   fGetVersion = (lpGetVersion)GetProcAddress(hModule_, "NSGetModuleVersion"); 
     323    throw NSPluginException(module_, _T("Could not load NSGetModuleName")); 
     324 
     325  fGetVersion = (lpGetVersion)module_.load_proc("NSGetModuleVersion"); 
    326326  if (!fGetVersion) 
    327     throw NSPluginException(file_, _T("Could not load NSGetModuleVersion")); 
    328  
    329   fGetDescription = (lpGetDescription)GetProcAddress(hModule_, "NSGetModuleDescription"); 
     327    throw NSPluginException(module_, _T("Could not load NSGetModuleVersion")); 
     328 
     329  fGetDescription = (lpGetDescription)module_.load_proc("NSGetModuleDescription"); 
    330330  if (!fGetDescription) 
    331     throw NSPluginException(file_, _T("Could not load NSGetModuleDescription")); 
    332  
    333   fHasCommandHandler = (lpHasCommandHandler)GetProcAddress(hModule_, "NSHasCommandHandler"); 
     331    throw NSPluginException(module_, _T("Could not load NSGetModuleDescription")); 
     332 
     333  fHasCommandHandler = (lpHasCommandHandler)module_.load_proc("NSHasCommandHandler"); 
    334334  if (!fHasCommandHandler) 
    335     throw NSPluginException(file_, _T("Could not load NSHasCommandHandler")); 
    336  
    337   fHasMessageHandler = (lpHasMessageHandler)GetProcAddress(hModule_, "NSHasMessageHandler"); 
     335    throw NSPluginException(module_, _T("Could not load NSHasCommandHandler")); 
     336 
     337  fHasMessageHandler = (lpHasMessageHandler)module_.load_proc("NSHasMessageHandler"); 
    338338  if (!fHasMessageHandler) 
    339     throw NSPluginException(file_, _T("Could not load NSHasMessageHandler")); 
    340  
    341   fHandleCommand = (lpHandleCommand)GetProcAddress(hModule_, "NSHandleCommand"); 
     339    throw NSPluginException(module_, _T("Could not load NSHasMessageHandler")); 
     340 
     341  fHandleCommand = (lpHandleCommand)module_.load_proc("NSHandleCommand"); 
    342342  if (!fHandleCommand) 
    343     throw NSPluginException(file_, _T("Could not load NSHandleCommand")); 
    344  
    345   fHandleMessage = (lpHandleMessage)GetProcAddress(hModule_, "NSHandleMessage"); 
     343    throw NSPluginException(module_, _T("Could not load NSHandleCommand")); 
     344 
     345  fHandleMessage = (lpHandleMessage)module_.load_proc("NSHandleMessage"); 
    346346  if (!fHandleMessage) 
    347     throw NSPluginException(file_, _T("Could not load NSHandleMessage")); 
    348  
    349   fUnLoadModule = (lpUnLoadModule)GetProcAddress(hModule_, "NSUnloadModule"); 
     347    throw NSPluginException(module_, _T("Could not load NSHandleMessage")); 
     348 
     349  fUnLoadModule = (lpUnLoadModule)module_.load_proc("NSUnloadModule"); 
    350350  if (!fUnLoadModule) 
    351     throw NSPluginException(file_, _T("Could not load NSUnloadModule")); 
    352  
    353   fGetConfigurationMeta = (lpGetConfigurationMeta)GetProcAddress(hModule_, "NSGetConfigurationMeta"); 
    354   fCommandLineExec = (lpCommandLineExec)GetProcAddress(hModule_, "NSCommandLineExec"); 
    355  
    356   fShowTray = (lpShowTray)GetProcAddress(hModule_, "ShowIcon"); 
    357   fHideTray = (lpHideTray)GetProcAddress(hModule_, "HideIcon"); 
     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"); 
    358358 
    359359} 
     
    362362std::wstring NSCPlugin::getCongifurationMeta()  
    363363{ 
    364   TCHAR *buffer = new TCHAR[4097]; 
     364  wchar_t *buffer = new wchar_t[4097]; 
    365365  if (!getConfigurationMeta_(buffer, 4096)) { 
    366     throw NSPluginException(file_, _T("Could not get metadata")); 
     366    throw NSPluginException(module_, _T("Could not get metadata")); 
    367367  } 
    368368  std::wstring ret = buffer; 
     
    370370  return ret; 
    371371} 
    372 bool NSCPlugin::getConfigurationMeta_(TCHAR* buf, unsigned int buflen) { 
     372bool NSCPlugin::getConfigurationMeta_(wchar_t* buf, unsigned int buflen) { 
    373373  if (fGetConfigurationMeta == NULL) 
    374     throw NSPluginException(file_, _T("Critical error (getCongifurationMeta)")); 
     374    throw NSPluginException(module_, _T("Critical error (getCongifurationMeta)")); 
    375375  try { 
    376376    return fGetConfigurationMeta(buflen, buf)?true:false; 
    377377  } catch (...) { 
    378     throw NSPluginException(file_, _T("Unhandled exception in getConfigurationMeta.")); 
    379   } 
    380 } 
    381  
    382 int NSCPlugin::commandLineExec(const TCHAR* command, const unsigned int argLen, TCHAR **arguments) { 
     378    throw NSPluginException(module_, _T("Unhandled exception in getConfigurationMeta.")); 
     379  } 
     380} 
     381 
     382int NSCPlugin::commandLineExec(const wchar_t* command, const unsigned int argLen, wchar_t **arguments) { 
    383383  if (fCommandLineExec== NULL) 
    384     throw NSPluginException(file_, _T("Module does not support CommandLineExec")); 
     384    throw NSPluginException(module_, _T("Module does not support CommandLineExec")); 
    385385  try { 
    386386    return fCommandLineExec(command, argLen, arguments); 
    387387  } catch (...) { 
    388     throw NSPluginException(file_, _T("Unhandled exception in commandLineExec.")); 
    389   } 
    390 } 
     388    throw NSPluginException(module_, _T("Unhandled exception in commandLineExec.")); 
     389  } 
     390} 
  • trunk/service/NSCPlugin.h

    r202 r207  
    2222 
    2323#include <NSCAPI.h> 
    24 #include <NSCHelper.h> 
     24//#include <NSCHelper.h> 
    2525#include <sstream> 
     26#include <dll/dll.hpp> 
    2627 
    2728/** 
     
    5859   * @param error An error message (human readable format) 
    5960   */ 
    60   NSPluginException(std::wstring file, std::wstring error) : error_(error) { 
    61     file_ = getModule(file); 
     61  NSPluginException(dll::dll &module, std::wstring error) : error_(error) { 
     62    file_ = getModule(module.get_file()); 
    6263  } 
    6364  std::wstring getModule(std::wstring file) { 
     
    105106private: 
    106107  bool bLoaded_;      // Status of plug in 
    107   HMODULE hModule_;   // module handle to the DLL (once it is loaded) 
    108   std::wstring file_;   // Name of the DLL file 
     108  dll::dll module_; 
    109109  bool broken_; 
    110110 
    111   typedef INT (*lpModuleHelperInit)(NSCModuleHelper::lpNSAPILoader f); 
    112   typedef INT (*lpLoadModule)(int); 
    113   typedef INT (*lpGetName)(TCHAR*,unsigned int); 
    114   typedef INT (*lpGetDescription)(TCHAR*,unsigned int); 
    115   typedef INT (*lpGetVersion)(int*,int*,int*); 
    116   typedef INT (*lpHasCommandHandler)(); 
    117   typedef INT (*lpHasMessageHandler)(); 
    118   typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const TCHAR*,const unsigned int, TCHAR**,TCHAR*,unsigned int,TCHAR *,unsigned int); 
    119   typedef INT (*lpCommandLineExec)(const TCHAR*,const unsigned int,TCHAR**); 
    120   typedef INT (*lpHandleMessage)(int,const TCHAR*,const int,const TCHAR*); 
    121   typedef INT (*lpUnLoadModule)(); 
    122   typedef INT (*lpGetConfigurationMeta)(int, TCHAR*); 
     111  typedef int (*lpModuleHelperInit)(NSCModuleHelper::lpNSAPILoader f); 
     112  typedef int (*lpLoadModule)(int); 
     113  typedef int (*lpGetName)(wchar_t*,unsigned int); 
     114  typedef int (*lpGetDescription)(wchar_t*,unsigned int); 
     115  typedef int (*lpGetVersion)(int*,int*,int*); 
     116  typedef int (*lpHasCommandHandler)(); 
     117  typedef int (*lpHasMessageHandler)(); 
     118  typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const wchar_t*,const unsigned int, wchar_t**,wchar_t*,unsigned int,wchar_t *,unsigned int); 
     119  typedef int (*lpCommandLineExec)(const wchar_t*,const unsigned int,wchar_t**); 
     120  typedef int (*lpHandleMessage)(int,const wchar_t*,const int,const wchar_t*); 
     121  typedef int (*lpUnLoadModule)(); 
     122  typedef int (*lpGetConfigurationMeta)(int, wchar_t*); 
    123123  typedef void (*lpShowTray)(); 
    124124  typedef void (*lpHideTray)(); 
     
    154154  bool hasCommandHandler(void); 
    155155  bool hasMessageHandler(void); 
    156   NSCAPI::nagiosReturn handleCommand(const TCHAR *command, const unsigned int argLen, TCHAR **arguments, TCHAR* returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR* returnPerfBuffer, unsigned int returnPerfBufferLen); 
    157   void handleMessage(int msgType, const TCHAR* file, const int line, const TCHAR *message); 
     156  NSCAPI::nagiosReturn handleCommand(const wchar_t *command, const unsigned int argLen, wchar_t **arguments, wchar_t* returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR* returnPerfBuffer, unsigned int returnPerfBufferLen); 
     157  void handleMessage(int msgType, const wchar_t* file, const int line, const wchar_t *message); 
    158158  void unload(void); 
    159159  std::wstring getCongifurationMeta(); 
    160   int commandLineExec(const TCHAR* command, const unsigned int argLen, TCHAR **arguments); 
     160  int commandLineExec(const wchar_t* command, const unsigned int argLen, wchar_t **arguments); 
    161161  void showTray(); 
    162162  void hideTray(); 
    163163 
    164164  std::wstring getFilename() { 
    165     if (file_.empty()) 
     165    std::wstring file = module_.get_file(); 
     166    if (file.empty()) 
    166167      return _T(""); 
    167     std::wstring::size_type pos = file_.find_last_of(_T("\\")); 
    168     if (pos != std::wstring::npos && ++pos < file_.length()) { 
    169       return file_.substr(pos); 
     168    std::wstring::size_type pos = file.find_last_of(_T("\\")); 
     169    if (pos != std::wstring::npos && ++pos < file.length()) { 
     170      return file.substr(pos); 
    170171    } 
    171     return file_; 
     172    return file; 
    172173  } 
    173174  std::wstring getModule() { 
    174     if (file_.empty()) 
    175       return _T(""); 
    176     std::wstring ret = file_; 
    177     std::wstring::size_type pos = ret.find_last_of(_T("\\")); 
    178     if (pos != std::wstring::npos && ++pos < ret.length()) { 
    179       ret = ret.substr(pos); 
     175    std::wstring file = getFilename(); 
     176    std::wstring::size_type pos = file.find_last_of(_T(".")); 
     177    if (pos != std::wstring::npos) { 
     178      file = file.substr(0, pos); 
    180179    } 
    181     pos = ret.find_last_of(_T(".")); 
    182     if (pos != std::wstring::npos) { 
    183       ret = ret.substr(0, pos); 
    184     } 
    185     return ret; 
     180    return file; 
    186181  } 
    187182  bool getLastIsMsgPlugin() { 
     
    194189private: 
    195190  bool lastIsMsgPlugin_; 
    196   bool getName_(TCHAR* buf, unsigned int buflen); 
    197   bool getDescription_(TCHAR* buf, unsigned int buflen); 
     191  bool getName_(wchar_t* buf, unsigned int buflen); 
     192  bool getDescription_(wchar_t* buf, unsigned int buflen); 
    198193  void loadRemoteProcs_(void); 
    199   bool getConfigurationMeta_(TCHAR* buf, unsigned int buflen); 
     194  bool getConfigurationMeta_(wchar_t* buf, unsigned int buflen); 
    200195}; 
    201196 
  • trunk/service/NSClient++-2005.vcproj

    r205 r207  
    20932093      </File> 
    20942094      <File 
    2095         RelativePath="..\include\Socket.cpp" 
    2096         > 
    2097         <FileConfiguration 
    2098           Name="Release|Win32" 
    2099           > 
    2100           <Tool 
    2101             Name="VCCLCompilerTool" 
    2102             UsePrecompiledHeader="0" 
    2103             PrecompiledHeaderThrough=" " 
    2104             PrecompiledHeaderFile=" " 
    2105           /> 
    2106         </FileConfiguration> 
    2107         <FileConfiguration 
    2108           Name="Release|x64" 
    2109           > 
    2110           <Tool 
    2111             Name="VCCLCompilerTool" 
    2112             UsePrecompiledHeader="0" 
    2113             PrecompiledHeaderThrough=" " 
    2114             PrecompiledHeaderFile=" " 
    2115           /> 
    2116         </FileConfiguration> 
    2117         <FileConfiguration 
    2118           Name="Debug|Win32" 
    2119           > 
    2120           <Tool 
    2121             Name="VCCLCompilerTool" 
    2122             UsePrecompiledHeader="0" 
    2123             PrecompiledHeaderThrough=" " 
    2124             PrecompiledHeaderFile=" " 
    2125           /> 
    2126         </FileConfiguration> 
    2127         <FileConfiguration 
    2128           Name="Debug|x64" 
    2129           > 
    2130           <Tool 
    2131             Name="VCCLCompilerTool" 
    2132             UsePrecompiledHeader="0" 
    2133             PrecompiledHeaderThrough=" " 
    2134             PrecompiledHeaderFile=" " 
    2135           /> 
    2136         </FileConfiguration> 
    2137         <FileConfiguration 
    2138           Name="Distribution|Win32" 
    2139           > 
    2140           <Tool 
    2141             Name="VCCLCompilerTool" 
    2142             UsePrecompiledHeader="0" 
    2143             PrecompiledHeaderThrough=" " 
    2144             PrecompiledHeaderFile=" " 
    2145           /> 
    2146         </FileConfiguration> 
    2147         <FileConfiguration 
    2148           Name="Distribution|x64" 
    2149           > 
    2150           <Tool 
    2151             Name="VCCLCompilerTool" 
    2152             UsePrecompiledHeader="0" 
    2153             PrecompiledHeaderThrough=" " 
    2154             PrecompiledHeaderFile=" " 
    2155           /> 
    2156         </FileConfiguration> 
    2157         <FileConfiguration 
    2158           Name="Nightly|Win32" 
    2159           > 
    2160           <Tool 
    2161             Name="VCCLCompilerTool" 
    2162             UsePrecompiledHeader="0" 
    2163             PrecompiledHeaderThrough=" " 
    2164             PrecompiledHeaderFile=" " 
    2165           /> 
    2166         </FileConfiguration> 
    2167         <FileConfiguration 
    2168           Name="Nightly|x64" 
    2169           > 
    2170           <Tool 
    2171             Name="VCCLCompilerTool" 
    2172             UsePrecompiledHeader="0" 
    2173             PrecompiledHeaderThrough=" " 
    2174             PrecompiledHeaderFile=" " 
    2175           /> 
    2176         </FileConfiguration> 
    2177         <FileConfiguration 
    2178           Name="Debug-MemCheck|Win32" 
    2179           > 
    2180           <Tool 
    2181             Name="VCCLCompilerTool" 
    2182             UsePrecompiledHeader="0" 
    2183             PrecompiledHeaderThrough=" " 
    2184             PrecompiledHeaderFile=" " 
    2185           /> 
    2186         </FileConfiguration> 
    2187         <FileConfiguration 
    2188           Name="Debug-MemCheck|x64" 
    2189           > 
    2190           <Tool 
    2191             Name="VCCLCompilerTool" 
    2192             UsePrecompiledHeader="0" 
    2193             PrecompiledHeaderThrough=" " 
    2194             PrecompiledHeaderFile=" " 
    2195           /> 
    2196         </FileConfiguration> 
    2197         <FileConfiguration 
    2198           Name="OP5|Win32" 
    2199           > 
    2200           <Tool 
    2201             Name="VCCLCompilerTool" 
    2202             UsePrecompiledHeader="0" 
    2203             PrecompiledHeaderThrough=" " 
    2204             PrecompiledHeaderFile=" " 
    2205           /> 
    2206         </FileConfiguration> 
    2207         <FileConfiguration 
    2208           Name="OP5|x64" 
    2209           > 
    2210           <Tool 
    2211             Name="VCCLCompilerTool" 
    2212             UsePrecompiledHeader="0" 
    2213             PrecompiledHeaderThrough=" " 
    2214             PrecompiledHeaderFile=" " 
    2215           /> 
    2216         </FileConfiguration> 
    2217       </File> 
    2218       <File 
    22192095        RelativePath="StdAfx.cpp" 
    22202096        > 
     
    23952271      </File> 
    23962272      <File 
     2273        RelativePath="..\include\dll\dll.hpp" 
     2274        > 
     2275      </File> 
     2276      <File 
    23972277        RelativePath=".\include\error.hpp" 
    23982278        > 
     
    24032283      </File> 
    24042284      <File 
     2285        RelativePath="..\include\dll\impl_unix.hpp" 
     2286        > 
     2287      </File> 
     2288      <File 
     2289        RelativePath="..\include\dll\impl_w32.hpp" 
     2290        > 
     2291      </File> 
     2292      <File 
    24052293        RelativePath=".\include\Mutex.h" 
    24062294        > 
     
    24112299      </File> 
    24122300      <File 
    2413         RelativePath=".\include\NSCAPI.h" 
     2301        RelativePath="..\include\NSCAPI.h" 
    24142302        > 
    24152303      </File> 
     
    24312319      </File> 
    24322320      <File 
    2433         RelativePath=".\include\NTService.h" 
     2321        RelativePath="..\include\NTService.h" 
    24342322        > 
    24352323      </File> 
     
    24872375      </File> 
    24882376      <File 
    2489         RelativePath=".\include\Socket.h" 
    2490         > 
    2491       </File> 
    2492       <File 
    24932377        RelativePath="StdAfx.h" 
    24942378        > 
     
    25042388      <File 
    25052389        RelativePath=".\tray_manager.hpp" 
     2390        > 
     2391      </File> 
     2392      <File 
     2393        RelativePath="..\include\unicode_char.hpp" 
    25062394        > 
    25072395      </File> 
  • trunk/service/NSClient++.cpp

    r206 r207  
    1313// 
    1414////////////////////////////////////////////////////////////////////////// 
    15 #include "stdafx.h" 
    16 #include <winsvc.h> 
     15#include "StdAfx.h" 
    1716#include "NSClient++.h" 
    1817#include <settings/Settings.h> 
    1918#include <charEx.h> 
    20 #include <Socket.h> 
     19//#include <Socket.h> 
    2120#include <config.h> 
    2221#include <msvc_wrappers.h> 
     22#ifdef WIN32 
    2323#include <Userenv.h> 
    24 #include <remote_processes.hpp> 
    2524#include <Lmcons.h> 
    2625//#ifdef DEBUG 
    2726#include <crtdbg.h> 
    2827//#endif 
    29 #include <Userenv.h> 
     28#endif 
    3029#include <remote_processes.hpp> 
    31 #include <Lmcons.h> 
     30//#include <winsvc.h> 
     31//#include <Userenv.h> 
     32//#include <Lmcons.h> 
     33#include <remote_processes.hpp> 
    3234#include "core_api.h" 
    3335#include "settings_manager_impl.h" 
    3436#include <settings/macros.h> 
     37#include <NSCHelper.h> 
    3538 
    3639NSClient mainClient(SZSERVICENAME); // Global core instance. 
     
    209212  int nRetCode = 0; 
    210213  if ( (argc > 1) && ((*argv[1] == '-') || (*argv[1] == '/')) ) { 
    211     if ( _wcsicmp( _T("install"), argv[1]+1 ) == 0 ) { 
     214    if (false) { 
     215#ifdef WIN32 
     216    } if ( _wcsicmp( _T("install"), argv[1]+1 ) == 0 ) { 
    212217      bool bGui = false; 
    213218      bool bStart = false; 
     
    288293      LOG_MESSAGE(_T("Service uninstalled!")); 
    289294      return 0; 
     295    } else if ( _wcsicmp( _T("start"), argv[1]+1 ) == 0 ) { 
     296      g_bConsoleLog = true; 
     297      bool bGui = false; 
     298      std::wstring service_name; 
     299      for (int i=2;i<argc;i++) { 
     300        if (_wcsicmp( _T("gui"), argv[i]) == 0) { 
     301          bGui = true; 
     302        } else { 
     303          service_name = argv[i]; 
     304        } 
     305      } 
     306      if (service_name.empty()) 
     307        service_name = SZSERVICENAME; 
     308      try { 
     309        serviceControll::Start(service_name.c_str()); 
     310      } catch (const serviceControll::SCException& e) { 
     311        if (bGui) 
     312          display(_T("Service failed to start"), e.error_); 
     313        LOG_MESSAGE_STD(_T("Service failed to start: ") + e.error_); 
     314        return -1; 
     315      } 
     316    } else if ( _wcsicmp( _T("stop"), argv[1]+1 ) == 0 ) { 
     317      g_bConsoleLog = true; 
     318      bool bGui = false; 
     319      std::wstring service_name; 
     320      for (int i=2;i<argc;i++) { 
     321        if (_wcsicmp( _T("gui"), argv[i]) == 0) { 
     322          bGui = true; 
     323        } else { 
     324          service_name = argv[i]; 
     325        } 
     326      } 
     327      if (service_name.empty()) 
     328        service_name = SZSERVICENAME; 
     329      try { 
     330        serviceControll::Stop(service_name.c_str()); 
     331      } catch (const serviceControll::SCException& e) { 
     332        if (bGui) 
     333          display(_T("Service failed to stop"), e.error_); 
     334        LOG_MESSAGE_STD(_T("Service failed to stop: ") + e.error_); 
     335        return -1; 
     336      } 
     337    } else if ( _wcsicmp( _T("svc"), argv[1]+1 ) == 0 ) { 
     338      g_bConsoleLog = true; 
     339      try { 
     340        std::wstring exe = serviceControll::get_exe_path(SZSERVICENAME); 
     341        LOG_MESSAGE_STD(_T("The Service uses: ") + exe); 
     342      } catch (const serviceControll::SCException& e) { 
     343        LOG_ERROR_STD(_T("Failed to find service: ") + e.error_); 
     344      } 
     345#endif 
    290346    } else if ( _wcsicmp( _T("encrypt"), argv[1]+1 ) == 0 ) { 
    291347      g_bConsoleLog = true; 
     
    304360      settings_manager::destroy_settings(); 
    305361      return 0; 
    306     } else if ( _wcsicmp( _T("start"), argv[1]+1 ) == 0 ) { 
    307       g_bConsoleLog = true; 
    308       bool bGui = false; 
    309       std::wstring service_name; 
    310       for (int i=2;i<argc;i++) { 
    311         if (_wcsicmp( _T("gui"), argv[i]) == 0) { 
    312           bGui = true; 
    313         } else { 
    314           service_name = argv[i]; 
    315         } 
    316       } 
    317       if (service_name.empty()) 
    318         service_name = SZSERVICENAME; 
    319       try { 
    320         serviceControll::Start(service_name.c_str()); 
    321       } catch (const serviceControll::SCException& e) { 
    322         if (bGui) 
    323           display(_T("Service failed to start"), e.error_); 
    324         LOG_MESSAGE_STD(_T("Service failed to start: ") + e.error_); 
    325         return -1; 
    326       } 
    327     } else if ( _wcsicmp( _T("stop"), argv[1]+1 ) == 0 ) { 
    328       g_bConsoleLog = true; 
    329       bool bGui = false; 
    330       std::wstring service_name; 
    331       for (int i=2;i<argc;i++) { 
    332         if (_wcsicmp( _T("gui"), argv[i]) == 0) { 
    333           bGui = true; 
    334         } else { 
    335           service_name = argv[i]; 
    336         } 
    337       } 
    338       if (service_name.empty()) 
    339         service_name = SZSERVICENAME; 
    340       try { 
    341         serviceControll::Stop(service_name.c_str()); 
    342       } catch (const serviceControll::SCException& e) { 
    343         if (bGui) 
    344           display(_T("Service failed to stop"), e.error_); 
    345         LOG_MESSAGE_STD(_T("Service failed to stop: ") + e.error_); 
    346         return -1; 
    347       } 
    348362    } else if ( _wcsicmp( _T("about"), argv[1]+1 ) == 0 ) { 
    349363      g_bConsoleLog = true; 
     
    391405    } else if ( _wcsicmp( _T("noboot"), argv[1]+1 ) == 0 ) { 
    392406      g_bConsoleLog = true; 
    393       mainClient.enableDebug(true); 
    394       mainClient.initCore(true); 
    395       std::wstring command, args, msg, perf; 
    396       if (argc > 2) 
    397         command = argv[2]; 
    398       for (int i=3;i<argc;i++) { 
    399         if (i!=3) args += _T(" "); 
    400         args += argv[i]; 
    401       } 
    402       nRetCode = mainClient.inject(command, args, L' ', true, msg, perf); 
    403       std::wcout << msg << _T("|") << perf << std::endl; 
     407      mainClient.enableDebug(false); 
     408      mainClient.initCore(false); 
     409      if (argc>=4) 
     410        nRetCode = mainClient.commandLineExec(argv[2], argv[3], argc-4, &argv[4]); 
     411      else 
     412        nRetCode = mainClient.commandLineExec(argv[2], argv[3], 0, NULL); 
    404413      mainClient.exitCore(true); 
    405414      return nRetCode; 
     
    420429      mainClient.exitCore(true); 
    421430      return nRetCode; 
    422       g_bConsoleLog = true; 
    423       mainClient.enableDebug(false); 
    424       mainClient.initCore(false); 
    425       int nRetCode = -1; 
    426       if (argc>=4) 
    427         nRetCode = mainClient.commandLineExec(argv[2], argv[3], argc-4, &argv[4]); 
    428       else if (argc>=3) 
    429         nRetCode = mainClient.commandLineExec(argv[2], argv[3], 0, NULL); 
    430       mainClient.exitCore(false); 
    431       return nRetCode; 
    432     } else if ( _wcsicmp( _T("svc"), argv[1]+1 ) == 0 ) { 
    433       g_bConsoleLog = true; 
    434       try { 
    435         std::wstring exe = serviceControll::get_exe_path(SZSERVICENAME); 
    436         LOG_MESSAGE_STD(_T("The Service uses: ") + exe); 
    437       } catch (const serviceControll::SCException& e) { 
    438         LOG_ERROR_STD(_T("Failed to find service: ") + e.error_); 
    439       } 
    440431    } else if ( _wcsicmp( _T("test"), argv[1]+1 ) == 0 ) { 
    441432      bool server = false; 
     
    445436      std::wcout << "Launching test mode - " << (server?_T("server mode"):_T("client mode")) << std::endl; 
    446437      LOG_MESSAGE_STD(_T("Booting: " SZSERVICEDISPLAYNAME )); 
     438#ifdef WIN32 
    447439      try { 
    448440        if (serviceControll::isStarted(SZSERVICENAME)) { 
     
    452444        e;// Empty by design 
    453445      } 
     446#endif 
    454447      g_bConsoleLog = true; 
    455448      mainClient.enableDebug(true); 
     
    788781    } 
    789782  } 
    790  
     783/* 
    791784  try { 
    792785    simpleSocket::WSAStartup(); 
     
    798791    return false; 
    799792  } 
    800  
     793*/ 
    801794  try { 
    802795    com_helper_.initialize(); 
     
    921914    LOG_ERROR_STD(_T("Unknown exception uniniating COM...")); 
    922915  } 
     916  /* 
    923917  LOG_DEBUG_STD(_T("Stopping: Socket Helpers")); 
    924918  try { 
     
    929923    LOG_ERROR_STD(_T("Unknown exception uniniating socket...")); 
    930924  } 
     925  */ 
    931926  LOG_DEBUG_STD(_T("Stopping: Settings instance")); 
    932927  settings_manager::destroy_settings(); 
     
    979974void WINAPI NSClientT::service_main_dispatch(DWORD dwArgc, LPTSTR *lpszArgv) { 
    980975  try { 
    981     mainClient.service_main(dwArgc, lpszArgv); 
     976    //WTF!!! mainClient.service_main(dwArgc, lpszArgv); 
    982977  } catch (service_helper::service_exception e) { 
    983978    LOG_ERROR_STD(_T("Unknown service error: ") + e.what()); 
     
    10451040    return plugin->commandLineExec(command, argLen, args); 
    10461041  } catch (NSPluginException e) { 
    1047     LOG_MESSAGE_STD(_T("Failed to load (") + e.file_ + _T("): ") + e.error_); 
     1042    LOG_MESSAGE_STD(_T("Module (") + e.file_ + _T(") was not found: ") + e.error_); 
    10481043  } 
    10491044  try { 
     
    14051400 */ 
    14061401void NSClientT::reportMessage(int msgType, const TCHAR* file, const int line, std::wstring message) { 
    1407   strEx::replace(message, _T("\n"), _T(" ")); 
    1408   strEx::replace(message, _T("\r"), _T(" ")); 
    1409   if ((msgType == NSCAPI::debug)&&(!logDebug())) { 
    1410     return; 
    1411   } 
    1412   if (shared_server_.get() != NULL && shared_server_->hasClients()) { 
    1413     try { 
    1414       shared_server_->sendLogMessageToClients(msgType, file, line, message); 
    1415     } catch (nsclient_session::session_exception e) { 
    1416       log_broken_message(_T("Failed to send message to clients: ") + e.what()); 
    1417     } 
    1418   } 
    1419   std::wstring file_stl = file; 
    1420   std::wstring::size_type pos = file_stl.find_last_of(_T("\\")); 
    1421   if (pos != std::wstring::npos) 
    1422     file_stl = file_stl.substr(pos); 
    1423   { 
    1424     ReadLock readLock(&m_mutexRW, true, 5000); 
    1425     if (!readLock.IsLocked()) { 
    1426       log_broken_message(_T("Message was lost as the (mutexRW) core was locked: ") + message); 
     1402  try { 
     1403    strEx::replace(message, _T("\n"), _T(" ")); 
     1404    strEx::replace(message, _T("\r"), _T(" ")); 
     1405    if ((msgType == NSCAPI::debug)&&(!logDebug())) { 
    14271406      return; 
    14281407    } 
    1429     MutexLock lock(messageMutex); 
    1430     if (!lock.hasMutex()) { 
    1431       log_broken_message(_T("Message was lost as the core was locked: ") + message); 
    1432       return; 
    1433     } 
    1434     if (g_bConsoleLog) { 
    1435       std::string k = "?"; 
    1436       switch (msgType) { 
    1437       case NSCAPI::critical: 
    1438         k ="c"; 
    1439         break; 
    1440       case NSCAPI::warning: 
    1441         k ="w"; 
    1442         break; 
    1443       case NSCAPI::error: 
    1444         k ="e"; 
    1445         break; 
    1446       case NSCAPI::log: 
    1447         k ="l"; 
    1448         break; 
    1449       case NSCAPI::debug: 
    1450         k ="d"; 
    1451         break; 
    1452       }  
    1453       std::cout << k << " " << strEx::wstring_to_string(file_stl) << "(" << line << ") " << strEx::wstring_to_string(message) << std::endl; 
    1454     } 
    1455     if (!plugins_loaded_) { 
    1456       OutputDebugString(message.c_str()); 
    1457       log_cache_.push_back(cached_log_entry(msgType, file, line, message)); 
    1458     } else { 
    1459       if (log_cache_.size() > 0) { 
    1460         for (log_cache_type::const_iterator cit=log_cache_.begin();cit!=log_cache_.end();++cit) { 
    1461           for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 
    1462             try { 
    1463               messageHandlers_[i]->handleMessage((*cit).msgType, (_T("CACHE") + (*cit).file).c_str(), (*cit).line, (*cit).message.c_str()); 
    1464             } catch(const NSPluginException& e) { 
    1465               log_broken_message(_T("Caught: ") + e.error_ + _T(" when trying to log a message...")); 
    1466               return; 
    1467             } catch(...) { 
    1468               log_broken_message(_T("Caught: Unknown Exception when trying to log a message...")); 
    1469               return; 
     1408    if (shared_server_.get() != NULL && shared_server_->hasClients()) { 
     1409      try { 
     1410        shared_server_->sendLogMessageToClients(msgType, file, line, message); 
     1411      } catch (nsclient_session::session_exception e) { 
     1412        log_broken_message(_T("Failed to send message to clients: ") + e.what()); 
     1413      } 
     1414    } 
     1415    std::wstring file_stl = file; 
     1416    std::wstring::size_type pos = file_stl.find_last_of(_T("\\")); 
     1417    if (pos != std::wstring::npos) 
     1418      file_stl = file_stl.substr(pos); 
     1419    { 
     1420      ReadLock readLock(&m_mutexRW, true, 5000); 
     1421      if (!readLock.IsLocked()) { 
     1422        log_broken_message(_T("Message was lost as the (mutexRW) core was locked: ") + message); 
     1423        return; 
     1424      } 
     1425      boost::unique_lock<boost::timed_mutex> lock(messageMutex, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
     1426      if (!lock.owns_lock()) { 
     1427        log_broken_message(_T("Message was lost as the core was locked: ") + message); 
     1428        return; 
     1429      } 
     1430      if (g_bConsoleLog) { 
     1431        std::string k = "?"; 
     1432        switch (msgType) { 
     1433        case NSCAPI::critical: 
     1434          k ="c"; 
     1435          break; 
     1436        case NSCAPI::warning: 
     1437          k ="w"; 
     1438          break; 
     1439        case NSCAPI::error: 
     1440          k ="e"; 
     1441          break; 
     1442        case NSCAPI::log: 
     1443          k ="l"; 
     1444          break; 
     1445        case NSCAPI::debug: 
     1446          k ="d"; 
     1447          break; 
     1448        }  
     1449        std::cout << k << " " << strEx::wstring_to_string(file_stl) << "(" << line << ") " << strEx::wstring_to_string(message) << std::endl; 
     1450      } 
     1451      if (!plugins_loaded_) { 
     1452        log_broken_message(message); 
     1453        cached_log_entry entry(msgType, file, line, message); 
     1454        log_cache_.push_back(entry); 
     1455      } else { 
     1456        if (log_cache_.size() > 0) { 
     1457          for (log_cache_type::const_iterator cit=log_cache_.begin();cit!=log_cache_.end();++cit) { 
     1458            for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 
     1459              try { 
     1460                messageHandlers_[i]->handleMessage((*cit).msgType, (_T("CACHE") + (*cit).file).c_str(), (*cit).line, (*cit).message.c_str()); 
     1461              } catch(const NSPluginException& e) { 
     1462                log_broken_message(_T("Caught: ") + e.error_ + _T(" when trying to log a message...")); 
     1463                return; 
     1464              } catch(...) { 
     1465                log_broken_message(_T("Caught: Unknown Exception when trying to log a message...")); 
     1466                return; 
     1467              } 
    14701468            } 
    14711469          } 
    1472         } 
    1473         log_cache_.clear(); 
    1474       } 
    1475       for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 
    1476         try { 
    1477           messageHandlers_[i]->handleMessage(msgType, file, line, message.c_str()); 
    1478         } catch(const NSPluginException& e) { 
    1479           log_broken_message(_T("Caught: ") + e.error_ + _T(" when trying to log a message...")); 
    1480           return; 
    1481         } catch(...) { 
    1482           log_broken_message(_T("Caught: Unknown Exception when trying to log a message...")); 
    1483           return; 
    1484         } 
    1485       } 
    1486     } 
     1470          log_cache_.clear(); 
     1471        } 
     1472        for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 
     1473          try { 
     1474            messageHandlers_[i]->handleMessage(msgType, file, line, message.c_str()); 
     1475          } catch(const NSPluginException& e) { 
     1476            log_broken_message(_T("Caught: ") + e.error_ + _T(" when trying to log a message...")); 
     1477            return; 
     1478          } catch(...) { 
     1479            log_broken_message(_T("Caught: Unknown Exception when trying to log a message...")); 
     1480            return; 
     1481          } 
     1482        } 
     1483      } 
     1484    } 
     1485  } catch (...) { 
     1486    log_broken_message(_T("Caught UNKNOWN Exception when trying to log a message: ") + message); 
    14871487  } 
    14881488} 
    14891489std::wstring NSClientT::getBasePath(void) { 
    1490   MutexLock lock(internalVariables); 
    1491   if (!lock.hasMutex()) { 
     1490  boost::unique_lock<boost::timed_mutex> lock(internalVariables, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
     1491  if (!lock.owns_lock()) { 
    14921492    LOG_ERROR(_T("FATAL ERROR: Could not get mutex.")); 
    14931493    return _T("FATAL ERROR"); 
  • trunk/service/NSClient++.h

    r205 r207  
    2222 
    2323#include <config.h> 
    24 #include <ServiceCmd.h> 
    25 #include <NTService.h> 
     24#include <service/system_service.hpp> 
    2625#include "NSCPlugin.h" 
    2726#include <Mutex.h> 
     
    3130#include <com_helpers.hpp> 
    3231#include <nsclient_session.hpp> 
    33  
     32#include <boost/thread/thread.hpp> 
     33#include <boost/thread/locks.hpp> 
    3434 
    3535/** 
     
    9999  pluginList messageHandlers_; 
    100100  std::wstring basePath; 
    101   MutexHandler internalVariables; 
    102   MutexHandler messageMutex; 
     101  boost::timed_mutex internalVariables; 
     102  boost::timed_mutex messageMutex; 
    103103  MutexRW  m_mutexRW; 
    104104  MutexRW  m_mutexRWcmdDescriptions; 
     
    180180}; 
    181181 
    182 typedef service_helper::NTService<NSClientT> NSClient; 
     182typedef service_helper::impl<NSClientT>::system_service NSClient; 
    183183 
    184184extern NSClient mainClient; // Global core instance forward declaration. 
    185185 
    186186 
    187 std::wstring Encrypt(std::wstring str, unsigned int algorithm = NSCAPI::xor); 
    188 std::wstring Decrypt(std::wstring str, unsigned int algorithm = NSCAPI::xor); 
     187std::wstring Encrypt(std::wstring str, unsigned int algorithm = NSCAPI::encryption_xor); 
     188std::wstring Decrypt(std::wstring str, unsigned int algorithm = NSCAPI::encryption_xor); 
    189189 
    190190////////////////////////////////////////////////////////////////////////// 
  • trunk/service/StdAfx.h

    r202 r207  
    2020***************************************************************************/ 
    2121#pragma once 
    22  
     22#ifdef WIN32 
    2323#define _WINSOCKAPI_ 
    2424//#include <WinSock2.h> 
     25#include <tchar.h> 
    2526 
    2627#define _WIN32_DCOM 
     
    2930#define VC_EXTRALEAN    // Exclude rarely-used stuff from Windows headers 
    3031#include <windows.h> 
    31  
     32#endif  
    3233 
    3334#define COMPILE_NEWAPIS_STUBS 
     
    3637 
    3738#include <iostream> 
    38 #include <tchar.h> 
    3939#include <string> 
    4040#include <list> 
  • trunk/service/core_api.cpp

    r205 r207  
    2626#include "settings_manager_impl.h" 
    2727#include <b64/b64.h> 
     28#include <NSCHelper.h> 
    2829 
    2930 
     
    5859} 
    5960void NSAPIStopServer(void) { 
     61#ifdef WIN32 
    6062  serviceControll::StopNoWait(SZSERVICENAME); 
     63#endif 
    6164} 
    6265NSCAPI::nagiosReturn NSAPIInject(const TCHAR* command, const unsigned int argLen, TCHAR **argument, TCHAR *returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR *returnPerfBuffer, unsigned int returnPerfBufferLen) { 
     
    9093 
    9194NSCAPI::errorReturn NSAPIEncrypt(unsigned int algorithm, const TCHAR* inBuffer, unsigned int inBufLen, TCHAR* outBuf, unsigned int *outBufLen) { 
    92   if (algorithm != NSCAPI::xor) { 
     95  if (algorithm != NSCAPI::encryption_xor) { 
    9396    LOG_ERROR(_T("Unknown algortihm requested.")); 
    9497    return NSCAPI::hasFailed; 
    9598  } 
     99  /* 
     100  TODO reimplement this 
     101 
    96102  std::wstring key = settings_manager::get_settings()->get_string(SETTINGS_KEY(protocol_def::MASTER_KEY)); 
    97103  int tcharInBufLen = 0; 
     
    125131  outBuf[realOutLen] = 0; 
    126132  *outBufLen = static_cast<unsigned int>(realOutLen); 
     133  */ 
    127134  return NSCAPI::isSuccess; 
    128135} 
    129136 
    130137NSCAPI::errorReturn NSAPIDecrypt(unsigned int algorithm, const TCHAR* inBuffer, unsigned int inBufLen, TCHAR* outBuf, unsigned int *outBufLen) { 
    131   if (algorithm != NSCAPI::xor) { 
     138  if (algorithm != NSCAPI::encryption_xor) { 
    132139    LOG_ERROR(_T("Unknown algortihm requested.")); 
    133140    return NSCAPI::hasFailed; 
    134141  } 
     142  /* 
    135143  int inBufLenC = 0; 
    136144  char *inBufferC = charEx::tchar_to_char(inBuffer, inBufLen, inBufLenC); 
     
    166174  outBuf[realOutLen] = 0; 
    167175  *outBufLen = static_cast<unsigned int>(realOutLen); 
     176  */ 
    168177  return NSCAPI::isSuccess; 
    169178} 
Note: See TracChangeset for help on using the changeset viewer.