summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Rühsen <tim.ruehsen@gmx.de>2023-02-17 19:26:03 +0100
committerTim Rühsen <tim.ruehsen@gmx.de>2023-02-18 17:25:56 +0100
commit77929eda1b9fe426e0fb45046ac2ea7f7ae92879 (patch)
tree7d61bf029e19f02e57ff390ca8365040ad8f4c34
parent218f6fee30f8138e049ec624ef05456bd5d9e662 (diff)
downloadwget-77929eda1b9fe426e0fb45046ac2ea7f7ae92879.tar.gz
Simplify url_error function.
* src/url.c (url_error): simplify, remove url arg, return const char *. * src/url.h (url_error): remove url arg, return const char *. * src/html-url.c (get_urls_file): Simplify call to url_error(), remove call to free(). * src/http.c (metalink_from_http): Likewise. * src/main.c (main): Likewise. * src/metalink.c (retrieve_from_metalink, fetch_metalink_file): Likewise. * src/recur.c (retrieve_tree): Likewise. * src/res.c (res_retrieve_file): Likewise. * src/retr.c (retrieve_url, retrieve_from_file): Likewise.
-rw-r--r--src/html-url.c4
-rw-r--r--src/http.c4
-rw-r--r--src/main.c4
-rw-r--r--src/metalink.c8
-rw-r--r--src/recur.c4
-rw-r--r--src/res.c4
-rw-r--r--src/retr.c12
-rw-r--r--src/url.c42
-rw-r--r--src/url.h2
9 files changed, 29 insertions, 55 deletions
diff --git a/src/html-url.c b/src/html-url.c
index 4bcb1751..896d6fc4 100644
--- a/src/html-url.c
+++ b/src/html-url.c
@@ -941,11 +941,9 @@ get_urls_file (const char *file)
url = url_parse (url_text, &up_error_code, NULL, false);
if (!url)
{
- char *error = url_error (url_text, up_error_code);
logprintf (LOG_NOTQUIET, _("%s: Invalid URL %s: %s\n"),
- file, url_text, error);
+ file, url_text, url_error (up_error_code));
xfree (url_text);
- xfree (error);
inform_exit_status (URLERROR);
continue;
}
diff --git a/src/http.c b/src/http.c
index e3a1a394..116a93a3 100644
--- a/src/http.c
+++ b/src/http.c
@@ -2827,10 +2827,8 @@ skip_content_type:
if (!url)
{
- char *error = url_error (urlstr, url_err);
logprintf (LOG_NOTQUIET, _("When downloading signature:\n"
- "%s: %s.\n"), urlstr, error);
- xfree (error);
+ "%s: %s.\n"), urlstr, url_error (url_err));
iri_free (iri);
}
else
diff --git a/src/main.c b/src/main.c
index 87fa2e09..d1c3c3e7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2135,9 +2135,7 @@ only if outputting to a regular file.\n"));
if (!url_parsed)
{
- char *error = url_error (t, url_err);
- logprintf (LOG_NOTQUIET, "%s: %s.\n",t, error);
- xfree (error);
+ logprintf (LOG_NOTQUIET, "%s: %s.\n", t, url_error (url_err));
inform_exit_status (URLERROR);
}
else
diff --git a/src/metalink.c b/src/metalink.c
index 0370f80c..eca839c2 100644
--- a/src/metalink.c
+++ b/src/metalink.c
@@ -419,9 +419,7 @@ retrieve_from_metalink (const metalink_t* metalink)
if (!url)
{
- char *error = url_error (mres->url, url_err);
- logprintf (LOG_NOTQUIET, "%s: %s.\n", mres->url, error);
- xfree (error);
+ logprintf (LOG_NOTQUIET, "%s: %s.\n", mres->url, url_error (url_err));
inform_exit_status (URLERROR);
iri_free (iri);
continue;
@@ -1175,11 +1173,9 @@ fetch_metalink_file (const char *url_str,
if (!url)
{
- char *error = url_error (url_str, url_err);
- logprintf (LOG_NOTQUIET, "%s: %s.\n", url_str, error);
+ logprintf (LOG_NOTQUIET, "%s: %s.\n", url_str, url_error (url_err));
inform_exit_status (retr_err);
iri_free (iri);
- xfree (error);
return retr_err;
}
diff --git a/src/recur.c b/src/recur.c
index 260307da..c546dabb 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -321,9 +321,7 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
if (!url_parsed)
{
- char *error = url_error (url, url_err);
- logprintf (LOG_NOTQUIET, "%s: %s.\n",url, error);
- xfree (error);
+ logprintf (LOG_NOTQUIET, "%s: %s.\n",url, url_error (url_err));
inform_exit_status (URLERROR);
}
else
diff --git a/src/res.c b/src/res.c
index 9bf34014..83317a24 100644
--- a/src/res.c
+++ b/src/res.c
@@ -561,9 +561,7 @@ res_retrieve_file (const char *url, char **file, struct iri *iri)
url_parsed = url_parse (robots_url, &url_err, i, true);
if (!url_parsed)
{
- char *error = url_error (robots_url, url_err);
- logprintf (LOG_NOTQUIET, "%s: %s.\n", robots_url, error);
- xfree (error);
+ logprintf (LOG_NOTQUIET, "%s: %s.\n", robots_url, url_error (url_err));
err = URLERROR;
}
else
diff --git a/src/retr.c b/src/retr.c
index 107e0811..51d0575a 100644
--- a/src/retr.c
+++ b/src/retr.c
@@ -929,11 +929,9 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
proxy_url = url_parse (proxy, &up_error_code, pi, true);
if (!proxy_url)
{
- char *error = url_error (proxy, up_error_code);
logprintf (LOG_NOTQUIET, _("Error parsing proxy URL %s: %s.\n"),
- proxy, error);
+ proxy, url_error (up_error_code));
xfree (url);
- xfree (error);
xfree (proxy);
iri_free (pi);
RESTORE_METHOD;
@@ -1052,16 +1050,14 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
newloc_parsed = url_parse (mynewloc, &up_error_code, iri, true);
if (!newloc_parsed)
{
- char *error = url_error (mynewloc, up_error_code);
logprintf (LOG_NOTQUIET, "%s: %s.\n", escnonprint_uri (mynewloc),
- error);
+ url_error (up_error_code));
if (orig_parsed != u)
{
url_free (u);
}
xfree (url);
xfree (mynewloc);
- xfree (error);
RESTORE_METHOD;
goto bail;
}
@@ -1217,9 +1213,7 @@ retrieve_from_file (const char *file, bool html, int *count)
struct url *url_parsed = url_parse (url, &url_err, iri, true);
if (!url_parsed)
{
- char *error = url_error (url, url_err);
- logprintf (LOG_NOTQUIET, "%s: %s.\n", url, error);
- xfree (error);
+ logprintf (LOG_NOTQUIET, "%s: %s.\n", url, url_error (url_err));
iri_free (iri);
return URLERROR;
}
diff --git a/src/url.c b/src/url.c
index 76c32ad0..2ff0b550 100644
--- a/src/url.c
+++ b/src/url.c
@@ -673,6 +673,8 @@ init_seps (enum url_scheme scheme)
enum {
PE_NO_ERROR = 0,
PE_UNSUPPORTED_SCHEME,
+ PE_UNSUPPORTED_SCHEME_HTTPS,
+ PE_UNSUPPORTED_SCHEME_FTPS,
PE_MISSING_SCHEME,
PE_INVALID_HOST_NAME,
PE_BAD_PORT_NUMBER,
@@ -684,7 +686,9 @@ enum {
static const char *parse_errors[] = {
[PE_NO_ERROR] = N_("No error"),
- // PE_UNSUPPORTED_SCHEME is handled separately in url_error()
+ [PE_UNSUPPORTED_SCHEME] = N_("Unsupported scheme"),
+ [PE_UNSUPPORTED_SCHEME_HTTPS] = N_("HTTPS support not compiled in"),
+ [PE_UNSUPPORTED_SCHEME_FTPS] = N_("FTPS support not compiled in"),
[PE_MISSING_SCHEME] = N_("Scheme missing"),
[PE_INVALID_HOST_NAME] = N_("Invalid host name"),
[PE_BAD_PORT_NUMBER] = N_("Bad port number"),
@@ -726,10 +730,14 @@ url_parse (const char *url, int *error, struct iri *iri, bool percent_encode)
scheme = url_scheme (url);
if (scheme == SCHEME_INVALID)
{
- if (url_has_scheme (url))
- error_code = PE_UNSUPPORTED_SCHEME;
- else
+ if (!url_has_scheme (url))
error_code = PE_MISSING_SCHEME;
+ else if (!c_strncasecmp (url, "https:", 6))
+ error_code = PE_UNSUPPORTED_SCHEME_HTTPS;
+ else if (!c_strncasecmp (url, "ftps:", 5))
+ error_code = PE_UNSUPPORTED_SCHEME_FTPS;
+ else
+ error_code = PE_UNSUPPORTED_SCHEME;
goto error;
}
@@ -993,29 +1001,15 @@ url_parse (const char *url, int *error, struct iri *iri, bool percent_encode)
/* Return the error message string from ERROR_CODE, which should have
been retrieved from url_parse. The error message is translated. */
-char *
-url_error (const char *url, int error_code)
+const char *
+url_error (int error_code)
{
- assert (error_code >= 0 && ((size_t) error_code) < countof (parse_errors));
+ assert (error_code >= 0 && error_code < (int) countof (parse_errors));
- if (error_code != PE_UNSUPPORTED_SCHEME)
- return xstrdup (_(parse_errors[error_code]));
-
- assert (url_has_scheme (url));
-
- if (!url_has_scheme (url))
- return xstrdup (_("Unexpected missing scheme"));
-
- const char *p = strchr (url, ':');
- if (p)
- {
- if (!c_strncasecmp (url, "https", p - url))
- return xstrdup (_("HTTPS support not compiled in"));
-
- return aprintf (_("Unsupported scheme %s"), quote_mem (url, url - p));
- }
+ if (error_code >= 0 && error_code < (int) countof (parse_errors))
+ return _(parse_errors[error_code]);
- return xstrdup (""); // This should never be reached
+ return ""; // This should never be reached
}
/* Split PATH into DIR and FILE. PATH comes from the URL and is
diff --git a/src/url.h b/src/url.h
index 72c0079e..fb9da33e 100644
--- a/src/url.h
+++ b/src/url.h
@@ -108,7 +108,7 @@ void url_unescape (char *);
void url_unescape_except_reserved (char *);
struct url *url_parse (const char *, int *, struct iri *iri, bool percent_encode);
-char *url_error (const char *, int);
+const char *url_error (int);
char *url_full_path (const struct url *);
void url_set_dir (struct url *, const char *);
void url_set_file (struct url *, const char *);