/* * UserListManager.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 Lesser 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along * with this program. If not, see . */ #include "UserListManager.h" #include "Application.h" #include "RequestHandlers/UserListRequestHandlerGroup.h" #include "RequestHandlers/UserListUploadRequestHandler.h" #include "RequestHandlers/UserListDiffUploadRequestHandler.h" #include #include #include #include #include #include namespace Mad { namespace Server { UserListManager::UserListManager(Application *application0) : application(application0), requestHandlerGroup(new RequestHandlers::UserListRequestHandlerGroup(application)) { application->getRequestManager()->registerRequestHandlerGroup(requestHandlerGroup); application->getRequestManager()->registerPacketType("UploadUserList"); application->getRequestManager()->registerPacketType("UploadUserListDiff"); } UserListManager::~UserListManager() { application->getRequestManager()->unregisterPacketType("UploadUserList"); application->getRequestManager()->unregisterPacketType("UploadUserListDiff"); application->getRequestManager()->unregisterRequestHandlerGroup(requestHandlerGroup); } std::set UserListManager::getUserLists() { return application->getStorageManager()->list("UserList"); } bool UserListManager::existsUserList(const Core::String &name) { return application->getStorageManager()->exists("UserList", name); } boost::shared_ptr UserListManager::loadUserList(const Core::String &name) { boost::shared_ptr data = application->getStorageManager()->load("UserList", name); if(!data) return boost::shared_ptr(); return Common::UserLists::Util::deserializeUserList(data.get()); } void UserListManager::storeUserList(const Core::String &name, const Common::UserLists::UserList *list) { Common::XmlData data; Common::UserLists::Util::serializeUserList(list, &data); application->getStorageManager()->store("UserList", name, &data); } void UserListManager::copyUserList(const Core::String &fromName, const Core::String &toName) { application->getStorageManager()->copy("UserList", fromName, toName); } void UserListManager::renameUserList(const Core::String &fromName, const Core::String &toName) { application->getStorageManager()->rename("UserList", fromName, toName); } void UserListManager::removeUserList(const Core::String &name) { application->getStorageManager()->remove("UserList", name); } std::set UserListManager::getUserListDiffs() { return application->getStorageManager()->list("UserListDiff"); } bool UserListManager::existsUserListDiff(const Core::String &name) { return application->getStorageManager()->exists("UserListDiff", name); } boost::shared_ptr UserListManager::loadUserListDiff(const Core::String &name) { boost::shared_ptr data = application->getStorageManager()->load("UserListDiff", name); if(!data) return boost::shared_ptr(); return Common::UserLists::Util::deserializeUserListDiff(data.get()); } void UserListManager::storeUserListDiff(const Core::String &name, const Common::UserLists::UserListDiff *list) { Common::XmlData data; Common::UserLists::Util::serializeUserListDiff(list, &data); application->getStorageManager()->store("UserListDiff", name, &data); } void UserListManager::copyUserListDiff(const Core::String &fromName, const Core::String &toName) { application->getStorageManager()->copy("UserListDiff", fromName, toName); } void UserListManager::renameUserListDiff(const Core::String &fromName, const Core::String &toName) { application->getStorageManager()->rename("UserListDiff", fromName, toName); } void UserListManager::removeUserListDiff(const Core::String &name) { application->getStorageManager()->remove("UserListDiff", name); } boost::shared_ptr UserListManager::getCurrentUserList() { boost::shared_ptr list(new Common::UserLists::UserList); boost::shared_ptr > userList = application->getUserManager()->getUserList(); boost::shared_ptr > groupList = application->getUserManager()->getGroupList(); for(std::map::const_iterator user = userList->begin(); user != userList->end(); ++user) { std::map::const_iterator group = groupList->find(user->second.getGid()); Core::String groupname; if(group != groupList->end()) { groupname = group->second.getName(); } else { std::ostringstream stream; stream << user->second.getGid(); groupname = stream.str().c_str(); } Common::UserLists::UserListEntry entry(user->second.getUsername(), groupname); entry.setDetail("Full name", user->second.getFullName()); list->addUser(entry); } return list; } } }