Author: jmb
Date: Mon Nov 21 18:34:06 2011
New Revision: 13161
URL:
http://source.netsurf-browser.org?rev=13161&view=rev
Log:
Fix cookie expiration
Modified:
trunk/netsurf/content/urldb.c
trunk/netsurf/test/urldbtest.c
Modified: trunk/netsurf/content/urldb.c
URL:
http://source.netsurf-browser.org/trunk/netsurf/content/urldb.c?rev=13161...
==============================================================================
--- trunk/netsurf/content/urldb.c (original)
+++ trunk/netsurf/content/urldb.c Mon Nov 21 18:34:06 2011
@@ -120,7 +120,7 @@
char *domain; /**< Domain */
bool path_from_set; /**< Path came from Set-Cookie: header */
char *path; /**< Path */
- time_t expires; /**< Expiry timestamp, or 1 for session */
+ time_t expires; /**< Expiry timestamp, or -1 for session */
time_t last_used; /**< Last used time */
bool secure; /**< Only send for HTTPS requests */
cookie_version version; /**< Specification compliance */
@@ -2505,7 +2505,7 @@
/* Consider all cookies associated with
* this exact path */
for (c = q->cookies; c; c = c->next) {
- if (c->expires != 1 && c->expires < now)
+ if (c->expires != -1 && c->expires < now)
/* cookie has expired => ignore */
continue;
@@ -2537,7 +2537,7 @@
continue;
for (c = q->cookies; c; c = c->next) {
- if (c->expires != 1 && c->expires < now)
+ if (c->expires != -1 && c->expires < now)
/* cookie has expired => ignore */
continue;
@@ -2573,7 +2573,7 @@
/* Consider p itself - may be the result of Path=/foo */
for (c = p->cookies; c; c = c->next) {
- if (c->expires != 1 && c->expires < now)
+ if (c->expires != -1 && c->expires < now)
/* cookie has expired => ignore */
continue;
@@ -2604,7 +2604,7 @@
for (h = (const struct host_part *)p; h && h != &db_root;
h = h->parent) {
for (c = h->paths.cookies; c; c = c->next) {
- if (c->expires != 1 && c->expires < now)
+ if (c->expires != -1 && c->expires < now)
/* cookie has expired => ignore */
continue;
@@ -3180,9 +3180,6 @@
c->path = path;
}
- if (c->expires == -1)
- c->expires = 1;
-
/* Write back current position */
*cookie = cur;
@@ -3308,6 +3305,7 @@
struct cookie_internal_data *d;
const struct host_part *h;
struct path_data *p;
+ time_t now = time(NULL);
assert(c && scheme && url);
@@ -3355,7 +3353,7 @@
}
if (d) {
- if (c->expires == 0) {
+ if (c->expires != -1 && c->expires < now) {
/* remove cookie */
if (d->next)
d->next->prev = d->prev;
@@ -3856,8 +3854,8 @@
struct cookie_internal_data *c;
for (c = p->cookies; c != NULL; c = c->next) {
- if (c->expires < now)
- /* Skip expired cookies */
+ if (c->expires == -1 || c->expires < now)
+ /* Skip expired & session cookies */
continue;
fprintf(fp,
Modified: trunk/netsurf/test/urldbtest.c
URL:
http://source.netsurf-browser.org/trunk/netsurf/test/urldbtest.c?rev=1316...
==============================================================================
--- trunk/netsurf/test/urldbtest.c (original)
+++ trunk/netsurf/test/urldbtest.c Mon Nov 21 18:34:06 2011
@@ -247,6 +247,12 @@
assert(urldb_set_cookie("foo=bar; domain=.example.tld\r\n",
"http://www.foo.example.tld/", "http://bar.example.tld/"));
assert(strcmp(urldb_get_cookie("http://www.foo.example.tld/"),
"foo=bar") == 0);
+ /* Test expiry */
+ assert(urldb_set_cookie("foo=bar", "http://expires.com/", NULL));
+
assert(strcmp(urldb_get_cookie("http://expires.com/"), "foo=bar") ==
0);
+ assert(urldb_set_cookie("foo=bar; expires=Thu, 01-Jan-1970 00:00:01 GMT\r\n",
"http://expires.com/", NULL));
+
assert(urldb_get_cookie("http://expires.com/") == NULL);
+
urldb_dump();
printf("PASS\n");