From ce5db9a86ea1508b0caaeec38adc5397e390dc3e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 17 Oct 2003 13:11:00 +0000 Subject: Dominick Meglio implemented CURLOPT_MAXFILESIZE and --max-filesize. --- lib/ftp.c | 7 ++++++- lib/transfer.c | 5 +++++ lib/url.c | 7 +++++++ lib/urldata.h | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/ftp.c b/lib/ftp.c index 6ee81b5d2..4b19bd0fc 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -1777,8 +1777,13 @@ CURLcode Curl_ftp_nextconnect(struct connectdata *conn) downloads and when talking to servers that don't give away the size in the RETR response line. */ result = ftp_getsize(conn, ftp->file, &foundsize); - if(CURLE_OK == result) + if(CURLE_OK == result) { + if (data->set.max_filesize && foundsize > data->set.max_filesize) { + failf(data, "Maximum file size exceeded"); + return CURLE_FILESIZE_EXCEEDED; + } downloadsize = foundsize; + } if(conn->resume_from) { diff --git a/lib/transfer.c b/lib/transfer.c index 956a47996..1938a8a2c 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -578,6 +578,11 @@ CURLcode Curl_readwrite(struct connectdata *conn, /* check for Content-Length: header lines to get size */ if (checkprefix("Content-Length:", k->p) && sscanf (k->p+15, " %ld", &k->contentlength)) { + if (data->set.max_filesize && k->contentlength > + data->set.max_filesize) { + failf(data, "Maximum file size exceeded"); + return CURLE_FILESIZE_EXCEEDED; + } conn->size = k->contentlength; Curl_pgrsSetDownloadSize(data, k->contentlength); } diff --git a/lib/url.c b/lib/url.c index b4cfc798e..0d07e686d 100644 --- a/lib/url.c +++ b/lib/url.c @@ -1238,6 +1238,13 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...) data->set.http200aliases = va_arg(param, struct curl_slist *); break; + case CURLOPT_MAXFILESIZE: + /* + * Set the maximum size of a file to download. + */ + data->set.max_filesize = va_arg(param, long); + break; + default: /* unknown tag and its companion, just ignore: */ return CURLE_FAILED_INIT; /* correct this */ diff --git a/lib/urldata.h b/lib/urldata.h index 471049d51..0ebff5687 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -828,6 +828,8 @@ struct UserDefined { struct curl_slist *http200aliases; /* linked list of aliases for http200 */ int ip_version; + + long max_filesize; /* Maximum file size to download */ /* Here follows boolean settings that define how to behave during this session. They are STATIC, set by libcurl users or at least initially -- cgit v1.2.3