1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-23 00:28:48 -05:00

tool: Moved --trace and --verbose to the global config

This commit is contained in:
Steve Holme 2014-02-27 20:51:49 +00:00
parent fd97c17bb7
commit 4efa1d29e2
6 changed files with 35 additions and 29 deletions

View File

@ -44,8 +44,9 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
unsigned char *data, size_t size, unsigned char *data, size_t size,
void *userdata) void *userdata)
{ {
struct OperationConfig *config = userdata; struct OperationConfig *operation = userdata;
FILE *output = config->errors; struct GlobalConfig *config = operation->global;
FILE *output = operation->errors;
const char *text; const char *text;
struct timeval tv; struct timeval tv;
struct tm *now; struct tm *now;
@ -76,7 +77,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
config->trace_stream = stdout; config->trace_stream = stdout;
else if(curlx_strequal("%", config->trace_dump)) else if(curlx_strequal("%", config->trace_dump))
/* Ok, this is somewhat hackish but we do it undocumented for now */ /* 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 { else {
config->trace_stream = fopen(config->trace_dump, "w"); config->trace_stream = fopen(config->trace_dump, "w");
config->trace_fopened = TRUE; config->trace_fopened = TRUE;
@ -87,7 +88,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
output = config->trace_stream; output = config->trace_stream;
if(!output) { if(!output) {
warnf(config, "Failed to create/open output"); warnf(operation, "Failed to create/open output");
return 0; 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 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 being shown as the data _is_ shown then just not via this
function */ function */
if(!config->isatty || if(!operation->isatty ||
((output != stderr) && (output != stdout))) { ((output != stderr) && (output != stdout))) {
if(!newl) if(!newl)
fprintf(output, "%s%s ", timebuf, s_infotype[type]); fprintf(output, "%s%s ", timebuf, s_infotype[type]);

View File

@ -111,14 +111,9 @@ static void free_config_fields(struct OperationConfig *config)
Curl_safefree(config->customrequest); Curl_safefree(config->customrequest);
Curl_safefree(config->krblevel); Curl_safefree(config->krblevel);
Curl_safefree(config->trace_dump);
Curl_safefree(config->xoauth2_bearer); Curl_safefree(config->xoauth2_bearer);
if(config->trace_fopened && config->trace_stream)
fclose(config->trace_stream);
config->trace_stream = NULL;
Curl_safefree(config->writeout); Curl_safefree(config->writeout);
if(config->errors_fopened && config->errors) if(config->errors_fopened && config->errors)

View File

@ -121,11 +121,6 @@ struct OperationConfig {
bool crlf; bool crlf;
char *customrequest; char *customrequest;
char *krblevel; 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; long httpversion;
int progressmode; /* CURL_PROGRESS_BAR or CURL_PROGRESS_STATS */ int progressmode; /* CURL_PROGRESS_BAR or CURL_PROGRESS_STATS */
bool nobuffer; bool nobuffer;
@ -225,6 +220,11 @@ struct GlobalConfig {
0 => -s is used to NOT show errors 0 => -s is used to NOT show errors
1 => -S has been used to show errors */ 1 => -S has been used to show errors */
bool mute; /* don't show messages, --silent given */ 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 *first;
struct OperationConfig *current; struct OperationConfig *current;

View File

@ -522,20 +522,20 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
GetStr(&config->dns_servers, nextarg); GetStr(&config->dns_servers, nextarg);
break; break;
case 'g': /* --trace */ case 'g': /* --trace */
GetStr(&config->trace_dump, nextarg); GetStr(&global->trace_dump, nextarg);
if(config->tracetype && (config->tracetype != TRACE_BIN)) if(global->tracetype && (global->tracetype != TRACE_BIN))
warnf(config, "--trace overrides an earlier trace/verbose option\n"); warnf(config, "--trace overrides an earlier trace/verbose option\n");
config->tracetype = TRACE_BIN; global->tracetype = TRACE_BIN;
break; break;
case 'G': /* --npn */ case 'G': /* --npn */
config->nonpn = (!toggle)?TRUE:FALSE; config->nonpn = (!toggle)?TRUE:FALSE;
break; break;
case 'h': /* --trace-ascii */ case 'h': /* --trace-ascii */
GetStr(&config->trace_dump, nextarg); GetStr(&global->trace_dump, nextarg);
if(config->tracetype && (config->tracetype != TRACE_ASCII)) if(global->tracetype && (global->tracetype != TRACE_ASCII))
warnf(config, warnf(config,
"--trace-ascii overrides an earlier trace/verbose option\n"); "--trace-ascii overrides an earlier trace/verbose option\n");
config->tracetype = TRACE_ASCII; global->tracetype = TRACE_ASCII;
break; break;
case 'H': /* --alpn */ case 'H': /* --alpn */
config->noalpn = (!toggle)?TRUE:FALSE; config->noalpn = (!toggle)?TRUE:FALSE;
@ -809,7 +809,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
config->proxyanyauth = toggle; config->proxyanyauth = toggle;
break; break;
case 'o': /* --trace-time */ case 'o': /* --trace-time */
config->tracetime = toggle; global->tracetime = toggle;
break; break;
case 'p': /* --ignore-content-length */ case 'p': /* --ignore-content-length */
config->ignorecl = toggle; config->ignorecl = toggle;
@ -1684,18 +1684,18 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
case 'v': case 'v':
if(toggle) { if(toggle) {
/* the '%' thing here will cause the trace get sent to stderr */ /* the '%' thing here will cause the trace get sent to stderr */
Curl_safefree(config->trace_dump); Curl_safefree(global->trace_dump);
config->trace_dump = strdup("%"); global->trace_dump = strdup("%");
if(!config->trace_dump) if(!global->trace_dump)
return PARAM_NO_MEM; return PARAM_NO_MEM;
if(config->tracetype && (config->tracetype != TRACE_PLAIN)) if(global->tracetype && (global->tracetype != TRACE_PLAIN))
warnf(config, warnf(config,
"-v, --verbose overrides an earlier trace/verbose option\n"); "-v, --verbose overrides an earlier trace/verbose option\n");
config->tracetype = TRACE_PLAIN; global->tracetype = TRACE_PLAIN;
} }
else else
/* verbose is disabled here */ /* verbose is disabled here */
config->tracetype = TRACE_NONE; global->tracetype = TRACE_NONE;
break; break;
case 'V': case 'V':
if(toggle) /* --no-version yields no output! */ if(toggle) /* --no-version yields no output! */

View File

@ -170,6 +170,15 @@ static CURLcode main_init(struct GlobalConfig *config)
return result; 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 * This is the main global destructor for the app. Call this after
* _all_ libcurl usage is done. * _all_ libcurl usage is done.
@ -184,6 +193,7 @@ static void main_free(struct GlobalConfig *config)
curl_global_cleanup(); curl_global_cleanup();
convert_cleanup(); convert_cleanup();
metalink_cleanup(); metalink_cleanup();
free_config_fields(config);
/* Free the config structures */ /* Free the config structures */
config_free(config->last); config_free(config->last);

View File

@ -1147,7 +1147,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
/* disable it */ /* disable it */
my_setopt(curl, CURLOPT_FTP_USE_EPRT, 0L); 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_DEBUGFUNCTION, tool_debug_cb);
my_setopt(curl, CURLOPT_DEBUGDATA, config); my_setopt(curl, CURLOPT_DEBUGDATA, config);
my_setopt(curl, CURLOPT_VERBOSE, 1L); my_setopt(curl, CURLOPT_VERBOSE, 1L);