From 1af3eab2b23c67795b188e5edaf83bf47a8879bd Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 22 Sep 2008 18:24:26 +0200 Subject: NetworkLogger implementiert --- src/Core/ConnectionManager.cpp | 2 + src/Core/RequestHandlers/IdentifyRequestHandler.h | 6 +-- src/Core/RequestHandlers/LogRequestHandler.cpp | 51 +++++++++++++++++++++++ src/Core/RequestHandlers/LogRequestHandler.h | 41 ++++++++++++++++++ src/Core/RequestHandlers/Makefile.am | 4 +- src/Core/RequestHandlers/Makefile.in | 7 ++-- 6 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 src/Core/RequestHandlers/LogRequestHandler.cpp create mode 100644 src/Core/RequestHandlers/LogRequestHandler.h (limited to 'src/Core') diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index 8356594..272c04b 100644 --- a/src/Core/ConnectionManager.cpp +++ b/src/Core/ConnectionManager.cpp @@ -25,6 +25,7 @@ #include "RequestHandlers/DaemonStatusRequestHandler.h" #include "RequestHandlers/GSSAPIAuthRequestHandler.h" #include "RequestHandlers/IdentifyRequestHandler.h" +#include "RequestHandlers/LogRequestHandler.h" #include #include #include @@ -70,6 +71,7 @@ ConnectionManager::ConnectionManager() { Common::RequestManager::getRequestManager()->registerPacketType(Net::Packet::DAEMON_STATUS); Common::RequestManager::getRequestManager()->registerPacketType(Net::Packet::GSSAPI_AUTH); Common::RequestManager::getRequestManager()->registerPacketType(Net::Packet::IDENTIFY); + Common::RequestManager::getRequestManager()->registerPacketType(Net::Packet::LOG); ConfigManager *configManager = ConfigManager::getConfigManager(); diff --git a/src/Core/RequestHandlers/IdentifyRequestHandler.h b/src/Core/RequestHandlers/IdentifyRequestHandler.h index 58f10ba..f38fff6 100644 --- a/src/Core/RequestHandlers/IdentifyRequestHandler.h +++ b/src/Core/RequestHandlers/IdentifyRequestHandler.h @@ -17,8 +17,8 @@ * with this program. If not, see . */ -#ifndef MAD_COMMON_REQUESTHANDLERS_IDENTIFYREQUESTHANDLER_H_ -#define MAD_COMMON_REQUESTHANDLERS_IDENTIFYREQUESTHANDLER_H_ +#ifndef MAD_CORE_REQUESTHANDLERS_IDENTIFYREQUESTHANDLER_H_ +#define MAD_CORE_REQUESTHANDLERS_IDENTIFYREQUESTHANDLER_H_ #include @@ -38,4 +38,4 @@ class IdentifyRequestHandler : public Common::RequestHandler { } } -#endif /* MAD_COMMON_REQUESTHANDLERS_IDENTIFYREQUESTHANDLER_H_ */ +#endif /* MAD_CORE_REQUESTHANDLERS_IDENTIFYREQUESTHANDLER_H_ */ diff --git a/src/Core/RequestHandlers/LogRequestHandler.cpp b/src/Core/RequestHandlers/LogRequestHandler.cpp new file mode 100644 index 0000000..f2021b2 --- /dev/null +++ b/src/Core/RequestHandlers/LogRequestHandler.cpp @@ -0,0 +1,51 @@ +/* + * LogRequestHandler.cpp + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 . + */ + +#include "LogRequestHandler.h" +#include +#include +#include +#include + +namespace Mad { +namespace Core { +namespace RequestHandlers { + +void LogRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(packet.getType() != Net::Packet::LOG) { + Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); + connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + + signalFinished().emit(); + return; + } + + // TODO Require authentication + + Net::Packets::LogPacket logPacket(packet); + Common::Logger::logf(logPacket.getCategory(), logPacket.getLevel(), "Remote log: %s", logPacket.getMessage().c_str()); + + connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId())); + + signalFinished().emit(); +} + +} +} +} diff --git a/src/Core/RequestHandlers/LogRequestHandler.h b/src/Core/RequestHandlers/LogRequestHandler.h new file mode 100644 index 0000000..b82f24b --- /dev/null +++ b/src/Core/RequestHandlers/LogRequestHandler.h @@ -0,0 +1,41 @@ +/* + * LogRequestHandler.h + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 . + */ + +#ifndef MAD_CORE_REQUESTHANDLERS_LOGREQUESTHANDLER_H_ +#define MAD_CORE_REQUESTHANDLERS_LOGREQUESTHANDLER_H_ + +#include + +namespace Mad { +namespace Core { +namespace RequestHandlers { + +class LogRequestHandler : public Common::RequestHandler { + protected: + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + + public: + LogRequestHandler() {} +}; + +} +} +} + +#endif /* MAD_CORE_REQUESTHANDLERS_LOGREQUESTHANDLER_H_ */ diff --git a/src/Core/RequestHandlers/Makefile.am b/src/Core/RequestHandlers/Makefile.am index 2c65ceb..3c52634 100644 --- a/src/Core/RequestHandlers/Makefile.am +++ b/src/Core/RequestHandlers/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp +librequesthandlers_la_SOURCES = DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp -noinst_HEADERS = DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h +noinst_HEADERS = DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h diff --git a/src/Core/RequestHandlers/Makefile.in b/src/Core/RequestHandlers/Makefile.in index af6ffb4..a450ea0 100644 --- a/src/Core/RequestHandlers/Makefile.in +++ b/src/Core/RequestHandlers/Makefile.in @@ -50,7 +50,7 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) librequesthandlers_la_LIBADD = am_librequesthandlers_la_OBJECTS = DaemonListRequestHandler.lo \ DaemonStatusRequestHandler.lo GSSAPIAuthRequestHandler.lo \ - IdentifyRequestHandler.lo + IdentifyRequestHandler.lo LogRequestHandler.lo librequesthandlers_la_OBJECTS = $(am_librequesthandlers_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -189,8 +189,8 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = librequesthandlers.la -librequesthandlers_la_SOURCES = DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp -noinst_HEADERS = DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h +librequesthandlers_la_SOURCES = DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp +noinst_HEADERS = DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h all: all-am .SUFFIXES: @@ -246,6 +246,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequestHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GSSAPIAuthRequestHandler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/IdentifyRequestHandler.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LogRequestHandler.Plo@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -- cgit v1.2.3