Changeset - 0a78acefef91
[Not reviewed]
backends/libpurple/main.cpp
Show inline comments
 
@@ -42,12 +42,17 @@
 

	
 
#include "purple_defs.h"
 

	
 
DEFINE_LOGGER(logger_libpurple, "libpurple");
 
DEFINE_LOGGER(logger, "backend");
 

	
 
/* Additional PURPLE_MESSAGE_* flags as a hack to track the origin of the message. */
 
typedef enum {
 
    PURPLE_MESSAGE_SPECTRUM2_ORIGINATED = 0x80000000,
 
} PurpleMessageSpectrum2Flags;
 

	
 
int main_socket;
 
static int writeInput;
 
bool firstPing = true;
 

	
 
using namespace Transport;
 

	
 
@@ -539,25 +544,25 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
						conv = purple_conversation_new_wrapped(PURPLE_CONV_TYPE_IM, account, LegacyNameToName(account, legacyName).c_str());
 
					}
 
				}
 
				if (xhtml.empty()) {
 
					gchar *_markup = purple_markup_escape_text_wrapped(message.c_str(), -1);
 
					if (purple_conversation_get_type_wrapped(conv) == PURPLE_CONV_TYPE_IM) {
 
						purple_conv_im_send_wrapped(PURPLE_CONV_IM_WRAPPED(conv), _markup);
 
						purple_conv_im_send_with_flags_wrapped(PURPLE_CONV_IM_WRAPPED(conv), _markup, static_cast<PurpleMessageFlags>(PURPLE_MESSAGE_SPECTRUM2_ORIGINATED));
 
					}
 
					else if (purple_conversation_get_type_wrapped(conv) == PURPLE_CONV_TYPE_CHAT) {
 
						purple_conv_chat_send_wrapped(PURPLE_CONV_CHAT_WRAPPED(conv), _markup);
 
						purple_conv_chat_send_with_flags_wrapped(PURPLE_CONV_CHAT_WRAPPED(conv), _markup, static_cast<PurpleMessageFlags>(PURPLE_MESSAGE_SPECTRUM2_ORIGINATED));
 
					}
 
					g_free(_markup);
 
				}
 
				else {
 
					if (purple_conversation_get_type_wrapped(conv) == PURPLE_CONV_TYPE_IM) {
 
						purple_conv_im_send_wrapped(PURPLE_CONV_IM_WRAPPED(conv), xhtml.c_str());
 
						purple_conv_im_send_with_flags_wrapped(PURPLE_CONV_IM_WRAPPED(conv), xhtml.c_str(), static_cast<PurpleMessageFlags>(PURPLE_MESSAGE_SPECTRUM2_ORIGINATED));
 
					}
 
					else if (purple_conversation_get_type_wrapped(conv) == PURPLE_CONV_TYPE_CHAT) {
 
						purple_conv_chat_send_wrapped(PURPLE_CONV_CHAT_WRAPPED(conv), xhtml.c_str());
 
						purple_conv_chat_send_with_flags_wrapped(PURPLE_CONV_CHAT_WRAPPED(conv), xhtml.c_str(), static_cast<PurpleMessageFlags>(PURPLE_MESSAGE_SPECTRUM2_ORIGINATED));
 
					}
 
				}
 
			}
 
		}
 

	
 
		void handleRoomSubjectChangedRequest(const std::string &user, const std::string &legacyName, const std::string &message) {
 
@@ -1135,13 +1140,17 @@ static PurpleBlistUiOps blistUiOps =
 
	buddyListSaveNode,
 
	buddyListRemoveNode,
 
	buddyListSaveAccount,
 
	NULL
 
};
 

	
 
static void conv_write_im(PurpleConversation *conv, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime);
 

	
 
