Coverage Report

Created: 2026-09-14 07:04

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