1 /* Reading/parsing the initialization file.
2 Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Wget.
7 GNU Wget is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GNU Wget is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Wget; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include <sys/types.h>
39 # include <sys/socket.h>
40 # include <netinet/in.h>
41 # include <arpa/inet.h>
54 #include "cookies.h" /* for cookies_cleanup */
60 /* We want tilde expansion enabled only when reading `.wgetrc' lines;
61 otherwise, it will be performed by the shell. This variable will
62 be set by the wgetrc-reading function. */
64 static int enable_tilde_expansion;
67 #define CMD_DECLARE(func) static int func \
68 PARAMS ((const char *, const char *, void *))
70 CMD_DECLARE (cmd_address);
71 CMD_DECLARE (cmd_boolean);
72 CMD_DECLARE (cmd_bytes);
73 CMD_DECLARE (cmd_directory_vector);
74 CMD_DECLARE (cmd_lockable_boolean);
75 CMD_DECLARE (cmd_number);
76 CMD_DECLARE (cmd_number_inf);
77 CMD_DECLARE (cmd_string);
78 CMD_DECLARE (cmd_file);
79 CMD_DECLARE (cmd_time);
80 CMD_DECLARE (cmd_vector);
82 CMD_DECLARE (cmd_spec_dirstruct);
83 CMD_DECLARE (cmd_spec_dotstyle);
84 CMD_DECLARE (cmd_spec_header);
85 CMD_DECLARE (cmd_spec_htmlify);
86 CMD_DECLARE (cmd_spec_mirror);
87 CMD_DECLARE (cmd_spec_recursive);
88 CMD_DECLARE (cmd_spec_useragent);
90 /* List of recognized commands, each consisting of name, closure and function.
91 When adding a new command, simply add it to the list, but be sure to keep the
92 list sorted alphabetically, as comind() depends on it. Also, be sure to add
93 any entries that allocate memory (e.g. cmd_string and cmd_vector guys) to the
94 cleanup() function below. */
98 int (*action) PARAMS ((const char *, const char *, void *));
100 { "accept", &opt.accepts, cmd_vector },
101 { "addhostdir", &opt.add_hostdir, cmd_boolean },
102 { "alwaysrest", &opt.always_rest, cmd_boolean }, /* deprecated */
103 { "background", &opt.background, cmd_boolean },
104 { "backupconverted", &opt.backup_converted, cmd_boolean },
105 { "backups", &opt.backups, cmd_number },
106 { "base", &opt.base_href, cmd_string },
107 { "bindaddress", &opt.bind_address, cmd_address },
108 { "cache", &opt.allow_cache, cmd_boolean },
109 { "continue", &opt.always_rest, cmd_boolean },
110 { "convertlinks", &opt.convert_links, cmd_boolean },
111 { "cookies", &opt.cookies, cmd_boolean },
112 { "cutdirs", &opt.cut_dirs, cmd_number },
114 { "debug", &opt.debug, cmd_boolean },
116 { "deleteafter", &opt.delete_after, cmd_boolean },
117 { "dirprefix", &opt.dir_prefix, cmd_file },
118 { "dirstruct", NULL, cmd_spec_dirstruct },
119 { "domains", &opt.domains, cmd_vector },
120 { "dotbytes", &opt.dot_bytes, cmd_bytes },
121 { "dotsinline", &opt.dots_in_line, cmd_number },
122 { "dotspacing", &opt.dot_spacing, cmd_number },
123 { "dotstyle", NULL, cmd_spec_dotstyle },
124 { "excludedirectories", &opt.excludes, cmd_directory_vector },
125 { "excludedomains", &opt.exclude_domains, cmd_vector },
126 { "followftp", &opt.follow_ftp, cmd_boolean },
127 { "followtags", &opt.follow_tags, cmd_vector },
128 { "forcehtml", &opt.force_html, cmd_boolean },
129 { "ftpproxy", &opt.ftp_proxy, cmd_string },
130 { "glob", &opt.ftp_glob, cmd_boolean },
131 { "header", NULL, cmd_spec_header },
132 { "htmlextension", &opt.html_extension, cmd_boolean },
133 { "htmlify", NULL, cmd_spec_htmlify },
134 { "httpkeepalive", &opt.http_keep_alive, cmd_boolean },
135 { "httppasswd", &opt.http_passwd, cmd_string },
136 { "httpproxy", &opt.http_proxy, cmd_string },
137 { "httpsproxy", &opt.https_proxy, cmd_string },
138 { "httpuser", &opt.http_user, cmd_string },
139 { "ignorelength", &opt.ignore_length, cmd_boolean },
140 { "ignoretags", &opt.ignore_tags, cmd_vector },
141 { "includedirectories", &opt.includes, cmd_directory_vector },
142 { "input", &opt.input_filename, cmd_file },
143 { "killlonger", &opt.kill_longer, cmd_boolean },
144 { "loadcookies", &opt.cookies_input, cmd_file },
145 { "logfile", &opt.lfilename, cmd_file },
146 { "login", &opt.ftp_acc, cmd_string },
147 { "mirror", NULL, cmd_spec_mirror },
148 { "netrc", &opt.netrc, cmd_boolean },
149 { "noclobber", &opt.noclobber, cmd_boolean },
150 { "noparent", &opt.no_parent, cmd_boolean },
151 { "noproxy", &opt.no_proxy, cmd_vector },
152 { "numtries", &opt.ntry, cmd_number_inf },/* deprecated*/
153 { "outputdocument", &opt.output_document, cmd_file },
154 { "pagerequisites", &opt.page_requisites, cmd_boolean },
155 { "passiveftp", &opt.ftp_pasv, cmd_lockable_boolean },
156 { "passwd", &opt.ftp_pass, cmd_string },
157 { "proxypasswd", &opt.proxy_passwd, cmd_string },
158 { "proxyuser", &opt.proxy_user, cmd_string },
159 { "quiet", &opt.quiet, cmd_boolean },
160 { "quota", &opt.quota, cmd_bytes },
161 { "reclevel", &opt.reclevel, cmd_number_inf },
162 { "recursive", NULL, cmd_spec_recursive },
163 { "referer", &opt.referer, cmd_string },
164 { "reject", &opt.rejects, cmd_vector },
165 { "relativeonly", &opt.relative_only, cmd_boolean },
166 { "removelisting", &opt.remove_listing, cmd_boolean },
167 { "retrsymlinks", &opt.retr_symlinks, cmd_boolean },
168 { "robots", &opt.use_robots, cmd_boolean },
169 { "savecookies", &opt.cookies_output, cmd_file },
170 { "saveheaders", &opt.save_headers, cmd_boolean },
171 { "serverresponse", &opt.server_response, cmd_boolean },
172 { "simplehostcheck", &opt.simple_check, cmd_boolean },
173 { "spanhosts", &opt.spanhost, cmd_boolean },
174 { "spider", &opt.spider, cmd_boolean },
176 { "sslcertfile", &opt.sslcertfile, cmd_file },
177 { "sslcertkey", &opt.sslcertkey, cmd_file },
178 #endif /* HAVE_SSL */
179 { "timeout", &opt.timeout, cmd_time },
180 { "timestamping", &opt.timestamping, cmd_boolean },
181 { "tries", &opt.ntry, cmd_number_inf },
182 { "useproxy", &opt.use_proxy, cmd_boolean },
183 { "useragent", NULL, cmd_spec_useragent },
184 { "verbose", &opt.verbose, cmd_boolean },
185 { "wait", &opt.wait, cmd_time },
186 { "waitretry", &opt.waitretry, cmd_time }
189 /* Return index of COM if it is a valid command, or -1 otherwise. COM
190 is looked up in `commands' using binary search algorithm. */
192 comind (const char *com)
194 int min = 0, max = ARRAY_SIZE (commands) - 1;
198 int i = (min + max) / 2;
199 int cmp = strcasecmp (com, commands[i].name);
211 /* Reset the variables to default values. */
217 /* Most of the default values are 0. Just reset everything, and
218 fill in the non-zero values. Note that initializing pointers to
219 NULL this way is technically illegal, but porting Wget to a
220 machine where NULL is not all-zero bit pattern will be the least
221 of the implementors' worries. */
222 memset (&opt, 0, sizeof (opt));
227 opt.dir_prefix = xstrdup (".");
231 opt.ftp_acc = xstrdup ("anonymous");
232 opt.ftp_pass = xstrdup ("-wget@");
236 opt.http_keep_alive = 1;
238 tmp = getenv ("no_proxy");
240 opt.no_proxy = sepstring (tmp);
248 opt.remove_listing = 1;
250 opt.dot_bytes = 1024;
251 opt.dot_spacing = 10;
252 opt.dots_in_line = 50;
255 /* Return the user's home directory (strdup-ed), or NULL if none is
260 char *home = getenv ("HOME");
265 /* If HOME is not defined, try getting it from the password
267 struct passwd *pwd = getpwuid (getuid ());
268 if (!pwd || !pwd->pw_dir)
273 /* #### Maybe I should grab home_dir from registry, but the best
274 that I could get from there is user's Start menu. It sucks! */
278 return home ? xstrdup (home) : NULL;
281 /* Return the path to the user's .wgetrc. This is either the value of
282 `WGETRC' environment variable, or `$HOME/.wgetrc'.
284 If the `WGETRC' variable exists but the file does not exist, the
285 function will exit(). */
287 wgetrc_file_name (void)
292 /* Try the environment. */
293 env = getenv ("WGETRC");
296 if (!file_exists_p (env))
298 fprintf (stderr, "%s: %s: %s.\n", exec_name, file, strerror (errno));
301 return xstrdup (env);
305 /* If that failed, try $HOME/.wgetrc. */
309 file = (char *)xmalloc (strlen (home) + 1 + strlen (".wgetrc") + 1);
310 sprintf (file, "%s/.wgetrc", home);
314 /* Under Windows, "home" is (for the purposes of this function) the
315 directory where `wget.exe' resides, and `wget.ini' will be used
316 as file name. SYSTEM_WGETRC should not be defined under WINDOWS.
318 It is not as trivial as I assumed, because on 95 argv[0] is full
319 path, but on NT you get what you typed in command line. --dbudor */
323 file = (char *)xmalloc (strlen (home) + strlen ("wget.ini") + 1);
324 sprintf (file, "%swget.ini", home);
330 if (!file_exists_p (file))
338 /* Initialize variables from a wgetrc file */
340 run_wgetrc (const char *file)
346 fp = fopen (file, "rb");
349 fprintf (stderr, _("%s: Cannot read %s (%s).\n"), exec_name,
350 file, strerror (errno));
353 enable_tilde_expansion = 1;
355 while ((line = read_whole_line (fp)))
360 /* Parse the line. */
361 status = parse_line (line, &com, &val);
363 /* If everything is OK, set the value. */
366 if (!setval (com, val))
367 fprintf (stderr, _("%s: Error in %s at line %d.\n"), exec_name,
372 else if (status == 0)
373 fprintf (stderr, _("%s: Error in %s at line %d.\n"), exec_name,
377 enable_tilde_expansion = 0;
381 /* Initialize the defaults and run the system wgetrc and user's own
388 /* Load the hard-coded defaults. */
391 /* If SYSTEM_WGETRC is defined, use it. */
393 if (file_exists_p (SYSTEM_WGETRC))
394 run_wgetrc (SYSTEM_WGETRC);
396 /* Override it with your own, if one exists. */
397 file = wgetrc_file_name ();
400 /* #### We should somehow canonicalize `file' and SYSTEM_WGETRC,
403 if (!strcmp (file, SYSTEM_WGETRC))
405 fprintf (stderr, _("\
406 %s: Warning: Both system and user wgetrc point to `%s'.\n"),
416 /* Parse the line pointed by line, with the syntax:
417 <sp>* command <sp>* = <sp>* value <newline>
418 Uses malloc to allocate space for command and value.
419 If the line is invalid, data is freed and 0 is returned.
426 parse_line (const char *line, char **com, char **val)
428 const char *p = line;
429 const char *orig_comptr, *end;
432 /* Skip whitespace. */
433 while (*p && ISSPACE (*p))
436 /* Don't process empty lines. */
437 if (!*p || *p == '#')
440 for (orig_comptr = p; ISALPHA (*p) || *p == '_' || *p == '-'; p++)
442 /* The next char should be space or '='. */
443 if (!ISSPACE (*p) && (*p != '='))
445 /* Here we cannot use strdupdelim() as we normally would because we
446 want to skip the `-' and `_' characters in the input string. */
447 *com = (char *)xmalloc (p - orig_comptr + 1);
448 for (new_comptr = *com; orig_comptr < p; orig_comptr++)
450 if (*orig_comptr == '_' || *orig_comptr == '-')
452 *new_comptr++ = *orig_comptr;
455 /* If the command is invalid, exit now. */
456 if (comind (*com) == -1)
462 /* Skip spaces before '='. */
463 for (; ISSPACE (*p); p++);
464 /* If '=' not found, bail out. */
470 /* Skip spaces after '='. */
471 for (++p; ISSPACE (*p); p++);
472 /* Get the ending position for VAL by starting with the end of the
473 line and skipping whitespace. */
474 end = line + strlen (line) - 1;
475 while (end > p && ISSPACE (*end))
477 *val = strdupdelim (p, end + 1);
481 /* Set COM to VAL. This is the meat behind processing `.wgetrc'. No
482 fatals -- error signal prints a warning and resets to default
483 value. All error messages are printed to stderr, *not* to
484 opt.lfile, since opt.lfile wasn't even generated yet. */
486 setval (const char *com, const char *val)
495 /* #### Should I just abort()? */
497 fprintf (stderr, _("%s: BUG: unknown command `%s', value `%s'.\n"),
498 exec_name, com, val);
502 return ((*commands[ind].action) (com, val, commands[ind].closure));
505 /* Generic helper functions, for use with `commands'. */
507 static int myatoi PARAMS ((const char *s));
509 /* Interpret VAL as an Internet address (a hostname or a dotted-quad
510 IP address), and write it (in network order) to a malloc-allocated
511 address. That address gets stored to the memory pointed to by
512 CLOSURE. COM is ignored, except for error messages.
514 #### IMHO it's a mistake to do this kind of work so early in the
515 process (before any download even started!) opt.bind_address
516 should simply remember the provided value as a string. Another
517 function should do the lookup, when needed, and cache the
520 cmd_address (const char *com, const char *val, void *closure)
522 struct sockaddr_in sin;
523 struct sockaddr_in **target = (struct sockaddr_in **)closure;
525 memset (&sin, '\0', sizeof (sin));
527 if (!store_hostaddress ((unsigned char *)&sin.sin_addr, val))
529 fprintf (stderr, _("%s: %s: Cannot convert `%s' to an IP address.\n"),
530 exec_name, com, val);
533 sin.sin_family = AF_INET;
536 FREE_MAYBE (*target);
538 *target = xmalloc (sizeof (sin));
539 memcpy (*target, &sin, sizeof (sin));
544 /* Store the boolean value from VAL to CLOSURE. COM is ignored,
545 except for error messages. */
547 cmd_boolean (const char *com, const char *val, void *closure)
551 if (!strcasecmp (val, "on")
552 || (*val == '1' && !*(val + 1)))
554 else if (!strcasecmp (val, "off")
555 || (*val == '0' && !*(val + 1)))
559 fprintf (stderr, _("%s: %s: Please specify on or off.\n"),
564 *(int *)closure = bool_value;
568 /* Store the lockable_boolean {2, 1, 0, -1} value from VAL to CLOSURE. COM is
569 ignored, except for error messages. Values 2 and -1 indicate that once
570 defined, the value may not be changed by successive wgetrc files or
571 command-line arguments.
573 Values: 2 - Enable a particular option for good ("always")
574 1 - Enable an option ("on")
575 0 - Disable an option ("off")
576 -1 - Disable an option for good ("never") */
578 cmd_lockable_boolean (const char *com, const char *val, void *closure)
580 int lockable_boolean_value;
583 * If a config file said "always" or "never", don't allow command line
584 * arguments to override the config file.
586 if (*(int *)closure == -1 || *(int *)closure == 2)
589 if (!strcasecmp (val, "always")
590 || (*val == '2' && !*(val + 1)))
591 lockable_boolean_value = 2;
592 else if (!strcasecmp (val, "on")
593 || (*val == '1' && !*(val + 1)))
594 lockable_boolean_value = 1;
595 else if (!strcasecmp (val, "off")
596 || (*val == '0' && !*(val + 1)))
597 lockable_boolean_value = 0;
598 else if (!strcasecmp (val, "never")
599 || (*val == '-' && *(val + 1) == '1' && !*(val + 2)))
600 lockable_boolean_value = -1;
603 fprintf (stderr, _("%s: %s: Please specify always, on, off, "
609 *(int *)closure = lockable_boolean_value;
613 /* Set the non-negative integer value from VAL to CLOSURE. With
614 incorrect specification, the number remains unchanged. */
616 cmd_number (const char *com, const char *val, void *closure)
618 int num = myatoi (val);
622 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
623 exec_name, com, val);
626 *(int *)closure = num;
630 /* Similar to cmd_number(), only accepts `inf' as a synonym for 0. */
632 cmd_number_inf (const char *com, const char *val, void *closure)
634 if (!strcasecmp (val, "inf"))
639 return cmd_number (com, val, closure);
642 /* Copy (strdup) the string at COM to a new location and place a
643 pointer to *CLOSURE. */
645 cmd_string (const char *com, const char *val, void *closure)
647 char **pstring = (char **)closure;
649 FREE_MAYBE (*pstring);
650 *pstring = xstrdup (val);
654 /* Like the above, but handles tilde-expansion when reading a user's
655 `.wgetrc'. In that case, and if VAL begins with `~', the tilde
656 gets expanded to the user's home directory. */
658 cmd_file (const char *com, const char *val, void *closure)
660 char **pstring = (char **)closure;
662 FREE_MAYBE (*pstring);
663 if (!enable_tilde_expansion || !(*val == '~' && *(val + 1) == '/'))
666 *pstring = xstrdup (val);
672 char *home = home_dir ();
676 homelen = strlen (home);
677 while (homelen && home[homelen - 1] == '/')
678 home[--homelen] = '\0';
680 /* Skip the leading "~/". */
681 for (++val; *val == '/'; val++)
684 result = xmalloc (homelen + 1 + strlen (val));
685 memcpy (result, home, homelen);
686 result[homelen] = '/';
687 strcpy (result + homelen + 1, val);
694 /* Merge the vector (array of strings separated with `,') in COM with
695 the vector (NULL-terminated array of strings) pointed to by
698 cmd_vector (const char *com, const char *val, void *closure)
700 char ***pvec = (char ***)closure;
703 *pvec = merge_vecs (*pvec, sepstring (val));
713 cmd_directory_vector (const char *com, const char *val, void *closure)
715 char ***pvec = (char ***)closure;
719 /* Strip the trailing slashes from directories. */
722 seps = sepstring (val);
723 for (t = seps; t && *t; t++)
725 int len = strlen (*t);
726 /* Skip degenerate case of root directory. */
729 if ((*t)[len - 1] == '/')
730 (*t)[len - 1] = '\0';
733 *pvec = merge_vecs (*pvec, seps);
743 /* Set the value stored in VAL to CLOSURE (which should point to a
744 long int), allowing several postfixes, with the following syntax
748 [0-9]+[kK] -> bytes * 1024
749 [0-9]+[mM] -> bytes * 1024 * 1024
752 Anything else is flagged as incorrect, and CLOSURE is unchanged. */
754 cmd_bytes (const char *com, const char *val, void *closure)
757 long *out = (long *)closure;
762 /* Check for "inf". */
763 if (p[0] == 'i' && p[1] == 'n' && p[2] == 'f' && p[3] == '\0')
768 /* Search for digits and construct result. */
769 for (; *p && ISDIGIT (*p); p++)
770 result = (10 * result) + (*p - '0');
771 /* If no digits were found, or more than one character is following
773 if (p == val || (*p != '\0' && *(p + 1) != '\0'))
775 printf (_("%s: Invalid specification `%s'\n"), com, val);
778 /* Search for a designator. */
779 switch (TOLOWER (*p))
790 result *= (long)1024 * 1024;
794 result *= (long)1024 * 1024 * 1024;
797 printf (_("%s: Invalid specification `%s'\n"), com, val);
804 /* Store the value of VAL to *OUT, allowing suffixes for minutes and
807 cmd_time (const char *com, const char *val, void *closure)
812 /* Search for digits and construct result. */
813 for (; *p && ISDIGIT (*p); p++)
814 result = (10 * result) + (*p - '0');
815 /* If no digits were found, or more than one character is following
817 if (p == val || (*p != '\0' && *(p + 1) != '\0'))
819 printf (_("%s: Invalid specification `%s'\n"), com, val);
822 /* Search for a suffix. */
823 switch (TOLOWER (*p))
837 /* Days (overflow on 16bit machines) */
845 printf (_("%s: Invalid specification `%s'\n"), com, val);
848 *(long *)closure = result;
852 /* Specialized helper functions, used by `commands' to handle some
853 options specially. */
855 static int check_user_specified_header PARAMS ((const char *));
858 cmd_spec_dirstruct (const char *com, const char *val, void *closure)
860 if (!cmd_boolean (com, val, &opt.dirstruct))
862 /* Since dirstruct behaviour is explicitly changed, no_dirstruct
863 must be affected inversely. */
865 opt.no_dirstruct = 0;
867 opt.no_dirstruct = 1;
872 cmd_spec_dotstyle (const char *com, const char *val, void *closure)
874 /* Retrieval styles. */
875 if (!strcasecmp (val, "default"))
877 /* Default style: 1K dots, 10 dots in a cluster, 50 dots in a
879 opt.dot_bytes = 1024;
880 opt.dot_spacing = 10;
881 opt.dots_in_line = 50;
883 else if (!strcasecmp (val, "binary"))
885 /* "Binary" retrieval: 8K dots, 16 dots in a cluster, 48 dots
887 opt.dot_bytes = 8192;
888 opt.dot_spacing = 16;
889 opt.dots_in_line = 48;
891 else if (!strcasecmp (val, "mega"))
893 /* "Mega" retrieval, for retrieving very long files; each dot is
894 64K, 8 dots in a cluster, 6 clusters (3M) in a line. */
895 opt.dot_bytes = 65536L;
897 opt.dots_in_line = 48;
899 else if (!strcasecmp (val, "giga"))
901 /* "Giga" retrieval, for retrieving very very *very* long files;
902 each dot is 1M, 8 dots in a cluster, 4 clusters (32M) in a
904 opt.dot_bytes = (1L << 20);
906 opt.dots_in_line = 32;
908 else if (!strcasecmp (val, "micro"))
910 /* "Micro" retrieval, for retrieving very small files (and/or
911 slow connections); each dot is 128 bytes, 8 dots in a
912 cluster, 6 clusters (6K) in a line. */
915 opt.dots_in_line = 48;
919 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
920 exec_name, com, val);
927 cmd_spec_header (const char *com, const char *val, void *closure)
931 /* Empty header means reset headers. */
932 FREE_MAYBE (opt.user_header);
933 opt.user_header = NULL;
939 if (!check_user_specified_header (val))
941 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
942 exec_name, com, val);
945 i = opt.user_header ? strlen (opt.user_header) : 0;
946 opt.user_header = (char *)xrealloc (opt.user_header, i + strlen (val)
948 strcpy (opt.user_header + i, val);
950 opt.user_header[i++] = '\r';
951 opt.user_header[i++] = '\n';
952 opt.user_header[i] = '\0';
958 cmd_spec_htmlify (const char *com, const char *val, void *closure)
960 int flag = cmd_boolean (com, val, &opt.htmlify);
961 if (flag && !opt.htmlify)
962 opt.remove_listing = 0;
967 cmd_spec_mirror (const char *com, const char *val, void *closure)
971 if (!cmd_boolean (com, val, &mirror))
976 if (!opt.no_dirstruct)
978 opt.timestamping = 1;
979 opt.reclevel = INFINITE_RECURSION;
980 opt.remove_listing = 0;
986 cmd_spec_recursive (const char *com, const char *val, void *closure)
988 if (!cmd_boolean (com, val, &opt.recursive))
992 if (opt.recursive && !opt.no_dirstruct)
999 cmd_spec_useragent (const char *com, const char *val, void *closure)
1001 /* Just check for empty string and newline, so we don't throw total
1002 junk to the server. */
1003 if (!*val || strchr (val, '\n'))
1005 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
1006 exec_name, com, val);
1009 opt.useragent = xstrdup (val);
1013 /* Miscellaneous useful routines. */
1015 /* Return the integer value of a positive integer written in S, or -1
1016 if an error was encountered. */
1018 myatoi (const char *s)
1021 const char *orig = s;
1023 for (res = 0; *s && ISDIGIT (*s); s++)
1024 res = 10 * res + (*s - '0');
1025 if (*s || orig == s)
1031 #define ISODIGIT(x) ((x) >= '0' && (x) <= '7')
1034 check_user_specified_header (const char *s)
1038 for (p = s; *p && *p != ':' && !ISSPACE (*p); p++);
1039 /* The header MUST contain `:' preceded by at least one
1040 non-whitespace character. */
1041 if (*p != ':' || p == s)
1043 /* The header MUST NOT contain newlines. */
1044 if (strchr (s, '\n'))
1049 void cleanup_html_url PARAMS ((void));
1050 void downloaded_files_free PARAMS ((void));
1053 /* Free the memory allocated by global variables. */
1057 extern acc_t *netrc_list;
1059 recursive_cleanup ();
1061 free_netrc (netrc_list);
1064 cleanup_html_url ();
1065 downloaded_files_free ();
1067 FREE_MAYBE (opt.lfilename);
1068 xfree (opt.dir_prefix);
1069 FREE_MAYBE (opt.input_filename);
1070 FREE_MAYBE (opt.output_document);
1071 free_vec (opt.accepts);
1072 free_vec (opt.rejects);
1073 free_vec (opt.excludes);
1074 free_vec (opt.includes);
1075 free_vec (opt.domains);
1076 free_vec (opt.follow_tags);
1077 free_vec (opt.ignore_tags);
1078 xfree (opt.ftp_acc);
1079 FREE_MAYBE (opt.ftp_pass);
1080 FREE_MAYBE (opt.ftp_proxy);
1081 FREE_MAYBE (opt.https_proxy);
1082 FREE_MAYBE (opt.http_proxy);
1083 free_vec (opt.no_proxy);
1084 FREE_MAYBE (opt.useragent);
1085 FREE_MAYBE (opt.referer);
1086 FREE_MAYBE (opt.http_user);
1087 FREE_MAYBE (opt.http_passwd);
1088 FREE_MAYBE (opt.user_header);
1090 FREE_MAYBE (opt.sslcertkey);
1091 FREE_MAYBE (opt.sslcertfile);
1092 #endif /* HAVE_SSL */
1093 FREE_MAYBE (opt.bind_address);
1094 FREE_MAYBE (opt.cookies_input);
1095 FREE_MAYBE (opt.cookies_output);