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/smtp/SMTPConnection.cpp | 82 ++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'src/net/smtp/SMTPConnection.cpp') diff --git a/src/net/smtp/SMTPConnection.cpp b/src/net/smtp/SMTPConnection.cpp index e831ccfc..9fcacbc1 100644 --- a/src/net/smtp/SMTPConnection.cpp +++ b/src/net/smtp/SMTPConnection.cpp @@ -51,11 +51,11 @@ // Helpers for service properties #define GET_PROPERTY(type, prop) \ - (m_transport.acquire()->getInfos().getPropertyValue (getSession(), \ - dynamic_cast (m_transport.acquire()->getInfos()).getProperties().prop)) + (m_transport.lock()->getInfos().getPropertyValue (getSession(), \ + dynamic_cast (m_transport.lock()->getInfos()).getProperties().prop)) #define HAS_PROPERTY(prop) \ - (m_transport.acquire()->getInfos().hasProperty(getSession(), \ - dynamic_cast (m_transport.acquire()->getInfos()).getProperties().prop)) + (m_transport.lock()->getInfos().hasProperty(getSession(), \ + dynamic_cast (m_transport.lock()->getInfos()).getProperties().prop)) namespace vmime { @@ -64,8 +64,8 @@ namespace smtp { -SMTPConnection::SMTPConnection(ref transport, ref auth) - : m_transport(transport), m_auth(auth), m_socket(NULL), m_timeoutHandler(NULL), +SMTPConnection::SMTPConnection(shared_ptr transport, shared_ptr auth) + : m_transport(transport), m_auth(auth), m_socket(null), m_timeoutHandler(null), m_authenticated(false), m_secured(false), m_extendedSMTP(false) { } @@ -95,7 +95,7 @@ void SMTPConnection::connect() const string address = GET_PROPERTY(string, PROPERTY_SERVER_ADDRESS); const port_t port = GET_PROPERTY(port_t, PROPERTY_SERVER_PORT); - ref transport = m_transport.acquire(); + shared_ptr transport = m_transport.lock(); // Create the time-out handler if (transport->getTimeoutHandlerFactory()) @@ -107,22 +107,22 @@ void SMTPConnection::connect() #if VMIME_HAVE_TLS_SUPPORT if (transport->isSMTPS()) // dedicated port/SMTPS { - ref tlsSession = tls::TLSSession::create + shared_ptr tlsSession = tls::TLSSession::create (transport->getCertificateVerifier(), transport->getSession()->getTLSProperties()); - ref tlsSocket = + shared_ptr tlsSocket = tlsSession->getSocket(m_socket); m_socket = tlsSocket; m_secured = true; - m_cntInfos = vmime::create (address, port, tlsSession, tlsSocket); + m_cntInfos = make_shared (address, port, tlsSession, tlsSocket); } else #endif // VMIME_HAVE_TLS_SUPPORT { - m_cntInfos = vmime::create (address, port); + m_cntInfos = make_shared (address, port); } m_socket->connect(address, port); @@ -132,7 +132,7 @@ void SMTPConnection::connect() // eg: C: // --- S: 220 smtp.domain.com Service ready - ref resp; + shared_ptr resp; if ((resp = readResponse())->getCode() != 220) { @@ -199,7 +199,7 @@ void SMTPConnection::helo() sendRequest(SMTPCommand::EHLO(platform::getHandler()->getHostName())); - ref resp; + shared_ptr resp; if ((resp = readResponse())->getCode() != 250) { @@ -281,7 +281,7 @@ void SMTPConnection::authenticate() throw exceptions::command_error("AUTH", "ESMTP not supported."); } - getAuthenticator()->setService(m_transport.acquire()); + getAuthenticator()->setService(m_transport.lock()); #if VMIME_HAVE_SASL_SUPPORT // First, try SASL authentication @@ -325,7 +325,7 @@ void SMTPConnection::authenticate() void SMTPConnection::authenticateSASL() { - if (!getAuthenticator().dynamicCast ()) + if (!dynamicCast (getAuthenticator())) throw exceptions::authentication_error("No SASL authenticator available."); // Obtain SASL mechanisms supported by server from ESMTP extensions @@ -335,10 +335,10 @@ void SMTPConnection::authenticateSASL() if (saslMechs.empty()) throw exceptions::authentication_error("No SASL mechanism available."); - std::vector > mechList; + std::vector > mechList; - ref saslContext = - vmime::create (); + shared_ptr saslContext = + make_shared (); for (unsigned int i = 0 ; i < saslMechs.size() ; ++i) { @@ -357,14 +357,14 @@ void SMTPConnection::authenticateSASL() throw exceptions::authentication_error("No SASL mechanism available."); // Try to suggest a mechanism among all those supported - ref suggestedMech = + shared_ptr suggestedMech = saslContext->suggestMechanism(mechList); if (!suggestedMech) throw exceptions::authentication_error("Unable to suggest SASL mechanism."); // Allow application to choose which mechanisms to use - mechList = getAuthenticator().dynamicCast ()-> + mechList = dynamicCast (getAuthenticator())-> getAcceptableMechanisms(mechList, suggestedMech); if (mechList.empty()) @@ -373,9 +373,9 @@ void SMTPConnection::authenticateSASL() // Try each mechanism in the list in turn for (unsigned int i = 0 ; i < mechList.size() ; ++i) { - ref mech = mechList[i]; + shared_ptr mech = mechList[i]; - ref saslSession = + shared_ptr saslSession = saslContext->createSession("smtp", getAuthenticator(), mech); saslSession->init(); @@ -384,7 +384,7 @@ void SMTPConnection::authenticateSASL() for (bool cont = true ; cont ; ) { - ref response = readResponse(); + shared_ptr response = readResponse(); switch (response->getCode()) { @@ -472,7 +472,7 @@ void SMTPConnection::startTLS() { sendRequest(SMTPCommand::STARTTLS()); - ref resp = readResponse(); + shared_ptr resp = readResponse(); if (resp->getCode() != 220) { @@ -480,11 +480,11 @@ void SMTPConnection::startTLS() resp->getCode(), resp->getEnhancedCode()); } - ref tlsSession = tls::TLSSession::create + shared_ptr tlsSession = tls::TLSSession::create (getTransport()->getCertificateVerifier(), getTransport()->getSession()->getTLSProperties()); - ref tlsSocket = + shared_ptr tlsSocket = tlsSession->getSocket(m_socket); tlsSocket->handshake(m_timeoutHandler); @@ -492,7 +492,7 @@ void SMTPConnection::startTLS() m_socket = tlsSocket; m_secured = true; - m_cntInfos = vmime::create + m_cntInfos = make_shared (m_cntInfos->getHost(), m_cntInfos->getPort(), tlsSession, tlsSocket); } catch (exceptions::command_error&) @@ -533,27 +533,27 @@ void SMTPConnection::internalDisconnect() } m_socket->disconnect(); - m_socket = NULL; + m_socket = null; - m_timeoutHandler = NULL; + m_timeoutHandler = null; m_authenticated = false; m_extendedSMTP = false; m_secured = false; - m_cntInfos = NULL; + m_cntInfos = null; } -void SMTPConnection::sendRequest(ref cmd) +void SMTPConnection::sendRequest(shared_ptr cmd) { cmd->writeToSocket(m_socket); } -ref SMTPConnection::readResponse() +shared_ptr SMTPConnection::readResponse() { - ref resp = SMTPResponse::readResponse + shared_ptr resp = SMTPResponse::readResponse (m_socket, m_timeoutHandler, m_responseState); m_responseState = resp->getCurrentState(); @@ -574,37 +574,37 @@ bool SMTPConnection::isSecuredConnection() const } -ref SMTPConnection::getConnectionInfos() const +shared_ptr SMTPConnection::getConnectionInfos() const { return m_cntInfos; } -ref SMTPConnection::getTransport() +shared_ptr SMTPConnection::getTransport() { - return m_transport.acquire(); + return m_transport.lock(); } -ref SMTPConnection::getSession() +shared_ptr SMTPConnection::getSession() { - return m_transport.acquire()->getSession(); + return m_transport.lock()->getSession(); } -ref SMTPConnection::getSocket() +shared_ptr SMTPConnection::getSocket() { return m_socket; } -ref SMTPConnection::getTimeoutHandler() +shared_ptr SMTPConnection::getTimeoutHandler() { return m_timeoutHandler; } -ref SMTPConnection::getAuthenticator() +shared_ptr SMTPConnection::getAuthenticator() { return m_auth; } -- cgit v1.2.3