summaryrefslogtreecommitdiffstats
path: root/src/Core
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-02-13 00:00:05 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-02-13 00:00:05 +0100
commit04363ca342914ba75e693edb876cbe535839fa79 (patch)
treed1309d7b0f6288a8250e972e5cab2546f2a77609 /src/Core
parent2ab1fbd763ad8692ea3ca29705a4fe821ccb1309 (diff)
downloadmad-04363ca342914ba75e693edb876cbe535839fa79.tar
mad-04363ca342914ba75e693edb876cbe535839fa79.zip
Einfache Abfrage der Benutzerdatenbank implementiert
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/Backends/Makefile.in7
-rw-r--r--src/Core/ConnectionManager.cpp2
-rw-r--r--src/Core/Makefile.in9
-rw-r--r--src/Core/RequestHandlers/Makefile.am4
-rw-r--r--src/Core/RequestHandlers/Makefile.in17
-rw-r--r--src/Core/RequestHandlers/UserListRequestHandler.cpp63
-rw-r--r--src/Core/RequestHandlers/UserListRequestHandler.h51
-rw-r--r--src/Core/Requests/Makefile.in9
-rw-r--r--src/Core/UserBackend.cpp4
-rw-r--r--src/Core/UserBackend.h21
10 files changed, 150 insertions, 37 deletions
diff --git a/src/Core/Backends/Makefile.in b/src/Core/Backends/Makefile.in
index ba6fe71..0f181f4 100644
--- a/src/Core/Backends/Makefile.in
+++ b/src/Core/Backends/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -206,6 +206,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libbackends.la
@@ -218,8 +219,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index c347e29..fde7e62 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -31,6 +31,7 @@
#include "RequestHandlers/GSSAPIAuthRequestHandler.h"
#include "RequestHandlers/IdentifyRequestHandler.h"
#include "RequestHandlers/LogRequestHandler.h"
+#include "RequestHandlers/UserListRequestHandler.h"
#include <Net/FdManager.h>
#include <Net/ServerConnection.h>
#include <Net/Packet.h>
@@ -144,6 +145,7 @@ void ConnectionManager::doInit() {
Common::RequestManager::get()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH);
Common::RequestManager::get()->registerPacketType<RequestHandlers::IdentifyRequestHandler>(Net::Packet::IDENTIFY);
Common::RequestManager::get()->registerPacketType<RequestHandlers::LogRequestHandler>(Net::Packet::LOG);
+ Common::RequestManager::get()->registerPacketType<RequestHandlers::UserListRequestHandler>(Net::Packet::USERS_LIST);
}
void ConnectionManager::doDeinit() {
diff --git a/src/Core/Makefile.in b/src/Core/Makefile.in
index 0718c95..4745e1b 100644
--- a/src/Core/Makefile.in
+++ b/src/Core/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -221,6 +221,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Backends Requests RequestHandlers
@@ -236,8 +237,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -384,7 +385,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Core/RequestHandlers/Makefile.am b/src/Core/RequestHandlers/Makefile.am
index 79aef5e..5a044c8 100644
--- a/src/Core/RequestHandlers/Makefile.am
+++ b/src/Core/RequestHandlers/Makefile.am
@@ -1,6 +1,6 @@
noinst_LTLIBRARIES = librequesthandlers.la
librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonFSInfoRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp \
- IdentifyRequestHandler.cpp LogRequestHandler.cpp
+ IdentifyRequestHandler.cpp LogRequestHandler.cpp UserListRequestHandler.cpp
noinst_HEADERS = DaemonCommandRequestHandler.h DaemonFSInfoRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h \
- IdentifyRequestHandler.h LogRequestHandler.h
+ IdentifyRequestHandler.h LogRequestHandler.h UserListRequestHandler.h
diff --git a/src/Core/RequestHandlers/Makefile.in b/src/Core/RequestHandlers/Makefile.in
index 980ffd4..18076c0 100644
--- a/src/Core/RequestHandlers/Makefile.in
+++ b/src/Core/RequestHandlers/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -53,7 +53,8 @@ librequesthandlers_la_LIBADD =
am_librequesthandlers_la_OBJECTS = DaemonCommandRequestHandler.lo \
DaemonFSInfoRequestHandler.lo DaemonListRequestHandler.lo \
DaemonStatusRequestHandler.lo GSSAPIAuthRequestHandler.lo \
- IdentifyRequestHandler.lo LogRequestHandler.lo
+ IdentifyRequestHandler.lo LogRequestHandler.lo \
+ UserListRequestHandler.lo
librequesthandlers_la_OBJECTS = $(am_librequesthandlers_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -213,14 +214,15 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequesthandlers.la
librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonFSInfoRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp \
- IdentifyRequestHandler.cpp LogRequestHandler.cpp
+ IdentifyRequestHandler.cpp LogRequestHandler.cpp UserListRequestHandler.cpp
noinst_HEADERS = DaemonCommandRequestHandler.h DaemonFSInfoRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h \
- IdentifyRequestHandler.h LogRequestHandler.h
+ IdentifyRequestHandler.h LogRequestHandler.h UserListRequestHandler.h
all: all-am
@@ -230,8 +232,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -280,6 +282,7 @@ distclean-compile:
@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@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserListRequestHandler.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -313,7 +316,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Core/RequestHandlers/UserListRequestHandler.cpp b/src/Core/RequestHandlers/UserListRequestHandler.cpp
new file mode 100644
index 0000000..01c2eb3
--- /dev/null
+++ b/src/Core/RequestHandlers/UserListRequestHandler.cpp
@@ -0,0 +1,63 @@
+/*
+ * UserListRequestHandler.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "UserListRequestHandler.h"
+#include "../UserBackend.h"
+#include <Common/Logger.h>
+#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
+#include <Net/Packets/UserListPacket.h>
+
+namespace Mad {
+namespace Core {
+namespace RequestHandlers {
+
+void UserListRequestHandler::handlePacket(Net::Connection *con, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::USERS_LIST) {
+ 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
+
+ connection = con;
+ requestId = packet.getRequestId();
+
+ if(!UserBackend::getUserList(sigc::mem_fun(this, &UserListRequestHandler::userListHandler))) {
+ con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::NOT_IMPLEMENTED)));
+ signalFinished().emit();
+ }
+}
+
+void UserListRequestHandler::userListHandler(const std::map<unsigned long, Common::UserInfo> &info) {
+ std::vector<Common::UserInfo> userList;
+
+ for(std::map<unsigned long, Common::UserInfo>::const_iterator user = info.begin(); user != info.end(); ++user)
+ userList.push_back(user->second);
+
+ connection->send(Net::Packets::UserListPacket(Net::Packet::OK, requestId, userList));
+ signalFinished().emit();
+}
+
+}
+}
+}
diff --git a/src/Core/RequestHandlers/UserListRequestHandler.h b/src/Core/RequestHandlers/UserListRequestHandler.h
new file mode 100644
index 0000000..92eddb7
--- /dev/null
+++ b/src/Core/RequestHandlers/UserListRequestHandler.h
@@ -0,0 +1,51 @@
+/*
+ * UserListRequestHandler.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CORE_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_
+#define MAD_CORE_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_
+
+#include <Common/RequestHandler.h>
+#include <Common/UserInfo.h>
+
+#include <map>
+#include <stdint.h>
+
+namespace Mad {
+namespace Core {
+namespace RequestHandlers {
+
+class UserListRequestHandler : public Common::RequestHandler {
+ private:
+ Net::Connection *connection;
+ uint16_t requestId;
+
+ void userListHandler(const std::map<unsigned long, Common::UserInfo> &info);
+
+ protected:
+ virtual void handlePacket(Net::Connection *con, const Net::Packet &packet);
+
+ public:
+ UserListRequestHandler() {}
+};
+
+}
+}
+}
+
+#endif /* MAD_CORE_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_ */
diff --git a/src/Core/Requests/Makefile.in b/src/Core/Requests/Makefile.in
index da413f4..8b2ad77 100644
--- a/src/Core/Requests/Makefile.in
+++ b/src/Core/Requests/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -211,6 +211,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
@@ -224,8 +225,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -302,7 +303,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Core/UserBackend.cpp b/src/Core/UserBackend.cpp
index ccb5e18..de8b943 100644
--- a/src/Core/UserBackend.cpp
+++ b/src/Core/UserBackend.cpp
@@ -25,7 +25,7 @@ namespace Core {
std::set<UserBackend*, UserBackend::Compare> UserBackend::backends;
-bool UserBackend::getUserList(const sigc::slot<void, const std::map<unsigned long, UserInfo>& > &callback) {
+bool UserBackend::getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback) {
for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
if((*backend)->userList(callback))
return true;
@@ -34,7 +34,7 @@ bool UserBackend::getUserList(const sigc::slot<void, const std::map<unsigned lon
return false;
}
-bool UserBackend::getUserInfo(unsigned long uid, const sigc::slot<void, const UserInfo&> &callback) {
+bool UserBackend::getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback) {
for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
if((*backend)->userInfo(uid, callback))
return true;
diff --git a/src/Core/UserBackend.h b/src/Core/UserBackend.h
index 6031d2f..aad9ace 100644
--- a/src/Core/UserBackend.h
+++ b/src/Core/UserBackend.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_USERBACKEND_H_
#define MAD_CORE_USERBACKEND_H_
+#include <Common/UserInfo.h>
+
#include <map>
#include <set>
#include <string>
@@ -44,17 +46,6 @@ class UserBackend {
static std::set<UserBackend*, Compare> backends;
- public:
- struct UserInfo {
- unsigned long uid;
- unsigned long gid;
-
- std::vector<unsigned long> gids;
-
- std::string username;
- std::string fullName;
- };
-
protected:
UserBackend() {}
@@ -66,11 +57,11 @@ class UserBackend {
backends.erase(backend);
}
- virtual bool userList(const sigc::slot<void, const std::map<unsigned long, UserInfo>& >&) {
+ virtual bool userList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& >&) {
return false;
}
- virtual bool userInfo(unsigned long, const sigc::slot<void, const UserInfo&>&) {
+ virtual bool userInfo(unsigned long, const sigc::slot<void, const Common::UserInfo&>&) {
return false;
}
@@ -85,8 +76,8 @@ class UserBackend {
public:
virtual ~UserBackend() {}
- static bool getUserList(const sigc::slot<void, const std::map<unsigned long, UserInfo>& > &callback);
- static bool getUserInfo(unsigned long uid, const sigc::slot<void, const UserInfo&> &callback);
+ static bool getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback);
+ static bool getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback);
static bool setPassword(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback);
};