]> granicus.if.org Git - curl/commitdiff
Dominick Meglio implemented CURLOPT_MAXFILESIZE and --max-filesize.
authorDaniel Stenberg <daniel@haxx.se>
Fri, 17 Oct 2003 13:11:00 +0000 (13:11 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 17 Oct 2003 13:11:00 +0000 (13:11 +0000)
CHANGES
RELEASE-NOTES
docs/TODO
docs/curl.1
docs/libcurl/curl_easy_setopt.3
include/curl/curl.h
lib/ftp.c
lib/transfer.c
lib/url.c
lib/urldata.h
src/main.c

diff --git a/CHANGES b/CHANGES
index 9ebbd11c206cb84f207ec400f3a81804ca0498c2..fb0d29d5572bd7289323d6fe2cdbbf8e6bfdb00a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,8 @@
 
 
 Daniel (17 October)
+- Dominick Meglio implemented CURLOPT_MAXFILESIZE and --max-filesize.
+
 - Made libcurl show verbose info about what auth type and user name that is
   being sent in its HTTP request-headers.
 
index 2fe80d22b249e31d5ac49f13bb6dcbcbe8cbd57a..72c645aed9b75918d5acc937a7465426c05ef269 100644 (file)
@@ -2,6 +2,7 @@ Curl and libcurl 7.10.8 is out! A bugfix release.
 
 This release includes the following changes:
 
+ o CURLOPT_MAXFILESIZE was added, and --max-filesize.
  o CURLOPT_PASSWDFUNCTION and CURLOPT_PASSWDDATA are no longer supported.
  o IPv6 is now supported on Windows builds too
  o CURLOPT_IPRESOLVE lets you select pure IPv6 or IPv4 resolved addresses
index a72fe2b2d1b78f7cd80c517e5bd1d09314d8d1f1..add94bf2657d4e8e7f8e8026c8ddff0e280a5ecb 100644 (file)
--- a/docs/TODO
+++ b/docs/TODO
@@ -34,11 +34,6 @@ TODO
    >4GB all over. Bug reports (and source reviews) show that it doesn't
    currently work.
 
- * CURLOPT_MAXFILESIZE. Prevent downloads that are larger than the specified
-   size. CURLE_FILESIZE_EXCEEDED would then be returned. Gautam Mani
-   requested. That is, the download should not even begin but be aborted
-   immediately.
-
  LIBCURL - multi interface
 
  * Add curl_multi_timeout() to make libcurl's ares-functionality better.
index 7c042780e6530b8a5f94ed6dc4253e95ee71817f..fc55ed2c9524726ec12c3ce2ed716bd6c25e107d 100644 (file)
@@ -2,7 +2,7 @@
 .\" nroff -man curl.1
 .\" Written by Daniel Stenberg
 .\"
-.TH curl 1 "23 Sep 2003" "Curl 7.10.8" "Curl Manual"
+.TH curl 1 "17 Oct 2003" "Curl 7.10.8" "Curl Manual"
 .SH NAME
 curl \- transfer a URL
 .SH SYNOPSIS
@@ -456,6 +456,14 @@ authentication info (which is plaintext in the case of HTTP Basic
 authentication).
 
 If this option is used twice, the second will again disable location following.
+.IP "--max-filesize <bytes>"
+Specify the maximum size (in bytes) of a file to download. If the file
+requested is larger than this value, the transfer will not start and curl will
+return with exit code 63.
+
+NOTE: The file size is not always known prior to download, and for such files
+this option has no effect even if the file transfer ends up being larger than
+this given limit. This concerns both FTP and HTTP transfers.
 .IP "-m/--max-time <seconds>"
 Maximum time in seconds that you allow the whole operation to take.  This is
 useful for preventing your batch jobs from hanging for hours due to slow
@@ -1053,6 +1061,10 @@ Couldn't use specified SSL cipher
 Problem with the CA cert (path? permission?)
 .IP 61
 Unrecognized transfer encoding
+.IP 62
+Invalid LDAP URL
+.IP 63
+Maximum file size exceeded
 .IP XX
 There will appear more error codes here in future releases. The existing ones
 are meant to never change.
index 22563a1ff2756f2a472494b31332a1cf7a893932..b9aa0568241e5dd275f5460629ea8a1868be24c2 100644 (file)
@@ -719,6 +719,15 @@ libcurl what the expected size of the infile is.
 .B CURLOPT_UPLOAD
 A non-zero parameter tells the library to prepare for an upload. The
 CURLOPT_READDATA and CURLOPT_INFILESIZE are also interesting for uploads.
+.TP
+.B CURLOPT_MAXFILESIZE
+Pass a long as parameter. This allows you to specify the maximum size (in
+bytes) of a file to download. If the file requested is larger than this value,
+the transfer will not start and CURLE_FILESIZE_EXCEEDED will be returned.
+
+NOTE: The file size is not always known prior to download, and for such files
+this option has no effect even if the file transfer ends up being larger than
+this given limit. This concerns both FTP and HTTP transfers.
 .PP
 .SH CONNECTION OPTIONS
 .TP 0.4i
index 0f9e38b5b2cefeb022895ab9e9b3abe89a85c3e3..557c942a56d3f4e7cee09ad1a97f072fcf1bcbf6 100644 (file)
@@ -218,6 +218,7 @@ typedef enum {
   CURLE_SSL_CACERT,              /* 60 - problem with the CA cert (path?) */
   CURLE_BAD_CONTENT_ENCODING,    /* 61 - Unrecognized transfer encoding */
   CURLE_LDAP_INVALID_URL,        /* 62 - Invalid LDAP URL */
+  CURLE_FILESIZE_EXCEEDED,       /* 63 - Maximum file size exceeded */
 
   CURL_LAST /* never use! */
 } CURLcode;
@@ -689,6 +690,10 @@ typedef enum {
      affect on systems with support for more than one, i.e IPv4 _and_ IPv6. */
   CINIT(IPRESOLVE, LONG, 113),
 
+  /* Set this option to limit the size of a file that will be downloaded from
+     an HTTP or FTP server. */
+  CINIT(MAXFILESIZE, LONG, 114),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
index 6ee81b5d20e4df7c53505af012c875c2cd22a753..4b19bd0fc36418a0af1430d4235abd75f2e27dce 100644 (file)
--- 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) {
 
index 956a479967a27bb5a756bf57d85a40c20ee0a5c1..1938a8a2c98fb56e4f3b80df471614a9a977fec6 100644 (file)
@@ -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);
             }
