diff --git a/src/ChangeLog b/src/ChangeLog index 3e08d0d8..73e9bd3f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2008-08-03 Steven Schubiger + + * url.c, url.h (url_error): Better messages for unsupported + schemes, especially https. + + * html-url.c, recur.c, retr.c: Adjust to new url_error + invocation, and free result. + 2008-07-17 Steven Schubiger * retr.c (retrieve_from_file): When given an URL as input file, diff --git a/src/html-url.c b/src/html-url.c index 75bec7d9..95df8bf9 100644 --- a/src/html-url.c +++ b/src/html-url.c @@ -729,9 +729,11 @@ get_urls_file (const char *file) url = url_parse (url_text, &up_error_code); if (!url) { + char *error = url_error (url_text, up_error_code); logprintf (LOG_NOTQUIET, _("%s: Invalid URL %s: %s\n"), - file, url_text, url_error (up_error_code)); + file, url_text, error); xfree (url_text); + xfree (error); continue; } xfree (url_text); diff --git a/src/recur.c b/src/recur.c index 729a14e9..741ca823 100644 --- a/src/recur.c +++ b/src/recur.c @@ -196,8 +196,9 @@ retrieve_tree (const char *start_url) if (!start_url_parsed) { - logprintf (LOG_NOTQUIET, "%s: %s.\n", start_url, - url_error (up_error_code)); + char *error = url_error (start_url, up_error_code); + logprintf (LOG_NOTQUIET, "%s: %s.\n", start_url, error); + xfree (error); return URLERROR; } diff --git a/src/retr.c b/src/retr.c index 0fc46837..85774297 100644 --- a/src/retr.c +++ b/src/retr.c @@ -628,8 +628,10 @@ retrieve_url (const char *origurl, char **file, char **newloc, u = url_parse (url, &up_error_code); if (!u) { - logprintf (LOG_NOTQUIET, "%s: %s.\n", url, url_error (up_error_code)); + char *error = url_error (url, up_error_code); + logprintf (LOG_NOTQUIET, "%s: %s.\n", url, error); xfree (url); + xfree (error); return URLERROR; } @@ -650,9 +652,11 @@ retrieve_url (const char *origurl, char **file, char **newloc, proxy_url = url_parse (proxy, &up_error_code); if (!proxy_url) { + char *error = url_error (proxy, up_error_code); logprintf (LOG_NOTQUIET, _("Error parsing proxy URL %s: %s.\n"), - proxy, url_error (up_error_code)); + proxy, error); xfree (url); + xfree (error); RESTORE_POST_DATA; return PROXERR; } @@ -726,11 +730,13 @@ retrieve_url (const char *origurl, char **file, char **newloc, newloc_parsed = url_parse (mynewloc, &up_error_code); if (!newloc_parsed) { + char *error = url_error (mynewloc, up_error_code); logprintf (LOG_NOTQUIET, "%s: %s.\n", escnonprint_uri (mynewloc), - url_error (up_error_code)); + error); url_free (u); xfree (url); xfree (mynewloc); + xfree (error); RESTORE_POST_DATA; return result; } diff --git a/src/url.c b/src/url.c index f5d621f9..5d9cd91f 100644 --- a/src/url.c +++ b/src/url.c @@ -619,7 +619,7 @@ static const char *parse_errors[] = { #define PE_NO_ERROR 0 N_("No error"), #define PE_UNSUPPORTED_SCHEME 1 - N_("Unsupported scheme"), + N_("Unsupported scheme %s"), #define PE_INVALID_HOST_NAME 2 N_("Invalid host name"), #define PE_BAD_PORT_NUMBER 3 @@ -886,11 +886,29 @@ url_parse (const char *url, int *error) /* Return the error message string from ERROR_CODE, which should have been retrieved from url_parse. The error message is translated. */ -const char * -url_error (int error_code) +char * +url_error (const char *url, int error_code) { assert (error_code >= 0 && ((size_t) error_code) < countof (parse_errors)); - return _(parse_errors[error_code]); + + if (error_code == PE_UNSUPPORTED_SCHEME) + { + char *error, *p; + char *scheme = xstrdup (url); + assert (url_has_scheme (url)); + + if ((p = strchr (scheme, ':'))) + *p = '\0'; + if (!strcasecmp (scheme, "https")) + asprintf (&error, _("HTTPS support not compiled in")); + else + asprintf (&error, _(parse_errors[error_code]), quote (scheme)); + xfree (scheme); + + return error; + } + else + return xstrdup (_(parse_errors[error_code])); } /* Split PATH into DIR and FILE. PATH comes from the URL and is diff --git a/src/url.h b/src/url.h index 7c8bcfed..ce308f6f 100644 --- a/src/url.h +++ b/src/url.h @@ -85,7 +85,7 @@ struct url char *url_escape (const char *); struct url *url_parse (const char *, int *); -const char *url_error (int); +char *url_error (const char *, int); char *url_full_path (const struct url *); void url_set_dir (struct url *, const char *); void url_set_file (struct url *, const char *);