Coverage Report

Created: 2026-09-04 07:16

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