mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-21 03:32:35 +03:00
Add a function to retrieve the decoded version of IDNA URLs
This commit is contained in:
parent
c752c85618
commit
5f5ca2c205
@ -1698,6 +1698,51 @@ const char *nsurl_access(const nsurl *url)
|
||||
return url->string;
|
||||
}
|
||||
|
||||
const char *nsurl_access_utf8(const nsurl *url)
|
||||
{
|
||||
lwc_string *host;
|
||||
char *idna_host;
|
||||
size_t idna_host_len;
|
||||
char *scheme;
|
||||
size_t scheme_len;
|
||||
char *path;
|
||||
size_t path_len;
|
||||
char *idna_url;
|
||||
size_t idna_url_len;
|
||||
|
||||
assert(url != NULL);
|
||||
|
||||
host = nsurl_get_component(url, NSURL_HOST);
|
||||
if (idna_decode(lwc_string_data(host), lwc_string_length(host),
|
||||
&idna_host, &idna_host_len) != NSERROR_OK) {
|
||||
lwc_string_unref(host);
|
||||
return strdup(url->string);
|
||||
}
|
||||
|
||||
lwc_string_unref(host);
|
||||
|
||||
if (nsurl_get(url, NSURL_SCHEME | NSURL_CREDENTIALS,
|
||||
&scheme, &scheme_len) != NSERROR_OK) {
|
||||
return strdup(url->string);
|
||||
}
|
||||
|
||||
if (nsurl_get(url, NSURL_PORT | NSURL_PATH | NSURL_QUERY,
|
||||
&path, &path_len) != NSERROR_OK) {
|
||||
return strdup(url->string);
|
||||
}
|
||||
|
||||
idna_url_len = scheme_len + idna_host_len + path_len + 1; /* +1 for \0 */
|
||||
idna_url = malloc(idna_url_len);
|
||||
|
||||
if (idna_url == NULL) {
|
||||
return strdup(url->string);
|
||||
}
|
||||
|
||||
snprintf(idna_url, idna_url_len, "%s%s%s", scheme, idna_host, path);
|
||||
|
||||
return(idna_url);
|
||||
}
|
||||
|
||||
|
||||
/* exported interface, documented in nsurl.h */
|
||||
const char *nsurl_access_leaf(const nsurl *url)
|
||||
|
@ -180,6 +180,20 @@ bool nsurl_has_component(const nsurl *url, nsurl_component part);
|
||||
const char *nsurl_access(const nsurl *url);
|
||||
|
||||
|
||||
/**
|
||||
* Access a NetSurf URL object as a UTF-8 string (for human readable IDNA)
|
||||
*
|
||||
* \param url NetSurf URL to retrieve a string pointer for.
|
||||
* \return the required string
|
||||
*
|
||||
* It is up to the client to free the returned string when they have
|
||||
* finished with it.
|
||||
*
|
||||
* The returned string has a trailing '\0'.
|
||||
*/
|
||||
const char *nsurl_access_utf8(const nsurl *url);
|
||||
|
||||
|
||||
/**
|
||||
* Access a URL's path leaf as a string
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user