index b4cfc798efce412821b4916d0d6fc11ab030ee8c..0d07e686d087d4f2f2badf2a87adfcc789fad2c1 100644 (file)
--- 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 */
index 471049d517651ac344850344a4fdb2e493c301e7..0ebff5687a08670a45394b4337e26e9c06d9e691 100644 (file)
@@ -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
index 54b97377594b120554f07e46115027dc5be51a7c..5caf803df54d5ed328d4ef0a3c79bc6260b3f176 100644 (file)
@@ -428,6 +428,7 @@ static void help(void)
     "                    following locations, even when hostname changed",
     " -m/--max-time <seconds> Maximum time allowed for the transfer",
     "    --max-redirs <num> Set maximum number of redirections allowed (H)",
+    "    --max-filesize <bytes> Set the maximum file size to download (H/F)",
     " -M/--manual        Display huge help text",
     " -n/--netrc         Must read .netrc for user name and password",
     "    --netrc-optional  Use either .netrc or URL; overrides -n",
@@ -506,6 +507,7 @@ struct Configurable {
   long timeout;
   long connecttimeout;
   long maxredirs;
+  long max_filesize;
   char *headerfile;
   char *ftpport;
   char *iface;
@@ -1140,6 +1142,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
     {"*v", "stderr",      TRUE},
     {"*w", "interface",   TRUE},
     {"*x", "krb4",        TRUE},
+    {"*y", "max-filesize", TRUE},
     {"0", "http1.0",     FALSE},
     {"1", "tlsv1",       FALSE},
     {"2", "sslv2",       FALSE},
@@ -1406,6 +1409,9 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
         /* krb4 level string */
         GetStr(&config->krb4level, nextarg);
         break;
+      case 'y': /* --max-filesize */
+        config->max_filesize = atoi(nextarg);
+        break;
 
       default: /* the URL! */
         {
@@ -3247,6 +3253,10 @@ operate(struct Configurable *config, int argc, char *argv[])
         if(config->proxyntlm)
           curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
 
+        /* new in curl 7.10.8 */
+        if (config->max_filesize)
+          curl_easy_setopt(curl, CURLOPT_MAXFILESIZE, config->max_filesize);
+
         res = curl_easy_perform(curl);
         
         if((config->progressmode == CURL_PROGRESS_BAR) &&