]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Made -D option work with -O and -J.
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>
Fri, 25 May 2012 08:33:28 +0000 (17:33 +0900)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 25 May 2012 21:06:08 +0000 (23:06 +0200)
To achieve this, first new structure HeaderData is defined to hold
necessary data to perform header-related work.  Then tool_header_cb now
receives HeaderData pointer as userdata.  All header-related work
(currently, dumping header and Content-Disposition inspection) are done
in this callback function.  HeaderData.outs->config is used to determine
whether each work is done.

Unit tests were also updated because after this change, curl code always
sets CURLOPT_HEADERFUNCTION and CURLOPT_HEADERDATA.

Tested with -O -J -D, -O -J -i and -O -J -D -i and all worked fine.

src/tool_cb_hdr.c
src/tool_cb_hdr.h
src/tool_operate.c
tests/data/test1400
tests/data/test1401
tests/data/test1402
tests/data/test1403
tests/data/test1404
tests/data/test1405
tests/data/test1406
tests/data/test1407

index e963311773bf5365732e6a7e88ac46c0ed4636bc..738cd5dfc0751b3c29a7a63fe05e76e71141f168 100644 (file)
@@ -41,7 +41,10 @@ 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)
 {
-  struct OutStruct *outs = userdata;
+  HeaderData *hdrdata = userdata;
+  struct getout *urlnode = hdrdata->urlnode;
+  struct OutStruct *outs = hdrdata->outs;
+  struct OutStruct *heads = hdrdata->heads;
   const char *str = ptr;
   const size_t cb = size * nmemb;
   const char *end = (char*)ptr + cb;
@@ -63,8 +66,13 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
     return failure;
   }
 #endif
+  /* --dump-header option */
+  if(outs->config->headerfile) {
+    fwrite(ptr, size, nmemb, heads->stream);
+  }
 
-  if((cb > 20) && checkprefix("Content-disposition:", str)) {
+  if((urlnode->flags & GETOUT_USEREMOTE) && outs->config->content_disposition
+     && (cb > 20) && checkprefix("Content-disposition:", str)) {
     const char *p = str + 20;
 
     /* look for the 'filename=' parameter
index 5909336e6d09a7a9c551ce4eb9ea369852a75238..0300c0068ab0f3489a75ac241f63aa4ab408e19e 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 */
+  struct OutStruct *outs;
+  /* header output stream */
+  struct OutStruct *heads;
+} HeaderData;
+
 /*
 ** callback for CURLOPT_HEADERFUNCTION
 */
index e3d00213316e13550fa1d7a5393b78fee6bd177b..689ffb2d7d5aae02c2798167d3ec78227a9dd0f4 100644 (file)
@@ -504,6 +504,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
         long retry_sleep_default;
         long retry_sleep;
         char *this_url;
+        HeaderData hdrdata;
 
         outfile = NULL;
         infdopen = FALSE;
@@ -1211,17 +1212,12 @@ 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);
 
-        if((urlnode->flags & GETOUT_USEREMOTE)
-           && config->content_disposition) {
-          my_setopt(curl, CURLOPT_HEADERFUNCTION, tool_header_cb);
-          my_setopt(curl, CURLOPT_HEADERDATA, &outs);
-        }
-        else {
-          /* if HEADERFUNCTION was set to something in the previous loop, it
-             is important that we set it (back) to NULL now */
-          my_setopt(curl, CURLOPT_HEADERFUNCTION, NULL);
-          my_setopt(curl, CURLOPT_HEADERDATA, config->headerfile?&heads:NULL);
-        }
+        hdrdata.urlnode = urlnode;
+        hdrdata.outs = &outs;
+        hdrdata.heads = &heads;
+
+        my_setopt(curl, CURLOPT_HEADERFUNCTION, tool_header_cb);
+        my_setopt(curl, CURLOPT_HEADERDATA, &hdrdata);
 
         if(config->resolve)
           /* new in 7.21.3 */
index 59b2856dd5b6463f88700fa416da981cbf4e9ad1..72989c4c4a807e952fe0d85e06382ab2e51ba120 100644 (file)
@@ -85,6 +85,8 @@ int main(int argc, char *argv[])
   CURLOPT_STDERR set to a objectpointer
   CURLOPT_DEBUGFUNCTION set to a functionpointer
   CURLOPT_DEBUGDATA set to a objectpointer
