diff options
Diffstat (limited to 'src/Server/RequestHandlers')
13 files changed, 233 insertions, 569 deletions
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_ */ |