From 68ad348b4466819600f3139be404b6296f3cecf3 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Sun, 13 Mar 2016 17:22:21 +0100 Subject: [PATCH] Issue #126: don't use deprecated 'auto_ptr' on C++11. --- src/vmime/net/imap/IMAPConnection.cpp | 12 ++-- src/vmime/net/imap/IMAPFolder.cpp | 36 +++++----- src/vmime/net/imap/IMAPMessage.cpp | 2 +- src/vmime/net/imap/IMAPParser.hpp | 68 ++++++++++++------- src/vmime/net/imap/IMAPStore.cpp | 2 +- .../net/tls/openssl/TLSSocket_OpenSSL.cpp | 2 +- .../net/tls/openssl/TLSSocket_OpenSSL.hpp | 2 +- .../platforms/posix/posixChildProcess.cpp | 2 +- 8 files changed, 71 insertions(+), 55 deletions(-) diff --git a/src/vmime/net/imap/IMAPConnection.cpp b/src/vmime/net/imap/IMAPConnection.cpp index 2de93314..4daa2774 100644 --- a/src/vmime/net/imap/IMAPConnection.cpp +++ b/src/vmime/net/imap/IMAPConnection.cpp @@ -157,7 +157,7 @@ void IMAPConnection::connect() // eg: C: // --- S: * OK mydomain.org IMAP4rev1 v12.256 server ready - std::auto_ptr greet(m_parser->readGreeting()); + scoped_ptr greet(m_parser->readGreeting()); bool needAuth = false; if (greet->resp_cond_bye()) @@ -274,7 +274,7 @@ void IMAPConnection::authenticate() shared_ptr conn = dynamicCast (shared_from_this()); IMAPCommand::LOGIN(username, password)->send(conn); - std::auto_ptr resp(m_parser->readResponse()); + scoped_ptr resp(m_parser->readResponse()); if (resp->isBad()) { @@ -393,7 +393,7 @@ void IMAPConnection::authenticateSASL() for (bool cont = true ; cont ; ) { - std::auto_ptr resp(m_parser->readResponse()); + scoped_ptr resp(m_parser->readResponse()); if (resp->response_done() && resp->response_done()->response_tagged() && @@ -507,7 +507,7 @@ void IMAPConnection::startTLS() { IMAPCommand::STARTTLS()->send(dynamicCast (shared_from_this())); - std::auto_ptr resp(m_parser->readResponse()); + scoped_ptr resp(m_parser->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -606,7 +606,7 @@ void IMAPConnection::fetchCapabilities() { IMAPCommand::CAPABILITY()->send(dynamicCast (shared_from_this())); - std::auto_ptr resp(m_parser->readResponse()); + scoped_ptr resp(m_parser->readResponse()); if (resp->response_done()->response_tagged()-> resp_cond_state()->status() == IMAPParser::resp_cond_state::OK) @@ -716,7 +716,7 @@ void IMAPConnection::initHierarchySeparator() { IMAPCommand::LIST("", "")->send(dynamicCast (shared_from_this())); - std::auto_ptr resp(m_parser->readResponse()); + scoped_ptr resp(m_parser->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) diff --git a/src/vmime/net/imap/IMAPFolder.cpp b/src/vmime/net/imap/IMAPFolder.cpp index 3c55dbad..5f8c8b71 100644 --- a/src/vmime/net/imap/IMAPFolder.cpp +++ b/src/vmime/net/imap/IMAPFolder.cpp @@ -177,7 +177,7 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable) )->send(connection); // Read the response - std::auto_ptr resp(connection->readResponse()); + scoped_ptr resp(connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -381,7 +381,7 @@ void IMAPFolder::create(const folderAttributes& attribs) IMAPCommand::CREATE(mailbox, createParams)->send(m_connection); - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -416,7 +416,7 @@ void IMAPFolder::destroy() IMAPCommand::DELETE(mailbox)->send(m_connection); - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -471,7 +471,7 @@ int IMAPFolder::testExistAndGetType() (m_connection->hierarchySeparator(), getFullPath()))->send(m_connection); - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -565,7 +565,7 @@ std::vector > IMAPFolder::getMessages(const messageSet& ms IMAPCommand::FETCH(msgs, params)->send(m_connection); // Get the response - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -692,7 +692,7 @@ std::vector > IMAPFolder::getFolders(const bool recursive) cmd->send(m_connection); - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -776,7 +776,7 @@ void IMAPFolder::fetchMessages(std::vector >& msg, const f (m_connection, messageSet::byNumber(list), options)->send(m_connection); // Get the response - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -872,7 +872,7 @@ std::vector > IMAPFolder::getAndFetchMessages (m_connection, msgs, attribsWithUID)->send(m_connection); // Get the response - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -1008,7 +1008,7 @@ void IMAPFolder::deleteMessages(const messageSet& msgs) )->send(m_connection); // Get the response - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -1031,7 +1031,7 @@ void IMAPFolder::setMessageFlags(const messageSet& msgs, const int flags, const IMAPCommand::STORE(msgs, mode, flagList)->send(m_connection); // Get the response - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -1081,7 +1081,7 @@ messageSet IMAPFolder::addMessage )->send(m_connection); // Get the response - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); bool ok = false; const std::vector & respList @@ -1138,7 +1138,7 @@ messageSet IMAPFolder::addMessage progress->stop(total); // Get the response - std::auto_ptr finalResp(m_connection->readResponse()); + scoped_ptr finalResp(m_connection->readResponse()); if (finalResp->isBad() || finalResp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -1174,7 +1174,7 @@ void IMAPFolder::expunge() IMAPCommand::EXPUNGE()->send(m_connection); // Get the response - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -1207,7 +1207,7 @@ void IMAPFolder::rename(const folder::path& newPath) )->send(m_connection); // Get the response - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -1268,7 +1268,7 @@ messageSet IMAPFolder::copyMessages(const folder::path& dest, const messageSet& )->send(m_connection); // Get the response - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -1326,7 +1326,7 @@ shared_ptr IMAPFolder::getStatus() )->send(m_connection); // Get the response - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -1372,7 +1372,7 @@ void IMAPFolder::noop() IMAPCommand::NOOP()->send(m_connection); - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) @@ -1397,7 +1397,7 @@ std::vector IMAPFolder::getMessageNumbersStartingOnUID(const message::uid& IMAPCommand::SEARCH(searchKeys, /* charset */ NULL)->send(m_connection); // Get the response - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()->resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) diff --git a/src/vmime/net/imap/IMAPMessage.cpp b/src/vmime/net/imap/IMAPMessage.cpp index c79c4ffa..c0141337 100644 --- a/src/vmime/net/imap/IMAPMessage.cpp +++ b/src/vmime/net/imap/IMAPMessage.cpp @@ -364,7 +364,7 @@ void IMAPMessage::extractImpl )->send(constCast (folder)->m_connection); // Get the response - std::auto_ptr resp + scoped_ptr resp (constCast (folder)->m_connection->readResponse(&literalHandler)); if (resp->isBad() || resp->response_done()->response_tagged()-> diff --git a/src/vmime/net/imap/IMAPParser.hpp b/src/vmime/net/imap/IMAPParser.hpp index 44f9d23b..b1241224 100644 --- a/src/vmime/net/imap/IMAPParser.hpp +++ b/src/vmime/net/imap/IMAPParser.hpp @@ -113,7 +113,7 @@ VIMAP_PARSER_FAIL_UNLESS(variable = parser.get (line, &pos)); \ } -#define VIMAP_PARSER_GET_PTR(type, variable) /* auto_ptr/shared_ptr version */ \ +#define VIMAP_PARSER_GET_PTR(type, variable) /* scoped_ptr/shared_ptr version */ \ { \ variable.reset(parser.get (line, &pos)); \ VIMAP_PARSER_FAIL_UNLESS(variable.get()); \ @@ -125,9 +125,36 @@ #define VIMAP_PARSER_TRY_GET(type, variable) /* raw pointer version */ \ (variable = parser.get (line, &pos)) -#define VIMAP_PARSER_TRY_GET_PTR(type, variable) /* auto_ptr/shared_ptr version */ \ +#define VIMAP_PARSER_TRY_GET_PTR(type, variable) /* scoped_ptr/shared_ptr version */ \ (variable.reset(parser.get (line, &pos)), variable.get()) +/** Get an optional token and advance. If found, token will be pushed back + * to a vector. If the token is not matched, stopInstr will be executed. + * + * @param type token class + * @param variable variable of type std::vector<> to which the retrieved + * token will be pushed + * @param stopInstr instruction to execute if token is not found + */ +#define VIMAP_PARSER_TRY_GET_PUSHBACK_OR_ELSE(type, variable, stopInstr) \ + { \ + type* v = NULL; \ + try \ + { \ + v = parser.get (line, &pos); \ + if (!v) \ + { \ + stopInstr; \ + } \ + variable.push_back(v); \ + } \ + catch (...) \ + { \ + delete v; \ + throw; \ + } \ + } + /** Get a token and advance. Token will be pushed back to a vector. * If the token is not matched, parsing will fail. * @@ -136,11 +163,8 @@ * token will be pushed */ #define VIMAP_PARSER_GET_PUSHBACK(type, variable) \ - { \ - std::auto_ptr v(parser.get (line, &pos)); \ - VIMAP_PARSER_FAIL_UNLESS(v.get()); \ - variable.push_back(v.release()); \ - } + VIMAP_PARSER_TRY_GET_PUSHBACK_OR_ELSE(type, variable, VIMAP_PARSER_FAIL()) + /** Check for a token which takes an argument and advance. * If the token is not matched, parsing will fail. @@ -1452,7 +1476,7 @@ public: m_charset = theCharset->value(); // Decode text - std::auto_ptr theEncoder; + scoped_ptr theEncoder; if (theEncoding->value()[0] == 'q' || theEncoding->value()[0] == 'Q') { @@ -2364,10 +2388,9 @@ public: { size_t pos = *currentPos; - std::auto_ptr at; - VIMAP_PARSER_GET_PTR(IMAPParser::atom, at); + VIMAP_PARSER_GET(IMAPParser::atom, m_atom); - string value = at->value(); + string value = m_atom->value(); const char* str = value.c_str(); if ((str[0] == 'a' || str[0] == 'A') && @@ -2378,10 +2401,9 @@ public: { size_t pos = 5; m_auth_type = parser.get (value, &pos); - } - else - { - m_atom = at.release(); + + delete m_atom; + m_atom = NULL; } *currentPos = pos; @@ -4064,13 +4086,7 @@ public: while (true) { - std::auto_ptr b; - VIMAP_PARSER_TRY_GET_PTR(xbody, b); - - if (!b.get()) - break; - - m_list.push_back(b.release()); + VIMAP_PARSER_TRY_GET_PUSHBACK_OR_ELSE(xbody, m_list, break); } VIMAP_PARSER_CHECK(SPACE); @@ -4432,7 +4448,7 @@ public: { size_t pos = *currentPos; - std::auto_ptr num; + scoped_ptr num; VIMAP_PARSER_GET_PTR(nz_number, num); m_number = static_cast (num->value()); @@ -4731,7 +4747,7 @@ public: VIMAP_PARSER_TRY_CHECK(SPACE); } - std::auto_ptr text1; + scoped_ptr text1; VIMAP_PARSER_TRY_GET_PTR(text_mime2, text1); if (text1.get()) @@ -4740,7 +4756,7 @@ public: } else { - std::auto_ptr text2; + scoped_ptr text2; VIMAP_PARSER_TRY_GET_PTR(IMAPParser::text, text2); if (text2.get()) @@ -5729,7 +5745,7 @@ public: const size_t oldPos = *currentPos; TYPE term(arg); - + if (!term.parse(*this, line, currentPos)) { *currentPos = oldPos; diff --git a/src/vmime/net/imap/IMAPStore.cpp b/src/vmime/net/imap/IMAPStore.cpp index 28ba34e8..cc7c7a3f 100644 --- a/src/vmime/net/imap/IMAPStore.cpp +++ b/src/vmime/net/imap/IMAPStore.cpp @@ -187,7 +187,7 @@ void IMAPStore::noop() IMAPCommand::NOOP()->send(m_connection); - std::auto_ptr resp(m_connection->readResponse()); + scoped_ptr resp(m_connection->readResponse()); if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) diff --git a/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.cpp b/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.cpp index 4f61e355..5faafdbe 100644 --- a/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.cpp +++ b/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.cpp @@ -77,7 +77,7 @@ shared_ptr TLSSocket::wrap(shared_ptr session, shared_p TLSSocket_OpenSSL::TLSSocket_OpenSSL(shared_ptr session, shared_ptr sok) - : m_session(session), m_wrapped(sok), m_connected(false), m_ssl(0), m_status(0), m_ex(NULL) + : m_session(session), m_wrapped(sok), m_connected(false), m_ssl(0), m_status(0), m_ex() { } diff --git a/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp b/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp index 913a02fe..b4b90098 100644 --- a/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp +++ b/src/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp @@ -121,7 +121,7 @@ private: unsigned long m_status; // Last exception thrown from C BIO functions - std::auto_ptr m_ex; + scoped_ptr m_ex; }; diff --git a/src/vmime/platforms/posix/posixChildProcess.cpp b/src/vmime/platforms/posix/posixChildProcess.cpp index 54d4cd75..275cacfd 100644 --- a/src/vmime/platforms/posix/posixChildProcess.cpp +++ b/src/vmime/platforms/posix/posixChildProcess.cpp @@ -377,7 +377,7 @@ void posixChildProcess::waitForFinish() { if (WEXITSTATUS(wstat) == 255) { - std::auto_ptr pfsf(new posixFileSystemFactory()); + scoped_ptr pfsf(new posixFileSystemFactory()); throw exceptions::system_error("Could not execute '" + pfsf->pathToString(m_processPath) + "'");