aboutsummaryrefslogtreecommitdiff
path: root/lib/cookie.c
diff options
context:
space:
mode:
authorLauri Kasanen <cand@gmx.com>2018-04-05 15:55:59 +0300
committerDaniel Stenberg <daniel@haxx.se>2018-04-06 14:13:08 +0200
commit746479adcbd2bba06077642fefe0414ad6e1e0ea (patch)
tree6156243c63cfa2ab9941cf961b49d6db26830462 /lib/cookie.c
parent82dfdac5f797d2e906b94aef3f82b6a80353a575 (diff)
cookie: case-insensitive hashing for the domains
closes #2458
Diffstat (limited to 'lib/cookie.c')
-rw-r--r--lib/cookie.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/cookie.c b/lib/cookie.c
index ec3b1bf9a..5aa959690 100644
--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -90,7 +90,6 @@ Example set of cookies:
#include "urldata.h"
#include "cookie.h"
-#include "hash.h"
#include "strtok.h"
#include "sendf.h"
#include "slist.h"
@@ -266,6 +265,22 @@ static const char *get_top_domain(const char * const domain, size_t *outlen)
}
/*
+ * A case-insensitive hash for the cookie domains.
+ */
+static size_t cookie_hash_domain(const char *domain, const size_t len)
+{
+ const char *end = domain + len;
+ unsigned long h = 5381;
+
+ while(domain < end) {
+ h += h << 5;
+ h ^= (unsigned long) Curl_raw_toupper(*domain++);
+ }
+
+ return (h % COOKIE_HASH_SIZE);
+}
+
+/*
* Hash this domain.
*/
static size_t cookiehash(const char * const domain)
@@ -277,7 +292,7 @@ static size_t cookiehash(const char * const domain)
return 0;
top = get_top_domain(domain, &len);
- return Curl_hash_str((void *) top, len, COOKIE_HASH_SIZE);
+ return cookie_hash_domain(top, len);
}
/*