Changeset - 8ee031044843
backends/libpurple/main.cpp
Show inline comments
 
@@ -476,24 +476,34 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 

	
 
					// Add newly created buddy to legacy network roster.
 
					PurpleGroup *group = purple_find_group(groups.c_str());
 
					if (!group) {
 
						group = purple_group_new(groups.c_str());
 
					}
 
					purple_blist_add_buddy(buddy, NULL, group ,NULL);
 
					purple_account_add_buddy(account, buddy);
 
				}
 
			}
 
		}
 

	
 
		void handleBuddyBlockToggled(const std::string &user, const std::string &buddyName, bool blocked) {
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
				if (blocked)
 
					purple_privacy_deny(account, buddyName.c_str(), FALSE, FALSE);
 
				else
 
					purple_privacy_allow(account, buddyName.c_str(), FALSE, FALSE);
 
			}
 
		}
 

	
 
		void handleTypingRequest(const std::string &user, const std::string &buddyName) {
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
				serv_send_typing(purple_account_get_connection(account), buddyName.c_str(), PURPLE_TYPING);
 
			}
 
		}
 

	
 
		void handleTypedRequest(const std::string &user, const std::string &buddyName) {
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
				serv_send_typing(purple_account_get_connection(account), buddyName.c_str(), PURPLE_TYPED);
 
			}
 
