summaryrefslogtreecommitdiffstats
blob: 0cb50eb3097362f35e255271497bca9820ffadc9 (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
#pragma once

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

#include "Swiften/Network/Connection.h"
#include "Swiften/Session/SessionStream.h"

namespace Swift {
  class TLSLayerFactory;
  class TLSLayer;
  class WhitespacePingLayer;
	class PayloadParserFactoryCollection;
	class PayloadSerializerCollection;
  class StreamStack;
	class XMPPLayer;
  class ConnectionLayer;

  class BasicSessionStream : 
      public SessionStream, 
      public boost::enable_shared_from_this<BasicSessionStream> {
    public:
      BasicSessionStream(
		    boost::shared_ptr<Connection> connection,
        PayloadParserFactoryCollection* payloadParserFactories, 
        PayloadSerializerCollection* payloadSerializers,
		    TLSLayerFactory* tlsLayerFactory
      );
      ~BasicSessionStream();

			void initialize();

			virtual bool isAvailable();

			virtual void writeHeader(const ProtocolHeader& header);
			virtual void writeElement(boost::shared_ptr<Element>);
			virtual void writeFooter();

			virtual bool supportsTLSEncryption();
			virtual void addTLSEncryption();

			virtual void setWhitespacePingEnabled(bool);

			virtual void resetXMPPParser();

    private:
			void handleConnectionError(const boost::optional<Connection::Error>& error);
      void handleXMPPError();
			void handleTLSConnected();
      void handleTLSError();
			void handleStreamStartReceived(const ProtocolHeader&);
			void handleElementReceived(boost::shared_ptr<Element>);
      void handleDataRead(const ByteArray& data);
      void handleDataWritten(const ByteArray& data);

    private:
			bool available;
			boost::shared_ptr<Connection> connection;
			PayloadParserFactoryCollection* payloadParserFactories;
			PayloadSerializerCollection* payloadSerializers;
			TLSLayerFactory* tlsLayerFactory;
			boost::shared_ptr<XMPPLayer> xmppLayer;
			boost::shared_ptr<ConnectionLayer> connectionLayer;
			StreamStack* streamStack;
      boost::shared_ptr<TLSLayer> tlsLayer;
      boost::shared_ptr<WhitespacePingLayer> whitespacePingLayer;
  };
}