}
if(result < 0) {
int error = errno;
- warnf(config->global,
- "Setting type of service to %d failed with errno %d: %s;\n",
+ warnf("Setting type of service to %d failed with errno %d: %s",
tos, error, strerror(error));
}
}
if(config->vlan_priority > 0) {
int priority = (int)config->vlan_priority;
if(setsockopt(curlfd, SOL_SOCKET, SO_PRIORITY,
- (void *)&priority, sizeof(priority)) != 0) {
+ (void *)&priority, sizeof(priority)) != 0) {
int error = errno;
- warnf(config->global, "VLAN priority %d failed with errno %d: %s;\n",
+ warnf("VLAN priority %d failed with errno %d: %s",
priority, error, strerror(error));
}
}
static CURLcode ssh_setopts(struct OperationConfig *config, CURL *curl)
{
- struct GlobalConfig *global = config->global;
CURLcode result;
/* SSH and SSL private key uses same command-line option */
global->knownhosts = known;
}
else if(!config->hostpubmd5 && !config->hostpubsha256) {
- errorf(global, "Couldn't find a known_hosts file");
+ errorf("Couldn't find a known_hosts file");
return CURLE_FAILED_INIT;
}
else
- warnf(global, "Couldn't find a known_hosts file");
+ warnf("Couldn't find a known_hosts file");
}
return CURLE_OK; /* ignore if SHA256 did not work */
}
/* only called if libcurl supports TLS */
static CURLcode ssl_setopts(struct OperationConfig *config, CURL *curl)
{
- struct GlobalConfig *global = config->global;
CURLcode result = CURLE_OK;
if(config->cacert)
if((result == CURLE_NOT_BUILT_IN) ||
(result == CURLE_UNKNOWN_OPTION)) {
if(config->proxy_capath) {
- warnf(global, "ignoring %s, not supported by libcurl with %s",
+ warnf("ignoring %s, not supported by libcurl with %s",
config->proxy_capath ? "--proxy-capath" : "--capath",
ssl_backend());
}
blob.data = CURL_UNCONST(curl_ca_embed);
blob.len = strlen((const char *)curl_ca_embed);
blob.flags = CURL_BLOB_NOCOPY;
- notef(config->global,
- "Using embedded CA bundle (%zu bytes)",
- blob.len);
+ notef("Using embedded CA bundle (%zu bytes)", blob.len);
result = curl_easy_setopt(curl, CURLOPT_CAINFO_BLOB, &blob);
if(result == CURLE_NOT_BUILT_IN) {
- warnf(global, "ignoring %s, not supported by libcurl with %s",
+ warnf("ignoring %s, not supported by libcurl with %s",
"embedded CA bundle", ssl_backend());
}
}
blob.data = CURL_UNCONST(curl_ca_embed);
blob.len = strlen((const char *)curl_ca_embed);
blob.flags = CURL_BLOB_NOCOPY;
- notef(config->global,
- "Using embedded CA bundle, for proxies (%zu bytes)",
- blob.len);
+ notef("Using embedded CA bundle, for proxies (%zu bytes)", blob.len);
result = curl_easy_setopt(curl, CURLOPT_PROXY_CAINFO_BLOB, &blob);
if(result == CURLE_NOT_BUILT_IN) {
- warnf(global, "ignoring %s, not supported by libcurl with %s",
+ warnf("ignoring %s, not supported by libcurl with %s",
"embedded CA bundle", ssl_backend());
}
}
result = my_setopt_str(curl, CURLOPT_PINNEDPUBLICKEY,
config->pinnedpubkey);
if(result == CURLE_NOT_BUILT_IN)
- warnf(global, "ignoring %s, not supported by libcurl with %s",
+ warnf("ignoring %s, not supported by libcurl with %s",
"--pinnedpubkey", ssl_backend());
}
if(config->proxy_pinnedpubkey) {
result = my_setopt_str(curl, CURLOPT_PROXY_PINNEDPUBLICKEY,
config->proxy_pinnedpubkey);
if(result == CURLE_NOT_BUILT_IN)
- warnf(global, "ignoring %s, not supported by libcurl with %s",
+ warnf("ignoring %s, not supported by libcurl with %s",
"--proxy-pinnedpubkey", ssl_backend());
}
result = my_setopt_str(curl, CURLOPT_SSL_CIPHER_LIST,
config->cipher_list);
if(result == CURLE_NOT_BUILT_IN)
- warnf(global, "ignoring %s, not supported by libcurl with %s",
+ warnf("ignoring %s, not supported by libcurl with %s",
"--ciphers", ssl_backend());
}
if(config->proxy_cipher_list) {
result = my_setopt_str(curl, CURLOPT_PROXY_SSL_CIPHER_LIST,
config->proxy_cipher_list);
if(result == CURLE_NOT_BUILT_IN)
- warnf(global, "ignoring %s, not supported by libcurl with %s",
+ warnf("ignoring %s, not supported by libcurl with %s",
"--proxy-ciphers", ssl_backend());
}
if(config->cipher13_list) {
result = my_setopt_str(curl, CURLOPT_TLS13_CIPHERS,
config->cipher13_list);
if(result == CURLE_NOT_BUILT_IN)
- warnf(global, "ignoring %s, not supported by libcurl with %s",
+ warnf("ignoring %s, not supported by libcurl with %s",
"--tls13-ciphers", ssl_backend());
}
if(config->proxy_cipher13_list) {
result = my_setopt_str(curl, CURLOPT_PROXY_TLS13_CIPHERS,
config->proxy_cipher13_list);
if(result == CURLE_NOT_BUILT_IN)
- warnf(global, "ignoring %s, not supported by libcurl with %s",
+ warnf("ignoring %s, not supported by libcurl with %s",
"--proxy-tls13-ciphers", ssl_backend());
}
result = curlx_dyn_addf(&cookies, ";%s", cl->data);
if(result) {
- warnf(config->global,
- "skipped provided cookie, the cookie header "
+ warnf("skipped provided cookie, the cookie header "
"would go over %u bytes", MAX_COOKIE_LINE);
return result;
}
static void gen_trace_setopts(struct OperationConfig *config, CURL *curl)
{
- if(config->global->tracetype != TRACE_NONE) {
+ if(global->tracetype != TRACE_NONE) {
my_setopt(curl, CURLOPT_DEBUGFUNCTION, tool_debug_cb);
my_setopt(curl, CURLOPT_DEBUGDATA, config);
my_setopt_long(curl, CURLOPT_VERBOSE, 1L);
struct per_transfer *per,
CURL *curl)
{
- struct GlobalConfig *global = config->global;
- (void)config;
+ (void)config; /* when --libcurl is disabled */
+
/* where to store */
my_setopt(curl, CURLOPT_WRITEDATA, per);
my_setopt(curl, CURLOPT_INTERLEAVEDATA, per);
CURLcode result = my_setopt_str(curl, CURLOPT_PROXY, config->proxy);
if(result) {
- errorf(config->global, "proxy support is disabled in this libcurl");
+ errorf("proxy support is disabled in this libcurl");
config->synthetic_error = TRUE;
return CURLE_NOT_BUILT_IN;
}
CURL *curl,
CURLSH *share)
{
- struct GlobalConfig *global = config->global;
const char *use_proto;
CURLcode result = url_proto_and_rewrite(&per->url, config, &use_proto);
switch(config->httpreq) {
case TOOL_HTTPREQ_SIMPLEPOST:
if(config->resume_from) {
- errorf(global, "cannot mix --continue-at with --data");
+ errorf("cannot mix --continue-at with --data");
result = CURLE_FAILED_INIT;
}
else {
curl_mime_free(config->mimepost);
config->mimepost = NULL;
if(config->resume_from) {
- errorf(global, "cannot mix --continue-at with --form");
+ errorf("cannot mix --continue-at with --form");
result = CURLE_FAILED_INIT;
}
else {
my_setopt_enum(curl, CURLOPT_TIMECONDITION, config->timecond);
my_setopt_offt(curl, CURLOPT_TIMEVALUE_LARGE, config->condtime);
my_setopt_str(curl, CURLOPT_CUSTOMREQUEST, config->customrequest);
- customrequest_helper(config, config->httpreq, config->customrequest);
+ customrequest_helper(config->httpreq, config->customrequest);
my_setopt(curl, CURLOPT_STDERR, tool_stderr);
my_setopt_str(curl, CURLOPT_INTERFACE, config->iface);
my_setopt_str(curl, CURLOPT_KRBLEVEL, config->krblevel);
my_setopt(curl, CURLOPT_SOCKOPTDATA, config);
#else
if(config->ip_tos > 0) {
- errorf(config->global,
- "Type of service is not supported in this build.");
+ errorf("Type of service is not supported in this build.");
result = CURLE_NOT_BUILT_IN;
}
if(config->vlan_priority > 0) {
- errorf(config->global,
- "VLAN priority is not supported in this build.");
+ errorf("VLAN priority is not supported in this build.");
result = CURLE_NOT_BUILT_IN;
}
#endif
char *data, size_t size,
void *userdata)
{
- struct OperationConfig *operation = userdata;
- struct GlobalConfig *global = operation->global;
FILE *output = tool_stderr;
const char *text;
struct timeval tv;
curl_off_t xfer_id, conn_id;
(void)handle; /* not used */
+ (void)userdata;
if(global->tracetime) {
tv = tvrealnow();
output = global->trace_stream;
if(!output) {
- warnf(global, "Failed to create/open output");
+ warnf("Failed to create/open output");
return 0;
}
#ifdef DEBUGBUILD
if(size * nmemb > (size_t)CURL_MAX_HTTP_HEADER) {
- warnf(per->config->global, "Header data exceeds write limit");
+ warnf("Header data exceeds write limit");
return CURL_WRITEFUNC_ERROR;
}
#endif
return rc;
/* flush the stream to send off what we got earlier */
if(fflush(heads->stream)) {
- errorf(per->config->global, "Failed writing headers to %s",
- per->config->headerfile);
+ errorf("Failed writing headers to %s", per->config->headerfile);
return CURL_WRITEFUNC_ERROR;
}
}
if(!outs->stream && !tool_create_output_file(outs, per->config))
return CURL_WRITEFUNC_ERROR;
- if(hdrcbdata->config->global->isatty &&
+ if(global->isatty &&
#ifdef _WIN32
tool_term_has_bold &&
#endif
- hdrcbdata->config->global->styled_output)
+ global->styled_output)
value = memchr(ptr, ':', cb);
if(value) {
size_t namelen = value - ptr;
rc = 0;
}
#else
- warnf(per->config->global, "per->infd != 0: FD == %d. This behavior"
+ warnf("per->infd != 0: FD == %d. This behavior"
" is only supported on desktop Windows", per->infd);
#endif
}
(per->uploadedsofar + rc > per->uploadfilesize)) {
/* do not allow uploading more than originally set out to do */
curl_off_t delta = per->uploadedsofar + rc - per->uploadfilesize;
- warnf(per->config->global, "File size larger in the end than when "
+ warnf("File size larger in the end than when "
"started. Dropping at least %" CURL_FORMAT_CURL_OFF_T " bytes",
delta);
rc = (ssize_t)(per->uploadfilesize - per->uploadedsofar);
bool tool_create_output_file(struct OutStruct *outs,
struct OperationConfig *config)
{
- struct GlobalConfig *global;
FILE *file = NULL;
const char *fname = outs->filename;
DEBUGASSERT(outs);
DEBUGASSERT(config);
- global = config->global;
DEBUGASSERT(fname && *fname);
if(config->file_clobber_mode == CLOBBER_ALWAYS ||
}
if(!file) {
- warnf(global, "Failed to open the file %s: %s", fname,
- strerror(errno));
+ warnf("Failed to open the file %s: %s", fname, strerror(errno));
return FALSE;
}
outs->s_isreg = TRUE;
struct OutStruct *outs = &per->outs;
struct OperationConfig *config = per->config;
size_t bytes = sz * nmemb;
- bool is_tty = config->global->isatty;
+ bool is_tty = global->isatty;
#if defined(_WIN32) && !defined(UNDER_CE)
CONSOLE_SCREEN_BUFFER_INFO console_info;
intptr_t fhnd;
if(config->show_headers) {
if(bytes > (size_t)CURL_MAX_HTTP_HEADER) {
- warnf(config->global, "Header data size exceeds write limit");
+ warnf("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 write limit");
+ warnf("Data size exceeds write limit");
return CURL_WRITEFUNC_ERROR;
}
}
check_fails = TRUE;
}
if(check_fails) {
- warnf(config->global, "Invalid output struct data for write callback");
+ warnf("Invalid output struct data for write callback");
return CURL_WRITEFUNC_ERROR;
}
}
if(is_tty && (outs->bytes < 2000) && !config->terminal_binary_ok) {
/* binary output to terminal? */
if(memchr(buffer, 0, bytes)) {
- warnf(config->global, "Binary output can mess up your terminal. "
+ warnf("Binary output can mess up your terminal. "
"Use \"--output -\" to tell curl to output it to your terminal "
"anyway, or consider \"--output <FILE>\" to save to a file.");
config->synthetic_error = TRUE;
#include "tool_formparse.h"
#include "tool_paramhlp.h"
#include "tool_main.h"
+#include "tool_msgs.h"
#include "memdebug.h" /* keep this as LAST include */
-struct OperationConfig *config_alloc(struct GlobalConfig *global)
+static struct GlobalConfig globalconf;
+struct GlobalConfig *global;
+
+struct OperationConfig *config_alloc(void)
{
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;
last = prev;
}
}
+
+/*
+ * This is the main global constructor for the app. Call this before
+ * _any_ libcurl usage. If this fails, *NO* libcurl functions may be
+ * used, or havoc may be the result.
+ */
+CURLcode globalconf_init(void)
+{
+ CURLcode result = CURLE_OK;
+ global = &globalconf;
+
+#ifdef __DJGPP__
+ /* stop stat() wasting time */
+ _djstat_flags |= _STAT_INODE | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
+#endif
+
+ /* Initialise the global config */
+ global->showerror = FALSE; /* show errors when silent */
+ global->styled_output = TRUE; /* enable detection */
+ global->parallel_max = PARALLEL_DEFAULT;
+
+ /* Allocate the initial operate config */
+ global->first = global->last = config_alloc();
+ 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) {
+ errorf("error retrieving curl library information");
+ free(global->first);
+ }
+ }
+ else {
+ errorf("error initializing curl library");
+ free(global->first);
+ }
+ }
+ else {
+ errorf("error initializing curl");
+ result = CURLE_FAILED_INIT;
+ }
+
+ return result;
+}
+
+static void free_globalconfig(void)
+{
+ tool_safefree(global->trace_dump);
+
+ if(global->trace_fopened && global->trace_stream)
+ fclose(global->trace_stream);
+ global->trace_stream = NULL;
+
+ tool_safefree(global->libcurl);
+}
+
+/*
+ * This is the main global destructor for the app. Call this after _all_
+ * libcurl usage is done.
+ */
+void globalconf_free(void)
+{
+ /* Cleanup the easy handle */
+ /* Main cleanup */
+ curl_global_cleanup();
+ free_globalconfig();
+
+ /* Free the OperationConfig structures */
+ config_free(global->last);
+ global->first = NULL;
+ global->last = NULL;
+}
#define tool_safefree(ptr) \
do { free((ptr)); (ptr) = NULL;} while(0)
-struct GlobalConfig;
+extern struct GlobalConfig *global;
struct State {
struct getout *urlnode;
char *ech; /* Config set by --ech keywords */
char *ech_config; /* Config set by "--ech esl:" option */
char *ech_public; /* Config set by "--ech pn:" option */
- struct GlobalConfig *global;
struct OperationConfig *prev;
struct OperationConfig *next; /* Always last in the struct */
curl_off_t condtime;
BIT(isatty); /* Updated internally if output is a tty */
};
-struct OperationConfig *config_alloc(struct GlobalConfig *global);
+struct OperationConfig *config_alloc(void);
void config_free(struct OperationConfig *config);
+CURLcode globalconf_init(void);
+void globalconf_free(void);
#endif /* HEADER_CURL_TOOL_CFGABLE_H */
# endif
#endif
-static void show_dir_errno(struct GlobalConfig *global, const char *name)
+static void show_dir_errno(const char *name)
{
switch(errno) {
#ifdef EACCES
/* !checksrc! disable ERRNOVAR 1 */
case EACCES:
- errorf(global, "You do not have permission to create %s", name);
+ errorf("You do not have permission to create %s", name);
break;
#endif
#ifdef ENAMETOOLONG
case ENAMETOOLONG:
- errorf(global, "The directory name %s is too long", name);
+ errorf("The directory name %s is too long", name);
break;
#endif
#ifdef EROFS
case EROFS:
- errorf(global, "%s resides on a read-only file system", name);
+ errorf("%s resides on a read-only file system", name);
break;
#endif
#ifdef ENOSPC
case ENOSPC:
- errorf(global, "No space left on the file system that will "
+ errorf("No space left on the file system that will "
"contain the directory %s", name);
break;
#endif
#ifdef EDQUOT
case EDQUOT:
- errorf(global, "Cannot create directory %s because you "
+ errorf("Cannot create directory %s because you "
"exceeded your quota", name);
break;
#endif
default:
- errorf(global, "Error creating directory %s", name);
+ errorf("Error creating directory %s", name);
break;
}
}
#define PATH_DELIMITERS DIR_CHAR
#endif
-CURLcode create_dir_hierarchy(const char *outfile, struct GlobalConfig *global)
+CURLcode create_dir_hierarchy(const char *outfile)
{
CURLcode result = CURLE_OK;
size_t outlen = strlen(outfile);
/* !checksrc! disable ERRNOVAR 1 */
if(!skip && (mkdir(curlx_dyn_ptr(&dirbuf), (mode_t)0000750) == -1) &&
(errno != EACCES) && (errno != EEXIST)) {
- show_dir_errno(global, curlx_dyn_ptr(&dirbuf));
+ show_dir_errno(curlx_dyn_ptr(&dirbuf));
result = CURLE_WRITE_ERROR;
break; /* get out of loop */
}
#include "tool_setup.h"
#include "tool_cfgable.h"
-CURLcode create_dir_hierarchy(const char *outfile,
- struct GlobalConfig *global);
+CURLcode create_dir_hierarchy(const char *outfileo);
#endif /* HEADER_CURL_TOOL_DIRHIE_H */
by nmap and ncat (https://nmap.org/ncat/) */
struct win_thread_data {
/* This is a copy of the true stdin file handle before any redirection. It is
- read by the thread. */
+ read by the thread. */
HANDLE stdin_handle;
/* This is the listen socket for the thread. It is closed after the first
- connection. */
+ connection. */
curl_socket_t socket_l;
- /* This is the global config - used for printing errors and so forth */
- struct GlobalConfig *global;
};
static DWORD WINAPI win_stdin_thread_func(void *thread_data)
&clientAddrLen);
if(socket_w == CURL_SOCKET_BAD) {
- errorf(tdata->global, "accept error: %08lx\n", GetLastError());
+ errorf("accept error: %08lx", GetLastError());
goto ThreadCleanup;
}
closesocket(tdata->socket_l); /* sclose here fails test 1498 */
tdata->socket_l = CURL_SOCKET_BAD;
if(shutdown(socket_w, SD_RECEIVE) == SOCKET_ERROR) {
- errorf(tdata->global, "shutdown error: %08lx\n", GetLastError());
+ errorf("shutdown error: %08lx", GetLastError());
goto ThreadCleanup;
}
for(;;) {
static HANDLE stdin_thread = NULL;
static curl_socket_t socket_r = CURL_SOCKET_BAD;
-curl_socket_t win32_stdin_read_thread(struct GlobalConfig *global)
+curl_socket_t win32_stdin_read_thread(void)
{
int result;
bool r;
/* Prepare handles for thread */
tdata = (struct win_thread_data*)calloc(1, sizeof(struct win_thread_data));
if(!tdata) {
- errorf(global, "calloc() error");
+ errorf("calloc() error");
break;
}
/* Create the listening socket for the thread. When it starts, it will
IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
if(tdata->socket_l == CURL_SOCKET_BAD) {
- errorf(global, "WSASocketW error: %08lx", GetLastError());
+ errorf("WSASocketW error: %08lx", GetLastError());
break;
}
/* Bind to any available loopback port */
result = bind(tdata->socket_l, (SOCKADDR*)&selfaddr, socksize);
if(result == SOCKET_ERROR) {
- errorf(global, "bind error: %08lx", GetLastError());
+ errorf("bind error: %08lx", GetLastError());
break;
}
/* Bind to any available loopback port */
result = getsockname(tdata->socket_l, (SOCKADDR*)&selfaddr, &socksize);
if(result == SOCKET_ERROR) {
- errorf(global, "getsockname error: %08lx", GetLastError());
+ errorf("getsockname error: %08lx", GetLastError());
break;
}
result = listen(tdata->socket_l, 1);
if(result == SOCKET_ERROR) {
- errorf(global, "listen error: %08lx\n", GetLastError());
+ errorf("listen error: %08lx", GetLastError());
break;
}
0, FALSE, DUPLICATE_SAME_ACCESS);
if(!r) {
- errorf(global, "DuplicateHandle error: %08lx", GetLastError());
+ errorf("DuplicateHandle error: %08lx", GetLastError());
break;
}
stdin_thread = CreateThread(NULL, 0, win_stdin_thread_func,
tdata, 0, NULL);
if(!stdin_thread) {
- errorf(global, "CreateThread error: %08lx", GetLastError());
+ errorf("CreateThread error: %08lx", GetLastError());
break;
}
/* Connect to the thread and rearrange our own STDIN handles */
socket_r = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(socket_r == CURL_SOCKET_BAD) {
- errorf(global, "socket error: %08lx", GetLastError());
+ errorf("socket error: %08lx", GetLastError());
break;
}
setsockopt(socket_r, SOL_SOCKET, SO_DONTLINGER, 0, 0);
if(connect(socket_r, (SOCKADDR*)&selfaddr, socksize) == SOCKET_ERROR) {
- errorf(global, "connect error: %08lx", GetLastError());
+ errorf("connect error: %08lx", GetLastError());
break;
}
if(shutdown(socket_r, SD_SEND) == SOCKET_ERROR) {
- errorf(global, "shutdown error: %08lx", GetLastError());
+ errorf("shutdown error: %08lx", GetLastError());
break;
}
/* Set the stdin handle to read from the socket. */
if(SetStdHandle(STD_INPUT_HANDLE, (HANDLE)socket_r) == 0) {
- errorf(global, "SetStdHandle error: %08lx", GetLastError());
+ errorf("SetStdHandle error: %08lx", GetLastError());
break;
}
CURLcode win32_init(void);
#if !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
-curl_socket_t win32_stdin_read_thread(struct GlobalConfig *global);
+curl_socket_t win32_stdin_read_thread(void);
#endif /* !CURL_WINDOWS_UWP && !UNDER_CE */
#endif /* _WIN32 */
return ret;
}
-void dumpeasysrc(struct GlobalConfig *global)
+void dumpeasysrc(void)
{
struct curl_slist *ptr;
char *o = global->libcurl;
else
out = stdout;
if(!out)
- warnf(global, "Failed to open %s to write libcurl code", o);
+ warnf("Failed to open %s to write libcurl code", o);
else {
int i;
const char *c;
const char *fmt, ...) CURL_PRINTF(2, 3);
extern CURLcode easysrc_perform(void);
extern CURLcode easysrc_cleanup(void);
-
-void dumpeasysrc(struct GlobalConfig *global);
+void dumpeasysrc(void);
#else /* CURL_DISABLE_LIBCURL_OPTION is defined */
#endif
/* Returns 0 on success, non-zero on file problems */
-int getfiletime(const char *filename, struct GlobalConfig *global,
- curl_off_t *stamp)
+int getfiletime(const char *filename, curl_off_t *stamp)
{
int rc = 1;
| ((curl_off_t)ft.dwHighDateTime) << 32;
if(converted < 116444736000000000)
- warnf(global, "Failed to get filetime: underflow");
+ warnf("Failed to get filetime: underflow");
else {
*stamp = (converted - 116444736000000000) / 10000000;
rc = 0;
}
}
else {
- warnf(global, "Failed to get filetime: "
+ warnf("Failed to get filetime: "
"GetFileTime failed: GetLastError %u",
(unsigned int)GetLastError());
}
CloseHandle(hfile);
}
else if(GetLastError() != ERROR_FILE_NOT_FOUND) {
- warnf(global, "Failed to get filetime: "
+ warnf("Failed to get filetime: "
"CreateFile failed: GetLastError %u",
(unsigned int)GetLastError());
}
rc = 0;
}
else
- warnf(global, "Failed to get filetime: %s", strerror(errno));
+ warnf("Failed to get filetime: %s", strerror(errno));
#endif
return rc;
}
#if defined(HAVE_UTIME) || defined(HAVE_UTIMES) || defined(_WIN32)
-void setfiletime(curl_off_t filetime, const char *filename,
- struct GlobalConfig *global)
+void setfiletime(curl_off_t filetime, const char *filename)
{
if(filetime >= 0) {
/* Windows utime() may attempt to adjust the Unix GMT file time by a daylight
/* 910670515199 is the maximum Unix filetime that can be used as a
Windows FILETIME without overflow: 30827-12-31T23:59:59. */
if(filetime > 910670515199) {
- warnf(global, "Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
+ warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
" on outfile: overflow", filetime);
curlx_unicodefree(tchar_filename);
return;
ft.dwLowDateTime = (DWORD)(converted & 0xFFFFFFFF);
ft.dwHighDateTime = (DWORD)(converted >> 32);
if(!SetFileTime(hfile, NULL, &ft, &ft)) {
- warnf(global, "Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
+ warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
" on outfile: SetFileTime failed: GetLastError %u",
filetime, (unsigned int)GetLastError());
}
CloseHandle(hfile);
}
else {
- warnf(global, "Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
+ warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
" on outfile: CreateFile failed: GetLastError %u",
filetime, (unsigned int)GetLastError());
}
times[0].tv_sec = times[1].tv_sec = (time_t)filetime;
times[0].tv_usec = times[1].tv_usec = 0;
if(utimes(filename, times)) {
- warnf(global, "Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
+ warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
" on '%s': %s", filetime, filename, strerror(errno));
}
times.actime = (time_t)filetime;
times.modtime = (time_t)filetime;
if(utime(filename, ×)) {
- warnf(global, "Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
+ warnf("Failed to set filetime %" CURL_FORMAT_CURL_OFF_T
" on '%s': %s", filetime, filename, strerror(errno));
}
#endif
***************************************************************************/
#include "tool_setup.h"
-struct GlobalConfig;
-
-int getfiletime(const char *filename, struct GlobalConfig *global,
- curl_off_t *stamp);
+int getfiletime(const char *filename, curl_off_t *stamp);
#if defined(HAVE_UTIME) || defined(HAVE_UTIMES) || \
(defined(_WIN32) && (SIZEOF_CURL_OFF_T >= 8))
-void setfiletime(curl_off_t filetime, const char *filename,
- struct GlobalConfig *global);
+void setfiletime(curl_off_t filetime, const char *filename);
#else
#define setfiletime(a,b,c) tool_nop_stmt
#endif
nitems = fread(buffer, 1, nitems, stdin);
if(ferror(stdin)) {
/* Show error only once. */
- if(sip->global) {
- warnf(sip->global, "stdin: %s", strerror(errno));
- sip->global = NULL;
- }
+ warnf("stdin: %s", strerror(errno));
return CURL_READFUNC_ABORT;
}
}
* after call get_param_word, str either point to string end
* or point to any of end chars.
*/
-static char *get_param_word(struct OperationConfig *config, char **str,
- char **end_pos, char endchar)
+static char *get_param_word(char **str, char **end_pos, char endchar)
{
char *ptr = *str;
/* the first non-space char is here */
++ptr;
}
if(trailing_data)
- warnf(config->global, "Trailing data after quoted form parameter");
+ warnf("Trailing data after quoted form parameter");
*str = ptr;
return word_begin + 1;
}
}
/* Read headers from a file and append to list. */
-static int read_field_headers(struct OperationConfig *config,
- const char *filename, FILE *fp,
+static int read_field_headers(const char *filename, FILE *fp,
struct curl_slist **pheaders)
{
size_t hdrlen = 0;
if(hdrlen) {
hdrbuf[hdrlen] = '\0';
if(slist_append(pheaders, hdrbuf)) {
- errorf(config->global, "Out of memory for field headers");
+ errorf("Out of memory for field headers");
return -1;
}
hdrlen = 0;
switch(c) {
case EOF:
if(ferror(fp)) {
- errorf(config->global, "Header file %s read error: %s", filename,
+ errorf("Header file %s read error: %s", filename,
strerror(errno));
return -1;
}
pos++;
if(!incomment) {
if(hdrlen == sizeof(hdrbuf) - 1) {
- warnf(config->global, "File %s line %d: header too long (truncated)",
+ warnf("File %s line %d: header too long (truncated)",
filename, lineno);
c = ' ';
}
/* NOTREACHED */
}
-static int get_param_part(struct OperationConfig *config, char endchar,
+static int get_param_part(char endchar,
char **str, char **pdata, char **ptype,
char **pfilename, char **pencoder,
struct curl_slist **pheaders)
while(ISBLANK(*p))
p++;
tp = p;
- *pdata = get_param_word(config, &p, &endpos, endchar);
+ *pdata = get_param_word(&p, &endpos, endchar);
/* If not quoted, strip trailing spaces. */
if(*pdata == tp)
while(endpos > *pdata && ISBLANK(endpos[-1]))
for(p += 9; ISBLANK(*p); p++)
;
tp = p;
- filename = get_param_word(config, &p, &endpos, endchar);
+ filename = get_param_word(&p, &endpos, endchar);
/* If not quoted, strip trailing spaces. */
if(filename == tp)
while(endpos > filename && ISBLANK(endpos[-1]))
p++;
} while(ISBLANK(*p));
tp = p;
- hdrfile = get_param_word(config, &p, &endpos, endchar);
+ hdrfile = get_param_word(&p, &endpos, endchar);
/* If not quoted, strip trailing spaces. */
if(hdrfile == tp)
while(endpos > hdrfile && ISBLANK(endpos[-1]))
*endpos = '\0';
fp = fopen(hdrfile, FOPEN_READTEXT);
if(!fp)
- warnf(config->global, "Cannot read from %s: %s", hdrfile,
+ warnf("Cannot read from %s: %s", hdrfile,
strerror(errno));
else {
- int i = read_field_headers(config, hdrfile, fp, &headers);
+ int i = read_field_headers(hdrfile, fp, &headers);
fclose(fp);
if(i) {
while(ISBLANK(*p))
p++;
tp = p;
- hdr = get_param_word(config, &p, &endpos, endchar);
+ hdr = get_param_word(&p, &endpos, endchar);
/* If not quoted, strip trailing spaces. */
if(hdr == tp)
while(endpos > hdr && ISBLANK(endpos[-1]))
sep = *p;
*endpos = '\0';
if(slist_append(&headers, hdr)) {
- errorf(config->global, "Out of memory for field header");
+ errorf("Out of memory for field header");
curl_slist_free_all(headers);
return -1;
}
for(p += 8; ISBLANK(*p); p++)
;
tp = p;
- encoder = get_param_word(config, &p, &endpos, endchar);
+ encoder = get_param_word(&p, &endpos, endchar);
/* If not quoted, strip trailing spaces. */
if(encoder == tp)
while(endpos > encoder && ISSPACE(endpos[-1]))
}
else {
/* unknown prefix, skip to next block */
- char *unknown = get_param_word(config, &p, &endpos, endchar);
+ char *unknown = get_param_word(&p, &endpos, endchar);
sep = *p;
*endpos = '\0';
if(*unknown)
- warnf(config->global, "skip unknown form field: %s", unknown);
+ warnf("skip unknown form field: %s", unknown);
}
}
if(ptype)
*ptype = type;
else if(type)
- warnf(config->global, "Field content type not allowed here: %s", type);
+ warnf("Field content type not allowed here: %s", type);
if(pfilename)
*pfilename = filename;
else if(filename)
- warnf(config->global,
- "Field filename not allowed here: %s", filename);
+ warnf("Field filename not allowed here: %s", filename);
if(pencoder)
*pencoder = encoder;
else if(encoder)
- warnf(config->global,
- "Field encoder not allowed here: %s", encoder);
+ warnf("Field encoder not allowed here: %s", encoder);
if(pheaders)
*pheaders = headers;
else if(headers) {
- warnf(config->global,
- "Field headers not allowed here: %s", headers->data);
+ warnf("Field headers not allowed here: %s", headers->data);
curl_slist_free_all(headers);
}
} \
} while(0)
-int formparse(struct OperationConfig *config,
- const char *input,
+int formparse(const char *input,
struct tool_mime **mimeroot,
struct tool_mime **mimecurrent,
bool literal_value)
if(*contp == '(' && !literal_value) {
/* Starting a multipart. */
- sep = get_param_part(config, '\0',
- &contp, &data, &type, NULL, NULL, &headers);
+ sep = get_param_part('\0', &contp, &data, &type, NULL, NULL, &headers);
if(sep < 0)
goto fail;
part = tool_mime_new_parts(*mimecurrent);
else if(!name && !strcmp(contp, ")") && !literal_value) {
/* Ending a multipart. */
if(*mimecurrent == *mimeroot) {
- warnf(config->global, "no multipart to terminate");
+ warnf("no multipart to terminate");
goto fail;
}
*mimecurrent = (*mimecurrent)->parent;
/* since this was a file, it may have a content-type specifier
at the end too, or a filename. Or both. */
++contp;
- sep = get_param_part(config, ',', &contp,
+ sep = get_param_part(',', &contp,
&data, &type, &filename, &encoder, &headers);
if(sep < 0) {
goto fail;
goto fail;
part->headers = headers;
headers = NULL;
- 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
libcurl. */
if(part->size > 0) {
- warnf(config->global,
- "error while reading standard input");
+ warnf("error while reading standard input");
goto fail;
}
tool_safefree(part->data);
else {
if(*contp == '<' && !literal_value) {
++contp;
- sep = get_param_part(config, '\0', &contp,
+ sep = get_param_part('\0', &contp,
&data, &type, NULL, &encoder, &headers);
if(sep < 0)
goto fail;
goto fail;
part->headers = headers;
headers = NULL;
- 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
libcurl. */
if(part->size > 0) {
- warnf(config->global,
- "error while reading standard input");
+ warnf("error while reading standard input");
goto fail;
}
tool_safefree(part->data);
if(literal_value)
data = contp;
else {
- sep = get_param_part(config, '\0', &contp,
+ sep = get_param_part('\0', &contp,
&data, &type, &filename, &encoder, &headers);
if(sep < 0)
goto fail;
if(sep) {
*contp = (char) sep;
- warnf(config->global,
- "garbage at end of field specification: %s", contp);
+ warnf("garbage at end of field specification: %s", contp);
}
}
SET_TOOL_MIME_PTR(part, name);
}
else {
- warnf(config->global, "Illegally formatted input field");
+ warnf("Illegally formatted input field");
goto fail;
}
err = 0;
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 *global; /* For access from callback. */
};
size_t tool_mime_stdin_read(char *buffer,
size_t size, size_t nitems, void *arg);
int tool_mime_stdin_seek(void *instream, curl_off_t offset, int whence);
-int formparse(struct OperationConfig *config,
- const char *input,
+int formparse(const char *input,
struct tool_mime **mimeroot,
struct tool_mime **mimecurrent,
bool literal_value);
/* Get a size parameter for '--limit-rate' or '--max-filesize'.
* We support a 'G', 'M' or 'K' suffix too.
*/
-static ParameterError GetSizeParameter(struct GlobalConfig *global,
- const char *arg,
+static ParameterError GetSizeParameter(const char *arg,
const char *which,
curl_off_t *value_out)
{
curl_off_t value;
if(curlx_str_number(&unit, &value, CURL_OFF_T_MAX)) {
- warnf(global, "invalid number specified for %s", which);
+ warnf("invalid number specified for %s", which);
return PARAM_BAD_USE;
}
/* for plain bytes, leave as-is */
break;
default:
- warnf(global, "unsupported %s unit. Use G, M, K or B", which);
+ warnf("unsupported %s unit. Use G, M, K or B", which);
return PARAM_BAD_USE;
}
*value_out = value;
#define MAX_DATAURLENCODE (500*1024*1024)
/* --data-urlencode */
-static ParameterError data_urlencode(struct GlobalConfig *global,
- const char *nextarg,
+static ParameterError data_urlencode(const char *nextarg,
char **postp,
size_t *lenp)
{
else {
file = fopen(p, "rb");
if(!file) {
- errorf(global, "Failed to open %s", p);
+ errorf("Failed to open %s", p);
return PARAM_READ_ERROR;
}
}
{
if(config->httpversion &&
(config->httpversion != httpversion))
- warnf(config->global, "Overrides previous HTTP version option");
+ warnf("Overrides previous HTTP version option");
config->httpversion = httpversion;
}
-static CURLcode set_trace_config(struct GlobalConfig *global,
- const char *token)
+static CURLcode set_trace_config(const char *token)
{
CURLcode result = CURLE_OK;
const char *next, *name;
err = PARAM_NO_MEM;
}
else
- err = data_urlencode(config->global, nextarg, &query, &size);
+ err = data_urlencode(nextarg, &query, &size);
if(!err) {
if(config->query) {
FILE *file;
size_t size = 0;
ParameterError err = PARAM_OK;
- struct GlobalConfig *global = config->global;
if(cmd == C_DATA_URLENCODE) { /* --data-urlencode */
- err = data_urlencode(global, nextarg, &postdata, &size);
+ err = data_urlencode(nextarg, &postdata, &size);
if(err)
return err;
}
else {
file = fopen(nextarg, "rb");
if(!file) {
- errorf(global, "Failed to open %s", nextarg);
+ errorf("Failed to open %s", nextarg);
return PARAM_READ_ERROR;
}
}
return err;
}
-static ParameterError set_rate(struct GlobalConfig *global,
- const char *nextarg)
+static ParameterError set_rate(const char *nextarg)
{
/* --rate */
/* support a few different suffixes, extract the suffix first, then
numerator = 24*60*60*1000;
break;
default:
- errorf(global, "unsupported --rate unit");
+ errorf("unsupported --rate unit");
err = PARAM_BAD_USE;
break;
}
if((LONG_MAX / numerator) < numunits) {
/* overflow, too large number */
- errorf(global, "too large --rate unit");
+ errorf("too large --rate unit");
err = PARAM_NUMBER_TOO_LARGE;
}
/* this typecast is okay based on the check above */
url->useremote = url->noglob = TRUE;
if(!err && (++config->num_urls > 1) &&
(config->etag_save_file || config->etag_compare_file)) {
- errorf(config->global, "The etag options only work on a single URL");
+ errorf("The etag options only work on a single URL");
return PARAM_BAD_USE;
}
}
static ParameterError parse_continue_at(struct OperationConfig *config,
const char *nextarg)
{
- struct GlobalConfig *global = config->global;
ParameterError err = PARAM_OK;
if(config->range) {
- errorf(global, "--continue-at is mutually exclusive with --range");
+ errorf("--continue-at is mutually exclusive with --range");
return PARAM_BAD_USE;
}
if(config->rm_partial) {
- errorf(config->global,
- "--continue-at is mutually exclusive with --remove-on-error");
+ errorf("--continue-at is mutually exclusive with --remove-on-error");
return PARAM_BAD_USE;
}
if(config->file_clobber_mode == CLOBBER_NEVER) {
- errorf(config->global,
- "--continue-at is mutually exclusive with --no-clobber");
+ errorf("--continue-at is mutually exclusive with --no-clobber");
return PARAM_BAD_USE;
}
/* This makes us continue an ftp transfer at given position */
file = fopen(nextarg, FOPEN_READTEXT);
}
if(!file) {
- warnf(config->global,
- "Couldn't read file \"%s\" "
+ warnf("Couldn't read file \"%s\" "
"specified for \"--ech ecl:\" option",
nextarg);
return PARAM_BAD_USE; /* */
bool use_stdin = !strcmp(&nextarg[1], "-");
FILE *file = use_stdin ? stdin : fopen(&nextarg[1], FOPEN_READTEXT);
if(!file) {
- errorf(config->global, "Failed to open %s", &nextarg[1]);
+ errorf("Failed to open %s", &nextarg[1]);
err = PARAM_READ_ERROR;
}
else {
ParameterError err = PARAM_OK;
curl_off_t value;
const char *orig = nextarg;
- struct GlobalConfig *global = config->global;
if(config->use_resume) {
- errorf(global, "--continue-at is mutually exclusive with --range");
+ errorf("--continue-at is mutually exclusive with --range");
return PARAM_BAD_USE;
}
if(!curlx_str_number(&nextarg, &value, CURL_OFF_T_MAX) &&
claimed that to be a good way, why this code is added to work-around
it. */
char buffer[32];
- warnf(global, "A specified range MUST include at least one dash (-). "
+ warnf("A specified range MUST include at least one dash (-). "
"Appending one for you");
msnprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-",
value);
/* byte range requested */
while(*nextarg) {
if(!ISDIGIT(*nextarg) && *nextarg != '-' && *nextarg != ',') {
- warnf(global, "Invalid character is found in given range. "
+ warnf("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.");
static size_t verbose_nopts;
-static ParameterError parse_verbose(struct GlobalConfig *global,
- bool toggle)
+static ParameterError parse_verbose(bool toggle)
{
ParameterError err = PARAM_OK;
* more than once in the same argument flag, like `-vvv`. */
if(!toggle) {
global->verbosity = 0;
- if(set_trace_config(global, "-all"))
+ if(set_trace_config("-all"))
err = PARAM_NO_MEM;
global->tracetype = TRACE_NONE;
return err;
else if(!verbose_nopts) {
/* fist `-v` in an argument resets to base verbosity */
global->verbosity = 0;
- if(set_trace_config(global, "-all"))
+ if(set_trace_config("-all"))
return PARAM_NO_MEM;
}
/* the '%' thing here will cause the trace get sent to stderr */
err = PARAM_NO_MEM;
else {
if(global->tracetype && (global->tracetype != TRACE_PLAIN))
- warnf(global,
- "-v, --verbose overrides an earlier trace option");
+ warnf("-v, --verbose overrides an earlier trace option");
global->tracetype = TRACE_PLAIN;
}
break;
case 1:
global->verbosity = 2;
- if(set_trace_config(global, "ids,time,protocol"))
+ if(set_trace_config("ids,time,protocol"))
err = PARAM_NO_MEM;
break;
case 2:
global->verbosity = 3;
global->tracetype = TRACE_ASCII;
- if(set_trace_config(global, "ssl,read,write"))
+ if(set_trace_config("ssl,read,write"))
err = PARAM_NO_MEM;
break;
case 3:
global->verbosity = 4;
- if(set_trace_config(global, "network"))
+ if(set_trace_config("network"))
err = PARAM_NO_MEM;
break;
default:
fname = nextarg;
file = fopen(fname, FOPEN_READTEXT);
if(!file) {
- errorf(config->global, "Failed to open %s", fname);
+ errorf("Failed to open %s", fname);
return PARAM_READ_ERROR;
}
}
if(err)
return err;
if(!config->writeout)
- warnf(config->global, "Failed to read %s", fname);
+ warnf("Failed to read %s", fname);
}
else
err = getstr(&config->writeout, nextarg, ALLOW_BLANK);
if(config->condtime == -1) {
curl_off_t value;
/* now let's see if it is a filename to get the time from instead! */
- int rc = getfiletime(nextarg, config->global, &value);
+ int rc = getfiletime(nextarg, &value);
if(!rc)
/* pull the time out from the file */
config->condtime = value;
else {
/* failed, remove time condition */
config->timecond = CURL_TIMECOND_NONE;
- warnf(config->global,
- "Illegal date format for -z, --time-cond (and not "
+ warnf("Illegal date format for -z, --time-cond (and not "
"a filename). Disabling time condition. "
"See curl_getdate(3) for valid date syntax.");
}
}
/* opt_depr is the function that handles ARG_DEPR options */
-static void opt_depr(struct GlobalConfig *global,
- const struct LongShort *a)
+static void opt_depr(const struct LongShort *a)
{
- warnf(global, "--%s is deprecated and has no function anymore", a->lname);
+ warnf("--%s is deprecated and has no function anymore", a->lname);
}
static ParameterError opt_sslver(struct OperationConfig *config,
{
if(config->ssl_version_max &&
(config->ssl_version_max < ver)) {
- errorf(config->global, "Minimum TLS version set higher than max");
+ errorf("Minimum TLS version set higher than max");
return PARAM_BAD_USE;
}
config->ssl_version = ver;
const struct LongShort *a,
bool toggle)
{
- struct GlobalConfig *global = config->global;
switch(a->cmd) {
case C_ALPN: /* --alpn */
config->noalpn = !toggle;
case C_SSL: /* --ssl */
config->ftp_ssl = toggle;
if(config->ftp_ssl)
- warnf(global, "--%s is an insecure option, consider --ssl-reqd instead",
+ warnf("--%s is an insecure option, consider --ssl-reqd instead",
a->lname);
break;
case C_FTP_SSL_CCC: /* --ftp-ssl-ccc */
config->doh_verifystatus = toggle;
break;
case C_FALSE_START: /* --false-start */
- opt_depr(global, a);
+ opt_depr(a);
break;
case C_SSL_NO_REVOKE: /* --ssl-no-revoke */
config->ssl_no_revoke = toggle;
case C_FAIL_WITH_BODY: /* --fail-with-body */
config->failwithbody = toggle;
if(config->failonerror && config->failwithbody) {
- errorf(config->global, "You must select either --fail or "
+ errorf("You must select either --fail or "
"--fail-with-body, not both.");
return PARAM_BAD_USE;
}
break;
case C_REMOVE_ON_ERROR: /* --remove-on-error */
if(config->use_resume && toggle) {
- errorf(config->global,
- "--continue-at is mutually exclusive with --remove-on-error");
+ errorf("--continue-at is mutually exclusive with --remove-on-error");
return PARAM_BAD_USE;
}
config->rm_partial = toggle;
case C_FAIL: /* --fail */
config->failonerror = toggle;
if(config->failonerror && config->failwithbody) {
- errorf(config->global, "You must select either --fail or "
+ errorf("You must select either --fail or "
"--fail-with-body, not both.");
return PARAM_BAD_USE;
}
case C_HEAD: /* --head */
config->no_body = toggle;
config->show_headers = toggle;
- if(SetHTTPrequest(config, (config->no_body) ? TOOL_HTTPREQ_HEAD :
+ if(SetHTTPrequest((config->no_body) ? TOOL_HTTPREQ_HEAD :
TOOL_HTTPREQ_GET, &config->httpreq))
return PARAM_BAD_USE;
break;
break;
case C_CLOBBER: /* --clobber */
if(config->use_resume && !toggle) {
- errorf(config->global,
- "--continue-at is mutually exclusive with --no-clobber");
+ errorf("--continue-at is mutually exclusive with --no-clobber");
return PARAM_BAD_USE;
}
config->file_clobber_mode = toggle ? CLOBBER_ALWAYS : CLOBBER_NEVER;
global->showerror = toggle;
break;
case C_VERBOSE: /* --verbose */
- return parse_verbose(global, toggle);
+ return parse_verbose(toggle);
break;
case C_VERSION: /* --version */
if(toggle) /* --no-version yields no output! */
FALLTHROUGH();
case C_LOCATION: /* --location */
if(config->followlocation == CURLFOLLOW_OBEYCODE)
- warnf(global, "--location overrides --follow");
+ warnf("--location overrides --follow");
config->followlocation = toggle ? CURLFOLLOW_ALL : 0;
break;
case C_FOLLOW: /* --follow */
if(config->followlocation == CURLFOLLOW_ALL)
- warnf(global, "--follow overrides --location");
+ warnf("--follow overrides --location");
config->followlocation = toggle ? CURLFOLLOW_OBEYCODE : 0;
break;
default:
ParameterError err = PARAM_OK;
curl_off_t value;
long val;
- struct GlobalConfig *global = config->global;
static const char *redir_protos[] = {
"http",
"https",
err = getstr(&global->trace_dump, nextarg, DENY_BLANK);
if(!err) {
if(global->tracetype && (global->tracetype != TRACE_BIN))
- warnf(global, "--trace overrides an earlier trace/verbose option");
+ warnf("--trace overrides an earlier trace/verbose option");
global->tracetype = TRACE_BIN;
}
break;
err = getstr(&global->trace_dump, nextarg, DENY_BLANK);
if(!err) {
if(global->tracetype && (global->tracetype != TRACE_ASCII))
- warnf(global,
- "--trace-ascii overrides an earlier trace/verbose option");
+ warnf("--trace-ascii overrides an earlier trace/verbose option");
global->tracetype = TRACE_ASCII;
}
break;
case C_LIMIT_RATE: /* --limit-rate */
- err = GetSizeParameter(global, nextarg, "rate", &value);
+ err = GetSizeParameter(nextarg, "rate", &value);
if(!err) {
config->recvpersecond = value;
config->sendpersecond = value;
}
break;
case C_RATE:
- err = set_rate(global, nextarg);
+ err = set_rate(nextarg);
break;
case C_CREATE_FILE_MODE: /* --create-file-mode */
err = oct2nummax(&config->create_file_mode, nextarg, 0777);
err = getstr(&config->aws_sigv4, nextarg, ALLOW_BLANK);
break;
case C_STDERR: /* --stderr */
- tool_set_stderr_file(global, nextarg);
+ tool_set_stderr_file(nextarg);
break;
case C_INTERFACE: /* --interface */
/* interface */
err = getstr(&config->haproxy_clientip, nextarg, DENY_BLANK);
break;
case C_MAX_FILESIZE: /* --max-filesize */
- err = GetSizeParameter(global, nextarg, "max-filesize", &value);
+ err = GetSizeParameter(nextarg, "max-filesize", &value);
if(!err)
config->max_filesize = value;
break;
err = getstr(&config->ftp_account, nextarg, DENY_BLANK);
break;
case C_FTP_METHOD: /* --ftp-method */
- config->ftp_filemethod = ftpfilemethod(config, nextarg);
+ config->ftp_filemethod = ftpfilemethod(nextarg);
break;
case C_LOCAL_PORT: /* --local-port */
err = parse_localport(config, nextarg);
break;
case C_LIBCURL: /* --libcurl */
#ifdef CURL_DISABLE_LIBCURL_OPTION
- warnf(global,
- "--libcurl option was disabled at build-time");
+ warnf("--libcurl option was disabled at build-time");
err = PARAM_OPTION_UNKNOWN;
#else
err = getstr(&global->libcurl, nextarg, DENY_BLANK);
break;
case C_PROTO: /* --proto */
config->proto_present = TRUE;
- err = proto2num(config, built_in_protos, &config->proto_str, nextarg);
+ err = proto2num(built_in_protos, &config->proto_str, nextarg);
break;
case C_PROTO_REDIR: /* --proto-redir */
config->proto_redir_present = TRUE;
- if(proto2num(config, redir_protos, &config->proto_redir_str,
- nextarg))
+ if(proto2num(redir_protos, &config->proto_redir_str, nextarg))
err = PARAM_BAD_USE;
break;
case C_RESOLVE: /* --resolve */
err = add2list(&config->resolve, nextarg);
break;
case C_DELEGATION: /* --delegation */
- config->gssapi_delegation = delegation(config, nextarg);
+ config->gssapi_delegation = delegation(nextarg);
break;
case C_MAIL_AUTH: /* --mail-auth */
err = getstr(&config->mail_auth, nextarg, DENY_BLANK);
case C_TLS_MAX: /* --tls-max */
err = str2tls_max(&config->ssl_version_max, nextarg);
if(!err && (config->ssl_version_max < config->ssl_version)) {
- errorf(global, "--tls-max set lower than minimum accepted version");
+ errorf("--tls-max set lower than minimum accepted version");
err = PARAM_BAD_USE;
}
break;
/* 0 is a valid value for this timeout */
break;
case C_TRACE_CONFIG: /* --trace-config */
- if(set_trace_config(global, nextarg))
+ if(set_trace_config(nextarg))
err = PARAM_NO_MEM;
break;
case C_VARIABLE: /* --variable */
- err = setvariable(global, nextarg);
+ err = setvariable(nextarg);
break;
case C_TLS13_CIPHERS: /* --tls13-ciphers */
err = getstr(&config->cipher13_list, nextarg, DENY_BLANK);
break;
case C_ETAG_SAVE: /* --etag-save */
if(config->num_urls > 1) {
- errorf(global, "The etag options only work on a single URL");
+ errorf("The etag options only work on a single URL");
err = PARAM_BAD_USE;
}
else
break;
case C_ETAG_COMPARE: /* --etag-compare */
if(config->num_urls > 1) {
- errorf(global, "The etag options only work on a single URL");
+ errorf("The etag options only work on a single URL");
err = PARAM_BAD_USE;
}
else
case C_FORM_STRING: /* --form-string */
/* "form data" simulation, this is a little advanced so lets do our best
to sort this out slowly and carefully */
- if(formparse(config,
- nextarg,
- &config->mimeroot,
- &config->mimecurrent,
+ if(formparse(nextarg, &config->mimeroot, &config->mimecurrent,
(a->cmd == C_FORM_STRING))) /* literal string */
err = PARAM_BAD_USE;
- else if(SetHTTPrequest(config, TOOL_HTTPREQ_MIMEPOST, &config->httpreq))
+ else if(SetHTTPrequest(TOOL_HTTPREQ_MIMEPOST, &config->httpreq))
err = PARAM_BAD_USE;
break;
case C_REQUEST_TARGET: /* --request-target */
err = parse_header(config, (cmdline_t)a->cmd, nextarg);
break;
case C_CONFIG: /* --config */
- if(parseconfig(nextarg, global)) {
- errorf(global, "cannot read config from '%s'", nextarg);
+ if(parseconfig(nextarg)) {
+ errorf("cannot read config from '%s'", nextarg);
err = PARAM_READ_ERROR;
}
break;
break;
case C_FTP_SSL_CCC_MODE: /* --ftp-ssl-ccc-mode */
config->ftp_ssl_ccc = TRUE;
- config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
+ config->ftp_ssl_ccc_mode = ftpcccmethod(nextarg);
break;
case C_QUOTE: /* --quote */
err = parse_quote(config, nextarg);
bool nextalloc = FALSE; /* if nextarg is allocated */
bool consumearg = TRUE; /* the argument comes separate */
const struct LongShort *a = NULL;
- struct GlobalConfig *global = config->global;
verbose_nopts = 0; /* options processed in `flag`*/
*usedarg = FALSE; /* default is that we do not use the arg */
err = PARAM_EXPAND_ERROR;
goto error;
}
- err = varexpand(global, nextarg, &nbuf, &replaced);
+ err = varexpand(nextarg, &nbuf, &replaced);
if(err) {
curlx_dyn_free(&nbuf);
goto error;
*usedarg = consumearg; /* mark it as used */
}
if(a->desc & ARG_DEPR) {
- opt_depr(global, a);
+ opt_depr(a);
break;
}
if((ARGTYPE(a->desc) == ARG_FILE) &&
(nextarg[0] == '-') && nextarg[1]) {
/* if the filename looks like a command line option */
- warnf(global, "The filename argument '%s' looks like a flag.",
+ warnf("The filename argument '%s' looks like a flag.",
nextarg);
}
else if(!strncmp("\xe2\x80\x9c", nextarg, 3)) {
- warnf(global, "The argument '%s' starts with a Unicode quote where "
+ warnf("The argument '%s' starts with a Unicode quote where "
"maybe an ASCII \" was intended?",
nextarg);
}
}
else {
if(a->desc & ARG_DEPR) {
- opt_depr(global, a);
+ opt_depr(a);
break;
}
/* ARG_NONE | ARG_BOOL */
return err;
}
-ParameterError parse_args(struct GlobalConfig *global, int argc,
- argv_item_t argv[])
+ParameterError parse_args(int argc, argv_item_t argv[])
{
int i;
bool stillflags;
if(config->url_list && config->url_list->url) {
/* Allocate the next config */
- config->next = config_alloc(global);
+ config->next = config_alloc();
if(config->next) {
/* Update the last config pointer */
global->last = config->next;
result = PARAM_NO_MEM;
}
else {
- errorf(global, "missing URL before --next");
+ errorf("missing URL before --next");
result = PARAM_BAD_USE;
}
}
PARAM_LAST
} ParameterError;
-struct GlobalConfig;
struct OperationConfig;
const struct LongShort *findlongopt(const char *opt);
char **passphrase);
#endif
-ParameterError parse_args(struct GlobalConfig *global, int argc,
- argv_item_t argv[]);
+ParameterError parse_args(int argc, argv_item_t argv[]);
#if defined(UNICODE) && defined(_WIN32) && !defined(UNDER_CE)
}
}
-int SetHTTPrequest(struct OperationConfig *config, HttpReq req, HttpReq *store)
+int SetHTTPrequest(HttpReq req, HttpReq *store)
{
/* this mirrors the HttpReq enum in tool_sdecls.h */
const char *reqname[]= {
*store = req;
return 0;
}
- warnf(config->global, "You can only select one HTTP request method! "
+ warnf("You can only select one HTTP request method! "
"You asked for both %s and %s.",
reqname[req], reqname[*store]);
return 1;
}
-void customrequest_helper(struct OperationConfig *config, HttpReq req,
- char *method)
+void customrequest_helper(HttpReq req, char *method)
{
/* this mirrors the HttpReq enum in tool_sdecls.h */
const char *dflt[]= {
if(!method)
;
else if(curl_strequal(method, dflt[req])) {
- notef(config->global, "Unnecessary use of -X or --request, %s is already "
+ notef("Unnecessary use of -X or --request, %s is already "
"inferred.", dflt[req]);
}
else if(curl_strequal(method, "head")) {
- warnf(config->global,
- "Setting custom HTTP method to HEAD with -X/--request may not work "
+ warnf("Setting custom HTTP method to HEAD with -X/--request may not work "
"the way you want. Consider using -I/--head instead.");
}
}
#include "tool_setup.h"
const char *param2text(ParameterError error);
-
-int SetHTTPrequest(struct OperationConfig *config, HttpReq req,
- HttpReq *store);
-
-void customrequest_helper(struct OperationConfig *config, HttpReq req,
- char *method);
+int SetHTTPrequest(HttpReq req, HttpReq *store);
+void customrequest_helper(HttpReq req, char *method);
#endif /* HEADER_CURL_TOOL_HELPERS_H */
# define memory_tracking_init() tool_nop_stmt
#endif
-/*
- * This is the main global constructor for the app. Call this before
- * _any_ libcurl usage. If this fails, *NO* libcurl functions may be
- * used, or havoc may be the result.
- */
-static CURLcode main_init(struct GlobalConfig *global)
-{
- CURLcode result = CURLE_OK;
-
-#ifdef __DJGPP__
- /* stop stat() wasting time */
- _djstat_flags |= _STAT_INODE | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
-#endif
-
- /* Initialise the global config */
- global->showerror = FALSE; /* show errors when silent */
- global->styled_output = TRUE; /* enable detection */
- global->parallel_max = PARALLEL_DEFAULT;
-
- /* Allocate the initial operate config */
- 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) {
- errorf(global, "error retrieving curl library information");
- free(global->first);
- }
- }
- else {
- errorf(global, "error initializing curl library");
- free(global->first);
- }
- }
- else {
- errorf(global, "error initializing curl");
- result = CURLE_FAILED_INIT;
- }
-
- return result;
-}
-
-static void free_globalconfig(struct GlobalConfig *global)
-{
- tool_safefree(global->trace_dump);
-
- if(global->trace_fopened && global->trace_stream)
- fclose(global->trace_stream);
- global->trace_stream = NULL;
-
- tool_safefree(global->libcurl);
-}
-
-/*
- * This is the main global destructor for the app. Call this after _all_
- * libcurl usage is done.
- */
-static void main_free(struct GlobalConfig *global)
-{
- /* Cleanup the easy handle */
- /* Main cleanup */
- curl_global_cleanup();
- free_globalconfig(global);
-
- /* Free the OperationConfig structures */
- config_free(global->last);
- global->first = NULL;
- global->last = NULL;
-}
-
/*
** curl tool main function.
*/
#endif
{
CURLcode result = CURLE_OK;
- struct GlobalConfig global;
- memset(&global, 0, sizeof(global));
tool_init_stderr();
/* win32_init must be called before other init routines. */
result = win32_init();
if(result) {
- errorf(&global, "(%d) Windows-specific init failed", result);
+ errorf("(%d) Windows-specific init failed", result);
return (int)result;
}
#endif
if(main_checkfds()) {
- errorf(&global, "out of file descriptors");
+ errorf("out of file descriptors");
return CURLE_FAILED_INIT;
}
/* Initialize the curl library - do not call any libcurl functions before
this point */
- result = main_init(&global);
+ result = globalconf_init();
if(!result) {
/* Start our curl operation */
- result = operate(&global, argc, argv);
+ result = operate(argc, argv);
/* Perform the main cleanup */
- main_free(&global);
+ globalconf_free();
}
#ifdef _WIN32
#define NOTE_PREFIX "Note: "
#define ERROR_PREFIX "curl: "
-static void voutf(struct GlobalConfig *global,
- const char *prefix,
+static void voutf(const char *prefix,
const char *fmt,
- va_list ap) CURL_PRINTF(3, 0);
+ va_list ap) CURL_PRINTF(2, 0);
-static void voutf(struct GlobalConfig *global,
- const char *prefix,
+static void voutf(const char *prefix,
const char *fmt,
va_list ap)
{
* Emit 'note' formatted message on configured 'errors' stream, if verbose was
* selected.
*/
-void notef(struct GlobalConfig *global, const char *fmt, ...)
+void notef(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if(global->tracetype)
- voutf(global, NOTE_PREFIX, fmt, ap);
+ voutf(NOTE_PREFIX, fmt, ap);
va_end(ap);
}
* Emit warning formatted message on configured 'errors' stream unless
* mute (--silent) was selected.
*/
-void warnf(struct GlobalConfig *global, const char *fmt, ...)
+void warnf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- voutf(global, WARN_PREFIX, fmt, ap);
+ voutf(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 *global, const char *fmt, ...)
+void errorf(const char *fmt, ...)
{
if(!global->silent || global->showerror) {
va_list ap;
va_start(ap, fmt);
- voutf(global, ERROR_PREFIX, fmt, ap);
+ voutf(ERROR_PREFIX, fmt, ap);
va_end(ap);
}
}
#include "tool_setup.h"
#include "tool_cfgable.h"
-void warnf(struct GlobalConfig *global, const char *fmt, ...)
- CURL_PRINTF(2, 3);
-void notef(struct GlobalConfig *global, const char *fmt, ...)
- CURL_PRINTF(2, 3);
+void warnf(const char *fmt, ...)
+ CURL_PRINTF(1, 2);
+void notef(const char *fmt, ...)
+ CURL_PRINTF(1, 2);
void helpf(FILE *errors, const char *fmt, ...)
CURL_PRINTF(2, 3);
-void errorf(struct GlobalConfig *global, const char *fmt, ...)
- CURL_PRINTF(2, 3);
+void errorf(const char *fmt, ...)
+ CURL_PRINTF(1, 2);
#endif /* HEADER_CURL_TOOL_MSGS_H */
CURLSH *share,
bool *added,
bool *skipped);
-static CURLcode create_transfer(struct GlobalConfig *global,
- CURLSH *share,
+static CURLcode create_transfer(CURLSH *share,
bool *added,
bool *skipped);
curl_off_t uploadfilesize = -1;
struct_stat fileinfo;
CURLcode result = CURLE_OK;
-#ifndef CURL_DISABLE_LIBCURL_OPTION
- struct OperationConfig *config = per->config;
-#endif
if(per->uploadfile && !stdin_upload(per->uploadfile)) {
/* VMS Note:
if((CURL_OFF_T_MAX - sleeptime < ms) ||
(ms + sleeptime > config->retry_maxtime_ms)) {
- warnf(config->global, "The Retry-After: time would "
+ warnf("The Retry-After: time would "
"make this command line exceed the maximum allowed time "
"for retries.");
*retryp = FALSE;
}
}
}
- warnf(config->global, "Problem %s. "
+ warnf("Problem %s. "
"Will retry in %ld second%s. "
"%ld retr%s left.",
m[retry], sleeptime/1000L,
int rc;
/* We have written data to an output file, we truncate file */
fflush(outs->stream);
- notef(config->global,
- "Throwing away %" CURL_FORMAT_CURL_OFF_T " bytes",
+ notef("Throwing away %" CURL_FORMAT_CURL_OFF_T " bytes",
outs->bytes);
/* truncate file at the position where we started appending */
#if defined(HAVE_FTRUNCATE) && !defined(__DJGPP__) && !defined(__AMIGA__) && \
if(ftruncate(fileno(outs->stream), outs->init)) {
/* when truncate fails, we cannot just append as then we will
create something strange, bail out */
- errorf(config->global, "Failed to truncate file");
+ errorf("Failed to truncate file");
return CURLE_WRITE_ERROR;
}
/* now seek to the end of the file, the position where we
rc = fseek(outs->stream, (long)outs->init, SEEK_SET);
#endif
if(rc) {
- errorf(config->global, "Failed seeking to end of file");
+ errorf("Failed seeking to end of file");
return CURLE_WRITE_ERROR;
}
outs->bytes = 0; /* clear for next round */
/*
* Call this after a transfer has completed.
*/
-static CURLcode post_per_transfer(struct GlobalConfig *global,
- struct per_transfer *per,
+static CURLcode post_per_transfer(struct per_transfer *per,
CURLcode result,
bool *retryp,
long *delay) /* milliseconds! */
#if defined(_WIN32) && !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE)
sclose(per->infd);
#else
- warnf(per->config->global, "Closing per->infd != 0: FD == "
+ warnf("Closing per->infd != 0: FD == "
"%d. This behavior is only supported on desktop "
" Windows", per->infd);
#endif
if(!result && config->xattr && outs->fopened && outs->stream) {
rc = fwrite_xattr(curl, per->url, fileno(outs->stream));
if(rc)
- warnf(config->global, "Error setting extended attributes on '%s': %s",
+ warnf("Error setting extended attributes on '%s': %s",
outs->filename, strerror(errno));
}
if(!result && rc) {
/* something went wrong in the writing process */
result = CURLE_WRITE_ERROR;
- errorf(global, "Failed writing body");
+ errorf("Failed writing body");
}
}
if(!result && rc) {
/* something went wrong in the writing process */
result = CURLE_WRITE_ERROR;
- errorf(config->global, "curl: (%d) Failed writing body", result);
+ errorf("curl: (%d) Failed writing body", result);
}
if(result && config->rm_partial) {
struct_stat st;
if(!stat(outs->filename, &st) &&
S_ISREG(st.st_mode)) {
if(!unlink(outs->filename))
- notef(global, "Removed output file: %s", outs->filename);
+ notef("Removed output file: %s", outs->filename);
else
- warnf(global, "Failed removing: %s", outs->filename);
+ warnf("Failed removing: %s", outs->filename);
}
else
- warnf(global, "Skipping removal; not a regular file: %s",
+ warnf("Skipping removal; not a regular file: %s",
outs->filename);
}
}
/* Ask libcurl if we got a remote file time */
curl_off_t filetime = -1;
curl_easy_getinfo(curl, CURLINFO_FILETIME_T, &filetime);
- setfiletime(filetime, outs->filename, global);
+ setfiletime(filetime, outs->filename);
}
skip:
/* Write the --write-out data before cleanup but after result is final */
CURLU_GUESS_SCHEME);
if(uerr) {
result = urlerr_cvt(uerr);
- errorf(config->global, "(%d) Could not parse the URL, "
+ errorf("(%d) Could not parse the URL, "
"failed to set query", result);
config->synthetic_error = TRUE;
}
/* open file for reading: */
FILE *file = fopen(config->etag_compare_file, FOPEN_READTEXT);
if(!file)
- warnf(config->global, "Failed to open %s: %s", config->etag_compare_file,
+ warnf("Failed to open %s: %s", config->etag_compare_file,
strerror(errno));
if((PARAM_OK == file2string(&etag_from_file, file)) &&
if(!header) {
if(file)
fclose(file);
- errorf(config->global,
- "Failed to allocate memory for custom etag header");
+ errorf("Failed to allocate memory for custom etag header");
return CURLE_OUT_OF_MEMORY;
}
bool *skip)
{
if(config->create_dirs) {
- CURLcode result = create_dir_hierarchy(config->etag_save_file,
- config->global);
+ CURLcode result = create_dir_hierarchy(config->etag_save_file);
if(result)
return result;
}
FILE *newfile = fopen(config->etag_save_file, "ab");
if(!newfile) {
struct State *state = &config->state;
- warnf(config->global, "Failed creating file for saving etags: \"%s\". "
+ warnf("Failed creating file for saving etags: \"%s\". "
"Skip this transfer", config->etag_save_file);
state->outfiles = NULL;
glob_cleanup(&state->urlglob);
* that it does not need to be opened/closed for every transfer.
*/
if(config->create_dirs) {
- CURLcode result = create_dir_hierarchy(config->headerfile,
- config->global);
+ CURLcode result = create_dir_hierarchy(config->headerfile);
/* create_dir_hierarchy shows error upon CURLE_WRITE_ERROR */
if(result)
return result;
newfile = fopen(config->headerfile, "ab");
if(!newfile) {
- errorf(config->global, "Failed to open %s", config->headerfile);
+ errorf("Failed to open %s", config->headerfile);
return CURLE_WRITE_ERROR;
}
else {
* decided we want to use the remote filename.
*/
struct State *state = &config->state;
- struct GlobalConfig *global = config->global;
if(!per->outfile) {
/* extract the filename from the URL */
- CURLcode result = get_url_file_name(global, &per->outfile, per->url);
+ CURLcode result = get_url_file_name(&per->outfile, per->url);
if(result) {
- errorf(global, "Failed to extract a filename"
+ errorf("Failed to extract a filename"
" from the URL to use for storage");
return result;
}
tool_safefree(storefile);
if(result) {
/* bad globbing */
- warnf(global, "bad output glob");
+ warnf("bad output glob");
return result;
}
if(!*per->outfile) {
- warnf(global, "output glob produces empty string");
+ warnf("output glob produces empty string");
return CURLE_WRITE_ERROR;
}
}
file output call */
if(config->create_dirs) {
- CURLcode result = create_dir_hierarchy(per->outfile, global);
+ CURLcode result = create_dir_hierarchy(per->outfile);
/* create_dir_hierarchy shows error upon CURLE_WRITE_ERROR */
if(result)
return result;
struct_stat fileinfo;
if(!stat(per->outfile, &fileinfo)) {
/* file is present */
- notef(global, "skips transfer, \"%s\" exists locally",
- per->outfile);
+ notef("skips transfer, \"%s\" exists locally", per->outfile);
per->skip = TRUE;
*skipped = TRUE;
}
FILE *file = fopen(per->outfile, "ab");
#endif
if(!file) {
- errorf(global, "cannot open '%s'", per->outfile);
+ errorf("cannot open '%s'", per->outfile);
return CURLE_WRITE_ERROR;
}
outs->fopened = TRUE;
static void check_stdin_upload(struct OperationConfig *config,
struct per_transfer *per)
{
- struct GlobalConfig *global = config->global;
/* count to see if there are more than one auth bit set
in the authtype field */
int authbits = 0;
* we should warn them.
*/
if(config->proxyanyauth || (authbits > 1)) {
- warnf(global,
- "Using --anyauth or --proxy-anyauth with upload from stdin"
+ warnf("Using --anyauth or --proxy-anyauth with upload from stdin"
" involves a big risk of it not working. Use a temporary"
" file or a fixed auth type instead");
}
/* non-blocking stdin behavior on Windows is challenging
Spawn a new thread that will read from stdin and write
out to a socket */
- curl_socket_t f = win32_stdin_read_thread(global);
+ curl_socket_t f = win32_stdin_read_thread();
if(f == CURL_SOCKET_BAD)
- warnf(global, "win32_stdin_read_thread returned INVALID_SOCKET "
+ warnf("win32_stdin_read_thread returned INVALID_SOCKET "
"falling back to blocking mode");
else if(f > INT_MAX) {
- warnf(global, "win32_stdin_read_thread returned identifier "
+ warnf("win32_stdin_read_thread returned identifier "
"larger than INT_MAX. This should not happen unless "
"the upper 32 bits of a Windows socket have started "
"being used for something... falling back to blocking "
per->infd = (int)f;
#endif
if(curlx_nonblock((curl_socket_t)per->infd, TRUE) < 0)
- warnf(global,
- "fcntl failed on fd=%d: %s", per->infd, strerror(errno));
+ warnf("fcntl failed on fd=%d: %s", per->infd, strerror(errno));
}
}
bool *skipped)
{
CURLcode result = CURLE_OK;
- struct GlobalConfig *global = config->global;
bool orig_noprogress = global->noprogress;
bool orig_isatty = global->isatty;
struct State *state = &config->state;
/* Use the postfields data for an HTTP get */
httpgetfields = state->httpgetfields = config->postfields;
config->postfields = NULL;
- if(SetHTTPrequest(config, (config->no_body ? TOOL_HTTPREQ_HEAD :
- TOOL_HTTPREQ_GET), &config->httpreq))
+ if(SetHTTPrequest((config->no_body ? TOOL_HTTPREQ_HEAD :
+ TOOL_HTTPREQ_GET), &config->httpreq))
return CURLE_FAILED_INIT;
}
}
- else if(SetHTTPrequest(config, TOOL_HTTPREQ_SIMPLEPOST, &config->httpreq))
+ else if(SetHTTPrequest(TOOL_HTTPREQ_SIMPLEPOST, &config->httpreq))
return CURLE_FAILED_INIT;
}
/* u->url is the full URL or NULL */
if(!u->url) {
/* This node has no URL. End of the road. */
- warnf(config->global, "Got more output options than URLs");
+ warnf("Got more output options than URLs");
break;
}
if(glob_inuse(&state->inglob)) {
result = glob_next_url(&state->uploadfile, &state->inglob);
if(result == CURLE_OUT_OF_MEMORY)
- errorf(global, "out of memory");
+ errorf("out of memory");
}
else if(!state->up) {
/* copy the allocated string */
if(state->uploadfile) {
per->uploadfile = strdup(state->uploadfile);
if(!per->uploadfile ||
- SetHTTPrequest(config, TOOL_HTTPREQ_PUT, &config->httpreq)) {
+ SetHTTPrequest(TOOL_HTTPREQ_PUT, &config->httpreq)) {
tool_safefree(per->uploadfile);
curl_easy_cleanup(curl);
return CURLE_FAILED_INIT;
* to add even after this call returns. sets 'addedp' to TRUE if one or more
* transfers were added.
*/
-static CURLcode add_parallel_transfers(struct GlobalConfig *global,
- CURLM *multi,
- CURLSH *share,
- bool *morep,
- bool *addedp)
+static CURLcode add_parallel_transfers(CURLM *multi, CURLSH *share,
+ bool *morep, bool *addedp)
{
struct per_transfer *per;
CURLcode result = CURLE_OK;
if(nxfers < (curl_off_t)(global->parallel_max*2)) {
bool skipped = FALSE;
do {
- result = create_transfer(global, share, addedp, &skipped);
+ result = create_transfer(share, addedp, &skipped);
if(result)
return result;
} while(skipped);
bool getadded = FALSE;
bool skipped = FALSE;
do {
- result = create_transfer(global, share, &getadded, &skipped);
+ result = create_transfer(share, &getadded, &skipped);
if(result)
break;
} while(skipped);
}
struct parastate {
- struct GlobalConfig *global;
CURLM *multi;
CURLSH *share;
CURLMcode mcode;
uv->s->result = result;
if(uv->s->more_transfers) {
- result = add_parallel_transfers(uv->s->global, uv->s->multi,
- uv->s->share,
+ result = add_parallel_transfers(uv->s->multi, uv->s->share,
&uv->s->more_transfers,
&uv->s->added_transfers);
if(result && !uv->s->result)
curl_multi_setopt(s->multi, CURLMOPT_TIMERFUNCTION, cb_timeout);
curl_multi_setopt(s->multi, CURLMOPT_TIMERDATA, &uv);
curl_multi_setopt(s->multi, CURLMOPT_MAX_HOST_CONNECTIONS,
- s->global->parallel_host);
+ global->parallel_host);
/* kickstart the thing */
curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0,
}
if(s->more_transfers) {
- result = add_parallel_transfers(s->global, s->multi, s->share,
- &s->more_transfers, &s->added_transfers);
+ result = add_parallel_transfers(s->multi, s->share, &s->more_transfers,
+ &s->added_transfers);
if(result && !s->result)
s->result = result;
}
int rc;
CURLMsg *msg;
bool checkmore = FALSE;
- struct GlobalConfig *global = s->global;
- progress_meter(global, s->multi, &s->start, FALSE);
+ progress_meter(s->multi, &s->start, FALSE);
do {
msg = curl_multi_info_read(s->multi, &rc);
if(msg) {
"Transfer aborted due to critical error "
"in another transfer");
}
- tres = post_per_transfer(global, ended, tres, &retry, &delay);
+ tres = post_per_transfer(ended, tres, &retry, &delay);
progress_finalize(ended); /* before it goes away */
all_added--; /* one fewer added */
checkmore = TRUE;
}
if(checkmore) {
/* one or more transfers completed, add more! */
- CURLcode tres = add_parallel_transfers(global,
- s->multi, s->share,
+ CURLcode tres = add_parallel_transfers(s->multi, s->share,
&s->more_transfers,
&s->added_transfers);
if(tres)
return result;
}
-static CURLcode parallel_transfers(struct GlobalConfig *global,
- CURLSH *share)
+static CURLcode parallel_transfers(CURLSH *share)
{
CURLcode result;
struct parastate p;
s->wrapitup = FALSE;
s->wrapitup_processed = FALSE;
s->tick = time(NULL);
- s->global = global;
s->multi = curl_multi_init();
if(!s->multi)
return CURLE_OUT_OF_MEMORY;
- result = add_parallel_transfers(global, s->multi, s->share,
+ result = add_parallel_transfers(s->multi, s->share,
&s->more_transfers, &s->added_transfers);
if(result) {
curl_multi_cleanup(s->multi);
#ifdef USE_LIBUV
return parallel_event(s);
#else
- errorf(global, "Testing --parallel event-based requires libuv");
+ errorf("Testing --parallel event-based requires libuv");
#endif
else
#endif
result = check_finished(s);
}
- (void)progress_meter(global, s->multi, &s->start, TRUE);
+ (void)progress_meter(s->multi, &s->start, TRUE);
}
/* Make sure to return some kind of error if there was a multi problem */
return result;
}
-static CURLcode serial_transfers(struct GlobalConfig *global,
- CURLSH *share)
+static CURLcode serial_transfers(CURLSH *share)
{
CURLcode returncode = CURLE_OK;
CURLcode result = CURLE_OK;
bool added = FALSE;
bool skipped = FALSE;
- result = create_transfer(global, share, &added, &skipped);
+ result = create_transfer(share, &added, &skipped);
if(result)
return result;
if(!added) {
- errorf(global, "no transfer performed");
+ errorf("no transfer performed");
return CURLE_READ_ERROR;
}
for(per = transfers; per;) {
result = curl_easy_perform(per->curl);
}
- returncode = post_per_transfer(global, per, result, &retry, &delay_ms);
+ returncode = post_per_transfer(per, result, &retry, &delay_ms);
if(retry) {
curlx_wait_ms(delay_ms);
continue;
else {
do {
/* setup the next one just before we delete this */
- result = create_transfer(global, share, &added, &skipped);
+ result = create_transfer(share, &added, &skipped);
if(result) {
returncode = result;
bailout = TRUE;
milliseconds */
timediff_t milli = curlx_timediff(curlx_now(), start);
if(milli < global->ms_per_transfer) {
- notef(global, "Transfer took %" CURL_FORMAT_CURL_OFF_T " ms, "
- "waits %ldms as set by --rate",
+ notef("Transfer took %" CURL_FORMAT_CURL_OFF_T " ms, "
+ "waits %ldms as set by --rate",
milli, (long)(global->ms_per_transfer - milli));
/* The transfer took less time than wanted. Wait a little. */
curlx_wait_ms((long)(global->ms_per_transfer - milli));
* 'create_transfer' gets the details and sets up a new transfer if 'added'
* returns TRUE.
*/
-static CURLcode create_transfer(struct GlobalConfig *global,
- CURLSH *share,
+static CURLcode create_transfer(CURLSH *share,
bool *added,
bool *skipped)
{
return result;
}
-static CURLcode run_all_transfers(struct GlobalConfig *global,
- CURLSH *share,
+static CURLcode run_all_transfers(CURLSH *share,
CURLcode result)
{
/* Save the values of noprogress and isatty to restore them later on */
/* Time to actually do the transfers */
if(!result) {
if(global->parallel)
- result = parallel_transfers(global, share);
+ result = parallel_transfers(share);
else
- result = serial_transfers(global, share);
+ result = serial_transfers(share);
}
/* cleanup if there are any left */
for(per = transfers; per;) {
bool retry;
long delay;
- CURLcode result2 = post_per_transfer(global, per, result, &retry, &delay);
+ CURLcode result2 = post_per_transfer(per, result, &retry, &delay);
if(!result)
/* do not overwrite the original error */
result = result2;
return result;
}
-CURLcode operate(struct GlobalConfig *global, int argc, argv_item_t argv[])
+CURLcode operate(int argc, argv_item_t argv[])
{
CURLcode result = CURLE_OK;
const char *first_arg;
if((argc == 1) ||
(first_arg && strncmp(first_arg, "-q", 2) &&
strcmp(first_arg, "--disable"))) {
- parseconfig(NULL, global); /* ignore possible failure */
+ parseconfig(NULL); /* ignore possible failure */
/* If we had no arguments then make sure a url was specified in .curlrc */
if((argc < 2) && (!global->first->url_list)) {
if(!result) {
/* Parse the command line arguments */
- ParameterError res = parse_args(global, argc, argv);
+ ParameterError res = parse_args(argc, argv);
if(res) {
result = CURLE_OK;
#ifdef USE_MANUAL
hugehelp();
#else
- warnf(global,
- "built-in manual was disabled at build-time");
+ warnf("built-in manual was disabled at build-time");
#endif
}
/* Check if we were asked for the version information */
global->current = global->first;
/* now run! */
- result = run_all_transfers(global, share, result);
+ result = run_all_transfers(share, result);
if(global->ssl_sessions && feature_ssls_export) {
CURLcode r2 = tool_ssls_save(global->first, share,
easysrc_cleanup();
/* Dump the libcurl code if previously enabled */
- dumpeasysrc(global);
+ dumpeasysrc();
}
}
}
else
- errorf(global, "out of memory");
+ errorf("out of memory");
}
}
- varcleanup(global);
+ varcleanup();
curl_free(global->knownhosts);
return result;
BIT(skip); /* considered already done */
};
-CURLcode operate(struct GlobalConfig *global, int argc, argv_item_t argv[]);
+CURLcode operate(int argc, argv_item_t argv[]);
void single_transfer_cleanup(struct OperationConfig *config);
extern struct per_transfer *transfers; /* first node */
* Returns a pointer to a heap-allocated string or NULL if
* no name part, at location indicated by first argument.
*/
-CURLcode get_url_file_name(struct GlobalConfig *global,
- char **filename, const char *url)
+CURLcode get_url_file_name(char **filename, const char *url)
{
CURLU *uh = curl_url();
char *path = NULL;
else {
/* no slash => empty string, use default */
*filename = strdup("curl_response");
- warnf(global, "No remote file name, uses \"%s\"", *filename);
+ warnf("No remote file name, uses \"%s\"", *filename);
}
curl_free(path);
struct OperationConfig;
void clean_getout(struct OperationConfig *config);
-
bool output_expected(const char *url, const char *uploadfile);
-
bool stdin_upload(const char *uploadfile);
-
CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename);
-
-CURLcode get_url_file_name(struct GlobalConfig *global,
- char **filename, const char *url);
-
+CURLcode get_url_file_name(char **filename, const char *url);
CURLcode urlerr_cvt(CURLUcode ucode);
#endif /* HEADER_CURL_TOOL_OPERHLP_H */
#define MAX_PROTOSTRING (64*11) /* Enough room for 64 10-chars proto names. */
-ParameterError proto2num(struct OperationConfig *config,
- const char * const *val, char **ostr, const char *str)
+ParameterError proto2num(const char * const *val, char **ostr, const char *str)
{
const char **protoset;
struct dynbuf obuf;
if no protocols are allowed */
if(action == set)
protoset[0] = NULL;
- warnf(config->global, "unrecognized protocol '%s'", buffer);
+ warnf("unrecognized protocol '%s'", buffer);
}
}
if(next)
return PARAM_OK;
}
-long ftpfilemethod(struct OperationConfig *config, const char *str)
+long ftpfilemethod(const char *str)
{
if(curl_strequal("singlecwd", str))
return CURLFTPMETHOD_SINGLECWD;
if(curl_strequal("multicwd", str))
return CURLFTPMETHOD_MULTICWD;
- warnf(config->global, "unrecognized ftp file method '%s', using default",
- str);
+ warnf("unrecognized ftp file method '%s', using default", str);
return CURLFTPMETHOD_MULTICWD;
}
-long ftpcccmethod(struct OperationConfig *config, const char *str)
+long ftpcccmethod(const char *str)
{
if(curl_strequal("passive", str))
return CURLFTPSSL_CCC_PASSIVE;
if(curl_strequal("active", str))
return CURLFTPSSL_CCC_ACTIVE;
- warnf(config->global, "unrecognized ftp CCC method '%s', using default",
- str);
+ warnf("unrecognized ftp CCC method '%s', using default", str);
return CURLFTPSSL_CCC_PASSIVE;
}
-long delegation(struct OperationConfig *config, const char *str)
+long delegation(const char *str)
{
if(curl_strequal("none", str))
return CURLGSSAPI_DELEGATION_NONE;
if(curl_strequal("always", str))
return CURLGSSAPI_DELEGATION_FLAG;
- warnf(config->global, "unrecognized delegation method '%s', using none",
- str);
+ warnf("unrecognized delegation method '%s', using none", str);
return CURLGSSAPI_DELEGATION_NONE;
}
if(!result && !config->useragent) {
config->useragent = my_useragent();
if(!config->useragent) {
- errorf(config->global, "out of memory");
+ errorf("out of memory");
result = CURLE_OUT_OF_MEMORY;
}
}
ParameterError oct2nummax(long *val, const char *str, long max);
ParameterError str2unummax(long *val, const char *str, long max);
ParameterError secs2ms(long *val, const char *str);
-
-ParameterError proto2num(struct OperationConfig *config,
- const char * const *val, char **obuf,
+ParameterError proto2num(const char * const *val, char **obuf,
const char *str);
-
ParameterError check_protocol(const char *str);
-
ParameterError str2offset(curl_off_t *val, const char *str);
-
CURLcode get_args(struct OperationConfig *config, const size_t i);
-
ParameterError add2list(struct curl_slist **list, const char *ptr);
-
-long ftpfilemethod(struct OperationConfig *config, const char *str);
-
-long ftpcccmethod(struct OperationConfig *config, const char *str);
-
-long delegation(struct OperationConfig *config, const char *str);
+long ftpfilemethod(const char *str);
+long ftpcccmethod(const char *str);
+long delegation(const char *str);
ParameterError str2tls_max(unsigned char *val, const char *str);
#define MAX_CONFIG_LINE_LENGTH (10*1024*1024)
/* return 0 on everything-is-fine, and non-zero otherwise */
-int parseconfig(const char *filename, struct GlobalConfig *global)
+int parseconfig(const char *filename)
{
FILE *file = NULL;
bool usedarg = FALSE;
case '#': /* comment */
break;
default:
- warnf(config->global, "%s:%d: warning: '%s' uses unquoted "
+ warnf("%s:%d: warning: '%s' uses unquoted "
"whitespace", filename, lineno, option);
- warnf(config->global, "This may cause side-effects. "
+ warnf("This may cause side-effects. "
"Consider using double quotes?");
}
}
if(res == PARAM_NEXT_OPERATION) {
if(config->url_list && config->url_list->url) {
/* Allocate the next config */
- config->next = config_alloc(global);
+ config->next = config_alloc();
if(config->next) {
/* Update the last operation pointer */
global->last = config->next;
res != PARAM_ENGINES_REQUESTED &&
res != PARAM_CA_EMBED_REQUESTED) {
const char *reason = param2text(res);
- errorf(config->global, "%s:%d: '%s' %s",
+ errorf("%s:%d: '%s' %s",
filename, lineno, option, reason);
rc = (int)res;
}
***************************************************************************/
#include "tool_setup.h"
-int parseconfig(const char *filename, struct GlobalConfig *global);
-
+int parseconfig(const char *filename);
bool my_get_line(FILE *fp, struct dynbuf *db, bool *error);
#endif /* HEADER_CURL_TOOL_PARSECFG_H */
|DL% UL% Dled Uled Xfers Live Total Current Left Speed
| 6 -- 9.9G 0 2 2 0:00:40 0:00:02 0:00:37 4087M
*/
-bool progress_meter(struct GlobalConfig *global,
- CURLM *multi,
+bool progress_meter(CURLM *multi,
struct curltime *start,
bool final)
{
curl_off_t ultotal,
curl_off_t ulnow);
-bool progress_meter(struct GlobalConfig *global,
- CURLM *multi,
+bool progress_meter(CURLM *multi,
struct curltime *start,
bool final);
void progress_finalize(struct per_transfer *per);
}
/* setopt wrapper for enum types */
-CURLcode tool_setopt_enum(CURL *curl, struct OperationConfig *config,
- const char *name, CURLoption tag,
+CURLcode tool_setopt_enum(CURL *curl, const char *name, CURLoption tag,
const struct NameValue *nvlist, long lval)
{
CURLcode ret = CURLE_OK;
if(!lval)
skip = TRUE;
- if(config->global->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->global, "option %s returned error (%d)", name, (int)ret);
+ warnf("option %s returned error (%d)", name, (int)ret);
#endif
return ret;
}
/* setopt wrapper for CURLOPT_SSLVERSION */
-CURLcode tool_setopt_SSLVERSION(CURL *curl, struct OperationConfig *config,
- const char *name, CURLoption tag,
+CURLcode tool_setopt_SSLVERSION(CURL *curl, const char *name, CURLoption tag,
long lval)
{
CURLcode ret = CURLE_OK;
if(!lval)
skip = TRUE;
- if(config->global->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->global, "option %s returned error (%d)", name, (int)ret);
+ warnf("option %s returned error (%d)", name, (int)ret);
#endif
return ret;
}
/* setopt wrapper for bitmasks */
-CURLcode tool_setopt_bitmask(CURL *curl, struct OperationConfig *config,
- const char *name, CURLoption tag,
+CURLcode tool_setopt_bitmask(CURL *curl, const char *name, CURLoption tag,
const struct NameValueUnsigned *nvlist,
long lval)
{
if(!lval)
skip = TRUE;
- if(config->global->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;
CURLcode ret = curl_easy_setopt(curl, tag, mimepost);
int mimeno = 0;
- if(!ret && config->global->libcurl) {
+ if(!ret && global->libcurl) {
ret = libcurl_generate_mime(curl, config, config->mimeroot, &mimeno);
if(!ret)
}
/* setopt wrapper for curl_slist options */
-CURLcode tool_setopt_slist(CURL *curl, struct OperationConfig *config,
- const char *name, CURLoption tag,
+CURLcode tool_setopt_slist(CURL *curl, const char *name, CURLoption tag,
struct curl_slist *list)
{
CURLcode ret = CURLE_OK;
ret = curl_easy_setopt(curl, tag, list);
- if(config->global->libcurl && list && !ret) {
+ if(global->libcurl && list && !ret) {
int i;
ret = libcurl_generate_slist(list, &i);
}
/* options that set long */
-CURLcode tool_setopt_long(CURL *curl, struct OperationConfig *config,
- const char *name, CURLoption tag,
+CURLcode tool_setopt_long(CURL *curl, const char *name, CURLoption tag,
long lval)
{
long defval = 0L;
}
ret = curl_easy_setopt(curl, tag, lval);
- if((lval != defval) && config->global->libcurl && !ret) {
+ if((lval != defval) && global->libcurl && !ret) {
/* we only use this for real if --libcurl was used */
ret = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, %ldL);",
name, lval);
}
/* options that set curl_off_t */
-CURLcode tool_setopt_offt(CURL *curl, struct OperationConfig *config,
- const char *name, CURLoption tag,
+CURLcode tool_setopt_offt(CURL *curl, const char *name, CURLoption tag,
curl_off_t lval)
{
CURLcode ret = CURLE_OK;
DEBUGASSERT((tag >= CURLOPTTYPE_OFF_T) && (tag < CURLOPTTYPE_BLOB));
ret = curl_easy_setopt(curl, tag, lval);
- if(config->global->libcurl && !ret && lval) {
+ if(global->libcurl && !ret && lval) {
/* we only use this for real if --libcurl was used */
ret = easysrc_addf(&easysrc_code, "curl_easy_setopt(hnd, %s, (curl_off_t)%"
CURL_FORMAT_CURL_OFF_T ");", name, lval);
}
/* setopt wrapper for setting object and function pointer options */
-CURLcode tool_setopt(CURL *curl, bool str, struct OperationConfig *config,
- const char *name, CURLoption tag, ...)
+CURLcode tool_setopt(CURL *curl, struct OperationConfig *config,
+ bool str, const char *name, CURLoption tag,
+ ...)
{
va_list arg;
CURLcode ret = CURLE_OK;
va_end(arg);
- if(config->global->libcurl && pval && !ret) {
+ if(global->libcurl && pval && !ret) {
/* we only use this if --libcurl was used */
if(!str) {
/* Intercept setopt calls for --libcurl */
-CURLcode tool_setopt_enum(CURL *curl, struct OperationConfig *config,
- const char *name, CURLoption tag,
+CURLcode tool_setopt_enum(CURL *curl, const char *name, CURLoption tag,
const struct NameValue *nv, long lval);
-CURLcode tool_setopt_SSLVERSION(CURL *curl, struct OperationConfig *config,
- const char *name, CURLoption tag,
+CURLcode tool_setopt_SSLVERSION(CURL *curl, const char *name, CURLoption tag,
long lval);
CURLcode tool_setopt_flags(CURL *curl, struct OperationConfig *config,
const char *name, CURLoption tag,
const struct NameValue *nv, long lval);
-CURLcode tool_setopt_bitmask(CURL *curl, struct OperationConfig *config,
+CURLcode tool_setopt_bitmask(CURL *curl,
const char *name, CURLoption tag,
const struct NameValueUnsigned *nv, long lval);
CURLcode tool_setopt_mimepost(CURL *curl, struct OperationConfig *config,
const char *name, CURLoption tag,
curl_mime *mimepost);
-CURLcode tool_setopt_slist(CURL *curl, struct OperationConfig *config,
- const char *name, CURLoption tag,
+CURLcode tool_setopt_slist(CURL *curl, const char *name, CURLoption tag,
struct curl_slist *list);
-CURLcode tool_setopt_long(CURL *curl, struct OperationConfig *config,
- const char *name, CURLoption tag,
+CURLcode tool_setopt_long(CURL *curl, const char *name, CURLoption tag,
long lval);
-CURLcode tool_setopt_offt(CURL *curl, struct OperationConfig *config,
- const char *name, CURLoption tag,
+CURLcode tool_setopt_offt(CURL *curl, const char *name, CURLoption tag,
curl_off_t lval);
-CURLcode tool_setopt(CURL *curl, bool str,
- struct OperationConfig *config,
- const char *name, CURLoption tag, ...);
+CURLcode tool_setopt(CURL *curl, struct OperationConfig *config,
+ bool str, const char *name, CURLoption tag,
+ ...);
#define my_setopt(x,y,z) \
- tool_setopt(x, FALSE, config, #y, y, z)
+ tool_setopt(x, config, FALSE, #y, y, z)
#define my_setopt_long(x,y,z) \
- tool_setopt_long(x, config, #y, y, z)
+ tool_setopt_long(x, #y, y, z)
#define my_setopt_offt(x,y,z) \
- tool_setopt_offt(x, config, #y, y, z)
+ tool_setopt_offt(x, #y, y, z)
#define my_setopt_str(x,y,z) \
- tool_setopt(x, TRUE, config, #y, y, z)
+ tool_setopt(x, config, TRUE, #y, y, z)
#define my_setopt_enum(x,y,z) \
- tool_setopt_enum(x, config, #y, y, setopt_nv_ ## y, z)
+ tool_setopt_enum(x, #y, y, setopt_nv_ ## y, z)
#define my_setopt_SSLVERSION(x,y,z) \
- tool_setopt_SSLVERSION(x, config, #y, y, z)
+ tool_setopt_SSLVERSION(x, #y, y, z)
#define my_setopt_bitmask(x,y,z) \
- tool_setopt_bitmask(x, config, #y, y, setopt_nv_ ## y, z)
+ tool_setopt_bitmask(x, #y, y, setopt_nv_ ## y, z)
#define my_setopt_mimepost(x,y,z) \
tool_setopt_mimepost(x, config, #y, y, z)
#define my_setopt_slist(x,y,z) \
- tool_setopt_slist(x, config, #y, y, z)
+ tool_setopt_slist(x, #y, y, z)
#else /* CURL_DISABLE_LIBCURL_OPTION */
CURLSH *share, CURL **peasy)
{
CURLcode result = CURLE_OK;
- struct GlobalConfig *global = config->global;
*peasy = curl_easy_init();
if(!*peasy)
CURLcode r = CURLE_OK;
int i, imported;
bool error = FALSE;
- struct GlobalConfig *global = config->global;
curlx_dyn_init(&buf, MAX_SSLS_LINE);
fp = fopen(filename, FOPEN_READTEXT);
if(!fp) { /* ok if it does not exist */
- notef(global, "SSL session file does not exist (yet?): %s", filename);
+ notef("SSL session file does not exist (yet?): %s", filename);
goto out;
}
c = memchr(line, ':', strlen(line));
if(!c) {
- warnf(global, "unrecognized line %d in ssl session file %s",
- i, filename);
+ warnf("unrecognized line %d in ssl session file %s", i, filename);
continue;
}
*c = '\0';
r = curlx_base64_decode(line, &shmac, &shmac_len);
if(r) {
- warnf(global, "invalid shmax base64 encoding in line %d", i);
+ warnf("invalid shmax base64 encoding in line %d", i);
continue;
}
line = c + 1;
}
r = curlx_base64_decode(line, &sdata, &sdata_len);
if(r) {
- warnf(global, "invalid sdata base64 encoding in line %d: %s", i, line);
+ warnf("invalid sdata base64 encoding in line %d: %s", i, line);
continue;
}
r = curl_easy_ssls_import(easy, NULL, shmac, shmac_len, sdata, sdata_len);
if(r) {
- warnf(global, "import of session from line %d rejected(%d)", i, r);
+ warnf("import of session from line %d rejected(%d)", i, r);
continue;
}
++imported;
}
struct tool_ssls_ctx {
- struct GlobalConfig *global;
FILE *fp;
int exported;
};
ctx->exported++;
out:
if(r)
- warnf(ctx->global, "Warning: error saving SSL session for '%s': %d",
- session_key, r);
+ warnf("Warning: error saving SSL session for '%s': %d", session_key, r);
curl_free(enc);
return r;
}
CURL *easy = NULL;
CURLcode r = CURLE_OK;
- ctx.global = config->global;
ctx.exported = 0;
ctx.fp = fopen(filename, FOPEN_WRITETEXT);
if(!ctx.fp) {
- warnf(config->global, "Warning: Failed to create SSL session file %s",
+ warnf("Warning: Failed to create SSL session file %s",
filename);
goto out;
}
tool_stderr = stderr;
}
-void tool_set_stderr_file(struct GlobalConfig *global, const char *filename)
+void tool_set_stderr_file(const char *filename)
{
FILE *fp;
subsequent freopen will fail. */
fp = fopen(filename, FOPEN_WRITETEXT);
if(!fp) {
- warnf(global, "Warning: Failed to open %s", filename);
+ warnf("Warning: Failed to open %s", filename);
return;
}
fclose(fp);
#include "tool_cfgable.h"
void tool_init_stderr(void);
-void tool_set_stderr_file(struct GlobalConfig *global, const char *filename);
+void tool_set_stderr_file(const char *filename);
#endif /* HEADER_CURL_TOOL_STDERR_H */
#define MAX_VAR_LEN 128 /* max length of a name */
/* free everything */
-void varcleanup(struct GlobalConfig *global)
+void varcleanup(void)
{
struct tool_var *list = global->variables;
while(list) {
}
}
-static const struct tool_var *varcontent(struct GlobalConfig *global,
- const char *name, size_t nlen)
+static const struct tool_var *varcontent(const char *name, size_t nlen)
{
struct tool_var *list = global->variables;
while(list) {
#define FUNC_64DEC "64dec" /* base64 decode */
#define FUNC_64DEC_LEN (sizeof(FUNC_64DEC) - 1)
-static ParameterError varfunc(struct GlobalConfig *global,
- char *c, /* content */
+static ParameterError varfunc(char *c, /* content */
size_t clen, /* content length */
char *f, /* functions */
size_t flen, /* function string length */
}
else {
/* unsupported function */
- errorf(global, "unknown variable function in '%.*s'",
- (int)flen, finput);
+ errorf("unknown variable function in '%.*s'", (int)flen, finput);
err = PARAM_EXPAND_ERROR;
break;
}
return err;
}
-ParameterError varexpand(struct GlobalConfig *global,
- const char *line, struct dynbuf *out,
+ParameterError varexpand(const char *line, struct dynbuf *out,
bool *replaced)
{
CURLcode result;
if(!clp) {
/* uneven braces */
- warnf(global, "missing close '}}' in '%s'", input);
+ warnf("missing close '}}' in '%s'", input);
break;
}
else
nlen = clp - envp;
if(!nlen || (nlen >= sizeof(name))) {
- warnf(global, "bad variable name length '%s'", input);
+ warnf("bad variable name length '%s'", input);
/* insert the text as-is since this is not an env variable */
result = curlx_dyn_addn(out, line, clp - line + prefix);
if(result)
for(i = 0; (i < nlen) &&
(ISALNUM(name[i]) || (name[i] == '_')); i++);
if(i != nlen) {
- warnf(global, "bad variable name: %s", name);
+ warnf("bad variable name: %s", name);
/* insert the text as-is since this is not an env variable */
result = curlx_dyn_addn(out, envp - prefix,
clp - envp + prefix + 2);
char *value;
size_t vlen = 0;
struct dynbuf buf;
- const struct tool_var *v = varcontent(global, name, nlen);
+ const struct tool_var *v = varcontent(name, nlen);
if(v) {
value = (char *)CURL_UNCONST(v->content);
vlen = v->clen;
if(funcp) {
/* apply the list of functions on the value */
size_t flen = clp - funcp;
- ParameterError err = varfunc(global, value, vlen, funcp, flen,
- &buf);
+ ParameterError err = varfunc(value, vlen, funcp, flen, &buf);
if(err)
return err;
value = curlx_dyn_ptr(&buf);
using normal means, this is an error. */
char *nb = memchr(value, '\0', vlen);
if(nb) {
- errorf(global, "variable contains null byte");
+ errorf("variable contains null byte");
return PARAM_EXPAND_ERROR;
}
}
* that we can improve this if we want better performance when managing many
* at a later point.
*/
-static ParameterError addvariable(struct GlobalConfig *global,
- const char *name,
+static ParameterError addvariable(const char *name,
size_t nlen,
const char *content,
size_t clen,
bool contalloc)
{
struct tool_var *p;
- const struct tool_var *check = varcontent(global, name, nlen);
+ const struct tool_var *check = varcontent(name, nlen);
DEBUGASSERT(nlen);
if(check)
- notef(global, "Overwriting variable '%s'", check->name);
+ notef("Overwriting variable '%s'", check->name);
p = calloc(1, sizeof(struct tool_var) + nlen);
if(p) {
#define MAX_FILENAME 10000
-ParameterError setvariable(struct GlobalConfig *global,
- const char *input)
+ParameterError setvariable(const char *input)
{
const char *name;
size_t nlen;
line++;
nlen = line - name;
if(!nlen || (nlen >= MAX_VAR_LEN)) {
- warnf(global, "Bad variable name length (%zd), skipping", nlen);
+ warnf("Bad variable name length (%zd), skipping", nlen);
return PARAM_OK;
}
if(import) {
ge = getenv(name);
if(!*line && !ge) {
/* no assign, no variable, fail */
- errorf(global, "Variable '%s' import fail, not set", name);
+ errorf("Variable '%s' import fail, not set", name);
return PARAM_EXPAND_ERROR;
}
else if(ge) {
else {
file = fopen(line, "rb");
if(!file) {
- errorf(global, "Failed to open %s: %s", line,
- strerror(errno));
+ errorf("Failed to open %s: %s", line, strerror(errno));
err = PARAM_READ_ERROR;
}
}
}
}
else {
- warnf(global, "Bad --variable syntax, skipping: %s", input);
+ warnf("Bad --variable syntax, skipping: %s", input);
return PARAM_OK;
}
- err = addvariable(global, name, nlen, content, clen, contalloc);
+ err = addvariable(name, nlen, content, clen, contalloc);
if(err) {
if(contalloc)
free(content);
char name[1]; /* allocated as part of the struct */
};
-struct GlobalConfig;
-
-ParameterError setvariable(struct GlobalConfig *global, const char *input);
-ParameterError varexpand(struct GlobalConfig *global,
- const char *line, struct dynbuf *out,
+ParameterError setvariable(const char *input);
+ParameterError varexpand(const char *line, struct dynbuf *out,
bool *replaced);
/* free everything */
-void varcleanup(struct GlobalConfig *global);
+void varcleanup(void);
#endif /* HEADER_CURL_VAR_H */
MEM tool_cfgable.c
MEM tool_cfgable.c
MEM tool_cfgable.c
+MEM tool_cfgable.c
</file>
<stripfile>
$_ = '' if((($_ !~ /tool_paramhlp/) && ($_ !~ /tool_cfgable/)) || ($_ =~ /free\(\(nil\)\)/))