@@ -648,25 +658,26 @@ static void buddyListNewNode(PurpleBlistNode *node) {
 
// 	np->handleBuddyChanged(np->m_accounts[account], purple_buddy_get_name(buddy), getAlias(buddy), getGroups(buddy)[0], (int) status.getType(), message, getIconHash(buddy));
 
// }
 

	
 
static void buddyListUpdate(PurpleBuddyList *list, PurpleBlistNode *node) {
 
	if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
 
		return;
 
	PurpleBuddy *buddy = (PurpleBuddy *) node;
 
	PurpleAccount *account = purple_buddy_get_account(buddy);
 
	Swift::StatusShow status;
 
	std::string message;
 
	getStatus(buddy, status, message);
 

	
 
	np->handleBuddyChanged(np->m_accounts[account], purple_buddy_get_name(buddy), getAlias(buddy), getGroups(buddy)[0], (int) status.getType(), message, getIconHash(buddy));
 
	np->handleBuddyChanged(np->m_accounts[account], purple_buddy_get_name(buddy), getAlias(buddy), getGroups(buddy)[0], (int) status.getType(), message, getIconHash(buddy),
 
		purple_privacy_check(account, purple_buddy_get_name(buddy)) == false);
 
}
 

	
 
static void NodeRemoved(PurpleBlistNode *node, void *data) {
 
	if (!PURPLE_BLIST_NODE_IS_BUDDY(node))
 
		return;
 
// 	PurpleBuddy *buddy = (PurpleBuddy *) node;
 
}
 

	
 
static PurpleBlistUiOps blistUiOps =
 
{
 
	NULL,
 
	buddyListNewNode,
include/Swiften/Elements/BlockPayload.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Elements/BlockPayload.h>
 

	
 
namespace Swift {
 

	
 
// This payload is NOT part of ANY XEP and it is only
 
// libtransport related extension.
 
BlockPayload::BlockPayload() {
 
	
 
}
 

	
 
}
include/Swiften/Elements/BlockPayload.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <vector>
 
#include <string>
 
#include <boost/shared_ptr.hpp>
 

	
 
#include <Swiften/Elements/Payload.h>
 

	
 
// This payload is NOT part of ANY XEP and it is only
 
// libtransport related extension.
 
namespace Swift {
 
	class BlockPayload : public Payload {
 
		public:
 
			typedef boost::shared_ptr<BlockPayload> ref;
 

	
 
		public:
 
			BlockPayload();
 
	};
 
}
include/Swiften/Parser/PayloadParsers/BlockParser.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Parser/PayloadParsers/BlockParser.h>
 

	
 
namespace Swift {
 

	
 
// This payload is NOT part of ANY XEP and it is only
 
// libtransport related extension.
 
BlockParser::BlockParser() /*: level_(0)*/ {
 
}
 

	
 
void BlockParser::handleStartElement(const std::string& /*element*/, const std::string& /*ns*/, const AttributeMap& /*attributes*/) {
 
}
 

	
 
void BlockParser::handleEndElement(const std::string&, const std::string&) {
 
}
 

	
 
void BlockParser::handleCharacterData(const std::string&) {
 

	
 
}
 

	
 
}
include/Swiften/Parser/PayloadParsers/BlockParser.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <Swiften/Elements/BlockPayload.h>
 
#include <Swiften/Parser/GenericPayloadParser.h>
 

	
 
// This payload is NOT part of ANY XEP and it is only
 
// libtransport related extension.
 
namespace Swift {
 
	class BlockParser : public GenericPayloadParser<BlockPayload> {
 
		public:
 
			BlockParser();
 

	
 
			virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes);
 
			virtual void handleEndElement(const std::string& element, const std::string&);
 
			virtual void handleCharacterData(const std::string& data);
 

	
 
// 		private:
 
// 			int level_;
 
	};
 
}
include/Swiften/Serializer/PayloadSerializers/BlockSerializer.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Serializer/PayloadSerializers/BlockSerializer.h>
 

	
 
#include <boost/shared_ptr.hpp>
 

	
 
#include <Swiften/Serializer/XML/XMLTextNode.h>
 
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
 
#include <Swiften/Serializer/XML/XMLElement.h>
 

	
 
namespace Swift {
 

	
 
// This payload is NOT part of ANY XEP and it is only
 
// libtransport related extension.
 
BlockSerializer::BlockSerializer() : GenericPayloadSerializer<BlockPayload>() {
 
}
 

	
 
std::string BlockSerializer::serializePayload(boost::shared_ptr<BlockPayload> attention)  const {
 
	XMLElement attentionElement("block", "urn:xmpp:block:0");
 

	
 
	return attentionElement.serialize();
 
}
 

	
 
}
include/Swiften/Serializer/PayloadSerializers/BlockSerializer.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <Swiften/Serializer/GenericPayloadSerializer.h>
 
#include <Swiften/Elements/BlockPayload.h>
 

	
 
// This payload is NOT part of ANY XEP and it is only
 
// libtransport related extension.
 
namespace Swift {
 
	class BlockSerializer : public GenericPayloadSerializer<BlockPayload> {
 
		public:
 
			BlockSerializer();
 

	
 
			virtual std::string serializePayload(boost::shared_ptr<BlockPayload>)  const;
 
	};
 
}
include/transport/buddy.h
Show inline comments
 
@@ -75,24 +75,32 @@ class Buddy {
 
		/// \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);
 

	
 
		/// Marks this buddy as available.
 
		void setOnline();
 

	
 
		/// Marks this buddy as offline.
 
		void setOffline();
 

	
 
		void setBlocked(bool block) {
 
			m_blocked = block;
 
		}
 

	
 
		bool isBlocked() {
 
			return m_blocked;
 
		}
 

	
 
		/// Returns true if this buddy is marked as available/online.
 

	
 
		/// \return true if this buddy is marked as available/online.
 
		bool isOnline();
 

	
 
		/// Sets current subscription.
 

	
 
		/// \param subscription "to", "from", "both", "ask"
 
		void setSubscription(const std::string &subscription);
 

	
 
		/// Returns current subscription
 

	
 
@@ -161,20 +169,21 @@ class Buddy {
 

	
 
		/// 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);
 

	
 
	private:
 
		void generateJID();
 

	
 
		long m_id;
 
		bool m_online;
 
		bool m_blocked;
 
		std::string m_subscription;
 
		Swift::Presence::ref m_lastPresence;
 
		Swift::JID m_jid;
 
		BuddyFlag m_flags;
 
		RosterManager *m_rosterManager;
 
};
 

	
 
}
include/transport/networkplugin.h
Show inline comments
 
@@ -32,25 +32,26 @@
 
#include "Swiften/Network/Connection.h"
 
#include "storagebackend.h"
 

	
 
namespace Transport {
 

	
 
class NetworkPlugin {
 
	public:
 
		NetworkPlugin(Swift::EventLoop *loop, const std::string &host, int port);
 

	
 
		virtual ~NetworkPlugin();
 

	
 
		void handleBuddyChanged(const std::string &user, const std::string &buddyName, const std::string &alias,
 
			const std::string &groups, int status, const std::string &statusMessage = "", const std::string &iconHash = ""
 
			const std::string &groups, int status, const std::string &statusMessage = "", const std::string &iconHash = "",
 
			bool blocked = false
 
		);
 

	
 
		void handleParticipantChanged(const std::string &user, const std::string &nickname, const std::string &room, int flags, int status = Swift::StatusShow::None, const std::string &statusMessage = "", const std::string &newname = "");
 

	
 
		void handleDisconnected(const std::string &user, const std::string &legacyName, int error, const std::string &message);
 

	
 
		void handleConnected(const std::string &user);
 

	
 
		void handleMessage(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &nickname = "", const std::string &xhtml = "");
 

	
 
		void handleSubject(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &nickname = "");
 

	
 
@@ -69,24 +70,25 @@ class NetworkPlugin {
 
		void handleAttention(const std::string &user, const std::string &buddyName, const std::string &message);
 

	
 
		virtual void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) = 0;
 
		virtual void handleLogoutRequest(const std::string &user, const std::string &legacyName) = 0;
 
		virtual void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml = "") = 0;
 
		virtual void handleVCardRequest(const std::string &/*user*/, const std::string &/*legacyName*/, unsigned int /*id*/) {}
 
		virtual void handleVCardUpdatedRequest(const std::string &/*user*/, const std::string &/*photo*/) {}
 
		virtual void handleJoinRoomRequest(const std::string &/*user*/, const std::string &/*room*/, const std::string &/*nickname*/, const std::string &/*pasword*/) {}
 
		virtual void handleLeaveRoomRequest(const std::string &/*user*/, const std::string &/*room*/) {}
 
		virtual void handleStatusChangeRequest(const std::string &/*user*/, int status, const std::string &statusMessage) {}
 
		virtual void handleBuddyUpdatedRequest(const std::string &/*user*/, const std::string &/*buddyName*/, const std::string &/*alias*/, const std::string &/*groups*/) {}
 
		virtual void handleBuddyRemovedRequest(const std::string &/*user*/, const std::string &/*buddyName*/, const std::string &/*groups*/) {}
 
		virtual void handleBuddyBlockToggled(const std::string &/*user*/, const std::string &/*buddyName*/, bool /*blocked*/) {}
 

	
 
		virtual void handleTypingRequest(const std::string &/*user*/, const std::string &/*buddyName*/) {}
 
		virtual void handleTypedRequest(const std::string &/*user*/, const std::string &/*buddyName*/) {}
 
		virtual void handleStoppedTypingRequest(const std::string &/*user*/, const std::string &/*buddyName*/) {}
 
		virtual void handleAttentionRequest(const std::string &/*user*/, const std::string &/*buddyName*/, const std::string &/*message*/) {}
 

	
 
		virtual void handleExit() { std::cout << "EXITING\n"; exit(1); }
 
		
 

	
 
	private:
 
		void connect();
 
		void handleLoginPayload(const std::string &payload);
include/transport/networkpluginserver.h
Show inline comments
 
@@ -30,24 +30,25 @@
 

	
 
namespace Transport {
 

	
 
class UserManager;
 
class User;
 
class Component;
 
class Buddy;
 
class LocalBuddy;
 
class Config;
 
class NetworkConversation;
 
class VCardResponder;
 
class RosterResponder;
 
class BlockResponder;
 

	
 
class NetworkPluginServer {
 
	public:
 
		struct Backend {
 
			int pongReceived;
 
			std::list<User *> users;
 
			Swift::SafeByteArray data;
 
			boost::shared_ptr<Swift::Connection> connection;
 
			unsigned long res;
 
			unsigned long init_res;
 
			unsigned long shared;
 
			bool acceptUsers;
 
@@ -86,33 +87,36 @@ class NetworkPluginServer {
 

	
 
		void handleUserCreated(User *user);
 
		void handleRoomJoined(User *user, const std::string &room, const std::string &nickname, const std::string &password);
 
		void handleRoomLeft(User *user, const std::string &room);
 
		void handleUserReadyToConnect(User *user);
 
		void handleUserPresenceChanged(User *user, Swift::Presence::ref presence);
 
		void handleUserDestroyed(User *user);
 

	
 
		void handleBuddyUpdated(Buddy *buddy, const Swift::RosterItemPayload &item);
 
		void handleBuddyRemoved(Buddy *buddy);
 
		void handleBuddyAdded(Buddy *buddy, const Swift::RosterItemPayload &item);
 

	
 
		void handleBlockToggled(Buddy *buddy);
 

	
 
		void handleVCardUpdated(User *user, boost::shared_ptr<Swift::VCard> vcard);
 
		void handleVCardRequired(User *user, const std::string &name, unsigned int id);
 

	
 
		void send(boost::shared_ptr<Swift::Connection> &, const std::string &data);
 

	
 
		void pingTimeout();
 
		void sendPing(Backend *c);
 
		Backend *getFreeClient();
 

	
 
		UserManager *m_userManager;
 
		VCardResponder *m_vcardResponder;
 
		RosterResponder *m_rosterResponder;
 
		BlockResponder *m_blockResponder;
 
		Config *m_config;
 
		boost::shared_ptr<Swift::BoostConnectionServer> m_server;
 
		std::list<Backend *>  m_clients;
 
		Swift::Timer::ref m_pingTimer;
 
		Component *m_component;
 
		std::list<User *> m_waitingUsers;
 
};
 

	
 
}
src/blockresponder.cpp
Show inline comments
 
new file 100644
 
/**
 
 * 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 "blockresponder.h"
 

	
 
#include <iostream>
 
#include <boost/bind.hpp>
 
#include "Swiften/Queries/IQRouter.h"
 
#include "Swiften/Elements/BlockPayload.h"
 
#include "Swiften/Swiften.h"
 
#include "transport/usermanager.h"
 
#include "transport/user.h"
 
#include "transport/buddy.h"
 
#include "transport/rostermanager.h"
 
#include "log4cxx/logger.h"
 

	
 
using namespace log4cxx;
 

	
 
using namespace Swift;
 
using namespace boost;
 

	
 
namespace Transport {
 

	
 
static LoggerPtr logger = Logger::getLogger("BlockResponder");
 

	
 
BlockResponder::BlockResponder(Swift::IQRouter *router, UserManager *userManager) : Swift::SetResponder<BlockPayload>(router) {
 
	m_userManager = userManager;
 
}
 

	
 
BlockResponder::~BlockResponder() {
 
	
 
}
 

	
 
bool BlockResponder::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::BlockPayload> info) {
 
	User *user = m_userManager->getUser(from.toBare().toString());
 
	if (!user) {
 
		LOG4CXX_WARN(logger, from.toBare().toString() << ": User is not logged in");
 
		return true;
 
	}
 

	
 
	Buddy *buddy = user->getRosterManager()->getBuddy(Buddy::JIDToLegacyName(to));
 
	if (buddy) {
 
		LOG4CXX_WARN(logger, from.toBare().toString() << ": Buddy " << Buddy::JIDToLegacyName(to) << " does not exist");
 
		return true;
 
	}
 

	
 
	onBlockToggled(buddy);
 

	
 
	return true;
 
}
 

	
 
}
src/blockresponder.h
Show inline comments
 
new file 100644
 
/**
 
 * libtransport -- C++ library for easy XMPP Transports development
 
 *
 
 * Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
 
 *
 
 * 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
 
 */
 

	
 
#pragma once
 

	
 
#include <vector>
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Queries/SetResponder.h"
 
#include "Swiften/Elements/BlockPayload.h"
 

	
 
namespace Transport {
 

	
 
class UserManager;
 
class Buddy;
 

	
 
class BlockResponder : public Swift::SetResponder<Swift::BlockPayload> {
 
	public:
 
		BlockResponder(Swift::IQRouter *router, UserManager *userManager);
 
		~BlockResponder();
 

	
 
		boost::signal<void (Buddy *)> onBlockToggled;
 

	
 
	private:
 
		virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::BlockPayload> payload);
 

	
 
		UserManager *m_userManager;
 
};
 

	
 
}
 
\ No newline at end of file
src/buddy.cpp
Show inline comments
 
@@ -13,28 +13,29 @@
 
 * 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/buddy.h"
 
#include "transport/rostermanager.h"
 
#include "transport/user.h"
 
#include "transport/transport.h"
 
#include "Swiften/Elements/BlockPayload.h"
 

	
 
namespace Transport {
 

	
 
Buddy::Buddy(RosterManager *rosterManager, long id) : m_id(id), m_online(false), m_subscription("ask"), m_flags(BUDDY_NO_FLAG), m_rosterManager(rosterManager){
 
Buddy::Buddy(RosterManager *rosterManager, long id) : m_id(id), m_online(false), m_blocked(false), m_subscription("ask"), m_flags(BUDDY_NO_FLAG), m_rosterManager(rosterManager){
 
// 	m_rosterManager->setBuddy(this);
 
}
 

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

	
 
void Buddy::generateJID() {
 
	m_jid = Swift::JID();
 
	m_jid = Swift::JID(getSafeName(), m_rosterManager->getUser()->getComponent()->getJID().toString(), "bot");
 
}
 

	
 
@@ -103,24 +104,27 @@ Swift::Presence::ref Buddy::generatePresenceStanza(int features, bool only_new)
 

	
 
	if (s.getType() == Swift::StatusShow::None)
 
		presence->setType(Swift::Presence::Unavailable);
 
	presence->setShow(s.getType());
 

	
 
	if (presence->getType() != Swift::Presence::Unavailable) {
 
		// caps
 
// 		presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::CapsInfo (CONFIG().caps)));
 

	
 
// 		if (features & 0/*TRANSPORT_FEATURE_AVATARS*/) {
 
			presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::VCardUpdate (getIconHash())));
 
// 		}
 
		if (m_blocked) {
 
			presence->addPayload(boost::shared_ptr<Swift::Payload>(new Swift::BlockPayload ()));
 
		}
 
	}
 

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

	
 
	return presence;
src/networkplugin.cpp
Show inline comments
 
@@ -121,33 +121,34 @@ void NetworkPlugin::handleSubject(const std::string &user, const std::string &le
 
	m.set_nickname(nickname);
 

	
 
	std::string message;
 
	m.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_ROOM_SUBJECT_CHANGED);
 
// 	std::cout << "SENDING MESSAGE\n";
 

	
 
	send(message);
 
}
 

	
 
void NetworkPlugin::handleBuddyChanged(const std::string &user, const std::string &buddyName, const std::string &alias,
 
			const std::string &groups, int status, const std::string &statusMessage, const std::string &iconHash) {
 
			const std::string &groups, int status, const std::string &statusMessage, const std::string &iconHash, bool blocked) {
 
	pbnetwork::Buddy buddy;
 
	buddy.set_username(user);
 
	buddy.set_buddyname(buddyName);
 
	buddy.set_alias(alias);
 
	buddy.set_groups(groups);
 
	buddy.set_status(status);
 
	buddy.set_statusmessage(statusMessage);
 
	buddy.set_iconhash(iconHash);
 
	buddy.set_blocked(blocked);
 

	
 
	std::string message;
 
	buddy.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_BUDDY_CHANGED);
 

	
 
	send(message);
 
}
 

	
 
void NetworkPlugin::handleBuddyTyping(const std::string &user, const std::string &buddyName) {
 
	pbnetwork::Buddy buddy;
 
	buddy.set_username(user);
 
@@ -364,26 +365,30 @@ void NetworkPlugin::handleVCardPayload(const std::string &data) {
 
	}
 
	else if (!payload.buddyname().empty()) {
 
		handleVCardRequest(payload.username(), payload.buddyname(), payload.id());
 
	}
 
}
 

	
 
void NetworkPlugin::handleBuddyChangedPayload(const std::string &data) {
 
	pbnetwork::Buddy payload;
 
	if (payload.ParseFromString(data) == false) {
 
		// TODO: ERROR
 
		return;
 
	}
 

	
 
	handleBuddyUpdatedRequest(payload.username(), payload.buddyname(), payload.alias(), payload.groups());
 
	if (payload.has_blocked()) {
 
		handleBuddyBlockToggled(payload.username(), payload.buddyname(), payload.blocked());
 
	}
 
	else {
 
		handleBuddyUpdatedRequest(payload.username(), payload.buddyname(), payload.alias(), payload.groups());
 
	}
 
}
 

	
 
void NetworkPlugin::handleBuddyRemovedPayload(const std::string &data) {
 
	pbnetwork::Buddy payload;
 
	if (payload.ParseFromString(data) == false) {
 
		// TODO: ERROR
 
		return;
 
	}
 

	
 
	handleBuddyRemovedRequest(payload.username(), payload.buddyname(), payload.groups());
 
}
 

	
src/networkpluginserver.cpp
Show inline comments
 
@@ -21,24 +21,25 @@
 
#include "transport/networkpluginserver.h"
 
#include "transport/user.h"
 
#include "transport/transport.h"
 
#include "transport/storagebackend.h"
 
#include "transport/rostermanager.h"
 
#include "transport/usermanager.h"
 
#include "transport/conversationmanager.h"
 
#include "transport/localbuddy.h"
 
#include "transport/config.h"
 
#include "transport/conversation.h"
 
#include "transport/vcardresponder.h"
 
#include "transport/rosterresponder.h"
 
#include "blockresponder.h"
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Elements/StreamError.h"
 
#include "Swiften/Network/BoostConnectionServer.h"
 
#include "Swiften/Elements/AttentionPayload.h"
 
#include "Swiften/Elements/XHTMLIMPayload.h"
 
#include "pbnetwork.pb.h"
 
#include "sys/wait.h"
 
#include "sys/signal.h"
 
#include "log4cxx/logger.h"
 

	
 
using namespace log4cxx;
 
@@ -121,24 +122,25 @@ static void SigCatcher(int n) {
 
		}
 
	}
 
}
 

	
 
