Michael Wallner provided a patch that allows "SESS" to be set with

CURLOPT_COOKIELIST, which then makes all session cookies get cleared. (slightly
edited by me, and the re-indent in cookie.c was also done by me)
This commit is contained in:
Daniel Stenberg 2006-05-24 22:46:38 +00:00
parent f689d06ca9
commit 606562aa7e
6 changed files with 160 additions and 98 deletions

View File

@ -6,6 +6,10 @@
Changelog Changelog
Daniel (25 May 2006)
- Michael Wallner provided a patch that allows "SESS" to be set with
CURLOPT_COOKIELIST, which then makes all session cookies get cleared.
Daniel (11 May 2006) Daniel (11 May 2006)
- David McCreedy provided a fix for CURLINFO_LASTSOCKET that does extended - David McCreedy provided a fix for CURLINFO_LASTSOCKET that does extended
checks on the to-be-returned socket to make sure it truly seems to be alive checks on the to-be-returned socket to make sure it truly seems to be alive

View File

@ -11,6 +11,7 @@ Curl and libcurl 7.15.4
This release includes the following changes: This release includes the following changes:
o CURLOPT_COOKIELIST set to "SESS" clears all session cookies
o CURLINFO_LASTSOCKET returned sockets are now checked more before returned o CURLINFO_LASTSOCKET returned sockets are now checked more before returned
o curl-config got a --checkfor option to compare version numbers o curl-config got a --checkfor option to compare version numbers
o line end conversions for FTP ASCII transfers o line end conversions for FTP ASCII transfers
@ -56,6 +57,6 @@ advice from friends like these:
Dan Fandrich, Ilja van Sprundel, David McCreedy, Tor Arntsen, Xavier Bouchoux, Dan Fandrich, Ilja van Sprundel, David McCreedy, Tor Arntsen, Xavier Bouchoux,
David Byron, Michele Bini, Ates Goral, Katie Wang, Robson Braga Araujo, David Byron, Michele Bini, Ates Goral, Katie Wang, Robson Braga Araujo,
Ale Vesely, Paul Querna, Gisle Vanem, Mark Eichin, Roland Blom, Andreas Ale Vesely, Paul Querna, Gisle Vanem, Mark Eichin, Roland Blom, Andreas
Ntaflos, David Shaw Ntaflos, David Shaw, Michael Wallner
Thanks! (and sorry if I forgot to mention someone) Thanks! (and sorry if I forgot to mention someone)

View File

