From 1fc28980d7fc252322676c5e2cdca9f3e56829ea Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 16 Mar 2006 22:13:40 +0100 Subject: [PATCH] Parsing filesize on ftp.task.gda.pl --- src/protocol/ftp/ftp.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/protocol/ftp/ftp.c b/src/protocol/ftp/ftp.c index c46c21ecb..2dafe83a4 100644 --- a/src/protocol/ftp/ftp.c +++ b/src/protocol/ftp/ftp.c @@ -805,8 +805,28 @@ get_filesize_from_RETR(unsigned char *data, int data_len) if (data[pos] == '(') pos_file_len = pos; - if (!pos_file_len || pos_file_len == data_len - 1) - return -1; + if (!pos_file_len || pos_file_len == data_len - 1) { + /* Getting file size from ftp.task.gda.pl */ + /* 150 5676.4 kbytes to download */ + unsigned char tmp = data[data_len - 1]; + unsigned char *kbytes; + char *endptr; + double size; + + data[data_len - 1] = '\0'; + kbytes = strstr(data, "kbytes"); + data[data_len - 1] = tmp; + if (!kbytes) return -1; + + for (kbytes -= 2; kbytes >= data; kbytes--) { + if (*kbytes == ' ') break; + } + if (*kbytes != ' ') return -1; + kbytes++; + size = strtod((const char *)kbytes, &endptr); + if (endptr == (char *)kbytes) return -1; + return (off_t)(size * 1024.0); + } pos_file_len++; if (!isdigit(data[pos_file_len]))