]> sjero.net Git - wget/blobdiff - src/init.c
[svn] Added support for cookies.
[wget] / src / init.c
index 321f50d4bf7d63ada9e695b2f6f898c6e989acda..035a24c34f035aefcf4fa36649031f91e769814b 100644 (file)
@@ -20,7 +20,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <config.h>
 
 #include <stdio.h>
-#include <ctype.h>
 #include <sys/types.h>
 #include <stdlib.h>
 #ifdef HAVE_UNISTD_H
@@ -100,6 +99,7 @@ static struct {
   { "cache",           &opt.proxy_cache,       cmd_boolean },
   { "continue",                &opt.always_rest,       cmd_boolean },
   { "convertlinks",    &opt.convert_links,     cmd_boolean },
+  { "cookies",         &opt.cookies,           cmd_boolean },
   { "cutdirs",         &opt.cut_dirs,          cmd_number },
 #ifdef DEBUG
   { "debug",           &opt.debug,             cmd_boolean },
@@ -125,13 +125,14 @@ static struct {
   { "httpkeepalive",   &opt.http_keep_alive,   cmd_boolean },
   { "httppasswd",      &opt.http_passwd,       cmd_string },
   { "httpproxy",       &opt.http_proxy,        cmd_string },
-  { "httpuser",                &opt.http_user,         cmd_string },
   { "httpsproxy",      &opt.https_proxy,       cmd_string },
+  { "httpuser",                &opt.http_user,         cmd_string },
   { "ignorelength",    &opt.ignore_length,     cmd_boolean },
   { "ignoretags",      &opt.ignore_tags,       cmd_vector },
   { "includedirectories", &opt.includes,       cmd_directory_vector },
   { "input",           &opt.input_filename,    cmd_string },
   { "killlonger",      &opt.kill_longer,       cmd_boolean },
+  { "loadcookies",     &opt.cookies_input,     cmd_string },
   { "logfile",         &opt.lfilename,         cmd_string },
   { "login",           &opt.ftp_acc,           cmd_string },
   { "mirror",          NULL,                   cmd_spec_mirror },
@@ -156,6 +157,7 @@ static struct {
   { "removelisting",   &opt.remove_listing,    cmd_boolean },
   { "retrsymlinks",    &opt.retr_symlinks,     cmd_boolean },
   { "robots",          &opt.use_robots,        cmd_boolean },
+  { "savecookies",     &opt.cookies_output,    cmd_string },
   { "saveheaders",     &opt.save_headers,      cmd_boolean },
   { "serverresponse",  &opt.server_response,   cmd_boolean },
   { "simplehostcheck", &opt.simple_check,      cmd_boolean },
@@ -210,6 +212,8 @@ defaults (void)
      of the implementors' worries.  */
   memset (&opt, 0, sizeof (opt));
 
+  opt.cookies = 1;
+
   opt.verbose = -1;
   opt.dir_prefix = xstrdup (".");
   opt.ntry = 20;
@@ -492,12 +496,21 @@ setval (const char *com, const char *val)
 
 static int myatoi PARAMS ((const char *s));
 
-/* Store the address (specified as hostname or dotted-quad IP address) from VAL
-   to CLOSURE.  COM is ignored, except for error messages.  */
+/* Interpret VAL as an Internet address (a hostname or a dotted-quad
+   IP address), and write it (in network order) to a malloc-allocated
+   address.  That address gets stored to the memory pointed to by
+   CLOSURE.  COM is ignored, except for error messages.
+
+   #### IMHO it's a mistake to do this kind of work so early in the
+   process (before any download even started!)  opt.bind_address
+   should simply remember the provided value as a string.  Another
+   function should do the lookup, when needed, and cache the
+   result.  --hniksic  */
 static int
 cmd_address (const char *com, const char *val, void *closure)
 {
   struct sockaddr_in sin;
+  struct sockaddr_in **target = (struct sockaddr_in **)closure;
 
   if (!store_hostaddress ((unsigned char *)&sin.sin_addr, val))
     {
@@ -509,7 +522,10 @@ cmd_address (const char *com, const char *val, void *closure)
   sin.sin_family = AF_INET;
   sin.sin_port = 0;
 
-  memcpy (closure, &sin, sizeof (sin));
+  FREE_MAYBE (*target);
+
+  *target = xmalloc (sizeof (sin));
+  memcpy (*target, &sin, sizeof (sin));
 
   return 1;
 }
@@ -996,6 +1012,7 @@ cleanup (void)
     fclose (opt.dfp);
   cleanup_html_url ();
   downloaded_files_free ();
+  cookies_cleanup ();
   FREE_MAYBE (opt.lfilename);
   xfree (opt.dir_prefix);
   FREE_MAYBE (opt.input_filename);
@@ -1022,4 +1039,7 @@ cleanup (void)
   FREE_MAYBE (opt.sslcertkey);
   FREE_MAYBE (opt.sslcertfile);
 #endif /* HAVE_SSL */
+  FREE_MAYBE (opt.bind_address);
+  FREE_MAYBE (opt.cookies_input);
+  FREE_MAYBE (opt.cookies_output);
 }