mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 16:18:48 -05:00
tool: Moved --trace and --verbose to the global config
This commit is contained in:
parent
fd97c17bb7
commit
4efa1d29e2
@ -44,8 +44,9 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
|
||||
unsigned char *data, size_t size,
|
||||
void *userdata)
|
||||
{
|
||||
struct OperationConfig *config = userdata;
|
||||
FILE *output = config->errors;
|
||||
struct OperationConfig *operation = userdata;
|
||||
struct GlobalConfig *config = operation->global;
|
||||
FILE *output = operation->errors;
|
||||
const char *text;
|
||||
struct timeval tv;
|
||||
struct tm *now;
|
||||
@ -76,7 +77,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
|
||||
config->trace_stream = stdout;
|
||||
else if(curlx_strequal("%", config->trace_dump))
|
||||
/* Ok, this is somewhat hackish but we do it undocumented for now */
|
||||
config->trace_stream = config->errors; /* aka stderr */
|
||||
config->trace_stream = operation->errors; /* aka stderr */
|
||||
else {
|
||||
config->trace_stream = fopen(config->trace_dump, "w");
|
||||
config->trace_fopened = TRUE;
|
||||
@ -87,7 +88,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
|
||||
output = config->trace_stream;
|
||||
|
||||
if(!output) {
|
||||
warnf(config, "Failed to create/open output");
|
||||
warnf(operation, "Failed to create/open output");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -141,7 +142,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
|
||||
to stderr or stdout, we don't display the alert about the data not
|
||||
being shown as the data _is_ shown then just not via this
|
||||
function */
|
||||
if(!config->isatty ||
|
||||
if(!operation->isatty ||
|
||||
((output != stderr) && (output != stdout))) {
|
||||
if(!newl)
|
||||
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
|
||||
|
@ -111,14 +111,9 @@ static void free_config_fields(struct OperationConfig *config)
|
||||
|
||||
Curl_safefree(config->customrequest);
|
||||
Curl_safefree(config->krblevel);
|
||||
Curl_safefree(config->trace_dump);
|
||||
|
||||
Curl_safefree(config->xoauth2_bearer);
|
||||
|
||||
if(config->trace_fopened && config->trace_stream)
|
||||
fclose(config->trace_stream);
|
||||
config->trace_stream = NULL;
|
||||
|
||||
Curl_safefree(config->writeout);
|
||||
|
||||
if(config->errors_fopened && config->errors)
|
||||
|
@ -121,11 +121,6 @@ struct OperationConfig {
|
||||
bool crlf;
|
||||
char *customrequest;
|
||||
char *krblevel;
|
||||
char *trace_dump; /* file to dump the network trace to, or NULL */
|
||||
FILE *trace_stream;
|
||||
bool trace_fopened;
|
||||
trace tracetype;
|
||||
bool tracetime; /* include timestamp? */
|
||||
long httpversion;
|
||||
int progressmode; /* CURL_PROGRESS_BAR or CURL_PROGRESS_STATS */
|
||||
bool nobuffer;
|
||||
@ -225,6 +220,11 @@ struct GlobalConfig {
|
||||
0 => -s is used to NOT show errors
|
||||
1 => -S has been used to show errors */
|
||||
bool mute; /* don't show messages, --silent given */
|
||||
char *trace_dump; /* file to dump the network trace to */
|
||||
FILE *trace_stream;
|
||||
bool trace_fopened;
|
||||
trace tracetype;
|
||||
bool tracetime; /* include timestamp? */
|
||||
|
||||
struct OperationConfig *first;
|
||||
struct OperationConfig *current;
|
||||
|
@ -522,20 +522,20 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
|
||||
GetStr(&config->dns_servers, nextarg);
|
||||
break;
|
||||
case 'g': /* --trace */
|
||||
GetStr(&config->trace_dump, nextarg);
|
||||
if(config->tracetype && (config->tracetype != TRACE_BIN))
|
||||
GetStr(&global->trace_dump, nextarg);
|
||||
if(global->tracetype && (global->tracetype != TRACE_BIN))
|
||||
warnf(config, "--trace overrides an earlier trace/verbose option\n");
|
||||
config->tracetype = TRACE_BIN;
|
||||
global->tracetype = TRACE_BIN;
|
||||
break;
|
||||
case 'G': /* --npn */
|
||||
config->nonpn = (!toggle)?TRUE:FALSE;
|
||||
break;
|
||||
case 'h': /* --trace-ascii */
|
||||
GetStr(&config->trace_dump, nextarg);
|
||||
if(config->tracetype && (config->tracetype != TRACE_ASCII))
|
||||
GetStr(&global->trace_dump, nextarg);
|
||||
if(global->tracetype && (global->tracetype != TRACE_ASCII))
|
||||
warnf(config,
|
||||
"--trace-ascii overrides an earlier trace/verbose option\n");
|
||||
config->tracetype = TRACE_ASCII;
|
||||
global->tracetype = TRACE_ASCII;
|
||||
break;
|
||||
case 'H': /* --alpn */
|
||||
config->noalpn = (!toggle)?TRUE:FALSE;
|
||||
@ -809,7 +809,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
|
||||
config->proxyanyauth = toggle;
|
||||
break;
|
||||
case 'o': /* --trace-time */
|
||||
config->tracetime = toggle;
|
||||
global->tracetime = toggle;
|
||||
break;
|
||||
case 'p': /* --ignore-content-length */
|
||||
config->ignorecl = toggle;
|
||||
@ -1684,18 +1684,18 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
|
||||
case 'v':
|
||||
if(toggle) {
|
||||
/* the '%' thing here will cause the trace get sent to stderr */
|
||||
Curl_safefree(config->trace_dump);
|
||||
config->trace_dump = strdup("%");
|
||||
if(!config->trace_dump)
|
||||
Curl_safefree(global->trace_dump);
|
||||
global->trace_dump = strdup("%");
|
||||
if(!global->trace_dump)
|
||||
return PARAM_NO_MEM;
|
||||
if(config->tracetype && (config->tracetype != TRACE_PLAIN))
|
||||
if(global->tracetype && (global->tracetype != TRACE_PLAIN))
|
||||
warnf(config,
|
||||
"-v, --verbose overrides an earlier trace/verbose option\n");
|
||||
config->tracetype = TRACE_PLAIN;
|
||||
global->tracetype = TRACE_PLAIN;
|
||||
}
|
||||
else
|
||||
/* verbose is disabled here */
|
||||
config->tracetype = TRACE_NONE;
|
||||
global->tracetype = TRACE_NONE;
|
||||
break;
|
||||
case 'V':
|
||||
if(toggle) /* --no-version yields no output! */
|
||||
|
@ -170,6 +170,15 @@ static CURLcode main_init(struct GlobalConfig *config)
|
||||
return result;
|
||||
}
|
||||
|
||||
static void free_config_fields(struct GlobalConfig *config)
|
||||
{
|
||||
Curl_safefree(config->trace_dump);
|
||||
|
||||
if(config->trace_fopened && config->trace_stream)
|
||||
fclose(config->trace_stream);
|
||||
config->trace_stream = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the main global destructor for the app. Call this after
|
||||
* _all_ libcurl usage is done.
|
||||
@ -184,6 +193,7 @@ static void main_free(struct GlobalConfig *config)
|
||||
curl_global_cleanup();
|
||||
convert_cleanup();
|
||||
metalink_cleanup();
|
||||
free_config_fields(config);
|
||||
|
||||
/* Free the config structures */
|
||||
config_free(config->last);
|
||||
|
@ -1147,7 +1147,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
|
||||
/* disable it */
|
||||
my_setopt(curl, CURLOPT_FTP_USE_EPRT, 0L);
|
||||
|
||||
if(config->tracetype != TRACE_NONE) {
|
||||
if(global->tracetype != TRACE_NONE) {
|
||||
my_setopt(curl, CURLOPT_DEBUGFUNCTION, tool_debug_cb);
|
||||
my_setopt(curl, CURLOPT_DEBUGDATA, config);
|
||||
my_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
|
Loading…
Reference in New Issue
Block a user