"James Gregory" <[EMAIL PROTECTED]> writes:

> I.e., [--header] is truncating some of the header arguments after
> commas, and ignoring other header arguments altogether.

Thanks for reporting this.  Here is a patch that fixes the problem:

2005-05-30  Hrvoje Niksic  <[EMAIL PROTECTED]>

        * init.c (cmd_spec_header): Don't split the string along the
        commas using cmd_vector; just append the new value using
        vec_append instead.

        * utils.c (vec_append): New function.

Index: src/init.c
===================================================================
RCS file: /pack/anoncvs/wget/src/init.c,v
retrieving revision 1.117
diff -u -r1.117 init.c
--- src/init.c  2005/05/30 12:52:44     1.117
+++ src/init.c  2005/05/30 13:28:23
@@ -162,7 +162,7 @@
   { "ftpproxy",                &opt.ftp_proxy,         cmd_string },
   { "ftpuser",         &opt.ftp_user,          cmd_string },
   { "glob",            &opt.ftp_glob,          cmd_boolean },
-  { "header",          &opt.user_headers,      cmd_spec_header },
+  { "header",          NULL,                   cmd_spec_header },
   { "htmlextension",   &opt.html_extension,    cmd_boolean },
   { "htmlify",         NULL,                   cmd_spec_htmlify },
   { "httpkeepalive",   &opt.http_keep_alive,   cmd_boolean },
@@ -1118,15 +1118,24 @@
 }
 
 static int
-cmd_spec_header (const char *com, const char *val, void *place)
+cmd_spec_header (const char *com, const char *val, void *place_ignored)
 {
+  /* Empty value means reset the list of headers. */
+  if (*val == '\0')
+    {
+      free_vec (opt.user_headers);
+      opt.user_headers = NULL;
+      return 1;
+    }
+
   if (!check_user_specified_header (val))
     {
       fprintf (stderr, _("%s: %s: Invalid header `%s'.\n"),
               exec_name, com, val);
       return 0;
     }
-  return cmd_vector (com, val, place);
+  opt.user_headers = vec_append (opt.user_headers, val);
+  return 1;
 }
 
 static int
Index: src/utils.c
===================================================================
RCS file: /pack/anoncvs/wget/src/utils.c,v
retrieving revision 1.99
diff -u -r1.99 utils.c
--- src/utils.c 2005/05/06 11:03:21     1.99
+++ src/utils.c 2005/05/30 13:28:27
@@ -1085,6 +1085,30 @@
   xfree (v2);
   return v1;
 }
+
+/* Append a freshly allocated copy of STR to VEC.  If VEC is NULL, it
+   is allocated as needed.  Return the new value of the vector. */
+
+char **
+vec_append (char **vec, const char *str)
+{
+  int cnt;                     /* count of vector elements, including
+                                  the one we're about to append */
+  if (vec != NULL)
+    {
+      for (cnt = 0; vec[cnt]; cnt++)
+       ;
+      ++cnt;
+    }
+  else
+    cnt = 1;
+  /* Reallocate the array to fit the new element and the NULL. */
+  vec = xrealloc (vec, (cnt + 1) * sizeof (char *));
+  /* Append a copy of STR to the vector. */
+  vec[cnt - 1] = xstrdup (str);
+  vec[cnt] = NULL;
+  return vec;
+}
 
 /* Sometimes it's useful to create "sets" of strings, i.e. special
    hash tables where you want to store strings as keys and merely
Index: src/utils.h
===================================================================
RCS file: /pack/anoncvs/wget/src/utils.h,v
retrieving revision 1.43
diff -u -r1.43 utils.h
--- src/utils.h 2005/04/24 20:00:19     1.43
+++ src/utils.h 2005/05/30 13:28:27
@@ -92,6 +92,7 @@
 
 void free_vec PARAMS ((char **));
 char **merge_vecs PARAMS ((char **, char **));
+char **vec_append PARAMS ((char **, const char *));
 
 void string_set_add PARAMS ((struct hash_table *, const char *));
 int string_set_contains PARAMS ((struct hash_table *, const char *));

Reply via email to