summaryrefslogtreecommitdiffstats
path: root/src/Core/RequestHandlers
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core/RequestHandlers')
-rw-r--r--src/Core/RequestHandlers/DaemonListRequestHandler.cpp19
-rw-r--r--src/Core/RequestHandlers/DaemonListRequestHandler.h2
-rw-r--r--src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp29
-rw-r--r--src/Core/RequestHandlers/DaemonStatusRequestHandler.h2
-rw-r--r--src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp28
-rw-r--r--src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h2
-rw-r--r--src/Core/RequestHandlers/IdentifyRequestHandler.cpp29
-rw-r--r--src/Core/RequestHandlers/IdentifyRequestHandler.h2
8 files changed, 72 insertions, 41 deletions
diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.cpp b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
index 1f137ad..2bee423 100644
--- a/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
+++ b/src/Core/RequestHandlers/DaemonListRequestHandler.cpp
@@ -20,15 +20,23 @@
#include "DaemonListRequestHandler.h"
#include "../ConnectionManager.h"
#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
#include <Net/Packets/NameListPacket.h>
+#include <iostream>
+
namespace Mad {
namespace Core {
namespace RequestHandlers {
-bool DaemonListRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::LIST_DAEMONS)
- return false; // TODO Logging
+void DaemonListRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::LIST_DAEMONS) {
+ std::cerr << "Received an unexpected packet." << std::endl;
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET)));
+
+ signalFinished().emit();
+ return;
+ }
// TODO Require authentication
@@ -38,12 +46,9 @@ bool DaemonListRequestHandler::handlePacket(Net::Connection *connection, const N
for(std::map<std::string,DaemonInfo>::iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon)
names.push_back(daemon->first);
- if(!connection->send(Net::Packets::NameListPacket(Net::Packet::OK, packet.getRequestId(), names)))
- return false;
+ connection->send(Net::Packets::NameListPacket(Net::Packet::OK, packet.getRequestId(), names));
signalFinished().emit();
-
- return true;
}
}
diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.h b/src/Core/RequestHandlers/DaemonListRequestHandler.h
index 406d212..1aabe5b 100644
--- a/src/Core/RequestHandlers/DaemonListRequestHandler.h
+++ b/src/Core/RequestHandlers/DaemonListRequestHandler.h
@@ -30,7 +30,7 @@ class DaemonListRequestHandler : public Common::RequestHandler {
public:
DaemonListRequestHandler() {}
- virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
};
}
diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp
index 0179ecc..bb5d45f 100644
--- a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp
+++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp
@@ -20,15 +20,24 @@
#include "DaemonStatusRequestHandler.h"
#include "../ConnectionManager.h"
#include <Core/Requests/DaemonStatusRequest.h>
+#include <Net/Packets/ErrorPacket.h>
#include <Net/Packets/HostStatusPacket.h>
+#include <iostream>
+
+
namespace Mad {
namespace Core {
namespace RequestHandlers {
-bool DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::DAEMON_STATUS)
- return false; // TODO Logging
+void DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::DAEMON_STATUS) {
+ std::cerr << "Received an unexpected packet." << std::endl;
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET)));
+
+ signalFinished().emit();
+ return;
+ }
// TODO Require authentication
@@ -37,13 +46,13 @@ bool DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, const
std::string daemonName((char*)packet.getData(), packet.getLength());
- Net::Connection *daemonCon = ConnectionManager::getConnectionManager()->getDaemonConnection(daemonName);
- if(!daemonCon)
- return false;
-
- Requests::DaemonStatusRequest::send(daemonCon, sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished));
-
- return true;
+ try {
+ Net::Connection *daemonCon = ConnectionManager::getConnectionManager()->getDaemonConnection(daemonName);
+ Requests::DaemonStatusRequest::send(daemonCon, sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished));
+ }
+ catch(Common::Exception &e) {
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), e));
+ }
}
void DaemonStatusRequestHandler::requestFinished(const Net::Packets::HostStatusPacket &packet) {
diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.h b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h
index 5d755bd..916a3ec 100644
--- a/src/Core/RequestHandlers/DaemonStatusRequestHandler.h
+++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h
@@ -47,7 +47,7 @@ class DaemonStatusRequestHandler : public Common::RequestHandler {
public:
DaemonStatusRequestHandler() {}
- virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
};
}
diff --git a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp
index 94098b9..d65da7e 100644
--- a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp
+++ b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp
@@ -19,6 +19,7 @@
#include "GSSAPIAuthRequestHandler.h"
#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
#include <cstring>
@@ -30,13 +31,20 @@ namespace RequestHandlers {
// TODO Error handling
-bool GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::GSSAPI_AUTH)
- return false; // TODO Logging
+void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::GSSAPI_AUTH) {
+ std::cerr << "Received an unexpected packet." << std::endl;
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET)));
+
+ signalFinished().emit();
+ return;
+ }
OM_uint32 majStat, minStat;
gss_buffer_desc recvBuffer, sendBuffer;
+ // Needs error handling!
+
if(gssContinue) {
recvBuffer.length = packet.getLength();
recvBuffer.value = std::malloc(recvBuffer.length);
@@ -52,19 +60,19 @@ bool GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, const N
}
else if(majStat != GSS_S_CONTINUE_NEEDED) {
gss_release_buffer(&minStat, &sendBuffer);
- return false;
+ return;
}
if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, packet.getRequestId(), sendBuffer.value, sendBuffer.length))) {
gss_release_buffer(&minStat, &sendBuffer);
- return false;
+ return;
}
gss_release_buffer(&minStat, &sendBuffer);
}
else if(!sentSignature) {
if(packet.getLength() != 0)
- return false;
+ return;
const gnutls_datum_t *cert = connection->getCertificate();
@@ -75,12 +83,12 @@ bool GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, const N
if(majStat != GSS_S_COMPLETE) {
gss_release_buffer(&minStat, &sendBuffer);
- return false;
+ return;
}
if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, packet.getRequestId(), sendBuffer.value, sendBuffer.length))) {
gss_release_buffer(&minStat, &sendBuffer);
- return false;
+ return;
}
gss_release_buffer(&minStat, &sendBuffer);
@@ -97,12 +105,10 @@ bool GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, const N
std::free(recvBuffer.value);
if(majStat != GSS_S_COMPLETE)
- return false;
+ return;
signalFinished().emit();
}
-
- return true;
}
}
diff --git a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h
index 57ea14f..2a7884b 100644
--- a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h
+++ b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h
@@ -36,7 +36,7 @@ class GSSAPIAuthRequestHandler : public Common::RequestHandler {
public:
GSSAPIAuthRequestHandler() : gssContext(GSS_C_NO_CONTEXT), gssContinue(true), sentSignature(false) {}
- virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
};
}
diff --git a/src/Core/RequestHandlers/IdentifyRequestHandler.cpp b/src/Core/RequestHandlers/IdentifyRequestHandler.cpp
index 48fccf2..4e65aca 100644
--- a/src/Core/RequestHandlers/IdentifyRequestHandler.cpp
+++ b/src/Core/RequestHandlers/IdentifyRequestHandler.cpp
@@ -19,26 +19,37 @@
#include "IdentifyRequestHandler.h"
#include "../ConnectionManager.h"
+#include <Common/Exception.h>
#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
+
+#include <iostream>
+
namespace Mad {
namespace Core {
namespace RequestHandlers {
-bool IdentifyRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::IDENTIFY)
- return false; // TODO Logging
+void IdentifyRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::IDENTIFY) {
+ std::cerr << "Received an unexpected packet." << std::endl;
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET)));
- // TODO Require authentication
+ signalFinished().emit();
+ return;
+ }
- ConnectionManager::getConnectionManager()->identifyDaemonConnection(connection, std::string((const char*)packet.getData(), packet.getLength()));
+ // TODO Require authentication
+ try {
+ ConnectionManager::getConnectionManager()->identifyDaemonConnection(connection, std::string((const char*)packet.getData(), packet.getLength()));
- if(!connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId())))
- return false;
+ connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()));
+ }
+ catch(Common::Exception &e) {
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), e));
+ }
signalFinished().emit();
-
- return true;
}
}
diff --git a/src/Core/RequestHandlers/IdentifyRequestHandler.h b/src/Core/RequestHandlers/IdentifyRequestHandler.h
index df03434..74ffd54 100644
--- a/src/Core/RequestHandlers/IdentifyRequestHandler.h
+++ b/src/Core/RequestHandlers/IdentifyRequestHandler.h
@@ -30,7 +30,7 @@ class IdentifyRequestHandler : public Common::RequestHandler {
public:
IdentifyRequestHandler() {}
- virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
};
}