diff options
32 files changed, 255 insertions, 90 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index decb28e..9644d71 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -86,14 +86,14 @@ void CommandParser::helpCommand(const std::vector<std::string> &args) { void CommandParser::statusCommand(const std::vector<std::string>&) { activeRequests++; - Requests::CoreStatusRequest::send(connection, *requestManager, sigc::mem_fun(this, &CommandParser::coreStatusRequestFinished)); + Requests::CoreStatusRequest::send(connection, sigc::mem_fun(this, &CommandParser::coreStatusRequestFinished)); } void CommandParser::exitCommand(const std::vector<std::string>&) { activeRequests++; disconnect = true; - Common::Requests::DisconnectRequest::send(connection, *requestManager, sigc::mem_fun(this, &CommandParser::requestFinished)); + Common::Requests::DisconnectRequest::send(connection, sigc::mem_fun(this, &CommandParser::requestFinished)); } void CommandParser::coreStatusRequestFinished(const Net::Packets::HostStatusPacket &packet) { diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h index 78ed6fa..69ed217 100644 --- a/src/Client/CommandParser.h +++ b/src/Client/CommandParser.h @@ -26,10 +26,6 @@ namespace Mad { -namespace Common { -class RequestManager; -} - namespace Net { class Connection; @@ -56,7 +52,6 @@ class CommandParser { sigc::signal<void> finished; - Common::RequestManager *requestManager; Net::Connection *connection; unsigned int activeRequests; @@ -80,7 +75,7 @@ class CommandParser { } public: - CommandParser(Common::RequestManager *requestManager0, Net::Connection *connection0) : requestManager(requestManager0), connection(connection0), activeRequests(0), disconnect(false) {} + CommandParser(Net::Connection *connection0) : connection(connection0), activeRequests(0), disconnect(false) {} bool requestsActive() {return (activeRequests > 0);} bool willDisconnect() {return disconnect;} diff --git a/src/Client/Requests/CoreStatusRequest.cpp b/src/Client/Requests/CoreStatusRequest.cpp index fa3f1f1..6d0f634 100644 --- a/src/Client/Requests/CoreStatusRequest.cpp +++ b/src/Client/Requests/CoreStatusRequest.cpp @@ -28,12 +28,12 @@ namespace Mad { namespace Client { namespace Requests { -bool CoreStatusRequest::send(Net::Connection *connection, Common::RequestManager &requestManager, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback) { +bool CoreStatusRequest::send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback) { CoreStatusRequest *request = new CoreStatusRequest(); request->finished.connect(callback); - if(requestManager.sendRequest(connection, request)) + if(Mad::Common::RequestManager::getRequestManager()->sendRequest(connection, request)) return true; delete request; diff --git a/src/Client/Requests/CoreStatusRequest.h b/src/Client/Requests/CoreStatusRequest.h index 7de8a68..55d6a22 100644 --- a/src/Client/Requests/CoreStatusRequest.h +++ b/src/Client/Requests/CoreStatusRequest.h @@ -26,10 +26,6 @@ namespace Mad { -namespace Common { -class RequestManager; -} - namespace Net { namespace Packets { class HostStatusPacket; @@ -46,7 +42,7 @@ class CoreStatusRequest : public Common::Request { CoreStatusRequest() {} public: - static bool send(Net::Connection *connection, Common::RequestManager &requestManager, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback); + static bool send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback); virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); virtual bool handlePacket(Net::Connection*, const Net::Packet &packet); diff --git a/src/Common/ConfigManager.cpp b/src/Common/ConfigManager.cpp index a363862..76227b4 100644 --- a/src/Common/ConfigManager.cpp +++ b/src/Common/ConfigManager.cpp @@ -27,6 +27,9 @@ namespace Mad { namespace Common { +std::auto_ptr<ConfigManager> ConfigManager::configManager; + + bool ConfigManager::loadFile(const std::string &filename) { std::ifstream file(filename.c_str()); std::vector<std::string> section; diff --git a/src/Common/ConfigManager.h b/src/Common/ConfigManager.h index 5c94614..91126ca 100644 --- a/src/Common/ConfigManager.h +++ b/src/Common/ConfigManager.h @@ -22,16 +22,24 @@ #include <string> #include <vector> +#include <memory> namespace Mad { namespace Common { class ConfigManager { + private: + static std::auto_ptr<ConfigManager> configManager; + protected: ConfigManager() { initBackends(); } + static void setConfigManager(ConfigManager *configManager0) { + configManager = std::auto_ptr<ConfigManager>(configManager0); + } + virtual bool parseLine(const std::vector<std::string> §ion, const std::string &key, const std::string &value = std::string()) = 0; bool loadFile(const std::string &filename); @@ -40,6 +48,10 @@ class ConfigManager { public: virtual ~ConfigManager() {} + + static ConfigManager *getConfigManager() { + return configManager.get(); + } }; } diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h index a6995ec..4a72bd5 100644 --- a/src/Common/RequestHandler.h +++ b/src/Common/RequestHandler.h @@ -29,6 +29,8 @@ class Packet; namespace Common { +class RequestManager; + class RequestHandler { private: bool finished; diff --git a/src/Common/RequestHandlers/IdentifyRequestHandler.cpp b/src/Common/RequestHandlers/IdentifyRequestHandler.cpp index 791eadd..d17c3b2 100644 --- a/src/Common/RequestHandlers/IdentifyRequestHandler.cpp +++ b/src/Common/RequestHandlers/IdentifyRequestHandler.cpp @@ -32,7 +32,8 @@ bool IdentifyRequestHandler::handlePacket(Net::Connection *connection, const Net return false; // TODO Logging // TODO Require authentication - // TODO Save identity information + + connection->setName(std::string((const char*)packet.getData(), packet.getLength())); if(!connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()))) return false; diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index 7075229..93bbea5 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -27,6 +27,9 @@ namespace Mad { namespace Common { +std::auto_ptr<RequestManager> RequestManager::requestManager; + + RequestHandler* RequestManager::RequestMap::findRequest(uint16_t id) { iterator it = find(id); if(it == end()) diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h index 2ca10e7..795f277 100644 --- a/src/Common/RequestManager.h +++ b/src/Common/RequestManager.h @@ -22,7 +22,10 @@ #include "RequestHandler.h" #include <Net/Connection.h> + #include <map> +#include <memory> + namespace Mad { namespace Common { @@ -68,9 +71,7 @@ class RequestManager { } }; - // Prevent shallow copy - RequestManager(const RequestManager &o); - RequestManager& operator=(const RequestManager &o); + static std::auto_ptr<RequestManager> requestManager; std::map<Net::Connection*,RequestMap*> requestMaps; uint16_t requestId; @@ -81,9 +82,23 @@ class RequestManager { return requestId+=2; } + // Prevent shallow copy + RequestManager(const RequestManager &o); + RequestManager& operator=(const RequestManager &o); + + RequestManager(bool core); + void receiveHandler(Net::Connection *connection, const Net::Packet &packet); public: + static void init(bool core) { + requestManager = std::auto_ptr<RequestManager>(new RequestManager(core)); + } + + static RequestManager* getRequestManager() { + return requestManager.get(); + } + void registerConnection(Net::Connection *connection); void unregisterConnection(Net::Connection *connection); @@ -95,7 +110,6 @@ class RequestManager { bool sendRequest(Net::Connection *connection, Request *request); - RequestManager(bool core); virtual ~RequestManager(); }; diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp index 2652af2..0b6e3bc 100644 --- a/src/Common/Requests/DisconnectRequest.cpp +++ b/src/Common/Requests/DisconnectRequest.cpp @@ -24,12 +24,12 @@ namespace Mad { namespace Common { namespace Requests { -bool DisconnectRequest::send(Net::Connection *connection, RequestManager &requestManager, const sigc::slot<void> &callback) { +bool DisconnectRequest::send(Net::Connection *connection, const sigc::slot<void> &callback) { DisconnectRequest *request = new DisconnectRequest(); request->finished.connect(callback); - if(requestManager.sendRequest(connection, request)) + if(Mad::Common::RequestManager::getRequestManager()->sendRequest(connection, request)) return true; delete request; diff --git a/src/Common/Requests/DisconnectRequest.h b/src/Common/Requests/DisconnectRequest.h index a569d8f..6c87f85 100644 --- a/src/Common/Requests/DisconnectRequest.h +++ b/src/Common/Requests/DisconnectRequest.h @@ -26,9 +26,6 @@ namespace Mad { namespace Common { - -class RequestManager; - namespace Requests { class DisconnectRequest : public Request { @@ -38,7 +35,7 @@ class DisconnectRequest : public Request { DisconnectRequest() {} public: - static bool send(Net::Connection *connection, RequestManager &requestManager, const sigc::slot<void> &callback); + static bool send(Net::Connection *connection, const sigc::slot<void> &callback); virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); diff --git a/src/Common/Requests/GSSAPIAuthRequest.cpp b/src/Common/Requests/GSSAPIAuthRequest.cpp index 1874064..705db41 100644 --- a/src/Common/Requests/GSSAPIAuthRequest.cpp +++ b/src/Common/Requests/GSSAPIAuthRequest.cpp @@ -37,10 +37,10 @@ GSSAPIAuthRequest::~GSSAPIAuthRequest() { gss_release_name(&minStat, &gssServiceName); } -bool GSSAPIAuthRequest::send(Net::Connection *connection, RequestManager &requestManager, const std::string &serviceName0) { +bool GSSAPIAuthRequest::send(Net::Connection *connection, const std::string &serviceName0) { GSSAPIAuthRequest *request = new GSSAPIAuthRequest(serviceName0); - if(requestManager.sendRequest(connection, request)) + if(Mad::Common::RequestManager::getRequestManager()->sendRequest(connection, request)) return true; delete request; diff --git a/src/Common/Requests/GSSAPIAuthRequest.h b/src/Common/Requests/GSSAPIAuthRequest.h index a4a2f17..e9a200e 100644 --- a/src/Common/Requests/GSSAPIAuthRequest.h +++ b/src/Common/Requests/GSSAPIAuthRequest.h @@ -46,7 +46,7 @@ class GSSAPIAuthRequest : public Request { public: virtual ~GSSAPIAuthRequest(); - static bool send(Net::Connection *connection, RequestManager &requestManager, const std::string &serviceName0); + static bool send(Net::Connection *connection, const std::string &serviceName0); virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); diff --git a/src/Common/Requests/IdentifyRequest.cpp b/src/Common/Requests/IdentifyRequest.cpp index 18b515f..54d49e2 100644 --- a/src/Common/Requests/IdentifyRequest.cpp +++ b/src/Common/Requests/IdentifyRequest.cpp @@ -25,10 +25,10 @@ namespace Mad { namespace Common { namespace Requests { -bool IdentifyRequest::send(Net::Connection *connection, RequestManager &requestManager, const std::string &hostname0) { +bool IdentifyRequest::send(Net::Connection *connection, const std::string &hostname0) { IdentifyRequest *request = new IdentifyRequest(hostname0); - if(requestManager.sendRequest(connection, request)) + if(RequestManager::getRequestManager()->sendRequest(connection, request)) return true; delete request; @@ -53,8 +53,8 @@ bool IdentifyRequest::handlePacket(Net::Connection*, const Net::Packet &packet) if(packet.getType() != Net::Packet::OK) return false; // TODO Logging - setFinished(); - return true; + setFinished(); + return true; } } diff --git a/src/Common/Requests/IdentifyRequest.h b/src/Common/Requests/IdentifyRequest.h index 9fb45d9..0b783e4 100644 --- a/src/Common/Requests/IdentifyRequest.h +++ b/src/Common/Requests/IdentifyRequest.h @@ -25,9 +25,6 @@ namespace Mad { namespace Common { - -class RequestManager; - namespace Requests { class IdentifyRequest : public Request { @@ -37,7 +34,7 @@ class IdentifyRequest : public Request { std::string hostname; public: - static bool send(Net::Connection *connection, RequestManager &requestManager, const std::string &hostname0); + static bool send(Net::Connection *connection, const std::string &hostname0); virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); virtual bool handlePacket(Net::Connection*, const Net::Packet &packet); diff --git a/src/Common/SystemBackend.cpp b/src/Common/SystemBackend.cpp index 8b9aa0d..c9be525 100644 --- a/src/Common/SystemBackend.cpp +++ b/src/Common/SystemBackend.cpp @@ -22,7 +22,7 @@ namespace Mad { namespace Common { -SystemBackend *SystemBackend::backend = new SystemBackend(); +std::auto_ptr<SystemBackend> SystemBackend::backend(new SystemBackend()); } } diff --git a/src/Common/SystemBackend.h b/src/Common/SystemBackend.h index 6929c8d..19b0715 100644 --- a/src/Common/SystemBackend.h +++ b/src/Common/SystemBackend.h @@ -21,20 +21,20 @@ #define MAD_COMMON_SYSTEMBACKEND_H_ #include <stdint.h> +#include <memory> namespace Mad { namespace Common { class SystemBackend { private: - static SystemBackend *backend; + static std::auto_ptr<SystemBackend> backend; protected: SystemBackend() {} static void setBackend(SystemBackend *backend0) { - delete backend; - backend = backend0; + backend = std::auto_ptr<SystemBackend>(backend0); } public: @@ -63,7 +63,7 @@ class SystemBackend { } static SystemBackend *getBackend() { - return backend; + return backend.get(); } }; 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: diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp index da1ff3f..22f4570 100644 --- a/src/Net/Connection.cpp +++ b/src/Net/Connection.cpp @@ -281,6 +281,7 @@ void Connection::doDisconnect() { peer = 0; authenticated = false; + name.clear(); state = DISCONNECTED; } diff --git a/src/Net/Connection.h b/src/Net/Connection.h index 58e7291..953ccc8 100644 --- a/src/Net/Connection.h +++ b/src/Net/Connection.h @@ -20,11 +20,13 @@ #ifndef MAD_NET_CONNECTION_H_ #define MAD_NET_CONNECTION_H_ +#include "Packet.h" + #include <queue> +#include <string> #include <gnutls/gnutls.h> #include <sigc++/signal.h> #include <poll.h> -#include "Packet.h" namespace Mad { namespace Net { @@ -55,6 +57,7 @@ class Connection { sigc::signal<void,Connection*,const Packet&> signal; bool authenticated; + std::string name; void doHandshake(); @@ -152,6 +155,9 @@ class Connection { sigc::signal<void,Connection*,const Packet&> signalReceive() const {return signal;} + std::string getName() const {return name;} + void setName(const std::string& name0) {name = name0;} + static void init() { gnutls_global_init(); } diff --git a/src/mad-core.conf b/src/mad-core.conf index 9eda7c3..8094a97 100644 --- a/src/mad-core.conf +++ b/src/mad-core.conf @@ -8,6 +8,6 @@ X509TrustFile ../Cert/ca-cert.pem X509CertFile ../Cert/cert.pem X509KeyFile ../Cert/key.pem -Daemon ic01 { - IpAddress 192.168.2.11 +Daemon test { + IpAddress 127.0.0.1 } diff --git a/src/mad-core.cpp b/src/mad-core.cpp index 0bbee97..4bfbcfc 100644 --- a/src/mad-core.cpp +++ b/src/mad-core.cpp @@ -29,20 +29,12 @@ int main() { sigaddset(&signals, SIGPIPE); sigprocmask(SIG_BLOCK, &signals, 0); - Mad::Core::ConfigManager configManager; - - Mad::Net::Connection::init(); - - Mad::Core::ConnectionManager *connectionManager = new Mad::Core::ConnectionManager(configManager); + Mad::Core::ConfigManager::useConfigManager(); while(true) { - if(connectionManager->wait(10000)) - connectionManager->run(); + if(Mad::Core::ConnectionManager::getConnectionManager()->wait(10000)) + Mad::Core::ConnectionManager::getConnectionManager()->run(); } - delete connectionManager; - - Mad::Net::Connection::deinit(); - return 0; } diff --git a/src/mad.cpp b/src/mad.cpp index 613747b..a70be5a 100644 --- a/src/mad.cpp +++ b/src/mad.cpp @@ -29,7 +29,7 @@ int main() { Mad::Net::Connection::init(); - Mad::Common::RequestManager requestManager(false); + Mad::Common::RequestManager::init(false); Mad::Net::ClientConnection *connection = new Mad::Net::ClientConnection; try { @@ -42,11 +42,12 @@ int main() { connection->sendReceive(fd.revents); } - requestManager.registerConnection(connection); + Mad::Common::RequestManager::getRequestManager()->registerConnection(connection); - char hostname[256]; - gethostname(hostname, sizeof(hostname)); - Mad::Common::Requests::IdentifyRequest::send(connection, requestManager, hostname); + //char hostname[256]; + //gethostname(hostname, sizeof(hostname)); + //Mad::Common::Requests::IdentifyRequest::send(connection, hostname); + Mad::Common::Requests::IdentifyRequest::send(connection, "test"); while(connection->isConnected()) { struct pollfd fd = connection->getPollfd(); @@ -55,7 +56,7 @@ int main() { connection->sendReceive(fd.revents); } - requestManager.unregisterConnection(connection); + Mad::Common::RequestManager::getRequestManager()->unregisterConnection(connection); } catch(Mad::Net::Exception &e) { std::cerr << "Connection error: " << e.what() << std::endl; diff --git a/src/madc.cpp b/src/madc.cpp index 5b0e3a1..12a190e 100644 --- a/src/madc.cpp +++ b/src/madc.cpp @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) { Mad::Net::Connection::init(); - Mad::Common::RequestManager requestManager(false); + Mad::Common::RequestManager::init(false); Mad::Net::ClientConnection *connection = new Mad::Net::ClientConnection; try { @@ -89,9 +89,9 @@ int main(int argc, char *argv[]) { std::cout << " connected." << std::endl << std::endl; - requestManager.registerConnection(connection); + Mad::Common::RequestManager::getRequestManager()->registerConnection(connection); - parser = new Mad::Client::CommandParser(&requestManager, connection); + parser = new Mad::Client::CommandParser(connection); parser->signalFinished().connect(sigc::ptr_fun(activateReadline)); fds[0].fd = STDIN_FILENO; @@ -111,7 +111,7 @@ int main(int argc, char *argv[]) { delete parser; - requestManager.unregisterConnection(connection); + Mad::Common::RequestManager::getRequestManager()->unregisterConnection(connection); } catch(Mad::Net::Exception &e) { std::cerr << "Connection error: " << e.what() << std::endl; |