diff options
Diffstat (limited to 'src/Core')
-rw-r--r-- | src/Core/ConnectionManager.cpp | 13 | ||||
-rw-r--r-- | src/Core/ConnectionManager.h | 1 | ||||
-rw-r--r-- | src/Core/RequestHandlers/CoreStatusRequestHandler.h | 6 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonListRequestHandler.cpp | 54 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonListRequestHandler.h | 40 | ||||
-rw-r--r-- | src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h | 6 | ||||
-rw-r--r-- | src/Core/RequestHandlers/Makefile.am | 4 | ||||
-rw-r--r-- | src/Core/RequestHandlers/Makefile.in | 9 |
8 files changed, 121 insertions, 12 deletions
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index 72bf07f..9cbda90 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/DaemonListRequestHandler.h" #include "RequestHandlers/DaemonStatusRequestHandler.h" #include "RequestHandlers/GSSAPIAuthRequestHandler.h" #include "RequestHandlers/IdentifyRequestHandler.h" @@ -66,6 +67,7 @@ ConnectionManager::ConnectionManager() { Common::RequestManager::init(true); Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::CoreStatusRequestHandler>(Net::Packet::CORE_STATUS); + 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); @@ -199,5 +201,16 @@ void ConnectionManager::identifyDaemonConnection(Net::Connection *connection, co std::cerr << "Identified as '" << name << "'." << std::endl; } +std::map<std::string,DaemonInfo> ConnectionManager::getDaemonList() const { + std::map<std::string,DaemonInfo> ret; + + for(std::map<std::string,Net::ServerConnection*>::const_iterator con = identifiedDaemonConnections.begin(); con != identifiedDaemonConnections.end(); ++con) { + if(con->second) + ret.insert(std::make_pair(con->first, daemonInfo.at(con->first))); + } + + return ret; +} + } } diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h index 6e098b6..ba029ec 100644 --- a/src/Core/ConnectionManager.h +++ b/src/Core/ConnectionManager.h @@ -84,6 +84,7 @@ class ConnectionManager { Net::Connection* getDaemonConnection(const std::string &name) const; void identifyDaemonConnection(Net::Connection *connection, const std::string &name); + std::map<std::string,DaemonInfo> getDaemonList() const; }; } diff --git a/src/Core/RequestHandlers/CoreStatusRequestHandler.h b/src/Core/RequestHandlers/CoreStatusRequestHandler.h index c6c0da3..c9d3199 100644 --- a/src/Core/RequestHandlers/CoreStatusRequestHandler.h +++ b/src/Core/RequestHandlers/CoreStatusRequestHandler.h @@ -17,8 +17,8 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef MAD_CORE_REQUESTHANDLER_CORESTATUSREQUESTHANDLER_H_ -#define MAD_CORE_REQUESTHANDLER_CORESTATUSREQUESTHANDLER_H_ +#ifndef MAD_CORE_REQUESTHANDLERS_CORESTATUSREQUESTHANDLER_H_ +#define MAD_CORE_REQUESTHANDLERS_CORESTATUSREQUESTHANDLER_H_ #include <Common/RequestHandler.h> @@ -37,4 +37,4 @@ class CoreStatusRequestHandler : public Common::RequestHandler { } } -#endif /* MAD_CORE_REQUESTHANDLER_CORESTATUSREQUESTHANDLER_H_ */ +#endif /* MAD_CORE_REQUESTHANDLERS_CORESTATUSREQUESTHANDLER_H_ */ diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.cpp b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp new file mode 100644 index 0000000..00ee0ff --- /dev/null +++ b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp @@ -0,0 +1,54 @@ +/* + * DaemonListRequestHandler.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 "DaemonListRequestHandler.h" +#include "../ConnectionManager.h" +#include <Net/Connection.h> +#include <Net/Packets/NameListPacket.h> + +namespace Mad { +namespace Core { +namespace RequestHandlers { + +bool DaemonListRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(isFinished()) + return false; + + if(packet.getType() != Net::Packet::LIST_DAEMONS) + return false; // TODO Logging + + // TODO Require authentication + + std::map<std::string,DaemonInfo> daemons = ConnectionManager::getConnectionManager()->getDaemonList(); + std::vector<std::string> names; + + for(std::map<std::string,DaemonInfo>::iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon) + names.push_back(daemon->first); + + if(!connection->send(Net::Packets::NameListPacket(Net::Packet::OK, packet.getRequestId(), names))) + return false; + + setFinished(); + + return true; +} + +} +} +} diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.h b/src/Core/RequestHandlers/DaemonListRequestHandler.h new file mode 100644 index 0000000..406d212 --- /dev/null +++ b/src/Core/RequestHandlers/DaemonListRequestHandler.h @@ -0,0 +1,40 @@ +/* + * DaemonListRequestHandler.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_DAEMONLISTREQUESTHANDLER_H_ +#define MAD_CORE_REQUESTHANDLERS_DAEMONLISTREQUESTHANDLER_H_ + +#include <Common/RequestHandler.h> + +namespace Mad { +namespace Core { +namespace RequestHandlers { + +class DaemonListRequestHandler : public Common::RequestHandler { + public: + DaemonListRequestHandler() {} + + virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); +}; + +} +} +} + +#endif /* MAD_CORE_REQUESTHANDLERS_DAEMONLISTREQUESTHANDLER_H_ */ diff --git a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h index a88969b..57ea14f 100644 --- a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h +++ b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h @@ -17,8 +17,8 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef MAD_CORE_REQUESTHANDLER_GSSAPIAUTHREQUESTHANDLER_H_ -#define MAD_CORE_REQUESTHANDLER_GSSAPIAUTHREQUESTHANDLER_H_ +#ifndef MAD_CORE_REQUESTHANDLERS_GSSAPIAUTHREQUESTHANDLER_H_ +#define MAD_CORE_REQUESTHANDLERS_GSSAPIAUTHREQUESTHANDLER_H_ #include <Common/RequestHandler.h> #include <gssapi/gssapi.h> @@ -43,4 +43,4 @@ class GSSAPIAuthRequestHandler : public Common::RequestHandler { } } -#endif /* MAD_CORE_REQUESTHANDLER_GSSAPIAUTHREQUESTHANDLER_H_ */ +#endif /* MAD_CORE_REQUESTHANDLERS_GSSAPIAUTHREQUESTHANDLER_H_ */ diff --git a/src/Core/RequestHandlers/Makefile.am b/src/Core/RequestHandlers/Makefile.am index c13d0d7..8155a80 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 DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp +librequesthandlers_la_SOURCES = CoreStatusRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp -noinst_HEADERS = CoreStatusRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h +noinst_HEADERS = CoreStatusRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h diff --git a/src/Core/RequestHandlers/Makefile.in b/src/Core/RequestHandlers/Makefile.in index 191fd28..88e1ca3 100644 --- a/src/Core/RequestHandlers/Makefile.in +++ b/src/Core/RequestHandlers/Makefile.in @@ -46,8 +46,8 @@ CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) librequesthandlers_la_LIBADD = am_librequesthandlers_la_OBJECTS = CoreStatusRequestHandler.lo \ - DaemonStatusRequestHandler.lo GSSAPIAuthRequestHandler.lo \ - IdentifyRequestHandler.lo + DaemonListRequestHandler.lo DaemonStatusRequestHandler.lo \ + GSSAPIAuthRequestHandler.lo IdentifyRequestHandler.lo librequesthandlers_la_OBJECTS = $(am_librequesthandlers_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -186,8 +186,8 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = CoreStatusRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp -noinst_HEADERS = CoreStatusRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h +librequesthandlers_la_SOURCES = CoreStatusRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp +noinst_HEADERS = CoreStatusRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h all: all-am .SUFFIXES: @@ -240,6 +240,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)/DaemonListRequestHandler.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@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/IdentifyRequestHandler.Plo@am__quote@ |