Files
@ 022a723079d8
Branch filter:
Location: libtransport.git/src/rosterresponder.cpp - annotation
022a723079d8
4.0 KiB
text/x-c++hdr
working joining/leaving XMPP MUC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 7a0e5e31e6e2 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 8ab47cce7012 8ab47cce7012 8ab47cce7012 ac7bbb6cccf3 c00d5149d528 c00d5149d528 c00d5149d528 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a c00d5149d528 c00d5149d528 7a0e5e31e6e2 525a07a4d19a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 07859ef3936a 23782242786f 23782242786f 8ab47cce7012 8ab47cce7012 7b5810a41076 7b5810a41076 7b5810a41076 8ab47cce7012 8ab47cce7012 9477e3f83882 07859ef3936a 07859ef3936a 07859ef3936a 525a07a4d19a 525a07a4d19a ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 c00d5149d528 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 c00d5149d528 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 c00d5149d528 a6781df77f76 6d96d5725b0d 6d96d5725b0d 6d96d5725b0d 6d96d5725b0d ac7bbb6cccf3 ac7bbb6cccf3 c00d5149d528 a6781df77f76 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 90aacd41d9df c00d5149d528 ac7bbb6cccf3 ac7bbb6cccf3 ac7bbb6cccf3 a6781df77f76 ac7bbb6cccf3 ac7bbb6cccf3 525a07a4d19a 525a07a4d19a 525a07a4d19a 07859ef3936a | /**
* XMPP - libpurple transport
*
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include "transport/rosterresponder.h"
#include <iostream>
#include <boost/bind.hpp>
#include "Swiften/Queries/IQRouter.h"
#include "Swiften/Swiften.h"
#include "transport/user.h"
#include "transport/usermanager.h"
#include "transport/rostermanager.h"
#include "transport/buddy.h"
#include "log4cxx/logger.h"
using namespace log4cxx;
using namespace Swift;
using namespace boost;
namespace Transport {
static LoggerPtr logger = Logger::getLogger("RosterResponder");
RosterResponder::RosterResponder(Swift::IQRouter *router, UserManager *userManager) : Swift::Responder<RosterPayload>(router) {
m_userManager = userManager;
}
RosterResponder::~RosterResponder() {
}
bool RosterResponder::handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::RosterPayload> payload) {
// Get means we're in server mode and user wants to fetch his roster.
// For now we send empty reponse, but TODO: Get buddies from database and send proper stored roster.
User *user = m_userManager->getUser(from.toBare().toString());
if (!user) {
sendResponse(from, id, boost::shared_ptr<RosterPayload>(new RosterPayload()));
LOG4CXX_WARN(logger, from.toBare().toString() << ": User is not logged in");
return true;
}
sendResponse(from, id, user->getRosterManager()->generateRosterPayload());
user->getRosterManager()->sendCurrentPresences(from);
return true;
}
bool RosterResponder::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::RosterPayload> payload) {
sendResponse(from, id, boost::shared_ptr<RosterPayload>(new RosterPayload()));
User *user = m_userManager->getUser(from.toBare().toString());
if (!user) {
LOG4CXX_WARN(logger, from.toBare().toString() << ": User is not logged in");
return true;
}
if (payload->getItems().size() == 0) {
LOG4CXX_WARN(logger, from.toBare().toString() << ": Roster push with no item");
return true;
}
Swift::RosterItemPayload item = payload->getItems()[0];
Buddy *buddy = user->getRosterManager()->getBuddy(Buddy::JIDToLegacyName(item.getJID()));
if (buddy) {
if (item.getSubscription() == Swift::RosterItemPayload::Remove) {
LOG4CXX_INFO(logger, from.toBare().toString() << ": Removing buddy " << buddy->getName());
onBuddyRemoved(buddy);
// send roster push here
Swift::SetRosterRequest::ref request = Swift::SetRosterRequest::create(payload, user->getJID().toBare(), user->getComponent()->getIQRouter());
request->send();
}
else {
LOG4CXX_INFO(logger, from.toBare().toString() << ": Updating buddy " << buddy->getName());
onBuddyUpdated(buddy, item);
}
}
else if (item.getSubscription() != Swift::RosterItemPayload::Remove) {
// Roster push for this new buddy is sent by RosterManager
BuddyInfo buddyInfo;
buddyInfo.id = -1;
buddyInfo.alias = item.getName();
buddyInfo.legacyName = Buddy::JIDToLegacyName(item.getJID());
buddyInfo.subscription = "both";
buddyInfo.flags = Buddy::buddFlagsFromJID(item.getJID());
LOG4CXX_INFO(logger, from.toBare().toString() << ": Adding buddy " << buddyInfo.legacyName);
buddy = user->getComponent()->getFactory()->createBuddy(user->getRosterManager(), buddyInfo);
user->getRosterManager()->setBuddy(buddy);
onBuddyAdded(buddy, item);
}
return true;
}
}
|