Coverage Report

Created: 2024-02-25 06:14

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