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

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

Fixed some more VC8 aissues and added some missing file...

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