X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Finit.c;h=879d3aac80b27a419cdd9154128fe8cfaf2fe74b;hp=43a0f95e363e1e428e4a6a308b5852a57ca195ce;hb=d5e283b1a75c5f8249300b465b4e7b55130bec49;hpb=7a54d852bfa09c828bbc4907adddee7e4beb1715 diff --git a/src/init.c b/src/init.c index 43a0f95e..879d3aac 100644 --- a/src/init.c +++ b/src/init.c @@ -1,6 +1,6 @@ /* Reading/parsing the initialization file. Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. + 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GNU Wget. @@ -58,11 +58,6 @@ as that of the covered work. */ #include "test.h" #endif -/* We want tilde expansion enabled only when reading `.wgetrc' lines; - otherwise, it will be performed by the shell. This variable will - be set by the wgetrc-reading function. */ - -static bool enable_tilde_expansion; #define CMD_DECLARE(func) static bool func (const char *, const char *, void *) @@ -113,6 +108,7 @@ static const struct { { "accept", &opt.accepts, cmd_vector }, { "addhostdir", &opt.add_hostdir, cmd_boolean }, { "alwaysrest", &opt.always_rest, cmd_boolean }, /* deprecated */ + { "askpassword", &opt.ask_passwd, cmd_boolean }, { "authnochallenge", &opt.auth_without_challenge, cmd_boolean }, { "background", &opt.background, cmd_boolean }, @@ -139,6 +135,7 @@ static const struct { #ifdef ENABLE_DEBUG { "debug", &opt.debug, cmd_boolean }, #endif + { "defaultpage", &opt.default_page, cmd_string}, { "deleteafter", &opt.delete_after, cmd_boolean }, { "dirprefix", &opt.dir_prefix, cmd_directory }, { "dirstruct", NULL, cmd_spec_dirstruct }, @@ -183,9 +180,11 @@ static const struct { { "inet6only", &opt.ipv6_only, cmd_boolean }, #endif { "input", &opt.input_filename, cmd_file }, + { "iri", &opt.enable_iri, cmd_boolean }, { "keepsessioncookies", &opt.keep_session_cookies, cmd_boolean }, { "limitrate", &opt.limit_rate, cmd_bytes }, { "loadcookies", &opt.cookies_input, cmd_file }, + { "locale", &opt.locale, cmd_string }, { "logfile", &opt.lfilename, cmd_file }, { "login", &opt.ftp_user, cmd_string },/* deprecated*/ { "maxredirect", &opt.max_redirect, cmd_number }, @@ -225,6 +224,7 @@ static const struct { { "referer", &opt.referer, cmd_string }, { "reject", &opt.rejects, cmd_vector }, { "relativeonly", &opt.relative_only, cmd_boolean }, + { "remoteencoding", &opt.encoding_remote, cmd_string }, { "removelisting", &opt.remove_listing, cmd_boolean }, { "restrictfilenames", NULL, cmd_spec_restrict_file_names }, { "retrsymlinks", &opt.retr_symlinks, cmd_boolean }, @@ -303,6 +303,7 @@ defaults (void) tmp = getenv ("no_proxy"); if (tmp) opt.no_proxy = sepstring (tmp); + opt.prefer_family = prefer_none; opt.allow_cache = true; opt.read_timeout = 900; @@ -331,6 +332,16 @@ defaults (void) opt.restrict_files_case = restrict_no_case_restriction; opt.max_redirect = 20; + + opt.waitretry = 10; + +#ifdef ENABLE_IRI + opt.enable_iri = true; +#else + opt.enable_iri = false; +#endif + opt.locale = NULL; + opt.encoding_remote = NULL; } /* Return the user's home directory (strdup-ed), or NULL if none is @@ -338,53 +349,54 @@ defaults (void) char * home_dir (void) { - char *home = getenv ("HOME"); + static char buf[PATH_MAX]; + static char *home; if (!home) { + home = getenv ("HOME"); + if (!home) + { #if defined(MSDOS) - /* Under MSDOS, if $HOME isn't defined, use the directory where - `wget.exe' resides. */ - const char *_w32_get_argv0 (void); /* in libwatt.a/pcconfig.c */ - char *p, buf[PATH_MAX]; - - strcpy (buf, _w32_get_argv0 ()); - p = strrchr (buf, '/'); /* djgpp */ - if (!p) - p = strrchr (buf, '\\'); /* others */ - assert (p); - *p = '\0'; - home = buf; + /* Under MSDOS, if $HOME isn't defined, use the directory where + `wget.exe' resides. */ + const char *_w32_get_argv0 (void); /* in libwatt.a/pcconfig.c */ + char *p; + + strcpy (buf, _w32_get_argv0 ()); + p = strrchr (buf, '/'); /* djgpp */ + if (!p) + p = strrchr (buf, '\\'); /* others */ + assert (p); + *p = '\0'; + home = buf; #elif !defined(WINDOWS) - /* If HOME is not defined, try getting it from the password - file. */ - struct passwd *pwd = getpwuid (getuid ()); - if (!pwd || !pwd->pw_dir) - return NULL; - home = pwd->pw_dir; + /* If HOME is not defined, try getting it from the password + file. */ + struct passwd *pwd = getpwuid (getuid ()); + if (!pwd || !pwd->pw_dir) + return NULL; + strcpy (buf, pwd->pw_dir); + home = buf; #else /* !WINDOWS */ - /* Under Windows, if $HOME isn't defined, use the directory where - `wget.exe' resides. */ - home = ws_mypath (); + /* Under Windows, if $HOME isn't defined, use the directory where + `wget.exe' resides. */ + home = ws_mypath (); #endif /* WINDOWS */ + } } return home ? xstrdup (home) : NULL; } -/* Return the path to the user's .wgetrc. This is either the value of - `WGETRC' environment variable, or `$HOME/.wgetrc'. - +/* Check the 'WGETRC' environment variable and return the file name + if 'WGETRC' is set and is a valid file. If the `WGETRC' variable exists but the file does not exist, the function will exit(). */ -static char * -wgetrc_file_name (void) +char * +wgetrc_env_file_name (void) { - char *env, *home; - char *file = NULL; - - /* Try the environment. */ - env = getenv ("WGETRC"); + char *env = getenv ("WGETRC"); if (env && *env) { if (!file_exists_p (env)) @@ -395,7 +407,16 @@ wgetrc_file_name (void) } return xstrdup (env); } + return NULL; +} +/* Check for the existance of '$HOME/.wgetrc' and return it's path + if it exists and is set. */ +char * +wgetrc_user_file_name (void) +{ + char *home = home_dir (); + char *file = NULL; /* If that failed, try $HOME/.wgetrc (or equivalent). */ #ifdef __VMS @@ -407,28 +428,54 @@ wgetrc_file_name (void) xfree_null (home); #endif /* def __VMS [else] */ + if (!file) + return NULL; + if (!file_exists_p (file)) + { + xfree (file); + return NULL; + } + return file; +} + +/* Return the path to the user's .wgetrc. This is either the value of + `WGETRC' environment variable, or `$HOME/.wgetrc'. + + Additionally, for windows, look in the directory where wget.exe + resides. */ +char * +wgetrc_file_name (void) +{ + char *file = wgetrc_env_file_name (); + if (file && *file) + return file; + + file = wgetrc_user_file_name (); + #ifdef WINDOWS /* Under Windows, if we still haven't found .wgetrc, look for the file `wget.ini' in the directory where `wget.exe' resides; we do this for backward compatibility with previous versions of Wget. SYSTEM_WGETRC should not be defined under WINDOWS. */ - if (!file || !file_exists_p (file)) + if (!file) { + char *home = home_dir (); xfree_null (file); file = NULL; home = ws_mypath (); if (home) - file = aprintf ("%s/wget.ini", home); + { + file = aprintf ("%s/wget.ini", home); + if (!file_exists_p (file)) + { + xfree (file); + file = NULL; + } + xfree (home); + } } #endif /* WINDOWS */ - if (!file) - return NULL; - if (!file_exists_p (file)) - { - xfree (file); - return NULL; - } return file; } @@ -442,6 +489,7 @@ enum parse_line { static enum parse_line parse_line (const char *, char **, char **, int *); static bool setval_internal (int, const char *, const char *); +static bool setval_internal_tilde (int, const char *, const char *); /* Initialize variables from a wgetrc file. Returns zero (failure) if there were errors in the file. */ @@ -461,7 +509,6 @@ run_wgetrc (const char *file) file, strerror (errno)); return true; /* not a fatal error */ } - enable_tilde_expansion = true; ln = 1; while ((line = read_whole_line (fp)) != NULL) { @@ -473,7 +520,7 @@ run_wgetrc (const char *file) { case line_ok: /* If everything is OK, set the value. */ - if (!setval_internal (comind, com, val)) + if (!setval_internal_tilde (comind, com, val)) { fprintf (stderr, _("%s: Error in %s at line %d.\n"), exec_name, file, ln); @@ -486,8 +533,8 @@ run_wgetrc (const char *file) ++errcnt; break; case line_unknown_command: - fprintf (stderr, _("%s: Unknown command `%s' in %s at line %d.\n"), - exec_name, com, file, ln); + fprintf (stderr, _("%s: Unknown command %s in %s at line %d.\n"), + exec_name, quote (com), file, ln); ++errcnt; break; case line_empty: @@ -500,7 +547,6 @@ run_wgetrc (const char *file) xfree (line); ++ln; } - enable_tilde_expansion = false; fclose (fp); return errcnt == 0; @@ -511,15 +557,20 @@ run_wgetrc (const char *file) void initialize (void) { - char *file; + char *file, *env_sysrc; int ok = true; /* Load the hard-coded defaults. */ defaults (); - - /* If SYSTEM_WGETRC is defined, use it. */ + + /* Run a non-standard system rc file when the according environment + variable has been set. For internal testing purposes only! */ + env_sysrc = getenv ("SYSTEM_WGETRC"); + if (env_sysrc && file_exists_p (env_sysrc)) + ok &= run_wgetrc (env_sysrc); + /* Otherwise, if SYSTEM_WGETRC is defined, use it. */ #ifdef SYSTEM_WGETRC - if (file_exists_p (SYSTEM_WGETRC)) + else if (file_exists_p (SYSTEM_WGETRC)) ok &= run_wgetrc (SYSTEM_WGETRC); #endif /* Override it with your own, if one exists. */ @@ -532,8 +583,8 @@ initialize (void) if (!strcmp (file, SYSTEM_WGETRC)) { fprintf (stderr, _("\ -%s: Warning: Both system and user wgetrc point to `%s'.\n"), - exec_name, file); +%s: Warning: Both system and user wgetrc point to %s.\n"), + exec_name, quote (file)); } else #endif @@ -546,7 +597,7 @@ initialize (void) xfree (file); return; } - + /* Remove dashes and underscores from S, modifying S in the process. */ @@ -632,16 +683,53 @@ parse_line (const char *line, char **com, char **val, int *comind) return line_ok; } +#if defined(WINDOWS) || defined(MSDOS) +# define ISSEP(c) ((c) == '/' || (c) == '\\') +#else +# define ISSEP(c) ((c) == '/') +#endif + /* Run commands[comind].action. */ static bool setval_internal (int comind, const char *com, const char *val) { - assert (0 <= comind && comind < countof (commands)); + assert (0 <= comind && ((size_t) comind) < countof (commands)); DEBUGP (("Setting %s (%s) to %s\n", com, commands[comind].name, val)); return commands[comind].action (com, val, commands[comind].place); } +static bool +setval_internal_tilde (int comind, const char *com, const char *val) +{ + bool ret; + int homelen; + char *home; + char **pstring; + ret = setval_internal (comind, com, val); + + /* We make tilde expansion for cmd_file and cmd_directory */ + if (((commands[comind].action == cmd_file) || + (commands[comind].action == cmd_directory)) + && ret && (*val == '~' && ISSEP (val[1]))) + { + pstring = commands[comind].place; + home = home_dir (); + if (home) + { + homelen = strlen (home); + while (homelen && ISSEP (home[homelen - 1])) + home[--homelen] = '\0'; + + /* Skip the leading "~/". */ + for (++val; ISSEP (*val); val++) + ; + *pstring = concat_strings (home, "/", val, (char *)0); + } + } + return ret; +} + /* Run command COM with value VAL. If running the command produces an error, report the error and exit. @@ -684,8 +772,8 @@ run_command (const char *opt) xfree (val); break; default: - fprintf (stderr, _("%s: Invalid --execute command `%s'\n"), - exec_name, opt); + fprintf (stderr, _("%s: Invalid --execute command %s\n"), + exec_name, quote (opt)); exit (2); } } @@ -729,8 +817,8 @@ cmd_boolean (const char *com, const char *val, void *place) else { fprintf (stderr, - _("%s: %s: Invalid boolean `%s'; use `on' or `off'.\n"), - exec_name, com, val); + _("%s: %s: Invalid boolean %s; use `on' or `off'.\n"), + exec_name, com, quote (val)); return false; } @@ -746,8 +834,8 @@ cmd_number (const char *com, const char *val, void *place) if (!simple_atoi (val, val + strlen (val), place) || *(int *) place < 0) { - fprintf (stderr, _("%s: %s: Invalid number `%s'.\n"), - exec_name, com, val); + fprintf (stderr, _("%s: %s: Invalid number %s.\n"), + exec_name, com, quote (val)); return false; } return true; @@ -777,11 +865,6 @@ cmd_string (const char *com, const char *val, void *place) return true; } -#if defined(WINDOWS) || defined(MSDOS) -# define ISSEP(c) ((c) == '/' || (c) == '\\') -#else -# define ISSEP(c) ((c) == '/') -#endif /* Like the above, but handles tilde-expansion when reading a user's `.wgetrc'. In that case, and if VAL begins with `~', the tilde @@ -795,28 +878,7 @@ cmd_file (const char *com, const char *val, void *place) /* #### If VAL is empty, perhaps should set *PLACE to NULL. */ - if (!enable_tilde_expansion || !(*val == '~' && ISSEP (val[1]))) - { - noexpand: - *pstring = xstrdup (val); - } - else - { - int homelen; - char *home = home_dir (); - if (!home) - goto noexpand; - - homelen = strlen (home); - while (homelen && ISSEP (home[homelen - 1])) - home[--homelen] = '\0'; - - /* Skip the leading "~/". */ - for (++val; ISSEP (*val); val++) - ; - - *pstring = concat_strings (home, "/", val, (char *) 0); - } + *pstring = xstrdup (val); #if defined(WINDOWS) || defined(MSDOS) /* Convert "\" to "/". */ @@ -977,8 +1039,8 @@ cmd_bytes (const char *com, const char *val, void *place) double byte_value; if (!parse_bytes_helper (val, &byte_value)) { - fprintf (stderr, _("%s: %s: Invalid byte value `%s'\n"), - exec_name, com, val); + fprintf (stderr, _("%s: %s: Invalid byte value %s\n"), + exec_name, com, quote (val)); return false; } *(wgint *)place = (wgint)byte_value; @@ -996,8 +1058,8 @@ cmd_bytes_sum (const char *com, const char *val, void *place) double byte_value; if (!parse_bytes_helper (val, &byte_value)) { - fprintf (stderr, _("%s: %s: Invalid byte value `%s'\n"), - exec_name, com, val); + fprintf (stderr, _("%s: %s: Invalid byte value %s\n"), + exec_name, com, quote (val)); return false; } *(SUM_SIZE_INT *) place = (SUM_SIZE_INT) byte_value; @@ -1021,8 +1083,8 @@ cmd_time (const char *com, const char *val, void *place) if (val == end) { err: - fprintf (stderr, _("%s: %s: Invalid time period `%s'\n"), - exec_name, com, val); + fprintf (stderr, _("%s: %s: Invalid time period %s\n"), + exec_name, com, quote (val)); return false; } @@ -1075,7 +1137,7 @@ cmd_cert_type (const char *com, const char *val, void *place) }; int ok = decode_string (val, choices, countof (choices), place); if (!ok) - fprintf (stderr, _("%s: %s: Invalid value `%s'.\n"), exec_name, com, val); + fprintf (stderr, _("%s: %s: Invalid value %s.\n"), exec_name, com, quote (val)); return ok; } #endif @@ -1112,8 +1174,8 @@ cmd_spec_header (const char *com, const char *val, void *place_ignored) if (!check_user_specified_header (val)) { - fprintf (stderr, _("%s: %s: Invalid header `%s'.\n"), - exec_name, com, val); + fprintf (stderr, _("%s: %s: Invalid header %s.\n"), + exec_name, com, quote (val)); return false; } opt.user_headers = vec_append (opt.user_headers, val); @@ -1162,10 +1224,10 @@ cmd_spec_prefer_family (const char *com, const char *val, void *place_ignored) { "IPv6", prefer_ipv6 }, { "none", prefer_none }, }; - int prefer_family = prefer_ipv4; + int prefer_family = prefer_none; int ok = decode_string (val, choices, countof (choices), &prefer_family); if (!ok) - fprintf (stderr, _("%s: %s: Invalid value `%s'.\n"), exec_name, com, val); + fprintf (stderr, _("%s: %s: Invalid value %s.\n"), exec_name, com, quote (val)); opt.prefer_family = prefer_family; return ok; } @@ -1178,8 +1240,8 @@ cmd_spec_progress (const char *com, const char *val, void *place_ignored) { if (!valid_progress_implementation_p (val)) { - fprintf (stderr, _("%s: %s: Invalid progress type `%s'.\n"), - exec_name, com, val); + fprintf (stderr, _("%s: %s: Invalid progress type %s.\n"), + exec_name, com, quote (val)); return false; } xfree_null (opt.progress_type); @@ -1237,8 +1299,8 @@ cmd_spec_restrict_file_names (const char *com, const char *val, void *place_igno else { fprintf (stderr, - _("%s: %s: Invalid restriction `%s', use [unix|windows],[lowercase|uppercase],[nocontrol].\n"), - exec_name, com, val); + _("%s: %s: Invalid restriction %s, use [unix|windows],[lowercase|uppercase],[nocontrol].\n"), + exec_name, com, quote (val)); return false; } @@ -1268,7 +1330,7 @@ cmd_spec_secure_protocol (const char *com, const char *val, void *place) }; int ok = decode_string (val, choices, countof (choices), place); if (!ok) - fprintf (stderr, _("%s: %s: Invalid value `%s'.\n"), exec_name, com, val); + fprintf (stderr, _("%s: %s: Invalid value %s.\n"), exec_name, com, quote (val)); return ok; } #endif @@ -1293,8 +1355,8 @@ cmd_spec_useragent (const char *com, const char *val, void *place_ignored) /* Disallow embedded newlines. */ if (strchr (val, '\n')) { - fprintf (stderr, _("%s: %s: Invalid value `%s'.\n"), - exec_name, com, val); + fprintf (stderr, _("%s: %s: Invalid value %s.\n"), + exec_name, com, quote (val)); return false; } xfree_null (opt.useragent); @@ -1531,6 +1593,8 @@ cleanup (void) xfree_null (opt.cookies_output); xfree_null (opt.user); xfree_null (opt.passwd); + xfree_null (opt.base_href); + #endif /* DEBUG_MALLOC */ } @@ -1538,6 +1602,29 @@ cleanup (void) #ifdef TESTING +const char * +test_commands_sorted() +{ + int prev_idx = 0, next_idx = 1; + int command_count = countof (commands) - 1; + int cmp = 0; + while (next_idx <= command_count) + { + cmp = strcasecmp (commands[prev_idx].name, commands[next_idx].name); + if (cmp > 0) + { + mu_assert ("FAILED", false); + break; + } + else + { + prev_idx ++; + next_idx ++; + } + } + return NULL; +} + const char * test_cmd_spec_restrict_file_names() {