summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Gustafsson <daniel@yesql.se>2021-02-25 18:12:28 +0100
committerDaniel Gustafsson <daniel@yesql.se>2021-02-25 18:12:28 +0100
commit82c583dcf009f038a9ceccc695f942f24015f9ab (patch)
tree8bf04adb2ee16faa8406b5b3cabd516f6b223dc5 /src
parent1b2098c3c9580c431cc9c4b110249abfd94792ed (diff)
downloadcurl-82c583dcf009f038a9ceccc695f942f24015f9ab.tar.gz
cookies: Support multiple -b parameters
Previously only a single -b cookie parameter was supported with the last one winning. This adds support for supplying multiple -b params to have them serialized semicolon separated. Both cookiefiles and cookies can be entered multiple times. Closes #6649 Reviewed-by: Daniel Stenberg <daniel@haxx.se>
Diffstat (limited to 'src')
-rw-r--r--src/tool_cfgable.c4
-rw-r--r--src/tool_cfgable.h4
-rw-r--r--src/tool_getparam.c8
-rw-r--r--src/tool_operate.c33
4 files changed, 39 insertions, 10 deletions
diff --git a/src/tool_cfgable.c b/src/tool_cfgable.c
index ea186a7c3..c3f7cecb1 100644
--- a/src/tool_cfgable.c
+++ b/src/tool_cfgable.c
@@ -56,9 +56,9 @@ static void free_config_fields(struct OperationConfig *config)
Curl_safefree(config->useragent);
Curl_safefree(config->altsvc);
Curl_safefree(config->hsts);
- Curl_safefree(config->cookie);
+ curl_slist_free_all(config->cookies);
Curl_safefree(config->cookiejar);
- Curl_safefree(config->cookiefile);
+ curl_slist_free_all(config->cookiefiles);
Curl_safefree(config->postfields);
Curl_safefree(config->referer);
diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h
index bd84315f5..95c66d081 100644
--- a/src/tool_cfgable.h
+++ b/src/tool_cfgable.h
@@ -54,9 +54,9 @@ struct OperationConfig {
char *random_file;
char *egd_file;
char *useragent;
- char *cookie; /* single line with specified cookies */
+ struct curl_slist *cookies; /* cookies to serialize into a single line */
char *cookiejar; /* write to this file */
- char *cookiefile; /* read from this file */
+ struct curl_slist *cookiefiles; /* file(s) to load cookies from */
char *altsvc; /* alt-svc cache file name */
char *hsts; /* HSTS cache file name */
bool cookiesession; /* new session? */
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index 5b155cf00..f1393c373 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -1320,11 +1320,15 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
}
else if(strchr(nextarg, '=')) {
/* A cookie string must have a =-letter */
- GetStr(&config->cookie, nextarg);
+ err = add2list(&config->cookies, nextarg);
+ if(err)
+ return err;
break;
}
/* We have a cookie file to read from! */
- GetStr(&config->cookiefile, nextarg);
+ err = add2list(&config->cookiefiles, nextarg);
+ if(err)
+ return err;
}
break;
case 'B':
diff --git a/src/tool_operate.c b/src/tool_operate.c
index 2605a4cdf..e2b287269 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -82,6 +82,7 @@
#include "tool_help.h"
#include "tool_hugehelp.h"
#include "tool_progress.h"
+#include "dynbuf.h"
#include "memdebug.h" /* keep this as LAST include */
@@ -1765,11 +1766,35 @@ static CURLcode single_transfer(struct GlobalConfig *global,
my_setopt_slist(curl, CURLOPT_POSTQUOTE, config->postquote);
my_setopt_slist(curl, CURLOPT_PREQUOTE, config->prequote);
- if(config->cookie)
- my_setopt_str(curl, CURLOPT_COOKIE, config->cookie);
+ if(config->cookies) {
+ struct curlx_dynbuf cookies;
+ struct curl_slist *cl;
+ CURLcode ret;
- if(config->cookiefile)
- my_setopt_str(curl, CURLOPT_COOKIEFILE, config->cookiefile);
+ /* The maximum size needs to match MAX_NAME in cookie.h */
+ curlx_dyn_init(&cookies, 4096);
+ for(cl = config->cookies; cl; cl = cl->next) {
+ if(cl == config->cookies)
+ ret = curlx_dyn_addf(&cookies, "%s", cl->data);
+ else
+ ret = curlx_dyn_addf(&cookies, ";%s", cl->data);
+
+ if(ret) {
+ result = CURLE_OUT_OF_MEMORY;
+ break;
+ }
+ }
+
+ my_setopt_str(curl, CURLOPT_COOKIE, curlx_dyn_ptr(&cookies));
+ curlx_dyn_free(&cookies);
+ }
+
+ if(config->cookiefiles) {
+ struct curl_slist *cfl;
+
+ for(cfl = config->cookiefiles; cfl; cfl = cfl->next)
+ my_setopt_str(curl, CURLOPT_COOKIEFILE, cfl->data);
+ }
/* new in libcurl 7.9 */
if(config->cookiejar)