From: Daniel Stenberg Date: Mon, 10 Jun 2024 11:57:01 +0000 (+0200) Subject: tool_writeout: get certinfo only when needing it X-Git-Tag: curl-8_9_0~272 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0a3c78f6b657f1ef041e0a1aa9977d380bcca4d8;p=thirdparty%2Fcurl.git tool_writeout: get certinfo only when needing it Removes a fairly expensive libcurl call when not necessary Closes #13914 --- diff --git a/src/tool_writeout.c b/src/tool_writeout.c index 9ef6946755..d30a2b8412 100644 --- a/src/tool_writeout.c +++ b/src/tool_writeout.c @@ -268,6 +268,15 @@ static int urlpart(struct per_transfer *per, writeoutid vid, return rc; } +static void certinfo(struct per_transfer *per) +{ + if(!per->certinfo) { + struct curl_certinfo *certinfo; + CURLcode res = curl_easy_getinfo(per->curl, CURLINFO_CERTINFO, &certinfo); + per->certinfo = (!res && certinfo) ? certinfo : NULL; + } +} + static int writeString(FILE *stream, const struct writeoutvar *wovar, struct per_transfer *per, CURLcode per_result, bool use_json) @@ -303,6 +312,7 @@ static int writeString(FILE *stream, const struct writeoutvar *wovar, else { switch(wovar->id) { case VAR_CERT: + certinfo(per); if(per->certinfo) { int i; bool error = FALSE; @@ -434,6 +444,7 @@ static int writeLong(FILE *stream, const struct writeoutvar *wovar, else { switch(wovar->id) { case VAR_NUM_CERTS: + certinfo(per); longinfo = per->certinfo ? per->certinfo->num_of_certs : 0; valid = true; break; @@ -526,17 +537,12 @@ void ourWriteOut(struct OperationConfig *config, struct per_transfer *per, const char *writeinfo = config->writeout; const char *ptr = writeinfo; bool done = FALSE; - struct curl_certinfo *certinfo; - CURLcode res = curl_easy_getinfo(per->curl, CURLINFO_CERTINFO, &certinfo); bool fclose_stream = FALSE; struct dynbuf name; if(!writeinfo) return; - if(!res && certinfo) - per->certinfo = certinfo; - curlx_dyn_init(&name, MAX_WRITEOUT_NAME_LENGTH); while(ptr && *ptr && !done) { if('%' == *ptr && ptr[1]) {