mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-26 08:19:55 +03:00
Add function to get a nsurl's hash value.
This commit is contained in:
parent
abebc6ae2b
commit
39cc1a6d4a
@ -154,6 +154,7 @@ struct nsurl {
|
|||||||
struct nsurl_components components;
|
struct nsurl_components components;
|
||||||
|
|
||||||
int count; /* Number of references to NetSurf URL object */
|
int count; /* Number of references to NetSurf URL object */
|
||||||
|
uint32_t hash; /* Hash value for nsurl identification */
|
||||||
|
|
||||||
size_t length; /* Length of string */
|
size_t length; /* Length of string */
|
||||||
char string[FLEX_ARRAY_LEN_DECL]; /* Full URL as a 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
|
#ifdef NSURL_DEBUG
|
||||||
/**
|
/**
|
||||||
* Dump a NetSurf URL's internal components
|
* 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 */
|
/* Fill out the url string */
|
||||||
nsurl_get_string(&c, (*url)->string, &str_len, str_flags);
|
nsurl_get_string(&c, (*url)->string, &str_len, str_flags);
|
||||||
|
|
||||||
|
/* Get the nsurl's hash */
|
||||||
|
nsurl_calc_hash(*url);
|
||||||
|
|
||||||
/* Give the URL a reference */
|
/* Give the URL a reference */
|
||||||
(*url)->count = 1;
|
(*url)->count = 1;
|
||||||
|
|
||||||
@ -1614,6 +1655,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 */
|
/* exported interface, documented in nsurl.h */
|
||||||
nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined)
|
nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined)
|
||||||
{
|
{
|
||||||
@ -1819,6 +1869,9 @@ nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined)
|
|||||||
/* Fill out the url string */
|
/* Fill out the url string */
|
||||||
nsurl_get_string(&c, (*joined)->string, &str_len, str_flags);
|
nsurl_get_string(&c, (*joined)->string, &str_len, str_flags);
|
||||||
|
|
||||||
|
/* Get the nsurl's hash */
|
||||||
|
nsurl_calc_hash(*joined);
|
||||||
|
|
||||||
/* Give the URL a reference */
|
/* Give the URL a reference */
|
||||||
(*joined)->count = 1;
|
(*joined)->count = 1;
|
||||||
|
|
||||||
@ -1871,6 +1924,9 @@ nserror nsurl_defragment(const nsurl *url, nsurl **no_frag)
|
|||||||
pos += length;
|
pos += length;
|
||||||
*pos = '\0';
|
*pos = '\0';
|
||||||
|
|
||||||
|
/* Get the nsurl's hash */
|
||||||
|
nsurl_calc_hash(*no_frag);
|
||||||
|
|
||||||
/* Give the URL a reference */
|
/* Give the URL a reference */
|
||||||
(*no_frag)->count = 1;
|
(*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;
|
(*new_url)->components.scheme_type = url->components.scheme_type;
|
||||||
|
|
||||||
|
/* Get the nsurl's hash */
|
||||||
|
nsurl_calc_hash(*new_url);
|
||||||
|
|
||||||
/* Give the URL a reference */
|
/* Give the URL a reference */
|
||||||
(*new_url)->count = 1;
|
(*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;
|
(*new_url)->components.scheme_type = url->components.scheme_type;
|
||||||
|
|
||||||
|
/* Get the nsurl's hash */
|
||||||
|
nsurl_calc_hash(*new_url);
|
||||||
|
|
||||||
/* Give the URL a reference */
|
/* Give the URL a reference */
|
||||||
(*new_url)->count = 1;
|
(*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;
|
(*new_url)->components.scheme_type = url->components.scheme_type;
|
||||||
|
|
||||||
|
/* Get the nsurl's hash */
|
||||||
|
nsurl_calc_hash(*new_url);
|
||||||
|
|
||||||
/* Give the URL a reference */
|
/* Give the URL a reference */
|
||||||
(*new_url)->count = 1;
|
(*new_url)->count = 1;
|
||||||
|
|
||||||
|
@ -207,6 +207,15 @@ const char *nsurl_access_leaf(const nsurl *url);
|
|||||||
size_t nsurl_length(const nsurl *url);
|
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
|
* Join a base url to a relative link part, creating a new NetSurf URL object
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user