From 4f8c2ba997d4f89b392a3b0683773a71d21a4f80 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 29 Sep 2008 22:58:39 +0200 Subject: Abfrage des Quell-Daemon-Namens eines Requests m?glich f?r RemoteLogger --- src/Core/ConnectionManager.cpp | 9 +++++++++ src/Core/ConnectionManager.h | 2 ++ src/Core/RequestHandlers/LogRequestHandler.cpp | 10 +++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index c83f3aa..93d6d3f 100644 --- a/src/Core/ConnectionManager.cpp +++ b/src/Core/ConnectionManager.cpp @@ -190,6 +190,15 @@ Net::Connection* ConnectionManager::getDaemonConnection(const std::string &name) return daemon->second; } +std::string ConnectionManager::getDaemonName(const Net::Connection *con) const throw (Common::Exception&) { + for(std::map::const_iterator daemon = identifiedDaemonConnections.begin(); daemon != identifiedDaemonConnections.end(); ++daemon) { + if(daemon->second == con) + return daemon->first; + } + + throw Common::Exception(Common::Exception::UNKNOWN_DAEMON); +} + void ConnectionManager::identifyDaemonConnection(Net::Connection *connection, const std::string &name) throw (Common::Exception&) { // TODO Logging diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h index cd470d9..4f3ff67 100644 --- a/src/Core/ConnectionManager.h +++ b/src/Core/ConnectionManager.h @@ -86,6 +86,8 @@ class ConnectionManager { void run(); Net::Connection* getDaemonConnection(const std::string &name) const throw (Common::Exception&); + std::string getDaemonName(const Net::Connection *con) const throw (Common::Exception&); + void identifyDaemonConnection(Net::Connection *connection, const std::string &name) throw (Common::Exception&); std::vector getDaemonList() const; }; diff --git a/src/Core/RequestHandlers/LogRequestHandler.cpp b/src/Core/RequestHandlers/LogRequestHandler.cpp index 5640159..6bda627 100644 --- a/src/Core/RequestHandlers/LogRequestHandler.cpp +++ b/src/Core/RequestHandlers/LogRequestHandler.cpp @@ -20,6 +20,7 @@ #include "LogRequestHandler.h" #include #include +#include "../ConnectionManager.h" #include #include #include @@ -40,7 +41,14 @@ void LogRequestHandler::handlePacket(Net::Connection *connection, const Net::Pac // TODO Require authentication Net::Packets::LogPacket logPacket(packet); - Common::RemoteLogger::log(logPacket.getCategory(), logPacket.getLevel(), logPacket.getTimestamp(), logPacket.getMessage().c_str(), std::string()); + + try { + Common::RemoteLogger::log(logPacket.getCategory(), logPacket.getLevel(), logPacket.getTimestamp(), logPacket.getMessage().c_str(), + ConnectionManager::getConnectionManager()->getDaemonName(connection)); + } + catch(Common::Exception &e) { + Common::Logger::logf(Common::Logger::ERROR, "Can't determine daemon name: %s", e.strerror().c_str()); + } connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId())); -- cgit v1.2.3