Issue #126: don't use deprecated 'auto_ptr' on C++11.

This commit is contained in:
Vincent Richard 2016-03-13 17:22:21 +01:00
parent 997f9300a5
commit 68ad348b44
8 changed files with 71 additions and 55 deletions

View File

@ -157,7 +157,7 @@ void IMAPConnection::connect()
// eg: C: <connection to server> // eg: C: <connection to server>
// --- S: * OK mydomain.org IMAP4rev1 v12.256 server ready // --- S: * OK mydomain.org IMAP4rev1 v12.256 server ready
std::auto_ptr <IMAPParser::greeting> greet(m_parser->readGreeting()); scoped_ptr <IMAPParser::greeting> greet(m_parser->readGreeting());
bool needAuth = false; bool needAuth = false;
if (greet->resp_cond_bye()) if (greet->resp_cond_bye())
@ -274,7 +274,7 @@ void IMAPConnection::authenticate()
shared_ptr <IMAPConnection> conn = dynamicCast <IMAPConnection>(shared_from_this()); shared_ptr <IMAPConnection> conn = dynamicCast <IMAPConnection>(shared_from_this());
IMAPCommand::LOGIN(username, password)->send(conn); IMAPCommand::LOGIN(username, password)->send(conn);
std::auto_ptr <IMAPParser::response> resp(m_parser->readResponse()); scoped_ptr <IMAPParser::response> resp(m_parser->readResponse());
if (resp->isBad()) if (resp->isBad())
{ {
@ -393,7 +393,7 @@ void IMAPConnection::authenticateSASL()
for (bool cont = true ; cont ; ) for (bool cont = true ; cont ; )
{ {
std::auto_ptr <IMAPParser::response> resp(m_parser->readResponse()); scoped_ptr <IMAPParser::response> resp(m_parser->readResponse());
if (resp->response_done() && if (resp->response_done() &&
resp->response_done()->response_tagged() && resp->response_done()->response_tagged() &&
@ -507,7 +507,7 @@ void IMAPConnection::startTLS()
{ {
IMAPCommand::STARTTLS()->send(dynamicCast <IMAPConnection>(shared_from_this())); IMAPCommand::STARTTLS()->send(dynamicCast <IMAPConnection>(shared_from_this()));
std::auto_ptr <IMAPParser::response> resp(m_parser->readResponse()); scoped_ptr <IMAPParser::response> resp(m_parser->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -606,7 +606,7 @@ void IMAPConnection::fetchCapabilities()
{ {
IMAPCommand::CAPABILITY()->send(dynamicCast <IMAPConnection>(shared_from_this())); IMAPCommand::CAPABILITY()->send(dynamicCast <IMAPConnection>(shared_from_this()));
std::auto_ptr <IMAPParser::response> resp(m_parser->readResponse()); scoped_ptr <IMAPParser::response> resp(m_parser->readResponse());
if (resp->response_done()->response_tagged()-> if (resp->response_done()->response_tagged()->
resp_cond_state()->status() == IMAPParser::resp_cond_state::OK) resp_cond_state()->status() == IMAPParser::resp_cond_state::OK)
@ -716,7 +716,7 @@ void IMAPConnection::initHierarchySeparator()
{ {
IMAPCommand::LIST("", "")->send(dynamicCast <IMAPConnection>(shared_from_this())); IMAPCommand::LIST("", "")->send(dynamicCast <IMAPConnection>(shared_from_this()));
std::auto_ptr <IMAPParser::response> resp(m_parser->readResponse()); scoped_ptr <IMAPParser::response> resp(m_parser->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)

View File

@ -177,7 +177,7 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable)
)->send(connection); )->send(connection);
// Read the response // Read the response
std::auto_ptr <IMAPParser::response> resp(connection->readResponse()); scoped_ptr <IMAPParser::response> resp(connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) 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); IMAPCommand::CREATE(mailbox, createParams)->send(m_connection);
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -416,7 +416,7 @@ void IMAPFolder::destroy()
IMAPCommand::DELETE(mailbox)->send(m_connection); IMAPCommand::DELETE(mailbox)->send(m_connection);
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -471,7 +471,7 @@ int IMAPFolder::testExistAndGetType()
(m_connection->hierarchySeparator(), getFullPath()))->send(m_connection); (m_connection->hierarchySeparator(), getFullPath()))->send(m_connection);
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -565,7 +565,7 @@ std::vector <shared_ptr <message> > IMAPFolder::getMessages(const messageSet& ms
IMAPCommand::FETCH(msgs, params)->send(m_connection); IMAPCommand::FETCH(msgs, params)->send(m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -692,7 +692,7 @@ std::vector <shared_ptr <folder> > IMAPFolder::getFolders(const bool recursive)
cmd->send(m_connection); cmd->send(m_connection);
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -776,7 +776,7 @@ void IMAPFolder::fetchMessages(std::vector <shared_ptr <message> >& msg, const f
(m_connection, messageSet::byNumber(list), options)->send(m_connection); (m_connection, messageSet::byNumber(list), options)->send(m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -872,7 +872,7 @@ std::vector <shared_ptr <message> > IMAPFolder::getAndFetchMessages
(m_connection, msgs, attribsWithUID)->send(m_connection); (m_connection, msgs, attribsWithUID)->send(m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -1008,7 +1008,7 @@ void IMAPFolder::deleteMessages(const messageSet& msgs)
)->send(m_connection); )->send(m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) 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); IMAPCommand::STORE(msgs, mode, flagList)->send(m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -1081,7 +1081,7 @@ messageSet IMAPFolder::addMessage
)->send(m_connection); )->send(m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
bool ok = false; bool ok = false;
const std::vector <IMAPParser::continue_req_or_response_data*>& respList const std::vector <IMAPParser::continue_req_or_response_data*>& respList
@ -1138,7 +1138,7 @@ messageSet IMAPFolder::addMessage
progress->stop(total); progress->stop(total);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> finalResp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> finalResp(m_connection->readResponse());
if (finalResp->isBad() || finalResp->response_done()->response_tagged()-> if (finalResp->isBad() || finalResp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -1174,7 +1174,7 @@ void IMAPFolder::expunge()
IMAPCommand::EXPUNGE()->send(m_connection); IMAPCommand::EXPUNGE()->send(m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -1207,7 +1207,7 @@ void IMAPFolder::rename(const folder::path& newPath)
)->send(m_connection); )->send(m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) 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); )->send(m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -1326,7 +1326,7 @@ shared_ptr <folderStatus> IMAPFolder::getStatus()
)->send(m_connection); )->send(m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -1372,7 +1372,7 @@ void IMAPFolder::noop()
IMAPCommand::NOOP()->send(m_connection); IMAPCommand::NOOP()->send(m_connection);
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@ -1397,7 +1397,7 @@ std::vector <int> IMAPFolder::getMessageNumbersStartingOnUID(const message::uid&
IMAPCommand::SEARCH(searchKeys, /* charset */ NULL)->send(m_connection); IMAPCommand::SEARCH(searchKeys, /* charset */ NULL)->send(m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || if (resp->isBad() ||
resp->response_done()->response_tagged()->resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp->response_done()->response_tagged()->resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)

View File

@ -364,7 +364,7 @@ void IMAPMessage::extractImpl
)->send(constCast <IMAPFolder>(folder)->m_connection); )->send(constCast <IMAPFolder>(folder)->m_connection);
// Get the response // Get the response
std::auto_ptr <IMAPParser::response> resp scoped_ptr <IMAPParser::response> resp
(constCast <IMAPFolder>(folder)->m_connection->readResponse(&literalHandler)); (constCast <IMAPFolder>(folder)->m_connection->readResponse(&literalHandler));
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->

View File

@ -113,7 +113,7 @@
VIMAP_PARSER_FAIL_UNLESS(variable = parser.get <type>(line, &pos)); \ VIMAP_PARSER_FAIL_UNLESS(variable = parser.get <type>(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 <type>(line, &pos)); \ variable.reset(parser.get <type>(line, &pos)); \
VIMAP_PARSER_FAIL_UNLESS(variable.get()); \ VIMAP_PARSER_FAIL_UNLESS(variable.get()); \
@ -125,9 +125,36 @@
#define VIMAP_PARSER_TRY_GET(type, variable) /* raw pointer version */ \ #define VIMAP_PARSER_TRY_GET(type, variable) /* raw pointer version */ \
(variable = parser.get <type>(line, &pos)) (variable = parser.get <type>(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 <type>(line, &pos)), variable.get()) (variable.reset(parser.get <type>(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 <type>(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. /** Get a token and advance. Token will be pushed back to a vector.
* If the token is not matched, parsing will fail. * If the token is not matched, parsing will fail.
* *
@ -136,11 +163,8 @@
* token will be pushed * token will be pushed
*/ */
#define VIMAP_PARSER_GET_PUSHBACK(type, variable) \ #define VIMAP_PARSER_GET_PUSHBACK(type, variable) \
{ \ VIMAP_PARSER_TRY_GET_PUSHBACK_OR_ELSE(type, variable, VIMAP_PARSER_FAIL())
std::auto_ptr <type> v(parser.get <type>(line, &pos)); \
VIMAP_PARSER_FAIL_UNLESS(v.get()); \
variable.push_back(v.release()); \
}
/** Check for a token which takes an argument and advance. /** Check for a token which takes an argument and advance.
* If the token is not matched, parsing will fail. * If the token is not matched, parsing will fail.
@ -1452,7 +1476,7 @@ public:
m_charset = theCharset->value(); m_charset = theCharset->value();
// Decode text // Decode text
std::auto_ptr <utility::encoder::encoder> theEncoder; scoped_ptr <utility::encoder::encoder> theEncoder;
if (theEncoding->value()[0] == 'q' || theEncoding->value()[0] == 'Q') if (theEncoding->value()[0] == 'q' || theEncoding->value()[0] == 'Q')
{ {
@ -2364,10 +2388,9 @@ public:
{ {
size_t pos = *currentPos; size_t pos = *currentPos;
std::auto_ptr <IMAPParser::atom> at; VIMAP_PARSER_GET(IMAPParser::atom, m_atom);
VIMAP_PARSER_GET_PTR(IMAPParser::atom, at);
string value = at->value(); string value = m_atom->value();
const char* str = value.c_str(); const char* str = value.c_str();
if ((str[0] == 'a' || str[0] == 'A') && if ((str[0] == 'a' || str[0] == 'A') &&
@ -2378,10 +2401,9 @@ public:
{ {
size_t pos = 5; size_t pos = 5;
m_auth_type = parser.get <IMAPParser::auth_type>(value, &pos); m_auth_type = parser.get <IMAPParser::auth_type>(value, &pos);
}
else delete m_atom;
{ m_atom = NULL;
m_atom = at.release();
} }
*currentPos = pos; *currentPos = pos;
@ -4064,13 +4086,7 @@ public:
while (true) while (true)
{ {
std::auto_ptr <xbody> b; VIMAP_PARSER_TRY_GET_PUSHBACK_OR_ELSE(xbody, m_list, break);
VIMAP_PARSER_TRY_GET_PTR(xbody, b);
if (!b.get())
break;
m_list.push_back(b.release());
} }
VIMAP_PARSER_CHECK(SPACE); VIMAP_PARSER_CHECK(SPACE);
@ -4432,7 +4448,7 @@ public:
{ {
size_t pos = *currentPos; size_t pos = *currentPos;
std::auto_ptr <nz_number> num; scoped_ptr <nz_number> num;
VIMAP_PARSER_GET_PTR(nz_number, num); VIMAP_PARSER_GET_PTR(nz_number, num);
m_number = static_cast <unsigned int>(num->value()); m_number = static_cast <unsigned int>(num->value());
@ -4731,7 +4747,7 @@ public:
VIMAP_PARSER_TRY_CHECK(SPACE); VIMAP_PARSER_TRY_CHECK(SPACE);
} }
std::auto_ptr <text_mime2> text1; scoped_ptr <text_mime2> text1;
VIMAP_PARSER_TRY_GET_PTR(text_mime2, text1); VIMAP_PARSER_TRY_GET_PTR(text_mime2, text1);
if (text1.get()) if (text1.get())
@ -4740,7 +4756,7 @@ public:
} }
else else
{ {
std::auto_ptr <IMAPParser::text> text2; scoped_ptr <IMAPParser::text> text2;
VIMAP_PARSER_TRY_GET_PTR(IMAPParser::text, text2); VIMAP_PARSER_TRY_GET_PTR(IMAPParser::text, text2);
if (text2.get()) if (text2.get())
@ -5729,7 +5745,7 @@ public:
const size_t oldPos = *currentPos; const size_t oldPos = *currentPos;
TYPE term(arg); TYPE term(arg);
if (!term.parse(*this, line, currentPos)) if (!term.parse(*this, line, currentPos))
{ {
*currentPos = oldPos; *currentPos = oldPos;

View File

@ -187,7 +187,7 @@ void IMAPStore::noop()
IMAPCommand::NOOP()->send(m_connection); IMAPCommand::NOOP()->send(m_connection);
std::auto_ptr <IMAPParser::response> resp(m_connection->readResponse()); scoped_ptr <IMAPParser::response> resp(m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()-> if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)

View File

@ -77,7 +77,7 @@ shared_ptr <TLSSocket> TLSSocket::wrap(shared_ptr <TLSSession> session, shared_p
TLSSocket_OpenSSL::TLSSocket_OpenSSL(shared_ptr <TLSSession_OpenSSL> session, shared_ptr <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_status(0), m_ex(NULL) : m_session(session), m_wrapped(sok), m_connected(false), m_ssl(0), m_status(0), m_ex()
{ {
} }

View File

@ -121,7 +121,7 @@ private:
unsigned long m_status; unsigned long m_status;
// Last exception thrown from C BIO functions // Last exception thrown from C BIO functions
std::auto_ptr <exception> m_ex; scoped_ptr <exception> m_ex;
}; };

View File

@ -377,7 +377,7 @@ void posixChildProcess::waitForFinish()
{ {
if (WEXITSTATUS(wstat) == 255) if (WEXITSTATUS(wstat) == 255)
{ {
std::auto_ptr <posixFileSystemFactory> pfsf(new posixFileSystemFactory()); scoped_ptr <posixFileSystemFactory> pfsf(new posixFileSystemFactory());
throw exceptions::system_error("Could not execute '" throw exceptions::system_error("Could not execute '"
+ pfsf->pathToString(m_processPath) + "'"); + pfsf->pathToString(m_processPath) + "'");