diff options
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Exception.h | 50 | ||||
-rw-r--r-- | src/Common/Makefile.am | 2 | ||||
-rw-r--r-- | src/Common/Makefile.in | 2 | ||||
-rw-r--r-- | src/Common/RequestHandler.h | 2 | ||||
-rw-r--r-- | src/Common/RequestHandlers/DisconnectRequestHandler.cpp | 18 | ||||
-rw-r--r-- | src/Common/RequestHandlers/DisconnectRequestHandler.h | 2 | ||||
-rw-r--r-- | src/Common/RequestHandlers/StatusRequestHandler.cpp | 21 | ||||
-rw-r--r-- | src/Common/RequestHandlers/StatusRequestHandler.h | 2 | ||||
-rw-r--r-- | src/Common/RequestManager.cpp | 3 | ||||
-rw-r--r-- | src/Common/Requests/DisconnectRequest.cpp | 15 | ||||
-rw-r--r-- | src/Common/Requests/DisconnectRequest.h | 2 | ||||
-rw-r--r-- | src/Common/Requests/GSSAPIAuthRequest.cpp | 22 | ||||
-rw-r--r-- | src/Common/Requests/GSSAPIAuthRequest.h | 2 | ||||
-rw-r--r-- | src/Common/Requests/IdentifyRequest.cpp | 5 | ||||
-rw-r--r-- | src/Common/Requests/IdentifyRequest.h | 2 |
15 files changed, 107 insertions, 43 deletions
diff --git a/src/Common/Exception.h b/src/Common/Exception.h new file mode 100644 index 0000000..6b4cf9f --- /dev/null +++ b/src/Common/Exception.h @@ -0,0 +1,50 @@ +/* + * Exception.h + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MAD_COMMON_EXCEPTION_H_ +#define MAD_COMMON_EXCEPTION_H_ + +namespace Mad { +namespace Common { + +class Exception { + public: + enum ErrorCode { + SUCCESS = 0x0000, UNEXPECTED_PACKET = 0x0001, INVALID_ACTION = 0x0002, + ALREADY_IDENTIFIED = 0x0010, UNKNOWN_DAEMON = 0x0011, DAEMON_INACTIVE = 0x0012 + }; + + private: + ErrorCode errorCode; + unsigned long subCode; + unsigned long subSubCode; + + public: + Exception(ErrorCode errorCode0, unsigned long subCode0 = 0, unsigned long subSubCode0 = 0) : errorCode(errorCode0), subCode(subCode0), subSubCode(subSubCode0) {} + virtual ~Exception() {} + + ErrorCode getErrorCode() const {return errorCode;} + unsigned long getSubCode() const {return subCode;} + unsigned long getSubSubCode() const {return subSubCode;} +}; + +} +} + +#endif /* MAD_COMMON_EXCEPTION_H_ */ diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am index 8ea7c14..f422b46 100644 --- a/src/Common/Makefile.am +++ b/src/Common/Makefile.am @@ -4,4 +4,4 @@ noinst_LTLIBRARIES = libcommon.la libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp SystemBackend.cpp Util.cpp libcommon_la_LIBADD = Backends/libbackends.la Requests/librequests.la RequestHandlers/librequesthandlers.la -noinst_HEADERS = ConfigManager.h Request.h RequestHandler.h RequestManager.h SystemBackend.h Util.h +noinst_HEADERS = ConfigManager.h Exception.h Request.h RequestHandler.h RequestManager.h SystemBackend.h Util.h diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in index 66992ea..9361d39 100644 --- a/src/Common/Makefile.in +++ b/src/Common/Makefile.in @@ -199,7 +199,7 @@ SUBDIRS = Backends Requests RequestHandlers noinst_LTLIBRARIES = libcommon.la libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp SystemBackend.cpp Util.cpp libcommon_la_LIBADD = Backends/libbackends.la Requests/librequests.la RequestHandlers/librequesthandlers.la -noinst_HEADERS = ConfigManager.h Request.h RequestHandler.h RequestManager.h SystemBackend.h Util.h +noinst_HEADERS = ConfigManager.h Exception.h Request.h RequestHandler.h RequestManager.h SystemBackend.h Util.h all: all-recursive .SUFFIXES: diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h index 305836c..2bc2361 100644 --- a/src/Common/RequestHandler.h +++ b/src/Common/RequestHandler.h @@ -45,7 +45,7 @@ class RequestHandler { sigc::signal<void> signalFinished() {return finished;} - virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet) = 0; + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet) = 0; }; } diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp index aa98c04..010f1e7 100644 --- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp +++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp @@ -19,23 +19,27 @@ #include "DisconnectRequestHandler.h" #include <Net/Connection.h> +#include <Net/Packets/ErrorPacket.h> + +#include <iostream> namespace Mad { namespace Common { namespace RequestHandlers { -bool DisconnectRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(packet.getType() != Net::Packet::DISCONNECT) - return false; // TODO Logging +void DisconnectRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::DISCONNECT) { + std::cerr << "Received an unexpected packet." << std::endl; + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); - if(!connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()))) - return false; + signalFinished().emit(); + return; + } + connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId())); connection->disconnect(); signalFinished().emit(); - - return true; } } diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.h b/src/Common/RequestHandlers/DisconnectRequestHandler.h index 784700d..b4da634 100644 --- a/src/Common/RequestHandlers/DisconnectRequestHandler.h +++ b/src/Common/RequestHandlers/DisconnectRequestHandler.h @@ -30,7 +30,7 @@ class DisconnectRequestHandler : public RequestHandler { public: DisconnectRequestHandler() {} - virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp index 0a437fa..bcff6b6 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.cpp +++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp @@ -20,28 +20,33 @@ #include "StatusRequestHandler.h" #include "../SystemBackend.h" #include <Net/Connection.h> +#include <Net/Packets/ErrorPacket.h> #include <Net/Packets/HostStatusPacket.h> +#include <iostream> + namespace Mad { namespace Common { namespace RequestHandlers { -bool StatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(packet.getType() != Net::Packet::STATUS) - return false; // TODO Logging +void StatusRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::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 SystemBackend::UptimeInfo uptimeInfo = SystemBackend::getBackend()->getUptimeInfo(); SystemBackend::MemoryInfo memInfo = SystemBackend::getBackend()->getMemoryInfo(); - if(!connection->send(Net::Packets::HostStatusPacket(Net::Packet::OK, packet.getRequestId(), uptimeInfo.uptime, uptimeInfo.idleTime, - memInfo.totalMem, memInfo.freeMem, memInfo.totalSwap, memInfo.freeSwap))) - return false; + connection->send(Net::Packets::HostStatusPacket(Net::Packet::OK, packet.getRequestId(), uptimeInfo.uptime, uptimeInfo.idleTime, + memInfo.totalMem, memInfo.freeMem, memInfo.totalSwap, memInfo.freeSwap)); signalFinished().emit(); - - return true; } } diff --git a/src/Common/RequestHandlers/StatusRequestHandler.h b/src/Common/RequestHandlers/StatusRequestHandler.h index db2176a..f98a9a4 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.h +++ b/src/Common/RequestHandlers/StatusRequestHandler.h @@ -30,7 +30,7 @@ class StatusRequestHandler : public RequestHandler { public: StatusRequestHandler() {} - virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index e2864b1..5d3fdcd 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -21,6 +21,8 @@ #include "Request.h" #include "RequestHandlers/DisconnectRequestHandler.h" +#include <Net/Packets/ErrorPacket.h> + #include <sigc++/bind.h> #include <sigc++/retype_return.h> #include <iostream> @@ -90,6 +92,7 @@ void RequestManager::receiveHandler(Net::Connection *connection, const Net::Pack std::cerr << "Received an unexpected packet." << std::endl; + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Exception(Exception::UNEXPECTED_PACKET))); } bool RequestManager::sendRequest(Net::Connection *connection, Request *request) { diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp index 090b840..81208f2 100644 --- a/src/Common/Requests/DisconnectRequest.cpp +++ b/src/Common/Requests/DisconnectRequest.cpp @@ -43,16 +43,17 @@ bool DisconnectRequest::sendRequest(Net::Connection *connection, uint16_t reques return true; } -bool DisconnectRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(packet.getType() != Net::Packet::OK) - return false; // TODO Logging +void DisconnectRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::OK) { + signalFinished().emit(); + return; // TODO Logging + } - connection->disconnect(); + connection->disconnect(); - finished(); + finished(); - signalFinished().emit(); - return true; + signalFinished().emit(); } } diff --git a/src/Common/Requests/DisconnectRequest.h b/src/Common/Requests/DisconnectRequest.h index 6c87f85..dcc2b9c 100644 --- a/src/Common/Requests/DisconnectRequest.h +++ b/src/Common/Requests/DisconnectRequest.h @@ -38,7 +38,7 @@ class DisconnectRequest : public Request { static bool send(Net::Connection *connection, const sigc::slot<void> &callback); virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); - virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } diff --git a/src/Common/Requests/GSSAPIAuthRequest.cpp b/src/Common/Requests/GSSAPIAuthRequest.cpp index a4a1b17..91488d0 100644 --- a/src/Common/Requests/GSSAPIAuthRequest.cpp +++ b/src/Common/Requests/GSSAPIAuthRequest.cpp @@ -86,13 +86,17 @@ bool GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t reques return true; } -bool GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(packet.getType() != Net::Packet::GSSAPI_AUTH) - return false; // TODO Logging +void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::GSSAPI_AUTH) { + signalFinished().emit(); + return; // TODO Logging + } OM_uint32 majStat, minStat; gss_buffer_desc recvBuffer, sendBuffer; + // Needs error handling! + if(gssContinue) { recvBuffer.length = packet.getLength(); recvBuffer.value = std::malloc(recvBuffer.length); @@ -109,12 +113,12 @@ bool GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Pac } 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); @@ -134,7 +138,7 @@ bool GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Pac std::free(recvBuffer.value); if(majStat != GSS_S_COMPLETE) - return false; + return; connection->setAuthenticated(); std::cout << "Authentication complete." << std::endl; @@ -143,20 +147,18 @@ bool GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Pac 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); signalFinished().emit(); } - - return true; } } diff --git a/src/Common/Requests/GSSAPIAuthRequest.h b/src/Common/Requests/GSSAPIAuthRequest.h index e9a200e..336e4f0 100644 --- a/src/Common/Requests/GSSAPIAuthRequest.h +++ b/src/Common/Requests/GSSAPIAuthRequest.h @@ -49,7 +49,7 @@ class GSSAPIAuthRequest : public Request { static bool send(Net::Connection *connection, const std::string &serviceName0); virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); - virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } diff --git a/src/Common/Requests/IdentifyRequest.cpp b/src/Common/Requests/IdentifyRequest.cpp index 9214baf..23249cd 100644 --- a/src/Common/Requests/IdentifyRequest.cpp +++ b/src/Common/Requests/IdentifyRequest.cpp @@ -42,12 +42,11 @@ bool IdentifyRequest::sendRequest(Net::Connection *connection, uint16_t requestI return true; } -bool IdentifyRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { +void IdentifyRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { if(packet.getType() != Net::Packet::OK) - return false; // TODO Logging + return; // TODO Logging signalFinished().emit(); - return true; } } diff --git a/src/Common/Requests/IdentifyRequest.h b/src/Common/Requests/IdentifyRequest.h index 0b783e4..5a02949 100644 --- a/src/Common/Requests/IdentifyRequest.h +++ b/src/Common/Requests/IdentifyRequest.h @@ -37,7 +37,7 @@ class IdentifyRequest : public Request { static bool send(Net::Connection *connection, const std::string &hostname0); 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); }; } |