* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, 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 "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 */
free(*(str)); \
*(str) = NULL; \
} \
- if((val)) \
+ if((val)) { \
*(str) = strdup((val)); \
- if(!(val)) \
- return PARAM_NO_MEM; \
+ if(!(*(str))) \
+ return PARAM_NO_MEM; \
+ } \
} WHILE_FALSE
struct LongShort {
/* 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},
{"$H", "mail-auth", TRUE},
{"$I", "post303", FALSE},
{"$J", "metalink", FALSE},
- {"0", "http1.0", FALSE},
+ {"$K", "sasl-ir", FALSE},
+ {"$L", "test-event", FALSE},
+ {"$M", "unix-socket", TRUE},
+ {"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},
+ {"Ep", "pinnedpubkey", TRUE},
+ {"Eq", "cert-status", FALSE},
{"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;
-};
+/* 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. */
+#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)
+ 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, ":\\")) {
+ *certname = strdup(cert_parameter);
+ return;
+ }
+ /* deal with escaped chars; find unescaped colon if it exists */
+ 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;
+ /* 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) {
+ case '\0':
+ break;
+ case '\\':
+ param_place++;
+ switch(*param_place) {
+ case '\0':
+ *certname_place++ = '\\';
+ break;
+ case '\\':
+ *certname_place++ = '\\';
+ param_place++;
+ break;
+ case ':':
+ *certname_place++ = ':';
+ param_place++;
+ break;
+ default:
+ *certname_place++ = '\\';
+ *certname_place++ = *param_place;
+ param_place++;
+ break;
+ }
+ break;
+ case ':':
+ /* Since we live in a world of weirdness and confusion, the win32
+ dudes can use : when using drive letters and thus c:\file:password
+ needs to work. In order not to break compatibility, we still use : as
+ separator, but we try to detect when it is used for a file name! On
+ windows. */
+#ifdef WIN32
+ if(param_place &&
+ (param_place == &cert_parameter[1]) &&
+ (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
+ (ISALPHA(cert_parameter[0])) ) {
+ /* colon in the second column, followed by a backslash, and the
+ first character is an alphabetic letter:
-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}
-};
+ this is a drive letter colon */
+ *certname_place++ = ':';
+ param_place++;
+ break;
+ }
+#endif
+ /* escaped colons and Windows drive letter colons were handled
+ * above; if we're still here, this is a separating colon */
+ param_place++;
+ if(strlen(param_place) > 0) {
+ *passphrase = strdup(param_place);
+ }
+ 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 */
/* we can loop here if we have multiple single-letters */
if(!longopt) {
- if(NULL != parse) {
- letter = (char)*parse;
- }
- else {
- letter = '\0';
- }
+ letter = (char)*parse;
subletter='\0';
}
else {
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 */
- if(str2num(&config->connecttimeout, nextarg))
- return PARAM_BAD_NUMERIC;
+ 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 */
{
case 'l': /* --negotiate */
if(toggle) {
- if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
- config->authtype |= CURLAUTH_GSSNEGOTIATE;
+ if(curlinfo->features & CURL_VERSION_SPNEGO)
+ config->authtype |= CURLAUTH_NEGOTIATE;
else
return PARAM_LIBCURL_DOESNT_SUPPORT;
}
else
- config->authtype &= ~CURLAUTH_GSSNEGOTIATE;
+ config->authtype &= ~CURLAUTH_NEGOTIATE;
break;
case 'm': /* --ntlm */
break;
case 'r': /* --create-dirs */
- config->create_dirs = TRUE;
+ config->create_dirs = toggle;
break;
case 's': /* --max-redirs */
- /* specified max no of redirects (http(s)) */
- if(str2num(&config->maxredirs, nextarg))
+ /* specified max no of redirects (http(s)), this accepts -1 as a
+ special condition */
+ err = str2num(&config->maxredirs, nextarg);
+ if(err)
+ return err;
+ if(config->maxredirs < -1)
return PARAM_BAD_NUMERIC;
break;
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 */
break;
case 'x': /* --krb */
/* kerberos level string */
- if(curlinfo->features & (CURL_VERSION_KERBEROS4 |
- CURL_VERSION_GSSNEGOTIATE))
+ if(curlinfo->features & CURL_VERSION_KERBEROS4)
GetStr(&config->krblevel, nextarg);
else
return PARAM_LIBCURL_DOESNT_SUPPORT;
break;
case 'y': /* --max-filesize */
- if(str2offset(&config->max_filesize, nextarg))
- return PARAM_BAD_NUMERIC;
+ err = str2offset(&config->max_filesize, nextarg);
+ if(err)
+ return err;
break;
case 'z': /* --disable-eprt */
config->disable_eprt = toggle;
config->proxybasic = toggle;
break;
case 'g': /* --retry */
- if(str2num(&config->req_retry, nextarg))
- return PARAM_BAD_NUMERIC;
+ err = str2unum(&config->req_retry, nextarg);
+ if(err)
+ return err;
break;
case 'h': /* --retry-delay */
- if(str2num(&config->retry_delay, nextarg))
- return PARAM_BAD_NUMERIC;
+ err = str2unum(&config->retry_delay, nextarg);
+ if(err)
+ return err;
break;
case 'i': /* --retry-max-time */
- if(str2num(&config->retry_maxtime, nextarg))
- return PARAM_BAD_NUMERIC;
+ err = str2unum(&config->retry_maxtime, nextarg);
+ if(err)
+ return err;
break;
case 'k': /* --proxy-negotiate */
- if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
+ if(curlinfo->features & CURL_VERSION_SPNEGO)
config->proxynegotiate = toggle;
else
return PARAM_LIBCURL_DOESNT_SUPPORT;
break;
+
case 'm': /* --ftp-account */
GetStr(&config->ftp_account, nextarg);
break;
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 */
config->nokeepalive = (!toggle)?TRUE:FALSE;
break;
case '3': /* --keepalive-time */
- if(str2num(&config->alivetime, nextarg))
- return PARAM_BAD_NUMERIC;
+ err = str2unum(&config->alivetime, nextarg);
+ if(err)
+ return err;
break;
case '4': /* --post302 */
config->post302 = toggle;
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 */
config->proxyver = CURLPROXY_HTTP_1_0;
break;
case '9': /* --tftp-blksize */
- str2num(&config->tftp_blksize, nextarg);
+ err = str2unum(&config->tftp_blksize, nextarg);
+ if(err)
+ return err;
break;
case 'A': /* --mail-from */
GetStr(&config->mail_from, nextarg);
case 'J': /* --metalink */
{
#ifdef USE_METALINK
- int major, minor, patch;
- metalink_get_version(&major, &minor, &patch);
- if((major*10000)+(minor*100)+patch < CURL_REQ_LIBMETALINK_VERS) {
+ int mlmaj, mlmin, mlpatch;
+ metalink_get_version(&mlmaj, &mlmin, &mlpatch);
+ if((mlmaj*10000)+(mlmin*100)+mlpatch < CURL_REQ_LIBMETALINK_VERS) {
warnf(config,
"--metalink option cannot be used because the version of "
"the linked libmetalink library is too old. "
CURL_REQ_LIBMETALINK_MAJOR,
CURL_REQ_LIBMETALINK_MINOR,
CURL_REQ_LIBMETALINK_PATCH,
- major, minor, patch);
+ mlmaj, mlmin, mlpatch);
return PARAM_BAD_USE;
}
else
#endif
break;
}
+ case 'K': /* --sasl-ir */
+ 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;
+ case 'M': /* --unix-socket */
+ GetStr(&config->unix_socket_path, nextarg);
+ 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 */
case 'C':
/* This makes us continue an ftp transfer at given position */
if(!curlx_strequal(nextarg, "-")) {
- if(str2offset(&config->resume_from, nextarg))
- return PARAM_BAD_NUMERIC;
+ err = str2offset(&config->resume_from, nextarg);
+ if(err)
+ return err;
config->resume_from_current = FALSE;
}
else {
&-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;
+
+ case 'p': /* Pinned public key DER file */
+ /* Pinned public key DER file */
+ GetStr(&config->pinnedpubkey, nextarg);
+ break;
+
+ case 'q': /* --cert-status */
+ config->verifystatus = TRUE;
+ break;
+
default: /* certificate file */
{
- char *ptr = strchr(nextarg, ':');
- /* Since we live in a world of weirdness and confusion, the win32
- dudes can use : when using drive letters and thus
- c:\file:password needs to work. In order not to break
- compatibility, we still use : as separator, but we try to detect
- when it is used for a file name! On windows. */
-#ifdef WIN32
- if(ptr &&
- (ptr == &nextarg[1]) &&
- (nextarg[2] == '\\' || nextarg[2] == '/') &&
- (ISALPHA(nextarg[0])) )
- /* colon in the second column, followed by a backslash, and the
- first character is an alphabetic letter:
-
- this is a drive letter colon */
- ptr = strchr(&nextarg[3], ':'); /* find the next one instead */
-#endif
- if(ptr) {
- /* we have a password too */
- *ptr = '\0';
- ptr++;
- GetStr(&config->key_passwd, ptr);
+ char *certname, *passphrase;
+ parse_cert_parameter(nextarg, &certname, &passphrase);
+ Curl_safefree(config->cert);
+ config->cert = certname;
+ if(passphrase) {
+ Curl_safefree(config->key_passwd);
+ config->key_passwd = passphrase;
}
- GetStr(&config->cert, nextarg);
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 */
- if(str2num(&config->timeout, nextarg))
- return PARAM_BAD_NUMERIC;
+ 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) {
break;
case 'y':
/* low speed time */
- if(str2num(&config->low_speed_time, nextarg))
- return PARAM_BAD_NUMERIC;
+ err = str2unum(&config->low_speed_time, nextarg);
+ if(err)
+ return err;
if(!config->low_speed_limit)
config->low_speed_limit = 1;
break;
case 'Y':
/* low speed limit */
- if(str2num(&config->low_speed_limit, nextarg))
- return PARAM_BAD_NUMERIC;
+ err = str2unum(&config->low_speed_limit, nextarg);
+ if(err)
+ return err;
if(!config->low_speed_time)
config->low_speed_time = 30;
break;
switch(*nextarg) {
case '+':
nextarg++;
+ /* FALLTHROUGH */
default:
/* If-Modified-Since: (section 14.28 in RFC2068) */
config->timecond = CURL_TIMECOND_IFMODSINCE;
return PARAM_OK;
}
+ParameterError parse_args(struct GlobalConfig *config, int argc,
+ argv_item_t argv[])
+{
+ int i;
+ bool stillflags;
+ char *orig_opt = NULL;
+ 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(orig_opt && !curlx_strequal(":", orig_opt))
+ helpf(config->errors, "option %s: %s\n", orig_opt, reason);
+ else
+ helpf(config->errors, "%s\n", reason);
+ }
+
+ return result;
+}