mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-26 22:09:43 +03:00
Rework IDN URL retrieval to return an nserror
This commit is contained in:
parent
5206518a75
commit
65b510fbc3
26
amiga/gui.c
26
amiga/gui.c
@ -4892,23 +4892,27 @@ static void gui_window_set_status(struct gui_window *g, const char *text)
|
|||||||
|
|
||||||
static nserror gui_window_set_url(struct gui_window *g, nsurl *url)
|
static nserror gui_window_set_url(struct gui_window *g, nsurl *url)
|
||||||
{
|
{
|
||||||
|
size_t idn_url_l;
|
||||||
|
char *idn_url_s = NULL;
|
||||||
|
char *url_lc = NULL;
|
||||||
|
|
||||||
if(!g) return NSERROR_OK;
|
if(!g) return NSERROR_OK;
|
||||||
|
|
||||||
if (g == g->shared->gw) {
|
if (g == g->shared->gw) {
|
||||||
if(nsoption_bool(display_decoded_idn) == false) {
|
if(nsoption_bool(display_decoded_idn) == true) {
|
||||||
|
if (nsurl_access_utf8(url, &idn_url_s, &idn_url_l) == NSERROR_OK) {
|
||||||
|
url_lc = ami_utf8_easy(idn_url_s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RefreshSetGadgetAttrs((struct Gadget *)g->shared->objects[GID_URL],
|
RefreshSetGadgetAttrs((struct Gadget *)g->shared->objects[GID_URL],
|
||||||
g->shared->win, NULL,
|
g->shared->win, NULL,
|
||||||
STRINGA_TextVal, nsurl_access(url),
|
STRINGA_TextVal, url_lc ? url_lc : nsurl_access(url),
|
||||||
TAG_DONE);
|
TAG_DONE);
|
||||||
} else {
|
|
||||||
char *idn_url = nsurl_access_utf8(url);
|
if(url_lc) {
|
||||||
char *idn_url_lc = ami_utf8_easy(idn_url);
|
ami_utf8_free(url_lc);
|
||||||
RefreshSetGadgetAttrs((struct Gadget *)g->shared->objects[GID_URL],
|
if(idn_url_s) free(idn_url_s);
|
||||||
g->shared->win, NULL,
|
|
||||||
STRINGA_TextVal, idn_url_lc,
|
|
||||||
TAG_DONE);
|
|
||||||
free(idn_url);
|
|
||||||
ami_utf8_free(idn_url_lc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,7 +300,8 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
|
|||||||
enum { ACTION_NONE, ACTION_SUBMIT, ACTION_GO } action = ACTION_NONE;
|
enum { ACTION_NONE, ACTION_SUBMIT, ACTION_GO } action = ACTION_NONE;
|
||||||
const char *title = 0;
|
const char *title = 0;
|
||||||
nsurl *url = 0;
|
nsurl *url = 0;
|
||||||
char *idn_url = NULL;
|
char *url_s = NULL;
|
||||||
|
size_t url_l = 0;
|
||||||
const char *target = 0;
|
const char *target = 0;
|
||||||
char status_buffer[200];
|
char status_buffer[200];
|
||||||
const char *status = 0;
|
const char *status = 0;
|
||||||
@ -816,21 +817,25 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
|
|||||||
}
|
}
|
||||||
} else if (url) {
|
} else if (url) {
|
||||||
if (nsoption_bool(display_decoded_idn) == true) {
|
if (nsoption_bool(display_decoded_idn) == true) {
|
||||||
idn_url = nsurl_access_utf8(url);
|
if (nsurl_access_utf8(url, &url_s, &url_l) != NSERROR_OK) {
|
||||||
|
/* Unable to obtain a decoded IDN. This is not a fatal error.
|
||||||
|
* Ensure the string pointer is NULL so we use the encoded version. */
|
||||||
|
url_s = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (title) {
|
if (title) {
|
||||||
snprintf(status_buffer, sizeof status_buffer, "%s: %s",
|
snprintf(status_buffer, sizeof status_buffer, "%s: %s",
|
||||||
idn_url ? idn_url : nsurl_access(url), title);
|
url_s ? url_s : nsurl_access(url), title);
|
||||||
} else {
|
} else {
|
||||||
snprintf(status_buffer, sizeof status_buffer, "%s",
|
snprintf(status_buffer, sizeof status_buffer, "%s",
|
||||||
idn_url ? idn_url : nsurl_access(url));
|
url_s ? url_s : nsurl_access(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
status = status_buffer;
|
status = status_buffer;
|
||||||
|
|
||||||
if (idn_url != NULL)
|
if (url_s != NULL)
|
||||||
free(idn_url);
|
free(url_s);
|
||||||
|
|
||||||
pointer = get_pointer_shape(url_box, imagemap);
|
pointer = get_pointer_shape(url_box, imagemap);
|
||||||
|
|
||||||
|
@ -1698,8 +1698,11 @@ const char *nsurl_access(const nsurl *url)
|
|||||||
return url->string;
|
return url->string;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *nsurl_access_utf8(const nsurl *url)
|
|
||||||
|
/* exported interface, documented in nsurl.h */
|
||||||
|
nserror nsurl_access_utf8(const nsurl *url, char **url_s, size_t *url_l)
|
||||||
{
|
{
|
||||||
|
nserror err;
|
||||||
lwc_string *host;
|
lwc_string *host;
|
||||||
char *idna_host;
|
char *idna_host;
|
||||||
size_t idna_host_len;
|
size_t idna_host_len;
|
||||||
@ -1707,45 +1710,43 @@ char *nsurl_access_utf8(const nsurl *url)
|
|||||||
size_t scheme_len;
|
size_t scheme_len;
|
||||||
char *path;
|
char *path;
|
||||||
size_t path_len;
|
size_t path_len;
|
||||||
char *idna_url;
|
|
||||||
size_t idna_url_len;
|
|
||||||
|
|
||||||
assert(url != NULL);
|
assert(url != NULL);
|
||||||
|
|
||||||
host = nsurl_get_component(url, NSURL_HOST);
|
host = nsurl_get_component(url, NSURL_HOST);
|
||||||
|
|
||||||
if(host == NULL) {
|
if(host == NULL)
|
||||||
return strdup(url->string);
|
return NSERROR_BAD_URL;
|
||||||
}
|
|
||||||
|
|
||||||
if (idna_decode(lwc_string_data(host), lwc_string_length(host),
|
err = idna_decode(lwc_string_data(host), lwc_string_length(host),
|
||||||
&idna_host, &idna_host_len) != NSERROR_OK) {
|
&idna_host, &idna_host_len);
|
||||||
lwc_string_unref(host);
|
|
||||||
return strdup(url->string);
|
|
||||||
}
|
|
||||||
|
|
||||||
lwc_string_unref(host);
|
lwc_string_unref(host);
|
||||||
|
|
||||||
if (nsurl_get(url, NSURL_SCHEME | NSURL_CREDENTIALS,
|
if (err != NSERROR_OK)
|
||||||
&scheme, &scheme_len) != NSERROR_OK) {
|
return err;
|
||||||
return strdup(url->string);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nsurl_get(url, NSURL_PORT | NSURL_PATH | NSURL_QUERY | NSURL_FRAGMENT,
|
err = nsurl_get(url, NSURL_SCHEME | NSURL_CREDENTIALS,
|
||||||
&path, &path_len) != NSERROR_OK) {
|
&scheme, &scheme_len);
|
||||||
return strdup(url->string);
|
|
||||||
}
|
|
||||||
|
|
||||||
idna_url_len = scheme_len + idna_host_len + path_len + 1; /* +1 for \0 */
|
if (err != NSERROR_OK)
|
||||||
idna_url = malloc(idna_url_len);
|
return err;
|
||||||
|
|
||||||
if (idna_url == NULL) {
|
err = nsurl_get(url, NSURL_PORT | NSURL_PATH | NSURL_QUERY | NSURL_FRAGMENT,
|
||||||
return strdup(url->string);
|
&path, &path_len);
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(idna_url, idna_url_len, "%s%s%s", scheme, idna_host, path);
|
if (err != NSERROR_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
return(idna_url);
|
*url_l = scheme_len + idna_host_len + path_len + 1; /* +1 for \0 */
|
||||||
|
*url_s = malloc(*url_l);
|
||||||
|
|
||||||
|
if (*url_s == NULL)
|
||||||
|
return NSERROR_NOMEM;
|
||||||
|
|
||||||
|
snprintf(*url_s, *url_l, "%s%s%s", scheme, idna_host, path);
|
||||||
|
|
||||||
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,17 +181,21 @@ const char *nsurl_access(const nsurl *url);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access a NetSurf URL object as a UTF-8 string (for human readable IDNA)
|
* Access a NetSurf URL object as a UTF-8 string (for human readable IDNs)
|
||||||
*
|
*
|
||||||
* \param url NetSurf URL to retrieve a string pointer for.
|
* \param url NetSurf URL to retrieve a string pointer for.
|
||||||
* \return the required string
|
* \param url_s Returns a url string
|
||||||
|
* \param url_l Returns length of url_s
|
||||||
|
* \return NSERROR_OK on success, appropriate error otherwise
|
||||||
*
|
*
|
||||||
* It is up to the client to free the returned string when they have
|
* If return value != NSERROR_OK, nothing will be returned in url_s or url_l.
|
||||||
* finished with it.
|
|
||||||
*
|
*
|
||||||
* The returned string has a trailing '\0'.
|
* The string returned in url_s is owned by the client and it is up to them
|
||||||
|
* to free it. It includes a trailing '\0'.
|
||||||
|
*
|
||||||
|
* The length returned in url_l excludes the trailing '\0'.
|
||||||
*/
|
*/
|
||||||
char *nsurl_access_utf8(const nsurl *url);
|
nserror nsurl_access_utf8(const nsurl *url, char **url_s, size_t *url_l);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user