Changeset - 6b83d9f942fa
CMakeLists.txt
Show inline comments
 
@@ -94,13 +94,18 @@ else(WIN32)
 
	if (NOT Boost_FOUND)
 
		set(Boost_FIND_QUIETLY OFF)
 
		find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals REQUIRED)
 
	endif()
 
endif(WIN32)
 

	
 
message( STATUS "Found Boost: ${Boost_LIBRARIES}, ${Boost_INCLUDE_DIR}")
 
message( STATUS "Found Boost: ${Boost_VERSION}, ${Boost_LIBRARIES}, ${Boost_INCLUDE_DIR}")
 

	
 
if (${Boost_VERSION} GREATER 104999)
 
	message( STATUS "Using BOOST_FILESYSTEM_VERSION=3")
 
	add_definitions(-DBOOST_FILESYSTEM_VERSION=3)
 
endif()
 

	
 
# FIND POPT
 
if (NOT WIN32)
 
	set(popt_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
	find_package(popt REQUIRED)
 
endif()
backends/CMakeLists.txt
Show inline comments
 
@@ -6,13 +6,12 @@ if (PROTOBUF_FOUND)
 
	if (IRC_FOUND)
 
		ADD_SUBDIRECTORY(libcommuni)
 
	endif()
 

	
 
	if (ENABLE_SWIFTEN)
 
		ADD_SUBDIRECTORY(swiften)
 
		ADD_SUBDIRECTORY(swiften_raw)
 
	endif()
 

	
 
	ADD_SUBDIRECTORY(template)
 
	if(ENABLE_TWITTER)
 
		ADD_SUBDIRECTORY(twitter)
 
	endif()
backends/libpurple/main.cpp
Show inline comments
 
@@ -937,22 +937,21 @@ static void NodeRemoved(PurpleBlistNode *node, void *data) {
 
	if (!PURPLE_BLIST_NODE_IS_BUDDY_WRAPPED(node))
 
		return;
 
// 	PurpleBuddy *buddy = (PurpleBuddy *) node;
 
}
 

	
 
static void buddyListSaveNode(PurpleBlistNode *node) {
 
	if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
 
	if (!PURPLE_BLIST_NODE_IS_BUDDY_WRAPPED(node))
 
		return;
 

	
 
}
 

	
 
static void buddyListSaveAccount(PurpleAccount *account) {
 
}
 

	
 
static void buddyListRemoveNode(PurpleBlistNode *node) {
 
	if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
 
	if (!PURPLE_BLIST_NODE_IS_BUDDY_WRAPPED(node))
 
		return;
 
}
 

	
 
static PurpleBlistUiOps blistUiOps =
 
{
 
	NULL,
backends/skype/skype.cpp
Show inline comments
 
@@ -17,12 +17,13 @@
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "skype.h"
 
#include "skypeplugin.h"
 
#include "skypedb.h"
 

	
 
#include "transport/config.h"
 
#include "transport/logging.h"
 
#include "transport/transport.h"
 
#include "transport/usermanager.h"
 
#include "transport/memoryusage.h"
 
@@ -92,20 +93,21 @@ void Skype::login() {
 
	// Do not allow usernames with unsecure symbols
 
	if (m_username.find("..") == 0 || m_username.find("/") != std::string::npos) {
 
		m_np->handleDisconnected(m_user, pbnetwork::CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, "Invalid username");
 
		return;
 
	}
 

	
 
	std::string db_path = createSkypeDirectory();
 
	m_db = createSkypeDirectory();
 

	
 
	bool spawned = spawnSkype(db_path);
 
	bool spawned = spawnSkype(m_db);
 
	if (!spawned) {
 
		m_np->handleDisconnected(m_user, pbnetwork::CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, "Error spawning the Skype instance.");
 
		return;
 
	}
 

	
 
	m_db += "/" + getUsername() + "/main.db";
 

	
 
	if (m_connection == NULL) {
 
		LOG4CXX_INFO(logger, "Creating DBUS connection.");
 
		GError *error = NULL;
 
		m_connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
 
		if (m_connection == NULL && error != NULL)
 
@@ -226,57 +228,61 @@ bool Skype::loadSkypeBuddies() {
 
			BOOST_FOREACH(std::string u, data) {
 
				group_map[u] = grp;
 
			}
 
		}
 
	}
 

	
 
	std::string friends = send_command("GET AUTH_CONTACTS_PROFILES");
 
	// Try to load skype buddies from database, if it fails
 
	// fallback to old method.
 
	if (!SkypeDB::loadBuddies(m_np, m_db, m_user, group_map)) {
 
		std::string friends = send_command("GET AUTH_CONTACTS_PROFILES");
 

	
 
	char **full_friends_list = g_strsplit((strchr(friends.c_str(), ' ')+1), ";", 0);
 
	if (full_friends_list && full_friends_list[0])
 
	{
 
		//in the format of: username;full name;phone;office phone;mobile phone;
 
		//                  online status;friendly name;voicemail;mood
 
		// (comma-seperated lines, usernames can have comma's)
 

	
 
		for (int i=0; full_friends_list[i] && full_friends_list[i+1] && *full_friends_list[i] != '\0'; i+=8)
 
		char **full_friends_list = g_strsplit((strchr(friends.c_str(), ' ')+1), ";", 0);
 
		if (full_friends_list && full_friends_list[0])
 
		{
 
			std::string buddy = full_friends_list[i];
 
			//in the format of: username;full name;phone;office phone;mobile phone;
 
			//                  online status;friendly name;voicemail;mood
 
			// (comma-seperated lines, usernames can have comma's)
 

	
 
			if (buddy[0] == ',') {
 
				buddy.erase(buddy.begin());
 
			}
 
			for (int i=0; full_friends_list[i] && full_friends_list[i+1] && *full_friends_list[i] != '\0'; i+=8)
 
			{
 
				std::string buddy = full_friends_list[i];
 

	
 
			if (buddy.rfind(",") != std::string::npos) {
 
				buddy = buddy.substr(buddy.rfind(","));
 
			}
 
				if (buddy[0] == ',') {
 
					buddy.erase(buddy.begin());
 
				}
 

	
 
			if (buddy[0] == ',') {
 
				buddy.erase(buddy.begin());
 
			}
 
				if (buddy.rfind(",") != std::string::npos) {
 
					buddy = buddy.substr(buddy.rfind(","));
 
				}
 

	
 
			LOG4CXX_INFO(logger, "Got buddy " << buddy);
 
			std::string st = full_friends_list[i + 5];
 
				if (buddy[0] == ',') {
 
					buddy.erase(buddy.begin());
 
				}
 

	
 
			pbnetwork::StatusType status = getStatus(st);
 
				LOG4CXX_INFO(logger, "Got buddy " << buddy);
 
				std::string st = full_friends_list[i + 5];
 

	
 
			std::string alias = full_friends_list[i + 6];
 
				pbnetwork::StatusType status = getStatus(st);
 

	
 
			std::string mood_text = "";
 
			if (full_friends_list[i + 8] && *full_friends_list[i + 8] != '\0' && *full_friends_list[i + 8] != ',') {
 
				mood_text = full_friends_list[i + 8];
 
			}
 
				std::string alias = full_friends_list[i + 6];
 

	
 
			std::vector<std::string> groups;
 
			if (group_map.find(buddy) != group_map.end()) {
 
				groups.push_back(group_map[buddy]);
 
				std::string mood_text = "";
 
				if (full_friends_list[i + 8] && *full_friends_list[i + 8] != '\0' && *full_friends_list[i + 8] != ',') {
 
					mood_text = full_friends_list[i + 8];
 
				}
 

	
 
				std::vector<std::string> groups;
 
				if (group_map.find(buddy) != group_map.end()) {
 
					groups.push_back(group_map[buddy]);
 
				}
 
				m_np->handleBuddyChanged(m_user, buddy, alias, groups, status, mood_text);
 
			}
 
			m_np->handleBuddyChanged(m_user, buddy, alias, groups, status, mood_text);
 
		}
 
		g_strfreev(full_friends_list);
 
	}
 
	g_strfreev(full_friends_list);
 

	
 
	send_command("SET AUTOAWAY OFF");
 
	send_command("SET USERSTATUS ONLINE");
 
	return FALSE;
 
}
 

	
backends/skype/skype.h
Show inline comments
 
@@ -84,8 +84,9 @@ class Skype {
 
		std::string m_user;
 
		int m_timer;
 
		int m_counter;
 
		int fd_output;
 
		std::map<std::string, std::string> m_groups;
 
		SkypePlugin *m_np;
 
		std::string m_db;
 
};
 

	
backends/skype/skypedb.cpp
Show inline comments
 
@@ -37,12 +37,14 @@
 
#include "sys/signal.h"
 
// #include "valgrind/memcheck.h"
 
#ifndef __FreeBSD__
 
#include "malloc.h"
 
#endif
 

	
 
#include "skypeplugin.h"
 

	
 
// Prepare the SQL statement
 
#define PREP_STMT(sql, str) \
 
	if(sqlite3_prepare_v2(db, std::string(str).c_str(), -1, &sql, NULL)) { \
 
		LOG4CXX_ERROR(logger, str<< (sqlite3_errmsg(db) == NULL ? "" : sqlite3_errmsg(db))); \
 
		sql = NULL; \
 
	}
 
@@ -101,13 +103,57 @@ bool getAvatar(const std::string &db_path, const std::string &name, std::string
 
			int ret;
 
			while((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
 
			}
 
			FINALIZE_STMT(stmt);
 
		}
 
		else {
 
			LOG4CXX_ERROR(logger, "Can't created prepared statement");
 
			LOG4CXX_ERROR(logger, "Can't create prepared statement");
 
			LOG4CXX_ERROR(logger, (sqlite3_errmsg(db) == NULL ? "" : sqlite3_errmsg(db)));
 
		}
 
		sqlite3_close(db);
 
	}
 
	return ret;
 
}
 

	
 
bool loadBuddies(SkypePlugin *np, const std::string &db_path, std::string &user, std::map<std::string, std::string> &group_map) {
 
	bool ret = false;
 
	sqlite3 *db;
 
	LOG4CXX_INFO(logger, "Opening database " << db_path);
 
	if (sqlite3_open(db_path.c_str(), &db)) {
 
		sqlite3_close(db);
 
		LOG4CXX_ERROR(logger, "Can't open database");
 
	}
 
	else {
 
		sqlite3_stmt *stmt;
 
// 		aliases, fullname, 
 
		PREP_STMT(stmt, "select skypename, displayname, mood_text from Contacts;");
 
		if (stmt) {
 
			BEGIN(stmt);
 
			int ret2;
 
			while((ret2 = sqlite3_step(stmt)) == SQLITE_ROW) {
 
				std::string buddy = (const char *) sqlite3_column_text(stmt, 0);
 
				std::string alias = (const char *) sqlite3_column_text(stmt, 1);
 
				const char *d = (const char *) sqlite3_column_text(stmt, 2);
 
				std::string mood_text = d ? d : "";
 

	
 
				std::vector<std::string> groups;
 
				if (group_map.find(buddy) != group_map.end()) {
 
					groups.push_back(group_map[buddy]);
 
				}
 
				np->handleBuddyChanged(user, buddy, alias, groups, pbnetwork::STATUS_NONE, mood_text);
 
			}
 
			if (ret2 != SQLITE_DONE) {
 
				FINALIZE_STMT(stmt);
 
				ret = false;
 
			}
 
			else {
 
				ret = true;
 
			}
 
		}
 
		else {
 
			LOG4CXX_ERROR(logger, "Can't create prepared statement");
 
			LOG4CXX_ERROR(logger, (sqlite3_errmsg(db) == NULL ? "" : sqlite3_errmsg(db)));
 
		}
 
		sqlite3_close(db);
 
	}
 
	return ret;
 
}
backends/skype/skypedb.h
Show inline comments
 
@@ -23,11 +23,13 @@
 
#include "glib.h"
 
#include <dbus-1.0/dbus/dbus-glib-lowlevel.h>
 
#include "sqlite3.h"
 
#include <iostream>
 
#include <map>
 

	
 
class SkypePlugin;
 

	
 
namespace SkypeDB {
 
	bool getAvatar(const std::string &db, const std::string &name, std::string &avatar);
 

	
 
	bool loadBuddies(SkypePlugin *np, const std::string &db, std::string &user, std::map<std::string, std::string> &group_map);
 
}
 

	
backends/swiften/main.cpp
Show inline comments
 
@@ -27,123 +27,139 @@
 
#include <boost/algorithm/string.hpp>
 
using namespace boost::filesystem;
 
using namespace boost::program_options;
 
using namespace Transport;
 

	
 
DEFINE_LOGGER(logger, "Swiften");
 
DEFINE_LOGGER(logger_xml, "backend.xml");
 

	
 
// eventloop
 
Swift::SimpleEventLoop *loop_;
 

	
 
// Plugins
 
class SwiftenPlugin;
 
NetworkPlugin *np = NULL;
 
Swift::XMPPSerializer *serializer;
 

	
 
class MUCController {
 
class ForwardIQHandler : public Swift::IQHandler {
 
	public:
 
		MUCController(const std::string &user, boost::shared_ptr<Swift::Client> client, const std::string &room, const std::string &nickname, const std::string &password) {
 
			m_user = user;
 
			m_room = room;
 
			muc = client->getMUCManager()->createMUC(room);
 
			if (!password.empty()) {
 
				muc->setPassword(password);
 
			}
 

	
 
			muc->onJoinComplete.connect(boost::bind(&MUCController::handleJoinComplete, this, _1));
 
			muc->onJoinFailed.connect(boost::bind(&MUCController::handleJoinFailed, this, _1));
 
			muc->onOccupantJoined.connect(boost::bind(&MUCController::handleOccupantJoined, this, _1));
 
			muc->onOccupantPresenceChange.connect(boost::bind(&MUCController::handleOccupantPresenceChange, this, _1));
 
			muc->onOccupantLeft.connect(boost::bind(&MUCController::handleOccupantLeft, this, _1, _2, _3));
 
			muc->onOccupantRoleChanged.connect(boost::bind(&MUCController::handleOccupantRoleChanged, this, _1, _2, _3));
 
			muc->onOccupantAffiliationChanged.connect(boost::bind(&MUCController::handleOccupantAffiliationChanged, this, _1, _2, _3));
 

	
 
			muc->joinAs(nickname);
 
		}
 

	
 
		virtual ~MUCController() {
 
			muc->onJoinComplete.disconnect(boost::bind(&MUCController::handleJoinComplete, this, _1));
 
			muc->onJoinFailed.disconnect(boost::bind(&MUCController::handleJoinFailed, this, _1));
 
			muc->onOccupantJoined.disconnect(boost::bind(&MUCController::handleOccupantJoined, this, _1));
 
			muc->onOccupantPresenceChange.disconnect(boost::bind(&MUCController::handleOccupantPresenceChange, this, _1));
 
			muc->onOccupantLeft.disconnect(boost::bind(&MUCController::handleOccupantLeft, this, _1, _2, _3));
 
			muc->onOccupantRoleChanged.disconnect(boost::bind(&MUCController::handleOccupantRoleChanged, this, _1, _2, _3));
 
			muc->onOccupantAffiliationChanged.disconnect(boost::bind(&MUCController::handleOccupantAffiliationChanged, this, _1, _2, _3));
 
		}
 

	
 
		const std::string &getNickname() {
 
			//return muc->getCurrentNick();
 
			return m_nick;
 
		}
 

	
 
		void handleOccupantJoined(const Swift::MUCOccupant& occupant) {
 
			np->handleParticipantChanged(m_user, occupant.getNick(), m_room, occupant.getRole() == Swift::MUCOccupant::Moderator, pbnetwork::STATUS_ONLINE);
 
		}
 

	
 
		void handleOccupantLeft(const Swift::MUCOccupant& occupant, Swift::MUC::LeavingType type, const std::string& reason) {
 
			np->handleParticipantChanged(m_user, occupant.getNick(), m_room, occupant.getRole() == Swift::MUCOccupant::Moderator, pbnetwork::STATUS_NONE);
 
		}
 
		std::map <std::string, std::string> m_id2resource;
 

	
 
		void handleOccupantPresenceChange(boost::shared_ptr<Swift::Presence> presence) {
 
			const Swift::MUCOccupant& occupant = muc->getOccupant(presence->getFrom().getResource());
 
			np->handleParticipantChanged(m_user, presence->getFrom().getResource(), m_room, (int) occupant.getRole() == Swift::MUCOccupant::Moderator, (pbnetwork::StatusType) presence->getShow(), presence->getStatus());
 
		}
 

	
 
		void handleOccupantRoleChanged(const std::string& nick, const Swift::MUCOccupant& occupant, const Swift::MUCOccupant::Role& oldRole) {
 

	
 
		}
 

	
 
		void handleOccupantAffiliationChanged(const std::string& nick, const Swift::MUCOccupant::Affiliation& affiliation, const Swift::MUCOccupant::Affiliation& oldAffiliation) {
 
// 			np->handleParticipantChanged(m_user, occupant->getNick(), m_room, (int) occupant.getRole() == Swift::MUCOccupant::Moderator, pbnetwork::STATUS_ONLINE);
 
		}
 

	
 
		void handleJoinComplete(const std::string& nick) {
 
			m_nick = nick;
 
		ForwardIQHandler(NetworkPlugin *np, const std::string &user) {
 
			m_np = np;
 
			m_user = user;
 
		}
 

	
 
		void handleJoinFailed(boost::shared_ptr<Swift::ErrorPayload> error) {
 
			
 
		}
 
		bool handleIQ(boost::shared_ptr<Swift::IQ> iq) {
 
			if (iq->getPayload<Swift::RosterPayload>() != NULL) {
 
				return false;
 
			}
 
			if (iq->getType() == Swift::IQ::Get) {
 
				m_id2resource[iq->getID()] = iq->getFrom().getResource();
 
			}
 

	
 
		void part() {
 
			muc->part();
 
			iq->setTo(m_user);
 
			std::string xml = safeByteArrayToString(serializer->serializeElement(iq));
 
			m_np->sendRawXML(xml);
 
			return true;
 
		}
 

	
 
	private:
 
		Swift::MUC::ref muc;
 
		NetworkPlugin *m_np;
 
		std::string m_user;
 
		std::string m_room;
 
		std::string m_nick;
 
		
 
};
 

	
 
class SwiftenPlugin : public NetworkPlugin {
 
class SwiftenPlugin : public NetworkPlugin, Swift::XMPPParserClient {
 
	public:
 
		Swift::BoostNetworkFactories *m_factories;
 
		Swift::BoostIOServiceThread m_boostIOServiceThread;
 
		boost::shared_ptr<Swift::Connection> m_conn;
 
		bool m_firstPing;
 
		
 
		Swift::FullPayloadSerializerCollection collection;
 
		Swift::XMPPParser *m_xmppParser;
 
		Swift::FullPayloadParserFactoryCollection m_collection2;
 

	
 
		SwiftenPlugin(Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin() {
 
			this->config = config;
 
			m_firstPing = true;
 
			m_factories = new Swift::BoostNetworkFactories(loop);
 
			m_conn = m_factories->getConnectionFactory()->createConnection();
 
			m_conn->onDataRead.connect(boost::bind(&SwiftenPlugin::_handleDataRead, this, _1));
 
			m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port));
 

	
 
			serializer = new Swift::XMPPSerializer(&collection, Swift::ClientStreamType);
 
			m_xmppParser = new Swift::XMPPParser(this, &m_collection2, m_factories->getXMLParserFactory());
 
			m_xmppParser->parse("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='localhost' version='1.0'>");
 

	
 
			LOG4CXX_INFO(logger, "Starting the plugin.");
 
		}
 

	
 
		// NetworkPlugin uses this method to send the data to networkplugin server
 
		void sendData(const std::string &string) {
 
			m_conn->write(Swift::createSafeByteArray(string));
 
		}
 

	
 
		// This method has to call handleDataRead with all received data from network plugin server
 
		void _handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data) {
 
			if (m_firstPing) {
 
				m_firstPing = false;
 
				NetworkPlugin::PluginConfig cfg;
 
				cfg.setRawXML(true);
 
				sendConfig(cfg);
 
			}
 
			std::string d(data->begin(), data->end());
 
			handleDataRead(d);
 
		}
 

	
 
		void handleStreamStart(const Swift::ProtocolHeader&) {}
 

	
 
		void handleElement(boost::shared_ptr<Swift::Element> element) {
 
			boost::shared_ptr<Swift::Stanza> stanza = boost::dynamic_pointer_cast<Swift::Stanza>(element);
 
			if (!stanza) {
 
				return;
 
			}
 

	
 
			std::string user = stanza->getFrom().toBare();
 

	
 
			boost::shared_ptr<Swift::Client> client = m_users[user];
 
			if (!client)
 
				return;
 

	
 
			stanza->setFrom(client->getJID());
 

	
 
			boost::shared_ptr<Swift::Message> message = boost::dynamic_pointer_cast<Swift::Message>(stanza);
 
			if (message) {
 
				client->sendMessage(message);
 
				return;
 
			}
 

	
 
			boost::shared_ptr<Swift::Presence> presence = boost::dynamic_pointer_cast<Swift::Presence>(stanza);
 
			if (presence) {
 
				client->sendPresence(presence);
 
				return;
 
			}
 

	
 
			boost::shared_ptr<Swift::IQ> iq = boost::dynamic_pointer_cast<Swift::IQ>(stanza);
 
			if (iq) {
 
				if (m_handlers[user]->m_id2resource.find(stanza->getID()) != m_handlers[user]->m_id2resource.end()) {
 
					iq->setTo(Swift::JID(iq->getTo().getNode(), iq->getTo().getDomain(), m_handlers[user]->m_id2resource[stanza->getID()]));
 
					m_handlers[user]->m_id2resource.erase(stanza->getID());
 
				}
 
				client->getIQRouter()->sendIQ(iq);
 
				return;
 
			}
 
		}
 

	
 
		void handleStreamEnd() {}
 

	
 
		void handleRawXML(const std::string &xml) {
 
			m_xmppParser->parse(xml);
 
		}
 

	
 
		void handleSwiftDisconnected(const std::string &user, const boost::optional<Swift::ClientError> &error) {
 
			std::string message = "";
 
			bool reconnect = false;
 
			if (error) {
 
				switch(error->getType()) {
 
					case Swift::ClientError::UnknownError: message = ("Unknown Error"); reconnect = true; break;
 
@@ -183,13 +199,13 @@ class SwiftenPlugin : public NetworkPlugin {
 
			boost::shared_ptr<Swift::Client> client = m_users[user];
 
			if (client) {
 
				client->onConnected.disconnect(boost::bind(&SwiftenPlugin::handleSwiftConnected, this, user));
 
				client->onDisconnected.disconnect(boost::bind(&SwiftenPlugin::handleSwiftDisconnected, this, user, _1));
 
				client->onMessageReceived.disconnect(boost::bind(&SwiftenPlugin::handleSwiftMessageReceived, this, user, _1));
 
				m_users.erase(user);
 
				m_mucs.erase(user);
 
				m_handlers.erase(user);
 
			}
 

	
 
#ifndef WIN32
 
#ifndef __FreeBSD__
 
#ifndef __MACH__
 
			// force returning of memory chunks allocated by libxml2 to kernel
 
@@ -216,136 +232,119 @@ class SwiftenPlugin : public NetworkPlugin {
 
				handleBuddyChanged(user, item.getJID().toBare().toString(),
 
								   item.getName(), item.getGroups(), status);
 
			}
 
		}
 

	
 
		void handleSwiftPresenceChanged(const std::string &user, Swift::Presence::ref presence) {
 
			boost::shared_ptr<Swift::Client> client = m_users[user];
 
			if (client->getMUCRegistry()->isMUC(presence->getFrom().toBare())) {
 
				return;
 
			}
 

	
 
			if (presence->getPayload<Swift::MUCUserPayload>() != NULL || presence->getPayload<Swift::MUCPayload>() != NULL) {
 
				return;
 
			}
 

	
 
			LOG4CXX_INFO(logger, user << ": " << presence->getFrom().toBare().toString() << " presence changed");
 

	
 
			std::string message = presence->getStatus();
 
			std::string photo = "";
 

	
 
			boost::shared_ptr<Swift::VCardUpdate> update = presence->getPayload<Swift::VCardUpdate>();
 
			if (update) {
 
				photo = update->getPhotoHash();
 
			}
 

	
 
			boost::optional<Swift::XMPPRosterItem> item = m_users[user]->getRoster()->getItem(presence->getFrom());
 
			if (item) {
 
				handleBuddyChanged(user, presence->getFrom().toBare().toString(), item->getName(), item->getGroups(), (pbnetwork::StatusType) presence->getShow(), message, photo);
 
			}
 
			else {
 
				std::vector<std::string> groups;
 
				handleBuddyChanged(user, presence->getFrom().toBare().toString(), presence->getFrom().toBare(), groups, (pbnetwork::StatusType) presence->getShow(), message, photo);
 
			}
 
// 			boost::shared_ptr<Swift::Client> client = m_users[user];
 
// 			if (client->getMUCRegistry()->isMUC(presence->getFrom().toBare())) {
 
// 				return;
 
// 			}
 
// 
 
// 			if (presence->getPayload<Swift::MUCUserPayload>() != NULL || presence->getPayload<Swift::MUCPayload>() != NULL) {
 
// 				return;
 
// 			}
 
// 
 
// 			LOG4CXX_INFO(logger, user << ": " << presence->getFrom().toBare().toString() << " presence changed");
 
// 
 
// 			std::string message = presence->getStatus();
 
// 			std::string photo = "";
 
// 
 
// 			boost::shared_ptr<Swift::VCardUpdate> update = presence->getPayload<Swift::VCardUpdate>();
 
// 			if (update) {
 
// 				photo = update->getPhotoHash();
 
// 			}
 
// 
 
// 			boost::optional<Swift::XMPPRosterItem> item = m_users[user]->getRoster()->getItem(presence->getFrom());
 
// 			if (item) {
 
// 				handleBuddyChanged(user, presence->getFrom().toBare().toString(), item->getName(), item->getGroups(), (pbnetwork::StatusType) presence->getShow(), message, photo);
 
// 			}
 
// 			else {
 
// 				std::vector<std::string> groups;
 
// 				handleBuddyChanged(user, presence->getFrom().toBare().toString(), presence->getFrom().toBare(), groups, (pbnetwork::StatusType) presence->getShow(), message, photo);
 
// 			}
 
			presence->setTo(user);
 
			std::string xml = safeByteArrayToString(serializer->serializeElement(presence));
 
			sendRawXML(xml);
 
		}
 

	
 
		void handleSwiftMessageReceived(const std::string &user, Swift::Message::ref message) {
 
			std::string body = message->getBody();
 
			boost::shared_ptr<Swift::Client> client = m_users[user];
 
			if (client) {
 
				if (message->getType() == Swift::Message::Groupchat) {
 
					boost::shared_ptr<Swift::Delay> delay = message->getPayload<Swift::Delay>();
 
					std::string timestamp = "";
 
					if (delay) {
 
						timestamp = boost::posix_time::to_iso_string(delay->getStamp());
 
					}
 
					handleMessage(user, message->getFrom().toBare().toString(), body, message->getFrom().getResource(), "", timestamp);
 
				}
 
				else {
 
					if (client->getMUCRegistry()->isMUC(message->getFrom().toBare())) {
 
						handleMessage(user, message->getFrom().toBare().toString(), body, message->getFrom().getResource(), "", "", false, true);
 
					}
 
					else {
 
						handleMessage(user, message->getFrom().toBare().toString(), body, "", "");
 
					}
 
				}
 
			}
 
			message->setTo(user);
 
			std::string xml = safeByteArrayToString(serializer->serializeElement(message));
 
			sendRawXML(xml);
 
		}
 

	
 
		void handleSwiftVCardReceived(const std::string &user, unsigned int id, Swift::VCard::ref vcard, Swift::ErrorPayload::ref error) {
 
			if (error || !vcard) {
 
				LOG4CXX_INFO(logger, user << ": error fetching VCard with id=" << id);
 
				handleVCard(user, id, "", "", "", "");
 
				return;
 
		void handleSwiftenDataRead(const Swift::SafeByteArray &data) {
 
			std::string d = safeByteArrayToString(data);
 
			if (!boost::starts_with(d, "<auth")) {
 
				LOG4CXX_INFO(logger_xml, "XML IN " << d);
 
			}
 
			LOG4CXX_INFO(logger, user << ": VCard fetched - id=" << id);
 
			std::string photo((const char *)&vcard->getPhoto()[0], vcard->getPhoto().size());
 
			handleVCard(user, id, vcard->getFullName(), vcard->getFullName(), vcard->getNickname(), photo);
 
		}
 

	
 
		void handleSwiftenDataWritten(const Swift::SafeByteArray &data) {
 
			LOG4CXX_INFO(logger_xml, "XML OUT " << safeByteArrayToString(data));
 
		}
 

	
 
		void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
 
			LOG4CXX_INFO(logger, user << ": connecting as " << legacyName);
 
			boost::shared_ptr<Swift::Client> client = boost::make_shared<Swift::Client>(Swift::JID(legacyName), password, m_factories);
 
			m_users[user] = client;
 
			client->setAlwaysTrustCertificates();
 
			client->onConnected.connect(boost::bind(&SwiftenPlugin::handleSwiftConnected, this, user));
 
			client->onDisconnected.connect(boost::bind(&SwiftenPlugin::handleSwiftDisconnected, this, user, _1));
 
			client->onMessageReceived.connect(boost::bind(&SwiftenPlugin::handleSwiftMessageReceived, this, user, _1));
 
			client->getRoster()->onInitialRosterPopulated.connect(boost::bind(&SwiftenPlugin::handleSwiftRosterReceived, this, user));
 
			client->getPresenceOracle()->onPresenceChange.connect(boost::bind(&SwiftenPlugin::handleSwiftPresenceChanged, this, user, _1));
 
			client->onDataRead.connect(boost::bind(&SwiftenPlugin::handleSwiftenDataRead, this, _1));
 
			client->onDataWritten.connect(boost::bind(&SwiftenPlugin::handleSwiftenDataWritten, this, _1));
 
			client->getSubscriptionManager()->onPresenceSubscriptionRequest.connect(boost::bind(&SwiftenPlugin::handleSubscriptionRequest, this, user, _1, _2, _3));
 
			client->getSubscriptionManager()->onPresenceSubscriptionRevoked.connect(boost::bind(&SwiftenPlugin::handleSubscriptionRevoked, this, user, _1, _2));
 
			Swift::ClientOptions opt;
 
			opt.allowPLAINWithoutTLS = true;
 
			client->connect(opt);
 

	
 
			boost::shared_ptr<ForwardIQHandler> handler = boost::make_shared<ForwardIQHandler>(this, user);
 
			client->getIQRouter()->addHandler(handler);
 
			m_handlers[user] = handler;
 
		}
 

	
 
		void handleSubscriptionRequest(const std::string &user, const Swift::JID& jid, const std::string& message, Swift::Presence::ref presence) {
 
			handleSwiftPresenceChanged(user, presence);
 
		}
 

	
 
		void handleSubscriptionRevoked(const std::string &user, const Swift::JID& jid, const std::string& message) {
 
			Swift::Presence::ref presence = Swift::Presence::create();
 
			presence->setTo(user);
 
			presence->setFrom(jid);
 
			presence->setType(Swift::Presence::Unsubscribe);
 
			handleSwiftPresenceChanged(user, presence);
 
		}
 

	
 
		void handleLogoutRequest(const std::string &user, const std::string &legacyName) {
 
			boost::shared_ptr<Swift::Client> client = m_users[user];
 
			if (client) {
 
				client->onConnected.disconnect(boost::bind(&SwiftenPlugin::handleSwiftConnected, this, user));
 
// 				client->onDisconnected.disconnect(boost::bind(&SwiftenPlugin::handleSwiftDisconnected, this, user, _1));
 
				client->onMessageReceived.disconnect(boost::bind(&SwiftenPlugin::handleSwiftMessageReceived, this, user, _1));
 
				client->getRoster()->onInitialRosterPopulated.disconnect(boost::bind(&SwiftenPlugin::handleSwiftRosterReceived, this, user));
 
				client->getPresenceOracle()->onPresenceChange.disconnect(boost::bind(&SwiftenPlugin::handleSwiftPresenceChanged, this, user, _1));
 
				client->disconnect();
 
				m_mucs.erase(user);
 
			}
 
		}
 

	
 
		void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &msg, const std::string &xhtml = "", const std::string &id = "") {
 
			LOG4CXX_INFO(logger, "Sending message from " << user << " to " << legacyName << ".");
 
			boost::shared_ptr<Swift::Client> client = m_users[user];
 
			if (client) {
 
				boost::shared_ptr<Swift::Message> message(new Swift::Message());
 
				message->setTo(Swift::JID(legacyName));
 
				message->setFrom(client->getJID());
 
				message->setBody(msg);
 
				if (client->getMUCRegistry()->isMUC(legacyName)) {
 
					message->setType(Swift::Message::Groupchat);
 
					boost::shared_ptr<MUCController> muc = m_mucs[user][legacyName];
 
// 					handleMessage(user, legacyName, msg, muc->getNickname(), xhtml);
 
				}
 

	
 
				client->sendMessage(message);
 
			}
 
		}
 

	
 
		void handleVCardRequest(const std::string &user, const std::string &legacyName, unsigned int id) {
 
			boost::shared_ptr<Swift::Client> client = m_users[user];
 
			if (client) {
 
				LOG4CXX_INFO(logger, user << ": fetching VCard of " << legacyName << " id=" << id);
 
				Swift::GetVCardRequest::ref request = Swift::GetVCardRequest::create(Swift::JID(legacyName), client->getIQRouter());
 
				request->onResponse.connect(boost::bind(&SwiftenPlugin::handleSwiftVCardReceived, this, user, id, _1, _2));
 
				request->send();
 
			}
 
		}
 

	
 
		void handleBuddyUpdatedRequest(const std::string &user, const std::string &buddyName, const std::string &alias, const std::vector<std::string> &groups) {
 
			boost::shared_ptr<Swift::Client> client = m_users[user];
 
			if (client) {
 
				LOG4CXX_INFO(logger, user << ": Added/Updated buddy " << buddyName << ".");
 
				if (!client->getRoster()->containsJID(buddyName)) {
 
				if (!client->getRoster()->containsJID(buddyName) || client->getRoster()->getSubscriptionStateForJID(buddyName) != Swift::RosterItemPayload::Both) {
 
					Swift::RosterItemPayload item;
 
					item.setName(alias);
 
					item.setJID(buddyName);
 
					item.setGroups(groups);
 
					boost::shared_ptr<Swift::RosterPayload> roster(new Swift::RosterPayload());
 
					roster->addItem(item);
 
@@ -378,45 +377,23 @@ class SwiftenPlugin : public NetworkPlugin {
 
// 				request->onResponse.connect(boost::bind(&RosterController::handleRosterSetError, this, _1, roster));
 
				request->send();
 
			}
 
		}
 

	
 
		void handleJoinRoomRequest(const std::string &user, const std::string &room, const std::string &nickname, const std::string &password) {
 
			boost::shared_ptr<Swift::Client> client = m_users[user];
 
			if (client) {
 
				if (client->getMUCRegistry()->isMUC(room)) {
 
					return;
 
				}
 

	
 
				boost::shared_ptr<MUCController> muc = boost::shared_ptr<MUCController>( new MUCController(user, client, room, nickname, password));
 
				m_mucs[user][room] = muc;
 
			}
 
		}
 

	
 
		void handleLeaveRoomRequest(const std::string &user, const std::string &room) {
 
			boost::shared_ptr<Swift::Client> client = m_users[user];
 
			if (client) {
 
				if (!client->getMUCRegistry()->isMUC(room)) {
 
					return;
 
				}
 

	
 
				boost::shared_ptr<MUCController> muc = m_mucs[user][room];
 
				if (!muc) {
 
					m_mucs[user].erase(room);
 
					return;
 
				}
 

	
 
				muc->part();
 
				m_mucs[user].erase(room);
 
			}
 
		}
 

	
 
	private:
 
		Config *config;
 
		std::map<std::string, boost::shared_ptr<Swift::Client> > m_users;
 
		std::map<std::string, std::map<std::string, boost::shared_ptr<MUCController> > > m_mucs;
 
		std::map<std::string, boost::shared_ptr<ForwardIQHandler> > m_handlers;
 
};
 

	
 
#ifndef WIN32
 
static void spectrum_sigchld_handler(int sig)
 
{
 
	int status;
backends/swiften_raw/CMakeLists.txt
Show inline comments
 
deleted file
backends/swiften_raw/main.cpp
Show inline comments
 
deleted file
backends/twitter/libtwitcurl/twitcurl.cpp
Show inline comments
 
@@ -25,13 +25,13 @@ static int myDebugCallback(CURL *,
 
twitCurl::twitCurl():
 
m_curlHandle( NULL ),
 
m_curlProxyParamsSet( false ),
 
m_curlLoginParamsSet( false ),
 
m_curlCallbackParamsSet( false ),
 
m_eApiFormatType( twitCurlTypes::eTwitCurlApiFormatXml ),
 
m_eProtocolType( twitCurlTypes::eTwitCurlProtocolHttp )
 
m_eProtocolType( twitCurlTypes::eTwitCurlProtocolHttps )
 
{
 
    /* Clear callback buffers */
 
    clearCurlCallbackBuffers();
 
 
    /* Initialize cURL */
 
    m_curlHandle = curl_easy_init();
include/transport/buddy.h
Show inline comments
 
@@ -77,13 +77,13 @@ class Buddy {
 

	
 
		/// Presence stanza does not containt "to" attribute, it has to be added manually.
 
		/// \param features features used in returned stanza
 
		/// \param only_new if True, this function returns Presence stanza only if it's different
 
		/// than the previously generated one.
 
		/// \return Presence stanza or NULL.
 
		Swift::Presence::ref generatePresenceStanza(int features, bool only_new = false);
 
		std::vector<Swift::Presence::ref> &generatePresenceStanzas(int features, bool only_new = false);
 

	
 
		void setBlocked(bool block) {
 
			if (block)
 
				m_flags = (BuddyFlag) (m_flags | BUDDY_BLOCKED);
 
			else
 
				m_flags = (BuddyFlag) (m_flags & ~BUDDY_BLOCKED);
 
@@ -121,12 +121,14 @@ class Buddy {
 
		/// Returns legacy network username which does not contain unsafe characters,
 
		/// so it can be used in JIDs.
 
		std::string getSafeName();
 

	
 
		void sendPresence();
 

	
 
		void handleRawPresence(Swift::Presence::ref);
 

	
 
		/// Handles VCard from legacy network and forwards it to XMPP user.
 

	
 
		/// \param id ID used in IQ-result.
 
		/// \param vcard VCard which will be sent.
 
		void handleVCardReceived(const std::string &id, Swift::VCard::ref vcard);
 

	
 
@@ -154,26 +156,28 @@ class Buddy {
 

	
 
		/// Returns SHA-1 hash of buddy icon (avatar) or empty string if there is no avatar for this buddy.
 

	
 
		/// \return avatar hash or empty string.
 
		virtual std::string getIconHash() = 0;
 

	
 
		virtual bool isAvailable() = 0;
 

	
 
		/// Returns legacy name of buddy from JID.
 

	
 
		/// \param jid Jabber ID.
 
		/// \return legacy name of buddy from JID.
 
		static std::string JIDToLegacyName(const Swift::JID &jid);
 
		static BuddyFlag buddyFlagsFromJID(const Swift::JID &jid);
 

	
 
	protected:
 
		void generateJID();
 
		Swift::JID m_jid;
 
		std::vector<Swift::Presence::ref> m_presences;
 

	
 
	private:
 
		long m_id;
 
// 		Swift::Presence::ref m_lastPresence;
 
		BuddyFlag m_flags;
 
		RosterManager *m_rosterManager;
 
		Subscription m_subscription;
 
};
 

	
 
}
include/transport/conversation.h
Show inline comments
 
@@ -69,12 +69,13 @@ class Conversation {
 

	
 
		/// \param message Message received from legacy network.
 
		/// \param nickname For MUC conversation this is nickname of room participant who sent this message.
 
		void handleMessage(boost::shared_ptr<Swift::Message> &message, const std::string &nickname = "");
 

	
 
		void handleRawMessage(boost::shared_ptr<Swift::Message> &message);
 
		void handleRawPresence(Swift::Presence::ref presence);
 

	
 
		/// Handles participant change in MUC.
 

	
 
		/// \param nickname Nickname of participant which changed.
 
		/// \param flag ParticipantFlag.
 
		/// \param status Current status of this participant.
 
@@ -158,14 +159,20 @@ class Conversation {
 
		std::string m_legacyName;
 
		std::string m_nickname;
 
		std::string m_room;
 
		bool m_muc;
 
		Swift::JID m_jid;
 
		std::list<Swift::JID> m_jids;
 
		std::map<std::string, Participant> m_participants;
 
		boost::shared_ptr<Swift::Message> m_subject;
 
		bool m_sentInitialPresence;
 
		bool m_nicknameChanged;
 

	
 
		// TODO: Move this to some extra class to cache the most used
 
		// rooms across different accounts. Just now if we have 10 users
 
		// connected to single room, we store all those things 10 times.
 
		// It would be also great to store last 100 messages per room
 
		// every time, so we can get history messages for IRC for example.
 
		boost::shared_ptr<Swift::Message> m_subject;
 
		std::list<boost::shared_ptr<Swift::Message> > m_cachedMessages;
 
		std::map<std::string, Swift::Presence::ref> m_participants;
 
};
 

	
 
}
include/transport/localbuddy.h
Show inline comments
 
@@ -36,16 +36,16 @@ class LocalBuddy : public Buddy {
 
		std::string getAlias() { return m_alias; }
 
		void setAlias(const std::string &alias);
 

	
 
		std::string getName() { return m_name; }
 
		bool setName(const std::string &name);
 

	
 
		bool getStatus(Swift::StatusShow &status, std::string &statusMessage) {
 
			status = m_status;
 
			statusMessage = m_statusMessage;
 
			return true;
 
		bool getStatus(Swift::StatusShow &status, std::string &statusMessage);
 

	
 
		bool isAvailable() {
 
			return m_status.getType() != Swift::StatusShow::None;
 
		}
 

	
 
		void setStatus(const Swift::StatusShow &status, const std::string &statusMessage);
 

	
 
		std::string getIconHash() { return m_iconHash; }
 
		void setIconHash(const std::string &iconHash);
include/transport/transport.h
Show inline comments
 
@@ -152,12 +152,16 @@ namespace Transport {
 
			/// \param jid JID of the client for which we received capabilities
 
			/// \param info disco#info with response.
 
			boost::signal<void (const Swift::JID& jid, boost::shared_ptr<Swift::DiscoInfo> info)> onUserDiscoInfoReceived;
 

	
 
			boost::signal<void (boost::shared_ptr<Swift::IQ>)> onRawIQReceived;
 

	
 
			bool isRawXMLEnabled() {
 
				return m_rawXML;
 
			}
 

	
 
		private:
 
			void handleConnected();
 
			void handleConnectionError(const Swift::ComponentError &error);
 
			void handleServerStopped(boost::optional<Swift::BoostConnectionServer::Error> e);
 
			void handlePresence(Swift::Presence::ref presence);
 
			void handleDataRead(const Swift::SafeByteArray &data);
src/buddy.cpp
Show inline comments
 
@@ -37,14 +37,14 @@ Buddy::Buddy(RosterManager *rosterManager, long id, BuddyFlag flags) : m_id(id),
 

	
 
Buddy::~Buddy() {
 
// 	m_rosterManager->unsetBuddy(this);
 
}
 

	
 
void Buddy::sendPresence() {
 
	Swift::Presence::ref presence = generatePresenceStanza(255);
 
	if (presence) {
 
	std::vector<Swift::Presence::ref> &presences = generatePresenceStanzas(255);
 
	BOOST_FOREACH(Swift::Presence::ref presence, presences) {
 
		m_rosterManager->getUser()->getComponent()->getStanzaChannel()->sendPresence(presence);
 
	}
 
}
 

	
 
void Buddy::generateJID() {
 
	m_jid = Swift::JID();
 
@@ -86,25 +86,41 @@ void Buddy::setSubscription(Subscription subscription) {
 
}
 

	
 
Buddy::Subscription Buddy::getSubscription() {
 
	return m_subscription;
 
}
 

	
 
Swift::Presence::ref Buddy::generatePresenceStanza(int features, bool only_new) {
 
	std::string alias = getAlias();
 
	std::string name = getSafeName();
 
void Buddy::handleRawPresence(Swift::Presence::ref presence) {
 
	for (std::vector<Swift::Presence::ref>::iterator it = m_presences.begin(); it != m_presences.end(); it++) {
 
		if ((*it)->getFrom() == presence->getFrom()) {
 
			m_presences.erase(it);
 
			break;
 
		}
 
	}
 

	
 
	Swift::StatusShow s;
 
	std::string statusMessage;
 
	if (!getStatus(s, statusMessage))
 
		return Swift::Presence::ref();
 
	m_presences.push_back(presence);
 
	m_rosterManager->getUser()->getComponent()->getStanzaChannel()->sendPresence(presence);
 
}
 

	
 
std::vector<Swift::Presence::ref> &Buddy::generatePresenceStanzas(int features, bool only_new) {
 
	if (m_jid.getNode().empty()) {
 
		generateJID();
 
	}
 

	
 
	Swift::StatusShow s;
 
	std::string statusMessage;
 
	if (!getStatus(s, statusMessage)) {
 
		for (std::vector<Swift::Presence::ref>::iterator it = m_presences.begin(); it != m_presences.end(); it++) {
 
			if ((*it)->getFrom() == m_jid) {
 
				m_presences.erase(it);
 
				break;
 
			}
 
		}
 
		return m_presences;
 
	}
 

	
 
	Swift::Presence::ref presence = Swift::Presence::create();
 
	presence->setTo(m_rosterManager->getUser()->getJID().toBare());
 
	presence->setFrom(m_jid);
 
	presence->setType(Swift::Presence::Available);
 

	
 
	if (!statusMessage.empty())
 
@@ -125,22 +141,31 @@ Swift::Presence::ref Buddy::generatePresenceStanza(int features, bool only_new)
 
// 		}
 
		if (isBlocked()) {
 
			presence->addPayload(boost::shared_ptr<Swift::Payload>(new Transport::BlockPayload ()));
 
		}
 
	}
 

	
 
	BOOST_FOREACH(Swift::Presence::ref &p, m_presences) {
 
		if (p->getFrom() == presence->getFrom()) {
 
			p = presence;
 
			return m_presences;
 
		}
 
	}
 

	
 
	m_presences.push_back(presence);
 

	
 
// 	if (only_new) {
 
// 		if (m_lastPresence)
 
// 			m_lastPresence->setTo(Swift::JID(""));
 
// 		if (m_lastPresence == presence) {
 
// 			return Swift::Presence::ref();
 
// 		}
 
// 		m_lastPresence = presence;
 
// 	}
 

	
 
	return presence;
 
	return m_presences;
 
}
 

	
 
std::string Buddy::getSafeName() {
 
	if (m_jid.isValid()) {
 
		return m_jid.getNode();
 
	}
src/conversation.cpp
Show inline comments
 
@@ -196,16 +196,15 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, con
 
	}
 

	
 
	handleRawMessage(message);
 
}
 

	
 
void Conversation::sendParticipants(const Swift::JID &to) {
 
	for (std::map<std::string, Participant>::iterator it = m_participants.begin(); it != m_participants.end(); it++) {
 
		Swift::Presence::ref presence = generatePresence(it->first, it->second.flag, it->second.status, it->second.statusMessage, "");
 
		presence->setTo(to);
 
		m_conversationManager->getComponent()->getStanzaChannel()->sendPresence(presence);
 
	for (std::map<std::string, Swift::Presence::ref>::iterator it = m_participants.begin(); it != m_participants.end(); it++) {
 
		(*it).second->setTo(to);
 
		m_conversationManager->getComponent()->getStanzaChannel()->sendPresence((*it).second);
 
	}
 
}
 

	
 
void Conversation::sendCachedMessages(const Swift::JID &to) {
 
	for (std::list<boost::shared_ptr<Swift::Message> >::const_iterator it = m_cachedMessages.begin(); it != m_cachedMessages.end(); it++) {
 
		if (to.isValid()) {
 
@@ -213,12 +212,23 @@ void Conversation::sendCachedMessages(const Swift::JID &to) {
 
		}
 
		else {
 
			(*it)->setTo(m_jid.toBare());
 
		}
 
		m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(*it);
 
	}
 

	
 
	if (m_subject) {
 
		if (to.isValid()) {
 
			m_subject->setTo(to);
 
		}
 
		else {
 
			m_subject->setTo(m_jid.toBare());
 
		}
 
		m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(m_subject);
 
	}
 

	
 
	m_cachedMessages.clear();
 
}
 

	
 
Swift::Presence::ref Conversation::generatePresence(const std::string &nick, int flag, int status, const std::string &statusMessage, const std::string &newname) {
 
	std::string nickname = nick;
 
	Swift::Presence::ref presence = Swift::Presence::create();
 
@@ -299,31 +309,34 @@ Swift::Presence::ref Conversation::generatePresence(const std::string &nick, int
 
	
 
	p->addItem(item);
 
	presence->addPayload(boost::shared_ptr<Swift::Payload>(p));
 
	return presence;
 
}
 

	
 

	
 
void Conversation::setNickname(const std::string &nickname) {
 
	if (!nickname.empty() && m_nickname != nickname) {
 
		m_nicknameChanged = true;
 
	}
 
	m_nickname = nickname;
 
}
 

	
 
void Conversation::handleRawPresence(Swift::Presence::ref presence) {
 
	// TODO: Detect nickname change.
 
	m_conversationManager->getComponent()->getStanzaChannel()->sendPresence(presence);
 
	m_participants[presence->getFrom().getResource()] = presence;
 
}
 

	
 
void Conversation::handleParticipantChanged(const std::string &nick, Conversation::ParticipantFlag flag, int status, const std::string &statusMessage, const std::string &newname) {
 
	Swift::Presence::ref presence = generatePresence(nick, flag, status, statusMessage, newname);
 

	
 
	if (presence->getType() == Swift::Presence::Unavailable) {
 
		m_participants.erase(nick);
 
	}
 
	else {
 
		Participant p;
 
		p.flag = flag;
 
		p.status = status;
 
		p.statusMessage = statusMessage;
 
		m_participants[nick] = p;
 
		m_participants[nick] = presence;
 
	}
 

	
 

	
 
	BOOST_FOREACH(const Swift::JID &jid, m_jids) {
 
		presence->setTo(jid);
 
		m_conversationManager->getComponent()->getStanzaChannel()->sendPresence(presence);
src/localbuddy.cpp
Show inline comments
 
@@ -99,7 +99,16 @@ void LocalBuddy::setGroups(const std::vector<std::string> &groups) {
 
			getRosterManager()->sendBuddyRosterPush(this);
 
		}
 
		getRosterManager()->storeBuddy(this);
 
	}
 
}
 

	
 
bool LocalBuddy::getStatus(Swift::StatusShow &status, std::string &statusMessage) {
 
	if (getRosterManager()->getUser()->getComponent()->isRawXMLEnabled()) {
 
		return false;
 
	}
 
	status = m_status;
 
	statusMessage = m_statusMessage;
 
	return true;
 
}
 

	
 
}
src/networkpluginserver.cpp
Show inline comments
 
@@ -1050,16 +1050,23 @@ void NetworkPluginServer::handleElement(boost::shared_ptr<Swift::Element> elemen
 
		m_component->getStanzaChannel()->sendMessage(message);
 
		return;
 
	}
 

	
 
	boost::shared_ptr<Swift::Presence> presence = boost::dynamic_pointer_cast<Swift::Presence>(stanza);
 
	if (presence) {
 
		m_component->getStanzaChannel()->sendPresence(presence);
 
		if (buddy) {
 
			buddy->m_statusMessage = presence->getStatus();
 
			buddy->m_status = Swift::StatusShow(presence->getShow());
 
			if (!buddy->isAvailable() && presence->getType() != Swift::Presence::Unavailable) {
 
				buddy->m_status.setType(Swift::StatusShow::Online);
 
			}
 
			buddy->handleRawPresence(presence);
 
		}
 
		else if (conv) {
 
			conv->handleRawPresence(presence);
 
		}
 
		else {
 
			m_component->getStanzaChannel()->sendPresence(presence);
 
		}
 

	
 
		return;
 
	}
 

	
 
	boost::shared_ptr<Swift::IQ> iq = boost::dynamic_pointer_cast<Swift::IQ>(stanza);
src/rostermanager.cpp
Show inline comments
 
@@ -252,15 +252,17 @@ void RosterManager::storeBuddy(Buddy *buddy) {
 
	}
 
}
 

	
 
void RosterManager::handleBuddyRosterPushResponse(Swift::ErrorPayload::ref error, Swift::SetRosterRequest::ref request, const std::string &key) {
 
	LOG4CXX_INFO(logger, "handleBuddyRosterPushResponse called for buddy " << key);
 
	if (m_buddies[key] != NULL) {
 
		Swift::Presence::ref presence = m_buddies[key]->generatePresenceStanza(255);
 
		if (presence && presence->getType() == Swift::Presence::Available) {
 
			m_component->getStanzaChannel()->sendPresence(presence);
 
		if (m_buddies[key]->isAvailable()) {
 
			std::vector<Swift::Presence::ref> &presences = m_buddies[key]->generatePresenceStanzas(255);
 
			BOOST_FOREACH(Swift::Presence::ref &presence, presences) {
 
				m_component->getStanzaChannel()->sendPresence(presence);
 
			}
 
		}
 
	}
 
	else {
 
		LOG4CXX_WARN(logger, "handleBuddyRosterPushResponse called for unknown buddy " << key);
 
	}
 

	
 
@@ -437,19 +439,19 @@ void RosterManager::handleSubscription(Swift::Presence::ref presence) {
 
		Swift::Presence::ref currentPresence;
 
		response->setTo(presence->getFrom().toBare());
 
		response->setFrom(presence->getTo().toBare());
 

	
 
		Buddy *buddy = getBuddy(Buddy::JIDToLegacyName(presence->getTo()));
 
		if (buddy) {
 
			std::vector<Swift::Presence::ref> &presences = buddy->generatePresenceStanzas(255);
 
			switch (presence->getType()) {
 
				// buddy is already there, so nothing to do, just answer
 
				case Swift::Presence::Subscribe:
 
					onBuddyAdded(buddy);
 
					response->setType(Swift::Presence::Subscribed);
 
					currentPresence = buddy->generatePresenceStanza(255);
 
					if (currentPresence) {
 
					BOOST_FOREACH(Swift::Presence::ref &currentPresence, presences) {
 
						currentPresence->setTo(presence->getFrom());
 
						m_component->getStanzaChannel()->sendPresence(currentPresence);
 
					}
 
					if (buddy->getSubscription() != Buddy::Both) {
 
						buddy->setSubscription(Buddy::Both);
 
						storeBuddy(buddy);
 
@@ -584,25 +586,28 @@ Swift::RosterPayload::ref RosterManager::generateRosterPayload() {
 
void RosterManager::sendCurrentPresences(const Swift::JID &to) {
 
	for (std::map<std::string, Buddy *, std::less<std::string>, boost::pool_allocator< std::pair<std::string, Buddy *> > >::iterator it = m_buddies.begin(); it != m_buddies.end(); it++) {
 
		Buddy *buddy = (*it).second;
 
		if (!buddy) {
 
			continue;
 
		}
 
		Swift::Presence::ref presence = buddy->generatePresenceStanza(255);
 
		if (presence && presence->getType() == Swift::Presence::Available) {
 
		if (!buddy->isAvailable()) {
 
			continue;
 
		}
 
		std::vector<Swift::Presence::ref> &presences = buddy->generatePresenceStanzas(255);
 
		BOOST_FOREACH(Swift::Presence::ref &presence, presences) {
 
			presence->setTo(to);
 
			m_component->getStanzaChannel()->sendPresence(presence);
 
		}
 
	}
 
}
 

	
 
void RosterManager::sendCurrentPresence(const Swift::JID &from, const Swift::JID &to) {
 
	Buddy *buddy = getBuddy(Buddy::JIDToLegacyName(from));
 
	if (buddy) {
 
		Swift::Presence::ref presence = buddy->generatePresenceStanza(255);
 
		if (presence) {
 
		std::vector<Swift::Presence::ref> &presences = buddy->generatePresenceStanzas(255);
 
		BOOST_FOREACH(Swift::Presence::ref &presence, presences) {
 
			presence->setTo(to);
 
			m_component->getStanzaChannel()->sendPresence(presence);
 
		}
 
	}
 
	else {
 
		Swift::Presence::ref response = Swift::Presence::create();
 
@@ -616,17 +621,24 @@ void RosterManager::sendCurrentPresence(const Swift::JID &from, const Swift::JID
 
void RosterManager::sendUnavailablePresences(const Swift::JID &to) {
 
	for (std::map<std::string, Buddy *, std::less<std::string>, boost::pool_allocator< std::pair<std::string, Buddy *> > >::iterator it = m_buddies.begin(); it != m_buddies.end(); it++) {
 
		Buddy *buddy = (*it).second;
 
		if (!buddy) {
 
			continue;
 
		}
 
		Swift::Presence::ref presence = buddy->generatePresenceStanza(255);
 
		if (presence && presence->getType() == Swift::Presence::Available) {
 

	
 
		if (!buddy->isAvailable()) {
 
			continue;
 
		}
 

	
 
		std::vector<Swift::Presence::ref> &presences = buddy->generatePresenceStanzas(255);
 
		BOOST_FOREACH(Swift::Presence::ref &presence, presences) {
 
			Swift::Presence::Type type = presence->getType();
 
			presence->setTo(to);
 
			presence->setType(Swift::Presence::Unavailable);
 
			m_component->getStanzaChannel()->sendPresence(presence);
 
			presence->setType(type);
 
		}
 
	}
 

	
 
	// in gateway mode, we have to send unavailable presence for transport
 
	// contact
 
	Swift::Presence::ref response = Swift::Presence::create();
src/tests/basictest.cpp
Show inline comments
 
@@ -238,12 +238,15 @@ void BasicTest::connectSecondResource() {
 

	
 
void BasicTest::disconnectUser() {
 
	User *user = userManager->getUser("user@localhost");
 
	if (user) {
 
		user->addUserSetting("stay_connected", "0");
 
	}
 
	else {
 
		return;
 
	}
 
	received.clear();
 
	userManager->disconnectUser("user@localhost");
 
	dynamic_cast<Swift::DummyTimerFactory *>(factories->getTimerFactory())->setTime(100);
 
	loop->processEvents();
 

	
 
	CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
src/tests/conversationmanager.cpp
Show inline comments
 
@@ -20,12 +20,13 @@
 
#include "basictest.h"
 

	
 
using namespace Transport;
 

	
 
class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(ConversationManagerTest);
 
	CPPUNIT_TEST(conversationSize);
 
	CPPUNIT_TEST(handleNormalMessages);
 
	CPPUNIT_TEST(handleNormalMessagesHeadline);
 
	CPPUNIT_TEST(handleGroupchatMessages);
 
	CPPUNIT_TEST(handleGroupchatMessagesBouncer);
 
	CPPUNIT_TEST(handleGroupchatMessagesBouncerLeave);
 
	CPPUNIT_TEST(handleGroupchatMessagesTwoResources);
 
@@ -58,12 +59,16 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
			received.clear();
 
			disconnectUser();
 
			factory->onMessageToSend.disconnect(boost::bind(&ConversationManagerTest::handleMessageReceived, this, _1, _2));
 
			tearMeDown();
 
		}
 

	
 
	void conversationSize() {
 
		std::cout << " = " << sizeof(Conversation) << " B";
 
	}
 

	
 
	void handleMessageReceived(TestingConversation *_conv, boost::shared_ptr<Swift::Message> &_msg) {
 
		m_conv = _conv;
 
		m_msg = _msg;
 
	}
 

	
 
	void handleChatstateMessages() {
 
@@ -306,12 +311,16 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		TestingConversation *conv = new TestingConversation(user->getConversationManager(), "#room", true);
 
		user->getConversationManager()->addConversation(conv);
 
		conv->onMessageToSend.connect(boost::bind(&ConversationManagerTest::handleMessageReceived, this, _1, _2));
 
		conv->setNickname("nickname");
 
		conv->addJID("user@localhost/resource");
 

	
 
		boost::shared_ptr<Swift::Message> msg0(new Swift::Message());
 
		msg0->setSubject("subject");
 
		conv->handleMessage(msg0, "anotheruser");
 

	
 
		CPPUNIT_ASSERT(!user->shouldCacheMessages());
 

	
 
		// disconnectUser
 
		userManager->disconnectUser("user@localhost");
 
		dynamic_cast<Swift::DummyTimerFactory *>(factories->getTimerFactory())->setTime(10);
 
		loop->processEvents();
 
@@ -343,23 +352,27 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
		Swift::MUCPayload *payload = new Swift::MUCPayload();
 
		payload->setPassword("password");
 
		response->addPayload(boost::shared_ptr<Swift::Payload>(payload));
 
		injectPresence(response);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(3, (int) received.size());
 
		CPPUNIT_ASSERT_EQUAL(4, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[1])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there!"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/anotheruser"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getFrom().toString());
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[2])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("hi there2!"), dynamic_cast<Swift::Message *>(getStanza(received[2]))->getBody());
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[2]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/anotheruser"), dynamic_cast<Swift::Message *>(getStanza(received[2]))->getFrom().toString());
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[3])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("subject"), dynamic_cast<Swift::Message *>(getStanza(received[3]))->getSubject());
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[3]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/anotheruser"), dynamic_cast<Swift::Message *>(getStanza(received[3]))->getFrom().toString());
 
	}
 

	
 
	void handleGroupchatMessagesBouncerLeave() {
 
		User *user = userManager->getUser("user@localhost");
 
		user->addUserSetting("stay_connected", "1");
 
		TestingConversation *conv = new TestingConversation(user->getConversationManager(), "#room", true);
src/tests/localbuddy.cpp
Show inline comments
 
@@ -19,12 +19,13 @@
 
#include "basictest.h"
 

	
 
using namespace Transport;
 

	
 
class LocalBuddyTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(LocalBuddyTest);
 
	CPPUNIT_TEST(localBuddySize);
 
	CPPUNIT_TEST(createWithInvalidName);
 
	CPPUNIT_TEST(buddyFlagsFromJID);
 
	CPPUNIT_TEST(JIDToLegacyName);
 
	CPPUNIT_TEST(getSafeName);
 
	CPPUNIT_TEST(sendPresence);
 
	CPPUNIT_TEST(setAlias);
 
@@ -40,12 +41,16 @@ class LocalBuddyTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		void tearDown (void) {
 
			received.clear();
 
			disconnectUser();
 
			tearMeDown();
 
		}
 

	
 
	void localBuddySize() {
 
		std::cout << " = " << sizeof(LocalBuddy) << " B";
 
	}
 

	
 
	void createWithInvalidName() {
 
		User *user = userManager->getUser("user@localhost");
 
		CPPUNIT_ASSERT(user);
 

	
 
		std::vector<std::string> grp;
 
		grp.push_back("group");
src/tests/networkpluginserver.cpp
Show inline comments
 
@@ -22,12 +22,13 @@
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 
#include <cppunit/TestListener.h>
 
#include <cppunit/Test.h>
 
#include <time.h>    // for clock()
 
#include <stdint.h>
 

	
 
using namespace Transport;
 

	
 
class Clock {
 
	public:
 
		double m_beginTime;
 
@@ -51,14 +52,16 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
	CPPUNIT_TEST(handleBuddyChangedPayload);
 
	CPPUNIT_TEST(handleBuddyChangedPayloadNoEscaping);
 
	CPPUNIT_TEST(handleBuddyChangedPayloadUserContactInRoster);
 
	CPPUNIT_TEST(handleMessageHeadline);
 
	CPPUNIT_TEST(handleConvMessageAckPayload);
 
	CPPUNIT_TEST(handleRawXML);
 
	CPPUNIT_TEST(handleRawXMLSplit);
 

	
 
	CPPUNIT_TEST(benchmarkHandleBuddyChangedPayload);
 
	CPPUNIT_TEST(benchmarkSendUnavailablePresence);
 
	CPPUNIT_TEST_SUITE_END();
 

	
 
	public:
 
		NetworkPluginServer *serv;
 

	
 
		void setUp (void) {
 
@@ -137,12 +140,55 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
				received.clear();
 
			}
 
			clk.end();
 
			std::cerr << " " << clk.elapsedTime() << " s";
 
		}
 

	
 
		void benchmarkSendUnavailablePresence() {
 
			Clock clk;
 
			std::vector<std::string> lst;
 
			for (int i = 0; i < 1000; i++) {
 
				pbnetwork::Buddy buddy;
 
				buddy.set_username("user@localhost");
 
				buddy.set_buddyname("buddy" + boost::lexical_cast<std::string>(i)  + "@test");
 
				buddy.set_status((pbnetwork::StatusType) 5);
 

	
 
				std::string message;
 
				buddy.SerializeToString(&message);
 
				lst.push_back(message);
 
			}
 

	
 
			std::vector<std::string> lst2;
 
			for (int i = 0; i < 1000; i++) {
 
				pbnetwork::Buddy buddy;
 
				buddy.set_username("user@localhost");
 
				buddy.set_buddyname("buddy" + boost::lexical_cast<std::string>(1000+i)  + "@test");
 
				buddy.set_status((pbnetwork::StatusType) 2);
 

	
 
				std::string message;
 
				buddy.SerializeToString(&message);
 
				lst2.push_back(message);
 
			}
 

	
 
			
 
			for (int i = 0; i < 1000; i++) {
 
				serv->handleBuddyChangedPayload(lst[i]);
 
				received.clear();
 
			}
 
			for (int i = 0; i < 1000; i++) {
 
				serv->handleBuddyChangedPayload(lst2[i]);
 
				received.clear();
 
			}
 

	
 
			User *user = userManager->getUser("user@localhost");
 
			clk.start();
 
			user->getRosterManager()->sendUnavailablePresences("user@localhost");
 
			clk.end();
 
			std::cerr << " " << clk.elapsedTime() << " s";
 
		}
 

	
 
		void handleBuddyChangedPayload() {
 
			User *user = userManager->getUser("user@localhost");
 

	
 
			pbnetwork::Buddy buddy;
 
			buddy.set_username("user@localhost");
 
			buddy.set_buddyname("buddy1@test");
 
@@ -195,20 +241,42 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 

	
 
			serv->handleBuddyChangedPayload(message);
 
			CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 
		}
 

	
 
		void handleRawXML() {
 
			cfg->updateBackendConfig("[features]\nrawxml=1\n");
 
			User *user = userManager->getUser("user@localhost");
 
			std::vector<std::string> grp;
 
			grp.push_back("group1");
 
			LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1, "buddy1@domain.tld", "Buddy 1", grp, BUDDY_JID_ESCAPING);
 
			user->getRosterManager()->setBuddy(buddy);
 
			received.clear();
 

	
 
			std::string xml = "<presence from='buddy1@domain.tld' to='user@localhost'/>";
 

	
 
			std::string xml = "<presence from='buddy1@domain.tld/res' to='user@localhost'/>";
 
			serv->handleRawXML(xml);
 
			CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 

	
 
			std::string xml2 = "<presence from='buddy1@domain.tld/res2' to='user@localhost'/>";
 
			serv->handleRawXML(xml2);
 

	
 
			CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40domain.tld@localhost"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getFrom().toString());
 
			CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40domain.tld@localhost/res"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getFrom().toString());
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[1])));
 
			CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40domain.tld@localhost/res2"), dynamic_cast<Swift::Presence *>(getStanza(received[1]))->getFrom().toString());
 

	
 
			received.clear();
 
			user->getRosterManager()->sendUnavailablePresences("user@localhost");
 

	
 
			CPPUNIT_ASSERT_EQUAL(3, (int) received.size());
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40domain.tld@localhost/res"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getFrom().toString());
 
			CPPUNIT_ASSERT_EQUAL(Swift::Presence::Unavailable, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getType());
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[1])));
 
			CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40domain.tld@localhost/res2"), dynamic_cast<Swift::Presence *>(getStanza(received[1]))->getFrom().toString());
 
			CPPUNIT_ASSERT_EQUAL(Swift::Presence::Unavailable, dynamic_cast<Swift::Presence *>(getStanza(received[1]))->getType());
 
		}
 

	
 
		void handleMessageHeadline() {
 
			User *user = userManager->getUser("user@localhost");
 

	
 
			pbnetwork::ConversationMessage m;
 
@@ -232,9 +300,29 @@ class NetworkPluginServerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 
			user->addUserSetting("send_headlines", "1");
 
			serv->handleConvMessagePayload(message, false);
 
			CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::Message::Headline, dynamic_cast<Swift::Message *>(getStanza(received[0]))->getType());
 
		}
 

	
 
		void handleRawXMLSplit() {
 
			cfg->updateBackendConfig("[features]\nrawxml=1\n");
 
			User *user = userManager->getUser("user@localhost");
 
			std::vector<std::string> grp;
 
			grp.push_back("group1");
 
			LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1, "buddy1@domain.tld", "Buddy 1", grp, BUDDY_JID_ESCAPING);
 
			user->getRosterManager()->setBuddy(buddy);
 
			received.clear();
 

	
 
			std::string xml = "<presence from='buddy1@domain.tld/res' ";
 
			serv->handleRawXML(xml);
 

	
 
			std::string xml2 = " to='user@localhost'/>";
 
			serv->handleRawXML(xml2);
 

	
 
			CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40domain.tld@localhost/res"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getFrom().toString());
 
		}
 
};
 

	
 
CPPUNIT_TEST_SUITE_REGISTRATION (NetworkPluginServerTest);
0 comments (0 inline, 0 general)