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 */
63 /* We want tilde expansion enabled only when reading `.wgetrc' lines;
64 otherwise, it will be performed by the shell. This variable will
65 be set by the wgetrc-reading function. */
67 static int enable_tilde_expansion;
70 #define CMD_DECLARE(func) static int func \
71 PARAMS ((const char *, const char *, void *))
73 CMD_DECLARE (cmd_address);
74 CMD_DECLARE (cmd_boolean);
75 CMD_DECLARE (cmd_bytes);
76 CMD_DECLARE (cmd_directory_vector);
77 CMD_DECLARE (cmd_lockable_boolean);
78 CMD_DECLARE (cmd_number);
79 CMD_DECLARE (cmd_number_inf);
80 CMD_DECLARE (cmd_string);
81 CMD_DECLARE (cmd_file);
82 CMD_DECLARE (cmd_directory);
83 CMD_DECLARE (cmd_time);
84 CMD_DECLARE (cmd_vector);
86 CMD_DECLARE (cmd_spec_dirstruct);
87 CMD_DECLARE (cmd_spec_header);
88 CMD_DECLARE (cmd_spec_htmlify);
89 CMD_DECLARE (cmd_spec_mirror);
90 CMD_DECLARE (cmd_spec_progress);
91 CMD_DECLARE (cmd_spec_recursive);
92 CMD_DECLARE (cmd_spec_useragent);
94 /* List of recognized commands, each consisting of name, closure and function.
95 When adding a new command, simply add it to the list, but be sure to keep the
96 list sorted alphabetically, as comind() depends on it. Also, be sure to add
97 any entries that allocate memory (e.g. cmd_string and cmd_vector guys) to the
98 cleanup() function below. */
102 int (*action) PARAMS ((const char *, const char *, void *));
104 { "accept", &opt.accepts, cmd_vector },
105 { "addhostdir", &opt.add_hostdir, cmd_boolean },
106 { "alwaysrest", &opt.always_rest, cmd_boolean }, /* deprecated */
107 { "background", &opt.background, cmd_boolean },
108 { "backupconverted", &opt.backup_converted, cmd_boolean },
109 { "backups", &opt.backups, cmd_number },
110 { "base", &opt.base_href, cmd_string },
111 { "bindaddress", &opt.bind_address, cmd_address },
112 { "cache", &opt.allow_cache, cmd_boolean },
113 { "continue", &opt.always_rest, cmd_boolean },
114 { "convertlinks", &opt.convert_links, cmd_boolean },
115 { "cookies", &opt.cookies, cmd_boolean },
116 { "cutdirs", &opt.cut_dirs, cmd_number },
118 { "debug", &opt.debug, cmd_boolean },
120 { "deleteafter", &opt.delete_after, cmd_boolean },
121 { "dirprefix", &opt.dir_prefix, cmd_directory },
122 { "dirstruct", NULL, cmd_spec_dirstruct },
123 { "domains", &opt.domains, cmd_vector },
124 { "dotbytes", &opt.dot_bytes, cmd_bytes },
125 { "dotsinline", &opt.dots_in_line, cmd_number },
126 { "dotspacing", &opt.dot_spacing, cmd_number },
127 { "dotstyle", &opt.dot_style, cmd_string },
128 { "excludedirectories", &opt.excludes, cmd_directory_vector },
129 { "excludedomains", &opt.exclude_domains, cmd_vector },
130 { "followftp", &opt.follow_ftp, cmd_boolean },
131 { "followtags", &opt.follow_tags, cmd_vector },
132 { "forcehtml", &opt.force_html, cmd_boolean },
133 { "ftpproxy", &opt.ftp_proxy, cmd_string },
134 { "glob", &opt.ftp_glob, cmd_boolean },
135 { "header", NULL, cmd_spec_header },
136 { "htmlextension", &opt.html_extension, cmd_boolean },
137 { "htmlify", NULL, cmd_spec_htmlify },
138 { "httpkeepalive", &opt.http_keep_alive, cmd_boolean },
139 { "httppasswd", &opt.http_passwd, cmd_string },
140 { "httpproxy", &opt.http_proxy, cmd_string },
141 { "httpsproxy", &opt.https_proxy, cmd_string },
142 { "httpuser", &opt.http_user, cmd_string },
143 { "ignorelength", &opt.ignore_length, cmd_boolean },
144 { "ignoretags", &opt.ignore_tags, cmd_vector },
145 { "includedirectories", &opt.includes, cmd_directory_vector },
146 { "input", &opt.input_filename, cmd_file },
147 { "killlonger", &opt.kill_longer, cmd_boolean },
148 { "limitrate", &opt.limit_rate, cmd_bytes },
149 { "loadcookies", &opt.cookies_input, cmd_file },
150 { "logfile", &opt.lfilename, cmd_file },
151 { "login", &opt.ftp_acc, cmd_string },
152 { "mirror", NULL, cmd_spec_mirror },
153 { "netrc", &opt.netrc, cmd_boolean },
154 { "noclobber", &opt.noclobber, cmd_boolean },
155 { "noparent", &opt.no_parent, cmd_boolean },
156 { "noproxy", &opt.no_proxy, cmd_vector },
157 { "numtries", &opt.ntry, cmd_number_inf },/* deprecated*/
158 { "outputdocument", &opt.output_document, cmd_file },
159 { "pagerequisites", &opt.page_requisites, cmd_boolean },
160 { "passiveftp", &opt.ftp_pasv, cmd_lockable_boolean },
161 { "passwd", &opt.ftp_pass, cmd_string },
162 { "progress", &opt.progress_type, cmd_spec_progress },
163 { "proxypasswd", &opt.proxy_passwd, cmd_string },
164 { "proxyuser", &opt.proxy_user, cmd_string },
165 { "quiet", &opt.quiet, cmd_boolean },
166 { "quota", &opt.quota, cmd_bytes },
167 { "randomwait", &opt.random_wait, cmd_boolean },
168 { "reclevel", &opt.reclevel, cmd_number_inf },
169 { "recursive", NULL, cmd_spec_recursive },
170 { "referer", &opt.referer, cmd_string },
171 { "reject", &opt.rejects, cmd_vector },
172 { "relativeonly", &opt.relative_only, cmd_boolean },
173 { "removelisting", &opt.remove_listing, cmd_boolean },
174 { "retrsymlinks", &opt.retr_symlinks, cmd_boolean },
175 { "robots", &opt.use_robots, cmd_boolean },
176 { "savecookies", &opt.cookies_output, cmd_file },
177 { "saveheaders", &opt.save_headers, cmd_boolean },
178 { "serverresponse", &opt.server_response, cmd_boolean },
179 { "spanhosts", &opt.spanhost, cmd_boolean },
180 { "spider", &opt.spider, cmd_boolean },
182 { "sslcertfile", &opt.sslcertfile, cmd_file },
183 { "sslcertkey", &opt.sslcertkey, cmd_file },
184 { "egdfile", &opt.sslegdsock, cmd_file },
185 #endif /* HAVE_SSL */
186 { "timeout", &opt.timeout, cmd_time },
187 { "timestamping", &opt.timestamping, cmd_boolean },
188 { "tries", &opt.ntry, cmd_number_inf },
189 { "useproxy", &opt.use_proxy, cmd_boolean },
190 { "useragent", NULL, cmd_spec_useragent },
191 { "verbose", &opt.verbose, cmd_boolean },
192 { "wait", &opt.wait, cmd_time },
193 { "waitretry", &opt.waitretry, cmd_time }
196 /* Return index of COM if it is a valid command, or -1 otherwise. COM
197 is looked up in `commands' using binary search algorithm. */
199 comind (const char *com)
201 int min = 0, max = ARRAY_SIZE (commands) - 1;
205 int i = (min + max) / 2;
206 int cmp = strcasecmp (com, commands[i].name);
218 /* Reset the variables to default values. */
224 /* Most of the default values are 0. Just reset everything, and
225 fill in the non-zero values. Note that initializing pointers to
226 NULL this way is technically illegal, but porting Wget to a
227 machine where NULL is not all-zero bit pattern will be the least
228 of the implementors' worries. */
229 memset (&opt, 0, sizeof (opt));
234 opt.dir_prefix = xstrdup (".");
238 opt.ftp_acc = xstrdup ("anonymous");
239 opt.ftp_pass = xstrdup ("-wget@");
243 opt.http_keep_alive = 1;
245 tmp = getenv ("no_proxy");
247 opt.no_proxy = sepstring (tmp);
255 opt.remove_listing = 1;
257 opt.dot_bytes = 1024;
258 opt.dot_spacing = 10;
259 opt.dots_in_line = 50;
262 /* Return the user's home directory (strdup-ed), or NULL if none is
267 char *home = getenv ("HOME");
272 /* If HOME is not defined, try getting it from the password
274 struct passwd *pwd = getpwuid (getuid ());
275 if (!pwd || !pwd->pw_dir)
280 /* #### Maybe I should grab home_dir from registry, but the best
281 that I could get from there is user's Start menu. It sucks! */
285 return home ? xstrdup (home) : NULL;
288 /* Return the path to the user's .wgetrc. This is either the value of
289 `WGETRC' environment variable, or `$HOME/.wgetrc'.
291 If the `WGETRC' variable exists but the file does not exist, the
292 function will exit(). */
294 wgetrc_file_name (void)
299 /* Try the environment. */
300 env = getenv ("WGETRC");
303 if (!file_exists_p (env))
305 fprintf (stderr, "%s: %s: %s.\n", exec_name, env, strerror (errno));
308 return xstrdup (env);
312 /* If that failed, try $HOME/.wgetrc. */
316 file = (char *)xmalloc (strlen (home) + 1 + strlen (".wgetrc") + 1);
317 sprintf (file, "%s/.wgetrc", home);
321 /* Under Windows, "home" is (for the purposes of this function) the
322 directory where `wget.exe' resides, and `wget.ini' will be used
323 as file name. SYSTEM_WGETRC should not be defined under WINDOWS.
325 It is not as trivial as I assumed, because on 95 argv[0] is full
326 path, but on NT you get what you typed in command line. --dbudor */
330 file = (char *)xmalloc (strlen (home) + strlen ("wget.ini") + 1);
331 sprintf (file, "%swget.ini", home);
337 if (!file_exists_p (file))
345 /* Initialize variables from a wgetrc file */
347 run_wgetrc (const char *file)
353 fp = fopen (file, "rb");
356 fprintf (stderr, _("%s: Cannot read %s (%s).\n"), exec_name,
357 file, strerror (errno));
360 enable_tilde_expansion = 1;
362 while ((line = read_whole_line (fp)))
367 /* Parse the line. */
368 status = parse_line (line, &com, &val);
370 /* If everything is OK, set the value. */
373 if (!setval (com, val))
374 fprintf (stderr, _("%s: Error in %s at line %d.\n"), exec_name,
379 else if (status == 0)
380 fprintf (stderr, _("%s: Error in %s at line %d.\n"), exec_name,
384 enable_tilde_expansion = 0;
388 /* Initialize the defaults and run the system wgetrc and user's own
395 /* Load the hard-coded defaults. */
398 /* If SYSTEM_WGETRC is defined, use it. */
400 if (file_exists_p (SYSTEM_WGETRC))
401 run_wgetrc (SYSTEM_WGETRC);
403 /* Override it with your own, if one exists. */
404 file = wgetrc_file_name ();
407 /* #### We should somehow canonicalize `file' and SYSTEM_WGETRC,
410 if (!strcmp (file, SYSTEM_WGETRC))
412 fprintf (stderr, _("\
413 %s: Warning: Both system and user wgetrc point to `%s'.\n"),
423 /* Parse the line pointed by line, with the syntax:
424 <sp>* command <sp>* = <sp>* value <newline>
425 Uses malloc to allocate space for command and value.
426 If the line is invalid, data is freed and 0 is returned.
433 parse_line (const char *line, char **com, char **val)
435 const char *p = line;
436 const char *orig_comptr, *end;
439 /* Skip whitespace. */
440 while (*p && ISSPACE (*p))
443 /* Don't process empty lines. */
444 if (!*p || *p == '#')
447 for (orig_comptr = p; ISALPHA (*p) || *p == '_' || *p == '-'; p++)
449 /* The next char should be space or '='. */
450 if (!ISSPACE (*p) && (*p != '='))
452 /* Here we cannot use strdupdelim() as we normally would because we
453 want to skip the `-' and `_' characters in the input string. */
454 *com = (char *)xmalloc (p - orig_comptr + 1);
455 for (new_comptr = *com; orig_comptr < p; orig_comptr++)
457 if (*orig_comptr == '_' || *orig_comptr == '-')
459 *new_comptr++ = *orig_comptr;
462 /* If the command is invalid, exit now. */
463 if (comind (*com) == -1)
469 /* Skip spaces before '='. */
470 for (; ISSPACE (*p); p++);
471 /* If '=' not found, bail out. */
477 /* Skip spaces after '='. */
478 for (++p; ISSPACE (*p); p++);
479 /* Get the ending position for VAL by starting with the end of the
480 line and skipping whitespace. */
481 end = line + strlen (line) - 1;
482 while (end > p && ISSPACE (*end))
484 *val = strdupdelim (p, end + 1);
488 /* Set COM to VAL. This is the meat behind processing `.wgetrc'. No
489 fatals -- error signal prints a warning and resets to default
490 value. All error messages are printed to stderr, *not* to
491 opt.lfile, since opt.lfile wasn't even generated yet. */
493 setval (const char *com, const char *val)
502 /* #### Should I just abort()? */
504 fprintf (stderr, _("%s: BUG: unknown command `%s', value `%s'.\n"),
505 exec_name, com, val);
509 return ((*commands[ind].action) (com, val, commands[ind].closure));
512 /* Generic helper functions, for use with `commands'. */
514 static int myatoi PARAMS ((const char *s));
516 /* Interpret VAL as an Internet address (a hostname or a dotted-quad
517 IP address), and write it (in network order) to a malloc-allocated
518 address. That address gets stored to the memory pointed to by
519 CLOSURE. COM is ignored, except for error messages.
521 #### IMHO it's a mistake to do this kind of work so early in the
522 process (before any download even started!) opt.bind_address
523 should simply remember the provided value as a string. Another
524 function should do the lookup, when needed, and cache the
527 cmd_address (const char *com, const char *val, void *closure)
529 struct address_list *al;
531 wget_sockaddr **target = (wget_sockaddr **)closure;
533 memset (&sa, '\0', sizeof (sa));
535 al = lookup_host (val, 1);
538 fprintf (stderr, _("%s: %s: Cannot convert `%s' to an IP address.\n"),
539 exec_name, com, val);
542 sa.sa.sa_family = ip_default_family;
543 wget_sockaddr_set_port (&sa, 0);
544 address_list_copy_one (al, 0, wget_sockaddr_get_addr (&sa));
545 address_list_release (al);
547 FREE_MAYBE (*target);
549 *target = xmalloc (sizeof (sa));
550 memcpy (*target, &sa, sizeof (sa));
555 /* Store the boolean value from VAL to CLOSURE. COM is ignored,
556 except for error messages. */
558 cmd_boolean (const char *com, const char *val, void *closure)
562 if (!strcasecmp (val, "on")
563 || (*val == '1' && !*(val + 1)))
565 else if (!strcasecmp (val, "off")
566 || (*val == '0' && !*(val + 1)))
570 fprintf (stderr, _("%s: %s: Please specify on or off.\n"),
575 *(int *)closure = bool_value;
579 /* Store the lockable_boolean {2, 1, 0, -1} value from VAL to CLOSURE. COM is
580 ignored, except for error messages. Values 2 and -1 indicate that once
581 defined, the value may not be changed by successive wgetrc files or
582 command-line arguments.
584 Values: 2 - Enable a particular option for good ("always")
585 1 - Enable an option ("on")
586 0 - Disable an option ("off")
587 -1 - Disable an option for good ("never") */
589 cmd_lockable_boolean (const char *com, const char *val, void *closure)
591 int lockable_boolean_value;
594 * If a config file said "always" or "never", don't allow command line
595 * arguments to override the config file.
597 if (*(int *)closure == -1 || *(int *)closure == 2)
600 if (!strcasecmp (val, "always")
601 || (*val == '2' && !*(val + 1)))
602 lockable_boolean_value = 2;
603 else if (!strcasecmp (val, "on")
604 || (*val == '1' && !*(val + 1)))
605 lockable_boolean_value = 1;
606 else if (!strcasecmp (val, "off")
607 || (*val == '0' && !*(val + 1)))
608 lockable_boolean_value = 0;
609 else if (!strcasecmp (val, "never")
610 || (*val == '-' && *(val + 1) == '1' && !*(val + 2)))
611 lockable_boolean_value = -1;
614 fprintf (stderr, _("%s: %s: Please specify always, on, off, "
620 *(int *)closure = lockable_boolean_value;
624 /* Set the non-negative integer value from VAL to CLOSURE. With
625 incorrect specification, the number remains unchanged. */
627 cmd_number (const char *com, const char *val, void *closure)
629 int num = myatoi (val);
633 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
634 exec_name, com, val);
637 *(int *)closure = num;
641 /* Similar to cmd_number(), only accepts `inf' as a synonym for 0. */
643 cmd_number_inf (const char *com, const char *val, void *closure)
645 if (!strcasecmp (val, "inf"))
650 return cmd_number (com, val, closure);
653 /* Copy (strdup) the string at COM to a new location and place a
654 pointer to *CLOSURE. */
656 cmd_string (const char *com, const char *val, void *closure)
658 char **pstring = (char **)closure;
660 FREE_MAYBE (*pstring);
661 *pstring = xstrdup (val);
665 /* Like the above, but handles tilde-expansion when reading a user's
666 `.wgetrc'. In that case, and if VAL begins with `~', the tilde
667 gets expanded to the user's home directory. */
669 cmd_file (const char *com, const char *val, void *closure)
671 char **pstring = (char **)closure;
673 FREE_MAYBE (*pstring);
675 /* #### If VAL is empty, perhaps should set *CLOSURE to NULL. */
677 if (!enable_tilde_expansion || !(*val == '~' && (*(val + 1) == '/'
679 || *(val + 1) == '\\'
684 *pstring = xstrdup (val);
690 char *home = home_dir ();
694 homelen = strlen (home);
695 while (homelen && (home[homelen - 1] == '/'
697 || home[homelen - 1] == '\\'
700 home[--homelen] = '\0';
702 /* Skip the leading "~/". */
704 for (++val; *val == '/' || *val == '\\'; val++)
707 for (++val; *val == '/'; val++)
711 result = xmalloc (homelen + 1 + strlen (val));
712 memcpy (result, home, homelen);
713 result[homelen] = '/';
714 strcpy (result + homelen + 1, val);
719 /* Convert "\" to "/". */
722 for (s = *pstring; *s; s++)
730 /* Like cmd_file, but strips trailing '/' characters. */
732 cmd_directory (const char *com, const char *val, void *closure)
736 /* Call cmd_file() for tilde expansion and separator
737 canonicalization (backslash -> slash under Windows). These
738 things should perhaps be in a separate function. */
739 if (!cmd_file (com, val, closure))
742 s = *(char **)closure;
744 while (t > s && *--t == '/')
750 /* Merge the vector (array of strings separated with `,') in COM with
751 the vector (NULL-terminated array of strings) pointed to by
754 cmd_vector (const char *com, const char *val, void *closure)
756 char ***pvec = (char ***)closure;
759 *pvec = merge_vecs (*pvec, sepstring (val));
769 cmd_directory_vector (const char *com, const char *val, void *closure)
771 char ***pvec = (char ***)closure;
775 /* Strip the trailing slashes from directories. */
778 seps = sepstring (val);
779 for (t = seps; t && *t; t++)
781 int len = strlen (*t);
782 /* Skip degenerate case of root directory. */
785 if ((*t)[len - 1] == '/')
786 (*t)[len - 1] = '\0';
789 *pvec = merge_vecs (*pvec, seps);
799 /* Set the value stored in VAL to CLOSURE (which should point to a
800 long int), allowing several postfixes, with the following syntax
804 [0-9]+[kK] -> bytes * 1024
805 [0-9]+[mM] -> bytes * 1024 * 1024
808 Anything else is flagged as incorrect, and CLOSURE is unchanged. */
810 cmd_bytes (const char *com, const char *val, void *closure)
813 long *out = (long *)closure;
818 /* Check for "inf". */
819 if (p[0] == 'i' && p[1] == 'n' && p[2] == 'f' && p[3] == '\0')
824 /* Search for digits and construct result. */
825 for (; *p && ISDIGIT (*p); p++)
826 result = (10 * result) + (*p - '0');
827 /* If no digits were found, or more than one character is following
829 if (p == val || (*p != '\0' && *(p + 1) != '\0'))
831 printf (_("%s: Invalid specification `%s'\n"), com, val);
834 /* Search for a designator. */
835 switch (TOLOWER (*p))
846 result *= (long)1024 * 1024;
850 result *= (long)1024 * 1024 * 1024;
853 printf (_("%s: Invalid specification `%s'\n"), com, val);
860 /* Store the value of VAL to *OUT, allowing suffixes for minutes and
863 cmd_time (const char *com, const char *val, void *closure)
868 /* Search for digits and construct result. */
869 for (; *p && ISDIGIT (*p); p++)
870 result = (10 * result) + (*p - '0');
871 /* If no digits were found, or more than one character is following
873 if (p == val || (*p != '\0' && *(p + 1) != '\0'))
875 printf (_("%s: Invalid specification `%s'\n"), com, val);
878 /* Search for a suffix. */
879 switch (TOLOWER (*p))
893 /* Days (overflow on 16bit machines) */
901 printf (_("%s: Invalid specification `%s'\n"), com, val);
904 *(long *)closure = result;
908 /* Specialized helper functions, used by `commands' to handle some
909 options specially. */
911 static int check_user_specified_header PARAMS ((const char *));
914 cmd_spec_dirstruct (const char *com, const char *val, void *closure)
916 if (!cmd_boolean (com, val, &opt.dirstruct))
918 /* Since dirstruct behaviour is explicitly changed, no_dirstruct
919 must be affected inversely. */
921 opt.no_dirstruct = 0;
923 opt.no_dirstruct = 1;
928 cmd_spec_header (const char *com, const char *val, void *closure)
932 /* Empty header means reset headers. */
933 FREE_MAYBE (opt.user_header);
934 opt.user_header = NULL;
940 if (!check_user_specified_header (val))
942 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
943 exec_name, com, val);
946 i = opt.user_header ? strlen (opt.user_header) : 0;
947 opt.user_header = (char *)xrealloc (opt.user_header, i + strlen (val)
949 strcpy (opt.user_header + i, val);
951 opt.user_header[i++] = '\r';
952 opt.user_header[i++] = '\n';
953 opt.user_header[i] = '\0';
959 cmd_spec_htmlify (const char *com, const char *val, void *closure)
961 int flag = cmd_boolean (com, val, &opt.htmlify);
962 if (flag && !opt.htmlify)
963 opt.remove_listing = 0;
968 cmd_spec_mirror (const char *com, const char *val, void *closure)
972 if (!cmd_boolean (com, val, &mirror))
977 if (!opt.no_dirstruct)
979 opt.timestamping = 1;
980 opt.reclevel = INFINITE_RECURSION;
981 opt.remove_listing = 0;
987 cmd_spec_progress (const char *com, const char *val, void *closure)
989 if (!valid_progress_implementation_p (val))
991 fprintf (stderr, _("%s: %s: Invalid progress type `%s'.\n"),
992 exec_name, com, val);
995 FREE_MAYBE (opt.progress_type);
997 /* Don't call set_progress_implementation here. It will be called
998 in main() when it becomes clear what the log output is. */
999 opt.progress_type = xstrdup (val);
1004 cmd_spec_recursive (const char *com, const char *val, void *closure)
1006 if (!cmd_boolean (com, val, &opt.recursive))
1010 if (opt.recursive && !opt.no_dirstruct)
1017 cmd_spec_useragent (const char *com, const char *val, void *closure)
1019 /* Just check for empty string and newline, so we don't throw total
1020 junk to the server. */
1021 if (!*val || strchr (val, '\n'))
1023 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
1024 exec_name, com, val);
1027 opt.useragent = xstrdup (val);
1031 /* Miscellaneous useful routines. */
1033 /* Return the integer value of a positive integer written in S, or -1
1034 if an error was encountered. */
1036 myatoi (const char *s)
1039 const char *orig = s;
1041 for (res = 0; *s && ISDIGIT (*s); s++)
1042 res = 10 * res + (*s - '0');
1043 if (*s || orig == s)
1049 #define ISODIGIT(x) ((x) >= '0' && (x) <= '7')
1052 check_user_specified_header (const char *s)
1056 for (p = s; *p && *p != ':' && !ISSPACE (*p); p++);
1057 /* The header MUST contain `:' preceded by at least one
1058 non-whitespace character. */
1059 if (*p != ':' || p == s)
1061 /* The header MUST NOT contain newlines. */
1062 if (strchr (s, '\n'))
1067 void cleanup_html_url PARAMS ((void));
1068 void res_cleanup PARAMS ((void));
1069 void downloaded_files_free PARAMS ((void));
1070 void http_cleanup PARAMS ((void));
1073 /* Free the memory allocated by global variables. */
1077 /* Free external resources, close files, etc. */
1082 /* We're exiting anyway so there's no real need to call free()
1083 hundreds of times. Skipping the frees will make Wget exit
1086 However, when detecting leaks, it's crucial to free() everything
1087 because then you can find the real leaks, i.e. the allocated
1088 memory which grows with the size of the program. */
1091 recursive_cleanup ();
1094 cleanup_html_url ();
1095 downloaded_files_free ();
1100 extern acc_t *netrc_list;
1101 free_netrc (netrc_list);
1103 FREE_MAYBE (opt.lfilename);
1104 xfree (opt.dir_prefix);
1105 FREE_MAYBE (opt.input_filename);
1106 FREE_MAYBE (opt.output_document);
1107 free_vec (opt.accepts);
1108 free_vec (opt.rejects);
1109 free_vec (opt.excludes);
1110 free_vec (opt.includes);
1111 free_vec (opt.domains);
1112 free_vec (opt.follow_tags);
1113 free_vec (opt.ignore_tags);
1114 FREE_MAYBE (opt.progress_type);
1115 xfree (opt.ftp_acc);
1116 FREE_MAYBE (opt.ftp_pass);
1117 FREE_MAYBE (opt.ftp_proxy);
1118 FREE_MAYBE (opt.https_proxy);
1119 FREE_MAYBE (opt.http_proxy);
1120 free_vec (opt.no_proxy);
1121 FREE_MAYBE (opt.useragent);
1122 FREE_MAYBE (opt.referer);
1123 FREE_MAYBE (opt.http_user);
1124 FREE_MAYBE (opt.http_passwd);
1125 FREE_MAYBE (opt.user_header);
1127 FREE_MAYBE (opt.sslcertkey);
1128 FREE_MAYBE (opt.sslcertfile);
1129 #endif /* HAVE_SSL */
1130 FREE_MAYBE (opt.bind_address);
1131 FREE_MAYBE (opt.cookies_input);
1132 FREE_MAYBE (opt.cookies_output);