diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-02-24 22:03:34 +0100 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-02-24 22:03:34 +0100 |
commit | f85b6d5ab264910f272e69ce5997cebec54886ce (patch) | |
tree | 06b801d5b11c2d8a2dfae16b698ebaf0b74f429b /src/Core | |
parent | 8d629ca48e9b5530416127e2e52c945fe1f9ee52 (diff) | |
download | mad-f85b6d5ab264910f272e69ce5997cebec54886ce.tar mad-f85b6d5ab264910f272e69ce5997cebec54886ce.zip |
Requests Status, DaemonStatus und UserList in XmlRequests umgewandelt
Diffstat (limited to 'src/Core')
-rw-r--r-- | src/Core/ConnectionManager.cpp | 13 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp | 43 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonStatusRequestHandler.h | 12 | ||||
-rw-r--r-- | src/Core/RequestHandlers/UserListRequestHandler.cpp | 40 | ||||
-rw-r--r-- | src/Core/RequestHandlers/UserListRequestHandler.h | 8 |
5 files changed, 77 insertions, 39 deletions
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index fde7e62..6362314 100644 --- a/src/Core/ConnectionManager.cpp +++ b/src/Core/ConnectionManager.cpp @@ -136,16 +136,17 @@ void ConnectionManager::doInit() { Net::Connection::init(); Common::RequestManager::get()->registerPacketType<Common::RequestHandlers::FSInfoRequestHandler>(Net::Packet::FS_INFO); - Common::RequestManager::get()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>(Net::Packet::STATUS); Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_REBOOT); Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_SHUTDOWN); Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonFSInfoRequestHandler>(Net::Packet::DAEMON_FS_INFO); Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonListRequestHandler>(Net::Packet::LIST_DAEMONS); - Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>(Net::Packet::DAEMON_STATUS); Common::RequestManager::get()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH); Common::RequestManager::get()->registerPacketType<RequestHandlers::IdentifyRequestHandler>(Net::Packet::IDENTIFY); Common::RequestManager::get()->registerPacketType<RequestHandlers::LogRequestHandler>(Net::Packet::LOG); - Common::RequestManager::get()->registerPacketType<RequestHandlers::UserListRequestHandler>(Net::Packet::USERS_LIST); + + Common::RequestManager::get()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>("GetStatus"); + Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>("GetDaemonStatus"); + Common::RequestManager::get()->registerPacketType<RequestHandlers::UserListRequestHandler>("ListUsers"); } void ConnectionManager::doDeinit() { @@ -156,16 +157,18 @@ void ConnectionManager::doDeinit() { delete *con; Common::RequestManager::get()->unregisterPacketType(Net::Packet::FS_INFO); - Common::RequestManager::get()->unregisterPacketType(Net::Packet::STATUS); Common::RequestManager::get()->unregisterPacketType(Net::Packet::DAEMON_COMMAND_REBOOT); Common::RequestManager::get()->unregisterPacketType(Net::Packet::DAEMON_COMMAND_SHUTDOWN); Common::RequestManager::get()->unregisterPacketType(Net::Packet::DAEMON_FS_INFO); Common::RequestManager::get()->unregisterPacketType(Net::Packet::LIST_DAEMONS); - Common::RequestManager::get()->unregisterPacketType(Net::Packet::DAEMON_STATUS); Common::RequestManager::get()->unregisterPacketType(Net::Packet::GSSAPI_AUTH); Common::RequestManager::get()->unregisterPacketType(Net::Packet::IDENTIFY); Common::RequestManager::get()->unregisterPacketType(Net::Packet::LOG); + Common::RequestManager::get()->unregisterPacketType("GetStatus"); + Common::RequestManager::get()->unregisterPacketType("GetDaemonStatus"); + Common::RequestManager::get()->unregisterPacketType("ListUsers"); + Net::Connection::deinit(); } diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp index 80b61ba..a1dfdee 100644 --- a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp +++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp @@ -21,18 +21,21 @@ #include "../ConnectionManager.h" #include <Common/Logger.h> #include <Common/Requests/StatusRequest.h> -#include <Net/Packets/ErrorPacket.h> -#include <Net/Packets/HostStatusPacket.h> namespace Mad { namespace Core { namespace RequestHandlers { -void DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(packet.getType() != Net::Packet::DAEMON_STATUS) { +void DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) { + if(packet.getType() != "GetDaemonStatus") { Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); - connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + + Common::XmlPacket ret; + ret.setType("Error"); + ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET); + + con->send(ret.encode(requestId)); signalFinished().emit(); return; @@ -41,26 +44,40 @@ void DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, const // TODO Require authentication con = connection; - requestId = packet.getRequestId(); + rid = requestId; - std::string daemonName((char*)packet.getData(), packet.getLength()); + std::string daemonName = packet["daemonName"]; try { Net::Connection *daemonCon = ConnectionManager::get()->getDaemonConnection(daemonName); - Common::RequestManager::get()->sendRequest(daemonCon, std::auto_ptr<Common::RequestBase>(new Common::Requests::StatusRequest(sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished)))); + Common::RequestManager::get()->sendRequest(daemonCon, std::auto_ptr<Common::XmlRequestBase>(new Common::Requests::StatusRequest(sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished)))); } catch(Common::Exception &e) { - connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), e)); + Common::XmlPacket ret; + ret.setType("Error"); + ret.add("ErrorCode", e.getErrorCode()); + ret.add("SubCode", e.getSubCode()); + ret.add("SubSubCode", e.getSubSubCode()); + ret.add("Where", e.getWhere()); + + con->send(ret.encode(rid)); } } -void DaemonStatusRequestHandler::requestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request) { +void DaemonStatusRequestHandler::requestFinished(const Common::XmlRequest &request) { try { - const Net::Packet &packet = request.getResult(); - con->send(Net::Packet(Net::Packet::OK, requestId, packet.getData(), packet.getLength())); + const Common::XmlPacket &packet = request.getResult(); + con->send(packet.encode(rid)); } catch(Common::Exception &e) { - con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, requestId, e)); + Common::XmlPacket ret; + ret.setType("Error"); + ret.add("ErrorCode", e.getErrorCode()); + ret.add("SubCode", e.getSubCode()); + ret.add("SubSubCode", e.getSubSubCode()); + ret.add("Where", e.getWhere()); + + con->send(ret.encode(rid)); } signalFinished().emit(); diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.h b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h index 36fabc0..30b2ae1 100644 --- a/src/Core/RequestHandlers/DaemonStatusRequestHandler.h +++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h @@ -20,8 +20,8 @@ #ifndef MAD_CORE_REQUESTHANDLERS_DAEMONSTATUSREQUESTHANDLER_H_ #define MAD_CORE_REQUESTHANDLERS_DAEMONSTATUSREQUESTHANDLER_H_ -#include <Common/RequestHandler.h> -#include <Common/Request.h> +#include <Common/XmlRequestHandler.h> +#include <Common/XmlRequest.h> #include <stdint.h> namespace Mad { @@ -35,15 +35,15 @@ class HostStatusPacket; namespace Core { namespace RequestHandlers { -class DaemonStatusRequestHandler : public Common::RequestHandler { +class DaemonStatusRequestHandler : public Common::XmlRequestHandler { private: Net::Connection *con; - uint16_t requestId; + uint16_t rid; - void requestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request); + void requestFinished(const Common::XmlRequest &request); protected: - virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet); public: DaemonStatusRequestHandler() {} diff --git a/src/Core/RequestHandlers/UserListRequestHandler.cpp b/src/Core/RequestHandlers/UserListRequestHandler.cpp index 01c2eb3..176fde9 100644 --- a/src/Core/RequestHandlers/UserListRequestHandler.cpp +++ b/src/Core/RequestHandlers/UserListRequestHandler.cpp @@ -19,19 +19,24 @@ #include "UserListRequestHandler.h" #include "../UserBackend.h" +#include <Common/Exception.h> #include <Common/Logger.h> +#include <Common/XmlPacket.h> #include <Net/Connection.h> -#include <Net/Packets/ErrorPacket.h> -#include <Net/Packets/UserListPacket.h> namespace Mad { namespace Core { namespace RequestHandlers { -void UserListRequestHandler::handlePacket(Net::Connection *con, const Net::Packet &packet) { - if(packet.getType() != Net::Packet::USERS_LIST) { +void UserListRequestHandler::handlePacket(Net::Connection *con, uint16_t requestId, const Common::XmlPacket &packet) { + if(packet.getType() != "ListUsers") { Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); - connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + + Common::XmlPacket ret; + ret.setType("Error"); + ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET); + + con->send(ret.encode(requestId)); signalFinished().emit(); return; @@ -40,21 +45,34 @@ void UserListRequestHandler::handlePacket(Net::Connection *con, const Net::Packe // TODO Require authentication connection = con; - requestId = packet.getRequestId(); + rid = requestId; if(!UserBackend::getUserList(sigc::mem_fun(this, &UserListRequestHandler::userListHandler))) { - con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::NOT_IMPLEMENTED))); + Common::XmlPacket ret; + ret.setType("Error"); + ret.add("ErrorCode", Common::Exception::NOT_IMPLEMENTED); + + con->send(ret.encode(requestId)); signalFinished().emit(); } } void UserListRequestHandler::userListHandler(const std::map<unsigned long, Common::UserInfo> &info) { - std::vector<Common::UserInfo> userList; + Common::XmlPacket ret; + ret.setType("OK"); + ret.addList("users"); - for(std::map<unsigned long, Common::UserInfo>::const_iterator user = info.begin(); user != info.end(); ++user) - userList.push_back(user->second); + for(std::map<unsigned long, Common::UserInfo>::const_iterator user = info.begin(); user != info.end(); ++user) { + ret["users"].addEntry(); + Common::XmlPacket::Entry &entry = ret["users"].back(); + + entry.add("uid", user->second.getUid()); + entry.add("gid", user->second.getGid()); + entry.add("username", user->second.getUsername()); + entry.add("fullName", user->second.getFullName()); + } - connection->send(Net::Packets::UserListPacket(Net::Packet::OK, requestId, userList)); + connection->send(ret.encode(rid)); signalFinished().emit(); } diff --git a/src/Core/RequestHandlers/UserListRequestHandler.h b/src/Core/RequestHandlers/UserListRequestHandler.h index 92eddb7..7739809 100644 --- a/src/Core/RequestHandlers/UserListRequestHandler.h +++ b/src/Core/RequestHandlers/UserListRequestHandler.h @@ -20,7 +20,7 @@ #ifndef MAD_CORE_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_ #define MAD_CORE_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_ -#include <Common/RequestHandler.h> +#include <Common/XmlRequestHandler.h> #include <Common/UserInfo.h> #include <map> @@ -30,15 +30,15 @@ namespace Mad { namespace Core { namespace RequestHandlers { -class UserListRequestHandler : public Common::RequestHandler { +class UserListRequestHandler : public Common::XmlRequestHandler { private: Net::Connection *connection; - uint16_t requestId; + uint16_t rid; void userListHandler(const std::map<unsigned long, Common::UserInfo> &info); protected: - virtual void handlePacket(Net::Connection *con, const Net::Packet &packet); + virtual void handlePacket(Net::Connection *con, uint16_t requestId, const Common::XmlPacket &packet); public: UserListRequestHandler() {} |