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