@ -762,6 +762,8 @@ Pass a char * to a cookie string. Cookie can be either in Netscape / Mozilla
format or just regular HTTP-style header (Set-Cookie: ...) format. If cURL format or just regular HTTP-style header (Set-Cookie: ...) format. If cURL
cookie engine was not enabled it will enable its cookie engine. Passing a cookie engine was not enabled it will enable its cookie engine. Passing a
magic string \&"ALL" will erase all cookies known by cURL. (Added in 7.14.1) magic string \&"ALL" will erase all cookies known by cURL. (Added in 7.14.1)
Passing the special string \&"SESS" will only erase all session cookies known
by cURL. (Added in 7.15.4)
.IP CURLOPT_HTTPGET .IP CURLOPT_HTTPGET
Pass a long. If the long is non-zero, this forces the HTTP request to get back Pass a long. If the long is non-zero, this forces the HTTP request to get back
to GET. usable if a POST, HEAD, PUT or a custom request have been used to GET. usable if a POST, HEAD, PUT or a custom request have been used

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -733,68 +733,81 @@ struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
struct Cookie *Curl_cookie_getlist(struct CookieInfo *c, struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
char *host, char *path, bool secure) char *host, char *path, bool secure)
{ {
struct Cookie *newco; struct Cookie *newco;
struct Cookie *co; struct Cookie *co;
time_t now = time(NULL); time_t now = time(NULL);
struct Cookie *mainco=NULL; struct Cookie *mainco=NULL;
if(!c || !c->cookies) if(!c || !c->cookies)
return NULL; /* no cookie struct or no cookies in the struct */ return NULL; /* no cookie struct or no cookies in the struct */
co = c->cookies; co = c->cookies;
while(co) { while(co) {
/* only process this cookie if it is not expired or had no expire /* only process this cookie if it is not expired or had no expire
date AND that if the cookie requires we're secure we must only date AND that if the cookie requires we're secure we must only
continue if we are! */ continue if we are! */
if( (co->expires<=0 || (co->expires> now)) && if( (co->expires<=0 || (co->expires> now)) &&
(co->secure?secure:TRUE) ) { (co->secure?secure:TRUE) ) {
/* now check if the domain is correct */ /* now check if the domain is correct */
if(!co->domain || if(!co->domain ||
(co->tailmatch && tailmatch(co->domain, host)) || (co->tailmatch && tailmatch(co->domain, host)) ||
(!co->tailmatch && strequal(host, co->domain)) ) { (!co->tailmatch && strequal(host, co->domain)) ) {
/* the right part of the host matches the domain stuff in the /* the right part of the host matches the domain stuff in the
cookie data */ cookie data */
/* now check the left part of the path with the cookies path /* now check the left part of the path with the cookies path
requirement */ requirement */
if(!co->path || if(!co->path ||
checkprefix(co->path, path) ) { checkprefix(co->path, path) ) {
/* and now, we know this is a match and we should create an /* and now, we know this is a match and we should create an
entry for the return-linked-list */ entry for the return-linked-list */
newco = (struct Cookie *)malloc(sizeof(struct Cookie)); newco = (struct Cookie *)malloc(sizeof(struct Cookie));
if(newco) { if(newco) {
/* first, copy the whole source cookie: */ /* first, copy the whole source cookie: */
memcpy(newco, co, sizeof(struct Cookie)); memcpy(newco, co, sizeof(struct Cookie));
/* then modify our next */ /* then modify our next */
newco->next = mainco; newco->next = mainco;
/* point the main to us */ /* point the main to us */
mainco = newco; mainco = newco;
} }
else { else {
/* failure, clear up the allocated chain and return NULL */ /* failure, clear up the allocated chain and return NULL */
while(mainco) { while(mainco) {
co = mainco->next; co = mainco->next;
free(mainco); free(mainco);
mainco = co; mainco = co;
} }
return NULL; return NULL;
} }
} }
} }
} }
co = co->next; co = co->next;
} }
return mainco; /* return the new list */ return mainco; /* return the new list */
} }
/*****************************************************************************
*
* Curl_cookie_clearall()
*
* Clear all existing cookies and reset the counter.
*
****************************************************************************/
void Curl_cookie_clearall(struct CookieInfo *cookies)
{
Curl_cookie_freelist(cookies->cookies);
cookies->cookies = NULL;
cookies->numcookies = 0;
}
/***************************************************************************** /*****************************************************************************
* *
@ -806,17 +819,56 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
void Curl_cookie_freelist(struct Cookie *co) void Curl_cookie_freelist(struct Cookie *co)
{ {
struct Cookie *next; struct Cookie *next;
if(co) { if(co) {
while(co) { while(co) {
next = co->next; next = co->next;
free(co); /* we only free the struct since the "members" are all free(co); /* we only free the struct since the "members" are all
just copied! */ just copied! */
co = next; co = next;
} }
} }
} }
/*****************************************************************************
*
* Curl_cookie_clearsess()
*
* Free all session cookies in the cookies list.
*
****************************************************************************/
void Curl_cookie_clearsess(struct CookieInfo *cookies)
{
struct Cookie *first, *curr, *next, *prev = NULL;
if(!cookies->cookies)
return;
first = curr = prev = cookies->cookies;
for(; curr; curr = next) {
next = curr->next;
if(!curr->expires) {
if(first == curr)
first = next;
if(prev == curr)
prev = next;
else
prev->next = next;
free(curr);
cookies->numcookies--;
}
else
prev = curr;
}
cookies->cookies = first;
}
/***************************************************************************** /*****************************************************************************
* *
* Curl_cookie_cleanup() * Curl_cookie_cleanup()
@ -826,20 +878,20 @@ void Curl_cookie_freelist(struct Cookie *co)
****************************************************************************/ ****************************************************************************/
void Curl_cookie_cleanup(struct CookieInfo *c) void Curl_cookie_cleanup(struct CookieInfo *c)
{ {
struct Cookie *co; struct Cookie *co;
struct Cookie *next; struct Cookie *next;
if(c) { if(c) {
if(c->filename) if(c->filename)
free(c->filename); free(c->filename);
co = c->cookies; co = c->cookies;
while(co) { while(co) {
next = co->next; next = co->next;
freecookie(co); freecookie(co);
co = next; co = next;
} }
free(c); /* free the base struct as well */ free(c); /* free the base struct as well */
} }
} }
/* get_netscape_format() /* get_netscape_format()
@ -850,24 +902,24 @@ void Curl_cookie_cleanup(struct CookieInfo *c)
*/ */
static char *get_netscape_format(const struct Cookie *co) static char *get_netscape_format(const struct Cookie *co)
{ {
return aprintf( return aprintf(
"%s%s\t" /* domain */ "%s%s\t" /* domain */
"%s\t" /* tailmatch */ "%s\t" /* tailmatch */
"%s\t" /* path */ "%s\t" /* path */
"%s\t" /* secure */ "%s\t" /* secure */
"%" FORMAT_OFF_T "\t" /* expires */ "%" FORMAT_OFF_T "\t" /* expires */
"%s\t" /* name */ "%s\t" /* name */
"%s", /* value */ "%s", /* value */
/* Make sure all domains are prefixed with a dot if they allow /* Make sure all domains are prefixed with a dot if they allow
tailmatching. This is Mozilla-style. */ tailmatching. This is Mozilla-style. */
(co->tailmatch && co->domain && co->domain[0] != '.')? ".":"", (co->tailmatch && co->domain && co->domain[0] != '.')? ".":"",
co->domain?co->domain:"unknown", co->domain?co->domain:"unknown",
co->tailmatch?"TRUE":"FALSE", co->tailmatch?"TRUE":"FALSE",
co->path?co->path:"/", co->path?co->path:"/",
co->secure?"TRUE":"FALSE", co->secure?"TRUE":"FALSE",
co->expires, co->expires,
co->name, co->name,
co->value?co->value:""); co->value?co->value:"");
} }
/* /*

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -89,6 +89,8 @@ struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
char *, struct CookieInfo *, bool); char *, struct CookieInfo *, bool);
struct Cookie *Curl_cookie_getlist(struct CookieInfo *, char *, char *, bool); struct Cookie *Curl_cookie_getlist(struct CookieInfo *, char *, char *, bool);
void Curl_cookie_freelist(struct Cookie *); void Curl_cookie_freelist(struct Cookie *);
void Curl_cookie_clearall(struct CookieInfo *cookies);
void Curl_cookie_clearsess(struct CookieInfo *cookies);
void Curl_cookie_cleanup(struct CookieInfo *); void Curl_cookie_cleanup(struct CookieInfo *);
int Curl_cookie_output(struct CookieInfo *, char *); int Curl_cookie_output(struct CookieInfo *, char *);

View File

@ -829,12 +829,13 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
break; break;
if(strequal(argptr, "ALL")) { if(strequal(argptr, "ALL")) {
if(data->cookies) { /* clear all cookies */
/* clear all cookies */ Curl_cookie_clearall(data->cookies);
Curl_cookie_freelist(data->cookies->cookies); break;
data->cookies->cookies = NULL; }
data->cookies->numcookies = 0; else if(strequal(argptr, "SESS")) {
} /* clear session cookies */
Curl_cookie_clearsess(data->cookies);
break; break;
} }
@ -2299,7 +2300,7 @@ static CURLcode ConnectPlease(struct connectdata *conn,
break; break;
case CURLPROXY_SOCKS4: case CURLPROXY_SOCKS4:
return handleSock4Proxy(conn->proxyuser, conn) ? return handleSock4Proxy(conn->proxyuser, conn) ?
CURLE_COULDNT_CONNECT : CURLE_OK; CURLE_COULDNT_CONNECT : CURLE_OK;
default: default:
failf(conn->data, "unknown proxytype option given"); failf(conn->data, "unknown proxytype option given");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;