← Commit list

0824bae8b0

Daniel Stenberg
Daniel Stenberg
2026-02-22
SUCCESS Duration: 345s

Subject

config2setopts: split into smaller functions

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

src/config2setopts.c+147 -120
@@ -178,10 +178,14 @@ static CURLcode url_proto_and_rewrite(char **url,
return result;
}
-static CURLcode ssh_setopts(struct OperationConfig *config, CURL *curl)
+static CURLcode ssh_setopts(struct OperationConfig *config, CURL *curl,
+ const char *use_proto)
{
CURLcode result;
+ if(use_proto != proto_scp && use_proto != proto_sftp)
+ return CURLE_OK;
+
/* SSH and SSL private key uses same command-line option */
MY_SETOPT_STR(curl, CURLOPT_SSH_PRIVATE_KEYFILE, config->key);
MY_SETOPT_STR(curl, CURLOPT_SSH_PUBLIC_KEYFILE, config->pubkey);
@@ -270,7 +274,7 @@ static long tlsversion(unsigned char mintls,
}
/* only called if libcurl supports TLS */
-static CURLcode ssl_setopts(struct OperationConfig *config, CURL *curl)
+static CURLcode ssl_ca_setopts(struct OperationConfig *config, CURL *curl)
{
CURLcode result = CURLE_OK;
@@ -322,6 +326,13 @@ static CURLcode ssl_setopts(struct OperationConfig *config, CURL *curl)
}
}
#endif
+ return result;
+}
+
+/* only called if libcurl supports TLS */
+static CURLcode ssl_setopts(struct OperationConfig *config, CURL *curl)
+{
+ CURLcode result = CURLE_OK;
if(config->crlfile)
MY_SETOPT_STR(curl, CURLOPT_CRLFILE, config->crlfile);
@@ -476,12 +487,60 @@ static CURLcode ssl_setopts(struct OperationConfig *config, CURL *curl)
return CURLE_OK;
}
-/* only called for HTTP transfers */
-static CURLcode http_setopts(struct OperationConfig *config, CURL *curl)
+static CURLcode cookie_setopts(struct OperationConfig *config, CURL *curl)
+{
+ CURLcode result = CURLE_OK;
+ if(config->cookies) {
+ struct dynbuf cookies;
+ struct curl_slist *cl;
+
+ /* The maximum size needs to match MAX_NAME in cookie.h */
+#define MAX_COOKIE_LINE 8200
+ curlx_dyn_init(&cookies, MAX_COOKIE_LINE);
+ for(cl = config->cookies; cl; cl = cl->next) {
+ if(cl == config->cookies)
+ result = curlx_dyn_add(&cookies, cl->data);
+ else
+ result = curlx_dyn_addf(&cookies, ";%s%s",
+ ISBLANK(cl->data[0]) ? "" : " ", cl->data);
+ if(result) {
+ warnf("skipped provided cookie, the cookie header "
+ "would go over %u bytes", MAX_COOKIE_LINE);
+ return result;
+ }
+ }
+
+ result = my_setopt_str(curl, CURLOPT_COOKIE, curlx_dyn_ptr(&cookies));
+ curlx_dyn_free(&cookies);
+ if(result)
+ return result;
+ }
+
+ if(config->cookiefiles) {
+ struct curl_slist *cfl;
+
+ for(cfl = config->cookiefiles; cfl; cfl = cfl->next)
+ MY_SETOPT_STR(curl, CURLOPT_COOKIEFILE, cfl->data);
+ }
+
+ if(config->cookiejar)
+ MY_SETOPT_STR(curl, CURLOPT_COOKIEJAR, config->cookiejar);
+
+ my_setopt_long(curl, CURLOPT_COOKIESESSION, config->cookiesession);
+
+ return result;
+}
+
+/* only for HTTP transfers */
+static CURLcode http_setopts(struct OperationConfig *config, CURL *curl,
+ const char *use_proto)
{
CURLcode result = CURLE_OK;
long postRedir = 0;
+ if(use_proto != proto_http && use_proto != proto_https)
+ return CURLE_OK;
+
my_setopt_long(curl, CURLOPT_FOLLOWLOCATION, config->followlocation);
my_setopt_long(curl, CURLOPT_UNRESTRICTED_AUTH, config->unrestricted_auth);
#ifndef CURL_DISABLE_AWS
@@ -524,50 +583,15 @@ static CURLcode http_setopts(struct OperationConfig *config, CURL *curl)
my_setopt_long(curl, CURLOPT_EXPECT_100_TIMEOUT_MS,
config->expect100timeout_ms);
- return result;
-}
-
-static CURLcode cookie_setopts(struct OperationConfig *config, CURL *curl)
-{
- CURLcode result = CURLE_OK;
- if(config->cookies) {
- struct dynbuf cookies;
- struct curl_slist *cl;
-
- /* The maximum size needs to match MAX_NAME in cookie.h */
-#define MAX_COOKIE_LINE 8200
- curlx_dyn_init(&cookies, MAX_COOKIE_LINE);
- for(cl = config->cookies; cl; cl = cl->next) {
- if(cl == config->cookies)
- result = curlx_dyn_add(&cookies, cl->data);
- else
- result = curlx_dyn_addf(&cookies, ";%s%s",
- ISBLANK(cl->data[0]) ? "" : " ", cl->data);
- if(result) {
- warnf("skipped provided cookie, the cookie header "
- "would go over %u bytes", MAX_COOKIE_LINE);
- return result;
- }
- }
-
- result = my_setopt_str(curl, CURLOPT_COOKIE, curlx_dyn_ptr(&cookies));
- curlx_dyn_free(&cookies);
- if(result)
- return result;
- }
-
- if(config->cookiefiles) {
- struct curl_slist *cfl;
-
- for(cfl = config->cookiefiles; cfl; cfl = cfl->next)
- MY_SETOPT_STR(curl, CURLOPT_COOKIEFILE, cfl->data);
- }
-
- if(config->cookiejar)
- MY_SETOPT_STR(curl, CURLOPT_COOKIEJAR, config->cookiejar);
-
- my_setopt_long(curl, CURLOPT_COOKIESESSION, config->cookiesession);
-
+ if(!result)
+ result = cookie_setopts(config, curl);
+ if(result)
+ return result;
+ /* Enable header separation when using a proxy with HTTPS or proxytunnel
+ * to prevent --header content from leaking into CONNECT requests */
+ if((config->proxy || config->proxyheaders) &&
+ (use_proto == proto_https || config->proxytunnel))
+ my_setopt_long(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
return result;
}
@@ -596,9 +620,14 @@ static void tcp_setopts(struct OperationConfig *config, CURL *curl)
my_setopt_long(curl, CURLOPT_TCP_KEEPALIVE, 0);
}
-static CURLcode ftp_setopts(struct OperationConfig *config, CURL *curl)
+static CURLcode ftp_setopts(struct OperationConfig *config, CURL *curl,
+ const char *use_proto)
{
CURLcode result;
+
+ if(use_proto != proto_ftp && use_proto != proto_ftps)
+ return CURLE_OK;
+
MY_SETOPT_STR(curl, CURLOPT_FTPPORT, config->ftpport);
if(config->disable_epsv)
@@ -743,6 +772,61 @@ static CURLcode tls_srp_setopts(struct OperationConfig *config, CURL *curl)
return result;
}
+static CURLcode setopt_post(struct OperationConfig *config, CURL *curl)
+{
+ CURLcode result = CURLE_OK;
+ switch(config->httpreq) {
+ case TOOL_HTTPREQ_SIMPLEPOST:
+ if(config->resume_from) {
+ errorf("cannot mix --continue-at with --data");
+ result = CURLE_FAILED_INIT;
+ }
+ else {
+ MY_SETOPT_STR(curl, CURLOPT_POSTFIELDS,
+ curlx_dyn_ptr(&config->postdata));
+ my_setopt_offt(curl, CURLOPT_POSTFIELDSIZE_LARGE,
+ curlx_dyn_len(&config->postdata));
+ }
+ break;
+ case TOOL_HTTPREQ_MIMEPOST:
+ /* free previous remainders */
+ curl_mime_free(config->mimepost);
+ config->mimepost = NULL;
+ if(config->resume_from) {
+ errorf("cannot mix --continue-at with --form");
+ result = CURLE_FAILED_INIT;
+ }
+ else {
+ result = tool2curlmime(curl, config->mimeroot, &config->mimepost);
+ if(!result)
+ result = my_setopt_mimepost(curl, CURLOPT_MIMEPOST, config->mimepost);
+ }
+ break;
+ default:
+ break;
+ }
+ return result;
+}
+
+static void buffersize(struct OperationConfig *config, CURL *curl)
+{
+#ifdef DEBUGBUILD
+ char *env = getenv("CURL_BUFFERSIZE");
+ if(env) {
+ curl_off_t num;
+ const char *p = env;
+ if(!curlx_str_number(&p, &num, LONG_MAX))
+ my_setopt_long(curl, CURLOPT_BUFFERSIZE, (long)num);
+ return;
+ }
+#endif
+ if(config->recvpersecond && (config->recvpersecond < BUFFER_SIZE))
+ /* use a smaller sized buffer for better sleeps */
+ my_setopt_long(curl, CURLOPT_BUFFERSIZE, (long)config->recvpersecond);
+ else
+ my_setopt_long(curl, CURLOPT_BUFFERSIZE, BUFFER_SIZE);
+}
+
CURLcode config2setopts(struct OperationConfig *config,
struct per_transfer *per,
CURL *curl,
@@ -770,23 +854,7 @@ CURLcode config2setopts(struct OperationConfig *config,
gen_trace_setopts(config, curl);
- {
-#ifdef DEBUGBUILD
- char *env = getenv("CURL_BUFFERSIZE");
- if(env) {
- curl_off_t num;
- const char *p = env;
- if(!curlx_str_number(&p, &num, LONG_MAX))
- my_setopt_long(curl, CURLOPT_BUFFERSIZE, (long)num);
- }
- else
-#endif
- if(config->recvpersecond && (config->recvpersecond < BUFFER_SIZE))
- /* use a smaller sized buffer for better sleeps */
- my_setopt_long(curl, CURLOPT_BUFFERSIZE, (long)config->recvpersecond);
- else
- my_setopt_long(curl, CURLOPT_BUFFERSIZE, BUFFER_SIZE);
- }
+ buffersize(config, curl);
MY_SETOPT_STR(curl, CURLOPT_URL, per->url);
my_setopt_long(curl, CURLOPT_NOPROGRESS,
@@ -821,36 +889,7 @@ CURLcode config2setopts(struct OperationConfig *config,
my_setopt_ptr(curl, CURLOPT_ERRORBUFFER, per->errorbuffer);
my_setopt_long(curl, CURLOPT_TIMEOUT_MS, config->timeout_ms);
- switch(config->httpreq) {
- case TOOL_HTTPREQ_SIMPLEPOST:
- if(config->resume_from) {
- errorf("cannot mix --continue-at with --data");
- result = CURLE_FAILED_INIT;
- }
- else {
- MY_SETOPT_STR(curl, CURLOPT_POSTFIELDS,
- curlx_dyn_ptr(&config->postdata));
- my_setopt_offt(curl, CURLOPT_POSTFIELDSIZE_LARGE,
- curlx_dyn_len(&config->postdata));
- }
- break;
- case TOOL_HTTPREQ_MIMEPOST:
- /* free previous remainders */
- curl_mime_free(config->mimepost);
- config->mimepost = NULL;
- if(config->resume_from) {
- errorf("cannot mix --continue-at with --form");
- result = CURLE_FAILED_INIT;
- }
- else {
- result = tool2curlmime(curl, config->mimeroot, &config->mimepost);
- if(!result)
- result = my_setopt_mimepost(curl, CURLOPT_MIMEPOST, config->mimepost);
- }
- break;
- default:
- break;
- }
+ result = setopt_post(config, curl);
if(result)
return result;
@@ -868,24 +907,11 @@ CURLcode config2setopts(struct OperationConfig *config,
config->useragent : CURL_NAME "/" CURL_VERSION);
}
- if(use_proto == proto_http || use_proto == proto_https) {
- result = http_setopts(config, curl);
- if(!result)
- result = cookie_setopts(config, curl);
- if(result)
- return result;
- /* Enable header separation when using a proxy with HTTPS or proxytunnel
- * to prevent --header content from leaking into CONNECT requests */
- if((config->proxy || config->proxyheaders) &&
- (use_proto == proto_https || config->proxytunnel))
- my_setopt_long(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
- }
-
- if(use_proto == proto_ftp || use_proto == proto_ftps) {
- result = ftp_setopts(config, curl);
- if(result)
- return result;
- }
+ result = http_setopts(config, curl, use_proto);
+ if(!result)
+ result = ftp_setopts(config, curl, use_proto);
+ if(result)
+ return result;
my_setopt_long(curl, CURLOPT_LOW_SPEED_LIMIT, config->low_speed_limit);
my_setopt_long(curl, CURLOPT_LOW_SPEED_TIME, config->low_speed_time);
@@ -900,13 +926,14 @@ CURLcode config2setopts(struct OperationConfig *config,
MY_SETOPT_STR(curl, CURLOPT_KEYPASSWD, config->key_passwd);
MY_SETOPT_STR(curl, CURLOPT_PROXY_KEYPASSWD, config->proxy_key_passwd);
- if(use_proto == proto_scp || use_proto == proto_sftp) {
- result = ssh_setopts(config, curl);
- if(setopt_bad(result))
- return result;
- }
+ result = ssh_setopts(config, curl, use_proto);
+ if(setopt_bad(result))
+ return result;
+
if(feature_ssl) {
- result = ssl_setopts(config, curl);
+ result = ssl_ca_setopts(config, curl);
+ if(!result)
+ result = ssl_setopts(config, curl);
if(setopt_bad(result))
return result;
}