Skip to content

Commit

Permalink
tool: Updated the warnf() function to use the GlobalConfig structure
Browse files Browse the repository at this point in the history
As the 'error' and 'mute' options are now part of the GlobalConfig,
rather than per Operation, updated the warnf() function to use this
structure rather than the OperationConfig.
  • Loading branch information
captain-caveman2k committed Feb 27, 2015
1 parent adf27bf commit c715fa0
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 77 deletions.
4 changes: 2 additions & 2 deletions src/tool_cb_dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -88,7 +88,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
output = config->trace_stream;

if(!output) {
warnf(operation, "Failed to create/open output");
warnf(config, "Failed to create/open output");
return 0;
}

Expand Down
5 changes: 3 additions & 2 deletions src/tool_cb_hdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -61,7 +61,8 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)

#ifdef DEBUGBUILD
if(size * nmemb > (size_t)CURL_MAX_HTTP_HEADER) {
warnf(heads->config, "Header data exceeds single call write limit!\n");
warnf(heads->config->global, "Header data exceeds single call write "
"limit!\n");
return failure;
}
#endif
Expand Down
16 changes: 8 additions & 8 deletions src/tool_cb_wrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -55,13 +55,14 @@ size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
#ifdef DEBUGBUILD
if(config->include_headers) {
if(sz * nmemb > (size_t)CURL_MAX_HTTP_HEADER) {
warnf(config, "Header data size exceeds single call write limit!\n");
warnf(config->global, "Header data size exceeds single call write "
"limit!\n");
return failure;
}
}
else {
if(sz * nmemb > (size_t)CURL_MAX_WRITE_SIZE) {
warnf(config, "Data size exceeds single call write limit!\n");
warnf(config->global, "Data size exceeds single call write limit!\n");
return failure;
}
}
Expand Down Expand Up @@ -90,7 +91,7 @@ size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
check_fails = TRUE;
}
if(check_fails) {
warnf(config, "Invalid output struct data for write callback\n");
warnf(config->global, "Invalid output struct data for write callback\n");
return failure;
}
}
Expand All @@ -100,7 +101,7 @@ size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
FILE *file;

if(!outs->filename || !*outs->filename) {
warnf(config, "Remote filename has no length!\n");
warnf(config->global, "Remote filename has no length!\n");
return failure;
}

Expand All @@ -109,7 +110,7 @@ size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
file = fopen(outs->filename, "rb");
if(file) {
fclose(file);
warnf(config, "Refusing to overwrite %s: %s\n", outs->filename,
warnf(config->global, "Refusing to overwrite %s: %s\n", outs->filename,
strerror(EEXIST));
return failure;
}
Expand All @@ -118,7 +119,7 @@ size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
/* open file for writing */
file = fopen(outs->filename, "wb");
if(!file) {
warnf(config, "Failed to create the file %s: %s\n", outs->filename,
warnf(config->global, "Failed to create the file %s: %s\n", outs->filename,
strerror(errno));
return failure;
}
Expand Down Expand Up @@ -149,4 +150,3 @@ size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)

return rc;
}

