* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
/* use our own printf() functions */
#include "curlx.h"
-#ifdef USE_MANUAL
-# include "tool_hugehelp.h"
-#endif
-
#include "tool_binmode.h"
#include "tool_cfgable.h"
#include "tool_cb_prg.h"
#include "tool_formparse.h"
#include "tool_getparam.h"
-#include "tool_help.h"
#include "tool_helpers.h"
#include "tool_libinfo.h"
#include "tool_metalink.h"
#include "tool_msgs.h"
#include "tool_paramhlp.h"
#include "tool_parsecfg.h"
-#include "tool_version.h"
#include "memdebug.h" /* keep this as LAST include */
/* all these ones, starting with "*" or "$" as a short-option have *no*
short option to mention. */
{"*", "url", TRUE},
+ {"*4", "dns-ipv4-addr", TRUE},
+ {"*6", "dns-ipv6-addr", TRUE},
{"*a", "random-file", TRUE},
{"*b", "egd-file", TRUE},
+ {"*B", "oauth2-bearer", TRUE},
{"*c", "connect-timeout", TRUE},
{"*d", "ciphers", TRUE},
+ {"*D", "dns-interface", TRUE},
{"*e", "disable-epsv", FALSE},
{"*E", "epsv", FALSE},
/* 'epsv' made like this to make --no-epsv and --epsv to work
#ifdef USE_ENVIRONMENT
{"*f", "environment", FALSE},
#endif
+ {"*F", "dns-servers", TRUE},
{"*g", "trace", TRUE},
+ {"*G", "npn", FALSE},
{"*h", "trace-ascii", TRUE},
+ {"*H", "alpn", FALSE},
{"*i", "limit-rate", TRUE},
{"*j", "compressed", FALSE},
{"*J", "tr-encoding", FALSE},
{"$I", "post303", FALSE},
{"$J", "metalink", FALSE},
{"$K", "sasl-ir", FALSE},
- {"0", "http1.0", FALSE},
+ {"$L", "test-event", FALSE},
+ {"0", "http1.0", FALSE},
+ {"01", "http1.1", FALSE},
+ {"02", "http2", FALSE},
{"1", "tlsv1", FALSE},
+ {"10", "tlsv1.0", FALSE},
+ {"11", "tlsv1.1", FALSE},
+ {"12", "tlsv1.2", FALSE},
{"2", "sslv2", FALSE},
{"3", "sslv3", FALSE},
{"4", "ipv4", FALSE},
{"El", "tlspassword", TRUE},
{"Em", "tlsauthtype", TRUE},
{"En", "ssl-allow-beast", FALSE},
+ {"Eo", "login-options", TRUE},
{"f", "fail", FALSE},
{"F", "form", TRUE},
{"Fs", "form-string", TRUE},
{"G", "get", FALSE},
{"h", "help", FALSE},
{"H", "header", TRUE},
+ {"Hp", "proxy-header", TRUE},
{"i", "include", FALSE},
{"I", "head", FALSE},
{"j", "junk-session-cookies", FALSE},
{"y", "speed-time", TRUE},
{"z", "time-cond", TRUE},
{"#", "progress-bar", FALSE},
+ {":", "next", FALSE},
{"~", "xattr", FALSE},
};
-struct feat {
- const char *name;
- int bitmask;
-};
-
-static const struct feat feats[] = {
- {"AsynchDNS", CURL_VERSION_ASYNCHDNS},
- {"Debug", CURL_VERSION_DEBUG},
- {"TrackMemory", CURL_VERSION_CURLDEBUG},
- {"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
- {"IDN", CURL_VERSION_IDN},
- {"IPv6", CURL_VERSION_IPV6},
- {"Largefile", CURL_VERSION_LARGEFILE},
- {"NTLM", CURL_VERSION_NTLM},
- {"NTLM_WB", CURL_VERSION_NTLM_WB},
- {"SPNEGO", CURL_VERSION_SPNEGO},
- {"SSL", CURL_VERSION_SSL},
- {"SSPI", CURL_VERSION_SSPI},
- {"krb4", CURL_VERSION_KERBEROS4},
- {"libz", CURL_VERSION_LIBZ},
- {"CharConv", CURL_VERSION_CONV},
- {"TLS-SRP", CURL_VERSION_TLSAUTH_SRP}
-};
-
/* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
* We allow ':' and '\' to be escaped by '\' so that we can use certificate
* nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/>
* for details. */
-static void parse_cert_parameter(const char *cert_parameter,
- char **certname,
- char **passphrase)
+#ifndef UNITTESTS
+static
+#endif
+void parse_cert_parameter(const char *cert_parameter,
+ char **certname,
+ char **passphrase)
{
size_t param_length = strlen(cert_parameter);
size_t span;
const char *param_place = NULL;
char *certname_place = NULL;
+ *certname = NULL;
*passphrase = NULL;
/* most trivial assumption: cert_parameter is empty */
- if(param_length == 0) {
- *certname = NULL;
+ if(param_length == 0)
return;
- }
+
/* next less trivial: cert_parameter contains no colon nor backslash; this
* means no passphrase was given and no characters escaped */
if(!strpbrk(cert_parameter, ":\\")) {
return;
}
/* deal with escaped chars; find unescaped colon if it exists */
- *certname = (char *) malloc(param_length + 1);
- param_place = cert_parameter;
- certname_place = *certname;
+ certname_place = malloc(param_length + 1);
+ if(!certname_place)
+ return;
+
+ *certname = certname_place;
param_place = cert_parameter;
while(*param_place) {
span = strcspn(param_place, ":\\");
strncpy(certname_place, param_place, span);
param_place += span;
certname_place += span;
- *certname_place = '\0';
/* we just ate all the non-special chars. now we're on either a special
* char or the end of the string. */
switch(*param_place) {
if(strlen(param_place) > 0) {
*passphrase = strdup(param_place);
}
- return;
+ goto done;
}
}
+done:
+ *certname_place = '\0';
}
ParameterError getparameter(char *flag, /* f or -long-flag */
char *nextarg, /* NULL if unset */
bool *usedarg, /* set to TRUE if the arg
has been used */
- struct Configurable *config)
+ struct GlobalConfig *global,
+ struct OperationConfig *config)
{
char letter;
char subletter = '\0'; /* subletters can only occur on long options */
switch(letter) {
case '*': /* options without a short option */
switch(subletter) {
+ case '4': /* --dns-ipv4-addr */
+ /* addr in dot notation */
+ GetStr(&config->dns_ipv4_addr, nextarg);
+ break;
+ case '6': /* --dns-ipv6-addr */
+ /* addr in dot notation */
+ GetStr(&config->dns_ipv6_addr, nextarg);
+ break;
case 'a': /* random-file */
GetStr(&config->random_file, nextarg);
break;
case 'b': /* egd-file */
GetStr(&config->egd_file, nextarg);
break;
+ case 'B': /* XOAUTH2 Bearer */
+ GetStr(&config->xoauth2_bearer, nextarg);
+ break;
case 'c': /* connect-timeout */
- err = str2unum(&config->connecttimeout, nextarg);
+ err = str2udouble(&config->connecttimeout, nextarg);
if(err)
return err;
break;
case 'd': /* ciphers */
GetStr(&config->cipher_list, nextarg);
break;
+ case 'D': /* --dns-interface */
+ /* interface name */
+ GetStr(&config->dns_interface, nextarg);
+ break;
case 'e': /* --disable-epsv */
config->disable_epsv = toggle;
break;
config->writeenv = toggle;
break;
#endif
+ case 'F': /* --dns-servers */
+ /* IP addrs of DNS servers */
+ GetStr(&config->dns_servers, nextarg);
+ break;
case 'g': /* --trace */
- GetStr(&config->trace_dump, nextarg);
- if(config->tracetype && (config->tracetype != TRACE_BIN))
+ GetStr(&global->trace_dump, nextarg);
+ if(global->tracetype && (global->tracetype != TRACE_BIN))
warnf(config, "--trace overrides an earlier trace/verbose option\n");
- config->tracetype = TRACE_BIN;
+ global->tracetype = TRACE_BIN;
+ break;
+ case 'G': /* --npn */
+ config->nonpn = (!toggle)?TRUE:FALSE;
break;
case 'h': /* --trace-ascii */
- GetStr(&config->trace_dump, nextarg);
- if(config->tracetype && (config->tracetype != TRACE_ASCII))
+ GetStr(&global->trace_dump, nextarg);
+ if(global->tracetype && (global->tracetype != TRACE_ASCII))
warnf(config,
"--trace-ascii overrides an earlier trace/verbose option\n");
- config->tracetype = TRACE_ASCII;
+ global->tracetype = TRACE_ASCII;
+ break;
+ case 'H': /* --alpn */
+ config->noalpn = (!toggle)?TRUE:FALSE;
break;
case 'i': /* --limit-rate */
{
break;
case 'r': /* --create-dirs */
- config->create_dirs = TRUE;
+ config->create_dirs = toggle;
break;
case 's': /* --max-redirs */
case 'u': /* --crlf */
/* LF -> CRLF conversion? */
- config->crlf = TRUE;
+ config->crlf = toggle;
break;
case 'v': /* --stderr */
if(!newfile)
warnf(config, "Failed to open %s!\n", nextarg);
else {
- if(config->errors_fopened)
- fclose(config->errors);
- config->errors = newfile;
- config->errors_fopened = TRUE;
+ if(global->errors_fopened)
+ fclose(global->errors);
+ global->errors = newfile;
+ global->errors_fopened = TRUE;
}
}
else
- config->errors = stdout;
+ global->errors = stdout;
break;
case 'w': /* --interface */
/* interface */
config->proxyanyauth = toggle;
break;
case 'o': /* --trace-time */
- config->tracetime = toggle;
+ global->tracetime = toggle;
break;
case 'p': /* --ignore-content-length */
config->ignorecl = toggle;
"--libcurl option was disabled at build-time!\n");
return PARAM_OPTION_UNKNOWN;
#else
- GetStr(&config->libcurl, nextarg);
+ GetStr(&global->libcurl, nextarg);
break;
#endif
case '#': /* --raw */
GetStr(&config->socks5_gssapi_service, nextarg);
break;
case '7': /* --socks5-gssapi-nec*/
- config->socks5_gssapi_nec = TRUE;
+ config->socks5_gssapi_nec = toggle;
break;
#endif
case '8': /* --proxy1.0 */
break;
}
case 'K': /* --sasl-ir */
- config->sasl_ir = TRUE;
+ config->sasl_ir = toggle;
+ break;
+ case 'L': /* --test-event */
+#ifdef CURLDEBUG
+ config->test_event_based = toggle;
+#else
+ warnf(config, "--test-event is ignored unless a debug build!\n");
+#endif
break;
}
break;
case '#': /* --progress-bar */
if(toggle)
- config->progressmode = CURL_PROGRESS_BAR;
+ global->progressmode = CURL_PROGRESS_BAR;
else
- config->progressmode = CURL_PROGRESS_STATS;
+ global->progressmode = CURL_PROGRESS_STATS;
break;
+ case ':': /* --next */
+ return PARAM_NEXT_OPERATION;
case '~': /* --xattr */
config->xattr = toggle;
break;
- case '0':
- /* HTTP version 1.0 */
- config->httpversion = CURL_HTTP_VERSION_1_0;
+ case '0': /* --http* options */
+ switch(subletter) {
+ case '\0':
+ /* HTTP version 1.0 */
+ config->httpversion = CURL_HTTP_VERSION_1_0;
+ break;
+ case '1':
+ /* HTTP version 1.1 */
+ config->httpversion = CURL_HTTP_VERSION_1_1;
+ break;
+ case '2':
+ /* HTTP version 2.0 */
+ config->httpversion = CURL_HTTP_VERSION_2_0;
+ break;
+ }
break;
- case '1':
- /* TLS version 1 */
- config->ssl_version = CURL_SSLVERSION_TLSv1;
+ case '1': /* --tlsv1* options */
+ switch(subletter) {
+ case '\0':
+ /* TLS version 1.x */
+ config->ssl_version = CURL_SSLVERSION_TLSv1;
+ break;
+ case '0':
+ /* TLS version 1.0 */
+ config->ssl_version = CURL_SSLVERSION_TLSv1_0;
+ break;
+ case '1':
+ /* TLS version 1.1 */
+ config->ssl_version = CURL_SSLVERSION_TLSv1_1;
+ break;
+ case '2':
+ /* TLS version 1.2 */
+ config->ssl_version = CURL_SSLVERSION_TLSv1_2;
+ break;
+ }
break;
case '2':
/* SSL version 2 */
&-letter */
char *oldpost = config->postfields;
curl_off_t oldlen = config->postfieldsize;
- curl_off_t newlen = oldlen + size + 2;
+ curl_off_t newlen = oldlen + curlx_uztoso(size) + 2;
config->postfields = malloc((size_t)newlen);
if(!config->postfields) {
Curl_safefree(oldpost);
}
else {
config->postfields = postdata;
- config->postfieldsize = size;
+ config->postfieldsize = curlx_uztoso(size);
}
}
/*
case 'f': /* crypto engine */
GetStr(&config->engine, nextarg);
if(config->engine && curlx_raw_equal(config->engine,"list"))
- config->list_engines = TRUE;
+ return PARAM_ENGINES_REQUESTED;
break;
case 'g': /* CA info PEM file */
/* CA cert directory */
else
return PARAM_LIBCURL_DOESNT_SUPPORT;
break;
- case 'n': /* no empty SSL fragments */
+ case 'n': /* no empty SSL fragments, --ssl-allow-beast */
if(curlinfo->features & CURL_VERSION_SSL)
config->ssl_allow_beast = toggle;
break;
+
+ case 'o': /* --login-options */
+ GetStr(&config->login_options, nextarg);
+ break;
+
default: /* certificate file */
{
char *certname, *passphrase;
parse_cert_parameter(nextarg, &certname, &passphrase);
- if(certname) {
- GetStr(&config->cert, certname);
- }
+ Curl_safefree(config->cert);
+ config->cert = certname;
if(passphrase) {
- GetStr(&config->key_passwd, passphrase);
+ Curl_safefree(config->key_passwd);
+ config->key_passwd = passphrase;
}
cleanarg(nextarg);
}
case 'h': /* h for help */
if(toggle) {
- tool_help();
return PARAM_HELP_REQUESTED;
}
/* we now actually support --no-help too! */
break;
case 'H':
/* A custom header to append to a list */
- err = add2list(&config->headers, nextarg);
+ if(subletter == 'p') /* --proxy-header */
+ err = add2list(&config->proxyheaders, nextarg);
+ else
+ err = add2list(&config->headers, nextarg);
if(err)
return err;
break;
config->insecure_ok = toggle;
break;
case 'K': /* parse config file */
- if(parseconfig(nextarg, config))
+ if(parseconfig(nextarg, global))
warnf(config, "error trying read config from the '%s' file\n",
nextarg);
break;
break;
case 'm':
/* specified max time */
- err = str2unum(&config->timeout, nextarg);
+ err = str2udouble(&config->timeout, nextarg);
if(err)
return err;
break;
case 'M': /* M for manual, huge help */
if(toggle) { /* --no-manual shows no manual... */
#ifdef USE_MANUAL
- hugehelp();
- return PARAM_HELP_REQUESTED;
+ return PARAM_MANUAL_REQUESTED;
#else
warnf(config,
"built-in manual was disabled at build-time!\n");
case 's':
/* don't show progress meter, don't show errors : */
if(toggle)
- config->mute = config->noprogress = TRUE;
+ global->mute = global->noprogress = TRUE;
else
- config->mute = config->noprogress = FALSE;
- if(config->showerror < 0)
+ global->mute = global->noprogress = FALSE;
+ if(global->showerror < 0)
/* if still on the default value, set showerror to the reverse of
toggle. This is to allow -S and -s to be used in an independent
order but still have the same effect. */
- config->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
+ global->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
break;
case 'S':
/* show errors */
- config->showerror = toggle?1:0; /* toggle on if used with -s */
+ global->showerror = toggle?1:0; /* toggle on if used with -s */
break;
case 't':
/* Telnet options */
/* user:password */
GetStr(&config->userpwd, nextarg);
cleanarg(nextarg);
- err = checkpasswd("host", &config->userpwd);
- if(err)
- return err;
break;
case 'U':
/* Proxy user:password */
GetStr(&config->proxyuserpwd, nextarg);
cleanarg(nextarg);
- err = checkpasswd("proxy", &config->proxyuserpwd);
- if(err)
- return err;
break;
case 'v':
if(toggle) {
/* the '%' thing here will cause the trace get sent to stderr */
- Curl_safefree(config->trace_dump);
- config->trace_dump = strdup("%");
- if(!config->trace_dump)
+ Curl_safefree(global->trace_dump);
+ global->trace_dump = strdup("%");
+ if(!global->trace_dump)
return PARAM_NO_MEM;
- if(config->tracetype && (config->tracetype != TRACE_PLAIN))
+ if(global->tracetype && (global->tracetype != TRACE_PLAIN))
warnf(config,
"-v, --verbose overrides an earlier trace/verbose option\n");
- config->tracetype = TRACE_PLAIN;
+ global->tracetype = TRACE_PLAIN;
}
else
/* verbose is disabled here */
- config->tracetype = TRACE_NONE;
+ global->tracetype = TRACE_NONE;
break;
case 'V':
- {
- const char *const *proto;
-
- if(!toggle)
- /* --no-version yields no output! */
- break;
+ if(toggle) /* --no-version yields no output! */
+ return PARAM_VERSION_INFO_REQUESTED;
+ break;
- printf(CURL_ID "%s\n", curl_version());
- if(curlinfo->protocols) {
- printf("Protocols: ");
- for(proto = curlinfo->protocols; *proto; ++proto) {
- printf("%s ", *proto);
- }
- puts(""); /* newline */
- }
- if(curlinfo->features) {
- unsigned int i;
- printf("Features: ");
- for(i = 0; i < sizeof(feats)/sizeof(feats[0]); i++) {
- if(curlinfo->features & feats[i].bitmask)
- printf("%s ", feats[i].name);
- }
-#ifdef USE_METALINK
- printf("Metalink ");
-#endif
- puts(""); /* newline */
- }
- }
- return PARAM_HELP_REQUESTED;
case 'w':
/* get the output string */
if('@' == *nextarg) {
return PARAM_OK;
}
+ParameterError parse_args(struct GlobalConfig *config, int argc,
+ argv_item_t argv[])
+{
+ int i;
+ bool stillflags;
+ char *orig_opt;
+ ParameterError result = PARAM_OK;
+ struct OperationConfig *operation = config->first;
+
+ for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
+ orig_opt = argv[i];
+
+ if(stillflags && ('-' == argv[i][0])) {
+ char *nextarg;
+ bool passarg;
+ char *flag = argv[i];
+
+ if(curlx_strequal("--", argv[i]))
+ /* This indicates the end of the flags and thus enables the
+ following (URL) argument to start with -. */
+ stillflags = FALSE;
+ else {
+ nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
+
+ result = getparameter(flag, nextarg, &passarg, config, operation);
+ if(result == PARAM_NEXT_OPERATION) {
+ /* Reset result as PARAM_NEXT_OPERATION is only used here and not
+ returned from this function */
+ result = PARAM_OK;
+
+ if(operation->url_list && operation->url_list->url) {
+ /* Allocate the next config */
+ operation->next = malloc(sizeof(struct OperationConfig));
+ if(operation->next) {
+ /* Initialise the newly created config */
+ config_init(operation->next);
+
+ /* Copy the easy handle */
+ operation->next->easy = config->easy;
+
+ /* Set the global config pointer */
+ operation->next->global = config;
+
+ /* Update the last operation pointer */
+ config->last = operation->next;
+
+ /* Move onto the new config */
+ operation->next->prev = operation;
+ operation = operation->next;
+ }
+ else
+ result = PARAM_NO_MEM;
+ }
+ }
+ else if(!result && passarg)
+ i++; /* we're supposed to skip this */
+ }
+ }
+ else {
+ bool used;
+
+ /* Just add the URL please */
+ result = getparameter((char *)"--url", argv[i], &used, config,
+ operation);
+ }
+ }
+
+ if(result && result != PARAM_HELP_REQUESTED &&
+ result != PARAM_MANUAL_REQUESTED &&
+ result != PARAM_VERSION_INFO_REQUESTED &&
+ result != PARAM_ENGINES_REQUESTED) {
+ const char *reason = param2text(result);
+
+ if(!curlx_strequal(":", orig_opt))
+ helpf(config->errors, "option %s: %s\n", orig_opt, reason);
+ else
+ helpf(config->errors, "%s\n", reason);
+ }
+
+ return result;
+}