]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
CURLOPT_COOKIELIST: Added "RELOAD" command
authorYousuke Kimoto <yousuke.kimoto@gmail.com>
Thu, 25 Sep 2014 14:25:52 +0000 (16:25 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 25 Sep 2014 14:28:17 +0000 (16:28 +0200)
docs/libcurl/opts/CURLOPT_COOKIELIST.3
lib/url.c
tests/data/test506
tests/libtest/lib506.c

index 278a520da6eeaa8b10682bb63ea62a1d42615b46..815def1b980e3df8ffc5590b18b994783af7358f 100644 (file)
@@ -46,6 +46,10 @@ erases all session cookies held in memory
 
 .IP FLUSH
 writes all known cookies to the file specified by \fICURLOPT_COOKIEJAR(3)\fP
+
+.IP RELOAD
+loads all cookies from the files specified by \fICURLOPT_COOKIEFILE(3)\fP
+
 .SH DEFAULT
 NULL
 .SH PROTOCOLS
@@ -58,6 +62,8 @@ ALL was added in 7.14.1
 SESS was added in 7.15.4
 
 FLUSH was added in 7.17.1
+
+RELOAD was added in 7.39.0
 .SH RETURN VALUE
 Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
 CURLE_OUT_OF_MEMORY if there was insufficient heap space.
index b2b68378a95292e1167b7559926fdb611a57d8c0..69a75e31086f791fa1d066465a9dff27d12bfe83 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -1191,6 +1191,11 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
       /* flush cookies to file, takes care of the locking */
       Curl_flush_cookies(data, 0);
     }
+    else if(Curl_raw_equal(argptr, "RELOAD")) {
+      /* reload cookies from file */
+      Curl_cookie_loadfiles(data);
+      break;
+    }
     else {
       if(!data->cookies)
         /* if cookie engine was not running, activate it */
index f53a68040d9f176d150bbc88818b9f5781eeafa4..07bbdeaf3b59d2bcfe8652eea529fe02a0c5748c 100644 (file)
@@ -169,18 +169,42 @@ unlock: cookie [Pigs in space]: 63
 run 3: overwrite cookie 1 and 4
 lock:   dns    [Pigs in space]: 64
 unlock: dns    [Pigs in space]: 65
-try SHARE_CLEANUP...
-lock:   share  [Pigs in space]: 66
-unlock: share  [Pigs in space]: 67
-SHARE_CLEANUP failed, correct
 CLEANUP
-lock:   cookie [Pigs in space]: 68
-unlock: cookie [Pigs in space]: 69
+lock:   cookie [Pigs in space]: 66
+unlock: cookie [Pigs in space]: 67
+lock:   share  [Pigs in space]: 68
+unlock: share  [Pigs in space]: 69
+CURLOPT_SHARE
 lock:   share  [Pigs in space]: 70
 unlock: share  [Pigs in space]: 71
+CURLOPT_COOKIELIST ALL
+lock:   cookie [Pigs in space]: 72
+unlock: cookie [Pigs in space]: 73
+CURLOPT_COOKIEJAR
+CURLOPT_COOKIELIST RELOAD
+lock:   cookie [Pigs in space]: 74
+unlock: cookie [Pigs in space]: 75
+loaded cookies:
+-----------------
+  .host.foo.com        TRUE    /       FALSE   1896263787      injected        yes
+  .foo.com     TRUE    /       FALSE   1993463787      test1   overwritten1
+  .host.foo.com        TRUE    /       FALSE   1896263787      test2   two
+  .foo.com     TRUE    /       FALSE   1896263787      test3   three
+  .host.foo.com        TRUE    /       FALSE   2061978987      test4   overwritten4
+  .host.foo.com        TRUE    /       FALSE   1896263787      test5   five
+-----------------
+try SHARE_CLEANUP...
+lock:   share  [Pigs in space]: 76
+unlock: share  [Pigs in space]: 77
+SHARE_CLEANUP failed, correct
+CLEANUP
+lock:   cookie [Pigs in space]: 78
+unlock: cookie [Pigs in space]: 79
+lock:   share  [Pigs in space]: 80
+unlock: share  [Pigs in space]: 81
 SHARE_CLEANUP
-lock:   share  [Pigs in space]: 72
-unlock: share  [Pigs in space]: 73
+lock:   share  [Pigs in space]: 82
+unlock: share  [Pigs in space]: 83
 GLOBAL_CLEANUP
 </stdout>
 <stderr>
index 4a3ec5aed555b69d5f534c3da3e441845ea22a6d..9bb4ff27edefeaf9e907d779c873e8fbc36e5d8e 100644 (file)
@@ -175,11 +175,13 @@ int test(char *URL)
 {
   int res;
   CURLSHcode scode = CURLSHE_OK;
+  CURLcode code = CURLE_OK;
   char *url = NULL;
   struct Tdata tdata;
   CURL *curl;
   CURLSH *share;
   struct curl_slist *headers = NULL;
+  struct curl_slist *cookies = NULL;
   int i;
   struct userdata user;
 
@@ -296,6 +298,54 @@ int test(char *URL)
   printf( "PERFORM\n" );
   curl_easy_perform( curl );
 
+  printf( "CLEANUP\n" );
+  curl_easy_cleanup( curl );
+
+  /* load cookies */
+  if ((curl = curl_easy_init()) == NULL) {
+    fprintf(stderr, "curl_easy_init() failed\n");
+    curl_share_cleanup(share);
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+  url = suburl( URL, i );
+  headers = sethost( NULL );
+  test_setopt( curl, CURLOPT_HTTPHEADER, headers );
+  test_setopt( curl, CURLOPT_URL,        url );
+  printf( "CURLOPT_SHARE\n" );
+  test_setopt( curl, CURLOPT_SHARE,      share );
+  printf( "CURLOPT_COOKIELIST ALL\n" );
+  test_setopt( curl, CURLOPT_COOKIELIST, "ALL" );
+  printf( "CURLOPT_COOKIEJAR\n" );
+  test_setopt( curl, CURLOPT_COOKIEFILE, JAR );
+  printf( "CURLOPT_COOKIELIST RELOAD\n" );
+  test_setopt( curl, CURLOPT_COOKIELIST, "RELOAD" );
+
+  code = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
+  if ( code != CURLE_OK )
+  {
+    fprintf(stderr, "curl_easy_getinfo() failed\n");
+    curl_share_cleanup(share);
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+  printf("loaded cookies:\n");
+  if ( !cookies )
+  {
+    fprintf(stderr, "  reloading cookies from '%s' failed\n", JAR);
+    curl_share_cleanup(share);
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+  printf("-----------------\n");
+  while ( cookies )
+  {
+    printf( "  %s\n", cookies->data );
+    cookies = cookies->next;
+  }
+  printf("-----------------\n");
+  curl_slist_free_all( cookies );
+
   /* try to free share, expect to fail because share is in use*/
   printf( "try SHARE_CLEANUP...\n" );
   scode = curl_share_cleanup( share );