/* * UserRequestHandlerGroup.cpp * * Copyright (C) 2009 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 "UserRequestHandlerGroup.h" #include "../Application.h" #include namespace Mad { namespace Server { namespace RequestHandlers { void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr packet _UNUSED_PARAMETER_, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { boost::shared_ptr > info = application->getUserManager()->getUserList(); ret->setType("OK"); Common::XmlPacket::List *list = ret->createList("users"); for(std::map::iterator user = info->begin(); user != info->end(); ++user) { Common::XmlPacket::List::iterator entry = list->addEntry(); entry->set("uid", user->second.getUid()); entry->set("gid", user->second.getGid()); entry->set("username", user->second.getUsername()); entry->set("fullName", user->second.getFullName()); } } void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { boost::shared_ptr info = application->getUserManager()->getUserInfo(packet->get("uid")); ret->setType("OK"); ret->set("uid", info->getUid()); ret->set("gid", info->getGid()); ret->set("username", info->getUsername()); ret->set("fullName", info->getFullName()); } void UserRequestHandlerGroup::handleUserGroupListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { boost::shared_ptr > groups = application->getUserManager()->getUserGroupList(packet->get("uid")); ret->setType("OK"); Common::XmlPacket::List *list = ret->createList("groups"); for(std::set::iterator group = groups->begin(); group != groups->end(); ++group) { Common::XmlPacket::List::iterator entry = list->addEntry(); entry->set("gid", *group); } } void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr packet _UNUSED_PARAMETER_, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { boost::shared_ptr > info = application->getUserManager()->getGroupList(); ret->setType("OK"); Common::XmlPacket::List *list = ret->createList("groups"); for(std::map::iterator group = info->begin(); group != info->end(); ++group) { Common::XmlPacket::List::iterator entry = list->addEntry(); entry->set("gid", group->second.getGid()); entry->set("name", group->second.getName()); } } void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptr packet, Common::XmlPacket *ret, Common::Connection *connection _UNUSED_PARAMETER_) { boost::shared_ptr > users = application->getUserManager()->getGroupUserList(packet->get("gid")); ret->setType("OK"); Common::XmlPacket::List *list = ret->createList("users"); for(std::set::iterator user = users->begin(); user != users->end(); ++user) { Common::XmlPacket::List::iterator entry = list->addEntry(); entry->set("uid", *user); } } UserRequestHandlerGroup::UserRequestHandlerGroup(Application *application0) : application(application0) { registerHandler("ListUsers", boost::bind(&UserRequestHandlerGroup::handleUserListRequest, this, _1, _2, _3)); registerHandler("GetUserInfo", boost::bind(&UserRequestHandlerGroup::handleUserInfoRequest, this, _1, _2, _3)); registerHandler("ListUserGroups", boost::bind(&UserRequestHandlerGroup::handleUserGroupListRequest, this, _1, _2, _3)); registerHandler("ListGroups", boost::bind(&UserRequestHandlerGroup::handleGroupListRequest, this, _1, _2, _3)); registerHandler("ListGroupUsers", boost::bind(&UserRequestHandlerGroup::handleGroupUserListRequest, this, _1, _2, _3)); } } } }