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

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

*OBS* This might no longer work! (expect updated code in the next few days if things are broken)

  • Fundamental API changes (due to NRPE compatibility)
    • HandleCommand? has changed
    • Inject has changed
    • Most API calls have new "return codes" (typedef:ed INT to allow for return code compiler checks)
    • A lot of the old return codes have changed
  • Preliminary NRPE support (can parse and execute incoming requests, cant return data yet, and no encryption)
  • New SimpleSocket? in include/ will be used as base class for Listeners
  • A lot of rewrite to the NSC API
  • Property mode set to 100644
File size: 4.2 KB
Line 
1#pragma once
2
3#include "resource.h"
4#include <ServiceCmd.h>
5#include <NTService.h>
6#include "NSCPlugin.h"
7#include <Mutex.h>
8#include <NSCAPI.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::list<plugin_type> pluginList;
40        pluginList plugins_;
41        pluginList commandHandlers_;
42        pluginList messageHandlers_;
43        std::string basePath;
44        MutexHandler pluginMutex;
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 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//      std::string inject(const std::string buffer);
63        std::string execute(std::string password, std::string cmd, std::list<std::string> args);
64        void reportMessage(int msgType, const char* file, const int line, std::string message);
65
66        void loadPlugins(const std::list<std::string> plugins);
67        void loadPlugin(const std::string plugin);
68        void loadPlugins(void);
69        void unloadPlugins(void);
70
71private:
72        void addPlugin(plugin_type plugin);
73
74};
75
76typedef NTService<NSClientT> NSClient;
77
78//////////////////////////////////////////////////////////////////////////
79// Various NSAPI callback functions (available for plug-ins to make calls back to the core.
80// <b>NOTICE</b> No threading is allowed so technically every thread is responsible for marshaling things back.
81// Though I think this is not the case at the moment.
82//
83
84LPVOID NSAPILoader(char*buffer);
85NSCAPI::errorReturn NSAPIGetApplicationName(char*buffer, unsigned int bufLen);
86NSCAPI::errorReturn NSAPIGetBasePath(char*buffer, unsigned int bufLen);
87NSCAPI::errorReturn NSAPIGetApplicationVersionStr(char*buffer, unsigned int bufLen);
88NSCAPI::errorReturn NSAPIGetSettingsString(const char* section, const char* key, const char* defaultValue, char* buffer, unsigned int bufLen);
89int NSAPIGetSettingsInt(const char* section, const char* key, int defaultValue);
90void NSAPIMessage(int msgType, const char* file, const int line, const char* message);
91void NSAPIStopServer(void);
92NSCAPI::nagiosReturn NSAPIInject(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen);
93
94//////////////////////////////////////////////////////////////////////////
95// Log macros to simplify logging
96// Generally names are of the form LOG_<severity>[_STD]
97// Where _STD indicates that strings are force wrapped inside a std::string
98//
99#define LOG_ERROR_STD(msg) LOG_ERROR(((std::string)msg).c_str())
100#define LOG_ERROR(msg) \
101        NSAPIMessage(NSCAPI::error, __FILE__, __LINE__, msg)
102#define LOG_CRITICAL_STD(msg) LOG_CRITICAL(((std::string)msg).c_str())
103#define LOG_CRITICAL(msg) \
104        NSAPIMessage(NSCAPI::critical, __FILE__, __LINE__, msg)
105#define LOG_MESSAGE_STD(msg) LOG_MESSAGE(((std::string)msg).c_str())
106#define LOG_MESSAGE(msg) \
107        NSAPIMessage(NSCAPI::log, __FILE__, __LINE__, msg)
108#define LOG_DEBUG_STD(msg) LOG_DEBUG(((std::string)msg).c_str())
109#define LOG_DEBUG(msg) \
110        NSAPIMessage(NSCAPI::debug, __FILE__, __LINE__, msg)
Note: See TracBrowser for help on using the repository browser.