diff options
Diffstat (limited to 'src/Core')
-rw-r--r-- | src/Core/ConfigManager.h | 10 | ||||
-rw-r--r-- | src/Core/ConnectionManager.cpp | 44 | ||||
-rw-r--r-- | src/Core/ConnectionManager.h | 33 | ||||
-rw-r--r-- | src/Core/DaemonInfo.h | 2 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp | 50 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonStatusRequestHandler.h | 43 | ||||
-rw-r--r-- | src/Core/RequestHandlers/Makefile.am | 4 | ||||
-rw-r--r-- | src/Core/RequestHandlers/Makefile.in | 7 |
8 files changed, 169 insertions, 24 deletions
diff --git a/src/Core/ConfigManager.h b/src/Core/ConfigManager.h index 6470a33..760312a 100644 --- a/src/Core/ConfigManager.h +++ b/src/Core/ConfigManager.h @@ -42,11 +42,19 @@ class ConfigManager : public Common::ConfigManager { 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: - ConfigManager(); + static void useConfigManager() { + setConfigManager(new ConfigManager()); + } + + static ConfigManager *getConfigManager() { + return dynamic_cast<ConfigManager*>(Common::ConfigManager::getConfigManager()); + } const std::vector<Net::IPAddress>& getListenerAddresses() const {return listeners;} const std::vector<DaemonInfo>& getDaemonList() const {return daemons;} diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index 98288ba..78497e7 100644 --- a/src/Core/ConnectionManager.cpp +++ b/src/Core/ConnectionManager.cpp @@ -20,6 +20,7 @@ #include "ConnectionManager.h" #include "ConfigManager.h" #include "RequestHandlers/CoreStatusRequestHandler.h" +#include "RequestHandlers/DaemonStatusRequestHandler.h" #include "RequestHandlers/GSSAPIAuthRequestHandler.h" #include <Net/ServerConnection.h> #include <Net/Packet.h> @@ -29,6 +30,9 @@ namespace Mad { namespace Core { +std::auto_ptr<ConnectionManager> ConnectionManager::connectionManager; + + void ConnectionManager::refreshPollfds() { pollfds.clear(); pollfdMap.clear(); @@ -53,15 +57,22 @@ void ConnectionManager::refreshPollfds() { } } -ConnectionManager::ConnectionManager(const ConfigManager& configManager) : requestManager(true) { - requestManager.registerPacketType<RequestHandlers::CoreStatusRequestHandler>(Net::Packet::CORE_STATUS); - requestManager.registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH); +ConnectionManager::ConnectionManager() { + Common::RequestManager::init(true); + + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::CoreStatusRequestHandler>(Net::Packet::CORE_STATUS); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>(Net::Packet::DAEMON_STATUS); + Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH); - const std::vector<Net::IPAddress> &listenerAddresses = configManager.getListenerAddresses(); + ConfigManager *configManager = ConfigManager::getConfigManager(); + + Net::Connection::init(); + + const std::vector<Net::IPAddress> &listenerAddresses = configManager->getListenerAddresses(); if(listenerAddresses.empty()) { try { - listeners.push_back(new Net::Listener(configManager.getX509CertFile(), configManager.getX509KeyFile())); + listeners.push_back(new Net::Listener(configManager->getX509CertFile(), configManager->getX509KeyFile())); } catch(Net::Exception &e) { // TODO Log error @@ -70,7 +81,7 @@ ConnectionManager::ConnectionManager(const ConfigManager& configManager) : reque 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(configManager->getX509CertFile(), configManager->getX509KeyFile(), *address)); } catch(Net::Exception &e) { // TODO Log error @@ -79,6 +90,13 @@ ConnectionManager::ConnectionManager(const ConfigManager& configManager) : reque } refreshPollfds(); + + const std::vector<DaemonInfo>& daemons = configManager->getDaemonList(); + + for(std::vector<DaemonInfo>::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)); + } } ConnectionManager::~ConnectionManager() { @@ -87,6 +105,8 @@ ConnectionManager::~ConnectionManager() { for(std::list<Net::ServerConnection*>::iterator con = clientConnections.begin(); con != clientConnections.end(); ++con) delete *con; + + Net::Connection::deinit(); } void ConnectionManager::handleConnections(std::list<Net::ServerConnection*>& connections) { @@ -100,7 +120,7 @@ void ConnectionManager::handleConnections(std::list<Net::ServerConnection*>& con ++con; } else { - requestManager.unregisterConnection(*con); + Common::RequestManager::getRequestManager()->unregisterConnection(*con); delete *con; connections.erase(con++); } @@ -118,12 +138,20 @@ void ConnectionManager::run() { while((con = (*listener)->getConnection(pollfdMap)) != 0) { (con->isDaemonConnection() ? daemonConnections : clientConnections).push_back(con); - requestManager.registerConnection(con); + Common::RequestManager::getRequestManager()->registerConnection(con); } } refreshPollfds(); } +Net::Connection* ConnectionManager::getDaemonConnection(const std::string &name) const { + std::map<std::string,Net::ServerConnection*>::const_iterator daemon = identifiedDaemonConnections.find(name); + if(daemon == identifiedDaemonConnections.end()) + return 0; + + return daemon->second; +} + } } diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h index 6161c3f..4ca3d59 100644 --- a/src/Core/ConnectionManager.h +++ b/src/Core/ConnectionManager.h @@ -23,7 +23,10 @@ #include <list> #include <vector> #include <map> +#include <memory> #include <poll.h> + +#include "DaemonInfo.h" #include <Common/RequestManager.h> namespace Mad { @@ -37,37 +40,49 @@ class Packet; namespace Core { -class ConfigManager; - class ConnectionManager { private: - // Prevent shallow copy - ConnectionManager(const ConnectionManager &o); - ConnectionManager& operator=(const ConnectionManager &o); - - Common::RequestManager requestManager; + static std::auto_ptr<ConnectionManager> connectionManager; std::list<Net::Listener*> listeners; std::list<Net::ServerConnection*> daemonConnections; std::list<Net::ServerConnection*> clientConnections; + std::map<std::string,DaemonInfo> daemonInfo; + std::map<std::string,Net::ServerConnection*> identifiedDaemonConnections; + std::vector<struct pollfd> pollfds; std::map<int,const short*> pollfdMap; + // Prevent shallow copy + ConnectionManager(const ConnectionManager &o); + ConnectionManager& operator=(const ConnectionManager &o); + + ConnectionManager(); + void refreshPollfds(); - void handleConnections(std::list<Net::ServerConnection*>& connections); + void handleConnections(std::list<Net::ServerConnection*> &connections); public: - ConnectionManager(const ConfigManager& configManager); + static ConnectionManager* getConnectionManager() { + return connectionManager.get(); + } + virtual ~ConnectionManager(); + void init() { + connectionManager = std::auto_ptr<ConnectionManager>(new ConnectionManager()); + } + bool wait(int timeout) { return (poll(pollfds.data(), pollfds.size(), timeout) > 0); } void run(); + + Net::Connection* getDaemonConnection(const std::string &name) const; }; } diff --git a/src/Core/DaemonInfo.h b/src/Core/DaemonInfo.h index b1dd2ff..0377c57 100644 --- a/src/Core/DaemonInfo.h +++ b/src/Core/DaemonInfo.h @@ -1,7 +1,7 @@ /* * DaemonInfo.h * - * Copyright (C) 2008 neoraider + * 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 diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp new file mode 100644 index 0000000..81f066d --- /dev/null +++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp @@ -0,0 +1,50 @@ +/* + * DaemonStatusRequestHandler.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 "DaemonStatusRequestHandler.h" +#include "../ConnectionManager.h" +#include <Net/Packet.h> + +namespace Mad { +namespace Core { +namespace RequestHandlers { + +bool DaemonStatusRequestHandler::handlePacket(Net::Connection*, const Net::Packet &packet) { + if(isFinished()) + return false; + + if(packet.getType() != Net::Packet::DAEMON_STATUS) + return false; // TODO Logging + + // TODO Require authentication + + std::string daemonName((char*)packet.getData(), packet.getLength()); + + /*Net::Connection *daemonCon = connectionManager->getDaemonConnection(daemonName); + if(!daemonCon) + return false;*/ + + + + return true; +} + +} +} +} diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.h b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h new file mode 100644 index 0000000..accc990 --- /dev/null +++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h @@ -0,0 +1,43 @@ +/* + * DaemonStatusRequestHandler.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_REQUESTHANDLERS_DAEMONSTATUSREQUESTHANDLER_H_ +#define MAD_CORE_REQUESTHANDLERS_DAEMONSTATUSREQUESTHANDLER_H_ + +#include <Common/RequestHandler.h> + +namespace Mad { +namespace Core { + +class ConnectionManager; + +namespace RequestHandlers { + +class DaemonStatusRequestHandler : public Common::RequestHandler { + public: + DaemonStatusRequestHandler() {} + + virtual bool handlePacket(Net::Connection*, const Net::Packet &packet); +}; + +} +} +} + +#endif /* MAD_CORE_REQUESTHANDLERS_DAEMONSTATUSREQUESTHANDLER_H_ */ diff --git a/src/Core/RequestHandlers/Makefile.am b/src/Core/RequestHandlers/Makefile.am index d556af6..3be5350 100644 --- a/src/Core/RequestHandlers/Makefile.am +++ b/src/Core/RequestHandlers/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = CoreStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp +librequesthandlers_la_SOURCES = CoreStatusRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp -noinst_HEADERS = CoreStatusRequestHandler.h GSSAPIAuthRequestHandler.h +noinst_HEADERS = CoreStatusRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h diff --git a/src/Core/RequestHandlers/Makefile.in b/src/Core/RequestHandlers/Makefile.in index 9147203..6661e32 100644 --- a/src/Core/RequestHandlers/Makefile.in +++ b/src/Core/RequestHandlers/Makefile.in @@ -46,7 +46,7 @@ CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequesthandlers_la_LIBADD = am_librequesthandlers_la_OBJECTS = CoreStatusRequestHandler.lo \ - GSSAPIAuthRequestHandler.lo + DaemonStatusRequestHandler.lo GSSAPIAuthRequestHandler.lo librequesthandlers_la_OBJECTS = $(am_librequesthandlers_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -185,8 +185,8 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = CoreStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp -noinst_HEADERS = CoreStatusRequestHandler.h GSSAPIAuthRequestHandler.h +librequesthandlers_la_SOURCES = CoreStatusRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp +noinst_HEADERS = CoreStatusRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h all: all-am .SUFFIXES: @@ -239,6 +239,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CoreStatusRequestHandler.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequestHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GSSAPIAuthRequestHandler.Plo@am__quote@ .cpp.o: |