diff options
Diffstat (limited to 'src/Server')
20 files changed, 267 insertions, 303 deletions
diff --git a/src/Server/RequestHandlers/IdentifyRequestHandler.cpp b/src/Server/Application.cpp index e48563b..3414e53 100644 --- a/src/Server/RequestHandlers/IdentifyRequestHandler.cpp +++ b/src/Server/Application.cpp @@ -1,7 +1,7 @@ /* - * IdentifyRequestHandler.cpp + * Application.cpp * - * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * Copyright (C) 2009 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 @@ -17,23 +17,22 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "IdentifyRequestHandler.h" -#include "../ConnectionManager.h" - +#include "Application.h" +#include "ConnectionManager.h" +#include "UserManager.h" namespace Mad { namespace Server { -namespace RequestHandlers { -void IdentifyRequestHandler::handleRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret) { - if((*packet)["hostname"].isEmpty()) - ConnectionManager::get()->identifyClientConnection(getConnection()); - else - ConnectionManager::get()->identifyDaemonConnection(getConnection(), (*packet)["hostname"]); +Application::Application() : Common::Application(true), connectionManager(new ConnectionManager(this)), +userManager(new UserManager) { - ret->setType("OK"); } +Application::~Application() { + delete userManager; + delete connectionManager; } + } } diff --git a/src/Server/RequestHandlers/LogRequestHandler.h b/src/Server/Application.h index cf1ce34..b62893b 100644 --- a/src/Server/RequestHandlers/LogRequestHandler.h +++ b/src/Server/Application.h @@ -1,7 +1,7 @@ /* - * LogRequestHandler.h + * Application.h * - * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * Copyright (C) 2009 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 @@ -17,25 +17,36 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef MAD_SERVER_REQUESTHANDLERS_LOGREQUESTHANDLER_H_ -#define MAD_SERVER_REQUESTHANDLERS_LOGREQUESTHANDLER_H_ +#ifndef MAD_SERVER_APPLICATION_H_ +#define MAD_SERVER_APPLICATION_H_ -#include <Common/RequestHandlers/SimpleRequestHandler.h> +#include <Common/Application.h> namespace Mad { namespace Server { -namespace RequestHandlers { -class LogRequestHandler : public Common::RequestHandlers::SimpleRequestHandler { +class ConnectionManager; +class UserManager; + +class Application : public Common::Application { private: - void handleRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret); + ConnectionManager *connectionManager; + UserManager *userManager; public: - LogRequestHandler() : Common::RequestHandlers::SimpleRequestHandler("Log", boost::bind(&LogRequestHandler::handleRequest, this, _1, _2)) {} + Application(); + virtual ~Application(); + + ConnectionManager* getConnectionManager() const { + return connectionManager; + } + + UserManager* getUserManager() const { + return userManager; + } }; } } -} -#endif /* MAD_SERVER_REQUESTHANDLERS_LOGREQUESTHANDLER_H_ */ +#endif /* MAD_SERVER_APPLICATION_H_ */ diff --git a/src/Server/CMakeLists.txt b/src/Server/CMakeLists.txt index e38d860..b609de3 100644 --- a/src/Server/CMakeLists.txt +++ b/src/Server/CMakeLists.txt @@ -4,6 +4,7 @@ add_subdirectory(Requests) include_directories(${INCLUDES}) add_library(Server + Application.cpp Application.h ConnectionManager.cpp ConnectionManager.h UserBackend.h UserManager.cpp UserManager.h diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp index a15a516..bbf7ab1 100644 --- a/src/Server/ConnectionManager.cpp +++ b/src/Server/ConnectionManager.cpp @@ -18,16 +18,15 @@ */ #include "ConnectionManager.h" +#include "Application.h" #include <Core/ConfigEntry.h> #include <Core/ConfigManager.h> -#include <Core/Logger.h> +#include <Common/RequestManager.h> #include <Common/RequestHandlers/FSInfoRequestHandler.h> #include <Common/RequestHandlers/StatusRequestHandler.h> #include "Requests/DaemonStateUpdateRequest.h" -#include "RequestHandlers/DaemonListRequestHandler.h" //#include "RequestHandlers/GSSAPIAuthRequestHandler.h" -#include "RequestHandlers/IdentifyRequestHandler.h" -#include "RequestHandlers/LogRequestHandler.h" +#include "RequestHandlers/ConnectionRequestHandlerGroup.h" #include "RequestHandlers/DaemonRequestHandlerGroup.h" #include "RequestHandlers/UserRequestHandlerGroup.h" #include <Net/Packet.h> @@ -39,14 +38,12 @@ namespace Mad { namespace Server { -ConnectionManager ConnectionManager::connectionManager; - bool ConnectionManager::ServerConnection::send(const Net::Packet &packet) { return connection->send(packet); } -ConnectionManager::ServerConnection::ServerConnection(boost::shared_ptr<Net::Connection> connection0) -: connection(connection0), type(UNKNOWN), hostInfo(0) { +ConnectionManager::ServerConnection::ServerConnection(Core::Application *application, boost::shared_ptr<Net::Connection> connection0) +: Common::Connection(application), connection(connection0), type(UNKNOWN), hostInfo(0) { connection->connectSignalReceive(boost::bind(&ServerConnection::receive, this, _1)); } @@ -80,8 +77,8 @@ void ConnectionManager::updateState(Common::HostInfo *hostInfo, Common::HostInfo for(std::set<boost::shared_ptr<ServerConnection> >::iterator con = connections.begin(); con != connections.end(); ++con) { if((*con)->getConnectionType() == ServerConnection::CLIENT) { - boost::shared_ptr<Requests::DaemonStateUpdateRequest> request(new Requests::DaemonStateUpdateRequest(hostInfo->getName(), state)); - Common::RequestManager::get()->sendRequest(con->get(), request); + boost::shared_ptr<Requests::DaemonStateUpdateRequest> request(new Requests::DaemonStateUpdateRequest(application, hostInfo->getName(), state)); + application->getRequestManager()->sendRequest(con->get(), request); } } } @@ -141,7 +138,7 @@ bool ConnectionManager::handleConfigEntry(const Core::ConfigEntry &entry, bool h void ConnectionManager::configFinished() { if(listenerAddresses.empty()) { try { - boost::shared_ptr<Net::Listener> listener(new Net::Listener(x509CertFile, x509KeyFile)); + boost::shared_ptr<Net::Listener> listener(new Net::Listener(application, x509CertFile, x509KeyFile)); listener->connectSignalNewConnection(boost::bind(&ConnectionManager::handleNewConnection, this, _1)); listeners.push_back(listener); } @@ -152,7 +149,7 @@ void ConnectionManager::configFinished() { else { for(std::vector<boost::asio::ip::tcp::endpoint>::const_iterator address = listenerAddresses.begin(); address != listenerAddresses.end(); ++address) { try { - boost::shared_ptr<Net::Listener> listener(new Net::Listener(x509CertFile, x509KeyFile, *address)); + boost::shared_ptr<Net::Listener> listener(new Net::Listener(application, x509CertFile, x509KeyFile, *address)); listener->connectSignalNewConnection(boost::bind(&ConnectionManager::handleNewConnection, this, _1)); listeners.push_back(listener); } @@ -164,11 +161,11 @@ void ConnectionManager::configFinished() { } void ConnectionManager::handleNewConnection(boost::shared_ptr<Net::Connection> con) { - boost::shared_ptr<ServerConnection> connection(new ServerConnection(con)); + boost::shared_ptr<ServerConnection> connection(new ServerConnection(application, con)); con->connectSignalDisconnected(boost::bind(&ConnectionManager::handleDisconnect, this, connection)); connections.insert(connection); - Common::RequestManager::get()->registerConnection(connection.get()); + application->getRequestManager()->registerConnection(connection.get()); } void ConnectionManager::handleDisconnect(boost::shared_ptr<ServerConnection> con) { @@ -177,44 +174,36 @@ void ConnectionManager::handleDisconnect(boost::shared_ptr<ServerConnection> con connections.erase(con); - Common::RequestManager::get()->unregisterConnection(con.get()); + application->getRequestManager()->unregisterConnection(con.get()); } -void ConnectionManager::doInit() { - Common::RequestManager::get()->setServer(true); - - daemonRequestHandlerGroup.reset(new RequestHandlers::DaemonRequestHandlerGroup); - userRequestHandlerGroup.reset(new RequestHandlers::UserRequestHandlerGroup); +ConnectionManager::ConnectionManager(Application *application0) : application(application0), +connectionRequestHandlerGroup(new RequestHandlers::ConnectionRequestHandlerGroup(application)), +daemonRequestHandlerGroup(new RequestHandlers::DaemonRequestHandlerGroup), +userRequestHandlerGroup(new RequestHandlers::UserRequestHandlerGroup(application)) { + //requestManager->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>("AuthGSSAPI"); + application->getRequestManager()->registerPacketType<Common::RequestHandlers::FSInfoRequestHandler>("FSInfo"); + application->getRequestManager()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>("GetStatus"); - //Common::RequestManager::get()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>("AuthGSSAPI"); - //Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>("DaemonCommand"); - //Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonFSInfoRequestHandler>("DaemonFSInfo"); - Common::RequestManager::get()->registerPacketType<Common::RequestHandlers::FSInfoRequestHandler>("FSInfo"); - Common::RequestManager::get()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>("GetStatus"); - //Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>("GetDaemonStatus"); - Common::RequestManager::get()->registerPacketType<RequestHandlers::IdentifyRequestHandler>("Identify"); - Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonListRequestHandler>("ListHosts"); - Common::RequestManager::get()->registerPacketType<RequestHandlers::LogRequestHandler>("Log"); + application->getRequestManager()->registerRequestHandlerGroup(connectionRequestHandlerGroup); + application->getRequestManager()->registerRequestHandlerGroup(daemonRequestHandlerGroup); + application->getRequestManager()->registerRequestHandlerGroup(userRequestHandlerGroup); - Common::RequestManager::get()->registerRequestHandlerGroup(daemonRequestHandlerGroup); - Common::RequestManager::get()->registerRequestHandlerGroup(userRequestHandlerGroup); + application->getConfigManager()->registerConfigurable(this); } -void ConnectionManager::doDeinit() { +ConnectionManager::~ConnectionManager() { + application->getConfigManager()->unregisterConfigurable(this); + connections.clear(); - Common::RequestManager::get()->unregisterRequestHandlerGroup(userRequestHandlerGroup); - Common::RequestManager::get()->unregisterRequestHandlerGroup(daemonRequestHandlerGroup); - - //Common::RequestManager::get()->unregisterPacketType("AuthGSSAPI"); - //Common::RequestManager::get()->unregisterPacketType("DaemonCommand"); - //Common::RequestManager::get()->unregisterPacketType("DaemonFSInfo"); - Common::RequestManager::get()->unregisterPacketType("FSInfo"); - Common::RequestManager::get()->unregisterPacketType("GetStatus"); - //Common::RequestManager::get()->unregisterPacketType("GetDaemonStatus"); - Common::RequestManager::get()->unregisterPacketType("Identify"); - Common::RequestManager::get()->unregisterPacketType("ListHosts"); - Common::RequestManager::get()->unregisterPacketType("Log"); + application->getRequestManager()->unregisterRequestHandlerGroup(userRequestHandlerGroup); + application->getRequestManager()->unregisterRequestHandlerGroup(daemonRequestHandlerGroup); + application->getRequestManager()->unregisterRequestHandlerGroup(connectionRequestHandlerGroup); + + //requestManager->unregisterPacketType("AuthGSSAPI"); + application->getRequestManager()->unregisterPacketType("FSInfo"); + application->getRequestManager()->unregisterPacketType("GetStatus"); } boost::shared_ptr<Common::Connection> ConnectionManager::getDaemonConnection(const std::string &name) const throw (Core::Exception&) { @@ -266,7 +255,7 @@ void ConnectionManager::identifyDaemonConnection(Common::Connection *con, const if(hostInfo->getState() != Common::HostInfo::INACTIVE) { try { getDaemonConnection(name)->disconnect(); - Core::Logger::log(Core::Logger::WARNING, "Disconnecting old connection."); + application->log(Core::LoggerBase::WARNING, "Disconnecting old connection."); } catch(Core::Exception&) {} } @@ -274,7 +263,7 @@ void ConnectionManager::identifyDaemonConnection(Common::Connection *con, const connection->identify(hostInfo); updateState(hostInfo, Common::HostInfo::RUNNING); - Core::Logger::logf("Identified as '%s'.", name.c_str()); + application->logf("Identified as '%s'.", name.c_str()); } void ConnectionManager::identifyClientConnection(Common::Connection *con) throw (Core::Exception&) { diff --git a/src/Server/ConnectionManager.h b/src/Server/ConnectionManager.h index 4cc12a5..b8f77f1 100644 --- a/src/Server/ConnectionManager.h +++ b/src/Server/ConnectionManager.h @@ -21,9 +21,10 @@ #define MAD_SERVER_CONNECTIONMANAGER_H_ #include <Core/Configurable.h> -#include <Core/Initializable.h> +#include <Core/Exception.h> +#include <Common/Connection.h> #include <Common/HostInfo.h> -#include <Common/RequestManager.h> +#include <Common/RequestHandlerGroup.h> #include <list> #include <vector> @@ -42,7 +43,9 @@ class Packet; namespace Server { -class ConnectionManager : public Core::Configurable, public Core::Initializable, boost::noncopyable { +class Application; + +class ConnectionManager : public Core::Configurable, private boost::noncopyable { private: class ServerConnection : public Common::Connection { public: @@ -59,7 +62,7 @@ class ConnectionManager : public Core::Configurable, public Core::Initializable, virtual bool send(const Net::Packet &packet); public: - ServerConnection(boost::shared_ptr<Net::Connection> connection0); + ServerConnection(Core::Application *application, boost::shared_ptr<Net::Connection> connection0); bool isConnected() const; @@ -89,7 +92,9 @@ class ConnectionManager : public Core::Configurable, public Core::Initializable, } }; - static ConnectionManager connectionManager; + friend class Application; + + Application *application; std::string x509TrustFile, x509CrlFile, x509CertFile, x509KeyFile; @@ -100,28 +105,23 @@ class ConnectionManager : public Core::Configurable, public Core::Initializable, std::map<std::string,Common::HostInfo> daemonInfo; + boost::shared_ptr<Common::RequestHandlerGroup> connectionRequestHandlerGroup; boost::shared_ptr<Common::RequestHandlerGroup> daemonRequestHandlerGroup; boost::shared_ptr<Common::RequestHandlerGroup> userRequestHandlerGroup; void updateState(Common::HostInfo *hostInfo, Common::HostInfo::State state); - ConnectionManager() {} - void handleNewConnection(boost::shared_ptr<Net::Connection> con); void handleDisconnect(boost::shared_ptr<ServerConnection> con); + ConnectionManager(Application *application0); + ~ConnectionManager(); + protected: virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool handled); virtual void configFinished(); - virtual void doInit(); - virtual void doDeinit(); - public: - static ConnectionManager* get() { - return &connectionManager; - } - boost::shared_ptr<Common::Connection> getDaemonConnection(const std::string &name) const throw (Core::Exception&); std::string getDaemonName(const Common::Connection *con) const throw (Core::Exception&); diff --git a/src/Server/RequestHandlers/CMakeLists.txt b/src/Server/RequestHandlers/CMakeLists.txt index 9b9b9ea..065a85d 100644 --- a/src/Server/RequestHandlers/CMakeLists.txt +++ b/src/Server/RequestHandlers/CMakeLists.txt @@ -1,10 +1,8 @@ include_directories(${INCLUDES}) add_library(ServerRequestHandlers STATIC - DaemonListRequestHandler.cpp DaemonListRequestHandler.h + ConnectionRequestHandlerGroup.cpp ConnectionRequestHandlerGroup.h DaemonRequestHandlerGroup.cpp DaemonRequestHandlerGroup.h - IdentifyRequestHandler.cpp IdentifyRequestHandler.h - LogRequestHandler.cpp LogRequestHandler.h UserRequestHandlerGroup.cpp UserRequestHandlerGroup.h ) target_link_libraries(ServerRequestHandlers Server ${KRB5_LIBRARIES}) diff --git a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp new file mode 100644 index 0000000..3af5439 --- /dev/null +++ b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp @@ -0,0 +1,79 @@ +/* + * ConnectionRequestHandlerGroup.cpp + * + * Copyright (C) 2009 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 "ConnectionRequestHandlerGroup.h" +#include "../Application.h" +#include "../ConnectionManager.h" + +#include <Core/LogManager.h> + +namespace Mad { +namespace Server { +namespace RequestHandlers { + +void ConnectionRequestHandlerGroup::handleDaemonListRequest(boost::shared_ptr<const Common::XmlPacket> packet _UNUSED_PARAMETER_, Common::XmlPacket *ret, + Common::Connection *connection _UNUSED_PARAMETER_) { + // TODO Require authentication + + ret->setType("OK"); + ret->addList("hosts"); + + std::vector<Common::HostInfo> daemons = application->getConnectionManager()->getDaemonList(); + + for(std::vector<Common::HostInfo>::iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon) { + (*ret)["hosts"].addEntry(); + + (*ret)["hosts"].back().add("name", daemon->getName()); + (*ret)["hosts"].back().add("address", daemon->getIP()); + (*ret)["hosts"].back().add("state", daemon->getState()); + } +} + +void ConnectionRequestHandlerGroup::handleIdentifyRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection) { + if((*packet)["hostname"].isEmpty()) + application->getConnectionManager()->identifyClientConnection(connection); + else + application->getConnectionManager()->identifyDaemonConnection(connection, (*packet)["hostname"]); + + ret->setType("OK"); +} + +void ConnectionRequestHandlerGroup::handleLogRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection) { + // TODO Require authentication + + try { + application->getLogManager()->log((*packet)["category"], (*packet)["level"], (*packet)["timestamp"], (*packet)["message"], + application->getConnectionManager()->getDaemonName(connection)); + } + catch(Core::Exception &e) { + application->logf(Core::LoggerBase::ERROR, "Can't determine daemon name: %s", e.strerror().c_str()); + } + + ret->setType("OK"); +} + +ConnectionRequestHandlerGroup::ConnectionRequestHandlerGroup(Application *application0) : application(application0) { + registerHandler("ListHosts", boost::bind(&ConnectionRequestHandlerGroup::handleDaemonListRequest, this, _1, _2, _3)); + registerHandler("Identify", boost::bind(&ConnectionRequestHandlerGroup::handleIdentifyRequest, this, _1, _2, _3)); + registerHandler("Log", boost::bind(&ConnectionRequestHandlerGroup::handleLogRequest, this, _1, _2, _3)); +} + +} +} +} diff --git a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h new file mode 100644 index 0000000..6efa021 --- /dev/null +++ b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h @@ -0,0 +1,48 @@ +/* + * ConnectionRequestHandlerGroup.h + * + * Copyright (C) 2009 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_SERVER_REQUESTHANDLERS_CONNECTIONREQUESTHANDLERGROUP_H_ +#define MAD_SERVER_REQUESTHANDLERS_CONNECTIONREQUESTHANDLERGROUP_H_ + +#include <Common/RequestHandlers/SimpleRequestHandlerGroup.h> + +namespace Mad { +namespace Server { + +class Application; + +namespace RequestHandlers { + +class ConnectionRequestHandlerGroup : public Common::RequestHandlers::SimpleRequestHandlerGroup { + private: + Application *application; + + void handleDaemonListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleIdentifyRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleLogRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection); + + public: + ConnectionRequestHandlerGroup(Application *application0); +}; + +} +} +} + +#endif /* MAD_SERVER_REQUESTHANDLERS_CONNECTIONREQUESTHANDLERGROUP_H_ */ diff --git a/src/Server/RequestHandlers/DaemonListRequestHandler.cpp b/src/Server/RequestHandlers/DaemonListRequestHandler.cpp deleted file mode 100644 index fc6900c..0000000 --- a/src/Server/RequestHandlers/DaemonListRequestHandler.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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" - -namespace Mad { -namespace Server { -namespace RequestHandlers { - -void DaemonListRequestHandler::handleRequest(boost::shared_ptr<const Common::XmlPacket> packet _UNUSED_PARAMETER_, Common::XmlPacket *ret) { - // TODO Require authentication - - ret->setType("OK"); - ret->addList("hosts"); - - std::vector<Common::HostInfo> daemons = ConnectionManager::get()->getDaemonList(); - - for(std::vector<Common::HostInfo>::iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon) { - (*ret)["hosts"].addEntry(); - - (*ret)["hosts"].back().add("name", daemon->getName()); - (*ret)["hosts"].back().add("address", daemon->getIP()); - (*ret)["hosts"].back().add("state", daemon->getState()); - } -} - -} -} -} diff --git a/src/Server/RequestHandlers/DaemonListRequestHandler.h b/src/Server/RequestHandlers/DaemonListRequestHandler.h deleted file mode 100644 index 45eebc8..0000000 --- a/src/Server/RequestHandlers/DaemonListRequestHandler.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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_SERVER_REQUESTHANDLERS_DAEMONLISTREQUESTHANDLER_H_ -#define MAD_SERVER_REQUESTHANDLERS_DAEMONLISTREQUESTHANDLER_H_ - -#include <Common/RequestHandlers/SimpleRequestHandler.h> - -namespace Mad { -namespace Server { -namespace RequestHandlers { - -class DaemonListRequestHandler : public Common::RequestHandlers::SimpleRequestHandler { - private: - static void handleRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret); - - public: - DaemonListRequestHandler() : Common::RequestHandlers::SimpleRequestHandler("ListHosts", &DaemonListRequestHandler::handleRequest) {} -}; - -} -} -} - -#endif /* MAD_SERVER_REQUESTHANDLERS_DAEMONLISTREQUESTHANDLER_H_ */ diff --git a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp index 0e21fdd..344cf4c 100644 --- a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp @@ -18,10 +18,11 @@ */ #include "DaemonRequestHandlerGroup.h" +#include "../Application.h" #include "../ConnectionManager.h" #include "../Requests/CommandRequest.h" -#include <Core/Logger.h> +#include <Common/RequestManager.h> #include <Common/Requests/FSInfoRequest.h> #include <Common/Requests/StatusRequest.h> @@ -31,7 +32,7 @@ namespace RequestHandlers { void DaemonRequestHandlerGroup::DaemonRequestHandler::handlePacket(boost::shared_ptr<const Common::XmlPacket> packet) { if(packet->getType() != type) { - Core::Logger::log(Core::Logger::ERROR, "Received an unexpected packet."); + getApplication()->log(Core::LoggerBase::ERROR, "Received an unexpected packet."); Common::XmlPacket ret; ret.setType("Error"); @@ -46,18 +47,18 @@ void DaemonRequestHandlerGroup::DaemonRequestHandler::handlePacket(boost::shared // TODO Require authentication try { - boost::shared_ptr<Common::Connection> daemonCon = ConnectionManager::get()->getDaemonConnection((*packet)["daemon"]); + boost::shared_ptr<Common::Connection> daemonCon = dynamic_cast<Application&>(*getApplication()).getConnectionManager()->getDaemonConnection((*packet)["daemon"]); boost::shared_ptr<Common::Request> request; if(type == "DaemonCommand") - request.reset(new Requests::CommandRequest((std::string&)((*packet)["command"]) == "reboot")); + request.reset(new Requests::CommandRequest(getApplication(), (std::string&)((*packet)["command"]) == "reboot")); else if(type == "DaemonFSInfo") - request.reset(new Common::Requests::FSInfoRequest); + request.reset(new Common::Requests::FSInfoRequest(getApplication())); else // type == "GetDaemonStatus" - request.reset(new Common::Requests::StatusRequest); + request.reset(new Common::Requests::StatusRequest(getApplication())); request->connectSignalFinished(boost::bind(&DaemonRequestHandlerGroup::DaemonRequestHandler::requestFinished, this, _1, _2)); - Common::RequestManager::get()->sendRequest(daemonCon.get(), request); + getRequestManager()->sendRequest(daemonCon.get(), request); } catch(Core::Exception &e) { Common::XmlPacket ret; @@ -97,11 +98,11 @@ DaemonRequestHandlerGroup::DaemonRequestHandlerGroup() { types.insert("GetDaemonStatus"); } -boost::shared_ptr<Common::RequestHandler> DaemonRequestHandlerGroup::createRequestHandler(const std::string &type) { +boost::shared_ptr<Common::RequestHandler> DaemonRequestHandlerGroup::createRequestHandler(Common::Application *application, const std::string &type) { if(types.find(type) == types.end()) return boost::shared_ptr<Common::RequestHandler>(); else - return boost::shared_ptr<DaemonRequestHandler>(new DaemonRequestHandler(type)); + return boost::shared_ptr<DaemonRequestHandler>(new DaemonRequestHandler(application, type)); } } diff --git a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h index 7a709f4..524baac 100644 --- a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h +++ b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h @@ -25,6 +25,8 @@ namespace Mad { namespace Server { +class ConnectionManager; + namespace RequestHandlers { class DaemonRequestHandlerGroup : public Common::RequestHandlerGroup { @@ -39,9 +41,12 @@ class DaemonRequestHandlerGroup : public Common::RequestHandlerGroup { virtual void handlePacket(boost::shared_ptr<const Common::XmlPacket> packet); public: - DaemonRequestHandler(const std::string &type0) : type(type0) {} + DaemonRequestHandler(Common::Application *application, const std::string &type0) + : Common::RequestHandler(application), type(type0) {} }; + ConnectionManager *connectionManager; + std::set<std::string> types; public: @@ -51,7 +56,7 @@ class DaemonRequestHandlerGroup : public Common::RequestHandlerGroup { return types; } - virtual boost::shared_ptr<Common::RequestHandler> createRequestHandler(const std::string &type); + virtual boost::shared_ptr<Common::RequestHandler> createRequestHandler(Common::Application *application, const std::string &type); }; } diff --git a/src/Server/RequestHandlers/IdentifyRequestHandler.h b/src/Server/RequestHandlers/IdentifyRequestHandler.h deleted file mode 100644 index d9954a3..0000000 --- a/src/Server/RequestHandlers/IdentifyRequestHandler.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * IdentifyRequestHandler.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_SERVER_REQUESTHANDLERS_IDENTIFYREQUESTHANDLER_H_ -#define MAD_SERVER_REQUESTHANDLERS_IDENTIFYREQUESTHANDLER_H_ - -#include <Common/RequestHandlers/SimpleRequestHandler.h> - -namespace Mad { -namespace Server { -namespace RequestHandlers { - -class IdentifyRequestHandler : public Common::RequestHandlers::SimpleRequestHandler { - private: - void handleRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret); - - public: - IdentifyRequestHandler() : Common::RequestHandlers::SimpleRequestHandler("Identify", boost::bind(&IdentifyRequestHandler::handleRequest, this, _1, _2)) {} -}; - -} -} -} - -#endif /* MAD_SERVER_REQUESTHANDLERS_IDENTIFYREQUESTHANDLER_H_ */ diff --git a/src/Server/RequestHandlers/LogRequestHandler.cpp b/src/Server/RequestHandlers/LogRequestHandler.cpp deleted file mode 100644 index f33aad4..0000000 --- a/src/Server/RequestHandlers/LogRequestHandler.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * LogRequestHandler.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 "LogRequestHandler.h" -#include <Core/LogManager.h> -#include "../ConnectionManager.h" - -namespace Mad { -namespace Server { -namespace RequestHandlers { - -void LogRequestHandler::handleRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret) { - // TODO Require authentication - - try { - Core::LogManager::get()->log((*packet)["category"], (*packet)["level"], (*packet)["timestamp"], (*packet)["message"], - ConnectionManager::get()->getDaemonName(getConnection())); - } - catch(Core::Exception &e) { - Core::Logger::logf(Core::Logger::ERROR, "Can't determine daemon name: %s", e.strerror().c_str()); - } - - ret->setType("OK"); -} - -} -} -} diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp index 7836c34..3aaa576 100644 --- a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp @@ -18,14 +18,16 @@ */ #include "UserRequestHandlerGroup.h" +#include "../Application.h" #include "../UserManager.h" namespace Mad { namespace Server { namespace RequestHandlers { -void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet _UNUSED_PARAMETER_, Common::XmlPacket *ret) { - boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > info = UserManager::get()->getUserList(); +void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet _UNUSED_PARAMETER_, Common::XmlPacket *ret, + Common::Connection *connection _UNUSED_PARAMETER_) { + boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > info = application->getUserManager()->getUserList(); ret->setType("OK"); ret->addList("users"); @@ -41,8 +43,9 @@ void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr<const Comm } } -void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret) { - boost::shared_ptr<Common::UserInfo> info = UserManager::get()->getUserInfo((*packet)["uid"]); +void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, + Common::Connection *connection _UNUSED_PARAMETER_) { + boost::shared_ptr<Common::UserInfo> info = application->getUserManager()->getUserInfo((*packet)["uid"]); ret->setType("OK"); @@ -52,8 +55,9 @@ void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr<const Comm ret->add("fullName", info->getFullName()); } -void UserRequestHandlerGroup::handleUserGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret) { - boost::shared_ptr<std::set<unsigned long> > groups = UserManager::get()->getUserGroupList((unsigned long)(*packet)["uid"]); +void UserRequestHandlerGroup::handleUserGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, + Common::Connection *connection _UNUSED_PARAMETER_) { + boost::shared_ptr<std::set<unsigned long> > groups = application->getUserManager()->getUserGroupList((unsigned long)(*packet)["uid"]); ret->setType("OK"); ret->addList("groups"); @@ -66,8 +70,9 @@ void UserRequestHandlerGroup::handleUserGroupListRequest(boost::shared_ptr<const } } -void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet _UNUSED_PARAMETER_, Common::XmlPacket *ret) { - boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > info = UserManager::get()->getGroupList(); +void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet _UNUSED_PARAMETER_, Common::XmlPacket *ret, + Common::Connection *connection _UNUSED_PARAMETER_) { + boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > info = application->getUserManager()->getGroupList(); ret->setType("OK"); ret->addList("groups"); @@ -81,8 +86,9 @@ void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr<const Com } } -void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret) { - boost::shared_ptr<std::set<unsigned long> > users = UserManager::get()->getGroupUserList((unsigned long)(*packet)["gid"]); +void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, + Common::Connection *connection _UNUSED_PARAMETER_) { + boost::shared_ptr<std::set<unsigned long> > users = application->getUserManager()->getGroupUserList((unsigned long)(*packet)["gid"]); ret->setType("OK"); ret->addList("users"); @@ -95,12 +101,12 @@ void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptr<const } } -UserRequestHandlerGroup::UserRequestHandlerGroup() { - registerHandler("ListUsers", &UserRequestHandlerGroup::handleUserListRequest); - registerHandler("GetUserInfo", &UserRequestHandlerGroup::handleUserInfoRequest); - registerHandler("ListUserGroups", &UserRequestHandlerGroup::handleUserGroupListRequest); - registerHandler("ListGroups", &UserRequestHandlerGroup::handleGroupListRequest); - registerHandler("ListGroupUsers", &UserRequestHandlerGroup::handleGroupUserListRequest); +UserRequestHandlerGroup::UserRequestHandlerGroup(Application *application0) : application(application0) { + registerHandler("ListUsers", boost::bind(&UserRequestHandlerGroup::handleUserListRequest, this, _1, _2, _3)); + registerHandler("GetUserInfo", boost::bind(&UserRequestHandlerGroup::handleUserInfoRequest, this, _1, _2, _3)); + registerHandler("ListUserGroups", boost::bind(&UserRequestHandlerGroup::handleUserGroupListRequest, this, _1, _2, _3)); + registerHandler("ListGroups", boost::bind(&UserRequestHandlerGroup::handleGroupListRequest, this, _1, _2, _3)); + registerHandler("ListGroupUsers", boost::bind(&UserRequestHandlerGroup::handleGroupUserListRequest, this, _1, _2, _3)); } } diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.h b/src/Server/RequestHandlers/UserRequestHandlerGroup.h index 52965dd..2a17a9a 100644 --- a/src/Server/RequestHandlers/UserRequestHandlerGroup.h +++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.h @@ -24,18 +24,23 @@ namespace Mad { namespace Server { + +class Application; + namespace RequestHandlers { class UserRequestHandlerGroup : public Common::RequestHandlers::SimpleRequestHandlerGroup { private: - static void handleUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret); - static void handleUserInfoRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret); - static void handleUserGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret); - static void handleGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret); - static void handleGroupUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret); + Application *application; + + void handleUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleUserInfoRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleUserGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection); + void handleGroupUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection); public: - UserRequestHandlerGroup(); + UserRequestHandlerGroup(Application *application0); }; } diff --git a/src/Server/Requests/CommandRequest.h b/src/Server/Requests/CommandRequest.h index 8221b14..3b2dcdd 100644 --- a/src/Server/Requests/CommandRequest.h +++ b/src/Server/Requests/CommandRequest.h @@ -34,7 +34,7 @@ class CommandRequest : public Common::Request { virtual void sendRequest(); public: - CommandRequest(bool reboot0) : reboot(reboot0) {} + CommandRequest(Common::Application *application, bool reboot0) : Common::Request(application), reboot(reboot0) {} }; } diff --git a/src/Server/Requests/DaemonStateUpdateRequest.h b/src/Server/Requests/DaemonStateUpdateRequest.h index c3ed792..762514a 100644 --- a/src/Server/Requests/DaemonStateUpdateRequest.h +++ b/src/Server/Requests/DaemonStateUpdateRequest.h @@ -36,8 +36,8 @@ class DaemonStateUpdateRequest : public Common::Request { virtual void sendRequest(); public: - DaemonStateUpdateRequest(const std::string &name0, Common::HostInfo::State state0) - : name(name0), state(state0) {} + DaemonStateUpdateRequest(Common::Application *application, const std::string &name0, Common::HostInfo::State state0) + : Common::Request(application), name(name0), state(state0) {} }; } diff --git a/src/Server/UserManager.cpp b/src/Server/UserManager.cpp index 0c45b78..243457c 100644 --- a/src/Server/UserManager.cpp +++ b/src/Server/UserManager.cpp @@ -23,9 +23,6 @@ namespace Mad { namespace Server { -UserManager UserManager::userManager; - - bool UserManager::Compare::operator() (boost::shared_ptr<UserBackend> b1, boost::shared_ptr<UserBackend> b2) { if(b1->getPriority() == b2->getPriority()) return (b1.get() > b2.get()); diff --git a/src/Server/UserManager.h b/src/Server/UserManager.h index 31f50d5..6d3c034 100644 --- a/src/Server/UserManager.h +++ b/src/Server/UserManager.h @@ -34,16 +34,17 @@ namespace Mad { namespace Server { +class Application; class UserBackend; class UserManager : boost::noncopyable { private: + friend class Application; + struct Compare { bool operator() (boost::shared_ptr<UserBackend> b1, boost::shared_ptr<UserBackend> b2); }; - static UserManager userManager; - std::set<boost::shared_ptr<UserBackend>, Compare> backends; UserManager() {} @@ -70,10 +71,6 @@ class UserManager : boost::noncopyable { void setPassword(unsigned long uid, const std::string &password) throw(Core::Exception); void addUser(const Common::UserInfo &userInfo) throw(Core::Exception); - - static UserManager *get() { - return &userManager; - } }; } |