From: Daniel Stenberg Date: Thu, 13 Mar 2025 14:09:15 +0000 (+0100) Subject: tool_setopt: simplify tool_setopt X-Git-Tag: curl-8_13_0~145 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=212f9a97421c35efc29afae2c3c74973a22a7f95;p=thirdparty%2Fcurl.git tool_setopt: simplify tool_setopt Since this is only used for object and function pointers now. Closes #16709 --- diff --git a/src/tool_setopt.c b/src/tool_setopt.c index 3f841fcc1c..b2a479cc4e 100644 --- a/src/tool_setopt.c +++ b/src/tool_setopt.c @@ -645,18 +645,12 @@ nomem: return ret; } -/* generic setopt wrapper for all other options. - * Some type information is encoded in the tag value. */ +/* setopt wrapper for setting object and function pointer options */ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global, struct OperationConfig *config, const char *name, CURLoption tag, ...) { va_list arg; - const char *value = NULL; - bool remark = FALSE; - bool skip = FALSE; - bool escape = FALSE; - char *escaped = NULL; CURLcode ret = CURLE_OK; void *pval; @@ -668,55 +662,37 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global, /* we never set _BLOB options in the curl tool */ DEBUGASSERT(tag < CURLOPTTYPE_BLOB); - /* Value is some sort of object pointer */ + /* argument is an object or function pointer */ pval = va_arg(arg, void *); - /* function pointers are never printable */ - if(tag >= CURLOPTTYPE_FUNCTIONPOINT) { - if(pval) { - value = "function pointer"; - remark = TRUE; - } - else - skip = TRUE; - } - - else if(pval && str) { - value = (char *)pval; - escape = TRUE; - } - else if(pval) { - value = "object pointer"; - remark = TRUE; - } - else - skip = TRUE; - ret = curl_easy_setopt(curl, tag, pval); va_end(arg); - if(global->libcurl && !skip && !ret) { - /* we only use this for real if --libcurl was used */ + if(global->libcurl && pval && !ret) { + /* we only use this if --libcurl was used */ - if(remark) - REM3("%s was set to a%s %s", name, (*value == 'o' ? "n" : ""), value); + if(!str) { + /* function pointers are never printable */ + const char *remark = (tag >= CURLOPTTYPE_FUNCTIONPOINT) ? + "function" : "object"; + REM3("%s was set to a%s %s pointer", name, + (*remark == 'o' ? "n" : ""), remark); + } else { - if(escape) { - curl_off_t len = ZERO_TERMINATED; - if(tag == CURLOPT_POSTFIELDS) - len = curlx_dyn_len(&config->postdata); - escaped = c_escape(value, len); - NULL_CHECK(escaped); + curl_off_t len = ZERO_TERMINATED; + char *escaped; + if(tag == CURLOPT_POSTFIELDS) + len = curlx_dyn_len(&config->postdata); + escaped = c_escape(pval, len); + if(escaped) { CODE2("curl_easy_setopt(hnd, %s, \"%s\");", name, escaped); + free(escaped); } - else - CODE2("curl_easy_setopt(hnd, %s, %s);", name, value); } } nomem: - curlx_safefree(escaped); return ret; }