source: nscp/include/NSCAPI.h @ 8013c0c

0.4.00.4.10.4.2
Last change on this file since 8013c0c was 8013c0c, checked in by Michael Medin <michael@…>, 17 months ago
  • Fixed so NSCAClient parses address correctly
  • settings exception is now derived from exception meaning it will show up more with details (instead of unknown)
  • Added API for handling log level (replaces older debug flag)
  • Added options for settings debug level
  • Changed to --settings is a global argument (meaning you can use it in any mode)
  • Added arguments parsing to test: so you can use global arguments such as --log and --settings.
  • Removed memory leak in settings parsing interface
  • Property mode set to 100644
File size: 9.4 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
24#include <unicode_char.hpp>
25#include <string>
26#include <strEx.h>
27
28namespace NSCAPI {
29/*
30#ifdef DEBUG
31        typedef enum {
32                returnCRIT = 2,
33                returnOK = 0,
34                returnWARN = 1,
35                returnUNKNOWN = 3,
36                returnInvalidBufferLen = -2,
37                returnIgnored = -1
38        } nagiosReturn;
39        typedef enum {
40                istrue = 1,
41                isfalse = 0
42        } boolReturn;
43        typedef enum {
44                isSuccess = 1,
45                hasFailed = 0,
46                isInvalidBufferLen = -2
47        } errorReturn;
48        typedef enum {
49                key_string = 100,
50                key_integer = 200,
51                key_bool = 300,
52        } settings_type;
53
54        typedef enum {
55                normalStart = 0,
56                dontStart = 1,
57        } moduleLoadMode;
58#else
59        */
60        const int normalStart = 0;
61        const int dontStart = 1;
62        const int returnOK = 0;
63        const int returnWARN = 1;
64        const int returnCRIT = 2;
65        const int returnUNKNOWN = 3;
66        const int returnInvalidBufferLen = -2;
67        const int returnIgnored = -1;
68        const int istrue = 1;
69        const int isfalse = 0;
70        const int isSuccess = 1;
71        const int hasFailed = 0;
72        const int isInvalidBufferLen = -2;
73        const int key_string = 100;
74        const int key_integer = 200;
75        const int key_bool = 300;
76
77        const int message_processed     = 0x01;
78        const int message_routed        = 0x02;
79        const int message_ignored       = 0x04;
80        const int message_digested      = 0x08;
81        const int message_modified      = 0x10;
82
83        typedef int nagiosReturn;
84        typedef int boolReturn;
85        typedef int errorReturn;
86        typedef int settings_type;
87        typedef int moduleLoadMode;
88//#endif
89
90        const int encryption_xor = 1;
91
92        // Settings types
93        const int settings_default = 0;
94        const int settings_registry = 1;
95        const int settings_inifile = 2;
96
97        // Various message Types
98        namespace log_level {
99                typedef int level;
100                const int critical = 1; // Critical error
101                const int error = 10;   // Error
102                const int warning = 50; // Warning                      <<< Default for command line interface
103                const int log = 100;    // Log message          <<< Default for service
104                const int info = 150;   // information
105                const int debug = 500;  // Debug messages       <<< Default for test
106                const int trace = 1000; // Trace messages
107        }
108
109        typedef log_level::level messageTypes;          // Message type
110
111        struct plugin_info {
112                wchar_t *dll;
113                wchar_t *name;
114                wchar_t *description;
115                wchar_t *version;
116        };
117        typedef plugin_info* plugin_info_list;
118
119
120};
121
122namespace nscapi {
123
124
125        class nscapi_exception : public std::exception {
126        public:
127                std::string msg_;
128                nscapi_exception(std::wstring msg) : msg_(utf8::cvt<std::string>(msg)) {}
129
130
131                ~nscapi_exception() throw() {}
132                const char* what() const throw() {
133                        return msg_.c_str();
134                }
135                const std::wstring wwhat() const throw() {
136                        return utf8::cvt<std::wstring>(msg_);
137                }
138        };
139
140        namespace core_api {
141                typedef void* (*lpNSAPILoader)(const wchar_t*);
142
143                typedef NSCAPI::errorReturn (*lpNSAPIGetBasePath)(wchar_t*,unsigned int);
144                typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationName)(wchar_t*,unsigned int);
145                typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationVersionStr)(wchar_t*,unsigned int);
146                typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsString)(const wchar_t*,const wchar_t*,const wchar_t*,wchar_t*,unsigned int);
147                typedef NSCAPI::errorReturn (*lpNSAPIExpandPath)(const wchar_t*,wchar_t*,unsigned int);
148                typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsInt)(const wchar_t*, const wchar_t*, int);
149                typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsBool)(const wchar_t*, const wchar_t*, int);
150                typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSection)(const wchar_t*, wchar_t***, unsigned int *);
151                typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSections)(const wchar_t*, wchar_t***, unsigned int *);
152                typedef NSCAPI::errorReturn (*lpNSAPIReleaseSettingsSectionBuffer)(wchar_t***, unsigned int *);
153                typedef void (*lpNSAPIMessage)(const char*, unsigned int);
154                typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void);
155                typedef NSCAPI::errorReturn (*lpNSAPIExit)(void);
156                typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const wchar_t*, const char *, const unsigned int, char **, unsigned int *);
157                typedef NSCAPI::nagiosReturn (*lpNSAPIExecCommand)(const wchar_t* target, const wchar_t* command, const char *request, const unsigned int request_len, char ** response, unsigned int * response_len);
158                typedef void (*lpNSAPIDestroyBuffer)(char**);
159
160                typedef NSCAPI::errorReturn (*lpNSAPINotify)(const wchar_t* channel, const char* buffer, unsigned int buffer_len, char ** result_buffer, unsigned int *result_buffer_len);
161
162                typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int);
163                typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const wchar_t*, unsigned int, wchar_t*, unsigned int *);
164                typedef NSCAPI::errorReturn (*lpNSAPIDecrypt)(unsigned int, const wchar_t*, unsigned int, wchar_t*, unsigned int *);
165                typedef NSCAPI::errorReturn (*lpNSAPISetSettingsString)(const wchar_t*, const wchar_t*, const wchar_t*);
166                typedef NSCAPI::errorReturn (*lpNSAPISetSettingsInt)(const wchar_t*, const wchar_t*, int);
167                typedef NSCAPI::errorReturn (*lpNSAPIWriteSettings)(int);
168                typedef NSCAPI::errorReturn (*lpNSAPIReadSettings)(int);
169                typedef NSCAPI::errorReturn (*lpNSAPIRehash)(int);
170                typedef NSCAPI::errorReturn (*lpNSAPIDescribeCommand)(const wchar_t*,wchar_t*,unsigned int);
171                typedef NSCAPI::errorReturn (*lpNSAPIGetAllCommandNames)(wchar_t***, unsigned int *);
172                typedef NSCAPI::errorReturn (*lpNSAPIReleaseAllCommandNamessBuffer)(wchar_t***, unsigned int *);
173                typedef NSCAPI::errorReturn (*lpNSAPIRegisterCommand)(unsigned int, const wchar_t*,const wchar_t*);
174                typedef NSCAPI::errorReturn (*lpNSAPISettingsRegKey)(const wchar_t*, const wchar_t*, int, const wchar_t*, const wchar_t*, const wchar_t*, int);
175                typedef NSCAPI::errorReturn (*lpNSAPISettingsRegPath)(const wchar_t*, const wchar_t*, const wchar_t*, int);
176                typedef NSCAPI::errorReturn (*lpNSAPIGetPluginList)(int *len, NSCAPI::plugin_info *list[]);
177                typedef NSCAPI::errorReturn (*lpNSAPIReleasePluginList)(int len, NSCAPI::plugin_info *list[]);
178                typedef NSCAPI::errorReturn (*lpNSAPISettingsSave)(void);
179                typedef NSCAPI::errorReturn (*lpNSAPIRegisterSubmissionListener)(unsigned int plugin_id, const wchar_t* channel);
180                typedef NSCAPI::errorReturn (*lpNSAPIRegisterRoutingListener)(unsigned int plugin_id, const wchar_t* channel);
181                typedef NSCAPI::errorReturn (*lpNSAPIReload)(const wchar_t* module);
182                typedef NSCAPI::log_level::level (*lpNSAPIGetLoglevel)();
183
184        }
185
186        namespace plugin_api {
187                typedef NSCAPI::errorReturn (*lpGetName)(wchar_t*,unsigned int);
188                typedef NSCAPI::errorReturn (*lpGetDescription)(wchar_t*,unsigned int);
189                typedef NSCAPI::errorReturn (*lpModuleHelperInit)(unsigned int, ::nscapi::core_api::lpNSAPILoader f);
190                typedef NSCAPI::errorReturn (*lpGetVersion)(int* major, int* minor, int* revision);
191                typedef NSCAPI::errorReturn (*lpDeleteBuffer)(char** buffer);
192
193                typedef NSCAPI::errorReturn (*lpLoadModule)(unsigned int plugin_id, const wchar_t* alias, int mode);
194                typedef NSCAPI::errorReturn (*lpUnLoadModule)(unsigned int plugin_id);
195
196                typedef NSCAPI::errorReturn (*lpHasCommandHandler)(unsigned int plugin_id);
197                typedef NSCAPI::errorReturn (*lpHandleCommand)(unsigned int plugin_id, const wchar_t* command, const char* in_buffer, const unsigned int in_buffer_len, char** out_buffer, unsigned int* out_buffer_len);
198
199                typedef NSCAPI::errorReturn (*lpHasMessageHandler)(unsigned int plugin_id);
200                typedef NSCAPI::errorReturn (*lpHandleMessage)(unsigned int plugin_id, const char* buffer, const unsigned int buffer_len);
201
202                typedef NSCAPI::errorReturn (*lpHasNotificationHandler)(unsigned int plugin_id);
203                typedef NSCAPI::errorReturn (*lpHandleNotification)(unsigned int plugin_id, const wchar_t *channel, const char* buffer, unsigned int buffer_len, char **result_buffer, unsigned int *result_buffer_len);
204
205                typedef NSCAPI::errorReturn (*lpHasRoutingHandler)(unsigned int plugin_id);
206                typedef NSCAPI::errorReturn (*lpRouteMessage)(unsigned int plugin_id, const wchar_t *channel, const char* buffer, unsigned int buffer_len, wchar_t **new_channel_buffer, char **new_buffer, unsigned int *new_buffer_len);
207
208                typedef NSCAPI::errorReturn (*lpCommandLineExec)(unsigned int plugin_id, const wchar_t* command, const char* in_buffer ,const unsigned int in_buffer_len, char** out_buffer, unsigned int* out_buffer_len);
209        }
210}
Note: See TracBrowser for help on using the repository browser.