4 changes: 2 additions & 2 deletions src/tool_easysrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -182,7 +182,7 @@ void dumpeasysrc(struct GlobalConfig *config)
else
out = stdout;
if(!out)
warnf(config->current, "Failed to open %s to write libcurl code!\n", o);
warnf(config, "Failed to open %s to write libcurl code!\n", o);
else {
int i;
const char *c;
Expand Down
21 changes: 10 additions & 11 deletions src/tool_formparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -206,7 +206,7 @@ int formparse(struct OperationConfig *config,
/* verify that this is a fine type specifier */
if(2 != sscanf(type, "%127[^/]/%127[^;,\n]",
type_major, type_minor)) {
warnf(config, "Illegally formatted content-type field!\n");
warnf(config->global, "Illegally formatted content-type field!\n");
Curl_safefree(contents);
FreeMultiInfo(&multi_start, &multi_current);
return 2; /* illegal content-type syntax! */
Expand Down Expand Up @@ -246,7 +246,7 @@ int formparse(struct OperationConfig *config,
semicolon = (';' == *ptr) ? TRUE : FALSE;
if(*unknown) {
*word_end = '\0';
warnf(config, "skip unknown form field: %s\n", unknown);
warnf(config->global, "skip unknown form field: %s\n", unknown);
}
}
}
Expand All @@ -257,7 +257,7 @@ int formparse(struct OperationConfig *config,

if(*contp && !AddMultiFiles(contp, type, filename, &multi_start,
&multi_current)) {
warnf(config, "Error building form post!\n");
warnf(config->global, "Error building form post!\n");
Curl_safefree(contents);
FreeMultiInfo(&multi_start, &multi_current);
return 3;
Expand Down Expand Up @@ -291,7 +291,7 @@ int formparse(struct OperationConfig *config,
if(curl_formadd(httppost, last_post,
CURLFORM_COPYNAME, name,
CURLFORM_ARRAY, forms, CURLFORM_END) != 0) {
warnf(config, "curl_formadd failed!\n");
warnf(config->global, "curl_formadd failed!\n");
Curl_safefree(forms);
Curl_safefree(contents);
return 5;
Expand Down Expand Up @@ -323,16 +323,16 @@ int formparse(struct OperationConfig *config,

if(curl_formadd(httppost, last_post,
CURLFORM_ARRAY, info, CURLFORM_END ) != 0) {
warnf(config, "curl_formadd failed, possibly the file %s is bad!\n",
contp+1);
warnf(config->global, "curl_formadd failed, possibly the file %s is "
"bad!\n", contp + 1);
Curl_safefree(contents);
return 6;
}
}
else {
#ifdef CURL_DOES_CONVERSIONS
if(convert_to_network(contp, strlen(contp))) {
warnf(config, "curl_formadd failed!\n");
warnf(config->global, "curl_formadd failed!\n");
Curl_safefree(contents);
return 7;
}
Expand All @@ -343,7 +343,7 @@ int formparse(struct OperationConfig *config,
info[i].option = CURLFORM_END;
if(curl_formadd(httppost, last_post,
CURLFORM_ARRAY, info, CURLFORM_END) != 0) {
warnf(config, "curl_formadd failed!\n");
warnf(config->global, "curl_formadd failed!\n");
Curl_safefree(contents);
return 8;
}
Expand All @@ -352,10 +352,9 @@ int formparse(struct OperationConfig *config,

}
else {
warnf(config, "Illegally formatted input field!\n");
warnf(config->global, "Illegally formatted input field!\n");
return 1;
}
Curl_safefree(contents);
return 0;
}

38 changes: 19 additions & 19 deletions src/tool_getparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
case 'g': /* --trace */
GetStr(&global->trace_dump, nextarg);
if(global->tracetype && (global->tracetype != TRACE_BIN))
warnf(config, "--trace overrides an earlier trace/verbose option\n");
warnf(global, "--trace overrides an earlier trace/verbose option\n");
global->tracetype = TRACE_BIN;
break;
case 'G': /* --npn */
Expand All @@ -532,7 +532,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
case 'h': /* --trace-ascii */
GetStr(&global->trace_dump, nextarg);
if(global->tracetype && (global->tracetype != TRACE_ASCII))
warnf(config,
warnf(global,
"--trace-ascii overrides an earlier trace/verbose option\n");
global->tracetype = TRACE_ASCII;
break;
Expand Down Expand Up @@ -568,7 +568,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
/* for plain bytes, leave as-is */
break;
default:
warnf(config, "unsupported rate unit. Use G, M, K or B!\n");
warnf(global, "unsupported rate unit. Use G, M, K or B!\n");
return PARAM_BAD_USE;
}
config->recvpersecond = value;
Expand Down Expand Up @@ -678,7 +678,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
if(strcmp(nextarg, "-")) {
FILE *newfile = fopen(nextarg, "wt");
if(!newfile)
warnf(config, "Failed to open %s!\n", nextarg);
warnf(global, "Failed to open %s!\n", nextarg);
else {
if(global->errors_fopened)
fclose(global->errors);
Expand Down Expand Up @@ -830,7 +830,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
else {
config->localportrange -= config->localport;
if(config->localportrange < 1) {
warnf(config, "bad range input\n");
warnf(global, "bad range input\n");
return PARAM_BAD_USE;
}
}
Expand Down Expand Up @@ -862,7 +862,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
break;
case 'z': /* --libcurl */
#ifdef CURL_DISABLE_LIBCURL_OPTION
warnf(config,
warnf(global,
"--libcurl option was disabled at build-time!\n");
return PARAM_OPTION_UNKNOWN;
#else
Expand Down Expand Up @@ -950,7 +950,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
int mlmaj, mlmin, mlpatch;
metalink_get_version(&mlmaj, &mlmin, &mlpatch);
if((mlmaj*10000)+(mlmin*100)+mlpatch < CURL_REQ_LIBMETALINK_VERS) {
warnf(config,
warnf(global,
"--metalink option cannot be used because the version of "
"the linked libmetalink library is too old. "
"Required: %d.%d.%d, found %d.%d.%d\n",
Expand All @@ -963,7 +963,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
else
config->use_metalink = toggle;
#else
warnf(config, "--metalink option is ignored because the binary is "
warnf(global, "--metalink option is ignored because the binary is "
"built without the Metalink support.\n");
#endif
break;
Expand All @@ -975,7 +975,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
#ifdef CURLDEBUG
config->test_event_based = toggle;
#else
warnf(config, "--test-event is ignored unless a debug build!\n");
warnf(global, "--test-event is ignored unless a debug build!\n");
#endif
break;
case 'M': /* --unix-socket */
Expand Down Expand Up @@ -1127,7 +1127,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
else {
file = fopen(p, "rb");
if(!file)
warnf(config,
warnf(global,
"Couldn't read data from file \"%s\", this makes "
"an empty POST.\n", nextarg);
}
Expand Down Expand Up @@ -1193,7 +1193,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
else {
file = fopen(nextarg, "rb");
if(!file)
warnf(config, "Couldn't read data from file \"%s\", this makes "
warnf(global, "Couldn't read data from file \"%s\", this makes "
"an empty POST.\n", nextarg);
}

Expand Down Expand Up @@ -1441,7 +1441,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
break;
case 'J': /* --remote-header-name */
if(config->include_headers) {
warnf(config,
warnf(global,
"--include and --remote-header-name cannot be combined.\n");
return PARAM_BAD_USE;
}
Expand All @@ -1452,7 +1452,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
break;
case 'K': /* parse config file */
if(parseconfig(nextarg, global))
warnf(config, "error trying read config from the '%s' file\n",
warnf(global, "error trying read config from the '%s' file\n",
nextarg);
break;
case 'l':
Expand All @@ -1479,7 +1479,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
#ifdef USE_MANUAL
return PARAM_MANUAL_REQUESTED;
#else
warnf(config,
warnf(global,
"built-in manual was disabled at build-time!\n");
return PARAM_OPTION_UNKNOWN;
#endif
Expand Down Expand Up @@ -1598,7 +1598,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
char buffer[32];
curl_off_t off;
warnf(config,
warnf(global,
"A specified range MUST include at least one dash (-). "
"Appending one for you!\n");
off = curlx_strtoofft(nextarg, NULL, 10);
Expand All @@ -1614,7 +1614,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
tmp_range = nextarg;
while(*tmp_range != '\0') {
if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
warnf(config,"Invalid character is found in given range. "
warnf(global, "Invalid character is found in given range. "
"A specified range MUST have only digits in "
"\'start\'-\'stop\'. The server's response to this "
"request is uncertain.\n");
Expand Down Expand Up @@ -1703,7 +1703,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
if(!global->trace_dump)
return PARAM_NO_MEM;
if(global->tracetype && (global->tracetype != TRACE_PLAIN))
warnf(config,
warnf(global,
"-v, --verbose overrides an earlier trace/verbose option\n");
global->tracetype = TRACE_PLAIN;
}
Expand Down Expand Up @@ -1738,7 +1738,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
if(err)
return err;
if(!config->writeout)
warnf(config, "Failed to read %s", fname);
warnf(global, "Failed to read %s", fname);
}
else
GetStr(&config->writeout, nextarg);
Expand Down Expand Up @@ -1796,7 +1796,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
if(-1 == stat(nextarg, &statbuf)) {
/* failed, remove time condition */
config->timecond = CURL_TIMECOND_NONE;
warnf(config,
warnf(global,
"Illegal date format for -z, --timecond (and not "
"a file name). Disabling time condition. "
"See curl_getdate(3) for valid date syntax.\n");
Expand Down
6 changes: 4 additions & 2 deletions src/tool_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -72,6 +72,8 @@ int SetHTTPrequest(struct OperationConfig *config, HttpReq req, HttpReq *store)
*store = req;
return 0;
}
warnf(config, "You can only select one HTTP request!\n");

warnf(config->global, "You can only select one HTTP request!\n");

return 1;
}
Loading

0 comments on commit c715fa0

Please sign in to comment.