Changeset - df369e65d8f0
[Not reviewed]
0 5 0
HanzZ - 12 years ago 2013-01-30 18:59:14
hanzz.k@gmail.com
libtransport: support service.server also in server-mode
5 files changed with 13 insertions and 5 deletions:
0 comments (0 inline, 0 general)
include/Swiften/Server/Server.cpp
Show inline comments
 
@@ -29,50 +29,57 @@
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Queries/IQRouter.h"
 
#include <iostream>
 

	
 

	
 
namespace Swift {
 

	
 
Server::Server(
 
		EventLoop* eventLoop,
 
		NetworkFactories* networkFactories,
 
		UserRegistry *userRegistry,
 
		const JID& jid,
 
		const std::string &address,
 
		int port) :
 
			userRegistry_(userRegistry),
 
			port_(port),
 
			eventLoop(eventLoop),
 
			networkFactories_(networkFactories),
 
			stopping(false),
 
			selfJID(jid),
 
			stanzaChannel_(){
 
			stanzaChannel_(),
 
			address_(address){
 
	stanzaChannel_ = new ServerStanzaChannel();
 
	iqRouter_ = new IQRouter(stanzaChannel_);
 
	tlsFactory = NULL;
 
	parserFactory_ = new PlatformXMLParserFactory();
 
}
 

	
 
Server::~Server() {
 
	stop();
 
	delete iqRouter_;
 
	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_);
 
	}
 
	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() {
 
	if (stopping) {
include/Swiften/Server/Server.h
Show inline comments
 
@@ -26,25 +26,25 @@
 

	
 
namespace Swift {
 
	class ConnectionServer;
 
	class SessionTracer;
 
	class EventLoop;
 
	class NetworkFactories;
 
	class StanzaChannel;
 
	class IQRouter;
 
	class TLSServerContextFactory;
 

	
 
	class Server : public Entity {
 
		public:
 
			Server(EventLoop* eventLoop, NetworkFactories* networkFactories, UserRegistry *userRegistry, const JID& jid, int port);
 
			Server(EventLoop* eventLoop, NetworkFactories* networkFactories, UserRegistry *userRegistry, const JID& jid, const std::string &address, int port);
 
			~Server();
 

	
 
			void start();
 
			void stop();
 

	
 
			int getPort() const {
 
				return port_;
 
			}
 

	
 
			StanzaChannel* getStanzaChannel() const {
 
				return stanzaChannel_;
 
			}
 
@@ -77,14 +77,15 @@ namespace Swift {
 
			EventLoop* eventLoop;
 
			NetworkFactories* networkFactories_;
 
			bool stopping;
 
			boost::shared_ptr<ConnectionServer> serverFromClientConnectionServer;
 
			std::vector<boost::bsignals::connection> serverFromClientConnectionServerSignalConnections;
 
			std::list<boost::shared_ptr<ServerFromClientSession> > serverFromClientSessions;
 
			JID selfJID;
 
			StanzaChannel *stanzaChannel_;
 
			IQRouter *iqRouter_;
 
			TLSServerContextFactory *tlsFactory;
 
			CertificateWithKey::ref cert;
 
			PlatformXMLParserFactory *parserFactory_;
 
			std::string address_;
 
	};
 
}
spectrum/src/sample2.cfg
Show inline comments
 
@@ -5,25 +5,25 @@ server_mode = 1
 
# The name of user/group Spectrum runs as.
 
#user=spectrum
 
#group=spectrum
 

	
 
# JID of Spectrum instance.
 
jid = localhost
 

	
 
# Password used to connect the XMPP server in gateway mode.
 
# In server mode, this option is ignored.
 
password = secret
 

	
 
# XMPP server to which Spectrum connects in gateway mode.
 
# In server mode, this option is ignored.
 
# To bind to all ipv4 interfaces, use server=0.0.0.0
 
server = 127.0.0.1
 

	
 
# XMPP server port.
 
port = 5222
 

	
 
# Interface on which Spectrum listens for backends.
 
backend_host = localhost
 

	
 
# Port on which Spectrum listens for backends.
 
# By default Spectrum chooses random backend port and there's
 
# no need to change it normally
 
#backend_port=10001
src/tests/userregistry.cpp
Show inline comments
 
@@ -27,25 +27,25 @@ class UserRegistryTest : public CPPUNIT_NS :: TestFixture {
 
			state2 = Init;
 
			std::istringstream ifs;
 
			cfg = new Config();
 
			cfg->load(ifs);
 

	
 
			loop = new Swift::DummyEventLoop();
 
			factories = new Swift::DummyNetworkFactories(loop);
 

	
 
			userRegistry = new UserRegistry(cfg, factories);
 
			userRegistry->onConnectUser.connect(bind(&UserRegistryTest::handleConnectUser, this, _1));
 
			userRegistry->onDisconnectUser.connect(bind(&UserRegistryTest::handleDisconnectUser, this, _1));
 

	
 
			server = new Swift::Server(loop, factories, userRegistry, "localhost", 5222);
 
			server = new Swift::Server(loop, factories, userRegistry, "localhost", "0.0.0.0", 5222);
 
			server->start();
 
			connectionServer = server->getConnectionServer();
 

	
 
			client1 = factories->getConnectionFactory()->createConnection();
 
			dynamic_cast<Swift::DummyConnectionServer *>(connectionServer.get())->acceptConnection(client1);
 

	
 
			dynamic_cast<Swift::DummyConnection *>(client1.get())->onDataSent.connect(boost::bind(&UserRegistryTest::handleDataReceived, this, _1, client1));
 

	
 
			client2 = factories->getConnectionFactory()->createConnection();
 
			dynamic_cast<Swift::DummyConnectionServer *>(connectionServer.get())->acceptConnection(client2);
 

	
 
			dynamic_cast<Swift::DummyConnection *>(client2.get())->onDataSent.connect(boost::bind(&UserRegistryTest::handleDataReceived, this, _1, client2));
src/transport.cpp
Show inline comments
 
@@ -71,25 +71,25 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories,
 
	m_loop = loop;
 
	m_userRegistry = userRegistry;
 

	
 
	m_jid = Swift::JID(CONFIG_STRING(m_config, "service.jid"));
 

	
 
	m_factories = factories;
 

	
 
	m_reconnectTimer = m_factories->getTimerFactory()->createTimer(3000);
 
	m_reconnectTimer->onTick.connect(bind(&Component::start, this)); 
 

	
 
	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, m_factories, m_userRegistry, m_jid, CONFIG_INT(m_config, "service.port"));
 
		m_server = new Swift::Server(loop, m_factories, m_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
 
//TODO: fix
 
			LOG4CXX_INFO(logger, "Using PKCS#12 certificate " << CONFIG_STRING(m_config, "service.cert"));
 
			LOG4CXX_INFO(logger, "SSLv23_server_method used.");
 
			TLSServerContextFactory *f = new OpenSSLServerContextFactory();
 
			CertificateWithKey::ref certificate = boost::make_shared<PKCS12Certificate>(CONFIG_STRING(m_config, "service.cert"), createSafeByteArray(CONFIG_STRING(m_config, "service.cert_password")));
 
			m_server->addTLSEncryption(f, certificate);
 
#endif
 
			
 
		}
 
		else {
0 comments (0 inline, 0 general)