+  CURLOPT_HEADERFUNCTION set to a functionpointer
+  CURLOPT_HEADERDATA set to a objectpointer
 
   */
 
index e094ec456032493a26f75e018bf0b8aa2a7d13e5..e709c8e08d65c2862ae1dd66dc9dbd6e3adbbfc5 100644 (file)
@@ -104,6 +104,8 @@ int main(int argc, char *argv[])
   CURLOPT_STDERR set to a objectpointer
   CURLOPT_DEBUGFUNCTION set to a functionpointer
   CURLOPT_DEBUGDATA set to a objectpointer
+  CURLOPT_HEADERFUNCTION set to a functionpointer
+  CURLOPT_HEADERDATA set to a objectpointer
 
   */
 
index d56779207bce8511869e871c2b83e969515710fb..c3bf834bde30a3b9d8f31a32a30edf5aceb73c75 100644 (file)
@@ -92,6 +92,8 @@ int main(int argc, char *argv[])
   CURLOPT_STDERR set to a objectpointer
   CURLOPT_DEBUGFUNCTION set to a functionpointer
   CURLOPT_DEBUGDATA set to a objectpointer
+  CURLOPT_HEADERFUNCTION set to a functionpointer
+  CURLOPT_HEADERDATA set to a objectpointer
 
   */
 
index 3e4a03440fad5aac2e2ffa070f5112bd68984659..3ec7dd032fd790ed687173bfccccf0dfb3ceee10 100644 (file)
@@ -87,6 +87,8 @@ int main(int argc, char *argv[])
   CURLOPT_STDERR set to a objectpointer
   CURLOPT_DEBUGFUNCTION set to a functionpointer
   CURLOPT_DEBUGDATA set to a objectpointer
+  CURLOPT_HEADERFUNCTION set to a functionpointer
+  CURLOPT_HEADERDATA set to a objectpointer
 
   */
 
index f856a74163f39b4a5a4857708dd82010d7927b8c..88a06ba39c3d7394ffde85343653ebf47a124358 100644 (file)
@@ -141,6 +141,8 @@ int main(int argc, char *argv[])
   CURLOPT_STDERR set to a objectpointer
   CURLOPT_DEBUGFUNCTION set to a functionpointer
   CURLOPT_DEBUGDATA set to a objectpointer
+  CURLOPT_HEADERFUNCTION set to a functionpointer
+  CURLOPT_HEADERDATA set to a objectpointer
 
   */
 
index 187f8498346603087e4ddc0844d3e7f2fae40ee4..692bb1af77fe5601aab018097c24da2531eba74b 100644 (file)
@@ -103,6 +103,8 @@ int main(int argc, char *argv[])
   CURLOPT_STDERR set to a objectpointer
   CURLOPT_DEBUGFUNCTION set to a functionpointer
   CURLOPT_DEBUGDATA set to a objectpointer
+  CURLOPT_HEADERFUNCTION set to a functionpointer
+  CURLOPT_HEADERDATA set to a objectpointer
 
   */
 
index 216d68e81132783803c7b0d34be2438b07344b9b..478e45ff394daa1ca29082795ffcc4ad05a78ed3 100644 (file)
@@ -95,6 +95,8 @@ int main(int argc, char *argv[])
   CURLOPT_STDERR set to a objectpointer
   CURLOPT_DEBUGFUNCTION set to a functionpointer
   CURLOPT_DEBUGDATA set to a objectpointer
+  CURLOPT_HEADERFUNCTION set to a functionpointer
+  CURLOPT_HEADERDATA set to a objectpointer
 
   */
 
index ab25a30a3cf9f6a13e18553d48d787d3428cfeca..0b40a4732a73e90625d36cbc75a3fe05c707151a 100644 (file)
@@ -75,6 +75,8 @@ int main(int argc, char *argv[])
   CURLOPT_STDERR set to a objectpointer
   CURLOPT_DEBUGFUNCTION set to a functionpointer
   CURLOPT_DEBUGDATA set to a objectpointer
+  CURLOPT_HEADERFUNCTION set to a functionpointer
+  CURLOPT_HEADERDATA set to a objectpointer
 
   */