diff options
Diffstat (limited to 'Swiften/Session/BasicSessionStream.cpp')
-rw-r--r-- | Swiften/Session/BasicSessionStream.cpp | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp index 54cd225..183b986 100644 --- a/Swiften/Session/BasicSessionStream.cpp +++ b/Swiften/Session/BasicSessionStream.cpp @@ -36,5 +36,2 @@ BasicSessionStream::BasicSessionStream( timerFactory(timerFactory), - compressionLayer(nullptr), - tlsLayer(nullptr), - whitespacePingLayer(nullptr), tlsOptions_(tlsOptions) { @@ -57,10 +54,7 @@ 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; @@ -114,3 +108,3 @@ void BasicSessionStream::addTLSEncryption() { auto tlsContext = tlsContextFactory->createTLSContext(tlsOptions_); - tlsLayer = new TLSLayer(std::move(tlsContext)); + auto tlsLayer = std::make_unique<TLSLayer>(std::move(tlsContext)); if (hasTLSCertificate() && !tlsLayer->setClientCertificate(getTLSCertificate())) { @@ -119,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)); @@ -127,3 +122,3 @@ void BasicSessionStream::addTLSEncryption() { bool BasicSessionStream::isTLSEncrypted() { - return tlsLayer; + return streamStack->getLayer<TLSLayer>() != nullptr; } @@ -131,3 +126,3 @@ bool BasicSessionStream::isTLSEncrypted() { Certificate::ref BasicSessionStream::getPeerCertificate() const { - return tlsLayer->getPeerCertificate(); + return streamStack->getLayer<TLSLayer>()->getPeerCertificate(); } @@ -135,3 +130,3 @@ Certificate::ref BasicSessionStream::getPeerCertificate() const { std::vector<Certificate::ref> BasicSessionStream::getPeerCertificateChain() const { - return tlsLayer->getPeerCertificateChain(); + return streamStack->getLayer<TLSLayer>()->getPeerCertificateChain(); } @@ -139,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(); } @@ -143,3 +138,3 @@ std::shared_ptr<CertificateVerificationError> BasicSessionStream::getPeerCertifi ByteArray BasicSessionStream::getTLSFinishMessage() const { - return tlsLayer->getContext()->getFinishMessage(); + return streamStack->getLayer<TLSLayer>()->getContext()->getFinishMessage(); } @@ -151,4 +146,4 @@ bool BasicSessionStream::supportsZLibCompression() { void BasicSessionStream::addZLibCompression() { - compressionLayer = new CompressionLayer(); - streamStack->addLayer(compressionLayer); + auto compressionLayer = std::make_unique<CompressionLayer>(); + streamStack->addLayer(std::move(compressionLayer)); } @@ -156,6 +151,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>(); } |