From f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 21 Nov 2013 22:16:57 +0100 Subject: Boost/C++11 shared pointers. --- src/net/tls/TLSSecuredConnectionInfos.cpp | 4 +-- src/net/tls/gnutls/TLSProperties_GnuTLS.cpp | 10 +++---- src/net/tls/gnutls/TLSSession_GnuTLS.cpp | 12 ++++----- src/net/tls/gnutls/TLSSocket_GnuTLS.cpp | 38 +++++++++++++-------------- src/net/tls/openssl/OpenSSLInitializer.cpp | 4 +-- src/net/tls/openssl/TLSProperties_OpenSSL.cpp | 10 +++---- src/net/tls/openssl/TLSSession_OpenSSL.cpp | 12 ++++----- src/net/tls/openssl/TLSSocket_OpenSSL.cpp | 32 +++++++++++----------- 8 files changed, 61 insertions(+), 61 deletions(-) (limited to 'src/net/tls') diff --git a/src/net/tls/TLSSecuredConnectionInfos.cpp b/src/net/tls/TLSSecuredConnectionInfos.cpp index 5060aede..4856e9af 100644 --- a/src/net/tls/TLSSecuredConnectionInfos.cpp +++ b/src/net/tls/TLSSecuredConnectionInfos.cpp @@ -38,7 +38,7 @@ namespace tls { TLSSecuredConnectionInfos::TLSSecuredConnectionInfos (const string& host, const port_t port, - ref tlsSession, ref tlsSocket) + shared_ptr tlsSession, shared_ptr tlsSocket) : m_host(host), m_port(port), m_tlsSession(tlsSession), m_tlsSocket(tlsSocket) { @@ -57,7 +57,7 @@ port_t TLSSecuredConnectionInfos::getPort() const } -ref TLSSecuredConnectionInfos::getPeerCertificates() const +shared_ptr TLSSecuredConnectionInfos::getPeerCertificates() const { return m_tlsSocket->getPeerCertificates(); } diff --git a/src/net/tls/gnutls/TLSProperties_GnuTLS.cpp b/src/net/tls/gnutls/TLSProperties_GnuTLS.cpp index 2a161dee..36ab7d7a 100644 --- a/src/net/tls/gnutls/TLSProperties_GnuTLS.cpp +++ b/src/net/tls/gnutls/TLSProperties_GnuTLS.cpp @@ -42,7 +42,7 @@ namespace tls { TLSProperties::TLSProperties() - : m_data(vmime::create ()) + : m_data(make_shared ()) { setCipherSuite(CIPHERSUITE_DEFAULT); } @@ -50,9 +50,9 @@ TLSProperties::TLSProperties() TLSProperties::TLSProperties(const TLSProperties& props) : object(), - m_data(vmime::create ()) + m_data(make_shared ()) { - *m_data.dynamicCast () = *props.m_data.dynamicCast (); + *dynamicCast (m_data) = *dynamicCast (props.m_data); } @@ -86,13 +86,13 @@ void TLSProperties::setCipherSuite(const GenericCipherSuite cipherSuite) void TLSProperties::setCipherSuite(const string& cipherSuite) { - m_data.dynamicCast ()->cipherSuite = cipherSuite; + dynamicCast (m_data)->cipherSuite = cipherSuite; } const string TLSProperties::getCipherSuite() const { - return m_data.dynamicCast ()->cipherSuite; + return dynamicCast (m_data)->cipherSuite; } diff --git a/src/net/tls/gnutls/TLSSession_GnuTLS.cpp b/src/net/tls/gnutls/TLSSession_GnuTLS.cpp index 52fedc78..1c520ed1 100644 --- a/src/net/tls/gnutls/TLSSession_GnuTLS.cpp +++ b/src/net/tls/gnutls/TLSSession_GnuTLS.cpp @@ -134,13 +134,13 @@ static TLSGlobal g_gnutlsGlobal; // static -ref TLSSession::create(ref cv, ref props) +shared_ptr TLSSession::create(shared_ptr cv, shared_ptr props) { - return vmime::create (cv, props); + return make_shared (cv, props); } -TLSSession_GnuTLS::TLSSession_GnuTLS(ref cv, ref props) +TLSSession_GnuTLS::TLSSession_GnuTLS(shared_ptr cv, shared_ptr props) : m_certVerifier(cv), m_props(props) { int res; @@ -267,13 +267,13 @@ TLSSession_GnuTLS::~TLSSession_GnuTLS() } -ref TLSSession_GnuTLS::getSocket(ref sok) +shared_ptr TLSSession_GnuTLS::getSocket(shared_ptr sok) { - return TLSSocket::wrap(thisRef().dynamicCast (), sok); + return TLSSocket::wrap(dynamicCast (shared_from_this()), sok); } -ref TLSSession_GnuTLS::getCertificateVerifier() +shared_ptr TLSSession_GnuTLS::getCertificateVerifier() { return m_certVerifier; } diff --git a/src/net/tls/gnutls/TLSSocket_GnuTLS.cpp b/src/net/tls/gnutls/TLSSocket_GnuTLS.cpp index 0a24b720..bb21cb9d 100644 --- a/src/net/tls/gnutls/TLSSocket_GnuTLS.cpp +++ b/src/net/tls/gnutls/TLSSocket_GnuTLS.cpp @@ -44,14 +44,14 @@ namespace tls { // static -ref TLSSocket::wrap(ref session, ref sok) +shared_ptr TLSSocket::wrap(shared_ptr session, shared_ptr sok) { - return vmime::create - (session.dynamicCast (), sok); + return make_shared + (dynamicCast (session), sok); } -TLSSocket_GnuTLS::TLSSocket_GnuTLS(ref session, ref sok) +TLSSocket_GnuTLS::TLSSocket_GnuTLS(shared_ptr session, shared_ptr sok) : m_session(session), m_wrapped(sok), m_connected(false), m_handshaking(false), m_ex(NULL), m_status(0) { @@ -85,7 +85,7 @@ void TLSSocket_GnuTLS::connect(const string& address, const port_t port) { m_wrapped->connect(address, port); - handshake(NULL); + handshake(null); m_connected = true; } @@ -219,7 +219,7 @@ unsigned int TLSSocket_GnuTLS::getStatus() const } -void TLSSocket_GnuTLS::handshake(ref toHandler) +void TLSSocket_GnuTLS::handshake(shared_ptr toHandler) { if (toHandler) toHandler->resetTimeOut(); @@ -260,16 +260,16 @@ void TLSSocket_GnuTLS::handshake(ref toHandler) catch (...) { m_handshaking = false; - m_toHandler = NULL; + m_toHandler = null; throw; } m_handshaking = false; - m_toHandler = NULL; + m_toHandler = null; // Verify server's certificate(s) - ref certs = getPeerCertificates(); + shared_ptr certs = getPeerCertificates(); if (certs == NULL) throw exceptions::tls_exception("No peer certificate."); @@ -364,14 +364,14 @@ ssize_t TLSSocket_GnuTLS::gnutlsPullFunc } -ref TLSSocket_GnuTLS::getPeerCertificates() const +shared_ptr TLSSocket_GnuTLS::getPeerCertificates() const { unsigned int certCount = 0; const gnutls_datum* rawData = gnutls_certificate_get_peers (*m_session->m_gnutlsSession, &certCount); if (rawData == NULL) - return NULL; + return null; // Try X.509 gnutls_x509_crt* x509Certs = new gnutls_x509_crt[certCount]; @@ -387,12 +387,12 @@ ref TLSSocket_GnuTLS::getPeerCertificates() c { // XXX more fine-grained error reporting? delete [] x509Certs; - return NULL; + return null; } } { - std::vector > certs; + std::vector > certs; bool error = false; for (unsigned int i = 0 ; i < certCount ; ++i) @@ -407,7 +407,7 @@ ref TLSSocket_GnuTLS::getPeerCertificates() c gnutls_x509_crt_export(x509Certs[i], GNUTLS_X509_FMT_DER, &data[0], &dataSize); - ref cert = + shared_ptr cert = security::cert::X509Certificate::import(&data[0], dataSize); if (cert != NULL) @@ -421,14 +421,14 @@ ref TLSSocket_GnuTLS::getPeerCertificates() c delete [] x509Certs; if (error) - return NULL; + return null; - return vmime::create (certs); + return make_shared (certs); } delete [] x509Certs; - return NULL; + return null; } @@ -457,7 +457,7 @@ private: void TLSSocket_GnuTLS::internalThrow() { - static std::vector > exToDelete; + static std::vector > exToDelete; if (m_ex) { @@ -467,7 +467,7 @@ void TLSSocket_GnuTLS::internalThrow() m_ex = NULL; // To avoid memory leaks - exToDelete.push_back(vmime::create (ex)); + exToDelete.push_back(make_shared (ex)); throw *ex; } diff --git a/src/net/tls/openssl/OpenSSLInitializer.cpp b/src/net/tls/openssl/OpenSSLInitializer.cpp index 8238b864..1bbb9ee5 100644 --- a/src/net/tls/openssl/OpenSSLInitializer.cpp +++ b/src/net/tls/openssl/OpenSSLInitializer.cpp @@ -49,7 +49,7 @@ namespace net { namespace tls { -ref * OpenSSLInitializer::sm_mutexes; +shared_ptr * OpenSSLInitializer::sm_mutexes; OpenSSLInitializer::autoInitializer::autoInitializer() @@ -93,7 +93,7 @@ void OpenSSLInitializer::initialize() RAND_seed(seed, SEEDSIZE); int numMutexes = CRYPTO_num_locks(); - sm_mutexes = new ref [numMutexes]; + sm_mutexes = new shared_ptr [numMutexes]; for (int i = 0 ; i < numMutexes ; ++i) sm_mutexes[i] = vmime::platform::getHandler()->createCriticalSection(); diff --git a/src/net/tls/openssl/TLSProperties_OpenSSL.cpp b/src/net/tls/openssl/TLSProperties_OpenSSL.cpp index 34e31cf1..932477df 100644 --- a/src/net/tls/openssl/TLSProperties_OpenSSL.cpp +++ b/src/net/tls/openssl/TLSProperties_OpenSSL.cpp @@ -40,7 +40,7 @@ namespace tls { TLSProperties::TLSProperties() - : m_data(vmime::create ()) + : m_data(make_shared ()) { setCipherSuite(CIPHERSUITE_DEFAULT); } @@ -48,9 +48,9 @@ TLSProperties::TLSProperties() TLSProperties::TLSProperties(const TLSProperties& props) : object(), - m_data(vmime::create ()) + m_data(make_shared ()) { - *m_data.dynamicCast () = *props.m_data.dynamicCast (); + *dynamicCast (m_data) = *dynamicCast (props.m_data); } @@ -84,13 +84,13 @@ void TLSProperties::setCipherSuite(const GenericCipherSuite cipherSuite) void TLSProperties::setCipherSuite(const string& cipherSuite) { - m_data.dynamicCast ()->cipherSuite = cipherSuite; + dynamicCast (m_data)->cipherSuite = cipherSuite; } const string TLSProperties::getCipherSuite() const { - return m_data.dynamicCast ()->cipherSuite; + return dynamicCast (m_data)->cipherSuite; } diff --git a/src/net/tls/openssl/TLSSession_OpenSSL.cpp b/src/net/tls/openssl/TLSSession_OpenSSL.cpp index 953e4ebc..cf600a63 100644 --- a/src/net/tls/openssl/TLSSession_OpenSSL.cpp +++ b/src/net/tls/openssl/TLSSession_OpenSSL.cpp @@ -46,13 +46,13 @@ static OpenSSLInitializer::autoInitializer openSSLInitializer; // static -ref TLSSession::create(ref cv, ref props) +shared_ptr TLSSession::create(shared_ptr cv, shared_ptr props) { - return vmime::create (cv, props); + return make_shared (cv, props); } -TLSSession_OpenSSL::TLSSession_OpenSSL(ref cv, ref props) +TLSSession_OpenSSL::TLSSession_OpenSSL(shared_ptr cv, shared_ptr props) : m_sslctx(0), m_certVerifier(cv), m_props(props) { m_sslctx = SSL_CTX_new(SSLv23_client_method()); @@ -76,13 +76,13 @@ TLSSession_OpenSSL::~TLSSession_OpenSSL() } -ref TLSSession_OpenSSL::getSocket(ref sok) +shared_ptr TLSSession_OpenSSL::getSocket(shared_ptr sok) { - return TLSSocket::wrap(thisRef().dynamicCast (), sok); + return TLSSocket::wrap(dynamicCast (shared_from_this()), sok); } -ref TLSSession_OpenSSL::getCertificateVerifier() +shared_ptr TLSSession_OpenSSL::getCertificateVerifier() { return m_certVerifier; } diff --git a/src/net/tls/openssl/TLSSocket_OpenSSL.cpp b/src/net/tls/openssl/TLSSocket_OpenSSL.cpp index 7fda1f15..9aec43e5 100644 --- a/src/net/tls/openssl/TLSSocket_OpenSSL.cpp +++ b/src/net/tls/openssl/TLSSocket_OpenSSL.cpp @@ -65,14 +65,14 @@ BIO_METHOD TLSSocket_OpenSSL::sm_customBIOMethod = // static -ref TLSSocket::wrap(ref session, ref sok) +shared_ptr TLSSocket::wrap(shared_ptr session, shared_ptr sok) { - return vmime::create - (session.dynamicCast (), sok); + return make_shared + (dynamicCast (session), sok); } -TLSSocket_OpenSSL::TLSSocket_OpenSSL(ref session, ref sok) +TLSSocket_OpenSSL::TLSSocket_OpenSSL(shared_ptr session, shared_ptr sok) : m_session(session), m_wrapped(sok), m_connected(false), m_ssl(0), m_ex(NULL) { } @@ -128,7 +128,7 @@ void TLSSocket_OpenSSL::connect(const string& address, const port_t port) createSSLHandle(); - handshake(NULL); + handshake(null); m_connected = true; } @@ -224,7 +224,7 @@ TLSSocket_OpenSSL::size_type TLSSocket_OpenSSL::sendRawNonBlocking(const char* b } -void TLSSocket_OpenSSL::handshake(ref toHandler) +void TLSSocket_OpenSSL::handshake(shared_ptr toHandler) { if (toHandler) toHandler->resetTimeOut(); @@ -245,14 +245,14 @@ void TLSSocket_OpenSSL::handshake(ref toHandler) { SSL_free(m_ssl); m_ssl = 0; - m_toHandler = NULL; + m_toHandler = null; throw; } - m_toHandler = NULL; + m_toHandler = null; // Verify server's certificate(s) - ref certs = getPeerCertificates(); + shared_ptr certs = getPeerCertificates(); if (certs == NULL) throw exceptions::tls_exception("No peer certificate."); @@ -263,24 +263,24 @@ void TLSSocket_OpenSSL::handshake(ref toHandler) } -ref TLSSocket_OpenSSL::getPeerCertificates() const +shared_ptr TLSSocket_OpenSSL::getPeerCertificates() const { STACK_OF(X509)* chain = SSL_get_peer_cert_chain(m_ssl); if (chain == NULL) - return NULL; + return null; int certCount = sk_X509_num(chain); if (certCount == 0) - return NULL; + return null; bool error = false; - std::vector > certs; + std::vector > certs; for (int i = 0; i < certCount && !error; i++) { - ref cert = + shared_ptr cert = vmime::security::cert::X509Certificate_OpenSSL::importInternal(sk_X509_value(chain, i)); if (cert) @@ -290,9 +290,9 @@ ref TLSSocket_OpenSSL::getPeerCertificates() } if (error) - return NULL; + return null; - return vmime::create (certs); + return make_shared (certs); } -- cgit v1.2.3