summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2018-08-02 09:00:25 (GMT)
committerTobias Markmann <tm@ayena.de>2018-08-02 09:00:25 (GMT)
commit091f6e520694360a0407ab0cf3bb036fb461e6e3 (patch)
tree717ff863e8cd799842e5c82fc2d833ae026c9b20 /Swiften/Session
parent80f74201f0a35718642e434c58b631b238fd85df (diff)
downloadswift-091f6e520694360a0407ab0cf3bb036fb461e6e3.zip
swift-091f6e520694360a0407ab0cf3bb036fb461e6e3.tar.bz2
Have StreamStack own the top and bottom layer
Test-Information: Builds, unit tests and integration tests pass on macOS with clang 7.0 master. Change-Id: I0db411e49339ccb2301edd1a16612cb1ad2c927c
Diffstat (limited to 'Swiften/Session')
-rw-r--r--Swiften/Session/BasicSessionStream.cpp15
-rw-r--r--Swiften/Session/BasicSessionStream.h4
-rw-r--r--Swiften/Session/Session.cpp28
-rw-r--r--Swiften/Session/Session.h16
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(
tlsContextFactory(tlsContextFactory),
timerFactory(timerFactory),
tlsOptions_(tlsOptions) {
- xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType);
+ auto xmppLayer = std::make_unique<XMPPLayer>(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType);
xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1));
xmppLayer->onStreamEnd.connect(boost::bind(&BasicSessionStream::handleStreamEndReceived, this));
xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1));
@@ -44,10 +44,8 @@ BasicSessionStream::BasicSessionStream(
xmppLayer->onWriteData.connect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1));
connection->onDisconnected.connect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1));
- connectionLayer = new ConnectionLayer(connection);
-
- streamStack = new StreamStack(xmppLayer, connectionLayer);
+ streamStack = std::make_unique<StreamStack>(std::move(xmppLayer), std::unique_ptr<ConnectionLayer>(new ConnectionLayer(connection)));
available = true;
}
@@ -57,37 +55,39 @@ BasicSessionStream::~BasicSessionStream() {
tlsLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleTLSError, this, _1));
tlsLayer->onConnected.disconnect(boost::bind(&BasicSessionStream::handleTLSConnected, this));
}
- delete streamStack;
connection->onDisconnected.disconnect(boost::bind(&BasicSessionStream::handleConnectionFinished, this, _1));
- delete connectionLayer;
+ auto xmppLayer = streamStack->getLayer<XMPPLayer>();
xmppLayer->onStreamStart.disconnect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1));
xmppLayer->onStreamEnd.disconnect(boost::bind(&BasicSessionStream::handleStreamEndReceived, this));
xmppLayer->onElement.disconnect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1));
xmppLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleXMPPError, this));
xmppLayer->onDataRead.disconnect(boost::bind(&BasicSessionStream::handleDataRead, this, _1));
xmppLayer->onWriteData.disconnect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1));
- delete xmppLayer;
}
void BasicSessionStream::writeHeader(const ProtocolHeader& header) {
assert(available);
+ auto* xmppLayer = streamStack->getLayer<XMPPLayer>();
xmppLayer->writeHeader(header);
}
void BasicSessionStream::writeElement(std::shared_ptr<ToplevelElement> element) {
assert(available);
+ auto* xmppLayer = streamStack->getLayer<XMPPLayer>();
xmppLayer->writeElement(element);
}
void BasicSessionStream::writeFooter() {
assert(available);
+ auto* xmppLayer = streamStack->getLayer<XMPPLayer>();
xmppLayer->writeFooter();
}
void BasicSessionStream::writeData(const std::string& data) {
assert(available);
+ auto* xmppLayer = streamStack->getLayer<XMPPLayer>();
xmppLayer->writeData(data);
}
@@ -162,6 +162,7 @@ void BasicSessionStream::setWhitespacePingEnabled(bool enabled) {
}
void BasicSessionStream::resetXMPPParser() {
+ auto* xmppLayer = streamStack->getLayer<XMPPLayer>();
xmppLayer->resetParser();
}
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 {
std::shared_ptr<Connection> connection;
TLSContextFactory* tlsContextFactory;
TimerFactory* timerFactory;
- XMPPLayer* xmppLayer;
- ConnectionLayer* connectionLayer;
- StreamStack* streamStack;
+ std::unique_ptr<StreamStack> streamStack;
TLSOptions tlsOptions_;
};
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 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -22,16 +22,10 @@ Session::Session(
payloadParserFactories(payloadParserFactories),
payloadSerializers(payloadSerializers),
xmlParserFactory(xmlParserFactory),
- xmppLayer(nullptr),
- connectionLayer(nullptr),
- streamStack(nullptr),
finishing(false) {
}
Session::~Session() {
- delete streamStack;
- delete connectionLayer;
- delete xmppLayer;
}
void Session::startSession() {
@@ -44,7 +38,7 @@ void Session::finishSession() {
return;
}
finishing = true;
- if (xmppLayer) {
+ if (auto xmppLayer = getXMPPLayer()) {
xmppLayer->writeFooter();
}
connection->disconnect();
@@ -55,14 +49,14 @@ void Session::finishSession(const SessionError& /*error*/) {
return;
}
finishing = true;
- if (xmppLayer) {
+ if (auto xmppLayer = getXMPPLayer()) {
xmppLayer->writeFooter();
}
connection->disconnect();
}
void Session::initializeStreamStack() {
- xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType);
+ auto xmppLayer = std::unique_ptr<XMPPLayer>(new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType));
xmppLayer->onStreamStart.connect(
boost::bind(&Session::handleStreamStart, this, _1));
xmppLayer->onElement.connect(boost::bind(&Session::handleElement, this, _1));
@@ -72,12 +66,20 @@ void Session::initializeStreamStack() {
xmppLayer->onWriteData.connect(boost::bind(boost::ref(onDataWritten), _1));
connection->onDisconnected.connect(
boost::bind(&Session::handleDisconnected, this, _1));
- connectionLayer = new ConnectionLayer(connection);
- streamStack = new StreamStack(xmppLayer, connectionLayer);
+ streamStack = std::unique_ptr<StreamStack>(new StreamStack(std::move(xmppLayer), std::unique_ptr<ConnectionLayer>(new ConnectionLayer(connection))));
}
+XMPPLayer* Session::getXMPPLayer() const {
+ return dynamic_cast<XMPPLayer*>(streamStack->getTopLayer());
+}
+
+StreamStack* Session::getStreamStack() const {
+ return streamStack.get();
+}
+
+
void Session::sendElement(std::shared_ptr<ToplevelElement> stanza) {
- xmppLayer->writeElement(stanza);
+ getXMPPLayer()->writeElement(stanza);
}
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 @@
/*
- * Copyright (c) 2010-2017 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -85,13 +85,8 @@ namespace Swift {
void initializeStreamStack();
- XMPPLayer* getXMPPLayer() const {
- return xmppLayer;
- }
-
- StreamStack* getStreamStack() const {
- return streamStack;
- }
+ XMPPLayer* getXMPPLayer() const;
+ StreamStack* getStreamStack() const;
void setFinished();
@@ -105,9 +100,8 @@ namespace Swift {
PayloadParserFactoryCollection* payloadParserFactories;
PayloadSerializerCollection* payloadSerializers;
XMLParserFactory* xmlParserFactory;
- XMPPLayer* xmppLayer;
- ConnectionLayer* connectionLayer;
- StreamStack* streamStack;
+
+ std::unique_ptr<StreamStack> streamStack;
bool finishing;
};
}