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 cookie_jar_delete */
63 extern struct cookie_jar *wget_cookie_jar;
65 /* We want tilde expansion enabled only when reading `.wgetrc' lines;
66 otherwise, it will be performed by the shell. This variable will
67 be set by the wgetrc-reading function. */
69 static int enable_tilde_expansion;
72 #define CMD_DECLARE(func) static int func \
73 PARAMS ((const char *, const char *, void *))
75 CMD_DECLARE (cmd_boolean);
76 CMD_DECLARE (cmd_bytes);
77 CMD_DECLARE (cmd_directory_vector);
78 CMD_DECLARE (cmd_lockable_boolean);
79 CMD_DECLARE (cmd_number);
80 CMD_DECLARE (cmd_number_inf);
81 CMD_DECLARE (cmd_string);
82 CMD_DECLARE (cmd_file);
83 CMD_DECLARE (cmd_directory);
84 CMD_DECLARE (cmd_time);
85 CMD_DECLARE (cmd_vector);
87 CMD_DECLARE (cmd_spec_dirstruct);
88 CMD_DECLARE (cmd_spec_header);
89 CMD_DECLARE (cmd_spec_htmlify);
90 CMD_DECLARE (cmd_spec_mirror);
91 CMD_DECLARE (cmd_spec_progress);
92 CMD_DECLARE (cmd_spec_recursive);
93 CMD_DECLARE (cmd_spec_useragent);
95 /* List of recognized commands, each consisting of name, closure and function.
96 When adding a new command, simply add it to the list, but be sure to keep the
97 list sorted alphabetically, as comind() depends on it. Also, be sure to add
98 any entries that allocate memory (e.g. cmd_string and cmd_vector guys) to the
99 cleanup() function below. */
103 int (*action) PARAMS ((const char *, const char *, void *));
105 { "accept", &opt.accepts, cmd_vector },
106 { "addhostdir", &opt.add_hostdir, cmd_boolean },
107 { "alwaysrest", &opt.always_rest, cmd_boolean }, /* deprecated */
108 { "background", &opt.background, cmd_boolean },
109 { "backupconverted", &opt.backup_converted, cmd_boolean },
110 { "backups", &opt.backups, cmd_number },
111 { "base", &opt.base_href, cmd_string },
112 { "bindaddress", &opt.bind_address, cmd_string },
113 { "cache", &opt.allow_cache, cmd_boolean },
114 { "continue", &opt.always_rest, cmd_boolean },
115 { "convertlinks", &opt.convert_links, cmd_boolean },
116 { "cookies", &opt.cookies, cmd_boolean },
117 { "cutdirs", &opt.cut_dirs, cmd_number },
119 { "debug", &opt.debug, cmd_boolean },
121 { "deleteafter", &opt.delete_after, cmd_boolean },
122 { "dirprefix", &opt.dir_prefix, cmd_directory },
123 { "dirstruct", NULL, cmd_spec_dirstruct },
124 { "domains", &opt.domains, cmd_vector },
125 { "dotbytes", &opt.dot_bytes, cmd_bytes },
126 { "dotsinline", &opt.dots_in_line, cmd_number },
127 { "dotspacing", &opt.dot_spacing, cmd_number },
128 { "dotstyle", &opt.dot_style, cmd_string },
130 { "egdfile", &opt.sslegdsock, cmd_file },
132 { "excludedirectories", &opt.excludes, cmd_directory_vector },
133 { "excludedomains", &opt.exclude_domains, cmd_vector },
134 { "followftp", &opt.follow_ftp, cmd_boolean },
135 { "followtags", &opt.follow_tags, cmd_vector },
136 { "forcehtml", &opt.force_html, cmd_boolean },
137 { "ftpproxy", &opt.ftp_proxy, cmd_string },
138 { "glob", &opt.ftp_glob, cmd_boolean },
139 { "header", NULL, cmd_spec_header },
140 { "htmlextension", &opt.html_extension, cmd_boolean },
141 { "htmlify", NULL, cmd_spec_htmlify },
142 { "httpkeepalive", &opt.http_keep_alive, cmd_boolean },
143 { "httppasswd", &opt.http_passwd, cmd_string },
144 { "httpproxy", &opt.http_proxy, cmd_string },
145 { "httpsproxy", &opt.https_proxy, cmd_string },
146 { "httpuser", &opt.http_user, cmd_string },
147 { "ignorelength", &opt.ignore_length, cmd_boolean },
148 { "ignoretags", &opt.ignore_tags, cmd_vector },
149 { "includedirectories", &opt.includes, cmd_directory_vector },
150 { "input", &opt.input_filename, cmd_file },
151 { "killlonger", &opt.kill_longer, cmd_boolean },
152 { "limitrate", &opt.limit_rate, cmd_bytes },
153 { "loadcookies", &opt.cookies_input, cmd_file },
154 { "logfile", &opt.lfilename, cmd_file },
155 { "login", &opt.ftp_acc, cmd_string },
156 { "mirror", NULL, cmd_spec_mirror },
157 { "netrc", &opt.netrc, cmd_boolean },
158 { "noclobber", &opt.noclobber, cmd_boolean },
159 { "noparent", &opt.no_parent, cmd_boolean },
160 { "noproxy", &opt.no_proxy, cmd_vector },
161 { "numtries", &opt.ntry, cmd_number_inf },/* deprecated*/
162 { "outputdocument", &opt.output_document, cmd_file },
163 { "pagerequisites", &opt.page_requisites, cmd_boolean },
164 { "passiveftp", &opt.ftp_pasv, cmd_lockable_boolean },
165 { "passwd", &opt.ftp_pass, cmd_string },
166 { "postdata", &opt.post_data, cmd_string },
167 { "postfile", &opt.post_file_name, cmd_file },
168 { "progress", &opt.progress_type, cmd_spec_progress },
169 { "proxypasswd", &opt.proxy_passwd, cmd_string },
170 { "proxyuser", &opt.proxy_user, cmd_string },
171 { "quiet", &opt.quiet, cmd_boolean },
172 { "quota", &opt.quota, cmd_bytes },
173 { "randomwait", &opt.random_wait, cmd_boolean },
174 { "reclevel", &opt.reclevel, cmd_number_inf },
175 { "recursive", NULL, cmd_spec_recursive },
176 { "referer", &opt.referer, cmd_string },
177 { "reject", &opt.rejects, cmd_vector },
178 { "relativeonly", &opt.relative_only, cmd_boolean },
179 { "removelisting", &opt.remove_listing, cmd_boolean },
180 { "retrsymlinks", &opt.retr_symlinks, cmd_boolean },
181 { "robots", &opt.use_robots, cmd_boolean },
182 { "savecookies", &opt.cookies_output, cmd_file },
183 { "saveheaders", &opt.save_headers, cmd_boolean },
184 { "serverresponse", &opt.server_response, cmd_boolean },
185 { "spanhosts", &opt.spanhost, cmd_boolean },
186 { "spider", &opt.spider, cmd_boolean },
188 { "sslcertfile", &opt.sslcertfile, cmd_file },
189 { "sslcertkey", &opt.sslcertkey, cmd_file },
190 #endif /* HAVE_SSL */
191 { "timeout", &opt.timeout, cmd_time },
192 { "timestamping", &opt.timestamping, cmd_boolean },
193 { "tries", &opt.ntry, cmd_number_inf },
194 { "useproxy", &opt.use_proxy, cmd_boolean },
195 { "useragent", NULL, cmd_spec_useragent },
196 { "verbose", &opt.verbose, cmd_boolean },
197 { "wait", &opt.wait, cmd_time },
198 { "waitretry", &opt.waitretry, cmd_time }
201 /* Look up COM in the commands[] array and return its index. If COM
202 is not found, -1 is returned. This function uses binary search. */
205 comind (const char *com)
207 int lo = 0, hi = ARRAY_SIZE (commands) - 1;
211 int mid = (lo + hi) >> 1;
212 int cmp = strcasecmp (com, commands[mid].name);
223 /* Reset the variables to default values. */
229 /* Most of the default values are 0. Just reset everything, and
230 fill in the non-zero values. Note that initializing pointers to
231 NULL this way is technically illegal, but porting Wget to a
232 machine where NULL is not all-zero bit pattern will be the least
233 of the implementors' worries. */
234 memset (&opt, 0, sizeof (opt));
239 opt.dir_prefix = xstrdup (".");
243 opt.ftp_acc = xstrdup ("anonymous");
244 opt.ftp_pass = xstrdup ("-wget@");
248 opt.http_keep_alive = 1;
250 tmp = getenv ("no_proxy");
252 opt.no_proxy = sepstring (tmp);
260 opt.remove_listing = 1;
262 opt.dot_bytes = 1024;
263 opt.dot_spacing = 10;
264 opt.dots_in_line = 50;
267 /* Return the user's home directory (strdup-ed), or NULL if none is
272 char *home = getenv ("HOME");
277 /* If HOME is not defined, try getting it from the password
279 struct passwd *pwd = getpwuid (getuid ());
280 if (!pwd || !pwd->pw_dir)
285 /* #### Maybe I should grab home_dir from registry, but the best
286 that I could get from there is user's Start menu. It sucks! */
290 return home ? xstrdup (home) : NULL;
293 /* Return the path to the user's .wgetrc. This is either the value of
294 `WGETRC' environment variable, or `$HOME/.wgetrc'.
296 If the `WGETRC' variable exists but the file does not exist, the
297 function will exit(). */
299 wgetrc_file_name (void)
304 /* Try the environment. */
305 env = getenv ("WGETRC");
308 if (!file_exists_p (env))
310 fprintf (stderr, "%s: %s: %s.\n", exec_name, env, strerror (errno));
313 return xstrdup (env);
317 /* If that failed, try $HOME/.wgetrc. */
321 file = (char *)xmalloc (strlen (home) + 1 + strlen (".wgetrc") + 1);
322 sprintf (file, "%s/.wgetrc", home);
326 /* Under Windows, "home" is (for the purposes of this function) the
327 directory where `wget.exe' resides, and `wget.ini' will be used
328 as file name. SYSTEM_WGETRC should not be defined under WINDOWS.
330 It is not as trivial as I assumed, because on 95 argv[0] is full
331 path, but on NT you get what you typed in command line. --dbudor */
335 file = (char *)xmalloc (strlen (home) + strlen ("wget.ini") + 1);
336 sprintf (file, "%swget.ini", home);
342 if (!file_exists_p (file))
350 /* Initialize variables from a wgetrc file */
352 run_wgetrc (const char *file)
358 fp = fopen (file, "rb");
361 fprintf (stderr, _("%s: Cannot read %s (%s).\n"), exec_name,
362 file, strerror (errno));
365 enable_tilde_expansion = 1;
367 while ((line = read_whole_line (fp)))
372 /* Parse the line. */
373 status = parse_line (line, &com, &val);
375 /* If everything is OK, set the value. */
378 if (!setval (com, val))
379 fprintf (stderr, _("%s: Error in %s at line %d.\n"), exec_name,
384 else if (status == 0)
385 fprintf (stderr, _("%s: Error in %s at line %d.\n"), exec_name,
389 enable_tilde_expansion = 0;
393 /* Initialize the defaults and run the system wgetrc and user's own
400 /* Load the hard-coded defaults. */
403 /* If SYSTEM_WGETRC is defined, use it. */
405 if (file_exists_p (SYSTEM_WGETRC))
406 run_wgetrc (SYSTEM_WGETRC);
408 /* Override it with your own, if one exists. */
409 file = wgetrc_file_name ();
412 /* #### We should somehow canonicalize `file' and SYSTEM_WGETRC,
415 if (!strcmp (file, SYSTEM_WGETRC))
417 fprintf (stderr, _("\
418 %s: Warning: Both system and user wgetrc point to `%s'.\n"),
428 /* Parse the line pointed by line, with the syntax:
429 <sp>* command <sp>* = <sp>* value <newline>
430 Uses malloc to allocate space for command and value.
431 If the line is invalid, data is freed and 0 is returned.
438 parse_line (const char *line, char **com, char **val)
440 const char *p = line;
441 const char *orig_comptr, *end;
444 /* Skip whitespace. */
445 while (*p && ISSPACE (*p))
448 /* Don't process empty lines. */
449 if (!*p || *p == '#')
452 for (orig_comptr = p; ISALPHA (*p) || *p == '_' || *p == '-'; p++)
454 /* The next char should be space or '='. */
455 if (!ISSPACE (*p) && (*p != '='))
457 /* Here we cannot use strdupdelim() as we normally would because we
458 want to skip the `-' and `_' characters in the input string. */
459 *com = (char *)xmalloc (p - orig_comptr + 1);
460 for (new_comptr = *com; orig_comptr < p; orig_comptr++)
462 if (*orig_comptr == '_' || *orig_comptr == '-')
464 *new_comptr++ = *orig_comptr;
467 /* If the command is invalid, exit now. */
468 if (comind (*com) == -1)
474 /* Skip spaces before '='. */
475 for (; ISSPACE (*p); p++);
476 /* If '=' not found, bail out. */
482 /* Skip spaces after '='. */
483 for (++p; ISSPACE (*p); p++);
484 /* Get the ending position for VAL by starting with the end of the
485 line and skipping whitespace. */
486 end = line + strlen (line) - 1;
487 while (end > p && ISSPACE (*end))
489 *val = strdupdelim (p, end + 1);
493 /* Set COM to VAL. This is the meat behind processing `.wgetrc'. No
494 fatals -- error signal prints a warning and resets to default
495 value. All error messages are printed to stderr, *not* to
496 opt.lfile, since opt.lfile wasn't even generated yet. */
498 setval (const char *com, const char *val)
507 /* #### Should I just abort()? */
509 fprintf (stderr, _("%s: BUG: unknown command `%s', value `%s'.\n"),
510 exec_name, com, val);
514 return ((*commands[ind].action) (com, val, commands[ind].closure));
517 /* Generic helper functions, for use with `commands'. */
519 static int myatoi PARAMS ((const char *s));
521 /* Store the boolean value from VAL to CLOSURE. COM is ignored,
522 except for error messages. */
524 cmd_boolean (const char *com, const char *val, void *closure)
528 if (!strcasecmp (val, "on")
529 || (*val == '1' && !*(val + 1)))
531 else if (!strcasecmp (val, "off")
532 || (*val == '0' && !*(val + 1)))
536 fprintf (stderr, _("%s: %s: Please specify on or off.\n"),
541 *(int *)closure = bool_value;
545 /* Store the lockable_boolean {2, 1, 0, -1} value from VAL to CLOSURE. COM is
546 ignored, except for error messages. Values 2 and -1 indicate that once
547 defined, the value may not be changed by successive wgetrc files or
548 command-line arguments.
550 Values: 2 - Enable a particular option for good ("always")
551 1 - Enable an option ("on")
552 0 - Disable an option ("off")
553 -1 - Disable an option for good ("never") */
555 cmd_lockable_boolean (const char *com, const char *val, void *closure)
557 int lockable_boolean_value;
560 * If a config file said "always" or "never", don't allow command line
561 * arguments to override the config file.
563 if (*(int *)closure == -1 || *(int *)closure == 2)
566 if (!strcasecmp (val, "always")
567 || (*val == '2' && !*(val + 1)))
568 lockable_boolean_value = 2;
569 else if (!strcasecmp (val, "on")
570 || (*val == '1' && !*(val + 1)))
571 lockable_boolean_value = 1;
572 else if (!strcasecmp (val, "off")
573 || (*val == '0' && !*(val + 1)))
574 lockable_boolean_value = 0;
575 else if (!strcasecmp (val, "never")
576 || (*val == '-' && *(val + 1) == '1' && !*(val + 2)))
577 lockable_boolean_value = -1;
580 fprintf (stderr, _("%s: %s: Please specify always, on, off, "
586 *(int *)closure = lockable_boolean_value;
590 /* Set the non-negative integer value from VAL to CLOSURE. With
591 incorrect specification, the number remains unchanged. */
593 cmd_number (const char *com, const char *val, void *closure)
595 int num = myatoi (val);
599 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
600 exec_name, com, val);
603 *(int *)closure = num;
607 /* Similar to cmd_number(), only accepts `inf' as a synonym for 0. */
609 cmd_number_inf (const char *com, const char *val, void *closure)
611 if (!strcasecmp (val, "inf"))
616 return cmd_number (com, val, closure);
619 /* Copy (strdup) the string at COM to a new location and place a
620 pointer to *CLOSURE. */
622 cmd_string (const char *com, const char *val, void *closure)
624 char **pstring = (char **)closure;
626 FREE_MAYBE (*pstring);
627 *pstring = xstrdup (val);
631 /* Like the above, but handles tilde-expansion when reading a user's
632 `.wgetrc'. In that case, and if VAL begins with `~', the tilde
633 gets expanded to the user's home directory. */
635 cmd_file (const char *com, const char *val, void *closure)
637 char **pstring = (char **)closure;
639 FREE_MAYBE (*pstring);
641 /* #### If VAL is empty, perhaps should set *CLOSURE to NULL. */
643 if (!enable_tilde_expansion || !(*val == '~' && (*(val + 1) == '/'
645 || *(val + 1) == '\\'
650 *pstring = xstrdup (val);
656 char *home = home_dir ();
660 homelen = strlen (home);
661 while (homelen && (home[homelen - 1] == '/'
663 || home[homelen - 1] == '\\'
666 home[--homelen] = '\0';
668 /* Skip the leading "~/". */
670 for (++val; *val == '/' || *val == '\\'; val++)
673 for (++val; *val == '/'; val++)
677 result = xmalloc (homelen + 1 + strlen (val));
678 memcpy (result, home, homelen);
679 result[homelen] = '/';
680 strcpy (result + homelen + 1, val);
685 /* Convert "\" to "/". */
688 for (s = *pstring; *s; s++)
696 /* Like cmd_file, but strips trailing '/' characters. */
698 cmd_directory (const char *com, const char *val, void *closure)
702 /* Call cmd_file() for tilde expansion and separator
703 canonicalization (backslash -> slash under Windows). These
704 things should perhaps be in a separate function. */
705 if (!cmd_file (com, val, closure))
708 s = *(char **)closure;
710 while (t > s && *--t == '/')
716 /* Merge the vector (array of strings separated with `,') in COM with
717 the vector (NULL-terminated array of strings) pointed to by
720 cmd_vector (const char *com, const char *val, void *closure)
722 char ***pvec = (char ***)closure;
725 *pvec = merge_vecs (*pvec, sepstring (val));
735 cmd_directory_vector (const char *com, const char *val, void *closure)
737 char ***pvec = (char ***)closure;
741 /* Strip the trailing slashes from directories. */
744 seps = sepstring (val);
745 for (t = seps; t && *t; t++)
747 int len = strlen (*t);
748 /* Skip degenerate case of root directory. */
751 if ((*t)[len - 1] == '/')
752 (*t)[len - 1] = '\0';
755 *pvec = merge_vecs (*pvec, seps);
765 /* Set the value stored in VAL to CLOSURE (which should point to a
766 long int), allowing several postfixes, with the following syntax
770 [0-9]+[kK] -> bytes * 1024
771 [0-9]+[mM] -> bytes * 1024 * 1024
774 Anything else is flagged as incorrect, and CLOSURE is unchanged. */
776 cmd_bytes (const char *com, const char *val, void *closure)
779 long *out = (long *)closure;
784 /* Check for "inf". */
785 if (p[0] == 'i' && p[1] == 'n' && p[2] == 'f' && p[3] == '\0')
790 /* Search for digits and construct result. */
791 for (; *p && ISDIGIT (*p); p++)
792 result = (10 * result) + (*p - '0');
793 /* If no digits were found, or more than one character is following
795 if (p == val || (*p != '\0' && *(p + 1) != '\0'))
797 printf (_("%s: Invalid specification `%s'\n"), com, val);
800 /* Search for a designator. */
801 switch (TOLOWER (*p))
812 result *= (long)1024 * 1024;
816 result *= (long)1024 * 1024 * 1024;
819 printf (_("%s: Invalid specification `%s'\n"), com, val);
826 /* Store the value of VAL to *OUT, allowing suffixes for minutes and
829 cmd_time (const char *com, const char *val, void *closure)
834 /* Search for digits and construct result. */
835 for (; *p && ISDIGIT (*p); p++)
836 result = (10 * result) + (*p - '0');
837 /* If no digits were found, or more than one character is following
839 if (p == val || (*p != '\0' && *(p + 1) != '\0'))
841 printf (_("%s: Invalid specification `%s'\n"), com, val);
844 /* Search for a suffix. */
845 switch (TOLOWER (*p))
859 /* Days (overflow on 16bit machines) */
867 printf (_("%s: Invalid specification `%s'\n"), com, val);
870 *(long *)closure = result;
874 /* Specialized helper functions, used by `commands' to handle some
875 options specially. */
877 static int check_user_specified_header PARAMS ((const char *));
880 cmd_spec_dirstruct (const char *com, const char *val, void *closure)
882 if (!cmd_boolean (com, val, &opt.dirstruct))
884 /* Since dirstruct behaviour is explicitly changed, no_dirstruct
885 must be affected inversely. */
887 opt.no_dirstruct = 0;
889 opt.no_dirstruct = 1;
894 cmd_spec_header (const char *com, const char *val, void *closure)
898 /* Empty header means reset headers. */
899 FREE_MAYBE (opt.user_header);
900 opt.user_header = NULL;
906 if (!check_user_specified_header (val))
908 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
909 exec_name, com, val);
912 i = opt.user_header ? strlen (opt.user_header) : 0;
913 opt.user_header = (char *)xrealloc (opt.user_header, i + strlen (val)
915 strcpy (opt.user_header + i, val);
917 opt.user_header[i++] = '\r';
918 opt.user_header[i++] = '\n';
919 opt.user_header[i] = '\0';
925 cmd_spec_htmlify (const char *com, const char *val, void *closure)
927 int flag = cmd_boolean (com, val, &opt.htmlify);
928 if (flag && !opt.htmlify)
929 opt.remove_listing = 0;
934 cmd_spec_mirror (const char *com, const char *val, void *closure)
938 if (!cmd_boolean (com, val, &mirror))
943 if (!opt.no_dirstruct)
945 opt.timestamping = 1;
946 opt.reclevel = INFINITE_RECURSION;
947 opt.remove_listing = 0;
953 cmd_spec_progress (const char *com, const char *val, void *closure)
955 if (!valid_progress_implementation_p (val))
957 fprintf (stderr, _("%s: %s: Invalid progress type `%s'.\n"),
958 exec_name, com, val);
961 FREE_MAYBE (opt.progress_type);
963 /* Don't call set_progress_implementation here. It will be called
964 in main() when it becomes clear what the log output is. */
965 opt.progress_type = xstrdup (val);
970 cmd_spec_recursive (const char *com, const char *val, void *closure)
972 if (!cmd_boolean (com, val, &opt.recursive))
976 if (opt.recursive && !opt.no_dirstruct)
983 cmd_spec_useragent (const char *com, const char *val, void *closure)
985 /* Just check for empty string and newline, so we don't throw total
986 junk to the server. */
987 if (!*val || strchr (val, '\n'))
989 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
990 exec_name, com, val);
993 opt.useragent = xstrdup (val);
997 /* Miscellaneous useful routines. */
999 /* Return the integer value of a positive integer written in S, or -1
1000 if an error was encountered. */
1002 myatoi (const char *s)
1005 const char *orig = s;
1007 for (res = 0; *s && ISDIGIT (*s); s++)
1008 res = 10 * res + (*s - '0');
1009 if (*s || orig == s)
1015 #define ISODIGIT(x) ((x) >= '0' && (x) <= '7')
1018 check_user_specified_header (const char *s)
1022 for (p = s; *p && *p != ':' && !ISSPACE (*p); p++);
1023 /* The header MUST contain `:' preceded by at least one
1024 non-whitespace character. */
1025 if (*p != ':' || p == s)
1027 /* The header MUST NOT contain newlines. */
1028 if (strchr (s, '\n'))
1033 void cleanup_html_url PARAMS ((void));
1034 void res_cleanup PARAMS ((void));
1035 void downloaded_files_free PARAMS ((void));
1036 void http_cleanup PARAMS ((void));
1039 /* Free the memory allocated by global variables. */
1043 /* Free external resources, close files, etc. */
1048 /* We're exiting anyway so there's no real need to call free()
1049 hundreds of times. Skipping the frees will make Wget exit
1052 However, when detecting leaks, it's crucial to free() everything
1053 because then you can find the real leaks, i.e. the allocated
1054 memory which grows with the size of the program. */
1057 recursive_cleanup ();
1060 cleanup_html_url ();
1061 downloaded_files_free ();
1063 cookie_jar_delete (wget_cookie_jar);
1066 extern acc_t *netrc_list;
1067 free_netrc (netrc_list);
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 FREE_MAYBE (opt.progress_type);
1081 xfree (opt.ftp_acc);
1082 FREE_MAYBE (opt.ftp_pass);
1083 FREE_MAYBE (opt.ftp_proxy);
1084 FREE_MAYBE (opt.https_proxy);
1085 FREE_MAYBE (opt.http_proxy);
1086 free_vec (opt.no_proxy);
1087 FREE_MAYBE (opt.useragent);
1088 FREE_MAYBE (opt.referer);
1089 FREE_MAYBE (opt.http_user);
1090 FREE_MAYBE (opt.http_passwd);
1091 FREE_MAYBE (opt.user_header);
1093 FREE_MAYBE (opt.sslcertkey);
1094 FREE_MAYBE (opt.sslcertfile);
1095 #endif /* HAVE_SSL */
1096 FREE_MAYBE (opt.bind_address);
1097 FREE_MAYBE (opt.cookies_input);
1098 FREE_MAYBE (opt.cookies_output);