static void conv_write(PurpleConversation *conv, const char *who, const char *alias, const char *msg, PurpleMessageFlags flags, time_t mtime) {
 
	LOG4CXX_INFO(logger, "conv_write()");
 

	
 
	if (flags & PURPLE_MESSAGE_SYSTEM && CONFIG_STRING(config, "service.protocol") == "prpl-telegram") {
 
		PurpleAccount *account = purple_conversation_get_account_wrapped(conv);
 

	
 
	// 	char *striped = purple_markup_strip_html_wrapped(message);
 
	// 	std::string msg = striped;
 
	// 	g_free(striped);
 
@@ -1191,12 +1200,16 @@ static void conv_write(PurpleConversation *conv, const char *who, const char *al
 
		else {
 
			std::string conversationName = purple_conversation_get_name_wrapped(conv);
 
			LOG4CXX_INFO(logger, "Received message body='" << message_ << "' name='" << conversationName << "' " << who);
 
			np->handleMessage(np->m_accounts[account], np->NameToLegacyName(account, conversationName), message_, who, xhtml_, timestamp);
 
		}
 
	}
 
	else {
 
	    //Handle all non-special cases by just passing them to conv_write_im
 
	    conv_write_im(conv, who, msg, flags, mtime);
 
	}
 
}
 

	
 
static char *calculate_data_hash(guchar *data, size_t len,
 
    const gchar *hash_algo)
 
{
 
	PurpleCipherContext *context;
 
@@ -1220,15 +1233,32 @@ static char *calculate_data_hash(guchar *data, size_t len,
 
	purple_cipher_context_destroy(context);
 

	
 
	return g_strdup(digest);
 
}
 

	
 
static void conv_write_im(PurpleConversation *conv, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime) {
 
	// Don't forwards our own messages.
 
	if (purple_conversation_get_type_wrapped(conv) == PURPLE_CONV_TYPE_IM && (flags & PURPLE_MESSAGE_SEND || flags & PURPLE_MESSAGE_SYSTEM)) {
 
		return;
 
	LOG4CXX_INFO(logger, "conv_write_im()");
 
	bool isCarbon = false;
 
	
 
	if (purple_conversation_get_type_wrapped(conv) == PURPLE_CONV_TYPE_IM) {
 
		//Don't forwards our own messages, but do forward messages "from=us" which originated elsewhere
 
		//(such as carbons of our messages from other legacy network clients)
 
		if (flags & PURPLE_MESSAGE_SPECTRUM2_ORIGINATED) {
 
			LOG4CXX_INFO(logger, "conv_write_im(): ignoring a message generated by us");
 
			return;
 
		}
 
		
 
		//If this is a carbon of a message from us, mark it as such
 
		if(flags & PURPLE_MESSAGE_SEND)
 
			isCarbon = true;
 
		
 
		//Originally the transport had this filter too, I'm leaving it in for now:
 
		if (flags & PURPLE_MESSAGE_SYSTEM) {
 
			LOG4CXX_INFO(logger, "conv_write_im(): ignoring a system message");
 
			return;
 
		}
 
	}
 
	PurpleAccount *account = purple_conversation_get_account_wrapped(conv);
 

	
 
	std::string message_;
 
	std::string xhtml_;
 

	
 
@@ -1333,18 +1363,18 @@ static void conv_write_im(PurpleConversation *conv, const char *who, const char
 
		size_t pos = w.find("/");
 
		if (pos != std::string::npos) {
 
			n = w.substr((int) pos + 1, w.length() - (int) pos);
 
			w.erase((int) pos, w.length() - (int) pos);
 
		}
 
		LOG4CXX_INFO(logger, "Received message body='" << message_ << "' xhtml='" << xhtml_ << "' name='" << w << "'");
 
		np->handleMessage(np->m_accounts[account], w, message_, n, xhtml_, timestamp);
 
		np->handleMessage(np->m_accounts[account], w, message_, n, xhtml_, timestamp, false, false, isCarbon);
 
	}
 
	else {
 
		std::string conversationName = purple_conversation_get_name_wrapped(conv);
 
		LOG4CXX_INFO(logger, "Received message body='" << message_ << "' xhtml='" << xhtml_ << "' name='" << conversationName << "' " << who);
 
		np->handleMessage(np->m_accounts[account], np->NameToLegacyName(account, conversationName), message_, who, xhtml_, timestamp);
 
		np->handleMessage(np->m_accounts[account], np->NameToLegacyName(account, conversationName), message_, who, xhtml_, timestamp, false, false, isCarbon);
 
	}
 
}
 

	
 
static void conv_chat_add_users(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals) {
 
	PurpleAccount *account = purple_conversation_get_account_wrapped(conv);
 

	
backends/libpurple/purple_defs.cpp
Show inline comments
 
@@ -71,13 +71,15 @@ purple_connections_get_handle_wrapped_fnc purple_connections_get_handle_wrapped
 
purple_conversation_get_im_data_wrapped_fnc purple_conversation_get_im_data_wrapped = NULL;
 
purple_conversation_get_chat_data_wrapped_fnc purple_conversation_get_chat_data_wrapped = NULL;
 
purple_find_conversation_with_account_wrapped_fnc purple_find_conversation_with_account_wrapped = NULL;
 
purple_conversation_new_wrapped_fnc purple_conversation_new_wrapped = NULL;
 
purple_conversation_get_type_wrapped_fnc purple_conversation_get_type_wrapped = NULL;
 
purple_conv_im_send_wrapped_fnc purple_conv_im_send_wrapped = NULL;
 
purple_conv_im_send_with_flags_wrapped_fnc purple_conv_im_send_with_flags_wrapped = NULL;
 
purple_conv_chat_send_wrapped_fnc purple_conv_chat_send_wrapped = NULL;
 
purple_conv_chat_send_with_flags_wrapped_fnc purple_conv_chat_send_with_flags_wrapped = NULL;
 
purple_conversation_destroy_wrapped_fnc purple_conversation_destroy_wrapped = NULL;
 
purple_conversation_get_account_wrapped_fnc purple_conversation_get_account_wrapped = NULL;
 
purple_conversation_get_name_wrapped_fnc purple_conversation_get_name_wrapped = NULL;
 
purple_conversations_set_ui_ops_wrapped_fnc purple_conversations_set_ui_ops_wrapped = NULL;
 
purple_conversations_get_handle_wrapped_fnc purple_conversations_get_handle_wrapped = NULL;
 
purple_core_set_ui_ops_wrapped_fnc purple_core_set_ui_ops_wrapped = NULL;
 
@@ -438,16 +440,24 @@ bool resolvePurpleFunctions() {
 
		return false;
 

	
 
	purple_conv_im_send_wrapped = (purple_conv_im_send_wrapped_fnc)GetProcAddress(f_hPurple, "purple_conv_im_send");
 
	if (!purple_conv_im_send_wrapped)
 
		return false;
 

	
 
	purple_conv_im_send_with_flags_wrapped = (purple_conv_im_send_with_flags_wrapped_fnc)GetProcAddress(f_hPurple, "purple_conv_im_send_with_flags");
 
	if (!purple_conv_im_send_with_flags_wrapped)
 
		return false;
 

	
 
	purple_conv_chat_send_wrapped = (purple_conv_chat_send_wrapped_fnc)GetProcAddress(f_hPurple, "purple_conv_chat_send");
 
	if (!purple_conv_chat_send_wrapped)
 
		return false;
 

	
 
	purple_conv_chat_send_with_flags_wrapped = (purple_conv_chat_send_with_flags_wrapped_fnc)GetProcAddress(f_hPurple, "purple_conv_chat_send_with_flags");
 
	if (!purple_conv_chat_send_with_flags_wrapped)
 
		return false;
 

	
 
	purple_conversation_destroy_wrapped = (purple_conversation_destroy_wrapped_fnc)GetProcAddress(f_hPurple, "purple_conversation_destroy");
 
	if (!purple_conversation_destroy_wrapped)
 
		return false;
 

	
 
	purple_conversation_get_account_wrapped = (purple_conversation_get_account_wrapped_fnc)GetProcAddress(f_hPurple, "purple_conversation_get_account");
 
	if (!purple_conversation_get_account_wrapped)
backends/libpurple/purple_defs.h
Show inline comments
 
@@ -233,15 +233,21 @@ extern purple_conversation_set_data_wrapped_func purple_conversation_set_data_wr
 
typedef void (_cdecl * purple_conversation_update_wrapped_func)(const PurpleConversation *conv, PurpleConversationUpdateType type); 
 
extern purple_conversation_update_wrapped_func purple_conversation_update_wrapped;
 

	
 
typedef void  (_cdecl * purple_conv_im_send_wrapped_fnc)(PurpleConvIm *im, const char *message);
 
extern purple_conv_im_send_wrapped_fnc purple_conv_im_send_wrapped;
 

	
 
typedef void  (_cdecl * purple_conv_im_send_with_flags_wrapped_fnc)(PurpleConvIm *im, const char *message, PurpleMessageFlags flags);
 
extern purple_conv_im_send_with_flags_wrapped_fnc purple_conv_im_send_with_flags_wrapped;
 

	
 
typedef void  (_cdecl * purple_conv_chat_send_wrapped_fnc)(PurpleConvChat *chat, const char *message);
 
extern purple_conv_chat_send_wrapped_fnc purple_conv_chat_send_wrapped;
 

	
 
typedef void  (_cdecl * purple_conv_chat_send_with_flags_wrapped_fnc)(PurpleConvChat *chat, const char *message, PurpleMessageFlags flags);
 
extern purple_conv_chat_send_with_flags_wrapped_fnc purple_conv_chat_send_with_flags_wrapped;
 

	
 
typedef void  (_cdecl * purple_conversation_destroy_wrapped_fnc)(PurpleConversation *conv);
 
extern purple_conversation_destroy_wrapped_fnc purple_conversation_destroy_wrapped;
 

	
 
typedef PurpleAccount * (_cdecl * purple_conversation_get_account_wrapped_fnc)(const PurpleConversation *conv);
 
extern purple_conversation_get_account_wrapped_fnc purple_conversation_get_account_wrapped;
 

	
 
@@ -540,13 +546,15 @@ extern wpurple_g_io_channel_win32_new_socket_wrapped_fnc wpurple_g_io_channel_wi
 
#define purple_find_conversation_with_account_wrapped purple_find_conversation_with_account
 
#define purple_conversation_new_wrapped purple_conversation_new
 
#define purple_conversation_get_type_wrapped purple_conversation_get_type
 
#define purple_conversation_set_data_wrapped purple_conversation_set_data
 
#define purple_conversation_update_wrapped purple_conversation_update
 
#define purple_conv_im_send_wrapped purple_conv_im_send
 
#define purple_conv_im_send_with_flags_wrapped purple_conv_im_send_with_flags
 
#define purple_conv_chat_send_wrapped purple_conv_chat_send
 
#define purple_conv_chat_send_with_flags_wrapped purple_conv_chat_send_with_flags
 
#define purple_conversation_destroy_wrapped purple_conversation_destroy
 
#define purple_conversation_get_account_wrapped purple_conversation_get_account
 
#define purple_conversation_get_name_wrapped purple_conversation_get_name
 
#define purple_conversations_set_ui_ops_wrapped purple_conversations_set_ui_ops
 
#define purple_conversations_get_handle_wrapped purple_conversations_get_handle
 
#define purple_core_set_ui_ops_wrapped purple_core_set_ui_ops
docs/guide/developer_lowlevel.textile
Show inline comments
 
@@ -178,12 +178,13 @@ Backend sends this payload when it receives new message from legacy network whic
 
|_. Variable|_. Description|
 
|userName| JID of XMPP user|
 
|buddyName| Name of the buddy in legacy network who sent the message. If the conversation is room, buddyName is name of the room.|
 
|message|Plain text message|
 
|xhtml|Message formatted using XHTML-IM XEP if available|
 
|nickname| If the conversation is room, this is the nickname of user who sent the original message|
 
|carbon| If set, the message is a carbon copy of our own message sent in a different legacy network client. It should be treated as a message FROM us, not TO us|
 

	
 
h3. Type: TYPE_ATTENTION, Payload: ConversationMessage
 

	
 
Backend sends this payload when it receives attention request from legacy network which should be forwarded to XMPP user.
 

	
 
|_. Variable|_. Description|
include/Swiften/Elements/HintPayload.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Implements XEP-0334: Message Processing Hints
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Elements/HintPayload.h>
 

	
 
namespace Swift {
 

	
 
HintPayload::HintPayload(Type type)
 
: type_(type) {
 
}
 

	
 
}
include/Swiften/Elements/HintPayload.h
Show inline comments
 
new file 100644
 
/*
 
 * Implements XEP-0334: Message Processing Hints
 
 * 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>
 

	
 
#include "Swiften/SwiftenCompat.h"
 

	
 
namespace Swift {
 
	class HintPayload : public Payload {
 
	public:
 
		typedef SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<HintPayload> ref;
 

	
 
		enum Type { NoPermanentStore, NoStore, NoCopy, Store };
 

	
 
	public:
 
		HintPayload(Type type = NoCopy);
 

	
 
		void setType(Type type) { type_ = type; }
 
		const Type getType() { return type_; }
 

	
 
	private:
 
		Type type_;
 
	};
 
}
include/Swiften/Elements/Privilege.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Implements Privilege tag for XEP-0356: Privileged Entity
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Elements/Privilege.h>
 

	
 
namespace Swift {
 

	
 
Privilege::Privilege() {
 
}
 

	
 
}
include/Swiften/Elements/Privilege.h
Show inline comments
 
new file 100644
 
/*
 
 * Implements Privilege tag for XEP-0356: Privileged Entity
 
 * 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/Base/API.h>
 
#include <Swiften/Elements/Payload.h>
 

	
 
#include <Swiften/Version.h>
 
#if (SWIFTEN_VERSION >= 0x030000)
 
#define SWIFTEN_SUPPORTS_FORWARDED
 
#include <Swiften/Elements/Forwarded.h>
 
#endif
 

	
 
#include "Swiften/SwiftenCompat.h"
 

	
 
namespace Swift {
 
	class Stanza;
 

	
 
	class Privilege : public Payload {
 
	public:
 
		typedef SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Privilege> ref;
 
#ifdef SWIFTEN_SUPPORTS_FORWARDED
 
		typedef Swift::Forwarded Forwarded;
 
#else
 
		typedef Payload Forwarded;
 
#endif
 

	
 
	public:
 
		Privilege();
 

	
 
		void setForwarded(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Forwarded> forwarded) { forwarded_ = forwarded; }
 
		const SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Forwarded>& getForwarded() const { return forwarded_; }
 

	
 
	private:
 
		SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Forwarded> forwarded_;
 
	};
 
}
include/Swiften/Parser/PayloadParsers/HintPayloadParser.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Implements XEP-0334: Message Processing Hints
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

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

	
 
namespace Swift {
 

	
 
HintPayloadParser::HintPayloadParser() : level_(0) {
 
}
 

	
 
void HintPayloadParser::handleStartElement(const std::string& element, const std::string& /*ns*/, const AttributeMap& /*attributes*/) {
 
	if (level_ == 0) {
 
		HintPayload::Type type = HintPayload::NoCopy;
 
		if (element == "no-permanent-store") {
 
			type = HintPayload::NoPermanentStore;
 
		} else if (element == "no-store") {
 
			type = HintPayload::NoStore;
 
		} else if (element == "no-copy") {
 
			type = HintPayload::NoCopy;
 
		} else if (element == "store") {
 
			type = HintPayload::Store;
 
		}
 
		getPayloadInternal()->setType(type);
 
	}
 
	++level_;
 
}
 

	
 
void HintPayloadParser::handleEndElement(const std::string&, const std::string&) {
 
	--level_;
 
}
 

	
 
void HintPayloadParser::handleCharacterData(const std::string&) {
 
}
 

	
 
}
include/Swiften/Parser/PayloadParsers/HintPayloadParser.h
Show inline comments
 
new file 100644
 
/*
 
 * Implements XEP-0334: Message Processing Hints
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

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

	
 
namespace Swift {
 
	class HintPayloadParser : public GenericPayloadParser<HintPayload> {
 
	public:
 
		HintPayloadParser();
 

	
 
		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/Parser/PayloadParsers/PrivilegeParser.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Implements Privilege tag for XEP-0356: Privileged Entity
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Parser/PayloadParsers/PrivilegeParser.h>
 
#ifdef SWIFTEN_SUPPORTS_FORWARDED
 
#include <Swiften/Parser/PayloadParsers/ForwardedParser.h>
 
#else
 
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
 
#include <Swiften/Parser/PayloadParserFactory.h>
 
#include <Swiften/Parser/UnknownPayloadParser.h>
 
#endif
 

	
 
namespace Swift {
 

	
 
PrivilegeParser::PrivilegeParser(PayloadParserFactoryCollection* factories) : factories_(factories), level_(TopLevel) {
 
}
 

	
 
void PrivilegeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
 
	if (level_ == PayloadLevel) {
 
		if (element == "forwarded" && ns == "urn:xmpp:forward:0") {
 
#ifdef SWIFTEN_SUPPORTS_FORWARDED
 
			childParser_ = SWIFTEN_SHRPTR_NAMESPACE::dynamic_pointer_cast<PayloadParser>(SWIFTEN_SHRPTR_NAMESPACE::make_shared<ForwardedParser>(factories_));
 
#else
 
			PayloadParserFactory* parserFactory = factories_->getPayloadParserFactory(element, ns, attributes);
 
			if (parserFactory) {
 
				childParser_.reset(parserFactory->createPayloadParser());
 
			}
 
			else {
 
				childParser_.reset(new UnknownPayloadParser());
 
			}
 
#endif
 
		};
 
	}
 
	if (childParser_) {
 
		childParser_->handleStartElement(element, ns, attributes);
 
	}
 
	++level_;
 
}
 

	
 
void PrivilegeParser::handleEndElement(const std::string& element, const std::string& ns) {
 
	--level_;
 
	if (childParser_ && level_ >= PayloadLevel) {
 
		childParser_->handleEndElement(element, ns);
 
	}
 
	if (childParser_ && level_ == PayloadLevel) {
 
		getPayloadInternal()->setForwarded(SWIFTEN_SHRPTR_NAMESPACE::dynamic_pointer_cast<Privilege::Forwarded>(childParser_->getPayload()));
 
		childParser_.reset();
 
	}
 
}
 

	
 
void PrivilegeParser::handleCharacterData(const std::string& data) {
 
	if (childParser_) {
 
		childParser_->handleCharacterData(data);
 
	}
 
}
 

	
 
}
include/Swiften/Parser/PayloadParsers/PrivilegeParser.h
Show inline comments
 
new file 100644
 
/*
 
 * Implements Privilege tag for XEP-0356: Privileged Entity
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <Swiften/Base/API.h>
 
#include <Swiften/Elements/Privilege.h>
 
#include <Swiften/Parser/GenericPayloadParser.h>
 

	
 
namespace Swift {
 
	class PayloadParserFactoryCollection;
 
	class PayloadParser;
 

	
 
	class PrivilegeParser : public GenericPayloadParser<Privilege> {
 
	public:
 
		PrivilegeParser(PayloadParserFactoryCollection* factories);
 

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

	
 
	enum Level {
 
		TopLevel = 0,
 
		PayloadLevel = 1
 
	};
 

	
 
	private:
 
		PayloadParserFactoryCollection* factories_;
 
		SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<PayloadParser> childParser_;
 
		int level_;
 
	};
 
}
include/Swiften/Serializer/PayloadSerializers/HintPayloadSerializer.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Implements XEP-0334: Message Processing Hints
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <string>
 

	
 
#include <Swiften/Serializer/PayloadSerializers/HintPayloadSerializer.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 {
 

	
 
HintPayloadSerializer::HintPayloadSerializer() : GenericPayloadSerializer<HintPayload>() {
 
}
 

	
 
std::string HintPayloadSerializer::serializePayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<HintPayload> hint)  const {
 
	std::string tagname = "";
 
	switch(hint->getType()) {
 
	case HintPayload::NoPermanentStore: tagname = "no-permanent-store"; break;
 
	case HintPayload::NoStore: tagname = "no-store"; break;
 
	case HintPayload::NoCopy: tagname = "no-copy"; break;
 
	case HintPayload::Store: tagname = "store"; break;
 
	}
 

	
 
	return XMLElement(tagname, "urn:xmpp:hints").serialize();
 
}
 

	
 
}
include/Swiften/Serializer/PayloadSerializers/HintPayloadSerializer.h
Show inline comments
 
new file 100644
 
/*
 
 * Implements XEP-0334: Message Processing Hints
 
 * 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/HintPayload.h>
 

	
 
#include "Swiften/SwiftenCompat.h"
 

	
 
namespace Swift {
 
	class HintPayloadSerializer : public GenericPayloadSerializer<HintPayload> {
 
	public:
 
		HintPayloadSerializer();
 

	
 
		virtual std::string serializePayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<HintPayload>)  const;
 
	};
 
}
include/Swiften/Serializer/PayloadSerializers/PrivilegeSerializer.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Implements Privilege tag for XEP-0356: Privileged Entity
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

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

	
 
#include <boost/shared_ptr.hpp>
 

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

	
 
#ifdef SWIFTEN_SUPPORTS_FORWARDED
 
#include <Swiften/Elements/Forwarded.h>
 
#include <Swiften/Serializer/PayloadSerializers/ForwardedSerializer.h>
 
#else
 
#include <Swiften/Serializer/PayloadSerializerCollection.h>
 
#endif
 

	
 
namespace Swift {
 

	
 
PrivilegeSerializer::PrivilegeSerializer(PayloadSerializerCollection* serializers) : GenericPayloadSerializer<Privilege>(), serializers_(serializers) {
 
}
 

	
 
PrivilegeSerializer::~PrivilegeSerializer() {
 
}
 

	
 
std::string PrivilegeSerializer::serializePayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Privilege> payload)  const {
 
	if (!payload) {
 
		return "";
 
	}
 

	
 
	XMLElement element("privilege", "urn:xmpp:privilege:1");
 

	
 
	SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Privilege::Forwarded> forwarded(payload->getForwarded());
 
	if (forwarded) {
 
		std::string forwardedStr = "";
 
#ifdef SWIFTEN_SUPPORTS_FORWARDED
 
		forwardedStr = ForwardedSerializer(serializers_).serialize(forwarded);
 
#else
 
		PayloadSerializer* serializer = serializers_->getPayloadSerializer(payload);
 
		if(serializer) {
 
			forwardedStr = serializer->serialize(payload);
 
		}
 
#endif
 
		element.addNode(SWIFTEN_SHRPTR_NAMESPACE::make_shared<XMLRawTextNode>(forwardedStr));
 
	}
 

	
 
	return element.serialize();
 
}
 

	
 
}
include/Swiften/Serializer/PayloadSerializers/PrivilegeSerializer.h
Show inline comments
 
new file 100644
 
/*
 
 * Implements Privilege tag for XEP-0356: Privileged Entity
 
 * 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/Privilege.h>
 

	
 
#include "Swiften/SwiftenCompat.h"
 

	
 
namespace Swift {
 
	class PayloadSerializerCollection;
 

	
 
	class PrivilegeSerializer : public GenericPayloadSerializer<Privilege> {
 
	public:
 
		PrivilegeSerializer(PayloadSerializerCollection* serializers);
 
		virtual ~PrivilegeSerializer();
 

	
 
		virtual std::string serializePayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Privilege>) const;
 

	
 
	private:
 
		PayloadSerializerCollection* serializers_;
 
	};
 
}
include/Swiften/SwiftenCompat.h
Show inline comments
 
@@ -48,6 +48,15 @@
 
#define SWIFTEN_SHRPTR_NAMESPACE boost
 
#include <boost/signals.hpp>
 
#define SWIFTEN_SIGNAL_NAMESPACE boost
 
#define SWIFTEN_SIGNAL_CONNECTION_NAMESPACE boost::signals
 
#define SWIFT_HOSTADDRESS(x) Swift::HostAddress(x)
 
#endif
 

	
 
#if (SWIFTEN_VERSION >= 0x030000)
 
//Swiften supports carbon Sent and Received tags as well as Forwarded tags inside those
 
#define SWIFTEN_SUPPORTS_CARBONS
 
//Swiften supports Forwarded tag
 
#define SWIFTEN_SUPPORTS_FORWARDED
 
//Privilege tag is implemented locally, but it makes little sense without forwarded tag
 
#define SWIFTEN_SUPPORTS_PRIVILEGE
 
#endif
 
\ No newline at end of file
include/transport/Conversation.h
Show inline comments
 
@@ -61,13 +61,23 @@ class Conversation {
 
		const std::string &getLegacyName() { return m_legacyName; }
 

	
 
		/// Handles new message from Legacy network and forwards it to XMPP.
 

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

	
 
		//Generates a carbon <sent> wrapper <message> around the given payload and delivers it
 
		void forwardAsCarbonSent(
 
			const SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &payload,
 
			const Swift::JID& to);
 

	
 
		//Generates a impersonation request <message> arount the given payload and delivers it
 
		void forwardImpersonated(
 
			SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> payload,
 
			const Swift::JID& server);
 

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

	
 
		/// Handles participant change in MUC.
 

	
include/transport/NetworkPlugin.h
Show inline comments
 
@@ -119,13 +119,14 @@ class NetworkPlugin {
 
		/// Call this function when new message is received from legacy network for user.
 
		/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
 
		/// \param legacyName Name of legacy network buddy or name of room. (eg. "user2@gmail.com")
 
		/// \param message Plain text message.
 
		/// \param nickname Nickname of buddy in room. Empty if it's normal chat message.
 
		/// \param xhtml XHTML message.
 
		void handleMessage(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &nickname = "", const std::string &xhtml = "", const std::string &timestamp = "", bool headline = false, bool pm = false);
 
		/// \param carbon If set, the message is a carbon copy of our own message, sent in a different legacy network client. The message should be treated as sent FROM us, not TO us.
 
		void handleMessage(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &nickname = "", const std::string &xhtml = "", const std::string &timestamp = "", bool headline = false, bool pm = false, bool carbon = false);
 

	
 
		void handleMessageAck(const std::string &user, const std::string &legacyName, const std::string &id);
 

	
 
		/// Call this function when subject in room changed.
 
		/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
 
		/// \param legacyName Name of room. (eg. "#spectrum")
include/transport/protocol.proto
Show inline comments
 
@@ -74,12 +74,13 @@ message ConversationMessage {
 
	optional string nickname = 4;
 
	optional string xhtml = 5;
 
	optional string timestamp = 6;
 
	optional bool headline = 7;
 
	optional string id = 8;
 
	optional bool pm = 9;
 
	optional bool carbon = 10;
 
}
 

	
 
message Room {
 
	required string userName = 1;
 
	required string nickname = 2;
 
	required string room = 3;
libtransport/Conversation.cpp
Show inline comments
 
@@ -21,24 +21,37 @@
 
#include <iostream>
 
#include "transport/Conversation.h"
 
#include "transport/ConversationManager.h"
 
#include "transport/User.h"
 
#include "transport/Transport.h"
 
#include "transport/Buddy.h"
 
#include "transport/PresenceOracle.h"
 
#include "transport/RosterManager.h"
 
#include "transport/Frontend.h"
 
#include "transport/Config.h"
 
#include "transport/Logging.h"
 

	
 
#include "Swiften/Elements/MUCItem.h"
 
#include "Swiften/Elements/MUCOccupant.h"
 
#include "Swiften/Elements/MUCUserPayload.h"
 
#include "Swiften/Elements/Delay.h"
 
#include "Swiften/Elements/MUCPayload.h"
 
#include "Swiften/Elements/Presence.h"
 
#include "Swiften/Elements/VCardUpdate.h"
 

	
 
#include "Swiften/SwiftenCompat.h"
 
#ifdef SWIFTEN_SUPPORTS_CARBONS
 
#include "Swiften/Elements/CarbonsSent.h"
 
#include "Swiften/Elements/Forwarded.h"
 
#include "Swiften/Elements/HintPayload.h"
 
#endif
 

	
 
#ifdef SWIFTEN_SUPPORTS_PRIVILEGE
 
#include "Swiften/Elements/Privilege.h"
 
#endif
 

	
 
namespace Transport {
 
	
 
DEFINE_LOGGER(logger, "Conversation");
 

	
 
Conversation::Conversation(ConversationManager *conversationManager, const std::string &legacyName, bool isMUC) : m_conversationManager(conversationManager) {
 
	m_legacyName = legacyName;
 
@@ -142,13 +155,13 @@ void Conversation::handleRawMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::
 
				m_conversationManager->getComponent()->getFrontend()->sendMessage(message);
 
			}
 
		}
 
	}
 
}
 

	
 
void Conversation::handleMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message, const std::string &nickname) {
 
void Conversation::handleMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &message, const std::string &nickname, const bool carbon) {
 
	if (m_muc) {
 
		message->setType(Swift::Message::Groupchat);
 
	}
 
	else {
 
		if (message->getType() == Swift::Message::Headline) {
 
			if (m_conversationManager->getUser()->getUserSetting("send_headlines") != "1") {
 
@@ -220,13 +233,108 @@ void Conversation::handleMessage(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Mes
 
		}
 

	
 
		message->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), n));
 
		LOG4CXX_INFO(logger, "MSG FROM " << message->getFrom().toString());
 
	}
 

	
 

	
 
	if (carbon) {
 
#ifdef SWIFTEN_SUPPORTS_CARBONS
 
		LOG4CXX_INFO(logger, "CARBON MSG");
 
		//Swap from and to
 
		Swift::JID from = message->getFrom();
 
		message->setFrom(message->getTo());
 
		message->setTo(from);
 

	
 
		//Carbons should be sent to every resource directly.
 
		//Even if we tried to send to bare jid, the server would at best route it
 
		//as it would normal message (usually to the highest priority resource),
 
		//but won't produce carbons to other resources as it does with normal messages.
 
		Component* transport = this->getConversationManager()->getComponent();
 
		std::vector<Swift::Presence::ref> presences = transport->getPresenceOracle()->getAllPresence(this->m_jid.toBare());
 
		if (presences.empty()) {
 
			LOG4CXX_INFO(logger, "No presences for JID " << this->m_jid.toString()
 
			    << ", will send to bare JID for archival.");
 
			this->forwardAsCarbonSent(message, this->m_jid.toBare());
 
		} else
 
		BOOST_FOREACH(const Swift::Presence::ref &it, presences) {
 
			this->forwardAsCarbonSent(message, it->getFrom());
 
		}
 
#else //!SWIFTEN_SUPPORTS_CARBONS
 
		//Ignore the message.
 
#endif
 
	} else {
 
		handleRawMessage(message);
 
	}
 
}
 

	
 
void Conversation::forwardAsCarbonSent(
 
	const SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> &payload,
 
	const Swift::JID& to)
 
{
 
#ifdef SWIFTEN_SUPPORTS_CARBONS
 
	LOG4CXX_INFO(logger, "Carbon <sent> to -> " << to.toString());
 

	
 
	//Message envelope
 
	SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> message(new Swift::Message());
 

	
 
	//Type MUST be equal to the original message type
 
	message->setType(payload->getType());
 

	
 
	//XEP-0280 docs say "from" MUST be the carbon subscriber's JID,
 
	//so a transport will need to wrap this in another <privilege> wrapper.
 
	message->setFrom(m_jid.toBare());
 
	message->setTo(to);
 

	
 
	//Wrap the payload in a <sent><forwarded>
 
	SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Forwarded> forwarded(new Swift::Forwarded());
 
	forwarded->setStanza(payload);
 
	SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::CarbonsSent> sent(new Swift::CarbonsSent());
 
	sent->setForwarded(forwarded);
 
	message->addPayload(sent);
 

	
 
	//Add no-copy to prevent some servers from creating carbons of carbons
 
	Swift::HintPayload::ref noCopy(new Swift::HintPayload(Swift::HintPayload::NoCopy));
 
	message->addPayload(noCopy);
 

	
 
	this->forwardImpersonated(message, Swift::JID("", message->getFrom().getDomain()));
 
#else
 
	//We cannot send the carbon.
 
#endif
 
}
 

	
 
//Generates a XEP-0356 privilege wrapper asking to impersonate a user from a given domain
 
void Conversation::forwardImpersonated(
 
	SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> payload,
 
	const Swift::JID& server)
 
{
 
#ifdef SWIFTEN_SUPPORTS_PRIVILEGE
 
	LOG4CXX_INFO(logger, "Impersonate to -> " << server.toString());
 
	Component* transport = this->getConversationManager()->getComponent();
 

	
 
	//Message envelope
 
	SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message> message(new Swift::Message());
 
	// "from" MUST be our bare jid
 
	message->setFrom(transport->getJID());
 
	// "to" MUST be the bare jid of the server we're asking to impersonate
 
	message->setTo(server);
 
	message->setType(Swift::Message::Normal);
 

	
 
	SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Forwarded> forwarded(new Swift::Forwarded());
 
	forwarded->setStanza(payload);
 
	
 
	Swift::Privilege::ref privilege(new Swift::Privilege());
 
	privilege->setForwarded(forwarded);
 

	
 
	message->addPayload(privilege);
 
	LOG4CXX_INFO(logger, "Impersonate: sending message");
 
	handleRawMessage(message);
 
#else
 
	//Try to send the message as is -- some servers can be configured to accept this
 
	handleRawMessage(payload);
 
#endif
 
}
 

	
 
std::string Conversation::getParticipants() {
 
	std::string ret;
 
	for (std::map<std::string, Participant>::iterator it = m_participants.begin(); it != m_participants.end(); it++) {
 
		ret += (*it).second.presence->getFrom().getResource() + ", ";
libtransport/NetworkPluginServer.cpp
Show inline comments
 
@@ -731,15 +731,14 @@ void NetworkPluginServer::handleConvMessagePayload(const std::string &data, bool
 
	// Create new Conversation if it does not exist
 
	if (!conv) {
 
		conv = new NetworkConversation(user->getConversationManager(), payload.buddyname());
 
		user->getConversationManager()->addConversation(conv);
 
		conv->onMessageToSend.connect(boost::bind(&NetworkPluginServer::handleMessageReceived, this, _1, _2));
 
	}
 

	
 
	// Forward it
 
	conv->handleMessage(msg, payload.nickname());
 
	conv->handleMessage(msg, payload.nickname(), payload.carbon());
 
	m_userManager->messageToXMPPSent();
 
}
 

	
 
void NetworkPluginServer::handleConvMessageAckPayload(const std::string &data) {
 
	pbnetwork::ConversationMessage payload;
 

	
plugin/cpp/networkplugin.cpp
Show inline comments
 
@@ -91,22 +91,23 @@ void NetworkPlugin::sendConfig(const PluginConfig &cfg) {
 
void NetworkPlugin::sendRawXML(std::string &xml) {
 
	WRAP(xml, pbnetwork::WrapperMessage_Type_TYPE_RAW_XML);
 

	
 
	send(xml);
 
}
 

	
 
void NetworkPlugin::handleMessage(const std::string &user, const std::string &legacyName, const std::string &msg, const std::string &nickname, const std::string &xhtml, const std::string &timestamp, bool headline, bool pm) {
 
void NetworkPlugin::handleMessage(const std::string &user, const std::string &legacyName, const std::string &msg, const std::string &nickname, const std::string &xhtml, const std::string &timestamp, bool headline, bool pm, bool carbon) {
 
	pbnetwork::ConversationMessage m;
 
	m.set_username(user);
 
	m.set_buddyname(legacyName);
 
	m.set_message(msg);
 
	m.set_nickname(nickname);
 
	m.set_xhtml(xhtml);
 
	m.set_timestamp(timestamp);
 
	m.set_headline(headline);
 
	m.set_pm(pm);
 
	m.set_carbon(carbon);
 

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

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_CONV_MESSAGE);
 

	
spectrum/src/frontends/xmpp/XMPPFrontend.cpp
Show inline comments
 
@@ -29,12 +29,13 @@
 
#include "transport/Factory.h"
 
#include "transport/UserRegistry.h"
 
#include "transport/Logging.h"
 
#include "transport/Config.h"
 
#include "transport/Transport.h"
 
#include "storageparser.h"
 
#include "Swiften/SwiftenCompat.h"
 
#ifdef _WIN32
 
#include <Swiften/TLS/CAPICertificate.h>
 
#include "Swiften/TLS/Schannel/SchannelServerContext.h"
 
#include "Swiften/TLS/Schannel/SchannelServerContextFactory.h"
 
#elif defined(__APPLE__) && HAVE_SWIFTEN_3
 
#include <Swiften/TLS/SecureTransport/SecureTransportCertificate.h>
 
@@ -56,13 +57,22 @@
 
#include "Swiften/Serializer/PayloadSerializers/SpectrumErrorSerializer.h"
 
#include "Swiften/Parser/PayloadParsers/MUCPayloadParser.h"
 
#include "BlockParser.h"
 
#include "BlockSerializer.h"
 
#include "Swiften/Parser/PayloadParsers/InvisibleParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/InvisibleSerializer.h"
 
#include "Swiften/Parser/PayloadParsers/HintPayloadParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/HintPayloadSerializer.h"
 
#ifdef SWIFTEN_SUPPORTS_PRIVILEGE
 
#include "Swiften/Parser/PayloadParsers/PrivilegeParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/PrivilegeSerializer.h"
 
#endif
 
#include "Swiften/Parser/GenericPayloadParserFactory.h"
 
#if SWIFTEN_VERSION >= 0x030000
 
#include "Swiften/Parser/GenericPayloadParserFactory2.h"
 
#endif
 
#include "Swiften/Queries/IQRouter.h"
 
#include "Swiften/Elements/RosterPayload.h"
 
#include "discoitemsresponder.h"
 
#include "Swiften/Elements/InBandRegistrationPayload.h"
 

	
 
using namespace Swift;
 
@@ -71,12 +81,26 @@ namespace Transport {
 
	
 
DEFINE_LOGGER(logger, "XMPPFrontend");
 

	
 
XMPPFrontend::XMPPFrontend() {
 
}
 

	
 
class SwiftServerExposed: public Swift::Server
 
{
 
public:
 
	PayloadParserFactoryCollection* getPayloadParserFactories() { return Swift::Server::getPayloadParserFactories(); }
 
	PayloadSerializerCollection* getPayloadSerializers() { return Swift::Server::getPayloadSerializers(); }
 
};
 

	
 
class SwiftComponentExposed: public Swift::Component
 
{
 
public:
 
	PayloadParserFactoryCollection* getPayloadParserFactories() { return Swift::Component::getPayloadParserFactories(); }
 
	PayloadSerializerCollection* getPayloadSerializers() { return Swift::Component::getPayloadSerializers(); }
 
};
 

	
 
void XMPPFrontend::init(Component *transport, Swift::EventLoop *loop, Swift::NetworkFactories *factories, Config *config, Transport::UserRegistry *userRegistry) {
 
	m_transport = transport;
 
	m_component = NULL;
 
	m_server = NULL;
 
	m_rawXML = false;
 
	m_config = transport->getConfig();
 
@@ -90,20 +114,25 @@ void XMPPFrontend::init(Component *transport, Swift::EventLoop *loop, Swift::Net
 
	m_parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::XHTMLIMParser>("html", "http://jabber.org/protocol/xhtml-im"));
 
	m_parserFactories.push_back(new Swift::GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0"));
 
	m_parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0"));
 
	m_parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats"));
 
	m_parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::GatewayPayloadParser>("query", "jabber:iq:gateway"));
 
	m_parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::MUCPayloadParser>("x", "http://jabber.org/protocol/muc"));
 
	m_parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::HintPayloadParser>("no-permanent-store", "urn:xmpp:hints"));
 
	m_parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::HintPayloadParser>("no-store", "urn:xmpp:hints"));
 
	m_parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::HintPayloadParser>("no-copy", "urn:xmpp:hints"));
 
	m_parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::HintPayloadParser>("store", "urn:xmpp:hints"));
 

	
 
	m_payloadSerializers.push_back(new Swift::AttentionSerializer());
 
	m_payloadSerializers.push_back(new Swift::XHTMLIMSerializer());
 
	m_payloadSerializers.push_back(new Transport::BlockSerializer());
 
	m_payloadSerializers.push_back(new Swift::InvisibleSerializer());
 
	m_payloadSerializers.push_back(new Swift::StatsSerializer());
 
	m_payloadSerializers.push_back(new Swift::SpectrumErrorSerializer());
 
	m_payloadSerializers.push_back(new Swift::GatewayPayloadSerializer());
 
	m_payloadSerializers.push_back(new Swift::HintPayloadSerializer());
 

	
 
	if (CONFIG_BOOL(m_config, "service.server_mode")) {
 
		LOG4CXX_INFO(logger, "Creating component in server mode on port " << CONFIG_INT(m_config, "service.port"));
 
		m_server = new Swift::Server(loop, factories, userRegistry, m_jid, CONFIG_STRING(m_config, "service.server"), CONFIG_INT(m_config, "service.port"));
 
		if (!CONFIG_STRING(m_config, "service.cert").empty()) {
 
#ifndef _WIN32
 
@@ -122,12 +151,18 @@ void XMPPFrontend::init(Component *transport, Swift::EventLoop *loop, Swift::Net
 
			LOG4CXX_WARN(logger, "No PKCS#12 certificate used. TLS is disabled.");
 
		}
 
// 		m_server->start();
 
		m_stanzaChannel = m_server->getStanzaChannel();
 
		m_iqRouter = m_server->getIQRouter();
 

	
 
		SwiftServerExposed* entity(reinterpret_cast<SwiftServerExposed*>(m_server));
 
#ifdef SWIFTEN_SUPPORTS_PRIVILEGE
 
		m_parserFactories.push_back(new Swift::GenericPayloadParserFactory2<Swift::PrivilegeParser>("privilege", "urn:xmpp:privilege:1", entity->getPayloadParserFactories()));
 
		m_payloadSerializers.push_back(new Swift::PrivilegeSerializer(entity->getPayloadSerializers()));
 
#endif
 

	
 
		BOOST_FOREACH(Swift::PayloadParserFactory *factory, m_parserFactories) {
 
			m_server->addPayloadParserFactory(factory);
 
		}
 

	
 
		BOOST_FOREACH(Swift::PayloadSerializer *serializer, m_payloadSerializers) {
 
			m_server->addPayloadSerializer(serializer);
 
@@ -146,24 +181,31 @@ void XMPPFrontend::init(Component *transport, Swift::EventLoop *loop, Swift::Net
 
		m_component->setSoftwareVersion("Spectrum", SPECTRUM_VERSION);
 
		m_component->onConnected.connect(boost::bind(&XMPPFrontend::handleConnected, this));
 
		m_component->onError.connect(boost::bind(&XMPPFrontend::handleConnectionError, this, _1));
 
		m_component->onDataRead.connect(boost::bind(&XMPPFrontend::handleDataRead, this, _1));
 
		m_component->onDataWritten.connect(boost::bind(&XMPPFrontend::handleDataWritten, this, _1));
 

	
 
		SwiftComponentExposed* entity(reinterpret_cast<SwiftComponentExposed*>(m_component));
 
#ifdef SWIFTEN_SUPPORTS_PRIVILEGE
 
		m_parserFactories.push_back(new Swift::GenericPayloadParserFactory2<Swift::PrivilegeParser>("privilege", "urn:xmpp:privilege:1", entity->getPayloadParserFactories()));
 
		m_payloadSerializers.push_back(new Swift::PrivilegeSerializer(entity->getPayloadSerializers()));
 
#endif
 

	
 
		BOOST_FOREACH(Swift::PayloadParserFactory *factory, m_parserFactories) {
 
			m_component->addPayloadParserFactory(factory);
 
		}
 

	
 
		BOOST_FOREACH(Swift::PayloadSerializer *serializer, m_payloadSerializers) {
 
			m_component->addPayloadSerializer(serializer);
 
		}
 

	
 
		m_stanzaChannel = m_component->getStanzaChannel();
 
		m_iqRouter = m_component->getIQRouter();
 
	}
 

	
 

	
 
	m_capsMemoryStorage = new CapsMemoryStorage();
 
#if HAVE_SWIFTEN_3
 
	m_capsManager = new CapsManager(m_capsMemoryStorage, m_stanzaChannel, m_iqRouter, factories->getCryptoProvider());
 
#else
 
	m_capsManager = new CapsManager(m_capsMemoryStorage, m_stanzaChannel, m_iqRouter);
 
#endif
tests/libtransport/basictest.cpp
Show inline comments
 
#include "basictest.h"
 
#include "XMPPFrontend.h"
 
#include "XMPPUserRegistration.h"
 
#include "XMPPUserManager.h"
 
#include <cppunit/TestFixture.h>
 
#include <cppunit/extensions/HelperMacros.h>
 
#include <Swiften/Version.h>
 
#include <Swiften/Swiften.h>
 
#include <Swiften/EventLoop/DummyEventLoop.h>
 
#include <Swiften/Server/Server.h>
 
#include <Swiften/Network/DummyNetworkFactories.h>
 
#include <Swiften/Network/DummyConnectionServer.h>
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 

	
 
#include "Swiften/Serializer/GenericPayloadSerializer.h"
 
#include "Swiften/Parser/GenericPayloadParserFactory.h"
 
#if SWIFTEN_VERSION >= 0x030000
 
#include "Swiften/Parser/GenericPayloadParserFactory2.h"
 
#endif
 

	
 
#include "storageparser.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"
 
@@ -27,12 +32,18 @@
 
#include "Swiften/Serializer/PayloadSerializers/SpectrumErrorSerializer.h"
 
#include "Swiften/Parser/PayloadParsers/MUCPayloadParser.h"
 
#include "BlockParser.h"
 
#include "BlockSerializer.h"
 
#include "Swiften/Parser/PayloadParsers/InvisibleParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/InvisibleSerializer.h"
 
#include "Swiften/Parser/PayloadParsers/HintPayloadParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/HintPayloadSerializer.h"
 
#ifdef SWIFTEN_SUPPORTS_PRIVILEGE
 
#include "Swiften/Parser/PayloadParsers/PrivilegeParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/PrivilegeSerializer.h"
 
#endif
 

	
 
using namespace Transport;
 

	
 
void BasicTest::setMeUp (void) {
 
	streamEnded = false;
 
	std::istringstream ifs("service.server_mode = 1\nservice.jid=localhost\nservice.more_resources=1\nservice.admin_jid=me@localhost\n");
 
@@ -65,24 +76,35 @@ void BasicTest::setMeUp (void) {
 
	parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::XHTMLIMParser>("html", "http://jabber.org/protocol/xhtml-im"));
 
	parserFactories.push_back(new Swift::GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0"));
 
	parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0"));
 
	parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats"));
 
	parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::GatewayPayloadParser>("query", "jabber:iq:gateway"));
 
	parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::MUCPayloadParser>("x", "http://jabber.org/protocol/muc"));
 
	parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::HintPayloadParser>("no-permanent-store", "urn:xmpp:hints"));
 
	parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::HintPayloadParser>("no-store", "urn:xmpp:hints"));
 
	parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::HintPayloadParser>("no-copy", "urn:xmpp:hints"));
 
	parserFactories.push_back(new Swift::GenericPayloadParserFactory<Swift::HintPayloadParser>("store", "urn:xmpp:hints"));
 
#ifdef SWIFTEN_SUPPORTS_PRIVILEGE
 
	parserFactories.push_back(new Swift::GenericPayloadParserFactory2<Swift::PrivilegeParser>("privilege", "urn:xmpp:privilege:1", payloadParserFactories));
 
#endif
 

	
 
	BOOST_FOREACH(Swift::PayloadParserFactory *factory, parserFactories) {
 
		payloadParserFactories->addFactory(factory);
 
	}
 

	
 
	_payloadSerializers.push_back(new Swift::AttentionSerializer());
 
	_payloadSerializers.push_back(new Swift::XHTMLIMSerializer());
 
	_payloadSerializers.push_back(new Transport::BlockSerializer());
 
	_payloadSerializers.push_back(new Swift::InvisibleSerializer());
 
	_payloadSerializers.push_back(new Swift::StatsSerializer());
 
	_payloadSerializers.push_back(new Swift::SpectrumErrorSerializer());
 
	_payloadSerializers.push_back(new Swift::GatewayPayloadSerializer());
 
	_payloadSerializers.push_back(new Swift::HintPayloadSerializer());
 
#ifdef SWIFTEN_SUPPORTS_PRIVILEGE
 
	_payloadSerializers.push_back(new Swift::PrivilegeSerializer(payloadSerializers));
 
#endif
 

	
 
	BOOST_FOREACH(Swift::PayloadSerializer *serializer, _payloadSerializers) {
 
		payloadSerializers->addSerializer(serializer);
 
	}
 

	
 
	parser = new Swift::XMPPParser(this, payloadParserFactories, factories->getXMLParserFactory());
0 comments (0 inline, 0 general)