From c42c8b7f9ca7d78c9aa1af505072e9ecf640373d Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 26 Jun 2008 10:54:50 +0000 Subject: [PATCH] 2008-06-26 Tatsuhiro Tsujikawa Use digits to find first byte of file size, which makes the intention of the code clearer. * src/FtpConnection.cc Don't call validateTotalLength() when size is 0. * src/FtpNegotiationCommand.cc --- ChangeLog | 9 +++++++++ src/FtpConnection.cc | 7 ++++--- src/FtpNegotiationCommand.cc | 6 +++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90fd2447..c390d742 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-06-26 Tatsuhiro Tsujikawa + + Use digits to find first byte of file size, which makes the intention + of the code clearer. + * src/FtpConnection.cc + + Don't call validateTotalLength() when size is 0. + * src/FtpNegotiationCommand.cc + 2008-06-26 Tatsuhiro Tsujikawa Updated po files. diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index 0eb56946..f8598882 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -285,6 +285,7 @@ unsigned int FtpConnection::receivePasvResponse(std::pair unsigned int FtpConnection::receiveRetrResponse(uint64_t& size) { + static const char* DIGITS = "0123456789"; std::pair response; if(bulkReceiveResponse(response)) { if(response.first == 150 || response.first == 125) { @@ -295,11 +296,11 @@ unsigned int FtpConnection::receiveRetrResponse(uint64_t& size) std::string& res = response.second; std::string::size_type start; if((start = res.find_first_of("(")) != std::string::npos && - (start = res.find_first_not_of("( ", start)) != std::string::npos) { + (start = res.find_first_of(DIGITS, start)) != std::string::npos) { - // now start points to the first byte of the size string. + // now start points to the first digit of the size string. std::string::size_type end = - res.find_first_not_of("0123456789", start); + res.find_first_not_of(DIGITS, start); if(end != std::string::npos) { size = Util::parseULLInt(res.substr(start, end-start)); diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index 80826481..c819433c 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -421,7 +421,11 @@ bool FtpNegotiationCommand::recvRetr() { return onFileSizeDetermined(size); } else { - _requestGroup->validateTotalLength(size); + // size == 0 means file size could not be retrieved from the response of + // RETR raw command. + if(size > 0) { + _requestGroup->validateTotalLength(size); + } } if(e->option->getAsBool(PREF_FTP_PASV)) {