| 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 |
|
|---|
| 26 | #include <NSCAPI.h>
|
|---|
| 27 |
|
|---|
| 28 | namespace nscapi {
|
|---|
| 29 | class core_wrapper {
|
|---|
| 30 | private:
|
|---|
| 31 | std::wstring alias; // This is actually the wrong value if multiple modules are loaded!
|
|---|
| 32 | nscapi::core_api::lpNSAPIGetBasePath fNSAPIGetBasePath;
|
|---|
| 33 | nscapi::core_api::lpNSAPIGetApplicationName fNSAPIGetApplicationName;
|
|---|
| 34 | nscapi::core_api::lpNSAPIGetApplicationVersionStr fNSAPIGetApplicationVersionStr;
|
|---|
| 35 | nscapi::core_api::lpNSAPIGetSettingsSection fNSAPIGetSettingsSection;
|
|---|
| 36 | nscapi::core_api::lpNSAPIGetSettingsSections fNSAPIGetSettingsSections;
|
|---|
| 37 | nscapi::core_api::lpNSAPIReleaseSettingsSectionBuffer fNSAPIReleaseSettingsSectionBuffer;
|
|---|
| 38 | nscapi::core_api::lpNSAPIGetSettingsString fNSAPIGetSettingsString;
|
|---|
| 39 | nscapi::core_api::lpNSAPIGetSettingsInt fNSAPIGetSettingsInt;
|
|---|
| 40 | nscapi::core_api::lpNSAPIGetSettingsBool fNSAPIGetSettingsBool;
|
|---|
| 41 | nscapi::core_api::lpNSAPIMessage fNSAPIMessage;
|
|---|
| 42 | nscapi::core_api::lpNSAPISimpleMessage fNSAPISimpleMessage;
|
|---|
| 43 | nscapi::core_api::lpNSAPIStopServer fNSAPIStopServer;
|
|---|
| 44 | nscapi::core_api::lpNSAPIExit fNSAPIExit;
|
|---|
| 45 | nscapi::core_api::lpNSAPIInject fNSAPIInject;
|
|---|
| 46 | nscapi::core_api::lpNSAPIExecCommand fNSAPIExecCommand;
|
|---|
| 47 | nscapi::core_api::lpNSAPIDestroyBuffer fNSAPIDestroyBuffer;
|
|---|
| 48 | nscapi::core_api::lpNSAPINotify fNSAPINotify;
|
|---|
| 49 | nscapi::core_api::lpNSAPIReload fNSAPIReload;
|
|---|
| 50 | nscapi::core_api::lpNSAPICheckLogMessages fNSAPICheckLogMessages;
|
|---|
| 51 | nscapi::core_api::lpNSAPIEncrypt fNSAPIEncrypt;
|
|---|
| 52 | nscapi::core_api::lpNSAPIDecrypt fNSAPIDecrypt;
|
|---|
| 53 | nscapi::core_api::lpNSAPISetSettingsString fNSAPISetSettingsString;
|
|---|
| 54 | nscapi::core_api::lpNSAPISetSettingsInt fNSAPISetSettingsInt;
|
|---|
| 55 | nscapi::core_api::lpNSAPIWriteSettings fNSAPIWriteSettings;
|
|---|
| 56 | nscapi::core_api::lpNSAPIReadSettings fNSAPIReadSettings;
|
|---|
| 57 | nscapi::core_api::lpNSAPIRehash fNSAPIRehash;
|
|---|
| 58 | nscapi::core_api::lpNSAPIDescribeCommand fNSAPIDescribeCommand;
|
|---|
| 59 | nscapi::core_api::lpNSAPIGetAllCommandNames fNSAPIGetAllCommandNames;
|
|---|
| 60 | nscapi::core_api::lpNSAPIReleaseAllCommandNamessBuffer fNSAPIReleaseAllCommandNamessBuffer;
|
|---|
| 61 | nscapi::core_api::lpNSAPIRegisterCommand fNSAPIRegisterCommand;
|
|---|
| 62 | nscapi::core_api::lpNSAPISettingsRegKey fNSAPISettingsRegKey;
|
|---|
| 63 | nscapi::core_api::lpNSAPISettingsRegPath fNSAPISettingsRegPath;
|
|---|
| 64 | nscapi::core_api::lpNSAPISettingsQuery fNSAPISettingsQuery;
|
|---|
| 65 | nscapi::core_api::lpNSAPIGetPluginList fNSAPIGetPluginList;
|
|---|
| 66 | nscapi::core_api::lpNSAPIReleasePluginList fNSAPIReleasePluginList;
|
|---|
| 67 | nscapi::core_api::lpNSAPISettingsSave fNSAPISettingsSave;
|
|---|
| 68 | nscapi::core_api::lpNSAPIExpandPath fNSAPIExpandPath;
|
|---|
| 69 | nscapi::core_api::lpNSAPIGetLoglevel fNSAPIGetLoglevel;
|
|---|
| 70 | nscapi::core_api::lpNSAPIRegisterSubmissionListener fNSAPIRegisterSubmissionListener;
|
|---|
| 71 | nscapi::core_api::lpNSAPIRegisterRoutingListener fNSAPIRegisterRoutingListener;
|
|---|
| 72 | nscapi::core_api::lpNSAPIRegistryQuery fNSAPIRegistryQuery;
|
|---|
| 73 |
|
|---|
| 74 | public:
|
|---|
| 75 |
|
|---|
| 76 | struct plugin_info_type {
|
|---|
| 77 | std::wstring dll;
|
|---|
| 78 | std::wstring name;
|
|---|
| 79 | std::wstring version;
|
|---|
| 80 | std::wstring description;
|
|---|
| 81 | };
|
|---|
| 82 | typedef std::list<plugin_info_type> plugin_info_list;
|
|---|
| 83 |
|
|---|
| 84 | core_wrapper()
|
|---|
| 85 | : fNSAPIGetBasePath(NULL)
|
|---|
| 86 | , fNSAPIGetApplicationName(NULL)
|
|---|
| 87 | , fNSAPIGetApplicationVersionStr(NULL)
|
|---|
| 88 | , fNSAPIGetSettingsSection(NULL)
|
|---|
| 89 | , fNSAPIGetSettingsSections(NULL)
|
|---|
| 90 | , fNSAPIReleaseSettingsSectionBuffer(NULL)
|
|---|
| 91 | , fNSAPIGetSettingsString(NULL)
|
|---|
| 92 | , fNSAPIGetSettingsInt(NULL)
|
|---|
| 93 | , fNSAPIGetSettingsBool(NULL)
|
|---|
| 94 | , fNSAPIMessage(NULL)
|
|---|
| 95 | , fNSAPISimpleMessage(NULL)
|
|---|
| 96 | , fNSAPIStopServer(NULL)
|
|---|
| 97 | , fNSAPIExit(NULL)
|
|---|
| 98 | , fNSAPIInject(NULL)
|
|---|
| 99 | , fNSAPIExecCommand(NULL)
|
|---|
| 100 | , fNSAPIDestroyBuffer(NULL)
|
|---|
| 101 | , fNSAPINotify(NULL)
|
|---|
| 102 | , fNSAPIReload(NULL)
|
|---|
| 103 | , fNSAPICheckLogMessages(NULL)
|
|---|
| 104 | , fNSAPIEncrypt(NULL)
|
|---|
| 105 | , fNSAPIDecrypt(NULL)
|
|---|
| 106 | , fNSAPISetSettingsString(NULL)
|
|---|
| 107 | , fNSAPISetSettingsInt(NULL)
|
|---|
| 108 | , fNSAPIWriteSettings(NULL)
|
|---|
| 109 | , fNSAPIReadSettings(NULL)
|
|---|
| 110 | , fNSAPIRehash(NULL)
|
|---|
| 111 | , fNSAPIDescribeCommand(NULL)
|
|---|
| 112 | , fNSAPIGetAllCommandNames(NULL)
|
|---|
| 113 | , fNSAPIReleaseAllCommandNamessBuffer(NULL)
|
|---|
| 114 | , fNSAPIRegisterCommand(NULL)
|
|---|
| 115 | , fNSAPISettingsRegKey(NULL)
|
|---|
| 116 | , fNSAPISettingsRegPath(NULL)
|
|---|
| 117 | , fNSAPISettingsQuery(NULL)
|
|---|
| 118 | , fNSAPIGetPluginList(NULL)
|
|---|
| 119 | , fNSAPIReleasePluginList(NULL)
|
|---|
| 120 | , fNSAPISettingsSave(NULL)
|
|---|
| 121 | , fNSAPIExpandPath(NULL)
|
|---|
| 122 | , fNSAPIGetLoglevel(NULL)
|
|---|
| 123 | , fNSAPIRegisterSubmissionListener(NULL)
|
|---|
| 124 | , fNSAPIRegisterRoutingListener(NULL)
|
|---|
| 125 | , fNSAPIRegistryQuery(NULL)
|
|---|
| 126 | {}
|
|---|
| 127 |
|
|---|
| 128 | // Helper functions for calling into the core
|
|---|
| 129 | std::wstring getApplicationName(void);
|
|---|
| 130 | std::wstring getApplicationVersionString(void);
|
|---|
| 131 | std::list<std::wstring> getSettingsSection(std::wstring section);
|
|---|
| 132 | std::list<std::wstring> getSettingsSections(std::wstring section);
|
|---|
| 133 | std::wstring getSettingsString(std::wstring section, std::wstring key, std::wstring defaultValue);
|
|---|
| 134 | std::wstring expand_path(std::wstring value);
|
|---|
| 135 | int getSettingsInt(std::wstring section, std::wstring key, int defaultValue);
|
|---|
| 136 | bool getSettingsBool(std::wstring section, std::wstring key, bool defaultValue);
|
|---|
| 137 | void settings_register_key(unsigned int plugin_id, std::wstring path, std::wstring key, NSCAPI::settings_type type, std::wstring title, std::wstring description, std::wstring defaultValue, bool advanced);
|
|---|
| 138 | void settings_register_path(unsigned int plugin_id, std::wstring path, std::wstring title, std::wstring description, bool advanced);
|
|---|
| 139 | NSCAPI::errorReturn settings_query(const char *request, const unsigned int request_len, char **response, unsigned int *response_len);
|
|---|
| 140 | NSCAPI::errorReturn settings_query(const std::string request, std::string &response);
|
|---|
| 141 | void settings_save();
|
|---|
| 142 |
|
|---|
| 143 | void log(NSCAPI::nagiosReturn msgType, std::string file, int line, std::wstring message);
|
|---|
| 144 | void log(NSCAPI::nagiosReturn msgType, std::string file, int line, std::string message);
|
|---|
| 145 | bool should_log(NSCAPI::nagiosReturn msgType);
|
|---|
| 146 | NSCAPI::log_level::level get_loglevel();
|
|---|
| 147 | void DestroyBuffer(char**buffer);
|
|---|
| 148 | NSCAPI::nagiosReturn query(const wchar_t* command, const char *request, const unsigned int request_len, char **response, unsigned int *response_len);
|
|---|
| 149 | NSCAPI::nagiosReturn query(const std::wstring & command, const std::string & request, std::string & result);
|
|---|
| 150 |
|
|---|
| 151 | 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);
|
|---|
| 152 | NSCAPI::nagiosReturn exec_command(const std::wstring target, const std::wstring command, std::string request, std::string & result);
|
|---|
| 153 |
|
|---|
| 154 | NSCAPI::errorReturn submit_message(const wchar_t* channel, const char *request, const unsigned int request_len, char **response, unsigned int *response_len);
|
|---|
| 155 | NSCAPI::errorReturn submit_message(std::wstring channel, std::string request, std::string &response);
|
|---|
| 156 | NSCAPI::errorReturn reload(std::wstring module);
|
|---|
| 157 | void StopService(void);
|
|---|
| 158 | void Exit(void);
|
|---|
| 159 | std::wstring getBasePath();
|
|---|
| 160 | bool checkLogMessages(int type);
|
|---|
| 161 | std::wstring Encrypt(std::wstring str, unsigned int algorithm = NSCAPI::encryption_xor);
|
|---|
| 162 | std::wstring Decrypt(std::wstring str, unsigned int algorithm = NSCAPI::encryption_xor);
|
|---|
| 163 | NSCAPI::errorReturn SetSettingsString(std::wstring section, std::wstring key, std::wstring value);
|
|---|
| 164 | NSCAPI::errorReturn SetSettingsInt(std::wstring section, std::wstring key, int value);
|
|---|
| 165 | NSCAPI::errorReturn WriteSettings(int type);
|
|---|
| 166 | NSCAPI::errorReturn ReadSettings(int type);
|
|---|
| 167 | NSCAPI::errorReturn Rehash(int flag);
|
|---|
| 168 | plugin_info_list getPluginList();
|
|---|
| 169 |
|
|---|
| 170 | std::list<std::wstring> getAllCommandNames();
|
|---|
| 171 | std::wstring describeCommand(std::wstring command);
|
|---|
| 172 | void registerCommand(unsigned int id, std::wstring command, std::wstring description);
|
|---|
| 173 | void registerSubmissionListener(unsigned int id, std::wstring channel);
|
|---|
| 174 | void registerRoutingListener(unsigned int id, std::wstring channel);
|
|---|
| 175 |
|
|---|
| 176 | NSCAPI::errorReturn registry_query(const char *request, const unsigned int request_len, char **response, unsigned int *response_len);
|
|---|
| 177 | NSCAPI::errorReturn registry_query(const std::string request, std::string &response);
|
|---|
| 178 |
|
|---|
| 179 | bool load_endpoints(nscapi::core_api::lpNSAPILoader f);
|
|---|
| 180 | void set_alias(const std::wstring default_alias, const std::wstring alias);
|
|---|
| 181 | };
|
|---|
| 182 | }
|
|---|