summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2018-07-28 11:45:35 (GMT)
committerTobias Markmann <tm@ayena.de>2018-07-30 13:27:15 (GMT)
commit798f8ec3331043a92f6ca3bc810b9477c3f8261e (patch)
tree868bde2ddcbad1a66d4256edd6050f486860eb2b /Swiften/Network
parent48596613cfe0f45c0916beabbcc3a27e01752c4b (diff)
downloadswift-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/Network')
-rw-r--r--Swiften/Network/BOSHConnection.cpp6
-rw-r--r--Swiften/Network/TLSConnection.cpp5
-rw-r--r--Swiften/Network/TLSConnection.h4
3 files changed, 8 insertions, 7 deletions
diff --git a/Swiften/Network/BOSHConnection.cpp b/Swiften/Network/BOSHConnection.cpp
index b4ffa7d..4bbb121 100644
--- a/Swiften/Network/BOSHConnection.cpp
+++ b/Swiften/Network/BOSHConnection.cpp
@@ -5,7 +5,7 @@
*/
/*
- * Copyright (c) 2011-2017 Isode Limited.
+ * Copyright (c) 2011-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -27,6 +27,7 @@
#include <Swiften/StreamStack/DummyStreamLayer.h>
#include <Swiften/StreamStack/TLSLayer.h>
#include <Swiften/TLS/TLSContext.h>
+#include <Swiften/TLS/TLSContextFactory.h>
#include <Swiften/TLS/TLSOptions.h>
namespace Swift {
@@ -42,7 +43,8 @@ BOSHConnection::BOSHConnection(const URL& boshURL, Connector::ref connector, XML
connectionReady_(false)
{
if (boshURL_.getScheme() == "https") {
- tlsLayer_ = std::make_shared<TLSLayer>(tlsContextFactory, tlsOptions);
+ auto tlsContext = tlsContextFactory->createTLSContext(tlsOptions);
+ tlsLayer_ = std::make_shared<TLSLayer>(std::move(tlsContext));
// The following dummyLayer_ is needed as the TLSLayer will pass the decrypted data to its parent layer.
// The dummyLayer_ will serve as the parent layer.
dummyLayer_ = std::make_shared<DummyStreamLayer>(tlsLayer_.get());
diff --git a/Swiften/Network/TLSConnection.cpp b/Swiften/Network/TLSConnection.cpp
index 7c293d1..82bf114 100644
--- a/Swiften/Network/TLSConnection.cpp
+++ b/Swiften/Network/TLSConnection.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2016 Isode Limited.
+ * Copyright (c) 2011-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -32,7 +32,6 @@ TLSConnection::~TLSConnection() {
connection->onDataRead.disconnect(boost::bind(&TLSConnection::handleRawDataRead, this, _1));
connection->onDataWritten.disconnect(boost::bind(&TLSConnection::handleRawDataWritten, this));
connection->onDisconnected.disconnect(boost::bind(&TLSConnection::handleRawDisconnected, this, _1));
- delete context;
}
void TLSConnection::handleTLSConnectFinished(bool error) {
@@ -71,7 +70,7 @@ HostAddressPort TLSConnection::getRemoteAddress() const {
}
TLSContext* TLSConnection::getTLSContext() const {
- return context;
+ return context.get();
}
void TLSConnection::handleRawConnectFinished(bool error) {
diff --git a/Swiften/Network/TLSConnection.h b/Swiften/Network/TLSConnection.h
index 0c395d1..1ab1ec6 100644
--- a/Swiften/Network/TLSConnection.h
+++ b/Swiften/Network/TLSConnection.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2016 Isode Limited.
+ * Copyright (c) 2011-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -46,7 +46,7 @@ namespace Swift {
void handleTLSDataForApplication(const SafeByteArray& data);
private:
- TLSContext* context;
+ std::unique_ptr<TLSContext> context;
Connection::ref connection;
};
}