summaryrefslogtreecommitdiffstats
path: root/src/Server
diff options
context:
space:
mode:
Diffstat (limited to 'src/Server')
-rw-r--r--src/Server/CMakeLists.txt6
-rw-r--r--src/Server/ConnectionManager.cpp22
-rw-r--r--src/Server/ConnectionManager.h2
-rw-r--r--src/Server/RequestHandlers/CMakeLists.txt14
-rw-r--r--src/Server/RequestHandlers/GroupListRequestHandler.cpp77
-rw-r--r--src/Server/RequestHandlers/GroupListRequestHandler.h38
-rw-r--r--src/Server/RequestHandlers/GroupUserListRequestHandler.cpp74
-rw-r--r--src/Server/RequestHandlers/GroupUserListRequestHandler.h38
-rw-r--r--src/Server/RequestHandlers/UserGroupListRequestHandler.cpp74
-rw-r--r--src/Server/RequestHandlers/UserGroupListRequestHandler.h38
-rw-r--r--src/Server/RequestHandlers/UserInfoRequestHandler.cpp71
-rw-r--r--src/Server/RequestHandlers/UserInfoRequestHandler.h38
-rw-r--r--src/Server/RequestHandlers/UserListRequestHandler.cpp77
-rw-r--r--src/Server/RequestHandlers/UserListRequestHandler.h38
-rw-r--r--src/Server/RequestHandlers/UserRequestHandlerGroup.cpp156
-rw-r--r--src/Server/RequestHandlers/UserRequestHandlerGroup.h69
-rw-r--r--src/Server/Requests/CMakeLists.txt5
17 files changed, 250 insertions, 587 deletions
diff --git a/src/Server/CMakeLists.txt b/src/Server/CMakeLists.txt
index 1c5885f..e38d860 100644
--- a/src/Server/CMakeLists.txt
+++ b/src/Server/CMakeLists.txt
@@ -3,5 +3,9 @@ add_subdirectory(Requests)
include_directories(${INCLUDES})
-add_library(Server ConnectionManager.cpp UserManager.cpp)
+add_library(Server
+ ConnectionManager.cpp ConnectionManager.h
+ UserBackend.h
+ UserManager.cpp UserManager.h
+)
target_link_libraries(Server ServerRequestHandlers ServerRequests Common)
diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp
index 3743e43..0a60ff4 100644
--- a/src/Server/ConnectionManager.cpp
+++ b/src/Server/ConnectionManager.cpp
@@ -29,13 +29,9 @@
#include "RequestHandlers/DaemonListRequestHandler.h"
#include "RequestHandlers/DaemonStatusRequestHandler.h"
//#include "RequestHandlers/GSSAPIAuthRequestHandler.h"
-#include "RequestHandlers/GroupListRequestHandler.h"
-#include "RequestHandlers/GroupUserListRequestHandler.h"
#include "RequestHandlers/IdentifyRequestHandler.h"
#include "RequestHandlers/LogRequestHandler.h"
-#include "RequestHandlers/UserGroupListRequestHandler.h"
-#include "RequestHandlers/UserInfoRequestHandler.h"
-#include "RequestHandlers/UserListRequestHandler.h"
+#include "RequestHandlers/UserRequestHandlerGroup.h"
#include <Net/Packet.h>
#include <Net/Listener.h>
@@ -189,6 +185,8 @@ void ConnectionManager::handleDisconnect(boost::shared_ptr<ServerConnection> con
void ConnectionManager::doInit() {
Common::RequestManager::get()->setServer(true);
+ userRequestHandlerGroup.reset(new RequestHandlers::UserRequestHandlerGroup);
+
//Common::RequestManager::get()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>("AuthGSSAPI");
Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>("DaemonCommand");
Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonFSInfoRequestHandler>("DaemonFSInfo");
@@ -197,17 +195,16 @@ void ConnectionManager::doInit() {
Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>("GetDaemonStatus");
Common::RequestManager::get()->registerPacketType<RequestHandlers::IdentifyRequestHandler>("Identify");
Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonListRequestHandler>("ListHosts");
- Common::RequestManager::get()->registerPacketType<RequestHandlers::UserInfoRequestHandler>("GetUserInfo");
- Common::RequestManager::get()->registerPacketType<RequestHandlers::UserListRequestHandler>("ListUsers");
- Common::RequestManager::get()->registerPacketType<RequestHandlers::UserGroupListRequestHandler>("ListUserGroups");
- Common::RequestManager::get()->registerPacketType<RequestHandlers::GroupListRequestHandler>("ListGroups");
- Common::RequestManager::get()->registerPacketType<RequestHandlers::GroupUserListRequestHandler>("ListGroupUsers");
Common::RequestManager::get()->registerPacketType<RequestHandlers::LogRequestHandler>("Log");
+
+ Common::RequestManager::get()->registerRequestHandlerGroup(userRequestHandlerGroup);
}
void ConnectionManager::doDeinit() {
connections.clear();
+ Common::RequestManager::get()->unregisterRequestHandlerGroup(userRequestHandlerGroup);
+
//Common::RequestManager::get()->unregisterPacketType("AuthGSSAPI");
Common::RequestManager::get()->unregisterPacketType("DaemonCommand");
Common::RequestManager::get()->unregisterPacketType("DaemonFSInfo");
@@ -216,11 +213,6 @@ void ConnectionManager::doDeinit() {
Common::RequestManager::get()->unregisterPacketType("GetDaemonStatus");
Common::RequestManager::get()->unregisterPacketType("Identify");
Common::RequestManager::get()->unregisterPacketType("ListHosts");
- Common::RequestManager::get()->unregisterPacketType("GetUserInfo");
- Common::RequestManager::get()->unregisterPacketType("ListUsers");
- Common::RequestManager::get()->unregisterPacketType("ListUserGroups");
- Common::RequestManager::get()->unregisterPacketType("ListGroups");
- Common::RequestManager::get()->unregisterPacketType("ListGroupUsers");
Common::RequestManager::get()->unregisterPacketType("Log");
}
diff --git a/src/Server/ConnectionManager.h b/src/Server/ConnectionManager.h
index 92cce11..0c4e76d 100644
--- a/src/Server/ConnectionManager.h
+++ b/src/Server/ConnectionManager.h
@@ -100,6 +100,8 @@ class ConnectionManager : public Common::Configurable, public Common::Initializa
std::map<std::string,Common::HostInfo> daemonInfo;
+ boost::shared_ptr<Common::RequestHandlerGroup> userRequestHandlerGroup;
+
void updateState(Common::HostInfo *hostInfo, Common::HostInfo::State state);
ConnectionManager() {}
diff --git a/src/Server/RequestHandlers/CMakeLists.txt b/src/Server/RequestHandlers/CMakeLists.txt
index fe4e71d..b57b9fe 100644
--- a/src/Server/RequestHandlers/CMakeLists.txt
+++ b/src/Server/RequestHandlers/CMakeLists.txt
@@ -1,10 +1,12 @@
include_directories(${INCLUDES})
-add_library(ServerRequestHandlers
- DaemonCommandRequestHandler.cpp DaemonFSInfoRequestHandler.cpp
- DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp
- GroupListRequestHandler.cpp GroupUserListRequestHandler.cpp IdentifyRequestHandler.cpp
- LogRequestHandler.cpp UserGroupListRequestHandler.cpp UserInfoRequestHandler.cpp
- UserListRequestHandler.cpp
+add_library(ServerRequestHandlers STATIC
+ DaemonCommandRequestHandler.cpp DaemonCommandRequestHandler.h
+ DaemonFSInfoRequestHandler.cpp DaemonFSInfoRequestHandler.h
+ DaemonListRequestHandler.cpp DaemonListRequestHandler.h
+ DaemonStatusRequestHandler.cpp DaemonStatusRequestHandler.h
+ IdentifyRequestHandler.cpp IdentifyRequestHandler.h
+ LogRequestHandler.cpp LogRequestHandler.h
+ UserRequestHandlerGroup.cpp UserRequestHandlerGroup.h
)
target_link_libraries(ServerRequestHandlers Server ${KRB5_LIBRARIES})
diff --git a/src/Server/RequestHandlers/GroupListRequestHandler.cpp b/src/Server/RequestHandlers/GroupListRequestHandler.cpp
deleted file mode 100644
index 453f4c2..0000000
--- a/src/Server/RequestHandlers/GroupListRequestHandler.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * GroupListRequestHandler.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 "GroupListRequestHandler.h"
-#include "../UserManager.h"
-#include <Net/Exception.h>
-#include <Common/Logger.h>
-
-namespace Mad {
-namespace Server {
-namespace RequestHandlers {
-
-void GroupListRequestHandler::handlePacket(boost::shared_ptr<const Common::XmlPacket> packet) {
- if(packet->getType() != "ListGroups") {
- Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
-
- Common::XmlPacket ret;
- ret.setType("Error");
- ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET);
-
- sendPacket(ret);
-
- signalFinished();
- return;
- }
-
- // TODO Require authentication
-
-
-
- Common::XmlPacket ret;
-
- try {
- boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > info = UserManager::get()->getGroupList();
-
- ret.setType("OK");
- ret.addList("groups");
-
- for(std::map<unsigned long, Common::GroupInfo>::iterator group = info->begin(); group != info->end(); ++group) {
- ret["groups"].addEntry();
- Common::XmlPacket::Entry &entry = ret["groups"].back();
-
- entry.add("gid", group->second.getGid());
- entry.add("name", group->second.getName());
- }
- }
- catch(Net::Exception e) {
- ret.setType("Error");
- ret.add("ErrorCode", e.getErrorCode());
- ret.add("SubCode", e.getSubCode());
- ret.add("SubSubCode", e.getSubSubCode());
- ret.add("Where", e.getWhere());
- }
-
- sendPacket(ret);
- signalFinished();
-}
-
-}
-}
-}
diff --git a/src/Server/RequestHandlers/GroupListRequestHandler.h b/src/Server/RequestHandlers/GroupListRequestHandler.h
deleted file mode 100644
index 8654708..0000000
--- a/src/Server/RequestHandlers/GroupListRequestHandler.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * GroupListRequestHandler.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_SERVER_REQUESTHANDLERS_GROUPLISTREQUESTHANDLER_H_
-#define MAD_SERVER_REQUESTHANDLERS_GROUPLISTREQUESTHANDLER_H_
-
-#include <Common/RequestHandler.h>
-
-namespace Mad {
-namespace Server {
-namespace RequestHandlers {
-
-class GroupListRequestHandler : public Common::RequestHandler {
- protected:
- virtual void handlePacket(boost::shared_ptr<const Common::XmlPacket> packet);
-};
-
-}
-}
-}
-
-#endif /* MAD_SERVER_REQUESTHANDLERS_GROUPLISTREQUESTHANDLER_H_ */
diff --git a/src/Server/RequestHandlers/GroupUserListRequestHandler.cpp b/src/Server/RequestHandlers/GroupUserListRequestHandler.cpp
deleted file mode 100644
index f862e8b..0000000
--- a/src/Server/RequestHandlers/GroupUserListRequestHandler.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * GroupUserListRequestHandler.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 "GroupUserListRequestHandler.h"
-#include "../UserManager.h"
-#include <Net/Exception.h>
-#include <Common/Logger.h>
-
-namespace Mad {
-namespace Server {
-namespace RequestHandlers {
-
-void GroupUserListRequestHandler::handlePacket(boost::shared_ptr<const Common::XmlPacket> packet) {
- if(packet->getType() != "ListGroupUsers") {
- Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
-
- Common::XmlPacket ret;
- ret.setType("Error");
- ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET);
-
- sendPacket(ret);
-
- signalFinished();
- return;
- }
-
- // TODO Require authentication
-
- Common::XmlPacket ret;
-
- try {
- boost::shared_ptr<std::set<unsigned long> > users = UserManager::get()->getGroupUserList((unsigned long)(*packet)["gid"]);
-
- ret.setType("OK");
- ret.addList("users");
-
- for(std::set<unsigned long>::iterator user = users->begin(); user != users->end(); ++user) {
- ret["users"].addEntry();
- Common::XmlPacket::Entry &entry = ret["users"].back();
-
- entry.add("uid", *user);
- }
- }
- catch(Net::Exception e) {
- ret.setType("Error");
- ret.add("ErrorCode", e.getErrorCode());
- ret.add("SubCode", e.getSubCode());
- ret.add("SubSubCode", e.getSubSubCode());
- ret.add("Where", e.getWhere());
- }
-
- sendPacket(ret);
- signalFinished();
-}
-
-}
-}
-}
diff --git a/src/Server/RequestHandlers/GroupUserListRequestHandler.h b/src/Server/RequestHandlers/GroupUserListRequestHandler.h
deleted file mode 100644
index 2220565..0000000
--- a/src/Server/RequestHandlers/GroupUserListRequestHandler.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * GroupUserListRequestHandler.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_SERVER_REQUESTHANDLERS_GROUPUSERLISTREQUESTHANDLER_H_
-#define MAD_SERVER_REQUESTHANDLERS_GROUPUSERLISTREQUESTHANDLER_H_
-
-#include <Common/RequestHandler.h>
-
-namespace Mad {
-namespace Server {
-namespace RequestHandlers {
-
-class GroupUserListRequestHandler : public Common::RequestHandler {
- protected:
- virtual void handlePacket(boost::shared_ptr<const Common::XmlPacket> packet);
-};
-
-}
-}
-}
-
-#endif /* MAD_SERVER_REQUESTHANDLERS_GROUPUSERLISTREQUESTHANDLER_H_ */
diff --git a/src/Server/RequestHandlers/UserGroupListRequestHandler.cpp b/src/Server/RequestHandlers/UserGroupListRequestHandler.cpp
deleted file mode 100644
index f5a3f7e..0000000
--- a/src/Server/RequestHandlers/UserGroupListRequestHandler.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * UserGroupListRequestHandler.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 "UserGroupListRequestHandler.h"
-#include "../UserManager.h"
-#include <Net/Exception.h>
-#include <Common/Logger.h>
-
-namespace Mad {
-namespace Server {
-namespace RequestHandlers {
-
-void UserGroupListRequestHandler::handlePacket(boost::shared_ptr<const Common::XmlPacket> packet) {
- if(packet->getType() != "ListUserGroups") {
- Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
-
- Common::XmlPacket ret;
- ret.setType("Error");
- ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET);
-
- sendPacket(ret);
-
- signalFinished();
- return;
- }
-
- // TODO Require authentication
-
- Common::XmlPacket ret;
-
- try {
- boost::shared_ptr<std::set<unsigned long> > groups = UserManager::get()->getUserGroupList((unsigned long)(*packet)["uid"]);
-
- ret.setType("OK");
- ret.addList("groups");
-
- for(std::set<unsigned long>::iterator group = groups->begin(); group != groups->end(); ++group) {
- ret["groups"].addEntry();
- Common::XmlPacket::Entry &entry = ret["groups"].back();
-
- entry.add("gid", *group);
- }
- }
- catch(Net::Exception e) {
- ret.setType("Error");
- ret.add("ErrorCode", e.getErrorCode());
- ret.add("SubCode", e.getSubCode());
- ret.add("SubSubCode", e.getSubSubCode());
- ret.add("Where", e.getWhere());
- }
-
- sendPacket(ret);
- signalFinished();
-}
-
-}
-}
-}
diff --git a/src/Server/RequestHandlers/UserGroupListRequestHandler.h b/src/Server/RequestHandlers/UserGroupListRequestHandler.h
deleted file mode 100644
index 35ff2eb..0000000
--- a/src/Server/RequestHandlers/UserGroupListRequestHandler.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * UserGroupListRequestHandler.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_SERVER_REQUESTHANDLERS_USERGROUPLISTREQUESTHANDLER_H_
-#define MAD_SERVER_REQUESTHANDLERS_USERGROUPLISTREQUESTHANDLER_H_
-
-#include <Common/RequestHandler.h>
-
-namespace Mad {
-namespace Server {
-namespace RequestHandlers {
-
-class UserGroupListRequestHandler : public Common::RequestHandler {
- protected:
- virtual void handlePacket(boost::shared_ptr<const Common::XmlPacket> packet);
-};
-
-}
-}
-}
-
-#endif /* MAD_SERVER_REQUESTHANDLERS_USERGROUPLISTREQUESTHANDLER_H_ */
diff --git a/src/Server/RequestHandlers/UserInfoRequestHandler.cpp b/src/Server/RequestHandlers/UserInfoRequestHandler.cpp
deleted file mode 100644
index e9e0716..0000000
--- a/src/Server/RequestHandlers/UserInfoRequestHandler.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * UserInfoRequestHandler.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 "UserInfoRequestHandler.h"
-#include "../UserManager.h"
-#include <Net/Exception.h>
-#include <Common/Logger.h>
-
-namespace Mad {
-namespace Server {
-namespace RequestHandlers {
-
-void UserInfoRequestHandler::handlePacket(boost::shared_ptr<const Common::XmlPacket> packet) {
- if(packet->getType() != "GetUserInfo") {
- Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
-
- Common::XmlPacket ret;
- ret.setType("Error");
- ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET);
-
- sendPacket(ret);
-
- signalFinished();
- return;
- }
-
- // TODO Require authentication
-
- Common::XmlPacket ret;
-
- try {
- boost::shared_ptr<Common::UserInfo> info = UserManager::get()->getUserInfo((*packet)["uid"]);
-
- ret.setType("OK");
-
- ret.add("uid", info->getUid());
- ret.add("gid", info->getGid());
- ret.add("username", info->getUsername());
- ret.add("fullName", info->getFullName());
- }
- catch(Net::Exception e) {
- ret.setType("Error");
- ret.add("ErrorCode", e.getErrorCode());
- ret.add("SubCode", e.getSubCode());
- ret.add("SubSubCode", e.getSubSubCode());
- ret.add("Where", e.getWhere());
- }
-
- sendPacket(ret);
- signalFinished();
-}
-
-}
-}
-}
diff --git a/src/Server/RequestHandlers/UserInfoRequestHandler.h b/src/Server/RequestHandlers/UserInfoRequestHandler.h
deleted file mode 100644
index af11678..0000000
--- a/src/Server/RequestHandlers/UserInfoRequestHandler.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * UserInfoRequestHandler.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_SERVER_REQUESTHANDLERS_USERINFOREQUESTHANDLER_H_
-#define MAD_SERVER_REQUESTHANDLERS_USERINFOREQUESTHANDLER_H_
-
-#include <Common/RequestHandler.h>
-
-namespace Mad {
-namespace Server {
-namespace RequestHandlers {
-
-class UserInfoRequestHandler : public Common::RequestHandler {
- protected:
- virtual void handlePacket(boost::shared_ptr<const Common::XmlPacket> packet);
-};
-
-}
-}
-}
-
-#endif /* MAD_SERVER_REQUESTHANDLERS_USERINFOREQUESTHANDLER_H_ */
diff --git a/src/Server/RequestHandlers/UserListRequestHandler.cpp b/src/Server/RequestHandlers/UserListRequestHandler.cpp
deleted file mode 100644
index 4164f22..0000000
--- a/src/Server/RequestHandlers/UserListRequestHandler.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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 "../UserManager.h"
-#include <Net/Exception.h>
-#include <Common/Logger.h>
-
-namespace Mad {
-namespace Server {
-namespace RequestHandlers {
-
-void UserListRequestHandler::handlePacket(boost::shared_ptr<const Common::XmlPacket> packet) {
- if(packet->getType() != "ListUsers") {
- Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
-
- Common::XmlPacket ret;
- ret.setType("Error");
- ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET);
-
- sendPacket(ret);
-
- signalFinished();
- return;
- }
-
- // TODO Require authentication
-
- Common::XmlPacket ret;
-
- try {
- boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > info = UserManager::get()->getUserList();
-
- ret.setType("OK");
- ret.addList("users");
-
- for(std::map<unsigned long, Common::UserInfo>::iterator user = info->begin(); user != info->end(); ++user) {
- ret["users"].addEntry();
- Common::XmlPacket::Entry &entry = ret["users"].back();
-
- entry.add("uid", user->second.getUid());
- entry.add("gid", user->second.getGid());
- entry.add("username", user->second.getUsername());
- entry.add("fullName", user->second.getFullName());
- }
- }
- catch(Net::Exception e) {
- ret.setType("Error");
- ret.add("ErrorCode", e.getErrorCode());
- ret.add("SubCode", e.getSubCode());
- ret.add("SubSubCode", e.getSubSubCode());
- ret.add("Where", e.getWhere());
- }
-
- sendPacket(ret);
- signalFinished();
-}
-
-}
-}
-}
diff --git a/src/Server/RequestHandlers/UserListRequestHandler.h b/src/Server/RequestHandlers/UserListRequestHandler.h
deleted file mode 100644
index 36cef00..0000000
--- a/src/Server/RequestHandlers/UserListRequestHandler.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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_SERVER_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_
-#define MAD_SERVER_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_
-
-#include <Common/RequestHandler.h>
-
-namespace Mad {
-namespace Server {
-namespace RequestHandlers {
-
-class UserListRequestHandler : public Common::RequestHandler {
- protected:
- virtual void handlePacket(boost::shared_ptr<const Common::XmlPacket> packet);
-};
-
-}
-}
-}
-
-#endif /* MAD_SERVER_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_ */
diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp
new file mode 100644
index 0000000..1b6dd3d
--- /dev/null
+++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp
@@ -0,0 +1,156 @@
+/*
+ * UserRequestHandlerGroup.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 "UserRequestHandlerGroup.h"
+
+#include <Common/Logger.h>
+#include "../UserManager.h"
+
+namespace Mad {
+namespace Server {
+namespace RequestHandlers {
+
+void UserRequestHandlerGroup::RequestHandler::handlePacket(boost::shared_ptr<const Common::XmlPacket> packet) {
+ if(packet->getType() != type) {
+ Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
+
+ Common::XmlPacket ret;
+ ret.setType("Error");
+ ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET);
+
+ sendPacket(ret);
+
+ signalFinished();
+ return;
+ }
+
+ // TODO Require authentication
+
+ Common::XmlPacket ret;
+
+ try {
+ handler(packet, &ret);
+ }
+ catch(Net::Exception e) {
+ ret.setType("Error");
+ ret.add("ErrorCode", e.getErrorCode());
+ ret.add("SubCode", e.getSubCode());
+ ret.add("SubSubCode", e.getSubSubCode());
+ ret.add("Where", e.getWhere());
+ }
+
+ sendPacket(ret);
+ signalFinished();
+}
+
+void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet _UNUSED_PARAMETER_, Common::XmlPacket *ret) {
+ boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > info = UserManager::get()->getUserList();
+
+ ret->setType("OK");
+ ret->addList("users");
+
+ for(std::map<unsigned long, Common::UserInfo>::iterator user = info->begin(); user != info->end(); ++user) {
+ (*ret)["users"].addEntry();
+ Common::XmlPacket::Entry &entry = (*ret)["users"].back();
+
+ entry.add("uid", user->second.getUid());
+ entry.add("gid", user->second.getGid());
+ entry.add("username", user->second.getUsername());
+ entry.add("fullName", user->second.getFullName());
+ }
+}
+
+void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret) {
+ boost::shared_ptr<Common::UserInfo> info = UserManager::get()->getUserInfo((*packet)["uid"]);
+
+ ret->setType("OK");
+
+ ret->add("uid", info->getUid());
+ ret->add("gid", info->getGid());
+ ret->add("username", info->getUsername());
+ ret->add("fullName", info->getFullName());
+}
+
+void UserRequestHandlerGroup::handleUserGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret) {
+ boost::shared_ptr<std::set<unsigned long> > groups = UserManager::get()->getUserGroupList((unsigned long)(*packet)["uid"]);
+
+ ret->setType("OK");
+ ret->addList("groups");
+
+ for(std::set<unsigned long>::iterator group = groups->begin(); group != groups->end(); ++group) {
+ (*ret)["groups"].addEntry();
+ Common::XmlPacket::Entry &entry = (*ret)["groups"].back();
+
+ entry.add("gid", *group);
+ }
+}
+
+void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet _UNUSED_PARAMETER_, Common::XmlPacket *ret) {
+ boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > info = UserManager::get()->getGroupList();
+
+ ret->setType("OK");
+ ret->addList("groups");
+
+ for(std::map<unsigned long, Common::GroupInfo>::iterator group = info->begin(); group != info->end(); ++group) {
+ (*ret)["groups"].addEntry();
+ Common::XmlPacket::Entry &entry = (*ret)["groups"].back();
+
+ entry.add("gid", group->second.getGid());
+ entry.add("name", group->second.getName());
+ }
+}
+
+void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret) {
+ boost::shared_ptr<std::set<unsigned long> > users = UserManager::get()->getGroupUserList((unsigned long)(*packet)["gid"]);
+
+ ret->setType("OK");
+ ret->addList("users");
+
+ for(std::set<unsigned long>::iterator user = users->begin(); user != users->end(); ++user) {
+ (*ret)["users"].addEntry();
+ Common::XmlPacket::Entry &entry = (*ret)["users"].back();
+
+ entry.add("uid", *user);
+ }
+}
+
+UserRequestHandlerGroup::UserRequestHandlerGroup() {
+ registerHandler("ListUsers", &UserRequestHandlerGroup::handleUserListRequest);
+ registerHandler("GetUserInfo", &UserRequestHandlerGroup::handleUserInfoRequest);
+ registerHandler("ListUserGroups", &UserRequestHandlerGroup::handleUserGroupListRequest);
+ registerHandler("ListGroups", &UserRequestHandlerGroup::handleGroupListRequest);
+ registerHandler("ListGroupUsers", &UserRequestHandlerGroup::handleGroupUserListRequest);
+}
+
+const std::set<std::string>& UserRequestHandlerGroup::getPacketTypes() {
+ return types;
+}
+
+boost::shared_ptr<Common::RequestHandler> UserRequestHandlerGroup::createRequestHandler(const std::string &type) {
+ std::map<std::string, boost::function2<void, boost::shared_ptr<const Common::XmlPacket>, Common::XmlPacket*> >::iterator handler = handlers.find(type);
+
+ if(handler == handlers.end())
+ return boost::shared_ptr<Common::RequestHandler>();
+ else
+ return boost::shared_ptr<RequestHandler>(new RequestHandler(type, handler->second));
+}
+
+}
+}
+}
diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.h b/src/Server/RequestHandlers/UserRequestHandlerGroup.h
new file mode 100644
index 0000000..c24d502
--- /dev/null
+++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.h
@@ -0,0 +1,69 @@
+/*
+ * UserRequestHandlerGroup.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_SERVER_REQUESTHANDLERS_USERREQUESTHANDLERGROUP_H_
+#define MAD_SERVER_REQUESTHANDLERS_USERREQUESTHANDLERGROUP_H_
+
+#include <Common/RequestHandlerGroup.h>
+
+namespace Mad {
+namespace Server {
+namespace RequestHandlers {
+
+class UserRequestHandlerGroup : public Common::RequestHandlerGroup {
+ private:
+ class RequestHandler : public Common::RequestHandler {
+ private:
+ std::string type;
+ boost::function2<void, boost::shared_ptr<const Common::XmlPacket>, Common::XmlPacket*> handler;
+
+ protected:
+ virtual void handlePacket(boost::shared_ptr<const Common::XmlPacket> packet);
+
+ public:
+ RequestHandler(const std::string &type0, const boost::function2<void, boost::shared_ptr<const Common::XmlPacket>, Common::XmlPacket*> &handler0) : type(type0), handler(handler0) {}
+ };
+
+
+ std::set<std::string> types;
+ std::map<std::string, boost::function2<void, boost::shared_ptr<const Common::XmlPacket>, Common::XmlPacket*> > handlers;
+
+ void registerHandler(const std::string &type, const boost::function2<void, boost::shared_ptr<const Common::XmlPacket>, Common::XmlPacket*> &handler) {
+ types.insert(type);
+ handlers.insert(std::make_pair(type, handler));
+ }
+
+ static void handleUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret);
+ static void handleUserInfoRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret);
+ static void handleUserGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret);
+ static void handleGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret);
+ static void handleGroupUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret);
+
+ public:
+ UserRequestHandlerGroup();
+
+ virtual const std::set<std::string>& getPacketTypes();
+ virtual boost::shared_ptr<Common::RequestHandler> createRequestHandler(const std::string &type);
+};
+
+}
+}
+}
+
+#endif /* MAD_SERVER_REQUESTHANDLERS_USERREQUESTHANDLERGROUP_H_ */
diff --git a/src/Server/Requests/CMakeLists.txt b/src/Server/Requests/CMakeLists.txt
index 5522809..6c5c8c5 100644
--- a/src/Server/Requests/CMakeLists.txt
+++ b/src/Server/Requests/CMakeLists.txt
@@ -1,5 +1,6 @@
include_directories(${INCLUDES})
-add_library(ServerRequests
- CommandRequest.cpp DaemonStateUpdateRequest.cpp
+add_library(ServerRequests STATIC
+ CommandRequest.cpp CommandRequest.h
+ DaemonStateUpdateRequest.cpp DaemonStateUpdateRequest.h
)