Coverage Report

Created: 2026-09-14 07:06

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
12.8k
{
55
12.8k
  if(secs < 0)
56
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
57
12.8k
#if LONG_MAX > (TIMEDIFF_T_MAX / 1000)
58
12.8k
  if(secs > (TIMEDIFF_T_MAX / 1000)) {
59
0
    *ptimeout_ms = TIMEDIFF_T_MAX;
60
0
    return CURLE_OK;
61
0
  }
62
12.8k
#endif
63
12.8k
  *ptimeout_ms = (timediff_t)secs * 1000;
64
12.8k
  return CURLE_OK;
65
12.8k
}
66
67
static CURLcode setopt_set_timeout_ms(timediff_t *ptimeout_ms, long ms)
68
12.8k
{
69
12.8k
  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
12.8k
  *ptimeout_ms = (timediff_t)ms;
78
12.8k
  return CURLE_OK;
79
12.8k
}
80
81
CURLcode Curl_setstropt(struct Curl_easy *data,
82
                        enum dupstring id, const char *s)
83
81.2k
{
84
81.2k
  size_t slen = s ? strlen(s) : 0;
85
81.2k
  DEBUGASSERT((unsigned)id <= UINT8_MAX);
86
81.2k
  if(s && (slen > CURL_MAX_INPUT_LENGTH))
87
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
88
89
81.2k
  return CURL_EASY_STR_SET(data, (uint8_t)id, s, slen);
90
81.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
253
{
126
253
  char *user = NULL;
127
253
  char *passwd = NULL;
128
129
253
  DEBUGASSERT(userp);
130
253
  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
253
  if(option) {
135
253
    size_t len = strlen(option);
136
253
    CURLcode result;
137
253
    if(len > CURL_MAX_INPUT_LENGTH)
138
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
139
140
253
    result = Curl_parse_login_details(option, len, &user, &passwd, NULL);
141
253
    if(result)
142
0
      return result;
143
253
  }
144
145
253
  curlx_free(*userp);
146
253
  *userp = user;
147
148
253
  curlx_strzero(*passwdp);
149
253
  curlx_free(*passwdp);
150
253
  *passwdp = passwd;
151
152
253
  return CURLE_OK;
153
253
}
154
155
static CURLcode setstropt_interface(struct Curl_easy *data, char *option)
156
327
{
157
327
  char *dev = NULL;
158
327
  char *iface = NULL;
159
327
  char *host = NULL;
160
327
  CURLcode result;
161
162
327
  if(option) {
163
    /* Parse the interface details if set, otherwise clear them all */
164
327
    result = Curl_parse_interface(option, &dev, &iface, &host);
165
327
    if(result)
166
6
      return result;
167
327
  }
168
169
321
  result = CURL_EASY_STR_SETN(data, STRING_DEVICE, dev);
170
321
  dev = NULL;
171
321
  if(!result) {
172
321
    result = CURL_EASY_STR_SETN(data, STRING_INTERFACE, iface);
173
321
    iface = NULL;
174
321
  }
175
321
  if(!result) {
176
321
    result = CURL_EASY_STR_SETN(data, STRING_BINDHOST, host);
177
321
    host = NULL;
178
321
  }
179
321
  curlx_free(dev);
180
321
  curlx_free(iface);
181
321
  curlx_free(host);
182
321
  return result;
183
327
}
184
185
#ifdef USE_SSL
186
53.6k
#define C_SSLVERSION_VALUE(x)     ((x) & 0xffff)
187
53.6k
#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
12.8k
{
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
12.8k
  *val = 0;
197
198
12.8k
  if(!str)
199
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
200
201
12.8k
  if(curl_strequal(str, "all")) {
202
1
    *val = ~(curl_prot_t)0;
203
1
    return CURLE_OK;
204
1
  }
205
206
26.8k
  do {
207
26.8k
    const char *token = str;
208
26.8k
    size_t tlen;
209
210
26.8k
    str = strchr(str, ',');
211
26.8k
    tlen = str ? (size_t)(str - token) : strlen(token);
212
26.8k
    if(tlen) {
213
26.4k
      const struct Curl_scheme *h = Curl_getn_scheme(token, tlen);
214
215
26.4k
      if(!h || !h->run)
216
262
        return CURLE_UNSUPPORTED_PROTOCOL;
217
218
26.1k
      *val |= h->protocol;
219
26.1k
    }
220
26.8k
  } while(str && str++);
221
222
12.5k
  if(!*val)
223
    /* no protocol listed */
224
12
    return CURLE_BAD_FUNCTION_ARGUMENT;
225
12.5k
  return CURLE_OK;
226
12.5k
}
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
565
{
232
565
  if(auth != CURLAUTH_NONE) {
233
560
    int bitcheck = 0;
234
560
    bool authbits = FALSE;
235
560
    if(auth & CURLAUTH_DIGEST_IE) {
236
95
      auth |= CURLAUTH_DIGEST; /* set standard digest bit */
237
95
      auth &= ~CURLAUTH_DIGEST_IE; /* drop the legacy bit */
238
95
    }
239
240
    /* switch off bits we cannot support */
241
560
#ifndef USE_NTLM
242
560
    auth &= ~CURLAUTH_NTLM; /* no NTLM support */
243
560
#endif
244
560
#ifndef USE_SPNEGO
245
560
    auth &= ~CURLAUTH_NEGOTIATE; /* no Negotiate (SPNEGO) auth without GSS-API
246
                                    or SSPI */
247
560
#endif
248
249
    /* check if any auth bit lower than CURLAUTH_ONLY is still set */
250
3.53k
    while(bitcheck < 31) {
251
3.53k
      if(auth & (1UL << bitcheck++)) {
252
558
        authbits = TRUE;
253
558
        break;
254
558
      }
255
3.53k
    }
256
560
    if(!authbits)
257
2
      return CURLE_NOT_BUILT_IN; /* no supported types left! */
258
560
  }
259
563
  if(proxy)
260
88
    data->set.proxyauth = (uint32_t)auth;
261
475
  else
262
475
    data->set.httpauth = (uint32_t)auth;
263
563
  return CURLE_OK;
264
565
}
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
40
{
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
40
  switch(arg) {
275
0
  case CURL_HTTP_VERSION_NONE:
276
    /* accepted */
277
0
    break;
278
1
  case CURL_HTTP_VERSION_1_0:
279
3
  case CURL_HTTP_VERSION_1_1:
280
    /* accepted */
281
3
    break;
282
0
#ifdef USE_HTTP2
283
2
  case CURL_HTTP_VERSION_2_0:
284
9
  case CURL_HTTP_VERSION_2TLS:
285
11
  case CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE:
286
    /* accepted */
287
11
    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
26
  default:
296
    /* not accepted */
297
26
    if(arg < CURL_HTTP_VERSION_NONE)
298
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
299
26
    return CURLE_UNSUPPORTED_PROTOCOL;
300
40
  }
301
14
  data->set.httpwant = (unsigned char)arg;
302
14
  return CURLE_OK;
303
40
}
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
53.6k
{
310
  /*
311
   * Set explicit SSL version to try to connect with, as some SSL
312
   * implementations are lame.
313
   */
314
53.6k
  {
315
53.6k
    long version, version_max;
316
53.6k
    struct ssl_easy_config *sslc = &data->set.ssl;
317
53.6k
#ifndef CURL_DISABLE_PROXY
318
53.6k
    if(option != CURLOPT_SSLVERSION)
319
26.7k
      sslc = &data->set.proxy_ssl;
320
#else
321
    (void)option; /* unused */
322
#endif
323
53.6k
    version = C_SSLVERSION_VALUE(arg);
324
53.6k
    version_max = (long)C_SSLVERSION_MAX_VALUE(arg);
325
326
53.6k
    if(version < CURL_SSLVERSION_DEFAULT ||
327
53.6k
       version == CURL_SSLVERSION_SSLv2 ||
328
53.6k
       version == CURL_SSLVERSION_SSLv3 ||
329
53.6k
       version >= CURL_SSLVERSION_LAST ||
330
53.6k
       version_max < CURL_SSLVERSION_MAX_NONE ||
331
53.6k
       version_max >= CURL_SSLVERSION_MAX_LAST)
332
30
      return CURLE_BAD_FUNCTION_ARGUMENT;
333
53.5k
    if(version == CURL_SSLVERSION_DEFAULT)
334
53.5k
      version = CURL_SSLVERSION_TLSv1_2;
335
336
53.5k
    sslc->version = (unsigned char)version;
337
53.5k
    sslc->version_max = (unsigned int)version_max;
338
53.5k
  }
339
0
  return CURLE_OK;
340
53.6k
}
341
#endif /* !USE_SSL */
342
343
#ifndef CURL_DISABLE_RTSP
344
static CURLcode setopt_RTSP_REQUEST(struct Curl_easy *data, long arg)
345
35
{
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
35
  if((arg <= CURL_RTSPREQ_NONE) || (arg >= CURL_RTSPREQ_LAST))
351
33
    return CURLE_BAD_FUNCTION_ARGUMENT;
352
353
2
  data->set.rtspreq = (unsigned char)arg;
354
2
  return CURLE_OK;
355
35
}
356
#endif /* !CURL_DISABLE_RTSP */
357
358
static CURLcode setopt_long_bool(struct Curl_easy *data, CURLoption option,
359
                                 long arg)
360
29.9k
{
361
29.9k
  bool enabled = !!arg;
362
29.9k
  int ok = 1;
363
29.9k
  struct UserDefined *s = &data->set;
364
29.9k
  switch(option) {
365
4
  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
4
    s->reuse_forbid = enabled;
371
4
    break;
372
14
  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
14
    s->reuse_fresh = enabled;
378
14
    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
42
  case CURLOPT_HEADER:
387
    /*
388
     * Set to include the header in the general data output stream.
389
     */
390
42
    s->include_header = enabled;
391
42
    break;
392
83
  case CURLOPT_NOPROGRESS:
393
    /*
394
     * Shut off the internal supported progress meter
395
     */
396
83
    data->progress.hide = enabled;
397
83
    break;
398
20
  case CURLOPT_NOBODY:
399
    /*
400
     * Do not include the body part in the output data stream.
401
     */
402
20
    s->opt_no_body = enabled;
403
20
#ifndef CURL_DISABLE_HTTP
404
20
    if(s->opt_no_body)
405
      /* in HTTP lingo, no body means using the HEAD request... */
406
19
      s->method = HTTPREQ_HEAD;
407
1
    else if(s->method == HTTPREQ_HEAD)
408
0
      s->method = HTTPREQ_GET;
409
20
#endif
410
20
    break;
411
14
  case CURLOPT_FAILONERROR:
412
    /*
413
     * Do not output the >=400 error code HTML-page, but instead only
414
     * return error.
415
     */
416
14
    s->http_fail_on_error = enabled;
417
14
    break;
418
2
  case CURLOPT_KEEP_SENDING_ON_ERROR:
419
2
    s->http_keep_sending_on_error = enabled;
420
2
    break;
421
44
  case CURLOPT_UPLOAD:
422
44
  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
44
    if(enabled) {
428
      /* If this is HTTP, PUT is what's needed to "upload" */
429
44
      s->method = HTTPREQ_PUT;
430
44
      s->opt_no_body = FALSE; /* this is implied */
431
44
    }
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
44
    break;
437
9
  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
9
    s->get_filetime = enabled;
443
9
    break;
444
0
#ifndef CURL_DISABLE_HTTP
445
25
  case CURLOPT_HTTP09_ALLOWED:
446
25
    s->http09_allowed = enabled;
447
25
    break;
448
0
#ifndef CURL_DISABLE_COOKIES
449
7
  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
7
    s->cookiesession = enabled;
457
7
    break;
458
0
#endif
459
6
  case CURLOPT_AUTOREFERER:
460
    /*
461
     * Switch on automatic referer that gets set if curl follows locations.
462
     */
463
6
    s->http_auto_referer = enabled;
464
6
    break;
465
3
  case CURLOPT_TRANSFER_ENCODING:
466
3
    s->http_transfer_encoding = enabled;
467
3
    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
3
  case CURLOPT_HTTP_TRANSFER_DECODING:
476
    /*
477
     * disable libcurl transfer encoding is used
478
     */
479
3
    s->http_te_skip = !enabled; /* reversed */
480
3
    break;
481
3
  case CURLOPT_HTTP_CONTENT_DECODING:
482
    /*
483
     * raw data passed to the application when content encoding is used
484
     */
485
3
    s->http_ce_skip = !enabled; /* reversed */
486
3
    break;
487
4
  case CURLOPT_HTTPGET:
488
    /*
489
     * Set to force us do HTTP GET
490
     */
491
4
    if(enabled) {
492
3
      s->method = HTTPREQ_GET;
493
3
      s->opt_no_body = FALSE; /* this is implied */
494
3
    }
495
4
    break;
496
29
  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
29
    if(enabled) {
501
26
      s->method = HTTPREQ_POST;
502
26
      s->opt_no_body = FALSE; /* this is implied */
503
26
    }
504
3
    else
505
3
      s->method = HTTPREQ_GET;
506
29
    break;
507
0
#endif /* !CURL_DISABLE_HTTP */
508
0
#ifndef CURL_DISABLE_PROXY
509
12
  case CURLOPT_HTTPPROXYTUNNEL:
510
    /*
511
     * Tunnel operations through the proxy instead of normal proxy use
512
     */
513
12
    s->tunnel_thru_httpproxy = enabled;
514
12
    break;
515
15
  case CURLOPT_HAPROXYPROTOCOL:
516
    /*
517
     * Set to send the HAProxy Proxy Protocol header
518
     */
519
15
    s->haproxyprotocol = enabled;
520
15
    break;
521
9
  case CURLOPT_PROXY_SSL_VERIFYPEER:
522
    /*
523
     * Enable peer SSL verifying for proxy.
524
     */
525
9
    s->proxy_ssl.verifypeer = enabled;
526
527
    /* Update the current connection proxy_ssl_config. */
528
9
    Curl_ssl_conn_config_update(data, TRUE);
529
9
    break;
530
8
  case CURLOPT_PROXY_SSL_VERIFYHOST:
531
    /*
532
     * Enable verification of the hostname in the peer certificate for proxy
533
     */
534
8
    s->proxy_ssl.verifyhost = enabled;
535
8
    ok = 2;
536
    /* Update the current connection proxy_ssl_config. */
537
8
    Curl_ssl_conn_config_update(data, TRUE);
538
8
    break;
539
5
  case CURLOPT_PROXY_TRANSFER_MODE:
540
    /*
541
     * set transfer mode (;type=<a|i>) when doing FTP via an HTTP proxy
542
     */
543
5
    s->proxy_transfer_mode = enabled;
544
5
    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
9
  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
9
    s->list_only = enabled;
561
9
    break;
562
0
#endif
563
6
  case CURLOPT_APPEND:
564
    /*
565
     * We want to upload and append to an existing file. Used for FTP and
566
     * SFTP.
567
     */
568
6
    s->remote_append = enabled;
569
6
    break;
570
0
#ifndef CURL_DISABLE_FTP
571
7
  case CURLOPT_FTP_USE_EPRT:
572
7
    s->ftp_use_eprt = enabled;
573
7
    break;
574
9
  case CURLOPT_FTP_USE_EPSV:
575
9
    s->ftp_use_epsv = enabled;
576
9
    break;
577
11
  case CURLOPT_FTP_USE_PRET:
578
11
    s->ftp_use_pret = enabled;
579
11
    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
12
  case CURLOPT_WILDCARDMATCH:
588
12
    s->wildcard_enabled = enabled;
589
12
    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
6
  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
6
    s->prefer_ascii = enabled;
614
6
    break;
615
467
  case CURLOPT_SSL_VERIFYPEER:
616
    /*
617
     * Enable peer SSL verifying.
618
     */
619
467
    s->ssl.verifypeer = enabled;
620
621
    /* Update the current connection ssl_config. */
622
467
    Curl_ssl_conn_config_update(data, FALSE);
623
467
    break;
624
0
#ifndef CURL_DISABLE_DOH
625
11
  case CURLOPT_DOH_SSL_VERIFYPEER:
626
    /*
627
     * Enable peer SSL verifying for DoH.
628
     */
629
11
    s->doh_verifypeer = enabled;
630
11
    break;
631
7
  case CURLOPT_DOH_SSL_VERIFYHOST:
632
    /*
633
     * Enable verification of the hostname in the peer certificate for DoH
634
     */
635
7
    s->doh_verifyhost = enabled;
636
7
    ok = 2;
637
7
    break;
638
4
  case CURLOPT_DOH_SSL_VERIFYSTATUS:
639
    /*
640
     * Enable certificate status verifying for DoH.
641
     */
642
4
    if(!Curl_ssl_cert_status_request())
643
0
      return CURLE_NOT_BUILT_IN;
644
645
4
    s->doh_verifystatus = enabled;
646
4
    ok = 2;
647
4
    break;
648
0
#endif /* !CURL_DISABLE_DOH */
649
31
  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
31
    s->ssl.verifyhost = enabled;
658
31
    ok = 2;
659
660
    /* Update the current connection ssl_config. */
661
31
    Curl_ssl_conn_config_update(data, FALSE);
662
31
    break;
663
19
  case CURLOPT_SSL_VERIFYSTATUS:
664
    /*
665
     * Enable certificate status verifying.
666
     */
667
19
    if(!Curl_ssl_cert_status_request())
668
0
      return CURLE_NOT_BUILT_IN;
669
670
19
    s->ssl.verifystatus = enabled;
671
672
    /* Update the current connection ssl_config. */
673
19
    Curl_ssl_conn_config_update(data, FALSE);
674
19
    break;
675
8
  case CURLOPT_CERTINFO:
676
8
#ifdef USE_SSL
677
8
    if(Curl_ssl_supports(data, SSLSUPP_CERTINFO))
678
8
      s->ssl.certinfo = enabled;
679
0
    else
680
0
#endif
681
0
      return CURLE_NOT_BUILT_IN;
682
8
    break;
683
12
  case CURLOPT_NOSIGNAL:
684
    /*
685
     * The application asks not to set any signal() or alarm() handlers,
686
     * even when using a timeout.
687
     */
688
12
    s->no_signal = enabled;
689
12
    break;
690
5
  case CURLOPT_TCP_NODELAY:
691
    /*
692
     * Enable or disable TCP_NODELAY, which will disable/enable the Nagle
693
     * algorithm
694
     */
695
5
    s->tcp_nodelay = enabled;
696
5
    break;
697
13
  case CURLOPT_IGNORE_CONTENT_LENGTH:
698
13
    s->ignorecl = enabled;
699
13
    break;
700
5
  case CURLOPT_SSL_SESSIONID_CACHE:
701
5
    s->ssl.cache_session = enabled;
702
5
#ifndef CURL_DISABLE_PROXY
703
5
    s->proxy_ssl.cache_session = s->ssl.cache_session;
704
5
#endif
705
5
    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
6
  case CURLOPT_MAIL_RCPT_ALLOWFAILS:
713
    /* allow RCPT TO command to fail for some recipients */
714
6
    s->mail_rcpt_allowfails = enabled;
715
6
    break;
716
0
#endif /* !CURL_DISABLE_SMTP */
717
2
  case CURLOPT_SASL_IR:
718
    /* Enable/disable SASL initial response */
719
2
    s->sasl_ir = enabled;
720
2
    break;
721
49
  case CURLOPT_TCP_KEEPALIVE:
722
49
    s->tcp_keepalive = enabled;
723
49
    break;
724
6
  case CURLOPT_TCP_FASTOPEN:
725
6
#if defined(CONNECT_DATA_IDEMPOTENT) || defined(MSG_FASTOPEN) || \
726
6
  defined(TCP_FASTOPEN_CONNECT)
727
6
    s->tcp_fastopen = enabled;
728
6
    break;
729
#else
730
    return CURLE_NOT_BUILT_IN;
731
#endif
732
18
  case CURLOPT_SSL_ENABLE_ALPN:
733
18
    s->ssl_enable_alpn = enabled;
734
18
    break;
735
18
  case CURLOPT_PATH_AS_IS:
736
18
    s->path_as_is = enabled;
737
18
    break;
738
3
  case CURLOPT_PIPEWAIT:
739
3
    s->pipewait = enabled;
740
3
    break;
741
14
  case CURLOPT_SUPPRESS_CONNECT_HEADERS:
742
14
    s->suppress_connect_headers = enabled;
743
14
    break;
744
0
#ifndef CURL_DISABLE_SHUFFLE_DNS
745
9
  case CURLOPT_DNS_SHUFFLE_ADDRESSES:
746
9
    s->dns_shuffle_addresses = enabled;
747
9
    break;
748
0
#endif
749
6
  case CURLOPT_DISALLOW_USERNAME_IN_URL:
750
6
    s->disallow_username_in_url = enabled;
751
6
    break;
752
6
  case CURLOPT_QUICK_EXIT:
753
6
    s->quick_exit = enabled;
754
6
    break;
755
28.8k
  default:
756
28.8k
    return CURLE_UNKNOWN_OPTION;
757
29.9k
  }
758
1.17k
  if((arg > ok) || (arg < 0))
759
    /* reserve other values for future use */
760
530
    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
29.9k
}
765
766
static CURLcode value_range(long *value, long below_error, long min, long max)
767
896
{
768
896
  if(*value < below_error)
769
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
770
896
  else if(*value < min)
771
81
    *value = min;
772
815
  else if(*value > max)
773
273
    *value = max;
774
896
  return CURLE_OK;
775
896
}
776
777
static CURLcode setopt_long_net(struct Curl_easy *data, CURLoption option,
778
                                long arg)
779
28.8k
{
780
28.8k
  CURLcode result = CURLE_OK;
781
28.8k
  struct UserDefined *s = &data->set;
782
783
28.8k
  switch(option) {
784
120
  case CURLOPT_DNS_CACHE_TIMEOUT:
785
120
    if(arg != -1)
786
120
      return setopt_set_timeout_sec(&s->dns_cache_timeout_ms, arg);
787
0
    s->dns_cache_timeout_ms = -1;
788
0
    break;
789
52
  case CURLOPT_MAXCONNECTS:
790
52
    result = value_range(&arg, 0, 0, INT_MAX);
791
52
    if(!result)
792
52
      s->maxconnects = arg ? (uint32_t)arg : DEFAULT_CONNCACHE_SIZE;
793
52
    break;
794
12.5k
  case CURLOPT_SERVER_RESPONSE_TIMEOUT:
795
12.5k
    return setopt_set_timeout_sec(&s->server_response_timeout, arg);
796
29
  case CURLOPT_SERVER_RESPONSE_TIMEOUT_MS:
797
29
    return setopt_set_timeout_ms(&s->server_response_timeout, arg);
798
79
  case CURLOPT_LOW_SPEED_LIMIT:
799
79
    if(arg < 0)
800
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
801
79
    else
802
79
      s->low_speed_limit = arg;
803
79
    break;
804
103
  case CURLOPT_LOW_SPEED_TIME:
805
103
    result = value_range(&arg, 0, 0, USHRT_MAX);
806
103
    if(!result)
807
103
      s->low_speed_time = (uint16_t)arg;
808
103
    break;
809
76
  case CURLOPT_PORT:
810
76
    if((arg < 0) || (arg > 65535))
811
23
      return CURLE_BAD_FUNCTION_ARGUMENT;
812
53
    s->use_port = (unsigned short)arg;
813
53
    break;
814
0
  case CURLOPT_TIMEOUT:
815
0
    return setopt_set_timeout_sec(&s->timeout, arg);
816
12.5k
  case CURLOPT_TIMEOUT_MS:
817
12.5k
    return setopt_set_timeout_ms(&s->timeout, arg);
818
96
  case CURLOPT_CONNECTTIMEOUT:
819
96
    return setopt_set_timeout_sec(&s->connecttimeout, arg);
820
187
  case CURLOPT_CONNECTTIMEOUT_MS:
821
187
    return setopt_set_timeout_ms(&s->connecttimeout, arg);
822
0
#ifndef CURL_DISABLE_BINDLOCAL
823
61
  case CURLOPT_LOCALPORT:
824
61
    if((arg < 0) || (arg > 65535))
825
18
      return CURLE_BAD_FUNCTION_ARGUMENT;
826
43
    s->localport = curlx_sltous(arg);
827
43
    break;
828
62
  case CURLOPT_LOCALPORTRANGE:
829
62
    if((arg < 0) || (arg > 65535))
830
26
      return CURLE_BAD_FUNCTION_ARGUMENT;
831
36
    s->localportrange = curlx_sltous(arg);
832
36
    break;
833
0
#endif
834
150
  case CURLOPT_BUFFERSIZE:
835
150
    result = value_range(&arg, 0, READBUFFER_MIN, READBUFFER_MAX);
836
150
    if(!result)
837
150
      s->buffer_size = (unsigned int)arg;
838
150
    break;
839
67
  case CURLOPT_UPLOAD_BUFFERSIZE:
840
67
    result = value_range(&arg, 0, UPLOADBUFFER_MIN, UPLOADBUFFER_MAX);
841
67
    if(!result)
842
67
      s->upload_buffer_size = (unsigned int)arg;
843
67
    break;
844
73
  case CURLOPT_MAXFILESIZE:
845
73
    if(arg < 0)
846
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
847
73
    else
848
73
      s->max_filesize = arg;
849
73
    break;
850
46
  case CURLOPT_IPRESOLVE:
851
46
    if((arg < CURL_IPRESOLVE_WHATEVER) || (arg > CURL_IPRESOLVE_V6))
852
34
      result = CURLE_BAD_FUNCTION_ARGUMENT;
853
12
    else
854
12
      s->ipver = (unsigned char)arg;
855
46
    break;
856
48
  case CURLOPT_CONNECT_ONLY:
857
48
    if(arg < 0 || arg > 2)
858
34
      result = CURLE_BAD_FUNCTION_ARGUMENT;
859
14
    else {
860
14
      s->connect_only = !!arg;
861
14
      s->connect_only_ws = (arg == 2);
862
14
    }
863
48
    break;
864
0
#ifdef USE_IPV6
865
148
  case CURLOPT_ADDRESS_SCOPE:
866
148
#if SIZEOF_LONG > 4
867
148
    if((unsigned long)arg > UINT_MAX)
868
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
869
148
    else
870
148
#endif
871
148
    s->scope_id = (unsigned int)arg;
872
148
    break;
873
0
#endif
874
77
  case CURLOPT_TCP_KEEPIDLE:
875
77
    result = value_range(&arg, 0, 0, INT_MAX);
876
77
    if(!result)
877
77
      s->tcp_keepidle = (int)arg;
878
77
    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
58
  case CURLOPT_TCP_KEEPCNT:
885
58
    result = value_range(&arg, 0, 0, INT_MAX);
886
58
    if(!result)
887
58
      s->tcp_keepcnt = (int)arg;
888
58
    break;
889
7
  case CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS:
890
7
    return setopt_set_timeout_ms(&s->happy_eyeballs_timeout, arg);
891
32
  case CURLOPT_UPKEEP_INTERVAL_MS:
892
32
    return setopt_set_timeout_ms(&s->upkeep_interval_ms, arg);
893
50
  case CURLOPT_MAXAGE_CONN:
894
50
    return setopt_set_timeout_sec(&s->conn_max_idle_ms, arg);
895
42
  case CURLOPT_MAXLIFETIME_CONN:
896
42
    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.06k
  default:
901
2.06k
    return CURLE_UNKNOWN_OPTION;
902
28.8k
  }
903
1.08k
  return result;
904
28.8k
}
905
906
static CURLcode setopt_long_ssl(struct Curl_easy *data, CURLoption option,
907
                                long arg)
908
918
{
909
918
#ifdef USE_SSL
910
918
  CURLcode result = CURLE_OK;
911
918
  struct UserDefined *s = &data->set;
912
918
  switch(option) {
913
81
  case CURLOPT_CA_CACHE_TIMEOUT:
914
81
    if(Curl_ssl_supports(data, SSLSUPP_CA_CACHE)) {
915
81
      result = value_range(&arg, -1, -1, INT_MAX);
916
81
      if(!result)
917
81
        s->ssl_ca_cache_timeout = (int)arg;
918
81
    }
919
0
    else
920
0
      result = CURLE_NOT_BUILT_IN;
921
81
    break;
922
103
  case CURLOPT_SSLVERSION:
923
103
#ifndef CURL_DISABLE_PROXY
924
122
  case CURLOPT_PROXY_SSLVERSION:
925
122
#endif
926
122
    return Curl_setopt_SSLVERSION(data, option, arg);
927
1
  case CURLOPT_SSL_FALSESTART:
928
1
    result = CURLE_NOT_BUILT_IN;
929
1
    break;
930
34
  case CURLOPT_USE_SSL:
931
34
    if((arg < CURLUSESSL_NONE) || (arg >= CURLUSESSL_LAST))
932
28
      result = CURLE_BAD_FUNCTION_ARGUMENT;
933
6
    else
934
6
      s->use_ssl = (unsigned char)arg;
935
34
    break;
936
6
  case CURLOPT_SSL_OPTIONS:
937
6
    s->ssl.ssl_options = (unsigned char)(arg & 0xff);
938
6
    break;
939
0
#ifndef CURL_DISABLE_PROXY
940
5
  case CURLOPT_PROXY_SSL_OPTIONS:
941
5
    s->proxy_ssl.ssl_options = (unsigned char)(arg & 0xff);
942
5
    break;
943
0
#endif
944
0
  case CURLOPT_SSL_ENABLE_NPN:
945
0
    break;
946
5
  case CURLOPT_SSLENGINE_DEFAULT:
947
5
    CURL_EASY_STR_CLEAR(data, STRING_SSL_ENGINE);
948
5
    result = Curl_ssl_set_engine_default(data);
949
5
    break;
950
664
  default:
951
664
    return CURLE_UNKNOWN_OPTION;
952
918
  }
953
132
  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
918
}
961
962
#ifndef CURL_DISABLE_PROXY
963
static void changeproxy(struct Curl_easy *data)
964
2.48k
{
965
2.48k
  Curl_auth_digest_cleanup(&data->state.proxydigest);
966
2.48k
  memset(&data->state.authproxy, 0, sizeof(data->state.authproxy));
967
2.48k
}
968
969
static CURLcode setopt_long_proxy(struct Curl_easy *data, CURLoption option,
970
                                  long arg)
971
1.13k
{
972
1.13k
  struct UserDefined *s = &data->set;
973
974
1.13k
  switch(option) {
975
76
  case CURLOPT_PROXYPORT:
976
76
    if((arg < 0) || (arg > UINT16_MAX))
977
27
      return CURLE_BAD_FUNCTION_ARGUMENT;
978
49
    if(arg != s->proxyport)
979
48
      changeproxy(data);
980
49
    s->proxyport = (uint16_t)arg;
981
49
    break;
982
89
  case CURLOPT_PROXYAUTH:
983
89
    return httpauth(data, TRUE, (unsigned long)arg);
984
45
  case CURLOPT_PROXYTYPE:
985
45
    if((arg < CURLPROXY_HTTP) || (arg > CURLPROXY_HTTPS3))
986
33
      return CURLE_BAD_FUNCTION_ARGUMENT;
987
12
#ifndef USE_PROXY_HTTP3
988
12
    if(arg == CURLPROXY_HTTPS3)
989
1
      return CURLE_NOT_BUILT_IN;
990
11
#endif
991
11
    s->proxytype = (unsigned char)arg;
992
11
    break;
993
7
  case CURLOPT_SOCKS5_AUTH:
994
7
    if(arg & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI))
995
1
      return CURLE_NOT_BUILT_IN;
996
6
    s->socks5auth = (unsigned char)arg;
997
6
    break;
998
918
  default:
999
918
    return CURLE_UNKNOWN_OPTION;
1000
1.13k
  }
1001
66
  return CURLE_OK;
1002
1.13k
}
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.06k
{
1017
2.06k
#ifndef CURL_DISABLE_HTTP
1018
2.06k
  CURLcode result = CURLE_OK;
1019
2.06k
  struct UserDefined *s = &data->set;
1020
1021
2.06k
  switch(option) {
1022
29
  case CURLOPT_FOLLOWLOCATION:
1023
29
    if((unsigned long)arg > 3)
1024
24
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1025
5
    else
1026
5
      s->http_follow_mode = (unsigned char)arg;
1027
29
    break;
1028
49
  case CURLOPT_MAXREDIRS:
1029
49
    result = value_range(&arg, -1, -1, 0x7fff);
1030
49
    if(!result)
1031
49
      s->maxredirs = (short)arg;
1032
49
    break;
1033
43
  case CURLOPT_POSTREDIR:
1034
43
    if(arg < CURL_REDIR_GET_ALL)
1035
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1036
43
    else {
1037
43
      s->post301 = !!(arg & CURL_REDIR_POST_301);
1038
43
      s->post302 = !!(arg & CURL_REDIR_POST_302);
1039
43
      s->post303 = !!(arg & CURL_REDIR_POST_303);
1040
43
    }
1041
43
    break;
1042
205
  case CURLOPT_HEADEROPT:
1043
205
    s->sep_headers = !!(arg & CURLHEADER_SEPARATE);
1044
205
    break;
1045
476
  case CURLOPT_HTTPAUTH:
1046
476
    return httpauth(data, FALSE, (unsigned long)arg);
1047
40
  case CURLOPT_HTTP_VERSION:
1048
40
    return setopt_HTTP_VERSION(data, arg);
1049
47
  case CURLOPT_EXPECT_100_TIMEOUT_MS:
1050
47
    result = value_range(&arg, 0, 0, 0xffff);
1051
47
    if(!result)
1052
47
      s->expect_100_timeout = (unsigned short)arg;
1053
47
    break;
1054
43
  case CURLOPT_STREAM_WEIGHT:
1055
43
#if defined(USE_HTTP2) || defined(USE_HTTP3)
1056
43
    if((arg >= 1) && (arg <= 256))
1057
9
      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.13k
  default:
1077
1.13k
    return CURLE_UNKNOWN_OPTION;
1078
2.06k
  }
1079
416
  return result;
1080
#else
1081
  (void)data;
1082
  (void)option;
1083
  (void)arg;
1084
  return CURLE_UNKNOWN_OPTION;
1085
#endif
1086
2.06k
}
1087
1088
static CURLcode setopt_long_proto(struct Curl_easy *data, CURLoption option,
1089
                                  long arg)
