]> sjero.net Git - wget/blobdiff - src/init.c
[svn] Allow --header to contain ",".
[wget] / src / init.c
index b70a7c6efcd1de88400c6c9eeabf593f2c833089..b6347aa5ecf8cc6804f99c50fe2ea37a220f3224 100644 (file)
@@ -105,7 +105,7 @@ CMD_DECLARE (cmd_spec_useragent);
    function.  When adding a new command, simply add it to the list,
    but be sure to keep the list sorted alphabetically, as
    command_by_name depends on it.  Also, be sure to add any entries
-   that allocate memory (e.g. cmd_string and cmd_vector guys) to the
+   that allocate memory (e.g. cmd_string and cmd_vector) to the
    cleanup() function below. */
 
 static struct {
@@ -159,10 +159,10 @@ static struct {
   { "forcehtml",       &opt.force_html,        cmd_boolean },
   { "ftppasswd",       &opt.ftp_passwd,        cmd_string }, /* deprecated */
   { "ftppassword",     &opt.ftp_passwd,        cmd_string },
-  { "ftpuser",         &opt.ftp_user,          cmd_string },
   { "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 },
@@ -612,7 +612,7 @@ static int
 setval_internal (int comind, const char *com, const char *val)
 {
   assert (0 <= comind && comind < countof (commands));
-  DEBUGP (("Setting %s (%d) to %s\n", com, comind, val));
+  DEBUGP (("Setting %s (%s) to %s\n", com, commands[comind].name, val));
   return ((*commands[comind].action) (com, val, commands[comind].place));
 }
 
@@ -649,16 +649,15 @@ run_command (const char *opt)
 {
   char *com, *val;
   int comind;
-  int status = parse_line (opt, &com, &val, &comind);
-  if (status == 1)
+  switch (parse_line (opt, &com, &val, &comind))
     {
+    case line_ok:
       if (!setval_internal (comind, com, val))
        exit (2);
       xfree (com);
       xfree (val);
-    }
-  else if (status == 0)
-    {
+      break;
+    default:
       fprintf (stderr, _("%s: Invalid --execute command `%s'\n"),
               exec_name, opt);
       exit (2);
@@ -1119,15 +1118,24 @@ cmd_spec_dirstruct (const char *com, const char *val, void *place_ignored)
 }
 
 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
@@ -1292,9 +1300,8 @@ cmd_spec_timeout (const char *com, const char *val, void *place_ignored)
 static int
 cmd_spec_useragent (const char *com, const char *val, void *place_ignored)
 {
-  /* Just check for empty string and newline, so we don't throw total
-     junk to the server.  */
-  if (!*val || strchr (val, '\n'))
+  /* Disallow embedded newlines.  */
+  if (strchr (val, '\n'))
     {
       fprintf (stderr, _("%s: %s: Invalid value `%s'.\n"),
               exec_name, com, val);
@@ -1496,7 +1503,6 @@ cleanup (void)
   free_vec (opt.follow_tags);
   free_vec (opt.ignore_tags);
   xfree_null (opt.progress_type);
-  xfree (opt.ftp_acc);
   xfree_null (opt.ftp_user);
   xfree_null (opt.ftp_passwd);
   xfree_null (opt.ftp_proxy);
@@ -1511,6 +1517,10 @@ cleanup (void)
 # ifdef HAVE_SSL
   xfree_null (opt.cert_file);
   xfree_null (opt.private_key);
+  xfree_null (opt.ca_directory);
+  xfree_null (opt.ca_cert);
+  xfree_null (opt.random_file);
+  xfree_null (opt.egd_file);
 # endif
   xfree_null (opt.bind_address);
   xfree_null (opt.cookies_input);