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.
21 In addition, as a special exception, the Free Software Foundation
22 gives permission to link the code of its release of Wget with the
23 OpenSSL project's "OpenSSL" library (or with modified versions of it
24 that use the same license as the "OpenSSL" library), and distribute
25 the linked executables. You must obey the GNU General Public License
26 in all respects for all of the code used other than "OpenSSL". If you
27 modify this file, you may extend this exception to your version of the
28 file, but you are not obligated to do so. If you do not wish to do
29 so, delete this exception statement from your version. */
34 #include <sys/types.h>
49 # include <sys/socket.h>
50 # include <netinet/in.h>
52 # include <arpa/inet.h>
66 #include "cookies.h" /* for cookie_jar_delete */
73 extern struct cookie_jar *wget_cookie_jar;
75 /* We want tilde expansion enabled only when reading `.wgetrc' lines;
76 otherwise, it will be performed by the shell. This variable will
77 be set by the wgetrc-reading function. */
79 static int enable_tilde_expansion;
82 #define CMD_DECLARE(func) static int func \
83 PARAMS ((const char *, const char *, void *))
85 CMD_DECLARE (cmd_boolean);
86 CMD_DECLARE (cmd_bytes);
87 CMD_DECLARE (cmd_directory_vector);
88 CMD_DECLARE (cmd_lockable_boolean);
89 CMD_DECLARE (cmd_number);
90 CMD_DECLARE (cmd_number_inf);
91 CMD_DECLARE (cmd_string);
92 CMD_DECLARE (cmd_file);
93 CMD_DECLARE (cmd_directory);
94 CMD_DECLARE (cmd_time);
95 CMD_DECLARE (cmd_vector);
97 CMD_DECLARE (cmd_spec_dirstruct);
98 CMD_DECLARE (cmd_spec_header);
99 CMD_DECLARE (cmd_spec_htmlify);
100 CMD_DECLARE (cmd_spec_mirror);
101 CMD_DECLARE (cmd_spec_progress);
102 CMD_DECLARE (cmd_spec_recursive);
103 CMD_DECLARE (cmd_spec_useragent);
105 /* List of recognized commands, each consisting of name, closure and function.
106 When adding a new command, simply add it to the list, but be sure to keep the
107 list sorted alphabetically, as comind() depends on it. Also, be sure to add
108 any entries that allocate memory (e.g. cmd_string and cmd_vector guys) to the
109 cleanup() function below. */
113 int (*action) PARAMS ((const char *, const char *, void *));
115 { "accept", &opt.accepts, cmd_vector },
116 { "addhostdir", &opt.add_hostdir, cmd_boolean },
117 { "alwaysrest", &opt.always_rest, cmd_boolean }, /* deprecated */
118 { "background", &opt.background, cmd_boolean },
119 { "backupconverted", &opt.backup_converted, cmd_boolean },
120 { "backups", &opt.backups, cmd_number },
121 { "base", &opt.base_href, cmd_string },
122 { "bindaddress", &opt.bind_address, cmd_string },
123 { "cache", &opt.allow_cache, cmd_boolean },
124 { "continue", &opt.always_rest, cmd_boolean },
125 { "convertlinks", &opt.convert_links, cmd_boolean },
126 { "cookies", &opt.cookies, cmd_boolean },
127 { "cutdirs", &opt.cut_dirs, cmd_number },
129 { "debug", &opt.debug, cmd_boolean },
131 { "deleteafter", &opt.delete_after, cmd_boolean },
132 { "dirprefix", &opt.dir_prefix, cmd_directory },
133 { "dirstruct", NULL, cmd_spec_dirstruct },
134 { "domains", &opt.domains, cmd_vector },
135 { "dotbytes", &opt.dot_bytes, cmd_bytes },
136 { "dotsinline", &opt.dots_in_line, cmd_number },
137 { "dotspacing", &opt.dot_spacing, cmd_number },
138 { "dotstyle", &opt.dot_style, cmd_string },
140 { "egdfile", &opt.sslegdsock, cmd_file },
142 { "excludedirectories", &opt.excludes, cmd_directory_vector },
143 { "excludedomains", &opt.exclude_domains, cmd_vector },
144 { "followftp", &opt.follow_ftp, cmd_boolean },
145 { "followtags", &opt.follow_tags, cmd_vector },
146 { "forcehtml", &opt.force_html, cmd_boolean },
147 { "ftpproxy", &opt.ftp_proxy, cmd_string },
148 { "glob", &opt.ftp_glob, cmd_boolean },
149 { "header", NULL, cmd_spec_header },
150 { "htmlextension", &opt.html_extension, cmd_boolean },
151 { "htmlify", NULL, cmd_spec_htmlify },
152 { "httpkeepalive", &opt.http_keep_alive, cmd_boolean },
153 { "httppasswd", &opt.http_passwd, cmd_string },
154 { "httpproxy", &opt.http_proxy, cmd_string },
155 { "httpsproxy", &opt.https_proxy, cmd_string },
156 { "httpuser", &opt.http_user, cmd_string },
157 { "ignorelength", &opt.ignore_length, cmd_boolean },
158 { "ignoretags", &opt.ignore_tags, cmd_vector },
159 { "includedirectories", &opt.includes, cmd_directory_vector },
160 { "input", &opt.input_filename, cmd_file },
161 { "killlonger", &opt.kill_longer, cmd_boolean },
162 { "limitrate", &opt.limit_rate, cmd_bytes },
163 { "loadcookies", &opt.cookies_input, cmd_file },
164 { "logfile", &opt.lfilename, cmd_file },
165 { "login", &opt.ftp_acc, cmd_string },
166 { "mirror", NULL, cmd_spec_mirror },
167 { "netrc", &opt.netrc, cmd_boolean },
168 { "noclobber", &opt.noclobber, cmd_boolean },
169 { "noparent", &opt.no_parent, cmd_boolean },
170 { "noproxy", &opt.no_proxy, cmd_vector },
171 { "numtries", &opt.ntry, cmd_number_inf },/* deprecated*/
172 { "outputdocument", &opt.output_document, cmd_file },
173 { "pagerequisites", &opt.page_requisites, cmd_boolean },
174 { "passiveftp", &opt.ftp_pasv, cmd_lockable_boolean },
175 { "passwd", &opt.ftp_pass, cmd_string },
176 { "postdata", &opt.post_data, cmd_string },
177 { "postfile", &opt.post_file_name, cmd_file },
178 { "progress", &opt.progress_type, cmd_spec_progress },
179 { "proxypasswd", &opt.proxy_passwd, cmd_string },
180 { "proxyuser", &opt.proxy_user, cmd_string },
181 { "quiet", &opt.quiet, cmd_boolean },
182 { "quota", &opt.quota, cmd_bytes },
183 { "randomwait", &opt.random_wait, cmd_boolean },
184 { "reclevel", &opt.reclevel, cmd_number_inf },
185 { "recursive", NULL, cmd_spec_recursive },
186 { "referer", &opt.referer, cmd_string },
187 { "reject", &opt.rejects, cmd_vector },
188 { "relativeonly", &opt.relative_only, cmd_boolean },
189 { "removelisting", &opt.remove_listing, cmd_boolean },
190 { "retrsymlinks", &opt.retr_symlinks, cmd_boolean },
191 { "robots", &opt.use_robots, cmd_boolean },
192 { "savecookies", &opt.cookies_output, cmd_file },
193 { "saveheaders", &opt.save_headers, cmd_boolean },
194 { "serverresponse", &opt.server_response, cmd_boolean },
195 { "spanhosts", &opt.spanhost, cmd_boolean },
196 { "spider", &opt.spider, cmd_boolean },
198 { "sslcadir", &opt.sslcadir, cmd_directory },
199 { "sslcafile", &opt.sslcafile, cmd_file },
200 { "sslcertfile", &opt.sslcertfile, cmd_file },
201 { "sslcertkey", &opt.sslcertkey, cmd_file },
202 { "sslcerttype", &opt.sslcerttype, cmd_number },
203 { "sslcheckcert", &opt.sslcheckcert, cmd_number },
204 { "sslprotocol", &opt.sslprotocol, cmd_number },
205 #endif /* HAVE_SSL */
206 { "timeout", &opt.timeout, cmd_time },
207 { "timestamping", &opt.timestamping, cmd_boolean },
208 { "tries", &opt.ntry, cmd_number_inf },
209 { "useproxy", &opt.use_proxy, cmd_boolean },
210 { "useragent", NULL, cmd_spec_useragent },
211 { "verbose", &opt.verbose, cmd_boolean },
212 { "wait", &opt.wait, cmd_time },
213 { "waitretry", &opt.waitretry, cmd_time }
216 /* Look up COM in the commands[] array and return its index. If COM
217 is not found, -1 is returned. This function uses binary search. */
220 comind (const char *com)
222 int lo = 0, hi = ARRAY_SIZE (commands) - 1;
226 int mid = (lo + hi) >> 1;
227 int cmp = strcasecmp (com, commands[mid].name);
238 /* Reset the variables to default values. */
244 /* Most of the default values are 0. Just reset everything, and
245 fill in the non-zero values. Note that initializing pointers to
246 NULL this way is technically illegal, but porting Wget to a
247 machine where NULL is not all-zero bit pattern will be the least
248 of the implementors' worries. */
249 memset (&opt, 0, sizeof (opt));
254 opt.dir_prefix = xstrdup (".");
258 opt.ftp_acc = xstrdup ("anonymous");
259 opt.ftp_pass = xstrdup ("-wget@");
263 opt.http_keep_alive = 1;
265 tmp = getenv ("no_proxy");
267 opt.no_proxy = sepstring (tmp);
275 opt.remove_listing = 1;
277 opt.dot_bytes = 1024;
278 opt.dot_spacing = 10;
279 opt.dots_in_line = 50;
282 /* Return the user's home directory (strdup-ed), or NULL if none is
287 char *home = getenv ("HOME");
292 /* If HOME is not defined, try getting it from the password
294 struct passwd *pwd = getpwuid (getuid ());
295 if (!pwd || !pwd->pw_dir)
300 /* #### Maybe I should grab home_dir from registry, but the best
301 that I could get from there is user's Start menu. It sucks! */
305 return home ? xstrdup (home) : NULL;
308 /* Return the path to the user's .wgetrc. This is either the value of
309 `WGETRC' environment variable, or `$HOME/.wgetrc'.
311 If the `WGETRC' variable exists but the file does not exist, the
312 function will exit(). */
314 wgetrc_file_name (void)
319 /* Try the environment. */
320 env = getenv ("WGETRC");
323 if (!file_exists_p (env))
325 fprintf (stderr, "%s: %s: %s.\n", exec_name, env, strerror (errno));
328 return xstrdup (env);
332 /* If that failed, try $HOME/.wgetrc. */
336 file = (char *)xmalloc (strlen (home) + 1 + strlen (".wgetrc") + 1);
337 sprintf (file, "%s/.wgetrc", home);
341 /* Under Windows, "home" is (for the purposes of this function) the
342 directory where `wget.exe' resides, and `wget.ini' will be used
343 as file name. SYSTEM_WGETRC should not be defined under WINDOWS.
345 It is not as trivial as I assumed, because on 95 argv[0] is full
346 path, but on NT you get what you typed in command line. --dbudor */
350 file = (char *)xmalloc (strlen (home) + strlen ("wget.ini") + 1);
351 sprintf (file, "%swget.ini", home);
357 if (!file_exists_p (file))
365 /* Initialize variables from a wgetrc file */
367 run_wgetrc (const char *file)
373 fp = fopen (file, "rb");
376 fprintf (stderr, _("%s: Cannot read %s (%s).\n"), exec_name,
377 file, strerror (errno));
380 enable_tilde_expansion = 1;
382 while ((line = read_whole_line (fp)))
387 /* Parse the line. */
388 status = parse_line (line, &com, &val);
390 /* If everything is OK, set the value. */
393 if (!setval (com, val))
394 fprintf (stderr, _("%s: Error in %s at line %d.\n"), exec_name,
399 else if (status == 0)
400 fprintf (stderr, _("%s: Error in %s at line %d.\n"), exec_name,
404 enable_tilde_expansion = 0;
408 /* Initialize the defaults and run the system wgetrc and user's own
415 /* Load the hard-coded defaults. */
418 /* If SYSTEM_WGETRC is defined, use it. */
420 if (file_exists_p (SYSTEM_WGETRC))
421 run_wgetrc (SYSTEM_WGETRC);
423 /* Override it with your own, if one exists. */
424 file = wgetrc_file_name ();
427 /* #### We should somehow canonicalize `file' and SYSTEM_WGETRC,
430 if (!strcmp (file, SYSTEM_WGETRC))
432 fprintf (stderr, _("\
433 %s: Warning: Both system and user wgetrc point to `%s'.\n"),
443 /* Parse the line pointed by line, with the syntax:
444 <sp>* command <sp>* = <sp>* value <newline>
445 Uses malloc to allocate space for command and value.
446 If the line is invalid, data is freed and 0 is returned.
453 parse_line (const char *line, char **com, char **val)
455 const char *p = line;
456 const char *orig_comptr, *end;
459 /* Skip whitespace. */
460 while (*p && ISSPACE (*p))
463 /* Don't process empty lines. */
464 if (!*p || *p == '#')
467 for (orig_comptr = p; ISALPHA (*p) || *p == '_' || *p == '-'; p++)
469 /* The next char should be space or '='. */
470 if (!ISSPACE (*p) && (*p != '='))
472 /* Here we cannot use strdupdelim() as we normally would because we
473 want to skip the `-' and `_' characters in the input string. */
474 *com = (char *)xmalloc (p - orig_comptr + 1);
475 for (new_comptr = *com; orig_comptr < p; orig_comptr++)
477 if (*orig_comptr == '_' || *orig_comptr == '-')
479 *new_comptr++ = *orig_comptr;
482 /* If the command is invalid, exit now. */
483 if (comind (*com) == -1)
489 /* Skip spaces before '='. */
490 for (; ISSPACE (*p); p++);
491 /* If '=' not found, bail out. */
497 /* Skip spaces after '='. */
498 for (++p; ISSPACE (*p); p++);
499 /* Get the ending position for VAL by starting with the end of the
500 line and skipping whitespace. */
501 end = line + strlen (line) - 1;
502 while (end > p && ISSPACE (*end))
504 *val = strdupdelim (p, end + 1);
508 /* Set COM to VAL. This is the meat behind processing `.wgetrc'. No
509 fatals -- error signal prints a warning and resets to default
510 value. All error messages are printed to stderr, *not* to
511 opt.lfile, since opt.lfile wasn't even generated yet. */
513 setval (const char *com, const char *val)
522 /* #### Should I just abort()? */
524 fprintf (stderr, _("%s: BUG: unknown command `%s', value `%s'.\n"),
525 exec_name, com, val);
529 return ((*commands[ind].action) (com, val, commands[ind].closure));
532 /* Generic helper functions, for use with `commands'. */
534 static int myatoi PARAMS ((const char *s));
536 /* Store the boolean value from VAL to CLOSURE. COM is ignored,
537 except for error messages. */
539 cmd_boolean (const char *com, const char *val, void *closure)
543 if (!strcasecmp (val, "on")
544 || (*val == '1' && !*(val + 1)))
546 else if (!strcasecmp (val, "off")
547 || (*val == '0' && !*(val + 1)))
551 fprintf (stderr, _("%s: %s: Please specify on or off.\n"),
556 *(int *)closure = bool_value;
560 /* Store the lockable_boolean {2, 1, 0, -1} value from VAL to CLOSURE. COM is
561 ignored, except for error messages. Values 2 and -1 indicate that once
562 defined, the value may not be changed by successive wgetrc files or
563 command-line arguments.
565 Values: 2 - Enable a particular option for good ("always")
566 1 - Enable an option ("on")
567 0 - Disable an option ("off")
568 -1 - Disable an option for good ("never") */
570 cmd_lockable_boolean (const char *com, const char *val, void *closure)
572 int lockable_boolean_value;
575 * If a config file said "always" or "never", don't allow command line
576 * arguments to override the config file.
578 if (*(int *)closure == -1 || *(int *)closure == 2)
581 if (!strcasecmp (val, "always")
582 || (*val == '2' && !*(val + 1)))
583 lockable_boolean_value = 2;
584 else if (!strcasecmp (val, "on")
585 || (*val == '1' && !*(val + 1)))
586 lockable_boolean_value = 1;
587 else if (!strcasecmp (val, "off")
588 || (*val == '0' && !*(val + 1)))
589 lockable_boolean_value = 0;
590 else if (!strcasecmp (val, "never")
591 || (*val == '-' && *(val + 1) == '1' && !*(val + 2)))
592 lockable_boolean_value = -1;
595 fprintf (stderr, _("%s: %s: Please specify always, on, off, "
601 *(int *)closure = lockable_boolean_value;
605 /* Set the non-negative integer value from VAL to CLOSURE. With
606 incorrect specification, the number remains unchanged. */
608 cmd_number (const char *com, const char *val, void *closure)
610 int num = myatoi (val);
614 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
615 exec_name, com, val);
618 *(int *)closure = num;
622 /* Similar to cmd_number(), only accepts `inf' as a synonym for 0. */
624 cmd_number_inf (const char *com, const char *val, void *closure)
626 if (!strcasecmp (val, "inf"))
631 return cmd_number (com, val, closure);
634 /* Copy (strdup) the string at COM to a new location and place a
635 pointer to *CLOSURE. */
637 cmd_string (const char *com, const char *val, void *closure)
639 char **pstring = (char **)closure;
641 FREE_MAYBE (*pstring);
642 *pstring = xstrdup (val);
646 /* Like the above, but handles tilde-expansion when reading a user's
647 `.wgetrc'. In that case, and if VAL begins with `~', the tilde
648 gets expanded to the user's home directory. */
650 cmd_file (const char *com, const char *val, void *closure)
652 char **pstring = (char **)closure;
654 FREE_MAYBE (*pstring);
656 /* #### If VAL is empty, perhaps should set *CLOSURE to NULL. */
658 if (!enable_tilde_expansion || !(*val == '~' && (*(val + 1) == '/'
660 || *(val + 1) == '\\'
665 *pstring = xstrdup (val);
671 char *home = home_dir ();
675 homelen = strlen (home);
676 while (homelen && (home[homelen - 1] == '/'
678 || home[homelen - 1] == '\\'
681 home[--homelen] = '\0';
683 /* Skip the leading "~/". */
685 for (++val; *val == '/' || *val == '\\'; val++)
688 for (++val; *val == '/'; val++)
692 result = xmalloc (homelen + 1 + strlen (val) + 1);
693 memcpy (result, home, homelen);
694 result[homelen] = '/';
695 strcpy (result + homelen + 1, val);
700 /* Convert "\" to "/". */
703 for (s = *pstring; *s; s++)
711 /* Like cmd_file, but strips trailing '/' characters. */
713 cmd_directory (const char *com, const char *val, void *closure)
717 /* Call cmd_file() for tilde expansion and separator
718 canonicalization (backslash -> slash under Windows). These
719 things should perhaps be in a separate function. */
720 if (!cmd_file (com, val, closure))
723 s = *(char **)closure;
725 while (t > s && *--t == '/')
731 /* Merge the vector (array of strings separated with `,') in COM with
732 the vector (NULL-terminated array of strings) pointed to by
735 cmd_vector (const char *com, const char *val, void *closure)
737 char ***pvec = (char ***)closure;
740 *pvec = merge_vecs (*pvec, sepstring (val));
750 cmd_directory_vector (const char *com, const char *val, void *closure)
752 char ***pvec = (char ***)closure;
756 /* Strip the trailing slashes from directories. */
759 seps = sepstring (val);
760 for (t = seps; t && *t; t++)
762 int len = strlen (*t);
763 /* Skip degenerate case of root directory. */
766 if ((*t)[len - 1] == '/')
767 (*t)[len - 1] = '\0';
770 *pvec = merge_vecs (*pvec, seps);
780 /* Set the value stored in VAL to CLOSURE (which should point to a
781 long int), allowing several postfixes, with the following syntax
785 [0-9]+[kK] -> bytes * 1024
786 [0-9]+[mM] -> bytes * 1024 * 1024
789 Anything else is flagged as incorrect, and CLOSURE is unchanged. */
791 cmd_bytes (const char *com, const char *val, void *closure)
794 long *out = (long *)closure;
799 /* Check for "inf". */
800 if (p[0] == 'i' && p[1] == 'n' && p[2] == 'f' && p[3] == '\0')
805 /* Search for digits and construct result. */
806 for (; *p && ISDIGIT (*p); p++)
807 result = (10 * result) + (*p - '0');
808 /* If no digits were found, or more than one character is following
810 if (p == val || (*p != '\0' && *(p + 1) != '\0'))
812 printf (_("%s: Invalid specification `%s'\n"), com, val);
815 /* Search for a designator. */
816 switch (TOLOWER (*p))
827 result *= (long)1024 * 1024;
831 result *= (long)1024 * 1024 * 1024;
834 printf (_("%s: Invalid specification `%s'\n"), com, val);
841 /* Store the value of VAL to *OUT, allowing suffixes for minutes and
844 cmd_time (const char *com, const char *val, void *closure)
849 /* Search for digits and construct result. */
850 for (; *p && ISDIGIT (*p); p++)
851 result = (10 * result) + (*p - '0');
852 /* If no digits were found, or more than one character is following
854 if (p == val || (*p != '\0' && *(p + 1) != '\0'))
856 printf (_("%s: Invalid specification `%s'\n"), com, val);
859 /* Search for a suffix. */
860 switch (TOLOWER (*p))
874 /* Days (overflow on 16bit machines) */
882 printf (_("%s: Invalid specification `%s'\n"), com, val);
885 *(long *)closure = result;
889 /* Specialized helper functions, used by `commands' to handle some
890 options specially. */
892 static int check_user_specified_header PARAMS ((const char *));
895 cmd_spec_dirstruct (const char *com, const char *val, void *closure)
897 if (!cmd_boolean (com, val, &opt.dirstruct))
899 /* Since dirstruct behaviour is explicitly changed, no_dirstruct
900 must be affected inversely. */
902 opt.no_dirstruct = 0;
904 opt.no_dirstruct = 1;
909 cmd_spec_header (const char *com, const char *val, void *closure)
913 /* Empty header means reset headers. */
914 FREE_MAYBE (opt.user_header);
915 opt.user_header = NULL;
921 if (!check_user_specified_header (val))
923 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
924 exec_name, com, val);
927 i = opt.user_header ? strlen (opt.user_header) : 0;
928 opt.user_header = (char *)xrealloc (opt.user_header, i + strlen (val)
930 strcpy (opt.user_header + i, val);
932 opt.user_header[i++] = '\r';
933 opt.user_header[i++] = '\n';
934 opt.user_header[i] = '\0';
940 cmd_spec_htmlify (const char *com, const char *val, void *closure)
942 int flag = cmd_boolean (com, val, &opt.htmlify);
943 if (flag && !opt.htmlify)
944 opt.remove_listing = 0;
949 cmd_spec_mirror (const char *com, const char *val, void *closure)
953 if (!cmd_boolean (com, val, &mirror))
958 if (!opt.no_dirstruct)
960 opt.timestamping = 1;
961 opt.reclevel = INFINITE_RECURSION;
962 opt.remove_listing = 0;
968 cmd_spec_progress (const char *com, const char *val, void *closure)
970 if (!valid_progress_implementation_p (val))
972 fprintf (stderr, _("%s: %s: Invalid progress type `%s'.\n"),
973 exec_name, com, val);
976 FREE_MAYBE (opt.progress_type);
978 /* Don't call set_progress_implementation here. It will be called
979 in main() when it becomes clear what the log output is. */
980 opt.progress_type = xstrdup (val);
985 cmd_spec_recursive (const char *com, const char *val, void *closure)
987 if (!cmd_boolean (com, val, &opt.recursive))
991 if (opt.recursive && !opt.no_dirstruct)
998 cmd_spec_useragent (const char *com, const char *val, void *closure)
1000 /* Just check for empty string and newline, so we don't throw total
1001 junk to the server. */
1002 if (!*val || strchr (val, '\n'))
1004 fprintf (stderr, _("%s: %s: Invalid specification `%s'.\n"),
1005 exec_name, com, val);
1008 opt.useragent = xstrdup (val);
1012 /* Miscellaneous useful routines. */
1014 /* Return the integer value of a positive integer written in S, or -1
1015 if an error was encountered. */
1017 myatoi (const char *s)
1020 const char *orig = s;
1022 for (res = 0; *s && ISDIGIT (*s); s++)
1023 res = 10 * res + (*s - '0');
1024 if (*s || orig == s)
1030 #define ISODIGIT(x) ((x) >= '0' && (x) <= '7')
1033 check_user_specified_header (const char *s)
1037 for (p = s; *p && *p != ':' && !ISSPACE (*p); p++);
1038 /* The header MUST contain `:' preceded by at least one
1039 non-whitespace character. */
1040 if (*p != ':' || p == s)
1042 /* The header MUST NOT contain newlines. */
1043 if (strchr (s, '\n'))
1048 void cleanup_html_url PARAMS ((void));
1049 void res_cleanup PARAMS ((void));
1050 void downloaded_files_free PARAMS ((void));
1051 void http_cleanup PARAMS ((void));
1054 /* Free the memory allocated by global variables. */
1058 /* Free external resources, close files, etc. */
1063 /* We're exiting anyway so there's no real need to call free()
1064 hundreds of times. Skipping the frees will make Wget exit
1067 However, when detecting leaks, it's crucial to free() everything
1068 because then you can find the real leaks, i.e. the allocated
1069 memory which grows with the size of the program. */
1072 recursive_cleanup ();
1075 cleanup_html_url ();
1076 downloaded_files_free ();
1078 cookie_jar_delete (wget_cookie_jar);
1081 extern acc_t *netrc_list;
1082 free_netrc (netrc_list);
1084 FREE_MAYBE (opt.lfilename);
1085 xfree (opt.dir_prefix);
1086 FREE_MAYBE (opt.input_filename);
1087 FREE_MAYBE (opt.output_document);
1088 free_vec (opt.accepts);
1089 free_vec (opt.rejects);
1090 free_vec (opt.excludes);
1091 free_vec (opt.includes);
1092 free_vec (opt.domains);
1093 free_vec (opt.follow_tags);
1094 free_vec (opt.ignore_tags);
1095 FREE_MAYBE (opt.progress_type);
1096 xfree (opt.ftp_acc);
1097 FREE_MAYBE (opt.ftp_pass);
1098 FREE_MAYBE (opt.ftp_proxy);
1099 FREE_MAYBE (opt.https_proxy);
1100 FREE_MAYBE (opt.http_proxy);
1101 free_vec (opt.no_proxy);
1102 FREE_MAYBE (opt.useragent);
1103 FREE_MAYBE (opt.referer);
1104 FREE_MAYBE (opt.http_user);
1105 FREE_MAYBE (opt.http_passwd);
1106 FREE_MAYBE (opt.user_header);
1108 FREE_MAYBE (opt.sslcertkey);
1109 FREE_MAYBE (opt.sslcertfile);
1110 #endif /* HAVE_SSL */
1111 FREE_MAYBE (opt.bind_address);
1112 FREE_MAYBE (opt.cookies_input);
1113 FREE_MAYBE (opt.cookies_output);