diff options
Diffstat (limited to 'src/Core')
-rw-r--r-- | src/Core/ConfigManager.cpp | 87 | ||||
-rw-r--r-- | src/Core/ConfigManager.h | 73 | ||||
-rw-r--r-- | src/Core/ConnectionManager.cpp | 106 | ||||
-rw-r--r-- | src/Core/ConnectionManager.h | 10 | ||||
-rw-r--r-- | src/Core/Makefile.am | 4 | ||||
-rw-r--r-- | src/Core/Makefile.in | 7 |
6 files changed, 97 insertions, 190 deletions
diff --git a/src/Core/ConfigManager.cpp b/src/Core/ConfigManager.cpp deleted file mode 100644 index 9361493..0000000 --- a/src/Core/ConfigManager.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * ConfigManager.cpp - * - * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "ConfigManager.h" -#include <Common/Util.h> - -namespace Mad { -namespace Core { - -bool ConfigManager::parseLine(const std::vector<std::string> §ion, const std::string &key, const std::string &value) { - if(section.empty()) { - if(Common::Util::tolower(key) == "configmethod") { - if(Common::Util::tolower(value) == "mysql") - methods |= (uint16_t)MYSQL; - else - return false; - } - else if(Common::Util::tolower(key) == "daemon") { - daemons.push_back(Common::HostInfo(value)); - } - else if(Common::Util::tolower(key) == "listen") { - try { - listeners.push_back(Net::IPAddress(value)); - } - catch(Common::Exception &e) { - // TODO Logging - } - } - else if(Common::Util::tolower(key) == "x509trustfile") { - x509TrustFile = value; - } - else if(Common::Util::tolower(key) == "x509crlfile") { - x509CrlFile = value; - } - else if(Common::Util::tolower(key) == "x509certfile") { - x509CertFile = value; - } - else if(Common::Util::tolower(key) == "x509keyfile") { - x509KeyFile = value; - } - else { - // TODO Logging - - return false; - } - - return true; - } - else if(section.size() == 1 && Common::Util::tolower(section[0]) == "daemon") { - if(Common::Util::tolower(key) == "ip") - daemons.back().setIP(value); - else { - // TODO Logging - - return false; - } - - return true; - } - - // TODO Logging - - return false; -} - -ConfigManager::ConfigManager() { - loadFile("mad-core.conf"); -} - -} -} diff --git a/src/Core/ConfigManager.h b/src/Core/ConfigManager.h deleted file mode 100644 index 7178887..0000000 --- a/src/Core/ConfigManager.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * ConfigManager.h - * - * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MAD_CORE_CONFIGMANAGER_H_ -#define MAD_CORE_CONFIGMANAGER_H_ - -#include <Common/ConfigManager.h> -#include <Common/HostInfo.h> -#include <Net/IPAddress.h> - -#include <vector> -#include <string> - -namespace Mad { -namespace Core { - -class ConfigManager : public Common::ConfigManager { - private: - enum Methods { - MYSQL = (1 << 0) - }; - - uint16_t methods; - - std::vector<Net::IPAddress> listeners; - std::vector<Common::HostInfo> daemons; - - std::string x509TrustFile, x509CrlFile, x509CertFile, x509KeyFile; - - ConfigManager(); - - protected: - virtual bool parseLine(const std::vector<std::string> §ion, const std::string &key, const std::string &value); - - public: - static void useConfigManager() { - setConfigManager(std::auto_ptr<Common::ConfigManager>(new ConfigManager())); - } - - static ConfigManager *getConfigManager() { - return dynamic_cast<ConfigManager*>(Common::ConfigManager::getConfigManager()); - } - - const std::vector<Net::IPAddress>& getListenerAddresses() const {return listeners;} - const std::vector<Common::HostInfo>& getDaemonList() const {return daemons;} - - const std::string& getX509TrustFile() const {return x509TrustFile;} - const std::string& getX509CrlFile() const {return x509CrlFile;} - const std::string& getX509CertFile() const {return x509CertFile;} - const std::string& getX509KeyFile() const {return x509KeyFile;} -}; - -} - -} - -#endif /* MAD_CORE_CONFIGMANAGER_H_ */ diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index c0edd61..5eed936 100644 --- a/src/Core/ConnectionManager.cpp +++ b/src/Core/ConnectionManager.cpp @@ -18,10 +18,11 @@ */ #include "ConnectionManager.h" -#include "ConfigManager.h" +#include <Common/ConfigManager.h> #include <Common/Logger.h> #include <Common/RequestHandlers/FSInfoRequestHandler.h> #include <Common/RequestHandlers/StatusRequestHandler.h> +#include <Common/Util.h> #include "Requests/DaemonStateUpdateRequest.h" #include "RequestHandlers/DaemonCommandRequestHandler.h" #include "RequestHandlers/DaemonFSInfoRequestHandler.h" @@ -54,29 +55,74 @@ void ConnectionManager::updateState(const std::string &name, Common::HostInfo::S } } -ConnectionManager::ConnectionManager() { - Common::RequestManager::init(true); +bool ConnectionManager::handleConfigEntry(const std::vector<std::string> &entry, const std::vector<std::vector<std::string> > §ion) { + if(section.empty()) { + if(Common::Util::tolower(entry.front()) == "listen") { + if(entry.size() == 2) { + try { + listenerAddresses.push_back(Net::IPAddress(entry.back())); + } + catch(Common::Exception &e) { + // TODO Log error + } - Common::RequestManager::getRequestManager()->registerPacketType<Common::RequestHandlers::FSInfoRequestHandler>(Net::Packet::FS_INFO); - Common::RequestManager::getRequestManager()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>(Net::Packet::STATUS); - Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_REBOOT); - Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_SHUTDOWN); - Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonFSInfoRequestHandler>(Net::Packet::DAEMON_FS_INFO); - Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonListRequestHandler>(Net::Packet::LIST_DAEMONS); - Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>(Net::Packet::DAEMON_STATUS); - Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH); - Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::IdentifyRequestHandler>(Net::Packet::IDENTIFY); - Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::LogRequestHandler>(Net::Packet::LOG); + return true; + } + } + else if(Common::Util::tolower(entry.front()) == "x509trustfile") { + if(entry.size() == 2) { + x509TrustFile = entry.back(); - ConfigManager *configManager = ConfigManager::getConfigManager(); + return true; + } + } + else if(Common::Util::tolower(entry.front()) == "x509crlfile") { + if(entry.size() == 2) { + x509CrlFile = entry.back(); - Net::Connection::init(); + return true; + } + } + else if(Common::Util::tolower(entry.front()) == "x509certfile") { + if(entry.size() == 2) { + x509CertFile = entry.back(); + + return true; + } + } + else if(Common::Util::tolower(entry.front()) == "x509keyfile") { + if(entry.size() == 2) { + x509KeyFile = entry.back(); + + return true; + } + } + else if(Common::Util::tolower(entry.front()) == "daemon") { + if(entry.size() == 2) { + daemonInfo.insert(std::make_pair(entry.back(), Common::HostInfo(entry.back()))); + identifiedDaemonConnections.insert(std::make_pair<std::string,Net::ServerConnection*>(entry.back(), 0)); - const std::vector<Net::IPAddress> &listenerAddresses = configManager->getListenerAddresses(); + return true; + } + } + } + else if(Common::Util::tolower(section.front().front()) == "daemon" && section.front().size() == 2 && section.size() == 1) { + if(Common::Util::tolower(entry.front()) == "ipaddress") { + if(entry.size() == 2) { + daemonInfo[section.front().back()].setIP(entry.back()); + + return true; + } + } + } + return false; +} + +void ConnectionManager::configFinished() { if(listenerAddresses.empty()) { try { - listeners.push_back(new Net::Listener(configManager->getX509CertFile(), configManager->getX509KeyFile())); + listeners.push_back(new Net::Listener(x509CertFile, x509KeyFile)); } catch(Common::Exception &e) { // TODO Log error @@ -85,23 +131,37 @@ ConnectionManager::ConnectionManager() { else { for(std::vector<Net::IPAddress>::const_iterator address = listenerAddresses.begin(); address != listenerAddresses.end(); ++address) { try { - listeners.push_back(new Net::Listener(configManager->getX509CertFile(), configManager->getX509KeyFile(), *address)); + listeners.push_back(new Net::Listener(x509CertFile, x509KeyFile, *address)); } catch(Common::Exception &e) { // TODO Log error } } } +} - const std::vector<Common::HostInfo>& daemons = configManager->getDaemonList(); +ConnectionManager::ConnectionManager() { + Common::RequestManager::init(true); - for(std::vector<Common::HostInfo>::const_iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon) { - daemonInfo.insert(std::make_pair(daemon->getName(), *daemon)); - identifiedDaemonConnections.insert(std::make_pair<std::string,Net::ServerConnection*>(daemon->getName(), 0)); - } + Common::RequestManager::getRequestManager()->registerPacketType<Common::RequestHandlers::FSInfoRequestHandler>(Net::Packet::FS_INFO); + Common::RequestManager::getRequestManager()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>(Net::Packet::STATUS); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_REBOOT); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_SHUTDOWN); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonFSInfoRequestHandler>(Net::Packet::DAEMON_FS_INFO); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonListRequestHandler>(Net::Packet::LIST_DAEMONS); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>(Net::Packet::DAEMON_STATUS); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::IdentifyRequestHandler>(Net::Packet::IDENTIFY); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::LogRequestHandler>(Net::Packet::LOG); + + Common::ConfigManager::getConfigManager()->registerConfigurable(this); + + Net::Connection::init(); } ConnectionManager::~ConnectionManager() { + Common::ConfigManager::getConfigManager()->unregisterConfigurable(this); + for(std::list<Net::ServerConnection*>::iterator con = daemonConnections.begin(); con != daemonConnections.end(); ++con) delete *con; diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h index 6bbd66a..ad5a57e 100644 --- a/src/Core/ConnectionManager.h +++ b/src/Core/ConnectionManager.h @@ -25,6 +25,7 @@ #include <map> #include <memory> +#include <Common/Configurable.h> #include <Common/Exception.h> #include <Common/HostInfo.h> #include <Common/RequestManager.h> @@ -40,10 +41,13 @@ class Packet; namespace Core { -class ConnectionManager { +class ConnectionManager : private Common::Configurable { private: static std::auto_ptr<ConnectionManager> connectionManager; + std::string x509TrustFile, x509CrlFile, x509CertFile, x509KeyFile; + + std::vector<Net::IPAddress> listenerAddresses; std::list<Net::Listener*> listeners; std::list<Net::ServerConnection*> daemonConnections; @@ -62,6 +66,10 @@ class ConnectionManager { void updateState(const std::string &name, Common::HostInfo::State state); + protected: + virtual bool handleConfigEntry(const std::vector<std::string> &entry, const std::vector<std::vector<std::string> > §ion); + virtual void configFinished(); + public: static ConnectionManager* getConnectionManager() { return connectionManager.get(); diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am index b72f766..fa7bb9e 100644 --- a/src/Core/Makefile.am +++ b/src/Core/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS = Requests RequestHandlers noinst_LTLIBRARIES = libcore.la -libcore_la_SOURCES = ConfigManager.cpp ConnectionManager.cpp +libcore_la_SOURCES = ConnectionManager.cpp libcore_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la -noinst_HEADERS = ConfigManager.h ConnectionManager.h +noinst_HEADERS = ConnectionManager.h diff --git a/src/Core/Makefile.in b/src/Core/Makefile.in index f770c09..a190ccd 100644 --- a/src/Core/Makefile.in +++ b/src/Core/Makefile.in @@ -49,7 +49,7 @@ CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libcore_la_DEPENDENCIES = Requests/librequests.la \ RequestHandlers/librequesthandlers.la -am_libcore_la_OBJECTS = ConfigManager.lo ConnectionManager.lo +am_libcore_la_OBJECTS = ConnectionManager.lo libcore_la_OBJECTS = $(am_libcore_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -199,9 +199,9 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = Requests RequestHandlers noinst_LTLIBRARIES = libcore.la -libcore_la_SOURCES = ConfigManager.cpp ConnectionManager.cpp +libcore_la_SOURCES = ConnectionManager.cpp libcore_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la -noinst_HEADERS = ConfigManager.h ConnectionManager.h +noinst_HEADERS = ConnectionManager.h all: all-recursive .SUFFIXES: @@ -253,7 +253,6 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConfigManager.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConnectionManager.Plo@am__quote@ .cpp.o: |