static void handleBuddyPayload(LocalBuddy *buddy, const pbnetwork::Buddy &payload) {
 
	buddy->setName(payload.buddyname());
 
	buddy->setAlias(payload.alias());
 
	std::vector<std::string> groups;
 
	groups.push_back(payload.groups());
 
	buddy->setGroups(groups);
 
	buddy->setStatus(Swift::StatusShow((Swift::StatusShow::Type) payload.status()), payload.statusmessage());
 
	buddy->setIconHash(payload.iconhash());
 
	buddy->setBlocked(payload.blocked());
 
}
 

	
 
NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, UserManager *userManager) {
 
	m_userManager = userManager;
 
	m_config = config;
 
	m_component = component;
 
	m_component->m_factory = new NetworkFactory(this);
 
	m_userManager->onUserCreated.connect(boost::bind(&NetworkPluginServer::handleUserCreated, this, _1));
 
	m_userManager->onUserDestroyed.connect(boost::bind(&NetworkPluginServer::handleUserDestroyed, this, _1));
 

	
 
	m_pingTimer = component->getNetworkFactories()->getTimerFactory()->createTimer(20000);
 
	m_pingTimer->onTick.connect(boost::bind(&NetworkPluginServer::pingTimeout, this));
 
@@ -146,42 +148,47 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U
 

	
 
	m_vcardResponder = new VCardResponder(component->getIQRouter(), userManager);
 
	m_vcardResponder->onVCardRequired.connect(boost::bind(&NetworkPluginServer::handleVCardRequired, this, _1, _2, _3));
 
	m_vcardResponder->onVCardUpdated.connect(boost::bind(&NetworkPluginServer::handleVCardUpdated, this, _1, _2));
 
	m_vcardResponder->start();
 

	
 
	m_rosterResponder = new RosterResponder(component->getIQRouter(), userManager);
 
	m_rosterResponder->onBuddyAdded.connect(boost::bind(&NetworkPluginServer::handleBuddyAdded, this, _1, _2));
 
	m_rosterResponder->onBuddyRemoved.connect(boost::bind(&NetworkPluginServer::handleBuddyRemoved, this, _1));
 
	m_rosterResponder->onBuddyUpdated.connect(boost::bind(&NetworkPluginServer::handleBuddyUpdated, this, _1, _2));
 
	m_rosterResponder->start();
 

	
 
	m_blockResponder = new BlockResponder(component->getIQRouter(), userManager);
 
	m_blockResponder->onBlockToggled.connect(boost::bind(&NetworkPluginServer::handleBlockToggled, this, _1));
 
	m_blockResponder->start();
 

	
 
	m_server = Swift::BoostConnectionServer::create(Swift::HostAddress(CONFIG_STRING(m_config, "service.backend_host")), boost::lexical_cast<int>(CONFIG_STRING(m_config, "service.backend_port")), component->getNetworkFactories()->getIOServiceThread()->getIOService(), component->m_loop);
 
	m_server->onNewConnection.connect(boost::bind(&NetworkPluginServer::handleNewClientConnection, this, _1));
 
	m_server->start();
 

	
 
	LOG4CXX_INFO(logger, "Listening on host " << CONFIG_STRING(m_config, "service.backend_host") << " port " << CONFIG_STRING(m_config, "service.backend_port"));
 

	
 
	signal(SIGCHLD, SigCatcher);
 

	
 
	exec_(CONFIG_STRING(m_config, "service.backend").c_str(), CONFIG_STRING(m_config, "service.backend_host").c_str(), CONFIG_STRING(m_config, "service.backend_port").c_str(), m_config->getConfigFile().c_str());
 
}
 

	
 
