Skip to content

Commit

Permalink
tool: Moved --trace and --verbose to the global config
Browse files Browse the repository at this point in the history
  • Loading branch information
captain-caveman2k committed Feb 27, 2014
1 parent fd97c17 commit 4efa1d2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 29 deletions.
11 changes: 6 additions & 5 deletions src/tool_cb_dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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]);
Expand Down
5 changes: 0 additions & 5 deletions src/tool_cfgable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/tool_cfgable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 13 additions & 13 deletions src/tool_getparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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! */
Expand Down
10 changes: 10 additions & 0 deletions src/tool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/tool_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4efa1d2

Please sign in to comment.