summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2015-07-17 19:18:20 +0100
committerChris Young <chris@unsatisfactorysoftware.co.uk>2015-10-24 15:12:56 +0100
commit5f5ca2c20587e035278163c9b444b36cfff6dced (patch)
treed5835847d6dc415b7da630c6ba070ef9b58b3a94 /utils
parentc752c85618a57f8c82dc2e939ba2bf735e6c8372 (diff)
downloadnetsurf-5f5ca2c20587e035278163c9b444b36cfff6dced.tar.gz
netsurf-5f5ca2c20587e035278163c9b444b36cfff6dced.tar.bz2
Add a function to retrieve the decoded version of IDNA URLs
Diffstat (limited to 'utils')
-rw-r--r--utils/nsurl.c45
-rw-r--r--utils/nsurl.h14
2 files changed, 59 insertions, 0 deletions
diff --git a/utils/nsurl.c b/utils/nsurl.c
index 8d53be84f..bb3054df1 100644
--- a/utils/nsurl.c
+++ b/utils/nsurl.c
@@ -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)
diff --git a/utils/nsurl.h b/utils/nsurl.h
index b84f55eed..4fbc17b49 100644
--- a/utils/nsurl.h
+++ b/utils/nsurl.h
@@ -181,6 +181,20 @@ 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
*
* \param url NetSurf URL to retrieve a string pointer for.