Changeset - 6b45e0e418ee
backends/frotz/main.cpp
Show inline comments
 
@@ -147,25 +147,25 @@ static void start_dfrotz(dfrotz &p, const std::string &game) {
 

	
 
class FrotzNetworkPlugin : public NetworkPlugin {
 
	public:
 
		Swift::BoostNetworkFactories *m_factories;
 
		Swift::BoostIOServiceThread m_boostIOServiceThread;
 
		SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Connection> m_conn;
 

	
 
		FrotzNetworkPlugin(Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin() {
 
			this->config = config;
 
			m_factories = new Swift::BoostNetworkFactories(loop);
 
			m_conn = m_factories->getConnectionFactory()->createConnection();
 
			m_conn->onDataRead.connect(boost::bind(&FrotzNetworkPlugin::_handleDataRead, this, _1));
 
			m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port));
 
			m_conn->connect(Swift::HostAddressPort(SWIFT_HOSTADDRESS(host), port));
 
// 			m_conn->onConnectFinished.connect(boost::bind(&FrotzNetworkPlugin::_handleConnected, this, _1));
 
// 			m_conn->onDisconnected.connect(boost::bind(&FrotzNetworkPlugin::handleDisconnected, this));
 
		}
 

	
 
		void sendData(const std::string &string) {
 
			m_conn->write(Swift::createSafeByteArray(string));
 
		}
 

	
 
		void _handleDataRead(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::SafeByteArray> data) {
 
			std::string d(data->begin(), data->end());
 
			handleDataRead(d);
 
		}
backends/smstools3/main.cpp
Show inline comments
 
@@ -48,25 +48,25 @@ class SMSNetworkPlugin : public NetworkPlugin {
 
		Swift::BoostIOServiceThread m_boostIOServiceThread;
 
		SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Connection> m_conn;
 
		Swift::Timer::ref m_timer;
 
		int m_internalUser;
 
		StorageBackend *storageBackend;
 

	
 
		SMSNetworkPlugin(Config *config, Swift::SimpleEventLoop *loop, StorageBackend *storagebackend, const std::string &host, int port) : NetworkPlugin() {
 
			this->config = config;
 
			this->storageBackend = storagebackend;
 
			m_factories = new Swift::BoostNetworkFactories(loop);
 
			m_conn = m_factories->getConnectionFactory()->createConnection();
 
			m_conn->onDataRead.connect(boost::bind(&SMSNetworkPlugin::_handleDataRead, this, _1));
 
			m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port));
 
			m_conn->connect(Swift::HostAddressPort(SWIFT_HOSTADDRESS(host), port));
 
// 			m_conn->onConnectFinished.connect(boost::bind(&FrotzNetworkPlugin::_handleConnected, this, _1));
 
// 			m_conn->onDisconnected.connect(boost::bind(&FrotzNetworkPlugin::handleDisconnected, this));
 

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

	
 
			m_timer = m_factories->getTimerFactory()->createTimer(5000);
 
			m_timer->onTick.connect(boost::bind(&SMSNetworkPlugin::handleSMSDir, this));
 
			m_timer->start();
 

	
 
			// We're reusing our database model here. Buddies of user with JID INTERNAL_USER are there
 
			// to match received GSM messages from number N with the XMPP users who sent message to number N.
 
			// BuddyName = GSM number
backends/swiften/main.cpp
Show inline comments
 
@@ -80,25 +80,25 @@ class SwiftenPlugin : public NetworkPlugin, Swift::XMPPParserClient {
 
		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));
 
			m_conn->connect(Swift::HostAddressPort(SWIFT_HOSTADDRESS(host), port));
 
#if HAVE_SWIFTEN_3
 
			serializer = new Swift::XMPPSerializer(&collection, Swift::ClientStreamType, false);
 
#else
 
			serializer = new Swift::XMPPSerializer(&collection, Swift::ClientStreamType);
 
#endif
 
			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
backends/template/plugin.cpp
Show inline comments
 
@@ -11,25 +11,25 @@
 
#include <boost/algorithm/string.hpp>
 
using namespace boost::filesystem;
 
using namespace boost::program_options;
 
using namespace Transport;
 

	
 
DEFINE_LOGGER(logger, "Backend Template");
 

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

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

	
 
// NetworkPlugin uses this method to send the data to networkplugin server
 
void Plugin::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 Plugin::_handleDataRead(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::SafeByteArray> data) {
 
	std::string d(data->begin(), data->end());
backends/twitter/TwitterPlugin.cpp
Show inline comments
 
@@ -63,25 +63,25 @@ TwitterPlugin::TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, Stora
 
	adminLegacyName = "twitter.com"; 
 
	adminChatRoom = "#twitter"; 
 
	adminNickName = "twitter"; 
 
	adminAlias = "twitter";
 

	
 
	OAUTH_KEY = "twitter_oauth_token";
 
	OAUTH_SECRET = "twitter_oauth_secret";
 
	MODE = "mode";
 

	
 
	m_factories = new Swift::BoostNetworkFactories(loop);
 
	m_conn = m_factories->getConnectionFactory()->createConnection();
 
	m_conn->onDataRead.connect(boost::bind(&TwitterPlugin::_handleDataRead, this, _1));
 
	m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port));
 
	m_conn->connect(Swift::HostAddressPort(SWIFT_HOSTADDRESS(host), port));
 

	
 
	tp = new ThreadPool(loop_, 10);
 

	
 
	LOG4CXX_INFO(logger, "Fetch timeout is set to " << CONFIG_INT_DEFAULTED(config, "twitter.fetch_timeout", 90000));
 
	tweet_timer = m_factories->getTimerFactory()->createTimer(CONFIG_INT_DEFAULTED(config, "twitter.fetch_timeout", 90000));
 
	message_timer = m_factories->getTimerFactory()->createTimer(CONFIG_INT_DEFAULTED(config, "twitter.fetch_timeout", 90000));
 

	
 
	tweet_timer->onTick.connect(boost::bind(&TwitterPlugin::pollForTweets, this));
 
	message_timer->onTick.connect(boost::bind(&TwitterPlugin::pollForDirectMessages, this));
 

	
 
	tweet_timer->start();
 
	message_timer->start();
include/Swiften/FileTransfer/CombinedOutgoingFileTransferManager.cpp
Show inline comments
 
