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()
This commit is contained in:
YAMADA Yasuharu
2013-09-17 15:51:22 +09:00
committed by Daniel Stenberg
parent dc016567ce
commit 4cfbb201c4
3 changed files with 110 additions and 1 deletions

View File

@@ -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;