aboutsummaryrefslogtreecommitdiff
path: root/src/tool_setopt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tool_setopt.c')
-rw-r--r--src/tool_setopt.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/tool_setopt.c b/src/tool_setopt.c
index 0b6207be4..9aefc21d5 100644
--- a/src/tool_setopt.c
+++ b/src/tool_setopt.c
@@ -51,7 +51,7 @@ const NameValue setopt_nv_CURLPROXY[] = {
NVEND,
};
-const NameValue setopt_nv_CURLAUTH[] = {
+const NameValueUnsigned setopt_nv_CURLAUTH[] = {
NV(CURLAUTH_ANY), /* combination */
NV(CURLAUTH_ANYSAFE), /* combination */
NV(CURLAUTH_BASIC),
@@ -234,7 +234,7 @@ CURLcode tool_setopt_enum(CURL *curl, struct Configurable *config,
return ret;
}
-/* setopt wrapper for bit mask */
+/* setopt wrapper for flags */
CURLcode tool_setopt_flags(CURL *curl, struct Configurable *config,
const char *name, CURLoption tag,
const NameValue *nvlist, long lval)
@@ -276,6 +276,49 @@ CURLcode tool_setopt_flags(CURL *curl, struct Configurable *config,
return ret;
}
+/* setopt wrapper for bitmasks */
+CURLcode tool_setopt_bitmask(CURL *curl, struct Configurable *config,
+ const char *name, CURLoption tag,
+ const NameValueUnsigned *nvlist,
+ long lval)
+{
+ CURLcode ret = CURLE_OK;
+ bool skip = FALSE;
+
+ ret = curl_easy_setopt(curl, tag, lval);
+ if(!lval)
+ skip = TRUE;
+
+ if(config->libcurl && !skip && !ret) {
+ /* we only use this for real if --libcurl was used */
+ char preamble[80];
+ unsigned long rest = (unsigned long)lval;
+ const NameValueUnsigned *nv = NULL;
+ snprintf(preamble, sizeof(preamble),
+ "curl_easy_setopt(hnd, %s, ", name);
+ for(nv=nvlist; nv->name; nv++) {
+ if((nv->value & ~ rest) == 0) {
+ /* all value flags contained in rest */
+ rest &= ~ nv->value; /* remove bits handled here */
+ CODE3("%s(long)%s%s",
+ preamble, nv->name, rest ? " |" : ");");
+ if(!rest)
+ break; /* handled them all */
+ /* replace with all spaces for continuation line */
+ sprintf(preamble, "%*s", strlen(preamble), "");
+ }
+ }
+ /* If any bits have no definition, output an explicit value.
+ * This could happen if new bits are defined and used
+ * but the NameValue list is not updated. */
+ if(rest)
+ CODE2("%s%luUL);", preamble, rest);
+ }
+
+ nomem:
+ return ret;
+}
+
/* setopt wrapper for CURLOPT_HTTPPOST */
CURLcode tool_setopt_httppost(CURL *curl, struct Configurable *config,
const char *name, CURLoption tag,