summaryrefslogtreecommitdiffstats
path: root/src/Common/RequestHandlers
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/Common/RequestHandlers
parent46c110f7a14e4b5d0e8bd27259f7744ae8a36382 (diff)
downloadmad-63907817cb057f497f03a28016d408885cbe41ea.tar
mad-63907817cb057f497f03a28016d408885cbe41ea.zip
Alle uebrigen Requests ausser GSSAPIAuthRequest in XmlRequests umgewandelt
Diffstat (limited to 'src/Common/RequestHandlers')
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.cpp20
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.h6
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.cpp41
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.h6
4 files changed, 54 insertions, 19 deletions
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
index 6a5ca99..346b6de 100644
--- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
+++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
@@ -18,24 +18,34 @@
*/
#include "DisconnectRequestHandler.h"
+#include "../Exception.h"
#include "../Logger.h"
+#include "../XmlPacket.h"
#include <Net/Connection.h>
-#include <Net/Packets/ErrorPacket.h>
namespace Mad {
namespace Common {
namespace RequestHandlers {
-void DisconnectRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::DISCONNECT) {
+void DisconnectRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet) {
+ if(packet.getType() != "Disconnect") {
Logger::log(Logger::ERROR, "Received an unexpected packet.");
- connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET)));
+
+ XmlPacket ret;
+ ret.setType("Error");
+ ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
+
+ connection->send(ret.encode(requestId));
signalFinished().emit();
return;
}
- connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()));
+ XmlPacket ret;
+ ret.setType("OK");
+
+ connection->send(ret.encode(requestId));
+
connection->disconnect();
signalFinished().emit();
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.h b/src/Common/RequestHandlers/DisconnectRequestHandler.h
index f0ca85f..23d07dc 100644
--- a/src/Common/RequestHandlers/DisconnectRequestHandler.h
+++ b/src/Common/RequestHandlers/DisconnectRequestHandler.h
@@ -20,15 +20,15 @@
#ifndef MAD_COMMON_REQUESTHANDLERS_DISCONNECTREQUESTHANDLER_H_
#define MAD_COMMON_REQUESTHANDLERS_DISCONNECTREQUESTHANDLER_H_
-#include "../RequestHandler.h"
+#include "../XmlRequestHandler.h"
namespace Mad {
namespace Common {
namespace RequestHandlers {
-class DisconnectRequestHandler : public RequestHandler {
+class DisconnectRequestHandler : public XmlRequestHandler {
protected:
- virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet);
public:
DisconnectRequestHandler() {}
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
index 5d71277..878dd7c 100644
--- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
@@ -18,19 +18,24 @@
*/
#include "FSInfoRequestHandler.h"
+#include "../Exception.h"
#include "../Logger.h"
+#include "../XmlPacket.h"
#include <Net/Connection.h>
-#include <Net/Packets/ErrorPacket.h>
-#include <Net/Packets/FSInfoPacket.h>
namespace Mad {
namespace Common {
namespace RequestHandlers {
-void FSInfoRequestHandler::handlePacket(Net::Connection *con, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::FS_INFO) {
+void FSInfoRequestHandler::handlePacket(Net::Connection *con, uint16_t rid, const XmlPacket &packet) {
+ if(packet.getType() != "FSInfo") {
Logger::log(Logger::ERROR, "Received an unexpected packet.");
- con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Exception(Exception::UNEXPECTED_PACKET)));
+
+ XmlPacket ret;
+ ret.setType("Error");
+ ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
+
+ connection->send(ret.encode(rid));
signalFinished().emit();
return;
@@ -39,16 +44,36 @@ void FSInfoRequestHandler::handlePacket(Net::Connection *con, const Net::Packet
// TODO Require authentication
connection = con;
- requestId = packet.getRequestId();
+ requestId = rid;
if(!SystemBackend::getFSInfo(sigc::mem_fun(this, &FSInfoRequestHandler::fsInfoHandler))) {
- con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Exception(Exception::NOT_IMPLEMENTED)));
+ XmlPacket ret;
+ ret.setType("Error");
+ ret.add("ErrorCode", Exception::NOT_IMPLEMENTED);
+
+ connection->send(ret.encode(requestId));
+
signalFinished().emit();
}
}
void FSInfoRequestHandler::fsInfoHandler(const std::vector<SystemBackend::FSInfo> &info) {
- connection->send(Net::Packets::FSInfoPacket(Net::Packet::OK, requestId, info));
+ XmlPacket ret;
+ ret.setType("OK");
+ ret.addList("filesystems");
+
+ for(std::vector<SystemBackend::FSInfo>::const_iterator fs = info.begin(); fs != info.end(); ++fs) {
+ ret["filesystems"].addEntry();
+ XmlPacket::Entry &entry = ret["filesystems"].back();
+
+ entry.add("name", fs->fsName);
+ entry.add("mountedOn", fs->mountedOn);
+ entry.add("totalSize", fs->total);
+ entry.add("usedSize", fs->used);
+ entry.add("availableSize", fs->available);
+ }
+
+ connection->send(ret.encode(requestId));
signalFinished().emit();
}
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.h b/src/Common/RequestHandlers/FSInfoRequestHandler.h
index 8de89ce..32e7a08 100644
--- a/src/Common/RequestHandlers/FSInfoRequestHandler.h
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.h
@@ -20,7 +20,7 @@
#ifndef MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_
#define MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_
-#include "../RequestHandler.h"
+#include "../XmlRequestHandler.h"
#include "../SystemBackend.h"
#include <stdint.h>
@@ -29,7 +29,7 @@ namespace Mad {
namespace Common {
namespace RequestHandlers {
-class FSInfoRequestHandler : public RequestHandler {
+class FSInfoRequestHandler : public XmlRequestHandler {
private:
Net::Connection *connection;
uint16_t requestId;
@@ -37,7 +37,7 @@ class FSInfoRequestHandler : public RequestHandler {
void fsInfoHandler(const std::vector<SystemBackend::FSInfo> &info);
protected:
- virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *con, uint16_t rid, const XmlPacket &packet);
public:
FSInfoRequestHandler() {}