Revert "Update to 7.40.1"
[platform/upstream/curl.git] / lib / ftplistparser.c
index 12ee51d..4a46dd1 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
  * 01-29-97 11:32PM <DIR> prog
  */
 
-#include "setup.h"
+#include "curl_setup.h"
 
-#include "ftplistparser.h"
-#include "curl_fnmatch.h"
+#ifndef CURL_DISABLE_FTP
+
+#include <curl/curl.h>
 
 #include "urldata.h"
-#include "ftp.h"
 #include "fileinfo.h"
 #include "llist.h"
 #include "strtoofft.h"
 #include "rawstr.h"
 #include "ftp.h"
+#include "ftplistparser.h"
+#include "curl_fnmatch.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #include <curl/mprintf.h>
@@ -354,8 +356,6 @@ static CURLcode ftp_pl_insert_finfo(struct connectdata *conn,
   return CURLE_OK;
 }
 
-/* Curl_ftp_parselist is a write callback function */
-
 size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
                           void *connptr)
 {
@@ -367,10 +367,6 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
   unsigned long i = 0;
   CURLcode rc;
 
-  if(bufflen >= CURL_WRITEFUNC_PAUSE)
-    /* CURL_WRITEFUNC_PAUSE limits input size */
-    return CURL_WRITEFUNC_OUT_OF_MEMORY;
-
   if(parser->error) { /* error in previous call */
     /* scenario:
      * 1. call => OK..
@@ -378,9 +374,6 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
      * 3. (last) call => is skipped RIGHT HERE and the error is hadled later
      *    in wc_statemach()
      */
-    if(parser->error == CURLE_OUT_OF_MEMORY)
-      return CURL_WRITEFUNC_OUT_OF_MEMORY;
-
     return bufflen;
   }
 
@@ -397,12 +390,12 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
       parser->file_data = Curl_fileinfo_alloc();
       if(!parser->file_data) {
         parser->error = CURLE_OUT_OF_MEMORY;
-        return CURL_WRITEFUNC_OUT_OF_MEMORY;
+        return bufflen;
       }
       parser->file_data->b_data = malloc(FTP_BUFFER_ALLOCSIZE);
       if(!parser->file_data->b_data) {
         PL_ERROR(conn, CURLE_OUT_OF_MEMORY);
-        return CURL_WRITEFUNC_OUT_OF_MEMORY;
+        return bufflen;
       }
       parser->file_data->b_size = FTP_BUFFER_ALLOCSIZE;
       parser->item_offset = 0;
@@ -425,7 +418,7 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
         parser->file_data = NULL;
         parser->error = CURLE_OUT_OF_MEMORY;
         PL_ERROR(conn, CURLE_OUT_OF_MEMORY);
-        return CURL_WRITEFUNC_OUT_OF_MEMORY;
+        return bufflen;
       }
     }
 
@@ -456,9 +449,12 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
             finfo->b_data[parser->item_length - 1] = 0;
             if(strncmp("total ", finfo->b_data, 6) == 0) {
               char *endptr = finfo->b_data+6;
-              /* here we can deal with directory size */
+              /* here we can deal with directory size, pass the leading white
+                 spaces and then the digits */
               while(ISSPACE(*endptr))
                 endptr++;
+              while(ISDIGIT(*endptr))
+                endptr++;
               if(*endptr != 0) {
                 PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
                 return bufflen;
@@ -1053,3 +1049,5 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
 
   return bufflen;
 }
+
+#endif /* CURL_DISABLE_FTP */