From 78db15a780cc5389fc6e01d500d5c91bdd8bc422 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 19 Sep 2009 18:12:26 +0200 Subject: UserListManager: Added user list diff support. --- .../UserListRequestHandlerGroup.cpp | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp') diff --git a/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp b/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp index 98d2815..99d2818 100644 --- a/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp +++ b/src/modules/UserListManager/RequestHandlers/UserListRequestHandlerGroup.cpp @@ -64,11 +64,55 @@ void UserListRequestHandlerGroup::handleUserListRemoveRequest(boost::shared_ptr< 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::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("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("RemoveUserListDiff", boost::bind(&UserListRequestHandlerGroup::handleUserListDiffRemoveRequest, this, _1, _2, _3)); } } -- cgit v1.2.3