/* * 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(); } } } } } }