/src/PROJ/curl/lib/setopt.c
Line | Count | Source (jump to first uncovered line) |
1 | | /*************************************************************************** |
2 | | * _ _ ____ _ |
3 | | * Project ___| | | | _ \| | |
4 | | * / __| | | | |_) | | |
5 | | * | (__| |_| | _ <| |___ |
6 | | * \___|\___/|_| \_\_____| |
7 | | * |
8 | | * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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 | | |
25 | | #include "curl_setup.h" |
26 | | |
27 | | #include <limits.h> |
28 | | |
29 | | #ifdef HAVE_NETINET_IN_H |
30 | | #include <netinet/in.h> |
31 | | #endif |
32 | | |
33 | | #ifdef HAVE_LINUX_TCP_H |
34 | | #include <linux/tcp.h> |
35 | | #elif defined(HAVE_NETINET_TCP_H) |
36 | | #include <netinet/tcp.h> |
37 | | #endif |
38 | | |
39 | | #include "urldata.h" |
40 | | #include "url.h" |
41 | | #include "progress.h" |
42 | | #include "content_encoding.h" |
43 | | #include "strcase.h" |
44 | | #include "share.h" |
45 | | #include "vtls/vtls.h" |
46 | | #include "curlx/warnless.h" |
47 | | #include "sendf.h" |
48 | | #include "hostip.h" |
49 | | #include "http2.h" |
50 | | #include "setopt.h" |
51 | | #include "multiif.h" |
52 | | #include "altsvc.h" |
53 | | #include "hsts.h" |
54 | | #include "tftp.h" |
55 | | #include "strdup.h" |
56 | | #include "escape.h" |
57 | | |
58 | | /* The last 3 #include files should be in this order */ |
59 | | #include "curl_printf.h" |
60 | | #include "curl_memory.h" |
61 | | #include "memdebug.h" |
62 | | |
63 | | |
64 | | static CURLcode setopt_set_timeout_sec(timediff_t *ptimeout_ms, long secs) |
65 | 0 | { |
66 | 0 | if(secs < 0) |
67 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
68 | 0 | #if LONG_MAX > (TIMEDIFF_T_MAX/1000) |
69 | 0 | if(secs > (TIMEDIFF_T_MAX/1000)) { |
70 | 0 | *ptimeout_ms = TIMEDIFF_T_MAX; |
71 | 0 | return CURLE_OK; |
72 | 0 | } |
73 | 0 | #endif |
74 | 0 | *ptimeout_ms = (timediff_t)secs * 1000; |
75 | 0 | return CURLE_OK; |
76 | 0 | } |
77 | | |
78 | | static CURLcode setopt_set_timeout_ms(timediff_t *ptimeout_ms, long ms) |
79 | 0 | { |
80 | 0 | if(ms < 0) |
81 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
82 | | #if LONG_MAX > TIMEDIFF_T_MAX |
83 | | if(ms > TIMEDIFF_T_MAX) { |
84 | | *ptimeout_ms = TIMEDIFF_T_MAX; |
85 | | return CURLE_OK; |
86 | | } |
87 | | #endif |
88 | 0 | *ptimeout_ms = (timediff_t)ms; |
89 | 0 | return CURLE_OK; |
90 | 0 | } |
91 | | |
92 | | CURLcode Curl_setstropt(char **charp, const char *s) |
93 | 0 | { |
94 | | /* Release the previous storage at `charp' and replace by a dynamic storage |
95 | | copy of `s'. Return CURLE_OK or CURLE_OUT_OF_MEMORY. */ |
96 | |
|
97 | 0 | Curl_safefree(*charp); |
98 | |
|
99 | 0 | if(s) { |
100 | 0 | if(strlen(s) > CURL_MAX_INPUT_LENGTH) |
101 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
102 | | |
103 | 0 | *charp = strdup(s); |
104 | 0 | if(!*charp) |
105 | 0 | return CURLE_OUT_OF_MEMORY; |
106 | 0 | } |
107 | | |
108 | 0 | return CURLE_OK; |
109 | 0 | } |
110 | | |
111 | | CURLcode Curl_setblobopt(struct curl_blob **blobp, |
112 | | const struct curl_blob *blob) |
113 | 0 | { |
114 | | /* free the previous storage at `blobp' and replace by a dynamic storage |
115 | | copy of blob. If CURL_BLOB_COPY is set, the data is copied. */ |
116 | |
|
117 | 0 | Curl_safefree(*blobp); |
118 | |
|
119 | 0 | if(blob) { |
120 | 0 | struct curl_blob *nblob; |
121 | 0 | if(blob->len > CURL_MAX_INPUT_LENGTH) |
122 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
123 | 0 | nblob = (struct curl_blob *) |
124 | 0 | malloc(sizeof(struct curl_blob) + |
125 | 0 | ((blob->flags & CURL_BLOB_COPY) ? blob->len : 0)); |
126 | 0 | if(!nblob) |
127 | 0 | return CURLE_OUT_OF_MEMORY; |
128 | 0 | *nblob = *blob; |
129 | 0 | if(blob->flags & CURL_BLOB_COPY) { |
130 | | /* put the data after the blob struct in memory */ |
131 | 0 | nblob->data = (char *)nblob + sizeof(struct curl_blob); |
132 | 0 | memcpy(nblob->data, blob->data, blob->len); |
133 | 0 | } |
134 | |
|
135 | 0 | *blobp = nblob; |
136 | 0 | return CURLE_OK; |
137 | 0 | } |
138 | | |
139 | 0 | return CURLE_OK; |
140 | 0 | } |
141 | | |
142 | | static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp) |
143 | 0 | { |
144 | 0 | char *user = NULL; |
145 | 0 | char *passwd = NULL; |
146 | |
|
147 | 0 | DEBUGASSERT(userp); |
148 | 0 | DEBUGASSERT(passwdp); |
149 | | |
150 | | /* Parse the login details if specified. It not then we treat NULL as a hint |
151 | | to clear the existing data */ |
152 | 0 | if(option) { |
153 | 0 | size_t len = strlen(option); |
154 | 0 | CURLcode result; |
155 | 0 | if(len > CURL_MAX_INPUT_LENGTH) |
156 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
157 | | |
158 | 0 | result = Curl_parse_login_details(option, len, &user, &passwd, NULL); |
159 | 0 | if(result) |
160 | 0 | return result; |
161 | 0 | } |
162 | | |
163 | 0 | free(*userp); |
164 | 0 | *userp = user; |
165 | |
|
166 | 0 | free(*passwdp); |
167 | 0 | *passwdp = passwd; |
168 | |
|
169 | 0 | return CURLE_OK; |
170 | 0 | } |
171 | | |
172 | | static CURLcode setstropt_interface(char *option, char **devp, |
173 | | char **ifacep, char **hostp) |
174 | 0 | { |
175 | 0 | char *dev = NULL; |
176 | 0 | char *iface = NULL; |
177 | 0 | char *host = NULL; |
178 | 0 | CURLcode result; |
179 | |
|
180 | 0 | DEBUGASSERT(devp); |
181 | 0 | DEBUGASSERT(ifacep); |
182 | 0 | DEBUGASSERT(hostp); |
183 | |
|
184 | 0 | if(option) { |
185 | | /* Parse the interface details if set, otherwise clear them all */ |
186 | 0 | result = Curl_parse_interface(option, &dev, &iface, &host); |
187 | 0 | if(result) |
188 | 0 | return result; |
189 | 0 | } |
190 | 0 | free(*devp); |
191 | 0 | *devp = dev; |
192 | |
|
193 | 0 | free(*ifacep); |
194 | 0 | *ifacep = iface; |
195 | |
|
196 | 0 | free(*hostp); |
197 | 0 | *hostp = host; |
198 | |
|
199 | 0 | return CURLE_OK; |
200 | 0 | } |
201 | | |
202 | 0 | #define C_SSLVERSION_VALUE(x) (x & 0xffff) |
203 | 0 | #define C_SSLVERSION_MAX_VALUE(x) ((unsigned long)x & 0xffff0000) |
204 | | |
205 | | static CURLcode protocol2num(const char *str, curl_prot_t *val) |
206 | 0 | { |
207 | | /* |
208 | | * We are asked to cherry-pick protocols, so play it safe and disallow all |
209 | | * protocols to start with, and re-add the wanted ones back in. |
210 | | */ |
211 | 0 | *val = 0; |
212 | |
|
213 | 0 | if(!str) |
214 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
215 | | |
216 | 0 | if(curl_strequal(str, "all")) { |
217 | 0 | *val = ~(curl_prot_t) 0; |
218 | 0 | return CURLE_OK; |
219 | 0 | } |
220 | | |
221 | 0 | do { |
222 | 0 | const char *token = str; |
223 | 0 | size_t tlen; |
224 | |
|
225 | 0 | str = strchr(str, ','); |
226 | 0 | tlen = str ? (size_t) (str - token) : strlen(token); |
227 | 0 | if(tlen) { |
228 | 0 | const struct Curl_handler *h = Curl_getn_scheme_handler(token, tlen); |
229 | |
|
230 | 0 | if(!h) |
231 | 0 | return CURLE_UNSUPPORTED_PROTOCOL; |
232 | | |
233 | 0 | *val |= h->protocol; |
234 | 0 | } |
235 | 0 | } while(str && str++); |
236 | | |
237 | 0 | if(!*val) |
238 | | /* no protocol listed */ |
239 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
240 | 0 | return CURLE_OK; |
241 | 0 | } |
242 | | |
243 | | #if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_PROXY) |
244 | | static CURLcode httpauth(struct Curl_easy *data, bool proxy, |
245 | | unsigned long auth) |
246 | 0 | { |
247 | 0 | if(auth != CURLAUTH_NONE) { |
248 | 0 | int bitcheck = 0; |
249 | 0 | bool authbits = FALSE; |
250 | | /* the DIGEST_IE bit is only used to set a special marker, for all the |
251 | | rest we need to handle it as normal DIGEST */ |
252 | 0 | bool iestyle = !!(auth & CURLAUTH_DIGEST_IE); |
253 | 0 | if(proxy) |
254 | 0 | data->state.authproxy.iestyle = iestyle; |
255 | 0 | else |
256 | 0 | data->state.authhost.iestyle = iestyle; |
257 | |
|
258 | 0 | if(auth & CURLAUTH_DIGEST_IE) { |
259 | 0 | auth |= CURLAUTH_DIGEST; /* set standard digest bit */ |
260 | 0 | auth &= ~CURLAUTH_DIGEST_IE; /* unset ie digest bit */ |
261 | 0 | } |
262 | | |
263 | | /* switch off bits we cannot support */ |
264 | | #ifndef USE_NTLM |
265 | | auth &= ~CURLAUTH_NTLM; /* no NTLM support */ |
266 | | #endif |
267 | 0 | #ifndef USE_SPNEGO |
268 | 0 | auth &= ~CURLAUTH_NEGOTIATE; /* no Negotiate (SPNEGO) auth without GSS-API |
269 | | or SSPI */ |
270 | 0 | #endif |
271 | | |
272 | | /* check if any auth bit lower than CURLAUTH_ONLY is still set */ |
273 | 0 | while(bitcheck < 31) { |
274 | 0 | if(auth & (1UL << bitcheck++)) { |
275 | 0 | authbits = TRUE; |
276 | 0 | break; |
277 | 0 | } |
278 | 0 | } |
279 | 0 | if(!authbits) |
280 | 0 | return CURLE_NOT_BUILT_IN; /* no supported types left! */ |
281 | 0 | } |
282 | 0 | if(proxy) |
283 | 0 | data->set.proxyauth = auth; |
284 | 0 | else |
285 | 0 | data->set.httpauth = auth; |
286 | 0 | return CURLE_OK; |
287 | 0 | } |
288 | | #endif /* !CURL_DISABLE_HTTP || !CURL_DISABLE_PROXY */ |
289 | | |
290 | | #ifndef CURL_DISABLE_HTTP |
291 | | static CURLcode setopt_HTTP_VERSION(struct Curl_easy *data, long arg) |
292 | 0 | { |
293 | | /* |
294 | | * This sets a requested HTTP version to be used. The value is one of |
295 | | * the listed enums in curl/curl.h. |
296 | | */ |
297 | 0 | switch(arg) { |
298 | 0 | case CURL_HTTP_VERSION_NONE: |
299 | | /* accepted */ |
300 | 0 | break; |
301 | 0 | case CURL_HTTP_VERSION_1_0: |
302 | 0 | case CURL_HTTP_VERSION_1_1: |
303 | | /* accepted */ |
304 | 0 | break; |
305 | | #ifdef USE_HTTP2 |
306 | | case CURL_HTTP_VERSION_2_0: |
307 | | case CURL_HTTP_VERSION_2TLS: |
308 | | case CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE: |
309 | | /* accepted */ |
310 | | break; |
311 | | #endif |
312 | | #ifdef USE_HTTP3 |
313 | | case CURL_HTTP_VERSION_3: |
314 | | case CURL_HTTP_VERSION_3ONLY: |
315 | | /* accepted */ |
316 | | break; |
317 | | #endif |
318 | 0 | default: |
319 | | /* not accepted */ |
320 | 0 | if(arg < CURL_HTTP_VERSION_NONE) |
321 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
322 | 0 | return CURLE_UNSUPPORTED_PROTOCOL; |
323 | 0 | } |
324 | 0 | data->set.httpwant = (unsigned char)arg; |
325 | 0 | return CURLE_OK; |
326 | 0 | } |
327 | | #endif /* ! CURL_DISABLE_HTTP */ |
328 | | |
329 | | #ifdef USE_SSL |
330 | | CURLcode Curl_setopt_SSLVERSION(struct Curl_easy *data, CURLoption option, |
331 | | long arg) |
332 | 0 | { |
333 | | /* |
334 | | * Set explicit SSL version to try to connect with, as some SSL |
335 | | * implementations are lame. |
336 | | */ |
337 | 0 | { |
338 | 0 | long version, version_max; |
339 | 0 | struct ssl_primary_config *primary = &data->set.ssl.primary; |
340 | 0 | #ifndef CURL_DISABLE_PROXY |
341 | 0 | if(option != CURLOPT_SSLVERSION) |
342 | 0 | primary = &data->set.proxy_ssl.primary; |
343 | | #else |
344 | | if(option) {} |
345 | | #endif |
346 | 0 | version = C_SSLVERSION_VALUE(arg); |
347 | 0 | version_max = (long)C_SSLVERSION_MAX_VALUE(arg); |
348 | |
|
349 | 0 | if(version < CURL_SSLVERSION_DEFAULT || |
350 | 0 | version == CURL_SSLVERSION_SSLv2 || |
351 | 0 | version == CURL_SSLVERSION_SSLv3 || |
352 | 0 | version >= CURL_SSLVERSION_LAST || |
353 | 0 | version_max < CURL_SSLVERSION_MAX_NONE || |
354 | 0 | version_max >= CURL_SSLVERSION_MAX_LAST) |
355 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
356 | 0 | if(version == CURL_SSLVERSION_DEFAULT) |
357 | 0 | version = CURL_SSLVERSION_TLSv1_2; |
358 | |
|
359 | 0 | primary->version = (unsigned char)version; |
360 | 0 | primary->version_max = (unsigned int)version_max; |
361 | 0 | } |
362 | 0 | return CURLE_OK; |
363 | 0 | } |
364 | | #endif /* ! USE_SSL */ |
365 | | |
366 | | #ifndef CURL_DISABLE_RTSP |
367 | | static CURLcode setopt_RTSP_REQUEST(struct Curl_easy *data, long arg) |
368 | 0 | { |
369 | | /* |
370 | | * Set the RTSP request method (OPTIONS, SETUP, PLAY, etc...) |
371 | | * Would this be better if the RTSPREQ_* were just moved into here? |
372 | | */ |
373 | 0 | Curl_RtspReq rtspreq = RTSPREQ_NONE; |
374 | 0 | switch(arg) { |
375 | 0 | case CURL_RTSPREQ_OPTIONS: |
376 | 0 | rtspreq = RTSPREQ_OPTIONS; |
377 | 0 | break; |
378 | | |
379 | 0 | case CURL_RTSPREQ_DESCRIBE: |
380 | 0 | rtspreq = RTSPREQ_DESCRIBE; |
381 | 0 | break; |
382 | | |
383 | 0 | case CURL_RTSPREQ_ANNOUNCE: |
384 | 0 | rtspreq = RTSPREQ_ANNOUNCE; |
385 | 0 | break; |
386 | | |
387 | 0 | case CURL_RTSPREQ_SETUP: |
388 | 0 | rtspreq = RTSPREQ_SETUP; |
389 | 0 | break; |
390 | | |
391 | 0 | case CURL_RTSPREQ_PLAY: |
392 | 0 | rtspreq = RTSPREQ_PLAY; |
393 | 0 | break; |
394 | | |
395 | 0 | case CURL_RTSPREQ_PAUSE: |
396 | 0 | rtspreq = RTSPREQ_PAUSE; |
397 | 0 | break; |
398 | | |
399 | 0 | case CURL_RTSPREQ_TEARDOWN: |
400 | 0 | rtspreq = RTSPREQ_TEARDOWN; |
401 | 0 | break; |
402 | | |
403 | 0 | case CURL_RTSPREQ_GET_PARAMETER: |
404 | 0 | rtspreq = RTSPREQ_GET_PARAMETER; |
405 | 0 | break; |
406 | | |
407 | 0 | case CURL_RTSPREQ_SET_PARAMETER: |
408 | 0 | rtspreq = RTSPREQ_SET_PARAMETER; |
409 | 0 | break; |
410 | | |
411 | 0 | case CURL_RTSPREQ_RECORD: |
412 | 0 | rtspreq = RTSPREQ_RECORD; |
413 | 0 | break; |
414 | | |
415 | 0 | case CURL_RTSPREQ_RECEIVE: |
416 | 0 | rtspreq = RTSPREQ_RECEIVE; |
417 | 0 | break; |
418 | 0 | default: |
419 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
420 | 0 | } |
421 | | |
422 | 0 | data->set.rtspreq = rtspreq; |
423 | 0 | return CURLE_OK; |
424 | 0 | } |
425 | | #endif /* ! CURL_DISABLE_RTSP */ |
426 | | |
427 | | #ifdef USE_SSL |
428 | | static void set_ssl_options(struct ssl_config_data *ssl, |
429 | | struct ssl_primary_config *config, |
430 | | long arg) |
431 | 0 | { |
432 | 0 | config->ssl_options = (unsigned char)(arg & 0xff); |
433 | 0 | ssl->enable_beast = !!(arg & CURLSSLOPT_ALLOW_BEAST); |
434 | 0 | ssl->no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE); |
435 | 0 | ssl->no_partialchain = !!(arg & CURLSSLOPT_NO_PARTIALCHAIN); |
436 | 0 | ssl->revoke_best_effort = !!(arg & CURLSSLOPT_REVOKE_BEST_EFFORT); |
437 | 0 | ssl->native_ca_store = !!(arg & CURLSSLOPT_NATIVE_CA); |
438 | 0 | ssl->auto_client_cert = !!(arg & CURLSSLOPT_AUTO_CLIENT_CERT); |
439 | 0 | ssl->earlydata = !!(arg & CURLSSLOPT_EARLYDATA); |
440 | 0 | } |
441 | | #endif |
442 | | |
443 | | static CURLcode setopt_bool(struct Curl_easy *data, CURLoption option, |
444 | | long arg, bool *set) |
445 | 0 | { |
446 | 0 | bool enabled = !!arg; |
447 | 0 | struct UserDefined *s = &data->set; |
448 | 0 | switch(option) { |
449 | 0 | case CURLOPT_FORBID_REUSE: |
450 | | /* |
451 | | * When this transfer is done, it must not be left to be reused by a |
452 | | * subsequent transfer but shall be closed immediately. |
453 | | */ |
454 | 0 | s->reuse_forbid = enabled; |
455 | 0 | break; |
456 | 0 | case CURLOPT_FRESH_CONNECT: |
457 | | /* |
458 | | * This transfer shall not use a previously cached connection but |
459 | | * should be made with a fresh new connect! |
460 | | */ |
461 | 0 | s->reuse_fresh = enabled; |
462 | 0 | break; |
463 | 0 | case CURLOPT_VERBOSE: |
464 | | /* |
465 | | * Verbose means infof() calls that give a lot of information about |
466 | | * the connection and transfer procedures as well as internal choices. |
467 | | */ |
468 | 0 | s->verbose = enabled; |
469 | 0 | break; |
470 | 0 | case CURLOPT_HEADER: |
471 | | /* |
472 | | * Set to include the header in the general data output stream. |
473 | | */ |
474 | 0 | s->include_header = enabled; |
475 | 0 | break; |
476 | 0 | case CURLOPT_NOPROGRESS: |
477 | | /* |
478 | | * Shut off the internal supported progress meter |
479 | | */ |
480 | 0 | data->progress.hide = enabled; |
481 | 0 | break; |
482 | 0 | case CURLOPT_NOBODY: |
483 | | /* |
484 | | * Do not include the body part in the output data stream. |
485 | | */ |
486 | 0 | s->opt_no_body = enabled; |
487 | 0 | #ifndef CURL_DISABLE_HTTP |
488 | 0 | if(s->opt_no_body) |
489 | | /* in HTTP lingo, no body means using the HEAD request... */ |
490 | 0 | s->method = HTTPREQ_HEAD; |
491 | 0 | else if(s->method == HTTPREQ_HEAD) |
492 | 0 | s->method = HTTPREQ_GET; |
493 | 0 | #endif |
494 | 0 | break; |
495 | 0 | case CURLOPT_FAILONERROR: |
496 | | /* |
497 | | * Do not output the >=400 error code HTML-page, but instead only |
498 | | * return error. |
499 | | */ |
500 | 0 | s->http_fail_on_error = enabled; |
501 | 0 | break; |
502 | 0 | case CURLOPT_KEEP_SENDING_ON_ERROR: |
503 | 0 | s->http_keep_sending_on_error = enabled; |
504 | 0 | break; |
505 | 0 | case CURLOPT_UPLOAD: |
506 | 0 | case CURLOPT_PUT: |
507 | | /* |
508 | | * We want to sent data to the remote host. If this is HTTP, that equals |
509 | | * using the PUT request. |
510 | | */ |
511 | 0 | if(enabled) { |
512 | | /* If this is HTTP, PUT is what's needed to "upload" */ |
513 | 0 | s->method = HTTPREQ_PUT; |
514 | 0 | s->opt_no_body = FALSE; /* this is implied */ |
515 | 0 | } |
516 | 0 | else |
517 | | /* In HTTP, the opposite of upload is GET (unless NOBODY is true as |
518 | | then this can be changed to HEAD later on) */ |
519 | 0 | s->method = HTTPREQ_GET; |
520 | 0 | break; |
521 | 0 | case CURLOPT_FILETIME: |
522 | | /* |
523 | | * Try to get the file time of the remote document. The time will |
524 | | * later (possibly) become available using curl_easy_getinfo(). |
525 | | */ |
526 | 0 | s->get_filetime = enabled; |
527 | 0 | break; |
528 | 0 | #ifndef CURL_DISABLE_HTTP |
529 | 0 | case CURLOPT_HTTP09_ALLOWED: |
530 | 0 | s->http09_allowed = enabled; |
531 | 0 | break; |
532 | 0 | #if !defined(CURL_DISABLE_COOKIES) |
533 | 0 | case CURLOPT_COOKIESESSION: |
534 | | /* |
535 | | * Set this option to TRUE to start a new "cookie session". It will |
536 | | * prevent the forthcoming read-cookies-from-file actions to accept |
537 | | * cookies that are marked as being session cookies, as they belong to a |
538 | | * previous session. |
539 | | */ |
540 | 0 | s->cookiesession = enabled; |
541 | 0 | break; |
542 | 0 | #endif |
543 | 0 | case CURLOPT_AUTOREFERER: |
544 | | /* |
545 | | * Switch on automatic referer that gets set if curl follows locations. |
546 | | */ |
547 | 0 | s->http_auto_referer = enabled; |
548 | 0 | break; |
549 | | |
550 | 0 | case CURLOPT_TRANSFER_ENCODING: |
551 | 0 | s->http_transfer_encoding = enabled; |
552 | 0 | break; |
553 | 0 | case CURLOPT_UNRESTRICTED_AUTH: |
554 | | /* |
555 | | * Send authentication (user+password) when following locations, even when |
556 | | * hostname changed. |
557 | | */ |
558 | 0 | s->allow_auth_to_other_hosts = enabled; |
559 | 0 | break; |
560 | | |
561 | 0 | case CURLOPT_HTTP_TRANSFER_DECODING: |
562 | | /* |
563 | | * disable libcurl transfer encoding is used |
564 | | */ |
565 | 0 | s->http_te_skip = !enabled; /* reversed */ |
566 | 0 | break; |
567 | | |
568 | 0 | case CURLOPT_HTTP_CONTENT_DECODING: |
569 | | /* |
570 | | * raw data passed to the application when content encoding is used |
571 | | */ |
572 | 0 | s->http_ce_skip = !enabled; /* reversed */ |
573 | 0 | break; |
574 | | |
575 | 0 | case CURLOPT_HTTPGET: |
576 | | /* |
577 | | * Set to force us do HTTP GET |
578 | | */ |
579 | 0 | if(enabled) { |
580 | 0 | s->method = HTTPREQ_GET; |
581 | 0 | s->opt_no_body = FALSE; /* this is implied */ |
582 | 0 | } |
583 | 0 | break; |
584 | 0 | case CURLOPT_POST: |
585 | | /* Does this option serve a purpose anymore? Yes it does, when |
586 | | CURLOPT_POSTFIELDS is not used and the POST data is read off the |
587 | | callback! */ |
588 | 0 | if(enabled) { |
589 | 0 | s->method = HTTPREQ_POST; |
590 | 0 | s->opt_no_body = FALSE; /* this is implied */ |
591 | 0 | } |
592 | 0 | else |
593 | 0 | s->method = HTTPREQ_GET; |
594 | 0 | break; |
595 | 0 | #endif /* ! CURL_DISABLE_HTTP */ |
596 | 0 | #ifndef CURL_DISABLE_PROXY |
597 | 0 | case CURLOPT_HTTPPROXYTUNNEL: |
598 | | /* |
599 | | * Tunnel operations through the proxy instead of normal proxy use |
600 | | */ |
601 | 0 | s->tunnel_thru_httpproxy = enabled; |
602 | 0 | break; |
603 | 0 | case CURLOPT_HAPROXYPROTOCOL: |
604 | | /* |
605 | | * Set to send the HAProxy Proxy Protocol header |
606 | | */ |
607 | 0 | s->haproxyprotocol = enabled; |
608 | 0 | break; |
609 | 0 | case CURLOPT_PROXY_SSL_VERIFYPEER: |
610 | | /* |
611 | | * Enable peer SSL verifying for proxy. |
612 | | */ |
613 | 0 | s->proxy_ssl.primary.verifypeer = enabled; |
614 | | |
615 | | /* Update the current connection proxy_ssl_config. */ |
616 | 0 | Curl_ssl_conn_config_update(data, TRUE); |
617 | 0 | break; |
618 | 0 | case CURLOPT_PROXY_SSL_VERIFYHOST: |
619 | | /* |
620 | | * Enable verification of the hostname in the peer certificate for proxy |
621 | | */ |
622 | 0 | s->proxy_ssl.primary.verifyhost = enabled; |
623 | | |
624 | | /* Update the current connection proxy_ssl_config. */ |
625 | 0 | Curl_ssl_conn_config_update(data, TRUE); |
626 | 0 | break; |
627 | 0 | case CURLOPT_PROXY_TRANSFER_MODE: |
628 | | /* |
629 | | * set transfer mode (;type=<a|i>) when doing FTP via an HTTP proxy |
630 | | */ |
631 | 0 | s->proxy_transfer_mode = enabled; |
632 | 0 | break; |
633 | 0 | #endif /* ! CURL_DISABLE_PROXY */ |
634 | | #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI) |
635 | | case CURLOPT_SOCKS5_GSSAPI_NEC: |
636 | | /* |
637 | | * Set flag for NEC SOCK5 support |
638 | | */ |
639 | | s->socks5_gssapi_nec = enabled; |
640 | | break; |
641 | | #endif |
642 | 0 | #ifdef CURL_LIST_ONLY_PROTOCOL |
643 | 0 | case CURLOPT_DIRLISTONLY: |
644 | | /* |
645 | | * An option that changes the command to one that asks for a list only, no |
646 | | * file info details. Used for FTP, POP3 and SFTP. |
647 | | */ |
648 | 0 | s->list_only = enabled; |
649 | 0 | break; |
650 | 0 | #endif |
651 | 0 | case CURLOPT_APPEND: |
652 | | /* |
653 | | * We want to upload and append to an existing file. Used for FTP and |
654 | | * SFTP. |
655 | | */ |
656 | 0 | s->remote_append = enabled; |
657 | 0 | break; |
658 | 0 | #ifndef CURL_DISABLE_FTP |
659 | 0 | case CURLOPT_FTP_USE_EPRT: |
660 | 0 | s->ftp_use_eprt = enabled; |
661 | 0 | break; |
662 | | |
663 | 0 | case CURLOPT_FTP_USE_EPSV: |
664 | 0 | s->ftp_use_epsv = enabled; |
665 | 0 | break; |
666 | | |
667 | 0 | case CURLOPT_FTP_USE_PRET: |
668 | 0 | s->ftp_use_pret = enabled; |
669 | 0 | break; |
670 | 0 | case CURLOPT_FTP_SKIP_PASV_IP: |
671 | | /* |
672 | | * Enable or disable FTP_SKIP_PASV_IP, which will disable/enable the |
673 | | * bypass of the IP address in PASV responses. |
674 | | */ |
675 | 0 | s->ftp_skip_ip = enabled; |
676 | 0 | break; |
677 | 0 | case CURLOPT_WILDCARDMATCH: |
678 | 0 | s->wildcard_enabled = enabled; |
679 | 0 | break; |
680 | 0 | #endif |
681 | 0 | case CURLOPT_CRLF: |
682 | | /* |
683 | | * Kludgy option to enable CRLF conversions. Subject for removal. |
684 | | */ |
685 | 0 | s->crlf = enabled; |
686 | 0 | break; |
687 | | |
688 | 0 | #ifndef CURL_DISABLE_TFTP |
689 | 0 | case CURLOPT_TFTP_NO_OPTIONS: |
690 | | /* |
691 | | * Option that prevents libcurl from sending TFTP option requests to the |
692 | | * server. |
693 | | */ |
694 | 0 | s->tftp_no_options = enabled; |
695 | 0 | break; |
696 | 0 | #endif /* ! CURL_DISABLE_TFTP */ |
697 | 0 | case CURLOPT_TRANSFERTEXT: |
698 | | /* |
699 | | * This option was previously named 'FTPASCII'. Renamed to work with |
700 | | * more protocols than merely FTP. |
701 | | * |
702 | | * Transfer using ASCII (instead of BINARY). |
703 | | */ |
704 | 0 | s->prefer_ascii = enabled; |
705 | 0 | break; |
706 | 0 | case CURLOPT_SSL_VERIFYPEER: |
707 | | /* |
708 | | * Enable peer SSL verifying. |
709 | | */ |
710 | 0 | s->ssl.primary.verifypeer = enabled; |
711 | | |
712 | | /* Update the current connection ssl_config. */ |
713 | 0 | Curl_ssl_conn_config_update(data, FALSE); |
714 | 0 | break; |
715 | 0 | #ifndef CURL_DISABLE_DOH |
716 | 0 | case CURLOPT_DOH_SSL_VERIFYPEER: |
717 | | /* |
718 | | * Enable peer SSL verifying for DoH. |
719 | | */ |
720 | 0 | s->doh_verifypeer = enabled; |
721 | 0 | break; |
722 | 0 | case CURLOPT_DOH_SSL_VERIFYHOST: |
723 | | /* |
724 | | * Enable verification of the hostname in the peer certificate for DoH |
725 | | */ |
726 | 0 | s->doh_verifyhost = enabled; |
727 | 0 | break; |
728 | 0 | case CURLOPT_DOH_SSL_VERIFYSTATUS: |
729 | | /* |
730 | | * Enable certificate status verifying for DoH. |
731 | | */ |
732 | 0 | if(!Curl_ssl_cert_status_request()) |
733 | 0 | return CURLE_NOT_BUILT_IN; |
734 | | |
735 | 0 | s->doh_verifystatus = enabled; |
736 | 0 | break; |
737 | 0 | #endif /* ! CURL_DISABLE_DOH */ |
738 | 0 | case CURLOPT_SSL_VERIFYHOST: |
739 | | /* |
740 | | * Enable verification of the hostname in the peer certificate |
741 | | */ |
742 | | |
743 | | /* Obviously people are not reading documentation and too many thought |
744 | | this argument took a boolean when it was not and misused it. |
745 | | Treat 1 and 2 the same */ |
746 | 0 | s->ssl.primary.verifyhost = enabled; |
747 | | |
748 | | /* Update the current connection ssl_config. */ |
749 | 0 | Curl_ssl_conn_config_update(data, FALSE); |
750 | 0 | break; |
751 | 0 | case CURLOPT_SSL_VERIFYSTATUS: |
752 | | /* |
753 | | * Enable certificate status verifying. |
754 | | */ |
755 | 0 | if(!Curl_ssl_cert_status_request()) |
756 | 0 | return CURLE_NOT_BUILT_IN; |
757 | | |
758 | 0 | s->ssl.primary.verifystatus = enabled; |
759 | | |
760 | | /* Update the current connection ssl_config. */ |
761 | 0 | Curl_ssl_conn_config_update(data, FALSE); |
762 | 0 | break; |
763 | 0 | case CURLOPT_CERTINFO: |
764 | 0 | #ifdef USE_SSL |
765 | 0 | if(Curl_ssl_supports(data, SSLSUPP_CERTINFO)) |
766 | 0 | s->ssl.certinfo = enabled; |
767 | 0 | else |
768 | 0 | #endif |
769 | 0 | return CURLE_NOT_BUILT_IN; |
770 | 0 | break; |
771 | 0 | case CURLOPT_NOSIGNAL: |
772 | | /* |
773 | | * The application asks not to set any signal() or alarm() handlers, |
774 | | * even when using a timeout. |
775 | | */ |
776 | 0 | s->no_signal = enabled; |
777 | 0 | break; |
778 | 0 | case CURLOPT_TCP_NODELAY: |
779 | | /* |
780 | | * Enable or disable TCP_NODELAY, which will disable/enable the Nagle |
781 | | * algorithm |
782 | | */ |
783 | 0 | s->tcp_nodelay = enabled; |
784 | 0 | break; |
785 | | |
786 | 0 | case CURLOPT_IGNORE_CONTENT_LENGTH: |
787 | 0 | s->ignorecl = enabled; |
788 | 0 | break; |
789 | 0 | case CURLOPT_SSL_SESSIONID_CACHE: |
790 | 0 | s->ssl.primary.cache_session = enabled; |
791 | 0 | #ifndef CURL_DISABLE_PROXY |
792 | 0 | s->proxy_ssl.primary.cache_session = |
793 | 0 | s->ssl.primary.cache_session; |
794 | 0 | #endif |
795 | 0 | break; |
796 | | #ifdef USE_SSH |
797 | | case CURLOPT_SSH_COMPRESSION: |
798 | | s->ssh_compression = enabled; |
799 | | break; |
800 | | #endif /* ! USE_SSH */ |
801 | 0 | #ifndef CURL_DISABLE_SMTP |
802 | 0 | case CURLOPT_MAIL_RCPT_ALLOWFAILS: |
803 | | /* allow RCPT TO command to fail for some recipients */ |
804 | 0 | s->mail_rcpt_allowfails = enabled; |
805 | 0 | break; |
806 | 0 | #endif /* !CURL_DISABLE_SMTP */ |
807 | 0 | case CURLOPT_SASL_IR: |
808 | | /* Enable/disable SASL initial response */ |
809 | 0 | s->sasl_ir = enabled; |
810 | 0 | break; |
811 | 0 | case CURLOPT_TCP_KEEPALIVE: |
812 | 0 | s->tcp_keepalive = enabled; |
813 | 0 | break; |
814 | 0 | case CURLOPT_TCP_FASTOPEN: |
815 | 0 | #if defined(CONNECT_DATA_IDEMPOTENT) || defined(MSG_FASTOPEN) || \ |
816 | 0 | defined(TCP_FASTOPEN_CONNECT) |
817 | 0 | s->tcp_fastopen = enabled; |
818 | | #else |
819 | | return CURLE_NOT_BUILT_IN; |
820 | | #endif |
821 | 0 | break; |
822 | 0 | case CURLOPT_SSL_ENABLE_ALPN: |
823 | 0 | s->ssl_enable_alpn = enabled; |
824 | 0 | break; |
825 | 0 | case CURLOPT_PATH_AS_IS: |
826 | 0 | s->path_as_is = enabled; |
827 | 0 | break; |
828 | 0 | case CURLOPT_PIPEWAIT: |
829 | 0 | s->pipewait = enabled; |
830 | 0 | break; |
831 | 0 | case CURLOPT_SUPPRESS_CONNECT_HEADERS: |
832 | 0 | s->suppress_connect_headers = enabled; |
833 | 0 | break; |
834 | 0 | #ifndef CURL_DISABLE_SHUFFLE_DNS |
835 | 0 | case CURLOPT_DNS_SHUFFLE_ADDRESSES: |
836 | 0 | s->dns_shuffle_addresses = enabled; |
837 | 0 | break; |
838 | 0 | #endif |
839 | 0 | case CURLOPT_DISALLOW_USERNAME_IN_URL: |
840 | 0 | s->disallow_username_in_url = enabled; |
841 | 0 | break; |
842 | 0 | case CURLOPT_QUICK_EXIT: |
843 | 0 | s->quick_exit = enabled; |
844 | 0 | break; |
845 | 0 | default: |
846 | 0 | return CURLE_OK; |
847 | 0 | } |
848 | 0 | if((arg > 1) || (arg < 0)) |
849 | | /* reserve other values for future use */ |
850 | 0 | infof(data, "boolean setopt(%d) got unsupported argument %ld," |
851 | 0 | " treated as %d", option, arg, enabled); |
852 | |
|
853 | 0 | *set = TRUE; |
854 | 0 | return CURLE_OK; |
855 | 0 | } |
856 | | |
857 | | static CURLcode setopt_long(struct Curl_easy *data, CURLoption option, |
858 | | long arg) |
859 | 0 | { |
860 | 0 | unsigned long uarg = (unsigned long)arg; |
861 | 0 | bool set = FALSE; |
862 | 0 | CURLcode result = setopt_bool(data, option, arg, &set); |
863 | 0 | struct UserDefined *s = &data->set; |
864 | 0 | if(set || result) |
865 | 0 | return result; |
866 | | |
867 | 0 | switch(option) { |
868 | 0 | case CURLOPT_DNS_CACHE_TIMEOUT: |
869 | 0 | if(arg < -1) |
870 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
871 | 0 | else if(arg > INT_MAX) |
872 | 0 | arg = INT_MAX; |
873 | | |
874 | 0 | s->dns_cache_timeout = (int)arg; |
875 | 0 | break; |
876 | 0 | case CURLOPT_CA_CACHE_TIMEOUT: |
877 | 0 | if(Curl_ssl_supports(data, SSLSUPP_CA_CACHE)) { |
878 | 0 | if(arg < -1) |
879 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
880 | 0 | else if(arg > INT_MAX) |
881 | 0 | arg = INT_MAX; |
882 | | |
883 | 0 | s->general_ssl.ca_cache_timeout = (int)arg; |
884 | 0 | } |
885 | 0 | else |
886 | 0 | return CURLE_NOT_BUILT_IN; |
887 | 0 | break; |
888 | 0 | case CURLOPT_MAXCONNECTS: |
889 | | /* |
890 | | * Set the absolute number of maximum simultaneous alive connection that |
891 | | * libcurl is allowed to have. |
892 | | */ |
893 | 0 | if(uarg > UINT_MAX) |
894 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
895 | 0 | s->maxconnects = (unsigned int)uarg; |
896 | 0 | break; |
897 | 0 | case CURLOPT_SERVER_RESPONSE_TIMEOUT: |
898 | | /* |
899 | | * Option that specifies how quickly a server response must be obtained |
900 | | * before it is considered failure. For pingpong protocols. |
901 | | */ |
902 | 0 | return setopt_set_timeout_sec(&s->server_response_timeout, arg); |
903 | | |
904 | 0 | case CURLOPT_SERVER_RESPONSE_TIMEOUT_MS: |
905 | | /* |
906 | | * Option that specifies how quickly a server response must be obtained |
907 | | * before it is considered failure. For pingpong protocols. |
908 | | */ |
909 | 0 | return setopt_set_timeout_ms(&s->server_response_timeout, arg); |
910 | | |
911 | 0 | #ifndef CURL_DISABLE_TFTP |
912 | 0 | case CURLOPT_TFTP_BLKSIZE: |
913 | | /* |
914 | | * TFTP option that specifies the block size to use for data transmission. |
915 | | */ |
916 | 0 | if(arg < TFTP_BLKSIZE_MIN) |
917 | 0 | arg = 512; |
918 | 0 | else if(arg > TFTP_BLKSIZE_MAX) |
919 | 0 | arg = TFTP_BLKSIZE_MAX; |
920 | 0 | s->tftp_blksize = arg; |
921 | 0 | break; |
922 | 0 | #endif |
923 | 0 | #ifndef CURL_DISABLE_NETRC |
924 | 0 | case CURLOPT_NETRC: |
925 | | /* |
926 | | * Parse the $HOME/.netrc file |
927 | | */ |
928 | 0 | if((arg < CURL_NETRC_IGNORED) || (arg >= CURL_NETRC_LAST)) |
929 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
930 | 0 | s->use_netrc = (unsigned char)arg; |
931 | 0 | break; |
932 | 0 | #endif |
933 | 0 | case CURLOPT_TIMECONDITION: |
934 | | /* |
935 | | * Set HTTP time condition. This must be one of the defines in the |
936 | | * curl/curl.h header file. |
937 | | */ |
938 | 0 | if((arg < CURL_TIMECOND_NONE) || (arg >= CURL_TIMECOND_LAST)) |
939 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
940 | 0 | s->timecondition = (unsigned char)arg; |
941 | 0 | break; |
942 | 0 | case CURLOPT_TIMEVALUE: |
943 | | /* |
944 | | * This is the value to compare with the remote document with the |
945 | | * method set with CURLOPT_TIMECONDITION |
946 | | */ |
947 | 0 | s->timevalue = (time_t)arg; |
948 | 0 | break; |
949 | 0 | case CURLOPT_SSLVERSION: |
950 | 0 | #ifndef CURL_DISABLE_PROXY |
951 | 0 | case CURLOPT_PROXY_SSLVERSION: |
952 | 0 | #endif |
953 | 0 | return Curl_setopt_SSLVERSION(data, option, arg); |
954 | | |
955 | 0 | case CURLOPT_POSTFIELDSIZE: |
956 | | /* |
957 | | * The size of the POSTFIELD data to prevent libcurl to do strlen() to |
958 | | * figure it out. Enables binary posts. |
959 | | */ |
960 | 0 | if(arg < -1) |
961 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
962 | | |
963 | 0 | if(s->postfieldsize < arg && |
964 | 0 | s->postfields == s->str[STRING_COPYPOSTFIELDS]) { |
965 | | /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */ |
966 | 0 | Curl_safefree(s->str[STRING_COPYPOSTFIELDS]); |
967 | 0 | s->postfields = NULL; |
968 | 0 | } |
969 | |
|
970 | 0 | s->postfieldsize = arg; |
971 | 0 | break; |
972 | 0 | #ifndef CURL_DISABLE_HTTP |
973 | 0 | case CURLOPT_FOLLOWLOCATION: |
974 | | /* |
975 | | * Follow Location: header hints on an HTTP-server. |
976 | | */ |
977 | 0 | if(uarg > 3) |
978 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
979 | 0 | s->http_follow_mode = (unsigned char)uarg; |
980 | 0 | break; |
981 | | |
982 | 0 | case CURLOPT_MAXREDIRS: |
983 | | /* |
984 | | * The maximum amount of hops you allow curl to follow Location: |
985 | | * headers. This should mostly be used to detect never-ending loops. |
986 | | */ |
987 | 0 | if(arg < -1) |
988 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
989 | 0 | s->maxredirs = arg; |
990 | 0 | break; |
991 | | |
992 | 0 | case CURLOPT_POSTREDIR: |
993 | | /* |
994 | | * Set the behavior of POST when redirecting |
995 | | * CURL_REDIR_GET_ALL - POST is changed to GET after 301 and 302 |
996 | | * CURL_REDIR_POST_301 - POST is kept as POST after 301 |
997 | | * CURL_REDIR_POST_302 - POST is kept as POST after 302 |
998 | | * CURL_REDIR_POST_303 - POST is kept as POST after 303 |
999 | | * CURL_REDIR_POST_ALL - POST is kept as POST after 301, 302 and 303 |
1000 | | * other - POST is kept as POST after 301 and 302 |
1001 | | */ |
1002 | 0 | if(arg < CURL_REDIR_GET_ALL) |
1003 | | /* no return error on too high numbers since the bitmask could be |
1004 | | extended in a future */ |
1005 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1006 | 0 | s->keep_post = arg & CURL_REDIR_POST_ALL; |
1007 | 0 | break; |
1008 | | |
1009 | 0 | case CURLOPT_HEADEROPT: |
1010 | | /* |
1011 | | * Set header option. |
1012 | | */ |
1013 | 0 | s->sep_headers = !!(arg & CURLHEADER_SEPARATE); |
1014 | 0 | break; |
1015 | 0 | case CURLOPT_HTTPAUTH: |
1016 | 0 | return httpauth(data, FALSE, uarg); |
1017 | | |
1018 | 0 | case CURLOPT_HTTP_VERSION: |
1019 | 0 | return setopt_HTTP_VERSION(data, arg); |
1020 | | |
1021 | 0 | case CURLOPT_EXPECT_100_TIMEOUT_MS: |
1022 | | /* |
1023 | | * Time to wait for a response to an HTTP request containing an |
1024 | | * Expect: 100-continue header before sending the data anyway. |
1025 | | */ |
1026 | 0 | if(arg < 0) |
1027 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1028 | 0 | s->expect_100_timeout = arg; |
1029 | 0 | break; |
1030 | | |
1031 | 0 | #endif /* ! CURL_DISABLE_HTTP */ |
1032 | | |
1033 | 0 | #ifndef CURL_DISABLE_MIME |
1034 | 0 | case CURLOPT_MIME_OPTIONS: |
1035 | 0 | s->mime_formescape = !!(arg & CURLMIMEOPT_FORMESCAPE); |
1036 | 0 | break; |
1037 | 0 | #endif |
1038 | 0 | #ifndef CURL_DISABLE_PROXY |
1039 | 0 | case CURLOPT_PROXYPORT: |
1040 | | /* |
1041 | | * Explicitly set HTTP proxy port number. |
1042 | | */ |
1043 | 0 | if((arg < 0) || (arg > 65535)) |
1044 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1045 | 0 | s->proxyport = (unsigned short)arg; |
1046 | 0 | break; |
1047 | | |
1048 | 0 | case CURLOPT_PROXYAUTH: |
1049 | 0 | return httpauth(data, TRUE, uarg); |
1050 | | |
1051 | 0 | case CURLOPT_PROXYTYPE: |
1052 | | /* |
1053 | | * Set proxy type. |
1054 | | */ |
1055 | 0 | if((arg < CURLPROXY_HTTP) || (arg > CURLPROXY_SOCKS5_HOSTNAME)) |
1056 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1057 | 0 | s->proxytype = (unsigned char)arg; |
1058 | 0 | break; |
1059 | | |
1060 | 0 | case CURLOPT_SOCKS5_AUTH: |
1061 | 0 | if(uarg & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI)) |
1062 | 0 | return CURLE_NOT_BUILT_IN; |
1063 | 0 | s->socks5auth = (unsigned char)uarg; |
1064 | 0 | break; |
1065 | 0 | #endif /* ! CURL_DISABLE_PROXY */ |
1066 | | |
1067 | 0 | #ifndef CURL_DISABLE_FTP |
1068 | 0 | case CURLOPT_FTP_FILEMETHOD: |
1069 | | /* |
1070 | | * How do access files over FTP. |
1071 | | */ |
1072 | 0 | if((arg < CURLFTPMETHOD_DEFAULT) || (arg >= CURLFTPMETHOD_LAST)) |
1073 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1074 | 0 | s->ftp_filemethod = (unsigned char)arg; |
1075 | 0 | break; |
1076 | 0 | case CURLOPT_FTP_SSL_CCC: |
1077 | 0 | if((arg < CURLFTPSSL_CCC_NONE) || (arg >= CURLFTPSSL_CCC_LAST)) |
1078 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1079 | 0 | s->ftp_ccc = (unsigned char)arg; |
1080 | 0 | break; |
1081 | | |
1082 | 0 | case CURLOPT_FTPSSLAUTH: |
1083 | | /* |
1084 | | * Set a specific auth for FTP-SSL transfers. |
1085 | | */ |
1086 | 0 | if((arg < CURLFTPAUTH_DEFAULT) || (arg >= CURLFTPAUTH_LAST)) |
1087 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1088 | 0 | s->ftpsslauth = (unsigned char)arg; |
1089 | 0 | break; |
1090 | 0 | case CURLOPT_ACCEPTTIMEOUT_MS: |
1091 | | /* |
1092 | | * The maximum time for curl to wait for FTP server connect |
1093 | | */ |
1094 | 0 | return setopt_set_timeout_ms(&s->accepttimeout, arg); |
1095 | 0 | #endif /* ! CURL_DISABLE_FTP */ |
1096 | 0 | #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH) |
1097 | 0 | case CURLOPT_FTP_CREATE_MISSING_DIRS: |
1098 | | /* |
1099 | | * An FTP/SFTP option that modifies an upload to create missing |
1100 | | * directories on the server. |
1101 | | */ |
1102 | | /* reserve other values for future use */ |
1103 | 0 | if((arg < CURLFTP_CREATE_DIR_NONE) || (arg > CURLFTP_CREATE_DIR_RETRY)) |
1104 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1105 | 0 | s->ftp_create_missing_dirs = (unsigned char)arg; |
1106 | 0 | break; |
1107 | 0 | #endif /* ! CURL_DISABLE_FTP || USE_SSH */ |
1108 | 0 | case CURLOPT_INFILESIZE: |
1109 | | /* |
1110 | | * If known, this should inform curl about the file size of the |
1111 | | * to-be-uploaded file. |
1112 | | */ |
1113 | 0 | if(arg < -1) |
1114 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1115 | 0 | s->filesize = arg; |
1116 | 0 | break; |
1117 | 0 | case CURLOPT_LOW_SPEED_LIMIT: |
1118 | | /* |
1119 | | * The low speed limit that if transfers are below this for |
1120 | | * CURLOPT_LOW_SPEED_TIME, the transfer is aborted. |
1121 | | */ |
1122 | 0 | if(arg < 0) |
1123 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1124 | 0 | s->low_speed_limit = arg; |
1125 | 0 | break; |
1126 | 0 | case CURLOPT_LOW_SPEED_TIME: |
1127 | | /* |
1128 | | * The low speed time that if transfers are below the set |
1129 | | * CURLOPT_LOW_SPEED_LIMIT during this time, the transfer is aborted. |
1130 | | */ |
1131 | 0 | if(arg < 0) |
1132 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1133 | 0 | s->low_speed_time = arg; |
1134 | 0 | break; |
1135 | 0 | case CURLOPT_PORT: |
1136 | | /* |
1137 | | * The port number to use when getting the URL. 0 disables it. |
1138 | | */ |
1139 | 0 | if((arg < 0) || (arg > 65535)) |
1140 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1141 | 0 | s->use_port = (unsigned short)arg; |
1142 | 0 | break; |
1143 | 0 | case CURLOPT_TIMEOUT: |
1144 | | /* |
1145 | | * The maximum time you allow curl to use for a single transfer |
1146 | | * operation. |
1147 | | */ |
1148 | 0 | return setopt_set_timeout_sec(&s->timeout, arg); |
1149 | | |
1150 | 0 | case CURLOPT_TIMEOUT_MS: |
1151 | 0 | return setopt_set_timeout_ms(&s->timeout, arg); |
1152 | | |
1153 | 0 | case CURLOPT_CONNECTTIMEOUT: |
1154 | | /* |
1155 | | * The maximum time you allow curl to use to connect. |
1156 | | */ |
1157 | 0 | return setopt_set_timeout_sec(&s->connecttimeout, arg); |
1158 | | |
1159 | 0 | case CURLOPT_CONNECTTIMEOUT_MS: |
1160 | 0 | return setopt_set_timeout_ms(&s->connecttimeout, arg); |
1161 | | |
1162 | 0 | case CURLOPT_RESUME_FROM: |
1163 | | /* |
1164 | | * Resume transfer at the given file position |
1165 | | */ |
1166 | 0 | if(arg < -1) |
1167 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1168 | 0 | s->set_resume_from = arg; |
1169 | 0 | break; |
1170 | | |
1171 | 0 | #ifndef CURL_DISABLE_BINDLOCAL |
1172 | 0 | case CURLOPT_LOCALPORT: |
1173 | | /* |
1174 | | * Set what local port to bind the socket to when performing an operation. |
1175 | | */ |
1176 | 0 | if((arg < 0) || (arg > 65535)) |
1177 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1178 | 0 | s->localport = curlx_sltous(arg); |
1179 | 0 | break; |
1180 | 0 | case CURLOPT_LOCALPORTRANGE: |
1181 | | /* |
1182 | | * Set number of local ports to try, starting with CURLOPT_LOCALPORT. |
1183 | | */ |
1184 | 0 | if((arg < 0) || (arg > 65535)) |
1185 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1186 | 0 | s->localportrange = curlx_sltous(arg); |
1187 | 0 | break; |
1188 | 0 | #endif |
1189 | | |
1190 | | #ifdef HAVE_GSSAPI |
1191 | | case CURLOPT_GSSAPI_DELEGATION: |
1192 | | /* |
1193 | | * GSS-API credential delegation bitmask |
1194 | | */ |
1195 | | s->gssapi_delegation = (unsigned char)uarg& |
1196 | | (CURLGSSAPI_DELEGATION_POLICY_FLAG|CURLGSSAPI_DELEGATION_FLAG); |
1197 | | break; |
1198 | | #endif |
1199 | | |
1200 | 0 | case CURLOPT_SSL_FALSESTART: |
1201 | | /* |
1202 | | * No TLS backends support false start anymore. |
1203 | | */ |
1204 | 0 | return CURLE_NOT_BUILT_IN; |
1205 | 0 | case CURLOPT_BUFFERSIZE: |
1206 | | /* |
1207 | | * The application kindly asks for a differently sized receive buffer. |
1208 | | * If it seems reasonable, we will use it. |
1209 | | */ |
1210 | 0 | if(arg > READBUFFER_MAX) |
1211 | 0 | arg = READBUFFER_MAX; |
1212 | 0 | else if(arg < 1) |
1213 | 0 | arg = READBUFFER_SIZE; |
1214 | 0 | else if(arg < READBUFFER_MIN) |
1215 | 0 | arg = READBUFFER_MIN; |
1216 | |
|
1217 | 0 | s->buffer_size = (unsigned int)arg; |
1218 | 0 | break; |
1219 | | |
1220 | 0 | case CURLOPT_UPLOAD_BUFFERSIZE: |
1221 | | /* |
1222 | | * The application kindly asks for a differently sized upload buffer. |
1223 | | * Cap it to sensible. |
1224 | | */ |
1225 | 0 | if(arg > UPLOADBUFFER_MAX) |
1226 | 0 | arg = UPLOADBUFFER_MAX; |
1227 | 0 | else if(arg < UPLOADBUFFER_MIN) |
1228 | 0 | arg = UPLOADBUFFER_MIN; |
1229 | |
|
1230 | 0 | s->upload_buffer_size = (unsigned int)arg; |
1231 | 0 | break; |
1232 | | |
1233 | 0 | case CURLOPT_MAXFILESIZE: |
1234 | | /* |
1235 | | * Set the maximum size of a file to download. |
1236 | | */ |
1237 | 0 | if(arg < 0) |
1238 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1239 | 0 | s->max_filesize = arg; |
1240 | 0 | break; |
1241 | | |
1242 | 0 | #ifdef USE_SSL |
1243 | 0 | case CURLOPT_USE_SSL: |
1244 | | /* |
1245 | | * Make transfers attempt to use SSL/TLS. |
1246 | | */ |
1247 | 0 | if((arg < CURLUSESSL_NONE) || (arg >= CURLUSESSL_LAST)) |
1248 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1249 | 0 | s->use_ssl = (unsigned char)arg; |
1250 | 0 | break; |
1251 | 0 | case CURLOPT_SSL_OPTIONS: |
1252 | 0 | set_ssl_options(&s->ssl, &s->ssl.primary, arg); |
1253 | 0 | break; |
1254 | | |
1255 | 0 | #ifndef CURL_DISABLE_PROXY |
1256 | 0 | case CURLOPT_PROXY_SSL_OPTIONS: |
1257 | 0 | set_ssl_options(&s->proxy_ssl, &s->proxy_ssl.primary, arg); |
1258 | 0 | break; |
1259 | 0 | #endif |
1260 | | |
1261 | 0 | #endif /* USE_SSL */ |
1262 | 0 | case CURLOPT_IPRESOLVE: |
1263 | 0 | if((arg < CURL_IPRESOLVE_WHATEVER) || (arg > CURL_IPRESOLVE_V6)) |
1264 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1265 | 0 | s->ipver = (unsigned char) arg; |
1266 | 0 | break; |
1267 | | |
1268 | 0 | case CURLOPT_CONNECT_ONLY: |
1269 | | /* |
1270 | | * No data transfer. |
1271 | | * (1) - only do connection |
1272 | | * (2) - do first get request but get no content |
1273 | | */ |
1274 | 0 | if(arg > 2) |
1275 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1276 | 0 | s->connect_only = !!arg; |
1277 | 0 | s->connect_only_ws = (arg == 2); |
1278 | 0 | break; |
1279 | | |
1280 | | |
1281 | | #ifdef USE_SSH |
1282 | | /* we only include SSH options if explicitly built to support SSH */ |
1283 | | case CURLOPT_SSH_AUTH_TYPES: |
1284 | | s->ssh_auth_types = (int)arg; |
1285 | | break; |
1286 | | #endif |
1287 | | |
1288 | 0 | #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH) |
1289 | 0 | case CURLOPT_NEW_FILE_PERMS: |
1290 | | /* |
1291 | | * Uses these permissions instead of 0644 |
1292 | | */ |
1293 | 0 | if((arg < 0) || (arg > 0777)) |
1294 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1295 | 0 | s->new_file_perms = (unsigned int)arg; |
1296 | 0 | break; |
1297 | 0 | #endif |
1298 | | #ifdef USE_SSH |
1299 | | case CURLOPT_NEW_DIRECTORY_PERMS: |
1300 | | /* |
1301 | | * Uses these permissions instead of 0755 |
1302 | | */ |
1303 | | if((arg < 0) || (arg > 0777)) |
1304 | | return CURLE_BAD_FUNCTION_ARGUMENT; |
1305 | | s->new_directory_perms = (unsigned int)arg; |
1306 | | break; |
1307 | | #endif |
1308 | 0 | #ifdef USE_IPV6 |
1309 | 0 | case CURLOPT_ADDRESS_SCOPE: |
1310 | | /* |
1311 | | * Use this scope id when using IPv6 |
1312 | | * We always get longs when passed plain numericals so we should check |
1313 | | * that the value fits into an unsigned 32-bit integer. |
1314 | | */ |
1315 | 0 | #if SIZEOF_LONG > 4 |
1316 | 0 | if(uarg > UINT_MAX) |
1317 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1318 | 0 | #endif |
1319 | 0 | s->scope_id = (unsigned int)uarg; |
1320 | 0 | break; |
1321 | 0 | #endif |
1322 | 0 | case CURLOPT_PROTOCOLS: |
1323 | | /* set the bitmask for the protocols that are allowed to be used for the |
1324 | | transfer, which thus helps the app which takes URLs from users or other |
1325 | | external inputs and want to restrict what protocol(s) to deal with. |
1326 | | Defaults to CURLPROTO_ALL. */ |
1327 | 0 | s->allowed_protocols = (curl_prot_t)arg; |
1328 | 0 | break; |
1329 | | |
1330 | 0 | case CURLOPT_REDIR_PROTOCOLS: |
1331 | | /* set the bitmask for the protocols that libcurl is allowed to follow to, |
1332 | | as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol |
1333 | | needs to be set in both bitmasks to be allowed to get redirected to. */ |
1334 | 0 | s->redir_protocols = (curl_prot_t)arg; |
1335 | 0 | break; |
1336 | | |
1337 | 0 | #ifndef CURL_DISABLE_RTSP |
1338 | 0 | case CURLOPT_RTSP_REQUEST: |
1339 | 0 | return setopt_RTSP_REQUEST(data, arg); |
1340 | 0 | case CURLOPT_RTSP_CLIENT_CSEQ: |
1341 | | /* |
1342 | | * Set the CSEQ number to issue for the next RTSP request. Useful if the |
1343 | | * application is resuming a previously broken connection. The CSEQ |
1344 | | * will increment from this new number henceforth. |
1345 | | */ |
1346 | 0 | data->state.rtsp_next_client_CSeq = arg; |
1347 | 0 | break; |
1348 | | |
1349 | 0 | case CURLOPT_RTSP_SERVER_CSEQ: |
1350 | | /* Same as the above, but for server-initiated requests */ |
1351 | 0 | data->state.rtsp_next_server_CSeq = arg; |
1352 | 0 | break; |
1353 | | |
1354 | 0 | #endif /* ! CURL_DISABLE_RTSP */ |
1355 | | |
1356 | 0 | case CURLOPT_TCP_KEEPIDLE: |
1357 | 0 | if(arg < 0) |
1358 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1359 | 0 | else if(arg > INT_MAX) |
1360 | 0 | arg = INT_MAX; |
1361 | 0 | s->tcp_keepidle = (int)arg; |
1362 | 0 | break; |
1363 | 0 | case CURLOPT_TCP_KEEPINTVL: |
1364 | 0 | if(arg < 0) |
1365 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1366 | 0 | else if(arg > INT_MAX) |
1367 | 0 | arg = INT_MAX; |
1368 | 0 | s->tcp_keepintvl = (int)arg; |
1369 | 0 | break; |
1370 | 0 | case CURLOPT_TCP_KEEPCNT: |
1371 | 0 | if(arg < 0) |
1372 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1373 | 0 | else if(arg > INT_MAX) |
1374 | 0 | arg = INT_MAX; |
1375 | 0 | s->tcp_keepcnt = (int)arg; |
1376 | 0 | break; |
1377 | 0 | case CURLOPT_SSL_ENABLE_NPN: |
1378 | 0 | break; |
1379 | 0 | case CURLOPT_STREAM_WEIGHT: |
1380 | | #if defined(USE_HTTP2) || defined(USE_HTTP3) |
1381 | | if((arg >= 1) && (arg <= 256)) |
1382 | | s->priority.weight = (int)arg; |
1383 | | break; |
1384 | | #else |
1385 | 0 | return CURLE_NOT_BUILT_IN; |
1386 | 0 | #endif |
1387 | 0 | case CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS: |
1388 | 0 | return setopt_set_timeout_ms(&s->happy_eyeballs_timeout, arg); |
1389 | | |
1390 | 0 | case CURLOPT_UPKEEP_INTERVAL_MS: |
1391 | 0 | if(arg < 0) |
1392 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1393 | 0 | s->upkeep_interval_ms = arg; |
1394 | 0 | break; |
1395 | 0 | case CURLOPT_MAXAGE_CONN: |
1396 | 0 | return setopt_set_timeout_sec(&s->conn_max_idle_ms, arg); |
1397 | | |
1398 | 0 | case CURLOPT_MAXLIFETIME_CONN: |
1399 | 0 | return setopt_set_timeout_sec(&s->conn_max_age_ms, arg); |
1400 | | |
1401 | 0 | #ifndef CURL_DISABLE_HSTS |
1402 | 0 | case CURLOPT_HSTS_CTRL: |
1403 | 0 | if(arg & CURLHSTS_ENABLE) { |
1404 | 0 | if(!data->hsts) { |
1405 | 0 | data->hsts = Curl_hsts_init(); |
1406 | 0 | if(!data->hsts) |
1407 | 0 | return CURLE_OUT_OF_MEMORY; |
1408 | 0 | } |
1409 | 0 | } |
1410 | 0 | else |
1411 | 0 | Curl_hsts_cleanup(&data->hsts); |
1412 | 0 | break; |
1413 | 0 | #endif /* ! CURL_DISABLE_HSTS */ |
1414 | 0 | #ifndef CURL_DISABLE_ALTSVC |
1415 | 0 | case CURLOPT_ALTSVC_CTRL: |
1416 | 0 | if(!arg) { |
1417 | 0 | DEBUGF(infof(data, "bad CURLOPT_ALTSVC_CTRL input")); |
1418 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1419 | 0 | } |
1420 | 0 | if(!data->asi) { |
1421 | 0 | data->asi = Curl_altsvc_init(); |
1422 | 0 | if(!data->asi) |
1423 | 0 | return CURLE_OUT_OF_MEMORY; |
1424 | 0 | } |
1425 | 0 | return Curl_altsvc_ctrl(data->asi, arg); |
1426 | 0 | #endif /* ! CURL_DISABLE_ALTSVC */ |
1427 | 0 | #ifndef CURL_DISABLE_WEBSOCKETS |
1428 | 0 | case CURLOPT_WS_OPTIONS: |
1429 | 0 | s->ws_raw_mode = (bool)(arg & CURLWS_RAW_MODE); |
1430 | 0 | s->ws_no_auto_pong = (bool)(arg & CURLWS_NOAUTOPONG); |
1431 | 0 | break; |
1432 | 0 | #endif |
1433 | 0 | case CURLOPT_DNS_USE_GLOBAL_CACHE: |
1434 | | /* deprecated */ |
1435 | 0 | break; |
1436 | 0 | case CURLOPT_SSLENGINE_DEFAULT: |
1437 | | /* |
1438 | | * flag to set engine as default. |
1439 | | */ |
1440 | 0 | Curl_safefree(s->str[STRING_SSL_ENGINE]); |
1441 | 0 | return Curl_ssl_set_engine_default(data); |
1442 | 0 | case CURLOPT_UPLOAD_FLAGS: |
1443 | 0 | s->upload_flags = (unsigned char)arg; |
1444 | 0 | break; |
1445 | 0 | default: |
1446 | | /* unknown option */ |
1447 | 0 | return CURLE_UNKNOWN_OPTION; |
1448 | 0 | } |
1449 | 0 | return CURLE_OK; |
1450 | 0 | } |
1451 | | |
1452 | | static CURLcode setopt_slist(struct Curl_easy *data, CURLoption option, |
1453 | | struct curl_slist *slist) |
1454 | 0 | { |
1455 | 0 | CURLcode result = CURLE_OK; |
1456 | 0 | struct UserDefined *s = &data->set; |
1457 | 0 | switch(option) { |
1458 | 0 | #ifndef CURL_DISABLE_PROXY |
1459 | 0 | case CURLOPT_PROXYHEADER: |
1460 | | /* |
1461 | | * Set a list with proxy headers to use (or replace internals with) |
1462 | | * |
1463 | | * Since CURLOPT_HTTPHEADER was the only way to set HTTP headers for a |
1464 | | * long time we remain doing it this way until CURLOPT_PROXYHEADER is |
1465 | | * used. As soon as this option has been used, if set to anything but |
1466 | | * NULL, custom headers for proxies are only picked from this list. |
1467 | | * |
1468 | | * Set this option to NULL to restore the previous behavior. |
1469 | | */ |
1470 | 0 | s->proxyheaders = slist; |
1471 | 0 | break; |
1472 | 0 | #endif |
1473 | 0 | #ifndef CURL_DISABLE_HTTP |
1474 | 0 | case CURLOPT_HTTP200ALIASES: |
1475 | | /* |
1476 | | * Set a list of aliases for HTTP 200 in response header |
1477 | | */ |
1478 | 0 | s->http200aliases = slist; |
1479 | 0 | break; |
1480 | 0 | #endif |
1481 | 0 | #if !defined(CURL_DISABLE_FTP) || defined(USE_SSH) |
1482 | 0 | case CURLOPT_POSTQUOTE: |
1483 | | /* |
1484 | | * List of RAW FTP commands to use after a transfer |
1485 | | */ |
1486 | 0 | s->postquote = slist; |
1487 | 0 | break; |
1488 | 0 | case CURLOPT_PREQUOTE: |
1489 | | /* |
1490 | | * List of RAW FTP commands to use prior to RETR (Wesley Laxton) |
1491 | | */ |
1492 | 0 | s->prequote = slist; |
1493 | 0 | break; |
1494 | 0 | case CURLOPT_QUOTE: |
1495 | | /* |
1496 | | * List of RAW FTP commands to use before a transfer |
1497 | | */ |
1498 | 0 | s->quote = slist; |
1499 | 0 | break; |
1500 | 0 | #endif |
1501 | 0 | case CURLOPT_RESOLVE: |
1502 | | /* |
1503 | | * List of HOST:PORT:[addresses] strings to populate the DNS cache with |
1504 | | * Entries added this way will remain in the cache until explicitly |
1505 | | * removed or the handle is cleaned up. |
1506 | | * |
1507 | | * Prefix the HOST with plus sign (+) to have the entry expire just like |
1508 | | * automatically added entries. |
1509 | | * |
1510 | | * Prefix the HOST with dash (-) to _remove_ the entry from the cache. |
1511 | | * |
1512 | | * This API can remove any entry from the DNS cache, but only entries |
1513 | | * that are not actually in use right now will be pruned immediately. |
1514 | | */ |
1515 | 0 | s->resolve = slist; |
1516 | 0 | data->state.resolve = s->resolve; |
1517 | 0 | break; |
1518 | 0 | #if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_MIME) |
1519 | 0 | case CURLOPT_HTTPHEADER: |
1520 | | /* |
1521 | | * Set a list with HTTP headers to use (or replace internals with) |
1522 | | */ |
1523 | 0 | s->headers = slist; |
1524 | 0 | break; |
1525 | 0 | #endif |
1526 | 0 | #ifndef CURL_DISABLE_TELNET |
1527 | 0 | case CURLOPT_TELNETOPTIONS: |
1528 | | /* |
1529 | | * Set a linked list of telnet options |
1530 | | */ |
1531 | 0 | s->telnet_options = slist; |
1532 | 0 | break; |
1533 | 0 | #endif |
1534 | 0 | #ifndef CURL_DISABLE_SMTP |
1535 | 0 | case CURLOPT_MAIL_RCPT: |
1536 | | /* Set the list of mail recipients */ |
1537 | 0 | s->mail_rcpt = slist; |
1538 | 0 | break; |
1539 | 0 | #endif |
1540 | 0 | case CURLOPT_CONNECT_TO: |
1541 | 0 | s->connect_to = slist; |
1542 | 0 | break; |
1543 | 0 | default: |
1544 | 0 | return CURLE_UNKNOWN_OPTION; |
1545 | 0 | } |
1546 | 0 | return result; |
1547 | 0 | } |
1548 | | |
1549 | | /* assorted pointer type arguments */ |
1550 | | static CURLcode setopt_pointers(struct Curl_easy *data, CURLoption option, |
1551 | | va_list param) |
1552 | 0 | { |
1553 | 0 | CURLcode result = CURLE_OK; |
1554 | 0 | struct UserDefined *s = &data->set; |
1555 | 0 | switch(option) { |
1556 | 0 | #ifndef CURL_DISABLE_HTTP |
1557 | 0 | #ifndef CURL_DISABLE_FORM_API |
1558 | 0 | case CURLOPT_HTTPPOST: |
1559 | | /* |
1560 | | * Set to make us do HTTP POST. Legacy API-style. |
1561 | | */ |
1562 | 0 | s->httppost = va_arg(param, struct curl_httppost *); |
1563 | 0 | s->method = HTTPREQ_POST_FORM; |
1564 | 0 | s->opt_no_body = FALSE; /* this is implied */ |
1565 | 0 | Curl_mime_cleanpart(data->state.formp); |
1566 | 0 | Curl_safefree(data->state.formp); |
1567 | 0 | data->state.mimepost = NULL; |
1568 | 0 | break; |
1569 | 0 | #endif /* ! CURL_DISABLE_FORM_API */ |
1570 | 0 | #endif /* ! CURL_DISABLE_HTTP */ |
1571 | 0 | #if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \ |
1572 | 0 | !defined(CURL_DISABLE_IMAP) |
1573 | 0 | # ifndef CURL_DISABLE_MIME |
1574 | 0 | case CURLOPT_MIMEPOST: |
1575 | | /* |
1576 | | * Set to make us do MIME POST |
1577 | | */ |
1578 | 0 | result = Curl_mime_set_subparts(&s->mimepost, |
1579 | 0 | va_arg(param, curl_mime *), |
1580 | 0 | FALSE); |
1581 | 0 | if(!result) { |
1582 | 0 | s->method = HTTPREQ_POST_MIME; |
1583 | 0 | s->opt_no_body = FALSE; /* this is implied */ |
1584 | 0 | #ifndef CURL_DISABLE_FORM_API |
1585 | 0 | Curl_mime_cleanpart(data->state.formp); |
1586 | 0 | Curl_safefree(data->state.formp); |
1587 | 0 | data->state.mimepost = NULL; |
1588 | 0 | #endif |
1589 | 0 | } |
1590 | 0 | break; |
1591 | 0 | #endif /* ! CURL_DISABLE_MIME */ |
1592 | 0 | #endif /* ! disabled HTTP, SMTP or IMAP */ |
1593 | 0 | case CURLOPT_STDERR: |
1594 | | /* |
1595 | | * Set to a FILE * that should receive all error writes. This |
1596 | | * defaults to stderr for normal operations. |
1597 | | */ |
1598 | 0 | s->err = va_arg(param, FILE *); |
1599 | 0 | if(!s->err) |
1600 | 0 | s->err = stderr; |
1601 | 0 | break; |
1602 | 0 | case CURLOPT_SHARE: |
1603 | 0 | { |
1604 | 0 | struct Curl_share *set = va_arg(param, struct Curl_share *); |
1605 | | |
1606 | | /* disconnect from old share, if any */ |
1607 | 0 | if(data->share) { |
1608 | 0 | Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE); |
1609 | |
|
1610 | 0 | #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) |
1611 | 0 | if(data->share->cookies == data->cookies) |
1612 | 0 | data->cookies = NULL; |
1613 | 0 | #endif |
1614 | |
|
1615 | 0 | #ifndef CURL_DISABLE_HSTS |
1616 | 0 | if(data->share->hsts == data->hsts) |
1617 | 0 | data->hsts = NULL; |
1618 | 0 | #endif |
1619 | | #ifdef USE_LIBPSL |
1620 | | if(data->psl == &data->share->psl) |
1621 | | data->psl = data->multi ? &data->multi->psl : NULL; |
1622 | | #endif |
1623 | 0 | if(data->share->specifier & (1 << CURL_LOCK_DATA_DNS)) { |
1624 | 0 | Curl_resolv_unlink(data, &data->state.dns[0]); |
1625 | 0 | Curl_resolv_unlink(data, &data->state.dns[1]); |
1626 | 0 | } |
1627 | |
|
1628 | 0 | data->share->dirty--; |
1629 | |
|
1630 | 0 | Curl_share_unlock(data, CURL_LOCK_DATA_SHARE); |
1631 | 0 | data->share = NULL; |
1632 | 0 | } |
1633 | |
|
1634 | 0 | if(GOOD_SHARE_HANDLE(set)) |
1635 | | /* use new share if it set */ |
1636 | 0 | data->share = set; |
1637 | 0 | if(data->share) { |
1638 | |
|
1639 | 0 | Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE); |
1640 | |
|
1641 | 0 | data->share->dirty++; |
1642 | |
|
1643 | 0 | #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) |
1644 | 0 | if(data->share->cookies) { |
1645 | | /* use shared cookie list, first free own one if any */ |
1646 | 0 | Curl_cookie_cleanup(data->cookies); |
1647 | | /* enable cookies since we now use a share that uses cookies! */ |
1648 | 0 | data->cookies = data->share->cookies; |
1649 | 0 | } |
1650 | 0 | #endif /* CURL_DISABLE_HTTP */ |
1651 | 0 | #ifndef CURL_DISABLE_HSTS |
1652 | 0 | if(data->share->hsts) { |
1653 | | /* first free the private one if any */ |
1654 | 0 | Curl_hsts_cleanup(&data->hsts); |
1655 | 0 | data->hsts = data->share->hsts; |
1656 | 0 | } |
1657 | 0 | #endif |
1658 | | #ifdef USE_LIBPSL |
1659 | | if(data->share->specifier & (1 << CURL_LOCK_DATA_PSL)) |
1660 | | data->psl = &data->share->psl; |
1661 | | #endif |
1662 | |
|
1663 | 0 | Curl_share_unlock(data, CURL_LOCK_DATA_SHARE); |
1664 | 0 | } |
1665 | | /* check for host cache not needed, |
1666 | | * it will be done by curl_easy_perform */ |
1667 | 0 | } |
1668 | 0 | break; |
1669 | | |
1670 | | #ifdef USE_HTTP2 |
1671 | | case CURLOPT_STREAM_DEPENDS: |
1672 | | case CURLOPT_STREAM_DEPENDS_E: { |
1673 | | struct Curl_easy *dep = va_arg(param, struct Curl_easy *); |
1674 | | if(!dep || GOOD_EASY_HANDLE(dep)) |
1675 | | return Curl_data_priority_add_child(dep, data, |
1676 | | option == CURLOPT_STREAM_DEPENDS_E); |
1677 | | break; |
1678 | | } |
1679 | | #endif |
1680 | | |
1681 | 0 | default: |
1682 | 0 | return CURLE_UNKNOWN_OPTION; |
1683 | 0 | } |
1684 | 0 | return result; |
1685 | 0 | } |
1686 | | |
1687 | | static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option, |
1688 | | char *ptr) |
1689 | 0 | { |
1690 | 0 | CURLcode result = CURLE_OK; |
1691 | 0 | struct UserDefined *s = &data->set; |
1692 | 0 | switch(option) { |
1693 | 0 | case CURLOPT_SSL_CIPHER_LIST: |
1694 | 0 | if(Curl_ssl_supports(data, SSLSUPP_CIPHER_LIST)) |
1695 | | /* set a list of cipher we want to use in the SSL connection */ |
1696 | 0 | return Curl_setstropt(&s->str[STRING_SSL_CIPHER_LIST], ptr); |
1697 | 0 | else |
1698 | 0 | return CURLE_NOT_BUILT_IN; |
1699 | 0 | #ifndef CURL_DISABLE_PROXY |
1700 | 0 | case CURLOPT_PROXY_SSL_CIPHER_LIST: |
1701 | 0 | if(Curl_ssl_supports(data, SSLSUPP_CIPHER_LIST)) { |
1702 | | /* set a list of cipher we want to use in the SSL connection for proxy */ |
1703 | 0 | return Curl_setstropt(&s->str[STRING_SSL_CIPHER_LIST_PROXY], |
1704 | 0 | ptr); |
1705 | 0 | } |
1706 | 0 | else |
1707 | 0 | return CURLE_NOT_BUILT_IN; |
1708 | 0 | #endif |
1709 | 0 | case CURLOPT_TLS13_CIPHERS: |
1710 | 0 | if(Curl_ssl_supports(data, SSLSUPP_TLS13_CIPHERSUITES)) { |
1711 | | /* set preferred list of TLS 1.3 cipher suites */ |
1712 | 0 | return Curl_setstropt(&s->str[STRING_SSL_CIPHER13_LIST], ptr); |
1713 | 0 | } |
1714 | 0 | else |
1715 | 0 | return CURLE_NOT_BUILT_IN; |
1716 | 0 | #ifndef CURL_DISABLE_PROXY |
1717 | 0 | case CURLOPT_PROXY_TLS13_CIPHERS: |
1718 | 0 | if(Curl_ssl_supports(data, SSLSUPP_TLS13_CIPHERSUITES)) |
1719 | | /* set preferred list of TLS 1.3 cipher suites for proxy */ |
1720 | 0 | return Curl_setstropt(&s->str[STRING_SSL_CIPHER13_LIST_PROXY], |
1721 | 0 | ptr); |
1722 | 0 | else |
1723 | 0 | return CURLE_NOT_BUILT_IN; |
1724 | 0 | #endif |
1725 | 0 | case CURLOPT_RANDOM_FILE: |
1726 | 0 | break; |
1727 | 0 | case CURLOPT_EGDSOCKET: |
1728 | 0 | break; |
1729 | 0 | case CURLOPT_REQUEST_TARGET: |
1730 | 0 | return Curl_setstropt(&s->str[STRING_TARGET], ptr); |
1731 | 0 | #ifndef CURL_DISABLE_NETRC |
1732 | 0 | case CURLOPT_NETRC_FILE: |
1733 | | /* |
1734 | | * Use this file instead of the $HOME/.netrc file |
1735 | | */ |
1736 | 0 | return Curl_setstropt(&s->str[STRING_NETRC_FILE], ptr); |
1737 | 0 | #endif |
1738 | | |
1739 | 0 | #if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_MQTT) |
1740 | 0 | case CURLOPT_COPYPOSTFIELDS: |
1741 | | /* |
1742 | | * A string with POST data. Makes curl HTTP POST. Even if it is NULL. |
1743 | | * If needed, CURLOPT_POSTFIELDSIZE must have been set prior to |
1744 | | * CURLOPT_COPYPOSTFIELDS and not altered later. |
1745 | | */ |
1746 | 0 | if(!ptr || s->postfieldsize == -1) |
1747 | 0 | result = Curl_setstropt(&s->str[STRING_COPYPOSTFIELDS], ptr); |
1748 | 0 | else { |
1749 | 0 | if(s->postfieldsize < 0) |
1750 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1751 | | #if SIZEOF_CURL_OFF_T > SIZEOF_SIZE_T |
1752 | | /* |
1753 | | * Check that requested length does not overflow the size_t type. |
1754 | | */ |
1755 | | else if(s->postfieldsize > SIZE_T_MAX) |
1756 | | return CURLE_OUT_OF_MEMORY; |
1757 | | #endif |
1758 | 0 | else { |
1759 | | /* Allocate even when size == 0. This satisfies the need of possible |
1760 | | later address compare to detect the COPYPOSTFIELDS mode, and to |
1761 | | mark that postfields is used rather than read function or form |
1762 | | data. |
1763 | | */ |
1764 | 0 | char *p = Curl_memdup0(ptr, (size_t)s->postfieldsize); |
1765 | 0 | if(!p) |
1766 | 0 | return CURLE_OUT_OF_MEMORY; |
1767 | 0 | else { |
1768 | 0 | free(s->str[STRING_COPYPOSTFIELDS]); |
1769 | 0 | s->str[STRING_COPYPOSTFIELDS] = p; |
1770 | 0 | } |
1771 | 0 | } |
1772 | 0 | } |
1773 | | |
1774 | 0 | s->postfields = s->str[STRING_COPYPOSTFIELDS]; |
1775 | 0 | s->method = HTTPREQ_POST; |
1776 | 0 | break; |
1777 | | |
1778 | 0 | case CURLOPT_POSTFIELDS: |
1779 | | /* |
1780 | | * Like above, but use static data instead of copying it. |
1781 | | */ |
1782 | 0 | s->postfields = ptr; |
1783 | | /* Release old copied data. */ |
1784 | 0 | Curl_safefree(s->str[STRING_COPYPOSTFIELDS]); |
1785 | 0 | s->method = HTTPREQ_POST; |
1786 | 0 | break; |
1787 | 0 | #endif /* ! CURL_DISABLE_HTTP || ! CURL_DISABLE_MQTT */ |
1788 | | |
1789 | 0 | #ifndef CURL_DISABLE_HTTP |
1790 | 0 | case CURLOPT_ACCEPT_ENCODING: |
1791 | | /* |
1792 | | * String to use at the value of Accept-Encoding header. |
1793 | | * |
1794 | | * If the encoding is set to "" we use an Accept-Encoding header that |
1795 | | * encompasses all the encodings we support. |
1796 | | * If the encoding is set to NULL we do not send an Accept-Encoding header |
1797 | | * and ignore an received Content-Encoding header. |
1798 | | * |
1799 | | */ |
1800 | 0 | if(ptr && !*ptr) { |
1801 | 0 | char all[256]; |
1802 | 0 | Curl_all_content_encodings(all, sizeof(all)); |
1803 | 0 | return Curl_setstropt(&s->str[STRING_ENCODING], all); |
1804 | 0 | } |
1805 | 0 | return Curl_setstropt(&s->str[STRING_ENCODING], ptr); |
1806 | | |
1807 | 0 | #ifndef CURL_DISABLE_AWS |
1808 | 0 | case CURLOPT_AWS_SIGV4: |
1809 | | /* |
1810 | | * String that is merged to some authentication |
1811 | | * parameters are used by the algorithm. |
1812 | | */ |
1813 | 0 | result = Curl_setstropt(&s->str[STRING_AWS_SIGV4], ptr); |
1814 | | /* |
1815 | | * Basic been set by default it need to be unset here |
1816 | | */ |
1817 | 0 | if(s->str[STRING_AWS_SIGV4]) |
1818 | 0 | s->httpauth = CURLAUTH_AWS_SIGV4; |
1819 | 0 | break; |
1820 | 0 | #endif |
1821 | 0 | case CURLOPT_REFERER: |
1822 | | /* |
1823 | | * String to set in the HTTP Referer: field. |
1824 | | */ |
1825 | 0 | if(data->state.referer_alloc) { |
1826 | 0 | Curl_safefree(data->state.referer); |
1827 | 0 | data->state.referer_alloc = FALSE; |
1828 | 0 | } |
1829 | 0 | result = Curl_setstropt(&s->str[STRING_SET_REFERER], ptr); |
1830 | 0 | data->state.referer = s->str[STRING_SET_REFERER]; |
1831 | 0 | break; |
1832 | | |
1833 | 0 | case CURLOPT_USERAGENT: |
1834 | | /* |
1835 | | * String to use in the HTTP User-Agent field |
1836 | | */ |
1837 | 0 | return Curl_setstropt(&s->str[STRING_USERAGENT], ptr); |
1838 | | |
1839 | 0 | #ifndef CURL_DISABLE_COOKIES |
1840 | 0 | case CURLOPT_COOKIE: |
1841 | | /* |
1842 | | * Cookie string to send to the remote server in the request. |
1843 | | */ |
1844 | 0 | return Curl_setstropt(&s->str[STRING_COOKIE], ptr); |
1845 | | |
1846 | 0 | case CURLOPT_COOKIEFILE: |
1847 | | /* |
1848 | | * Set cookie file to read and parse. Can be used multiple times. |
1849 | | */ |
1850 | 0 | if(ptr) { |
1851 | 0 | struct curl_slist *cl; |
1852 | | /* general protection against mistakes and abuse */ |
1853 | 0 | if(strlen(ptr) > CURL_MAX_INPUT_LENGTH) |
1854 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1855 | | /* append the cookie filename to the list of filenames, and deal with |
1856 | | them later */ |
1857 | 0 | cl = curl_slist_append(data->state.cookielist, ptr); |
1858 | 0 | if(!cl) { |
1859 | 0 | curl_slist_free_all(data->state.cookielist); |
1860 | 0 | data->state.cookielist = NULL; |
1861 | 0 | return CURLE_OUT_OF_MEMORY; |
1862 | 0 | } |
1863 | 0 | data->state.cookielist = cl; /* store the list for later use */ |
1864 | 0 | } |
1865 | 0 | else { |
1866 | | /* clear the list of cookie files */ |
1867 | 0 | curl_slist_free_all(data->state.cookielist); |
1868 | 0 | data->state.cookielist = NULL; |
1869 | |
|
1870 | 0 | if(!data->share || !data->share->cookies) { |
1871 | | /* throw away all existing cookies if this is not a shared cookie |
1872 | | container */ |
1873 | 0 | Curl_cookie_clearall(data->cookies); |
1874 | 0 | Curl_cookie_cleanup(data->cookies); |
1875 | 0 | } |
1876 | | /* disable the cookie engine */ |
1877 | 0 | data->cookies = NULL; |
1878 | 0 | } |
1879 | 0 | break; |
1880 | | |
1881 | 0 | case CURLOPT_COOKIEJAR: |
1882 | | /* |
1883 | | * Set cookie filename to dump all cookies to when we are done. |
1884 | | */ |
1885 | 0 | result = Curl_setstropt(&s->str[STRING_COOKIEJAR], ptr); |
1886 | 0 | if(!result) { |
1887 | | /* |
1888 | | * Activate the cookie parser. This may or may not already |
1889 | | * have been made. |
1890 | | */ |
1891 | 0 | struct CookieInfo *newcookies = |
1892 | 0 | Curl_cookie_init(data, NULL, data->cookies, s->cookiesession); |
1893 | 0 | if(!newcookies) |
1894 | 0 | result = CURLE_OUT_OF_MEMORY; |
1895 | 0 | data->cookies = newcookies; |
1896 | 0 | } |
1897 | 0 | break; |
1898 | | |
1899 | 0 | case CURLOPT_COOKIELIST: |
1900 | 0 | if(!ptr) |
1901 | 0 | break; |
1902 | | |
1903 | 0 | if(curl_strequal(ptr, "ALL")) { |
1904 | | /* clear all cookies */ |
1905 | 0 | Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); |
1906 | 0 | Curl_cookie_clearall(data->cookies); |
1907 | 0 | Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); |
1908 | 0 | } |
1909 | 0 | else if(curl_strequal(ptr, "SESS")) { |
1910 | | /* clear session cookies */ |
1911 | 0 | Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); |
1912 | 0 | Curl_cookie_clearsess(data->cookies); |
1913 | 0 | Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); |
1914 | 0 | } |
1915 | 0 | else if(curl_strequal(ptr, "FLUSH")) { |
1916 | | /* flush cookies to file, takes care of the locking */ |
1917 | 0 | Curl_flush_cookies(data, FALSE); |
1918 | 0 | } |
1919 | 0 | else if(curl_strequal(ptr, "RELOAD")) { |
1920 | | /* reload cookies from file */ |
1921 | 0 | Curl_cookie_loadfiles(data); |
1922 | 0 | break; |
1923 | 0 | } |
1924 | 0 | else { |
1925 | 0 | if(!data->cookies) { |
1926 | | /* if cookie engine was not running, activate it */ |
1927 | 0 | data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE); |
1928 | 0 | if(!data->cookies) |
1929 | 0 | return CURLE_OUT_OF_MEMORY; |
1930 | 0 | } |
1931 | | |
1932 | | /* general protection against mistakes and abuse */ |
1933 | 0 | if(strlen(ptr) > CURL_MAX_INPUT_LENGTH) |
1934 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
1935 | | |
1936 | 0 | Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE); |
1937 | 0 | if(checkprefix("Set-Cookie:", ptr)) |
1938 | | /* HTTP Header format line */ |
1939 | 0 | Curl_cookie_add(data, data->cookies, TRUE, FALSE, ptr + 11, NULL, |
1940 | 0 | NULL, TRUE); |
1941 | 0 | else |
1942 | | /* Netscape format line */ |
1943 | 0 | Curl_cookie_add(data, data->cookies, FALSE, FALSE, ptr, NULL, |
1944 | 0 | NULL, TRUE); |
1945 | 0 | Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); |
1946 | 0 | } |
1947 | 0 | break; |
1948 | 0 | #endif /* !CURL_DISABLE_COOKIES */ |
1949 | | |
1950 | 0 | #endif /* ! CURL_DISABLE_HTTP */ |
1951 | | |
1952 | 0 | case CURLOPT_CUSTOMREQUEST: |
1953 | | /* |
1954 | | * Set a custom string to use as request |
1955 | | */ |
1956 | 0 | return Curl_setstropt(&s->str[STRING_CUSTOMREQUEST], ptr); |
1957 | | |
1958 | | /* we do not set |
1959 | | s->method = HTTPREQ_CUSTOM; |
1960 | | here, we continue as if we were using the already set type |
1961 | | and this just changes the actual request keyword */ |
1962 | | |
1963 | 0 | #ifndef CURL_DISABLE_PROXY |
1964 | 0 | case CURLOPT_PROXY: |
1965 | | /* |
1966 | | * Set proxy server:port to use as proxy. |
1967 | | * |
1968 | | * If the proxy is set to "" (and CURLOPT_SOCKS_PROXY is set to "" or NULL) |
1969 | | * we explicitly say that we do not want to use a proxy |
1970 | | * (even though there might be environment variables saying so). |
1971 | | * |
1972 | | * Setting it to NULL, means no proxy but allows the environment variables |
1973 | | * to decide for us (if CURLOPT_SOCKS_PROXY setting it to NULL). |
1974 | | */ |
1975 | 0 | return Curl_setstropt(&s->str[STRING_PROXY], ptr); |
1976 | | |
1977 | 0 | case CURLOPT_PRE_PROXY: |
1978 | | /* |
1979 | | * Set proxy server:port to use as SOCKS proxy. |
1980 | | * |
1981 | | * If the proxy is set to "" or NULL we explicitly say that we do not want |
1982 | | * to use the socks proxy. |
1983 | | */ |
1984 | 0 | return Curl_setstropt(&s->str[STRING_PRE_PROXY], ptr); |
1985 | 0 | #endif /* CURL_DISABLE_PROXY */ |
1986 | | |
1987 | 0 | #ifndef CURL_DISABLE_PROXY |
1988 | 0 | case CURLOPT_SOCKS5_GSSAPI_SERVICE: |
1989 | 0 | case CURLOPT_PROXY_SERVICE_NAME: |
1990 | | /* |
1991 | | * Set proxy authentication service name for Kerberos 5 and SPNEGO |
1992 | | */ |
1993 | 0 | return Curl_setstropt(&s->str[STRING_PROXY_SERVICE_NAME], ptr); |
1994 | 0 | #endif |
1995 | 0 | case CURLOPT_SERVICE_NAME: |
1996 | | /* |
1997 | | * Set authentication service name for DIGEST-MD5, Kerberos 5 and SPNEGO |
1998 | | */ |
1999 | 0 | return Curl_setstropt(&s->str[STRING_SERVICE_NAME], ptr); |
2000 | | |
2001 | 0 | case CURLOPT_HEADERDATA: |
2002 | | /* |
2003 | | * Custom pointer to pass the header write callback function |
2004 | | */ |
2005 | 0 | s->writeheader = ptr; |
2006 | 0 | break; |
2007 | 0 | case CURLOPT_READDATA: |
2008 | | /* |
2009 | | * FILE pointer to read the file to be uploaded from. Or possibly used as |
2010 | | * argument to the read callback. |
2011 | | */ |
2012 | 0 | s->in_set = ptr; |
2013 | 0 | break; |
2014 | 0 | case CURLOPT_WRITEDATA: |
2015 | | /* |
2016 | | * FILE pointer to write to. Or possibly used as argument to the write |
2017 | | * callback. |
2018 | | */ |
2019 | 0 | s->out = ptr; |
2020 | 0 | break; |
2021 | 0 | case CURLOPT_DEBUGDATA: |
2022 | | /* |
2023 | | * Set to a void * that should receive all error writes. This |
2024 | | * defaults to CURLOPT_STDERR for normal operations. |
2025 | | */ |
2026 | 0 | s->debugdata = ptr; |
2027 | 0 | break; |
2028 | 0 | case CURLOPT_PROGRESSDATA: |
2029 | | /* |
2030 | | * Custom client data to pass to the progress callback |
2031 | | */ |
2032 | 0 | s->progress_client = ptr; |
2033 | 0 | break; |
2034 | 0 | case CURLOPT_SEEKDATA: |
2035 | | /* |
2036 | | * Seek control callback. Might be NULL. |
2037 | | */ |
2038 | 0 | s->seek_client = ptr; |
2039 | 0 | break; |
2040 | 0 | case CURLOPT_IOCTLDATA: |
2041 | | /* |
2042 | | * I/O control data pointer. Might be NULL. |
2043 | | */ |
2044 | 0 | s->ioctl_client = ptr; |
2045 | 0 | break; |
2046 | 0 | case CURLOPT_SSL_CTX_DATA: |
2047 | | /* |
2048 | | * Set an SSL_CTX callback parameter pointer |
2049 | | */ |
2050 | 0 | #ifdef USE_SSL |
2051 | 0 | if(Curl_ssl_supports(data, SSLSUPP_SSL_CTX)) { |
2052 | 0 | s->ssl.fsslctxp = ptr; |
2053 | 0 | break; |
2054 | 0 | } |
2055 | 0 | else |
2056 | 0 | #endif |
2057 | 0 | return CURLE_NOT_BUILT_IN; |
2058 | 0 | case CURLOPT_SOCKOPTDATA: |
2059 | | /* |
2060 | | * socket callback data pointer. Might be NULL. |
2061 | | */ |
2062 | 0 | s->sockopt_client = ptr; |
2063 | 0 | break; |
2064 | 0 | case CURLOPT_OPENSOCKETDATA: |
2065 | | /* |
2066 | | * socket callback data pointer. Might be NULL. |
2067 | | */ |
2068 | 0 | s->opensocket_client = ptr; |
2069 | 0 | break; |
2070 | 0 | case CURLOPT_RESOLVER_START_DATA: |
2071 | | /* |
2072 | | * resolver start callback data pointer. Might be NULL. |
2073 | | */ |
2074 | 0 | s->resolver_start_client = ptr; |
2075 | 0 | break; |
2076 | 0 | case CURLOPT_CLOSESOCKETDATA: |
2077 | | /* |
2078 | | * socket callback data pointer. Might be NULL. |
2079 | | */ |
2080 | 0 | s->closesocket_client = ptr; |
2081 | 0 | break; |
2082 | 0 | case CURLOPT_TRAILERDATA: |
2083 | 0 | #ifndef CURL_DISABLE_HTTP |
2084 | 0 | s->trailer_data = ptr; |
2085 | 0 | #endif |
2086 | 0 | break; |
2087 | 0 | case CURLOPT_PREREQDATA: |
2088 | 0 | s->prereq_userp = ptr; |
2089 | 0 | break; |
2090 | | |
2091 | 0 | case CURLOPT_ERRORBUFFER: |
2092 | | /* |
2093 | | * Error buffer provided by the caller to get the human readable error |
2094 | | * string in. |
2095 | | */ |
2096 | 0 | s->errorbuffer = ptr; |
2097 | 0 | break; |
2098 | | |
2099 | 0 | #ifndef CURL_DISABLE_FTP |
2100 | 0 | case CURLOPT_FTPPORT: |
2101 | | /* |
2102 | | * Use FTP PORT, this also specifies which IP address to use |
2103 | | */ |
2104 | 0 | result = Curl_setstropt(&s->str[STRING_FTPPORT], ptr); |
2105 | 0 | s->ftp_use_port = !!(s->str[STRING_FTPPORT]); |
2106 | 0 | break; |
2107 | | |
2108 | 0 | case CURLOPT_FTP_ACCOUNT: |
2109 | 0 | return Curl_setstropt(&s->str[STRING_FTP_ACCOUNT], ptr); |
2110 | | |
2111 | 0 | case CURLOPT_FTP_ALTERNATIVE_TO_USER: |
2112 | 0 | return Curl_setstropt(&s->str[STRING_FTP_ALTERNATIVE_TO_USER], ptr); |
2113 | | |
2114 | | #ifdef HAVE_GSSAPI |
2115 | | case CURLOPT_KRBLEVEL: |
2116 | | /* |
2117 | | * A string that defines the kerberos security level. |
2118 | | */ |
2119 | | result = Curl_setstropt(&s->str[STRING_KRB_LEVEL], ptr); |
2120 | | s->krb = !!(s->str[STRING_KRB_LEVEL]); |
2121 | | break; |
2122 | | #endif |
2123 | 0 | #endif |
2124 | 0 | case CURLOPT_URL: |
2125 | | /* |
2126 | | * The URL to fetch. |
2127 | | */ |
2128 | 0 | if(data->state.url_alloc) { |
2129 | 0 | Curl_safefree(data->state.url); |
2130 | 0 | data->state.url_alloc = FALSE; |
2131 | 0 | } |
2132 | 0 | result = Curl_setstropt(&s->str[STRING_SET_URL], ptr); |
2133 | 0 | data->state.url = s->str[STRING_SET_URL]; |
2134 | 0 | break; |
2135 | | |
2136 | 0 | case CURLOPT_USERPWD: |
2137 | | /* |
2138 | | * user:password to use in the operation |
2139 | | */ |
2140 | 0 | return setstropt_userpwd(ptr, &s->str[STRING_USERNAME], |
2141 | 0 | &s->str[STRING_PASSWORD]); |
2142 | | |
2143 | 0 | case CURLOPT_USERNAME: |
2144 | | /* |
2145 | | * authentication username to use in the operation |
2146 | | */ |
2147 | 0 | return Curl_setstropt(&s->str[STRING_USERNAME], ptr); |
2148 | | |
2149 | 0 | case CURLOPT_PASSWORD: |
2150 | | /* |
2151 | | * authentication password to use in the operation |
2152 | | */ |
2153 | 0 | return Curl_setstropt(&s->str[STRING_PASSWORD], ptr); |
2154 | | |
2155 | 0 | case CURLOPT_LOGIN_OPTIONS: |
2156 | | /* |
2157 | | * authentication options to use in the operation |
2158 | | */ |
2159 | 0 | return Curl_setstropt(&s->str[STRING_OPTIONS], ptr); |
2160 | | |
2161 | 0 | case CURLOPT_XOAUTH2_BEARER: |
2162 | | /* |
2163 | | * OAuth 2.0 bearer token to use in the operation |
2164 | | */ |
2165 | 0 | return Curl_setstropt(&s->str[STRING_BEARER], ptr); |
2166 | | |
2167 | 0 | #ifndef CURL_DISABLE_PROXY |
2168 | 0 | case CURLOPT_PROXYUSERPWD: { |
2169 | | /* |
2170 | | * user:password needed to use the proxy |
2171 | | */ |
2172 | 0 | char *u = NULL; |
2173 | 0 | char *p = NULL; |
2174 | 0 | result = setstropt_userpwd(ptr, &u, &p); |
2175 | | |
2176 | | /* URL decode the components */ |
2177 | 0 | if(!result && u) { |
2178 | 0 | Curl_safefree(s->str[STRING_PROXYUSERNAME]); |
2179 | 0 | result = Curl_urldecode(u, 0, &s->str[STRING_PROXYUSERNAME], NULL, |
2180 | 0 | REJECT_ZERO); |
2181 | 0 | } |
2182 | 0 | if(!result && p) { |
2183 | 0 | Curl_safefree(s->str[STRING_PROXYPASSWORD]); |
2184 | 0 | result = Curl_urldecode(p, 0, &s->str[STRING_PROXYPASSWORD], NULL, |
2185 | 0 | REJECT_ZERO); |
2186 | 0 | } |
2187 | 0 | free(u); |
2188 | 0 | free(p); |
2189 | 0 | } |
2190 | 0 | break; |
2191 | 0 | case CURLOPT_PROXYUSERNAME: |
2192 | | /* |
2193 | | * authentication username to use in the operation |
2194 | | */ |
2195 | 0 | return Curl_setstropt(&s->str[STRING_PROXYUSERNAME], ptr); |
2196 | | |
2197 | 0 | case CURLOPT_PROXYPASSWORD: |
2198 | | /* |
2199 | | * authentication password to use in the operation |
2200 | | */ |
2201 | 0 | return Curl_setstropt(&s->str[STRING_PROXYPASSWORD], ptr); |
2202 | | |
2203 | 0 | case CURLOPT_NOPROXY: |
2204 | | /* |
2205 | | * proxy exception list |
2206 | | */ |
2207 | 0 | return Curl_setstropt(&s->str[STRING_NOPROXY], ptr); |
2208 | 0 | #endif /* ! CURL_DISABLE_PROXY */ |
2209 | | |
2210 | 0 | case CURLOPT_RANGE: |
2211 | | /* |
2212 | | * What range of the file you want to transfer |
2213 | | */ |
2214 | 0 | return Curl_setstropt(&s->str[STRING_SET_RANGE], ptr); |
2215 | | |
2216 | 0 | case CURLOPT_CURLU: |
2217 | | /* |
2218 | | * pass CURLU to set URL |
2219 | | */ |
2220 | 0 | if(data->state.url_alloc) { |
2221 | 0 | Curl_safefree(data->state.url); |
2222 | 0 | data->state.url_alloc = FALSE; |
2223 | 0 | } |
2224 | 0 | else |
2225 | 0 | data->state.url = NULL; |
2226 | 0 | Curl_safefree(s->str[STRING_SET_URL]); |
2227 | 0 | s->uh = (CURLU *)ptr; |
2228 | 0 | break; |
2229 | 0 | case CURLOPT_SSLCERT: |
2230 | | /* |
2231 | | * String that holds filename of the SSL certificate to use |
2232 | | */ |
2233 | 0 | return Curl_setstropt(&s->str[STRING_CERT], ptr); |
2234 | | |
2235 | 0 | #ifndef CURL_DISABLE_PROXY |
2236 | 0 | case CURLOPT_PROXY_SSLCERT: |
2237 | | /* |
2238 | | * String that holds filename of the SSL certificate to use for proxy |
2239 | | */ |
2240 | 0 | return Curl_setstropt(&s->str[STRING_CERT_PROXY], ptr); |
2241 | | |
2242 | 0 | #endif |
2243 | 0 | case CURLOPT_SSLCERTTYPE: |
2244 | | /* |
2245 | | * String that holds file type of the SSL certificate to use |
2246 | | */ |
2247 | 0 | return Curl_setstropt(&s->str[STRING_CERT_TYPE], ptr); |
2248 | | |
2249 | 0 | #ifndef CURL_DISABLE_PROXY |
2250 | 0 | case CURLOPT_PROXY_SSLCERTTYPE: |
2251 | | /* |
2252 | | * String that holds file type of the SSL certificate to use for proxy |
2253 | | */ |
2254 | 0 | return Curl_setstropt(&s->str[STRING_CERT_TYPE_PROXY], ptr); |
2255 | | |
2256 | 0 | #endif |
2257 | 0 | case CURLOPT_SSLKEY: |
2258 | | /* |
2259 | | * String that holds filename of the SSL key to use |
2260 | | */ |
2261 | 0 | return Curl_setstropt(&s->str[STRING_KEY], ptr); |
2262 | | |
2263 | 0 | #ifndef CURL_DISABLE_PROXY |
2264 | 0 | case CURLOPT_PROXY_SSLKEY: |
2265 | | /* |
2266 | | * String that holds filename of the SSL key to use for proxy |
2267 | | */ |
2268 | 0 | return Curl_setstropt(&s->str[STRING_KEY_PROXY], ptr); |
2269 | | |
2270 | 0 | #endif |
2271 | 0 | case CURLOPT_SSLKEYTYPE: |
2272 | | /* |
2273 | | * String that holds file type of the SSL key to use |
2274 | | */ |
2275 | 0 | return Curl_setstropt(&s->str[STRING_KEY_TYPE], ptr); |
2276 | | |
2277 | 0 | #ifndef CURL_DISABLE_PROXY |
2278 | 0 | case CURLOPT_PROXY_SSLKEYTYPE: |
2279 | | /* |
2280 | | * String that holds file type of the SSL key to use for proxy |
2281 | | */ |
2282 | 0 | return Curl_setstropt(&s->str[STRING_KEY_TYPE_PROXY], ptr); |
2283 | | |
2284 | 0 | #endif |
2285 | 0 | case CURLOPT_KEYPASSWD: |
2286 | | /* |
2287 | | * String that holds the SSL or SSH private key password. |
2288 | | */ |
2289 | 0 | return Curl_setstropt(&s->str[STRING_KEY_PASSWD], ptr); |
2290 | | |
2291 | 0 | #ifndef CURL_DISABLE_PROXY |
2292 | 0 | case CURLOPT_PROXY_KEYPASSWD: |
2293 | | /* |
2294 | | * String that holds the SSL private key password for proxy. |
2295 | | */ |
2296 | 0 | return Curl_setstropt(&s->str[STRING_KEY_PASSWD_PROXY], ptr); |
2297 | | |
2298 | 0 | #endif |
2299 | 0 | case CURLOPT_SSLENGINE: |
2300 | | /* |
2301 | | * String that holds the SSL crypto engine. |
2302 | | */ |
2303 | 0 | if(ptr && ptr[0]) { |
2304 | 0 | result = Curl_setstropt(&s->str[STRING_SSL_ENGINE], ptr); |
2305 | 0 | if(!result) { |
2306 | 0 | result = Curl_ssl_set_engine(data, ptr); |
2307 | 0 | } |
2308 | 0 | } |
2309 | 0 | break; |
2310 | | |
2311 | 0 | #ifndef CURL_DISABLE_PROXY |
2312 | 0 | case CURLOPT_HAPROXY_CLIENT_IP: |
2313 | | /* |
2314 | | * Set the client IP to send through HAProxy PROXY protocol |
2315 | | */ |
2316 | 0 | result = Curl_setstropt(&s->str[STRING_HAPROXY_CLIENT_IP], ptr); |
2317 | | /* enable the HAProxy protocol */ |
2318 | 0 | s->haproxyprotocol = TRUE; |
2319 | 0 | break; |
2320 | | |
2321 | 0 | #endif |
2322 | 0 | case CURLOPT_INTERFACE: |
2323 | | /* |
2324 | | * Set what interface or address/hostname to bind the socket to when |
2325 | | * performing an operation and thus what from-IP your connection will use. |
2326 | | */ |
2327 | 0 | return setstropt_interface(ptr, |
2328 | 0 | &s->str[STRING_DEVICE], |
2329 | 0 | &s->str[STRING_INTERFACE], |
2330 | 0 | &s->str[STRING_BINDHOST]); |
2331 | | |
2332 | 0 | case CURLOPT_PINNEDPUBLICKEY: |
2333 | | /* |
2334 | | * Set pinned public key for SSL connection. |
2335 | | * Specify filename of the public key in DER format. |
2336 | | */ |
2337 | 0 | #ifdef USE_SSL |
2338 | 0 | if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY)) |
2339 | 0 | return Curl_setstropt(&s->str[STRING_SSL_PINNEDPUBLICKEY], ptr); |
2340 | 0 | #endif |
2341 | 0 | return CURLE_NOT_BUILT_IN; |
2342 | | |
2343 | 0 | #ifndef CURL_DISABLE_PROXY |
2344 | 0 | case CURLOPT_PROXY_PINNEDPUBLICKEY: |
2345 | | /* |
2346 | | * Set pinned public key for SSL connection. |
2347 | | * Specify filename of the public key in DER format. |
2348 | | */ |
2349 | 0 | #ifdef USE_SSL |
2350 | 0 | if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY)) |
2351 | 0 | return Curl_setstropt(&s->str[STRING_SSL_PINNEDPUBLICKEY_PROXY], |
2352 | 0 | ptr); |
2353 | 0 | #endif |
2354 | 0 | return CURLE_NOT_BUILT_IN; |
2355 | 0 | #endif |
2356 | 0 | case CURLOPT_CAINFO: |
2357 | | /* |
2358 | | * Set CA info for SSL connection. Specify filename of the CA certificate |
2359 | | */ |
2360 | 0 | return Curl_setstropt(&s->str[STRING_SSL_CAFILE], ptr); |
2361 | | |
2362 | 0 | #ifndef CURL_DISABLE_PROXY |
2363 | 0 | case CURLOPT_PROXY_CAINFO: |
2364 | | /* |
2365 | | * Set CA info SSL connection for proxy. Specify filename of the |
2366 | | * CA certificate |
2367 | | */ |
2368 | 0 | return Curl_setstropt(&s->str[STRING_SSL_CAFILE_PROXY], ptr); |
2369 | | |
2370 | 0 | #endif |
2371 | 0 | case CURLOPT_CAPATH: |
2372 | | /* |
2373 | | * Set CA path info for SSL connection. Specify directory name of the CA |
2374 | | * certificates which have been prepared using openssl c_rehash utility. |
2375 | | */ |
2376 | 0 | #ifdef USE_SSL |
2377 | 0 | if(Curl_ssl_supports(data, SSLSUPP_CA_PATH)) |
2378 | | /* This does not work on Windows. */ |
2379 | 0 | return Curl_setstropt(&s->str[STRING_SSL_CAPATH], ptr); |
2380 | 0 | #endif |
2381 | 0 | return CURLE_NOT_BUILT_IN; |
2382 | 0 | #ifndef CURL_DISABLE_PROXY |
2383 | 0 | case CURLOPT_PROXY_CAPATH: |
2384 | | /* |
2385 | | * Set CA path info for SSL connection proxy. Specify directory name of the |
2386 | | * CA certificates which have been prepared using openssl c_rehash utility. |
2387 | | */ |
2388 | 0 | #ifdef USE_SSL |
2389 | 0 | if(Curl_ssl_supports(data, SSLSUPP_CA_PATH)) |
2390 | | /* This does not work on Windows. */ |
2391 | 0 | return Curl_setstropt(&s->str[STRING_SSL_CAPATH_PROXY], ptr); |
2392 | 0 | #endif |
2393 | 0 | return CURLE_NOT_BUILT_IN; |
2394 | 0 | #endif |
2395 | 0 | case CURLOPT_CRLFILE: |
2396 | | /* |
2397 | | * Set CRL file info for SSL connection. Specify filename of the CRL |
2398 | | * to check certificates revocation |
2399 | | */ |
2400 | 0 | return Curl_setstropt(&s->str[STRING_SSL_CRLFILE], ptr); |
2401 | | |
2402 | 0 | #ifndef CURL_DISABLE_PROXY |
2403 | 0 | case CURLOPT_PROXY_CRLFILE: |
2404 | | /* |
2405 | | * Set CRL file info for SSL connection for proxy. Specify filename of the |
2406 | | * CRL to check certificates revocation |
2407 | | */ |
2408 | 0 | return Curl_setstropt(&s->str[STRING_SSL_CRLFILE_PROXY], ptr); |
2409 | | |
2410 | 0 | #endif |
2411 | 0 | case CURLOPT_ISSUERCERT: |
2412 | | /* |
2413 | | * Set Issuer certificate file |
2414 | | * to check certificates issuer |
2415 | | */ |
2416 | 0 | return Curl_setstropt(&s->str[STRING_SSL_ISSUERCERT], ptr); |
2417 | | |
2418 | 0 | #ifndef CURL_DISABLE_PROXY |
2419 | 0 | case CURLOPT_PROXY_ISSUERCERT: |
2420 | | /* |
2421 | | * Set Issuer certificate file |
2422 | | * to check certificates issuer |
2423 | | */ |
2424 | 0 | return Curl_setstropt(&s->str[STRING_SSL_ISSUERCERT_PROXY], ptr); |
2425 | | |
2426 | 0 | #endif |
2427 | 0 | case CURLOPT_PRIVATE: |
2428 | | /* |
2429 | | * Set private data pointer. |
2430 | | */ |
2431 | 0 | s->private_data = ptr; |
2432 | 0 | break; |
2433 | | |
2434 | 0 | #ifdef USE_SSL |
2435 | 0 | case CURLOPT_SSL_EC_CURVES: |
2436 | | /* |
2437 | | * Set accepted curves in SSL connection setup. |
2438 | | * Specify colon-delimited list of curve algorithm names. |
2439 | | */ |
2440 | 0 | return Curl_setstropt(&s->str[STRING_SSL_EC_CURVES], ptr); |
2441 | | |
2442 | 0 | case CURLOPT_SSL_SIGNATURE_ALGORITHMS: |
2443 | | /* |
2444 | | * Set accepted signature algorithms. |
2445 | | * Specify colon-delimited list of signature scheme names. |
2446 | | */ |
2447 | 0 | if(Curl_ssl_supports(data, SSLSUPP_SIGNATURE_ALGORITHMS)) |
2448 | 0 | return Curl_setstropt(&s->str[STRING_SSL_SIGNATURE_ALGORITHMS], |
2449 | 0 | ptr); |
2450 | 0 | return CURLE_NOT_BUILT_IN; |
2451 | 0 | #endif |
2452 | | #ifdef USE_SSH |
2453 | | case CURLOPT_SSH_PUBLIC_KEYFILE: |
2454 | | /* |
2455 | | * Use this file instead of the $HOME/.ssh/id_dsa.pub file |
2456 | | */ |
2457 | | return Curl_setstropt(&s->str[STRING_SSH_PUBLIC_KEY], ptr); |
2458 | | |
2459 | | case CURLOPT_SSH_PRIVATE_KEYFILE: |
2460 | | /* |
2461 | | * Use this file instead of the $HOME/.ssh/id_dsa file |
2462 | | */ |
2463 | | return Curl_setstropt(&s->str[STRING_SSH_PRIVATE_KEY], ptr); |
2464 | | |
2465 | | #if defined(USE_LIBSSH2) || defined(USE_LIBSSH) |
2466 | | case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5: |
2467 | | /* |
2468 | | * Option to allow for the MD5 of the host public key to be checked |
2469 | | * for validation purposes. |
2470 | | */ |
2471 | | return Curl_setstropt(&s->str[STRING_SSH_HOST_PUBLIC_KEY_MD5], ptr); |
2472 | | |
2473 | | case CURLOPT_SSH_KNOWNHOSTS: |
2474 | | /* |
2475 | | * Store the filename to read known hosts from. |
2476 | | */ |
2477 | | return Curl_setstropt(&s->str[STRING_SSH_KNOWNHOSTS], ptr); |
2478 | | #endif |
2479 | | case CURLOPT_SSH_KEYDATA: |
2480 | | /* |
2481 | | * Custom client data to pass to the SSH keyfunc callback |
2482 | | */ |
2483 | | s->ssh_keyfunc_userp = ptr; |
2484 | | break; |
2485 | | #ifdef USE_LIBSSH2 |
2486 | | case CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256: |
2487 | | /* |
2488 | | * Option to allow for the SHA256 of the host public key to be checked |
2489 | | * for validation purposes. |
2490 | | */ |
2491 | | return Curl_setstropt(&s->str[STRING_SSH_HOST_PUBLIC_KEY_SHA256], |
2492 | | ptr); |
2493 | | |
2494 | | case CURLOPT_SSH_HOSTKEYDATA: |
2495 | | /* |
2496 | | * Custom client data to pass to the SSH keyfunc callback |
2497 | | */ |
2498 | | s->ssh_hostkeyfunc_userp = ptr; |
2499 | | break; |
2500 | | #endif /* USE_LIBSSH2 */ |
2501 | | #endif /* USE_SSH */ |
2502 | 0 | case CURLOPT_PROTOCOLS_STR: |
2503 | 0 | if(ptr) |
2504 | 0 | return protocol2num(ptr, &s->allowed_protocols); |
2505 | | /* make a NULL argument reset to default */ |
2506 | 0 | s->allowed_protocols = (curl_prot_t) CURLPROTO_ALL; |
2507 | 0 | break; |
2508 | | |
2509 | 0 | case CURLOPT_REDIR_PROTOCOLS_STR: |
2510 | 0 | if(ptr) |
2511 | 0 | return protocol2num(ptr, &s->redir_protocols); |
2512 | | /* make a NULL argument reset to default */ |
2513 | 0 | s->redir_protocols = (curl_prot_t) CURLPROTO_REDIR; |
2514 | 0 | break; |
2515 | | |
2516 | 0 | case CURLOPT_DEFAULT_PROTOCOL: |
2517 | | /* Set the protocol to use when the URL does not include any protocol */ |
2518 | 0 | return Curl_setstropt(&s->str[STRING_DEFAULT_PROTOCOL], ptr); |
2519 | | |
2520 | 0 | #ifndef CURL_DISABLE_SMTP |
2521 | 0 | case CURLOPT_MAIL_FROM: |
2522 | | /* Set the SMTP mail originator */ |
2523 | 0 | return Curl_setstropt(&s->str[STRING_MAIL_FROM], ptr); |
2524 | | |
2525 | 0 | case CURLOPT_MAIL_AUTH: |
2526 | | /* Set the SMTP auth originator */ |
2527 | 0 | return Curl_setstropt(&s->str[STRING_MAIL_AUTH], ptr); |
2528 | 0 | #endif |
2529 | 0 | case CURLOPT_SASL_AUTHZID: |
2530 | | /* Authorization identity (identity to act as) */ |
2531 | 0 | return Curl_setstropt(&s->str[STRING_SASL_AUTHZID], ptr); |
2532 | | |
2533 | 0 | #ifndef CURL_DISABLE_RTSP |
2534 | 0 | case CURLOPT_RTSP_SESSION_ID: |
2535 | | /* |
2536 | | * Set the RTSP Session ID manually. Useful if the application is |
2537 | | * resuming a previously established RTSP session |
2538 | | */ |
2539 | 0 | return Curl_setstropt(&s->str[STRING_RTSP_SESSION_ID], ptr); |
2540 | | |
2541 | 0 | case CURLOPT_RTSP_STREAM_URI: |
2542 | | /* |
2543 | | * Set the Stream URI for the RTSP request. Unless the request is |
2544 | | * for generic server options, the application will need to set this. |
2545 | | */ |
2546 | 0 | return Curl_setstropt(&s->str[STRING_RTSP_STREAM_URI], ptr); |
2547 | | |
2548 | 0 | case CURLOPT_RTSP_TRANSPORT: |
2549 | | /* |
2550 | | * The content of the Transport: header for the RTSP request |
2551 | | */ |
2552 | 0 | return Curl_setstropt(&s->str[STRING_RTSP_TRANSPORT], ptr); |
2553 | | |
2554 | 0 | case CURLOPT_INTERLEAVEDATA: |
2555 | 0 | s->rtp_out = ptr; |
2556 | 0 | break; |
2557 | 0 | #endif /* ! CURL_DISABLE_RTSP */ |
2558 | 0 | #ifndef CURL_DISABLE_FTP |
2559 | 0 | case CURLOPT_CHUNK_DATA: |
2560 | 0 | s->wildcardptr = ptr; |
2561 | 0 | break; |
2562 | 0 | case CURLOPT_FNMATCH_DATA: |
2563 | 0 | s->fnmatch_data = ptr; |
2564 | 0 | break; |
2565 | 0 | #endif |
2566 | 0 | #ifdef USE_TLS_SRP |
2567 | 0 | case CURLOPT_TLSAUTH_USERNAME: |
2568 | 0 | return Curl_setstropt(&s->str[STRING_TLSAUTH_USERNAME], ptr); |
2569 | | |
2570 | 0 | #ifndef CURL_DISABLE_PROXY |
2571 | 0 | case CURLOPT_PROXY_TLSAUTH_USERNAME: |
2572 | 0 | return Curl_setstropt(&s->str[STRING_TLSAUTH_USERNAME_PROXY], ptr); |
2573 | | |
2574 | 0 | #endif |
2575 | 0 | case CURLOPT_TLSAUTH_PASSWORD: |
2576 | 0 | return Curl_setstropt(&s->str[STRING_TLSAUTH_PASSWORD], ptr); |
2577 | | |
2578 | 0 | #ifndef CURL_DISABLE_PROXY |
2579 | 0 | case CURLOPT_PROXY_TLSAUTH_PASSWORD: |
2580 | 0 | return Curl_setstropt(&s->str[STRING_TLSAUTH_PASSWORD_PROXY], ptr); |
2581 | 0 | #endif |
2582 | 0 | case CURLOPT_TLSAUTH_TYPE: |
2583 | 0 | if(ptr && !curl_strequal(ptr, "SRP")) |
2584 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
2585 | 0 | break; |
2586 | 0 | #ifndef CURL_DISABLE_PROXY |
2587 | 0 | case CURLOPT_PROXY_TLSAUTH_TYPE: |
2588 | 0 | if(ptr && !curl_strequal(ptr, "SRP")) |
2589 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
2590 | 0 | break; |
2591 | 0 | #endif |
2592 | 0 | #endif |
2593 | | #ifdef CURLRES_ARES |
2594 | | case CURLOPT_DNS_SERVERS: |
2595 | | result = Curl_setstropt(&s->str[STRING_DNS_SERVERS], ptr); |
2596 | | if(result) |
2597 | | return result; |
2598 | | return Curl_async_ares_set_dns_servers(data); |
2599 | | |
2600 | | case CURLOPT_DNS_INTERFACE: |
2601 | | result = Curl_setstropt(&s->str[STRING_DNS_INTERFACE], ptr); |
2602 | | if(result) |
2603 | | return result; |
2604 | | return Curl_async_ares_set_dns_interface(data); |
2605 | | |
2606 | | case CURLOPT_DNS_LOCAL_IP4: |
2607 | | result = Curl_setstropt(&s->str[STRING_DNS_LOCAL_IP4], ptr); |
2608 | | if(result) |
2609 | | return result; |
2610 | | return Curl_async_ares_set_dns_local_ip4(data); |
2611 | | |
2612 | | case CURLOPT_DNS_LOCAL_IP6: |
2613 | | result = Curl_setstropt(&s->str[STRING_DNS_LOCAL_IP6], ptr); |
2614 | | if(result) |
2615 | | return result; |
2616 | | return Curl_async_ares_set_dns_local_ip6(data); |
2617 | | |
2618 | | #endif |
2619 | 0 | #ifdef USE_UNIX_SOCKETS |
2620 | 0 | case CURLOPT_UNIX_SOCKET_PATH: |
2621 | 0 | s->abstract_unix_socket = FALSE; |
2622 | 0 | return Curl_setstropt(&s->str[STRING_UNIX_SOCKET_PATH], ptr); |
2623 | | |
2624 | 0 | case CURLOPT_ABSTRACT_UNIX_SOCKET: |
2625 | 0 | s->abstract_unix_socket = TRUE; |
2626 | 0 | return Curl_setstropt(&s->str[STRING_UNIX_SOCKET_PATH], ptr); |
2627 | | |
2628 | 0 | #endif |
2629 | | |
2630 | 0 | #ifndef CURL_DISABLE_DOH |
2631 | 0 | case CURLOPT_DOH_URL: |
2632 | 0 | result = Curl_setstropt(&s->str[STRING_DOH], ptr); |
2633 | 0 | s->doh = !!(s->str[STRING_DOH]); |
2634 | 0 | break; |
2635 | 0 | #endif |
2636 | 0 | #ifndef CURL_DISABLE_HSTS |
2637 | 0 | case CURLOPT_HSTSREADDATA: |
2638 | 0 | s->hsts_read_userp = ptr; |
2639 | 0 | break; |
2640 | 0 | case CURLOPT_HSTSWRITEDATA: |
2641 | 0 | s->hsts_write_userp = ptr; |
2642 | 0 | break; |
2643 | 0 | case CURLOPT_HSTS: { |
2644 | 0 | struct curl_slist *h; |
2645 | 0 | if(!data->hsts) { |
2646 | 0 | data->hsts = Curl_hsts_init(); |
2647 | 0 | if(!data->hsts) |
2648 | 0 | return CURLE_OUT_OF_MEMORY; |
2649 | 0 | } |
2650 | 0 | if(ptr) { |
2651 | 0 | result = Curl_setstropt(&s->str[STRING_HSTS], ptr); |
2652 | 0 | if(result) |
2653 | 0 | return result; |
2654 | | /* this needs to build a list of filenames to read from, so that it can |
2655 | | read them later, as we might get a shared HSTS handle to load them |
2656 | | into */ |
2657 | 0 | h = curl_slist_append(data->state.hstslist, ptr); |
2658 | 0 | if(!h) { |
2659 | 0 | curl_slist_free_all(data->state.hstslist); |
2660 | 0 | data->state.hstslist = NULL; |
2661 | 0 | return CURLE_OUT_OF_MEMORY; |
2662 | 0 | } |
2663 | 0 | data->state.hstslist = h; /* store the list for later use */ |
2664 | 0 | } |
2665 | 0 | else { |
2666 | | /* clear the list of HSTS files */ |
2667 | 0 | curl_slist_free_all(data->state.hstslist); |
2668 | 0 | data->state.hstslist = NULL; |
2669 | 0 | if(!data->share || !data->share->hsts) |
2670 | | /* throw away the HSTS cache unless shared */ |
2671 | 0 | Curl_hsts_cleanup(&data->hsts); |
2672 | 0 | } |
2673 | 0 | break; |
2674 | 0 | } |
2675 | 0 | #endif /* ! CURL_DISABLE_HSTS */ |
2676 | 0 | #ifndef CURL_DISABLE_ALTSVC |
2677 | 0 | case CURLOPT_ALTSVC: |
2678 | 0 | if(!data->asi) { |
2679 | 0 | data->asi = Curl_altsvc_init(); |
2680 | 0 | if(!data->asi) |
2681 | 0 | return CURLE_OUT_OF_MEMORY; |
2682 | 0 | } |
2683 | 0 | result = Curl_setstropt(&s->str[STRING_ALTSVC], ptr); |
2684 | 0 | if(result) |
2685 | 0 | return result; |
2686 | 0 | if(ptr) |
2687 | 0 | (void)Curl_altsvc_load(data->asi, ptr); |
2688 | 0 | break; |
2689 | 0 | #endif /* ! CURL_DISABLE_ALTSVC */ |
2690 | | #ifdef USE_ECH |
2691 | | case CURLOPT_ECH: { |
2692 | | size_t plen = 0; |
2693 | | |
2694 | | if(!ptr) { |
2695 | | s->tls_ech = CURLECH_DISABLE; |
2696 | | return CURLE_OK; |
2697 | | } |
2698 | | plen = strlen(ptr); |
2699 | | if(plen > CURL_MAX_INPUT_LENGTH) { |
2700 | | s->tls_ech = CURLECH_DISABLE; |
2701 | | return CURLE_BAD_FUNCTION_ARGUMENT; |
2702 | | } |
2703 | | /* set tls_ech flag value, preserving CLA_CFG bit */ |
2704 | | if(!strcmp(ptr, "false")) |
2705 | | s->tls_ech = CURLECH_DISABLE | |
2706 | | (s->tls_ech & CURLECH_CLA_CFG); |
2707 | | else if(!strcmp(ptr, "grease")) |
2708 | | s->tls_ech = CURLECH_GREASE | |
2709 | | (s->tls_ech & CURLECH_CLA_CFG); |
2710 | | else if(!strcmp(ptr, "true")) |
2711 | | s->tls_ech = CURLECH_ENABLE | |
2712 | | (s->tls_ech & CURLECH_CLA_CFG); |
2713 | | else if(!strcmp(ptr, "hard")) |
2714 | | s->tls_ech = CURLECH_HARD | |
2715 | | (s->tls_ech & CURLECH_CLA_CFG); |
2716 | | else if(plen > 5 && !strncmp(ptr, "ecl:", 4)) { |
2717 | | result = Curl_setstropt(&s->str[STRING_ECH_CONFIG], ptr + 4); |
2718 | | if(result) |
2719 | | return result; |
2720 | | s->tls_ech |= CURLECH_CLA_CFG; |
2721 | | } |
2722 | | else if(plen > 4 && !strncmp(ptr, "pn:", 3)) { |
2723 | | result = Curl_setstropt(&s->str[STRING_ECH_PUBLIC], ptr + 3); |
2724 | | if(result) |
2725 | | return result; |
2726 | | } |
2727 | | break; |
2728 | | } |
2729 | | #endif |
2730 | 0 | default: |
2731 | 0 | return CURLE_UNKNOWN_OPTION; |
2732 | 0 | } |
2733 | 0 | return result; |
2734 | 0 | } |
2735 | | |
2736 | | static CURLcode setopt_func(struct Curl_easy *data, CURLoption option, |
2737 | | va_list param) |
2738 | 0 | { |
2739 | 0 | struct UserDefined *s = &data->set; |
2740 | 0 | switch(option) { |
2741 | 0 | case CURLOPT_PROGRESSFUNCTION: |
2742 | | /* |
2743 | | * Progress callback function |
2744 | | */ |
2745 | 0 | s->fprogress = va_arg(param, curl_progress_callback); |
2746 | 0 | if(s->fprogress) |
2747 | 0 | data->progress.callback = TRUE; /* no longer internal */ |
2748 | 0 | else |
2749 | 0 | data->progress.callback = FALSE; /* NULL enforces internal */ |
2750 | 0 | break; |
2751 | | |
2752 | 0 | case CURLOPT_XFERINFOFUNCTION: |
2753 | | /* |
2754 | | * Transfer info callback function |
2755 | | */ |
2756 | 0 | s->fxferinfo = va_arg(param, curl_xferinfo_callback); |
2757 | 0 | if(s->fxferinfo) |
2758 | 0 | data->progress.callback = TRUE; /* no longer internal */ |
2759 | 0 | else |
2760 | 0 | data->progress.callback = FALSE; /* NULL enforces internal */ |
2761 | |
|
2762 | 0 | break; |
2763 | 0 | case CURLOPT_DEBUGFUNCTION: |
2764 | | /* |
2765 | | * stderr write callback. |
2766 | | */ |
2767 | 0 | s->fdebug = va_arg(param, curl_debug_callback); |
2768 | | /* |
2769 | | * if the callback provided is NULL, it will use the default callback |
2770 | | */ |
2771 | 0 | break; |
2772 | 0 | case CURLOPT_HEADERFUNCTION: |
2773 | | /* |
2774 | | * Set header write callback |
2775 | | */ |
2776 | 0 | s->fwrite_header = va_arg(param, curl_write_callback); |
2777 | 0 | break; |
2778 | 0 | case CURLOPT_WRITEFUNCTION: |
2779 | | /* |
2780 | | * Set data write callback |
2781 | | */ |
2782 | 0 | s->fwrite_func = va_arg(param, curl_write_callback); |
2783 | 0 | if(!s->fwrite_func) |
2784 | | /* When set to NULL, reset to our internal default function */ |
2785 | 0 | s->fwrite_func = (curl_write_callback)fwrite; |
2786 | 0 | break; |
2787 | 0 | case CURLOPT_READFUNCTION: |
2788 | | /* |
2789 | | * Read data callback |
2790 | | */ |
2791 | 0 | s->fread_func_set = va_arg(param, curl_read_callback); |
2792 | 0 | if(!s->fread_func_set) { |
2793 | 0 | s->is_fread_set = 0; |
2794 | | /* When set to NULL, reset to our internal default function */ |
2795 | 0 | s->fread_func_set = (curl_read_callback)fread; |
2796 | 0 | } |
2797 | 0 | else |
2798 | 0 | s->is_fread_set = 1; |
2799 | 0 | break; |
2800 | 0 | case CURLOPT_SEEKFUNCTION: |
2801 | | /* |
2802 | | * Seek callback. Might be NULL. |
2803 | | */ |
2804 | 0 | s->seek_func = va_arg(param, curl_seek_callback); |
2805 | 0 | break; |
2806 | 0 | case CURLOPT_IOCTLFUNCTION: |
2807 | | /* |
2808 | | * I/O control callback. Might be NULL. |
2809 | | */ |
2810 | 0 | s->ioctl_func = va_arg(param, curl_ioctl_callback); |
2811 | 0 | break; |
2812 | 0 | case CURLOPT_SSL_CTX_FUNCTION: |
2813 | | /* |
2814 | | * Set an SSL_CTX callback |
2815 | | */ |
2816 | 0 | #ifdef USE_SSL |
2817 | 0 | if(Curl_ssl_supports(data, SSLSUPP_SSL_CTX)) { |
2818 | 0 | s->ssl.fsslctx = va_arg(param, curl_ssl_ctx_callback); |
2819 | 0 | break; |
2820 | 0 | } |
2821 | 0 | else |
2822 | 0 | #endif |
2823 | 0 | return CURLE_NOT_BUILT_IN; |
2824 | | |
2825 | 0 | case CURLOPT_SOCKOPTFUNCTION: |
2826 | | /* |
2827 | | * socket callback function: called after socket() but before connect() |
2828 | | */ |
2829 | 0 | s->fsockopt = va_arg(param, curl_sockopt_callback); |
2830 | 0 | break; |
2831 | | |
2832 | 0 | case CURLOPT_OPENSOCKETFUNCTION: |
2833 | | /* |
2834 | | * open/create socket callback function: called instead of socket(), |
2835 | | * before connect() |
2836 | | */ |
2837 | 0 | s->fopensocket = va_arg(param, curl_opensocket_callback); |
2838 | 0 | break; |
2839 | | |
2840 | 0 | case CURLOPT_CLOSESOCKETFUNCTION: |
2841 | | /* |
2842 | | * close socket callback function: called instead of close() |
2843 | | * when shutting down a connection |
2844 | | */ |
2845 | 0 | s->fclosesocket = va_arg(param, curl_closesocket_callback); |
2846 | 0 | break; |
2847 | | |
2848 | 0 | case CURLOPT_RESOLVER_START_FUNCTION: |
2849 | | /* |
2850 | | * resolver start callback function: called before a new resolver request |
2851 | | * is started |
2852 | | */ |
2853 | 0 | s->resolver_start = va_arg(param, curl_resolver_start_callback); |
2854 | 0 | break; |
2855 | | |
2856 | | #ifdef USE_SSH |
2857 | | #ifdef USE_LIBSSH2 |
2858 | | case CURLOPT_SSH_HOSTKEYFUNCTION: |
2859 | | /* the callback to check the hostkey without the knownhost file */ |
2860 | | s->ssh_hostkeyfunc = va_arg(param, curl_sshhostkeycallback); |
2861 | | break; |
2862 | | #endif |
2863 | | |
2864 | | case CURLOPT_SSH_KEYFUNCTION: |
2865 | | /* setting to NULL is fine since the ssh.c functions themselves will |
2866 | | then revert to use the internal default */ |
2867 | | s->ssh_keyfunc = va_arg(param, curl_sshkeycallback); |
2868 | | break; |
2869 | | |
2870 | | #endif /* USE_SSH */ |
2871 | | |
2872 | 0 | #ifndef CURL_DISABLE_RTSP |
2873 | 0 | case CURLOPT_INTERLEAVEFUNCTION: |
2874 | | /* Set the user defined RTP write function */ |
2875 | 0 | s->fwrite_rtp = va_arg(param, curl_write_callback); |
2876 | 0 | break; |
2877 | 0 | #endif |
2878 | 0 | #ifndef CURL_DISABLE_FTP |
2879 | 0 | case CURLOPT_CHUNK_BGN_FUNCTION: |
2880 | 0 | s->chunk_bgn = va_arg(param, curl_chunk_bgn_callback); |
2881 | 0 | break; |
2882 | 0 | case CURLOPT_CHUNK_END_FUNCTION: |
2883 | 0 | s->chunk_end = va_arg(param, curl_chunk_end_callback); |
2884 | 0 | break; |
2885 | 0 | case CURLOPT_FNMATCH_FUNCTION: |
2886 | 0 | s->fnmatch = va_arg(param, curl_fnmatch_callback); |
2887 | 0 | break; |
2888 | 0 | #endif |
2889 | 0 | #ifndef CURL_DISABLE_HTTP |
2890 | 0 | case CURLOPT_TRAILERFUNCTION: |
2891 | 0 | s->trailer_callback = va_arg(param, curl_trailer_callback); |
2892 | 0 | break; |
2893 | 0 | #endif |
2894 | 0 | #ifndef CURL_DISABLE_HSTS |
2895 | 0 | case CURLOPT_HSTSREADFUNCTION: |
2896 | 0 | s->hsts_read = va_arg(param, curl_hstsread_callback); |
2897 | 0 | break; |
2898 | 0 | case CURLOPT_HSTSWRITEFUNCTION: |
2899 | 0 | s->hsts_write = va_arg(param, curl_hstswrite_callback); |
2900 | 0 | break; |
2901 | 0 | #endif |
2902 | 0 | case CURLOPT_PREREQFUNCTION: |
2903 | 0 | s->fprereq = va_arg(param, curl_prereq_callback); |
2904 | 0 | break; |
2905 | 0 | default: |
2906 | 0 | return CURLE_UNKNOWN_OPTION; |
2907 | 0 | } |
2908 | 0 | return CURLE_OK; |
2909 | 0 | } |
2910 | | |
2911 | | static CURLcode setopt_offt(struct Curl_easy *data, CURLoption option, |
2912 | | curl_off_t offt) |
2913 | 0 | { |
2914 | 0 | struct UserDefined *s = &data->set; |
2915 | 0 | switch(option) { |
2916 | 0 | case CURLOPT_TIMEVALUE_LARGE: |
2917 | | /* |
2918 | | * This is the value to compare with the remote document with the |
2919 | | * method set with CURLOPT_TIMECONDITION |
2920 | | */ |
2921 | 0 | s->timevalue = (time_t)offt; |
2922 | 0 | break; |
2923 | | |
2924 | | /* MQTT "borrows" some of the HTTP options */ |
2925 | 0 | case CURLOPT_POSTFIELDSIZE_LARGE: |
2926 | | /* |
2927 | | * The size of the POSTFIELD data to prevent libcurl to do strlen() to |
2928 | | * figure it out. Enables binary posts. |
2929 | | */ |
2930 | 0 | if(offt < -1) |
2931 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
2932 | | |
2933 | 0 | if(s->postfieldsize < offt && |
2934 | 0 | s->postfields == s->str[STRING_COPYPOSTFIELDS]) { |
2935 | | /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */ |
2936 | 0 | Curl_safefree(s->str[STRING_COPYPOSTFIELDS]); |
2937 | 0 | s->postfields = NULL; |
2938 | 0 | } |
2939 | 0 | s->postfieldsize = offt; |
2940 | 0 | break; |
2941 | 0 | case CURLOPT_INFILESIZE_LARGE: |
2942 | | /* |
2943 | | * If known, this should inform curl about the file size of the |
2944 | | * to-be-uploaded file. |
2945 | | */ |
2946 | 0 | if(offt < -1) |
2947 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
2948 | 0 | s->filesize = offt; |
2949 | 0 | break; |
2950 | 0 | case CURLOPT_MAX_SEND_SPEED_LARGE: |
2951 | | /* |
2952 | | * When transfer uploads are faster then CURLOPT_MAX_SEND_SPEED_LARGE |
2953 | | * bytes per second the transfer is throttled.. |
2954 | | */ |
2955 | 0 | if(offt < 0) |
2956 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
2957 | 0 | s->max_send_speed = offt; |
2958 | 0 | break; |
2959 | 0 | case CURLOPT_MAX_RECV_SPEED_LARGE: |
2960 | | /* |
2961 | | * When receiving data faster than CURLOPT_MAX_RECV_SPEED_LARGE bytes per |
2962 | | * second the transfer is throttled.. |
2963 | | */ |
2964 | 0 | if(offt < 0) |
2965 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
2966 | 0 | s->max_recv_speed = offt; |
2967 | 0 | break; |
2968 | 0 | case CURLOPT_RESUME_FROM_LARGE: |
2969 | | /* |
2970 | | * Resume transfer at the given file position |
2971 | | */ |
2972 | 0 | if(offt < -1) |
2973 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
2974 | 0 | s->set_resume_from = offt; |
2975 | 0 | break; |
2976 | 0 | case CURLOPT_MAXFILESIZE_LARGE: |
2977 | | /* |
2978 | | * Set the maximum size of a file to download. |
2979 | | */ |
2980 | 0 | if(offt < 0) |
2981 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
2982 | 0 | s->max_filesize = offt; |
2983 | 0 | break; |
2984 | | |
2985 | 0 | default: |
2986 | 0 | return CURLE_UNKNOWN_OPTION; |
2987 | 0 | } |
2988 | 0 | return CURLE_OK; |
2989 | 0 | } |
2990 | | |
2991 | | static CURLcode setopt_blob(struct Curl_easy *data, CURLoption option, |
2992 | | struct curl_blob *blob) |
2993 | 0 | { |
2994 | 0 | struct UserDefined *s = &data->set; |
2995 | 0 | switch(option) { |
2996 | 0 | case CURLOPT_SSLCERT_BLOB: |
2997 | | /* |
2998 | | * Blob that holds file content of the SSL certificate to use |
2999 | | */ |
3000 | 0 | return Curl_setblobopt(&s->blobs[BLOB_CERT], blob); |
3001 | 0 | #ifndef CURL_DISABLE_PROXY |
3002 | 0 | case CURLOPT_PROXY_SSLCERT_BLOB: |
3003 | | /* |
3004 | | * Blob that holds file content of the SSL certificate to use for proxy |
3005 | | */ |
3006 | 0 | return Curl_setblobopt(&s->blobs[BLOB_CERT_PROXY], blob); |
3007 | 0 | case CURLOPT_PROXY_SSLKEY_BLOB: |
3008 | | /* |
3009 | | * Blob that holds file content of the SSL key to use for proxy |
3010 | | */ |
3011 | 0 | return Curl_setblobopt(&s->blobs[BLOB_KEY_PROXY], blob); |
3012 | 0 | case CURLOPT_PROXY_CAINFO_BLOB: |
3013 | | /* |
3014 | | * Blob that holds CA info for SSL connection proxy. |
3015 | | * Specify entire PEM of the CA certificate |
3016 | | */ |
3017 | 0 | #ifdef USE_SSL |
3018 | 0 | if(Curl_ssl_supports(data, SSLSUPP_CAINFO_BLOB)) |
3019 | 0 | return Curl_setblobopt(&s->blobs[BLOB_CAINFO_PROXY], blob); |
3020 | 0 | #endif |
3021 | 0 | return CURLE_NOT_BUILT_IN; |
3022 | 0 | case CURLOPT_PROXY_ISSUERCERT_BLOB: |
3023 | | /* |
3024 | | * Blob that holds Issuer certificate to check certificates issuer |
3025 | | */ |
3026 | 0 | return Curl_setblobopt(&s->blobs[BLOB_SSL_ISSUERCERT_PROXY], |
3027 | 0 | blob); |
3028 | 0 | #endif |
3029 | 0 | case CURLOPT_SSLKEY_BLOB: |
3030 | | /* |
3031 | | * Blob that holds file content of the SSL key to use |
3032 | | */ |
3033 | 0 | return Curl_setblobopt(&s->blobs[BLOB_KEY], blob); |
3034 | 0 | case CURLOPT_CAINFO_BLOB: |
3035 | | /* |
3036 | | * Blob that holds CA info for SSL connection. |
3037 | | * Specify entire PEM of the CA certificate |
3038 | | */ |
3039 | 0 | #ifdef USE_SSL |
3040 | 0 | if(Curl_ssl_supports(data, SSLSUPP_CAINFO_BLOB)) |
3041 | 0 | return Curl_setblobopt(&s->blobs[BLOB_CAINFO], blob); |
3042 | 0 | #endif |
3043 | 0 | return CURLE_NOT_BUILT_IN; |
3044 | 0 | case CURLOPT_ISSUERCERT_BLOB: |
3045 | | /* |
3046 | | * Blob that holds Issuer certificate to check certificates issuer |
3047 | | */ |
3048 | 0 | return Curl_setblobopt(&s->blobs[BLOB_SSL_ISSUERCERT], blob); |
3049 | | |
3050 | 0 | default: |
3051 | 0 | return CURLE_UNKNOWN_OPTION; |
3052 | 0 | } |
3053 | | /* unreachable */ |
3054 | 0 | } |
3055 | | |
3056 | | /* |
3057 | | * Do not make Curl_vsetopt() static: it is called from |
3058 | | * packages/OS400/ccsidcurl.c. |
3059 | | */ |
3060 | | CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) |
3061 | 0 | { |
3062 | 0 | if(option < CURLOPTTYPE_OBJECTPOINT) |
3063 | 0 | return setopt_long(data, option, va_arg(param, long)); |
3064 | 0 | else if(option < CURLOPTTYPE_FUNCTIONPOINT) { |
3065 | | /* unfortunately, different pointer types cannot be identified any other |
3066 | | way than being listed explicitly */ |
3067 | 0 | switch(option) { |
3068 | 0 | case CURLOPT_HTTPHEADER: |
3069 | 0 | case CURLOPT_QUOTE: |
3070 | 0 | case CURLOPT_POSTQUOTE: |
3071 | 0 | case CURLOPT_TELNETOPTIONS: |
3072 | 0 | case CURLOPT_PREQUOTE: |
3073 | 0 | case CURLOPT_HTTP200ALIASES: |
3074 | 0 | case CURLOPT_MAIL_RCPT: |
3075 | 0 | case CURLOPT_RESOLVE: |
3076 | 0 | case CURLOPT_PROXYHEADER: |
3077 | 0 | case CURLOPT_CONNECT_TO: |
3078 | 0 | return setopt_slist(data, option, va_arg(param, struct curl_slist *)); |
3079 | 0 | case CURLOPT_HTTPPOST: /* curl_httppost * */ |
3080 | 0 | case CURLOPT_MIMEPOST: /* curl_mime * */ |
3081 | 0 | case CURLOPT_STDERR: /* FILE * */ |
3082 | 0 | case CURLOPT_SHARE: /* CURLSH * */ |
3083 | 0 | case CURLOPT_STREAM_DEPENDS: /* CURL * */ |
3084 | 0 | case CURLOPT_STREAM_DEPENDS_E: /* CURL * */ |
3085 | 0 | return setopt_pointers(data, option, param); |
3086 | 0 | default: |
3087 | 0 | break; |
3088 | 0 | } |
3089 | | /* the char pointer options */ |
3090 | 0 | return setopt_cptr(data, option, va_arg(param, char *)); |
3091 | 0 | } |
3092 | 0 | else if(option < CURLOPTTYPE_OFF_T) |
3093 | 0 | return setopt_func(data, option, param); |
3094 | 0 | else if(option < CURLOPTTYPE_BLOB) |
3095 | 0 | return setopt_offt(data, option, va_arg(param, curl_off_t)); |
3096 | 0 | return setopt_blob(data, option, va_arg(param, struct curl_blob *)); |
3097 | 0 | } |
3098 | | |
3099 | | /* |
3100 | | * curl_easy_setopt() is the external interface for setting options on an |
3101 | | * easy handle. |
3102 | | * |
3103 | | * NOTE: This is one of few API functions that are allowed to be called from |
3104 | | * within a callback. |
3105 | | */ |
3106 | | |
3107 | | #undef curl_easy_setopt |
3108 | | CURLcode curl_easy_setopt(CURL *d, CURLoption tag, ...) |
3109 | 0 | { |
3110 | 0 | va_list arg; |
3111 | 0 | CURLcode result; |
3112 | 0 | struct Curl_easy *data = d; |
3113 | |
|
3114 | 0 | if(!data) |
3115 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
3116 | | |
3117 | 0 | va_start(arg, tag); |
3118 | |
|
3119 | 0 | result = Curl_vsetopt(data, tag, arg); |
3120 | |
|
3121 | 0 | va_end(arg); |
3122 | 0 | if(result == CURLE_BAD_FUNCTION_ARGUMENT) |
3123 | 0 | failf(data, "setopt 0x%x got bad argument", tag); |
3124 | 0 | return result; |
3125 | 0 | } |