From 63907817cb057f497f03a28016d408885cbe41ea Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 1 Mar 2009 00:51:00 +0100 Subject: Alle uebrigen Requests ausser GSSAPIAuthRequest in XmlRequests umgewandelt --- .../DaemonCommandRequestHandler.cpp | 47 +++++++++++++++------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp') diff --git a/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp b/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp index 6782b8d..97a1bdc 100644 --- a/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp +++ b/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp @@ -21,16 +21,20 @@ #include "../ConnectionManager.h" #include #include -#include namespace Mad { namespace Core { namespace RequestHandlers { -void DaemonCommandRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(packet.getType() != Net::Packet::DAEMON_COMMAND_SHUTDOWN && packet.getType() != Net::Packet::DAEMON_COMMAND_REBOOT) { +void DaemonCommandRequestHandler::handlePacket(Net::Connection *connection, uint16_t rid, const Common::XmlPacket &packet) { + if(packet.getType() != "DaemonCommand") { 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); + + connection->send(ret.encode(rid)); signalFinished().emit(); return; @@ -39,28 +43,43 @@ void DaemonCommandRequestHandler::handlePacket(Net::Connection *connection, cons // TODO Require authentication con = connection; - requestId = packet.getRequestId(); + requestId = rid; - std::string daemonName((char*)packet.getData(), packet.getLength()); + std::string command = packet["command"]; try { - Net::Connection *daemonCon = ConnectionManager::get()->getDaemonConnection(daemonName); - Common::RequestManager::get()->sendRequest(daemonCon, std::auto_ptr( - new Requests::CommandRequest(packet.getType() == Net::Packet::DAEMON_COMMAND_REBOOT, sigc::mem_fun(this, &DaemonCommandRequestHandler::requestFinished)) + Net::Connection *daemonCon = ConnectionManager::get()->getDaemonConnection(packet["daemon"]); + Common::RequestManager::get()->sendRequest(daemonCon, std::auto_ptr( + new Requests::CommandRequest(command == "reboot", sigc::mem_fun(this, &DaemonCommandRequestHandler::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(requestId)); } } -void DaemonCommandRequestHandler::requestFinished(const Common::Request<> &request) { +void DaemonCommandRequestHandler::requestFinished(const Common::XmlRequest &request) { try { - request.getResult(); - con->send(Net::Packet(Net::Packet::OK, requestId)); + const Common::XmlPacket &packet = request.getResult(); + + con->send(packet.encode(requestId)); } 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(requestId)); } signalFinished().emit(); -- cgit v1.2.3