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/imap/IMAPConnection.cpp | 96 ++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'src/net/imap/IMAPConnection.cpp') diff --git a/src/net/imap/IMAPConnection.cpp b/src/net/imap/IMAPConnection.cpp index 53f8ba9f..0dba1ecc 100644 --- a/src/net/imap/IMAPConnection.cpp +++ b/src/net/imap/IMAPConnection.cpp @@ -53,11 +53,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 { @@ -65,9 +65,9 @@ namespace net { namespace imap { -IMAPConnection::IMAPConnection(ref store, ref auth) - : m_store(store), m_auth(auth), m_socket(NULL), m_parser(NULL), m_tag(NULL), - m_hierarchySeparator('\0'), m_state(STATE_NONE), m_timeoutHandler(NULL), +IMAPConnection::IMAPConnection(shared_ptr store, shared_ptr auth) + : m_store(store), m_auth(auth), m_socket(null), m_parser(null), m_tag(null), + m_hierarchySeparator('\0'), m_state(STATE_NONE), m_timeoutHandler(null), m_secured(false), m_firstTag(true), m_capabilitiesFetched(false), m_noModSeq(false) { } @@ -100,7 +100,7 @@ void IMAPConnection::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()) @@ -112,29 +112,29 @@ void IMAPConnection::connect() #if VMIME_HAVE_TLS_SUPPORT if (store->isIMAPS()) // dedicated port/IMAPS { - 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); - m_tag = vmime::create (); - m_parser = vmime::create (m_tag, m_socket, m_timeoutHandler); + m_tag = make_shared (); + m_parser = make_shared (m_tag, m_socket, m_timeoutHandler); setState(STATE_NON_AUTHENTICATED); @@ -145,7 +145,7 @@ void IMAPConnection::connect() // eg: C: // --- S: * OK mydomain.org IMAP4rev1 v12.256 server ready - utility::auto_ptr greet(m_parser->readGreeting()); + std::auto_ptr greet(m_parser->readGreeting()); bool needAuth = false; if (greet->resp_cond_bye()) @@ -223,7 +223,7 @@ void IMAPConnection::connect() void IMAPConnection::authenticate() { - getAuthenticator()->setService(m_store.acquire()); + getAuthenticator()->setService(m_store.lock()); #if VMIME_HAVE_SASL_SUPPORT // First, try SASL authentication @@ -262,7 +262,7 @@ void IMAPConnection::authenticate() send(true, "LOGIN " + IMAPUtils::quoteString(username) + " " + IMAPUtils::quoteString(password), true); - utility::auto_ptr resp(m_parser->readResponse()); + std::auto_ptr resp(m_parser->readResponse()); if (resp->isBad()) { @@ -277,7 +277,7 @@ void IMAPConnection::authenticate() } // Server capabilities may change when logged in - if (!processCapabilityResponseData(resp)) + if (!processCapabilityResponseData(resp.get())) invalidateCapabilities(); } @@ -286,7 +286,7 @@ void IMAPConnection::authenticate() void IMAPConnection::authenticateSASL() { - if (!getAuthenticator().dynamicCast ()) + if (!dynamicCast (getAuthenticator())) throw exceptions::authentication_error("No SASL authenticator available."); const std::vector capa = getCapabilities(); @@ -310,10 +310,10 @@ void IMAPConnection::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) { @@ -332,14 +332,14 @@ void IMAPConnection::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()) @@ -348,9 +348,9 @@ void IMAPConnection::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("imap", getAuthenticator(), mech); saslSession->init(); @@ -359,7 +359,7 @@ void IMAPConnection::authenticateSASL() for (bool cont = true ; cont ; ) { - utility::auto_ptr resp(m_parser->readResponse()); + std::auto_ptr resp(m_parser->readResponse()); if (resp->response_done() && resp->response_done()->response_tagged() && @@ -466,7 +466,7 @@ void IMAPConnection::startTLS() { send(true, "STARTTLS", true); - utility::auto_ptr resp(m_parser->readResponse()); + std::auto_ptr resp(m_parser->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -475,11 +475,11 @@ void IMAPConnection::startTLS() ("STARTTLS", resp->getErrorLog(), "bad response"); } - 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); @@ -488,7 +488,7 @@ void IMAPConnection::startTLS() m_parser->setSocket(m_socket); 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 @@ -551,12 +551,12 @@ void IMAPConnection::fetchCapabilities() { send(true, "CAPABILITY", true); - utility::auto_ptr resp(m_parser->readResponse()); + std::auto_ptr resp(m_parser->readResponse()); if (resp->response_done()->response_tagged()-> resp_cond_state()->status() == IMAPParser::resp_cond_state::OK) { - processCapabilityResponseData(resp); + processCapabilityResponseData(resp.get()); } } @@ -604,7 +604,7 @@ void IMAPConnection::processCapabilityResponseData(const IMAPParser::capability_ } -ref IMAPConnection::getAuthenticator() +shared_ptr IMAPConnection::getAuthenticator() { return m_auth; } @@ -623,7 +623,7 @@ bool IMAPConnection::isSecuredConnection() const } -ref IMAPConnection::getConnectionInfos() const +shared_ptr IMAPConnection::getConnectionInfos() const { return m_cntInfos; } @@ -645,15 +645,15 @@ void IMAPConnection::internalDisconnect() send(true, "LOGOUT", true); m_socket->disconnect(); - m_socket = NULL; + m_socket = null; } - m_timeoutHandler = NULL; + m_timeoutHandler = null; m_state = STATE_LOGOUT; m_secured = false; - m_cntInfos = NULL; + m_cntInfos = null; } @@ -661,7 +661,7 @@ void IMAPConnection::initHierarchySeparator() { send(true, "LIST \"\" \"\"", true); - vmime::utility::auto_ptr resp(m_parser->readResponse()); + std::auto_ptr resp(m_parser->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -769,25 +769,25 @@ char IMAPConnection::hierarchySeparator() const } -ref IMAPConnection::getStore() const +shared_ptr IMAPConnection::getStore() const { - return m_store.acquire(); + return m_store.lock(); } -ref IMAPConnection::getStore() +shared_ptr IMAPConnection::getStore() { - return m_store.acquire(); + return m_store.lock(); } -ref IMAPConnection::getSession() +shared_ptr IMAPConnection::getSession() { - return m_store.acquire()->getSession(); + return m_store.lock()->getSession(); } -ref IMAPConnection::getSocket() const +shared_ptr IMAPConnection::getSocket() const { return m_socket; } -- cgit v1.2.3