1090
664
{
1091
664
  CURLcode result = CURLE_OK;
1092
664
  struct UserDefined *s = &data->set;
1093
1094
664
  switch(option) {
1095
0
#ifndef CURL_DISABLE_TFTP
1096
59
  case CURLOPT_TFTP_BLKSIZE:
1097
59
    result = value_range(&arg, 0, TFTP_BLKSIZE_MIN, TFTP_BLKSIZE_MAX);
1098
59
    if(!result)
1099
59
      s->tftp_blksize = (unsigned short)arg;
1100
59
    break;
1101
0
#endif
1102
0
#ifndef CURL_DISABLE_NETRC
1103
51
  case CURLOPT_NETRC:
1104
51
    if((arg < CURL_NETRC_IGNORED) || (arg >= CURL_NETRC_LAST))
1105
36
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1106
15
    else
1107
15
      s->use_netrc = (unsigned char)arg;
1108
51
    break;
1109
0
#endif
1110
0
#ifndef CURL_DISABLE_FTP
1111
39
  case CURLOPT_FTP_FILEMETHOD:
1112
39
    if((arg < CURLFTPMETHOD_DEFAULT) || (arg >= CURLFTPMETHOD_LAST))
1113
34
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1114
5
    else
1115
5
      s->ftp_filemethod = (unsigned char)arg;
1116
39
    break;
1117
34
  case CURLOPT_FTP_SSL_CCC:
1118
34
    if((arg < CURLFTPSSL_CCC_NONE) || (arg >= CURLFTPSSL_CCC_LAST))
1119
30
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1120
4
    else
1121
4
      s->ftp_ccc = (unsigned char)arg;
1122
34
    break;
1123
37
  case CURLOPT_FTPSSLAUTH:
1124
37
    if((arg < CURLFTPAUTH_DEFAULT) || (arg >= CURLFTPAUTH_LAST))
1125
31
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1126
6
    else
1127
6
      s->ftpsslauth = (unsigned char)arg;
1128
37
    break;
1129
31
  case CURLOPT_ACCEPTTIMEOUT_MS:
1130
31
    return setopt_set_timeout_ms(&s->accepttimeout, arg);
1131
0
#endif
1132
0
#if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
1133
27
  case CURLOPT_FTP_CREATE_MISSING_DIRS:
1134
27
    if((arg < CURLFTP_CREATE_DIR_NONE) || (arg > CURLFTP_CREATE_DIR_RETRY))
1135
24
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1136
3
    else
1137
3
      s->ftp_create_missing_dirs = (unsigned char)arg;
1138
27
    break;
1139
33
  case CURLOPT_NEW_FILE_PERMS:
1140
33
    if((arg < 0) || (arg > 0777))
1141
25
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1142
8
    else
1143
8
      s->new_file_perms = (unsigned int)arg;
1144
33
    break;
1145
0
#endif
1146
0
#ifndef CURL_DISABLE_RTSP
1147
35
  case CURLOPT_RTSP_REQUEST:
1148
35
    return setopt_RTSP_REQUEST(data, arg);
1149
53
  case CURLOPT_RTSP_CLIENT_CSEQ:
1150
53
    result = value_range(&arg, 0, 0, INT_MAX);
1151
53
    if(!result)
1152
53
      data->state.rtsp_next_client_CSeq = (uint32_t)arg;
1153
53
    break;
1154
47
  case CURLOPT_RTSP_SERVER_CSEQ:
1155
47
    result = value_range(&arg, 0, 0, INT_MAX);
1156
47
    if(!result)
1157
47
      data->state.rtsp_next_server_CSeq = (uint32_t)arg;
1158
47
    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
31
  case CURLOPT_WS_OPTIONS:
1179
31
    s->ws_raw_mode = (bool)(arg & CURLWS_RAW_MODE);
1180
31
    s->ws_no_auto_pong = (bool)(arg & CURLWS_NOAUTOPONG);
1181
31
    break;
1182
0
#endif
1183
187
  default:
1184
187
    return CURLE_UNKNOWN_OPTION;
1185
664
  }
1186
411
  return result;
1187
664
}
1188
1189
static CURLcode setopt_long_misc(struct Curl_easy *data, CURLoption option,
1190
                                 long arg)
