diff options
author | Vincent Richard <[email protected]> | 2013-11-21 21:16:57 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2013-11-21 21:16:57 +0000 |
commit | f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8 (patch) | |
tree | 2bdc90e361a8f6e0a81164cf67afec9f78f9b959 /src/net/tls | |
parent | Per-protocol include files. (diff) | |
download | vmime-f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8.tar.gz vmime-f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8.zip |
Boost/C++11 shared pointers.
Diffstat (limited to 'src/net/tls')
-rw-r--r-- | src/net/tls/TLSSecuredConnectionInfos.cpp | 4 | ||||
-rw-r--r-- | src/net/tls/gnutls/TLSProperties_GnuTLS.cpp | 10 | ||||
-rw-r--r-- | src/net/tls/gnutls/TLSSession_GnuTLS.cpp | 12 | ||||
-rw-r--r-- | src/net/tls/gnutls/TLSSocket_GnuTLS.cpp | 38 | ||||
-rw-r--r-- | src/net/tls/openssl/OpenSSLInitializer.cpp | 4 | ||||
-rw-r--r-- | src/net/tls/openssl/TLSProperties_OpenSSL.cpp | 10 | ||||
-rw-r--r-- | src/net/tls/openssl/TLSSession_OpenSSL.cpp | 12 | ||||
-rw-r--r-- | src/net/tls/openssl/TLSSocket_OpenSSL.cpp | 32 |
8 files changed, 61 insertions, 61 deletions
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> tlsSession, ref <TLSSocket> tlsSocket) + shared_ptr <TLSSession> tlsSession, shared_ptr <TLSSocket> tlsSocket) : m_host(host), m_port(port), m_tlsSession(tlsSession), m_tlsSocket(tlsSocket) { @@ -57,7 +57,7 @@ port_t TLSSecuredConnectionInfos::getPort() const } -ref <const security::cert::certificateChain> TLSSecuredConnectionInfos::getPeerCertificates() const +shared_ptr <const security::cert::certificateChain> 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 <TLSProperties_GnuTLS>()) + : m_data(make_shared <TLSProperties_GnuTLS>()) { setCipherSuite(CIPHERSUITE_DEFAULT); } @@ -50,9 +50,9 @@ TLSProperties::TLSProperties() TLSProperties::TLSProperties(const TLSProperties& props) : object(), - m_data(vmime::create <TLSProperties_GnuTLS>()) + m_data(make_shared <TLSProperties_GnuTLS>()) { - *m_data.dynamicCast <TLSProperties_GnuTLS>() = *props.m_data.dynamicCast <TLSProperties_GnuTLS>(); + *dynamicCast <TLSProperties_GnuTLS>(m_data) = *dynamicCast <TLSProperties_GnuTLS>(props.m_data); } @@ -86,13 +86,13 @@ void TLSProperties::setCipherSuite(const GenericCipherSuite cipherSuite) void TLSProperties::setCipherSuite(const string& cipherSuite) { - m_data.dynamicCast <TLSProperties_GnuTLS>()->cipherSuite = cipherSuite; + dynamicCast <TLSProperties_GnuTLS>(m_data)->cipherSuite = cipherSuite; } const string TLSProperties::getCipherSuite() const { - return m_data.dynamicCast <TLSProperties_GnuTLS>()->cipherSuite; + return dynamicCast <TLSProperties_GnuTLS>(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> TLSSession::create(ref <security::cert::certificateVerifier> cv, ref <TLSProperties> props) +shared_ptr <TLSSession> TLSSession::create(shared_ptr <security::cert::certificateVerifier> cv, shared_ptr <TLSProperties> props) { - return vmime::create <TLSSession_GnuTLS>(cv, props); + return make_shared <TLSSession_GnuTLS>(cv, props); } -TLSSession_GnuTLS::TLSSession_GnuTLS(ref <security::cert::certificateVerifier> cv, ref <TLSProperties> props) +TLSSession_GnuTLS::TLSSession_GnuTLS(shared_ptr <security::cert::certificateVerifier> cv, shared_ptr <TLSProperties> props) : m_certVerifier(cv), m_props(props) { int res; @@ -267,13 +267,13 @@ TLSSession_GnuTLS::~TLSSession_GnuTLS() } -ref <TLSSocket> TLSSession_GnuTLS::getSocket(ref <socket> sok) +shared_ptr <TLSSocket> TLSSession_GnuTLS::getSocket(shared_ptr <socket> sok) { - return TLSSocket::wrap(thisRef().dynamicCast <TLSSession>(), sok); + return TLSSocket::wrap(dynamicCast <TLSSession>(shared_from_this()), sok); } -ref <security::cert::certificateVerifier> TLSSession_GnuTLS::getCertificateVerifier() +shared_ptr <security::cert::certificateVerifier> 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> TLSSocket::wrap(ref <TLSSession> session, ref <socket> sok) +shared_ptr <TLSSocket> TLSSocket::wrap(shared_ptr <TLSSession> session, shared_ptr <socket> sok) { - return vmime::create <TLSSocket_GnuTLS> - (session.dynamicCast <TLSSession_GnuTLS>(), sok); + return make_shared <TLSSocket_GnuTLS> + (dynamicCast <TLSSession_GnuTLS>(session), sok); } -TLSSocket_GnuTLS::TLSSocket_GnuTLS(ref <TLSSession_GnuTLS> session, ref <socket> sok) +TLSSocket_GnuTLS::TLSSocket_GnuTLS(shared_ptr <TLSSession_GnuTLS> session, shared_ptr <socket> 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 <timeoutHandler> toHandler) +void TLSSocket_GnuTLS::handshake(shared_ptr <timeoutHandler> toHandler) { if (toHandler) toHandler->resetTimeOut(); @@ -260,16 +260,16 @@ void TLSSocket_GnuTLS::handshake(ref <timeoutHandler> 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 <security::cert::certificateChain> certs = getPeerCertificates(); + shared_ptr <security::cert::certificateChain> certs = getPeerCertificates(); if (certs == NULL) throw exceptions::tls_exception("No peer certificate."); @@ -364,14 +364,14 @@ ssize_t TLSSocket_GnuTLS::gnutlsPullFunc } -ref <security::cert::certificateChain> TLSSocket_GnuTLS::getPeerCertificates() const +shared_ptr <security::cert::certificateChain> 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 <security::cert::certificateChain> TLSSocket_GnuTLS::getPeerCertificates() c { // XXX more fine-grained error reporting? delete [] x509Certs; - return NULL; + return null; } } { - std::vector <ref <security::cert::certificate> > certs; + std::vector <shared_ptr <security::cert::certificate> > certs; bool error = false; for (unsigned int i = 0 ; i < certCount ; ++i) @@ -407,7 +407,7 @@ ref <security::cert::certificateChain> TLSSocket_GnuTLS::getPeerCertificates() c gnutls_x509_crt_export(x509Certs[i], GNUTLS_X509_FMT_DER, &data[0], &dataSize); - ref <security::cert::X509Certificate> cert = + shared_ptr <security::cert::X509Certificate> cert = security::cert::X509Certificate::import(&data[0], dataSize); if (cert != NULL) @@ -421,14 +421,14 @@ ref <security::cert::certificateChain> TLSSocket_GnuTLS::getPeerCertificates() c delete [] x509Certs; if (error) - return NULL; + return null; - return vmime::create <security::cert::certificateChain>(certs); + return make_shared <security::cert::certificateChain>(certs); } delete [] x509Certs; - return NULL; + return null; } @@ -457,7 +457,7 @@ private: void TLSSocket_GnuTLS::internalThrow() { - static std::vector <ref <TLSSocket_DeleteExWrapper> > exToDelete; + static std::vector <shared_ptr <TLSSocket_DeleteExWrapper> > exToDelete; if (m_ex) { @@ -467,7 +467,7 @@ void TLSSocket_GnuTLS::internalThrow() m_ex = NULL; // To avoid memory leaks - exToDelete.push_back(vmime::create <TLSSocket_DeleteExWrapper>(ex)); + exToDelete.push_back(make_shared <TLSSocket_DeleteExWrapper>(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 <vmime::utility::sync::criticalSection >* OpenSSLInitializer::sm_mutexes; +shared_ptr <vmime::utility::sync::criticalSection >* 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 <vmime::utility::sync::criticalSection>[numMutexes]; + sm_mutexes = new shared_ptr <vmime::utility::sync::criticalSection>[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 <TLSProperties_OpenSSL>()) + : m_data(make_shared <TLSProperties_OpenSSL>()) { setCipherSuite(CIPHERSUITE_DEFAULT); } @@ -48,9 +48,9 @@ TLSProperties::TLSProperties() TLSProperties::TLSProperties(const TLSProperties& props) : object(), - m_data(vmime::create <TLSProperties_OpenSSL>()) + m_data(make_shared <TLSProperties_OpenSSL>()) { - *m_data.dynamicCast <TLSProperties_OpenSSL>() = *props.m_data.dynamicCast <TLSProperties_OpenSSL>(); + *dynamicCast <TLSProperties_OpenSSL>(m_data) = *dynamicCast <TLSProperties_OpenSSL>(props.m_data); } @@ -84,13 +84,13 @@ void TLSProperties::setCipherSuite(const GenericCipherSuite cipherSuite) void TLSProperties::setCipherSuite(const string& cipherSuite) { - m_data.dynamicCast <TLSProperties_OpenSSL>()->cipherSuite = cipherSuite; + dynamicCast <TLSProperties_OpenSSL>(m_data)->cipherSuite = cipherSuite; } const string TLSProperties::getCipherSuite() const { - return m_data.dynamicCast <TLSProperties_OpenSSL>()->cipherSuite; + return dynamicCast <TLSProperties_OpenSSL>(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> TLSSession::create(ref <security::cert::certificateVerifier> cv, ref <TLSProperties> props) +shared_ptr <TLSSession> TLSSession::create(shared_ptr <security::cert::certificateVerifier> cv, shared_ptr <TLSProperties> props) { - return vmime::create <TLSSession_OpenSSL>(cv, props); + return make_shared <TLSSession_OpenSSL>(cv, props); } -TLSSession_OpenSSL::TLSSession_OpenSSL(ref <vmime::security::cert::certificateVerifier> cv, ref <TLSProperties> props) +TLSSession_OpenSSL::TLSSession_OpenSSL(shared_ptr <vmime::security::cert::certificateVerifier> cv, shared_ptr <TLSProperties> 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 <TLSSocket> TLSSession_OpenSSL::getSocket(ref <socket> sok) +shared_ptr <TLSSocket> TLSSession_OpenSSL::getSocket(shared_ptr <socket> sok) { - return TLSSocket::wrap(thisRef().dynamicCast <TLSSession>(), sok); + return TLSSocket::wrap(dynamicCast <TLSSession>(shared_from_this()), sok); } -ref <security::cert::certificateVerifier> TLSSession_OpenSSL::getCertificateVerifier() +shared_ptr <security::cert::certificateVerifier> 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> TLSSocket::wrap(ref <TLSSession> session, ref <socket> sok) +shared_ptr <TLSSocket> TLSSocket::wrap(shared_ptr <TLSSession> session, shared_ptr <socket> sok) { - return vmime::create <TLSSocket_OpenSSL> - (session.dynamicCast <TLSSession_OpenSSL>(), sok); + return make_shared <TLSSocket_OpenSSL> + (dynamicCast <TLSSession_OpenSSL>(session), sok); } -TLSSocket_OpenSSL::TLSSocket_OpenSSL(ref <TLSSession_OpenSSL> session, ref <socket> sok) +TLSSocket_OpenSSL::TLSSocket_OpenSSL(shared_ptr <TLSSession_OpenSSL> session, shared_ptr <socket> 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 <timeoutHandler> toHandler) +void TLSSocket_OpenSSL::handshake(shared_ptr <timeoutHandler> toHandler) { if (toHandler) toHandler->resetTimeOut(); @@ -245,14 +245,14 @@ void TLSSocket_OpenSSL::handshake(ref <timeoutHandler> 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 <security::cert::certificateChain> certs = getPeerCertificates(); + shared_ptr <security::cert::certificateChain> certs = getPeerCertificates(); if (certs == NULL) throw exceptions::tls_exception("No peer certificate."); @@ -263,24 +263,24 @@ void TLSSocket_OpenSSL::handshake(ref <timeoutHandler> toHandler) } -ref <security::cert::certificateChain> TLSSocket_OpenSSL::getPeerCertificates() const +shared_ptr <security::cert::certificateChain> 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 <ref <security::cert::certificate> > certs; + std::vector <shared_ptr <security::cert::certificate> > certs; for (int i = 0; i < certCount && !error; i++) { - ref <vmime::security::cert::X509Certificate> cert = + shared_ptr <vmime::security::cert::X509Certificate> cert = vmime::security::cert::X509Certificate_OpenSSL::importInternal(sk_X509_value(chain, i)); if (cert) @@ -290,9 +290,9 @@ ref <security::cert::certificateChain> TLSSocket_OpenSSL::getPeerCertificates() } if (error) - return NULL; + return null; - return vmime::create <security::cert::certificateChain>(certs); + return make_shared <security::cert::certificateChain>(certs); } |