Coverage Report

Created: 2026-10-15 06:17

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