1191
187
{
1192
187
  struct UserDefined *s = &data->set;
1193
1194
187
  switch(option) {
1195
34
  case CURLOPT_TIMECONDITION:
1196
34
    if((arg < CURL_TIMECOND_NONE) || (arg >= CURL_TIMECOND_LAST))
1197
30
      return CURLE_BAD_FUNCTION_ARGUMENT;
1198
4
    s->timecondition = (unsigned char)arg;
1199
4
    break;
1200
11
  case CURLOPT_TIMEVALUE:
1201
11
    s->timevalue = (time_t)arg;
1202
11
    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
76
  case CURLOPT_RESUME_FROM:
1218
76
    if(arg < -1)
1219
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1220
76
    s->set_resume_from = arg;
1221
76
    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
8
  case CURLOPT_MIME_OPTIONS:
1227
8
    s->mime_formescape = !!(arg & CURLMIMEOPT_FORMESCAPE);
1228
8
    break;
1229
0
#endif
1230
0
#ifndef CURL_DISABLE_HSTS
1231
8
  case CURLOPT_HSTS_CTRL:
1232
8
    if(arg & CURLHSTS_ENABLE) {
1233
4
      if(!data->hsts) {
1234
4
        data->hsts = Curl_hsts_init();
1235
4
        if(!data->hsts)
1236
0
          return CURLE_OUT_OF_MEMORY;
1237
4
      }
1238
4
    }
1239
4
    else if(!data->share || !data->share->hsts) {
1240
      /* throw away the HSTS cache unless shared */
1241
4
      Curl_hsts_cleanup(&data->hsts);
1242
      /* flush all the entries */
1243
4
      curl_slist_free_all(data->state.hstslist);
1244
4
      data->state.hstslist = NULL;
1245
4
    }
1246
0
    else
1247
      /* detach from shared HSTS cache without freeing it */
1248
0
      data->hsts = NULL;
1249
8
    break;
1250
8
#endif
1251
8
#ifndef CURL_DISABLE_ALTSVC
1252
45
  case CURLOPT_ALTSVC_CTRL:
1253
45
    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
5
  default:
1262
5
    return CURLE_UNKNOWN_OPTION;
1263
187
  }
1264
107
  return CURLE_OK;
1265
187
}
1266
1267
static CURLcode setopt_long(struct Curl_easy *data, CURLoption option,
1268
                            long arg)