NetworkPluginServer::~NetworkPluginServer() {
 
	m_pingTimer->stop();
 
	m_server->stop();
 
	m_server.reset();
 
	delete m_component->m_factory;
 
	delete m_vcardResponder;
 
	delete m_rosterResponder;
 
	delete m_blockResponder;
 
}
 

	
 
void NetworkPluginServer::handleNewClientConnection(boost::shared_ptr<Swift::Connection> c) {
 
	Backend *client = new Backend;
 
	client->pongReceived = -1;
 
	client->connection = c;
 
	client->res = 0;
 
	client->init_res = 0;
 
	client->shared = 0;
 
	client->acceptUsers = true;
 

	
 
	LOG4CXX_INFO(logger, "New backend " << client << " connected. Current backend count=" << (m_clients.size() + 1));
 
@@ -848,24 +855,48 @@ void NetworkPluginServer::handleBuddyUpdated(Buddy *b, const Swift::RosterItemPa
 

	
 
	Backend *c = (Backend *) user->getData();
 
	if (!c) {
 
		return;
 
	}
 
	send(c->connection, message);
 
}
 

	
 
void NetworkPluginServer::handleBuddyAdded(Buddy *buddy, const Swift::RosterItemPayload &item) {
 
	handleBuddyUpdated(buddy, item);
 
}
 

	
 
void NetworkPluginServer::handleBlockToggled(Buddy *b) {
 
	User *user = b->getRosterManager()->getUser();
 

	
 
	pbnetwork::Buddy buddy;
 
	buddy.set_username(user->getJID().toBare());
 
	buddy.set_buddyname(b->getName());
 
	buddy.set_alias(b->getAlias());
 
	buddy.set_groups(b->getGroups().size() == 0 ? "" : b->getGroups()[0]);
 
	buddy.set_status(Swift::StatusShow::None);
 
	buddy.set_blocked(not b->isBlocked());
 

	
 
	std::string message;
 
	buddy.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_BUDDY_CHANGED);
 

	
 
	Backend *c = (Backend *) user->getData();
 
	if (!c) {
 
		return;
 
	}
 
	send(c->connection, message);
 
}
 

	
 

	
 
