diff options
author | Tobias Markmann <tm@ayena.de> | 2018-07-28 11:45:35 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2018-07-30 13:27:15 (GMT) |
commit | 798f8ec3331043a92f6ca3bc810b9477c3f8261e (patch) | |
tree | 868bde2ddcbad1a66d4256edd6050f486860eb2b /Swiften/StreamStack | |
parent | 48596613cfe0f45c0916beabbcc3a27e01752c4b (diff) | |
download | swift-798f8ec3331043a92f6ca3bc810b9477c3f8261e.zip swift-798f8ec3331043a92f6ca3bc810b9477c3f8261e.tar.bz2 |
Use std::unique_ptr to have TLS classes own the TLSContext
TLSLayer and TLSConnection now own the TLSContext they use.
The TLSContextFactory interface is adjusted to use
std::unique_ptr.
Test-Information:
Builds and all tests pass on macOS with clang-7-master.
Change-Id: I14e33c98b48445094f404b73ea41af0a51d2dde6
Diffstat (limited to 'Swiften/StreamStack')
-rw-r--r-- | Swiften/StreamStack/TLSLayer.cpp | 30 | ||||
-rw-r--r-- | Swiften/StreamStack/TLSLayer.h | 8 |
2 files changed, 19 insertions, 19 deletions
diff --git a/Swiften/StreamStack/TLSLayer.cpp b/Swiften/StreamStack/TLSLayer.cpp index ced879e..9f84889 100644 --- a/Swiften/StreamStack/TLSLayer.cpp +++ b/Swiften/StreamStack/TLSLayer.cpp @@ -1,11 +1,13 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/StreamStack/TLSLayer.h> +#include <memory> + #include <boost/bind.hpp> #include <Swiften/TLS/TLSContext.h> @@ -13,44 +15,42 @@ namespace Swift { -TLSLayer::TLSLayer(TLSContextFactory* factory, const TLSOptions& tlsOptions) { - context = factory->createTLSContext(tlsOptions); - context->onDataForNetwork.connect(boost::bind(&TLSLayer::writeDataToChildLayer, this, _1)); - context->onDataForApplication.connect(boost::bind(&TLSLayer::writeDataToParentLayer, this, _1)); - context->onConnected.connect(onConnected); - context->onError.connect(onError); +TLSLayer::TLSLayer(std::unique_ptr<TLSContext> tlsContext) : context_(std::move(tlsContext)) { + context_->onDataForNetwork.connect(boost::bind(&TLSLayer::writeDataToChildLayer, this, _1)); + context_->onDataForApplication.connect(boost::bind(&TLSLayer::writeDataToParentLayer, this, _1)); + context_->onConnected.connect(onConnected); + context_->onError.connect(onError); } TLSLayer::~TLSLayer() { - delete context; } void TLSLayer::connect() { - context->connect(); + context_->connect(); } void TLSLayer::writeData(const SafeByteArray& data) { - context->handleDataFromApplication(data); + context_->handleDataFromApplication(data); } void TLSLayer::handleDataRead(const SafeByteArray& data) { - context->handleDataFromNetwork(data); + context_->handleDataFromNetwork(data); } bool TLSLayer::setClientCertificate(CertificateWithKey::ref certificate) { - return context->setClientCertificate(certificate); + return context_->setClientCertificate(certificate); } Certificate::ref TLSLayer::getPeerCertificate() const { - return context->getPeerCertificate(); + return context_->getPeerCertificate(); } std::vector<Certificate::ref> TLSLayer::getPeerCertificateChain() const { - return context->getPeerCertificateChain(); + return context_->getPeerCertificateChain(); } std::shared_ptr<CertificateVerificationError> TLSLayer::getPeerCertificateVerificationError() const { - return context->getPeerCertificateVerificationError(); + return context_->getPeerCertificateVerificationError(); } } diff --git a/Swiften/StreamStack/TLSLayer.h b/Swiften/StreamStack/TLSLayer.h index 415a3f0..89588e3 100644 --- a/Swiften/StreamStack/TLSLayer.h +++ b/Swiften/StreamStack/TLSLayer.h @@ -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. */ @@ -23,7 +23,7 @@ namespace Swift { class SWIFTEN_API TLSLayer : public StreamLayer { public: - TLSLayer(TLSContextFactory*, const TLSOptions&); + TLSLayer(std::unique_ptr<TLSContext> tlsContext); virtual ~TLSLayer(); void connect(); @@ -37,7 +37,7 @@ namespace Swift { void handleDataRead(const SafeByteArray& data); TLSContext* getContext() const { - return context; + return context_.get(); } public: @@ -45,6 +45,6 @@ namespace Swift { boost::signals2::signal<void ()> onConnected; private: - TLSContext* context; + std::unique_ptr<TLSContext> context_; }; } |