summaryrefslogtreecommitdiffstats
blob: 733c4289d7af3b7bfa9d96a48ba77ff3d4b357fb (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
#pragma once

#include <boost/shared_ptr.hpp>
#include <boost/signal.hpp>
#include <boost/enable_shared_from_this.hpp>

#include "Swiften/Base/String.h"
#include "Swiften/JID/JID.h"
#include "Swiften/Network/Connection.h"

namespace Swift {
	class ProtocolHeader;
	class Element;
	class Stanza;
	class PayloadParserFactoryCollection;
	class PayloadSerializerCollection;
	class StreamStack;
	class UserRegistry;
	class XMPPLayer;
	class ConnectionLayer;
	class Connection;
	class ByteArray;

	class ServerFromClientSession : public boost::enable_shared_from_this<ServerFromClientSession> {
		public:
			ServerFromClientSession(
					const String& id,
					boost::shared_ptr<Connection> connection, 
					PayloadParserFactoryCollection* payloadParserFactories, 
					PayloadSerializerCollection* payloadSerializers,
					UserRegistry* userRegistry);
			~ServerFromClientSession();

			void start();

			void sendStanza(boost::shared_ptr<Stanza>);

			const JID& getJID() const {
				return jid_;
			}

			const JID& getDomain() const {
				return domain_;
			}

			boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaReceived;
			boost::signal<void ()> onSessionFinished;
			boost::signal<void ()> onSessionStarted;
			boost::signal<void (const ByteArray&)> onDataWritten;
			boost::signal<void (const ByteArray&)> onDataRead;

		private:
			void handleDisconnected(const boost::optional<Connection::Error>& error);
			void handleElement(boost::shared_ptr<Element>);
			void handleStreamStart(const ProtocolHeader& header);

		private:
			String id_;
			boost::shared_ptr<Connection> connection_;
			PayloadParserFactoryCollection* payloadParserFactories_;
			PayloadSerializerCollection* payloadSerializers_;
			UserRegistry* userRegistry_;
			bool authenticated_;
			bool initialized_;
			boost::shared_ptr<XMPPLayer> xmppLayer_;
			boost::shared_ptr<ConnectionLayer> connectionLayer_;
			StreamStack* streamStack_;
			JID domain_;
			String user_;
			JID jid_;
	};
}