1269
29.9k
{
1270
29.9k
  typedef CURLcode (*setoptfunc)(struct Curl_easy *data,
1271
29.9k
                                 CURLoption option, long arg);
1272
29.9k
  static const setoptfunc setopt_call[] = {
1273
29.9k
    setopt_long_bool,
1274
29.9k
    setopt_long_net,
1275
29.9k
    setopt_long_http,
1276
29.9k
    setopt_long_proxy,
1277
29.9k
    setopt_long_ssl,
1278
29.9k
    setopt_long_proto,
1279
29.9k
    setopt_long_misc
1280
29.9k
  };
1281
29.9k
  size_t i;
1282
1283
63.7k
  for(i = 0; i < CURL_ARRAYSIZE(setopt_call); i++) {
1284
63.7k
    CURLcode result = setopt_call[i](data, option, arg);
1285
63.7k
    if(result != CURLE_UNKNOWN_OPTION)
1286
29.9k
      return result;
1287
63.7k
  }
1288
5
  return CURLE_UNKNOWN_OPTION;
1289
29.9k
}
1290
1291
static CURLcode setopt_slist(struct Curl_easy *data, CURLoption option,
1292
                             struct curl_slist *slist)
1293
13.0k
{
1294
13.0k
  CURLcode result = CURLE_OK;
1295
13.0k
  struct UserDefined *s = &data->set;
1296
13.0k
  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
518
  case CURLOPT_HTTPHEADER:
1359
    /*
1360
     * Set a list with HTTP headers to use (or replace internals with)
1361
     */
1362
518
    s->headers = slist;
1363
518
    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
45
  case CURLOPT_MAIL_RCPT:
1375
    /* Set the list of mail recipients */
1376
45
    s->mail_rcpt = slist;
1377
45
    break;
1378
0
#endif
1379
12.5k
  case CURLOPT_CONNECT_TO:
1380
12.5k
    s->connect_to = slist;
1381
12.5k
    break;
1382
0
  default:
1383
0
    return CURLE_UNKNOWN_OPTION;
1384
13.0k
  }
