source: nscp/trunk/NSClient++.h @ e0705d4

Last change on this file since e0705d4 was e0705d4, checked in by Michael Medin <michael@…>, 8 years ago

Initial release

  • Property mode set to 100644
File size: 3.8 KB
Line 
1#pragma once
2
3#include "resource.h"
4#include <ServiceCmd.h>
5#include <NTService.h>
6#include "NSCPlugin.h"
7#include "TCPSocketResponder.h"
8#include <Mutex.h>
9#include <NSCAPI.h>
10
11
12/**
13 * @ingroup NSClient++
14 * Main NSClient++ core class. This is the service core and as such is responsible for pretty much everything.
15 * It also acts as a broker for all plugins and other sub threads and such.
16 *
17 * @version 1.0
18 * first version
19 *
20 * @date 02-12-2005
21 *
22 * @author mickem
23 *
24 * @par license
25 * This code is absolutely free to use and modify. The code is provided "as is" with
26 * no expressed or implied warranty. The author accepts no liability if it causes
27 * any damage to your computer, causes your pet to fall ill, increases baldness
28 * or makes your car start emitting strange noises when you start it up.
29 * This code has no bugs, just undocumented features!
30 *
31 * @todo Plugininfy the socket somehow ?
32 * It is technically possible to make the socket a plug-in but would it be a good idea ?
33 *
34 * @bug
35 *
36 */
37class NSClientT {
38private:
39        typedef std::list<NSCPlugin*> pluginList;
40        pluginList plugins_;
41        pluginList commandHandlers_;
42        pluginList messageHandlers_;
43        TCPSocketResponderThread socketThread;
44        std::string basePath;
45        MutexHandler messageMutex;
46
47public:
48        // c-tor, d-tor
49        NSClientT(void) {}
50        virtual ~NSClientT(void) {}
51
52        // Service helper functions
53        void InitiateService(void);
54        void TerminateService(void);
55        static void WINAPI service_main_dispatch(DWORD dwArgc, LPTSTR *lpszArgv);
56        static void WINAPI service_ctrl_dispatch(DWORD dwCtrlCode);
57
58        // Member functions
59        static std::string getPassword(void);
60        std::string inject(std::string buffer);
61        std::string execute(std::string password, std::string cmd, std::list<std::string> args);
62        void reportMessage(int msgType, const char* file, const int line, std::string message);
63
64        void loadPlugins(std::list<std::string> plugins);
65        void loadPlugin(std::string plugin);
66        void loadPlugins(void);
67        void unloadPlugins(void);
68
69private:
70        void addPlugin(NSCPlugin *plugin);
71
72};
73
74typedef NTService<NSClientT> NSClient;
75
76//////////////////////////////////////////////////////////////////////////
77// Various NSAPI callback functions (available for plug-ins to make calls back to the core.
78// <b>NOTICE</b> No threading is allowed so technically every thread is responsible for marshaling things back.
79// Though I think this is not the case at the moment.
80//
81
82LPVOID NSAPILoader(char*buffer);
83int NSAPIGetApplicationName(char*buffer, unsigned int bufLen);
84int NSAPIGetApplicationVersionStr(char*buffer, unsigned int bufLen);
85int NSAPIGetSettingsString(const char* section, const char* key, const char* defaultValue, char* buffer, unsigned int bufLen);
86int NSAPIGetSettingsInt(const char* section, const char* key, int defaultValue);
87void NSAPIMessage(int msgType, const char* file, const int line, const char* message);
88void NSAPIStopServer(void);
89int NSAPIInject(const char* command, char* buffer, unsigned int bufLen);
90
91//////////////////////////////////////////////////////////////////////////
92// Log macros to simplify logging
93// Generally names are of the form LOG_<severity>[_STD]
94// Where _STD indicates that strings are force wrapped inside a std::string
95//
96#define LOG_ERROR_STD(msg) LOG_ERROR(((std::string)msg).c_str())
97#define LOG_ERROR(msg) \
98        NSAPIMessage(NSCAPI::error, __FILE__, __LINE__, msg)
99#define LOG_CRITICAL_STD(msg) LOG_CRITICAL(((std::string)msg).c_str())
100#define LOG_CRITICAL(msg) \
101        NSAPIMessage(NSCAPI::critical, __FILE__, __LINE__, msg)
102#define LOG_MESSAGE_STD(msg) LOG_MESSAGE(((std::string)msg).c_str())
103#define LOG_MESSAGE(msg) \
104        NSAPIMessage(NSCAPI::log, __FILE__, __LINE__, msg)
105#ifdef _DEBUG
106#define LOG_DEBUG_STD(msg) LOG_DEBUG(((std::string)msg).c_str())
107#define LOG_DEBUG(msg) \
108        NSAPIMessage(NSCAPI::debug, __FILE__, __LINE__, msg)
109#else
110#define LOG_DEBUG_STD(msg)
111#define LOG_DEBUG(msg)
112#endif
113
Note: See TracBrowser for help on using the repository browser.