| 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 | |
|---|
| 28 | namespace 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 | const int log = 1; // Log message |
|---|
| 99 | const int error = -1; // Error (non critical) |
|---|
| 100 | const int critical = -10; // Critical error |
|---|
| 101 | const int warning = 2; // Warning |
|---|
| 102 | const int debug = 10; // Debug message |
|---|
| 103 | |
|---|
| 104 | typedef int messageTypes; // Message type |
|---|
| 105 | |
|---|
| 106 | struct plugin_info { |
|---|
| 107 | wchar_t *dll; |
|---|
| 108 | wchar_t *name; |
|---|
| 109 | wchar_t *description; |
|---|
| 110 | wchar_t *version; |
|---|
| 111 | }; |
|---|
| 112 | typedef plugin_info* plugin_info_list; |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | }; |
|---|
| 116 | |
|---|
| 117 | namespace nscapi { |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | class nscapi_exception : public std::exception { |
|---|
| 121 | public: |
|---|
| 122 | std::string msg_; |
|---|
| 123 | nscapi_exception(std::wstring msg) : msg_(utf8::cvt<std::string>(msg)) {} |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | ~nscapi_exception() throw() {} |
|---|
| 127 | const char* what() const throw() { |
|---|
| 128 | return msg_.c_str(); |
|---|
| 129 | } |
|---|
| 130 | const std::wstring wwhat() const throw() { |
|---|
| 131 | return utf8::cvt<std::wstring>(msg_); |
|---|
| 132 | } |
|---|
| 133 | }; |
|---|
| 134 | |
|---|
| 135 | namespace core_api { |
|---|
| 136 | typedef void* (*lpNSAPILoader)(const wchar_t*); |
|---|
| 137 | |
|---|
| 138 | typedef NSCAPI::errorReturn (*lpNSAPIGetBasePath)(wchar_t*,unsigned int); |
|---|
| 139 | typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationName)(wchar_t*,unsigned int); |
|---|
| 140 | typedef NSCAPI::errorReturn (*lpNSAPIGetApplicationVersionStr)(wchar_t*,unsigned int); |
|---|
| 141 | typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsString)(const wchar_t*,const wchar_t*,const wchar_t*,wchar_t*,unsigned int); |
|---|
| 142 | typedef NSCAPI::errorReturn (*lpNSAPIExpandPath)(const wchar_t*,wchar_t*,unsigned int); |
|---|
| 143 | typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsInt)(const wchar_t*, const wchar_t*, int); |
|---|
| 144 | typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsBool)(const wchar_t*, const wchar_t*, int); |
|---|
| 145 | typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSection)(const wchar_t*, wchar_t***, unsigned int *); |
|---|
| 146 | typedef NSCAPI::errorReturn (*lpNSAPIGetSettingsSections)(const wchar_t*, wchar_t***, unsigned int *); |
|---|
| 147 | typedef NSCAPI::errorReturn (*lpNSAPIReleaseSettingsSectionBuffer)(wchar_t***, unsigned int *); |
|---|
| 148 | typedef void (*lpNSAPIMessage)(const char*, unsigned int); |
|---|
| 149 | typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); |
|---|
| 150 | typedef NSCAPI::errorReturn (*lpNSAPIExit)(void); |
|---|
| 151 | typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const wchar_t*, const char *, const unsigned int, char **, unsigned int *); |
|---|
| 152 | 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); |
|---|
| 153 | typedef void (*lpNSAPIDestroyBuffer)(char**); |
|---|
| 154 | |
|---|
| 155 | typedef NSCAPI::errorReturn (*lpNSAPINotify)(const wchar_t* channel, const char* buffer, unsigned int buffer_len, char ** result_buffer, unsigned int *result_buffer_len); |
|---|
| 156 | |
|---|
| 157 | typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); |
|---|
| 158 | typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const wchar_t*, unsigned int, wchar_t*, unsigned int *); |
|---|
| 159 | typedef NSCAPI::errorReturn (*lpNSAPIDecrypt)(unsigned int, const wchar_t*, unsigned int, wchar_t*, unsigned int *); |
|---|
| 160 | typedef NSCAPI::errorReturn (*lpNSAPISetSettingsString)(const wchar_t*, const wchar_t*, const wchar_t*); |
|---|
| 161 | typedef NSCAPI::errorReturn (*lpNSAPISetSettingsInt)(const wchar_t*, const wchar_t*, int); |
|---|
| 162 | typedef NSCAPI::errorReturn (*lpNSAPIWriteSettings)(int); |
|---|
| 163 | typedef NSCAPI::errorReturn (*lpNSAPIReadSettings)(int); |
|---|
| 164 | typedef NSCAPI::errorReturn (*lpNSAPIRehash)(int); |
|---|
| 165 | typedef NSCAPI::errorReturn (*lpNSAPIDescribeCommand)(const wchar_t*,wchar_t*,unsigned int); |
|---|
| 166 | typedef NSCAPI::errorReturn (*lpNSAPIGetAllCommandNames)(wchar_t***, unsigned int *); |
|---|
| 167 | typedef NSCAPI::errorReturn (*lpNSAPIReleaseAllCommandNamessBuffer)(wchar_t***, unsigned int *); |
|---|
| 168 | typedef NSCAPI::errorReturn (*lpNSAPIRegisterCommand)(unsigned int, const wchar_t*,const wchar_t*); |
|---|
| 169 | typedef NSCAPI::errorReturn (*lpNSAPISettingsRegKey)(const wchar_t*, const wchar_t*, int, const wchar_t*, const wchar_t*, const wchar_t*, int); |
|---|
| 170 | typedef NSCAPI::errorReturn (*lpNSAPISettingsRegPath)(const wchar_t*, const wchar_t*, const wchar_t*, int); |
|---|
| 171 | typedef NSCAPI::errorReturn (*lpNSAPIGetPluginList)(int *len, NSCAPI::plugin_info *list[]); |
|---|
| 172 | typedef NSCAPI::errorReturn (*lpNSAPIReleasePluginList)(int len, NSCAPI::plugin_info *list[]); |
|---|
| 173 | typedef NSCAPI::errorReturn (*lpNSAPISettingsSave)(void); |
|---|
| 174 | typedef NSCAPI::errorReturn (*lpNSAPIRegisterSubmissionListener)(unsigned int plugin_id, const wchar_t* channel); |
|---|
| 175 | typedef NSCAPI::errorReturn (*lpNSAPIRegisterRoutingListener)(unsigned int plugin_id, const wchar_t* channel); |
|---|
| 176 | typedef NSCAPI::errorReturn (*lpNSAPIReload)(const wchar_t* module); |
|---|
| 177 | |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | namespace plugin_api { |
|---|
| 181 | typedef NSCAPI::errorReturn (*lpGetName)(wchar_t*,unsigned int); |
|---|
| 182 | typedef NSCAPI::errorReturn (*lpGetDescription)(wchar_t*,unsigned int); |
|---|
| 183 | typedef NSCAPI::errorReturn (*lpModuleHelperInit)(unsigned int, ::nscapi::core_api::lpNSAPILoader f); |
|---|
| 184 | typedef NSCAPI::errorReturn (*lpGetVersion)(int* major, int* minor, int* revision); |
|---|
| 185 | typedef NSCAPI::errorReturn (*lpDeleteBuffer)(char** buffer); |
|---|
| 186 | |
|---|
| 187 | typedef NSCAPI::errorReturn (*lpLoadModule)(unsigned int plugin_id, const wchar_t* alias, int mode); |
|---|
| 188 | typedef NSCAPI::errorReturn (*lpUnLoadModule)(unsigned int plugin_id); |
|---|
| 189 | |
|---|
| 190 | typedef NSCAPI::errorReturn (*lpHasCommandHandler)(unsigned int plugin_id); |
|---|
| 191 | 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); |
|---|
| 192 | |
|---|
| 193 | typedef NSCAPI::errorReturn (*lpHasMessageHandler)(unsigned int plugin_id); |
|---|
| 194 | typedef NSCAPI::errorReturn (*lpHandleMessage)(unsigned int plugin_id, const char* buffer, const unsigned int buffer_len); |
|---|
| 195 | |
|---|
| 196 | typedef NSCAPI::errorReturn (*lpHasNotificationHandler)(unsigned int plugin_id); |
|---|
| 197 | 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); |
|---|
| 198 | |
|---|
| 199 | typedef NSCAPI::errorReturn (*lpHasRoutingHandler)(unsigned int plugin_id); |
|---|
| 200 | 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); |
|---|
| 201 | |
|---|
| 202 | 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); |
|---|
| 203 | } |
|---|
| 204 | } |
|---|