1385
13.0k
  return result;
1386
13.0k
}
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
204
{
1393
  /*
1394
   * Set to make us do MIME POST
1395
   */
1396
204
  CURLcode result;
1397
204
  struct UserDefined *s = &data->set;
1398
204
  if(!s->mimepostp) {
1399
204
    s->mimepostp = curlx_malloc(sizeof(*s->mimepostp));
1400
204
    if(!s->mimepostp)
1401
0
      return CURLE_OUT_OF_MEMORY;
1402
204
    Curl_mime_initpart(s->mimepostp);
1403
204
  }
1404
1405
204
  result = Curl_mime_set_subparts(s->mimepostp, mimep, FALSE);
1406
204
  if(!result) {
1407
204
    s->method = HTTPREQ_POST_MIME;
1408
204
    s->opt_no_body = FALSE; /* this is implied */
1409
204
#ifndef CURL_DISABLE_FORM_API
1410
204
    Curl_mime_cleanpart(data->state.formp);
1411
204
    curlx_safefree(data->state.formp);
1412
204
    data->state.mimepost = NULL;
1413
204
#endif
1414
204
  }
1415
204
  return result;
1416
204
}
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
308
{
1444
308
  CURLcode result = CURLE_OK;
1445
308
  struct UserDefined *s = &data->set;
1446
308
  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
104
  case CURLOPT_HTTPPOST:
1458
    /*
1459
     * Set to make us do HTTP POST. Legacy API-style.
1460
     */
1461
104
    s->httppost = va_arg(param, struct curl_httppost *);
1462
104
    s->method = HTTPREQ_POST_FORM;
1463
104
    s->opt_no_body = FALSE; /* this is implied */
1464
104
    Curl_mime_cleanpart(data->state.formp);
1465
104
    curlx_safefree(data->state.formp);
1466
104
    data->state.mimepost = NULL;
1467
104
    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
204
  case CURLOPT_MIMEPOST:
1474
204
    result = setopt_mimepost(data, va_arg(param, curl_mime *));
1475
204
    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
308
  }
1493
308
  return result;
1494
308
}
1495
1496
#ifndef CURL_DISABLE_COOKIES
1497
static CURLcode cookielist(struct Curl_easy *data, const char *ptr)
1498
1.78k
{
1499
1.78k
  CURLcode result = CURLE_OK;
1500
1.78k
  if(!ptr)
1501
0
    return CURLE_OK;
1502
1503
1.78k
  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.78k
  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.78k
  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.78k
  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.78k
  else {
1526
1.78k
    if(!data->cookies) {
1527
      /* if cookie engine was not running, activate it */
1528
1.78k
      data->cookies = Curl_cookie_init();
1529
1.78k
      if(!data->cookies)
1530
0
        return CURLE_OUT_OF_MEMORY;
1531
1.78k
      data->state.cookie_engine = TRUE;
1532
1.78k
    }
1533
1534
    /* general protection against mistakes and abuse */
1535
1.78k
    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.78k
    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
1542
1.78k
    if(checkprefix("Set-Cookie:", ptr))
1543
      /* HTTP Header format line */
1544
1.10k
      result = Curl_cookie_add(data, data->cookies, ptr + 11,
1545
1.10k
                               NULL, NULL,
1546
1.10k
                               COOKIE_HTTPHEADER | COOKIE_SECURE |
1547
1.10k
                               COOKIE_NOPSL);
1548
677
    else
1549
      /* Netscape format line */
1550
677
      result = Curl_cookie_add(data, data->cookies, ptr, NULL,
1551
677
                               NULL, COOKIE_SECURE | COOKIE_NOPSL);
1552
1.78k
    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
1553
1.78k
  }
1554
1.78k
  return result;
1555
1.78k
}
1556
1557
static CURLcode cookiefile(struct Curl_easy *data, const char *ptr)
1558
12.5k
{
1559
  /*
1560
   * Set cookie file to read and parse. Can be used multiple times.
1561
   */
1562
12.5k
  if(ptr) {
1563
12.5k
    struct curl_slist *cl;
1564
    /* general protection against mistakes and abuse */
1565
12.5k
    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
12.5k
    cl = curl_slist_append(data->state.cookielist, ptr);
1570
12.5k
    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
12.5k
    data->state.cookielist = cl; /* store the list for later use */
1576
12.5k
  }
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
12.5k
  return CURLE_OK;
1592
12.5k
}
1593
#endif
1594
1595
#ifndef CURL_DISABLE_PROXY
1596
static CURLcode setproxy(struct Curl_easy *data, const char *proxy)
1597
3.22k
{
1598
3.22k
  const char *str = CURL_EASY_STR(data, STRING_PROXY);
1599
3.22k
  if(str && proxy &&
1600
     /* there was one set, is this a new one? */
1601
1.61k
     !strcmp(str, proxy))
1602
788
    return CURLE_OK; /* same one as before */
1603
1604
2.43k
  changeproxy(data);
1605
2.43k
  return Curl_setstropt(data, STRING_PROXY, proxy);
1606
3.22k
}
1607
1608
static CURLcode setopt_cptr_proxy(struct Curl_easy *data, CURLoption option,
1609
                                  char *ptr)
1610
32.8k
{
1611
32.8k
  CURLcode result = CURLE_OK;
1612
32.8k
  struct UserDefined *s = &data->set;
1613
32.8k
  switch(option) {
1614
142
  case CURLOPT_PROXYUSERPWD: {
1615
    /*
1616
     * user:password needed to use the proxy
1617
     */
1618
142
    char *u = NULL;
1619
142
    char *p = NULL;
1620
142
    result = setstropt_userpwd(ptr, &u, &p);
1621
1622
    /* URL decode the components */
1623
142
    if(!result) {
1624
142
      char *str = NULL;
1625
142
      CURL_EASY_STR_CLEAR(data, STRING_PROXYUSERNAME);
1626
142
      CURL_EASY_STR_CLEAR(data, STRING_PROXYPASSWORD);
1627
142
      if(u) {
1628
142
        result = Curl_urldecode(u, 0, &str, NULL, REJECT_ZERO);
1629
142
        if(!result)
1630
140
          result = Curl_u8_strset_setn(&s->strings, STRING_PROXYUSERNAME, str);
1631
142
      }
1632
142
      if(!result && p) {
1633
55
        str = NULL;
1634
55
        result = Curl_urldecode(p, 0, &str, NULL, REJECT_ZERO);
1635
55
        if(!result)
1636
54
          result = Curl_u8_strset_setn(&s->strings, STRING_PROXYPASSWORD, str);
1637
55
      }
1638
142
    }
1639
142
    curlx_free(u);
1640
142
    curlx_strzero(p);
1641
142
    curlx_free(p);
1642
142
    break;
1643
0
  }
1644
75
  case CURLOPT_PROXYUSERNAME:
1645
    /*
1646
     * authentication username to use in the operation
1647
     */
1648
75
    return Curl_setstropt(data, STRING_PROXYUSERNAME, ptr);
1649
1650
81
  case CURLOPT_PROXYPASSWORD:
1651
    /*
1652
     * authentication password to use in the operation
1653
     */
1654
81
    return Curl_setstropt(data, STRING_PROXYPASSWORD, ptr);
1655
1656
436
  case CURLOPT_NOPROXY:
1657
    /*
1658
     * proxy exception list
1659
     */
1660
436
    return Curl_setstropt(data, STRING_NOPROXY, ptr);
1661
40
  case CURLOPT_PROXY_SSLCERT:
1662
    /*
1663
     * String that holds filename of the SSL certificate to use for proxy
1664
     */
1665
40
    return Curl_setstropt(data, STRING_CERT_PROXY, ptr);
1666
45
  case CURLOPT_PROXY_SSLCERTTYPE:
1667
    /*
1668
     * String that holds file type of the SSL certificate to use for proxy
1669
     */
1670
45
    return Curl_setstropt(data, STRING_CERT_TYPE_PROXY, ptr);
1671
32
  case CURLOPT_PROXY_SSLKEY:
1672
    /*
1673
     * String that holds filename of the SSL key to use for proxy
1674
     */
1675
32
    return Curl_setstropt(data, STRING_KEY_PROXY, ptr);
1676
47
  case CURLOPT_PROXY_KEYPASSWD:
1677
    /*
1678
     * String that holds the SSL private key password for proxy.
1679
     */
1680
47
    return Curl_setstropt(data, STRING_KEY_PASSWD_PROXY, ptr);
1681
22
  case CURLOPT_PROXY_SSLKEYTYPE:
1682
    /*
1683
     * String that holds file type of the SSL key to use for proxy
1684
     */
1685
22
    return Curl_setstropt(data, STRING_KEY_TYPE_PROXY, ptr);
1686
7
  case CURLOPT_PROXY_SSL_CIPHER_LIST:
1687
7
    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
7
      return Curl_setstropt(data, STRING_SSL_CIPHER_LIST_PROXY, ptr);
1690
7
    }
1691
0
    else
1692
0
      return CURLE_NOT_BUILT_IN;
1693
23
  case CURLOPT_PROXY_TLS13_CIPHERS:
1694
23
    if(Curl_ssl_supports(data, SSLSUPP_TLS13_CIPHERSUITES))
1695
      /* set preferred list of TLS 1.3 cipher suites for proxy */
1696
23
      return Curl_setstropt(data, STRING_SSL_CIPHER13_LIST_PROXY, ptr);
1697
0
    else
1698
0
      return CURLE_NOT_BUILT_IN;
1699
3.22k
  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.22k
    return setproxy(data, ptr);
1711
253
  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
253
    return Curl_setstropt(data, STRING_PRE_PROXY, ptr);
1719
0
  case CURLOPT_SOCKS5_GSSAPI_SERVICE:
1720
43
  case CURLOPT_PROXY_SERVICE_NAME:
1721
    /*
1722
     * Set proxy authentication service name for Kerberos 5 and SPNEGO
1723
     */
1724
43
    return Curl_setstropt(data, STRING_PROXY_SERVICE_NAME, ptr);
1725
10
  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
10
#ifdef USE_SSL
1731
10
    if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY))