void NetworkPluginServer::handleVCardUpdated(User *user, boost::shared_ptr<Swift::VCard> v) {
 
	pbnetwork::VCard vcard;
 
	vcard.set_username(user->getJID().toBare());
 
	vcard.set_buddyname("");
 
	vcard.set_id(0);
 
	vcard.set_photo(&v->getPhoto()[0], v->getPhoto().size());
 

	
 
	std::string message;
 
	vcard.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_VCARD);
 

	
src/pbnetwork.proto
Show inline comments
 
@@ -21,24 +21,25 @@ message Logout {
 
	required string user = 1;
 
	required string legacyName = 2;
 
}
 

	
 
message Buddy {
 
	required string userName = 1;
 
	required string buddyName = 2;
 
	optional string alias = 3;
 
	optional string groups = 4;
 
	optional int32 status = 5;
 
	optional string statusMessage = 6;
 
	optional string iconHash = 7;
 
	optional bool blocked = 8;
 
}
 

	
 
message ConversationMessage {
 
	required string userName = 1;
 
	required string buddyName = 2;
 
	required string message = 3;
 
	optional string nickname = 4;
 
	optional string xhtml = 5;
 
}
 

	
 
message Room {
 
	required string userName = 1;
src/transport.cpp
Show inline comments
 
@@ -24,24 +24,26 @@
 
#include "transport/factory.h"
 
#include "transport/userregistry.h"
 
#include "discoinforesponder.h"
 
#include "discoitemsresponder.h"
 
#include "storageparser.h"
 
#include "Swiften/TLS/OpenSSL/OpenSSLServerContext.h"
 
#include "Swiften/TLS/PKCS12Certificate.h"
 
#include "Swiften/TLS/OpenSSL/OpenSSLServerContextFactory.h"
 
#include "Swiften/Parser/PayloadParsers/AttentionParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/AttentionSerializer.h"
 
#include "Swiften/Parser/PayloadParsers/XHTMLIMParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/XHTMLIMSerializer.h"
 
#include "Swiften/Parser/PayloadParsers/BlockParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/BlockSerializer.h"
 
#include "log4cxx/logger.h"
 
#include "log4cxx/consoleappender.h"
 
#include "log4cxx/patternlayout.h"
 
#include "log4cxx/propertyconfigurator.h"
 

	
 
using namespace Swift;
 
using namespace boost;
 
using namespace log4cxx;
 

	
 
namespace Transport {
 
	
 
static LoggerPtr logger = Logger::getLogger("Component");
 
@@ -81,27 +83,29 @@ Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory, T
 
			m_server->addTLSEncryption(f, PKCS12Certificate(CONFIG_STRING(m_config, "service.cert"), createSafeByteArray(CONFIG_STRING(m_config, "service.cert_password"))));
 
		}
 
		else {
 
			LOG4CXX_WARN(logger, "No PKCS#12 certificate used. TLS is disabled.");
 
		}
 
// 		m_server->start();
 
		m_stanzaChannel = m_server->getStanzaChannel();
 
		m_iqRouter = m_server->getIQRouter();
 

	
 
		m_server->addPayloadParserFactory(new GenericPayloadParserFactory<StorageParser>("private", "jabber:iq:private"));
 
		m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::AttentionParser>("attention", "urn:xmpp:attention:0"));
 
		m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::XHTMLIMParser>("html", "http://jabber.org/protocol/xhtml-im"));
 
		m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::BlockParser>("block", "urn:xmpp:block:0"));
 

	
 
		m_server->addPayloadSerializer(new Swift::AttentionSerializer());
 
		m_server->addPayloadSerializer(new Swift::XHTMLIMSerializer());
 
		m_server->addPayloadSerializer(new Swift::BlockSerializer());
 

	
 
		m_server->onDataRead.connect(bind(&Component::handleDataRead, this, _1));
 
		m_server->onDataWritten.connect(bind(&Component::handleDataWritten, this, _1));
 
	}
 
	else {
 
		LOG4CXX_INFO(logger, "Creating component in gateway mode");
 
		m_component = new Swift::Component(loop, m_factories, m_jid, CONFIG_STRING(m_config, "service.password"));
 
		m_component->setSoftwareVersion("", "");
 
		m_component->onConnected.connect(bind(&Component::handleConnected, this));
 
		m_component->onError.connect(bind(&Component::handleConnectionError, this, _1));
 
		m_component->onDataRead.connect(bind(&Component::handleDataRead, this, _1));
 
		m_component->onDataWritten.connect(bind(&Component::handleDataWritten, this, _1));
0 comments (0 inline, 0 general)