]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Fixes allowing HTTP test cases 1338, 1339, 1368 and 1369 to succeed
authorYang Tse <yangsita@gmail.com>
Thu, 7 Jun 2012 19:57:53 +0000 (21:57 +0200)
committerYang Tse <yangsita@gmail.com>
Thu, 7 Jun 2012 19:57:53 +0000 (21:57 +0200)
src/tool_cb_hdr.c
src/tool_cb_wrt.c
src/tool_operate.c
src/tool_sdecls.h
tests/data/DISABLED

index 738cd5dfc0751b3c29a7a63fe05e76e71141f168..ddc4c6638fc069870d3b86e8dcf87ca5fc654848 100644 (file)
@@ -71,8 +71,25 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
     fwrite(ptr, size, nmemb, heads->stream);
   }
 
-  if((urlnode->flags & GETOUT_USEREMOTE) && outs->config->content_disposition
-     && (cb > 20) && checkprefix("Content-disposition:", str)) {
+  /*
+  ** This callback callback MIGHT set the filename upon appropriate
+  ** conditions and server specifying filename in Content-Disposition.
+  */
+
+  if(!outs->config->content_disposition)
+    return cb;
+
+  if(!urlnode)
+    return failure;
+
+  if(!checkprefix("http://", urlnode->url) &&
+     !checkprefix("https://", urlnode->url))
+    return cb;
+
+  if(!(urlnode->flags & GETOUT_USEREMOTE))
+    return cb;
+
+  if((cb > 20) && checkprefix("Content-disposition:", str)) {
     const char *p = str + 20;
 
     /* look for the 'filename=' parameter
@@ -102,6 +119,7 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
       if(filename) {
         outs->filename = filename;
         outs->alloc_filename = TRUE;
+        outs->is_cd_filename = TRUE;
         outs->s_isreg = TRUE;
         outs->fopened = FALSE;
         outs->stream = NULL;
index fa47dd3f33c172561fb4c3eab43b83a6c647bb76..d6688110a4084f803fcdcadc2817678eaccb9c4d 100644 (file)
@@ -86,7 +86,7 @@ size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
       /* standard stream */
       if(!outs->stream || outs->s_isreg || outs->fopened)
         check_fails = TRUE;
-      if(outs->alloc_filename || outs->init)
+      if(outs->alloc_filename || outs->is_cd_filename || outs->init)
         check_fails = TRUE;
     }
     if(check_fails) {
@@ -104,7 +104,7 @@ size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
       return failure;
     }
 
-    if(config->content_disposition) {
+    if(outs->is_cd_filename) {
       /* don't overwrite existing files */
       file = fopen(outs->filename, "rb");
       if(file) {
index 75bb5b34d981ca0e8cd4b81dcd305ad716f9f74c..7c70fd2daab7223864be13ecc61ccc103faa84fc 100644 (file)
@@ -1309,7 +1309,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
         for(;;) {
           res = curl_easy_perform(curl);
 
-          if(config->content_disposition && outs.stream && !config->mute &&
+          if(outs.is_cd_filename && outs.stream && !config->mute &&
              outs.filename)
             printf("curl: Saved to filename '%s'\n", outs.filename);
 
index 7b129758810f2d9c7bb20c1014260ae39c295a36..da6253604af5f9dec01eb191bcc0f036f25bd87f 100644 (file)
@@ -34,6 +34,9 @@
  * 'alloc_filename' member is TRUE when string pointed by 'filename' has been
  * dynamically allocated and 'belongs' to this OutStruct, otherwise FALSE.
  *
+ * 'is_cd_filename' member is TRUE when string pointed by 'filename' has been
+ * set using a server-specified Content-Disposition filename, otherwise FALSE.
+ *
  * 's_isreg' member is TRUE when output goes to a regular file, this also
  * implies that output is 'seekable' and 'appendable' and also that member
  * 'filename' points to file name's string. For any standard stream member
@@ -57,6 +60,7 @@
 struct OutStruct {
   char *filename;
   bool alloc_filename;
+  bool is_cd_filename;
   bool s_isreg;
   bool fopened;
   FILE *stream;
index 60c10b094b3d6cdf61d4501bffedd0b12adb0c40..369fec17866d2d93e6d9d8942cb73a525e25904d 100644 (file)
 1361
 1362
 #
-1338
-1339
-#
 1370
 1371
 1385
 1393
 #
-1368
-1369
 1379
 1380
 1381