summaryrefslogtreecommitdiffstats
path: root/src/Core
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/ConnectionManager.cpp26
-rw-r--r--src/Core/ConnectionManager.h5
-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
-rw-r--r--src/Core/Requests/DaemonStatusRequest.cpp9
-rw-r--r--src/Core/Requests/DaemonStatusRequest.h2
12 files changed, 93 insertions, 62 deletions
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index 60f3ac4..2926fbf 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -162,32 +162,30 @@ void ConnectionManager::run() {
refreshPollfds();
}
-Net::Connection* ConnectionManager::getDaemonConnection(const std::string &name) const {
+Net::Connection* ConnectionManager::getDaemonConnection(const std::string &name) const throw (Common::Exception&) {
std::map<std::string,Net::ServerConnection*>::const_iterator daemon = identifiedDaemonConnections.find(name);
if(daemon == identifiedDaemonConnections.end())
- return 0;
+ throw Common::Exception(Common::Exception::UNKNOWN_DAEMON);
+
+ if(!daemon->second)
+ throw Common::Exception(Common::Exception::DAEMON_INACTIVE);
return daemon->second;
}
-void ConnectionManager::identifyDaemonConnection(Net::Connection *connection, const std::string &name) {
- // TODO Error handling
+void ConnectionManager::identifyDaemonConnection(Net::Connection *connection, const std::string &name) throw (Common::Exception&) {
+ // TODO Logging
- if(connection->isIdentified()) {
- std::cerr << "Already identified." << std::endl;
- return;
- }
+ if(connection->isIdentified())
+ throw Common::Exception(Common::Exception::ALREADY_IDENTIFIED);
std::list<Net::ServerConnection*>::iterator con = std::find(daemonConnections.begin(), daemonConnections.end(), connection);
- if(con == daemonConnections.end()) {
- std::cerr << "Connection not found." << std::endl;
- return;
- }
+ if(con == daemonConnections.end())
+ throw Common::Exception(Common::Exception::INVALID_ACTION);
std::map<std::string,Net::ServerConnection*>::iterator idCon = identifiedDaemonConnections.find(name);
if(idCon == identifiedDaemonConnections.end()) {
- std::cerr << "Name not found." << std::endl;
- return;
+ throw Common::Exception(Common::Exception::UNKNOWN_DAEMON);
}
if(idCon->second) {
diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h
index ba029ec..be9beb9 100644
--- a/src/Core/ConnectionManager.h
+++ b/src/Core/ConnectionManager.h
@@ -27,6 +27,7 @@
#include <poll.h>
#include "DaemonInfo.h"
+#include <Common/Exception.h>
#include <Common/RequestManager.h>
namespace Mad {
@@ -82,8 +83,8 @@ class ConnectionManager {
void run();
- Net::Connection* getDaemonConnection(const std::string &name) const;
- void identifyDaemonConnection(Net::Connection *connection, const std::string &name);
+ Net::Connection* getDaemonConnection(const std::string &name) const throw (Common::Exception&);
+ void identifyDaemonConnection(Net::Connection *connection, const std::string &name) throw (Common::Exception&);
std::map<std::string,DaemonInfo> getDaemonList() const;
};
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);
};
}
diff --git a/src/Core/Requests/DaemonStatusRequest.cpp b/src/Core/Requests/DaemonStatusRequest.cpp
index 118203f..86ef3c6 100644
--- a/src/Core/Requests/DaemonStatusRequest.cpp
+++ b/src/Core/Requests/DaemonStatusRequest.cpp
@@ -44,14 +44,15 @@ bool DaemonStatusRequest::sendRequest(Net::Connection *connection, uint16_t requ
return true;
}
-bool DaemonStatusRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::OK)
- return false; // TODO Logging
+void DaemonStatusRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::OK) {
+ signalFinished().emit();
+ return; // TODO Logging
+ }
finished(Net::Packets::HostStatusPacket(packet));
signalFinished().emit();
- return true;
}
}
diff --git a/src/Core/Requests/DaemonStatusRequest.h b/src/Core/Requests/DaemonStatusRequest.h
index b9ec401..ce6e4f7 100644
--- a/src/Core/Requests/DaemonStatusRequest.h
+++ b/src/Core/Requests/DaemonStatusRequest.h
@@ -46,7 +46,7 @@ class DaemonStatusRequest : public Common::Request {
static bool send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback);
virtual bool sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual bool handlePacket(Net::Connection*, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection*, const Net::Packet &packet);
};
}