Changeset 207
- Timestamp:
- 11/08/09 23:24:31 (2 years ago)
- Location:
- trunk
- Files:
-
- 14 added
- 46 edited
-
. (modified) (1 prop)
-
NSClient++-2005.sln (modified) (10 diffs)
-
include/NSCAPI.h (modified) (4 diffs)
-
include/NSCHelper.cpp (modified) (3 diffs)
-
include/NSCHelper.h (modified) (7 diffs)
-
include/NTService.h (modified) (1 diff)
-
include/arrayBuffer.cpp (modified) (10 diffs)
-
include/arrayBuffer.h (modified) (4 diffs)
-
include/charEx.h (modified) (6 diffs)
-
include/checkHelpers.hpp (modified) (2 diffs)
-
include/config.h (modified) (2 diffs)
-
include/dll (added)
-
include/dll/dll.hpp (added)
-
include/dll/impl_unix.hpp (added)
-
include/dll/impl_w32.hpp (added)
-
include/error.hpp (modified) (1 diff)
-
include/error_impl_unix.hpp (added)
-
include/error_impl_w32.hpp (added)
-
include/nrpe/nrpepacket.hpp (modified) (1 diff)
-
include/nsc_module_wrapper.hpp (added)
-
include/service (added)
-
include/service/system_service.hpp (added)
-
include/service/unix_service.hpp (added)
-
include/settings/macros.h (modified) (4 diffs)
-
include/settings/settings_old.hpp (modified) (1 diff)
-
include/settings/settings_registry.hpp (modified) (1 diff)
-
include/strEx.h (modified) (24 diffs)
-
include/unicode_char.hpp (added)
-
modules/CheckDisk/CheckDisk.cpp (modified) (1 diff)
-
modules/CheckDisk/stdafx.h (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (2 diffs)
-
modules/CheckEventLog/stdafx.h (modified) (1 diff)
-
modules/CheckExternalScripts (modified) (1 prop)
-
modules/CheckExternalScripts/CheckExternalScripts-2005.vcproj (modified) (3 diffs)
-
modules/CheckExternalScripts/stdafx.h (modified) (1 diff)
-
modules/CheckHelpers/stdafx.h (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.cpp (modified) (1 diff)
-
modules/CheckSystem/stdafx.h (modified) (1 diff)
-
modules/CheckTaskSched/stdafx.h (modified) (1 diff)
-
modules/CheckWMI/WMIQuery.h (modified) (1 diff)
-
modules/CheckWMI/stdafx.h (modified) (1 diff)
-
modules/DebugLogMetrics/stdafx.h (modified) (1 diff)
-
modules/FileLogger/stdafx.h (modified) (1 diff)
-
modules/LUAScript/stdafx.h (modified) (1 diff)
-
modules/NRPEClient/NRPEClient.cpp (modified) (7 diffs)
-
modules/NRPEClient/stdafx.h (modified) (1 diff)
-
modules/NRPEListener/stdafx.h (modified) (1 diff)
-
modules/NSCAAgent/stdafx.h (modified) (1 diff)
-
modules/NSClientListener/stdafx.h (modified) (1 diff)
-
modules/SysTray/stdafx.h (modified) (1 diff)
-
nrpe_dh_512.pem (added)
-
service/CMakeLists.txt (added)
-
service/NSCPlugin.cpp (modified) (19 diffs)
-
service/NSCPlugin.h (modified) (5 diffs)
-
service/NSClient++-2005.vcproj (modified) (7 diffs)
-
service/NSClient++.cpp (modified) (15 diffs)
-
service/NSClient++.h (modified) (4 diffs)
-
service/StdAfx.h (modified) (3 diffs)
-
service/config.h.in (added)
-
service/core_api.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 11 11 build.log 12 12 AutoBuild.h.bak 13 stage_cmake
-
- Property svn:ignore
-
trunk/NSClient++-2005.sln
r205 r207 237 237 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|Mixed Platforms.Build.0 = Debug|x64 238 238 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|Win32.ActiveCfg = Debug|Win32 239 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|Win32.Build.0 = Debug|Win32240 239 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|x64.ActiveCfg = Debug|x64 241 240 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|x64.Build.0 = Debug|x64 … … 321 320 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|Mixed Platforms.Build.0 = Debug|x64 322 321 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|Win32.ActiveCfg = Debug|Win32 323 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|Win32.Build.0 = Debug|Win32324 322 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|x64.ActiveCfg = Debug|x64 325 323 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|x64.Build.0 = Debug|x64 … … 342 340 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|Mixed Platforms.Build.0 = Debug|x64 343 341 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|Win32.ActiveCfg = Debug|Win32 344 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|Win32.Build.0 = Debug|Win32345 342 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|x64.ActiveCfg = Debug|x64 346 343 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|x64.Build.0 = Debug|x64 … … 426 423 {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|Mixed Platforms.Build.0 = Debug|x64 427 424 {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|Win32.ActiveCfg = Debug|Win32 428 {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|Win32.Build.0 = Debug|Win32429 425 {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|x64.ActiveCfg = Debug|x64 430 426 {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|x64.Build.0 = Debug|x64 … … 503 499 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Mixed Platforms.Build.0 = Debug|x64 504 500 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Win32.ActiveCfg = Debug|Win32 505 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|Win32.Build.0 = Debug|Win32506 501 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|x64.ActiveCfg = Debug|x64 507 502 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}.Debug|x64.Build.0 = Debug|x64 … … 545 540 {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Debug|Mixed Platforms.Build.0 = Debug|x64 546 541 {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Debug|Win32.ActiveCfg = Debug|Win32 547 {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Debug|Win32.Build.0 = Debug|Win32548 542 {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Debug|x64.ActiveCfg = Debug|x64 549 543 {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Debug|x64.Build.0 = Debug|x64 … … 566 560 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Mixed Platforms.Build.0 = Debug|Win32 567 561 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Win32.ActiveCfg = Debug|Win32 568 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Win32.Build.0 = Debug|Win32569 562 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|x64.ActiveCfg = Debug|x64 570 563 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|x64.Build.0 = Debug|x64 … … 675 668 {B6A2BD0C-9633-4DD4-A350-D98ACE660937}.Debug|Mixed Platforms.Build.0 = Debug 676 669 {B6A2BD0C-9633-4DD4-A350-D98ACE660937}.Debug|Win32.ActiveCfg = Debug 677 {B6A2BD0C-9633-4DD4-A350-D98ACE660937}.Debug|Win32.Build.0 = Debug678 670 {B6A2BD0C-9633-4DD4-A350-D98ACE660937}.Debug|x64.ActiveCfg = Debug 679 671 {B6A2BD0C-9633-4DD4-A350-D98ACE660937}.Debug|x64.Build.0 = Debug … … 696 688 {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Mixed Platforms.ActiveCfg = Release|x64 697 689 {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Mixed Platforms.Build.0 = Release|x64 698 {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Win32.ActiveCfg = Release|Win32699 {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Win32.Build.0 = Release|Win32690 {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Win32.ActiveCfg = Debug|Win32 691 {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|Win32.Build.0 = Debug|Win32 700 692 {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|x64.ActiveCfg = Release|x64 701 693 {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}.Debug|x64.Build.0 = Release|x64 … … 761 753 {743B2362-DF6A-4C28-A6C9-0F970D8E1B66} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 762 754 {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} 763 757 {D367E76D-9485-4DCB-A9D0-3D3C0E190648} = {BBE9A5E7-A16B-443C-A349-823DED5A9FF3} 764 758 {1D9DEE38-BBDC-49DE-A6F3-BAC26E114C1D} = {BBE9A5E7-A16B-443C-A349-823DED5A9FF3} 765 759 {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}768 760 EndGlobalSection 769 761 GlobalSection(DPCodeReviewSolutionGUID) = preSolution -
trunk/include/NSCAPI.h
r138 r207 22 22 23 23 24 #include < tchar.h>24 #include <unicode_char.hpp> 25 25 26 26 namespace NSCAPI { … … 79 79 #endif 80 80 81 const int xor = 1;81 const int encryption_xor = 1; 82 82 83 83 // Settings types … … 96 96 97 97 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; 102 102 }; 103 103 typedef plugin_info* plugin_info_list; … … 105 105 106 106 }; 107 108 namespace NSCModuleHelper { 109 typedef void* (*lpNSAPILoader)(wchar_t*); 110 } -
trunk/include/NSCHelper.cpp
r202 r207 21 21 22 22 #include <NSCHelper.h> 23 #include <nsc_module_wrapper.hpp> 23 24 #include <msvc_wrappers.h> 24 #include <config.h> 25 #include <settings/macros.h> 26 #include <arrayBuffer.h> 27 //#include <config.h> 25 28 #include <strEx.h> 26 29 … … 67 70 * @return NSCAPI::success unless the buffer is to short then it will be NSCAPI::invalidBufferLen 68 71 */ 69 int NSCHelper::wrapReturnString( TCHAR*buffer, unsigned int bufLen, std::wstring str, int defaultReturnCode ) {72 int NSCHelper::wrapReturnString(wchar_t *buffer, unsigned int bufLen, std::wstring str, int defaultReturnCode ) { 70 73 // @todo deprecate this 71 74 if (str.length() >= bufLen) { … … 215 218 * @return The returned status of the command 216 219 */ 217 NSCAPI::nagiosReturn NSCModuleHelper::InjectCommandRAW(const TCHAR* command, const unsigned int argLen, TCHAR **argument, TCHAR *returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR *returnPerfBuffer, unsigned int returnPerfBufferLen)220 NSCAPI::nagiosReturn NSCModuleHelper::InjectCommandRAW(const wchar_t* command, const unsigned int argLen, TCHAR **argument, TCHAR *returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR *returnPerfBuffer, unsigned int returnPerfBufferLen) 218 221 { 219 222 if (!fNSAPIInject) -
trunk/include/NSCHelper.h
r205 r207 27 27 #include <charEx.h> 28 28 #include <arrayBuffer.h> 29 #include <windows.h> 29 #ifdef WIN32 30 //#include <windows.h> 31 #endif 30 32 31 33 … … 33 35 { 34 36 #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); 37 39 #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); 39 41 #endif 40 42 std::wstring translateMessageType(NSCAPI::messageTypes msgType); … … 108 110 typedef std::list<plugin_info_type> plugin_info_list; 109 111 // 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 *); 116 119 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*); 118 121 typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); 119 122 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 122 125 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); 127 130 typedef NSCAPI::errorReturn (*lpNSAPIWriteSettings)(int); 128 131 typedef NSCAPI::errorReturn (*lpNSAPIReadSettings)(int); 129 132 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); 131 134 typedef NSCAPI::errorReturn (*lpNSAPIGetAllCommandNames)(arrayBuffer::arrayBuffer*, unsigned int *); 132 135 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); 136 139 typedef NSCAPI::errorReturn (*lpNSAPIGetPluginList)(int *len, NSCAPI::plugin_info *list[]); 137 140 typedef NSCAPI::errorReturn (*lpNSAPIReleasePluginList)(int len, NSCAPI::plugin_info *list[]); … … 150 153 151 154 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, TCHARsplitChar, std::wstring & message, std::wstring & perf);156 NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, TCHARsplitChar, 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); 157 160 void StopService(void); 158 161 void Exit(void); … … 160 163 bool logDebug(); 161 164 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); 164 167 NSCAPI::errorReturn SetSettingsString(std::wstring section, std::wstring key, std::wstring value); 165 168 NSCAPI::errorReturn SetSettingsInt(std::wstring section, std::wstring key, int value); … … 175 178 }; 176 179 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 DEBUG218 #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 #else223 #define NSC_LOG_ERROR_STD_C(msg) NSC_LOG_ERROR_STD(msg)224 #define NSC_LOG_ERROR_C(msg) NSC_LOG_ERROR(msg)225 #endif226 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 point251 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 }418 180 419 181 #define SETTINGS_MAKE_NAME(key) \ … … 437 199 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); 438 200 #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); 440 202 #define SETTINGS_REG_KEY_B(key) \ 441 203 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 24 24 #include <sysinfo.h> 25 25 26 namespace service_helper {26 namespace service_helper_impl { 27 27 class service_exception { 28 28 std::wstring what_; -
trunk/include/arrayBuffer.cpp
r169 r207 28 28 * @return Argument wrapped as a list 29 29 */ 30 arrayBuffer::arrayList arrayBuffer::arrayBuffer2list(const unsigned int argLen, TCHAR*argument[]) {30 arrayBuffer::arrayList arrayBuffer::arrayBuffer2list(const unsigned int argLen, wchar_t *argument[]) { 31 31 arrayList ret; 32 32 int i=0; … … 53 53 for (i=0;it!=lst.end();++it,i++) { 54 54 std::wstring::size_type alen = (*it).size(); 55 arrayBuffer[i] = new TCHAR[alen+2];55 arrayBuffer[i] = new wchar_t[alen+2]; 56 56 wcsncpy_s(arrayBuffer[i], alen+2, (*it).c_str(), alen+1); 57 57 } … … 107 107 * @return The arrayBuffer 108 108 */ 109 arrayBuffer::arrayBuffer arrayBuffer::split2arrayBuffer(const TCHAR* buffer, TCHARsplitChar, unsigned int &argLen) {109 arrayBuffer::arrayBuffer arrayBuffer::split2arrayBuffer(const wchar_t* buffer, wchar_t splitChar, unsigned int &argLen) { 110 110 if (!buffer) 111 111 throw ArrayBufferException(_T("Invalid buffer specified!")); 112 112 argLen = 0; 113 const TCHAR*p = buffer;113 const wchar_t *p = buffer; 114 114 if (!p[0]) { 115 115 return createEmptyArrayBuffer(argLen); … … 121 121 } 122 122 argLen++; 123 TCHAR **arrayBuffer = new TCHAR*[argLen];123 wchar_t **arrayBuffer = new wchar_t*[argLen]; 124 124 p = buffer; 125 125 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); 127 127 unsigned int len = static_cast<int>(q-p); 128 arrayBuffer[i] = new TCHAR[len+1];128 arrayBuffer[i] = new wchar_t[len+1]; 129 129 wcsncpy_s(arrayBuffer[i], len+1, p, len); 130 130 arrayBuffer[i][len] = 0; … … 140 140 delete [] arrayBuffer[position]; 141 141 size_t len = argument.length(); 142 arrayBuffer[position] = new TCHAR[len+2];142 arrayBuffer[position] = new wchar_t[len+2]; 143 143 wcsncpy_s(arrayBuffer[position], len+1, argument.c_str(), len); 144 144 arrayBuffer[position][len] = 0; … … 153 153 * @return The arrayBuffer 154 154 */ 155 arrayBuffer::arrayBuffer arrayBuffer::split2arrayBuffer(const std::wstring inBuf, TCHARsplitChar, unsigned int &argLen, bool escape) {155 arrayBuffer::arrayBuffer arrayBuffer::split2arrayBuffer(const std::wstring inBuf, wchar_t splitChar, unsigned int &argLen, bool escape) { 156 156 if (inBuf.empty()) 157 157 return createEmptyArrayBuffer(argLen); … … 197 197 for (std::list<std::wstring>::const_iterator cit=token_list.begin();cit!=token_list.end();++cit) { 198 198 size_t len = (*cit).size(); 199 TCHAR* token = new TCHAR[len+1];199 wchar_t* token = new wchar_t[len+1]; 200 200 wcsncpy_s(token, len+1, (*cit).c_str(), len); 201 201 arrayBuffer[argLen++] = token; … … 289 289 std::wcout << "arrayBuffer::test_createEmptyArrayBuffer() : "; 290 290 unsigned int argLen; 291 TCHAR** c = createEmptyArrayBuffer(argLen);291 wchar_t ** c = createEmptyArrayBuffer(argLen); 292 292 if ((c) && (argLen == 0)) 293 293 std::wcout << "Succeeded" << std::endl; … … 302 302 * @param OUT_argLen 303 303 */ 304 void arrayBuffer::test_split2arrayBuffer_str(std::wstring buffer, TCHARsplitter, int OUT_argLen) {304 void arrayBuffer::test_split2arrayBuffer_str(std::wstring buffer, wchar_t splitter, int OUT_argLen) { 305 305 std::wcout << _T("arrayBuffer::test_split2arrayBuffer(") << buffer << _T(", ...) : "); 306 306 unsigned int argLen = 0; 307 TCHAR** c = split2arrayBuffer(buffer, splitter, argLen);307 wchar_t ** c = split2arrayBuffer(buffer, splitter, argLen); 308 308 if ((c) && (argLen == OUT_argLen)) 309 309 std::wcout << _T("Succeeded") << std::endl; … … 318 318 * @param OUT_argLen 319 319 */ 320 void arrayBuffer::test_split2arrayBuffer_char( TCHAR* buffer, TCHARsplitter, int OUT_argLen) {320 void arrayBuffer::test_split2arrayBuffer_char(wchar_t* buffer, wchar_t splitter, int OUT_argLen) { 321 321 std::wcout << _T("arrayBuffer::test_split2arrayBuffer(") << buffer << _T(", ...) : "); 322 322 unsigned int argLen = 0; 323 TCHAR** c = split2arrayBuffer(buffer, splitter, argLen);323 wchar_t ** c = split2arrayBuffer(buffer, splitter, argLen); 324 324 if ((c) && (argLen == OUT_argLen)) 325 325 std::wcout << _T("Succeeded") << std::endl; -
trunk/include/arrayBuffer.h
r169 r207 20 20 ***************************************************************************/ 21 21 #pragma once 22 23 #include <tchar.h> 22 #include <unicode_char.hpp> 24 23 #include <string> 25 24 #include <list> … … 54 53 ArrayBufferException(std::wstring error) {} 55 54 }; 56 typedef TCHAR* arrayBufferItem;55 typedef wchar_t* arrayBufferItem; 57 56 typedef arrayBufferItem* arrayBuffer; 58 57 typedef std::list<std::wstring> arrayList; 59 58 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); 61 60 arrayBuffer list2arrayBuffer(const arrayList lst, unsigned int &argLen); 62 arrayBuffer split2arrayBuffer(const TCHAR* buffer, TCHARsplitChar, unsigned int &argLen);63 arrayBuffer split2arrayBuffer(const std::wstring inBuf, TCHARsplitChar, 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); 65 64 arrayBuffer createEmptyArrayBuffer(unsigned int &argLen); 66 65 arrayBuffer createArrayBuffer(unsigned int &argLen); … … 70 69 for (unsigned int i=0; i<argLen; i++) { 71 70 size_t s = wcslen(other[i]); 72 ret[i] = new TCHAR[s+2];71 ret[i] = new wchar_t[s+2]; 73 72 wcsncpy_s(ret[i], s+2, other[i], s); 74 73 } … … 78 77 #ifdef _DEBUG 79 78 void test_createEmptyArrayBuffer(); 80 void test_split2arrayBuffer_str(std::wstring buffer, TCHARsplitter, int OUT_argLen);81 void test_split2arrayBuffer_char( TCHAR* buffer, TCHARsplitter, 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); 82 81 void run_testArrayBuffer(); 83 82 #endif -
trunk/include/charEx.h
r169 r207 20 20 ***************************************************************************/ 21 21 #pragma once 22 #ifdef WIN32 22 23 #include <windows.h> 23 24 #include <tchar.h> 25 #endif 24 26 25 27 namespace charEx { … … 30 32 * @return a list with strings 31 33 */ 32 inline std::list<std::wstring> split(const TCHAR* buffer, TCHARsplit) {34 inline std::list<std::wstring> split(const wchar_t* buffer, wchar_t split) { 33 35 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++) { 36 38 if (*p==split) { 37 39 std::wstring str(start, p-start); … … 44 46 } 45 47 46 48 /* 47 49 inline char* tchar_to_char( const wchar_t* pStr, int len, int &nChars) { 48 50 if (pStr == NULL) … … 78 80 --nChars; 79 81 if (nChars == 0) { 80 TCHAR *ret = new TCHAR[1];82 wchar_t *ret = new wchar_t[1]; 81 83 ret[0] = 0; 82 84 return ret; … … 84 86 85 87 // convert the narrow string to a wide string 86 TCHAR *ret = new TCHAR[nChars+1];88 wchar_t *ret = new wchar_t[nChars+1]; 87 89 MultiByteToWideChar(CP_ACP, 0 ,pStr ,len, const_cast<wchar_t*>(ret), nChars); 88 90 return ret; 89 91 } 92 */ 90 93 91 94 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) { 95 97 if (buffer == NULL) 96 98 throw std::exception(); 97 TCHAR*p = wcschr(buffer, split);99 wchar_t *p = wcschr(buffer, split); 98 100 if (!p) 99 101 return token(buffer, NULL); … … 104 106 } 105 107 #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) { 107 109 token t = getToken(in1, in2); 108 110 std::wcout << _T("charEx::test_getToken(") << in1 << _T(", ") << in2 << _T(") : "); -
trunk/include/checkHelpers.hpp
r201 r207 277 277 } 278 278 static std::wstring print(__int64 value) { 279 return strEx::itos(value);279 return boost::lexical_cast<std::wstring>(value); 280 280 } 281 281 static std::wstring get_perf_unit(__int64 value) { … … 283 283 } 284 284 static std::wstring print_perf(__int64 value, std::wstring unit) { 285 return strEx::itos(value);285 return boost::lexical_cast<std::wstring>(value); 286 286 } 287 287 static std::wstring print_unformated(__int64 value) { 288 return strEx::itos(value);288 return boost::lexical_cast<std::wstring>(value); 289 289 } 290 290 static std::wstring print_percent(__int64 value) { 291 return strEx::itos(value) + _T("%");291 return boost::lexical_cast<std::wstring>(value) + _T("%"); 292 292 } 293 293 static std::wstring key_prefix() { -
trunk/include/config.h
r205 r207 22 22 23 23 #include "../AutoBuild.h" 24 /* 24 25 #include <tchar.h> 26 */ 25 27 #include <string> 26 28 #include <settings/macros.h> … … 197 199 #define LUA_SCRIPT_SECTION_TITLE _T("LUA Scripts") 198 200 */ 199 200 // Main Registry ROOT201 #define NS_HKEY_ROOT HKEY_LOCAL_MACHINE202 #define NS_REG_ROOT _T("SOFTWARE\\NSClient++") -
trunk/include/error.hpp
r201 r207 1 1 #pragma once 2 #include < tchar.h>2 #include <unicode_char.hpp> 3 3 #include <string> 4 #include <windows.h>5 4 #include <strEx.h> 6 5 #include <vector> 7 6 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 148 148 unsigned int getBufferLength() const { return getBufferLength(buffer_length_); } 149 149 static unsigned int getBufferLength(unsigned int buffer_length) { return sizeof(packet)+buffer_length*sizeof(char); } 150 unsigned int getInternalBufferLength() const { return buffer_length_; } 150 151 151 152 -
trunk/include/settings/macros.h
r205 r207 1 1 #pragma once 2 2 3 3 #include <unicode_char.hpp> 4 4 5 5 #define DEFINE_SETTING_S(name, path, key, value) \ … … 39 39 setting_keys::key ## _PATH, setting_keys::key, type, setting_keys::key ## _TITLE, setting_keys::key ## _DESC, setting_keys::key ## _DEFAULT, setting_keys::key ## _ADVANCED 40 40 #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 ## _ADVANCED41 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 42 42 #define SETTINGS_REG_KEY_B_GEN(key, type) \ 43 43 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 … … 57 57 #define GENERIC_KEY_OBFUSCATED_PWD "obfuscated password" 58 58 #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++") 59 64 60 65 … … 217 222 DESCRIBE_SETTING(SYNTAX, "SYNTAX", "Set this to use a specific syntax string for all commands (that don't specify one)."); 218 223 219 DEFINE_SETTING_I(BUFFER_SIZE, EVENT_LOG_SECTION, "buffer_size", 4096);224 DEFINE_SETTING_I(BUFFER_SIZE, EVENT_LOG_SECTION, "buffer_size", 65535); 220 225 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."); 221 226 } -
trunk/include/settings/settings_old.hpp
r205 r207 5 5 #include <settings/Settings.h> 6 6 #include <simpleini/SimpleIni.h> 7 #include <settings/macros.h> 7 8 8 9 #define MAIN_MODULES_SECTION_OLD _T("modules") -
trunk/include/settings/settings_registry.hpp
r202 r207 6 6 #include <msvc_wrappers.h> 7 7 #include <error.hpp> 8 #include <settings/macros.h> 8 9 #define BUFF_LEN 4096 9 10 -
trunk/include/strEx.h
r205 r207 20 20 ***************************************************************************/ 21 21 #pragma once 22 23 #include <tchar.h> 24 #include <windows.h> 22 #include <unicode_char.hpp> 25 23 #include <sstream> 26 24 #include <iomanip> … … 32 30 #include <algorithm> 33 31 #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 34 41 35 42 … … 38 45 #endif 39 46 47 48 49 50 #include <string> 51 #include <locale> 52 53 namespace 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 } 40 79 namespace strEx { 41 80 class string_exception : public std::exception { … … 46 85 return _what; 47 86 } 87 virtual ~string_exception() throw(); 48 88 }; 49 89 namespace s { … … 72 112 lst += append; 73 113 } 74 114 /* 75 115 inline std::string wstring_to_string( const wchar_t* pStr, int len) { 76 116 if (pStr == NULL) … … 95 135 return buf ; 96 136 } 137 */ 97 138 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 /* 101 143 inline std::wstring string_to_wstring( const char* pStr , int len ) { 102 144 if (pStr == NULL) … … 120 162 return buf ; 121 163 } 164 */ 122 165 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())) ; 124 168 } 125 169 … … 164 208 return ss.str(); 165 209 } 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]; 169 231 struct tm nt; // = new struct tm; 170 232 #if (_MSC_VER > 1300) // 1300 == VC++ 7.0 … … 172 234 return _T(""); 173 235 #else 236 struct tm nt; // = new struct tm; 174 237 nt = gmtime(&time); 175 238 if (nt == NULL) … … 181 244 buf[l] = 0; 182 245 return buf; 183 } 246 */ 247 } 248 /* 184 249 inline std::wstring format_date(const SYSTEMTIME &time, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 185 TCHAR buf[51];186 187 250 struct tm tmTime; 188 251 memset(&tmTime, 0, sizeof(tmTime)); … … 205 268 static const __int64 SECS_BETWEEN_EPOCHS = 11644473600; 206 269 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 207 279 inline std::wstring format_filetime(unsigned long long filetime, std::wstring format = _T("%Y-%m-%d %H:%M:%S")) { 208 280 filetime -= (SECS_BETWEEN_EPOCHS * SECS_TO_100NS); … … 222 294 } 223 295 } 224 inline std::wstring ctos( TCHARc) {296 inline std::wstring ctos(wchar_t c) { 225 297 return std::wstring(1, c); 226 298 } 227 inline TCHARstoc(std::wstring str) {299 inline wchar_t stoc(std::wstring str) { 228 300 if (str.length() == 0) 229 301 return L' '; … … 245 317 return ss.str(); 246 318 } 319 /* 247 320 inline std::wstring itos(__int64 i) { 248 321 std::wstringstream ss; … … 250 323 return ss.str(); 251 324 } 325 */ 252 326 inline std::wstring itos(unsigned long i) { 253 327 std::wstringstream ss; … … 284 358 } 285 359 inline int stoi(std::wstring s) { 286 return _wtoi(s.c_str());360 return boost::lexical_cast<int>(s.c_str()); 287 361 } 288 362 inline double stod(std::wstring s) { 289 return _wtof(s.c_str());363 return boost::lexical_cast<double>(s.c_str()); 290 364 } 291 365 inline long long stoi64(std::wstring s) { 292 return _wtoi64(s.c_str());366 return boost::lexical_cast<long long>(s.c_str()); 293 367 } 294 368 inline unsigned stoui_as_time(std::wstring time, unsigned int smallest_unit = 1000) { 295 369 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()); 297 371 if (p == std::wstring::npos) 298 372 return value * smallest_unit; … … 312 386 inline unsigned long long stoi64_as_time(std::wstring time, unsigned int smallest_unit = 1000) { 313 387 std::wstring::size_type p = time.find_first_of(_T("sSmMhHdDwW")); 314 unsigned long long value = _wtoi64(time.c_str());315 388 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') ) 318 392 return value * 1000; 319 393 else if ( (time[p] == 'm') || (time[p] == 'M') ) … … 378 452 std::wstring::size_type p = s.find_first_of(_T("BMKGT")); 379 453 if (p == std::wstring::npos) 380 return _wtoi64(s.c_str());454 return boost::lexical_cast<long long>(s.c_str()); 381 455 else if (s[p] == 'B') 382 return _wtoi64(s.c_str());456 return boost::lexical_cast<long long>(s.c_str()); 383 457 else if (s[p] == 'K') 384 return _wtoi64(s.c_str())*1024;458 return boost::lexical_cast<long long>(s.c_str())*1024; 385 459 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; 387 461 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; 389 463 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; 391 465 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") 395 469 #define BKMG_SIZE 5 396 470 397 inline std::wstring itos_as_BKMG(unsigned __int64i) {471 inline std::wstring itos_as_BKMG(unsigned long long i) { 398 472 double cpy = static_cast<double>(i); 399 TCHAR postfix[] = _T(BKMG_RANGE);473 wchar_t postfix[] = BKMG_RANGE; 400 474 int idx = 0; 401 475 while ((cpy > 999)&&(idx<BKMG_SIZE)) { … … 410 484 return ret; 411 485 } 412 inline std::wstring format_BKMG(unsigned __int64i, std::wstring unit) {486 inline std::wstring format_BKMG(unsigned long long i, std::wstring unit) { 413 487 double cpy = static_cast<double>(i); 414 TCHAR postfix[] = _T(BKMG_RANGE);488 wchar_t postfix[] = BKMG_RANGE; 415 489 if (unit.length() != 1) 416 490 return itos(cpy); … … 430 504 return itos(cpy); 431 505 } 432 inline std::wstring find_proper_unit_BKMG(unsigned __int64i) {506 inline std::wstring find_proper_unit_BKMG(unsigned long long i) { 433 507 double cpy = static_cast<double>(i); 434 TCHAR postfix[] = _T(BKMG_RANGE);508 wchar_t postfix[] = BKMG_RANGE; 435 509 int idx = 0; 436 510 while ((cpy > 999)&&(idx<BKMG_SIZE)) { … … 523 597 524 598 // There's no memichr(), so we roll our own. It ain't rocket science. 525 static const _E * __cdeclfind(const _E *buf, size_t len, const _E& ch) {599 static const _E * /*__cdecl*/ find(const _E *buf, size_t len, const _E& ch) { 526 600 // Jerry says that x86s have special mojo for memchr(), so the 527 601 // memchr() calls end up being reasonably efficient in practice. … … 539 613 540 614 // 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 ) ); 543 617 } 544 618 }; … … 547 621 //typedef std::basic_string<char, blind_traits<char>, std::allocator<char> > blindstr; 548 622 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 558 623 559 624 class StrICmp … … 596 661 } 597 662 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 }; 598 670 599 671 #ifdef _DEBUG … … 635 707 } 636 708 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; 709 template <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 ""; 667 715 } 668 716 } 669 717 template <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 680 680 unsigned long long now = ((now_.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now_.dwLowDateTime); 681 681 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); 683 683 return NSCAPI::returnOK; 684 684 } -
trunk/modules/CheckDisk/stdafx.h
r75 r207 30 30 #include <NSCAPI.h> 31 31 #include <NSCHelper.h> 32 #include <nsc_module_wrapper.hpp> 32 33 33 34 #ifdef MEMCHECK -
trunk/modules/CheckEventLog/CheckEventLog.cpp
r205 r207 361 361 return ret; 362 362 } 363 SYSTEMTIME get_time(DWORD time) { 363 // SYSTEMTIME 364 boost::posix_time::ptime get_time(DWORD time) { 364 365 FILETIME FileTime, LocalFileTime; 365 366 SYSTEMTIME SysTime; … … 372 373 FileTime.dwHighDateTime = (DWORD)(lgTemp >> 32); 373 374 375 return boost::date_time::time_from_ftime<boost::posix_time::ptime>(FileTime); 376 377 378 /* 374 379 FileTimeToLocalFileTime(&FileTime, &LocalFileTime); 375 380 FileTimeToSystemTime(&LocalFileTime, &SysTime); 376 381 return SysTime; 377 } 378 379 SYSTEMTIME get_time_generated() { 382 */ 383 } 384 385 boost::posix_time::ptime get_time_generated() { 380 386 return get_time(pevlr_->TimeGenerated); 381 387 } 382 SYSTEMTIMEget_time_written() {388 boost::posix_time::ptime get_time_written() { 383 389 return get_time(pevlr_->TimeWritten); 384 390 } -
trunk/modules/CheckEventLog/stdafx.h
r75 r207 34 34 35 35 #include <NSCAPI.h> 36 #include <nsc_module_wrapper.hpp> 36 37 #include <NSCHelper.h> 37 38 -
trunk/modules/CheckExternalScripts
- Property svn:ignore
-
old new 1 1 *.user 2 Debug
-
- Property svn:ignore
-
trunk/modules/CheckExternalScripts/CheckExternalScripts-2005.vcproj
r202 r207 49 49 Name="VCCLCompilerTool" 50 50 AdditionalIncludeDirectories="../include;../../include" 51 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1;USE_BOOST" 51 52 /> 52 53 <Tool … … 114 115 Name="VCCLCompilerTool" 115 116 AdditionalIncludeDirectories="../include;../../include" 117 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_STLP_USE_NEWALLOC;_STLP_DEBUG=1;USE_BOOST" 116 118 /> 117 119 <Tool … … 127 129 Name="VCLinkerTool" 128 130 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" 129 259 /> 130 260 <Tool -
trunk/modules/CheckExternalScripts/stdafx.h
r205 r207 30 30 #include <utils.h> 31 31 32 #include <boost/lexical_cast.hpp> 33 32 34 #include <NSCAPI.h> 35 #include <nsc_module_wrapper.hpp> 33 36 #include <NSCHelper.h> 34 37 -
trunk/modules/CheckHelpers/stdafx.h
r75 r207 29 29 30 30 #include <NSCAPI.h> 31 #include <nsc_module_wrapper.hpp> 31 32 #include <NSCHelper.h> 32 33 -
trunk/modules/CheckSystem/CheckSystem.cpp
r202 r207 365 365 } 366 366 static std::wstring print_perf(__int64 value, std::wstring unit) { 367 return strEx::itos(value);367 return to_wstring(value); 368 368 } 369 369 static std::wstring print_percent(int value) { 370 return strEx::itos(value) + _T("%");370 return to_wstring(value) + _T("%"); 371 371 } 372 372 static std::wstring key_prefix() { -
trunk/modules/CheckSystem/stdafx.h
r75 r207 35 35 #include <list> 36 36 #include <NSCAPI.h> 37 #include <nsc_module_wrapper.hpp> 37 38 #include <NSCHelper.h> 38 39 #include <config.h> -
trunk/modules/CheckTaskSched/stdafx.h
r130 r207 35 35 #include <NSCAPI.h> 36 36 #include <NSCHelper.h> 37 #include <nsc_module_wrapper.hpp> 37 38 #include <checkHelpers.hpp> 38 39 #include <filter_framework.hpp> -
trunk/modules/CheckWMI/WMIQuery.h
r201 r207 101 101 void setString(std::wstring a, std::wstring s) { 102 102 string = s; 103 numeric = strEx::stoi64(s);103 numeric = boost::lexical_cast<long long>(s); 104 104 alias = a; 105 105 } 106 106 void setNumeric(std::wstring a, long long n) { 107 107 numeric = n; 108 string = strEx::itos(n);108 string = to_wstring(n); 109 109 alias = a; 110 110 } -
trunk/modules/CheckWMI/stdafx.h
r75 r207 35 35 #include <NSCAPI.h> 36 36 #include <NSCHelper.h> 37 #include <nsc_module_wrapper.hpp> 37 38 #include <checkHelpers.hpp> 38 39 #include <filter_framework.hpp> -
trunk/modules/DebugLogMetrics/stdafx.h
r201 r207 33 33 #include <NSCAPI.h> 34 34 #include <NSCHelper.h> 35 #include <nsc_module_wrapper.hpp> 35 36 36 37 #ifdef MEMCHECK -
trunk/modules/FileLogger/stdafx.h
r75 r207 27 27 #include <NSCAPI.h> 28 28 #include <NSCHelper.h> 29 #include <nsc_module_wrapper.hpp> 29 30 #include <string> 30 31 #include <iostream> -
trunk/modules/LUAScript/stdafx.h
r88 r207 30 30 #include <NSCAPI.h> 31 31 #include <NSCHelper.h> 32 #include <nsc_module_wrapper.hpp> 32 33 33 34 #ifdef MEMCHECK -
trunk/modules/NRPEClient/NRPEClient.cpp
r206 r207 186 186 #endif 187 187 188 using boost::asio::ip::tcp;189 188 190 189 int NRPEClient::commandLineExec(const TCHAR* command, const unsigned int argLen, TCHAR** args) { … … 246 245 } 247 246 } 247 /* 248 248 NRPEPacket NRPEClient::send_ssl(std::wstring host, int port, int timeout, NRPEPacket packet) 249 249 { … … 251 251 return send_nossl(host, port, timeout, packet); 252 252 #else 253 253 254 initSSL(); 254 255 simpleSSL::Socket socket(true); … … 261 262 packet.readFrom(buffer.getBuffer(), buffer.getLength()); 262 263 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 */ 275 using boost::asio::ip::tcp; 266 276 267 277 void set_result(boost::optional<boost::system::error_code>* a, boost::system::error_code b) … … 269 279 a->reset(b); 270 280 } 271 template <typename MutableBufferSequence>272 void read_with_timeout( tcp::socket& sock, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration)281 template <typename AsyncReadStream, typename RawSocket, typename MutableBufferSequence> 282 void read_with_timeout(AsyncReadStream& sock, RawSocket& rawSocket, const MutableBufferSequence& buffers, boost::posix_time::time_duration duration) 273 283 { 274 284 boost::optional<boost::system::error_code> timer_result; … … 286 296 timer.cancel(); 287 297 else if (timer_result) 288 sock.close();298 rawSocket.close(); 289 299 } 290 300 … … 293 303 } 294 304 305 template <typename AsyncWriteStream, typename RawSocket, typename MutableBufferSequence> 306 void 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 329 class nrpe_socket : public boost::noncopyable { 330 public: 331 tcp::socket socket_; 332 333 public: 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 372 class nrpe_ssl_socket { 373 374 private: 375 boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_; 376 public: 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 295 422 NRPEPacket NRPEClient::send_nossl(std::wstring host, int port, int timeout, NRPEPacket packet) 296 423 { 297 424 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 430 NRPEPacket 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 } 338 441 /* 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 442 NRPEPacket 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 */ 349 468 350 469 -
trunk/modules/NRPEClient/stdafx.h
r206 r207 36 36 #include <NSCAPI.h> 37 37 #include <NSCHelper.h> 38 #include <nsc_module_wrapper.hpp> 38 39 39 40 #include <boost/array.hpp> 40 #include <boost/date_time/posix_time/posix_time.hpp>41 41 #include <boost/asio.hpp> 42 #include <boost/optional.hpp> 42 43 #include <boost/bind.hpp> 44 #include <boost/asio/ssl.hpp> 43 45 44 46 #ifdef MEMCHECK -
trunk/modules/NRPEListener/stdafx.h
r75 r207 33 33 #include <NSCAPI.h> 34 34 #include <NSCHelper.h> 35 #include <nsc_module_wrapper.hpp> 35 36 36 37 #ifdef MEMCHECK -
trunk/modules/NSCAAgent/stdafx.h
r87 r207 36 36 #include <NSCAPI.h> 37 37 #include <NSCHelper.h> 38 #include <nsc_module_wrapper.hpp> 38 39 #include <config.h> 39 40 #include <utils.h> -
trunk/modules/NSClientListener/stdafx.h
r75 r207 30 30 #include <NSCAPI.h> 31 31 #include <NSCHelper.h> 32 #include <nsc_module_wrapper.hpp> 32 33 33 34 #ifdef MEMCHECK -
trunk/modules/SysTray/stdafx.h
r75 r207 27 27 #include <string> 28 28 #include <NSCHelper.h> 29 #include <nsc_module_wrapper.hpp> 29 30 #include <assert.h> 30 31 -
trunk/service/NSCPlugin.cpp
r205 r207 31 31 */ 32 32 NSCPlugin::NSCPlugin(const std::wstring file) 33 : file_(file) 34 ,hModule_(NULL) 33 : module_(file) 35 34 ,fLoadModule(NULL) 36 35 ,fGetName(NULL) … … 50 49 { 51 50 } 52 51 /* 53 52 NSCPlugin::NSCPlugin(NSCPlugin &other) 54 : hModule_(NULL)53 :module_() 55 54 ,fLoadModule(NULL) 56 55 ,fGetName(NULL) … … 80 79 } 81 80 } 82 81 */ 83 82 /** 84 83 * Default d-tor … … 96 95 */ 97 96 std::wstring NSCPlugin::getName() { 98 TCHAR *buffer = new TCHAR[1024];97 wchar_t *buffer = new wchar_t[1024]; 99 98 if (!getName_(buffer, 1023)) { 100 99 return _T("Could not get name"); … … 105 104 } 106 105 std::wstring NSCPlugin::getDescription() { 107 TCHAR *buffer = new TCHAR[4096];106 wchar_t *buffer = new wchar_t[4096]; 108 107 if (!getDescription_(buffer, 4095)) { 109 throw NSPluginException( file_, _T("Could not get description"));108 throw NSPluginException(module_, _T("Could not get description")); 110 109 } 111 110 std::wstring ret = buffer; … … 121 120 */ 122 121 void 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 } 128 129 loadRemoteProcs_(); 129 130 bLoaded_ = true; … … 132 133 bool NSCPlugin::load_plugin(NSCAPI::moduleLoadMode mode) { 133 134 if (!fLoadModule) 134 throw NSPluginException( file_, _T("Critical error (fLoadModule)"));135 throw NSPluginException(module_, _T("Critical error (fLoadModule)")); 135 136 return fLoadModule(mode); 136 137 } … … 156 157 bool NSCPlugin::getVersion(int *major, int *minor, int *revision) { 157 158 if (!isLoaded()) 158 throw NSPluginException( file_, _T("Library is not loaded"));159 throw NSPluginException(module_, _T("Library is not loaded")); 159 160 if (!fGetVersion) 160 throw NSPluginException( file_, _T("Critical error (fGetVersion)"));161 throw NSPluginException(module_, _T("Critical error (fGetVersion)")); 161 162 try { 162 163 return fGetVersion(major, minor, revision)?true:false; 163 164 } catch (...) { 164 throw NSPluginException( file_, _T("Unhandled exception in getVersion."));165 throw NSPluginException(module_, _T("Unhandled exception in getVersion.")); 165 166 } 166 167 } … … 172 173 bool NSCPlugin::hasCommandHandler() { 173 174 if (!isLoaded()) 174 throw NSPluginException( file_, _T("Module not loaded"));175 throw NSPluginException(module_, _T("Module not loaded")); 175 176 try { 176 177 if (fHasCommandHandler()) … … 178 179 return false; 179 180 } catch (...) { 180 throw NSPluginException( file_, _T("Unhandled exception in hasCommandHandler."));181 throw NSPluginException(module_, _T("Unhandled exception in hasCommandHandler.")); 181 182 } 182 183 } … … 188 189 bool NSCPlugin::hasMessageHandler() { 189 190 if (!isLoaded()) 190 throw NSPluginException( file_, _T("Module not loaded"));191 throw NSPluginException(module_, _T("Module not loaded")); 191 192 try { 192 193 if (fHasMessageHandler()) { … … 196 197 return false; 197 198 } catch (...) { 198 throw NSPluginException( file_, _T("Unhandled exception in hasMessageHandler."));199 throw NSPluginException(module_, _T("Unhandled exception in hasMessageHandler.")); 199 200 } 200 201 } … … 214 215 * @throws NSPluginException if the module is not loaded. 215 216 */ 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"));217 NSCAPI::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")); 219 220 try { 220 221 return fHandleCommand(command, argLen, arguments, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 221 222 } catch (...) { 222 throw NSPluginException( file_, _T("Unhandled exception in handleCommand."));223 throw NSPluginException(module_, _T("Unhandled exception in handleCommand.")); 223 224 } 224 225 } … … 232 233 * @throws NSPluginException if the module is not loaded. 233 234 */ 234 void NSCPlugin::handleMessage(int msgType, const TCHAR* file, const int line, const TCHAR*message) {235 void NSCPlugin::handleMessage(int msgType, const wchar_t* file, const int line, const wchar_t *message) { 235 236 if (!fHandleMessage) 236 throw NSPluginException( file_, _T("Library is not loaded"));237 throw NSPluginException(module_, _T("Library is not loaded")); 237 238 try { 238 239 fHandleMessage(msgType, file, line, message); 239 240 } catch (...) { 240 throw NSPluginException( file_, _T("Unhandled exception in handleMessage."));241 throw NSPluginException(module_, _T("Unhandled exception in handleMessage.")); 241 242 } 242 243 } … … 247 248 void NSCPlugin::unload() { 248 249 if (!isLoaded()) 249 throw NSPluginException(file_, _T("Library is not loaded")); 250 throw NSPluginException(module_, _T("Library is not loaded")); 251 bLoaded_ = false; 250 252 if (!fUnLoadModule) 251 throw NSPluginException( file_, _T("Critical error (fUnLoadModule)"));253 throw NSPluginException(module_, _T("Critical error (fUnLoadModule)")); 252 254 try { 253 255 fUnLoadModule(); 254 256 } 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 } 261 bool NSCPlugin::getName_(wchar_t* buf, unsigned int buflen) { 262 262 if (fGetName == NULL) 263 return false;//throw NSPluginException( file_, _T("Critical error (fGetName)"));263 return false;//throw NSPluginException(module_, _T("Critical error (fGetName)")); 264 264 try { 265 265 return fGetName(buf, buflen)?true:false; 266 266 } 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 } 270 bool NSCPlugin::getDescription_(wchar_t* buf, unsigned int buflen) { 271 271 if (fGetDescription == NULL) 272 throw NSPluginException( file_, _T("Critical error (fGetDescription)"));272 throw NSPluginException(module_, _T("Critical error (fGetDescription)")); 273 273 try { 274 274 return fGetDescription(buf, buflen)?true:false; 275 275 } catch (...) { 276 throw NSPluginException( file_, _T("Unhandled exception in getDescription."));276 throw NSPluginException(module_, _T("Unhandled exception in getDescription.")); 277 277 } 278 278 } … … 280 280 void NSCPlugin::showTray() { 281 281 if (fShowTray == NULL) 282 throw NSPluginException( file_, _T("Critical error (ShowTray)"));282 throw NSPluginException(module_, _T("Critical error (ShowTray)")); 283 283 try { 284 284 fShowTray(); 285 285 } catch (...) { 286 throw NSPluginException( file_, _T("Unhandled exception in ShowTray."));286 throw NSPluginException(module_, _T("Unhandled exception in ShowTray.")); 287 287 } 288 288 } 289 289 void NSCPlugin::hideTray() { 290 290 if (fHideTray == NULL) 291 throw NSPluginException( file_, _T("Critical error (HideTray)"));291 throw NSPluginException(module_, _T("Critical error (HideTray)")); 292 292 try { 293 293 fHideTray(); 294 294 } catch (...) { 295 throw NSPluginException( file_, _T("Unhandled exception in HideTray."));295 throw NSPluginException(module_, _T("Unhandled exception in HideTray.")); 296 296 } 297 297 } … … 305 305 void NSCPlugin::loadRemoteProcs_(void) { 306 306 307 fLoadModule = (lpLoadModule) GetProcAddress(hModule_,"NSLoadModule");307 fLoadModule = (lpLoadModule)module_.load_proc("NSLoadModule"); 308 308 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"); 312 312 if (!fModuleHelperInit) 313 throw NSPluginException( file_, _T("Could not load NSModuleHelperInit"));313 throw NSPluginException(module_, _T("Could not load NSModuleHelperInit")); 314 314 315 315 try { 316 316 fModuleHelperInit(NSAPILoader); 317 317 } catch (...) { 318 throw NSPluginException( file_, _T("Unhandled exception in getDescription."));318 throw NSPluginException(module_, _T("Unhandled exception in getDescription.")); 319 319 } 320 320 321 fGetName = (lpGetName) GetProcAddress(hModule_,"NSGetModuleName");321 fGetName = (lpGetName)module_.load_proc("NSGetModuleName"); 322 322 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"); 326 326 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"); 330 330 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"); 334 334 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"); 338 338 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"); 342 342 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"); 346 346 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"); 350 350 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"); 358 358 359 359 } … … 362 362 std::wstring NSCPlugin::getCongifurationMeta() 363 363 { 364 TCHAR *buffer = new TCHAR[4097];364 wchar_t *buffer = new wchar_t[4097]; 365 365 if (!getConfigurationMeta_(buffer, 4096)) { 366 throw NSPluginException( file_, _T("Could not get metadata"));366 throw NSPluginException(module_, _T("Could not get metadata")); 367 367 } 368 368 std::wstring ret = buffer; … … 370 370 return ret; 371 371 } 372 bool NSCPlugin::getConfigurationMeta_( TCHAR* buf, unsigned int buflen) {372 bool NSCPlugin::getConfigurationMeta_(wchar_t* buf, unsigned int buflen) { 373 373 if (fGetConfigurationMeta == NULL) 374 throw NSPluginException( file_, _T("Critical error (getCongifurationMeta)"));374 throw NSPluginException(module_, _T("Critical error (getCongifurationMeta)")); 375 375 try { 376 376 return fGetConfigurationMeta(buflen, buf)?true:false; 377 377 } 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 382 int NSCPlugin::commandLineExec(const wchar_t* command, const unsigned int argLen, wchar_t **arguments) { 383 383 if (fCommandLineExec== NULL) 384 throw NSPluginException( file_, _T("Module does not support CommandLineExec"));384 throw NSPluginException(module_, _T("Module does not support CommandLineExec")); 385 385 try { 386 386 return fCommandLineExec(command, argLen, arguments); 387 387 } 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 22 22 23 23 #include <NSCAPI.h> 24 #include <NSCHelper.h>24 //#include <NSCHelper.h> 25 25 #include <sstream> 26 #include <dll/dll.hpp> 26 27 27 28 /** … … 58 59 * @param error An error message (human readable format) 59 60 */ 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()); 62 63 } 63 64 std::wstring getModule(std::wstring file) { … … 105 106 private: 106 107 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_; 109 109 bool broken_; 110 110 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*); 123 123 typedef void (*lpShowTray)(); 124 124 typedef void (*lpHideTray)(); … … 154 154 bool hasCommandHandler(void); 155 155 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); 158 158 void unload(void); 159 159 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); 161 161 void showTray(); 162 162 void hideTray(); 163 163 164 164 std::wstring getFilename() { 165 if (file_.empty()) 165 std::wstring file = module_.get_file(); 166 if (file.empty()) 166 167 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); 170 171 } 171 return file _;172 return file; 172 173 } 173 174 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); 180 179 } 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; 186 181 } 187 182 bool getLastIsMsgPlugin() { … … 194 189 private: 195 190 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); 198 193 void loadRemoteProcs_(void); 199 bool getConfigurationMeta_( TCHAR* buf, unsigned int buflen);194 bool getConfigurationMeta_(wchar_t* buf, unsigned int buflen); 200 195 }; 201 196 -
trunk/service/NSClient++-2005.vcproj
r205 r207 2093 2093 </File> 2094 2094 <File 2095 RelativePath="..\include\Socket.cpp"2096 >2097 <FileConfiguration2098 Name="Release|Win32"2099 >2100 <Tool2101 Name="VCCLCompilerTool"2102 UsePrecompiledHeader="0"2103 PrecompiledHeaderThrough=" "2104 PrecompiledHeaderFile=" "2105 />2106 </FileConfiguration>2107 <FileConfiguration2108 Name="Release|x64"2109 >2110 <Tool2111 Name="VCCLCompilerTool"2112 UsePrecompiledHeader="0"2113 PrecompiledHeaderThrough=" "2114 PrecompiledHeaderFile=" "2115 />2116 </FileConfiguration>2117 <FileConfiguration2118 Name="Debug|Win32"2119 >2120 <Tool2121 Name="VCCLCompilerTool"2122 UsePrecompiledHeader="0"2123 PrecompiledHeaderThrough=" "2124 PrecompiledHeaderFile=" "2125 />2126 </FileConfiguration>2127 <FileConfiguration2128 Name="Debug|x64"2129 >2130 <Tool2131 Name="VCCLCompilerTool"2132 UsePrecompiledHeader="0"2133 PrecompiledHeaderThrough=" "2134 PrecompiledHeaderFile=" "2135 />2136 </FileConfiguration>2137 <FileConfiguration2138 Name="Distribution|Win32"2139 >2140 <Tool2141 Name="VCCLCompilerTool"2142 UsePrecompiledHeader="0"2143 PrecompiledHeaderThrough=" "2144 PrecompiledHeaderFile=" "2145 />2146 </FileConfiguration>2147 <FileConfiguration2148 Name="Distribution|x64"2149 >2150 <Tool2151 Name="VCCLCompilerTool"2152 UsePrecompiledHeader="0"2153 PrecompiledHeaderThrough=" "2154 PrecompiledHeaderFile=" "2155 />2156 </FileConfiguration>2157 <FileConfiguration2158 Name="Nightly|Win32"2159 >2160 <Tool2161 Name="VCCLCompilerTool"2162 UsePrecompiledHeader="0"2163 PrecompiledHeaderThrough=" "2164 PrecompiledHeaderFile=" "2165 />2166 </FileConfiguration>2167 <FileConfiguration2168 Name="Nightly|x64"2169 >2170 <Tool2171 Name="VCCLCompilerTool"2172 UsePrecompiledHeader="0"2173 PrecompiledHeaderThrough=" "2174 PrecompiledHeaderFile=" "2175 />2176 </FileConfiguration>2177 <FileConfiguration2178 Name="Debug-MemCheck|Win32"2179 >2180 <Tool2181 Name="VCCLCompilerTool"2182 UsePrecompiledHeader="0"2183 PrecompiledHeaderThrough=" "2184 PrecompiledHeaderFile=" "2185 />2186 </FileConfiguration>2187 <FileConfiguration2188 Name="Debug-MemCheck|x64"2189 >2190 <Tool2191 Name="VCCLCompilerTool"2192 UsePrecompiledHeader="0"2193 PrecompiledHeaderThrough=" "2194 PrecompiledHeaderFile=" "2195 />2196 </FileConfiguration>2197 <FileConfiguration2198 Name="OP5|Win32"2199 >2200 <Tool2201 Name="VCCLCompilerTool"2202 UsePrecompiledHeader="0"2203 PrecompiledHeaderThrough=" "2204 PrecompiledHeaderFile=" "2205 />2206 </FileConfiguration>2207 <FileConfiguration2208 Name="OP5|x64"2209 >2210 <Tool2211 Name="VCCLCompilerTool"2212 UsePrecompiledHeader="0"2213 PrecompiledHeaderThrough=" "2214 PrecompiledHeaderFile=" "2215 />2216 </FileConfiguration>2217 </File>2218 <File2219 2095 RelativePath="StdAfx.cpp" 2220 2096 > … … 2395 2271 </File> 2396 2272 <File 2273 RelativePath="..\include\dll\dll.hpp" 2274 > 2275 </File> 2276 <File 2397 2277 RelativePath=".\include\error.hpp" 2398 2278 > … … 2403 2283 </File> 2404 2284 <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 2405 2293 RelativePath=".\include\Mutex.h" 2406 2294 > … … 2411 2299 </File> 2412 2300 <File 2413 RelativePath=". \include\NSCAPI.h"2301 RelativePath="..\include\NSCAPI.h" 2414 2302 > 2415 2303 </File> … … 2431 2319 </File> 2432 2320 <File 2433 RelativePath=". \include\NTService.h"2321 RelativePath="..\include\NTService.h" 2434 2322 > 2435 2323 </File> … … 2487 2375 </File> 2488 2376 <File 2489 RelativePath=".\include\Socket.h"2490 >2491 </File>2492 <File2493 2377 RelativePath="StdAfx.h" 2494 2378 > … … 2504 2388 <File 2505 2389 RelativePath=".\tray_manager.hpp" 2390 > 2391 </File> 2392 <File 2393 RelativePath="..\include\unicode_char.hpp" 2506 2394 > 2507 2395 </File> -
trunk/service/NSClient++.cpp
r206 r207 13 13 // 14 14 ////////////////////////////////////////////////////////////////////////// 15 #include "stdafx.h" 16 #include <winsvc.h> 15 #include "StdAfx.h" 17 16 #include "NSClient++.h" 18 17 #include <settings/Settings.h> 19 18 #include <charEx.h> 20 #include <Socket.h>19 //#include <Socket.h> 21 20 #include <config.h> 22 21 #include <msvc_wrappers.h> 22 #ifdef WIN32 23 23 #include <Userenv.h> 24 #include <remote_processes.hpp>25 24 #include <Lmcons.h> 26 25 //#ifdef DEBUG 27 26 #include <crtdbg.h> 28 27 //#endif 29 # include <Userenv.h>28 #endif 30 29 #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> 32 34 #include "core_api.h" 33 35 #include "settings_manager_impl.h" 34 36 #include <settings/macros.h> 37 #include <NSCHelper.h> 35 38 36 39 NSClient mainClient(SZSERVICENAME); // Global core instance. … … 209 212 int nRetCode = 0; 210 213 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 ) { 212 217 bool bGui = false; 213 218 bool bStart = false; … … 288 293 LOG_MESSAGE(_T("Service uninstalled!")); 289 294 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 290 346 } else if ( _wcsicmp( _T("encrypt"), argv[1]+1 ) == 0 ) { 291 347 g_bConsoleLog = true; … … 304 360 settings_manager::destroy_settings(); 305 361 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 }348 362 } else if ( _wcsicmp( _T("about"), argv[1]+1 ) == 0 ) { 349 363 g_bConsoleLog = true; … … 391 405 } else if ( _wcsicmp( _T("noboot"), argv[1]+1 ) == 0 ) { 392 406 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); 404 413 mainClient.exitCore(true); 405 414 return nRetCode; … … 420 429 mainClient.exitCore(true); 421 430 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 }440 431 } else if ( _wcsicmp( _T("test"), argv[1]+1 ) == 0 ) { 441 432 bool server = false; … … 445 436 std::wcout << "Launching test mode - " << (server?_T("server mode"):_T("client mode")) << std::endl; 446 437 LOG_MESSAGE_STD(_T("Booting: " SZSERVICEDISPLAYNAME )); 438 #ifdef WIN32 447 439 try { 448 440 if (serviceControll::isStarted(SZSERVICENAME)) { … … 452 444 e;// Empty by design 453 445 } 446 #endif 454 447 g_bConsoleLog = true; 455 448 mainClient.enableDebug(true); … … 788 781 } 789 782 } 790 783 /* 791 784 try { 792 785 simpleSocket::WSAStartup(); … … 798 791 return false; 799 792 } 800 793 */ 801 794 try { 802 795 com_helper_.initialize(); … … 921 914 LOG_ERROR_STD(_T("Unknown exception uniniating COM...")); 922 915 } 916 /* 923 917 LOG_DEBUG_STD(_T("Stopping: Socket Helpers")); 924 918 try { … … 929 923 LOG_ERROR_STD(_T("Unknown exception uniniating socket...")); 930 924 } 925 */ 931 926 LOG_DEBUG_STD(_T("Stopping: Settings instance")); 932 927 settings_manager::destroy_settings(); … … 979 974 void WINAPI NSClientT::service_main_dispatch(DWORD dwArgc, LPTSTR *lpszArgv) { 980 975 try { 981 mainClient.service_main(dwArgc, lpszArgv);976 //WTF!!! mainClient.service_main(dwArgc, lpszArgv); 982 977 } catch (service_helper::service_exception e) { 983 978 LOG_ERROR_STD(_T("Unknown service error: ") + e.what()); … … 1045 1040 return plugin->commandLineExec(command, argLen, args); 1046 1041 } 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_); 1048 1043 } 1049 1044 try { … … 1405 1400 */ 1406 1401 void 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())) { 1427 1406 return; 1428 1407 } 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 } 1470 1468 } 1471 1469 } 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); 1487 1487 } 1488 1488 } 1489 1489 std::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()) { 1492 1492 LOG_ERROR(_T("FATAL ERROR: Could not get mutex.")); 1493 1493 return _T("FATAL ERROR"); -
trunk/service/NSClient++.h
r205 r207 22 22 23 23 #include <config.h> 24 #include <ServiceCmd.h> 25 #include <NTService.h> 24 #include <service/system_service.hpp> 26 25 #include "NSCPlugin.h" 27 26 #include <Mutex.h> … … 31 30 #include <com_helpers.hpp> 32 31 #include <nsclient_session.hpp> 33 32 #include <boost/thread/thread.hpp> 33 #include <boost/thread/locks.hpp> 34 34 35 35 /** … … 99 99 pluginList messageHandlers_; 100 100 std::wstring basePath; 101 MutexHandlerinternalVariables;102 MutexHandlermessageMutex;101 boost::timed_mutex internalVariables; 102 boost::timed_mutex messageMutex; 103 103 MutexRW m_mutexRW; 104 104 MutexRW m_mutexRWcmdDescriptions; … … 180 180 }; 181 181 182 typedef service_helper:: NTService<NSClientT>NSClient;182 typedef service_helper::impl<NSClientT>::system_service NSClient; 183 183 184 184 extern NSClient mainClient; // Global core instance forward declaration. 185 185 186 186 187 std::wstring Encrypt(std::wstring str, unsigned int algorithm = NSCAPI:: xor);188 std::wstring Decrypt(std::wstring str, unsigned int algorithm = NSCAPI:: xor);187 std::wstring Encrypt(std::wstring str, unsigned int algorithm = NSCAPI::encryption_xor); 188 std::wstring Decrypt(std::wstring str, unsigned int algorithm = NSCAPI::encryption_xor); 189 189 190 190 ////////////////////////////////////////////////////////////////////////// -
trunk/service/StdAfx.h
r202 r207 20 20 ***************************************************************************/ 21 21 #pragma once 22 22 #ifdef WIN32 23 23 #define _WINSOCKAPI_ 24 24 //#include <WinSock2.h> 25 #include <tchar.h> 25 26 26 27 #define _WIN32_DCOM … … 29 30 #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 30 31 #include <windows.h> 31 32 #endif 32 33 33 34 #define COMPILE_NEWAPIS_STUBS … … 36 37 37 38 #include <iostream> 38 #include <tchar.h>39 39 #include <string> 40 40 #include <list> -
trunk/service/core_api.cpp
r205 r207 26 26 #include "settings_manager_impl.h" 27 27 #include <b64/b64.h> 28 #include <NSCHelper.h> 28 29 29 30 … … 58 59 } 59 60 void NSAPIStopServer(void) { 61 #ifdef WIN32 60 62 serviceControll::StopNoWait(SZSERVICENAME); 63 #endif 61 64 } 62 65 NSCAPI::nagiosReturn NSAPIInject(const TCHAR* command, const unsigned int argLen, TCHAR **argument, TCHAR *returnMessageBuffer, unsigned int returnMessageBufferLen, TCHAR *returnPerfBuffer, unsigned int returnPerfBufferLen) { … … 90 93 91 94 NSCAPI::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) { 93 96 LOG_ERROR(_T("Unknown algortihm requested.")); 94 97 return NSCAPI::hasFailed; 95 98 } 99 /* 100 TODO reimplement this 101 96 102 std::wstring key = settings_manager::get_settings()->get_string(SETTINGS_KEY(protocol_def::MASTER_KEY)); 97 103 int tcharInBufLen = 0; … … 125 131 outBuf[realOutLen] = 0; 126 132 *outBufLen = static_cast<unsigned int>(realOutLen); 133 */ 127 134 return NSCAPI::isSuccess; 128 135 } 129 136 130 137 NSCAPI::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) { 132 139 LOG_ERROR(_T("Unknown algortihm requested.")); 133 140 return NSCAPI::hasFailed; 134 141 } 142 /* 135 143 int inBufLenC = 0; 136 144 char *inBufferC = charEx::tchar_to_char(inBuffer, inBufLen, inBufLenC); … … 166 174 outBuf[realOutLen] = 0; 167 175 *outBufLen = static_cast<unsigned int>(realOutLen); 176 */ 168 177 return NSCAPI::isSuccess; 169 178 }
Note: See TracChangeset
for help on using the changeset viewer.







