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/pop3/POP3Connection.cpp | 104 ++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 52 deletions(-) (limited to 'src/net/pop3/POP3Connection.cpp') diff --git a/src/net/pop3/POP3Connection.cpp b/src/net/pop3/POP3Connection.cpp index dd0024e9..547ef5ef 100644 --- a/src/net/pop3/POP3Connection.cpp +++ b/src/net/pop3/POP3Connection.cpp @@ -50,11 +50,11 @@ // Helpers for service properties #define GET_PROPERTY(type, prop) \ - (m_store.acquire()->getInfos().getPropertyValue (getSession(), \ - dynamic_cast (m_store.acquire()->getInfos()).getProperties().prop)) + (m_store.lock()->getInfos().getPropertyValue (getSession(), \ + dynamic_cast (m_store.lock()->getInfos()).getProperties().prop)) #define HAS_PROPERTY(prop) \ - (m_store.acquire()->getInfos().hasProperty(getSession(), \ - dynamic_cast (m_store.acquire()->getInfos()).getProperties().prop)) + (m_store.lock()->getInfos().hasProperty(getSession(), \ + dynamic_cast (m_store.lock()->getInfos()).getProperties().prop)) namespace vmime { @@ -63,8 +63,8 @@ namespace pop3 { -POP3Connection::POP3Connection(ref store, ref auth) - : m_store(store), m_auth(auth), m_socket(NULL), m_timeoutHandler(NULL), +POP3Connection::POP3Connection(shared_ptr store, shared_ptr auth) + : m_store(store), m_auth(auth), m_socket(null), m_timeoutHandler(null), m_authenticated(false), m_secured(false), m_capabilitiesFetched(false) { } @@ -94,7 +94,7 @@ void POP3Connection::connect() const string address = GET_PROPERTY(string, PROPERTY_SERVER_ADDRESS); const port_t port = GET_PROPERTY(port_t, PROPERTY_SERVER_PORT); - ref store = m_store.acquire(); + shared_ptr store = m_store.lock(); // Create the time-out handler if (store->getTimeoutHandlerFactory()) @@ -106,22 +106,22 @@ void POP3Connection::connect() #if VMIME_HAVE_TLS_SUPPORT if (store->isPOP3S()) // dedicated port/POP3S { - ref tlsSession = tls::TLSSession::create + shared_ptr tlsSession = tls::TLSSession::create (store->getCertificateVerifier(), store->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); @@ -131,8 +131,8 @@ void POP3Connection::connect() // eg: C: // --- S: +OK MailSite POP3 Server 5.3.4.0 Ready <36938848.1056800841.634@somewhere.com> - ref response = POP3Response::readResponse - (thisRef().dynamicCast ()); + shared_ptr response = POP3Response::readResponse + (dynamicCast (shared_from_this())); if (!response->isSuccess()) { @@ -195,8 +195,8 @@ void POP3Connection::internalDisconnect() { try { - POP3Command::QUIT()->send(thisRef().dynamicCast ()); - POP3Response::readResponse(thisRef().dynamicCast ()); + POP3Command::QUIT()->send(dynamicCast (shared_from_this())); + POP3Response::readResponse(dynamicCast (shared_from_this())); } catch (exception&) { @@ -206,21 +206,21 @@ void POP3Connection::internalDisconnect() m_socket->disconnect(); } - m_socket = NULL; + m_socket = null; } - m_timeoutHandler = NULL; + m_timeoutHandler = null; m_authenticated = false; m_secured = false; - m_cntInfos = NULL; + m_cntInfos = null; } void POP3Connection::authenticate(const messageId& randomMID) { - getAuthenticator()->setService(m_store.acquire()); + getAuthenticator()->setService(m_store.lock()); #if VMIME_HAVE_SASL_SUPPORT // First, try SASL authentication @@ -262,8 +262,8 @@ void POP3Connection::authenticate(const messageId& randomMID) const string username = getAuthenticator()->getUsername(); const string password = getAuthenticator()->getPassword(); - ref conn = thisRef().dynamicCast (); - ref response; + shared_ptr conn = dynamicCast (shared_from_this()); + shared_ptr response; if (GET_PROPERTY(bool, PROPERTY_OPTIONS_APOP)) { @@ -271,7 +271,7 @@ void POP3Connection::authenticate(const messageId& randomMID) randomMID.getRight().length() != 0) { // is the result of MD5 applied to "password" - ref md5 = + shared_ptr md5 = security::digest::messageDigestFactory::getInstance()->create("md5"); md5->update(randomMID.generate() + password); @@ -361,7 +361,7 @@ void POP3Connection::authenticate(const messageId& randomMID) void POP3Connection::authenticateSASL() { - if (!getAuthenticator().dynamicCast ()) + if (!dynamicCast (getAuthenticator())) throw exceptions::authentication_error("No SASL authenticator available."); std::vector capa = getCapabilities(); @@ -401,10 +401,10 @@ void POP3Connection::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) { @@ -423,14 +423,14 @@ void POP3Connection::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()) @@ -439,19 +439,19 @@ void POP3Connection::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("pop3", getAuthenticator(), mech); saslSession->init(); - POP3Command::AUTH(mech->getName())->send(thisRef().dynamicCast ()); + POP3Command::AUTH(mech->getName())->send(dynamicCast (shared_from_this())); for (bool cont = true ; cont ; ) { - ref response = - POP3Response::readResponse(thisRef().dynamicCast ()); + shared_ptr response = + POP3Response::readResponse(dynamicCast (shared_from_this())); switch (response->getCode()) { @@ -537,19 +537,19 @@ void POP3Connection::startTLS() { try { - POP3Command::STLS()->send(thisRef().dynamicCast ()); + POP3Command::STLS()->send(dynamicCast (shared_from_this())); - ref response = - POP3Response::readResponse(thisRef().dynamicCast ()); + shared_ptr response = + POP3Response::readResponse(dynamicCast (shared_from_this())); if (!response->isSuccess()) throw exceptions::command_error("STLS", response->getFirstLine()); - ref tlsSession = tls::TLSSession::create - (m_store.acquire()->getCertificateVerifier(), - m_store.acquire()->getSession()->getTLSProperties()); + shared_ptr tlsSession = tls::TLSSession::create + (m_store.lock()->getCertificateVerifier(), + m_store.lock()->getSession()->getTLSProperties()); - ref tlsSocket = + shared_ptr tlsSocket = tlsSession->getSocket(m_socket); tlsSocket->handshake(m_timeoutHandler); @@ -557,7 +557,7 @@ void POP3Connection::startTLS() m_socket = tlsSocket; m_secured = true; - m_cntInfos = vmime::create + m_cntInfos = make_shared (m_cntInfos->getHost(), m_cntInfos->getPort(), tlsSession, tlsSocket); // " Once TLS has been started, the client MUST discard cached @@ -601,10 +601,10 @@ void POP3Connection::invalidateCapabilities() void POP3Connection::fetchCapabilities() { - POP3Command::CAPA()->send(thisRef().dynamicCast ()); + POP3Command::CAPA()->send(dynamicCast (shared_from_this())); - ref response = - POP3Response::readMultilineResponse(thisRef().dynamicCast ()); + shared_ptr response = + POP3Response::readMultilineResponse(dynamicCast (shared_from_this())); std::vector res; @@ -631,37 +631,37 @@ bool POP3Connection::isSecuredConnection() const } -ref POP3Connection::getConnectionInfos() const +shared_ptr POP3Connection::getConnectionInfos() const { return m_cntInfos; } -ref POP3Connection::getStore() +shared_ptr POP3Connection::getStore() { - return m_store.acquire(); + return m_store.lock(); } -ref POP3Connection::getSession() +shared_ptr POP3Connection::getSession() { - return m_store.acquire()->getSession(); + return m_store.lock()->getSession(); } -ref POP3Connection::getSocket() +shared_ptr POP3Connection::getSocket() { return m_socket; } -ref POP3Connection::getTimeoutHandler() +shared_ptr POP3Connection::getTimeoutHandler() { return m_timeoutHandler; } -ref POP3Connection::getAuthenticator() +shared_ptr POP3Connection::getAuthenticator() { return m_auth; } -- cgit v1.2.3