summaryrefslogtreecommitdiff
path: root/utils/nsurl.c
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-05-17 12:25:04 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2013-05-17 12:25:04 +0100
commit39cc1a6d4a77415de3a1b4ac8780c2d1b1839091 (patch)
tree8a52df2eabe2a1181aff9990410cbe1b56329163 /utils/nsurl.c
parentabebc6ae2b3fb5e40b581d9afdc32d954bcb51b9 (diff)
downloadnetsurf-39cc1a6d4a77415de3a1b4ac8780c2d1b1839091.tar.gz
netsurf-39cc1a6d4a77415de3a1b4ac8780c2d1b1839091.tar.bz2
Add function to get a nsurl's hash value.
Diffstat (limited to 'utils/nsurl.c')
-rw-r--r--utils/nsurl.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/utils/nsurl.c b/utils/nsurl.c
index 23e177e05..61f849e5f 100644
--- a/utils/nsurl.c
+++ b/utils/nsurl.c
@@ -154,6 +154,7 @@ struct nsurl {
struct nsurl_components components;
int count; /* Number of references to NetSurf URL object */
+ uint32_t hash; /* Hash value for nsurl identification */
size_t length; /* Length of string */
char string[FLEX_ARRAY_LEN_DECL]; /* Full URL as a string */
@@ -1185,6 +1186,43 @@ static void nsurl_get_string(const struct nsurl_components *url, char *url_s,
}
+/**
+ * Calculate hash value
+ *
+ * \param url NetSurf URL object to set hash value for
+ */
+static void nsurl_calc_hash(nsurl *url)
+{
+ uint32_t hash = 0;
+
+ if (url->components.scheme)
+ hash ^= lwc_string_hash_value(url->components.scheme);
+
+ if (url->components.username)
+ hash ^= lwc_string_hash_value(url->components.username);
+
+ if (url->components.password)
+ hash ^= lwc_string_hash_value(url->components.password);
+
+ if (url->components.host)
+ hash ^= lwc_string_hash_value(url->components.host);
+
+ if (url->components.port)
+ hash ^= lwc_string_hash_value(url->components.port);
+
+ if (url->components.path)
+ hash ^= lwc_string_hash_value(url->components.path);
+
+ if (url->components.query)
+ hash ^= lwc_string_hash_value(url->components.query);
+
+ if (url->components.fragment)
+ hash ^= lwc_string_hash_value(url->components.fragment);
+
+ url->hash = hash;
+}
+
+
#ifdef NSURL_DEBUG
/**
* Dump a NetSurf URL's internal components
@@ -1282,6 +1320,9 @@ nserror nsurl_create(const char * const url_s, nsurl **url)
/* Fill out the url string */
nsurl_get_string(&c, (*url)->string, &str_len, str_flags);
+ /* Get the nsurl's hash */
+ nsurl_calc_hash(*url);
+
/* Give the URL a reference */
(*url)->count = 1;
@@ -1615,6 +1656,15 @@ size_t nsurl_length(const nsurl *url)
/* exported interface, documented in nsurl.h */
+uint32_t nsurl_hash(const nsurl *url)
+{
+ assert(url != NULL);
+
+ return url->hash;
+}
+
+
+/* exported interface, documented in nsurl.h */
nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined)
{
struct url_markers m;
@@ -1819,6 +1869,9 @@ nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined)
/* Fill out the url string */
nsurl_get_string(&c, (*joined)->string, &str_len, str_flags);
+ /* Get the nsurl's hash */
+ nsurl_calc_hash(*joined);
+
/* Give the URL a reference */
(*joined)->count = 1;
@@ -1871,6 +1924,9 @@ nserror nsurl_defragment(const nsurl *url, nsurl **no_frag)
pos += length;
*pos = '\0';
+ /* Get the nsurl's hash */
+ nsurl_calc_hash(*no_frag);
+
/* Give the URL a reference */
(*no_frag)->count = 1;
@@ -1936,6 +1992,9 @@ nserror nsurl_refragment(const nsurl *url, lwc_string *frag, nsurl **new_url)
(*new_url)->components.scheme_type = url->components.scheme_type;
+ /* Get the nsurl's hash */
+ nsurl_calc_hash(*new_url);
+
/* Give the URL a reference */
(*new_url)->count = 1;
@@ -2019,6 +2078,9 @@ nserror nsurl_replace_query(const nsurl *url, const char *query,
(*new_url)->components.scheme_type = url->components.scheme_type;
+ /* Get the nsurl's hash */
+ nsurl_calc_hash(*new_url);
+
/* Give the URL a reference */
(*new_url)->count = 1;
@@ -2114,6 +2176,9 @@ nserror nsurl_parent(const nsurl *url, nsurl **new_url)
(*new_url)->components.scheme_type = url->components.scheme_type;
+ /* Get the nsurl's hash */
+ nsurl_calc_hash(*new_url);
+
/* Give the URL a reference */
(*new_url)->count = 1;