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