void Component::handleServerStopped(boost::optional<Swift::BoostConnectionServer::Error> e) { if(e != NULL ) { if(*e == Swift::BoostConnectionServer::Conflict) { LOG4CXX_INFO(logger, "Port "<< CONFIG_INT(m_config, "service.port") << " already in use! Stopping server.."); if (CONFIG_INT(m_config, "service.port") == 5347) { LOG4CXX_INFO(logger, "Port 5347 is usually used for components. You are using server_mode=1. Are you sure you don't want to use server_mode=0 and run spectrum as component?"); } } if(*e == Swift::BoostConnectionServer::UnknownError) LOG4CXX_INFO(logger, "Unknown error occured! Stopping server.."); exit(1); } }
void DiscoItemsResponder::addRoom(const std::string &node, const std::string &name) { if (m_rooms->getItems().size() > CONFIG_INT(m_component->getConfig(), "service.max_room_list_size")) { return; } m_rooms->addItem(DiscoItems::Item(name, node)); m_discoInfoResponder->addRoom(node, name); }
void Component::handleServerStopped(boost::optional<Swift::BoostConnectionServer::Error> e) { if(e != NULL ) { if(*e == Swift::BoostConnectionServer::Conflict) LOG4CXX_INFO(logger, "Port "<< CONFIG_INT(m_config, "service.port") << " already in use! Stopping server.."); if(*e == Swift::BoostConnectionServer::UnknownError) LOG4CXX_INFO(logger, "Unknown error occured! Stopping server.."); exit(1); } }
void Component::start() { if (m_component && !m_component->isAvailable()) { LOG4CXX_INFO(logger, "Connecting XMPP server " << CONFIG_STRING(m_config, "service.server") << " port " << CONFIG_INT(m_config, "service.port")); m_reconnectCount++; m_component->connect(CONFIG_STRING(m_config, "service.server"), CONFIG_INT(m_config, "service.port")); m_reconnectTimer->stop(); } else if (m_server) { LOG4CXX_INFO(logger, "Starting component in server mode on port " << CONFIG_INT(m_config, "service.port")); m_server->start(); //Type casting to BoostConnectionServer since onStopped signal is not defined in ConnectionServer //Ideally, onStopped must be defined in ConnectionServer boost::dynamic_pointer_cast<Swift::BoostConnectionServer>(m_server->getConnectionServer())->onStopped.connect(boost::bind(&Component::handleServerStopped, this, _1)); // We're connected right here, because we're in server mode... handleConnected(); } }
void XMPPFrontend::disconnectFromServer() { if (m_component) { // TODO: Call this once swiften will fix assert(!session_); // m_component->disconnect(); } else if (m_server) { LOG4CXX_INFO(logger, "Stopping component in server mode on port " << CONFIG_INT(m_config, "service.port")); m_server->stop(); } }
void Component::stop() { if (m_component) { m_reconnectCount = 0; // TODO: Call this once swiften will fix assert(!session_); // m_component->disconnect(); m_reconnectTimer->stop(); } else if (m_server) { LOG4CXX_INFO(logger, "Stopping component in server mode on port " << CONFIG_INT(m_config, "service.port")); m_server->stop(); } }
void XMPPFrontend::connectToServer() { if (m_component && !m_component->isAvailable()) { LOG4CXX_INFO(logger, "Connecting XMPP server " << CONFIG_STRING(m_config, "service.server") << " port " << CONFIG_INT(m_config, "service.port")); if (CONFIG_INT(m_config, "service.port") == 5222) { LOG4CXX_WARN(logger, "Port 5222 is usually used for client connections, not for component connections! Are you sure you are using right port?"); } m_component->connect(CONFIG_STRING(m_config, "service.server"), CONFIG_INT(m_config, "service.port")); } else if (m_server) { LOG4CXX_INFO(logger, "Starting XMPPFrontend in server mode on port " << CONFIG_INT(m_config, "service.port")); m_server->start(); //Type casting to BoostConnectionServer since onStopped signal is not defined in ConnectionServer //Ideally, onStopped must be defined in ConnectionServer if (boost::dynamic_pointer_cast<Swift::BoostConnectionServer>(m_server->getConnectionServer())) { boost::dynamic_pointer_cast<Swift::BoostConnectionServer>(m_server->getConnectionServer())->onStopped.connect(boost::bind(&XMPPFrontend::handleServerStopped, this, _1)); } // We're connected right here, because we're in server mode... handleConnected(); } }
Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories, Config *config, Factory *factory, Transport::UserRegistry *userRegistry) { m_component = NULL; m_userRegistry = NULL; m_server = NULL; m_reconnectCount = 0; m_config = config; m_factory = factory; 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")); 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(); m_server->addTLSEncryption(f, boost::make_shared<PKCS12Certificate>(CONFIG_STRING(m_config, "service.cert"), createSafeByteArray(CONFIG_STRING(m_config, "service.cert_password")))); #endif } else { LOG4CXX_WARN(logger, "No PKCS#12 certificate used. TLS is disabled."); } // m_server->start(); m_stanzaChannel = m_server->getStanzaChannel(); m_iqRouter = m_server->getIQRouter(); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<StorageParser>("private", "jabber:iq:private")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::AttentionParser>("attention", "urn:xmpp:attention:0")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::XHTMLIMParser>("html", "http://jabber.org/protocol/xhtml-im")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::GatewayPayloadParser>("query", "jabber:iq:gateway")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::MUCPayloadParser>("x", "http://jabber.org/protocol/muc")); m_server->addPayloadSerializer(new Swift::AttentionSerializer()); m_server->addPayloadSerializer(new Swift::XHTMLIMSerializer()); m_server->addPayloadSerializer(new Transport::BlockSerializer()); m_server->addPayloadSerializer(new Swift::InvisibleSerializer()); m_server->addPayloadSerializer(new Swift::StatsSerializer()); m_server->addPayloadSerializer(new Swift::SpectrumErrorSerializer()); m_server->addPayloadSerializer(new Swift::GatewayPayloadSerializer()); m_server->onDataRead.connect(boost::bind(&Component::handleDataRead, this, _1)); m_server->onDataWritten.connect(boost::bind(&Component::handleDataWritten, this, _1)); } else { LOG4CXX_INFO(logger, "Creating component in gateway mode"); m_component = new Swift::Component(loop, m_factories, m_jid, CONFIG_STRING(m_config, "service.password")); m_component->setSoftwareVersion("", ""); m_component->onConnected.connect(bind(&Component::handleConnected, this)); m_component->onError.connect(boost::bind(&Component::handleConnectionError, this, _1)); m_component->onDataRead.connect(boost::bind(&Component::handleDataRead, this, _1)); m_component->onDataWritten.connect(boost::bind(&Component::handleDataWritten, this, _1)); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<StorageParser>("private", "jabber:iq:private")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::AttentionParser>("attention", "urn:xmpp:attention:0")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::XHTMLIMParser>("html", "http://jabber.org/protocol/xhtml-im")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::GatewayPayloadParser>("query", "jabber:iq:gateway")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::MUCPayloadParser>("x", "http://jabber.org/protocol/muc")); m_component->addPayloadSerializer(new Swift::AttentionSerializer()); m_component->addPayloadSerializer(new Swift::XHTMLIMSerializer()); m_component->addPayloadSerializer(new Transport::BlockSerializer()); m_component->addPayloadSerializer(new Swift::InvisibleSerializer()); m_component->addPayloadSerializer(new Swift::StatsSerializer()); m_component->addPayloadSerializer(new Swift::SpectrumErrorSerializer()); m_component->addPayloadSerializer(new Swift::GatewayPayloadSerializer()); m_stanzaChannel = m_component->getStanzaChannel(); m_iqRouter = m_component->getIQRouter(); } m_capsMemoryStorage = new CapsMemoryStorage(); m_capsManager = new CapsManager(m_capsMemoryStorage, m_stanzaChannel, m_iqRouter); m_entityCapsManager = new EntityCapsManager(m_capsManager, m_stanzaChannel); m_entityCapsManager->onCapsChanged.connect(boost::bind(&Component::handleCapsChanged, this, _1)); m_presenceOracle = new Transport::PresenceOracle(m_stanzaChannel); m_presenceOracle->onPresenceChange.connect(bind(&Component::handlePresence, this, _1)); m_discoInfoResponder = new DiscoInfoResponder(m_iqRouter, m_config); m_discoInfoResponder->start(); // // m_registerHandler = new SpectrumRegisterHandler(m_component); // m_registerHandler->start(); }
#include "our_config_file.h" #include "player_util.h" // Okay - this is an ugly global... // Basic list of available config variables. Future work could make this // dynamic, but I'm not going to bother right now... static const SConfigVariable MyConfigVariables[] = { CONFIG_STRING(CONFIG_PREV_FILE_0, "File0", NULL), CONFIG_STRING(CONFIG_PREV_FILE_1, "File1", NULL), CONFIG_STRING(CONFIG_PREV_FILE_2, "File2", NULL), CONFIG_STRING(CONFIG_PREV_FILE_3, "File3", NULL), CONFIG_BOOL_HELP(CONFIG_LOOPED, "Looped", false, "Replay video"), CONFIG_INT_HELP(CONFIG_VOLUME, "Volume", 75, "Set Volume (0 - 100)"), CONFIG_BOOL_HELP(CONFIG_MUTED, "AudioMuted", false, "Mute Volume"), CONFIG_INT(CONFIG_HTTP_DEBUG, "HttpDebug", LOG_ALERT), CONFIG_INT(CONFIG_RTSP_DEBUG, "RtspDebug", LOG_ALERT), CONFIG_INT(CONFIG_SDP_DEBUG, "SdpDebug", LOG_ALERT), CONFIG_INT_HELP(CONFIG_IPPORT_MIN, "RtpIpPortMin", UINT32_MAX, "Set minimum IP port to receive on"), CONFIG_INT_HELP(CONFIG_IPPORT_MAX, "RtpIpPortMax", UINT32_MAX, "Set maximum IP port to receive on"), CONFIG_INT(CONFIG_USE_OLD_MP4_LIB, "UseOldMp4Lib", 0), CONFIG_INT_HELP(CONFIG_USE_RTP_OVER_RTSP, "UseRtpOverRtsp", 0, "Use RTP in TCP session (for firewalls)"), CONFIG_INT(CONFIG_SEND_RTCP_IN_RTP_OVER_RTSP, "SendRtcpInRtpOverRtsp", 0), CONFIG_STRING(CONFIG_PREV_DIRECTORY, "PrevDirectory", NULL), CONFIG_INT(CONFIG_RTP_DEBUG, "RtpDebug", LOG_ALERT), CONFIG_INT(CONFIG_PLAY_AUDIO, "PlayAudio", 1), CONFIG_INT(CONFIG_PLAY_VIDEO, "PlayVideo", 1), CONFIG_INT(CONFIG_PLAY_TEXT, "PlayText", 1), CONFIG_INT(CONFIG_RTP_BUFFER_TIME_MSEC, "RtpBufferTimeMsec", 2000), CONFIG_INT_HELP(CONFIG_MPEG2T_PAM_WAIT_SECS, "Mpeg2tPamWaitSecs", 30, "Time to wait for Program Map (seconds)"), CONFIG_INT(CONFIG_LIMIT_AUDIO_SDL_BUFFER, "LimitAudioSdlBuffer", 0),
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(); m_jid = Swift::JID(CONFIG_STRING(m_config, "service.jid")); m_config->onBackendConfigUpdated.connect(boost::bind(&XMPPFrontend::handleBackendConfigChanged, 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, 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 #ifndef __APPLE__ //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 #endif } else { LOG4CXX_WARN(logger, "No PKCS#12 certificate used. TLS is disabled."); } // m_server->start(); m_stanzaChannel = m_server->getStanzaChannel(); m_iqRouter = m_server->getIQRouter(); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<StorageParser>("private", "jabber:iq:private")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::AttentionParser>("attention", "urn:xmpp:attention:0")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::XHTMLIMParser>("html", "http://jabber.org/protocol/xhtml-im")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::GatewayPayloadParser>("query", "jabber:iq:gateway")); m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::MUCPayloadParser>("x", "http://jabber.org/protocol/muc")); m_server->addPayloadSerializer(new Swift::AttentionSerializer()); m_server->addPayloadSerializer(new Swift::XHTMLIMSerializer()); m_server->addPayloadSerializer(new Transport::BlockSerializer()); m_server->addPayloadSerializer(new Swift::InvisibleSerializer()); m_server->addPayloadSerializer(new Swift::StatsSerializer()); m_server->addPayloadSerializer(new Swift::SpectrumErrorSerializer()); m_server->addPayloadSerializer(new Swift::GatewayPayloadSerializer()); m_server->onDataRead.connect(boost::bind(&XMPPFrontend::handleDataRead, this, _1)); m_server->onDataWritten.connect(boost::bind(&XMPPFrontend::handleDataWritten, this, _1)); } else { LOG4CXX_INFO(logger, "Creating component in gateway mode"); #if HAVE_SWIFTEN_3 m_component = new Swift::Component(m_jid, CONFIG_STRING(m_config, "service.password"), factories); #else m_component = new Swift::Component(loop, factories, m_jid, CONFIG_STRING(m_config, "service.password")); #endif m_component->setSoftwareVersion("Spectrum", SPECTRUM_VERSION); m_component->onConnected.connect(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)); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<StorageParser>("private", "jabber:iq:private")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::AttentionParser>("attention", "urn:xmpp:attention:0")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::XHTMLIMParser>("html", "http://jabber.org/protocol/xhtml-im")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Transport::BlockParser>("block", "urn:xmpp:block:0")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::InvisibleParser>("invisible", "urn:xmpp:invisible:0")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::StatsParser>("query", "http://jabber.org/protocol/stats")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::GatewayPayloadParser>("query", "jabber:iq:gateway")); m_component->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::MUCPayloadParser>("x", "http://jabber.org/protocol/muc")); m_component->addPayloadSerializer(new Swift::AttentionSerializer()); m_component->addPayloadSerializer(new Swift::XHTMLIMSerializer()); m_component->addPayloadSerializer(new Transport::BlockSerializer()); m_component->addPayloadSerializer(new Swift::InvisibleSerializer()); m_component->addPayloadSerializer(new Swift::StatsSerializer()); m_component->addPayloadSerializer(new Swift::SpectrumErrorSerializer()); m_component->addPayloadSerializer(new Swift::GatewayPayloadSerializer()); 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 m_entityCapsManager = new EntityCapsManager(m_capsManager, m_stanzaChannel); m_entityCapsManager->onCapsChanged.connect(boost::bind(&XMPPFrontend::handleCapsChanged, this, _1)); m_stanzaChannel->onPresenceReceived.connect(bind(&XMPPFrontend::handleGeneralPresence, this, _1)); m_stanzaChannel->onMessageReceived.connect(bind(&XMPPFrontend::handleMessage, this, _1)); m_discoItemsResponder = new DiscoItemsResponder(transport); m_discoItemsResponder->start(); }
Server::Server(ManagerConfig *config, const std::string &config_file) { srand((unsigned) time(0)); m_config = config; m_user = CONFIG_STRING(m_config, "service.admin_username"); m_password = CONFIG_STRING(m_config, "service.admin_password"); mg_mgr_init(&m_mgr, this); struct mg_bind_opts opts; memset(&opts, 0, sizeof(opts)); const char *error_string; opts.error_string = &error_string; m_nc = mg_bind_opt(&m_mgr, std::string(":" + boost::lexical_cast<std::string>(CONFIG_INT(m_config, "service.port"))).c_str(), &_event_handler, opts); if (!m_nc) { std::cerr << "Error creating server: " << error_string << "\n"; exit(1); } if (!CONFIG_STRING(m_config, "service.cert").empty()) { const char *err_str = mg_set_ssl(m_nc, CONFIG_STRING(m_config, "service.cert").c_str(), NULL); if (err_str) { std::cerr << "Error setting SSL certificate: " << err_str << "\n"; exit(1); } } mg_set_protocol_http_websocket(m_nc); s_http_server_opts.document_root = CONFIG_STRING(m_config, "service.data_dir").c_str(); std::ifstream header(std::string(CONFIG_STRING(m_config, "service.data_dir") + "/header.html").c_str(), std::ios::in); if (header) { header.seekg(0, std::ios::end); m_header.resize(header.tellg()); header.seekg(0, std::ios::beg); header.read(&m_header[0], m_header.size()); header.close(); } std::ifstream footer(std::string(CONFIG_STRING(m_config, "service.data_dir") + "/footer.html").c_str(), std::ios::in); if (footer) { footer.seekg(0, std::ios::end); m_footer.resize(footer.tellg()); footer.seekg(0, std::ios::beg); footer.read(&m_footer[0], m_footer.size()); footer.close(); } m_storageCfg = new Config(); m_storageCfg->load(config_file); Logging::initManagerLogging(m_storageCfg); std::string error; m_storage = StorageBackend::createBackend(m_storageCfg, error); if (m_storage == NULL) { std::cerr << "Error creating StorageBackend! " << error << "\n"; std::cerr << "Registering new Spectrum 2 manager users won't work" << "\n"; } else if (!m_storage->connect()) { delete m_storage; m_storage = NULL; std::cerr << "Can't connect to database!\n"; } m_apiServer = new APIServer(config, m_storage); }