diff options
author | Rob Kendrick (humdrum) <rob.kendrick@codethink.co.uk> | 2013-05-17 13:15:25 +0100 |
---|---|---|
committer | Rob Kendrick (humdrum) <rob.kendrick@codethink.co.uk> | 2013-05-17 13:15:25 +0100 |
commit | bb08964f2726a168b77dfe147bbec1b737215aa9 (patch) | |
tree | 4a8f9fcdd644ff41c9188a98a2ce8d894b0504cd /utils | |
parent | c204e5ff0cbdb71eb8fe05c31252dc1d0674d300 (diff) | |
parent | c240fb0c008b57ee72ae6c1e9a9d94dbc3d7a955 (diff) | |
download | netsurf-bb08964f2726a168b77dfe147bbec1b737215aa9.tar.gz netsurf-bb08964f2726a168b77dfe147bbec1b737215aa9.tar.bz2 |
Merge branch 'master' into rjek/bloom
Diffstat (limited to 'utils')
-rw-r--r-- | utils/nsurl.c | 65 | ||||
-rw-r--r-- | utils/nsurl.h | 9 |
2 files changed, 74 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; diff --git a/utils/nsurl.h b/utils/nsurl.h index b075c42a1..435df73bd 100644 --- a/utils/nsurl.h +++ b/utils/nsurl.h @@ -208,6 +208,15 @@ size_t nsurl_length(const nsurl *url); /** + * Get a URL's hash value + * + * \param url NetSurf URL get hash value for. + * \return the hash value + */ +uint32_t nsurl_hash(const nsurl *url); + + +/** * Join a base url to a relative link part, creating a new NetSurf URL object * * \param base NetSurf URL containing the base to join rel to |