From df369e65d8f012b5e0356fe185be16d9e437d366 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Wed, 30 Jan 2013 18:59:14 +0100 Subject: [PATCH] libtransport: support service.server also in server-mode --- include/Swiften/Server/Server.cpp | 11 +++++++++-- include/Swiften/Server/Server.h | 3 ++- spectrum/src/sample2.cfg | 2 +- src/tests/userregistry.cpp | 2 +- src/transport.cpp | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/Swiften/Server/Server.cpp b/include/Swiften/Server/Server.cpp index 3cc63428..afd239de 100644 --- a/include/Swiften/Server/Server.cpp +++ b/include/Swiften/Server/Server.cpp @@ -38,6 +38,7 @@ Server::Server( NetworkFactories* networkFactories, UserRegistry *userRegistry, const JID& jid, + const std::string &address, int port) : userRegistry_(userRegistry), port_(port), @@ -45,7 +46,8 @@ Server::Server( networkFactories_(networkFactories), stopping(false), selfJID(jid), - stanzaChannel_(){ + stanzaChannel_(), + address_(address){ stanzaChannel_ = new ServerStanzaChannel(); iqRouter_ = new IQRouter(stanzaChannel_); tlsFactory = NULL; @@ -63,7 +65,12 @@ void Server::start() { if (serverFromClientConnectionServer) { return; } - serverFromClientConnectionServer = networkFactories_->getConnectionServerFactory()->createConnectionServer(port_); + 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))); diff --git a/include/Swiften/Server/Server.h b/include/Swiften/Server/Server.h index f3d70060..b32ae463 100644 --- a/include/Swiften/Server/Server.h +++ b/include/Swiften/Server/Server.h @@ -35,7 +35,7 @@ namespace Swift { 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(); @@ -86,5 +86,6 @@ namespace Swift { TLSServerContextFactory *tlsFactory; CertificateWithKey::ref cert; PlatformXMLParserFactory *parserFactory_; + std::string address_; }; } diff --git a/spectrum/src/sample2.cfg b/spectrum/src/sample2.cfg index 6cad8d9d..5a91d5b8 100644 --- a/spectrum/src/sample2.cfg +++ b/spectrum/src/sample2.cfg @@ -14,7 +14,7 @@ jid = localhost 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. diff --git a/src/tests/userregistry.cpp b/src/tests/userregistry.cpp index 7e567cfd..83fb21a1 100644 --- a/src/tests/userregistry.cpp +++ b/src/tests/userregistry.cpp @@ -36,7 +36,7 @@ class UserRegistryTest : public CPPUNIT_NS :: TestFixture { 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(); diff --git a/src/transport.cpp b/src/transport.cpp index 9c7172be..a98f101a 100644 --- a/src/transport.cpp +++ b/src/transport.cpp @@ -80,7 +80,7 @@ Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories, 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