fix -P w/ HTTP content disposition

Mauro Tortonesi <[email protected]> Wed, 27 Dec 2006 10:16:50 +0100
Newsgroups gmane.comp.web.wget.patches
Organization Ferrara Linux User Group
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------020407030906070609040902
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit


this patch fixes the behaviour of -P in case a HTTP Content-Disposition 
header is present.


2006-12-27  Mauro Tortonesi  <[email protected]>

        * http.c (parse_content_disposition): Consider directory prefix,
        if specified.

-- 
Aequam memento rebus in arduis servare mentem...

Mauro Tortonesi                          http://www.tortonesi.com

University of Ferrara - Dept. of Eng.    http://www.ing.unife.it
GNU Wget - HTTP/FTP file retrieval tool  http://www.gnu.org/software/wget
Deep Space 6 - IPv6 for Linux            http://www.deepspace6.net
Ferrara Linux User Group                 http://www.ferrara.linux.it

--------------020407030906070609040902
Content-Type: text/plain;
 name="fix-P.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="fix-P.diff"

Index: src/http.c
===================================================================
--- src/http.c	(revisione 2198)
+++ src/http.c	(copia locale)
@@ -966,6 +966,24 @@
           value.b = 1 + (last_slash ? last_slash : last_bs);
 	if (value.b == value.e)
 	  continue;
+        /* Start with the directory prefix, if specified. */
+        if (opt.dir_prefix)
+          {
+            int prefix_length = strlen (opt.dir_prefix);
+            bool add_slash = (opt.dir_prefix[prefix_length - 1] != '/');
+            int total_length;
+
+            if (add_slash) 
+              ++prefix_length;
+            total_length = prefix_length + (value.e - value.b);            
+            *filename = xmalloc (total_length + 1);
+            strcpy (*filename, opt.dir_prefix);
+            if (add_slash) 
+              (*filename)[prefix_length - 1] = '/';
+            memcpy (*filename + prefix_length, value.b, (value.e - value.b));
+            (*filename)[total_length] = '\0';
+          }
+        else
         *filename = strdupdelim (value.b, value.e);
         return true;
       }
@@ -3027,19 +3045,27 @@
   int i;
   struct {
     char *hdrval;    
+    char *opt_dir_prefix;
     char *filename;
     bool result;
   } test_array[] = {
-    { "filename=\"file.ext\"", "file.ext", true },
-    { "attachment; filename=\"file.ext\"", "file.ext", true },
-    { "attachment; filename=\"file.ext\"; dummy", "file.ext", true },
-    { "attachment", NULL, false },    
+    { "filename=\"file.ext\"", NULL, "file.ext", true },
+    { "filename=\"file.ext\"", "somedir", "somedir/file.ext", true },
+    { "attachment; filename=\"file.ext\"", NULL, "file.ext", true },
+    { "attachment; filename=\"file.ext\"", "somedir", "somedir/file.ext", true },
+    { "attachment; filename=\"file.ext\"; dummy", NULL, "file.ext", true },
+    { "attachment; filename=\"file.ext\"; dummy", "somedir", "somedir/file.ext", true },
+    { "attachment", NULL, NULL, false },
+    { "attachment", "somedir", NULL, false },
   };
   
   for (i = 0; i < sizeof(test_array)/sizeof(test_array[0]); ++i) 
     {
       char *filename;
-      bool res = parse_content_disposition (test_array[i].hdrval, &filename);
+      bool res;
+
+      opt.dir_prefix = test_array[i].opt_dir_prefix;
+      res = parse_content_disposition (test_array[i].hdrval, &filename);
 
       mu_assert ("test_parse_content_disposition: wrong result", 
                  res == test_array[i].result
Index: src/ChangeLog
===================================================================
--- src/ChangeLog	(revisione 2198)
+++ src/ChangeLog	(copia locale)
@@ -1,3 +1,8 @@
+2006-12-27  Mauro Tortonesi  <[email protected]>
+
+	* http.c (parse_content_disposition): Consider directory prefix, if
+	specified.
+
 2006-11-21  Hrvoje Niksic  <[email protected]>
 
 	* retr.c (retrieve_from_file): Ditto.

--------------020407030906070609040902--