1732
10
      return Curl_setstropt(data, STRING_SSL_PINNEDPUBLICKEY_PROXY, ptr);
1733
0
#endif
1734
0
    return CURLE_NOT_BUILT_IN;
1735
1736
57
  case CURLOPT_HAPROXY_CLIENT_IP:
1737
    /*
1738
     * Set the client IP to send through HAProxy PROXY protocol
1739
     */
1740
57
    result = Curl_setstropt(data, STRING_HAPROXY_CLIENT_IP, ptr);
1741
1742
    /* enable the HAProxy protocol if an IP is provided */
1743
57
    s->haproxyprotocol = !!CURL_EASY_STR(data, STRING_HAPROXY_CLIENT_IP);
1744
57
    break;
1745
45
  case CURLOPT_PROXY_CAINFO:
1746
    /*
1747
     * Set CA info SSL connection for proxy. Specify filename of the
1748
     * CA certificate
1749
     */
1750
45
    result = Curl_setstropt(data, STRING_SSL_CAFILE_PROXY, ptr);
1751
45
    s->proxy_ssl.custom_cafile =
1752
45
      !!CURL_EASY_STR(data, STRING_SSL_CAFILE_PROXY);
1753
45
    return result;
1754
23
  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
23
    if(Curl_ssl_supports(data, SSLSUPP_CRLFILE))
1760
23
      return Curl_setstropt(data, STRING_SSL_CRLFILE_PROXY, ptr);
1761
0
    return CURLE_NOT_BUILT_IN;
1762
27
  case CURLOPT_PROXY_ISSUERCERT:
1763
    /*
1764
     * Set Issuer certificate file to check certificates issuer
1765
     */
1766
27
    if(Curl_ssl_supports(data, SSLSUPP_ISSUERCERT))
1767
27
      return Curl_setstropt(data, STRING_SSL_ISSUERCERT_PROXY, ptr);
1768
0
    return CURLE_NOT_BUILT_IN;
1769
11
  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
11
#ifdef USE_SSL
1775
11
    if(Curl_ssl_supports(data, SSLSUPP_CA_PATH)) {
1776
      /* This does not work on Windows. */
1777
11
      result = Curl_setstropt(data, STRING_SSL_CAPATH_PROXY, ptr);
1778
11
      s->proxy_ssl.custom_capath =
1779
11
        !!CURL_EASY_STR(data, STRING_SSL_CAPATH_PROXY);
1780
11
      return result;
1781
11
    }
1782
0
#endif
1783
0
    return CURLE_NOT_BUILT_IN;
1784
28.2k
  default:
1785
28.2k
    return CURLE_UNKNOWN_OPTION;
1786
32.8k
  }
1787
199
  return result;
1788
32.8k
}
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
301
{
1839
301
  struct UserDefined *s = &data->set;
1840
301
  CURLcode result = CURLE_OK;
1841
1842
301
  if(!ptr || !strcmp(ptr, "false"))
1843
1
    s->tls_ech = CURLECH_DISABLE;
1844
300
  else {
1845
300
    size_t plen = strlen(ptr);
1846
300
    if(plen > CURL_MAX_INPUT_LENGTH)
1847
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1848
300
    else {
1849
300
      if(!strcmp(ptr, "grease"))
1850
15
        s->tls_ech = CURLECH_GREASE;
1851
285
      else if(!strcmp(ptr, "true"))
1852
2
        s->tls_ech = CURLECH_ENABLE;
1853
283
      else if(!strcmp(ptr, "hard"))
1854
2
        s->tls_ech = CURLECH_HARD;
1855
281
      else if(plen > 4 && !strncmp(ptr, "ecl:", 4)) {
1856
127
        if(!s->tls_ech)
1857
127
          s->tls_ech = CURLECH_HARD;
1858
127
        result = Curl_setstropt(data, STRING_ECH_CONFIG, ptr + 4);
1859
127
      }
1860
154
      else if(plen > 3 && !strncmp(ptr, "pn:", 3)) {
1861
11
        if(!s->tls_ech)
1862
11
          s->tls_ech = CURLECH_HARD;
1863
11
        result = Curl_setstropt(data, STRING_ECH_PUBLIC, ptr + 3);
1864
11
      }
1865
143
      else
1866
143
        result = CURLE_BAD_FUNCTION_ARGUMENT;
1867
300
    }
1868
300
  }
1869
301
  return result;
1870
301
}
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
48.7k
{
1880
48.7k
  CURLcode result = CURLE_OK;
1881
1882
48.7k
  switch(option) {
1883
25
  case CURLOPT_KEYPASSWD:
1884
    /*
1885
     * String that holds the SSL or SSH private key password.
1886
     */
1887
25
    result = Curl_setstropt(data, STRING_KEY_PASSWD, ptr);
1888
25
    break;
1889
0
#ifdef USE_SSL
1890
52
  case CURLOPT_CAINFO:
1891
    /*
1892
     * Set CA info for SSL connection. Specify filename of the CA certificate
1893
     */
1894
52
    result = Curl_setstropt(data, STRING_SSL_CAFILE, ptr);
1895
52
    data->set.ssl.custom_cafile = !!CURL_EASY_STR(data, STRING_SSL_CAFILE);
1896
52
    return result;
1897
119
  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
119
    if(Curl_ssl_supports(data, SSLSUPP_CA_PATH)) {
1903
      /* This does not work on Windows. */
1904
119
      result = Curl_setstropt(data, STRING_SSL_CAPATH, ptr);
1905
119
      data->set.ssl.custom_capath = !!CURL_EASY_STR(data, STRING_SSL_CAPATH);
1906
119
      return result;
1907
119
    }
1908
0
    return CURLE_NOT_BUILT_IN;
1909
12.5k
  case CURLOPT_CRLFILE:
1910
    /*
1911
     * Set CRL file info for SSL connection. Specify filename of the CRL
1912
     * to check certificates revocation
1913
     */
1914
12.5k
    if(Curl_ssl_supports(data, SSLSUPP_CRLFILE))
1915
12.5k
      return Curl_setstropt(data, STRING_SSL_CRLFILE, ptr);
1916
0
    return CURLE_NOT_BUILT_IN;
1917
930
  case CURLOPT_SSL_CIPHER_LIST:
1918
930
    if(Curl_ssl_supports(data, SSLSUPP_CIPHER_LIST))
1919
      /* set a list of cipher we want to use in the SSL connection */
1920
930
      return Curl_setstropt(data, STRING_SSL_CIPHER_LIST, ptr);
1921
0
    else
1922
0
      return CURLE_NOT_BUILT_IN;
1923
166
  case CURLOPT_TLS13_CIPHERS:
1924
166
    if(Curl_ssl_supports(data, SSLSUPP_TLS13_CIPHERSUITES))
1925
      /* set preferred list of TLS 1.3 cipher suites */
1926
166
      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
84
  case CURLOPT_SSLCERT:
1944
    /*
1945
     * String that holds filename of the SSL certificate to use
1946
     */
1947
84
    return Curl_setstropt(data, STRING_CERT, ptr);
1948
93
  case CURLOPT_SSLCERTTYPE:
1949
    /*
1950
     * String that holds file type of the SSL certificate to use
1951
     */
1952
93
    return Curl_setstropt(data, STRING_CERT_TYPE, ptr);
1953
26
  case CURLOPT_SSLKEY:
1954
    /*
1955
     * String that holds filename of the SSL key to use
1956
     */
1957
26
    return Curl_setstropt(data, STRING_KEY, ptr);
1958
30
  case CURLOPT_SSLKEYTYPE:
1959
    /*
1960
     * String that holds file type of the SSL key to use
1961
     */
1962
30
    return Curl_setstropt(data, STRING_KEY_TYPE, ptr);
1963
945
  case CURLOPT_SSLENGINE:
1964
    /*
1965
     * String that holds the SSL crypto engine.
1966
     */
1967
945
    if(ptr && ptr[0]) {
1968
943
      result = Curl_setstropt(data, STRING_SSL_ENGINE, ptr);
1969
943
      if(!result) {
1970
943
        result = Curl_ssl_set_engine(data, ptr);
1971
943
      }
1972
943
    }
1973
945
    break;
1974
29
  case CURLOPT_ISSUERCERT:
1975
    /*
1976
     * Set Issuer certificate file
1977
     * to check certificates issuer
1978
     */
1979
29
    if(Curl_ssl_supports(data, SSLSUPP_ISSUERCERT))
1980
29
      return Curl_setstropt(data, STRING_SSL_ISSUERCERT, ptr);
1981
0
    return CURLE_NOT_BUILT_IN;
1982
794
  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
794
    if(Curl_ssl_supports(data, SSLSUPP_SSL_EC_CURVES))
1988
794
      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
21
  case CURLOPT_PINNEDPUBLICKEY:
1999
    /*
2000
     * Set pinned public key for SSL connection.
2001
     * Specify filename of the public key in DER format.
2002
     */
2003
21
    if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY))
2004
21
      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
32.8k
  default:
2010
32.8k
    return CURLE_UNKNOWN_OPTION;
2011
48.7k
  }
2012
970
  return result;