/*
 
 * Copyright (c) 2011 Tobias Markmann
 
 * Licensed under the simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include "CombinedOutgoingFileTransferManager.h"
 

	
 
#include <boost/foreach.hpp>
 
#include <boost/smart_ptr/make_shared.hpp>
 

	
 
#include <Swiften/JID/JID.h>
 
#include "Swiften/Disco/EntityCapsProvider.h"
 
#include <Swiften/Jingle/JingleSessionManager.h>
 
#include <Swiften/Jingle/JingleSessionImpl.h>
 
#include <Swiften/Jingle/JingleContentID.h>
 
#include <Swiften/FileTransfer/OutgoingJingleFileTransfer.h>
 
#include <Swiften/FileTransfer/MyOutgoingSIFileTransfer.h>
 
#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h>
 
#include <Swiften/Base/IDGenerator.h>
 
#include <Swiften/Elements/Presence.h>
 
#include <Swiften/Base/foreach.h>
 

	
 

	
 
namespace Swift {
 

	
 
CombinedOutgoingFileTransferManager::CombinedOutgoingFileTransferManager(JingleSessionManager* jingleSessionManager, IQRouter* router, EntityCapsProvider* capsProvider, RemoteJingleTransportCandidateSelectorFactory* remoteFactory, LocalJingleTransportCandidateGeneratorFactory* localFactory, SOCKS5BytestreamRegistry* bytestreamRegistry, SOCKS5BytestreamProxy* bytestreamProxy, Transport::PresenceOracle *presOracle, SOCKS5BytestreamServer *bytestreamServer) : jsManager(jingleSessionManager), iqRouter(router), capsProvider(capsProvider), remoteFactory(remoteFactory), localFactory(localFactory), bytestreamRegistry(bytestreamRegistry), bytestreamProxy(bytestreamProxy), presenceOracle(presOracle), bytestreamServer(bytestreamServer) {
 
	idGenerator = new IDGenerator();
 
}
 

	
 
CombinedOutgoingFileTransferManager::~CombinedOutgoingFileTransferManager() {
 
	delete idGenerator;
 
}
 

	
 
@@ -59,49 +59,49 @@ SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<OutgoingFileTransfer> CombinedOutgoingFileT
 
	
 
	return jingleFT;
 
}
 

	
 
boost::optional<JID> CombinedOutgoingFileTransferManager::highestPriorityJIDSupportingJingle(const JID& bareJID) {
 
	JID fullReceipientJID;
 
	int priority = INT_MIN;
 
	
 
	//getAllPresence(bareJID) gives you all presences for the bare JID (i.e. all resources) Remko Tronçon @ 11:11
 
	std::vector<Presence::ref> presences = presenceOracle->getAllPresence(bareJID);
 

	
 
	//iterate over them
 
	foreach(Presence::ref pres, presences) {
 
	BOOST_FOREACH(Presence::ref pres, presences) {
 
		if (pres->getPriority() > priority) {
 
			// look up caps from the jid
 
			DiscoInfo::ref info = capsProvider->getCaps(pres->getFrom());
 
			if (info && info->hasFeature(DiscoInfo::JingleFeature) && info->hasFeature(DiscoInfo::JingleFTFeature) &&
 
				info->hasFeature(DiscoInfo::JingleTransportsIBBFeature)) {
 
			
 
				priority = pres->getPriority();
 
				fullReceipientJID = pres->getFrom();
 
			}
 
		}
 
	}
 
	
 
	return fullReceipientJID.isValid() ? boost::optional<JID>(fullReceipientJID) : boost::optional<JID>();
 
}
 

	
 
boost::optional<JID> CombinedOutgoingFileTransferManager::highestPriorityJIDSupportingSI(const JID& bareJID) {
 
	JID fullReceipientJID;
 
	int priority = INT_MIN;
 
	
 
	//getAllPresence(bareJID) gives you all presences for the bare JID (i.e. all resources) Remko Tronçon @ 11:11
 
	std::vector<Presence::ref> presences = presenceOracle->getAllPresence(bareJID);
 

	
 
	//iterate over them
 
	foreach(Presence::ref pres, presences) {
 
	BOOST_FOREACH(Presence::ref pres, presences) {
 
		if (pres->getPriority() > priority) {
 
			// look up caps from the jid
 
			DiscoInfo::ref info = capsProvider->getCaps(pres->getFrom());
 
			if (info && info->hasFeature("http://jabber.org/protocol/si/profile/file-transfer")) {
 
			
 
				priority = pres->getPriority();
 
				fullReceipientJID = pres->getFrom();
 
			}
 
		}
 
	}
 
	
 
	return fullReceipientJID.isValid() ? boost::optional<JID>(fullReceipientJID) : boost::optional<JID>();
include/Swiften/Parser/PayloadParsers/GatewayPayloadParser.cpp
Show inline comments
 
/*
 
 * Copyright (c) 2012 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

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

	
 
#include <boost/foreach.hpp>
 
#include <boost/lexical_cast.hpp>
 

	
 
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
 
#include <Swiften/Parser/PayloadParserFactory.h>
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Elements/MUCOccupant.h>
 
#include <Swiften/Parser/Tree/TreeReparser.h>
 

	
 
namespace Swift {
 

	
 
void GatewayPayloadParser::handleTree(ParserElement::ref root) {
 
	foreach (ParserElement::ref child, root->getAllChildren()) {
 
	BOOST_FOREACH (ParserElement::ref child, root->getAllChildren()) {
 
		if (child->getName() == "desc") {
 
			getPayloadInternal()->setDesc(child->getText());
 
		}
 
		else if (child->getName() == "prompt") {
 
			getPayloadInternal()->setPrompt(child->getText());
 
		}
 
		else if (child->getName() == "jid") {
 
			getPayloadInternal()->setJID(child->getText());
 
		}
 
	}
 
}
 

	
include/Swiften/Parser/PayloadParsers/MUCPayloadParser.cpp
Show inline comments
 
/*
 
 * Copyright (c) 2010 Kevin Smith
 
 * Licensed under the GNU General Public License v3.
 
 * See Documentation/Licenses/GPLv3.txt for more information.
 
 */
 

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

	
 
#include <boost/foreach.hpp>
 
#include <boost/lexical_cast.hpp>
 

	
 
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
 
#include <Swiften/Parser/PayloadParserFactory.h>
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Elements/MUCOccupant.h>
 
#include <Swiften/Parser/Tree/TreeReparser.h>
 

	
 
