* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2010, 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 <time.h>
+#ifndef CURL_DISABLE_FTP
-#include "ftplistparser.h"
-#include "curl_fnmatch.h"
+#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>
#define FTP_BUFFER_ALLOCSIZE 160
typedef enum {
- PL_UNIX_FILETYPE = 0,
+ PL_UNIX_TOTALSIZE = 0,
+ PL_UNIX_FILETYPE,
PL_UNIX_PERMISSION,
PL_UNIX_HLINKS,
PL_UNIX_USER,
typedef union {
enum {
+ PL_UNIX_TOTALSIZE_INIT = 0,
+ PL_UNIX_TOTALSIZE_READING
+ } total_dirsize;
+
+ enum {
PL_UNIX_HLINKS_PRESPACE = 0,
PL_UNIX_HLINKS_NUMBER
} hlinks;
} NT;
} state;
- struct {
- char *buffer;
- size_t bufferlength; /* how many bytes is allocated at *buffer */
- size_t bufferin; /* how many bytes is in buffer */
- } tmpdata;
-
- struct {
- curl_write_callback old_fwritefunc;
- FILE *old_file_descriptor;
- } backup;
-
CURLcode error;
struct curl_fileinfo *file_data;
unsigned int item_length;
struct ftp_parselist_data *Curl_ftp_parselist_data_alloc(void)
{
- struct ftp_parselist_data *parselist_data =
- malloc(sizeof(struct ftp_parselist_data));
- if(!parselist_data)
- return ZERO_NULL;
- memset(parselist_data, 0, sizeof(struct ftp_parselist_data));
- return parselist_data;
+ return calloc(1, sizeof(struct ftp_parselist_data));
}
compare = Curl_fnmatch;
/* filter pattern-corresponding filenames */
- if(compare(conn->data->set.fnmatch_data, wc->pattern, finfo->filename) == 0) {
+ if(compare(conn->data->set.fnmatch_data, wc->pattern,
+ finfo->filename) == 0) {
/* discard symlink which is containing multiple " -> " */
if((finfo->filetype == CURLFILETYPE_SYMLINK) && finfo->strings.target &&
(strstr(finfo->strings.target, " -> "))) {
}
finfo = parser->file_data;
- finfo->b_data[finfo->b_used++] = buffer[i];
+ finfo->b_data[finfo->b_used++] = c;
if(finfo->b_used >= finfo->b_size - 1) {
/* if it is important, extend buffer space for file data */
switch (parser->os_type) {
case OS_TYPE_UNIX:
switch (parser->state.UNIX.main) {
+ case PL_UNIX_TOTALSIZE:
+ switch(parser->state.UNIX.sub.total_dirsize) {
+ case PL_UNIX_TOTALSIZE_INIT:
+ if(c == 't') {
+ parser->state.UNIX.sub.total_dirsize = PL_UNIX_TOTALSIZE_READING;
+ parser->item_length++;
+ }
+ else {
+ parser->state.UNIX.main = PL_UNIX_FILETYPE;
+ /* start FSM again not considering size of directory */
+ finfo->b_used = 0;
+ i--;
+ }
+ break;
+ case PL_UNIX_TOTALSIZE_READING:
+ parser->item_length++;
+ if(c == '\r') {
+ parser->item_length--;
+ finfo->b_used--;
+ }
+ else if(c == '\n') {
+ 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, 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;
+ }
+ else {
+ parser->state.UNIX.main = PL_UNIX_FILETYPE;
+ finfo->b_used = 0;
+ }
+ }
+ else {
+ PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
+ return bufflen;
+ }
+ }
+ break;
+ }
+ break;
case PL_UNIX_FILETYPE:
switch (c) {
case '-':
parser->state.UNIX.main = PL_UNIX_TIME;
parser->state.UNIX.sub.time = PL_UNIX_TIME_PREPART1;
}
- else if (!ISDIGIT(c)) {
+ else if(!ISDIGIT(c)) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
return bufflen;
}
}
else {
char *endptr;
- finfo->size = curlx_strtoofft(finfo->b_data + parser->item_offset,
+ finfo->size = curlx_strtoofft(finfo->b_data +
+ parser->item_offset,
&endptr, 10);
if(!*endptr) {
if(finfo->size == CURL_OFF_T_MAX ||
return bufflen;
}
+
+#endif /* CURL_DISABLE_FTP */