/* * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Swift { class DNSSDServiceID; class VCardCollection; class LinkLocalConnector; class LinkLocalServiceBrowser; class LinkLocalPresenceManager; class BoostConnectionServer; class SessionTracer; class RosterPayload; class Presence; class EventLoop; class Server { public: Server( unsigned short clientConnectionPort, unsigned short linkLocalConnectionPort, LinkLocalServiceBrowser* browser, VCardCollection* vCardCollection, EventLoop* eventLoop); ~Server(); void start(); void stop(); unsigned short getLinkLocalPort() const { return linkLocalConnectionPort; } unsigned short getClientToServerPort() const { return clientConnectionPort; } boost::signals2::signal onSelfConnected; boost::signals2::signal)> onStopped; private: void stop(boost::optional); void handleNewClientConnection(std::shared_ptr c); void handleSessionStarted(); void handleSessionFinished(std::shared_ptr); void handleElementReceived(std::shared_ptr element, std::shared_ptr session); void handleRosterChanged(std::shared_ptr roster); void handlePresenceChanged(std::shared_ptr presence); void handleServiceRegistered(const DNSSDServiceID& service); void handleNewLinkLocalConnection(std::shared_ptr connection); void handleLinkLocalSessionFinished(std::shared_ptr session); void handleLinkLocalElementReceived(std::shared_ptr element, std::shared_ptr session); void handleConnectFinished(std::shared_ptr connector, bool error); void handleClientConnectionServerStopped( boost::optional); void handleLinkLocalConnectionServerStopped( boost::optional); std::shared_ptr getLinkLocalSessionForJID(const JID& jid); std::shared_ptr getLinkLocalConnectorForJID(const JID& jid); void registerLinkLocalSession(std::shared_ptr session); void unregisterService(); LinkLocalServiceInfo getLinkLocalServiceInfo(std::shared_ptr presence); private: class DummyUserRegistry : public UserRegistry { public: DummyUserRegistry() {} virtual bool isValidUserPassword(const JID&, const SafeByteArray&) const { return true; } }; private: IDGenerator idGenerator; FullPayloadParserFactoryCollection payloadParserFactories; FullPayloadSerializerCollection payloadSerializers; BoostIOServiceThread boostIOServiceThread; DummyUserRegistry userRegistry; PlatformXMLParserFactory xmlParserFactory; bool linkLocalServiceRegistered; bool rosterRequested; unsigned short clientConnectionPort; unsigned short linkLocalConnectionPort; LinkLocalServiceBrowser* linkLocalServiceBrowser; VCardCollection* vCardCollection; EventLoop* eventLoop; LinkLocalPresenceManager* presenceManager; bool stopping; std::shared_ptr serverFromClientConnectionServer; std::vector serverFromClientConnectionServerSignalConnections; std::shared_ptr serverFromClientSession; std::shared_ptr lastPresence; JID selfJID; std::shared_ptr serverFromNetworkConnectionServer; std::vector serverFromNetworkConnectionServerSignalConnections; std::vector< std::shared_ptr > linkLocalSessions; std::vector< std::shared_ptr > connectors; std::vector< std::shared_ptr > tracers; }; }