From 7e87778a02f3d37865c10051a3f14038bbbcbaef Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 13 Sep 2008 03:59:58 +0200 Subject: Benutze weniger Inline-Funktionen --- src/Common/Makefile.am | 4 +- src/Common/Makefile.in | 10 +- src/Common/Request/DisconnectRequest.cpp | 67 ++++++++ src/Common/Request/DisconnectRequest.h | 47 +----- src/Common/Request/GSSAPIAuthRequest.cpp | 171 +++++++++++++++++++++ src/Common/Request/GSSAPIAuthRequest.h | 149 +----------------- src/Common/Request/IdentifyRequest.cpp | 62 ++++++++ src/Common/Request/IdentifyRequest.h | 43 +----- src/Common/Request/Makefile.am | 5 +- src/Common/Request/Makefile.in | 102 ++++++++++-- src/Common/Request/Request.h | 1 + .../RequestHandler/DisconnectRequestHandler.cpp | 46 ++++++ .../RequestHandler/DisconnectRequestHandler.h | 17 +- .../RequestHandler/IdentifyRequestHandler.cpp | 47 ++++++ src/Common/RequestHandler/IdentifyRequestHandler.h | 18 +-- src/Common/RequestHandler/Makefile.am | 5 +- src/Common/RequestHandler/Makefile.in | 101 ++++++++++-- src/Common/RequestManager.cpp | 62 +++++++- src/Common/RequestManager.h | 59 +------ src/Common/Util.cpp | 50 ++++++ src/Common/Util.h | 27 +--- 21 files changed, 719 insertions(+), 374 deletions(-) create mode 100644 src/Common/Request/DisconnectRequest.cpp create mode 100644 src/Common/Request/GSSAPIAuthRequest.cpp create mode 100644 src/Common/Request/IdentifyRequest.cpp create mode 100644 src/Common/RequestHandler/DisconnectRequestHandler.cpp create mode 100644 src/Common/RequestHandler/IdentifyRequestHandler.cpp create mode 100644 src/Common/Util.cpp (limited to 'src/Common') diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am index 6df8a62..c282538 100644 --- a/src/Common/Makefile.am +++ b/src/Common/Makefile.am @@ -1,7 +1,7 @@ SUBDIRS = Backends Request RequestHandler noinst_LTLIBRARIES = libcommon.la -libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp SystemBackend.cpp -libcommon_la_LIBADD = Backends/libbackends.la +libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp SystemBackend.cpp Util.cpp +libcommon_la_LIBADD = Backends/libbackends.la Request/librequest.la RequestHandler/librequesthandler.la noinst_HEADERS = ConfigManager.h RequestManager.h SystemBackend.h Util.h diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in index d2e1f59..39ba3b6 100644 --- a/src/Common/Makefile.in +++ b/src/Common/Makefile.in @@ -44,9 +44,10 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) -libcommon_la_DEPENDENCIES = Backends/libbackends.la +libcommon_la_DEPENDENCIES = Backends/libbackends.la \ + Request/librequest.la RequestHandler/librequesthandler.la am_libcommon_la_OBJECTS = ConfigManager.lo RequestManager.lo \ - SystemBackend.lo + SystemBackend.lo Util.lo libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -194,8 +195,8 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = Backends Request RequestHandler noinst_LTLIBRARIES = libcommon.la -libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp SystemBackend.cpp -libcommon_la_LIBADD = Backends/libbackends.la +libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp SystemBackend.cpp Util.cpp +libcommon_la_LIBADD = Backends/libbackends.la Request/librequest.la RequestHandler/librequesthandler.la noinst_HEADERS = ConfigManager.h RequestManager.h SystemBackend.h Util.h all: all-recursive @@ -251,6 +252,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConfigManager.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestManager.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemBackend.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Util.Plo@am__quote@ .cpp.o: @am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/src/Common/Request/DisconnectRequest.cpp b/src/Common/Request/DisconnectRequest.cpp new file mode 100644 index 0000000..0f8a3c0 --- /dev/null +++ b/src/Common/Request/DisconnectRequest.cpp @@ -0,0 +1,67 @@ +/* + * DisconnectRequest.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 "DisconnectRequest.h" +#include "../RequestManager.h" + +namespace Mad { +namespace Common { +namespace Request { + +bool DisconnectRequest::send(Net::Connection *connection, RequestManager &requestManager, const sigc::slot &callback) { + DisconnectRequest *request = new DisconnectRequest(); + + request->finished.connect(callback); + + if(requestManager.sendRequest(connection, request)) + return true; + + delete request; + return false; +} + +bool DisconnectRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + if(isSent()) + return false; + + if(!connection->send(Net::Packet(Net::Packet::DISCONNECT, requestId))) + return false; + + setSent(); + return true; +} + +bool DisconnectRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(isFinished()) + return false; + + if(packet.getType() != Net::Packet::OK) + return false; // TODO Logging + + connection->disconnect(); + + finished(); + + setFinished(); + return true; +} + +} +} +} diff --git a/src/Common/Request/DisconnectRequest.h b/src/Common/Request/DisconnectRequest.h index 1b2d467..136ef73 100644 --- a/src/Common/Request/DisconnectRequest.h +++ b/src/Common/Request/DisconnectRequest.h @@ -21,60 +21,27 @@ #define MAD_COMMON_REQUEST_DISCONNECTREQUEST_H_ #include "Request.h" -#include "../RequestManager.h" -#include -#include #include namespace Mad { namespace Common { + +class RequestManager; + namespace Request { -class DisconnectRequest: public Request { +class DisconnectRequest : public Request { private: sigc::signal finished; DisconnectRequest() {} public: - static bool send(Net::Connection *connection, RequestManager &requestManager, const sigc::slot &callback) { - DisconnectRequest *request = new DisconnectRequest(); - - request->finished.connect(callback); - - if(requestManager.sendRequest(connection, request)) - return true; - - delete request; - return false; - } - - virtual bool sendRequest(Net::Connection *connection, uint16_t requestId) { - if(isSent()) - return false; - - if(!connection->send(Net::Packet(Net::Packet::DISCONNECT, requestId))) - return false; - - setSent(); - return true; - } - - virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(isFinished()) - return false; - - if(packet.getType() != Net::Packet::OK) - return false; // TODO Logging - - connection->disconnect(); - - finished(); + static bool send(Net::Connection *connection, RequestManager &requestManager, const sigc::slot &callback); - setFinished(); - return true; - } + virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); + virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } diff --git a/src/Common/Request/GSSAPIAuthRequest.cpp b/src/Common/Request/GSSAPIAuthRequest.cpp new file mode 100644 index 0000000..4387f97 --- /dev/null +++ b/src/Common/Request/GSSAPIAuthRequest.cpp @@ -0,0 +1,171 @@ +/* + * GSSAPIAuthRequest.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 "GSSAPIAuthRequest.h" +#include "../RequestManager.h" + +#include + +#include + +namespace Mad { +namespace Common { +namespace Request { + +// TODO Logging & error handling! + +GSSAPIAuthRequest::~GSSAPIAuthRequest() { + OM_uint32 minStat; + + if(gssServiceName != GSS_C_NO_NAME) + gss_release_name(&minStat, &gssServiceName); +} + +bool GSSAPIAuthRequest::send(Net::Connection *connection, RequestManager &requestManager, const std::string &serviceName0) { + GSSAPIAuthRequest *request = new GSSAPIAuthRequest(serviceName0); + + if(requestManager.sendRequest(connection, request)) + return true; + + delete request; + return false; +} + +bool GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + if(isSent()) + return false; + + OM_uint32 majStat, minStat; + gss_buffer_desc buffer; + + buffer.length = serviceName.length(); + buffer.value = std::malloc(buffer.length); + std::memcpy(buffer.value, serviceName.c_str(), buffer.length); + + majStat = gss_import_name(&minStat, &buffer, GSS_C_NT_HOSTBASED_SERVICE, &gssServiceName); + + std::free(buffer.value); + + if(majStat != GSS_S_COMPLETE) { + gssServiceName = GSS_C_NO_NAME; + return false; + } + + majStat = gss_init_sec_context(&minStat, GSS_C_NO_CREDENTIAL, &gssContext, gssServiceName, GSS_C_NO_OID, GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG, + 0, GSS_C_NO_CHANNEL_BINDINGS, GSS_C_NO_BUFFER, 0, &buffer, 0, 0); + + if(majStat == GSS_S_COMPLETE) { + std::cout << "GSS context established." << std::endl; + gssContinue = false; + } + else if(majStat != GSS_S_CONTINUE_NEEDED) { + gss_release_buffer(&minStat, &buffer); + return false; + } + + if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, requestId, buffer.value, buffer.length))) { + gss_release_buffer(&minStat, &buffer); + return false; + } + + gss_release_buffer(&minStat, &buffer); + + setSent(); + return true; +} + +bool GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(isFinished()) + return false; + + if(packet.getType() != Net::Packet::GSSAPI_AUTH) + return false; // TODO Logging + + OM_uint32 majStat, minStat; + gss_buffer_desc recvBuffer, sendBuffer; + + if(gssContinue) { + recvBuffer.length = packet.getLength(); + recvBuffer.value = std::malloc(recvBuffer.length); + std::memcpy(recvBuffer.value, packet.getData(), recvBuffer.length); + + majStat = gss_init_sec_context(&minStat, GSS_C_NO_CREDENTIAL, &gssContext, gssServiceName, GSS_C_NO_OID, GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG | GSS_C_INTEG_FLAG, + 0, GSS_C_NO_CHANNEL_BINDINGS, &recvBuffer, 0, &sendBuffer, 0, 0); + + std::free(recvBuffer.value); + + if(majStat == GSS_S_COMPLETE) { + std::cout << "GSS context established." << std::endl; + gssContinue = false; + } + else if(majStat != GSS_S_CONTINUE_NEEDED) { + gss_release_buffer(&minStat, &sendBuffer); + return false; + } + + if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, packet.getRequestId(), sendBuffer.value, sendBuffer.length))) { + gss_release_buffer(&minStat, &sendBuffer); + return false; + } + + gss_release_buffer(&minStat, &sendBuffer); + } + else { + recvBuffer.length = packet.getLength(); + recvBuffer.value = std::malloc(recvBuffer.length); + std::memcpy(recvBuffer.value, packet.getData(), recvBuffer.length); + + const gnutls_datum_t *cert = connection->getPeerCertificate(); + + sendBuffer.length = cert->size; + sendBuffer.value = cert->data; + + majStat = gss_verify_mic(&minStat, gssContext, &sendBuffer, &recvBuffer, 0); + + std::free(recvBuffer.value); + + if(majStat != GSS_S_COMPLETE) + return false; + + connection->setAuthenticated(); + std::cout << "Authentication complete." << std::endl; + + majStat = gss_delete_sec_context(&minStat, &gssContext, &sendBuffer); + + if(majStat != GSS_S_COMPLETE) { + gss_release_buffer(&minStat, &sendBuffer); + return false; + } + + if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, packet.getRequestId(), sendBuffer.value, sendBuffer.length))) { + gss_release_buffer(&minStat, &sendBuffer); + return false; + } + + gss_release_buffer(&minStat, &sendBuffer); + + setFinished(); + } + + return true; +} + +} +} +} diff --git a/src/Common/Request/GSSAPIAuthRequest.h b/src/Common/Request/GSSAPIAuthRequest.h index 6882f36..dd2afbb 100644 --- a/src/Common/Request/GSSAPIAuthRequest.h +++ b/src/Common/Request/GSSAPIAuthRequest.h @@ -21,19 +21,15 @@ #define MAD_COMMON_REQUEST_GSSAPIAUTHREQUEST_H_ #include "Request.h" -#include "../RequestManager.h" -#include -#include #include -#include #include -#include - namespace Mad { namespace Common { -namespace Request { +class RequestManager; + +namespace Request { // TODO Logging & error handling! @@ -48,147 +44,16 @@ class GSSAPIAuthRequest : public Request { GSSAPIAuthRequest(const std::string &serviceName0) : serviceName(serviceName0), gssServiceName(GSS_C_NO_NAME), gssContext(GSS_C_NO_CONTEXT), gssContinue(true) {} public: - virtual ~GSSAPIAuthRequest() { - OM_uint32 minStat; - - if(gssServiceName != GSS_C_NO_NAME) - gss_release_name(&minStat, &gssServiceName); - } - - static bool send(Net::Connection *connection, RequestManager &requestManager, const std::string &serviceName0) { - GSSAPIAuthRequest *request = new GSSAPIAuthRequest(serviceName0); - - if(requestManager.sendRequest(connection, request)) - return true; - - delete request; - return false; - } - - virtual bool sendRequest(Net::Connection *connection, uint16_t requestId) { - if(isSent()) - return false; - - OM_uint32 majStat, minStat; - gss_buffer_desc buffer; - - buffer.length = serviceName.length(); - buffer.value = std::malloc(buffer.length); - std::memcpy(buffer.value, serviceName.c_str(), buffer.length); - - majStat = gss_import_name(&minStat, &buffer, GSS_C_NT_HOSTBASED_SERVICE, &gssServiceName); - - std::free(buffer.value); - - if(majStat != GSS_S_COMPLETE) { - gssServiceName = GSS_C_NO_NAME; - return false; - } - - majStat = gss_init_sec_context(&minStat, GSS_C_NO_CREDENTIAL, &gssContext, gssServiceName, GSS_C_NO_OID, GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG, - 0, GSS_C_NO_CHANNEL_BINDINGS, GSS_C_NO_BUFFER, 0, &buffer, 0, 0); - - if(majStat == GSS_S_COMPLETE) { - std::cout << "GSS context established." << std::endl; - gssContinue = false; - } - else if(majStat != GSS_S_CONTINUE_NEEDED) { - gss_release_buffer(&minStat, &buffer); - return false; - } - - if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, requestId, buffer.value, buffer.length))) { - gss_release_buffer(&minStat, &buffer); - return false; - } - - gss_release_buffer(&minStat, &buffer); - - setSent(); - return true; - } - - virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(isFinished()) - return false; + virtual ~GSSAPIAuthRequest(); - if(packet.getType() != Net::Packet::GSSAPI_AUTH) - return false; // TODO Logging + static bool send(Net::Connection *connection, RequestManager &requestManager, const std::string &serviceName0); - OM_uint32 majStat, minStat; - gss_buffer_desc recvBuffer, sendBuffer; - - if(gssContinue) { - recvBuffer.length = packet.getLength(); - recvBuffer.value = std::malloc(recvBuffer.length); - std::memcpy(recvBuffer.value, packet.getData(), recvBuffer.length); - - majStat = gss_init_sec_context(&minStat, GSS_C_NO_CREDENTIAL, &gssContext, gssServiceName, GSS_C_NO_OID, GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG | GSS_C_INTEG_FLAG, - 0, GSS_C_NO_CHANNEL_BINDINGS, &recvBuffer, 0, &sendBuffer, 0, 0); - - std::free(recvBuffer.value); - - if(majStat == GSS_S_COMPLETE) { - std::cout << "GSS context established." << std::endl; - gssContinue = false; - } - else if(majStat != GSS_S_CONTINUE_NEEDED) { - gss_release_buffer(&minStat, &sendBuffer); - return false; - } - - if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, packet.getRequestId(), sendBuffer.value, sendBuffer.length))) { - gss_release_buffer(&minStat, &sendBuffer); - return false; - } - - gss_release_buffer(&minStat, &sendBuffer); - } - else { - recvBuffer.length = packet.getLength(); - recvBuffer.value = std::malloc(recvBuffer.length); - std::memcpy(recvBuffer.value, packet.getData(), recvBuffer.length); - - const gnutls_datum_t *cert = connection->getPeerCertificate(); - - sendBuffer.length = cert->size; - sendBuffer.value = cert->data; - - majStat = gss_verify_mic(&minStat, gssContext, &sendBuffer, &recvBuffer, 0); - - std::free(recvBuffer.value); - - if(majStat != GSS_S_COMPLETE) - return false; - - connection->setAuthenticated(); - std::cout << "Authentication complete." << std::endl; - - majStat = gss_delete_sec_context(&minStat, &gssContext, &sendBuffer); - - if(majStat != GSS_S_COMPLETE) { - gss_release_buffer(&minStat, &sendBuffer); - return false; - } - - if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, packet.getRequestId(), sendBuffer.value, sendBuffer.length))) { - gss_release_buffer(&minStat, &sendBuffer); - return false; - } - - gss_release_buffer(&minStat, &sendBuffer); - - setFinished(); - } - - return true; - } + virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); + virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } - } - } #endif /* MAD_COMMON_REQUEST_GSSAPIAUTHREQUEST_H_ */ diff --git a/src/Common/Request/IdentifyRequest.cpp b/src/Common/Request/IdentifyRequest.cpp new file mode 100644 index 0000000..5fe4227 --- /dev/null +++ b/src/Common/Request/IdentifyRequest.cpp @@ -0,0 +1,62 @@ +/* + * IdentifyRequest.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 "IdentifyRequest.h" +#include "../RequestManager.h" +#include + +namespace Mad { +namespace Common { +namespace Request { + +bool IdentifyRequest::send(Net::Connection *connection, RequestManager &requestManager, const std::string &hostname0) { + IdentifyRequest *request = new IdentifyRequest(hostname0); + + if(requestManager.sendRequest(connection, request)) + return true; + + delete request; + return false; +} + +bool IdentifyRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + if(isSent()) + return false; + + if(!connection->send(Net::Packet(Net::Packet::IDENTIFY, requestId, hostname.c_str(), hostname.length()))) + return false; + + setSent(); + return true; +} + +bool IdentifyRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { + if(isFinished()) + return false; + + if(packet.getType() != Net::Packet::OK) + return false; // TODO Logging + + setFinished(); + return true; +} + +} +} +} diff --git a/src/Common/Request/IdentifyRequest.h b/src/Common/Request/IdentifyRequest.h index 2637e47..276da23 100644 --- a/src/Common/Request/IdentifyRequest.h +++ b/src/Common/Request/IdentifyRequest.h @@ -21,55 +21,26 @@ #define MAD_COMMON_REQUEST_IDENTIFYREQUEST_H_ #include "Request.h" -#include "../RequestManager.h" -#include -#include #include -#include - namespace Mad { namespace Common { + +class RequestManager; + namespace Request { -class IdentifyRequest: public Request { +class IdentifyRequest : public Request { private: IdentifyRequest(const std::string &hostname0) : hostname(hostname0) {} std::string hostname; public: - static bool send(Net::Connection *connection, RequestManager &requestManager, const std::string &hostname0) { - IdentifyRequest *request = new IdentifyRequest(hostname0); - - if(requestManager.sendRequest(connection, request)) - return true; - - delete request; - return false; - } - - virtual bool sendRequest(Net::Connection *connection, uint16_t requestId) { - if(isSent()) - return false; - - if(!connection->send(Net::Packet(Net::Packet::IDENTIFY, requestId, hostname.c_str(), hostname.length()))) - return false; - - setSent(); - return true; - } - - virtual bool handlePacket(Net::Connection*, const Net::Packet &packet) { - if(isFinished()) - return false; - - if(packet.getType() != Net::Packet::OK) - return false; // TODO Logging + static bool send(Net::Connection *connection, RequestManager &requestManager, const std::string &hostname0); - setFinished(); - return true; - } + virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); + virtual bool handlePacket(Net::Connection*, const Net::Packet &packet); }; } diff --git a/src/Common/Request/Makefile.am b/src/Common/Request/Makefile.am index 64c5078..ef75dfe 100644 --- a/src/Common/Request/Makefile.am +++ b/src/Common/Request/Makefile.am @@ -1 +1,4 @@ -noinst_HEADERS = DisconnectRequest.h GSSAPIAuthRequest.h IdentifyRequest.h Request.h +noinst_LTLIBRARIES = librequest.la +librequest_la_SOURCES = DisconnectRequest.cpp GSSAPIAuthRequest.cpp IdentifyRequest.cpp + +noinst_HEADERS = DisconnectRequest.h GSSAPIAuthRequest.h IdentifyRequest.h Request.h diff --git a/src/Common/Request/Makefile.in b/src/Common/Request/Makefile.in index 4aa720d..f44ec75 100644 --- a/src/Common/Request/Makefile.in +++ b/src/Common/Request/Makefile.in @@ -14,6 +14,7 @@ @SET_MAKE@ + VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -42,8 +43,25 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = -SOURCES = -DIST_SOURCES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +librequest_la_LIBADD = +am_librequest_la_OBJECTS = DisconnectRequest.lo GSSAPIAuthRequest.lo \ + IdentifyRequest.lo +librequest_la_OBJECTS = $(am_librequest_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(librequest_la_SOURCES) +DIST_SOURCES = $(librequest_la_SOURCES) HEADERS = $(noinst_HEADERS) ETAGS = etags CTAGS = ctags @@ -164,10 +182,13 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ +noinst_LTLIBRARIES = librequest.la +librequest_la_SOURCES = DisconnectRequest.cpp GSSAPIAuthRequest.cpp IdentifyRequest.cpp noinst_HEADERS = DisconnectRequest.h GSSAPIAuthRequest.h IdentifyRequest.h Request.h all: all-am .SUFFIXES: +.SUFFIXES: .cpp .lo .o .obj $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ @@ -198,6 +219,48 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +librequest.la: $(librequest_la_OBJECTS) $(librequest_la_DEPENDENCIES) + $(CXXLINK) $(librequest_la_OBJECTS) $(librequest_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DisconnectRequest.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GSSAPIAuthRequest.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/IdentifyRequest.Plo@am__quote@ + +.cpp.o: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< + +.cpp.obj: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cpp.lo: +@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< + mostlyclean-libtool: -rm -f *.lo @@ -279,7 +342,7 @@ distdir: $(DISTFILES) done check-am: all-am check: check-am -all-am: Makefile $(HEADERS) +all-am: Makefile $(LTLIBRARIES) $(HEADERS) installdirs: install: install-am install-exec: install-exec-am @@ -307,11 +370,14 @@ maintainer-clean-generic: @echo "it deletes files that may require special tools to rebuild." clean: clean-am -clean-am: clean-generic clean-libtool mostlyclean-am +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am distclean: distclean-am + -rm -rf ./$(DEPDIR) -rm -f Makefile -distclean-am: clean-am distclean-generic distclean-tags +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags dvi: dvi-am @@ -342,12 +408,14 @@ install-ps: install-ps-am installcheck-am: maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am -mostlyclean-am: mostlyclean-generic mostlyclean-libtool +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf: pdf-am @@ -362,17 +430,17 @@ uninstall-am: .MAKE: install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libtool ctags distclean distclean-generic \ - distclean-libtool distclean-tags distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-pdf install-pdf-am \ - install-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-generic \ - mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \ - uninstall-am + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/src/Common/Request/Request.h b/src/Common/Request/Request.h index 5087992..c87d87d 100644 --- a/src/Common/Request/Request.h +++ b/src/Common/Request/Request.h @@ -21,6 +21,7 @@ #define MAD_COMMON_REQUEST_REQUEST_H_ #include "../RequestHandler/RequestHandler.h" +#include namespace Mad { namespace Common { diff --git a/src/Common/RequestHandler/DisconnectRequestHandler.cpp b/src/Common/RequestHandler/DisconnectRequestHandler.cpp new file mode 100644 index 0000000..af05457 --- /dev/null +++ b/src/Common/RequestHandler/DisconnectRequestHandler.cpp @@ -0,0 +1,46 @@ +/* + * DisconnectRequestHandler.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 "DisconnectRequestHandler.h" +#include + +namespace Mad { +namespace Common { +namespace RequestHandler { + +bool DisconnectRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(isFinished()) + return false; + + if(packet.getType() != Net::Packet::DISCONNECT) + return false; // TODO Logging + + if(!connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()))) + return false; + + connection->disconnect(); + + setFinished(); + + return true; +} + +} +} +} diff --git a/src/Common/RequestHandler/DisconnectRequestHandler.h b/src/Common/RequestHandler/DisconnectRequestHandler.h index 9da825a..90429c4 100644 --- a/src/Common/RequestHandler/DisconnectRequestHandler.h +++ b/src/Common/RequestHandler/DisconnectRequestHandler.h @@ -30,22 +30,7 @@ class DisconnectRequestHandler : public RequestHandler { public: DisconnectRequestHandler() {} - virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(isFinished()) - return false; - - if(packet.getType() != Net::Packet::DISCONNECT) - return false; // TODO Logging - - if(!connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()))) - return false; - - connection->disconnect(); - - setFinished(); - - return true; - } + virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } diff --git a/src/Common/RequestHandler/IdentifyRequestHandler.cpp b/src/Common/RequestHandler/IdentifyRequestHandler.cpp new file mode 100644 index 0000000..8a6ea40 --- /dev/null +++ b/src/Common/RequestHandler/IdentifyRequestHandler.cpp @@ -0,0 +1,47 @@ +/* + * IdentifyRequestHandler.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 "IdentifyRequestHandler.h" +#include + +namespace Mad { +namespace Common { +namespace RequestHandler { + +bool IdentifyRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { + if(isFinished()) + return false; + + if(packet.getType() != Net::Packet::IDENTIFY) + return false; // TODO Logging + + // TODO Require authentication + // TODO Save identity information + + if(!connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()))) + return false; + + setFinished(); + + return true; +} + +} +} +} diff --git a/src/Common/RequestHandler/IdentifyRequestHandler.h b/src/Common/RequestHandler/IdentifyRequestHandler.h index a8082c6..7ac2e3e 100644 --- a/src/Common/RequestHandler/IdentifyRequestHandler.h +++ b/src/Common/RequestHandler/IdentifyRequestHandler.h @@ -30,23 +30,7 @@ class IdentifyRequestHandler : public RequestHandler { public: IdentifyRequestHandler() {} - virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(isFinished()) - return false; - - if(packet.getType() != Net::Packet::IDENTIFY) - return false; // TODO Logging - - // TODO Require authentication - // TODO Save identity information - - if(!connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()))) - return false; - - setFinished(); - - return true; - } + virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } diff --git a/src/Common/RequestHandler/Makefile.am b/src/Common/RequestHandler/Makefile.am index 146c4cd..69e6c77 100644 --- a/src/Common/RequestHandler/Makefile.am +++ b/src/Common/RequestHandler/Makefile.am @@ -1,2 +1,5 @@ -noinst_HEADERS = DisconnectRequestHandler.h IdentifyRequestHandler.h RequestHandler.h +noinst_LTLIBRARIES = librequesthandler.la +librequesthandler_la_SOURCES = DisconnectRequestHandler.cpp IdentifyRequestHandler.cpp + +noinst_HEADERS = DisconnectRequestHandler.h IdentifyRequestHandler.h RequestHandler.h diff --git a/src/Common/RequestHandler/Makefile.in b/src/Common/RequestHandler/Makefile.in index 066da38..0140d46 100644 --- a/src/Common/RequestHandler/Makefile.in +++ b/src/Common/RequestHandler/Makefile.in @@ -14,6 +14,7 @@ @SET_MAKE@ + VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -42,8 +43,25 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = -SOURCES = -DIST_SOURCES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +librequesthandler_la_LIBADD = +am_librequesthandler_la_OBJECTS = DisconnectRequestHandler.lo \ + IdentifyRequestHandler.lo +librequesthandler_la_OBJECTS = $(am_librequesthandler_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(librequesthandler_la_SOURCES) +DIST_SOURCES = $(librequesthandler_la_SOURCES) HEADERS = $(noinst_HEADERS) ETAGS = etags CTAGS = ctags @@ -164,10 +182,13 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ +noinst_LTLIBRARIES = librequesthandler.la +librequesthandler_la_SOURCES = DisconnectRequestHandler.cpp IdentifyRequestHandler.cpp noinst_HEADERS = DisconnectRequestHandler.h IdentifyRequestHandler.h RequestHandler.h all: all-am .SUFFIXES: +.SUFFIXES: .cpp .lo .o .obj $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ @@ -198,6 +219,47 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +librequesthandler.la: $(librequesthandler_la_OBJECTS) $(librequesthandler_la_DEPENDENCIES) + $(CXXLINK) $(librequesthandler_la_OBJECTS) $(librequesthandler_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DisconnectRequestHandler.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/IdentifyRequestHandler.Plo@am__quote@ + +.cpp.o: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< + +.cpp.obj: +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cpp.lo: +@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< + mostlyclean-libtool: -rm -f *.lo @@ -279,7 +341,7 @@ distdir: $(DISTFILES) done check-am: all-am check: check-am -all-am: Makefile $(HEADERS) +all-am: Makefile $(LTLIBRARIES) $(HEADERS) installdirs: install: install-am install-exec: install-exec-am @@ -307,11 +369,14 @@ maintainer-clean-generic: @echo "it deletes files that may require special tools to rebuild." clean: clean-am -clean-am: clean-generic clean-libtool mostlyclean-am +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am distclean: distclean-am + -rm -rf ./$(DEPDIR) -rm -f Makefile -distclean-am: clean-am distclean-generic distclean-tags +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags dvi: dvi-am @@ -342,12 +407,14 @@ install-ps: install-ps-am installcheck-am: maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am -mostlyclean-am: mostlyclean-generic mostlyclean-libtool +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf: pdf-am @@ -362,17 +429,17 @@ uninstall-am: .MAKE: install-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libtool ctags distclean distclean-generic \ - distclean-libtool distclean-tags distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-pdf install-pdf-am \ - install-ps install-ps-am install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-generic \ - mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \ - uninstall-am + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index e71fd07..0dc7a48 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -27,11 +27,26 @@ namespace Mad { namespace Common { -RequestManager::RequestManager(bool core) : requestId(core ? -2 : -1) { - registerPacketType(Net::Packet::DISCONNECT); - registerPacketType(Net::Packet::IDENTIFY); +RequestHandler::RequestHandler* RequestManager::RequestMap::findRequest(uint16_t id) { + iterator it = find(id); + if(it == end()) + return 0; + + return it->second; +} + +bool RequestManager::RequestMap::deleteRequest(uint16_t id) { + iterator it = find(id); + if(it == end()) + return false; + + delete it->second; + + erase(it); + return true; } + void RequestManager::receiveHandler(Net::Connection *connection, const Net::Packet &packet) { std::map::iterator it = requestMaps.find(connection); @@ -92,5 +107,46 @@ bool RequestManager::sendRequest(Net::Connection *connection, Request::Request * return true; } +void RequestManager::registerConnection(Net::Connection *connection) { + requestMaps.insert(std::make_pair(connection, new RequestMap())); + + connection->signalReceive().connect(sigc::mem_fun(this, &RequestManager::receiveHandler)); +} + +void RequestManager::unregisterConnection(Net::Connection *connection) { + std::map::iterator it = requestMaps.find(connection); + + if(it == requestMaps.end()) + return; + + delete it->second; + + requestMaps.erase(it); +} + +void RequestManager::unregisterPacketType(Net::Packet::Type type) { + std::map::iterator it = requestHandlerFactories.find(type); + + if(it == requestHandlerFactories.end()) + return; + + delete it->second; + + requestHandlerFactories.erase(it); +} + +RequestManager::RequestManager(bool core) : requestId(core ? -2 : -1) { + registerPacketType(Net::Packet::DISCONNECT); + registerPacketType(Net::Packet::IDENTIFY); +} + +RequestManager::~RequestManager() { + for(std::map::iterator it = requestMaps.begin(); it != requestMaps.end(); ++it) + delete it->second; + + for(std::map::iterator it = requestHandlerFactories.begin(); it != requestHandlerFactories.end(); ++it) + delete it->second; +} + } } diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h index 68510f9..e7a8e7b 100644 --- a/src/Common/RequestManager.h +++ b/src/Common/RequestManager.h @@ -41,7 +41,6 @@ class RequestManager { public: RequestMap() {} - ~RequestMap() { for(iterator it = begin(); it != end(); ++it) delete it->second; @@ -51,24 +50,8 @@ class RequestManager { return insert(std::make_pair(id, info)).second; } - RequestHandler::RequestHandler* findRequest(uint16_t id) { - iterator it = find(id); - if(it == end()) - return 0; - - return it->second; - } - - bool deleteRequest(uint16_t id) { - iterator it = find(id); - if(it == end()) - return false; - - delete it->second; - - erase(it); - return true; - } + RequestHandler::RequestHandler* findRequest(uint16_t id); + bool deleteRequest(uint16_t id); }; class RequestHandlerFactory { @@ -103,49 +86,19 @@ class RequestManager { void receiveHandler(Net::Connection *connection, const Net::Packet &packet); public: - void registerConnection(Net::Connection *connection) { - requestMaps.insert(std::make_pair(connection, new RequestMap())); - - connection->signalReceive().connect(sigc::mem_fun(this, &RequestManager::receiveHandler)); - } - - void unregisterConnection(Net::Connection *connection) { - std::map::iterator it = requestMaps.find(connection); - - if(it == requestMaps.end()) - return; - - delete it->second; - - requestMaps.erase(it); - } + void registerConnection(Net::Connection *connection); + void unregisterConnection(Net::Connection *connection); template void registerPacketType(Net::Packet::Type type) { requestHandlerFactories.insert(std::make_pair(type, new SpecificRequestHandlerFactory())); } - void unregisterPacketType(Net::Packet::Type type) { - std::map::iterator it = requestHandlerFactories.find(type); - - if(it == requestHandlerFactories.end()) - return; - - delete it->second; - - requestHandlerFactories.erase(it); - } + void unregisterPacketType(Net::Packet::Type type); bool sendRequest(Net::Connection *connection, Request::Request *request); RequestManager(bool core); - - virtual ~RequestManager() { - for(std::map::iterator it = requestMaps.begin(); it != requestMaps.end(); ++it) - delete it->second; - - for(std::map::iterator it = requestHandlerFactories.begin(); it != requestHandlerFactories.end(); ++it) - delete it->second; - } + virtual ~RequestManager(); }; } diff --git a/src/Common/Util.cpp b/src/Common/Util.cpp new file mode 100644 index 0000000..2bf4d50 --- /dev/null +++ b/src/Common/Util.cpp @@ -0,0 +1,50 @@ +/* + * Util.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 "Util.h" + +namespace Mad { +namespace Common { + +std::string Util::tolower(const std::string &str) { + std::string ret; + + for(std::string::const_iterator c = str.begin(); c != str.end(); ++c) + ret += std::tolower(*c); + + return ret; +} + +std::string Util::trim(const std::string &str) { + size_t beg, end; + + beg = str.find_first_not_of(" \t"); + end = str.find_last_not_of(" \t"); + + if(beg == std::string::npos) + beg = 0; + + if(end != std::string::npos) + end = end-beg+1; + + return str.substr(beg, end); +} + +} +} diff --git a/src/Common/Util.h b/src/Common/Util.h index 19f87b9..8df5cac 100644 --- a/src/Common/Util.h +++ b/src/Common/Util.h @@ -21,8 +21,6 @@ #define MAD_COMMON_UTIL_H_ #include -#include -#include namespace Mad { namespace Common { @@ -32,29 +30,8 @@ class Util { Util(); public: - static std::string tolower(const std::string &str) { - std::string ret; - - for(std::string::const_iterator c = str.begin(); c != str.end(); ++c) - ret += std::tolower(*c); - - return ret; - } - - static std::string trim(const std::string &str) { - size_t beg, end; - - beg = str.find_first_not_of(" \t"); - end = str.find_last_not_of(" \t"); - - if(beg == std::string::npos) - beg = 0; - - if(end != std::string::npos) - end = end-beg+1; - - return str.substr(beg, end); - } + static std::string tolower(const std::string &str); + static std::string trim(const std::string &str); }; } -- cgit v1.2.3