Changeset - ac7bbb6cccf3
[Not reviewed]
0 3 0
Jan Kaluza - 14 years ago 2011-06-09 12:46:49
hanzz.k@gmail.com
Handle jabber:iq:roster sets
3 files changed with 38 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/localbuddy.cpp
Show inline comments
 
@@ -3,30 +3,31 @@
 
 *
 
 * 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/localbuddy.h"
 
#include "transport/user.h"
 

	
 
namespace Transport {
 

	
 
LocalBuddy::LocalBuddy(RosterManager *rosterManager, long id) : Buddy(rosterManager, id) {
 
	m_status = Swift::StatusShow::None;
 
}
 

	
 
LocalBuddy::~LocalBuddy() {
 
}
 

	
 
}
src/rosterresponder.cpp
Show inline comments
 
@@ -6,68 +6,104 @@
 
 * 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"
 

	
 
using namespace Swift;
 
using namespace boost;
 

	
 
namespace Transport {
 

	
 
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) {
 
		// Client can send jabber:iq:roster IQ before presence, so we do little hack here to
 
		// trigger logging in.
 
		// UserManager should create user now, if everything is OK.
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo(to);
 
		response->setFrom(from);
 
		response->setType(Swift::Presence::Available);
 
		m_userManager->handlePresence(response);
 

	
 
		// if it's not created, lets finish this get
 
		user = m_userManager->getUser(from.toBare().toString());
 
		if (!user) {
 
			sendResponse(from, id, boost::shared_ptr<RosterPayload>(new RosterPayload()));
 
			return true;
 
		}
 
	}
 
	sendResponse(from, id, user->getRosterManager()->generateRosterPayload());
 
	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) {
 
		return true;
 
	}
 

	
 
	if (payload->getItems().size() == 0) {
 
		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) {
 
			std::cout << "BUDDY REMOVED\n";
 
		}
 
		else {
 
			std::cout << "BUDDY UPDATED\n";
 
		}
 
	}
 
	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 = 0;
 

	
 
		buddy = user->getComponent()->getFactory()->createBuddy(user->getRosterManager(), buddyInfo);
 
		user->getRosterManager()->setBuddy(buddy);
 
		std::cout << "BUDDY ADDED\n";
 
	}
 

	
 
	return true;
 
}
 

	
 
}
src/sqlite3backend.cpp
Show inline comments
 
@@ -219,49 +219,49 @@ bool SQLite3Backend::getUser(const std::string &barejid, UserInfo &user) {
 
		user.password = (const char *) sqlite3_column_text(m_getUser, 3);
 
		user.encoding = (const char *) sqlite3_column_text(m_getUser, 4);
 
		user.language = (const char *) sqlite3_column_text(m_getUser, 5);
 
		user.vip = sqlite3_column_int(m_getUser, 6);
 
		return true;
 
	}
 

	
 
	if (ret != SQLITE_DONE) {
 
		onStorageError("getUser query", (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
 
	}
 

	
 
	return false;
 
}
 

	
 
void SQLite3Backend::setUserOnline(long id, bool online) {
 
	
 
}
 

	
 
long SQLite3Backend::addBuddy(long userId, const BuddyInfo &buddyInfo) {
 
// 	"INSERT INTO " + m_prefix + "buddies (user_id, uin, subscription, groups, nickname, flags) VALUES (?, ?, ?, ?, ?, ?)"
 
	BEGIN(m_addBuddy);
 
	BIND_INT(m_addBuddy, userId);
 
	BIND_STR(m_addBuddy, buddyInfo.legacyName);
 
	BIND_STR(m_addBuddy, buddyInfo.subscription);
 
	BIND_STR(m_addBuddy, buddyInfo.groups[0]); // TODO: serialize groups
 
	BIND_STR(m_addBuddy, buddyInfo.groups.size() == 0 ? "" : buddyInfo.groups[0]); // TODO: serialize groups
 
	BIND_STR(m_addBuddy, buddyInfo.alias);
 
	BIND_INT(m_addBuddy, buddyInfo.flags);
 

	
 
	if(sqlite3_step(m_addBuddy) != SQLITE_DONE) {
 
		onStorageError("addBuddy query", (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
 
		return -1;
 
	}
 

	
 
	long id = (long) sqlite3_last_insert_rowid(m_db);
 

	
 
// 	INSERT OR REPLACE INTO " + m_prefix + "buddies_settings (user_id, buddy_id, var, type, value) VALUES (?, ?, ?, ?, ?)
 
	BEGIN(m_updateBuddySetting);
 
	BIND_INT(m_updateBuddySetting, userId);
 
	BIND_INT(m_updateBuddySetting, id);
 
	BIND_STR(m_updateBuddySetting, buddyInfo.settings.find("icon_hash")->first);
 
	BIND_INT(m_updateBuddySetting, TYPE_STRING);
 
	BIND_STR(m_updateBuddySetting, buddyInfo.settings.find("icon_hash")->second.s);
 

	
 
	EXECUTE_STATEMENT(m_updateBuddySetting, "updateBuddySetting query");
 
	return id;
 
}
 

	
 
void SQLite3Backend::updateBuddy(long userId, const BuddyInfo &buddyInfo) {
 
// 	UPDATE " + m_prefix + "buddies SET groups=?, nickname=?, flags=?, subscription=? WHERE user_id=? AND uin=?
0 comments (0 inline, 0 general)