Coverage Report

Created: 2026-12-01 06:27

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