diff options
Diffstat (limited to 'src/Common/Requests')
-rw-r--r-- | src/Common/Requests/DisconnectRequest.cpp | 14 | ||||
-rw-r--r-- | src/Common/Requests/DisconnectRequest.h | 7 | ||||
-rw-r--r-- | src/Common/Requests/FSInfoRequest.h | 3 | ||||
-rw-r--r-- | src/Common/Requests/GSSAPIAuthRequest.cpp | 15 | ||||
-rw-r--r-- | src/Common/Requests/GSSAPIAuthRequest.h | 8 | ||||
-rw-r--r-- | src/Common/Requests/SimpleRequest.cpp | 6 | ||||
-rw-r--r-- | src/Common/Requests/SimpleRequest.h | 5 | ||||
-rw-r--r-- | src/Common/Requests/StatusRequest.h | 3 | ||||
-rw-r--r-- | src/Common/Requests/UserListRequest.h | 3 |
9 files changed, 35 insertions, 29 deletions
diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp index afab8ed..ec8719d 100644 --- a/src/Common/Requests/DisconnectRequest.cpp +++ b/src/Common/Requests/DisconnectRequest.cpp @@ -24,20 +24,24 @@ namespace Mad { namespace Common { namespace Requests { -void DisconnectRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { +void DisconnectRequest::sendRequest() { XmlPacket packet; packet.setType("Disconnect"); - connection->send(packet.encode(requestId)); + sendPacket(packet); } -void DisconnectRequest::handlePacket(Net::Connection *connection, uint16_t, const XmlPacket &packet) { - if(packet.getType() != "OK") { +void DisconnectRequest::handlePacket(const XmlPacket &packet) { + if(packet.getType() == "Error") { + finishWithError(Common::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"])); + return; + } + else if(packet.getType() != "OK") { finishWithError(Exception(Exception::UNEXPECTED_PACKET)); return; // TODO Logging } - connection->disconnect(); + getConnection()->disconnect(); finish(packet); } diff --git a/src/Common/Requests/DisconnectRequest.h b/src/Common/Requests/DisconnectRequest.h index af7cca5..22ff16b 100644 --- a/src/Common/Requests/DisconnectRequest.h +++ b/src/Common/Requests/DisconnectRequest.h @@ -28,11 +28,12 @@ namespace Requests { class DisconnectRequest : public Request { protected: - virtual void sendRequest(Net::Connection *connection, uint16_t requestId); - virtual void handlePacket(Net::Connection *connection, uint16_t, const XmlPacket &packet); + virtual void sendRequest(); + virtual void handlePacket(const XmlPacket &packet); public: - DisconnectRequest(slot_type slot) : Request(slot) {} + DisconnectRequest(Net::Connection *connection, uint16_t requestId, slot_type slot) + : Request(connection, requestId, slot) {} }; } diff --git a/src/Common/Requests/FSInfoRequest.h b/src/Common/Requests/FSInfoRequest.h index 27a38ed..285f662 100644 --- a/src/Common/Requests/FSInfoRequest.h +++ b/src/Common/Requests/FSInfoRequest.h @@ -28,7 +28,8 @@ namespace Requests { class FSInfoRequest : public SimpleRequest { public: - FSInfoRequest(slot_type slot) : SimpleRequest("FSInfo", slot) {} + FSInfoRequest(Net::Connection *connection, uint16_t requestId, slot_type slot) + : SimpleRequest(connection, requestId, slot, "FSInfo") {} }; } diff --git a/src/Common/Requests/GSSAPIAuthRequest.cpp b/src/Common/Requests/GSSAPIAuthRequest.cpp index 7f4617a..07e516f 100644 --- a/src/Common/Requests/GSSAPIAuthRequest.cpp +++ b/src/Common/Requests/GSSAPIAuthRequest.cpp @@ -19,7 +19,6 @@ #include "GSSAPIAuthRequest.h" #include "../Logger.h" -#include "../XmlPacket.h" #include <Net/Connection.h> #include <cstring> @@ -37,7 +36,7 @@ GSSAPIAuthRequest::~GSSAPIAuthRequest() { gss_release_name(&minStat, &gssServiceName); } -void GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { +void GSSAPIAuthRequest::sendRequest() { OM_uint32 majStat, minStat; gss_buffer_desc buffer; @@ -70,7 +69,7 @@ void GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t reques ret.setType("AuthGSSAPI"); ret.addBinary("authToken", buffer.value, buffer.length); - if(!connection->send(ret.encode(requestId))) { + if(!sendPacket(ret)) { gss_release_buffer(&minStat, &buffer); return; } @@ -78,7 +77,7 @@ void GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t reques gss_release_buffer(&minStat, &buffer); } -void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet) { +void GSSAPIAuthRequest::handlePacket(const XmlPacket &packet) { if(packet.getType() != "AuthGSSAPI") { finishWithError(Exception(Exception::UNEXPECTED_PACKET)); return; // TODO Logging @@ -114,7 +113,7 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, uint16_t reque ret.setType("AuthGSSAPI"); ret.addBinary("authToken", sendBuffer.value, sendBuffer.length); - if(!connection->send(ret.encode(requestId))) { + if(!sendPacket(ret)) { gss_release_buffer(&minStat, &sendBuffer); return; } @@ -128,7 +127,7 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, uint16_t reque recvBuffer.value = std::malloc(recvBuffer.length); std::memcpy(recvBuffer.value, pkgData, recvBuffer.length); - const gnutls_datum_t *cert = connection->getPeerCertificate(); + const gnutls_datum_t *cert = getConnection()->getPeerCertificate(); sendBuffer.length = cert->size; sendBuffer.value = cert->data; @@ -140,7 +139,7 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, uint16_t reque if(majStat != GSS_S_COMPLETE) return; - connection->setAuthenticated(); + getConnection()->setAuthenticated(); Logger::log(Logger::VERBOSE, "Authentication complete."); majStat = gss_delete_sec_context(&minStat, &gssContext, &sendBuffer); @@ -154,7 +153,7 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, uint16_t reque ret.setType("AuthGSSAPI"); ret.addBinary("authToken", sendBuffer.value, sendBuffer.length); - if(!connection->send(ret.encode(requestId))) { + if(!sendPacket(ret)) { gss_release_buffer(&minStat, &sendBuffer); return; } diff --git a/src/Common/Requests/GSSAPIAuthRequest.h b/src/Common/Requests/GSSAPIAuthRequest.h index ca6195b..104af0c 100644 --- a/src/Common/Requests/GSSAPIAuthRequest.h +++ b/src/Common/Requests/GSSAPIAuthRequest.h @@ -38,12 +38,12 @@ class GSSAPIAuthRequest : public Request { bool gssContinue; - virtual void sendRequest(Net::Connection *connection, uint16_t requestId); - virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet); + virtual void sendRequest(); + virtual void handlePacket(const XmlPacket &packet); public: - GSSAPIAuthRequest(const std::string &serviceName0, slot_type slot) - : Request(slot), serviceName(serviceName0), gssServiceName(GSS_C_NO_NAME), gssContext(GSS_C_NO_CONTEXT), gssContinue(true) {} + GSSAPIAuthRequest(Net::Connection *connection, uint16_t requestId, slot_type slot, const std::string &serviceName0) + : Request(connection, requestId, slot), serviceName(serviceName0), gssServiceName(GSS_C_NO_NAME), gssContext(GSS_C_NO_CONTEXT), gssContinue(true) {} virtual ~GSSAPIAuthRequest(); }; diff --git a/src/Common/Requests/SimpleRequest.cpp b/src/Common/Requests/SimpleRequest.cpp index 018ac39..97426ae 100644 --- a/src/Common/Requests/SimpleRequest.cpp +++ b/src/Common/Requests/SimpleRequest.cpp @@ -19,17 +19,15 @@ #include "SimpleRequest.h" -#include <Net/Connection.h> - namespace Mad { namespace Common { namespace Requests { -void SimpleRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { +void SimpleRequest::sendRequest() { XmlPacket packet; packet.setType(type); - connection->send(packet.encode(requestId)); + sendPacket(packet); } } diff --git a/src/Common/Requests/SimpleRequest.h b/src/Common/Requests/SimpleRequest.h index 0426910..ca95eca 100644 --- a/src/Common/Requests/SimpleRequest.h +++ b/src/Common/Requests/SimpleRequest.h @@ -32,9 +32,10 @@ class SimpleRequest : public Request { protected: const std::string type; - virtual void sendRequest(Net::Connection *connection, uint16_t requestId); + virtual void sendRequest(); - SimpleRequest(const std::string &type0, slot_type slot) : Request(slot), type(type0) {} + SimpleRequest(Net::Connection *connection, uint16_t requestId, slot_type slot, const std::string &type0) + : Request(connection, requestId, slot), type(type0) {} }; } diff --git a/src/Common/Requests/StatusRequest.h b/src/Common/Requests/StatusRequest.h index d557358..ad89ec4 100644 --- a/src/Common/Requests/StatusRequest.h +++ b/src/Common/Requests/StatusRequest.h @@ -28,7 +28,8 @@ namespace Requests { class StatusRequest : public SimpleRequest { public: - StatusRequest(slot_type slot) : SimpleRequest("GetStatus", slot) {} + StatusRequest(Net::Connection *connection, uint16_t requestId, slot_type slot) + : SimpleRequest(connection, requestId, slot, "GetStatus") {} }; } diff --git a/src/Common/Requests/UserListRequest.h b/src/Common/Requests/UserListRequest.h index 918925c..69b0f05 100644 --- a/src/Common/Requests/UserListRequest.h +++ b/src/Common/Requests/UserListRequest.h @@ -28,7 +28,8 @@ namespace Requests { class UserListRequest : public SimpleRequest { public: - UserListRequest(slot_type slot) : SimpleRequest("ListUsers", slot) {} + UserListRequest(Net::Connection *connection, uint16_t requestId, slot_type slot) + : SimpleRequest(connection, requestId, slot, "ListUsers") {} }; } |