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. --- .../UserListDiffUploadRequestHandler.cpp | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp (limited to 'src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp') diff --git a/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp b/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp new file mode 100644 index 0000000..4660850 --- /dev/null +++ b/src/modules/UserListManager/RequestHandlers/UserListDiffUploadRequestHandler.cpp @@ -0,0 +1,82 @@ +/* + * 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(); + } +} + +} +} +} +} -- cgit v1.2.3