Commit b77491c6 authored by Stewart Brodie's avatar Stewart Brodie
Browse files

Cookie fix - internal counter was getting out of sync with the number of...

Cookie fix - internal counter was getting out of sync with the number of cookies being held resulting in a limit of 20 cookies ever being received from any given site.
parent b14a5687
......@@ -756,51 +756,45 @@ static CookieDomain *find_domain(char *find)
*/
static void remove_cookie_from_list(Cookie *current_cookie, int remove_domain)
{
CookieDomain *current_domain;
#ifdef TRACE
cookie_debug("Removing cookie (handle %p) from the list.\n", current_cookie);
#endif
if (!current_cookie) return;
/* Unlink cookie from list */
if (current_cookie->previous) {
/* If in the middle of the list... optimise */
Cookie *fake_cookie = NULL;
#ifdef TRACE
cookie_debug("Taking it out of the middle of the list.\n");
#endif
cookie_unlink_cookie(&fake_cookie, current_cookie);
}
else {
/* Otherwise deal with head of list */
CookieDomain *current_domain = find_domain(current_cookie->domain);
#ifdef TRACE
if (!current_domain) cookie_debug("Failed to find cookie's domain!!!\n");
#endif
if (current_domain == NULL) return;
current_domain = find_domain(current_cookie->domain);
#ifdef TRACE
if (!current_domain) cookie_debug("Failed to find cookie's domain!!!\n");
#endif
if (current_domain == NULL) return;
/* Reduce the number of cookies in that domain by one and remove the cookie */
current_domain->cookies -= 1;
cookie_unlink_cookie(&current_domain->cookie, current_cookie);
/* Reduce the number of cookies in that domain by one and remove the cookie */
current_domain->cookies -= 1;
cookie_unlink_cookie(&current_domain->cookie, current_cookie);
if (current_domain->cookie == NULL && remove_domain == DOMAIN_TOO) {
/* Domain has no cookies and we were asked to delete empty domains */
cookie_unlink_cookie_domain(&cookie_domain_root, current_domain);
free(current_domain->domain);
free(current_domain);
}
if (current_domain->cookie == NULL && remove_domain == DOMAIN_TOO) {
/* Domain has no cookies and we were asked to delete empty domains */
cookie_unlink_cookie_domain(&cookie_domain_root, current_domain);
free(current_domain->domain);
free(current_domain);
}
}
/* Function to remove least used cookie from linked list */
static void expire_cookies(CookieDomain *cookie_domain)
{
#ifdef TRACE
size_t count = 0;
#endif
Cookie *cookie, *least_used;
least_used = cookie_domain->cookie;
for (cookie = least_used; cookie; cookie = cookie->next) {
#ifdef TRACE
++count;
#endif
if (cookie->last_access < least_used->last_access) {
least_used = cookie;
}
......@@ -810,6 +804,11 @@ static void expire_cookies(CookieDomain *cookie_domain)
cookie_debug("expire_cookies: Domain %s, cookie %s\n",cookie_domain->domain, least_used->domain);
#endif
#ifdef TRACE
cookie_debug("expire_cookies: Domain thinks it has %d cookie(s)\n", cookie_domain->cookies);
cookie_debug("expire_cookies: Our count says it has %d cookie(s)\n", count);
#endif
remove_cookie_from_list(least_used, NOT_DOMAIN);
destroy_cookie(least_used);
}
......@@ -1009,12 +1008,22 @@ static void cookie_link_to_domain(CookieDomain *head, Cookie *cookie)
destroy_cookie(insertion_point);
}
#ifdef TRACE
{
size_t count = 0;
Cookie *c;
for (c = head->cookie; c; c=c->next) ++count;
cookie_debug("Cookie domain (%s) thinks it has %d cookie(s)\n", head->domain, head->cookies);
cookie_debug("Cookie domain (%s) really has %d cookie(s)\n", head->domain, count);
}
#endif
head->cookies ++;
if (head->cookies >= MAX_COOKIES_PER_DOMAIN) {
expire_cookies(head);
}
if (head->cookie == NULL || strcmp(head->cookie->path, path) > 0) {
if (head->cookie == NULL || strcmp(head->cookie->path, path) >= 0) {
/* Simple case - either is the only cookie or it needs to go first */
#ifdef TRACE
cookie_debug("Inserting cookie at head of domain list\n");
......
......@@ -21,7 +21,7 @@
title-string: AcornHTTP
; Version information
help-string: Acorn_HTTP 0.75
help-string: Acorn_HTTP 0.76
; Initialisation routine.
initialisation-code: module_init
......@@ -54,4 +54,4 @@ service-call-handler: service_handler &83E00
vector-handlers: callevery_entry/callevery_handler,
callback_entry/callback_handler
date-string: 17 Feb 1998
date-string: 23 Feb 1998
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment