trace: make tracing available in non-debug builds

Add --trace-config to curl

Add curl_global_trace() to libcurl

Closes #11421
This commit is contained in:
Stefan Eissing 2023-08-03 17:32:25 +02:00 committed by Daniel Stenberg
parent 0f49b5bacb
commit e12b39e133
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
46 changed files with 1166 additions and 790 deletions

View file

@ -209,6 +209,7 @@ static const struct LongShort aliases[]= {
{"$~", "happy-eyeballs-timeout-ms", ARG_STRING},
{"$!", "retry-all-errors", ARG_BOOL},
{"$%", "trace-ids", ARG_BOOL},
{"$&", "trace-config", ARG_STRING},
{"0", "http1.0", ARG_NONE},
{"01", "http1.1", ARG_NONE},
{"02", "http2", ARG_NONE},
@ -681,6 +682,61 @@ static void sethttpver(struct GlobalConfig *global,
config->httpversion = httpversion;
}
static CURLcode set_trace_config(struct GlobalConfig *global,
const char *config)
{
CURLcode result = CURLE_OK;
char *token, *tmp, *name;
bool toggle;
tmp = strdup(config);
if(!tmp)
return CURLE_OUT_OF_MEMORY;
/* Allow strtok() here since this isn't used threaded */
/* !checksrc! disable BANNEDFUNC 2 */
token = strtok(tmp, ", ");
while(token) {
switch(*token) {
case '-':
toggle = FALSE;
name = token + 1;
break;
case '+':
toggle = TRUE;
name = token + 1;
break;
default:
toggle = TRUE;
name = token;
break;
}
if(strcasecompare(name, "all")) {
global->traceids = toggle;
global->tracetime = toggle;
result = curl_global_trace(token);
if(result)
goto out;
}
else if(strcasecompare(name, "ids")) {
global->traceids = toggle;
}
else if(strcasecompare(name, "time")) {
global->tracetime = toggle;
}
else {
result = curl_global_trace(token);
if(result)
goto out;
}
token = strtok(NULL, ", ");
}
out:
free(tmp);
return result;
}
ParameterError getparameter(const char *flag, /* f or -long-flag */
char *nextarg, /* NULL if unset */
argv_item_t cleararg,
@ -1463,6 +1519,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
case '%': /* --trace-ids */
global->traceids = toggle;
break;
case '&': /* --trace-config */
if(set_trace_config(global, nextarg)) {
err = PARAM_NO_MEM;
}
break;
}
break;
case '#':

View file

@ -759,6 +759,9 @@ const struct helptxt helptext[] = {
{" --trace-ascii <file>",
"Like --trace, but without hex output",
CURLHELP_VERBOSE},
{" --trace-config",
"Configure which details to log in trace/verbose output",
CURLHELP_VERBOSE},
{" --trace-ids",
"Add transfer and connection identifiers to trace/verbose output",
CURLHELP_VERBOSE},