2013
48.7k
}
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
27.6k
{
2020
27.6k
  CURLcode result = CURLE_OK;
2021
27.6k
  struct UserDefined *s = &data->set;
2022
2023
27.6k
  switch(option) {
2024
0
  case CURLOPT_COPYPOSTFIELDS:
2025
0
    return setopt_copypostfields(ptr, s);
2026
2027
38
  case CURLOPT_POSTFIELDS:
2028
    /*
2029
     * Like above, but use static data instead of copying it.
2030
     */
2031
38
    s->postfields = ptr;
2032
    /* Release old copied data. */
2033
38
    curlx_safefree(s->str_copypostfields);
2034
38
    s->method = HTTPREQ_POST;
2035
38
    break;
2036
2037
0
#ifndef CURL_DISABLE_HTTP
2038
0
  case CURLOPT_TRAILERDATA:
2039
0
    s->trailer_data = ptr;
2040
0
    break;
2041
72
  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
72
    if(ptr && !*ptr) {
2052
17
      ptr = Curl_get_content_encodings();
2053
17
      if(ptr)
2054
17
        result = CURL_EASY_STR_SETN(data, STRING_ENCODING, ptr);
2055
0
      else
2056
0
        result = CURLE_OUT_OF_MEMORY;
2057
17
      return result;
2058
17
    }
2059
55
    return Curl_setstropt(data, STRING_ENCODING, ptr);
2060
2061
0
#ifndef CURL_DISABLE_AWS
2062
637
  case CURLOPT_AWS_SIGV4:
2063
    /*
2064
     * String that is merged to some authentication
2065
     * parameters are used by the algorithm.
2066
     */
2067
637
    result = Curl_setstropt(data, STRING_AWS_SIGV4, ptr);
2068
    /*
2069
     * Basic has been set by default; it needs to be unset here.
2070
     */
2071
637
    if(CURL_EASY_STR(data, STRING_AWS_SIGV4))
2072
637
      s->httpauth = CURLAUTH_AWS_SIGV4;
2073
0
    else
2074
0
      s->httpauth &= ~(uint32_t)CURLAUTH_AWS_SIGV4;
2075
637
    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
16
  case CURLOPT_REFERER: {
2089
    /*
2090
     * String to set in the HTTP Referer: field.
2091
     */
2092
16
    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
16
    result = Curl_setstropt(data, STRING_SET_REFERER, ptr);
2096
16
    Curl_bufref_free(oldref);
2097
16
    break;
2098
72
  }
2099
2100
54
  case CURLOPT_USERAGENT:
2101
    /*
2102
     * String to use in the HTTP User-Agent field
2103
     */
2104
54
    return Curl_setstropt(data, STRING_USERAGENT, ptr);
2105
2106
0
#ifndef CURL_DISABLE_COOKIES
2107
35
  case CURLOPT_COOKIE:
2108
    /*
2109
     * Cookie string to send to the remote server in the request.
2110
     */
2111
35
    return Curl_setstropt(data, STRING_COOKIE, ptr);
2112
2113
12.5k
  case CURLOPT_COOKIEFILE:
2114
12.5k
    return cookiefile(data, ptr);
2115
2116
12.5k
  case CURLOPT_COOKIEJAR:
2117
    /*
2118
     * Set cookie filename to dump all cookies to when we are done.
2119
     */
2120
12.5k
    result = Curl_setstropt(data, STRING_COOKIEJAR, ptr);
2121
12.5k
    if(!result) {
2122
      /*
2123
       * Activate the cookie parser. This may or may not already
2124
       * have been made.
2125
       */
2126
12.5k
      if(!data->cookies)
2127
10.7k
        data->cookies = Curl_cookie_init();
2128
12.5k
      if(!data->cookies)
2129
0
        result = CURLE_OUT_OF_MEMORY;
2130
12.5k
      else
2131
12.5k
        data->state.cookie_engine = TRUE;
2132
12.5k
    }
2133
12.5k
    break;
2134
2135
1.78k
  case CURLOPT_COOKIELIST:
2136
1.78k
    return cookielist(data, ptr);
2137
0
#endif /* !CURL_DISABLE_COOKIES */
2138
2139
0
#endif /* !CURL_DISABLE_HTTP */
2140
14
  default:
2141
14
    return CURLE_UNKNOWN_OPTION;
2142
27.6k
  }
2143
13.2k
  return result;
2144
27.6k
}
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
27.7k
{
2205
27.7k
  CURLcode result = CURLE_OK;
2206
27.7k
  struct UserDefined *s = &data->set;
2207
27.7k
  switch(option) {
2208
32
  case CURLOPT_FTPPORT:
2209
    /*
2210
     * Use FTP PORT, this also specifies which IP address to use
2211
     */
2212
32
    result = Curl_setstropt(data, STRING_FTPPORT, ptr);
2213
32
    s->ftp_use_port = !!CURL_EASY_STR(data, STRING_FTPPORT);
2214
32
    break;
2215
2216
19
  case CURLOPT_FTP_ACCOUNT:
2217
19
    return Curl_setstropt(data, STRING_FTP_ACCOUNT, ptr);
2218
2219
38
  case CURLOPT_FTP_ALTERNATIVE_TO_USER:
2220
38
    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
27.6k
  default:
2231
27.6k
    return CURLE_UNKNOWN_OPTION;
2232
27.7k
  }
2233
32
  return result;
2234
27.7k
}
2235
#endif /* !CURL_DISABLE_FTP */
2236
2237
static CURLcode setopt_cptr_net(struct Curl_easy *data, CURLoption option,
2238
                                char *ptr)
2239
28.2k
{
2240
28.2k
  switch(option) {
2241
327
  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
327
    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
55
  case CURLOPT_UNIX_SOCKET_PATH:
2263
55
    data->set.abstract_unix_socket = FALSE;
2264
55
    return Curl_setstropt(data, STRING_UNIX_SOCKET_PATH, ptr);
2265
2266
52
  case CURLOPT_ABSTRACT_UNIX_SOCKET:
2267
52
    data->set.abstract_unix_socket = TRUE;
2268
52
    return Curl_setstropt(data, STRING_UNIX_SOCKET_PATH, ptr);
2269
0
#endif
2270
0
#ifndef CURL_DISABLE_DOH
2271
42
  case CURLOPT_DOH_URL:
2272
42
    {
2273
42
      CURLcode result = Curl_setstropt(data, STRING_DOH, ptr);
2274
42
      data->set.doh = !!CURL_EASY_STR(data, STRING_DOH);
2275
42
      return result;
2276
0
    }
2277
0
#endif
2278
27.7k
  default:
2279
27.7k
    return CURLE_UNKNOWN_OPTION;
2280
28.2k
  }
2281
28.2k
}
2282
2283
static CURLcode setopt_cptr_misc(struct Curl_easy *data, CURLoption option,
2284
                                 char *ptr)
2285
147k
{
2286
147k
  CURLcode result = CURLE_OK;
2287
147k
  struct UserDefined *s = &data->set;
2288
2289
147k
  switch(option) {
2290
31
  case CURLOPT_REQUEST_TARGET:
2291
31
    return Curl_setstropt(data, STRING_TARGET, ptr);
2292
0
#ifndef CURL_DISABLE_NETRC
2293
12.5k
  case CURLOPT_NETRC_FILE:
2294
12.5k
    return Curl_setstropt(data, STRING_NETRC_FILE, ptr);
2295
0
#endif
2296
28
  case CURLOPT_CUSTOMREQUEST:
2297
28
    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
56
  case CURLOPT_SERVICE_NAME:
2303
56
    return Curl_setstropt(data, STRING_SERVICE_NAME, ptr);
2304
2305
0
  case CURLOPT_HEADERDATA:
2306
0
    s->writeheader = ptr;
2307
0
    break;
2308
12.5k
  case CURLOPT_READDATA:
2309
12.5k
    s->in_set = ptr;
2310
12.5k
    break;
2311
12.5k
  case CURLOPT_WRITEDATA:
2312
12.5k
    s->out = ptr;
2313
12.5k
    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
12.5k
  case CURLOPT_OPENSOCKETDATA:
2330
12.5k
    s->opensocket_client = ptr;
2331
12.5k
    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
9.69k
  case CURLOPT_URL:
2345
9.69k
    result = Curl_setstropt(data, STRING_SET_URL, ptr);
2346
9.69k
    Curl_bufref_set(&data->state.url,
2347
9.69k
                    CURL_EASY_STR(data, STRING_SET_URL), 0, NULL);
2348
9.69k
    break;
2349
2350
111
  case CURLOPT_USERPWD: {
2351
111
    char *u = NULL, *p = NULL;
2352
111
    result = setstropt_userpwd(ptr, &u, &p);
2353
111
    if(!result) {
2354
111
      result = CURL_EASY_STR_SETN(data, STRING_USERNAME, u);
2355
111
      u = NULL;
2356
111
    }
2357
111
    if(!result) {
2358
111
      result = CURL_EASY_STR_SETN(data, STRING_PASSWORD, p);
2359
111
      p = NULL;
2360
111
    }
2361
111
    curlx_free(u);
2362
111
    curlx_free(p);
2363
111
    return result;
2364
0
  }
2365
2366
53
  case CURLOPT_USERNAME:
2367
53
    return Curl_setstropt(data, STRING_USERNAME, ptr);
2368
2369
101
  case CURLOPT_PASSWORD:
2370
101
    return Curl_setstropt(data, STRING_PASSWORD, ptr);
2371
2372
91
  case CURLOPT_LOGIN_OPTIONS:
2373
91
    return Curl_setstropt(data, STRING_OPTIONS, ptr);
2374
2375
55
  case CURLOPT_XOAUTH2_BEARER:
2376
55
    return Curl_setstropt(data, STRING_BEARER, ptr);
2377
30
  case CURLOPT_RANGE:
2378
30
    return Curl_setstropt(data, STRING_SET_RANGE, ptr);
2379
0
  case CURLOPT_PRIVATE:
2380
0
    s->private_data = ptr;
2381
0
    break;
2382
12.5k
  case CURLOPT_PROTOCOLS_STR:
2383
12.5k
    if(ptr) {
2384
12.5k
      curl_prot_t protos;
2385
12.5k
      result = protocol2num(ptr, &protos);
2386
12.5k
      if(!result)
2387
12.5k
        s->allowed_protocols = protos;
2388
12.5k
    }
2389
0
    else
2390
      /* make a NULL argument reset to default */
2391
0
      s->allowed_protocols = (curl_prot_t)CURLPROTO_64ALL;
2392
12.5k
    break;
2393
319
  case CURLOPT_REDIR_PROTOCOLS_STR:
2394
319
    if(ptr) {
2395
319
      curl_prot_t protos;
2396
319
      result = protocol2num(ptr, &protos);
2397
319
      if(!result)
2398
45
        s->redir_protocols = protos;
2399
319
    }
2400
0
    else
2401
      /* make a NULL argument reset to default */
2402
0
      s->redir_protocols = (curl_prot_t)CURLPROTO_REDIR;
2403
319
    break;
2404
124
  case CURLOPT_DEFAULT_PROTOCOL:
2405
    /* Set the protocol to use when the URL does not include any protocol */
2406
124
    return Curl_setstropt(data, STRING_DEFAULT_PROTOCOL, ptr);
2407
0
#ifndef CURL_DISABLE_SMTP
2408
36
  case CURLOPT_MAIL_FROM:
2409
    /* Set the SMTP mail originator */
2410
36
    return Curl_setstropt(data, STRING_MAIL_FROM, ptr);
2411
26
  case CURLOPT_MAIL_AUTH:
2412
    /* Set the SMTP auth originator */
2413
26
    return Curl_setstropt(data, STRING_MAIL_AUTH, ptr);
2414
0
#endif
2415
45
  case CURLOPT_SASL_AUTHZID:
2416
    /* Authorization identity (identity to act as) */
2417
45
    return Curl_setstropt(data, STRING_SASL_AUTHZID, ptr);
2418
0
#ifndef CURL_DISABLE_RTSP
2419
39
  case CURLOPT_RTSP_SESSION_ID:
2420
39
    return Curl_setstropt(data, STRING_RTSP_SESSION_ID, ptr);
2421
26
  case CURLOPT_RTSP_STREAM_URI:
2422
26
    return Curl_setstropt(data, STRING_RTSP_STREAM_URI, ptr);
2423
28
  case CURLOPT_RTSP_TRANSPORT:
2424
28
    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
4
  case CURLOPT_TLSAUTH_PASSWORD:
2431
5
  case CURLOPT_TLSAUTH_TYPE:
2432
7
  case CURLOPT_PROXY_TLSAUTH_USERNAME:
2433
10
  case CURLOPT_PROXY_TLSAUTH_PASSWORD:
2434
13
  case CURLOPT_PROXY_TLSAUTH_TYPE:
2435
13
    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
12.5k
  case CURLOPT_HSTS: {
2444
12.5k
    struct curl_slist *h;
2445
12.5k
    if(!data->hsts) {
2446
12.5k
      data->hsts = Curl_hsts_init();
2447
12.5k
      if(!data->hsts)
2448
0
        return CURLE_OUT_OF_MEMORY;
2449
12.5k
    }
2450
12.5k
    if(ptr) {
2451
12.5k
      result = Curl_setstropt(data, STRING_HSTS, ptr);
2452
12.5k
      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
12.5k
      h = curl_slist_append(data->state.hstslist, ptr);
2458
12.5k
      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
12.5k
      data->state.hstslist = h; /* store the list for later use */
2464
12.5k
    }
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
12.5k
    break;
2474
12.5k
  }
2475
12.5k
#endif /* !CURL_DISABLE_HSTS */
2476
12.5k
#ifndef CURL_DISABLE_ALTSVC
2477
12.5k
  case CURLOPT_ALTSVC:
2478
12.5k
    if(!data->asi) {
2479
12.4k
      data->asi = Curl_altsvc_init();
2480
12.4k
      if(!data->asi)
2481
0
        return CURLE_OUT_OF_MEMORY;
2482
12.4k
    }
2483
12.5k
    result = Curl_setstropt(data, STRING_ALTSVC, ptr);
2484
12.5k
    if(result)
2485
0
      break;
2486
12.5k
    if(ptr)
2487
12.5k
      return Curl_altsvc_load(data->asi, ptr);
2488
0
    break;
2489
0
#endif /* !CURL_DISABLE_ALTSVC */
2490
301
  case CURLOPT_ECH:
2491
301
    return setopt_ech(data, ptr);
2492
48.7k
  default:
2493
48.7k
    return CURLE_UNKNOWN_OPTION;
2494
147k
  }
2495
72.5k
  return result;
2496
147k
}
2497
2498
static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option,
2499
                            char *ptr)
