summaryrefslogtreecommitdiff
path: root/src/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.c')
-rw-r--r--src/init.c59
1 files changed, 46 insertions, 13 deletions
diff --git a/src/init.c b/src/init.c
index e6aa673..1064883 100644
--- a/src/init.c
+++ b/src/init.c
@@ -99,6 +99,9 @@ CMD_DECLARE (cmd_vector);
CMD_DECLARE (cmd_use_askpass);
+#ifdef HAVE_LIBZ
+CMD_DECLARE (cmd_spec_compression);
+#endif
CMD_DECLARE (cmd_spec_dirstruct);
CMD_DECLARE (cmd_spec_header);
CMD_DECLARE (cmd_spec_warc_header);
@@ -161,6 +164,9 @@ static const struct {
{ "checkcertificate", &opt.check_cert, cmd_check_cert },
#endif
{ "chooseconfig", &opt.choose_config, cmd_file },
+#ifdef HAVE_LIBZ
+ { "compression", &opt.compression, cmd_spec_compression },
+#endif
{ "connecttimeout", &opt.connect_timeout, cmd_time },
{ "contentdisposition", &opt.content_disposition, cmd_boolean },
{ "contentonerror", &opt.content_on_error, cmd_boolean },
@@ -445,6 +451,10 @@ defaults (void)
opt.ftps_clear_data_connection = false;
#endif
+#ifdef HAVE_LIBZ
+ opt.compression = compression_auto;
+#endif
+
/* The default for file name restriction defaults to the OS type. */
#if defined(WINDOWS) || defined(MSDOS) || defined(__CYGWIN__)
opt.restrict_files_os = restrict_windows;
@@ -566,10 +576,11 @@ wgetrc_env_file_name (void)
char *env = getenv ("WGETRC");
if (env && *env)
{
- if (!file_exists_p (env))
+ file_stats_t flstat;
+ if (!file_exists_p (env, &flstat))
{
- fprintf (stderr, _("%s: WGETRC points to %s, which doesn't exist.\n"),
- exec_name, env);
+ fprintf (stderr, _("%s: WGETRC points to %s, which couldn't be accessed because of error: %s.\n"),
+ exec_name, env, strerror(flstat.access_err));
exit (WGET_EXIT_GENERIC_ERROR);
}
return xstrdup (env);
@@ -577,7 +588,7 @@ wgetrc_env_file_name (void)
return NULL;
}
-/* Check for the existance of '$HOME/.wgetrc' and return its path
+/* Check for the existence of '$HOME/.wgetrc' and return its path
if it exists and is set. */
char *
wgetrc_user_file_name (void)
@@ -597,7 +608,7 @@ wgetrc_user_file_name (void)
if (!file)
return NULL;
- if (!file_exists_p (file))
+ if (!file_exists_p (file, NULL))
{
xfree (file);
return NULL;
@@ -630,7 +641,7 @@ wgetrc_file_name (void)
if (home)
{
file = aprintf ("%s/wget.ini", home);
- if (!file_exists_p (file))
+ if (!file_exists_p (file, NULL))
{
xfree (file);
}
@@ -658,7 +669,7 @@ static bool setval_internal_tilde (int, const char *, const char *);
there were errors in the file. */
bool
-run_wgetrc (const char *file)
+run_wgetrc (const char *file, file_stats_t *flstats)
{
FILE *fp;
char *line = NULL;
@@ -666,7 +677,7 @@ run_wgetrc (const char *file)
int ln;
int errcnt = 0;
- fp = fopen (file, "r");
+ fp = fopen_stat (file, "r", flstats);
if (!fp)
{
fprintf (stderr, _("%s: Cannot read %s (%s).\n"), exec_name,
@@ -722,14 +733,16 @@ void
initialize (void)
{
char *file, *env_sysrc;
+ file_stats_t flstats;
bool ok = true;
+ memset(&flstats, 0, sizeof(flstats));
/* 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))
+ if (env_sysrc && file_exists_p (env_sysrc, &flstats))
{
- ok &= run_wgetrc (env_sysrc);
+ ok &= run_wgetrc (env_sysrc, &flstats);
/* If there are any problems parsing the system wgetrc file, tell
the user and exit */
if (! ok)
@@ -743,8 +756,8 @@ or specify a different file using --config.\n"), env_sysrc);
}
/* Otherwise, if SYSTEM_WGETRC is defined, use it. */
#ifdef SYSTEM_WGETRC
- else if (file_exists_p (SYSTEM_WGETRC))
- ok &= run_wgetrc (SYSTEM_WGETRC);
+ else if (file_exists_p (SYSTEM_WGETRC, &flstats))
+ ok &= run_wgetrc (SYSTEM_WGETRC, &flstats);
/* If there are any problems parsing the system wgetrc file, tell
the user and exit */
if (! ok)
@@ -771,7 +784,8 @@ or specify a different file using --config.\n"), SYSTEM_WGETRC);
}
else
#endif
- ok &= run_wgetrc (file);
+ if (file_exists_p (file, &flstats))
+ ok &= run_wgetrc (file, &flstats);
/* If there were errors processing either `.wgetrc', abort. */
if (!ok)
@@ -1441,6 +1455,25 @@ cmd_cert_type (const char *com, const char *val, void *place)
static bool check_user_specified_header (const char *);
+#ifdef HAVE_LIBZ
+static bool
+cmd_spec_compression (const char *com, const char *val, void *place)
+{
+ static const struct decode_item choices[] = {
+ { "auto", compression_auto },
+ { "gzip", compression_gzip },
+ { "none", compression_none },
+ };
+ int ok = decode_string (val, choices, countof (choices), place);
+ if (!ok)
+ {
+ fprintf (stderr, _("%s: %s: Invalid value %s.\n"), exec_name, com,
+ quote (val));
+ }
+ return ok;
+}
+#endif
+
static bool
cmd_spec_dirstruct (const char *com, const char *val, void *place_ignored _GL_UNUSED)
{