From 0eddc28a331437ef95a60418ed1fc6de4e9b63c1 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 23 Sep 2009 09:44:02 +0200 Subject: UserListManager: Moved module into libCommon and libServer --- src/Common/CMakeLists.txt | 5 + src/Common/UserLists/UserList.h | 40 +++++ src/Common/UserLists/UserListDiff.cpp | 46 ++++++ src/Common/UserLists/UserListDiff.h | 88 +++++++++++ src/Common/UserLists/UserListEntry.h | 93 ++++++++++++ src/Common/UserLists/Util.cpp | 111 ++++++++++++++ src/Common/UserLists/Util.h | 55 +++++++ src/Server/Application.cpp | 5 +- src/Server/Application.h | 6 + src/Server/CMakeLists.txt | 4 + .../UserListDiffUploadRequestHandler.cpp | 84 +++++++++++ .../UserListDiffUploadRequestHandler.h | 47 ++++++ .../UserListRequestHandlerGroup.cpp | 161 +++++++++++++++++++++ .../RequestHandlers/UserListRequestHandlerGroup.h | 59 ++++++++ .../UserListUploadRequestHandler.cpp | 85 +++++++++++ .../RequestHandlers/UserListUploadRequestHandler.h | 47 ++++++ src/Server/UserListManager.cpp | 151 +++++++++++++++++++ src/Server/UserListManager.h | 95 ++++++++++++ src/mad-server.conf | 4 +- src/modules/CMakeLists.txt | 2 - src/modules/UserListManager/CMakeLists.txt | 16 -- src/modules/UserListManager/Module.cpp | 39 ----- src/modules/UserListManager/Module.h | 44 ------ .../UserListDiffUploadRequestHandler.cpp | 82 ----------- .../UserListDiffUploadRequestHandler.h | 51 ------- .../UserListRequestHandlerGroup.cpp | 161 --------------------- .../RequestHandlers/UserListRequestHandlerGroup.h | 66 --------- .../UserListUploadRequestHandler.cpp | 83 ----------- .../RequestHandlers/UserListUploadRequestHandler.h | 51 ------- src/modules/UserListManager/UserList.h | 40 ----- src/modules/UserListManager/UserListDiff.cpp | 46 ------ src/modules/UserListManager/UserListDiff.h | 88 ----------- src/modules/UserListManager/UserListEntry.h | 93 ------------ src/modules/UserListManager/UserListManager.cpp | 153 -------------------- src/modules/UserListManager/UserListManager.h | 95 ------------ src/modules/UserListManager/Util.cpp | 113 --------------- src/modules/UserListManager/Util.h | 55 ------- 37 files changed, 1182 insertions(+), 1282 deletions(-) create mode 100644 src/Common/UserLists/UserList.h create mode 100644 src/Common/UserLists/UserListDiff.cpp create mode 100644 src/Common/UserLists/UserListDiff.h create mode 100644 src/Common/UserLists/UserListEntry.h create mode 100644 src/Common/UserLists/Util.cpp create mode 100644 src/Common/UserLists/Util.h create mode 100644 src/Server/RequestHandlers/UserListDiffUploadRequestHandler.cpp create mode 100644 src/Server/RequestHandlers/UserListDiffUploadRequestHandler.h create mode 100644 src/Server/RequestHandlers/UserListRequestHandlerGroup.cpp create mode 100644 src/Server/RequestHandlers/UserListRequestHandlerGroup.h create mode 100644 src/Server/RequestHandlers/UserListUploadRequestHandler.cpp create mode 100644 src/Server/RequestHandlers/UserListUploadRequestHandler.h create mode 100644 src/Server/UserListManager.cpp create mode 100644 src/Server/UserListManager.h delete mode 100644 src/modules/UserListManager/CMakeLists.txt delete mode 100644 src/modules/UserListManager/Module.cpp delete mode 100644 src/modules/UserListManager/Module.h delete mode 100644 src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp delete mode 100644 src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.h delete mode 100644 src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp delete mode 100644 src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.h delete mode 100644 src/modules/UserListManager/RequestHandlers/UserListUploadRequestHandler.cpp delete mode 100644 src/modules/UserListManager/RequestHandlers/UserListUploadRequestHandler.h delete mode 100644 src/modules/UserListManager/UserList.h delete mode 100644 src/modules/UserListManager/UserListDiff.cpp delete mode 100644 src/modules/UserListManager/UserListDiff.h delete mode 100644 src/modules/UserListManager/UserListEntry.h delete mode 100644 src/modules/UserListManager/UserListManager.cpp delete mode 100644 src/modules/UserListManager/UserListManager.h delete mode 100644 src/modules/UserListManager/Util.cpp delete mode 100644 src/modules/UserListManager/Util.h (limited to 'src') diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt index dd12a36..a99f9be 100644 --- a/src/Common/CMakeLists.txt +++ b/src/Common/CMakeLists.txt @@ -18,6 +18,11 @@ mad_library(Common Requests/SimpleRequest.cpp Requests/SimpleRequest.h Requests/StatusRequest.h + UserLists/UserList.h + UserLists/UserListDiff.cpp UserLists/UserListDiff.h + UserLists/UserListEntry.h + UserLists/Util.cpp UserLists/Util.h + Application.cpp Application.h AuthBackend.h AuthContext.h diff --git a/src/Common/UserLists/UserList.h b/src/Common/UserLists/UserList.h new file mode 100644 index 0000000..e80abaf --- /dev/null +++ b/src/Common/UserLists/UserList.h @@ -0,0 +1,40 @@ +/* + * UserList.h + * + * 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 . + */ + +#ifndef MAD_COMMON_USERLISTS_USERLIST_H_ +#define MAD_COMMON_USERLISTS_USERLIST_H_ + +#include "UserListEntry.h" + +#include + +namespace Mad { +namespace Common { +namespace UserLists { + +class UserList : public std::list { + public: + UserList() {} +}; + +} +} +} + +#endif /* MAD_COMMON_USERLISTS_USERLIST_H_ */ diff --git a/src/Common/UserLists/UserListDiff.cpp b/src/Common/UserLists/UserListDiff.cpp new file mode 100644 index 0000000..e763afe --- /dev/null +++ b/src/Common/UserLists/UserListDiff.cpp @@ -0,0 +1,46 @@ +/* + * UserListDiff.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 "UserListDiff.h" +#include "UserList.h" + +namespace Mad { +namespace Common { +namespace UserLists { + +UserListDiff::UserListDiff(const UserList *oldList, const UserList *newList) { + for(UserList::const_iterator user = oldList->begin(); user != oldList->end(); ++user) + deletedUsers.insert(*user); + + for(UserList::const_iterator user = newList->begin(); user != newList->end(); ++user) { + std::set::const_iterator it = deletedUsers.find(*user); + + if(it != deletedUsers.end()) { + deletedUsers.erase(it); + unchangedUsers.insert(*user); + } + else { + addedUsers.insert(*user); + } + } +} + +} +} +} diff --git a/src/Common/UserLists/UserListDiff.h b/src/Common/UserLists/UserListDiff.h new file mode 100644 index 0000000..41b8e81 --- /dev/null +++ b/src/Common/UserLists/UserListDiff.h @@ -0,0 +1,88 @@ +/* + * UserListDiff.h + * + * 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 . + */ + +#ifndef MAD_COMMON_USERLISTS_USERLISTDIFF_H_ +#define MAD_COMMON_USERLISTS_USERLISTDIFF_H_ + +#include "../export.h" + +#include "UserListEntry.h" +#include + +#include + +namespace Mad { +namespace Common { +namespace UserLists { + +class UserList; + +class MAD_COMMON_EXPORT UserListDiff { + private: + std::set addedUsers; + std::set deletedUsers; + std::set unchangedUsers; + + public: + UserListDiff() {} + UserListDiff(const UserList *oldList, const UserList *newList); + + void invert() { + addedUsers.swap(deletedUsers); + } + + const std::set& getAddedUsers() const { + return addedUsers; + } + + const std::set& getDeletedUsers() const { + return deletedUsers; + } + + const std::set& getUnchangedUsers() const { + return unchangedUsers; + } + + bool insertAddedUser(UserListEntry user) { + if(deletedUsers.count(user) || unchangedUsers.count(user)) + return false; + + return addedUsers.insert(user).second; + } + + bool insertDeletedUser(UserListEntry user) { + if(addedUsers.count(user) || unchangedUsers.count(user)) + return false; + + return deletedUsers.insert(user).second; + } + + bool insertUnchangedUser(UserListEntry user) { + if(addedUsers.count(user) || deletedUsers.count(user)) + return false; + + return unchangedUsers.insert(user).second; + } +}; + +} +} +} + +#endif /* MAD_COMMON_USERLISTS_USERLISTDIFF_H_ */ diff --git a/src/Common/UserLists/UserListEntry.h b/src/Common/UserLists/UserListEntry.h new file mode 100644 index 0000000..8642275 --- /dev/null +++ b/src/Common/UserLists/UserListEntry.h @@ -0,0 +1,93 @@ +/* + * UserListEntry.h + * + * 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 . + */ + +#ifndef MAD_COMMON_USERLISTS_USERLISTENTRY_H_ +#define MAD_COMMON_USERLISTS_USERLISTENTRY_H_ + +#include +#include +#include + + +namespace Mad { +namespace Common { +namespace UserLists { + +class UserListEntry { + private: + std::string name; + std::string group; + + std::map details; + + public: + UserListEntry(const std::string &name0 = std::string(), const std::string &group0 = std::string()) : name(name0), group(group0) {} + + const std::string& getName() const { + return name; + } + + void setName(const std::string &newName) { + name = newName; + } + + const std::string& getGroup() const { + return group; + } + + void setGroup(const std::string &newGroup) { + group = newGroup; + } + + std::set getDetailList() const { + std::set ret; + + for(std::map::const_iterator it = details.begin(); it != details.end(); ++it) + ret.insert(it->first); + + return ret; + } + + std::string getDetail(const std::string &name) const { + std::map::const_iterator it = details.find(name); + if(it != details.end()) + return it->second; + else + return std::string(); + } + + void setDetail(const std::string &name, const std::string &value) { + details.erase(name); + details.insert(std::make_pair(name, value)); + } + + void unsetDetail(const std::string &name) { + details.erase(name); + } + + bool operator<(const UserListEntry o) const { + return (name < o.name); + } +}; + +} +} +} + +#endif /* MAD_COMMON_USERLISTS_USERLISTENTRY_H_ */ diff --git a/src/Common/UserLists/Util.cpp b/src/Common/UserLists/Util.cpp new file mode 100644 index 0000000..812c2c7 --- /dev/null +++ b/src/Common/UserLists/Util.cpp @@ -0,0 +1,111 @@ +/* + * Util.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 "Util.h" +#include "UserList.h" +#include "UserListDiff.h" + +namespace Mad { +namespace Common { +namespace UserLists { + +void Util::serializeUserListEntry(const UserListEntry *user, XmlData::List::iterator entry) { + std::set details = user->getDetailList(); + for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) + entry->set(*detail, user->getDetail(*detail)); + + entry->set("name", user->getName()); + entry->set("group", user->getGroup()); +} + +UserListEntry Util::deserializeUserListEntry(XmlData::List::const_iterator entry) { + UserListEntry user(entry->get("name"), entry->get("group")); + + std::set details = entry->getChildren(); + for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { + if(*detail == "user" || *detail == "group") + continue; + + user.setDetail(*detail, entry->get(*detail)); + } + + return user; +} + +void Util::serializeUserList(const UserList *list, XmlData *data) { + XmlData::List *userList = data->createList("users"); + + for(UserList::const_iterator user = list->begin(); user != list->end(); ++user) + serializeUserListEntry(&*user, userList->addEntry()); +} + +boost::shared_ptr Util::deserializeUserList(const XmlData *data) { + boost::shared_ptr users(new UserList); + + const XmlData::List *userList = data->getList("users"); + + if(userList) { + for(XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) + users->push_back(deserializeUserListEntry(user)); + } + + return users; +} + +void Util::serializeUserListDiff(const UserListDiff *diff, XmlData *data) { + XmlData::List *userList = data->createList("addedUsers"); + for(std::set::const_iterator user = diff->getAddedUsers().begin(); user != diff->getAddedUsers().end(); ++user) + serializeUserListEntry(&*user, userList->addEntry()); + + userList = data->createList("deletedUsers"); + for(std::set::const_iterator user = diff->getDeletedUsers().begin(); user != diff->getDeletedUsers().end(); ++user) + serializeUserListEntry(&*user, userList->addEntry()); + + userList = data->createList("unchangedUsers"); + for(std::set::const_iterator user = diff->getUnchangedUsers().begin(); user != diff->getUnchangedUsers().end(); ++user) + serializeUserListEntry(&*user, userList->addEntry()); +} + +boost::shared_ptr Util::deserializeUserListDiff(const XmlData *data) { + boost::shared_ptr diff(new UserListDiff); + + const XmlData::List *userList = data->getList("addedUsers"); + if(userList) { + for(XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) + diff->insertAddedUser(deserializeUserListEntry(user)); + } + + userList = data->getList("deletedUsers"); + if(userList) { + for(XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) + diff->insertDeletedUser(deserializeUserListEntry(user)); + } + + userList = data->getList("unchangedUsers"); + if(userList) { + for(XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) + diff->insertUnchangedUser(deserializeUserListEntry(user)); + } + + return diff; +} + +} +} +} diff --git a/src/Common/UserLists/Util.h b/src/Common/UserLists/Util.h new file mode 100644 index 0000000..df7f203 --- /dev/null +++ b/src/Common/UserLists/Util.h @@ -0,0 +1,55 @@ +/* + * Util.h + * + * 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 . + */ + +#ifndef MAD_COMMON_USERLISTS_UTIL_H_ +#define MAD_COMMON_USERLISTS_UTIL_H_ + +#include "../export.h" + +#include "../XmlData.h" +#include + +namespace Mad { +namespace Common { +namespace UserLists { + +class UserList; +class UserListDiff; +class UserListEntry; + +class MAD_COMMON_EXPORT Util { + private: + static void serializeUserListEntry(const UserListEntry *user, XmlData::List::iterator entry); + static UserListEntry deserializeUserListEntry(XmlData::List::const_iterator entry); + + Util(); + + public: + static void serializeUserList(const UserList *list, XmlData *data); + static boost::shared_ptr deserializeUserList(const XmlData *data); + + static void serializeUserListDiff(const UserListDiff *diff, XmlData *data); + static boost::shared_ptr deserializeUserListDiff(const XmlData *data); +}; + +} +} +} + +#endif /* MAD_COMMON_USERLISTS_UTIL_H_ */ diff --git a/src/Server/Application.cpp b/src/Server/Application.cpp index f8340d5..157f5b6 100644 --- a/src/Server/Application.cpp +++ b/src/Server/Application.cpp @@ -19,13 +19,16 @@ #include "Application.h" #include "ConnectionManager.h" +#include "UserListManager.h" namespace Mad { namespace Server { -Application::Application() : Common::Application(true), connectionManager(new ConnectionManager(this)) {} +Application::Application() : Common::Application(true), connectionManager(new ConnectionManager(this)), + userListManager(new UserListManager(this)) {} Application::~Application() { + delete userListManager; delete connectionManager; } diff --git a/src/Server/Application.h b/src/Server/Application.h index 205d398..5dc1e63 100644 --- a/src/Server/Application.h +++ b/src/Server/Application.h @@ -28,10 +28,12 @@ namespace Mad { namespace Server { class ConnectionManager; +class UserListManager; class MAD_SERVER_EXPORT Application : public Common::Application { private: ConnectionManager *connectionManager; + UserListManager *userListManager; public: Application(); @@ -40,6 +42,10 @@ class MAD_SERVER_EXPORT Application : public Common::Application { ConnectionManager* getConnectionManager() const { return connectionManager; } + + UserListManager* getUserListManager() const { + return userListManager; + } }; } diff --git a/src/Server/CMakeLists.txt b/src/Server/CMakeLists.txt index 80cf25d..4414bd8 100644 --- a/src/Server/CMakeLists.txt +++ b/src/Server/CMakeLists.txt @@ -5,6 +5,9 @@ mad_library(Server RequestHandlers/ConnectionRequestHandlerGroup.cpp RequestHandlers/ConnectionRequestHandlerGroup.h RequestHandlers/DaemonRequestHandlerGroup.cpp RequestHandlers/DaemonRequestHandlerGroup.h + RequestHandlers/UserListDiffUploadRequestHandler.cpp RequestHandlers/UserListDiffUploadRequestHandler.h + RequestHandlers/UserListRequestHandlerGroup.cpp RequestHandlers/UserListRequestHandlerGroup.h + RequestHandlers/UserListUploadRequestHandler.cpp RequestHandlers/UserListUploadRequestHandler.h RequestHandlers/UserRequestHandlerGroup.cpp RequestHandlers/UserRequestHandlerGroup.h Requests/CommandRequest.cpp Requests/CommandRequest.h @@ -12,5 +15,6 @@ mad_library(Server Application.cpp Application.h ConnectionManager.cpp ConnectionManager.h + UserListManager.cpp UserListManager.h ) target_link_libraries(Server Common Net Core) diff --git a/src/Server/RequestHandlers/UserListDiffUploadRequestHandler.cpp b/src/Server/RequestHandlers/UserListDiffUploadRequestHandler.cpp new file mode 100644 index 0000000..05aadf8 --- /dev/null +++ b/src/Server/RequestHandlers/UserListDiffUploadRequestHandler.cpp @@ -0,0 +1,84 @@ +/* + * UserListDiffUploadRequestHandler.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 "UserListDiffUploadRequestHandler.h" +#include "../Application.h" +#include "../UserListManager.h" + +#include + +#include + +namespace Mad { +namespace Server { +namespace RequestHandlers { + +void UserListDiffUploadRequestHandler::handlePacket(boost::shared_ptr packet) { + if(packet->getType() == "Cancel") { + Common::XmlData ret; + ret.setType("OK"); + sendPacket(ret); + + signalFinished(); + return; + } + else if(packet->getType() != "UploadUserListDiff") { + getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); + + Common::XmlData ret; + ret.setType("Error"); + ret.set("ErrorCode", Core::Exception::UNEXPECTED_PACKET); + + sendPacket(ret); + + signalFinished(); + return; + } + + if(!getConnection()->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + UserListManager *userListManager = dynamic_cast(getApplication())->getUserListManager(); + + if(name.empty()) { // Request + name = packet->get("name"); + + if(name.empty()) + name = boost::posix_time::to_simple_string(boost::posix_time::second_clock::universal_time()); + + Common::XmlData ret; + ret.setType("Continue"); + ret.set("exists", userListManager->existsUserListDiff(name)); + sendPacket(ret); + } + else { // Upload + boost::shared_ptr diff = Common::UserLists::Util::deserializeUserListDiff(packet.get()); + userListManager->storeUserListDiff(name, diff.get()); + + Common::XmlData ret; + ret.setType("OK"); + sendPacket(ret); + + signalFinished(); + } +} + +} +} +} diff --git a/src/Server/RequestHandlers/UserListDiffUploadRequestHandler.h b/src/Server/RequestHandlers/UserListDiffUploadRequestHandler.h new file mode 100644 index 0000000..3d74253 --- /dev/null +++ b/src/Server/RequestHandlers/UserListDiffUploadRequestHandler.h @@ -0,0 +1,47 @@ +/* + * UserListDiffUploadRequestHandler.h + * + * 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 . + */ + +#ifndef MAD_SERVER_REQUESTHANDLERS_USERLISTDIFFUPLOADREQUESTHANDLER_H_ +#define MAD_SERVER_REQUESTHANDLERS_USERLISTDIFFUPLOADREQUESTHANDLER_H_ + +#include + +namespace Mad { +namespace Server { + +class UserListManager; + +namespace RequestHandlers { + +class UserListDiffUploadRequestHandler : public Common::RequestHandler { + private: + std::string name; + + protected: + virtual void handlePacket(boost::shared_ptr packet); + + public: + UserListDiffUploadRequestHandler(Common::Application *application) : Common::RequestHandler(application) {} +}; + +} +} +} + +#endif /* MAD_SERVER_REQUESTHANDLERS_USERLISTDIFFUPLOADREQUESTHANDLER_H_ */ diff --git a/src/Server/RequestHandlers/UserListRequestHandlerGroup.cpp b/src/Server/RequestHandlers/UserListRequestHandlerGroup.cpp new file mode 100644 index 0000000..bb18194 --- /dev/null +++ b/src/Server/RequestHandlers/UserListRequestHandlerGroup.cpp @@ -0,0 +1,161 @@ +/* + * UserListRequestHandlerGroup.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 "UserListRequestHandlerGroup.h" +#include "../Application.h" +#include "../UserListManager.h" + +#include + +namespace Mad { +namespace Server { +namespace RequestHandlers { + +void UserListRequestHandlerGroup::handleUserListListRequest(boost::shared_ptr /*packet*/, Common::XmlData *ret, Common::Connection *connection) { + if(!connection->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + const std::set &userLists = application->getUserListManager()->getUserLists(); + + ret->setType("OK"); + Common::XmlData::List *list = ret->createList("userLists"); + + for(std::set::const_iterator userList = userLists.begin(); userList != userLists.end(); ++userList) { + Common::XmlData::List::iterator entry = list->addEntry(); + + entry->set("name", *userList); + } + +} + +void UserListRequestHandlerGroup::handleUserListDownloadRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { + if(!connection->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + boost::shared_ptr userList = application->getUserListManager()->loadUserList(packet->get("name")); + if(!userList) + throw(Core::Exception(Core::Exception::NOT_FOUND)); + + ret->setType("OK"); + Common::UserLists::Util::serializeUserList(userList.get(), ret); +} + +void UserListRequestHandlerGroup::handleUserListCopyRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { + if(!connection->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + application->getUserListManager()->copyUserList(packet->get("fromName"), packet->get("toName")); + + ret->setType("OK"); +} + +void UserListRequestHandlerGroup::handleUserListRenameRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { + if(!connection->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + application->getUserListManager()->renameUserList(packet->get("fromName"), packet->get("toName")); + + ret->setType("OK"); +} + +void UserListRequestHandlerGroup::handleUserListRemoveRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { + if(!connection->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + application->getUserListManager()->removeUserList(packet->get("name")); + + ret->setType("OK"); +} + + +void UserListRequestHandlerGroup::handleUserListDiffListRequest(boost::shared_ptr /*packet*/, Common::XmlData *ret, Common::Connection *connection) { + if(!connection->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + const std::set &userListDiffs = application->getUserListManager()->getUserListDiffs(); + + ret->setType("OK"); + Common::XmlData::List *list = ret->createList("userListDiffs"); + + for(std::set::const_iterator diff = userListDiffs.begin(); diff != userListDiffs.end(); ++diff) { + Common::XmlData::List::iterator entry = list->addEntry(); + + entry->set("name", *diff); + } + +} + +void UserListRequestHandlerGroup::handleUserListDiffDownloadRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { + if(!connection->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + boost::shared_ptr diff = application->getUserListManager()->loadUserListDiff(packet->get("name")); + if(!diff) + throw(Core::Exception(Core::Exception::NOT_FOUND)); + + ret->setType("OK"); + Common::UserLists::Util::serializeUserListDiff(diff.get(), ret); +} + +void UserListRequestHandlerGroup::handleUserListDiffCopyRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { + if(!connection->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + application->getUserListManager()->copyUserListDiff(packet->get("fromName"), packet->get("toName")); + + ret->setType("OK"); +} + +void UserListRequestHandlerGroup::handleUserListDiffRenameRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { + if(!connection->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + application->getUserListManager()->renameUserListDiff(packet->get("fromName"), packet->get("toName")); + + ret->setType("OK"); +} + +void UserListRequestHandlerGroup::handleUserListDiffRemoveRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { + if(!connection->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + application->getUserListManager()->removeUserListDiff(packet->get("name")); + + ret->setType("OK"); +} + + +UserListRequestHandlerGroup::UserListRequestHandlerGroup(Application *application0) +: application(application0) { + registerHandler("ListUserLists", boost::bind(&UserListRequestHandlerGroup::handleUserListListRequest, this, _1, _2, _3)); + registerHandler("DownloadUserList", boost::bind(&UserListRequestHandlerGroup::handleUserListDownloadRequest, this, _1, _2, _3)); + registerHandler("CopyUserList", boost::bind(&UserListRequestHandlerGroup::handleUserListCopyRequest, this, _1, _2, _3)); + registerHandler("RenameUserList", boost::bind(&UserListRequestHandlerGroup::handleUserListRenameRequest, this, _1, _2, _3)); + registerHandler("RemoveUserList", boost::bind(&UserListRequestHandlerGroup::handleUserListRemoveRequest, this, _1, _2, _3)); + + registerHandler("ListUserListDiffs", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffListRequest, this, _1, _2, _3)); + registerHandler("DownloadUserListDiff", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffDownloadRequest, this, _1, _2, _3)); + registerHandler("CopyUserListDiff", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffCopyRequest, this, _1, _2, _3)); + registerHandler("RenameUserListDiff", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffRenameRequest, this, _1, _2, _3)); + registerHandler("RemoveUserListDiff", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffRemoveRequest, this, _1, _2, _3)); +} + +} +} +} diff --git a/src/Server/RequestHandlers/UserListRequestHandlerGroup.h b/src/Server/RequestHandlers/UserListRequestHandlerGroup.h new file mode 100644 index 0000000..a7e09b3 --- /dev/null +++ b/src/Server/RequestHandlers/UserListRequestHandlerGroup.h @@ -0,0 +1,59 @@ +/* + * UserListRequestHandlerGroup.h + * + * 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 . + */ + +#ifndef MAD_SERVER_REQUESTHANDLERS_USERLISTREQUESTHANDLERGROUP_H_ +#define MAD_SERVER_REQUESTHANDLERS_USERLISTREQUESTHANDLERGROUP_H_ + +#include "../export.h" + +#include + +namespace Mad { +namespace Server { + +class Application; +class UserListManager; + +namespace RequestHandlers { + +class MAD_SERVER_EXPORT UserListRequestHandlerGroup : public Common::RequestHandlers::SimpleRequestHandlerGroup { + private: + Application *application; + + void handleUserListListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserListDownloadRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserListCopyRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserListRenameRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserListRemoveRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + + void handleUserListDiffListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserListDiffDownloadRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserListDiffCopyRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserListDiffRenameRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + void handleUserListDiffRemoveRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); + + public: + UserListRequestHandlerGroup(Application *application0); +}; + +} +} +} + +#endif /* MAD_SERVER_REQUESTHANDLERS_USERLISTREQUESTHANDLERGROUP_H_ */ diff --git a/src/Server/RequestHandlers/UserListUploadRequestHandler.cpp b/src/Server/RequestHandlers/UserListUploadRequestHandler.cpp new file mode 100644 index 0000000..307863a --- /dev/null +++ b/src/Server/RequestHandlers/UserListUploadRequestHandler.cpp @@ -0,0 +1,85 @@ +/* + * UserListUploadRequestHandler.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 "UserListUploadRequestHandler.h" +#include "../Application.h" +#include "../UserListManager.h" + +#include + +#include + + +namespace Mad { +namespace Server { +namespace RequestHandlers { + +void UserListUploadRequestHandler::handlePacket(boost::shared_ptr packet) { + if(packet->getType() == "Cancel") { + Common::XmlData ret; + ret.setType("OK"); + sendPacket(ret); + + signalFinished(); + return; + } + else if(packet->getType() != "UploadUserList") { + getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); + + Common::XmlData ret; + ret.setType("Error"); + ret.set("ErrorCode", Core::Exception::UNEXPECTED_PACKET); + + sendPacket(ret); + + signalFinished(); + return; + } + + if(!getConnection()->isAuthenticated()) + throw(Core::Exception(Core::Exception::PERMISSION)); + + UserListManager *userListManager = dynamic_cast(getApplication())->getUserListManager(); + + if(name.empty()) { // Request + name = packet->get("name"); + + if(name.empty()) + name = boost::posix_time::to_simple_string(boost::posix_time::second_clock::universal_time()); + + Common::XmlData ret; + ret.setType("Continue"); + ret.set("exists", userListManager->existsUserList(name)); + sendPacket(ret); + } + else { // Upload + boost::shared_ptr userList = Common::UserLists::Util::deserializeUserList(packet.get()); + userListManager->storeUserList(name, userList.get()); + + Common::XmlData ret; + ret.setType("OK"); + sendPacket(ret); + + signalFinished(); + } +} + +} +} +} diff --git a/src/Server/RequestHandlers/UserListUploadRequestHandler.h b/src/Server/RequestHandlers/UserListUploadRequestHandler.h new file mode 100644 index 0000000..4a20a4c --- /dev/null +++ b/src/Server/RequestHandlers/UserListUploadRequestHandler.h @@ -0,0 +1,47 @@ +/* + * UserListUploadRequestHandler.h + * + * 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 . + */ + +#ifndef MAD_SERVER_REQUESTHANDLERS_USERLISTUPLOADREQUESTHANDLER_H_ +#define MAD_SERVER_REQUESTHANDLERS_USERLISTUPLOADREQUESTHANDLER_H_ + +#include + +namespace Mad { +namespace Server { + +class UserListManager; + +namespace RequestHandlers { + +class UserListUploadRequestHandler : public Common::RequestHandler { + private: + std::string name; + + protected: + virtual void handlePacket(boost::shared_ptr packet); + + public: + UserListUploadRequestHandler(Common::Application *application) : Common::RequestHandler(application) {} +}; + +} +} +} + +#endif /* MAD_SERVER_REQUESTHANDLERS_USERLISTUPLOADREQUESTHANDLER_H_ */ diff --git a/src/Server/UserListManager.cpp b/src/Server/UserListManager.cpp new file mode 100644 index 0000000..d1a6e31 --- /dev/null +++ b/src/Server/UserListManager.cpp @@ -0,0 +1,151 @@ +/* + * 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->getConfigManager()->registerConfigurable(this); +} + +UserListManager::~UserListManager() { + application->getRequestManager()->unregisterPacketType("UploadUserList"); + application->getRequestManager()->unregisterPacketType("UploadUserListDiff"); + application->getRequestManager()->unregisterRequestHandlerGroup(requestHandlerGroup); + application->getConfigManager()->unregisterConfigurable(this); +} + + +void UserListManager::configFinished() { + userLists = application->getStorageManager()->list("UserList"); + userListDiffs = application->getStorageManager()->list("UserListDiff"); + + application->getRequestManager()->registerRequestHandlerGroup(requestHandlerGroup); + application->getRequestManager()->registerPacketType("UploadUserList"); + application->getRequestManager()->registerPacketType("UploadUserListDiff"); +} + +bool UserListManager::existsUserList(const std::string &name) { + return application->getStorageManager()->exists("UserList", name); +} + +boost::shared_ptr UserListManager::loadUserList(const std::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 std::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 std::string &fromName, const std::string &toName) { + application->getStorageManager()->copy("UserList", fromName, toName); +} + +void UserListManager::renameUserList(const std::string &fromName, const std::string &toName) { + application->getStorageManager()->rename("UserList", fromName, toName); +} + +void UserListManager::removeUserList(const std::string &name) { + application->getStorageManager()->remove("UserList", name); +} + + +bool UserListManager::existsUserListDiff(const std::string &name) { + return application->getStorageManager()->exists("UserListDiff", name); +} + +boost::shared_ptr UserListManager::loadUserListDiff(const std::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 std::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 std::string &fromName, const std::string &toName) { + application->getStorageManager()->copy("UserListDiff", fromName, toName); +} + +void UserListManager::renameUserListDiff(const std::string &fromName, const std::string &toName) { + application->getStorageManager()->rename("UserListDiff", fromName, toName); +} + +void UserListManager::removeUserListDiff(const std::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()); + std::string groupname; + + if(group != groupList->end()) { + groupname = group->second.getName(); + } + else { + std::ostringstream stream; + stream << user->second.getGid(); + groupname = stream.str(); + } + + Common::UserLists::UserListEntry entry(user->second.getUsername(), groupname); + entry.setDetail("Full name", user->second.getFullName()); + + list->push_back(entry); + } + + return list; +} + +} +} diff --git a/src/Server/UserListManager.h b/src/Server/UserListManager.h new file mode 100644 index 0000000..1651d42 --- /dev/null +++ b/src/Server/UserListManager.h @@ -0,0 +1,95 @@ +/* + * UserListManager.h + * + * 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 . + */ + +#ifndef MAD_SERVER_USERLISTMANAGER_H_ +#define MAD_SERVER_USERLISTMANAGER_H_ + +#include "export.h" + +#include + +#include +#include + +#include + +namespace Mad { + +namespace Common { +namespace UserLists { +class UserList; +class UserListDiff; +} +} + +namespace Server { + +class Application; + +namespace RequestHandlers { +class UserListRequestHandlerGroup; +} + +class MAD_SERVER_EXPORT UserListManager : private Core::Configurable, private boost::noncopyable { + private: + Application *application; + + boost::shared_ptr requestHandlerGroup; + + std::set userLists; + std::set userListDiffs; + + protected: + virtual void configFinished(); + + public: + virtual int getPriority() const {return -1;} + + UserListManager(Application *application0); + virtual ~UserListManager(); + + const std::set& getUserLists() const { + return userLists; + } + + bool existsUserList(const std::string &name); + boost::shared_ptr loadUserList(const std::string &name); + void storeUserList(const std::string &name, const Common::UserLists::UserList *list); + void copyUserList(const std::string &fromName, const std::string &toName); + void renameUserList(const std::string &fromName, const std::string &toName); + void removeUserList(const std::string &name); + + const std::set& getUserListDiffs() const { + return userListDiffs; + } + + bool existsUserListDiff(const std::string &name); + boost::shared_ptr loadUserListDiff(const std::string &name); + void storeUserListDiff(const std::string &name, const Common::UserLists::UserListDiff *list); + void copyUserListDiff(const std::string &fromName, const std::string &toName); + void renameUserListDiff(const std::string &fromName, const std::string &toName); + void removeUserListDiff(const std::string &name); + + boost::shared_ptr getCurrentUserList(); +}; + +} +} + +#endif /* MAD_SERVER_USERLISTMANAGER_H_ */ diff --git a/src/mad-server.conf b/src/mad-server.conf index d83f9b4..ad2a955 100644 --- a/src/mad-server.conf +++ b/src/mad-server.conf @@ -13,8 +13,6 @@ LoadModule "UserDBBackendMysql" LoadModule "UserConfigBackendHome" LoadModule "UserConfigBackendKrb5" -LoadModule "UserListManager" - Log Console { Level "verbose" } @@ -36,7 +34,7 @@ AuthProviderFile { } Storage { - Root "/tmp/storage" + Root "/home/neoraider/.mad/storage" } UserManager { diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 6681ad7..2f497de 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -53,8 +53,6 @@ if(MYSQL_FOUND) add_subdirectory(UserDBBackendMysql) endif(MYSQL_FOUND) -add_subdirectory(UserListManager) - SET(STATIC_MODULE_LOADERS "") SET(STATIC_MODULE_LIST "") diff --git a/src/modules/UserListManager/CMakeLists.txt b/src/modules/UserListManager/CMakeLists.txt deleted file mode 100644 index f8e72ce..0000000 --- a/src/modules/UserListManager/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -include_directories(${INCLUDES}) - -mad_module(UserListManager - RequestHandlers/UserListDiffUploadRequestHandler.cpp RequestHandlers/UserListDiffUploadRequestHandler.h - RequestHandlers/UserListRequestHandlerGroup.cpp RequestHandlers/UserListRequestHandlerGroup.h - RequestHandlers/UserListUploadRequestHandler.cpp RequestHandlers/UserListUploadRequestHandler.h - - Module.cpp Module.h - UserList.h - UserListDiff.cpp UserListDiff.h - UserListEntry.h - UserListManager.cpp UserListManager.h - Util.cpp Util.h -) - -mad_module_libraries(UserListManager) diff --git a/src/modules/UserListManager/Module.cpp b/src/modules/UserListManager/Module.cpp deleted file mode 100644 index 2145a32..0000000 --- a/src/modules/UserListManager/Module.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Module.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 "../export.h" - -#include "Module.h" - -#include - -extern "C" { - -MAD_MODULE_EXPORT Mad::Common::Module* UserListManager_create(Mad::Common::Application *application) { - Mad::Server::Application *serverApp = dynamic_cast(application); - - if(!serverApp) { - application->log(Mad::Core::Logger::LOG_ERROR, "UserListManager: This module can be used with mad-server only."); - return 0; - } - - return new Mad::Modules::UserListManager::Module(serverApp); -} - -} diff --git a/src/modules/UserListManager/Module.h b/src/modules/UserListManager/Module.h deleted file mode 100644 index 035cdaa..0000000 --- a/src/modules/UserListManager/Module.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Module.h - * - * 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 . - */ - -#ifndef MAD_MODULES_USERLISTMANAGER_MODULE_H_ -#define MAD_MODULES_USERLISTMANAGER_MODULE_H_ - -#include "UserListManager.h" -#include - -#include - -namespace Mad { -namespace Modules { -namespace UserListManager { - -class Module : public Common::Module { - private: - boost::scoped_ptr userListManager; - - public: - Module(Server::Application *application) : userListManager(new UserListManager(application)) {} -}; - -} -} -} - -#endif /* MAD_MODULES_USERLISTMANAGER_MODULE_H_ */ diff --git a/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp b/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp deleted file mode 100644 index 4660850..0000000 --- a/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * UserListDiffUploadRequestHandler.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 "UserListDiffUploadRequestHandler.h" -#include "../UserListManager.h" -#include "../Util.h" - -#include - -namespace Mad { -namespace Modules { -namespace UserListManager { -namespace RequestHandlers { - -void UserListDiffUploadRequestHandler::handlePacket(boost::shared_ptr packet) { - if(packet->getType() == "Cancel") { - Common::XmlData ret; - ret.setType("OK"); - sendPacket(ret); - - signalFinished(); - return; - } - else if(packet->getType() != "UploadUserListDiff") { - getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); - - Common::XmlData ret; - ret.setType("Error"); - ret.set("ErrorCode", Core::Exception::UNEXPECTED_PACKET); - - sendPacket(ret); - - signalFinished(); - return; - } - - if(!getConnection()->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - if(name.empty()) { // Request - name = packet->get("name"); - - if(name.empty()) - name = boost::posix_time::to_simple_string(boost::posix_time::second_clock::universal_time()); - - Common::XmlData ret; - ret.setType("Continue"); - ret.set("exists", userListManager->existsUserListDiff(name)); - sendPacket(ret); - } - else { // Upload - boost::shared_ptr diff = Util::deserializeUserListDiff(packet.get()); - userListManager->storeUserListDiff(name, diff.get()); - - Common::XmlData ret; - ret.setType("OK"); - sendPacket(ret); - - signalFinished(); - } -} - -} -} -} -} diff --git a/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.h b/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.h deleted file mode 100644 index 205a87f..0000000 --- a/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * UserListDiffUploadRequestHandler.h - * - * 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 . - */ - -#ifndef MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTDIFFUPLOADREQUESTHANDLER_H_ -#define MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTDIFFUPLOADREQUESTHANDLER_H_ - -#include - -namespace Mad { -namespace Modules { -namespace UserListManager { - -class UserListManager; - -namespace RequestHandlers { - -class UserListDiffUploadRequestHandler : public Common::RequestHandler { - private: - std::string name; - - UserListManager *userListManager; - - protected: - virtual void handlePacket(boost::shared_ptr packet); - - public: - UserListDiffUploadRequestHandler(Common::Application *application, UserListManager *userListManager0) : Common::RequestHandler(application), userListManager(userListManager0) {} -}; - -} -} -} -} - -#endif /* MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTDIFFUPLOADREQUESTHANDLER_H_ */ diff --git a/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp b/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp deleted file mode 100644 index 61bbf07..0000000 --- a/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * UserListRequestHandlerGroup.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 "UserListRequestHandlerGroup.h" -#include "../UserListManager.h" -#include "../Util.h" - -namespace Mad { -namespace Modules { -namespace UserListManager { -namespace RequestHandlers { - -void UserListRequestHandlerGroup::handleUserListListRequest(boost::shared_ptr /*packet*/, Common::XmlData *ret, Common::Connection *connection) { - if(!connection->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - const std::set &userLists = userListManager->getUserLists(); - - ret->setType("OK"); - Common::XmlData::List *list = ret->createList("userLists"); - - for(std::set::const_iterator userList = userLists.begin(); userList != userLists.end(); ++userList) { - Common::XmlData::List::iterator entry = list->addEntry(); - - entry->set("name", *userList); - } - -} - -void UserListRequestHandlerGroup::handleUserListDownloadRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { - if(!connection->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - boost::shared_ptr userList = userListManager->loadUserList(packet->get("name")); - if(!userList) - throw(Core::Exception(Core::Exception::NOT_FOUND)); - - ret->setType("OK"); - Util::serializeUserList(userList.get(), ret); -} - -void UserListRequestHandlerGroup::handleUserListCopyRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { - if(!connection->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - userListManager->copyUserList(packet->get("fromName"), packet->get("toName")); - - ret->setType("OK"); -} - -void UserListRequestHandlerGroup::handleUserListRenameRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { - if(!connection->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - userListManager->renameUserList(packet->get("fromName"), packet->get("toName")); - - ret->setType("OK"); -} - -void UserListRequestHandlerGroup::handleUserListRemoveRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { - if(!connection->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - userListManager->removeUserList(packet->get("name")); - - ret->setType("OK"); -} - - -void UserListRequestHandlerGroup::handleUserListDiffListRequest(boost::shared_ptr /*packet*/, Common::XmlData *ret, Common::Connection *connection) { - if(!connection->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - const std::set &userListDiffs = userListManager->getUserListDiffs(); - - ret->setType("OK"); - Common::XmlData::List *list = ret->createList("userListDiffs"); - - for(std::set::const_iterator diff = userListDiffs.begin(); diff != userListDiffs.end(); ++diff) { - Common::XmlData::List::iterator entry = list->addEntry(); - - entry->set("name", *diff); - } - -} - -void UserListRequestHandlerGroup::handleUserListDiffDownloadRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { - if(!connection->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - boost::shared_ptr diff = userListManager->loadUserListDiff(packet->get("name")); - if(!diff) - throw(Core::Exception(Core::Exception::NOT_FOUND)); - - ret->setType("OK"); - Util::serializeUserListDiff(diff.get(), ret); -} - -void UserListRequestHandlerGroup::handleUserListDiffCopyRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { - if(!connection->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - userListManager->copyUserListDiff(packet->get("fromName"), packet->get("toName")); - - ret->setType("OK"); -} - -void UserListRequestHandlerGroup::handleUserListDiffRenameRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { - if(!connection->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - userListManager->renameUserListDiff(packet->get("fromName"), packet->get("toName")); - - ret->setType("OK"); -} - -void UserListRequestHandlerGroup::handleUserListDiffRemoveRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection) { - if(!connection->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - userListManager->removeUserListDiff(packet->get("name")); - - ret->setType("OK"); -} - - -UserListRequestHandlerGroup::UserListRequestHandlerGroup(Server::Application *application0, UserListManager *userListManager0) -: application(application0), userListManager(userListManager0) { - registerHandler("ListUserLists", boost::bind(&UserListRequestHandlerGroup::handleUserListListRequest, this, _1, _2, _3)); - registerHandler("DownloadUserList", boost::bind(&UserListRequestHandlerGroup::handleUserListDownloadRequest, this, _1, _2, _3)); - registerHandler("CopyUserList", boost::bind(&UserListRequestHandlerGroup::handleUserListCopyRequest, this, _1, _2, _3)); - registerHandler("RenameUserList", boost::bind(&UserListRequestHandlerGroup::handleUserListRenameRequest, this, _1, _2, _3)); - registerHandler("RemoveUserList", boost::bind(&UserListRequestHandlerGroup::handleUserListRemoveRequest, this, _1, _2, _3)); - - registerHandler("ListUserListDiffs", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffListRequest, this, _1, _2, _3)); - registerHandler("DownloadUserListDiff", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffDownloadRequest, this, _1, _2, _3)); - registerHandler("CopyUserListDiff", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffCopyRequest, this, _1, _2, _3)); - registerHandler("RenameUserListDiff", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffRenameRequest, this, _1, _2, _3)); - registerHandler("RemoveUserListDiff", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffRemoveRequest, this, _1, _2, _3)); -} - -} -} -} -} diff --git a/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.h b/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.h deleted file mode 100644 index 61f4c7d..0000000 --- a/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * UserListRequestHandlerGroup.h - * - * 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 . - */ - -#ifndef MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTREQUESTHANDLERGROUP_H_ -#define MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTREQUESTHANDLERGROUP_H_ - -#include "../../export.h" - -#include - -namespace Mad { - -namespace Server { -class Application; -} - -namespace Modules { -namespace UserListManager { - -class UserListManager; - -namespace RequestHandlers { - -class MAD_MODULE_EXPORT UserListRequestHandlerGroup : public Common::RequestHandlers::SimpleRequestHandlerGroup { - private: - Server::Application *application; - UserListManager *userListManager; - - void handleUserListListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleUserListDownloadRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleUserListCopyRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleUserListRenameRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleUserListRemoveRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - - void handleUserListDiffListRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleUserListDiffDownloadRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleUserListDiffCopyRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleUserListDiffRenameRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - void handleUserListDiffRemoveRequest(boost::shared_ptr packet, Common::XmlData *ret, Common::Connection *connection); - - public: - UserListRequestHandlerGroup(Server::Application *application0, UserListManager *userListManager0); -}; - -} -} -} -} - -#endif /* MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTREQUESTHANDLERGROUP_H_ */ diff --git a/src/modules/UserListManager/RequestHandlers/UserListUploadRequestHandler.cpp b/src/modules/UserListManager/RequestHandlers/UserListUploadRequestHandler.cpp deleted file mode 100644 index 9d01b5e..0000000 --- a/src/modules/UserListManager/RequestHandlers/UserListUploadRequestHandler.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * UserListUploadRequestHandler.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 "UserListUploadRequestHandler.h" -#include "../UserListManager.h" -#include "../Util.h" - -#include - - -namespace Mad { -namespace Modules { -namespace UserListManager { -namespace RequestHandlers { - -void UserListUploadRequestHandler::handlePacket(boost::shared_ptr packet) { - if(packet->getType() == "Cancel") { - Common::XmlData ret; - ret.setType("OK"); - sendPacket(ret); - - signalFinished(); - return; - } - else if(packet->getType() != "UploadUserList") { - getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); - - Common::XmlData ret; - ret.setType("Error"); - ret.set("ErrorCode", Core::Exception::UNEXPECTED_PACKET); - - sendPacket(ret); - - signalFinished(); - return; - } - - if(!getConnection()->isAuthenticated()) - throw(Core::Exception(Core::Exception::PERMISSION)); - - if(name.empty()) { // Request - name = packet->get("name"); - - if(name.empty()) - name = boost::posix_time::to_simple_string(boost::posix_time::second_clock::universal_time()); - - Common::XmlData ret; - ret.setType("Continue"); - ret.set("exists", userListManager->existsUserList(name)); - sendPacket(ret); - } - else { // Upload - boost::shared_ptr userList = Util::deserializeUserList(packet.get()); - userListManager->storeUserList(name, userList.get()); - - Common::XmlData ret; - ret.setType("OK"); - sendPacket(ret); - - signalFinished(); - } -} - -} -} -} -} diff --git a/src/modules/UserListManager/RequestHandlers/UserListUploadRequestHandler.h b/src/modules/UserListManager/RequestHandlers/UserListUploadRequestHandler.h deleted file mode 100644 index 933d4a5..0000000 --- a/src/modules/UserListManager/RequestHandlers/UserListUploadRequestHandler.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * UserListUploadRequestHandler.h - * - * 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 . - */ - -#ifndef MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTUPLOADREQUESTHANDLER_H_ -#define MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTUPLOADREQUESTHANDLER_H_ - -#include - -namespace Mad { -namespace Modules { -namespace UserListManager { - -class UserListManager; - -namespace RequestHandlers { - -class UserListUploadRequestHandler : public Common::RequestHandler { - private: - std::string name; - - UserListManager *userListManager; - - protected: - virtual void handlePacket(boost::shared_ptr packet); - - public: - UserListUploadRequestHandler(Common::Application *application, UserListManager *userListManager0) : Common::RequestHandler(application), userListManager(userListManager0) {} -}; - -} -} -} -} - -#endif /* MAD_MODULES_USERLISTMANAGER_REQUESTHANDLERS_USERLISTUPLOADREQUESTHANDLER_H_ */ diff --git a/src/modules/UserListManager/UserList.h b/src/modules/UserListManager/UserList.h deleted file mode 100644 index 6ca3de4..0000000 --- a/src/modules/UserListManager/UserList.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * UserList.h - * - * 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 . - */ - -#ifndef MAD_MODULES_USERLISTMANAGER_USERLIST_H_ -#define MAD_MODULES_USERLISTMANAGER_USERLIST_H_ - -#include "UserListEntry.h" - -#include - -namespace Mad { -namespace Modules { -namespace UserListManager { - -class UserList : public std::list { - public: - UserList() {} -}; - -} -} -} - -#endif /* MAD_MODULES_USERLISTMANAGER_USERLIST_H_ */ diff --git a/src/modules/UserListManager/UserListDiff.cpp b/src/modules/UserListManager/UserListDiff.cpp deleted file mode 100644 index a7b5f2f..0000000 --- a/src/modules/UserListManager/UserListDiff.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * UserListDiff.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 "UserListDiff.h" -#include "UserList.h" - -namespace Mad { -namespace Modules { -namespace UserListManager { - -UserListDiff::UserListDiff(const UserList *oldList, const UserList *newList) { - for(UserList::const_iterator user = oldList->begin(); user != oldList->end(); ++user) - deletedUsers.insert(*user); - - for(UserList::const_iterator user = newList->begin(); user != newList->end(); ++user) { - std::set::const_iterator it = deletedUsers.find(*user); - - if(it != deletedUsers.end()) { - deletedUsers.erase(it); - unchangedUsers.insert(*user); - } - else { - addedUsers.insert(*user); - } - } -} - -} -} -} diff --git a/src/modules/UserListManager/UserListDiff.h b/src/modules/UserListManager/UserListDiff.h deleted file mode 100644 index de881bd..0000000 --- a/src/modules/UserListManager/UserListDiff.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * UserListDiff.h - * - * 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 . - */ - -#ifndef MAD_MODULES_USERLISTMANAGER_USERLISTDIFF_H_ -#define MAD_MODULES_USERLISTMANAGER_USERLISTDIFF_H_ - -#include "../export.h" - -#include "UserListEntry.h" -#include - -#include - -namespace Mad { -namespace Modules { -namespace UserListManager { - -class UserList; - -class MAD_MODULE_EXPORT UserListDiff { - private: - std::set addedUsers; - std::set deletedUsers; - std::set unchangedUsers; - - public: - UserListDiff() {} - UserListDiff(const UserList *oldList, const UserList *newList); - - void invert() { - addedUsers.swap(deletedUsers); - } - - const std::set& getAddedUsers() const { - return addedUsers; - } - - const std::set& getDeletedUsers() const { - return deletedUsers; - } - - const std::set& getUnchangedUsers() const { - return unchangedUsers; - } - - bool insertAddedUser(UserListEntry user) { - if(deletedUsers.count(user) || unchangedUsers.count(user)) - return false; - - return addedUsers.insert(user).second; - } - - bool insertDeletedUser(UserListEntry user) { - if(addedUsers.count(user) || unchangedUsers.count(user)) - return false; - - return deletedUsers.insert(user).second; - } - - bool insertUnchangedUser(UserListEntry user) { - if(addedUsers.count(user) || deletedUsers.count(user)) - return false; - - return unchangedUsers.insert(user).second; - } -}; - -} -} -} - -#endif /* MAD_MODULES_USERLISTMANAGER_USERLISTDIFF_H_ */ diff --git a/src/modules/UserListManager/UserListEntry.h b/src/modules/UserListManager/UserListEntry.h deleted file mode 100644 index 59776d6..0000000 --- a/src/modules/UserListManager/UserListEntry.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * UserListEntry.h - * - * 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 . - */ - -#ifndef MAD_MODULES_USERLISTMANAGER_USERLISTENTRY_H_ -#define MAD_MODULES_USERLISTMANAGER_USERLISTENTRY_H_ - -#include -#include -#include - - -namespace Mad { -namespace Modules { -namespace UserListManager { - -class UserListEntry { - private: - std::string name; - std::string group; - - std::map details; - - public: - UserListEntry(const std::string &name0 = std::string(), const std::string &group0 = std::string()) : name(name0), group(group0) {} - - const std::string& getName() const { - return name; - } - - void setName(const std::string &newName) { - name = newName; - } - - const std::string& getGroup() const { - return group; - } - - void setGroup(const std::string &newGroup) { - group = newGroup; - } - - std::set getDetailList() const { - std::set ret; - - for(std::map::const_iterator it = details.begin(); it != details.end(); ++it) - ret.insert(it->first); - - return ret; - } - - std::string getDetail(const std::string &name) const { - std::map::const_iterator it = details.find(name); - if(it != details.end()) - return it->second; - else - return std::string(); - } - - void setDetail(const std::string &name, const std::string &value) { - details.erase(name); - details.insert(std::make_pair(name, value)); - } - - void unsetDetail(const std::string &name) { - details.erase(name); - } - - bool operator<(const UserListEntry o) const { - return (name < o.name); - } -}; - -} -} -} - -#endif /* MAD_MODULES_USERLISTMANAGER_USERLISTENTRY_H_ */ diff --git a/src/modules/UserListManager/UserListManager.cpp b/src/modules/UserListManager/UserListManager.cpp deleted file mode 100644 index deb6214..0000000 --- a/src/modules/UserListManager/UserListManager.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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 "UserList.h" -#include "Util.h" -#include "RequestHandlers/UserListRequestHandlerGroup.h" -#include "RequestHandlers/UserListUploadRequestHandler.h" -#include "RequestHandlers/UserListDiffUploadRequestHandler.h" - -#include -#include -#include -#include -#include - -namespace Mad { -namespace Modules { -namespace UserListManager { - -UserListManager::UserListManager(Server::Application *application0) : application(application0), requestHandlerGroup(new RequestHandlers::UserListRequestHandlerGroup(application, this)) { - application->getConfigManager()->registerConfigurable(this); -} - -UserListManager::~UserListManager() { - application->getRequestManager()->unregisterPacketType("UploadUserList"); - application->getRequestManager()->unregisterPacketType("UploadUserListDiff"); - application->getRequestManager()->unregisterRequestHandlerGroup(requestHandlerGroup); - application->getConfigManager()->unregisterConfigurable(this); -} - - -void UserListManager::configFinished() { - userLists = application->getStorageManager()->list("UserList"); - userListDiffs = application->getStorageManager()->list("UserListDiff"); - - application->getRequestManager()->registerRequestHandlerGroup(requestHandlerGroup); - application->getRequestManager()->registerPacketType("UploadUserList", this); - application->getRequestManager()->registerPacketType("UploadUserListDiff", this); -} - -bool UserListManager::existsUserList(const std::string &name) { - return application->getStorageManager()->exists("UserList", name); -} - -boost::shared_ptr UserListManager::loadUserList(const std::string &name) { - boost::shared_ptr data = application->getStorageManager()->load("UserList", name); - - if(!data) - return boost::shared_ptr(); - - return Util::deserializeUserList(data.get()); -} - -void UserListManager::storeUserList(const std::string &name, const UserList *list) { - Common::XmlData data; - - Util::serializeUserList(list, &data); - application->getStorageManager()->store("UserList", name, &data); -} - -void UserListManager::copyUserList(const std::string &fromName, const std::string &toName) { - application->getStorageManager()->copy("UserList", fromName, toName); -} - -void UserListManager::renameUserList(const std::string &fromName, const std::string &toName) { - application->getStorageManager()->rename("UserList", fromName, toName); -} - -void UserListManager::removeUserList(const std::string &name) { - application->getStorageManager()->remove("UserList", name); -} - - -bool UserListManager::existsUserListDiff(const std::string &name) { - return application->getStorageManager()->exists("UserListDiff", name); -} - -boost::shared_ptr UserListManager::loadUserListDiff(const std::string &name) { - boost::shared_ptr data = application->getStorageManager()->load("UserListDiff", name); - - if(!data) - return boost::shared_ptr(); - - return Util::deserializeUserListDiff(data.get()); -} - -void UserListManager::storeUserListDiff(const std::string &name, const UserListDiff *list) { - Common::XmlData data; - - Util::serializeUserListDiff(list, &data); - application->getStorageManager()->store("UserListDiff", name, &data); -} - -void UserListManager::copyUserListDiff(const std::string &fromName, const std::string &toName) { - application->getStorageManager()->copy("UserListDiff", fromName, toName); -} - -void UserListManager::renameUserListDiff(const std::string &fromName, const std::string &toName) { - application->getStorageManager()->rename("UserListDiff", fromName, toName); -} - -void UserListManager::removeUserListDiff(const std::string &name) { - application->getStorageManager()->remove("UserListDiff", name); -} - -boost::shared_ptr UserListManager::getCurrentUserList() { - boost::shared_ptr list(new 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()); - std::string groupname; - - if(group != groupList->end()) { - groupname = group->second.getName(); - } - else { - std::ostringstream stream; - stream << user->second.getGid(); - groupname = stream.str(); - } - - UserListEntry entry(user->second.getUsername(), groupname); - entry.setDetail("Full name", user->second.getFullName()); - - list->push_back(entry); - } - - return list; -} - -} -} -} diff --git a/src/modules/UserListManager/UserListManager.h b/src/modules/UserListManager/UserListManager.h deleted file mode 100644 index 6763dae..0000000 --- a/src/modules/UserListManager/UserListManager.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * UserListManager.h - * - * 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 . - */ - -#ifndef MAD_MODULES_USERLISTMANAGER_USERLISTMANAGER_H_ -#define MAD_MODULES_USERLISTMANAGER_USERLISTMANAGER_H_ - -#include "../export.h" - -#include - -#include -#include - -#include - -namespace Mad { - -namespace Server { -class Application; -} - -namespace Modules { -namespace UserListManager { - -namespace RequestHandlers { -class UserListRequestHandlerGroup; -} - -class UserList; -class UserListDiff; - -class MAD_MODULE_EXPORT UserListManager : private Core::Configurable, private boost::noncopyable { - private: - Server::Application *application; - - boost::shared_ptr requestHandlerGroup; - - std::set userLists; - std::set userListDiffs; - - protected: - virtual void configFinished(); - - public: - virtual int getPriority() const {return -1;} - - UserListManager(Server::Application *application0); - virtual ~UserListManager(); - - const std::set& getUserLists() const { - return userLists; - } - - bool existsUserList(const std::string &name); - boost::shared_ptr loadUserList(const std::string &name); - void storeUserList(const std::string &name, const UserList *list); - void copyUserList(const std::string &fromName, const std::string &toName); - void renameUserList(const std::string &fromName, const std::string &toName); - void removeUserList(const std::string &name); - - const std::set& getUserListDiffs() const { - return userListDiffs; - } - - bool existsUserListDiff(const std::string &name); - boost::shared_ptr loadUserListDiff(const std::string &name); - void storeUserListDiff(const std::string &name, const UserListDiff *list); - void copyUserListDiff(const std::string &fromName, const std::string &toName); - void renameUserListDiff(const std::string &fromName, const std::string &toName); - void removeUserListDiff(const std::string &name); - - boost::shared_ptr getCurrentUserList(); -}; - -} -} -} - -#endif /* MAD_MODULES_USERLISTMANAGER_USERLISTMANAGER_H_ */ diff --git a/src/modules/UserListManager/Util.cpp b/src/modules/UserListManager/Util.cpp deleted file mode 100644 index 9b986d8..0000000 --- a/src/modules/UserListManager/Util.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Util.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 "Util.h" -#include "UserList.h" -#include "UserListDiff.h" - -#include - -namespace Mad { -namespace Modules { -namespace UserListManager { - -void Util::serializeUserListEntry(const UserListEntry *user, Common::XmlData::List::iterator entry) { - std::set details = user->getDetailList(); - for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) - entry->set(*detail, user->getDetail(*detail)); - - entry->set("name", user->getName()); - entry->set("group", user->getGroup()); -} - -UserListEntry Util::deserializeUserListEntry(Common::XmlData::List::const_iterator entry) { - UserListEntry user(entry->get("name"), entry->get("group")); - - std::set details = entry->getChildren(); - for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { - if(*detail == "user" || *detail == "group") - continue; - - user.setDetail(*detail, entry->get(*detail)); - } - - return user; -} - -void Util::serializeUserList(const UserList *list, Common::XmlData *data) { - Common::XmlData::List *userList = data->createList("users"); - - for(UserList::const_iterator user = list->begin(); user != list->end(); ++user) - serializeUserListEntry(&*user, userList->addEntry()); -} - -boost::shared_ptr Util::deserializeUserList(const Common::XmlData *data) { - boost::shared_ptr users(new UserList); - - const Common::XmlData::List *userList = data->getList("users"); - - if(userList) { - for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) - users->push_back(deserializeUserListEntry(user)); - } - - return users; -} - -void Util::serializeUserListDiff(const UserListDiff *diff, Common::XmlData *data) { - Common::XmlData::List *userList = data->createList("addedUsers"); - for(std::set::const_iterator user = diff->getAddedUsers().begin(); user != diff->getAddedUsers().end(); ++user) - serializeUserListEntry(&*user, userList->addEntry()); - - userList = data->createList("deletedUsers"); - for(std::set::const_iterator user = diff->getDeletedUsers().begin(); user != diff->getDeletedUsers().end(); ++user) - serializeUserListEntry(&*user, userList->addEntry()); - - userList = data->createList("unchangedUsers"); - for(std::set::const_iterator user = diff->getUnchangedUsers().begin(); user != diff->getUnchangedUsers().end(); ++user) - serializeUserListEntry(&*user, userList->addEntry()); -} - -boost::shared_ptr Util::deserializeUserListDiff(const Common::XmlData *data) { - boost::shared_ptr diff(new UserListDiff); - - const Common::XmlData::List *userList = data->getList("addedUsers"); - if(userList) { - for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) - diff->insertAddedUser(deserializeUserListEntry(user)); - } - - userList = data->getList("deletedUsers"); - if(userList) { - for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) - diff->insertDeletedUser(deserializeUserListEntry(user)); - } - - userList = data->getList("unchangedUsers"); - if(userList) { - for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) - diff->insertUnchangedUser(deserializeUserListEntry(user)); - } - - return diff; -} - -} -} -} diff --git a/src/modules/UserListManager/Util.h b/src/modules/UserListManager/Util.h deleted file mode 100644 index c9b9a2c..0000000 --- a/src/modules/UserListManager/Util.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Util.h - * - * 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 . - */ - -#ifndef MAD_MODULES_USERLISTMANAGER_UTIL_H_ -#define MAD_MODULES_USERLISTMANAGER_UTIL_H_ - -#include "../export.h" - -#include -#include - -namespace Mad { -namespace Modules { -namespace UserListManager { - -class UserList; -class UserListDiff; -class UserListEntry; - -class MAD_MODULE_EXPORT Util { - private: - static void serializeUserListEntry(const UserListEntry *user, Common::XmlData::List::iterator entry); - static UserListEntry deserializeUserListEntry(Common::XmlData::List::const_iterator entry); - - Util(); - - public: - static void serializeUserList(const UserList *list, Common::XmlData *data); - static boost::shared_ptr deserializeUserList(const Common::XmlData *data); - - static void serializeUserListDiff(const UserListDiff *diff, Common::XmlData *data); - static boost::shared_ptr deserializeUserListDiff(const Common::XmlData *data); -}; - -} -} -} - -#endif /* MAD_MODULES_USERLISTMANAGER_UTIL_H_ */ -- cgit v1.2.3