summaryrefslogtreecommitdiffstats
path: root/src/Core/ConnectionManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core/ConnectionManager.cpp')
-rw-r--r--src/Core/ConnectionManager.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index 78497e7..72bf07f 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -22,10 +22,15 @@
#include "RequestHandlers/CoreStatusRequestHandler.h"
#include "RequestHandlers/DaemonStatusRequestHandler.h"
#include "RequestHandlers/GSSAPIAuthRequestHandler.h"
+#include "RequestHandlers/IdentifyRequestHandler.h"
#include <Net/ServerConnection.h>
#include <Net/Packet.h>
#include <Net/Listener.h>
+
#include <unistd.h>
+#include <algorithm>
+
+#include <iostream>
namespace Mad {
namespace Core {
@@ -63,6 +68,7 @@ ConnectionManager::ConnectionManager() {
Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::CoreStatusRequestHandler>(Net::Packet::CORE_STATUS);
Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>(Net::Packet::DAEMON_STATUS);
Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH);
+ Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::IdentifyRequestHandler>(Net::Packet::IDENTIFY);
ConfigManager *configManager = ConfigManager::getConfigManager();
@@ -120,6 +126,15 @@ void ConnectionManager::handleConnections(std::list<Net::ServerConnection*>& con
++con;
}
else {
+ if((*con)->isIdentified()) {
+ for(std::map<std::string,Net::ServerConnection*>::iterator idCon = identifiedDaemonConnections.begin(); idCon != identifiedDaemonConnections.end(); ++idCon) {
+ if(idCon->second == *con) {
+ idCon->second = 0;
+ break;
+ }
+ }
+ }
+
Common::RequestManager::getRequestManager()->unregisterConnection(*con);
delete *con;
connections.erase(con++);
@@ -153,5 +168,36 @@ Net::Connection* ConnectionManager::getDaemonConnection(const std::string &name)
return daemon->second;
}
+void ConnectionManager::identifyDaemonConnection(Net::Connection *connection, const std::string &name) {
+ // TODO Error handling
+
+ if(connection->isIdentified()) {
+ std::cerr << "Already identified." << std::endl;
+ return;
+ }
+
+ 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;
+ }
+
+ std::map<std::string,Net::ServerConnection*>::iterator idCon = identifiedDaemonConnections.find(name);
+ if(idCon == identifiedDaemonConnections.end()) {
+ std::cerr << "Name not found." << std::endl;
+ return;
+ }
+
+ if(idCon->second) {
+ idCon->second->disconnect();
+ std::cerr << "Disconnecting old connection" << std::endl;
+ }
+
+ idCon->second = *con;
+ connection->setIdentified();
+
+ std::cerr << "Identified as '" << name << "'." << std::endl;
+}
+
}
}