aboutsummaryrefslogtreecommitdiff
path: root/lib/cookie.c
diff options
context:
space:
mode:
authorYAMADA Yasuharu <yasuharu.yamada@access-company.com>2013-09-17 15:51:22 +0900
committerDaniel Stenberg <daniel@haxx.se>2013-09-17 23:25:56 +0200
commit4cfbb201c4f823ba31ba4b895044088fba6ae535 (patch)
treedbb7293836bee3126e71f575a2381e3df3d05579 /lib/cookie.c
parentdc016567ced8d8e75fe45763f3a54ca483a1c7a2 (diff)
cookies: add expiration
Implement: Expired Cookies These following situation, curl removes cookie(s) from struct CookieInfo if the cookie expired. - Curl_cookie_add() - Curl_cookie_getlist() - cookie_output()
Diffstat (limited to 'lib/cookie.c')
-rw-r--r--lib/cookie.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/cookie.c b/lib/cookie.c
index b6790677f..9deeb1ac4 100644
--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -290,6 +290,34 @@ static void strstore(char **str, const char *newstr)
*str = strdup(newstr);
}
+/*
+ * remove_expired() removes expired cookies.
+ */
+static void remove_expired(struct CookieInfo *cookies)
+{
+ struct Cookie *co, *nx, *pv;
+ curl_off_t now = (curl_off_t)time(NULL);
+
+ co = cookies->cookies;
+ pv = NULL;
+ while(co) {
+ nx = co->next;
+ if((co->expirestr || co->maxage) && co->expires < now) {
+ if(co == cookies->cookies) {
+ cookies->cookies = co->next;
+ }
+ else {
+ pv->next = co->next;
+ }
+ cookies->numcookies--;
+ freecookie(co);
+ }
+ else {
+ pv = co;
+ }
+ co = nx;
+ }
+}
/****************************************************************************
*
@@ -700,6 +728,9 @@ Curl_cookie_add(struct SessionHandle *data,
superceeds an already existing cookie, which it may if the previous have
the same domain and path as this */
+ /* at first, remove expired cookies */
+ remove_expired(c);
+
clist = c->cookies;
replace_old = FALSE;
while(clist) {
@@ -931,6 +962,9 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
if(!c || !c->cookies)
return NULL; /* no cookie struct or no cookies in the struct */
+ /* at first, remove expired cookies */
+ remove_expired(c);
+
co = c->cookies;
while(co) {
@@ -1173,6 +1207,9 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
destination file */
return 0;
+ /* at first, remove expired cookies */
+ remove_expired(c);
+
if(strequal("-", dumphere)) {
/* use stdout */
out = stdout;