namespace Swift {
 

	
 
void MUCPayloadParser::handleTree(ParserElement::ref root) {
 
	foreach (ParserElement::ref child, root->getAllChildren()) {
 
	BOOST_FOREACH (ParserElement::ref child, root->getAllChildren()) {
 
		if (child->getName() == "password" && child->getNamespace() == root->getNamespace()) {
 
			getPayloadInternal()->setPassword(child->getText());
 
		}
 
	}
 
}
 

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

	
 
#include <Swiften/Parser/StringTreeParser.h>
 
#include <Swiften/Parser/PlatformXMLParserFactory.h>
 
#include <Swiften/Parser/Tree/ParserElement.h>
 
#include <Swiften/Parser/XMLParser.h>
 
#include <Swiften/Version.h>
 

	
 
namespace Swift {
 

	
 
class DefaultStringTreeParser : public StringTreeParser {
 
	public:
 
		void handleTree(ParserElement::ref root) {
 
			root_ = root;
 
		}
 

	
 
		ParserElement::ref getRoot() {
 
			return root_;
 
		}
 

	
 
	private:
 
		ParserElement::ref root_;
 
};
 
	
 
ParserElement::ref StringTreeParser::parse(const std::string &xml) {
 
	PlatformXMLParserFactory factory;
 
	DefaultStringTreeParser client;
 
#if (SWIFTEN_VERSION >= 0x040000)
 
	std::unique_ptr<XMLParser> parser = factory.createXMLParser(&client);
 
#else
 
	XMLParser *parser = factory.createXMLParser(&client);
 
#endif
 
	
 
	parser->parse(xml);
 
	ParserElement::ref root = client.getRoot();
 
#if (SWIFTEN_VERSION < 0x040000)
 
	delete parser;
 
#endif
 
	return root;
 
}
 

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

	
 
#include <Swiften/Serializer/PayloadSerializers/GatewayPayloadSerializer.h>
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
 
#include <Swiften/Serializer/XML/XMLTextNode.h>
 
#include <Swiften/Serializer/XML/XMLElement.h>
 
#include <Swiften/Serializer/PayloadSerializerCollection.h>
 

	
 
#include "Swiften/SwiftenCompat.h"
 

	
 
namespace Swift {
 

	
 
GatewayPayloadSerializer::GatewayPayloadSerializer()
 
	: GenericPayloadSerializer<GatewayPayload>() {
 
}
include/Swiften/Serializer/PayloadSerializers/SpectrumErrorSerializer.cpp
Show inline comments
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

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

	
 
#include <boost/shared_ptr.hpp>
 

	
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Serializer/XML/XMLTextNode.h>
 
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
 
#include <Swiften/Serializer/XML/XMLElement.h>
 
#include "Swiften/SwiftenCompat.h"
 
#include <boost/lexical_cast.hpp>
 

	
 
namespace Swift {
 

	
 
SpectrumErrorSerializer::SpectrumErrorSerializer() : GenericPayloadSerializer<SpectrumErrorPayload>() {
 
}
 

	
 
std::string SpectrumErrorSerializer::serializePayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<SpectrumErrorPayload> error)  const {
 
	std::string data;
 
	switch (error->getError()) {
 
		case SpectrumErrorPayload::CONNECTION_ERROR_NETWORK_ERROR: data = "CONNECTION_ERROR_NETWORK_ERROR"; break;
 
		case SpectrumErrorPayload::CONNECTION_ERROR_INVALID_USERNAME: data = "CONNECTION_ERROR_INVALID_USERNAME"; break;
include/Swiften/Serializer/PayloadSerializers/StatsSerializer.cpp
Show inline comments
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Serializer/PayloadSerializers/StatsSerializer.h>
 
#include <boost/foreach.hpp>
 

	
 
#include <boost/shared_ptr.hpp>
 
#include <Swiften/Serializer/PayloadSerializers/StatsSerializer.h>
 

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

	
 
#include "Swiften/SwiftenCompat.h"
 

	
 
namespace Swift {
 

	
 
StatsSerializer::StatsSerializer() : GenericPayloadSerializer<StatsPayload>() {
 
}
 

	
 
std::string StatsSerializer::serializePayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<StatsPayload> stats)  const {
 
	XMLElement queryElement("query", "http://jabber.org/protocol/stats");
 
	foreach(const StatsPayload::Item& item, stats->getItems()) {
 
	BOOST_FOREACH(const StatsPayload::Item& item, stats->getItems()) {
 
		SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<XMLElement> statElement(new XMLElement("stat"));
 
		statElement->setAttribute("name", item.getName());
 
		if (!item.getUnits().empty()) {
 
			statElement->setAttribute("units", item.getUnits());
 
		}
 
		if (!item.getValue().empty()) {
 
			statElement->setAttribute("value", item.getValue());
 
		}
 

	
 
		queryElement.addNode(statElement);
 
	}
 

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

	
 
#include <Swiften/Serializer/PayloadSerializers/XHTMLIMSerializer.h>
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
 
#include <Swiften/Serializer/XML/XMLTextNode.h>
 
#include <Swiften/Serializer/XML/XMLElement.h>
 

	
 
#include "Swiften/SwiftenCompat.h"
 

	
 
namespace Swift {
 

	
 
XHTMLIMSerializer::XHTMLIMSerializer() : GenericPayloadSerializer<XHTMLIMPayload>() {
 
}
 

	
 
std::string XHTMLIMSerializer::serializePayload(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<XHTMLIMPayload> payload)  const {
include/Swiften/Server/Server.cpp
Show inline comments
 
/*
 
 * Copyright (c) 2010 Remko Tronçon
 
 * Licensed under the GNU General Public License v3.
 
 * See Documentation/Licenses/GPLv3.txt for more information.
 
 */
 

	
 
#include "Swiften/Server/Server.h"
 

	
 
#include <string>
 
#include <boost/bind.hpp>
 
#include <boost/foreach.hpp>
 
#include <boost/signal.hpp>
 

	
 
#include "Swiften/Base/String.h"
 
#include "Swiften/Base/foreach.h"
 
#include "Swiften/Network/Connection.h"
 
#include "Swiften/Network/ConnectionServer.h"
 
#include "Swiften/Network/ConnectionServerFactory.h"
 
#include "Swiften/Elements/Element.h"
 
#include "Swiften/Elements/Presence.h"
 
#include "Swiften/Elements/RosterPayload.h"
 
#include "Swiften/Network/NetworkFactories.h"
 
#include "Swiften/Session/SessionTracer.h"
 
#include "Swiften/Elements/IQ.h"
 
#include "Swiften/Elements/VCard.h"
 
#include "Swiften/Server/UserRegistry.h"
 
#include <string>
 
@@ -61,25 +61,25 @@ Server::~Server() {
 
	delete stanzaChannel_;
 
	delete parserFactory_;
 
}
 

	
 
void Server::start() {
 
	if (serverFromClientConnectionServer) {
 
		return;
 
	}
 
	if (address_ == "0.0.0.0") {
 
		serverFromClientConnectionServer = networkFactories_->getConnectionServerFactory()->createConnectionServer(port_);
 
	}
 
	else {
 
		serverFromClientConnectionServer = networkFactories_->getConnectionServerFactory()->createConnectionServer(Swift::HostAddress(address_), port_);
 
		serverFromClientConnectionServer = networkFactories_->getConnectionServerFactory()->createConnectionServer(SWIFT_HOSTADDRESS(address_), port_);
 
	}
 
	serverFromClientConnectionServerSignalConnections.push_back(
 
		serverFromClientConnectionServer->onNewConnection.connect(
 
				boost::bind(&Server::handleNewClientConnection, this, _1)));
 
// 	serverFromClientConnectionServerSignalConnections.push_back(
 
// 		serverFromClientConnectionServer->onStopped.connect(
 
// 				boost::bind(&Server::handleClientConnectionServerStopped, this, _1)));
 

	
 
	serverFromClientConnectionServer->start();
 
}
 

	
 
void Server::stop() {
 
@@ -87,25 +87,25 @@ void Server::stop() {
 
		return;
 
	}
 

	
 
	stopping = true;
 

	
 
// 	foreach(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<ServerFromClientSession> session, serverFromClientSessions) {
 
// 		session->finishSession();
 
// 	}
 
	serverFromClientSessions.clear();
 

	
 
	if (serverFromClientConnectionServer) {
 
		serverFromClientConnectionServer->stop();
 
		foreach(SWIFTEN_SIGNAL_NAMESPACE::connection& connection, serverFromClientConnectionServerSignalConnections) {
 
		BOOST_FOREACH(SWIFTEN_SIGNAL_NAMESPACE::connection& connection, serverFromClientConnectionServerSignalConnections) {
 
			connection.disconnect();
 
		}
 
		serverFromClientConnectionServerSignalConnections.clear();
 
		serverFromClientConnectionServer.reset();
 
	}
 

	
 
	stopping = false;
 
// 	onStopped(e);
 
}
 

	
 
void Server::handleNewClientConnection(SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Connection> connection) {
 

	
include/Swiften/SwiftenCompat.h
Show inline comments
 
@@ -29,16 +29,18 @@
 
 * SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Type> ptr;
 
 *
 
 * These are guaranteed to be the same implementation as Swift uses internally,
 
 * thus can be used when passign/retrieveing data from/to swiften.
 
 *
 
 * This is due to Swift 4 moved from boost::shared_ptr to SWIFTEN_SHRPTR_NAMESPACE::shared_ptr
 
 * and from boost::signals to boost::signals2 .
 
 */
 

	
 
#if (SWIFTEN_VERSION >= 0x040000)
 
#define SWIFTEN_SHRPTR_NAMESPACE std
 
#define SWIFTEN_SIGNAL_NAMESPACE boost::signals2
 
#define SWIFT_HOSTADDRESS(x) *(Swift::HostAddress::fromString(x))
 
#else
 
#define SWIFTEN_SHRPTR_NAMESPACE boost
 
#define SWIFTEN_SIGNAL_NAMESPACE boost::signals
 
#define SWIFT_HOSTADDRESS(x) Swift::HostAddress(x)
 
#endif
libtransport/Config.cpp
Show inline comments
 
@@ -64,38 +64,38 @@ bool Config::load(const std::string &configfile, boost::program_options::options
 
		getcwd(path, PATH_MAX);
 
		m_file = std::string(path) + "/" + m_file;
 
	}
 
#endif
 

	
 
	return ret;
 
}
 

	
 
bool Config::load(std::istream &ifs, boost::program_options::options_description &opts, const std::string &_jid) {
 
	m_unregistered.clear();
 
	opts.add_options()
 
		("service.jid", value<std::string>()->default_value(""), "Transport Jabber ID")
 
		("service.server", value<std::string>()->default_value(""), "Server to connect to")
 
		("service.server", value<std::string>()->default_value("127.0.0.1"), "Server to connect to")
 
		("service.password", value<std::string>()->default_value(""), "Password used to auth the server")
 
		("service.port", value<int>()->default_value(0), "Port the server is listening on")
 
		("service.user", value<std::string>()->default_value(""), "The name of user Spectrum runs as.")
 
		("service.group", value<std::string>()->default_value(""), "The name of group Spectrum runs as.")
 
		("service.backend", value<std::string>()->default_value("libpurple_backend"), "Backend")
 
		("service.protocol", value<std::string>()->default_value(""), "Protocol")
 
		("service.pidfile", value<std::string>()->default_value("/var/run/spectrum2/$jid.pid"), "Full path to pid file")
 
		("service.portfile", value<std::string>()->default_value("/var/run/spectrum2/$jid.port"), "File to store backend_port to. It's used by spectrum2_manager.")
 
		("service.working_dir", value<std::string>()->default_value("/var/lib/spectrum2/$jid"), "Working dir")
 
		("service.allowed_servers", value<std::vector<std::string> >()->multitoken(), "Only users from these servers can connect")
 
		("service.server_mode", value<bool>()->default_value(false), "True if Spectrum should behave as server")
 
		("service.users_per_backend", value<int>()->default_value(100), "Number of users per one legacy network backend")
 
		("service.backend_host", value<std::string>()->default_value("localhost"), "Host to bind backend server to")
 
		("service.backend_host", value<std::string>()->default_value("127.0.0.1"), "Host to bind backend server to")
 
		("service.backend_port", value<std::string>()->default_value("0"), "Port to bind backend server to")
 
		("service.cert", value<std::string>()->default_value(""), "PKCS#12 Certificate.")
 
		("service.cert_password", value<std::string>()->default_value(""), "PKCS#12 Certificate password.")
 
		("service.admin_jid", value<std::vector<std::string> >()->multitoken(), "Administrator jid.")
 
		("service.admin_password", value<std::string>()->default_value(""), "Administrator password.")
 
		("service.reuse_old_backends", value<bool>()->default_value(true), "True if Spectrum should use old backends which were full in the past.")
 
		("service.idle_reconnect_time", value<int>()->default_value(0), "Time in seconds after which idle users are reconnected to let their backend die.")
 
		("service.memory_collector_time", value<int>()->default_value(0), "Time in seconds after which backend with most memory is set to die.")
 
		("service.more_resources", value<bool>()->default_value(false), "Allow more resources to be connected in server mode at the same time.")
 
		("service.enable_privacy_lists", value<bool>()->default_value(true), "")
 
		("service.enable_xhtml", value<bool>()->default_value(true), "")
 
		("service.max_room_list_size", value<int>()->default_value(100), "")
libtransport/NetworkPluginServer.cpp
Show inline comments
 
@@ -297,25 +297,25 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U
 

	
 
	m_component->getFrontend()->onVCardRequired.connect(boost::bind(&NetworkPluginServer::handleVCardRequired, this, _1, _2, _3));
 
	m_component->getFrontend()->onVCardUpdated.connect(boost::bind(&NetworkPluginServer::handleVCardUpdated, this, _1, _2));
 

	
 
	m_component->getFrontend()->onBuddyAdded.connect(boost::bind(&NetworkPluginServer::handleBuddyAdded, this, _1, _2));
 
	m_component->getFrontend()->onBuddyRemoved.connect(boost::bind(&NetworkPluginServer::handleBuddyRemoved, this, _1));
 
	m_component->getFrontend()->onBuddyUpdated.connect(boost::bind(&NetworkPluginServer::handleBuddyUpdated, this, _1, _2));
 

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

	
 
	m_server = component->getNetworkFactories()->getConnectionServerFactory()->createConnectionServer(Swift::HostAddress(CONFIG_STRING(m_config, "service.backend_host")), boost::lexical_cast<int>(CONFIG_STRING(m_config, "service.backend_port")));
 
	m_server = component->getNetworkFactories()->getConnectionServerFactory()->createConnectionServer(SWIFT_HOSTADDRESS(CONFIG_STRING_DEFAULTED(m_config, "service.backend_host", "127.0.0.1")), boost::lexical_cast<int>(CONFIG_STRING(m_config, "service.backend_port")));
 
	m_server->onNewConnection.connect(boost::bind(&NetworkPluginServer::handleNewClientConnection, this, _1));
 
}
 

	
 
NetworkPluginServer::~NetworkPluginServer() {
 
#ifndef _WIN32
 
	signal(SIGCHLD, SIG_IGN);
 
#endif
 

	
 
	for (std::list<Backend *>::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) {
 
		LOG4CXX_INFO(logger, "Stopping backend " << *it);
 
		std::string message;
 
		pbnetwork::WrapperMessage wrap;
spectrum_manager/src/methods.cpp
Show inline comments
 
@@ -582,25 +582,25 @@ void ask_local_server(ManagerConfig *config, Swift::BoostNetworkFactories &netwo
 
				}
 

	
 
				if (CONFIG_STRING(&cfg, "service.jid") != jid) {
 
					continue;
 
				}
 

	
 
				found = true;
 

	
 
				SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Connection> m_conn;
 
				m_conn = networkFactories.getConnectionFactory()->createConnection();
 
				m_conn->onDataRead.connect(boost::bind(&handleDataRead, m_conn, _1));
 
				m_conn->onConnectFinished.connect(boost::bind(&handleConnected, m_conn, message, _1));
 
				m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(CONFIG_STRING(&cfg, "service.backend_host")), getPort(CONFIG_STRING(&cfg, "service.portfile"))));
 
				m_conn->connect(Swift::HostAddressPort(SWIFT_HOSTADDRESS(CONFIG_STRING_DEFAULTED(&cfg, "service.backend_host", "127.0.0.1")), getPort(CONFIG_STRING(&cfg, "service.portfile"))));
 
			}
 
		}
 

	
 
		if (!found) {
 
			response = "Error: Config file for Spectrum instance with this JID was not found\n";
 
		}
 
	}
 
	catch (const filesystem_error& ex) {
 
		response = "Error: Filesystem error: " + std::string(ex.what()) + "\n";
 
	}
 
}
 

	
0 comments (0 inline, 0 general)