summaryrefslogtreecommitdiffstats
blob: 38c45deb7a83c943835825a18658c743430ef958 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once

#include <boost/shared_ptr.hpp>
#include <vector>

#include "Swiften/Network/BoostIOServiceThread.h"
#include "Swiften/Server/UserRegistry.h"
#include "Swiften/Base/IDGenerator.h"
#include "Swiften/Server/ServerFromClientSession.h"
#include "Swiften/JID/JID.h"
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h"
#include "Swiften/LinkLocal/LinkLocalServiceInfo.h"

namespace Swift {
	class DNSSDServiceID;
	class String;
	class VCardCollection;
	class LinkLocalConnector;
	class LinkLocalServiceBrowser;
	class LinkLocalPresenceManager;
	class BoostConnectionServer;
	class SessionTracer;
	class RosterPayload;
	class Presence;

	class Server {
		public:
			Server(
					int clientConnectionPort, 
					int linkLocalConnectionPort, 
					LinkLocalServiceBrowser* browser, 
					VCardCollection* vCardCollection);
			~Server();

			boost::signal<void (bool)> onSelfConnected;

		private:
			void handleNewClientConnection(boost::shared_ptr<Connection> c);
			void handleSessionStarted();
			void handleSessionFinished(boost::shared_ptr<ServerFromClientSession>);
			void handleElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<ServerFromClientSession> session);
			void handleRosterChanged(boost::shared_ptr<RosterPayload> roster);
			void handlePresenceChanged(boost::shared_ptr<Presence> presence);
			void handleServiceRegistered(const DNSSDServiceID& service);
			void handleNewLinkLocalConnection(boost::shared_ptr<Connection> connection);
			void handleLinkLocalSessionFinished(boost::shared_ptr<Session> session);
			void handleLinkLocalElementReceived(boost::shared_ptr<Element> element, boost::shared_ptr<Session> session);
			void handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connector, bool error);
			boost::shared_ptr<Session> getLinkLocalSessionForJID(const JID& jid);
			boost::shared_ptr<LinkLocalConnector> getLinkLocalConnectorForJID(const JID& jid);
			void registerLinkLocalSession(boost::shared_ptr<Session> session);
			void unregisterService();
			LinkLocalServiceInfo getLinkLocalServiceInfo(boost::shared_ptr<Presence> presence);

		private:
			class DummyUserRegistry : public UserRegistry {
				public:
					DummyUserRegistry() {}

					virtual bool isValidUserPassword(const JID&, const String&) const {
						return true;
					}
			};

		private:
			IDGenerator idGenerator;
			FullPayloadParserFactoryCollection payloadParserFactories;
			FullPayloadSerializerCollection payloadSerializers;
			BoostIOServiceThread boostIOServiceThread;
			DummyUserRegistry userRegistry;
			bool linkLocalServiceRegistered;
			bool rosterRequested;
			int clientConnectionPort;
			int linkLocalConnectionPort;
			LinkLocalServiceBrowser* linkLocalServiceBrowser;
			VCardCollection* vCardCollection;
			LinkLocalPresenceManager* presenceManager;
			boost::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer;
			boost::shared_ptr<ServerFromClientSession> serverFromClientSession;
			boost::shared_ptr<Presence> lastPresence;
			JID selfJID;
			boost::shared_ptr<BoostConnectionServer> serverFromNetworkConnectionServer;
			std::vector< boost::shared_ptr<Session> > linkLocalSessions;
			std::vector< boost::shared_ptr<LinkLocalConnector> > connectors;
			std::vector< boost::shared_ptr<SessionTracer> > tracers;
	};
}