From 4cfbb201c4f823ba31ba4b895044088fba6ae535 Mon Sep 17 00:00:00 2001 From: YAMADA Yasuharu Date: Tue, 17 Sep 2013 15:51:22 +0900 Subject: 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() --- lib/cookie.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'lib/cookie.c') 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; -- cgit v1.2.3