summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Session/BasicSessionStream.cpp')
-rw-r--r--Swiften/Session/BasicSessionStream.cpp49
1 files changed, 23 insertions, 26 deletions
diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp
index 10c6ad0..c44961d 100644
--- a/Swiften/Session/BasicSessionStream.cpp
+++ b/Swiften/Session/BasicSessionStream.cpp
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
@@ -36,7 +36,4 @@ BasicSessionStream::BasicSessionStream(
timerFactory(timerFactory),
- compressionLayer(nullptr),
- tlsLayer(nullptr),
- whitespacePingLayer(nullptr),
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));
@@ -49,6 +46,4 @@ BasicSessionStream::BasicSessionStream(
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,15 +52,11 @@ BasicSessionStream::BasicSessionStream(
BasicSessionStream::~BasicSessionStream() {
- delete compressionLayer;
- if (tlsLayer) {
+ if (auto tlsLayer = streamStack->getLayer<TLSLayer>()) {
tlsLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleTLSError, this, _1));
tlsLayer->onConnected.disconnect(boost::bind(&BasicSessionStream::handleTLSConnected, this));
- delete tlsLayer;
}
- delete whitespacePingLayer;
- 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));
@@ -76,3 +67,2 @@ BasicSessionStream::~BasicSessionStream() {
xmppLayer->onWriteData.disconnect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1));
- delete xmppLayer;
}
@@ -81,2 +71,3 @@ void BasicSessionStream::writeHeader(const ProtocolHeader& header) {
assert(available);
+ auto* xmppLayer = streamStack->getLayer<XMPPLayer>();
xmppLayer->writeHeader(header);
@@ -86,2 +77,3 @@ void BasicSessionStream::writeElement(std::shared_ptr<ToplevelElement> element)
assert(available);
+ auto* xmppLayer = streamStack->getLayer<XMPPLayer>();
xmppLayer->writeElement(element);
@@ -91,2 +83,3 @@ void BasicSessionStream::writeFooter() {
assert(available);
+ auto* xmppLayer = streamStack->getLayer<XMPPLayer>();
xmppLayer->writeFooter();
@@ -96,2 +89,3 @@ void BasicSessionStream::writeData(const std::string& data) {
assert(available);
+ auto* xmppLayer = streamStack->getLayer<XMPPLayer>();
xmppLayer->writeData(data);
@@ -113,3 +107,4 @@ void BasicSessionStream::addTLSEncryption() {
assert(available);
- tlsLayer = new TLSLayer(tlsContextFactory, tlsOptions_);
+ auto tlsContext = tlsContextFactory->createTLSContext(tlsOptions_);
+ auto tlsLayer = std::make_unique<TLSLayer>(std::move(tlsContext));
if (hasTLSCertificate() && !tlsLayer->setClientCertificate(getTLSCertificate())) {
@@ -118,3 +113,4 @@ void BasicSessionStream::addTLSEncryption() {
else {
- streamStack->addLayer(tlsLayer);
+ streamStack->addLayer(std::move(tlsLayer));
+ auto tlsLayer = streamStack->getLayer<TLSLayer>();
tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, this, _1));
@@ -126,3 +122,3 @@ void BasicSessionStream::addTLSEncryption() {
bool BasicSessionStream::isTLSEncrypted() {
- return tlsLayer;
+ return streamStack->getLayer<TLSLayer>();
}
@@ -130,3 +126,3 @@ bool BasicSessionStream::isTLSEncrypted() {
Certificate::ref BasicSessionStream::getPeerCertificate() const {
- return tlsLayer->getPeerCertificate();
+ return streamStack->getLayer<TLSLayer>()->getPeerCertificate();
}
@@ -134,3 +130,3 @@ Certificate::ref BasicSessionStream::getPeerCertificate() const {
std::vector<Certificate::ref> BasicSessionStream::getPeerCertificateChain() const {
- return tlsLayer->getPeerCertificateChain();
+ return streamStack->getLayer<TLSLayer>()->getPeerCertificateChain();
}
@@ -138,3 +134,3 @@ std::vector<Certificate::ref> BasicSessionStream::getPeerCertificateChain() cons
std::shared_ptr<CertificateVerificationError> BasicSessionStream::getPeerCertificateVerificationError() const {
- return tlsLayer->getPeerCertificateVerificationError();
+ return streamStack->getLayer<TLSLayer>()->getPeerCertificateVerificationError();
}
@@ -142,3 +138,3 @@ std::shared_ptr<CertificateVerificationError> BasicSessionStream::getPeerCertifi
ByteArray BasicSessionStream::getTLSFinishMessage() const {
- return tlsLayer->getContext()->getFinishMessage();
+ return streamStack->getLayer<TLSLayer>()->getContext()->getFinishMessage();
}
@@ -150,4 +146,3 @@ bool BasicSessionStream::supportsZLibCompression() {
void BasicSessionStream::addZLibCompression() {
- compressionLayer = new CompressionLayer();
- streamStack->addLayer(compressionLayer);
+ streamStack->addLayer(std::make_unique<CompressionLayer>());
}
@@ -155,6 +150,7 @@ void BasicSessionStream::addZLibCompression() {
void BasicSessionStream::setWhitespacePingEnabled(bool enabled) {
+ auto whitespacePingLayer = streamStack->getLayer<WhitespacePingLayer>();
if (enabled) {
if (!whitespacePingLayer) {
- whitespacePingLayer = new WhitespacePingLayer(timerFactory);
- streamStack->addLayer(whitespacePingLayer);
+ streamStack->addLayer(std::make_unique<WhitespacePingLayer>(timerFactory));
+ whitespacePingLayer = streamStack->getLayer<WhitespacePingLayer>();
}
@@ -168,2 +164,3 @@ void BasicSessionStream::setWhitespacePingEnabled(bool enabled) {
void BasicSessionStream::resetXMPPParser() {
+ auto* xmppLayer = streamStack->getLayer<XMPPLayer>();
xmppLayer->resetParser();