2500
147k
{
2501
147k
  typedef CURLcode (*ptrfunc)(struct Curl_easy *data, CURLoption option,
2502
147k
                              char *ptr);
2503
  /* Order by likeliness */
2504
147k
  static const ptrfunc setopt_call[] = {
2505
147k
    setopt_cptr_misc,
2506
147k
#if defined(USE_SSL) || defined(USE_SSH)
2507
147k
    setopt_cptr_ssl,
2508
147k
#endif
2509
147k
#ifndef CURL_DISABLE_PROXY
2510
147k
    setopt_cptr_proxy,
2511
147k
#endif
2512
147k
    setopt_cptr_net,
2513
147k
#ifndef CURL_DISABLE_FTP
2514
147k
    setopt_cptr_ftp,
2515
147k
#endif
2516
#ifdef USE_SSH
2517
    setopt_cptr_ssh,
2518
#endif
2519
147k
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_MQTT)
2520
147k
    setopt_cptr_http_mqtt,
2521
147k
#endif
2522
147k
  };
2523
147k
  size_t i;
2524
2525
312k
  for(i = 0; i < CURL_ARRAYSIZE(setopt_call); i++) {
2526
312k
    CURLcode result = setopt_call[i](data, option, ptr);
2527
312k
    if(result != CURLE_UNKNOWN_OPTION)
2528
147k
      return result;
2529
312k
  }
2530
14
  return CURLE_UNKNOWN_OPTION;
2531
147k
}
2532
2533
static CURLcode setopt_func(struct Curl_easy *data, CURLoption option,
2534
                            va_list param)
2535
50.0k
{
2536
50.0k
  struct UserDefined *s = &data->set;
2537
50.0k
  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
12.5k
  case CURLOPT_WRITEFUNCTION:
2576
    /*
2577
     * Set data write callback
2578
     */
2579
12.5k
    s->fwrite_func = va_arg(param, curl_write_callback);
2580
12.5k
    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
12.5k
#if defined(__clang__) && __clang_major__ >= 16
2588
12.5k
#pragma clang diagnostic pop
2589
12.5k
#endif
2590
12.5k
    break;
2591
12.5k
  case CURLOPT_READFUNCTION:
2592
    /*
2593
     * Read data callback
2594
     */
2595
12.5k
    s->fread_func_set = va_arg(param, curl_read_callback);
2596
12.5k
    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
12.5k
    else
2609
12.5k
      s->is_fread_set = 1;
2610
12.5k
    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
12.5k
  case CURLOPT_SOCKOPTFUNCTION:
2637
    /*
2638
     * socket callback function: called after socket() but before connect()
2639
     */
2640
12.5k
    s->fsockopt = va_arg(param, curl_sockopt_callback);
2641
12.5k
    break;
2642
2643
12.5k
  case CURLOPT_OPENSOCKETFUNCTION:
2644
    /*
2645
     * open/create socket callback function: called instead of socket(),
2646
     * before connect()
2647
     */
2648
12.5k
    s->fopensocket = va_arg(param, curl_opensocket_callback);
2649
12.5k
    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
50.0k
  }
2719
50.0k
  return CURLE_OK;
2720
50.0k
}
2721
2722
static CURLcode setopt_offt(struct Curl_easy *data, CURLoption option,
2723
                            curl_off_t offt)
2724
561
{
2725
561
  struct UserDefined *s = &data->set;
2726
561
  switch(option) {
2727
3
  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
3
    s->timevalue = (time_t)offt;
2733
3
    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
44
  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
44
    if(offt < -1)
2757
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2758
44
    s->filesize = offt;
2759
44
    break;
2760
99
  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
99
    if(offt < 0)
2766
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2767
99
    s->max_send_speed = offt;
2768
    /* use minimal burst rate of 32k. some protocol batch IO */
2769
99
    Curl_rlimit_init(&data->progress.ul.rlimit, offt,
2770
99
                     CURLMAX(offt, (32 * 1024)),
2771
99
                     Curl_pgrs_now(data));
2772
99
    break;
2773
282
  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
282
    if(offt < 0)
2779
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2780
282
    s->max_recv_speed = offt;
2781
    /* use minimal burst rate of 32k. some protocol batch IO */
2782
282
    Curl_rlimit_init(&data->progress.dl.rlimit, offt,
2783
282
                     CURLMAX(offt, (32 * 1024)),
2784
282
                     Curl_pgrs_now(data));
2785
282
    break;
2786
68
  case CURLOPT_RESUME_FROM_LARGE:
2787
    /*
2788
     * Resume transfer at the given file position
2789
     */
2790
68
    if(offt < -1)
2791
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2792
68
    s->set_resume_from = offt;
2793
68
    break;
2794
65
  case CURLOPT_MAXFILESIZE_LARGE:
2795
    /*
2796
     * Set the maximum size of a file to download.
2797
     */
2798
65
    if(offt < 0)
2799
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2800
65
    s->max_filesize = offt;
2801
65
    break;
2802
2803
0
  default:
2804
0
    return CURLE_UNKNOWN_OPTION;
2805
561
  }
2806
561
  return CURLE_OK;
2807
561
}
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
241k
{
2889
241k
  if(option < CURLOPTTYPE_OBJECTPOINT)
2890
29.9k
    return setopt_long(data, option, va_arg(param, long));
2891
211k
  else if(option < CURLOPTTYPE_FUNCTIONPOINT) {
2892
    /* unfortunately, different pointer types cannot be identified any other
2893
       way than being listed explicitly */
2894
160k
    switch(option) {
2895
518
    case CURLOPT_HTTPHEADER:
2896
518
    case CURLOPT_QUOTE:
2897
518
    case CURLOPT_POSTQUOTE:
2898
518
    case CURLOPT_TELNETOPTIONS:
2899
518
    case CURLOPT_PREQUOTE:
2900
518
    case CURLOPT_HTTP200ALIASES:
2901
563
    case CURLOPT_MAIL_RCPT:
2902
563
    case CURLOPT_RESOLVE:
2903
563
    case CURLOPT_PROXYHEADER:
2904
13.0k
    case CURLOPT_CONNECT_TO:
2905
13.0k
      return setopt_slist(data, option, va_arg(param, struct curl_slist *));
2906
104
    case CURLOPT_HTTPPOST:         /* curl_httppost * */
2907
308
    case CURLOPT_MIMEPOST:         /* curl_mime * */
2908
308
    case CURLOPT_STDERR:           /* FILE * */
2909
308
    case CURLOPT_SHARE:            /* CURLSH * */
2910
308
    case CURLOPT_CURLU:            /* CURLU * */
2911
308
      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
147k
    default:
2916
147k
      break;
2917
160k
    }
2918
    /* the char pointer options */
2919
147k
    return setopt_cptr(data, option, va_arg(param, char *));
2920
160k
  }
2921
50.6k
  else if(option < CURLOPTTYPE_OFF_T)
2922
50.0k
    return setopt_func(data, option, param);
2923
561
  else if(option < CURLOPTTYPE_BLOB)
2924
561
    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
241k
}
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
241k
{
2938
241k
  struct Curl_eapi_guard guard;
2939
241k
  CURLcode result;
2940
2941
241k
  if(CURL_EAPI_ENTER(&guard, curl, easy_setopt, &result)) {
2942
241k
    struct Curl_easy *data = curl;
2943
241k
    va_list arg;
2944
2945
241k
    va_start(arg, option);
2946
2947
241k
    result = Curl_vsetopt(data, option, arg);
2948
2949
241k
    va_end(arg);
2950
241k
    if(result == CURLE_BAD_FUNCTION_ARGUMENT)
2951
687
      failf(data, "setopt 0x%x got bad argument", (unsigned int)option);
2952
241k
  }
2953
241k
  CURL_EAPI_LEAVE(&guard);
2954
241k
  return result;
2955
241k
}