Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embryo for tracing options from config files #13295

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/tool_getparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -2376,10 +2376,8 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
config->doh_insecure_ok = toggle;
break;
case C_CONFIG: /* --config */
if(parseconfig(nextarg, global)) {
errorf(global, "cannot read config from '%s'", nextarg);
if(parseconfig(nextarg, global))
err = PARAM_READ_ERROR;
}
break;
case C_LIST_ONLY: /* --list-only */
config->dirlistonly = toggle; /* only list the names of the FTP dir */
Expand Down
12 changes: 12 additions & 0 deletions src/tool_msgs.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ void notef(struct GlobalConfig *config, const char *fmt, ...)
va_end(ap);
}

/*
* Generic prefixed message.
*/
void msgf(struct GlobalConfig *config, const char *prefix,
const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
voutf(config, prefix, fmt, ap);
va_end(ap);
}

/*
* Emit warning formatted message on configured 'errors' stream unless
* mute (--silent) was selected.
Expand Down
3 changes: 3 additions & 0 deletions src/tool_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ void helpf(FILE *errors, const char *fmt, ...)
CURL_PRINTF(2, 3);
void errorf(struct GlobalConfig *config, const char *fmt, ...)
CURL_PRINTF(2, 3);
void msgf(struct GlobalConfig *config, const char *prefix,
const char *fmt, ...)
CURL_PRINTF(3, 4);

#endif /* HEADER_CURL_TOOL_MSGS_H */
19 changes: 16 additions & 3 deletions src/tool_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2702,21 +2702,34 @@ CURLcode operate(struct GlobalConfig *global, int argc, argv_item_t argv[])
{
CURLcode result = CURLE_OK;
char *first_arg = argc > 1 ? curlx_convert_tchar_to_UTF8(argv[1]) : NULL;
char *curlrc = getenv("CURL_RC");

#ifdef HAVE_SETLOCALE
/* Override locale for number parsing (only) */
setlocale(LC_ALL, "");
setlocale(LC_NUMERIC, "C");
#endif

if(getenv("CURL_CONFIG_DEBUG")) {
configdebug = TRUE;
}
/* Parse .curlrc if necessary */
if((argc == 1) ||
(first_arg && strncmp(first_arg, "-q", 2) &&
!curl_strequal(first_arg, "--disable"))) {
parseconfig(NULL, global); /* ignore possible failure */
strcmp(first_arg, "--disable"))) {
if(first_arg && (!strncmp(first_arg, "-v", 2) ||
!strcmp(first_arg, "--verbose"))) {
configdebug = TRUE;
}
if(parseconfig(curlrc, global)) {
if(curlrc)
errorf(global,
"The config file provided in CURL_RC triggered an error");
result = CURLE_FAILED_INIT;
}

/* If we had no arguments then make sure a url was specified in .curlrc */
if((argc < 2) && (!global->first->url_list)) {
else if((argc < 2) && (!global->first->url_list)) {
helpf(tool_stderr, NULL);
result = CURLE_FAILED_INIT;
}
Expand Down
29 changes: 23 additions & 6 deletions src/tool_parsecfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ static FILE *execpath(const char *filename, char **pathp)
}
#endif

bool configdebug = FALSE;

#define DEBUGPREFIX "config: "

/* return 0 on everything-is-fine, and non-zero otherwise */
int parseconfig(const char *filename, struct GlobalConfig *global)
Expand Down Expand Up @@ -112,8 +115,14 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
#endif
}
else {
if(strcmp(filename, "-"))
if(strcmp(filename, "-")) {
file = fopen(filename, FOPEN_READTEXT);

if(!file) {
msgf(global, "config: ", "could not read '%s'", filename);
rc = 1;
}
}
else
file = stdin;
}
Expand All @@ -129,6 +138,9 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
curlx_dyn_init(&buf, MAX_CONFIG_LINE_LENGTH);
DEBUGASSERT(filename);

if(configdebug)
msgf(operation->global, DEBUGPREFIX, "Reading %s", filename);

while(!rc && my_get_line(file, &buf, &fileerror)) {
int res;
bool alloced_param = FALSE;
Expand Down Expand Up @@ -221,9 +233,16 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
param = NULL;
}

#ifdef DEBUG_CONFIG
fprintf(tool_stderr, "PARAM: \"%s\"\n",(param ? param : "(null)"));
#endif
if(configdebug) {
const char *d = "";
if(option[0] != '-')
d = "--";
if(param)
msgf(operation->global, DEBUGPREFIX, "%s%s \"%s\"",
d, option, param);
else
msgf(operation->global, DEBUGPREFIX, "%s%s", d, option);
}
res = getparameter(option, param, NULL, &usedarg, global, operation);
operation = global->last;

Expand Down Expand Up @@ -281,8 +300,6 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
if(fileerror)
rc = 1;
}
else
rc = 1; /* couldn't open the file */

free(pathalloc);
return rc;
Expand Down
2 changes: 2 additions & 0 deletions src/tool_parsecfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
***************************************************************************/
#include "tool_setup.h"

extern bool configdebug;

int parseconfig(const char *filename, struct GlobalConfig *config);

#endif /* HEADER_CURL_TOOL_PARSECFG_H */
2 changes: 1 addition & 1 deletion tests/data/test411
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ none
# Verify data after the test has been "shot"
<verify>
<stderr mode="text">
curl: cannot read config from '%LOGDIR/missing'
config: could not read '%LOGDIR/missing'
curl: option -K: error encountered when reading a file
%if manual
curl: try 'curl --help' or 'curl --manual' for more information
Expand Down