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>
42 # include <arpa/inet.h>
56 #include "cookies.h" /* for cookies_cleanup */
62 /* We want tilde expansion enabled only when reading `.wgetrc' lines;
63 otherwise, it will be performed by the shell. This variable will
64 be set by the wgetrc-reading function. */
66 static int enable_tilde_expansion;
69 #define CMD_DECLARE(func) static int func \
70 PARAMS ((const char *, const char *, void *))
72 CMD_DECLARE (cmd_address);
73 CMD_DECLARE (cmd_boolean);
74 CMD_DECLARE (cmd_bytes);
75 CMD_DECLARE (cmd_directory_vector);
76 CMD_DECLARE (cmd_lockable_boolean);
77 CMD_DECLARE (cmd_number);
78 CMD_DECLARE (cmd_number_inf);
79 CMD_DECLARE (cmd_string);
80 CMD_DECLARE (cmd_file);
81 CMD_DECLARE (cmd_time);
82 CMD_DECLARE (cmd_vector);
84 CMD_DECLARE (cmd_spec_dirstruct);
85 CMD_DECLARE (cmd_spec_dotstyle);
86 CMD_DECLARE (cmd_spec_header);
87 CMD_DECLARE (cmd_spec_htmlify);
88 CMD_DECLARE (cmd_spec_mirror);
89 CMD_DECLARE (cmd_spec_recursive);
90 CMD_DECLARE (cmd_spec_useragent);
92 /* List of recognized commands, each consisting of name, closure and function.
93 When adding a new command, simply add it to the list, but be sure to keep the
94 list sorted alphabetically, as comind() depends on it. Also, be sure to add
95 any entries that allocate memory (e.g. cmd_string and cmd_vector guys) to the
96 cleanup() function below. */
100 int (*action) PARAMS ((const char *, const char *, void *));
102 { "accept", &opt.accepts, cmd_vector },
103 { "addhostdir", &opt.add_hostdir, cmd_boolean },
104 { "alwaysrest", &opt.always_rest, cmd_boolean }, /* deprecated */
105 { "background", &opt.background, cmd_boolean },
106 { "backupconverted", &opt.backup_converted, cmd_boolean },
107 { "backups", &opt.backups, cmd_number },
108 { "base", &opt.base_href, cmd_string },
109 { "bindaddress", &opt.bind_address, cmd_address },
110 { "cache", &opt.allow_cache, cmd_boolean },
111 { "continue", &opt.always_rest, cmd_boolean },
112 { "convertlinks", &opt.convert_links, cmd_boolean },
113 { "cookies", &opt.cookies, cmd_boolean },
114 { "cutdirs", &opt.cut_dirs, cmd_number },
116 { "debug", &opt.debug, cmd_boolean },
118 { "deleteafter", &opt.delete_after, cmd_boolean },
119 { "dirprefix", &opt.dir_prefix, cmd_file },
120 { "dirstruct", NULL, cmd_spec_dirstruct },
121 { "domains", &opt.domains, cmd_vector },
122 { "dotbytes", &opt.dot_bytes, cmd_bytes },
123 { "dotsinline", &opt.dots_in_line, cmd_number },
124 { "dotspacing", &opt.dot_spacing, cmd_number },
125 { "dotstyle", NULL, cmd_spec_dotstyle },
126 { "excludedirectories", &opt.excludes, cmd_directory_vector },
127 { "excludedomains", &opt.exclude_domains, cmd_vector },
128 { "followftp", &opt.follow_ftp, cmd_boolean },
129 { "followtags", &opt.follow_tags, cmd_vector },
130 { "forcehtml", &opt.force_html, cmd_boolean },
131 { "ftpproxy", &opt.ftp_proxy, cmd_string },
132 { "glob", &opt.ftp_glob, cmd_boolean },
133 { "header", NULL, cmd_spec_header },
134 { "htmlextension", &opt.html_extension, cmd_boolean },
135 { "htmlify", NULL, cmd_spec_htmlify },
136 { "httpkeepalive", &opt.http_keep_alive, cmd_boolean },
137 { "httppasswd", &opt.http_passwd, cmd_string },
138 { "httpproxy", &opt.http_proxy, cmd_string },
139 { "httpsproxy", &opt.https_proxy, cmd_string },
140 { "httpuser", &opt.http_user, cmd_string },
141 { "ignorelength", &opt.ignore_length, cmd_boolean },
142 { "ignoretags", &opt.ignore_tags, cmd_vector },
143 { "includedirectories", &opt.includes, cmd_directory_vector },
144 { "input", &opt.input_filename, cmd_file },
145 { "killlonger", &opt.kill_longer, cmd_boolean },
146 { "loadcookies", &opt.cookies_input, cmd_file },
147 { "logfile", &opt.lfilename, cmd_file },
148 { "login", &opt.ftp_acc, cmd_string },
149 { "mirror", NULL, cmd_spec_mirror },
150 { "netrc", &opt.netrc, cmd_boolean },
151 { "noclobber", &opt.noclobber, cmd_boolean },
152 { "noparent", &opt.no_parent, cmd_boolean },
153 { "noproxy", &opt.no_proxy, cmd_vector },
154 { "numtries", &opt.ntry, cmd_number_inf },/* deprecated*/
155 { "outputdocument", &opt.output_document, cmd_file },
156 { "pagerequisites", &opt.page_requisites, cmd_boolean },
157 { "passiveftp", &opt.ftp_pasv, cmd_lockable_boolean },
158 { "passwd", &opt.ftp_pass, cmd_string },
159 { "proxypasswd", &opt.proxy_passwd, cmd_string },
160 { "proxyuser", &opt.proxy_user, cmd_string },
161 { "quiet", &opt.quiet, cmd_boolean },
162 { "quota", &opt.quota, cmd_bytes },
163 { "reclevel", &opt.reclevel, cmd_number_inf },
164 { "recursive", NULL, cmd_spec_recursive },
165 { "referer", &opt.referer, cmd_string },
166 { "reject", &opt.rejects, cmd_vector },
167 { "relativeonly", &opt.relative_only, cmd_boolean },
168 { "removelisting", &opt.remove_listing, cmd_boolean },
169 { "retrsymlinks", &opt.retr_symlinks, cmd_boolean },
170 { "robots", &opt.use_robots, cmd_boolean },
171 { "savecookies", &opt.cookies_output, cmd_file },
172 { "saveheaders", &opt.save_headers, cmd_boolean },
173 { "serverresponse", &opt.server_response, cmd_boolean },
174 { "simplehostcheck", &opt.simple_check, cmd_boolean },
175 { "spanhosts", &opt.spanhost, cmd_boolean },
176 { "spider", &opt.spider, cmd_boolean },
178 { "sslcertfile", &opt.sslcertfile, cmd_file },
179 { "sslcertkey", &opt.sslcertkey, cmd_file },
180 #endif /* HAVE_SSL */
181 { "timeout", &opt.timeout, cmd_time },
182 { "timestamping", &opt.timestamping, cmd_boolean },
183 { "tries", &opt.ntry, cmd_number_inf },
184 { "useproxy", &opt.use_proxy, cmd_boolean },
185 { "useragent", NULL, cmd_spec_useragent },
186 { "verbose", &opt.verbose, cmd_boolean },
187 { "wait", &opt.wait, cmd_time },
188 { "waitretry", &opt.waitretry, cmd_time }
191 /* Return index of COM if it is a valid command, or -1 otherwise. COM
192 is looked up in `commands' using binary search algorithm. */
194 comind (const char *com)
196 int min = 0, max = ARRAY_SIZE (commands) - 1;
200 int i = (min + max) / 2;
201 int cmp = strcasecmp (com, commands[i].name);
213 /* Reset the variables to default values. */
219 /* Most of the default values are 0. Just reset everything, and
220 fill in the non-zero values. Note that initializing pointers to
221 NULL this way is technically illegal, but porting Wget to a
222 machine where NULL is not all-zero bit pattern will be the least
223 of the implementors' worries. */
224 memset (&opt, 0, sizeof (opt));
229 opt.dir_prefix = xstrdup (".");
233 opt.ftp_acc = xstrdup ("anonymous");
234 opt.ftp_pass = xstrdup ("-wget@");
238 opt.http_keep_alive = 1;
240 tmp = getenv ("no_proxy");
242 opt.no_proxy = sepstring (tmp);
250 opt.remove_listing = 1;
252 opt.dot_bytes = 1024;
253 opt.dot_spacing = 10;
254 opt.dots_in_line = 50;
257 /* Return the user's home directory (strdup-ed), or NULL if none is
262 char *home = getenv ("HOME");
267 /* If HOME is not defined, try getting it from the password
269 struct passwd *pwd = getpwuid (getuid ());
270 if (!pwd || !pwd->pw_dir)
275 /* #### Maybe I should grab home_dir from registry, but the best
276 that I could get from there is user's Start menu. It sucks! */
280 return home ? xstrdup (home) : NULL;
283 /* Return the path to the user's .wgetrc. This is either the value of
284 `WGETRC' environment variable, or `$HOME/.wgetrc'.
286 If the `WGETRC' variable exists but the file does not exist, the
287 function will exit(). */
289 wgetrc_file_name (void)
294 /* Try the environment. */
295 env = getenv ("WGETRC");
298 if (!file_exists_p (env))
300 fprintf (stderr, "%s: %s: %s.\n", exec_name, file, strerror (errno));
303 return xstrdup (env);
307 /* If that failed, try $HOME/.wgetrc. */
311 file = (char *)xmalloc (strlen (home) + 1 + strlen (".wgetrc") + 1);
312 sprintf (file, "%s/.wgetrc", home);
316 /* Under Windows, "home" is (for the purposes of this function) the
317 directory where `wget.exe' resides, and `wget.ini' will be used
318 as file name. SYSTEM_WGETRC should not be defined under WINDOWS.
320 It is not as trivial as I assumed, because on 95 argv[0] is full
321 path, but on NT you get what you typed in command line. --dbudor */
325 file = (char *)xmalloc (strlen (home) + strlen ("wget.ini") + 1);
326 sprintf (file, "%swget.ini", home);
332 if (!file_exists_p (file))
340 /* Initialize variables from a wgetrc file */
342 run_wgetrc (const char *file)
348 fp = fopen (file, "rb");
351 fprintf (stderr, _("%s: Cannot read %s (%s).\n"), exec_name,
352 file, strerror (errno));
355 enable_tilde_expansion = 1;
357 while ((line = read_whole_line (fp)))
362 /* Parse the line. */
363 status = parse_line (line, &com, &val);
365 /* If everything is OK, set the value. */
368 if (!setval (com, val))
369 fprintf (stderr, _("%s: Error in %s at line %d.\n"), exec_name,
374 else if (status == 0)
375 fprintf (stderr, _("%s: Error in %s at line %d.\n"), exec_name,
379 enable_tilde_expansion = 0;
383 /* Initialize the defaults and run the system wgetrc and user's own
390 /* Load the hard-coded defaults. */
393 /* If SYSTEM_WGETRC is defined, use it. */
395 if (file_exists_p (SYSTEM_WGETRC))
396 run_wgetrc (SYSTEM_WGETRC);
398 /* Override it with your own, if one exists. */
399 file = wgetrc_file_name ();
402 /* #### We should somehow canonicalize `file' and SYSTEM_WGETRC,
405 if (!strcmp (file, SYSTEM_WGETRC))
407 fprintf (stderr, _("\
408 %s: Warning: Both system and user wgetrc point to `%s'.\n"),
418 /* Parse the line pointed by line, with the syntax:
419 <sp>* command <sp>* = <sp>* value <newline>
420 Uses malloc to allocate space for command and value.
421 If the line is invalid, data is freed and 0 is returned.
428 parse_line (const char *line, char **com, char **val)
430 const char *p = line;
431 const char *orig_comptr, *end;
434 /* Skip whitespace. */
435 while (*p && ISSPACE (*p))
438 /* Don't process empty lines. */
439 if (!*p || *p == '#')
442 for (orig_comptr = p; ISALPHA (*p) || *p == '_' || *p == '-'; p++)
444 /* The next char should be space or '='. */
445 if (!ISSPACE (*p) && (*p != '='))
447 /* Here we cannot use strdupdelim() as we normally would because we
448 want to skip the `-' and `_' characters in the input string. */
449 *com = (char *)xmalloc (p - orig_comptr + 1);
450 for (new_comptr = *com; orig_comptr < p; orig_comptr++)
452 if (*orig_comptr == '_' || *orig_comptr == '-')
454 *new_comptr++ = *orig_comptr;
457 /* If the command is invalid, exit now. */
458 if (comind (*com) == -1)
464 /* Skip spaces before '='. */
465 for (; ISSPACE (*p); p++);
466 /* If '=' not found, bail out. */
472 /* Skip spaces after '='. */
473 for (++p; ISSPACE (*p); p++);
474 /* Get the ending position for VAL by starting with the end of the
475 line and skipping whitespace. */
476 end = line + strlen (line) - 1;
477 while (end > p && ISSPACE (*end))
479 *val = strdupdelim (p, end + 1);
483 /* Set COM to VAL. This is the meat behind processing `.wgetrc'. No
484 fatals -- error signal prints a warning and resets to default
485 value. All error messages are printed to stderr, *not* to
486 opt.lfile, since opt.lfile wasn't even generated yet. */
488 setval (const char *com, const char *val)
497 /* #### Should I just abort()? */
499 fprintf (stderr, _("%s: BUG: unknown command `%s', value `%s'.\n"),
500 exec_name, com, val);
504 return ((*commands[ind].action) (com, val, commands[ind].closure));
507 /* Generic helper functions, for use with `commands'. */
509 static int myatoi PARAMS ((const char *s));
511 /* Interpret VAL as an Internet address (a hostname or a dotted-quad
512 IP address), and write it (in network order) to a malloc-allocated
513 address. That address gets stored to the memory pointed to by
514 CLOSURE. COM is ignored, except for error messages.
516 #### IMHO it's a mistake to do this kind of work so early in the
517 process (before any download even started!) opt.bind_address
518 should simply remember the provided value as a string. Another
519 function should do the lookup, when needed, and cache the
522 cmd_address (const char *com, const char *val, void *closure)
524 struct sockaddr_in sin;
525 struct sockaddr_in **target = (struct sockaddr_in **)closure;
527 memset (&sin, '\0', sizeof (sin));
529 if (!store_hostaddress ((unsigned char *)&sin.sin_addr, val))
531 fprintf (stderr, _("%s: %s: Cannot convert `%s' to an IP address.\n"),
532 exec_name, com, val);
535 sin.sin_family = AF_INET;
538 FREE_MAYBE (*target);
540 *target = xmalloc (sizeof (sin));
541 memcpy (*target, &sin, sizeof (sin));
546 /* Store the boolean value from VAL to CLOSURE. COM is ignored,
547 except for error messages. */
549 cmd_boolean (const char *com, const char *val, void *closure)
553 if (!strcasecmp (val, "on")
554 || (*val == '1' && !*(val + 1)))
556 else if (!strcasecmp (val, "off")
557 || (*val == '0' && !*(val + 1)))
561 fprintf (stderr, _("%s: %s: Please specify on or off.\n"),
566 *(int *)closure = bool_value;
570 /* Store the lockable_boolean {2, 1, 0, -1} value from VAL to CLOSURE. COM is
571 ignored, except for error messages. Values 2 and -1 indicate that once
572 defined, the value may not be changed by successive wgetrc files or
573 command-line arguments.
575 Values: 2 - Enable a particular option for good ("always")
576 1 - Enable an option ("on")
577 0 - Disable an option ("off")
578 -1 - Disable an option for good ("never") */
580 cmd_lockable_boolean (const char *com, const char *val, void *closure)
582 int lockable_boolean_value;
585 * If a config file said "always" or "never", don't allow command line
586 * arguments to override the config file.
588 if (*(int *)closure == -1 || *(int *)closure == 2)
591 if (!strcasecmp (val, "always")
592 || (*val == '2' && !*(val + 1)))
593 lockable_boolean_value = 2;
594 else if (!strcasecmp (val, "on")
595 || (*val == '1' && !*(val + 1)))
596 lockable_boolean_value = 1;
597 else if (!strcasecmp (val, "off")
598 || (*val == '0' && !*(val + 1)))
599 lockable_boolean_value = 0;
600 else if (!strcasecmp (val, "never")
601 || (*val == '-' && *(val + 1) == '1' && !*(val + 2)))
602 lockable_boolean_value = -1;
605 fprintf (stderr, _("%s: %s: Please specify always, on, off, "
611 *(int *)closure = lockable_boolean_value;
615 /* Set the non-negative integer value from VAL to CLOSURE. With
616 incorrect specification, the number remains unchanged. */
618 cmd_number (const char *com, const char *val, void *closure)
620 int num = myatoi (val);
624 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
625 exec_name, com, val);
628 *(int *)closure = num;
632 /* Similar to cmd_number(), only accepts `inf' as a synonym for 0. */
634 cmd_number_inf (const char *com, const char *val, void *closure)
636 if (!strcasecmp (val, "inf"))
641 return cmd_number (com, val, closure);
644 /* Copy (strdup) the string at COM to a new location and place a
645 pointer to *CLOSURE. */
647 cmd_string (const char *com, const char *val, void *closure)
649 char **pstring = (char **)closure;
651 FREE_MAYBE (*pstring);
652 *pstring = xstrdup (val);
656 /* Like the above, but handles tilde-expansion when reading a user's
657 `.wgetrc'. In that case, and if VAL begins with `~', the tilde
658 gets expanded to the user's home directory. */
660 cmd_file (const char *com, const char *val, void *closure)
662 char **pstring = (char **)closure;
664 FREE_MAYBE (*pstring);
665 if (!enable_tilde_expansion || !(*val == '~' && *(val + 1) == '/'))
668 *pstring = xstrdup (val);
674 char *home = home_dir ();
678 homelen = strlen (home);
679 while (homelen && home[homelen - 1] == '/')
680 home[--homelen] = '\0';
682 /* Skip the leading "~/". */
683 for (++val; *val == '/'; val++)
686 result = xmalloc (homelen + 1 + strlen (val));
687 memcpy (result, home, homelen);
688 result[homelen] = '/';
689 strcpy (result + homelen + 1, val);
696 /* Merge the vector (array of strings separated with `,') in COM with
697 the vector (NULL-terminated array of strings) pointed to by
700 cmd_vector (const char *com, const char *val, void *closure)
702 char ***pvec = (char ***)closure;
705 *pvec = merge_vecs (*pvec, sepstring (val));
715 cmd_directory_vector (const char *com, const char *val, void *closure)
717 char ***pvec = (char ***)closure;
721 /* Strip the trailing slashes from directories. */
724 seps = sepstring (val);
725 for (t = seps; t && *t; t++)
727 int len = strlen (*t);
728 /* Skip degenerate case of root directory. */
731 if ((*t)[len - 1] == '/')
732 (*t)[len - 1] = '\0';
735 *pvec = merge_vecs (*pvec, seps);
745 /* Set the value stored in VAL to CLOSURE (which should point to a
746 long int), allowing several postfixes, with the following syntax
750 [0-9]+[kK] -> bytes * 1024
751 [0-9]+[mM] -> bytes * 1024 * 1024
754 Anything else is flagged as incorrect, and CLOSURE is unchanged. */
756 cmd_bytes (const char *com, const char *val, void *closure)
759 long *out = (long *)closure;
764 /* Check for "inf". */
765 if (p[0] == 'i' && p[1] == 'n' && p[2] == 'f' && p[3] == '\0')
770 /* Search for digits and construct result. */
771 for (; *p && ISDIGIT (*p); p++)
772 result = (10 * result) + (*p - '0');
773 /* If no digits were found, or more than one character is following
775 if (p == val || (*p != '\0' && *(p + 1) != '\0'))
777 printf (_("%s: Invalid specification `%s'\n"), com, val);
780 /* Search for a designator. */
781 switch (TOLOWER (*p))
792 result *= (long)1024 * 1024;
796 result *= (long)1024 * 1024 * 1024;
799 printf (_("%s: Invalid specification `%s'\n"), com, val);
806 /* Store the value of VAL to *OUT, allowing suffixes for minutes and
809 cmd_time (const char *com, const char *val, void *closure)
814 /* Search for digits and construct result. */
815 for (; *p && ISDIGIT (*p); p++)
816 result = (10 * result) + (*p - '0');
817 /* If no digits were found, or more than one character is following
819 if (p == val || (*p != '\0' && *(p + 1) != '\0'))
821 printf (_("%s: Invalid specification `%s'\n"), com, val);
824 /* Search for a suffix. */
825 switch (TOLOWER (*p))
839 /* Days (overflow on 16bit machines) */
847 printf (_("%s: Invalid specification `%s'\n"), com, val);
850 *(long *)closure = result;
854 /* Specialized helper functions, used by `commands' to handle some
855 options specially. */
857 static int check_user_specified_header PARAMS ((const char *));
860 cmd_spec_dirstruct (const char *com, const char *val, void *closure)
862 if (!cmd_boolean (com, val, &opt.dirstruct))
864 /* Since dirstruct behaviour is explicitly changed, no_dirstruct
865 must be affected inversely. */
867 opt.no_dirstruct = 0;
869 opt.no_dirstruct = 1;
874 cmd_spec_dotstyle (const char *com, const char *val, void *closure)
876 /* Retrieval styles. */
877 if (!strcasecmp (val, "default"))
879 /* Default style: 1K dots, 10 dots in a cluster, 50 dots in a
881 opt.dot_bytes = 1024;
882 opt.dot_spacing = 10;
883 opt.dots_in_line = 50;
885 else if (!strcasecmp (val, "binary"))
887 /* "Binary" retrieval: 8K dots, 16 dots in a cluster, 48 dots
889 opt.dot_bytes = 8192;
890 opt.dot_spacing = 16;
891 opt.dots_in_line = 48;
893 else if (!strcasecmp (val, "mega"))
895 /* "Mega" retrieval, for retrieving very long files; each dot is
896 64K, 8 dots in a cluster, 6 clusters (3M) in a line. */
897 opt.dot_bytes = 65536L;
899 opt.dots_in_line = 48;
901 else if (!strcasecmp (val, "giga"))
903 /* "Giga" retrieval, for retrieving very very *very* long files;
904 each dot is 1M, 8 dots in a cluster, 4 clusters (32M) in a
906 opt.dot_bytes = (1L << 20);
908 opt.dots_in_line = 32;
910 else if (!strcasecmp (val, "micro"))
912 /* "Micro" retrieval, for retrieving very small files (and/or
913 slow connections); each dot is 128 bytes, 8 dots in a
914 cluster, 6 clusters (6K) in a line. */
917 opt.dots_in_line = 48;
921 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
922 exec_name, com, val);
929 cmd_spec_header (const char *com, const char *val, void *closure)
933 /* Empty header means reset headers. */
934 FREE_MAYBE (opt.user_header);
935 opt.user_header = NULL;
941 if (!check_user_specified_header (val))
943 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
944 exec_name, com, val);
947 i = opt.user_header ? strlen (opt.user_header) : 0;
948 opt.user_header = (char *)xrealloc (opt.user_header, i + strlen (val)
950 strcpy (opt.user_header + i, val);
952 opt.user_header[i++] = '\r';
953 opt.user_header[i++] = '\n';
954 opt.user_header[i] = '\0';
960 cmd_spec_htmlify (const char *com, const char *val, void *closure)
962 int flag = cmd_boolean (com, val, &opt.htmlify);
963 if (flag && !opt.htmlify)
964 opt.remove_listing = 0;
969 cmd_spec_mirror (const char *com, const char *val, void *closure)
973 if (!cmd_boolean (com, val, &mirror))
978 if (!opt.no_dirstruct)
980 opt.timestamping = 1;
981 opt.reclevel = INFINITE_RECURSION;
982 opt.remove_listing = 0;
988 cmd_spec_recursive (const char *com, const char *val, void *closure)
990 if (!cmd_boolean (com, val, &opt.recursive))
994 if (opt.recursive && !opt.no_dirstruct)
1001 cmd_spec_useragent (const char *com, const char *val, void *closure)
1003 /* Just check for empty string and newline, so we don't throw total
1004 junk to the server. */
1005 if (!*val || strchr (val, '\n'))
1007 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
1008 exec_name, com, val);
1011 opt.useragent = xstrdup (val);
1015 /* Miscellaneous useful routines. */
1017 /* Return the integer value of a positive integer written in S, or -1
1018 if an error was encountered. */
1020 myatoi (const char *s)
1023 const char *orig = s;
1025 for (res = 0; *s && ISDIGIT (*s); s++)
1026 res = 10 * res + (*s - '0');
1027 if (*s || orig == s)
1033 #define ISODIGIT(x) ((x) >= '0' && (x) <= '7')
1036 check_user_specified_header (const char *s)
1040 for (p = s; *p && *p != ':' && !ISSPACE (*p); p++);
1041 /* The header MUST contain `:' preceded by at least one
1042 non-whitespace character. */
1043 if (*p != ':' || p == s)
1045 /* The header MUST NOT contain newlines. */
1046 if (strchr (s, '\n'))
1051 void cleanup_html_url PARAMS ((void));
1052 void downloaded_files_free PARAMS ((void));
1055 /* Free the memory allocated by global variables. */
1059 extern acc_t *netrc_list;
1061 recursive_cleanup ();
1063 free_netrc (netrc_list);
1066 cleanup_html_url ();
1067 downloaded_files_free ();
1069 FREE_MAYBE (opt.lfilename);
1070 xfree (opt.dir_prefix);
1071 FREE_MAYBE (opt.input_filename);
1072 FREE_MAYBE (opt.output_document);
1073 free_vec (opt.accepts);
1074 free_vec (opt.rejects);
1075 free_vec (opt.excludes);
1076 free_vec (opt.includes);
1077 free_vec (opt.domains);
1078 free_vec (opt.follow_tags);
1079 free_vec (opt.ignore_tags);
1080 xfree (opt.ftp_acc);
1081 FREE_MAYBE (opt.ftp_pass);
1082 FREE_MAYBE (opt.ftp_proxy);
1083 FREE_MAYBE (opt.https_proxy);
1084 FREE_MAYBE (opt.http_proxy);
1085 free_vec (opt.no_proxy);
1086 FREE_MAYBE (opt.useragent);
1087 FREE_MAYBE (opt.referer);
1088 FREE_MAYBE (opt.http_user);
1089 FREE_MAYBE (opt.http_passwd);
1090 FREE_MAYBE (opt.user_header);
1092 FREE_MAYBE (opt.sslcertkey);
1093 FREE_MAYBE (opt.sslcertfile);
1094 #endif /* HAVE_SSL */
1095 FREE_MAYBE (opt.bind_address);
1096 FREE_MAYBE (opt.cookies_input);
1097 FREE_MAYBE (opt.cookies_output);