Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/src/tool_getparam.c
2645 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
*
10
* This software is licensed as described in the file COPYING, which
11
* you should have received as part of this distribution. The terms
12
* are also available at https://curl.se/docs/copyright.html.
13
*
14
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
* copies of the Software, and permit persons to whom the Software is
16
* furnished to do so, under the terms of the COPYING file.
17
*
18
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
* KIND, either express or implied.
20
*
21
* SPDX-License-Identifier: curl
22
*
23
***************************************************************************/
24
#include "tool_setup.h"
25
26
#include "tool_cfgable.h"
27
#include "tool_cb_prg.h"
28
#include "tool_filetime.h"
29
#include "tool_formparse.h"
30
#include "tool_getparam.h"
31
#include "tool_helpers.h"
32
#include "tool_libinfo.h"
33
#include "tool_msgs.h"
34
#include "tool_paramhlp.h"
35
#include "tool_parsecfg.h"
36
#include "tool_main.h"
37
#include "tool_stderr.h"
38
#include "tool_help.h"
39
#include "var.h"
40
41
#include "memdebug.h" /* keep this as LAST include */
42
43
#define ALLOW_BLANK TRUE
44
#define DENY_BLANK FALSE
45
46
static ParameterError getstr(char **str, const char *val, bool allowblank)
47
{
48
if(*str) {
49
free(*str);
50
*str = NULL;
51
}
52
DEBUGASSERT(val);
53
if(!allowblank && !val[0])
54
return PARAM_BLANK_STRING;
55
56
*str = strdup(val);
57
if(!*str)
58
return PARAM_NO_MEM;
59
60
return PARAM_OK;
61
}
62
63
static ParameterError getstrn(char **str, const char *val,
64
size_t len, bool allowblank)
65
{
66
if(*str) {
67
free(*str);
68
*str = NULL;
69
}
70
DEBUGASSERT(val);
71
if(!allowblank && !val[0])
72
return PARAM_BLANK_STRING;
73
74
*str = malloc(len + 1);
75
if(!*str)
76
return PARAM_NO_MEM;
77
78
memcpy(*str, val, len);
79
(*str)[len] = 0; /* null-terminate */
80
81
return PARAM_OK;
82
}
83
84
/* this array MUST be alphasorted based on the 'lname' */
85
static const struct LongShort aliases[]= {
86
{"abstract-unix-socket", ARG_FILE, ' ', C_ABSTRACT_UNIX_SOCKET},
87
{"alpn", ARG_BOOL|ARG_NO|ARG_TLS, ' ', C_ALPN},
88
{"alt-svc", ARG_STRG, ' ', C_ALT_SVC},
89
{"anyauth", ARG_NONE, ' ', C_ANYAUTH},
90
{"append", ARG_BOOL, 'a', C_APPEND},
91
{"aws-sigv4", ARG_STRG, ' ', C_AWS_SIGV4},
92
{"basic", ARG_BOOL, ' ', C_BASIC},
93
{"buffer", ARG_BOOL|ARG_NO, 'N', C_BUFFER},
94
{"ca-native", ARG_BOOL|ARG_TLS, ' ', C_CA_NATIVE},
95
{"cacert", ARG_FILE|ARG_TLS, ' ', C_CACERT},
96
{"capath", ARG_FILE|ARG_TLS, ' ', C_CAPATH},
97
{"cert", ARG_FILE|ARG_TLS|ARG_CLEAR, 'E', C_CERT},
98
{"cert-status", ARG_BOOL|ARG_TLS, ' ', C_CERT_STATUS},
99
{"cert-type", ARG_STRG|ARG_TLS, ' ', C_CERT_TYPE},
100
{"ciphers", ARG_STRG|ARG_TLS, ' ', C_CIPHERS},
101
{"clobber", ARG_BOOL|ARG_NO, ' ', C_CLOBBER},
102
{"compressed", ARG_BOOL, ' ', C_COMPRESSED},
103
{"compressed-ssh", ARG_BOOL, ' ', C_COMPRESSED_SSH},
104
{"config", ARG_FILE, 'K', C_CONFIG},
105
{"connect-timeout", ARG_STRG, ' ', C_CONNECT_TIMEOUT},
106
{"connect-to", ARG_STRG, ' ', C_CONNECT_TO},
107
{"continue-at", ARG_STRG, 'C', C_CONTINUE_AT},
108
{"cookie", ARG_STRG, 'b', C_COOKIE},
109
{"cookie-jar", ARG_STRG, 'c', C_COOKIE_JAR},
110
{"create-dirs", ARG_BOOL, ' ', C_CREATE_DIRS},
111
{"create-file-mode", ARG_STRG, ' ', C_CREATE_FILE_MODE},
112
{"crlf", ARG_BOOL, ' ', C_CRLF},
113
{"crlfile", ARG_FILE|ARG_TLS, ' ', C_CRLFILE},
114
{"curves", ARG_STRG|ARG_TLS, ' ', C_CURVES},
115
{"data", ARG_STRG, 'd', C_DATA},
116
{"data-ascii", ARG_STRG, ' ', C_DATA_ASCII},
117
{"data-binary", ARG_STRG, ' ', C_DATA_BINARY},
118
{"data-raw", ARG_STRG, ' ', C_DATA_RAW},
119
{"data-urlencode", ARG_STRG, ' ', C_DATA_URLENCODE},
120
{"delegation", ARG_STRG, ' ', C_DELEGATION},
121
{"digest", ARG_BOOL, ' ', C_DIGEST},
122
{"disable", ARG_BOOL, 'q', C_DISABLE},
123
{"disable-eprt", ARG_BOOL, ' ', C_DISABLE_EPRT},
124
{"disable-epsv", ARG_BOOL, ' ', C_DISABLE_EPSV},
125
{"disallow-username-in-url", ARG_BOOL, ' ', C_DISALLOW_USERNAME_IN_URL},
126
{"dns-interface", ARG_STRG, ' ', C_DNS_INTERFACE},
127
{"dns-ipv4-addr", ARG_STRG, ' ', C_DNS_IPV4_ADDR},
128
{"dns-ipv6-addr", ARG_STRG, ' ', C_DNS_IPV6_ADDR},
129
{"dns-servers", ARG_STRG, ' ', C_DNS_SERVERS},
130
{"doh-cert-status", ARG_BOOL|ARG_TLS, ' ', C_DOH_CERT_STATUS},
131
{"doh-insecure", ARG_BOOL|ARG_TLS, ' ', C_DOH_INSECURE},
132
{"doh-url" , ARG_STRG, ' ', C_DOH_URL},
133
{"dump-ca-embed", ARG_NONE|ARG_TLS, ' ', C_DUMP_CA_EMBED},
134
{"dump-header", ARG_FILE, 'D', C_DUMP_HEADER},
135
{"ech", ARG_STRG|ARG_TLS, ' ', C_ECH},
136
{"egd-file", ARG_STRG|ARG_DEPR, ' ', C_EGD_FILE},
137
{"engine", ARG_STRG|ARG_TLS, ' ', C_ENGINE},
138
{"eprt", ARG_BOOL, ' ', C_EPRT},
139
{"epsv", ARG_BOOL, ' ', C_EPSV},
140
{"etag-compare", ARG_FILE, ' ', C_ETAG_COMPARE},
141
{"etag-save", ARG_FILE, ' ', C_ETAG_SAVE},
142
{"expect100-timeout", ARG_STRG, ' ', C_EXPECT100_TIMEOUT},
143
{"fail", ARG_BOOL, 'f', C_FAIL},
144
{"fail-early", ARG_BOOL, ' ', C_FAIL_EARLY},
145
{"fail-with-body", ARG_BOOL, ' ', C_FAIL_WITH_BODY},
146
{"false-start", ARG_BOOL, ' ', C_FALSE_START},
147
{"follow", ARG_BOOL, ' ', C_FOLLOW},
148
{"form", ARG_STRG, 'F', C_FORM},
149
{"form-escape", ARG_BOOL, ' ', C_FORM_ESCAPE},
150
{"form-string", ARG_STRG, ' ', C_FORM_STRING},
151
{"ftp-account", ARG_STRG, ' ', C_FTP_ACCOUNT},
152
{"ftp-alternative-to-user", ARG_STRG, ' ', C_FTP_ALTERNATIVE_TO_USER},
153
{"ftp-create-dirs", ARG_BOOL, ' ', C_FTP_CREATE_DIRS},
154
{"ftp-method", ARG_STRG, ' ', C_FTP_METHOD},
155
{"ftp-pasv", ARG_NONE, ' ', C_FTP_PASV},
156
{"ftp-port", ARG_STRG, 'P', C_FTP_PORT},
157
{"ftp-pret", ARG_BOOL, ' ', C_FTP_PRET},
158
{"ftp-skip-pasv-ip", ARG_BOOL, ' ', C_FTP_SKIP_PASV_IP},
159
{"ftp-ssl", ARG_BOOL|ARG_TLS, ' ', C_FTP_SSL},
160
{"ftp-ssl-ccc", ARG_BOOL|ARG_TLS, ' ', C_FTP_SSL_CCC},
161
{"ftp-ssl-ccc-mode", ARG_STRG|ARG_TLS, ' ', C_FTP_SSL_CCC_MODE},
162
{"ftp-ssl-control", ARG_BOOL|ARG_TLS, ' ', C_FTP_SSL_CONTROL},
163
{"ftp-ssl-reqd", ARG_BOOL|ARG_TLS, ' ', C_FTP_SSL_REQD},
164
{"get", ARG_BOOL, 'G', C_GET},
165
{"globoff", ARG_BOOL, 'g', C_GLOBOFF},
166
{"happy-eyeballs-timeout-ms", ARG_STRG, ' ', C_HAPPY_EYEBALLS_TIMEOUT_MS},
167
{"haproxy-clientip", ARG_STRG, ' ', C_HAPROXY_CLIENTIP},
168
{"haproxy-protocol", ARG_BOOL, ' ', C_HAPROXY_PROTOCOL},
169
{"head", ARG_BOOL, 'I', C_HEAD},
170
{"header", ARG_STRG, 'H', C_HEADER},
171
{"help", ARG_STRG, 'h', C_HELP},
172
{"hostpubmd5", ARG_STRG, ' ', C_HOSTPUBMD5},
173
{"hostpubsha256", ARG_STRG, ' ', C_HOSTPUBSHA256},
174
{"hsts", ARG_STRG|ARG_TLS, ' ', C_HSTS},
175
{"http0.9", ARG_BOOL, ' ', C_HTTP0_9},
176
{"http1.0", ARG_NONE, '0', C_HTTP1_0},
177
{"http1.1", ARG_NONE, ' ', C_HTTP1_1},
178
{"http2", ARG_NONE, ' ', C_HTTP2},
179
{"http2-prior-knowledge", ARG_NONE, ' ', C_HTTP2_PRIOR_KNOWLEDGE},
180
{"http3", ARG_NONE|ARG_TLS, ' ', C_HTTP3},
181
{"http3-only", ARG_NONE|ARG_TLS, ' ', C_HTTP3_ONLY},
182
{"ignore-content-length", ARG_BOOL, ' ', C_IGNORE_CONTENT_LENGTH},
183
{"include", ARG_BOOL, ' ', C_INCLUDE},
184
{"insecure", ARG_BOOL, 'k', C_INSECURE},
185
{"interface", ARG_STRG, ' ', C_INTERFACE},
186
{"ip-tos", ARG_STRG, ' ', C_IP_TOS},
187
#ifndef CURL_DISABLE_IPFS
188
{"ipfs-gateway", ARG_STRG, ' ', C_IPFS_GATEWAY},
189
#endif /* !CURL_DISABLE_IPFS */
190
{"ipv4", ARG_NONE, '4', C_IPV4},
191
{"ipv6", ARG_NONE, '6', C_IPV6},
192
{"json", ARG_STRG, ' ', C_JSON},
193
{"junk-session-cookies", ARG_BOOL, 'j', C_JUNK_SESSION_COOKIES},
194
{"keepalive", ARG_BOOL|ARG_NO, ' ', C_KEEPALIVE},
195
{"keepalive-cnt", ARG_STRG, ' ', C_KEEPALIVE_CNT},
196
{"keepalive-time", ARG_STRG, ' ', C_KEEPALIVE_TIME},
197
{"key", ARG_FILE, ' ', C_KEY},
198
{"key-type", ARG_STRG|ARG_TLS, ' ', C_KEY_TYPE},
199
{"knownhosts", ARG_FILE, ' ', C_KNOWNHOSTS},
200
{"krb", ARG_STRG|ARG_DEPR, ' ', C_KRB},
201
{"krb4", ARG_STRG|ARG_DEPR, ' ', C_KRB4},
202
{"libcurl", ARG_STRG, ' ', C_LIBCURL},
203
{"limit-rate", ARG_STRG, ' ', C_LIMIT_RATE},
204
{"list-only", ARG_BOOL, 'l', C_LIST_ONLY},
205
{"local-port", ARG_STRG, ' ', C_LOCAL_PORT},
206
{"location", ARG_BOOL, 'L', C_LOCATION},
207
{"location-trusted", ARG_BOOL, ' ', C_LOCATION_TRUSTED},
208
{"login-options", ARG_STRG, ' ', C_LOGIN_OPTIONS},
209
{"mail-auth", ARG_STRG, ' ', C_MAIL_AUTH},
210
{"mail-from", ARG_STRG, ' ', C_MAIL_FROM},
211
{"mail-rcpt", ARG_STRG, ' ', C_MAIL_RCPT},
212
{"mail-rcpt-allowfails", ARG_BOOL, ' ', C_MAIL_RCPT_ALLOWFAILS},
213
{"manual", ARG_BOOL, 'M', C_MANUAL},
214
{"max-filesize", ARG_STRG, ' ', C_MAX_FILESIZE},
215
{"max-redirs", ARG_STRG, ' ', C_MAX_REDIRS},
216
{"max-time", ARG_STRG, 'm', C_MAX_TIME},
217
{"metalink", ARG_BOOL|ARG_DEPR, ' ', C_METALINK},
218
{"mptcp", ARG_BOOL, ' ', C_MPTCP},
219
{"negotiate", ARG_BOOL, ' ', C_NEGOTIATE},
220
{"netrc", ARG_BOOL, 'n', C_NETRC},
221
{"netrc-file", ARG_FILE, ' ', C_NETRC_FILE},
222
{"netrc-optional", ARG_BOOL, ' ', C_NETRC_OPTIONAL},
223
{"next", ARG_NONE, ':', C_NEXT},
224
{"noproxy", ARG_STRG, ' ', C_NOPROXY},
225
{"npn", ARG_BOOL|ARG_DEPR, ' ', C_NPN},
226
{"ntlm", ARG_BOOL, ' ', C_NTLM},
227
{"ntlm-wb", ARG_BOOL|ARG_DEPR, ' ', C_NTLM_WB},
228
{"oauth2-bearer", ARG_STRG|ARG_CLEAR, ' ', C_OAUTH2_BEARER},
229
{"out-null", ARG_BOOL, ' ', C_OUT_NULL},
230
{"output", ARG_FILE, 'o', C_OUTPUT},
231
{"output-dir", ARG_STRG, ' ', C_OUTPUT_DIR},
232
{"parallel", ARG_BOOL, 'Z', C_PARALLEL},
233
{"parallel-immediate", ARG_BOOL, ' ', C_PARALLEL_IMMEDIATE},
234
{"parallel-max", ARG_STRG, ' ', C_PARALLEL_MAX},
235
{"parallel-max-host", ARG_STRG, ' ', C_PARALLEL_HOST},
236
{"pass", ARG_STRG|ARG_CLEAR, ' ', C_PASS},
237
{"path-as-is", ARG_BOOL, ' ', C_PATH_AS_IS},
238
{"pinnedpubkey", ARG_STRG|ARG_TLS, ' ', C_PINNEDPUBKEY},
239
{"post301", ARG_BOOL, ' ', C_POST301},
240
{"post302", ARG_BOOL, ' ', C_POST302},
241
{"post303", ARG_BOOL, ' ', C_POST303},
242
{"preproxy", ARG_STRG, ' ', C_PREPROXY},
243
{"progress-bar", ARG_BOOL, '#', C_PROGRESS_BAR},
244
{"progress-meter", ARG_BOOL|ARG_NO, ' ', C_PROGRESS_METER},
245
{"proto", ARG_STRG, ' ', C_PROTO},
246
{"proto-default", ARG_STRG, ' ', C_PROTO_DEFAULT},
247
{"proto-redir", ARG_STRG, ' ', C_PROTO_REDIR},
248
{"proxy", ARG_STRG, 'x', C_PROXY},
249
{"proxy-anyauth", ARG_BOOL, ' ', C_PROXY_ANYAUTH},
250
{"proxy-basic", ARG_BOOL, ' ', C_PROXY_BASIC},
251
{"proxy-ca-native", ARG_BOOL|ARG_TLS, ' ', C_PROXY_CA_NATIVE},
252
{"proxy-cacert", ARG_FILE|ARG_TLS, ' ', C_PROXY_CACERT},
253
{"proxy-capath", ARG_FILE|ARG_TLS, ' ', C_PROXY_CAPATH},
254
{"proxy-cert", ARG_FILE|ARG_TLS|ARG_CLEAR, ' ', C_PROXY_CERT},
255
{"proxy-cert-type", ARG_STRG|ARG_TLS, ' ', C_PROXY_CERT_TYPE},
256
{"proxy-ciphers", ARG_STRG|ARG_TLS, ' ', C_PROXY_CIPHERS},
257
{"proxy-crlfile", ARG_FILE|ARG_TLS, ' ', C_PROXY_CRLFILE},
258
{"proxy-digest", ARG_BOOL, ' ', C_PROXY_DIGEST},
259
{"proxy-header", ARG_STRG, ' ', C_PROXY_HEADER},
260
{"proxy-http2", ARG_BOOL, ' ', C_PROXY_HTTP2},
261
{"proxy-insecure", ARG_BOOL, ' ', C_PROXY_INSECURE},
262
{"proxy-key", ARG_FILE|ARG_TLS, ' ', C_PROXY_KEY},
263
{"proxy-key-type", ARG_STRG|ARG_TLS, ' ', C_PROXY_KEY_TYPE},
264
{"proxy-negotiate", ARG_BOOL, ' ', C_PROXY_NEGOTIATE},
265
{"proxy-ntlm", ARG_BOOL, ' ', C_PROXY_NTLM},
266
{"proxy-pass", ARG_STRG|ARG_CLEAR, ' ', C_PROXY_PASS},
267
{"proxy-pinnedpubkey", ARG_STRG|ARG_TLS, ' ', C_PROXY_PINNEDPUBKEY},
268
{"proxy-service-name", ARG_STRG, ' ', C_PROXY_SERVICE_NAME},
269
{"proxy-ssl-allow-beast", ARG_BOOL|ARG_TLS, ' ',
270
C_PROXY_SSL_ALLOW_BEAST},
271
{"proxy-ssl-auto-client-cert", ARG_BOOL|ARG_TLS, ' ',
272
C_PROXY_SSL_AUTO_CLIENT_CERT},
273
{"proxy-tls13-ciphers", ARG_STRG|ARG_TLS, ' ', C_PROXY_TLS13_CIPHERS},
274
{"proxy-tlsauthtype", ARG_STRG|ARG_TLS, ' ', C_PROXY_TLSAUTHTYPE},
275
{"proxy-tlspassword", ARG_STRG|ARG_TLS|ARG_CLEAR, ' ', C_PROXY_TLSPASSWORD},
276
{"proxy-tlsuser", ARG_STRG|ARG_TLS|ARG_CLEAR, ' ', C_PROXY_TLSUSER},
277
{"proxy-tlsv1", ARG_NONE|ARG_TLS, ' ', C_PROXY_TLSV1},
278
{"proxy-user", ARG_STRG|ARG_CLEAR, 'U', C_PROXY_USER},
279
{"proxy1.0", ARG_STRG, ' ', C_PROXY1_0},
280
{"proxytunnel", ARG_BOOL, 'p', C_PROXYTUNNEL},
281
{"pubkey", ARG_STRG, ' ', C_PUBKEY},
282
{"quote", ARG_STRG, 'Q', C_QUOTE},
283
{"random-file", ARG_FILE|ARG_DEPR, ' ', C_RANDOM_FILE},
284
{"range", ARG_STRG, 'r', C_RANGE},
285
{"rate", ARG_STRG, ' ', C_RATE},
286
{"raw", ARG_BOOL, ' ', C_RAW},
287
{"referer", ARG_STRG, 'e', C_REFERER},
288
{"remote-header-name", ARG_BOOL, 'J', C_REMOTE_HEADER_NAME},
289
{"remote-name", ARG_BOOL, 'O', C_REMOTE_NAME},
290
{"remote-name-all", ARG_BOOL, ' ', C_REMOTE_NAME_ALL},
291
{"remote-time", ARG_BOOL, 'R', C_REMOTE_TIME},
292
{"remove-on-error", ARG_BOOL, ' ', C_REMOVE_ON_ERROR},
293
{"request", ARG_STRG, 'X', C_REQUEST},
294
{"request-target", ARG_STRG, ' ', C_REQUEST_TARGET},
295
{"resolve", ARG_STRG, ' ', C_RESOLVE},
296
{"retry", ARG_STRG, ' ', C_RETRY},
297
{"retry-all-errors", ARG_BOOL, ' ', C_RETRY_ALL_ERRORS},
298
{"retry-connrefused", ARG_BOOL, ' ', C_RETRY_CONNREFUSED},
299
{"retry-delay", ARG_STRG, ' ', C_RETRY_DELAY},
300
{"retry-max-time", ARG_STRG, ' ', C_RETRY_MAX_TIME},
301
{"sasl-authzid", ARG_STRG, ' ', C_SASL_AUTHZID},
302
{"sasl-ir", ARG_BOOL, ' ', C_SASL_IR},
303
{"service-name", ARG_STRG, ' ', C_SERVICE_NAME},
304
{"sessionid", ARG_BOOL|ARG_NO, ' ', C_SESSIONID},
305
{"show-error", ARG_BOOL, 'S', C_SHOW_ERROR},
306
{"show-headers", ARG_BOOL, 'i', C_SHOW_HEADERS},
307
{"sigalgs", ARG_STRG|ARG_TLS, ' ',
308
C_SIGNATURE_ALGORITHMS},
309
{"silent", ARG_BOOL, 's', C_SILENT},
310
{"skip-existing", ARG_BOOL, ' ', C_SKIP_EXISTING},
311
{"socks4", ARG_STRG, ' ', C_SOCKS4},
312
{"socks4a", ARG_STRG, ' ', C_SOCKS4A},
313
{"socks5", ARG_STRG, ' ', C_SOCKS5},
314
{"socks5-basic", ARG_BOOL, ' ', C_SOCKS5_BASIC},
315
{"socks5-gssapi", ARG_BOOL, ' ', C_SOCKS5_GSSAPI},
316
{"socks5-gssapi-nec", ARG_BOOL, ' ', C_SOCKS5_GSSAPI_NEC},
317
{"socks5-gssapi-service", ARG_STRG, ' ', C_SOCKS5_GSSAPI_SERVICE},
318
{"socks5-hostname", ARG_STRG, ' ', C_SOCKS5_HOSTNAME},
319
{"speed-limit", ARG_STRG, 'Y', C_SPEED_LIMIT},
320
{"speed-time", ARG_STRG, 'y', C_SPEED_TIME},
321
{"ssl", ARG_BOOL|ARG_TLS, ' ', C_SSL},
322
{"ssl-allow-beast", ARG_BOOL|ARG_TLS, ' ', C_SSL_ALLOW_BEAST},
323
{"ssl-auto-client-cert", ARG_BOOL|ARG_TLS, ' ',
324
C_SSL_AUTO_CLIENT_CERT},
325
{"ssl-no-revoke", ARG_BOOL|ARG_TLS, ' ', C_SSL_NO_REVOKE},
326
{"ssl-reqd", ARG_BOOL|ARG_TLS, ' ', C_SSL_REQD},
327
{"ssl-revoke-best-effort", ARG_BOOL|ARG_TLS, ' ',
328
C_SSL_REVOKE_BEST_EFFORT},
329
{"ssl-sessions", ARG_FILE|ARG_TLS, ' ', C_SSL_SESSIONS},
330
{"sslv2", ARG_NONE|ARG_DEPR, '2', C_SSLV2},
331
{"sslv3", ARG_NONE|ARG_DEPR, '3', C_SSLV3},
332
{"stderr", ARG_FILE, ' ', C_STDERR},
333
{"styled-output", ARG_BOOL, ' ', C_STYLED_OUTPUT},
334
{"suppress-connect-headers", ARG_BOOL, ' ', C_SUPPRESS_CONNECT_HEADERS},
335
{"tcp-fastopen", ARG_BOOL, ' ', C_TCP_FASTOPEN},
336
{"tcp-nodelay", ARG_BOOL, ' ', C_TCP_NODELAY},
337
{"telnet-option", ARG_STRG, 't', C_TELNET_OPTION},
338
#ifdef DEBUGBUILD
339
{"test-duphandle", ARG_BOOL, ' ', C_TEST_DUPHANDLE},
340
{"test-event", ARG_BOOL, ' ', C_TEST_EVENT},
341
#endif
342
{"tftp-blksize", ARG_STRG, ' ', C_TFTP_BLKSIZE},
343
{"tftp-no-options", ARG_BOOL, ' ', C_TFTP_NO_OPTIONS},
344
{"time-cond", ARG_STRG, 'z', C_TIME_COND},
345
{"tls-earlydata", ARG_BOOL|ARG_TLS, ' ', C_TLS_EARLYDATA},
346
{"tls-max", ARG_STRG|ARG_TLS, ' ', C_TLS_MAX},
347
{"tls13-ciphers", ARG_STRG|ARG_TLS, ' ', C_TLS13_CIPHERS},
348
{"tlsauthtype", ARG_STRG|ARG_TLS, ' ', C_TLSAUTHTYPE},
349
{"tlspassword", ARG_STRG|ARG_TLS|ARG_CLEAR, ' ', C_TLSPASSWORD},
350
{"tlsuser", ARG_STRG|ARG_TLS|ARG_CLEAR, ' ', C_TLSUSER},
351
{"tlsv1", ARG_NONE|ARG_TLS, '1', C_TLSV1},
352
{"tlsv1.0", ARG_NONE|ARG_TLS, ' ', C_TLSV1_0},
353
{"tlsv1.1", ARG_NONE|ARG_TLS, ' ', C_TLSV1_1},
354
{"tlsv1.2", ARG_NONE|ARG_TLS, ' ', C_TLSV1_2},
355
{"tlsv1.3", ARG_NONE|ARG_TLS, ' ', C_TLSV1_3},
356
{"tr-encoding", ARG_BOOL, ' ', C_TR_ENCODING},
357
{"trace", ARG_FILE, ' ', C_TRACE},
358
{"trace-ascii", ARG_FILE, ' ', C_TRACE_ASCII},
359
{"trace-config", ARG_STRG, ' ', C_TRACE_CONFIG},
360
{"trace-ids", ARG_BOOL, ' ', C_TRACE_IDS},
361
{"trace-time", ARG_BOOL, ' ', C_TRACE_TIME},
362
{"unix-socket", ARG_FILE, ' ', C_UNIX_SOCKET},
363
{"upload-file", ARG_FILE, 'T', C_UPLOAD_FILE},
364
{"upload-flags", ARG_STRG, ' ', C_UPLOAD_FLAGS},
365
{"url", ARG_STRG, ' ', C_URL},
366
{"url-query", ARG_STRG, ' ', C_URL_QUERY},
367
{"use-ascii", ARG_BOOL, 'B', C_USE_ASCII},
368
{"user", ARG_STRG|ARG_CLEAR, 'u', C_USER},
369
{"user-agent", ARG_STRG, 'A', C_USER_AGENT},
370
{"variable", ARG_STRG, ' ', C_VARIABLE},
371
{"verbose", ARG_BOOL, 'v', C_VERBOSE},
372
{"version", ARG_BOOL, 'V', C_VERSION},
373
{"vlan-priority", ARG_STRG, ' ', C_VLAN_PRIORITY},
374
#ifdef USE_WATT32
375
{"wdebug", ARG_BOOL, ' ', C_WDEBUG},
376
#endif
377
{"write-out", ARG_STRG, 'w', C_WRITE_OUT},
378
{"xattr", ARG_BOOL, ' ', C_XATTR},
379
};
380
381
/* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
382
* We allow ':' and '\' to be escaped by '\' so that we can use certificate
383
* nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/>
384
* for details. */
385
#ifndef UNITTESTS
386
static
387
#endif
388
void parse_cert_parameter(const char *cert_parameter,
389
char **certname,
390
char **passphrase)
391
{
392
size_t param_length = strlen(cert_parameter);
393
size_t span;
394
const char *param_place = NULL;
395
char *certname_place = NULL;
396
*certname = NULL;
397
*passphrase = NULL;
398
399
/* most trivial assumption: cert_parameter is empty */
400
if(param_length == 0)
401
return;
402
403
/* next less trivial: cert_parameter starts 'pkcs11:' and thus
404
* looks like a RFC7512 PKCS#11 URI which can be used as-is.
405
* Also if cert_parameter contains no colon nor backslash, this
406
* means no passphrase was given and no characters escaped */
407
if(curl_strnequal(cert_parameter, "pkcs11:", 7) ||
408
!strpbrk(cert_parameter, ":\\")) {
409
*certname = strdup(cert_parameter);
410
return;
411
}
412
/* deal with escaped chars; find unescaped colon if it exists */
413
certname_place = malloc(param_length + 1);
414
if(!certname_place)
415
return;
416
417
*certname = certname_place;
418
param_place = cert_parameter;
419
while(*param_place) {
420
span = strcspn(param_place, ":\\");
421
memcpy(certname_place, param_place, span);
422
param_place += span;
423
certname_place += span;
424
/* we just ate all the non-special chars. now we are on either a special
425
* char or the end of the string. */
426
switch(*param_place) {
427
case '\0':
428
break;
429
case '\\':
430
param_place++;
431
switch(*param_place) {
432
case '\0':
433
*certname_place++ = '\\';
434
break;
435
case '\\':
436
*certname_place++ = '\\';
437
param_place++;
438
break;
439
case ':':
440
*certname_place++ = ':';
441
param_place++;
442
break;
443
default:
444
*certname_place++ = '\\';
445
*certname_place++ = *param_place;
446
param_place++;
447
break;
448
}
449
break;
450
case ':':
451
/* Since we live in a world of weirdness and confusion, the Windows
452
dudes can use : when using drive letters and thus c:\file:password
453
needs to work. In order not to break compatibility, we still use : as
454
separator, but we try to detect when it is used for a filename! On
455
Windows. */
456
#ifdef _WIN32
457
if((param_place == &cert_parameter[1]) &&
458
(cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
459
(ISALPHA(cert_parameter[0])) ) {
460
/* colon in the second column, followed by a backslash, and the
461
first character is an alphabetic letter:
462
463
this is a drive letter colon */
464
*certname_place++ = ':';
465
param_place++;
466
break;
467
}
468
#endif
469
/* escaped colons and Windows drive letter colons were handled
470
* above; if we are still here, this is a separating colon */
471
param_place++;
472
if(*param_place) {
473
*passphrase = strdup(param_place);
474
}
475
goto done;
476
}
477
}
478
done:
479
*certname_place = '\0';
480
}
481
482
/* Replace (in-place) '%20' by '+' according to RFC1866 */
483
static size_t replace_url_encoded_space_by_plus(char *url)
484
{
485
size_t orig_len = strlen(url);
486
size_t orig_index = 0;
487
size_t new_index = 0;
488
489
while(orig_index < orig_len) {
490
if((url[orig_index] == '%') &&
491
(url[orig_index + 1] == '2') &&
492
(url[orig_index + 2] == '0')) {
493
url[new_index] = '+';
494
orig_index += 3;
495
}
496
else{
497
if(new_index != orig_index) {
498
url[new_index] = url[orig_index];
499
}
500
orig_index++;
501
}
502
new_index++;
503
}
504
505
url[new_index] = 0; /* terminate string */
506
507
return new_index; /* new size */
508
}
509
510
static void
511
GetFileAndPassword(const char *nextarg, char **file, char **password)
512
{
513
char *certname, *passphrase;
514
/* nextarg is never NULL here */
515
parse_cert_parameter(nextarg, &certname, &passphrase);
516
free(*file);
517
*file = certname;
518
if(passphrase) {
519
free(*password);
520
*password = passphrase;
521
}
522
}
523
524
/* Get a size parameter for '--limit-rate' or '--max-filesize'.
525
* We support a 'G', 'M' or 'K' suffix too.
526
*/
527
static ParameterError GetSizeParameter(const char *arg,
528
const char *which,
529
curl_off_t *value_out)
530
{
531
const char *unit = arg;
532
curl_off_t value;
533
534
if(curlx_str_number(&unit, &value, CURL_OFF_T_MAX)) {
535
warnf("invalid number specified for %s", which);
536
return PARAM_BAD_USE;
537
}
538
539
if(!*unit)
540
unit = "b";
541
else if(strlen(unit) > 1)
542
unit = "w"; /* unsupported */
543
544
switch(*unit) {
545
case 'G':
546
case 'g':
547
if(value > (CURL_OFF_T_MAX / (1024*1024*1024)))
548
return PARAM_NUMBER_TOO_LARGE;
549
value *= 1024*1024*1024;
550
break;
551
case 'M':
552
case 'm':
553
if(value > (CURL_OFF_T_MAX / (1024*1024)))
554
return PARAM_NUMBER_TOO_LARGE;
555
value *= 1024*1024;
556
break;
557
case 'K':
558
case 'k':
559
if(value > (CURL_OFF_T_MAX / 1024))
560
return PARAM_NUMBER_TOO_LARGE;
561
value *= 1024;
562
break;
563
case 'b':
564
case 'B':
565
/* for plain bytes, leave as-is */
566
break;
567
default:
568
warnf("unsupported %s unit. Use G, M, K or B", which);
569
return PARAM_BAD_USE;
570
}
571
*value_out = value;
572
return PARAM_OK;
573
}
574
575
#ifdef HAVE_WRITABLE_ARGV
576
static void cleanarg(char *str)
577
{
578
/* now that getstr has copied the contents of nextarg, wipe the next
579
* argument out so that the username:password is not displayed in the
580
* system process list */
581
if(str) {
582
size_t len = strlen(str);
583
memset(str, '*', len);
584
}
585
}
586
#else
587
#define cleanarg(x) tool_nop_stmt
588
#endif
589
590
/* the maximum size we allow the dynbuf generated string */
591
#define MAX_DATAURLENCODE (500*1024*1024)
592
593
/* --data-urlencode */
594
static ParameterError data_urlencode(const char *nextarg,
595
char **postp,
596
size_t *lenp)
597
{
598
/* [name]=[content], we encode the content part only
599
* [name]@[filename]
600
*
601
* Case 2: we first load the file using that name and then encode
602
* the content.
603
*/
604
ParameterError err;
605
const char *p = strchr(nextarg, '=');
606
size_t nlen;
607
char is_file;
608
char *postdata = NULL;
609
size_t size = 0;
610
if(!p)
611
/* there was no '=' letter, check for a '@' instead */
612
p = strchr(nextarg, '@');
613
if(p) {
614
nlen = p - nextarg; /* length of the name part */
615
is_file = *p++; /* pass the separator */
616
}
617
else {
618
/* neither @ nor =, so no name and it is not a file */
619
nlen = 0;
620
is_file = 0;
621
p = nextarg;
622
}
623
if('@' == is_file) {
624
FILE *file;
625
/* a '@' letter, it means that a filename or - (stdin) follows */
626
if(!strcmp("-", p)) {
627
file = stdin;
628
CURLX_SET_BINMODE(stdin);
629
}
630
else {
631
file = curlx_fopen(p, "rb");
632
if(!file) {
633
errorf("Failed to open %s", p);
634
return PARAM_READ_ERROR;
635
}
636
}
637
638
err = file2memory(&postdata, &size, file);
639
640
if(file && (file != stdin))
641
curlx_fclose(file);
642
if(err)
643
return err;
644
}
645
else {
646
err = getstr(&postdata, p, ALLOW_BLANK);
647
if(err)
648
goto error;
649
size = strlen(postdata);
650
}
651
652
if(!postdata) {
653
/* no data from the file, point to a zero byte string to make this
654
get sent as a POST anyway */
655
postdata = strdup("");
656
if(!postdata)
657
return PARAM_NO_MEM;
658
size = 0;
659
}
660
else {
661
char *enc = curl_easy_escape(NULL, postdata, (int)size);
662
tool_safefree(postdata); /* no matter if it worked or not */
663
if(enc) {
664
char *n;
665
replace_url_encoded_space_by_plus(enc);
666
if(nlen > 0) { /* only append '=' if we have a name */
667
struct dynbuf dyn;
668
curlx_dyn_init(&dyn, MAX_DATAURLENCODE);
669
if(curlx_dyn_addn(&dyn, nextarg, nlen) ||
670
curlx_dyn_addn(&dyn, "=", 1) ||
671
curlx_dyn_add(&dyn, enc)) {
672
curl_free(enc);
673
return PARAM_NO_MEM;
674
}
675
curl_free(enc);
676
n = curlx_dyn_ptr(&dyn);
677
size = curlx_dyn_len(&dyn);
678
}
679
else {
680
n = enc;
681
size = strlen(n);
682
}
683
postdata = n;
684
}
685
else
686
return PARAM_NO_MEM;
687
}
688
*postp = postdata;
689
*lenp = size;
690
return PARAM_OK;
691
error:
692
return err;
693
}
694
695
static void sethttpver(struct OperationConfig *config,
696
long httpversion)
697
{
698
if(config->httpversion &&
699
(config->httpversion != httpversion))
700
warnf("Overrides previous HTTP version option");
701
702
config->httpversion = httpversion;
703
}
704
705
static CURLcode set_trace_config(const char *token)
706
{
707
CURLcode result = CURLE_OK;
708
const char *next, *name;
709
bool toggle;
710
711
while(token) {
712
size_t len;
713
next = strchr(token, ',');
714
715
if(next)
716
len = next - token;
717
else
718
len = strlen(token);
719
720
switch(*token) {
721
case '-':
722
toggle = FALSE;
723
name = token + 1;
724
len--;
725
break;
726
case '+':
727
toggle = TRUE;
728
name = token + 1;
729
len--;
730
break;
731
default:
732
toggle = TRUE;
733
name = token;
734
break;
735
}
736
737
if((len == 3) && curl_strnequal(name, "all", 3)) {
738
global->traceids = toggle;
739
global->tracetime = toggle;
740
if(toggle)
741
result = curl_global_trace("all,-lib-ids");
742
else
743
result = curl_global_trace(token);
744
if(result)
745
goto out;
746
}
747
else if((len == 3) && curl_strnequal(name, "ids", 3)) {
748
global->traceids = toggle;
749
}
750
else if((len == 4) && curl_strnequal(name, "time", 4)) {
751
global->tracetime = toggle;
752
}
753
else {
754
char buffer[64];
755
curl_msnprintf(buffer, sizeof(buffer), "%c%.*s,-lib-ids",
756
toggle ? '+' : '-', (int)len, name);
757
result = curl_global_trace(buffer);
758
if(result)
759
goto out;
760
}
761
if(next) {
762
next++;
763
if(*next == ' ')
764
next++;
765
}
766
token = next;
767
}
768
out:
769
return result;
770
}
771
772
static int findarg(const void *a, const void *b)
773
{
774
const struct LongShort *aa = a;
775
const struct LongShort *bb = b;
776
return strcmp(aa->lname, bb->lname);
777
}
778
779
const struct LongShort *findshortopt(char letter)
780
{
781
static const struct LongShort *singles[128 - ' ']; /* ASCII => pointer */
782
static bool singles_done = FALSE;
783
if((letter >= 127) || (letter <= ' '))
784
return NULL;
785
786
if(!singles_done) {
787
unsigned int j;
788
for(j = 0; j < CURL_ARRAYSIZE(aliases); j++) {
789
if(aliases[j].letter != ' ') {
790
unsigned char l = (unsigned char)aliases[j].letter;
791
singles[l - ' '] = &aliases[j];
792
}
793
}
794
singles_done = TRUE;
795
}
796
return singles[letter - ' '];
797
}
798
799
struct TOSEntry {
800
const char *name;
801
unsigned char value;
802
};
803
804
static const struct TOSEntry tos_entries[] = {
805
{"AF11", 0x28},
806
{"AF12", 0x30},
807
{"AF13", 0x38},
808
{"AF21", 0x48},
809
{"AF22", 0x50},
810
{"AF23", 0x58},
811
{"AF31", 0x68},
812
{"AF32", 0x70},
813
{"AF33", 0x78},
814
{"AF41", 0x88},
815
{"AF42", 0x90},
816
{"AF43", 0x98},
817
{"CE", 0x03},
818
{"CS0", 0x00},
819
{"CS1", 0x20},
820
{"CS2", 0x40},
821
{"CS3", 0x60},
822
{"CS4", 0x80},
823
{"CS5", 0xa0},
824
{"CS6", 0xc0},
825
{"CS7", 0xe0},
826
{"ECT0", 0x02},
827
{"ECT1", 0x01},
828
{"EF", 0xb8},
829
{"LE", 0x04},
830
{"LOWCOST", 0x02},
831
{"LOWDELAY", 0x10},
832
{"MINCOST", 0x02},
833
{"RELIABILITY", 0x04},
834
{"THROUGHPUT", 0x08},
835
{"VOICE-ADMIT", 0xb0}
836
};
837
838
static int find_tos(const void *a, const void *b)
839
{
840
const struct TOSEntry *aa = a;
841
const struct TOSEntry *bb = b;
842
return strcmp(aa->name, bb->name);
843
}
844
845
#define MAX_QUERY_LEN 100000 /* larger is not likely to ever work */
846
static ParameterError url_query(const char *nextarg,
847
struct OperationConfig *config)
848
{
849
size_t size = 0;
850
ParameterError err = PARAM_OK;
851
char *query;
852
struct dynbuf dyn;
853
curlx_dyn_init(&dyn, MAX_QUERY_LEN);
854
855
if(*nextarg == '+') {
856
/* use without encoding */
857
query = strdup(&nextarg[1]);
858
if(!query)
859
err = PARAM_NO_MEM;
860
}
861
else
862
err = data_urlencode(nextarg, &query, &size);
863
864
if(!err) {
865
if(config->query) {
866
CURLcode result = curlx_dyn_addf(&dyn, "%s&%s", config->query, query);
867
free(query);
868
if(result)
869
err = PARAM_NO_MEM;
870
else {
871
free(config->query);
872
config->query = curlx_dyn_ptr(&dyn);
873
}
874
}
875
else
876
config->query = query;
877
}
878
return err;
879
}
880
881
static ParameterError set_data(cmdline_t cmd,
882
const char *nextarg,
883
struct OperationConfig *config)
884
{
885
char *postdata = NULL;
886
FILE *file;
887
size_t size = 0;
888
ParameterError err = PARAM_OK;
889
890
if(cmd == C_DATA_URLENCODE) { /* --data-urlencode */
891
err = data_urlencode(nextarg, &postdata, &size);
892
if(err)
893
return err;
894
}
895
else if('@' == *nextarg && (cmd != C_DATA_RAW)) {
896
/* the data begins with a '@' letter, it means that a filename
897
or - (stdin) follows */
898
nextarg++; /* pass the @ */
899
900
if(!strcmp("-", nextarg)) {
901
file = stdin;
902
if(cmd == C_DATA_BINARY) /* forced data-binary */
903
CURLX_SET_BINMODE(stdin);
904
}
905
else {
906
file = curlx_fopen(nextarg, "rb");
907
if(!file) {
908
errorf("Failed to open %s", nextarg);
909
return PARAM_READ_ERROR;
910
}
911
}
912
913
if((cmd == C_DATA_BINARY) || /* --data-binary */
914
(cmd == C_JSON) /* --json */)
915
/* forced binary */
916
err = file2memory(&postdata, &size, file);
917
else {
918
err = file2string(&postdata, file);
919
if(postdata)
920
size = strlen(postdata);
921
}
922
923
if(file && (file != stdin))
924
curlx_fclose(file);
925
if(err)
926
return err;
927
928
if(!postdata) {
929
/* no data from the file, point to a zero byte string to make this
930
get sent as a POST anyway */
931
postdata = strdup("");
932
if(!postdata)
933
return PARAM_NO_MEM;
934
}
935
}
936
else {
937
err = getstr(&postdata, nextarg, ALLOW_BLANK);
938
if(err)
939
return err;
940
size = strlen(postdata);
941
}
942
if(cmd == C_JSON)
943
config->jsoned = TRUE;
944
945
if(curlx_dyn_len(&config->postdata)) {
946
/* skip separator append for --json */
947
if(!err && (cmd != C_JSON) &&
948
curlx_dyn_addn(&config->postdata, "&", 1))
949
err = PARAM_NO_MEM;
950
}
951
952
if(!err && curlx_dyn_addn(&config->postdata, postdata, size))
953
err = PARAM_NO_MEM;
954
955
tool_safefree(postdata);
956
957
config->postfields = curlx_dyn_ptr(&config->postdata);
958
return err;
959
}
960
961
static ParameterError set_rate(const char *nextarg)
962
{
963
/* --rate */
964
/* support a few different suffixes, extract the suffix first, then
965
get the number and convert to per hour.
966
/s == per second
967
/m == per minute
968
/h == per hour (default)
969
/d == per day (24 hours)
970
*/
971
ParameterError err = PARAM_OK;
972
const char *div = strchr(nextarg, '/');
973
char number[26];
974
long denominator;
975
long numerator = 60*60*1000; /* default per hour */
976
size_t numlen = div ? (size_t)(div - nextarg) : strlen(nextarg);
977
if(numlen > sizeof(number) -1)
978
return PARAM_NUMBER_TOO_LARGE;
979
980
memcpy(number, nextarg, numlen);
981
number[numlen] = 0;
982
err = str2unum(&denominator, number);
983
if(err)
984
return err;
985
986
if(denominator < 1)
987
return PARAM_BAD_USE;
988
989
if(div) {
990
curl_off_t numunits;
991
div++;
992
993
if(curlx_str_number(&div, &numunits, CURL_OFF_T_MAX))
994
numunits = 1;
995
996
switch(*div) {
997
case 's': /* per second */
998
numerator = 1000;
999
break;
1000
case 'm': /* per minute */
1001
numerator = 60*1000;
1002
break;
1003
case 'h': /* per hour */
1004
break;
1005
case 'd': /* per day */
1006
numerator = 24*60*60*1000;
1007
break;
1008
default:
1009
errorf("unsupported --rate unit");
1010
err = PARAM_BAD_USE;
1011
break;
1012
}
1013
1014
if((LONG_MAX / numerator) < numunits) {
1015
/* overflow, too large number */
1016
errorf("too large --rate unit");
1017
err = PARAM_NUMBER_TOO_LARGE;
1018
}
1019
else
1020
/* this typecast is okay based on the check above */
1021
numerator *= (long)numunits;
1022
}
1023
1024
if(err)
1025
;
1026
else if(denominator > numerator)
1027
err = PARAM_NUMBER_TOO_LARGE;
1028
else
1029
global->ms_per_transfer = numerator/denominator;
1030
1031
return err;
1032
}
1033
1034
const struct LongShort *findlongopt(const char *opt)
1035
{
1036
struct LongShort key;
1037
key.lname = opt;
1038
1039
return bsearch(&key, aliases, CURL_ARRAYSIZE(aliases),
1040
sizeof(aliases[0]), findarg);
1041
}
1042
1043
static ParameterError add_url(struct OperationConfig *config,
1044
const char *thisurl,
1045
bool remote_noglob)
1046
{
1047
ParameterError err = PARAM_OK;
1048
struct getout *url;
1049
1050
if(!config->url_get)
1051
config->url_get = config->url_list;
1052
1053
if(config->url_get) {
1054
/* there is a node here, if it already is filled-in continue to find
1055
an "empty" node */
1056
while(config->url_get && config->url_get->urlset)
1057
config->url_get = config->url_get->next;
1058
}
1059
1060
/* now there might or might not be an available node to fill in! */
1061
1062
if(config->url_get)
1063
/* existing node */
1064
url = config->url_get;
1065
else
1066
/* there was no free node, create one! */
1067
config->url_get = url = new_getout(config);
1068
1069
if(!url)
1070
return PARAM_NO_MEM;
1071
else {
1072
/* fill in the URL */
1073
err = getstr(&url->url, thisurl, DENY_BLANK);
1074
url->urlset = TRUE;
1075
if(remote_noglob)
1076
url->useremote = url->noglob = TRUE;
1077
if(!err && (++config->num_urls > 1) &&
1078
(config->etag_save_file || config->etag_compare_file)) {
1079
errorf("The etag options only work on a single URL");
1080
return PARAM_BAD_USE;
1081
}
1082
}
1083
return err;
1084
}
1085
1086
static ParameterError parse_url(struct OperationConfig *config,
1087
const char *nextarg)
1088
{
1089
/* nextarg is never NULL here */
1090
if(nextarg[0] == '@') {
1091
/* read URLs from a file, treat all as -O */
1092
struct dynbuf line;
1093
ParameterError err = PARAM_OK;
1094
bool error = FALSE;
1095
bool fromstdin = !strcmp("-", &nextarg[1]);
1096
FILE *f;
1097
1098
if(fromstdin)
1099
f = stdin;
1100
else
1101
f = curlx_fopen(&nextarg[1], FOPEN_READTEXT);
1102
if(f) {
1103
curlx_dyn_init(&line, 8092);
1104
while(my_get_line(f, &line, &error)) {
1105
const char *ptr = curlx_dyn_ptr(&line);
1106
err = add_url(config, ptr, TRUE);
1107
if(err)
1108
break;
1109
}
1110
if(!fromstdin)
1111
curlx_fclose(f);
1112
curlx_dyn_free(&line);
1113
if(error || err)
1114
return PARAM_READ_ERROR;
1115
return PARAM_OK;
1116
}
1117
return PARAM_READ_ERROR; /* file not found */
1118
}
1119
return add_url(config, nextarg, FALSE);
1120
}
1121
1122
1123
static ParameterError parse_localport(struct OperationConfig *config,
1124
const char *nextarg)
1125
{
1126
const char *pp = NULL;
1127
const char *p = nextarg;
1128
char buffer[22];
1129
size_t plen = 0;
1130
while(ISDIGIT(*p))
1131
p++;
1132
plen = p - nextarg;
1133
if(*p) {
1134
pp = p;
1135
/* check for ' - [end]' */
1136
if(ISBLANK(*pp))
1137
pp++;
1138
if(*pp != '-')
1139
return PARAM_BAD_USE;
1140
pp++;
1141
if(ISBLANK(*pp))
1142
pp++;
1143
}
1144
curl_msnprintf(buffer, sizeof(buffer), "%.*s", (int)plen, nextarg);
1145
if(str2unummax(&config->localport, buffer, 65535))
1146
return PARAM_BAD_USE;
1147
if(!pp)
1148
config->localportrange = 1; /* default number of ports to try */
1149
else {
1150
if(str2unummax(&config->localportrange, pp, 65535))
1151
return PARAM_BAD_USE;
1152
config->localportrange -= (config->localport-1);
1153
if(config->localportrange < 1)
1154
return PARAM_BAD_USE;
1155
}
1156
return PARAM_OK;
1157
}
1158
1159
static ParameterError parse_continue_at(struct OperationConfig *config,
1160
const char *nextarg)
1161
{
1162
ParameterError err = PARAM_OK;
1163
if(config->range) {
1164
errorf("--continue-at is mutually exclusive with --range");
1165
return PARAM_BAD_USE;
1166
}
1167
if(config->rm_partial) {
1168
errorf("--continue-at is mutually exclusive with --remove-on-error");
1169
return PARAM_BAD_USE;
1170
}
1171
if(config->file_clobber_mode == CLOBBER_NEVER) {
1172
errorf("--continue-at is mutually exclusive with --no-clobber");
1173
return PARAM_BAD_USE;
1174
}
1175
/* This makes us continue an ftp transfer at given position */
1176
if(strcmp(nextarg, "-")) {
1177
err = str2offset(&config->resume_from, nextarg);
1178
config->resume_from_current = FALSE;
1179
}
1180
else {
1181
config->resume_from_current = TRUE;
1182
config->resume_from = 0;
1183
}
1184
config->use_resume = TRUE;
1185
return err;
1186
}
1187
1188
static ParameterError parse_ech(struct OperationConfig *config,
1189
const char *nextarg)
1190
{
1191
ParameterError err = PARAM_OK;
1192
if(!feature_ech)
1193
err = PARAM_LIBCURL_DOESNT_SUPPORT;
1194
else if(strlen(nextarg) > 4 && curl_strnequal("pn:", nextarg, 3)) {
1195
/* a public_name */
1196
err = getstr(&config->ech_public, nextarg, DENY_BLANK);
1197
}
1198
else if(strlen(nextarg) > 5 && curl_strnequal("ecl:", nextarg, 4)) {
1199
/* an ECHConfigList */
1200
if('@' != *(nextarg + 4)) {
1201
err = getstr(&config->ech_config, nextarg, DENY_BLANK);
1202
}
1203
else {
1204
/* Indirect case: @filename or @- for stdin */
1205
char *tmpcfg = NULL;
1206
FILE *file;
1207
1208
nextarg += 5; /* skip over 'ecl:@' */
1209
if(!strcmp("-", nextarg)) {
1210
file = stdin;
1211
}
1212
else {
1213
file = curlx_fopen(nextarg, FOPEN_READTEXT);
1214
}
1215
if(!file) {
1216
warnf("Couldn't read file \"%s\" "
1217
"specified for \"--ech ecl:\" option",
1218
nextarg);
1219
return PARAM_BAD_USE; /* */
1220
}
1221
err = file2string(&tmpcfg, file);
1222
if(file != stdin)
1223
curlx_fclose(file);
1224
if(err)
1225
return err;
1226
config->ech_config = curl_maprintf("ecl:%s",tmpcfg);
1227
free(tmpcfg);
1228
if(!config->ech_config)
1229
return PARAM_NO_MEM;
1230
} /* file done */
1231
}
1232
else {
1233
/* Simple case: just a string, with a keyword */
1234
err = getstr(&config->ech, nextarg, DENY_BLANK);
1235
}
1236
return err;
1237
}
1238
1239
static ParameterError parse_header(struct OperationConfig *config,
1240
cmdline_t cmd,
1241
const char *nextarg)
1242
{
1243
ParameterError err = PARAM_OK;
1244
1245
/* A custom header to append to a list */
1246
if(nextarg[0] == '@') {
1247
/* read many headers from a file or stdin */
1248
bool use_stdin = !strcmp(&nextarg[1], "-");
1249
FILE *file = use_stdin ? stdin : curlx_fopen(&nextarg[1], FOPEN_READTEXT);
1250
if(!file) {
1251
errorf("Failed to open %s", &nextarg[1]);
1252
err = PARAM_READ_ERROR;
1253
}
1254
else {
1255
struct dynbuf line;
1256
bool error = FALSE;
1257
curlx_dyn_init(&line, 1024*100);
1258
while(my_get_line(file, &line, &error)) {
1259
const char *ptr = curlx_dyn_ptr(&line);
1260
err = add2list(cmd == C_PROXY_HEADER ? /* --proxy-header? */
1261
&config->proxyheaders :
1262
&config->headers, ptr);
1263
if(err)
1264
break;
1265
}
1266
if(error)
1267
err = PARAM_READ_ERROR;
1268
curlx_dyn_free(&line);
1269
if(!use_stdin)
1270
curlx_fclose(file);
1271
}
1272
}
1273
else {
1274
if(!strchr(nextarg, ':') && !strchr(nextarg, ';')) {
1275
warnf("The provided %s header '%s' does not look like a header?",
1276
(cmd == C_PROXY_HEADER) ? "proxy": "HTTP", nextarg);
1277
}
1278
if(cmd == C_PROXY_HEADER) /* --proxy-header */
1279
err = add2list(&config->proxyheaders, nextarg);
1280
else
1281
err = add2list(&config->headers, nextarg);
1282
}
1283
return err;
1284
}
1285
1286
static ParameterError parse_output(struct OperationConfig *config,
1287
const char *nextarg)
1288
{
1289
ParameterError err = PARAM_OK;
1290
struct getout *url;
1291
1292
/* output file */
1293
if(!config->url_out)
1294
config->url_out = config->url_list;
1295
if(config->url_out) {
1296
/* there is a node here, if it already is filled-in continue to find
1297
an "empty" node */
1298
while(config->url_out && config->url_out->outset)
1299
config->url_out = config->url_out->next;
1300
}
1301
1302
/* now there might or might not be an available node to fill in! */
1303
1304
if(config->url_out)
1305
/* existing node */
1306
url = config->url_out;
1307
else {
1308
/* there was no free node, create one! */
1309
config->url_out = url = new_getout(config);
1310
}
1311
1312
if(!url)
1313
return PARAM_NO_MEM;
1314
1315
/* fill in the outfile */
1316
if(nextarg)
1317
err = getstr(&url->outfile, nextarg, DENY_BLANK);
1318
else
1319
url->outfile = NULL;
1320
url->useremote = FALSE; /* switch off */
1321
url->outset = TRUE;
1322
url->out_null = !nextarg;
1323
return err;
1324
}
1325
1326
static ParameterError parse_remote_name(struct OperationConfig *config,
1327
bool toggle)
1328
{
1329
ParameterError err = PARAM_OK;
1330
struct getout *url;
1331
1332
if(!toggle && !config->remote_name_all)
1333
return err; /* nothing to do */
1334
1335
/* output file */
1336
if(!config->url_out)
1337
config->url_out = config->url_list;
1338
if(config->url_out) {
1339
/* there is a node here, if it already is filled-in continue to find
1340
an "empty" node */
1341
while(config->url_out && config->url_out->outset)
1342
config->url_out = config->url_out->next;
1343
}
1344
1345
/* now there might or might not be an available node to fill in! */
1346
1347
if(config->url_out)
1348
/* existing node */
1349
url = config->url_out;
1350
else {
1351
/* there was no free node, create one! */
1352
config->url_out = url = new_getout(config);
1353
}
1354
1355
if(!url)
1356
return PARAM_NO_MEM;
1357
1358
url->outfile = NULL; /* leave it */
1359
url->useremote = toggle;
1360
url->outset = TRUE;
1361
url->out_null = FALSE;
1362
return PARAM_OK;
1363
}
1364
1365
static ParameterError parse_quote(struct OperationConfig *config,
1366
const char *nextarg)
1367
{
1368
ParameterError err = PARAM_OK;
1369
1370
/* QUOTE command to send to FTP server */
1371
switch(nextarg[0]) {
1372
case '-':
1373
/* prefixed with a dash makes it a POST TRANSFER one */
1374
nextarg++;
1375
err = add2list(&config->postquote, nextarg);
1376
break;
1377
case '+':
1378
/* prefixed with a plus makes it a just-before-transfer one */
1379
nextarg++;
1380
err = add2list(&config->prequote, nextarg);
1381
break;
1382
default:
1383
err = add2list(&config->quote, nextarg);
1384
break;
1385
}
1386
return err;
1387
}
1388
1389
static ParameterError parse_range(struct OperationConfig *config,
1390
const char *nextarg)
1391
{
1392
ParameterError err = PARAM_OK;
1393
curl_off_t value;
1394
const char *orig = nextarg;
1395
1396
if(config->use_resume) {
1397
errorf("--continue-at is mutually exclusive with --range");
1398
return PARAM_BAD_USE;
1399
}
1400
if(!curlx_str_number(&nextarg, &value, CURL_OFF_T_MAX) &&
1401
curlx_str_single(&nextarg, '-')) {
1402
/* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1403
(and will not actually be range by definition). The manpage previously
1404
claimed that to be a good way, why this code is added to work-around
1405
it. */
1406
char buffer[32];
1407
warnf("A specified range MUST include at least one dash (-). "
1408
"Appending one for you");
1409
curl_msnprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-",
1410
value);
1411
free(config->range);
1412
config->range = strdup(buffer);
1413
if(!config->range)
1414
err = PARAM_NO_MEM;
1415
}
1416
else {
1417
/* byte range requested */
1418
while(*nextarg) {
1419
if(!ISDIGIT(*nextarg) && *nextarg != '-' && *nextarg != ',') {
1420
warnf("Invalid character is found in given range. "
1421
"A specified range MUST have only digits in "
1422
"\'start\'-\'stop\'. The server's response to this "
1423
"request is uncertain.");
1424
break;
1425
}
1426
nextarg++;
1427
}
1428
err = getstr(&config->range, orig, DENY_BLANK);
1429
}
1430
return err;
1431
}
1432
1433
static ParameterError parse_upload_file(struct OperationConfig *config,
1434
const char *nextarg)
1435
{
1436
ParameterError err = PARAM_OK;
1437
struct getout *url;
1438
1439
/* we are uploading */
1440
if(!config->url_ul)
1441
config->url_ul = config->url_list;
1442
if(config->url_ul) {
1443
/* there is a node here, if it already is filled-in continue to find
1444
an "empty" node */
1445
while(config->url_ul && config->url_ul->uploadset)
1446
config->url_ul = config->url_ul->next;
1447
}
1448
1449
/* now there might or might not be an available node to fill in! */
1450
1451
if(config->url_ul)
1452
/* existing node */
1453
url = config->url_ul;
1454
else
1455
/* there was no free node, create one! */
1456
config->url_ul = url = new_getout(config);
1457
1458
if(!url)
1459
return PARAM_NO_MEM;
1460
1461
url->uploadset = TRUE; /* mark -T used */
1462
if(!*nextarg)
1463
url->noupload = TRUE;
1464
else {
1465
/* "-" equals stdin, but keep the string around for now */
1466
err = getstr(&url->infile, nextarg, DENY_BLANK);
1467
}
1468
return err;
1469
}
1470
1471
static size_t verbose_nopts;
1472
1473
static ParameterError parse_verbose(bool toggle)
1474
{
1475
ParameterError err = PARAM_OK;
1476
1477
/* This option is a super-boolean with side effect when applied
1478
* more than once in the same argument flag, like `-vvv`. */
1479
if(!toggle) {
1480
global->verbosity = 0;
1481
if(set_trace_config("-all"))
1482
err = PARAM_NO_MEM;
1483
global->tracetype = TRACE_NONE;
1484
return err;
1485
}
1486
else if(!verbose_nopts) {
1487
/* fist `-v` in an argument resets to base verbosity */
1488
global->verbosity = 0;
1489
if(!global->trace_set && set_trace_config("-all"))
1490
return PARAM_NO_MEM;
1491
}
1492
/* the '%' thing here will cause the trace get sent to stderr */
1493
switch(global->verbosity) {
1494
case 0:
1495
global->verbosity = 1;
1496
free(global->trace_dump);
1497
global->trace_dump = strdup("%");
1498
if(!global->trace_dump)
1499
err = PARAM_NO_MEM;
1500
else {
1501
if(global->tracetype && (global->tracetype != TRACE_PLAIN))
1502
warnf("-v, --verbose overrides an earlier trace option");
1503
global->tracetype = TRACE_PLAIN;
1504
}
1505
break;
1506
case 1:
1507
global->verbosity = 2;
1508
if(set_trace_config("ids,time,protocol"))
1509
err = PARAM_NO_MEM;
1510
break;
1511
case 2:
1512
global->verbosity = 3;
1513
global->tracetype = TRACE_ASCII;
1514
if(set_trace_config("ssl,read,write"))
1515
err = PARAM_NO_MEM;
1516
break;
1517
case 3:
1518
global->verbosity = 4;
1519
if(set_trace_config("network"))
1520
err = PARAM_NO_MEM;
1521
break;
1522
default:
1523
/* no effect for now */
1524
break;
1525
}
1526
return err;
1527
}
1528
1529
static ParameterError parse_writeout(struct OperationConfig *config,
1530
const char *nextarg)
1531
{
1532
ParameterError err = PARAM_OK;
1533
1534
/* get the output string */
1535
if('@' == *nextarg) {
1536
/* the data begins with a '@' letter, it means that a filename
1537
or - (stdin) follows */
1538
FILE *file;
1539
const char *fname;
1540
nextarg++; /* pass the @ */
1541
if(!strcmp("-", nextarg)) {
1542
fname = "<stdin>";
1543
file = stdin;
1544
}
1545
else {
1546
fname = nextarg;
1547
file = curlx_fopen(fname, FOPEN_READTEXT);
1548
if(!file) {
1549
errorf("Failed to open %s", fname);
1550
return PARAM_READ_ERROR;
1551
}
1552
}
1553
tool_safefree(config->writeout);
1554
err = file2string(&config->writeout, file);
1555
if(file && (file != stdin))
1556
curlx_fclose(file);
1557
if(err)
1558
return err;
1559
if(!config->writeout)
1560
warnf("Failed to read %s", fname);
1561
}
1562
else
1563
err = getstr(&config->writeout, nextarg, ALLOW_BLANK);
1564
1565
return err;
1566
}
1567
1568
static ParameterError parse_time_cond(struct OperationConfig *config,
1569
const char *nextarg)
1570
{
1571
ParameterError err = PARAM_OK;
1572
1573
switch(*nextarg) {
1574
case '+':
1575
nextarg++;
1576
FALLTHROUGH();
1577
default:
1578
/* If-Modified-Since: (section 14.28 in RFC2068) */
1579
config->timecond = CURL_TIMECOND_IFMODSINCE;
1580
break;
1581
case '-':
1582
/* If-Unmodified-Since: (section 14.24 in RFC2068) */
1583
config->timecond = CURL_TIMECOND_IFUNMODSINCE;
1584
nextarg++;
1585
break;
1586
case '=':
1587
/* Last-Modified: (section 14.29 in RFC2068) */
1588
config->timecond = CURL_TIMECOND_LASTMOD;
1589
nextarg++;
1590
break;
1591
}
1592
config->condtime = (curl_off_t)curl_getdate(nextarg, NULL);
1593
if(config->condtime == -1) {
1594
curl_off_t value;
1595
/* now let's see if it is a filename to get the time from instead! */
1596
int rc = getfiletime(nextarg, &value);
1597
if(!rc)
1598
/* pull the time out from the file */
1599
config->condtime = value;
1600
else {
1601
/* failed, remove time condition */
1602
config->timecond = CURL_TIMECOND_NONE;
1603
warnf("Illegal date format for -z, --time-cond (and not "
1604
"a filename). Disabling time condition. "
1605
"See curl_getdate(3) for valid date syntax.");
1606
}
1607
}
1608
return err;
1609
}
1610
1611
struct flagmap {
1612
const char *name;
1613
size_t len;
1614
unsigned char flag;
1615
};
1616
1617
static const struct flagmap flag_table[] = {
1618
{"answered", 8, CURLULFLAG_ANSWERED},
1619
{"deleted", 7, CURLULFLAG_DELETED},
1620
{"draft", 5, CURLULFLAG_DRAFT},
1621
{"flagged", 7, CURLULFLAG_FLAGGED},
1622
{"seen", 4, CURLULFLAG_SEEN},
1623
{NULL, 0, 0}
1624
};
1625
1626
static ParameterError parse_upload_flags(struct OperationConfig *config,
1627
const char *flag)
1628
{
1629
ParameterError err = PARAM_OK;
1630
1631
while(flag) {
1632
bool negate;
1633
const struct flagmap *map;
1634
size_t len;
1635
char *next = strchr(flag, ','); /* Find next comma or end */
1636
if(next)
1637
len = next - flag;
1638
else
1639
len = strlen(flag);
1640
1641
negate = (*flag == '-');
1642
if(negate) {
1643
flag++;
1644
len--;
1645
}
1646
1647
for(map = flag_table; map->name; map++) {
1648
if((len == map->len) && !strncmp(flag, map->name, map->len)) {
1649
if(negate)
1650
config->upload_flags &= (unsigned char)~map->flag;
1651
else
1652
config->upload_flags |= map->flag;
1653
break;
1654
}
1655
}
1656
1657
if(!map->name) {
1658
err = PARAM_OPTION_UNKNOWN;
1659
break;
1660
}
1661
1662
if(next)
1663
/* move over the comma */
1664
next++;
1665
flag = next;
1666
}
1667
1668
return err;
1669
}
1670
1671
/* if 'toggle' is TRUE, set the 'bits' in 'modify'.
1672
if 'toggle' is FALSE, clear the 'bits' in 'modify'
1673
*/
1674
static void togglebit(bool toggle, unsigned long *modify, unsigned long bits)
1675
{
1676
if(toggle)
1677
*modify |= bits;
1678
else
1679
*modify &= ~bits;
1680
}
1681
1682
/* opt_depr is the function that handles ARG_DEPR options */
1683
static void opt_depr(const struct LongShort *a)
1684
{
1685
warnf("--%s is deprecated and has no function anymore", a->lname);
1686
}
1687
1688
static ParameterError opt_sslver(struct OperationConfig *config,
1689
unsigned char ver)
1690
{
1691
if(config->ssl_version_max &&
1692
(config->ssl_version_max < ver)) {
1693
errorf("Minimum TLS version set higher than max");
1694
return PARAM_BAD_USE;
1695
}
1696
config->ssl_version = ver;
1697
return PARAM_OK;
1698
}
1699
1700
/* opt_none is the function that handles ARG_NONE options */
1701
static ParameterError opt_none(struct OperationConfig *config,
1702
const struct LongShort *a)
1703
{
1704
ParameterError err = PARAM_OK;
1705
switch(a->cmd) {
1706
case C_ANYAUTH: /* --anyauth */
1707
config->authtype = CURLAUTH_ANY;
1708
break;
1709
case C_DUMP_CA_EMBED: /* --dump-ca-embed */
1710
return PARAM_CA_EMBED_REQUESTED;
1711
case C_FTP_PASV: /* --ftp-pasv */
1712
tool_safefree(config->ftpport);
1713
break;
1714
1715
case C_HTTP1_0: /* --http1.0 */
1716
/* HTTP version 1.0 */
1717
sethttpver(config, CURL_HTTP_VERSION_1_0);
1718
break;
1719
case C_HTTP1_1: /* --http1.1 */
1720
/* HTTP version 1.1 */
1721
sethttpver(config, CURL_HTTP_VERSION_1_1);
1722
break;
1723
case C_HTTP2: /* --http2 */
1724
/* HTTP version 2.0 */
1725
if(!feature_http2)
1726
return PARAM_LIBCURL_DOESNT_SUPPORT;
1727
sethttpver(config, CURL_HTTP_VERSION_2_0);
1728
break;
1729
case C_HTTP2_PRIOR_KNOWLEDGE: /* --http2-prior-knowledge */
1730
/* HTTP version 2.0 over clean TCP */
1731
if(!feature_http2)
1732
return PARAM_LIBCURL_DOESNT_SUPPORT;
1733
sethttpver(config, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
1734
break;
1735
case C_HTTP3: /* --http3: */
1736
/* Try HTTP/3, allow fallback */
1737
if(!feature_http3)
1738
return PARAM_LIBCURL_DOESNT_SUPPORT;
1739
else
1740
sethttpver(config, CURL_HTTP_VERSION_3);
1741
break;
1742
case C_HTTP3_ONLY: /* --http3-only */
1743
/* Try HTTP/3 without fallback */
1744
if(!feature_http3)
1745
return PARAM_LIBCURL_DOESNT_SUPPORT;
1746
else
1747
sethttpver(config, CURL_HTTP_VERSION_3ONLY);
1748
break;
1749
case C_TLSV1: /* --tlsv1 */
1750
err = opt_sslver(config, 1);
1751
break;
1752
case C_TLSV1_0: /* --tlsv1.0 */
1753
err = opt_sslver(config, 1);
1754
break;
1755
case C_TLSV1_1: /* --tlsv1.1 */
1756
err = opt_sslver(config, 2);
1757
break;
1758
case C_TLSV1_2: /* --tlsv1.2 */
1759
err = opt_sslver(config, 3);
1760
break;
1761
case C_TLSV1_3: /* --tlsv1.3 */
1762
err = opt_sslver(config, 4);
1763
break;
1764
case C_IPV4: /* --ipv4 */
1765
config->ip_version = CURL_IPRESOLVE_V4;
1766
break;
1767
case C_IPV6: /* --ipv6 */
1768
config->ip_version = CURL_IPRESOLVE_V6;
1769
break;
1770
case C_NEXT: /* --next */
1771
return PARAM_NEXT_OPERATION;
1772
case C_PROXY_TLSV1: /* --proxy-tlsv1 */
1773
/* TLS version 1 for proxy */
1774
config->proxy_ssl_version = CURL_SSLVERSION_TLSv1;
1775
break;
1776
}
1777
return err;
1778
}
1779
1780
/* opt_bool is the function that handles boolean options */
1781
static ParameterError opt_bool(struct OperationConfig *config,
1782
const struct LongShort *a,
1783
bool toggle)
1784
{
1785
switch(a->cmd) {
1786
case C_ALPN: /* --alpn */
1787
config->noalpn = !toggle;
1788
break;
1789
case C_DISABLE_EPSV: /* --disable-epsv */
1790
config->disable_epsv = toggle;
1791
break;
1792
case C_DISALLOW_USERNAME_IN_URL: /* --disallow-username-in-url */
1793
config->disallow_username_in_url = toggle;
1794
break;
1795
case C_EPSV: /* --epsv */
1796
config->disable_epsv = !toggle;
1797
break;
1798
case C_COMPRESSED: /* --compressed */
1799
if(toggle && !(feature_libz || feature_brotli || feature_zstd))
1800
return PARAM_LIBCURL_DOESNT_SUPPORT;
1801
else
1802
config->encoding = toggle;
1803
break;
1804
case C_TR_ENCODING: /* --tr-encoding */
1805
config->tr_encoding = toggle;
1806
break;
1807
case C_DIGEST: /* --digest */
1808
togglebit(toggle, &config->authtype, CURLAUTH_DIGEST);
1809
break;
1810
case C_FTP_CREATE_DIRS: /* --ftp-create-dirs */
1811
config->ftp_create_dirs = toggle;
1812
break;
1813
case C_CREATE_DIRS: /* --create-dirs */
1814
config->create_dirs = toggle;
1815
break;
1816
case C_PROXY_NTLM: /* --proxy-ntlm */
1817
if(!feature_ntlm)
1818
return PARAM_LIBCURL_DOESNT_SUPPORT;
1819
else
1820
config->proxyntlm = toggle;
1821
break;
1822
case C_CRLF: /* --crlf */
1823
config->crlf = toggle;
1824
break;
1825
case C_HAPROXY_PROTOCOL: /* --haproxy-protocol */
1826
config->haproxy_protocol = toggle;
1827
break;
1828
case C_NEGOTIATE: /* --negotiate */
1829
if(!feature_spnego && toggle)
1830
return PARAM_LIBCURL_DOESNT_SUPPORT;
1831
togglebit(toggle, &config->authtype, CURLAUTH_NEGOTIATE);
1832
break;
1833
case C_NTLM: /* --ntlm */
1834
if(!feature_ntlm && toggle)
1835
return PARAM_LIBCURL_DOESNT_SUPPORT;
1836
togglebit(toggle, &config->authtype, CURLAUTH_NTLM);
1837
break;
1838
case C_OUT_NULL: /* --out-null */
1839
return parse_output(config, NULL);
1840
case C_BASIC: /* --basic */
1841
togglebit(toggle, &config->authtype, CURLAUTH_BASIC);
1842
break;
1843
#ifdef USE_WATT32
1844
case C_WDEBUG: /* --wdebug */
1845
dbug_init();
1846
break;
1847
#endif
1848
case C_DISABLE_EPRT: /* --disable-eprt */
1849
config->disable_eprt = toggle;
1850
break;
1851
case C_EPRT: /* --eprt */
1852
config->disable_eprt = !toggle;
1853
break;
1854
case C_XATTR: /* --xattr */
1855
config->xattr = toggle;
1856
break;
1857
case C_FTP_SSL: /* --ftp-ssl */
1858
case C_SSL: /* --ssl */
1859
config->ftp_ssl = toggle;
1860
if(config->ftp_ssl)
1861
warnf("--%s is an insecure option, consider --ssl-reqd instead",
1862
a->lname);
1863
break;
1864
case C_FTP_SSL_CCC: /* --ftp-ssl-ccc */
1865
config->ftp_ssl_ccc = toggle;
1866
if(!config->ftp_ssl_ccc_mode)
1867
config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
1868
break;
1869
case C_TCP_NODELAY: /* --tcp-nodelay */
1870
config->tcp_nodelay = toggle;
1871
break;
1872
case C_PROXY_DIGEST: /* --proxy-digest */
1873
config->proxydigest = toggle;
1874
break;
1875
case C_PROXY_BASIC: /* --proxy-basic */
1876
config->proxybasic = toggle;
1877
break;
1878
case C_RETRY_CONNREFUSED: /* --retry-connrefused */
1879
config->retry_connrefused = toggle;
1880
break;
1881
case C_RETRY_ALL_ERRORS: /* --retry-all-errors */
1882
config->retry_all_errors = toggle;
1883
break;
1884
case C_PROXY_NEGOTIATE: /* --proxy-negotiate */
1885
if(!feature_spnego)
1886
return PARAM_LIBCURL_DOESNT_SUPPORT;
1887
else
1888
config->proxynegotiate = toggle;
1889
break;
1890
case C_FORM_ESCAPE: /* --form-escape */
1891
togglebit(toggle, &config->mime_options, CURLMIMEOPT_FORMESCAPE);
1892
break;
1893
case C_PROXY_ANYAUTH: /* --proxy-anyauth */
1894
config->proxyanyauth = toggle;
1895
break;
1896
case C_TRACE_TIME: /* --trace-time */
1897
global->tracetime = toggle;
1898
break;
1899
case C_IGNORE_CONTENT_LENGTH: /* --ignore-content-length */
1900
config->ignorecl = toggle;
1901
break;
1902
case C_FTP_SKIP_PASV_IP: /* --ftp-skip-pasv-ip */
1903
config->ftp_skip_ip = toggle;
1904
break;
1905
case C_FTP_SSL_REQD: /* --ftp-ssl-reqd */
1906
case C_SSL_REQD: /* --ssl-reqd */
1907
config->ftp_ssl_reqd = toggle;
1908
break;
1909
case C_SESSIONID: /* --sessionid */
1910
config->disable_sessionid = !toggle;
1911
break;
1912
case C_FTP_SSL_CONTROL: /* --ftp-ssl-control */
1913
config->ftp_ssl_control = toggle;
1914
break;
1915
case C_RAW: /* --raw */
1916
config->raw = toggle;
1917
break;
1918
case C_KEEPALIVE: /* --keepalive */
1919
config->nokeepalive = !toggle;
1920
break;
1921
case C_POST301: /* --post301 */
1922
config->post301 = toggle;
1923
break;
1924
case C_POST302: /* --post302 */
1925
config->post302 = toggle;
1926
break;
1927
case C_POST303: /* --post303 */
1928
config->post303 = toggle;
1929
break;
1930
case C_SOCKS5_GSSAPI_NEC: /* --socks5-gssapi-nec */
1931
config->socks5_gssapi_nec = toggle;
1932
break;
1933
case C_FTP_PRET: /* --ftp-pret */
1934
config->ftp_pret = toggle;
1935
break;
1936
case C_SASL_IR: /* --sasl-ir */
1937
config->sasl_ir = toggle;
1938
break;
1939
#ifdef DEBUGBUILD
1940
case C_TEST_DUPHANDLE: /* --test-duphandle */
1941
global->test_duphandle = toggle;
1942
break;
1943
case C_TEST_EVENT: /* --test-event */
1944
global->test_event_based = toggle;
1945
break;
1946
#endif
1947
case C_PATH_AS_IS: /* --path-as-is */
1948
config->path_as_is = toggle;
1949
break;
1950
case C_TFTP_NO_OPTIONS: /* --tftp-no-options */
1951
config->tftp_no_options = toggle;
1952
break;
1953
case C_TLS_EARLYDATA: /* --tls-earlydata */
1954
config->ssl_allow_earlydata = toggle;
1955
break;
1956
case C_SUPPRESS_CONNECT_HEADERS: /* --suppress-connect-headers */
1957
config->suppress_connect_headers = toggle;
1958
break;
1959
case C_COMPRESSED_SSH: /* --compressed-ssh */
1960
config->ssh_compression = toggle;
1961
break;
1962
case C_TRACE_IDS: /* --trace-ids */
1963
global->traceids = toggle;
1964
break;
1965
case C_PROGRESS_METER: /* --progress-meter */
1966
global->noprogress = !toggle;
1967
break;
1968
case C_PROGRESS_BAR: /* --progress-bar */
1969
global->progressmode = toggle ? CURL_PROGRESS_BAR : CURL_PROGRESS_STATS;
1970
break;
1971
case C_HTTP0_9: /* --http0.9 */
1972
config->http09_allowed = toggle;
1973
break;
1974
case C_PROXY_HTTP2: /* --proxy-http2 */
1975
if(!feature_httpsproxy || !feature_http2)
1976
return PARAM_LIBCURL_DOESNT_SUPPORT;
1977
1978
config->proxyver = toggle ? CURLPROXY_HTTPS2 : CURLPROXY_HTTPS;
1979
break;
1980
case C_APPEND: /* --append */
1981
config->ftp_append = toggle;
1982
break;
1983
case C_USE_ASCII: /* --use-ascii */
1984
config->use_ascii = toggle;
1985
break;
1986
case C_CA_NATIVE: /* --ca-native */
1987
config->native_ca_store = toggle;
1988
break;
1989
case C_PROXY_CA_NATIVE: /* --proxy-ca-native */
1990
config->proxy_native_ca_store = toggle;
1991
break;
1992
case C_SSL_ALLOW_BEAST: /* --ssl-allow-beast */
1993
config->ssl_allow_beast = toggle;
1994
break;
1995
case C_SSL_AUTO_CLIENT_CERT: /* --ssl-auto-client-cert */
1996
config->ssl_auto_client_cert = toggle;
1997
break;
1998
case C_PROXY_SSL_AUTO_CLIENT_CERT: /* --proxy-ssl-auto-client-cert */
1999
config->proxy_ssl_auto_client_cert = toggle;
2000
break;
2001
case C_CERT_STATUS: /* --cert-status */
2002
config->verifystatus = toggle;
2003
break;
2004
case C_DOH_CERT_STATUS: /* --doh-cert-status */
2005
config->doh_verifystatus = toggle;
2006
break;
2007
case C_FALSE_START: /* --false-start */
2008
opt_depr(a);
2009
break;
2010
case C_SSL_NO_REVOKE: /* --ssl-no-revoke */
2011
config->ssl_no_revoke = toggle;
2012
break;
2013
case C_SSL_REVOKE_BEST_EFFORT: /* --ssl-revoke-best-effort */
2014
config->ssl_revoke_best_effort = toggle;
2015
break;
2016
case C_TCP_FASTOPEN: /* --tcp-fastopen */
2017
config->tcp_fastopen = toggle;
2018
break;
2019
case C_PROXY_SSL_ALLOW_BEAST: /* --proxy-ssl-allow-beast */
2020
config->proxy_ssl_allow_beast = toggle;
2021
break;
2022
case C_PROXY_INSECURE: /* --proxy-insecure */
2023
config->proxy_insecure_ok = toggle;
2024
break;
2025
case C_SOCKS5_BASIC: /* --socks5-basic */
2026
togglebit(toggle, &config->socks5_auth, CURLAUTH_BASIC);
2027
break;
2028
case C_SOCKS5_GSSAPI: /* --socks5-gssapi */
2029
togglebit(toggle, &config->socks5_auth, CURLAUTH_GSSAPI);
2030
break;
2031
case C_FAIL_EARLY: /* --fail-early */
2032
global->fail_early = toggle;
2033
break;
2034
case C_STYLED_OUTPUT: /* --styled-output */
2035
global->styled_output = toggle;
2036
break;
2037
case C_MAIL_RCPT_ALLOWFAILS: /* --mail-rcpt-allowfails */
2038
config->mail_rcpt_allowfails = toggle;
2039
break;
2040
case C_REMOVE_ON_ERROR: /* --remove-on-error */
2041
if(config->use_resume && toggle) {
2042
errorf("--continue-at is mutually exclusive with --remove-on-error");
2043
return PARAM_BAD_USE;
2044
}
2045
config->rm_partial = toggle;
2046
break;
2047
case C_FAIL: /* --fail without body */
2048
if(toggle && (config->fail == FAIL_WITH_BODY))
2049
warnf("--fail deselects --fail-with-body here");
2050
config->fail = toggle ? FAIL_WO_BODY : FAIL_NONE;
2051
break;
2052
case C_FAIL_WITH_BODY: /* --fail-with-body */
2053
if(toggle && (config->fail == FAIL_WO_BODY))
2054
warnf("--fail-with-body deselects --fail here");
2055
config->fail = toggle ? FAIL_WITH_BODY : FAIL_NONE;
2056
break;
2057
case C_GLOBOFF: /* --globoff */
2058
config->globoff = toggle;
2059
break;
2060
case C_GET: /* --get */
2061
config->use_httpget = toggle;
2062
break;
2063
case C_INCLUDE: /* --include */
2064
case C_SHOW_HEADERS: /* --show-headers */
2065
config->show_headers = toggle;
2066
break;
2067
case C_JUNK_SESSION_COOKIES: /* --junk-session-cookies */
2068
config->cookiesession = toggle;
2069
break;
2070
case C_HEAD: /* --head */
2071
config->no_body = toggle;
2072
config->show_headers = toggle;
2073
if(SetHTTPrequest((config->no_body) ? TOOL_HTTPREQ_HEAD :
2074
TOOL_HTTPREQ_GET, &config->httpreq))
2075
return PARAM_BAD_USE;
2076
break;
2077
case C_REMOTE_HEADER_NAME: /* --remote-header-name */
2078
config->content_disposition = toggle;
2079
break;
2080
case C_INSECURE: /* --insecure */
2081
config->insecure_ok = toggle;
2082
break;
2083
case C_DOH_INSECURE: /* --doh-insecure */
2084
config->doh_insecure_ok = toggle;
2085
break;
2086
case C_LIST_ONLY: /* --list-only */
2087
config->dirlistonly = toggle; /* only list the names of the FTP dir */
2088
break;
2089
case C_MANUAL: /* --manual */
2090
if(toggle) /* --no-manual shows no manual... */
2091
return PARAM_MANUAL_REQUESTED;
2092
break;
2093
case C_NETRC_OPTIONAL: /* --netrc-optional */
2094
config->netrc_opt = toggle;
2095
break;
2096
case C_NETRC: /* --netrc */
2097
config->netrc = toggle;
2098
break;
2099
case C_BUFFER: /* --buffer */
2100
config->nobuffer = !toggle;
2101
break;
2102
case C_REMOTE_NAME_ALL: /* --remote-name-all */
2103
config->remote_name_all = toggle;
2104
break;
2105
case C_CLOBBER: /* --clobber */
2106
if(config->use_resume && !toggle) {
2107
errorf("--continue-at is mutually exclusive with --no-clobber");
2108
return PARAM_BAD_USE;
2109
}
2110
config->file_clobber_mode = toggle ? CLOBBER_ALWAYS : CLOBBER_NEVER;
2111
break;
2112
case C_REMOTE_NAME: /* --remote-name */
2113
return parse_remote_name(config, toggle);
2114
case C_PROXYTUNNEL: /* --proxytunnel */
2115
config->proxytunnel = toggle;
2116
break;
2117
case C_DISABLE: /* --disable */
2118
/* if used first, already taken care of, we do it like this so we do not
2119
cause an error! */
2120
break;
2121
case C_REMOTE_TIME: /* --remote-time */
2122
config->remote_time = toggle;
2123
break;
2124
case C_SILENT: /* --silent */
2125
global->silent = toggle;
2126
break;
2127
case C_SKIP_EXISTING: /* --skip-existing */
2128
config->skip_existing = toggle;
2129
break;
2130
case C_SHOW_ERROR: /* --show-error */
2131
global->showerror = toggle;
2132
break;
2133
case C_VERBOSE: /* --verbose */
2134
return parse_verbose(toggle);
2135
case C_VERSION: /* --version */
2136
if(toggle) /* --no-version yields no output! */
2137
return PARAM_VERSION_INFO_REQUESTED;
2138
break;
2139
case C_PARALLEL: /* --parallel */
2140
global->parallel = toggle;
2141
break;
2142
case C_PARALLEL_IMMEDIATE: /* --parallel-immediate */
2143
global->parallel_connect = toggle;
2144
break;
2145
case C_MPTCP: /* --mptcp */
2146
config->mptcp = toggle;
2147
break;
2148
case C_LOCATION_TRUSTED: /* --location-trusted */
2149
config->unrestricted_auth = toggle;
2150
FALLTHROUGH();
2151
case C_LOCATION: /* --location */
2152
if(config->followlocation == CURLFOLLOW_OBEYCODE)
2153
warnf("--location overrides --follow");
2154
config->followlocation = toggle ? CURLFOLLOW_ALL : 0;
2155
break;
2156
case C_FOLLOW: /* --follow */
2157
if(config->followlocation == CURLFOLLOW_ALL)
2158
warnf("--follow overrides --location");
2159
config->followlocation = toggle ? CURLFOLLOW_OBEYCODE : 0;
2160
break;
2161
default:
2162
return PARAM_OPTION_UNKNOWN;
2163
}
2164
return PARAM_OK;
2165
}
2166
2167
/* opt_file handles file options */
2168
static ParameterError opt_file(struct OperationConfig *config,
2169
const struct LongShort *a,
2170
const char *nextarg,
2171
int max_recursive)
2172
{
2173
ParameterError err = PARAM_OK;
2174
if((nextarg[0] == '-') && nextarg[1]) {
2175
/* if the filename looks like a command line option */
2176
warnf("The filename argument '%s' looks like a flag.", nextarg);
2177
}
2178
switch(a->cmd) {
2179
case C_ABSTRACT_UNIX_SOCKET: /* --abstract-unix-socket */
2180
config->abstract_unix_socket = TRUE;
2181
err = getstr(&config->unix_socket_path, nextarg, DENY_BLANK);
2182
break;
2183
case C_CACERT: /* --cacert */
2184
err = getstr(&config->cacert, nextarg, DENY_BLANK);
2185
break;
2186
case C_CAPATH: /* --capath */
2187
err = getstr(&config->capath, nextarg, DENY_BLANK);
2188
break;
2189
case C_CERT: /* --cert */
2190
GetFileAndPassword(nextarg, &config->cert, &config->key_passwd);
2191
break;
2192
case C_CONFIG: /* --config */
2193
if(--max_recursive < 0) {
2194
errorf("Max config file recursion level reached (%u)",
2195
CONFIG_MAX_LEVELS);
2196
err = PARAM_BAD_USE;
2197
}
2198
else {
2199
err = parseconfig(nextarg, max_recursive);
2200
}
2201
break;
2202
case C_CRLFILE: /* --crlfile */
2203
err = getstr(&config->crlfile, nextarg, DENY_BLANK);
2204
break;
2205
case C_DUMP_HEADER: /* --dump-header */
2206
err = getstr(&config->headerfile, nextarg, DENY_BLANK);
2207
break;
2208
case C_ETAG_SAVE: /* --etag-save */
2209
if(config->num_urls > 1) {
2210
errorf("The etag options only work on a single URL");
2211
err = PARAM_BAD_USE;
2212
}
2213
else
2214
err = getstr(&config->etag_save_file, nextarg, DENY_BLANK);
2215
break;
2216
case C_ETAG_COMPARE: /* --etag-compare */
2217
if(config->num_urls > 1) {
2218
errorf("The etag options only work on a single URL");
2219
err = PARAM_BAD_USE;
2220
}
2221
else
2222
err = getstr(&config->etag_compare_file, nextarg, DENY_BLANK);
2223
break;
2224
case C_KEY: /* --key */
2225
err = getstr(&config->key, nextarg, DENY_BLANK);
2226
break;
2227
case C_KNOWNHOSTS: /* --knownhosts */
2228
err = getstr(&config->knownhosts, nextarg, DENY_BLANK);
2229
break;
2230
case C_NETRC_FILE: /* --netrc-file */
2231
err = getstr(&config->netrc_file, nextarg, DENY_BLANK);
2232
break;
2233
case C_OUTPUT: /* --output */
2234
err = parse_output(config, nextarg);
2235
break;
2236
case C_PROXY_CACERT: /* --proxy-cacert */
2237
err = getstr(&config->proxy_cacert, nextarg, DENY_BLANK);
2238
break;
2239
case C_PROXY_CAPATH: /* --proxy-capath */
2240
err = getstr(&config->proxy_capath, nextarg, DENY_BLANK);
2241
break;
2242
case C_PROXY_CERT: /* --proxy-cert */
2243
GetFileAndPassword(nextarg, &config->proxy_cert,
2244
&config->proxy_key_passwd);
2245
break;
2246
case C_PROXY_CRLFILE: /* --proxy-crlfile */
2247
err = getstr(&config->proxy_crlfile, nextarg, DENY_BLANK);
2248
break;
2249
case C_PROXY_KEY: /* --proxy-key */
2250
err = getstr(&config->proxy_key, nextarg, ALLOW_BLANK);
2251
break;
2252
case C_SSL_SESSIONS: /* --ssl-sessions */
2253
if(feature_ssls_export)
2254
err = getstr(&global->ssl_sessions, nextarg, DENY_BLANK);
2255
else
2256
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2257
break;
2258
case C_STDERR: /* --stderr */
2259
tool_set_stderr_file(nextarg);
2260
break;
2261
case C_TRACE: /* --trace */
2262
err = getstr(&global->trace_dump, nextarg, DENY_BLANK);
2263
if(!err) {
2264
if(global->tracetype && (global->tracetype != TRACE_BIN))
2265
warnf("--trace overrides an earlier trace/verbose option");
2266
global->tracetype = TRACE_BIN;
2267
}
2268
break;
2269
case C_TRACE_ASCII: /* --trace-ascii */
2270
err = getstr(&global->trace_dump, nextarg, DENY_BLANK);
2271
if(!err) {
2272
if(global->tracetype && (global->tracetype != TRACE_ASCII))
2273
warnf("--trace-ascii overrides an earlier trace/verbose option");
2274
global->tracetype = TRACE_ASCII;
2275
}
2276
break;
2277
case C_UNIX_SOCKET: /* --unix-socket */
2278
config->abstract_unix_socket = FALSE;
2279
err = getstr(&config->unix_socket_path, nextarg, DENY_BLANK);
2280
break;
2281
case C_UPLOAD_FILE: /* --upload-file */
2282
err = parse_upload_file(config, nextarg);
2283
break;
2284
}
2285
return err;
2286
}
2287
2288
/* opt_string handles string options */
2289
static ParameterError opt_string(struct OperationConfig *config,
2290
const struct LongShort *a,
2291
const char *nextarg)
2292
{
2293
ParameterError err = PARAM_OK;
2294
curl_off_t value;
2295
long val;
2296
static const char *redir_protos[] = {
2297
"http",
2298
"https",
2299
"ftp",
2300
"ftps",
2301
NULL
2302
};
2303
if(!nextarg)
2304
nextarg = "";
2305
2306
switch(a->cmd) {
2307
case C_DNS_IPV4_ADDR: /* --dns-ipv4-addr */
2308
if(!curlinfo->ares_num) /* c-ares is needed for this */
2309
return PARAM_LIBCURL_DOESNT_SUPPORT;
2310
/* addr in dot notation */
2311
return getstr(&config->dns_ipv4_addr, nextarg, DENY_BLANK);
2312
2313
case C_DNS_IPV6_ADDR: /* --dns-ipv6-addr */
2314
if(!curlinfo->ares_num) /* c-ares is needed for this */
2315
return PARAM_LIBCURL_DOESNT_SUPPORT;
2316
/* addr in dot notation */
2317
return getstr(&config->dns_ipv6_addr, nextarg, DENY_BLANK);
2318
2319
case C_OAUTH2_BEARER: /* --oauth2-bearer */
2320
config->authtype |= CURLAUTH_BEARER;
2321
return getstr(&config->oauth_bearer, nextarg, DENY_BLANK);
2322
2323
case C_CONNECT_TIMEOUT: /* --connect-timeout */
2324
return secs2ms(&config->connecttimeout_ms, nextarg);
2325
2326
case C_DOH_URL: /* --doh-url */
2327
err = getstr(&config->doh_url, nextarg, ALLOW_BLANK);
2328
if(!err && config->doh_url && !config->doh_url[0])
2329
/* if given a blank string, make it NULL again */
2330
tool_safefree(config->doh_url);
2331
break;
2332
2333
case C_CIPHERS: /* -- ciphers */
2334
err = getstr(&config->cipher_list, nextarg, DENY_BLANK);
2335
break;
2336
2337
case C_DNS_INTERFACE: /* --dns-interface */
2338
if(!curlinfo->ares_num) /* c-ares is needed for this */
2339
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2340
else
2341
/* interface name */
2342
err = getstr(&config->dns_interface, nextarg, DENY_BLANK);
2343
break;
2344
case C_DNS_SERVERS: /* --dns-servers */
2345
if(!curlinfo->ares_num) /* c-ares is needed for this */
2346
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2347
else
2348
/* IP addrs of DNS servers */
2349
err = getstr(&config->dns_servers, nextarg, DENY_BLANK);
2350
break;
2351
case C_LIMIT_RATE: /* --limit-rate */
2352
err = GetSizeParameter(nextarg, "rate", &value);
2353
if(!err) {
2354
config->recvpersecond = value;
2355
config->sendpersecond = value;
2356
}
2357
break;
2358
case C_RATE:
2359
err = set_rate(nextarg);
2360
break;
2361
case C_CREATE_FILE_MODE: /* --create-file-mode */
2362
err = oct2nummax(&config->create_file_mode, nextarg, 0777);
2363
break;
2364
case C_MAX_REDIRS: /* --max-redirs */
2365
/* specified max no of redirects (http(s)), this accepts -1 as a
2366
special condition */
2367
err = str2num(&config->maxredirs, nextarg);
2368
if(!err && (config->maxredirs < -1))
2369
err = PARAM_BAD_NUMERIC;
2370
break;
2371
#ifndef CURL_DISABLE_IPFS
2372
case C_IPFS_GATEWAY: /* --ipfs-gateway */
2373
err = getstr(&config->ipfs_gateway, nextarg, DENY_BLANK);
2374
break;
2375
#endif /* !CURL_DISABLE_IPFS */
2376
case C_AWS_SIGV4: /* --aws-sigv4 */
2377
config->authtype |= CURLAUTH_AWS_SIGV4;
2378
err = getstr(&config->aws_sigv4, nextarg, ALLOW_BLANK);
2379
break;
2380
case C_INTERFACE: /* --interface */
2381
/* interface */
2382
err = getstr(&config->iface, nextarg, DENY_BLANK);
2383
break;
2384
case C_HAPROXY_CLIENTIP: /* --haproxy-clientip */
2385
err = getstr(&config->haproxy_clientip, nextarg, DENY_BLANK);
2386
break;
2387
case C_MAX_FILESIZE: /* --max-filesize */
2388
err = GetSizeParameter(nextarg, "max-filesize", &value);
2389
if(!err)
2390
config->max_filesize = value;
2391
break;
2392
case C_URL: /* --url */
2393
err = parse_url(config, nextarg);
2394
break;
2395
case C_SOCKS5: /* --socks5 */
2396
/* socks5 proxy to use, and resolves the name locally and passes on the
2397
resolved address */
2398
err = getstr(&config->proxy, nextarg, DENY_BLANK);
2399
config->proxyver = CURLPROXY_SOCKS5;
2400
break;
2401
case C_SOCKS4: /* --socks4 */
2402
err = getstr(&config->proxy, nextarg, DENY_BLANK);
2403
config->proxyver = CURLPROXY_SOCKS4;
2404
break;
2405
case C_SOCKS4A: /* --socks4a */
2406
err = getstr(&config->proxy, nextarg, DENY_BLANK);
2407
config->proxyver = CURLPROXY_SOCKS4A;
2408
break;
2409
case C_SOCKS5_HOSTNAME: /* --socks5-hostname */
2410
err = getstr(&config->proxy, nextarg, DENY_BLANK);
2411
config->proxyver = CURLPROXY_SOCKS5_HOSTNAME;
2412
break;
2413
case C_IP_TOS: { /* --ip-tos */
2414
struct TOSEntry find;
2415
const struct TOSEntry *entry;
2416
find.name = nextarg;
2417
entry = bsearch(&find, tos_entries,
2418
CURL_ARRAYSIZE(tos_entries),
2419
sizeof(*tos_entries), find_tos);
2420
if(entry)
2421
config->ip_tos = entry->value;
2422
else /* numeric tos value */
2423
err = str2unummax(&config->ip_tos, nextarg, 0xFF);
2424
break;
2425
}
2426
case C_VLAN_PRIORITY: /* --vlan-priority */
2427
err = str2unummax(&config->vlan_priority, nextarg, 7);
2428
break;
2429
case C_RETRY: /* --retry */
2430
err = str2unum(&config->req_retry, nextarg);
2431
break;
2432
case C_RETRY_DELAY: /* --retry-delay */
2433
err = secs2ms(&config->retry_delay_ms, nextarg);
2434
break;
2435
case C_RETRY_MAX_TIME: /* --retry-max-time */
2436
err = secs2ms(&config->retry_maxtime_ms, nextarg);
2437
break;
2438
case C_FTP_ACCOUNT: /* --ftp-account */
2439
err = getstr(&config->ftp_account, nextarg, DENY_BLANK);
2440
break;
2441
case C_FTP_METHOD: /* --ftp-method */
2442
config->ftp_filemethod = ftpfilemethod(nextarg);
2443
break;
2444
case C_LOCAL_PORT: /* --local-port */
2445
err = parse_localport(config, nextarg);
2446
break;
2447
case C_FTP_ALTERNATIVE_TO_USER: /* --ftp-alternative-to-user */
2448
err = getstr(&config->ftp_alternative_to_user, nextarg, DENY_BLANK);
2449
break;
2450
case C_LIBCURL: /* --libcurl */
2451
#ifdef CURL_DISABLE_LIBCURL_OPTION
2452
warnf("--libcurl option was disabled at build-time");
2453
err = PARAM_OPTION_UNKNOWN;
2454
#else
2455
err = getstr(&global->libcurl, nextarg, DENY_BLANK);
2456
#endif
2457
break;
2458
case C_KEEPALIVE_TIME: /* --keepalive-time */
2459
err = str2unum(&config->alivetime, nextarg);
2460
break;
2461
case C_KEEPALIVE_CNT: /* --keepalive-cnt */
2462
err = str2unum(&config->alivecnt, nextarg);
2463
break;
2464
case C_NOPROXY: /* --noproxy */
2465
/* This specifies the noproxy list */
2466
err = getstr(&config->noproxy, nextarg, ALLOW_BLANK);
2467
break;
2468
case C_PROXY1_0: /* --proxy1.0 */
2469
/* http 1.0 proxy */
2470
err = getstr(&config->proxy, nextarg, DENY_BLANK);
2471
config->proxyver = CURLPROXY_HTTP_1_0;
2472
break;
2473
case C_TFTP_BLKSIZE: /* --tftp-blksize */
2474
err = str2unum(&config->tftp_blksize, nextarg);
2475
break;
2476
case C_MAIL_FROM: /* --mail-from */
2477
err = getstr(&config->mail_from, nextarg, DENY_BLANK);
2478
break;
2479
case C_MAIL_RCPT: /* --mail-rcpt */
2480
/* append receiver to a list */
2481
err = add2list(&config->mail_rcpt, nextarg);
2482
break;
2483
case C_PROTO: /* --proto */
2484
config->proto_present = TRUE;
2485
err = proto2num(built_in_protos, &config->proto_str, nextarg);
2486
break;
2487
case C_PROTO_REDIR: /* --proto-redir */
2488
config->proto_redir_present = TRUE;
2489
if(proto2num(redir_protos, &config->proto_redir_str, nextarg))
2490
err = PARAM_BAD_USE;
2491
break;
2492
case C_RESOLVE: /* --resolve */
2493
err = add2list(&config->resolve, nextarg);
2494
break;
2495
case C_DELEGATION: /* --delegation */
2496
config->gssapi_delegation = delegation(nextarg);
2497
break;
2498
case C_MAIL_AUTH: /* --mail-auth */
2499
err = getstr(&config->mail_auth, nextarg, DENY_BLANK);
2500
break;
2501
case C_SASL_AUTHZID: /* --sasl-authzid */
2502
err = getstr(&config->sasl_authzid, nextarg, DENY_BLANK);
2503
break;
2504
case C_PROXY_SERVICE_NAME: /* --proxy-service-name */
2505
err = getstr(&config->proxy_service_name, nextarg, DENY_BLANK);
2506
break;
2507
case C_SERVICE_NAME: /* --service-name */
2508
err = getstr(&config->service_name, nextarg, DENY_BLANK);
2509
break;
2510
case C_PROTO_DEFAULT: /* --proto-default */
2511
err = getstr(&config->proto_default, nextarg, DENY_BLANK);
2512
if(!err)
2513
err = check_protocol(config->proto_default);
2514
break;
2515
case C_EXPECT100_TIMEOUT: /* --expect100-timeout */
2516
err = secs2ms(&config->expect100timeout_ms, nextarg);
2517
break;
2518
case C_CONNECT_TO: /* --connect-to */
2519
err = add2list(&config->connect_to, nextarg);
2520
break;
2521
case C_TLS_MAX: /* --tls-max */
2522
err = str2tls_max(&config->ssl_version_max, nextarg);
2523
if(!err && (config->ssl_version_max < config->ssl_version)) {
2524
errorf("--tls-max set lower than minimum accepted version");
2525
err = PARAM_BAD_USE;
2526
}
2527
break;
2528
case C_HAPPY_EYEBALLS_TIMEOUT_MS: /* --happy-eyeballs-timeout-ms */
2529
err = str2unum(&config->happy_eyeballs_timeout_ms, nextarg);
2530
/* 0 is a valid value for this timeout */
2531
break;
2532
case C_TRACE_CONFIG: /* --trace-config */
2533
global->trace_set = TRUE;
2534
if(set_trace_config(nextarg))
2535
err = PARAM_NO_MEM;
2536
break;
2537
case C_VARIABLE: /* --variable */
2538
err = setvariable(nextarg);
2539
break;
2540
case C_TLS13_CIPHERS: /* --tls13-ciphers */
2541
err = getstr(&config->cipher13_list, nextarg, DENY_BLANK);
2542
break;
2543
case C_PROXY_TLS13_CIPHERS: /* --proxy-tls13-ciphers */
2544
err = getstr(&config->proxy_cipher13_list, nextarg, DENY_BLANK);
2545
break;
2546
case C_USER_AGENT: /* --user-agent */
2547
err = getstr(&config->useragent, nextarg, ALLOW_BLANK);
2548
break;
2549
case C_ALT_SVC: /* --alt-svc */
2550
if(!feature_altsvc)
2551
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2552
else
2553
err = getstr(&config->altsvc, nextarg, ALLOW_BLANK);
2554
break;
2555
case C_HSTS: /* --hsts */
2556
if(!feature_hsts)
2557
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2558
else
2559
err = getstr(&config->hsts, nextarg, ALLOW_BLANK);
2560
break;
2561
case C_COOKIE: /* --cookie */
2562
if(strchr(nextarg, '=')) {
2563
/* A cookie string must have a =-letter */
2564
err = add2list(&config->cookies, nextarg);
2565
break;
2566
}
2567
else {
2568
/* We have a cookie file to read from! */
2569
err = add2list(&config->cookiefiles, nextarg);
2570
}
2571
break;
2572
case C_COOKIE_JAR: /* --cookie-jar */
2573
err = getstr(&config->cookiejar, nextarg, DENY_BLANK);
2574
break;
2575
case C_CONTINUE_AT: /* --continue-at */
2576
err = parse_continue_at(config, nextarg);
2577
break;
2578
case C_DATA: /* --data */
2579
case C_DATA_ASCII: /* --data-ascii */
2580
case C_DATA_BINARY: /* --data-binary */
2581
case C_DATA_URLENCODE: /* --data-urlencode */
2582
case C_JSON: /* --json */
2583
case C_DATA_RAW: /* --data-raw */
2584
err = set_data((cmdline_t)a->cmd, nextarg, config);
2585
break;
2586
case C_URL_QUERY: /* --url-query */
2587
err = url_query(nextarg, config);
2588
break;
2589
case C_REFERER: { /* --referer */
2590
size_t len = strlen(nextarg);
2591
/* does it end with ;auto ? */
2592
if(len >= 5 && !strcmp(";auto", &nextarg[len - 5])) {
2593
/* Automatic referer requested, this may be combined with a set initial
2594
one */
2595
config->autoreferer = TRUE;
2596
len -= 5;
2597
}
2598
else
2599
config->autoreferer = FALSE;
2600
2601
if(len)
2602
err = getstrn(&config->referer, nextarg, len, ALLOW_BLANK);
2603
else
2604
tool_safefree(config->referer);
2605
}
2606
break;
2607
case C_CERT_TYPE: /* --cert-type */
2608
err = getstr(&config->cert_type, nextarg, DENY_BLANK);
2609
break;
2610
case C_KEY_TYPE: /* --key-type */
2611
err = getstr(&config->key_type, nextarg, DENY_BLANK);
2612
break;
2613
case C_PASS: /* --pass */
2614
err = getstr(&config->key_passwd, nextarg, DENY_BLANK);
2615
break;
2616
case C_ENGINE: /* --engine */
2617
err = getstr(&config->engine, nextarg, DENY_BLANK);
2618
if(!err &&
2619
config->engine && !strcmp(config->engine, "list")) {
2620
err = PARAM_ENGINES_REQUESTED;
2621
}
2622
break;
2623
case C_ECH: /* --ech */
2624
err = parse_ech(config, nextarg);
2625
break;
2626
case C_PUBKEY: /* --pubkey */
2627
err = getstr(&config->pubkey, nextarg, DENY_BLANK);
2628
break;
2629
case C_HOSTPUBMD5: /* --hostpubmd5 */
2630
err = getstr(&config->hostpubmd5, nextarg, DENY_BLANK);
2631
if(!err) {
2632
if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
2633
err = PARAM_BAD_USE;
2634
}
2635
break;
2636
case C_HOSTPUBSHA256: /* --hostpubsha256 */
2637
if(!feature_libssh2)
2638
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2639
else
2640
err = getstr(&config->hostpubsha256, nextarg, DENY_BLANK);
2641
break;
2642
case C_TLSUSER: /* --tlsuser */
2643
if(!feature_tls_srp)
2644
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2645
else
2646
err = getstr(&config->tls_username, nextarg, DENY_BLANK);
2647
break;
2648
case C_TLSPASSWORD: /* --tlspassword */
2649
if(!feature_tls_srp)
2650
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2651
else
2652
err = getstr(&config->tls_password, nextarg, ALLOW_BLANK);
2653
break;
2654
case C_TLSAUTHTYPE: /* --tlsauthtype */
2655
if(!feature_tls_srp)
2656
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2657
else {
2658
err = getstr(&config->tls_authtype, nextarg, DENY_BLANK);
2659
if(!err && config->tls_authtype && strcmp(config->tls_authtype, "SRP"))
2660
err = PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
2661
}
2662
break;
2663
case C_PINNEDPUBKEY: /* --pinnedpubkey */
2664
err = getstr(&config->pinnedpubkey, nextarg, DENY_BLANK);
2665
break;
2666
case C_PROXY_PINNEDPUBKEY: /* --proxy-pinnedpubkey */
2667
err = getstr(&config->proxy_pinnedpubkey, nextarg, DENY_BLANK);
2668
break;
2669
case C_PROXY_TLSUSER: /* --proxy-tlsuser */
2670
if(!feature_tls_srp)
2671
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2672
else
2673
err = getstr(&config->proxy_tls_username, nextarg, ALLOW_BLANK);
2674
break;
2675
case C_PROXY_TLSPASSWORD: /* --proxy-tlspassword */
2676
if(!feature_tls_srp)
2677
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2678
else
2679
err = getstr(&config->proxy_tls_password, nextarg, DENY_BLANK);
2680
break;
2681
case C_PROXY_TLSAUTHTYPE: /* --proxy-tlsauthtype */
2682
if(!feature_tls_srp)
2683
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2684
else {
2685
err = getstr(&config->proxy_tls_authtype, nextarg, DENY_BLANK);
2686
if(!err && config->proxy_tls_authtype &&
2687
strcmp(config->proxy_tls_authtype, "SRP"))
2688
err = PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
2689
}
2690
break;
2691
case C_PROXY_CERT_TYPE: /* --proxy-cert-type */
2692
err = getstr(&config->proxy_cert_type, nextarg, DENY_BLANK);
2693
break;
2694
case C_PROXY_KEY_TYPE: /* --proxy-key-type */
2695
err = getstr(&config->proxy_key_type, nextarg, DENY_BLANK);
2696
break;
2697
case C_PROXY_PASS: /* --proxy-pass */
2698
err = getstr(&config->proxy_key_passwd, nextarg, ALLOW_BLANK);
2699
break;
2700
case C_PROXY_CIPHERS: /* --proxy-ciphers */
2701
err = getstr(&config->proxy_cipher_list, nextarg, DENY_BLANK);
2702
break;
2703
case C_LOGIN_OPTIONS: /* --login-options */
2704
err = getstr(&config->login_options, nextarg, ALLOW_BLANK);
2705
break;
2706
case C_CURVES: /* --curves */
2707
err = getstr(&config->ssl_ec_curves, nextarg, DENY_BLANK);
2708
break;
2709
case C_SIGNATURE_ALGORITHMS: /* --sigalgs */
2710
err = getstr(&config->ssl_signature_algorithms, nextarg, DENY_BLANK);
2711
break;
2712
case C_FORM: /* --form */
2713
case C_FORM_STRING: /* --form-string */
2714
/* "form data" simulation, this is a little advanced so lets do our best
2715
to sort this out slowly and carefully */
2716
if(formparse(nextarg, &config->mimeroot, &config->mimecurrent,
2717
(a->cmd == C_FORM_STRING))) /* literal string */
2718
err = PARAM_BAD_USE;
2719
else if(SetHTTPrequest(TOOL_HTTPREQ_MIMEPOST, &config->httpreq))
2720
err = PARAM_BAD_USE;
2721
break;
2722
case C_REQUEST_TARGET: /* --request-target */
2723
err = getstr(&config->request_target, nextarg, DENY_BLANK);
2724
break;
2725
case C_HEADER: /* --header */
2726
case C_PROXY_HEADER: /* --proxy-header */
2727
err = parse_header(config, (cmdline_t)a->cmd, nextarg);
2728
break;
2729
case C_MAX_TIME: /* --max-time */
2730
/* specified max time */
2731
err = secs2ms(&config->timeout_ms, nextarg);
2732
break;
2733
case C_OUTPUT_DIR: /* --output-dir */
2734
err = getstr(&config->output_dir, nextarg, DENY_BLANK);
2735
break;
2736
case C_FTP_PORT: /* --ftp-port */
2737
/* This makes the FTP sessions use PORT instead of PASV */
2738
/* use <eth0> or <192.168.10.10> style addresses. Anything except
2739
this will make us try to get the "default" address.
2740
NOTE: this is a changed behavior since the released 4.1!
2741
*/
2742
err = getstr(&config->ftpport, nextarg, DENY_BLANK);
2743
break;
2744
case C_FTP_SSL_CCC_MODE: /* --ftp-ssl-ccc-mode */
2745
config->ftp_ssl_ccc = TRUE;
2746
config->ftp_ssl_ccc_mode = ftpcccmethod(nextarg);
2747
break;
2748
case C_QUOTE: /* --quote */
2749
err = parse_quote(config, nextarg);
2750
break;
2751
case C_RANGE: /* --range */
2752
err = parse_range(config, nextarg);
2753
break;
2754
case C_TELNET_OPTION: /* --telnet-option */
2755
/* Telnet options */
2756
err = add2list(&config->telnet_options, nextarg);
2757
break;
2758
case C_USER: /* --user */
2759
/* user:password */
2760
err = getstr(&config->userpwd, nextarg, ALLOW_BLANK);
2761
break;
2762
case C_PROXY_USER: /* --proxy-user */
2763
/* Proxy user:password */
2764
err = getstr(&config->proxyuserpwd, nextarg, ALLOW_BLANK);
2765
break;
2766
case C_WRITE_OUT: /* --write-out */
2767
err = parse_writeout(config, nextarg);
2768
break;
2769
case C_PREPROXY: /* --preproxy */
2770
err = getstr(&config->preproxy, nextarg, DENY_BLANK);
2771
break;
2772
case C_PROXY: /* --proxy */
2773
/* --proxy */
2774
err = getstr(&config->proxy, nextarg, ALLOW_BLANK);
2775
if(config->proxyver != CURLPROXY_HTTPS2)
2776
config->proxyver = CURLPROXY_HTTP;
2777
break;
2778
case C_REQUEST: /* --request */
2779
/* set custom request */
2780
err = getstr(&config->customrequest, nextarg, DENY_BLANK);
2781
break;
2782
case C_SPEED_TIME: /* --speed-time */
2783
/* low speed time */
2784
err = str2unum(&config->low_speed_time, nextarg);
2785
if(!err && !config->low_speed_limit)
2786
config->low_speed_limit = 1;
2787
break;
2788
case C_SPEED_LIMIT: /* --speed-limit */
2789
/* low speed limit */
2790
err = str2unum(&config->low_speed_limit, nextarg);
2791
if(!err && !config->low_speed_time)
2792
config->low_speed_time = 30;
2793
break;
2794
case C_PARALLEL_HOST: /* --parallel-max-host */
2795
err = str2unum(&val, nextarg);
2796
if(err)
2797
break;
2798
if(val > MAX_PARALLEL_HOST)
2799
global->parallel_host = MAX_PARALLEL_HOST;
2800
else if(val < 1)
2801
global->parallel_host = PARALLEL_HOST_DEFAULT;
2802
else
2803
global->parallel_host = (unsigned short)val;
2804
break;
2805
case C_PARALLEL_MAX: /* --parallel-max */
2806
err = str2unum(&val, nextarg);
2807
if(err)
2808
break;
2809
if(val > MAX_PARALLEL)
2810
global->parallel_max = MAX_PARALLEL;
2811
else if(val < 1)
2812
global->parallel_max = PARALLEL_DEFAULT;
2813
else
2814
global->parallel_max = (unsigned short)val;
2815
break;
2816
case C_TIME_COND: /* --time-cond */
2817
err = parse_time_cond(config, nextarg);
2818
break;
2819
case C_UPLOAD_FLAGS: /* --upload-flags */
2820
err = parse_upload_flags(config, nextarg);
2821
break;
2822
}
2823
return err;
2824
}
2825
2826
/* detect e2 80 80 - e2 80 ff */
2827
static bool has_leading_unicode(const unsigned char *arg)
2828
{
2829
return ((arg[0] == 0xe2) && (arg[1] == 0x80) && (arg[2] & 0x80));
2830
}
2831
2832
/* the longest command line option, excluding the leading -- */
2833
#define MAX_OPTION_LEN 26
2834
2835
ParameterError getparameter(const char *flag, /* f or -long-flag */
2836
const char *nextarg, /* NULL if unset */
2837
bool *usedarg, /* set to TRUE if the arg
2838
has been used */
2839
struct OperationConfig *config,
2840
int max_recursive)
2841
{
2842
const char *parse = NULL;
2843
bool longopt = FALSE;
2844
bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
2845
ParameterError err = PARAM_OK;
2846
bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
2847
by using --OPTION or --no-OPTION */
2848
bool nextalloc = FALSE; /* if nextarg is allocated */
2849
bool consumearg = TRUE; /* the argument comes separate */
2850
const struct LongShort *a = NULL;
2851
verbose_nopts = 0; /* options processed in `flag`*/
2852
2853
*usedarg = FALSE; /* default is that we do not use the arg */
2854
2855
if(('-' != flag[0]) || ('-' == flag[1])) {
2856
/* this should be a long name */
2857
const char *word = ('-' == flag[0]) ? flag + 2 : flag;
2858
bool noflagged = FALSE;
2859
bool expand = FALSE;
2860
const char *p;
2861
struct Curl_str out;
2862
2863
if(!strncmp(word, "no-", 3)) {
2864
/* disable this option but ignore the "no-" part when looking for it */
2865
word += 3;
2866
toggle = FALSE;
2867
noflagged = TRUE;
2868
}
2869
else if(!strncmp(word, "expand-", 7)) {
2870
/* variable expansions is to be done on the argument */
2871
word += 7;
2872
expand = TRUE;
2873
}
2874
2875
p = word;
2876
/* is there an '=' ? */
2877
if(!curlx_str_until(&p, &out, MAX_OPTION_LEN, '=') &&
2878
!curlx_str_single(&p, '=') ) {
2879
/* there's an equal sign */
2880
char tempword[MAX_OPTION_LEN + 1];
2881
memcpy(tempword, curlx_str(&out), curlx_strlen(&out));
2882
tempword[curlx_strlen(&out)] = 0;
2883
a = findlongopt(tempword);
2884
nextarg = p;
2885
consumearg = FALSE; /* it is not separate */
2886
}
2887
else
2888
a = findlongopt(word);
2889
2890
if(a) {
2891
longopt = TRUE;
2892
}
2893
else {
2894
err = PARAM_OPTION_UNKNOWN;
2895
goto error;
2896
}
2897
if(noflagged && (ARGTYPE(a->desc) != ARG_BOOL)) {
2898
/* --no- prefixed an option that is not boolean! */
2899
err = PARAM_NO_PREFIX;
2900
goto error;
2901
}
2902
else if(expand && nextarg) {
2903
struct dynbuf nbuf;
2904
bool replaced;
2905
2906
if((ARGTYPE(a->desc) != ARG_STRG) &&
2907
(ARGTYPE(a->desc) != ARG_FILE)) {
2908
/* --expand on an option that is not a string or a filename */
2909
err = PARAM_EXPAND_ERROR;
2910
goto error;
2911
}
2912
err = varexpand(nextarg, &nbuf, &replaced);
2913
if(err) {
2914
curlx_dyn_free(&nbuf);
2915
goto error;
2916
}
2917
if(replaced) {
2918
nextarg = curlx_dyn_ptr(&nbuf);
2919
nextalloc = TRUE;
2920
}
2921
}
2922
}
2923
else {
2924
flag++; /* prefixed with one dash, pass it */
2925
parse = flag;
2926
}
2927
2928
do {
2929
/* we can loop here if we have multiple single-letters */
2930
if(!longopt) {
2931
a = findshortopt(*parse);
2932
if(!a) {
2933
err = PARAM_OPTION_UNKNOWN;
2934
break;
2935
}
2936
toggle = !(a->desc & ARG_NO);
2937
}
2938
if((a->desc & ARG_TLS) && !feature_ssl) {
2939
err = PARAM_LIBCURL_DOESNT_SUPPORT;
2940
break;
2941
}
2942
else if(ARGTYPE(a->desc) >= ARG_STRG) {
2943
/* this option requires an extra parameter */
2944
if(!longopt && parse[1]) {
2945
nextarg = &parse[1]; /* this is the actual extra parameter */
2946
singleopt = TRUE; /* do not loop anymore after this */
2947
}
2948
else if(a->cmd == C_HELP) {
2949
/* --help is special */
2950
tool_help((nextarg && *nextarg) ? nextarg : NULL);
2951
err = PARAM_HELP_REQUESTED;
2952
break;
2953
}
2954
else if(!nextarg) {
2955
err = PARAM_REQUIRES_PARAMETER;
2956
break;
2957
}
2958
else {
2959
*usedarg = consumearg; /* mark it as used */
2960
}
2961
if(a->desc & ARG_DEPR) {
2962
opt_depr(a);
2963
break;
2964
}
2965
2966
if(has_leading_unicode((const unsigned char *)nextarg)) {
2967
warnf("The argument '%s' starts with a Unicode character. "
2968
"Maybe ASCII was intended?", nextarg);
2969
}
2970
if(ARGTYPE(a->desc) == ARG_FILE)
2971
err = opt_file(config, a, nextarg, max_recursive);
2972
else /* if(ARGTYPE(a->desc) == ARG_STRG) */
2973
err = opt_string(config, a, nextarg);
2974
if(a->desc & ARG_CLEAR)
2975
cleanarg(CURL_UNCONST(nextarg));
2976
}
2977
else {
2978
if(a->desc & ARG_DEPR) {
2979
opt_depr(a);
2980
break;
2981
}
2982
/* ARG_NONE | ARG_BOOL */
2983
if(ARGTYPE(a->desc) == ARG_BOOL)
2984
err = opt_bool(config, a, toggle);
2985
else
2986
err = opt_none(config, a);
2987
}
2988
2989
++verbose_nopts; /* processed one option from `flag` input, loop for
2990
more */
2991
} while(!longopt && !singleopt && *++parse && !*usedarg && !err);
2992
2993
error:
2994
if(nextalloc)
2995
free(CURL_UNCONST(nextarg));
2996
return err;
2997
}
2998
2999
ParameterError parse_args(int argc, argv_item_t argv[])
3000
{
3001
int i;
3002
bool stillflags;
3003
const char *orig_opt = NULL;
3004
ParameterError result = PARAM_OK;
3005
struct OperationConfig *config = global->first;
3006
3007
for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
3008
orig_opt = convert_tchar_to_UTF8(argv[i]);
3009
if(!orig_opt)
3010
return PARAM_NO_MEM;
3011
3012
if(stillflags && ('-' == orig_opt[0])) {
3013
bool passarg;
3014
3015
if(!strcmp("--", orig_opt))
3016
/* This indicates the end of the flags and thus enables the
3017
following (URL) argument to start with -. */
3018
stillflags = FALSE;
3019
else {
3020
const char *nextarg = NULL;
3021
if(i < (argc - 1)) {
3022
nextarg = convert_tchar_to_UTF8(argv[i + 1]);
3023
if(!nextarg) {
3024
unicodefree(orig_opt);
3025
return PARAM_NO_MEM;
3026
}
3027
}
3028
3029
result = getparameter(orig_opt, nextarg, &passarg, config,
3030
CONFIG_MAX_LEVELS);
3031
3032
unicodefree(nextarg);
3033
config = global->last;
3034
if(result == PARAM_NEXT_OPERATION) {
3035
/* Reset result as PARAM_NEXT_OPERATION is only used here and not
3036
returned from this function */
3037
result = PARAM_OK;
3038
3039
if(config->url_list && config->url_list->url) {
3040
/* Allocate the next config */
3041
config->next = config_alloc();
3042
if(config->next) {
3043
/* Update the last config pointer */
3044
global->last = config->next;
3045
3046
/* Move onto the new config */
3047
config->next->prev = config;
3048
config = config->next;
3049
}
3050
else
3051
result = PARAM_NO_MEM;
3052
}
3053
else {
3054
errorf("missing URL before --next");
3055
result = PARAM_BAD_USE;
3056
}
3057
}
3058
else if(!result && passarg)
3059
i++; /* we are supposed to skip this */
3060
}
3061
}
3062
else {
3063
bool used;
3064
3065
/* Just add the URL please */
3066
result = getparameter("--url", orig_opt, &used, config, 0);
3067
}
3068
3069
if(!result) {
3070
unicodefree(orig_opt);
3071
orig_opt = NULL;
3072
}
3073
}
3074
3075
if(!result && config->content_disposition) {
3076
if(config->resume_from_current)
3077
result = PARAM_CONTDISP_RESUME_FROM;
3078
}
3079
3080
if(result && result != PARAM_HELP_REQUESTED &&
3081
result != PARAM_MANUAL_REQUESTED &&
3082
result != PARAM_VERSION_INFO_REQUESTED &&
3083
result != PARAM_ENGINES_REQUESTED &&
3084
result != PARAM_CA_EMBED_REQUESTED) {
3085
const char *reason = param2text(result);
3086
3087
if(orig_opt && strcmp(":", orig_opt))
3088
helpf("option %s: %s", orig_opt, reason);
3089
else
3090
helpf("%s", reason);
3091
}
3092
3093
unicodefree(orig_opt);
3094
return result;
3095
}
3096
3097