cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH] CULROPT_COOKIELIST & "FLUSH"

From: Michael Wallner <mike_at_iworks.at>
Date: Wed, 03 Oct 2007 22:12:44 +0200

Hi,

attached is a patch which adds the "FLUSH" magic string to the
recognized ones by CURLOPT_COOKIELIST. This will cause curl to flush
its cookies to the CURLOPT_COOKIEJAR file.

Comments, objections, flame wars? ;)

Regards,

-- 
Michael

? flush_cookies.diff.txt
? huge.diff
Index: docs/libcurl/curl_easy_setopt.3
===================================================================
RCS file: /cvsroot/curl/curl/docs/libcurl/curl_easy_setopt.3,v
retrieving revision 1.197
diff -u -p -d -r1.197 curl_easy_setopt.3
--- docs/libcurl/curl_easy_setopt.3 3 Oct 2007 08:00:42 -0000 1.197
+++ docs/libcurl/curl_easy_setopt.3 3 Oct 2007 20:08:41 -0000
@@ -810,7 +810,9 @@ format or just regular HTTP-style header
 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)
+by cURL. (Added in 7.15.4) Passing the special string \&"FLUSH" will write
+all cookies known by cURL to the file specified by \fICURLOPT_COOKIEJAR\fP.
+(Added in 7.17.1)
 .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/url.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/url.c,v
retrieving revision 1.650
diff -u -p -d -r1.650 url.c
--- lib/url.c 3 Oct 2007 08:45:00 -0000 1.650
+++ lib/url.c 3 Oct 2007 20:08:48 -0000
@@ -165,6 +165,10 @@ static void signalPipeClose(struct curl_
 
 static struct SessionHandle* gethandleathead(struct curl_llist *pipeline);
 
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
+static void flush_cookies(struct SessionHandle *data, int cleanup);
+#endif
+
 #define MAX_PIPELINE_LENGTH 5
 
 /*
@@ -269,6 +273,36 @@ CURLcode Curl_dupset(struct SessionHandl
   return r;
 }
 
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
+static void flush_cookies(struct SessionHandle *data, int cleanup)
+{
+ Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
+ if(data->set.str[STRING_COOKIEJAR]) {
+ if(data->change.cookielist) {
+ /* If there is a list of cookie files to read, do it first so that
+ we have all the told files read before we write the new jar */
+ Curl_cookie_loadfiles(data);
+ }
+
+ /* we have a "destination" for all the cookies to get dumped to */
+ if(Curl_cookie_output(data->cookies, data->set.str[STRING_COOKIEJAR]))
+ infof(data, "WARNING: failed to save cookies in %s\n",
+ data->set.str[STRING_COOKIEJAR]);
+ }
+ else {
+ if(cleanup && data->change.cookielist)
+ /* since nothing is written, we can just free the list of cookie file
+ names */
+ curl_slist_free_all(data->change.cookielist); /* clean up list */
+ }
+
+ if(cleanup && (!data->share || (data->cookies != data->share->cookies))) {
+ Curl_cookie_cleanup(data->cookies);
+ }
+ Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
+}
+#endif
+
 /*
  * This is the internal function curl_easy_cleanup() calls. This should
  * cleanup and free all resources associated with this sessionhandle.
@@ -380,30 +414,7 @@ CURLcode Curl_close(struct SessionHandle
   Curl_safefree(data->state.headerbuff);
 
 #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
- Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
- if(data->set.str[STRING_COOKIEJAR]) {
- if(data->change.cookielist) {
- /* If there is a list of cookie files to read, do it first so that
- we have all the told files read before we write the new jar */
- Curl_cookie_loadfiles(data);
- }
-
- /* we have a "destination" for all the cookies to get dumped to */
- if(Curl_cookie_output(data->cookies, data->set.str[STRING_COOKIEJAR]))
- infof(data, "WARNING: failed to save cookies in %s\n",
- data->set.str[STRING_COOKIEJAR]);
- }
- else {
- if(data->change.cookielist)
- /* since nothing is written, we can just free the list of cookie file
- names */
- curl_slist_free_all(data->change.cookielist); /* clean up list */
- }
-
- if( !data->share || (data->cookies != data->share->cookies) ) {
- Curl_cookie_cleanup(data->cookies);
- }
- Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
+ flush_cookies(data, 1);
 #endif
 
   Curl_digest_cleanup(data);
@@ -1089,6 +1100,11 @@ CURLcode Curl_setopt(struct SessionHandl
       Curl_cookie_clearsess(data->cookies);
       break;
     }
+ else if(strequal(argptr, "FLUSH")) {
+ /* flush cookies to file */
+ flush_cookies(data, 0);
+ break;
+ }
 
     if(!data->cookies)
       /* if cookie engine was not running, activate it */
Received on 2007-10-03