source: nscp/include/nscapi/nscapi_core_wrapper.hpp @ 40fca56

0.4.00.4.10.4.2
Last change on this file since 40fca56 was 40fca56, checked in by Michael Medin <michael@…>, 20 months ago
  • Added initial SMTPClient to allow sending messages via SMTP. Still requires template support and configuration options (mainly PoC right now).
  • Fixed unicode log issue (still not sure message format is correct)
  • Renamed Message to log in internal wrapper API
  • Fixed issue in settings old (regarding readin new keys, not 100% supported yet)
  • Property mode set to 100644
File size: 9.3 KB
Line 
1/**************************************************************************
2*   Copyright (C) 2004-2007 by Michael Medin <michael@medin.name>         *
3*                                                                         *
4*   This code is part of NSClient++ - http://trac.nakednuns.org/nscp      *
5*                                                                         *
6*   This program is free software; you can redistribute it and/or modify  *
7*   it under the terms of the GNU General Public License as published by  *
8*   the Free Software Foundation; either version 2 of the License, or     *
9*   (at your option) any later version.                                   *
10*                                                                         *
11*   This program is distributed in the hope that it will be useful,       *
12*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14*   GNU General Public License for more details.                          *
15*                                                                         *
16*   You should have received a copy of the GNU General Public License     *
17*   along with this program; if not, write to the                         *
18*   Free Software Foundation, Inc.,                                       *
19*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20***************************************************************************/
21#pragma once
22
23#include <string>
24#include <list>
25//#include <iostream>
26
27#include <NSCAPI.h>
28//#include <charEx.h>
29//#include <arrayBuffer.h>
30//#include <types.hpp>
31
32//#include <unicode_char.hpp>
33//#include <strEx.h>
34
35namespace nscapi {
36        class core_wrapper {
37        private:
38                nscapi::core_api::lpNSAPIGetBasePath fNSAPIGetBasePath;
39                nscapi::core_api::lpNSAPIGetApplicationName fNSAPIGetApplicationName;
40                nscapi::core_api::lpNSAPIGetApplicationVersionStr fNSAPIGetApplicationVersionStr;
41                nscapi::core_api::lpNSAPIGetSettingsSection fNSAPIGetSettingsSection;
42                nscapi::core_api::lpNSAPIGetSettingsSections fNSAPIGetSettingsSections;
43                nscapi::core_api::lpNSAPIReleaseSettingsSectionBuffer fNSAPIReleaseSettingsSectionBuffer;
44                nscapi::core_api::lpNSAPIGetSettingsString fNSAPIGetSettingsString;
45                nscapi::core_api::lpNSAPIExpandPath fNSAPIExpandPath;
46                nscapi::core_api::lpNSAPIGetSettingsInt fNSAPIGetSettingsInt;
47                nscapi::core_api::lpNSAPIGetSettingsBool fNSAPIGetSettingsBool;
48                nscapi::core_api::lpNSAPIMessage fNSAPIMessage;
49                nscapi::core_api::lpNSAPIStopServer fNSAPIStopServer;
50                nscapi::core_api::lpNSAPIExit fNSAPIExit;
51                nscapi::core_api::lpNSAPIInject fNSAPIInject;
52                nscapi::core_api::lpNSAPIExecCommand fNSAPIExecCommand;
53                nscapi::core_api::lpNSAPIDestroyBuffer fNSAPIDestroyBuffer;
54                nscapi::core_api::lpNSAPINotify fNSAPINotify;
55                nscapi::core_api::lpNSAPIReload fNSAPIReload;
56                nscapi::core_api::lpNSAPICheckLogMessages fNSAPICheckLogMessages;
57                nscapi::core_api::lpNSAPIEncrypt fNSAPIEncrypt;
58                nscapi::core_api::lpNSAPIDecrypt fNSAPIDecrypt;
59                nscapi::core_api::lpNSAPISetSettingsString fNSAPISetSettingsString;
60                nscapi::core_api::lpNSAPISetSettingsInt fNSAPISetSettingsInt;
61                nscapi::core_api::lpNSAPIWriteSettings fNSAPIWriteSettings;
62                nscapi::core_api::lpNSAPIReadSettings fNSAPIReadSettings;
63                nscapi::core_api::lpNSAPIRehash fNSAPIRehash;
64                nscapi::core_api::lpNSAPIDescribeCommand fNSAPIDescribeCommand;
65                nscapi::core_api::lpNSAPIGetAllCommandNames fNSAPIGetAllCommandNames;
66                nscapi::core_api::lpNSAPIReleaseAllCommandNamessBuffer fNSAPIReleaseAllCommandNamessBuffer;
67                nscapi::core_api::lpNSAPIRegisterCommand fNSAPIRegisterCommand;
68                nscapi::core_api::lpNSAPISettingsRegKey fNSAPISettingsRegKey;
69                nscapi::core_api::lpNSAPISettingsRegPath fNSAPISettingsRegPath;
70                nscapi::core_api::lpNSAPIGetPluginList fNSAPIGetPluginList;
71                nscapi::core_api::lpNSAPIReleasePluginList fNSAPIReleasePluginList;
72                nscapi::core_api::lpNSAPISettingsSave fNSAPISettingsSave;
73                nscapi::core_api::lpNSAPIRegisterSubmissionListener fNSAPIRegisterSubmissionListener;
74                nscapi::core_api::lpNSAPIRegisterRoutingListener fNSAPIRegisterRoutingListener;
75
76        public:
77
78                struct plugin_info_type {
79                        std::wstring dll;
80                        std::wstring name;
81                        std::wstring version;
82                        std::wstring description;
83                };
84                typedef std::list<plugin_info_type> plugin_info_list;
85
86                core_wrapper()
87                        : fNSAPIGetBasePath(NULL)
88                        , fNSAPIGetApplicationName(NULL)
89                        , fNSAPIGetApplicationVersionStr(NULL)
90                        , fNSAPIGetSettingsSection(NULL)
91                        , fNSAPIGetSettingsSections(NULL)
92                        , fNSAPIReleaseSettingsSectionBuffer(NULL)
93                        , fNSAPIGetSettingsString(NULL)
94                        , fNSAPIGetSettingsInt(NULL)
95                        , fNSAPIGetSettingsBool(NULL)
96                        , fNSAPIMessage(NULL)
97                        , fNSAPIStopServer(NULL)
98                        , fNSAPIExit(NULL)
99                        , fNSAPIInject(NULL)
100                        , fNSAPIDestroyBuffer(NULL)
101                        , fNSAPINotify(NULL)
102                        , fNSAPICheckLogMessages(NULL)
103                        , fNSAPIEncrypt(NULL)
104                        , fNSAPIDecrypt(NULL)
105                        , fNSAPISetSettingsString(NULL)
106                        , fNSAPISetSettingsInt(NULL)
107                        , fNSAPIWriteSettings(NULL)
108                        , fNSAPIReadSettings(NULL)
109                        , fNSAPIRehash(NULL)
110                        , fNSAPIDescribeCommand(NULL)
111                        , fNSAPIGetAllCommandNames(NULL)
112                        , fNSAPIReleaseAllCommandNamessBuffer(NULL)
113                        , fNSAPIRegisterCommand(NULL)
114                        , fNSAPISettingsRegKey(NULL)
115                        , fNSAPISettingsRegPath(NULL)
116                        , fNSAPIGetPluginList(NULL)
117                        , fNSAPIReleasePluginList(NULL)
118                        , fNSAPISettingsSave(NULL)
119                        , fNSAPIExpandPath(NULL)
120                {}
121
122                // Helper functions for calling into the core
123                std::wstring getApplicationName(void);
124                std::wstring getApplicationVersionString(void);
125                std::list<std::wstring> getSettingsSection(std::wstring section);
126                std::list<std::wstring> getSettingsSections(std::wstring section);
127                std::wstring getSettingsString(std::wstring section, std::wstring key, std::wstring defaultValue);
128                std::wstring expand_path(std::wstring value);
129                int getSettingsInt(std::wstring section, std::wstring key, int defaultValue);
130                bool getSettingsBool(std::wstring section, std::wstring key, bool defaultValue);
131                void settings_register_key(std::wstring path, std::wstring key, NSCAPI::settings_type type, std::wstring title, std::wstring description, std::wstring defaultValue, bool advanced);
132                void settings_register_path(std::wstring path, std::wstring title, std::wstring description, bool advanced);
133                void settings_save();
134
135                void log(int msgType, std::string file, int line, std::wstring message);
136                void log(int msgType, std::string file, int line, std::string message);
137                void DestroyBuffer(char**buffer);
138                NSCAPI::nagiosReturn query(const wchar_t* command, const char *request, const unsigned int request_len, char **response, unsigned int *response_len);
139                NSCAPI::nagiosReturn query(const std::wstring & command, const std::string & request, std::string & result);
140                NSCAPI::nagiosReturn simple_query(const std::wstring command, const std::list<std::wstring> & argument, std::wstring & message, std::wstring & perf);
141                NSCAPI::nagiosReturn simple_query(const std::wstring command, const std::list<std::wstring> & argument, std::string & result);
142                NSCAPI::nagiosReturn simple_query_from_nrpe(const std::wstring command, const std::wstring & buffer, std::wstring & message, std::wstring & perf);
143
144                NSCAPI::nagiosReturn exec_command(const wchar_t* target, const wchar_t* command, const char *request, const unsigned int request_len, char **response, unsigned int *response_len);
145                NSCAPI::nagiosReturn exec_command(const std::wstring target, const std::wstring command, std::string request, std::string & result);
146                NSCAPI::nagiosReturn exec_simple_command(const std::wstring target, const std::wstring command, const std::list<std::wstring> &argument, std::list<std::wstring> & result);
147
148                bool submit_simple_message(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::wstring & message, std::wstring & perf, std::wstring & response);
149                NSCAPI::errorReturn submit_message(const wchar_t* channel, const char *request, const unsigned int request_len, char **response, unsigned int *response_len);
150                NSCAPI::errorReturn submit_message(std::wstring channel, std::string request, std::string &response);
151                NSCAPI::errorReturn reload(std::wstring module);
152                void StopService(void);
153                void Exit(void);
154                std::wstring getBasePath();
155                bool logDebug();
156                bool checkLogMessages(int type);
157                std::wstring Encrypt(std::wstring str, unsigned int algorithm = NSCAPI::encryption_xor);
158                std::wstring Decrypt(std::wstring str, unsigned int algorithm = NSCAPI::encryption_xor);
159                NSCAPI::errorReturn SetSettingsString(std::wstring section, std::wstring key, std::wstring value);
160                NSCAPI::errorReturn SetSettingsInt(std::wstring section, std::wstring key, int value);
161                NSCAPI::errorReturn WriteSettings(int type);
162                NSCAPI::errorReturn ReadSettings(int type);
163                NSCAPI::errorReturn Rehash(int flag);
164                plugin_info_list getPluginList();
165
166                std::list<std::wstring> getAllCommandNames();
167                std::wstring describeCommand(std::wstring command);
168                void registerCommand(unsigned int id, std::wstring command, std::wstring description);
169                void registerSubmissionListener(unsigned int id, std::wstring channel);
170                void registerRoutingListener(unsigned int id, std::wstring channel);
171
172                unsigned int getBufferLength();
173                bool load_endpoints(nscapi::core_api::lpNSAPILoader f);
174
175        };
176};
Note: See TracBrowser for help on using the repository browser.