Skip to content

Commit

Permalink
curl: embryo for tracing cmdline arguments from config files
Browse files Browse the repository at this point in the history
  • Loading branch information
bagder committed Apr 8, 2024
1 parent 50def7c commit 0e6a1ff
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
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 */
12 changes: 10 additions & 2 deletions src/tool_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2702,18 +2702,26 @@ 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;
}
parseconfig(curlrc, global); /* ignore possible failure */

/* If we had no arguments then make sure a url was specified in .curlrc */
if((argc < 2) && (!global->first->url_list)) {
Expand Down
19 changes: 16 additions & 3 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 @@ -129,6 +132,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 +227,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
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 */

0 comments on commit 0e6a1ff

Please sign in to comment.