summaryrefslogtreecommitdiffstats
path: root/src/Daemon
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-03-01 00:51:00 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-03-01 00:51:00 +0100
commit63907817cb057f497f03a28016d408885cbe41ea (patch)
treea9ad6b0b19bff7722b21375137ba6e53c8869c91 /src/Daemon
parent46c110f7a14e4b5d0e8bd27259f7744ae8a36382 (diff)
downloadmad-63907817cb057f497f03a28016d408885cbe41ea.tar
mad-63907817cb057f497f03a28016d408885cbe41ea.zip
Alle uebrigen Requests ausser GSSAPIAuthRequest in XmlRequests umgewandelt
Diffstat (limited to 'src/Daemon')
-rw-r--r--src/Daemon/RequestHandlers/CommandRequestHandler.cpp48
-rw-r--r--src/Daemon/RequestHandlers/CommandRequestHandler.h6
-rw-r--r--src/Daemon/Requests/IdentifyRequest.cpp13
-rw-r--r--src/Daemon/Requests/IdentifyRequest.h8
4 files changed, 46 insertions, 29 deletions
diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
index c6750ba..3f4ef17 100644
--- a/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
+++ b/src/Daemon/RequestHandlers/CommandRequestHandler.cpp
@@ -21,8 +21,8 @@
#include <Common/Exception.h>
#include <Common/Logger.h>
#include <Common/SystemBackend.h>
+#include <Common/XmlPacket.h>
#include <Net/Connection.h>
-#include <Net/Packets/ErrorPacket.h>
#include <sigc++/bind.h>
@@ -30,37 +30,49 @@ namespace Mad {
namespace Daemon {
namespace RequestHandlers {
-void CommandRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- // TODO Require authentication
+void CommandRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) {
+ if(packet.getType() != "Command") {
+ Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
- switch(packet.getType()) {
- case Net::Packet::COMMAND_SHUTDOWN:
- if(Common::SystemBackend::shutdown(sigc::bind(sigc::mem_fun(this, &CommandRequestHandler::sendReply), connection, packet.getRequestId())))
- return;
+ Common::XmlPacket ret;
+ ret.setType("Error");
+ ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET);
- break;
+ connection->send(ret.encode(requestId));
- case Net::Packet::COMMAND_REBOOT:
- if(Common::SystemBackend::reboot(sigc::bind(sigc::mem_fun(this, &CommandRequestHandler::sendReply), connection, packet.getRequestId())))
- return;
+ signalFinished().emit();
+ return;
+ }
- break;
+ // TODO Require authentication
+ // TODO Error handling
- default:
- 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)));
+ std::string command = packet["command"];
- signalFinished().emit();
+ if(command == "reboot") {
+ if(Common::SystemBackend::shutdown(sigc::bind(sigc::mem_fun(this, &CommandRequestHandler::sendReply), connection, requestId)))
+ return;
+ }
+ else {
+ if(Common::SystemBackend::reboot(sigc::bind(sigc::mem_fun(this, &CommandRequestHandler::sendReply), connection, requestId)))
return;
}
- connection->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);
+
+ connection->send(ret.encode(requestId));
signalFinished().emit();
}
void CommandRequestHandler::sendReply(Net::Connection *connection, uint16_t requestId) {
- connection->send(Net::Packet(Net::Packet::OK, requestId));
+ Common::XmlPacket packet;
+ packet.setType("OK");
+
+ connection->send(packet.encode(requestId));
+
signalFinished().emit();
}
diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.h b/src/Daemon/RequestHandlers/CommandRequestHandler.h
index 5066c1d..86391f2 100644
--- a/src/Daemon/RequestHandlers/CommandRequestHandler.h
+++ b/src/Daemon/RequestHandlers/CommandRequestHandler.h
@@ -20,19 +20,19 @@
#ifndef MAD_DAEMON_REQUESTHANDLERS_COMMANDREQUESTHANDLER_H_
#define MAD_DAEMON_REQUESTHANDLERS_COMMANDREQUESTHANDLER_H_
-#include <Common/RequestHandler.h>
+#include <Common/XmlRequestHandler.h>
#include <stdint.h>
namespace Mad {
namespace Daemon {
namespace RequestHandlers {
-class CommandRequestHandler : public Common::RequestHandler {
+class CommandRequestHandler : public Common::XmlRequestHandler {
private:
void sendReply(Net::Connection *connection, uint16_t requestId);
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:
CommandRequestHandler() {}
diff --git a/src/Daemon/Requests/IdentifyRequest.cpp b/src/Daemon/Requests/IdentifyRequest.cpp
index e8b6082..6334f00 100644
--- a/src/Daemon/Requests/IdentifyRequest.cpp
+++ b/src/Daemon/Requests/IdentifyRequest.cpp
@@ -19,22 +19,27 @@
#include "IdentifyRequest.h"
#include <Net/Connection.h>
+#include <Common/XmlPacket.h>
namespace Mad {
namespace Daemon {
namespace Requests {
void IdentifyRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
- connection->send(Net::Packet(Net::Packet::IDENTIFY, requestId, hostname.c_str(), hostname.length()));
+ Common::XmlPacket packet;
+ packet.setType("Identify");
+ packet.add("hostname", hostname);
+
+ connection->send(packet.encode(requestId));
}
-void IdentifyRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::OK) {
+void IdentifyRequest::handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet) {
+ if(packet.getType() != "OK") {
finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
- finish();
+ finish(packet);
}
}
diff --git a/src/Daemon/Requests/IdentifyRequest.h b/src/Daemon/Requests/IdentifyRequest.h
index c728461..c3ab821 100644
--- a/src/Daemon/Requests/IdentifyRequest.h
+++ b/src/Daemon/Requests/IdentifyRequest.h
@@ -20,23 +20,23 @@
#ifndef MAD_DAEMON_REQUESTS_IDENTIFYREQUEST_H_
#define MAD_DAEMON_REQUESTS_IDENTIFYREQUEST_H_
-#include <Common/Request.h>
+#include <Common/XmlRequest.h>
#include <string>
namespace Mad {
namespace Daemon {
namespace Requests {
-class IdentifyRequest : public Common::Request<> {
+class IdentifyRequest : public Common::XmlRequest {
private:
std::string hostname;
protected:
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection*, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet);
public:
- IdentifyRequest(const std::string &hostname0, slot_type slot) : Common::Request<>(slot), hostname(hostname0) {}
+ IdentifyRequest(const std::string &hostname0, slot_type slot) : Common::XmlRequest(slot), hostname(hostname0) {}
};
}