void *userdata)
{
struct OperationConfig *operation = userdata;
- struct GlobalConfig *config = operation->global;
+ struct GlobalConfig *global = operation->global;
FILE *output = tool_stderr;
const char *text;
struct timeval tv;
(void)handle; /* not used */
- if(config->tracetime) {
+ if(global->tracetime) {
tv = tvrealnow();
msnprintf(timebuf, sizeof(timebuf), "%s.%06ld ",
hms_for_sec(tv.tv_sec), (long)tv.tv_usec);
else
timebuf[0] = 0;
- if(handle && config->traceids &&
+ if(handle && global->traceids &&
!curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
conn_id >= 0) {
else
idsbuf[0] = 0;
- if(!config->trace_stream) {
+ if(!global->trace_stream) {
/* open for append */
- if(!strcmp("-", config->trace_dump))
- config->trace_stream = stdout;
- else if(!strcmp("%", config->trace_dump))
+ if(!strcmp("-", global->trace_dump))
+ global->trace_stream = stdout;
+ else if(!strcmp("%", global->trace_dump))
/* Ok, this is somewhat hackish but we do it undocumented for now */
- config->trace_stream = tool_stderr;
+ global->trace_stream = tool_stderr;
else {
- config->trace_stream = fopen(config->trace_dump, FOPEN_WRITETEXT);
- config->trace_fopened = TRUE;
+ global->trace_stream = fopen(global->trace_dump, FOPEN_WRITETEXT);
+ global->trace_fopened = TRUE;
}
}
- if(config->trace_stream)
- output = config->trace_stream;
+ if(global->trace_stream)
+ output = global->trace_stream;
if(!output) {
- warnf(config, "Failed to create/open output");
+ warnf(global, "Failed to create/open output");
return 0;
}
- if(config->tracetype == TRACE_PLAIN) {
+ if(global->tracetype == TRACE_PLAIN) {
static bool newl = FALSE;
static bool traced_data = FALSE;
to stderr or stdout, we do not display the alert about the data not
being shown as the data _is_ shown then just not via this
function */
- if(!config->isatty ||
+ if(!global->isatty ||
((output != tool_stderr) && (output != stdout))) {
if(!newl)
log_line_start(output, timebuf, idsbuf, type);
}
dump(timebuf, idsbuf, text, output, (unsigned char *) data, size,
- config->tracetype, type);
+ global->tracetype, type);
return 0;
}
#ifdef DEBUGBUILD
if(size * nmemb > (size_t)CURL_MAX_HTTP_HEADER) {
- warnf(per->config->global, "Header data exceeds single call write limit");
+ warnf(per->config->global, "Header data exceeds write limit");
return CURL_WRITEFUNC_ERROR;
}
#endif
if(config->show_headers) {
if(bytes > (size_t)CURL_MAX_HTTP_HEADER) {
- warnf(config->global, "Header data size exceeds single call write "
- "limit");
+ warnf(config->global, "Header data size exceeds write limit");
return CURL_WRITEFUNC_ERROR;
}
}
else {
if(bytes > (size_t)CURL_MAX_WRITE_SIZE) {
- warnf(config->global, "Data size exceeds single call write limit");
+ warnf(config->global, "Data size exceeds write limit");
return CURL_WRITEFUNC_ERROR;
}
}
#include "tool_main.h"
#include "memdebug.h" /* keep this as LAST include */
-void config_init(struct OperationConfig *config)
+struct OperationConfig *config_alloc(struct GlobalConfig *global)
{
- memset(config, 0, sizeof(struct OperationConfig));
+ struct OperationConfig *config =
+ calloc(1, sizeof(struct OperationConfig));
+ if(!config)
+ return NULL;
+ config->global = global;
config->use_httpget = FALSE;
config->create_dirs = FALSE;
config->maxredirs = DEFAULT_MAXREDIRS;
config->file_clobber_mode = CLOBBER_DEFAULT;
config->upload_flags = CURLULFLAG_SEEN;
curlx_dyn_init(&config->postdata, MAX_FILE2MEMORY);
+ return config;
}
static void free_config_fields(struct OperationConfig *config)
char *uploadfile;
curl_off_t infilenum; /* number of files to upload */
curl_off_t up; /* upload file counter within a single upload glob */
- curl_off_t urlnum; /* how many iterations this single URL has with ranges
- etc */
+ curl_off_t urlnum; /* how many iterations this URL has with ranges etc */
curl_off_t li;
};
BIT(isatty); /* Updated internally if output is a tty */
};
-void config_init(struct OperationConfig *config);
+struct OperationConfig *config_alloc(struct GlobalConfig *global);
void config_free(struct OperationConfig *config);
#endif /* HEADER_CURL_TOOL_CFGABLE_H */
return ret;
}
-void dumpeasysrc(struct GlobalConfig *config)
+void dumpeasysrc(struct GlobalConfig *global)
{
struct curl_slist *ptr;
- char *o = config->libcurl;
+ char *o = global->libcurl;
FILE *out;
bool fopened = FALSE;
else
out = stdout;
if(!out)
- warnf(config, "Failed to open %s to write libcurl code", o);
+ warnf(global, "Failed to open %s to write libcurl code", o);
else {
int i;
const char *c;
extern CURLcode easysrc_perform(void);
extern CURLcode easysrc_cleanup(void);
-void dumpeasysrc(struct GlobalConfig *config);
+void dumpeasysrc(struct GlobalConfig *global);
#else /* CURL_DISABLE_LIBCURL_OPTION is defined */
nitems = fread(buffer, 1, nitems, stdin);
if(ferror(stdin)) {
/* Show error only once. */
- if(sip->config) {
- warnf(sip->config, "stdin: %s", strerror(errno));
- sip->config = NULL;
+ if(sip->global) {
+ warnf(sip->global, "stdin: %s", strerror(errno));
+ sip->global = NULL;
}
return CURL_READFUNC_ABORT;
}
goto fail;
part->headers = headers;
headers = NULL;
- part->config = config->global;
+ part->global = config->global;
if(res == CURLE_READ_ERROR) {
/* An error occurred while reading stdin: if read has started,
issue the error now. Else, delay it until processed by
goto fail;
part->headers = headers;
headers = NULL;
- part->config = config->global;
+ part->global = config->global;
if(res == CURLE_READ_ERROR) {
/* An error occurred while reading stdin: if read has started,
issue the error now. Else, delay it until processed by
curl_off_t origin; /* Stdin read origin offset. */
curl_off_t size; /* Stdin data size. */
curl_off_t curpos; /* Stdin current read position. */
- struct GlobalConfig *config; /* For access from callback. */
+ struct GlobalConfig *global; /* For access from callback. */
};
size_t tool_mime_stdin_read(char *buffer,
if(config->url_list && config->url_list->url) {
/* Allocate the next config */
- config->next = malloc(sizeof(struct OperationConfig));
+ config->next = config_alloc(global);
if(config->next) {
- /* Initialise the newly created config */
- config_init(config->next);
-
- /* Set the global config pointer */
- config->next->global = global;
-
/* Update the last config pointer */
global->last = config->next;
char **passphrase);
#endif
-ParameterError parse_args(struct GlobalConfig *config, int argc,
+ParameterError parse_args(struct GlobalConfig *global, int argc,
argv_item_t argv[]);
#if defined(UNICODE) && defined(_WIN32) && !defined(UNDER_CE)
* _any_ libcurl usage. If this fails, *NO* libcurl functions may be
* used, or havoc may be the result.
*/
-static CURLcode main_init(struct GlobalConfig *config)
+static CURLcode main_init(struct GlobalConfig *global)
{
CURLcode result = CURLE_OK;
#endif
/* Initialise the global config */
- config->showerror = FALSE; /* show errors when silent */
- config->styled_output = TRUE; /* enable detection */
- config->parallel_max = PARALLEL_DEFAULT;
+ global->showerror = FALSE; /* show errors when silent */
+ global->styled_output = TRUE; /* enable detection */
+ global->parallel_max = PARALLEL_DEFAULT;
/* Allocate the initial operate config */
- config->first = config->last = malloc(sizeof(struct OperationConfig));
- if(config->first) {
+ global->first = global->last = config_alloc(global);
+ if(global->first) {
/* Perform the libcurl initialization */
result = curl_global_init(CURL_GLOBAL_DEFAULT);
if(!result) {
/* Get information about libcurl */
result = get_libcurl_info();
- if(!result) {
- /* Initialise the config */
- config_init(config->first);
- config->first->global = config;
- }
- else {
- errorf(config, "error retrieving curl library information");
- free(config->first);
+ if(result) {
+ errorf(global, "error retrieving curl library information");
+ free(global->first);
}
}
else {
- errorf(config, "error initializing curl library");
- free(config->first);
+ errorf(global, "error initializing curl library");
+ free(global->first);
}
}
else {
- errorf(config, "error initializing curl");
+ errorf(global, "error initializing curl");
result = CURLE_FAILED_INIT;
}
return result;
}
-static void free_globalconfig(struct GlobalConfig *config)
+static void free_globalconfig(struct GlobalConfig *global)
{
- tool_safefree(config->trace_dump);
+ tool_safefree(global->trace_dump);
- if(config->trace_fopened && config->trace_stream)
- fclose(config->trace_stream);
- config->trace_stream = NULL;
+ if(global->trace_fopened && global->trace_stream)
+ fclose(global->trace_stream);
+ global->trace_stream = NULL;
- tool_safefree(config->libcurl);
+ tool_safefree(global->libcurl);
}
/*
- * This is the main global destructor for the app. Call this after
- * _all_ libcurl usage is done.
+ * This is the main global destructor for the app. Call this after _all_
+ * libcurl usage is done.
*/
-static void main_free(struct GlobalConfig *config)
+static void main_free(struct GlobalConfig *global)
{
/* Cleanup the easy handle */
/* Main cleanup */
curl_global_cleanup();
- free_globalconfig(config);
+ free_globalconfig(global);
- /* Free the config structures */
- config_free(config->last);
- config->first = NULL;
- config->last = NULL;
+ /* Free the OperationConfig structures */
+ config_free(global->last);
+ global->first = NULL;
+ global->last = NULL;
}
/*
#define NOTE_PREFIX "Note: "
#define ERROR_PREFIX "curl: "
-static void voutf(struct GlobalConfig *config,
+static void voutf(struct GlobalConfig *global,
const char *prefix,
const char *fmt,
va_list ap) CURL_PRINTF(3, 0);
-static void voutf(struct GlobalConfig *config,
+static void voutf(struct GlobalConfig *global,
const char *prefix,
const char *fmt,
va_list ap)
{
size_t width = (get_terminal_columns() - strlen(prefix));
DEBUGASSERT(!strchr(fmt, '\n'));
- if(!config->silent) {
+ if(!global->silent) {
size_t len;
char *ptr;
char *print_buffer;
* Emit 'note' formatted message on configured 'errors' stream, if verbose was
* selected.
*/
-void notef(struct GlobalConfig *config, const char *fmt, ...)
+void notef(struct GlobalConfig *global, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- if(config->tracetype)
- voutf(config, NOTE_PREFIX, fmt, ap);
+ if(global->tracetype)
+ voutf(global, NOTE_PREFIX, fmt, ap);
va_end(ap);
}
* Emit warning formatted message on configured 'errors' stream unless
* mute (--silent) was selected.
*/
-void warnf(struct GlobalConfig *config, const char *fmt, ...)
+void warnf(struct GlobalConfig *global, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- voutf(config, WARN_PREFIX, fmt, ap);
+ voutf(global, WARN_PREFIX, fmt, ap);
va_end(ap);
}
* Emit error message on error stream if not muted. When errors are not tied
* to command line arguments, use helpf() for such errors.
*/
-void errorf(struct GlobalConfig *config, const char *fmt, ...)
+void errorf(struct GlobalConfig *global, const char *fmt, ...)
{
- if(!config->silent || config->showerror) {
+ if(!global->silent || global->showerror) {
va_list ap;
va_start(ap, fmt);
- voutf(config, ERROR_PREFIX, fmt, ap);
+ voutf(global, ERROR_PREFIX, fmt, ap);
va_end(ap);
}
}
#include "tool_setup.h"
#include "tool_cfgable.h"
-void warnf(struct GlobalConfig *config, const char *fmt, ...)
+void warnf(struct GlobalConfig *global, const char *fmt, ...)
CURL_PRINTF(2, 3);
-void notef(struct GlobalConfig *config, const char *fmt, ...)
+void notef(struct GlobalConfig *global, const char *fmt, ...)
CURL_PRINTF(2, 3);
void helpf(FILE *errors, const char *fmt, ...)
CURL_PRINTF(2, 3);
-void errorf(struct GlobalConfig *config, const char *fmt, ...)
+void errorf(struct GlobalConfig *global, const char *fmt, ...)
CURL_PRINTF(2, 3);
#endif /* HEADER_CURL_TOOL_MSGS_H */
BIT(skip); /* considered already done */
};
-CURLcode operate(struct GlobalConfig *config, int argc, argv_item_t argv[]);
+CURLcode operate(struct GlobalConfig *global, int argc, argv_item_t argv[]);
void single_transfer_cleanup(struct OperationConfig *config);
extern struct per_transfer *transfers; /* first node */
if(res == PARAM_NEXT_OPERATION) {
if(operation->url_list && operation->url_list->url) {
/* Allocate the next config */
- operation->next = malloc(sizeof(struct OperationConfig));
+ operation->next = config_alloc(global);
if(operation->next) {
- /* Initialise the newly created config */
- config_init(operation->next);
-
- /* Set the global config pointer */
- operation->next->global = global;
-
/* Update the last operation pointer */
global->last = operation->next;
***************************************************************************/
#include "tool_setup.h"
-int parseconfig(const char *filename, struct GlobalConfig *config);
+int parseconfig(const char *filename, struct GlobalConfig *global);
bool my_get_line(FILE *fp, struct dynbuf *db, bool *error);
}
/* setopt wrapper for enum types */
-CURLcode tool_setopt_enum(CURL *curl, struct GlobalConfig *config,
+CURLcode tool_setopt_enum(CURL *curl, struct GlobalConfig *global,
const char *name, CURLoption tag,
const struct NameValue *nvlist, long lval)
{
if(!lval)
skip = TRUE;
- if(config->libcurl && !skip && !ret) {
+ if(global->libcurl && !skip && !ret) {
/* we only use this for real if --libcurl was used */
const struct NameValue *nv = NULL;
for(nv = nvlist; nv->name; nv++) {
#ifdef DEBUGBUILD
if(ret)
- warnf(config, "option %s returned error (%d)", name, (int)ret);
+ warnf(global, "option %s returned error (%d)", name, (int)ret);
#endif
return ret;
}
/* setopt wrapper for CURLOPT_SSLVERSION */
-CURLcode tool_setopt_SSLVERSION(CURL *curl, struct GlobalConfig *config,
+CURLcode tool_setopt_SSLVERSION(CURL *curl, struct GlobalConfig *global,
const char *name, CURLoption tag,
long lval)
{
if(!lval)
skip = TRUE;
- if(config->libcurl && !skip && !ret) {
+ if(global->libcurl && !skip && !ret) {
/* we only use this for real if --libcurl was used */
const struct NameValue *nv = NULL;
const struct NameValue *nv2 = NULL;
#ifdef DEBUGBUILD
if(ret)
- warnf(config, "option %s returned error (%d)", name, (int)ret);
+ warnf(global, "option %s returned error (%d)", name, (int)ret);
#endif
return ret;
}
/* setopt wrapper for bitmasks */
-CURLcode tool_setopt_bitmask(CURL *curl, struct GlobalConfig *config,
+CURLcode tool_setopt_bitmask(CURL *curl, struct GlobalConfig *global,
const char *name, CURLoption tag,
const struct NameValueUnsigned *nvlist,
long lval)
if(!lval)
skip = TRUE;
- if(config->libcurl && !skip && !ret) {
+ if(global->libcurl && !skip && !ret) {
/* we only use this for real if --libcurl was used */
char preamble[80];
unsigned long rest = (unsigned long)lval;
}
static CURLcode libcurl_generate_mime(CURL *curl,
- struct GlobalConfig *config,
+ struct GlobalConfig *global,
struct tool_mime *toolmime,
int *mimeno); /* Forward. */
/* Wrapper to generate source code for a mime part. */
static CURLcode libcurl_generate_mime_part(CURL *curl,
- struct GlobalConfig *config,
+ struct GlobalConfig *global,
struct tool_mime *part,
int mimeno)
{
/* Parts are linked in reverse order. */
if(part->prev)
- ret = libcurl_generate_mime_part(curl, config, part->prev, mimeno);
+ ret = libcurl_generate_mime_part(curl, global, part->prev, mimeno);
/* Create the part. */
if(!ret)
switch(part->kind) {
case TOOLMIME_PARTS:
- ret = libcurl_generate_mime(curl, config, part, &submimeno);
+ ret = libcurl_generate_mime(curl, global, part, &submimeno);
if(!ret) {
ret = easysrc_addf(&easysrc_code, "curl_mime_subparts(part%d, mime%d);",
mimeno, submimeno);
/* Wrapper to generate source code for a mime structure. */
static CURLcode libcurl_generate_mime(CURL *curl,
- struct GlobalConfig *config,
+ struct GlobalConfig *global,
struct tool_mime *toolmime,
int *mimeno)
{
if(toolmime->subparts && !ret) {
ret = easysrc_addf(&easysrc_decl, "curl_mimepart *part%d;", *mimeno);
if(!ret)
- ret = libcurl_generate_mime_part(curl, config,
+ ret = libcurl_generate_mime_part(curl, global,
toolmime->subparts, *mimeno);
}
}
/* setopt wrapper for CURLOPT_MIMEPOST */
-CURLcode tool_setopt_mimepost(CURL *curl, struct GlobalConfig *config,
+CURLcode tool_setopt_mimepost(CURL *curl, struct GlobalConfig *global,
const char *name, CURLoption tag,
curl_mime *mimepost)
{
CURLcode ret = curl_easy_setopt(curl, tag, mimepost);
int mimeno = 0;
- if(!ret && config->libcurl) {
- ret = libcurl_generate_mime(curl, config,
- config->current->mimeroot, &mimeno);
+ if(!ret && global->libcurl) {
+ ret = libcurl_generate_mime(curl, global,
+ global->current->mimeroot, &mimeno);
if(!ret)
ret = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, mime%d);",
}
/* setopt wrapper for curl_slist options */
-CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *config,
+CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *global,
const char *name, CURLoption tag,
struct curl_slist *list)
{
ret = curl_easy_setopt(curl, tag, list);
- if(config->libcurl && list && !ret) {
+ if(global->libcurl && list && !ret) {
int i;
ret = libcurl_generate_slist(list, &i);
/* Intercept setopt calls for --libcurl */
-CURLcode tool_setopt_enum(CURL *curl, struct GlobalConfig *config,
+CURLcode tool_setopt_enum(CURL *curl, struct GlobalConfig *global,
const char *name, CURLoption tag,
const struct NameValue *nv, long lval);
-CURLcode tool_setopt_SSLVERSION(CURL *curl, struct GlobalConfig *config,
+CURLcode tool_setopt_SSLVERSION(CURL *curl, struct GlobalConfig *global,
const char *name, CURLoption tag,
long lval);
-CURLcode tool_setopt_flags(CURL *curl, struct GlobalConfig *config,
+CURLcode tool_setopt_flags(CURL *curl, struct GlobalConfig *global,
const char *name, CURLoption tag,
const struct NameValue *nv, long lval);
-CURLcode tool_setopt_bitmask(CURL *curl, struct GlobalConfig *config,
+CURLcode tool_setopt_bitmask(CURL *curl, struct GlobalConfig *global,
const char *name, CURLoption tag,
const struct NameValueUnsigned *nv, long lval);
-CURLcode tool_setopt_mimepost(CURL *curl, struct GlobalConfig *config,
+CURLcode tool_setopt_mimepost(CURL *curl, struct GlobalConfig *global,
const char *name, CURLoption tag,
curl_mime *mimepost);
-CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *config,
+CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *global,
const char *name, CURLoption tag,
struct curl_slist *list);
CURLcode tool_setopt_long(CURL *curl, struct GlobalConfig *global,
# Verify data after the test has been "shot"
<verify>
<file name="%LOGDIR/memdump">
+MEM tool_cfgable.c
MEM tool_paramhlp.c
MEM tool_cfgable.c
MEM tool_cfgable.c