瀏覽代碼

2008-06-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	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
Tatsuhiro Tsujikawa 17 年之前
父節點
當前提交
c42c8b7f9c
共有 3 個文件被更改,包括 18 次插入4 次删除
  1. 9 0
      ChangeLog
  2. 4 3
      src/FtpConnection.cc
  3. 5 1
      src/FtpNegotiationCommand.cc

+ 9 - 0
ChangeLog

@@ -1,3 +1,12 @@
+2008-06-26  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	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  <tujikawa at rednoah dot com>
 
 	Updated po files.

+ 4 - 3
src/FtpConnection.cc

@@ -285,6 +285,7 @@ unsigned int FtpConnection::receivePasvResponse(std::pair<std::string, uint16_t>
 
 unsigned int FtpConnection::receiveRetrResponse(uint64_t& size)
 {
+  static const char* DIGITS = "0123456789";
   std::pair<unsigned int, std::string> 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));

+ 5 - 1
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)) {