diff options
Diffstat (limited to 'Swiften/Session')
| -rw-r--r-- | Swiften/Session/BasicSessionStream.cpp | 15 | ||||
| -rw-r--r-- | Swiften/Session/BasicSessionStream.h | 4 | ||||
| -rw-r--r-- | Swiften/Session/Session.cpp | 28 | ||||
| -rw-r--r-- | Swiften/Session/Session.h | 16 |
4 files changed, 29 insertions, 34 deletions
diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp index 3e65640..c44961d 100644 --- a/Swiften/Session/BasicSessionStream.cpp +++ b/Swiften/Session/BasicSessionStream.cpp | |||
| @@ -35,7 +35,7 @@ BasicSessionStream::BasicSessionStream( | |||
| 35 | tlsContextFactory(tlsContextFactory), | 35 | tlsContextFactory(tlsContextFactory), |
| 36 | timerFactory(timerFactory), | 36 | timerFactory(timerFactory), |
| 37 | tlsOptions_(tlsOptions) { | 37 | tlsOptions_(tlsOptions) { |
| 38 | xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType); | 38 | auto xmppLayer = std::make_unique<XMPPLayer>(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType); |
| 39 | xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1)); | 39 | xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1)); |
| 40 | xmppLayer->onStreamEnd.connect(boost::bind(&BasicSessionStream::handleStreamEndReceived, this)); | 40 | xmppLayer->onStreamEnd.connect(boost::bind(&BasicSessionStream::handleStreamEndReceived, this)); |
| 41 | xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1)); | 41 | xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1)); |
| @@ -44,10 +44,8 @@ BasicSessionStream::BasicSessionStream( | |||
| 44 | xmppLayer->onWriteData.connect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1)); | 44 | xmppLayer->onWriteData.connect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1)); |
| 45 | 45 | ||
| 46 | connection->onDisconnected.connect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1)); | 46 | connection->onDisconnected.connect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1)); |
| 47 | connectionLayer = new ConnectionLayer(connection); | ||
| 48 | |||
| 49 | streamStack = new StreamStack(xmppLayer, connectionLayer); | ||
| 50 | 47 | ||
| 48 | streamStack = std::make_unique<StreamStack>(std::move(xmppLayer), std::unique_ptr<ConnectionLayer>(new ConnectionLayer(connection))); | ||
| 51 | available = true; | 49 | available = true; |
| 52 | } | 50 | } |
| 53 | 51 | ||
| @@ -57,37 +55,39 @@ BasicSessionStream::~BasicSessionStream() { | |||
| 57 | tlsLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleTLSError, this, _1)); | 55 | tlsLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleTLSError, this, _1)); |
| 58 | tlsLayer->onConnected.disconnect(boost::bind(&BasicSessionStream::handleTLSConnected, this)); | 56 | tlsLayer->onConnected.disconnect(boost::bind(&BasicSessionStream::handleTLSConnected, this)); |
| 59 | } | 57 | } |
| 60 | delete streamStack; | ||
| 61 | 58 | ||
| 62 | connection->onDisconnected.disconnect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1)); | 59 | connection->onDisconnected.disconnect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1)); |
| 63 | delete connectionLayer; | ||
| 64 | 60 | ||
| 61 | auto xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 65 | xmppLayer->onStreamStart.disconnect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1)); | 62 | xmppLayer->onStreamStart.disconnect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1)); |
| 66 | xmppLayer->onStreamEnd.disconnect(boost::bind(&BasicSessionStream::handleStreamEndReceived, this)); | 63 | xmppLayer->onStreamEnd.disconnect(boost::bind(&BasicSessionStream::handleStreamEndReceived, this)); |
| 67 | xmppLayer->onElement.disconnect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1)); | 64 | xmppLayer->onElement.disconnect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1)); |
| 68 | xmppLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleXMPPError, this)); | 65 | xmppLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleXMPPError, this)); |
| 69 | xmppLayer->onDataRead.disconnect(boost::bind(&BasicSessionStream::handleDataRead, this, _1)); | 66 | xmppLayer->onDataRead.disconnect(boost::bind(&BasicSessionStream::handleDataRead, this, _1)); |
| 70 | xmppLayer->onWriteData.disconnect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1)); | 67 | xmppLayer->onWriteData.disconnect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1)); |
| 71 | delete xmppLayer; | ||
| 72 | } | 68 | } |
| 73 | 69 | ||
| 74 | void BasicSessionStream::writeHeader(const ProtocolHeader& header) { | 70 | void BasicSessionStream::writeHeader(const ProtocolHeader& header) { |
| 75 | assert(available); | 71 | assert(available); |
| 72 | auto* xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 76 | xmppLayer->writeHeader(header); | 73 | xmppLayer->writeHeader(header); |
| 77 | } | 74 | } |
| 78 | 75 | ||
| 79 | void BasicSessionStream::writeElement(std::shared_ptr<ToplevelElement> element) { | 76 | void BasicSessionStream::writeElement(std::shared_ptr<ToplevelElement> element) { |
| 80 | assert(available); | 77 | assert(available); |
| 78 | auto* xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 81 | xmppLayer->writeElement(element); | 79 | xmppLayer->writeElement(element); |
| 82 | } | 80 | } |
| 83 | 81 | ||
| 84 | void BasicSessionStream::writeFooter() { | 82 | void BasicSessionStream::writeFooter() { |
| 85 | assert(available); | 83 | assert(available); |
| 84 | auto* xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 86 | xmppLayer->writeFooter(); | 85 | xmppLayer->writeFooter(); |
| 87 | } | 86 | } |
| 88 | 87 | ||
| 89 | void BasicSessionStream::writeData(const std::string& data) { | 88 | void BasicSessionStream::writeData(const std::string& data) { |
| 90 | assert(available); | 89 | assert(available); |
| 90 | auto* xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 91 | xmppLayer->writeData(data); | 91 | xmppLayer->writeData(data); |
| 92 | } | 92 | } |
| 93 | 93 | ||
| @@ -162,6 +162,7 @@ void BasicSessionStream::setWhitespacePingEnabled(bool enabled) { | |||
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | void BasicSessionStream::resetXMPPParser() { | 164 | void BasicSessionStream::resetXMPPParser() { |
| 165 | auto* xmppLayer = streamStack->getLayer<XMPPLayer>(); | ||
| 165 | xmppLayer->resetParser(); | 166 | xmppLayer->resetParser(); |
| 166 | } | 167 | } |
| 167 | 168 | ||
diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h index 472b5cc..30a7e3b 100644 --- a/Swiften/Session/BasicSessionStream.h +++ b/Swiften/Session/BasicSessionStream.h | |||
| @@ -83,9 +83,7 @@ namespace Swift { | |||
| 83 | std::shared_ptr<Connection> connection; | 83 | std::shared_ptr<Connection> connection; |
| 84 | TLSContextFactory* tlsContextFactory; | 84 | TLSContextFactory* tlsContextFactory; |
| 85 | TimerFactory* timerFactory; | 85 | TimerFactory* timerFactory; |
| 86 | XMPPLayer* xmppLayer; | 86 | std::unique_ptr<StreamStack> streamStack; |
| 87 | ConnectionLayer* connectionLayer; | ||
| 88 | StreamStack* streamStack; | ||
| 89 | TLSOptions tlsOptions_; | 87 | TLSOptions tlsOptions_; |
| 90 | }; | 88 | }; |
| 91 | 89 | ||
diff --git a/Swiften/Session/Session.cpp b/Swiften/Session/Session.cpp index ebdb5d1..b1525b8 100644 --- a/Swiften/Session/Session.cpp +++ b/Swiften/Session/Session.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -22,16 +22,10 @@ Session::Session( | |||
| 22 | payloadParserFactories(payloadParserFactories), | 22 | payloadParserFactories(payloadParserFactories), |
| 23 | payloadSerializers(payloadSerializers), | 23 | payloadSerializers(payloadSerializers), |
| 24 | xmlParserFactory(xmlParserFactory), | 24 | xmlParserFactory(xmlParserFactory), |
| 25 | xmppLayer(nullptr), | ||
| 26 | connectionLayer(nullptr), | ||
| 27 | streamStack(nullptr), | ||
| 28 | finishing(false) { | 25 | finishing(false) { |
| 29 | } | 26 | } |
| 30 | 27 | ||
| 31 | Session::~Session() { | 28 | Session::~Session() { |
| 32 | delete streamStack; | ||
| 33 | delete connectionLayer; | ||
| 34 | delete xmppLayer; | ||
| 35 | } | 29 | } |
| 36 | 30 | ||
| 37 | void Session::startSession() { | 31 | void Session::startSession() { |
| @@ -44,7 +38,7 @@ void Session::finishSession() { | |||
| 44 | return; | 38 | return; |
| 45 | } | 39 | } |
| 46 | finishing = true; | 40 | finishing = true; |
| 47 | if (xmppLayer) { | 41 | if (auto xmppLayer = getXMPPLayer()) { |
| 48 | xmppLayer->writeFooter(); | 42 | xmppLayer->writeFooter(); |
| 49 | } | 43 | } |
| 50 | connection->disconnect(); | 44 | connection->disconnect(); |
| @@ -55,14 +49,14 @@ void Session::finishSession(const SessionError& /*error*/) { | |||
| 55 | return; | 49 | return; |
| 56 | } | 50 | } |
| 57 | finishing = true; | 51 | finishing = true; |
| 58 | if (xmppLayer) { | 52 | if (auto xmppLayer = getXMPPLayer()) { |
| 59 | xmppLayer->writeFooter(); | 53 | xmppLayer->writeFooter(); |
| 60 | } | 54 | } |
| 61 | connection->disconnect(); | 55 | connection->disconnect(); |
| 62 | } | 56 | } |
| 63 | 57 | ||
| 64 | void Session::initializeStreamStack() { | 58 | void Session::initializeStreamStack() { |
| 65 | xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType); | 59 | auto xmppLayer = std::unique_ptr<XMPPLayer>(new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType)); |
| 66 | xmppLayer->onStreamStart.connect( | 60 | xmppLayer->onStreamStart.connect( |
| 67 | boost::bind(&Session::handleStreamStart, this, _1)); | 61 | boost::bind(&Session::handleStreamStart, this, _1)); |
| 68 | xmppLayer->onElement.connect(boost::bind(&Session::handleElement, this, _1)); | 62 | xmppLayer->onElement.connect(boost::bind(&Session::handleElement, this, _1)); |
| @@ -72,12 +66,20 @@ void Session::initializeStreamStack() { | |||
| 72 | xmppLayer->onWriteData.connect(boost::bind(boost::ref(onDataWritten), _1)); | 66 | xmppLayer->onWriteData.connect(boost::bind(boost::ref(onDataWritten), _1)); |
| 73 | connection->onDisconnected.connect( | 67 | connection->onDisconnected.connect( |
| 74 | boost::bind(&Session::handleDisconnected, this, _1)); | 68 | boost::bind(&Session::handleDisconnected, this, _1)); |
| 75 | connectionLayer = new ConnectionLayer(connection); | 69 | streamStack = std::unique_ptr<StreamStack>(new StreamStack(std::move(xmppLayer), std::unique_ptr<ConnectionLayer>(new ConnectionLayer(connection)))); |
| 76 | streamStack = new StreamStack(xmppLayer, connectionLayer); | ||
| 77 | } | 70 | } |
| 78 | 71 | ||
| 72 | XMPPLayer* Session::getXMPPLayer() const { | ||
| 73 | return dynamic_cast<XMPPLayer*>(streamStack->getTopLayer()); | ||
| 74 | } | ||
| 75 | |||
| 76 | StreamStack* Session::getStreamStack() const { | ||
| 77 | return streamStack.get(); | ||
| 78 | } | ||
| 79 | |||
| 80 | |||
| 79 | void Session::sendElement(std::shared_ptr<ToplevelElement> stanza) { | 81 | void Session::sendElement(std::shared_ptr<ToplevelElement> stanza) { |
| 80 | xmppLayer->writeElement(stanza); | 82 | getXMPPLayer()->writeElement(stanza); |
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | void Session::handleDisconnected(const boost::optional<Connection::Error>& connectionError) { | 85 | void Session::handleDisconnected(const boost::optional<Connection::Error>& connectionError) { |
diff --git a/Swiften/Session/Session.h b/Swiften/Session/Session.h index 04153ec..e6a0d53 100644 --- a/Swiften/Session/Session.h +++ b/Swiften/Session/Session.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2017 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -85,13 +85,8 @@ namespace Swift { | |||
| 85 | 85 | ||
| 86 | void initializeStreamStack(); | 86 | void initializeStreamStack(); |
| 87 | 87 | ||
| 88 | XMPPLayer* getXMPPLayer() const { | 88 | XMPPLayer* getXMPPLayer() const; |
| 89 | return xmppLayer; | 89 | StreamStack* getStreamStack() const; |
| 90 | } | ||
| 91 | |||
| 92 | StreamStack* getStreamStack() const { | ||
| 93 | return streamStack; | ||
| 94 | } | ||
| 95 | 90 | ||
| 96 | void setFinished(); | 91 | void setFinished(); |
| 97 | 92 | ||
| @@ -105,9 +100,8 @@ namespace Swift { | |||
| 105 | PayloadParserFactoryCollection* payloadParserFactories; | 100 | PayloadParserFactoryCollection* payloadParserFactories; |
| 106 | PayloadSerializerCollection* payloadSerializers; | 101 | PayloadSerializerCollection* payloadSerializers; |
| 107 | XMLParserFactory* xmlParserFactory; | 102 | XMLParserFactory* xmlParserFactory; |
| 108 | XMPPLayer* xmppLayer; | 103 | |
| 109 | ConnectionLayer* connectionLayer; | 104 | std::unique_ptr<StreamStack> streamStack; |
| 110 | StreamStack* streamStack; | ||
| 111 | bool finishing; | 105 | bool finishing; |
| 112 | }; | 106 | }; |
| 113 | } | 107 | } |
Swift