CURLOPT_COOKIELIST: Added "RELOAD" command

This commit is contained in:
Yousuke Kimoto 2014-09-25 16:25:52 +02:00 committed by Daniel Stenberg
parent 9ee8efc63b
commit b10a838a7a
4 changed files with 93 additions and 8 deletions

View File

@ -46,6 +46,10 @@ erases all session cookies held in memory
.IP FLUSH .IP FLUSH
writes all known cookies to the file specified by \fICURLOPT_COOKIEJAR(3)\fP 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 .SH DEFAULT
NULL NULL
.SH PROTOCOLS .SH PROTOCOLS
@ -58,6 +62,8 @@ ALL was added in 7.14.1
SESS was added in 7.15.4 SESS was added in 7.15.4
FLUSH was added in 7.17.1 FLUSH was added in 7.17.1
RELOAD was added in 7.39.0
.SH RETURN VALUE .SH RETURN VALUE
Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
CURLE_OUT_OF_MEMORY if there was insufficient heap space. CURLE_OUT_OF_MEMORY if there was insufficient heap space.

View File

@ -1191,6 +1191,11 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
/* flush cookies to file, takes care of the locking */ /* flush cookies to file, takes care of the locking */
Curl_flush_cookies(data, 0); Curl_flush_cookies(data, 0);
} }
else if(Curl_raw_equal(argptr, "RELOAD")) {
/* reload cookies from file */
Curl_cookie_loadfiles(data);
break;
}
else { else {
if(!data->cookies) if(!data->cookies)
/* if cookie engine was not running, activate it */ /* if cookie engine was not running, activate it */

View File

@ -169,18 +169,42 @@ unlock: cookie [Pigs in space]: 63
run 3: overwrite cookie 1 and 4 run 3: overwrite cookie 1 and 4
lock: dns [Pigs in space]: 64 lock: dns [Pigs in space]: 64
unlock: dns [Pigs in space]: 65 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 CLEANUP
lock: cookie [Pigs in space]: 68 lock: cookie [Pigs in space]: 66
unlock: cookie [Pigs in space]: 69 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 lock: share [Pigs in space]: 70
unlock: share [Pigs in space]: 71 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 SHARE_CLEANUP
lock: share [Pigs in space]: 72 lock: share [Pigs in space]: 82
unlock: share [Pigs in space]: 73 unlock: share [Pigs in space]: 83
GLOBAL_CLEANUP GLOBAL_CLEANUP
</stdout> </stdout>
<stderr> <stderr>

View File

@ -175,11 +175,13 @@ int test(char *URL)
{ {
int res; int res;
CURLSHcode scode = CURLSHE_OK; CURLSHcode scode = CURLSHE_OK;
CURLcode code = CURLE_OK;
char *url = NULL; char *url = NULL;
struct Tdata tdata; struct Tdata tdata;
CURL *curl; CURL *curl;
CURLSH *share; CURLSH *share;
struct curl_slist *headers = NULL; struct curl_slist *headers = NULL;
struct curl_slist *cookies = NULL;
int i; int i;
struct userdata user; struct userdata user;
@ -296,6 +298,54 @@ int test(char *URL)
printf( "PERFORM\n" ); printf( "PERFORM\n" );
curl_easy_perform( curl ); 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*/ /* try to free share, expect to fail because share is in use*/
printf( "try SHARE_CLEANUP...\n" ); printf( "try SHARE_CLEANUP...\n" );
scode = curl_share_cleanup( share ); scode = curl_share_cleanup( share );