cURL / Mailing Lists / curl-library / Single Mail

curl-library

Patch: "SESS" special string for CURLOPT_COOKIELIST

From: Michael Wallner <mike_at_iworks.at>
Date: Wed, 24 May 2006 17:09:36 +0200

Hi,

I wonder if the attached patch, which adds the possibility to
reset session cookies only for a curl handle, is intereseting
enough to be considered and included?

In constrast to curl_easy_setopt(ch, CURLOPT_COOKIELIST, "ALL"),
which resets all cookies, the string "SESS" would only reset
session cookies (identified by expires == 0).

AFAICS this is not possible at the moment, but I might miss
obvious things, of course...

PS: Is the three-spaces indentation in cookie.c intended?

Regards,

-- 
Michael

? CURLOPT_COOKIELIST--SESS.diff.txt
Index: docs/libcurl/curl_easy_setopt.3
===================================================================
RCS file: /cvsroot/curl/curl/docs/libcurl/curl_easy_setopt.3,v
retrieving revision 1.148
diff -u -p -d -r1.148 curl_easy_setopt.3
--- docs/libcurl/curl_easy_setopt.3 19 Apr 2006 09:08:15 -0000 1.148
+++ docs/libcurl/curl_easy_setopt.3 24 May 2006 15:00:05 -0000
@@ -762,6 +762,8 @@ Pass a char * to a cookie string. Cookie
 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
 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
 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
Index: lib/cookie.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/cookie.c,v
retrieving revision 1.73
diff -u -p -d -r1.73 cookie.c
--- lib/cookie.c 17 Aug 2005 09:11:27 -0000 1.73
+++ lib/cookie.c 24 May 2006 15:00:05 -0000
@@ -817,6 +817,44 @@ void Curl_cookie_freelist(struct Cookie
    }
 }
 
+
+/*****************************************************************************
+ *
+ * Curl_cookie_freesess()
+ *
+ * Free all session cookies in the cookies list.
+ *
+ ****************************************************************************/
+void Curl_cookie_freesess(struct Cookie **co, long *numcookies)
+{
+ struct Cookie *first, *curr, *next, *prev = NULL;
+
+ first = curr = prev = *co;
+
+ 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);
+ if(numcookies) {
+ --(*numcookies);
+ }
+ } else {
+ prev = curr;
+ }
+ }
+
+ *co = first;
+}
+
+
 /*****************************************************************************
  *
  * Curl_cookie_cleanup()
Index: lib/cookie.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/cookie.h,v
retrieving revision 1.20
diff -u -p -d -r1.20 cookie.h
--- lib/cookie.h 9 Jan 2006 13:17:14 -0000 1.20
+++ lib/cookie.h 24 May 2006 15:00:05 -0000
@@ -89,6 +89,7 @@ struct CookieInfo *Curl_cookie_init(stru
                                     char *, struct CookieInfo *, bool);
 struct Cookie *Curl_cookie_getlist(struct CookieInfo *, char *, char *, bool);
 void Curl_cookie_freelist(struct Cookie *);
+void Curl_cookie_freesess(struct Cookie **, long *);
 void Curl_cookie_cleanup(struct CookieInfo *);
 int Curl_cookie_output(struct CookieInfo *, char *);
 
Index: lib/url.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/url.c,v
retrieving revision 1.502
diff -u -p -d -r1.502 url.c
--- lib/url.c 10 Apr 2006 15:00:54 -0000 1.502
+++ lib/url.c 24 May 2006 15:00:06 -0000
@@ -837,6 +837,13 @@ CURLcode Curl_setopt(struct SessionHandl
       }
       break;
     }
+ if(strequal(argptr, "SESS")) {
+ if(data->cookies) {
+ /* clear session cookies */
+ Curl_cookie_freesess(&data->cookies->cookies, &data->cookies->numcookies);
+ }
+ break;
+ }
 
     if(!data->cookies)
       /* if cookie engine was not running, activate it */
Received on 2006-05-24