]> granicus.if.org Git - curl/commitdiff
Fixes allowing 26 more test cases in 1334 to 1393 range to succeed
authorYang Tse <yangsita@gmail.com>
Sat, 9 Jun 2012 03:42:39 +0000 (05:42 +0200)
committerYang Tse <yangsita@gmail.com>
Sat, 9 Jun 2012 03:49:49 +0000 (05:49 +0200)
src/tool_cb_hdr.c
src/tool_cb_hdr.h
src/tool_operate.c
tests/data/DISABLED

index ddc4c6638fc069870d3b86e8dcf87ca5fc654848..ef340f7983ce7b3b227df5b48bae3c61fafd30a2 100644 (file)
@@ -41,10 +41,9 @@ static char *parse_filename(const char *ptr, size_t len);
 
 size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
 {
-  HeaderData *hdrdata = userdata;
-  struct getout *urlnode = hdrdata->urlnode;
-  struct OutStruct *outs = hdrdata->outs;
-  struct OutStruct *heads = hdrdata->heads;
+  struct HdrCbData *hdrcbdata = userdata;
+  struct OutStruct *outs = hdrcbdata->outs;
+  struct OutStruct *heads = hdrcbdata->heads;
   const char *str = ptr;
   const size_t cb = size * nmemb;
   const char *end = (char*)ptr + cb;
@@ -57,39 +56,35 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
    */
   size_t failure = (size * nmemb) ? 0 : 1;
 
-  if(!outs->config)
+  if(!heads->config)
     return failure;
 
 #ifdef DEBUGBUILD
   if(size * nmemb > (size_t)CURL_MAX_HTTP_HEADER) {
-    warnf(outs->config, "Header data exceeds single call write limit!\n");
+    warnf(heads->config, "Header data exceeds single call write limit!\n");
     return failure;
   }
 #endif
-  /* --dump-header option */
-  if(outs->config->headerfile) {
-    fwrite(ptr, size, nmemb, heads->stream);
-  }
 
   /*
-  ** 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;
+   * Write header data when curl option --dump-header (-D) is given.
+   */
 
-  if(!checkprefix("http://", urlnode->url) &&
-     !checkprefix("https://", urlnode->url))
-    return cb;
+  if(heads->config->headerfile && heads->stream) {
+    size_t rc = fwrite(ptr, size, nmemb, heads->stream);
+    if(rc != cb)
+      return rc;
+  }
 
-  if(!(urlnode->flags & GETOUT_USEREMOTE))
-    return cb;
+  /*
+   * This callback sets the filename where output shall be written when
+   * curl options --remote-name (-O) and --remote-header-name (-J) have
+   * been simultaneously given and additionally server returns an HTTP
+   * Content-Disposition header specifying a filename property.
+   */
 
-  if((cb > 20) && checkprefix("Content-disposition:", str)) {
+  if(hdrcbdata->honor_cd_filename &&
+     (cb > 20) && checkprefix("Content-disposition:", str)) {
     const char *p = str + 20;
 
     /* look for the 'filename=' parameter
@@ -123,6 +118,7 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
         outs->s_isreg = TRUE;
         outs->fopened = FALSE;
         outs->stream = NULL;
+        hdrcbdata->honor_cd_filename = FALSE;
         break;
       }
       else
index 0300c0068ab0f3489a75ac241f63aa4ab408e19e..bd5043139300bdd7ab706855d0de4c2f4b95bf41 100644 (file)
  ***************************************************************************/
 #include "tool_setup.h"
 
-/* Structure to pass as userdata in tool_header_cb */
-typedef struct {
-  /* getout object pointer currently processing */
-  struct getout *urlnode;
-  /* output stream */
+/*
+ * curl operates using a single HdrCbData struct variable, a
+ * pointer to this is passed as userdata pointer to tool_header_cb.
+ *
+ * 'outs' member is a pointer to the OutStruct variable used to keep
+ * track of information relative to curl's output writing.
+ *
+ * 'heads' member is a pointer to the OutStruct variable used to keep
+ * track of information relative to header response writing.
+ *
+ * 'honor_cd_filename' member is TRUE when tool_header_cb is allowed
+ * to honor Content-Disposition filename property and accordingly
+ * set 'outs' filename, otherwise FALSE;
+ */
+
+struct HdrCbData {
   struct OutStruct *outs;
-  /* header output stream */
   struct OutStruct *heads;
-} HeaderData;
+  bool honor_cd_filename;
+};
 
 /*
 ** callback for CURLOPT_HEADERFUNCTION
index d01e38326914aa4147d7fb62c636123c1b377b7d..8a5569bd8a11883e2018170d6bf5e7335fb54ed5 100644 (file)
@@ -128,6 +128,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
   struct ProgressData progressbar;
   struct getout *urlnode;
 
+  struct HdrCbData hdrcbdata;
   struct OutStruct heads;
 
   metalinkfile *mlfile_last = NULL;
@@ -141,6 +142,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
 
   errorbuffer[0] = '\0';
   /* default headers output stream is stdout */
+  memset(&hdrcbdata, 0, sizeof(struct HdrCbData));
   memset(&heads, 0, sizeof(struct OutStruct));
   heads.stream = stdout;
   heads.config = config;
@@ -531,7 +533,6 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
         long retry_sleep_default;
         long retry_sleep;
         char *this_url;
-        HeaderData hdrdata;
         int metalink_next_res = 0;
 
         outfile = NULL;
@@ -1256,12 +1257,19 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
         if(config->proto_redir_present)
           my_setopt_flags(curl, CURLOPT_REDIR_PROTOCOLS, config->proto_redir);
 
-        hdrdata.urlnode = urlnode;
-        hdrdata.outs = &outs;
-        hdrdata.heads = &heads;
+        if(config->content_disposition
+           && (urlnode->flags & GETOUT_USEREMOTE)
+           && (checkprefix("http://", this_url) ||
+               checkprefix("https://", this_url)))
+          hdrcbdata.honor_cd_filename = TRUE;
+        else
+          hdrcbdata.honor_cd_filename = FALSE;
+
+        hdrcbdata.outs = &outs;
+        hdrcbdata.heads = &heads;
 
         my_setopt(curl, CURLOPT_HEADERFUNCTION, tool_header_cb);
-        my_setopt(curl, CURLOPT_HEADERDATA, &hdrdata);
+        my_setopt(curl, CURLOPT_HEADERDATA, &hdrcbdata);
 
         if(config->resolve)
           /* new in 7.21.3 */
@@ -1590,6 +1598,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
         if(outs.alloc_filename)
           Curl_safefree(outs.filename);
         memset(&outs, 0, sizeof(struct OutStruct));
+        hdrcbdata.outs = NULL;
 
         /* Free loop-local allocated memory and close loop-local opened fd */
 
@@ -1696,6 +1705,8 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
   easysrc_cleanup();
 #endif
 
+  hdrcbdata.heads = NULL;
+
   /* Close function-local opened file descriptors */
 
   if(heads.fopened && heads.stream)
index 369fec17866d2d93e6d9d8942cb73a525e25904d..4de3ff609aededc71f17e430f8de3c5b200d3e38 100644 (file)
@@ -9,34 +9,6 @@
 1355
 1363
 #
-1349
-1350
-1351
-1352
-1353
-1354
-1357
-1358
-1359
-1360
-1361
-1362
-#
-1370
-1371
 1385
 1393
 #
-1379
-1380
-1381
-1382
-1383
-1384
-1387
-1388
-1389
-1390
-1391
-1392
-#