Coverage Report

Created: 2026-10-22 06:49

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
0
{
69
0
  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
0
  *ptimeout_ms = (timediff_t)ms;
78
0
  return CURLE_OK;
79
0
}
80
81
CURLcode Curl_setstropt(struct Curl_easy *data,
82
                        enum dupstring id, const char *s)
83
0
{
84
0
  size_t slen = s ? strlen(s) : 0;
85
0
  DEBUGASSERT((unsigned)id <= UINT8_MAX);
86
0
  if(s && (slen > CURL_MAX_INPUT_LENGTH))
87
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
88
89
0
  return CURL_EASY_STR_SET(data, (uint8_t)id, s, slen);
90
0
}
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
0
{
126
0
  char *user = NULL;
127
0
  char *passwd = NULL;
128
129
0
  DEBUGASSERT(userp);
130
0
  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
0
  if(option) {
135
0
    size_t len = strlen(option);
136
0
    CURLcode result;
137
0
    if(len > CURL_MAX_INPUT_LENGTH)
138
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
139
140
0
    result = Curl_parse_login_details(option, len, &user, &passwd, NULL);
141
0
    if(result)
142
0
      return result;
143
0
  }
144
145
0
  curlx_free(*userp);
146
0
  *userp = user;
147
148
0
  curlx_strzero(*passwdp);
149
0
  curlx_free(*passwdp);
150
0
  *passwdp = passwd;
151
152
0
  return CURLE_OK;
153
0
}
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
2
#define C_SSLVERSION_VALUE(x)     ((x) & 0xffff)
173
2
#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
0
{
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
0
  *val = 0;
183
184
0
  if(!str)
185
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
186
187
0
  if(curl_strequal(str, "all")) {
188
0
    *val = ~(curl_prot_t)0;
189
0
    return CURLE_OK;
190
0
  }
191
192
0
  do {
193
0
    const char *token = str;
194
0
    size_t tlen;
195
196
0
    str = strchr(str, ',');
197
0
    tlen = str ? (size_t)(str - token) : strlen(token);
198
0
    if(tlen) {
199
0
      const struct Curl_scheme *h = Curl_getn_scheme(token, tlen);
200
201
0
      if(!h || !h->run)
202
0
        return CURLE_UNSUPPORTED_PROTOCOL;
203
204
0
      *val |= h->protocol;
205
0
    }
206
0
  } while(str && str++);
207
208
0
  if(!*val)
209
    /* no protocol listed */
210
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
211
0
  return CURLE_OK;
212
0
}
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
2
{
296
  /*
297
   * Set explicit SSL version to try to connect with, as some SSL
298
   * implementations are lame.
299
   */
300
2
  {
301
2
    long version, version_max;
302
2
    struct ssl_easy_config *sslc = &data->set.ssl;
303
2
#ifndef CURL_DISABLE_PROXY
304
2
    if(option != CURLOPT_SSLVERSION)
305
1
      sslc = &data->set.proxy_ssl;
306
#else
307
    (void)option; /* unused */
308
#endif
309
2
    version = C_SSLVERSION_VALUE(arg);
310
2
    version_max = (long)C_SSLVERSION_MAX_VALUE(arg);
311
312
2
    if(version < CURL_SSLVERSION_DEFAULT ||
313
2
       version == CURL_SSLVERSION_SSLv2 ||
314
2
       version == CURL_SSLVERSION_SSLv3 ||
315
2
       version >= CURL_SSLVERSION_LAST ||
316
2
       version_max < CURL_SSLVERSION_MAX_NONE ||
317
2
       version_max >= CURL_SSLVERSION_MAX_LAST)
318
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
319
2
    if(version == CURL_SSLVERSION_DEFAULT)
320
2
      version = CURL_SSLVERSION_TLSv1_2;
321
322
2
    sslc->version = (unsigned char)version;
323
2
    sslc->version_max = (unsigned int)version_max;
324
2
  }
325
0
  return CURLE_OK;
326
2
}
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
0
{
347
0
  bool enabled = !!arg;
348
0
  int ok = 1;
349
0
  struct UserDefined *s = &data->set;
350
0
  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
0
  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
0
    s->verbose = enabled;
371
0
    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
0
  case CURLOPT_CRLF:
578
    /*
579
     * Kludgy option to enable CRLF conversions. Subject for removal.
580
     */
581
0
    s->crlf = enabled;
582
0
    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
0
  case CURLOPT_SSL_VERIFYPEER:
602
    /*
603
     * Enable peer SSL verifying.
604
     */
605
0
    s->ssl.verifypeer = enabled;
606
607
    /* Update the current connection ssl_config. */
608
0
    Curl_ssl_conn_config_update(data, FALSE);
609
0
    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
0
  default:
742
0
    return CURLE_UNKNOWN_OPTION;
743
0
  }
744
0
  if((arg > ok) || (arg < 0))
745
    /* reserve other values for future use */
746
0
    infof(data, "boolean setopt(%d) got unsupported argument %ld,"
747
0
          " treated as %d", (int)option, arg, enabled);
748
749
0
  return CURLE_OK;
750
0
}
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
0
{
766
0
  CURLcode result = CURLE_OK;
767
0
  struct UserDefined *s = &data->set;
768
769
0
  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
0
  case CURLOPT_TIMEOUT_MS:
803
0
    return setopt_set_timeout_ms(&s->timeout, arg);
804
0
  case CURLOPT_CONNECTTIMEOUT:
805
0
    return setopt_set_timeout_sec(&s->connecttimeout, arg);
806
0
  case CURLOPT_CONNECTTIMEOUT_MS:
807
0
    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
0
  }
889
0
  return result;
890
0
}
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
#ifdef USE_OPENSSL
934
0
    if(Curl_ssl_backend() != CURLSSLBACKEND_OPENSSL)
935
0
      return CURLE_NOT_BUILT_IN;
936
0
    data->set.engine_default = (arg == 1);
937
#else
938
    return CURLE_NOT_BUILT_IN;
939
#endif
940
0
    break;
941
0
  default:
942
0
    return CURLE_UNKNOWN_OPTION;
943
0
  }
944
0
  return result;
945
#else  /* USE_SSL */
946
  (void)data;
947
  (void)option;
948
  (void)arg;
949
  return CURLE_UNKNOWN_OPTION;
950
#endif /* !USE_SSL */
951
0
}
952
953
#ifndef CURL_DISABLE_PROXY
954
static void changeproxy(struct Curl_easy *data)
955
0
{
956
0
  Curl_auth_digest_cleanup(&data->state.proxydigest);
957
0
  memset(&data->state.authproxy, 0, sizeof(data->state.authproxy));
958
0
}
959
960
static CURLcode setopt_long_proxy(struct Curl_easy *data, CURLoption option,
961
                                  long arg)
962
0
{
963
0
  struct UserDefined *s = &data->set;
964
965
0
  switch(option) {
966
0
  case CURLOPT_PROXYPORT:
967
0
    if((arg < 0) || (arg > UINT16_MAX))
968
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
969
0
    if(arg != s->proxyport)
970
0
      changeproxy(data);
971
0
    s->proxyport = (uint16_t)arg;
972
0
    break;
973
0
  case CURLOPT_PROXYAUTH:
974
0
    return httpauth(data, TRUE, (unsigned long)arg);
975
0
  case CURLOPT_PROXYTYPE:
976
0
    if((arg < CURLPROXY_HTTP) || (arg > CURLPROXY_HTTPS3))
977
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
978
0
#ifndef USE_PROXY_HTTP3
979
0
    if(arg == CURLPROXY_HTTPS3)
980
0
      return CURLE_NOT_BUILT_IN;
981
0
#endif
982
0
    s->proxytype = (unsigned char)arg;
983
0
    break;
984
0
  case CURLOPT_SOCKS5_AUTH: {
985
0
    unsigned long auth = (unsigned long)arg;
986
0
    if(auth & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI | CURLAUTH_ONLY))
987
0
      return CURLE_NOT_BUILT_IN;
988
0
    if((auth & CURLAUTH_ONLY) && !(auth & (CURLAUTH_BASIC | CURLAUTH_GSSAPI)))
989
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
990
0
    s->socks5auth = (unsigned char)(auth & (CURLAUTH_BASIC | CURLAUTH_GSSAPI));
991
0
    s->socks5_auth_only = !!(auth & CURLAUTH_ONLY);
992
0
    break;
993
0
  }
994
0
  default:
995
0
    return CURLE_UNKNOWN_OPTION;
996
0
  }
997
0
  return CURLE_OK;
998
0
}
999
#else
1000
static CURLcode setopt_long_proxy(struct Curl_easy *data, CURLoption option,
1001
                                  long arg)
1002
{
1003
  (void)data;
1004
  (void)option;
1005
  (void)arg;
1006
  return CURLE_UNKNOWN_OPTION;
1007
}
1008
#endif
1009
1010
static CURLcode setopt_long_http(struct Curl_easy *data, CURLoption option,
1011
                                 long arg)
1012
0
{
1013
0
#ifndef CURL_DISABLE_HTTP
1014
0
  CURLcode result = CURLE_OK;
1015
0
  struct UserDefined *s = &data->set;
1016
1017
0
  switch(option) {
1018
0
  case CURLOPT_FOLLOWLOCATION:
1019
0
    if((unsigned long)arg > 3)
1020
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1021
0
    else
1022
0
      s->http_follow_mode = (unsigned char)arg;
1023
0
    break;
1024
0
  case CURLOPT_MAXREDIRS:
1025
0
    result = value_range(&arg, -1, -1, 0x7fff);
1026
0
    if(!result)
1027
0
      s->maxredirs = (short)arg;
1028
0
    break;
1029
0
  case CURLOPT_POSTREDIR:
1030
0
    if(arg < CURL_REDIR_GET_ALL)
1031
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1032
0
    else {
1033
0
      s->post301 = !!(arg & CURL_REDIR_POST_301);
1034
0
      s->post302 = !!(arg & CURL_REDIR_POST_302);
1035
0
      s->post303 = !!(arg & CURL_REDIR_POST_303);
1036
0
    }
1037
0
    break;
1038
0
  case CURLOPT_HEADEROPT:
1039
0
    s->sep_headers = !!(arg & CURLHEADER_SEPARATE);
1040
0
    break;
1041
0
  case CURLOPT_HTTPAUTH:
1042
0
    return httpauth(data, FALSE, (unsigned long)arg);
1043
0
  case CURLOPT_HTTP_VERSION:
1044
0
    return setopt_HTTP_VERSION(data, arg);
1045
0
  case CURLOPT_EXPECT_100_TIMEOUT_MS:
1046
0
    result = value_range(&arg, 0, 0, 0xffff);
1047
0
    if(!result)
1048
0
      s->expect_100_timeout = (unsigned short)arg;
1049
0
    break;
1050
0
  case CURLOPT_STREAM_WEIGHT:
1051
0
#if defined(USE_HTTP2) || defined(USE_HTTP3)
1052
0
    if((arg >= 1) && (arg <= 256))
1053
0
      s->weight = (int)arg;
1054
0
    break;
1055
#else
1056
    result = CURLE_NOT_BUILT_IN;
1057
    break;
1058
#endif
1059
0
#ifndef CURL_DISABLE_HTTPSIG
1060
0
  case CURLOPT_HTTPSIG_ALGORITHM:
1061
0
    if(arg != CURLHTTPSIG_NONE &&
1062
0
       arg != CURLHTTPSIG_ED25519 &&
1063
0
       arg != CURLHTTPSIG_HMAC_SHA256)
1064
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1065
0
    s->httpsig_algorithm = (uint8_t)arg;
1066
0
    if(arg)
1067
0
      s->httpauth = (uint32_t)CURLAUTH_HTTPSIG;
1068
0
    else
1069
0
      s->httpauth &= ~(uint32_t)CURLAUTH_HTTPSIG;
1070
0
    break;
1071
0
#endif
1072
0
  default:
1073
0
    return CURLE_UNKNOWN_OPTION;
1074
0
  }
1075
0
  return result;
1076
#else
1077
  (void)data;
1078
  (void)option;
1079
  (void)arg;
1080
  return CURLE_UNKNOWN_OPTION;
1081
#endif
1082
0
}
1083
1084
static CURLcode setopt_long_proto(struct Curl_easy *data, CURLoption option,
1085
                                  long arg)
1086
0
{
1087
0
  CURLcode result = CURLE_OK;
1088
0
  struct UserDefined *s = &data->set;
1089
1090
0
  switch(option) {
1091
0
#ifndef CURL_DISABLE_TFTP
1092
0
  case CURLOPT_TFTP_BLKSIZE:
1093
0
    result = value_range(&arg, 0, TFTP_BLKSIZE_MIN, TFTP_BLKSIZE_MAX);
1094
0
    if(!result)
1095
0
      s->tftp_blksize = (unsigned short)arg;
1096
0
    break;
1097
0
#endif
1098
0
#ifndef CURL_DISABLE_NETRC
1099
0
  case CURLOPT_NETRC:
1100
0
    if((arg < CURL_NETRC_IGNORED) || (arg >= CURL_NETRC_LAST))
1101
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1102
0
    else
1103
0
      s->use_netrc = (unsigned char)arg;
1104
0
    break;
1105
0
#endif
1106
0
#ifndef CURL_DISABLE_FTP
1107
0
  case CURLOPT_FTP_FILEMETHOD:
1108
0
    if((arg < CURLFTPMETHOD_DEFAULT) || (arg >= CURLFTPMETHOD_LAST))
1109
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1110
0
    else
1111
0
      s->ftp_filemethod = (unsigned char)arg;
1112
0
    break;
1113
0
  case CURLOPT_FTP_SSL_CCC:
1114
0
    if((arg < CURLFTPSSL_CCC_NONE) || (arg >= CURLFTPSSL_CCC_LAST))
1115
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1116
0
    else
1117
0
      s->ftp_ccc = (unsigned char)arg;
1118
0
    break;
1119
0
  case CURLOPT_FTPSSLAUTH:
1120
0
    if((arg < CURLFTPAUTH_DEFAULT) || (arg >= CURLFTPAUTH_LAST))
1121
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1122
0
    else
1123
0
      s->ftpsslauth = (unsigned char)arg;
1124
0
    break;
1125
0
  case CURLOPT_ACCEPTTIMEOUT_MS:
1126
0
    return setopt_set_timeout_ms(&s->accepttimeout, arg);
1127
0
#endif
1128
0
#if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
1129
0
  case CURLOPT_FTP_CREATE_MISSING_DIRS:
1130
0
    if((arg < CURLFTP_CREATE_DIR_NONE) || (arg > CURLFTP_CREATE_DIR_RETRY))
1131
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1132
0
    else
1133
0
      s->ftp_create_missing_dirs = (unsigned char)arg;
1134
0
    break;
1135
0
  case CURLOPT_NEW_FILE_PERMS:
1136
0
    if((arg < 0) || (arg > 0777))
1137
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1138
0
    else
1139
0
      s->new_file_perms = (unsigned int)arg;
1140
0
    break;
1141
0
#endif
1142
0
#ifndef CURL_DISABLE_RTSP
1143
0
  case CURLOPT_RTSP_REQUEST:
1144
0
    return setopt_RTSP_REQUEST(data, arg);
1145
0
  case CURLOPT_RTSP_CLIENT_CSEQ:
1146
0
    result = value_range(&arg, 0, 0, INT_MAX);
1147
0
    if(!result)
1148
0
      data->state.rtsp_next_client_CSeq = (uint32_t)arg;
1149
0
    break;
1150
0
  case CURLOPT_RTSP_SERVER_CSEQ:
1151
0
    result = value_range(&arg, 0, 0, INT_MAX);
1152
0
    if(!result)
1153
0
      data->state.rtsp_next_server_CSeq = (uint32_t)arg;
1154
0
    break;
1155
0
#endif
1156
#ifdef USE_SSH
1157
  case CURLOPT_SSH_AUTH_TYPES:
1158
    s->ssh_auth_types = (uint32_t)arg;
1159
    break;
1160
  case CURLOPT_NEW_DIRECTORY_PERMS:
1161
    if((arg < 0) || (arg > 0777))
1162
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1163
    else
1164
      s->new_directory_perms = (unsigned int)arg;
1165
    break;
1166
#endif
1167
0
  case CURLOPT_PROTOCOLS:
1168
0
    s->allowed_protocols = (curl_prot_t)arg;
1169
0
    break;
1170
0
  case CURLOPT_REDIR_PROTOCOLS:
1171
0
    s->redir_protocols = (curl_prot_t)arg;
1172
0
    break;
1173
0
#ifndef CURL_DISABLE_WEBSOCKETS
1174
0
  case CURLOPT_WS_OPTIONS:
1175
0
    s->ws_raw_mode = !!(arg & CURLWS_RAW_MODE);
1176
0
    s->ws_no_auto_pong = !!(arg & CURLWS_NOAUTOPONG);
1177
0
    break;
1178
0
#endif
1179
0
  default:
1180
0
    return CURLE_UNKNOWN_OPTION;
1181
0
  }
1182
0
  return result;
1183
0
}
1184
1185
static CURLcode setopt_long_misc(struct Curl_easy *data, CURLoption option,
1186
                                 long arg)
1187
0
{
1188
0
  struct UserDefined *s = &data->set;
1189
1190
0
  switch(option) {
1191
0
  case CURLOPT_TIMECONDITION:
1192
0
    if((arg < CURL_TIMECOND_NONE) || (arg >= CURL_TIMECOND_LAST))
1193
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1194
0
    s->timecondition = (unsigned char)arg;
1195
0
    break;
1196
0
  case CURLOPT_TIMEVALUE:
1197
0
    s->timevalue = (time_t)arg;
1198
0
    break;
1199
0
  case CURLOPT_POSTFIELDSIZE:
1200
0
    if(arg < -1)
1201
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1202
0
    if(s->postfieldsize < arg && s->str_copypostfields) {
1203
0
      curlx_safefree(s->str_copypostfields);
1204
0
      s->postfields = NULL;
1205
0
    }
1206
0
    s->postfieldsize = arg;
1207
0
    break;
1208
0
  case CURLOPT_INFILESIZE:
1209
0
    if(arg < -1)
1210
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1211
0
    s->filesize = arg;
1212
0
    break;
1213
0
  case CURLOPT_RESUME_FROM:
1214
0
    if(arg < -1)
1215
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1216
0
    s->set_resume_from = arg;
1217
0
    break;
1218
0
  case CURLOPT_UPLOAD_FLAGS:
1219
0
    s->upload_flags = (unsigned char)arg;
1220
0
    break;
1221
0
#ifndef CURL_DISABLE_MIME
1222
0
  case CURLOPT_MIME_OPTIONS:
1223
0
    s->mime_formescape = !!(arg & CURLMIMEOPT_FORMESCAPE);
1224
0
    break;
1225
0
#endif
1226
0
#ifndef CURL_DISABLE_HSTS
1227
0
  case CURLOPT_HSTS_CTRL:
1228
0
    if(arg & CURLHSTS_ENABLE) {
1229
0
      if(!data->hsts) {
1230
0
        data->hsts = Curl_hsts_init();
1231
0
        if(!data->hsts)
1232
0
          return CURLE_OUT_OF_MEMORY;
1233
0
      }
1234
0
    }
1235
0
    else if(!data->share || !data->share->hsts) {
1236
      /* throw away the HSTS cache unless shared */
1237
0
      Curl_hsts_cleanup(&data->hsts);
1238
      /* flush all the entries */
1239
0
      curl_slist_free_all(data->state.hstslist);
1240
0
      data->state.hstslist = NULL;
1241
0
    }
1242
0
    else
1243
      /* detach from shared HSTS cache without freeing it */
1244
0
      data->hsts = NULL;
1245
0
    break;
1246
0
#endif
1247
0
#ifndef CURL_DISABLE_ALTSVC
1248
0
  case CURLOPT_ALTSVC_CTRL:
1249
0
    return Curl_altsvc_ctrl(data, arg);
1250
0
#endif
1251
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
1252
  case CURLOPT_GSSAPI_DELEGATION:
1253
    s->gssapi_delegation = (unsigned char)arg &
1254
      (CURLGSSAPI_DELEGATION_POLICY_FLAG | CURLGSSAPI_DELEGATION_FLAG);
1255
    break;
1256
#endif
1257
0
  default:
1258
0
    return CURLE_UNKNOWN_OPTION;
1259
0
  }
1260
0
  return CURLE_OK;
1261
0
}
1262
1263
static CURLcode setopt_long(struct Curl_easy *data, CURLoption option,
1264
                            long arg)
1265
0
{
1266
0
  typedef CURLcode (*setoptfunc)(struct Curl_easy *data,
1267
0
                                 CURLoption option, long arg);
1268
0
  static const setoptfunc setopt_call[] = {
1269
0
    setopt_long_bool,
1270
0
    setopt_long_net,
1271
0
    setopt_long_http,
1272
0
    setopt_long_proxy,
1273
0
    setopt_long_ssl,
1274
0
    setopt_long_proto,
1275
0
    setopt_long_misc
1276
0
  };
1277
0
  size_t i;
1278
1279
0
  for(i = 0; i < CURL_ARRAYSIZE(setopt_call); i++) {
1280
0
    CURLcode result = setopt_call[i](data, option, arg);
1281
0
    if(result != CURLE_UNKNOWN_OPTION)
1282
0
      return result;
1283
0
  }
1284
0
  return CURLE_UNKNOWN_OPTION;
1285
0
}
1286
1287
static CURLcode setopt_slist(struct Curl_easy *data, CURLoption option,
1288
                             struct curl_slist *slist)
1289
0
{
1290
0
  CURLcode result = CURLE_OK;
1291
0
  struct UserDefined *s = &data->set;
1292
0
  switch(option) {
1293
0
#ifndef CURL_DISABLE_PROXY
1294
0
  case CURLOPT_PROXYHEADER:
1295
    /*
1296
     * Set a list with proxy headers to use (or replace internals with)
1297
     *
1298
     * Since CURLOPT_HTTPHEADER was the only way to set HTTP headers for a
1299
     * long time we remain doing it this way until CURLOPT_PROXYHEADER is
1300
     * used. As soon as this option has been used, if set to anything but
1301
     * NULL, custom headers for proxies are only picked from this list.
1302
     *
1303
     * Set this option to NULL to restore the previous behavior.
1304
     */
1305
0
    s->proxyheaders = slist;
1306
0
    break;
1307
0
#endif
1308
0
#ifndef CURL_DISABLE_HTTP
1309
0
  case CURLOPT_HTTP200ALIASES:
1310
    /*
1311
     * Set a list of aliases for HTTP 200 in response header
1312
     */
1313
0
    s->http200aliases = slist;
1314
0
    break;
1315
0
#endif
1316
0
#if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
1317
0
  case CURLOPT_POSTQUOTE:
1318
    /*
1319
     * List of RAW FTP commands to use after a transfer
1320
     */
1321
0
    s->postquote = slist;
1322
0
    break;
1323
0
  case CURLOPT_PREQUOTE:
1324
    /*
1325
     * List of RAW FTP commands to use prior to RETR (Wesley Laxton)
1326
     */
1327
0
    s->prequote = slist;
1328
0
    break;
1329
0
  case CURLOPT_QUOTE:
1330
    /*
1331
     * List of RAW FTP commands to use before a transfer
1332
     */
1333
0
    s->quote = slist;
1334
0
    break;
1335
0
#endif
1336
0
  case CURLOPT_RESOLVE:
1337
    /*
1338
     * List of HOST:PORT:[addresses] strings to populate the DNS cache with
1339
     * Entries added this way will remain in the cache until explicitly
1340
     * removed or the handle is cleaned up.
1341
     *
1342
     * Prefix the HOST with plus sign (+) to have the entry expire like
1343
     * automatically added entries.
1344
     *
1345
     * Prefix the HOST with dash (-) to _remove_ the entry from the cache.
1346
     *
1347
     * This API can remove any entry from the DNS cache, but only entries
1348
     * that are not actually in use right now will be pruned immediately.
1349
     */
1350
0
    s->resolve = slist;
1351
0
    data->state.resolve = s->resolve;
1352
0
    break;
1353
0
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_MIME)
1354
0
  case CURLOPT_HTTPHEADER:
1355
    /*
1356
     * Set a list with HTTP headers to use (or replace internals with)
1357
     */
1358
0
    s->headers = slist;
1359
0
    break;
1360
0
#endif
1361
0
#ifndef CURL_DISABLE_TELNET
1362
0
  case CURLOPT_TELNETOPTIONS:
1363
    /*
1364
     * Set a linked list of telnet options
1365
     */
1366
0
    s->telnet_options = slist;
1367
0
    break;
1368
0
#endif
1369
0
#ifndef CURL_DISABLE_SMTP
1370
0
  case CURLOPT_MAIL_RCPT:
1371
    /* Set the list of mail recipients */
1372
0
    s->mail_rcpt = slist;
1373
0
    break;
1374
0
#endif
1375
0
  case CURLOPT_CONNECT_TO:
1376
0
    s->connect_to = slist;
1377
0
    break;
1378
0
  default:
1379
0
    return CURLE_UNKNOWN_OPTION;
1380
0
  }
1381
0
  return result;
1382
0
}
1383
1384
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) ||       \
1385
  !defined(CURL_DISABLE_IMAP)
1386
#ifndef CURL_DISABLE_MIME
1387
static CURLcode setopt_mimepost(struct Curl_easy *data, curl_mime *mimep)
1388
0
{
1389
  /*
1390
   * Set to make us do MIME POST
1391
   */
1392
0
  CURLcode result;
1393
0
  struct UserDefined *s = &data->set;
1394
0
  if(!s->mimepostp) {
1395
0
    s->mimepostp = curlx_malloc(sizeof(*s->mimepostp));
1396
0
    if(!s->mimepostp)
1397
0
      return CURLE_OUT_OF_MEMORY;
1398
0
    Curl_mime_initpart(s->mimepostp);
1399
0
  }
1400
1401
0
  result = Curl_mime_set_subparts(s->mimepostp, mimep, FALSE);
1402
0
  if(!result) {
1403
0
    s->method = HTTPREQ_POST_MIME;
1404
0
    s->opt_no_body = FALSE; /* this is implied */
1405
0
#ifndef CURL_DISABLE_FORM_API
1406
0
    Curl_mime_cleanpart(data->state.formp);
1407
0
    curlx_safefree(data->state.formp);
1408
0
    data->state.mimepost = NULL;
1409
0
#endif
1410
0
  }
1411
0
  return result;
1412
0
}
1413
#endif /* !CURL_DISABLE_MIME */
1414
#endif /* !CURL_DISABLE_HTTP || !CURL_DISABLE_SMTP || !CURL_DISABLE_IMAP */
1415
1416
static CURLcode setopt_share(struct Curl_easy *data, struct Curl_share *set)
1417
0
{
1418
0
  CURLcode result;
1419
1420
0
  if(data->conn) {
1421
    /* As this handle already has a connection attached, changing share now
1422
       would be complicated and error-prone */
1423
0
    infof(data, "Cannot change share object while in use");
1424
0
    result = CURLE_BAD_FUNCTION_ARGUMENT;
1425
0
  }
1426
0
  else {
1427
    /* disconnect from old share, if any and possible */
1428
0
    result = Curl_share_easy_unlink(data);
1429
0
    if(!result && GOOD_SHARE_HANDLE(set))
1430
      /* use new share if it set */
1431
0
      result = Curl_share_easy_link(data, set);
1432
0
  }
1433
0
  return result;
1434
0
}
1435
1436
/* assorted pointer type arguments */
1437
static CURLcode setopt_pointers(struct Curl_easy *data, CURLoption option,
1438
                                va_list param)
1439
0
{
1440
0
  CURLcode result = CURLE_OK;
1441
0
  struct UserDefined *s = &data->set;
1442
0
  switch(option) {
1443
0
  case CURLOPT_CURLU:
1444
    /*
1445
     * pass CURLU to set URL
1446
     */
1447
0
    Curl_bufref_free(&data->state.url);
1448
0
    CURL_EASY_STR_CLEAR(data, STRING_SET_URL);
1449
0
    s->uh = va_arg(param, CURLU *);
1450
0
    break;
1451
0
#ifndef CURL_DISABLE_HTTP
1452
0
#ifndef CURL_DISABLE_FORM_API
1453
0
  case CURLOPT_HTTPPOST:
1454
    /*
1455
     * Set to make us do HTTP POST. Legacy API-style.
1456
     */
1457
0
    s->httppost = va_arg(param, struct curl_httppost *);
1458
0
    s->method = HTTPREQ_POST_FORM;
1459
0
    s->opt_no_body = FALSE; /* this is implied */
1460
0
    Curl_mime_cleanpart(data->state.formp);
1461
0
    curlx_safefree(data->state.formp);
1462
0
    data->state.mimepost = NULL;
1463
0
    break;
1464
0
#endif /* !CURL_DISABLE_FORM_API */
1465
0
#endif /* !CURL_DISABLE_HTTP */
1466
0
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) ||       \
1467
0
  !defined(CURL_DISABLE_IMAP)
1468
0
#ifndef CURL_DISABLE_MIME
1469
0
  case CURLOPT_MIMEPOST:
1470
0
    result = setopt_mimepost(data, va_arg(param, curl_mime *));
1471
0
    break;
1472
0
#endif /* !CURL_DISABLE_MIME */
1473
0
#endif /* !CURL_DISABLE_HTTP || !CURL_DISABLE_SMTP || !CURL_DISABLE_IMAP */
1474
0
  case CURLOPT_STDERR:
1475
    /*
1476
     * Set to a FILE * that should receive all error writes. This
1477
     * defaults to stderr for normal operations.
1478
     */
1479
0
    s->err = va_arg(param, FILE *);
1480
0
    if(!s->err)
1481
0
      s->err = stderr;
1482
0
    break;
1483
0
  case CURLOPT_SHARE:
1484
0
    return setopt_share(data, va_arg(param, struct Curl_share *));
1485
1486
0
  default:
1487
0
    return CURLE_UNKNOWN_OPTION;
1488
0
  }
1489
0
  return result;
1490
0
}
1491
1492
#ifndef CURL_DISABLE_COOKIES
1493
static CURLcode cookielist(struct Curl_easy *data, const char *ptr)
1494
0
{
1495
0
  CURLcode result = CURLE_OK;
1496
0
  if(!ptr)
1497
0
    return CURLE_OK;
1498
1499
0
  if(curl_strequal(ptr, "ALL")) {
1500
    /* clear all cookies */
1501
0
    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
1502
0
    Curl_cookie_clearall(data->cookies);
1503
0
    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
1504
0
  }
1505
0
  else if(curl_strequal(ptr, "SESS")) {
1506
    /* clear session cookies */
1507
0
    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
1508
0
    Curl_cookie_clearsess(data->cookies);
1509
0
    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
1510
0
  }
1511
0
  else if(curl_strequal(ptr, "FLUSH")) {
1512
    /* flush cookies to file, takes care of the locking */
1513
0
    Curl_flush_cookies(data, FALSE);
1514
0
  }
1515
0
  else if(curl_strequal(ptr, "RELOAD")) {
1516
    /* reload cookies from file */
1517
0
    return Curl_cookie_loadfiles(data, COOKIE_NOPSL |
1518
0
                                 (data->set.cookiesession ?
1519
0
                                  COOKIE_NOSESSION : 0));
1520
0
  }
1521
0
  else {
1522
0
    if(!data->cookies) {
1523
      /* if cookie engine was not running, activate it */
1524
0
      data->cookies = Curl_cookie_init();
1525
0
      if(!data->cookies)
1526
0
        return CURLE_OUT_OF_MEMORY;
1527
0
      data->state.cookie_engine = TRUE;
1528
0
    }
1529
1530
    /* general protection against mistakes and abuse */
1531
0
    if(strlen(ptr) > CURL_MAX_INPUT_LENGTH)
1532
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1533
1534
    /* Adding these cookies without the PSL check, because the PSL is not
1535
       initialized until *perform() time, and this might be called before
1536
       that */
1537
0
    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
1538
0
    if(checkprefix("Set-Cookie:", ptr))
1539
      /* HTTP Header format line */
1540
0
      result = Curl_cookie_add(data, data->cookies, ptr + 11,
1541
0
                               NULL, NULL,
1542
0
                               COOKIE_HTTPHEADER | COOKIE_SECURE |
1543
0
                               COOKIE_NOPSL);
1544
0
    else
1545
      /* Netscape format line */
1546
0
      result = Curl_cookie_add(data, data->cookies, ptr, NULL,
1547
0
                               NULL, COOKIE_SECURE | COOKIE_NOPSL);
1548
0
    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
1549
0
  }
1550
0
  return result;
1551
0
}
1552
1553
static CURLcode cookiefile(struct Curl_easy *data, const char *ptr)
1554
0
{
1555
  /*
1556
   * Set cookie file to read and parse. Can be used multiple times.
1557
   */
1558
0
  if(ptr) {
1559
0
    struct curl_slist *cl;
1560
    /* general protection against mistakes and abuse */
1561
0
    if(strlen(ptr) > CURL_MAX_INPUT_LENGTH)
1562
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1563
    /* append the cookie filename to the list of filenames, and deal with
1564
       them later */
1565
0
    cl = curl_slist_append(data->state.cookielist, ptr);
1566
0
    if(!cl) {
1567
0
      curl_slist_free_all(data->state.cookielist);
1568
0
      data->state.cookielist = NULL;
1569
0
      return CURLE_OUT_OF_MEMORY;
1570
0
    }
1571
0
    data->state.cookielist = cl; /* store the list for later use */
1572
0
  }
1573
0
  else {
1574
    /* clear the list of cookie files */
1575
0
    curl_slist_free_all(data->state.cookielist);
1576
0
    data->state.cookielist = NULL;
1577
1578
0
    if(!data->share || !data->share->cookies) {
1579
      /* throw away all existing cookies if this is not a shared cookie
1580
         container */
1581
0
      Curl_cookie_clearall(data->cookies);
1582
0
      Curl_cookie_cleanup(data->cookies);
1583
0
    }
1584
    /* disable the cookie engine */
1585
0
    data->cookies = NULL;
1586
0
  }
1587
0
  return CURLE_OK;
1588
0
}
1589
#endif
1590
1591
#ifndef CURL_DISABLE_PROXY
1592
static CURLcode setproxy(struct Curl_easy *data, const char *proxy)
1593
0
{
1594
0
  const char *str = CURL_EASY_STR(data, STRING_PROXY);
1595
0
  if(str && proxy &&
1596
     /* there was one set, is this a new one? */
1597
0
     !strcmp(str, proxy))
1598
0
    return CURLE_OK; /* same one as before */
1599
1600
0
  changeproxy(data);
1601
0
  return Curl_setstropt(data, STRING_PROXY, proxy);
1602
0
}
1603
1604
static CURLcode setopt_cptr_proxy(struct Curl_easy *data, CURLoption option,
1605
                                  char *ptr)
1606
0
{
1607
0
  CURLcode result = CURLE_OK;
1608
0
  struct UserDefined *s = &data->set;
1609
0
  switch(option) {
1610
0
  case CURLOPT_PROXYUSERPWD: {
1611
    /*
1612
     * user:password needed to use the proxy
1613
     */
1614
0
    char *u = NULL;
1615
0
    char *p = NULL;
1616
0
    result = setstropt_userpwd(ptr, &u, &p);
1617
1618
    /* URL decode the components */
1619
0
    if(!result) {
1620
0
      char *str = NULL;
1621
0
      CURL_EASY_STR_CLEAR(data, STRING_PROXYUSERNAME);
1622
0
      CURL_EASY_STR_CLEAR(data, STRING_PROXYPASSWORD);
1623
0
      if(u) {
1624
0
        result = Curl_urldecode(u, 0, &str, NULL, REJECT_ZERO);
1625
0
        if(!result)
1626
0
          result = Curl_u8_strset_setn(&s->strings, STRING_PROXYUSERNAME, str);
1627
0
      }
1628
0
      if(!result && p) {
1629
0
        str = NULL;
1630
0
        result = Curl_urldecode(p, 0, &str, NULL, REJECT_ZERO);
1631
0
        if(!result)
1632
0
          result = Curl_u8_strset_setn(&s->strings, STRING_PROXYPASSWORD, str);
1633
0
      }
1634
0
    }
1635
0
    curlx_free(u);
1636
0
    curlx_strzero(p);
1637
0
    curlx_free(p);
1638
0
    break;
1639
0
  }
1640
0
  case CURLOPT_PROXYUSERNAME:
1641
    /*
1642
     * authentication username to use in the operation
1643
     */
1644
0
    return Curl_setstropt(data, STRING_PROXYUSERNAME, ptr);
1645
1646
0
  case CURLOPT_PROXYPASSWORD:
1647
    /*
1648
     * authentication password to use in the operation
1649
     */
1650
0
    return Curl_setstropt(data, STRING_PROXYPASSWORD, ptr);
1651
1652
0
  case CURLOPT_NOPROXY:
1653
    /*
1654
     * proxy exception list
1655
     */
1656
0
    return Curl_setstropt(data, STRING_NOPROXY, ptr);
1657
0
  case CURLOPT_PROXY_SSLCERT:
1658
    /*
1659
     * String that holds filename of the SSL certificate to use for proxy
1660
     */
1661
0
    return Curl_setstropt(data, STRING_CERT_PROXY, ptr);
1662
0
  case CURLOPT_PROXY_SSLCERTTYPE:
1663
    /*
1664
     * String that holds file type of the SSL certificate to use for proxy
1665
     */
1666
0
    return Curl_setstropt(data, STRING_CERT_TYPE_PROXY, ptr);
1667
0
  case CURLOPT_PROXY_SSLKEY:
1668
    /*
1669
     * String that holds filename of the SSL key to use for proxy
1670
     */
1671
0
    return Curl_setstropt(data, STRING_KEY_PROXY, ptr);
1672
0
  case CURLOPT_PROXY_KEYPASSWD:
1673
    /*
1674
     * String that holds the SSL private key password for proxy.
1675
     */
1676
0
    return Curl_setstropt(data, STRING_KEY_PASSWD_PROXY, ptr);
1677
0
  case CURLOPT_PROXY_SSLKEYTYPE:
1678
    /*
1679
     * String that holds file type of the SSL key to use for proxy
1680
     */
1681
0
    return Curl_setstropt(data, STRING_KEY_TYPE_PROXY, ptr);
1682
0
  case CURLOPT_PROXY_SSL_CIPHER_LIST:
1683
0
    if(Curl_ssl_supports(data, SSLSUPP_CIPHER_LIST)) {
1684
      /* set a list of cipher we want to use in the SSL connection for proxy */
1685
0
      return Curl_setstropt(data, STRING_SSL_CIPHER_LIST_PROXY, ptr);
1686
0
    }
1687
0
    else
1688
0
      return CURLE_NOT_BUILT_IN;
1689
0
  case CURLOPT_PROXY_TLS13_CIPHERS:
1690
0
    if(Curl_ssl_supports(data, SSLSUPP_TLS13_CIPHERSUITES))
1691
      /* set preferred list of TLS 1.3 cipher suites for proxy */
1692
0
      return Curl_setstropt(data, STRING_SSL_CIPHER13_LIST_PROXY, ptr);
1693
0
    else
1694
0
      return CURLE_NOT_BUILT_IN;
1695
0
  case CURLOPT_PROXY:
1696
    /*
1697
     * Set proxy server:port to use as proxy.
1698
     *
1699
     * If the proxy is set to "" (and CURLOPT_PRE_PROXY is set to "" or NULL)
1700
     * we explicitly say that we do not want to use a proxy (even though there
1701
     * might be environment variables saying so).
1702
     *
1703
     * Setting it to NULL, means no proxy but allows the environment variables
1704
     * to decide for us (if CURLOPT_PRE_PROXY setting it to NULL).
1705
     */
1706
0
    return setproxy(data, ptr);
1707
0
  case CURLOPT_PRE_PROXY:
1708
    /*
1709
     * Set proxy server:port to use as SOCKS proxy.
1710
     *
1711
     * If the proxy is set to "" or NULL we explicitly say that we do not want
1712
     * to use the socks proxy.
1713
     */
1714
0
    return Curl_setstropt(data, STRING_PRE_PROXY, ptr);
1715
0
  case CURLOPT_SOCKS5_GSSAPI_SERVICE:
1716
0
  case CURLOPT_PROXY_SERVICE_NAME:
1717
    /*
1718
     * Set proxy authentication service name for Kerberos 5 and SPNEGO
1719
     */
1720
0
    return Curl_setstropt(data, STRING_PROXY_SERVICE_NAME, ptr);
1721
0
  case CURLOPT_PROXY_PINNEDPUBLICKEY:
1722
    /*
1723
     * Set pinned public key for SSL connection.
1724
     * Specify filename of the public key in DER format.
1725
     */
1726
0
#ifdef USE_SSL
1727
0
    if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY))
1728
0
      return Curl_setstropt(data, STRING_SSL_PINNEDPUBLICKEY_PROXY, ptr);
1729
0
#endif
1730
0
    return CURLE_NOT_BUILT_IN;
1731
1732
0
  case CURLOPT_HAPROXY_CLIENT_IP:
1733
    /*
1734
     * Set the client IP to send through HAProxy PROXY protocol
1735
     */
1736
0
    result = Curl_setstropt(data, STRING_HAPROXY_CLIENT_IP, ptr);
1737
1738
    /* enable the HAProxy protocol if an IP is provided */
1739
0
    s->haproxyprotocol = !!CURL_EASY_STR(data, STRING_HAPROXY_CLIENT_IP);
1740
0
    break;
1741
0
  case CURLOPT_PROXY_CAINFO:
1742
    /*
1743
     * Set CA info SSL connection for proxy. Specify filename of the
1744
     * CA certificate
1745
     */
1746
0
    result = Curl_setstropt(data, STRING_SSL_CAFILE_PROXY, ptr);
1747
0
    if(!result)
1748
0
      s->proxy_ssl.custom_cafile = TRUE;
1749
0
    return result;
1750
0
  case CURLOPT_PROXY_CRLFILE:
1751
    /*
1752
     * Set CRL file info for SSL connection for proxy. Specify filename of the
1753
     * CRL to check certificates revocation
1754
     */
1755
0
    if(Curl_ssl_supports(data, SSLSUPP_CRLFILE))
1756
0
      return Curl_setstropt(data, STRING_SSL_CRLFILE_PROXY, ptr);
1757
0
    return CURLE_NOT_BUILT_IN;
1758
0
  case CURLOPT_PROXY_ISSUERCERT:
1759
    /*
1760
     * Set Issuer certificate file to check certificates issuer
1761
     */
1762
0
    if(Curl_ssl_supports(data, SSLSUPP_ISSUERCERT))
1763
0
      return Curl_setstropt(data, STRING_SSL_ISSUERCERT_PROXY, ptr);
1764
0
    return CURLE_NOT_BUILT_IN;
1765
0
  case CURLOPT_PROXY_CAPATH:
1766
    /*
1767
     * Set CA path info for SSL connection proxy. Specify directory name of the
1768
     * CA certificates which have been prepared using openssl c_rehash utility.
1769
     */
1770
0
#ifdef USE_SSL
1771
0
    if(Curl_ssl_supports(data, SSLSUPP_CA_PATH)) {
1772
      /* This does not work on Windows. */
1773
0
      result = Curl_setstropt(data, STRING_SSL_CAPATH_PROXY, ptr);
1774
0
      if(!result)
1775
0
        s->proxy_ssl.custom_capath = TRUE;
1776
0
      return result;
1777
0
    }
1778
0
#endif
1779
0
    return CURLE_NOT_BUILT_IN;
1780
0
  default:
1781
0
    return CURLE_UNKNOWN_OPTION;
1782
0
  }
1783
0
  return result;
1784
0
}
1785
#endif
1786
1787
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_MQTT)
1788
/*
1789
 * A string with POST data. Makes curl HTTP POST. Even if it is NULL. If
1790
 * needed, CURLOPT_POSTFIELDSIZE must have been set prior to
1791
 * CURLOPT_COPYPOSTFIELDS and not altered later.
1792
 */
1793
static CURLcode setopt_copypostfields(const char *ptr, struct UserDefined *s)
1794
0
{
1795
0
  CURLcode result = CURLE_OK;
1796
0
  if(s->postfieldsize < -1)
1797
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
1798
0
  if(!ptr || s->postfieldsize == -1) {
1799
0
    if(ptr && (strlen(ptr) > CURL_MAX_INPUT_LENGTH))
1800
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1801
0
    curlx_safefree(s->str_copypostfields);
1802
0
    if(ptr) {
1803
0
      s->str_copypostfields = curlx_strdup(ptr);
1804
0
      if(!s->str_copypostfields)
1805
0
        return CURLE_OUT_OF_MEMORY;
1806
0
    }
1807
0
  }
1808
0
  else {
1809
0
    size_t pflen = curlx_sotouz_range(s->postfieldsize, 0, SIZE_MAX);
1810
0
    if(pflen == SIZE_MAX)
1811
0
      return CURLE_OUT_OF_MEMORY;
1812
0
    else {
1813
      /* Allocate even when size == 0. This satisfies the need of possible
1814
         later address compare to detect the COPYPOSTFIELDS mode, and to mark
1815
         that postfields is used rather than read function or form data. */
1816
0
      char *p = curlx_memdup0(ptr, pflen);
1817
0
      if(!p)
1818
0
        return CURLE_OUT_OF_MEMORY;
1819
0
      else {
1820
0
        curlx_free(s->str_copypostfields);
1821
0
        s->str_copypostfields = p;
1822
0
      }
1823
0
    }
1824
0
  }
1825
1826
0
  s->postfields = s->str_copypostfields;
1827
0
  s->method = HTTPREQ_POST;
1828
0
  return result;
1829
0
}
1830
#endif
1831
1832
#ifdef USE_ECH
1833
static CURLcode setopt_ech(struct Curl_easy *data, const char *ptr)
1834
0
{
1835
0
  struct UserDefined *s = &data->set;
1836
0
  CURLcode result = CURLE_OK;
1837
1838
0
  if(!ptr || !strcmp(ptr, "false"))
1839
0
    s->ssl.ech = CURLECH_DISABLE;
1840
0
  else {
1841
0
    size_t plen = strlen(ptr);
1842
0
    if(plen > CURL_MAX_INPUT_LENGTH)
1843
0
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1844
0
    else {
1845
0
      if(!strcmp(ptr, "grease"))
1846
0
        s->ssl.ech = CURLECH_GREASE;
1847
0
      else if(!strcmp(ptr, "true"))
1848
0
        s->ssl.ech = CURLECH_ENABLE;
1849
0
      else if(!strcmp(ptr, "hard"))
1850
0
        s->ssl.ech = CURLECH_HARD;
1851
0
      else if(plen > 4 && !strncmp(ptr, "ecl:", 4)) {
1852
0
        if(!s->ssl.ech)
1853
0
          s->ssl.ech = CURLECH_HARD;
1854
0
        result = Curl_setstropt(data, STRING_ECH_CONFIG, ptr + 4);
1855
0
      }
1856
0
      else if(plen > 3 && !strncmp(ptr, "pn:", 3)) {
1857
0
        if(!s->ssl.ech)
1858
0
          s->ssl.ech = CURLECH_HARD;
1859
0
        result = Curl_setstropt(data, STRING_ECH_PUBLIC, ptr + 3);
1860
0
      }
1861
0
      else
1862
0
        result = CURLE_BAD_FUNCTION_ARGUMENT;
1863
0
    }
1864
0
  }
1865
0
  return result;
1866
0
}
1867
#else
1868
#define setopt_ech(x, y) CURLE_NOT_BUILT_IN
1869
#endif
1870
1871
#if defined(USE_SSL) || defined(USE_SSH)
1872
/* One of the options is used for both TLS and SSH */
1873
static CURLcode setopt_cptr_ssl(struct Curl_easy *data, CURLoption option,
1874
                                char *ptr)
1875
0
{
1876
0
  CURLcode result = CURLE_OK;
1877
1878
0
  switch(option) {
1879
0
  case CURLOPT_KEYPASSWD:
1880
    /*
1881
     * String that holds the SSL or SSH private key password.
1882
     */
1883
0
    result = Curl_setstropt(data, STRING_KEY_PASSWD, ptr);
1884
0
    break;
1885
0
#ifdef USE_SSL
1886
0
  case CURLOPT_CAINFO:
1887
    /*
1888
     * Set CA info for SSL connection. Specify filename of the CA certificate
1889
     */
1890
0
    result = Curl_setstropt(data, STRING_SSL_CAFILE, ptr);
1891
0
    if(!result)
1892
0
      data->set.ssl.custom_cafile = TRUE;
1893
0
    return result;
1894
0
  case CURLOPT_CAPATH:
1895
    /*
1896
     * Set CA path info for SSL connection. Specify directory name of the CA
1897
     * certificates which have been prepared using openssl c_rehash utility.
1898
     */
1899
0
    if(Curl_ssl_supports(data, SSLSUPP_CA_PATH)) {
1900
      /* This does not work on Windows. */
1901
0
      result = Curl_setstropt(data, STRING_SSL_CAPATH, ptr);
1902
0
      if(!result)
1903
0
        data->set.ssl.custom_capath = TRUE;
1904
0
      return result;
1905
0
    }
1906
0
    return CURLE_NOT_BUILT_IN;
1907
0
  case CURLOPT_CRLFILE:
1908
    /*
1909
     * Set CRL file info for SSL connection. Specify filename of the CRL
1910
     * to check certificates revocation
1911
     */
1912
0
    if(Curl_ssl_supports(data, SSLSUPP_CRLFILE))
1913
0
      return Curl_setstropt(data, STRING_SSL_CRLFILE, ptr);
1914
0
    return CURLE_NOT_BUILT_IN;
1915
0
  case CURLOPT_SSL_CIPHER_LIST:
1916
0
    if(Curl_ssl_supports(data, SSLSUPP_CIPHER_LIST))
1917
      /* set a list of cipher we want to use in the SSL connection */
1918
0
      return Curl_setstropt(data, STRING_SSL_CIPHER_LIST, ptr);
1919
0
    else
1920
0
      return CURLE_NOT_BUILT_IN;
1921
0
  case CURLOPT_TLS13_CIPHERS:
1922
0
    if(Curl_ssl_supports(data, SSLSUPP_TLS13_CIPHERSUITES))
1923
      /* set preferred list of TLS 1.3 cipher suites */
1924
0
      return Curl_setstropt(data, STRING_SSL_CIPHER13_LIST, ptr);
1925
0
    else
1926
0
      return CURLE_NOT_BUILT_IN;
1927
0
  case CURLOPT_RANDOM_FILE:
1928
0
    break;
1929
0
  case CURLOPT_EGDSOCKET:
1930
0
    break;
1931
0
  case CURLOPT_SSL_CTX_DATA:
1932
    /*
1933
     * Set an SSL_CTX callback parameter pointer
1934
     */
1935
0
    if(Curl_ssl_supports(data, SSLSUPP_SSL_CTX)) {
1936
0
      data->set.ssl_fsslctxp = ptr;
1937
0
      break;
1938
0
    }
1939
0
    else
1940
0
      return CURLE_NOT_BUILT_IN;
1941
0
  case CURLOPT_SSLCERT:
1942
    /*
1943
     * String that holds filename of the SSL certificate to use
1944
     */
1945
0
    return Curl_setstropt(data, STRING_CERT, ptr);
1946
0
  case CURLOPT_SSLCERTTYPE:
1947
    /*
1948
     * String that holds file type of the SSL certificate to use
1949
     */
1950
0
    return Curl_setstropt(data, STRING_CERT_TYPE, ptr);
1951
0
  case CURLOPT_SSLKEY:
1952
    /*
1953
     * String that holds filename of the SSL key to use
1954
     */
1955
0
    return Curl_setstropt(data, STRING_KEY, ptr);
1956
0
  case CURLOPT_SSLKEYTYPE:
1957
    /*
1958
     * String that holds file type of the SSL key to use
1959
     */
1960
0
    return Curl_setstropt(data, STRING_KEY_TYPE, ptr);
1961
0
  case CURLOPT_SSLENGINE:
1962
    /*
1963
     * String that holds the SSL crypto engine.
1964
     */
1965
0
    if(Curl_ssl_backend() != CURLSSLBACKEND_OPENSSL)
1966
0
      return CURLE_NOT_BUILT_IN;
1967
0
    result = Curl_setstropt(data, STRING_SSL_ENGINE, ptr);
1968
0
    break;
1969
0
  case CURLOPT_ISSUERCERT:
1970
    /*
1971
     * Set Issuer certificate file
1972
     * to check certificates issuer
1973
     */
1974
0
    if(Curl_ssl_supports(data, SSLSUPP_ISSUERCERT))
1975
0
      return Curl_setstropt(data, STRING_SSL_ISSUERCERT, ptr);
1976
0
    return CURLE_NOT_BUILT_IN;
1977
0
  case CURLOPT_SSL_EC_CURVES:
1978
    /*
1979
     * Set accepted curves in SSL connection setup.
1980
     * Specify colon-delimited list of curve algorithm names.
1981
     */
1982
0
    if(Curl_ssl_supports(data, SSLSUPP_SSL_EC_CURVES))
1983
0
      return Curl_setstropt(data, STRING_SSL_EC_CURVES, ptr);
1984
0
    return CURLE_NOT_BUILT_IN;
1985
0
  case CURLOPT_SSL_SIGNATURE_ALGORITHMS:
1986
    /*
1987
     * Set accepted signature algorithms.
1988
     * Specify colon-delimited list of signature scheme names.
1989
     */
1990
0
    if(Curl_ssl_supports(data, SSLSUPP_SIGNATURE_ALGORITHMS))
1991
0
      return Curl_setstropt(data, STRING_SSL_SIGNATURE_ALGORITHMS, ptr);
1992
0
    return CURLE_NOT_BUILT_IN;
1993
0
  case CURLOPT_PINNEDPUBLICKEY:
1994
    /*
1995
     * Set pinned public key for SSL connection.
1996
     * Specify filename of the public key in DER format.
1997
     */
1998
0
    if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY))
1999
0
      return Curl_setstropt(data, STRING_SSL_PINNEDPUBLICKEY, ptr);
2000
0
    return CURLE_NOT_BUILT_IN;
2001
0
  case CURLOPT_ECH:
2002
0
    return setopt_ech(data, ptr);
2003
0
#endif
2004
0
  default:
2005
0
    return CURLE_UNKNOWN_OPTION;
2006
0
  }
2007
0
  return result;
2008
0
}
2009
#endif
2010
2011
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_MQTT)
2012
static CURLcode setopt_cptr_http_mqtt(struct Curl_easy *data,
2013
                                      CURLoption option, char *ptr)
2014
0
{
2015
0
  CURLcode result = CURLE_OK;
2016
0
  struct UserDefined *s = &data->set;
2017
2018
0
  switch(option) {
2019
0
  case CURLOPT_COPYPOSTFIELDS:
2020
0
    return setopt_copypostfields(ptr, s);
2021
2022
0
  case CURLOPT_POSTFIELDS:
2023
    /*
2024
     * Like above, but use static data instead of copying it.
2025
     */
2026
0
    s->postfields = ptr;
2027
    /* Release old copied data. */
2028
0
    curlx_safefree(s->str_copypostfields);
2029
0
    s->method = HTTPREQ_POST;
2030
0
    break;
2031
2032
0
#ifndef CURL_DISABLE_HTTP
2033
0
  case CURLOPT_TRAILERDATA:
2034
0
    s->trailer_data = ptr;
2035
0
    break;
2036
0
  case CURLOPT_ACCEPT_ENCODING:
2037
    /*
2038
     * String to use at the value of Accept-Encoding header.
2039
     *
2040
     * If the encoding is set to "" we use an Accept-Encoding header that
2041
     * encompasses all the encodings we support.
2042
     * If the encoding is set to NULL we do not send an Accept-Encoding header
2043
     * and ignore any received Content-Encoding header.
2044
     *
2045
     */
2046
0
    if(ptr && !*ptr) {
2047
0
      ptr = Curl_get_content_encodings();
2048
0
      if(ptr)
2049
0
        result = CURL_EASY_STR_SETN(data, STRING_ENCODING, ptr);
2050
0
      else
2051
0
        result = CURLE_OUT_OF_MEMORY;
2052
0
      return result;
2053
0
    }
2054
0
    return Curl_setstropt(data, STRING_ENCODING, ptr);
2055
2056
0
#ifndef CURL_DISABLE_AWS
2057
0
  case CURLOPT_AWS_SIGV4:
2058
    /*
2059
     * String that is merged to some authentication
2060
     * parameters are used by the algorithm.
2061
     */
2062
0
    result = Curl_setstropt(data, STRING_AWS_SIGV4, ptr);
2063
    /*
2064
     * Basic has been set by default; it needs to be unset here.
2065
     */
2066
0
    if(CURL_EASY_STR(data, STRING_AWS_SIGV4))
2067
0
      s->httpauth = CURLAUTH_AWS_SIGV4;
2068
0
    else
2069
0
      s->httpauth &= ~(uint32_t)CURLAUTH_AWS_SIGV4;
2070
0
    break;
2071
0
#endif
2072
0
#ifndef CURL_DISABLE_HTTPSIG
2073
0
  case CURLOPT_HTTPSIG_KEY:
2074
0
    result = Curl_setstropt(data, STRING_HTTPSIG_KEY, ptr);
2075
0
    break;
2076
0
  case CURLOPT_HTTPSIG_KEYID:
2077
0
    result = Curl_setstropt(data, STRING_HTTPSIG_KEYID, ptr);
2078
0
    break;
2079
0
  case CURLOPT_HTTPSIG_HEADERS:
2080
0
    result = Curl_setstropt(data, STRING_HTTPSIG_HEADERS, ptr);
2081
0
    break;
2082
0
#endif
2083
0
  case CURLOPT_REFERER: {
2084
    /*
2085
     * String to set in the HTTP Referer: field.
2086
     */
2087
0
    struct bufref *oldref = &data->state.referer;
2088
    /* free the old after the storing the new in case the input is actually
2089
       pointing back to this */
2090
0
    result = Curl_setstropt(data, STRING_SET_REFERER, ptr);
2091
0
    Curl_bufref_free(oldref);
2092
0
    break;
2093
0
  }
2094
2095
0
  case CURLOPT_USERAGENT:
2096
    /*
2097
     * String to use in the HTTP User-Agent field
2098
     */
2099
0
    return Curl_setstropt(data, STRING_USERAGENT, ptr);
2100
2101
0
#ifndef CURL_DISABLE_COOKIES
2102
0
  case CURLOPT_COOKIE:
2103
    /*
2104
     * Cookie string to send to the remote server in the request.
2105
     */
2106
0
    return Curl_setstropt(data, STRING_COOKIE, ptr);
2107
2108
0
  case CURLOPT_COOKIEFILE:
2109
0
    return cookiefile(data, ptr);
2110
2111
0
  case CURLOPT_COOKIEJAR:
2112
    /*
2113
     * Set cookie filename to dump all cookies to when we are done.
2114
     */
2115
0
    result = Curl_setstropt(data, STRING_COOKIEJAR, ptr);
2116
0
    if(!result) {
2117
      /*
2118
       * Activate the cookie parser. This may or may not already
2119
       * have been made.
2120
       */
2121
0
      if(!data->cookies)
2122
0
        data->cookies = Curl_cookie_init();
2123
0
      if(!data->cookies)
2124
0
        result = CURLE_OUT_OF_MEMORY;
2125
0
      else
2126
0
        data->state.cookie_engine = TRUE;
2127
0
    }
2128
0
    break;
2129
2130
0
  case CURLOPT_COOKIELIST:
2131
0
    return cookielist(data, ptr);
2132
0
#endif /* !CURL_DISABLE_COOKIES */
2133
2134
0
#endif /* !CURL_DISABLE_HTTP */
2135
0
  default:
2136
0
    return CURLE_UNKNOWN_OPTION;
2137
0
  }
2138
0
  return result;
2139
0
}
2140
#endif /* !CURL_DISABLE_HTTP || !CURL_DISABLE_MQTT */
2141
2142
#ifdef USE_SSH
2143
static CURLcode setopt_cptr_ssh(struct Curl_easy *data, CURLoption option,
2144
                                char *ptr)
2145
{
2146
  struct UserDefined *s = &data->set;
2147
  switch(option) {
2148
  case CURLOPT_SSH_PUBLIC_KEYFILE:
2149
    /*
2150
     * Use this file instead of the $HOME/.ssh/id_dsa.pub file
2151
     */
2152
    return Curl_setstropt(data, STRING_SSH_PUBLIC_KEY, ptr);
2153
  case CURLOPT_SSH_PRIVATE_KEYFILE:
2154
    /*
2155
     * Use this file instead of the $HOME/.ssh/id_dsa file
2156
     */
2157
    return Curl_setstropt(data, STRING_SSH_PRIVATE_KEY, ptr);
2158
  case CURLOPT_SSH_KEYDATA:
2159
    /*
2160
     * Custom client data to pass to the SSH keyfunc callback
2161
     */
2162
    s->ssh_keyfunc_userp = ptr;
2163
    break;
2164
  case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5:
2165
    /*
2166
     * Option to allow for the MD5 of the host public key to be checked
2167
     * for validation purposes.
2168
     */
2169
    return Curl_setstropt(data, STRING_SSH_HOST_PUBLIC_KEY_MD5, ptr);
2170
  case CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256:
2171
    /*
2172
     * Option to allow for the SHA256 of the host public key to be checked
2173
     * for validation purposes.
2174
     */
2175
    return Curl_setstropt(data, STRING_SSH_HOST_PUBLIC_KEY_SHA256, ptr);
2176
  case CURLOPT_SSH_KNOWNHOSTS:
2177
    /*
2178
     * Store the filename to read known hosts from.
2179
     */
2180
    return Curl_setstropt(data, STRING_SSH_KNOWNHOSTS, ptr);
2181
#ifdef USE_LIBSSH2
2182
  case CURLOPT_SSH_HOSTKEYDATA:
2183
    /*
2184
     * Custom client data to pass to the SSH keyfunc callback
2185
     */
2186
    s->ssh_hostkeyfunc_userp = ptr;
2187
    break;
2188
#endif /* USE_LIBSSH2 */
2189
  default:
2190
    return CURLE_UNKNOWN_OPTION;
2191
  }
2192
  return CURLE_OK;
2193
}
2194
#endif /* USE_SSH */
2195
2196
#ifndef CURL_DISABLE_FTP
2197
static CURLcode setopt_cptr_ftp(struct Curl_easy *data, CURLoption option,
2198
                                char *ptr)
2199
0
{
2200
0
  CURLcode result = CURLE_OK;
2201
0
  struct UserDefined *s = &data->set;
2202
0
  switch(option) {
2203
0
  case CURLOPT_FTPPORT:
2204
    /*
2205
     * Use FTP PORT, this also specifies which IP address to use
2206
     */
2207
0
    result = Curl_setstropt(data, STRING_FTPPORT, ptr);
2208
0
    s->ftp_use_port = !!CURL_EASY_STR(data, STRING_FTPPORT);
2209
0
    break;
2210
2211
0
  case CURLOPT_FTP_ACCOUNT:
2212
0
    return Curl_setstropt(data, STRING_FTP_ACCOUNT, ptr);
2213
2214
0
  case CURLOPT_FTP_ALTERNATIVE_TO_USER:
2215
0
    return Curl_setstropt(data, STRING_FTP_ALTERNATIVE_TO_USER, ptr);
2216
2217
0
  case CURLOPT_KRBLEVEL:
2218
0
    return CURLE_NOT_BUILT_IN; /* removed in 8.17.0 */
2219
0
  case CURLOPT_CHUNK_DATA:
2220
0
    s->wildcardptr = ptr;
2221
0
    break;
2222
0
  case CURLOPT_FNMATCH_DATA:
2223
0
    s->fnmatch_data = ptr;
2224
0
    break;
2225
0
  default:
2226
0
    return CURLE_UNKNOWN_OPTION;
2227
0
  }
2228
0
  return result;
2229
0
}
2230
#endif /* !CURL_DISABLE_FTP */
2231
2232
static CURLcode setopt_cptr_net(struct Curl_easy *data, CURLoption option,
2233
                                char *ptr)
2234
0
{
2235
0
  switch(option) {
2236
0
  case CURLOPT_INTERFACE:
2237
    /*
2238
     * Set what interface or address/hostname to bind the socket to when
2239
     * performing an operation and thus what from-IP your connection will use.
2240
     */
2241
0
    return setstropt_interface(data, ptr);
2242
2243
#ifdef USE_RESOLV_ARES
2244
  case CURLOPT_DNS_SERVERS:
2245
    return Curl_setstropt(data, STRING_DNS_SERVERS, ptr);
2246
2247
  case CURLOPT_DNS_INTERFACE:
2248
    return Curl_setstropt(data, STRING_DNS_INTERFACE, ptr);
2249
2250
  case CURLOPT_DNS_LOCAL_IP4:
2251
    return Curl_setstropt(data, STRING_DNS_LOCAL_IP4, ptr);
2252
2253
  case CURLOPT_DNS_LOCAL_IP6:
2254
    return Curl_setstropt(data, STRING_DNS_LOCAL_IP6, ptr);
2255
#endif
2256
0
#ifdef USE_UNIX_SOCKETS
2257
0
  case CURLOPT_UNIX_SOCKET_PATH:
2258
0
    data->set.abstract_unix_socket = FALSE;
2259
0
    return Curl_setstropt(data, STRING_UNIX_SOCKET_PATH, ptr);
2260
2261
0
  case CURLOPT_ABSTRACT_UNIX_SOCKET:
2262
0
    data->set.abstract_unix_socket = TRUE;
2263
0
    return Curl_setstropt(data, STRING_UNIX_SOCKET_PATH, ptr);
2264
0
#endif
2265
0
#ifndef CURL_DISABLE_DOH
2266
0
  case CURLOPT_DOH_URL:
2267
0
    {
2268
0
      CURLcode result = Curl_setstropt(data, STRING_DOH, ptr);
2269
0
      data->set.doh = !!CURL_EASY_STR(data, STRING_DOH);
2270
0
      return result;
2271
0
    }
2272
0
#endif
2273
0
  default:
2274
0
    return CURLE_UNKNOWN_OPTION;
2275
0
  }
2276
0
}
2277
2278
static CURLcode setopt_cptr_misc(struct Curl_easy *data, CURLoption option,
2279
                                 char *ptr)
2280
0
{
2281
0
  CURLcode result = CURLE_OK;
2282
0
  struct UserDefined *s = &data->set;
2283
2284
0
  switch(option) {
2285
0
  case CURLOPT_REQUEST_TARGET:
2286
0
    return Curl_setstropt(data, STRING_TARGET, ptr);
2287
0
#ifndef CURL_DISABLE_NETRC
2288
0
  case CURLOPT_NETRC_FILE:
2289
0
    return Curl_setstropt(data, STRING_NETRC_FILE, ptr);
2290
0
#endif
2291
0
  case CURLOPT_CUSTOMREQUEST:
2292
0
    return Curl_setstropt(data, STRING_CUSTOMREQUEST, ptr);
2293
2294
    /* we do not set s->method = HTTPREQ_CUSTOM; here, we continue as if we
2295
       were using the already set type and this changes the actual request
2296
       keyword */
2297
0
  case CURLOPT_SERVICE_NAME:
2298
0
    return Curl_setstropt(data, STRING_SERVICE_NAME, ptr);
2299
2300
0
  case CURLOPT_HEADERDATA:
2301
0
    s->writeheader = ptr;
2302
0
    break;
2303
0
  case CURLOPT_READDATA:
2304
0
    s->in_set = ptr;
2305
0
    break;
2306
0
  case CURLOPT_WRITEDATA:
2307
0
    s->out = ptr;
2308
0
    break;
2309
0
  case CURLOPT_DEBUGDATA:
2310
0
    s->debugdata = ptr;
2311
0
    break;
2312
0
  case CURLOPT_PROGRESSDATA:
2313
0
    s->progress_client = ptr;
2314
0
    break;
2315
0
  case CURLOPT_SEEKDATA:
2316
0
    s->seek_client = ptr;
2317
0
    break;
2318
0
  case CURLOPT_IOCTLDATA:
2319
0
    s->ioctl_client = ptr;
2320
0
    break;
2321
0
  case CURLOPT_SOCKOPTDATA:
2322
0
    s->sockopt_client = ptr;
2323
0
    break;
2324
0
  case CURLOPT_OPENSOCKETDATA:
2325
0
    s->opensocket_client = ptr;
2326
0
    break;
2327
0
  case CURLOPT_RESOLVER_START_DATA:
2328
0
    s->resolver_start_client = ptr;
2329
0
    break;
2330
0
  case CURLOPT_CLOSESOCKETDATA:
2331
0
    s->closesocket_client = ptr;
2332
0
    break;
2333
0
  case CURLOPT_PREREQDATA:
2334
0
    s->prereq_userp = ptr;
2335
0
    break;
2336
0
  case CURLOPT_ERRORBUFFER:
2337
0
    s->errorbuffer = ptr;
2338
0
    break;
2339
0
  case CURLOPT_URL:
2340
0
    result = Curl_setstropt(data, STRING_SET_URL, ptr);
2341
0
    Curl_bufref_set(&data->state.url,
2342
0
                    CURL_EASY_STR(data, STRING_SET_URL), 0, NULL);
2343
0
    break;
2344
2345
0
  case CURLOPT_USERPWD: {
2346
0
    char *u = NULL, *p = NULL;
2347
0
    result = setstropt_userpwd(ptr, &u, &p);
2348
0
    if(!result) {
2349
0
      result = CURL_EASY_STR_SETN(data, STRING_USERNAME, u);
2350
0
      u = NULL;
2351
0
    }
2352
0
    if(!result) {
2353
0
      result = CURL_EASY_STR_SETN(data, STRING_PASSWORD, p);
2354
0
      p = NULL;
2355
0
    }
2356
0
    curlx_free(u);
2357
0
    curlx_free(p);
2358
0
    return result;
2359
0
  }
2360
2361
0
  case CURLOPT_USERNAME:
2362
0
    return Curl_setstropt(data, STRING_USERNAME, ptr);
2363
2364
0
  case CURLOPT_PASSWORD:
2365
0
    return Curl_setstropt(data, STRING_PASSWORD, ptr);
2366
2367
0
  case CURLOPT_LOGIN_OPTIONS:
2368
0
    return Curl_setstropt(data, STRING_OPTIONS, ptr);
2369
2370
0
  case CURLOPT_XOAUTH2_BEARER:
2371
0
    return Curl_setstropt(data, STRING_BEARER, ptr);
2372
0
  case CURLOPT_RANGE:
2373
0
    return Curl_setstropt(data, STRING_SET_RANGE, ptr);
2374
0
  case CURLOPT_PRIVATE:
2375
0
    s->private_data = ptr;
2376
0
    break;
2377
0
  case CURLOPT_PROTOCOLS_STR:
2378
0
    if(ptr) {
2379
0
      curl_prot_t protos;
2380
0
      result = protocol2num(ptr, &protos);
2381
0
      if(!result)
2382
0
        s->allowed_protocols = protos;
2383
0
    }
2384
0
    else
2385
      /* make a NULL argument reset to default */
2386
0
      s->allowed_protocols = (curl_prot_t)CURLPROTO_64ALL;
2387
0
    break;
2388
0
  case CURLOPT_REDIR_PROTOCOLS_STR:
2389
0
    if(ptr) {
2390
0
      curl_prot_t protos;
2391
0
      result = protocol2num(ptr, &protos);
2392
0
      if(!result)
2393
0
        s->redir_protocols = protos;
2394
0
    }
2395
0
    else
2396
      /* make a NULL argument reset to default */
2397
0
      s->redir_protocols = (curl_prot_t)CURLPROTO_REDIR;
2398
0
    break;
2399
0
  case CURLOPT_DEFAULT_PROTOCOL:
2400
    /* Set the protocol to use when the URL does not include any protocol */
2401
0
    return Curl_setstropt(data, STRING_DEFAULT_PROTOCOL, ptr);
2402
0
#ifndef CURL_DISABLE_SMTP
2403
0
  case CURLOPT_MAIL_FROM:
2404
    /* Set the SMTP mail originator */
2405
0
    return Curl_setstropt(data, STRING_MAIL_FROM, ptr);
2406
0
  case CURLOPT_MAIL_AUTH:
2407
    /* Set the SMTP auth originator */
2408
0
    return Curl_setstropt(data, STRING_MAIL_AUTH, ptr);
2409
0
#endif
2410
0
  case CURLOPT_SASL_AUTHZID:
2411
    /* Authorization identity (identity to act as) */
2412
0
    return Curl_setstropt(data, STRING_SASL_AUTHZID, ptr);
2413
0
#ifndef CURL_DISABLE_RTSP
2414
0
  case CURLOPT_RTSP_SESSION_ID:
2415
0
    Curl_peer_unlink(&data->state.rtsp_session_origin);
2416
0
    return Curl_setstropt(data, STRING_RTSP_SESSION_ID, ptr);
2417
0
  case CURLOPT_RTSP_STREAM_URI:
2418
0
    return Curl_setstropt(data, STRING_RTSP_STREAM_URI, ptr);
2419
0
  case CURLOPT_RTSP_TRANSPORT:
2420
0
    return Curl_setstropt(data, STRING_RTSP_TRANSPORT, ptr);
2421
0
  case CURLOPT_INTERLEAVEDATA:
2422
0
    s->rtp_out = ptr;
2423
0
    break;
2424
0
#endif /* !CURL_DISABLE_RTSP */
2425
0
  case CURLOPT_TLSAUTH_USERNAME:
2426
0
  case CURLOPT_TLSAUTH_PASSWORD:
2427
0
  case CURLOPT_TLSAUTH_TYPE:
2428
0
  case CURLOPT_PROXY_TLSAUTH_USERNAME:
2429
0
  case CURLOPT_PROXY_TLSAUTH_PASSWORD:
2430
0
  case CURLOPT_PROXY_TLSAUTH_TYPE:
2431
0
    return CURLE_NOT_BUILT_IN;
2432
0
#ifndef CURL_DISABLE_HSTS
2433
0
  case CURLOPT_HSTSREADDATA:
2434
0
    s->hsts_read_userp = ptr;
2435
0
    break;
2436
0
  case CURLOPT_HSTSWRITEDATA:
2437
0
    s->hsts_write_userp = ptr;
2438
0
    break;
2439
0
  case CURLOPT_HSTS: {
2440
0
    struct curl_slist *h;
2441
0
    if(!data->hsts) {
2442
0
      data->hsts = Curl_hsts_init();
2443
0
      if(!data->hsts)
2444
0
        return CURLE_OUT_OF_MEMORY;
2445
0
    }
2446
0
    if(ptr) {
2447
0
      result = Curl_setstropt(data, STRING_HSTS, ptr);
2448
0
      if(result)
2449
0
        return result;
2450
      /* this needs to build a list of filenames to read from, so that it can
2451
         read them later, as we might get a shared HSTS handle to load them
2452
         into */
2453
0
      h = curl_slist_append(data->state.hstslist, ptr);
2454
0
      if(!h) {
2455
0
        curl_slist_free_all(data->state.hstslist);
2456
0
        data->state.hstslist = NULL;
2457
0
        return CURLE_OUT_OF_MEMORY;
2458
0
      }
2459
0
      data->state.hstslist = h; /* store the list for later use */
2460
0
    }
2461
0
    else {
2462
      /* clear the list of HSTS files */
2463
0
      curl_slist_free_all(data->state.hstslist);
2464
0
      data->state.hstslist = NULL;
2465
0
      if(!data->share || !data->share->hsts)
2466
        /* throw away the HSTS cache unless shared */
2467
0
        Curl_hsts_cleanup(&data->hsts);
2468
0
    }
2469
0
    break;
2470
0
  }
2471
0
#endif /* !CURL_DISABLE_HSTS */
2472
0
#ifndef CURL_DISABLE_ALTSVC
2473
0
  case CURLOPT_ALTSVC:
2474
0
    if(!data->asi) {
2475
0
      data->asi = Curl_altsvc_init();
2476
0
      if(!data->asi)
2477
0
        return CURLE_OUT_OF_MEMORY;
2478
0
    }
2479
0
    result = Curl_setstropt(data, STRING_ALTSVC, ptr);
2480
0
    if(result)
2481
0
      break;
2482
0
    if(ptr)
2483
0
      return Curl_altsvc_load(data->asi, ptr);
2484
0
    break;
2485
0
#endif /* !CURL_DISABLE_ALTSVC */
2486
0
  case CURLOPT_ECH:
2487
0
    return setopt_ech(data, ptr);
2488
0
  default:
2489
0
    return CURLE_UNKNOWN_OPTION;
2490
0
  }
2491
0
  return result;
2492
0
}
2493
2494
static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option,
2495
                            char *ptr)
2496
0
{
2497
0
  typedef CURLcode (*ptrfunc)(struct Curl_easy *data, CURLoption option,
2498
0
                              char *ptr);
2499
  /* Order by likeliness */
2500
0
  static const ptrfunc setopt_call[] = {
2501
0
    setopt_cptr_misc,
2502
0
#if defined(USE_SSL) || defined(USE_SSH)
2503
0
    setopt_cptr_ssl,
2504
0
#endif
2505
0
#ifndef CURL_DISABLE_PROXY
2506
0
    setopt_cptr_proxy,
2507
0
#endif
2508
0
    setopt_cptr_net,
2509
0
#ifndef CURL_DISABLE_FTP
2510
0
    setopt_cptr_ftp,
2511
0
#endif
2512
#ifdef USE_SSH
2513
    setopt_cptr_ssh,
2514
#endif
2515
0
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_MQTT)
2516
0
    setopt_cptr_http_mqtt,
2517
0
#endif
2518
0
  };
2519
0
  size_t i;
2520
2521
0
  for(i = 0; i < CURL_ARRAYSIZE(setopt_call); i++) {
2522
0
    CURLcode result = setopt_call[i](data, option, ptr);
2523
0
    if(result != CURLE_UNKNOWN_OPTION)
2524
0
      return result;
2525
0
  }
2526
0
  return CURLE_UNKNOWN_OPTION;
2527
0
}
2528
2529
static CURLcode setopt_func(struct Curl_easy *data, CURLoption option,
2530
                            va_list param)
2531
0
{
2532
0
  struct UserDefined *s = &data->set;
2533
0
  switch(option) {
2534
0
  case CURLOPT_PROGRESSFUNCTION:
2535
    /*
2536
     * Progress callback function
2537
     */
2538
0
    s->fprogress = va_arg(param, curl_progress_callback);
2539
0
    if(s->fprogress)
2540
0
      data->progress.callback = TRUE; /* no longer internal */
2541
0
    else
2542
0
      data->progress.callback = FALSE; /* NULL enforces internal */
2543
0
    break;
2544
2545
0
  case CURLOPT_XFERINFOFUNCTION:
2546
    /*
2547
     * Transfer info callback function
2548
     */
2549
0
    s->fxferinfo = va_arg(param, curl_xferinfo_callback);
2550
0
    if(s->fxferinfo)
2551
0
      data->progress.callback = TRUE; /* no longer internal */
2552
0
    else
2553
0
      data->progress.callback = FALSE; /* NULL enforces internal */
2554
2555
0
    break;
2556
0
  case CURLOPT_DEBUGFUNCTION:
2557
    /*
2558
     * stderr write callback.
2559
     */
2560
0
    s->fdebug = va_arg(param, curl_debug_callback);
2561
    /*
2562
     * if the callback provided is NULL, it will use the default callback
2563
     */
2564
0
    break;
2565
0
  case CURLOPT_HEADERFUNCTION:
2566
    /*
2567
     * Set header write callback
2568
     */
2569
0
    s->fwrite_header = va_arg(param, curl_write_callback);
2570
0
    break;
2571
0
  case CURLOPT_WRITEFUNCTION:
2572
    /*
2573
     * Set data write callback
2574
     */
2575
0
    s->fwrite_func = va_arg(param, curl_write_callback);
2576
0
    if(!s->fwrite_func)
2577
0
#if defined(__clang__) && __clang_major__ >= 16
2578
0
#pragma clang diagnostic push
2579
0
#pragma clang diagnostic ignored "-Wcast-function-type-strict"
2580
0
#endif
2581
      /* When set to NULL, reset to our internal default function */
2582
0
      s->fwrite_func = (curl_write_callback)fwrite;
2583
0
#if defined(__clang__) && __clang_major__ >= 16
2584
0
#pragma clang diagnostic pop
2585
0
#endif
2586
0
    break;
2587
0
  case CURLOPT_READFUNCTION:
2588
    /*
2589
     * Read data callback
2590
     */
2591
0
    s->fread_func_set = va_arg(param, curl_read_callback);
2592
0
    if(!s->fread_func_set) {
2593
0
      s->is_fread_set = 0;
2594
0
#if defined(__clang__) && __clang_major__ >= 16
2595
0
#pragma clang diagnostic push
2596
0
#pragma clang diagnostic ignored "-Wcast-function-type-strict"
2597
0
#endif
2598
      /* When set to NULL, reset to our internal default function */
2599
0
      s->fread_func_set = (curl_read_callback)fread;
2600
0
#if defined(__clang__) && __clang_major__ >= 16
2601
0
#pragma clang diagnostic pop
2602
0
#endif
2603
0
    }
2604
0
    else
2605
0
      s->is_fread_set = 1;
2606
0
    break;
2607
0
  case CURLOPT_SEEKFUNCTION:
2608
    /*
2609
     * Seek callback. Might be NULL.
2610
     */
2611
0
    s->seek_func = va_arg(param, curl_seek_callback);
2612
0
    break;
2613
0
  case CURLOPT_IOCTLFUNCTION:
2614
    /*
2615
     * I/O control callback. Might be NULL.
2616
     */
2617
0
    s->ioctl_func = va_arg(param, curl_ioctl_callback);
2618
0
    break;
2619
0
  case CURLOPT_SSL_CTX_FUNCTION:
2620
    /*
2621
     * Set an SSL_CTX callback
2622
     */
2623
0
#ifdef USE_SSL
2624
0
    if(Curl_ssl_supports(data, SSLSUPP_SSL_CTX)) {
2625
0
      s->ssl_fsslctx = va_arg(param, curl_ssl_ctx_callback);
2626
0
      break;
2627
0
    }
2628
0
    else
2629
0
#endif
2630
0
      return CURLE_NOT_BUILT_IN;
2631
2632
0
  case CURLOPT_SOCKOPTFUNCTION:
2633
    /*
2634
     * socket callback function: called after socket() but before connect()
2635
     */
2636
0
    s->fsockopt = va_arg(param, curl_sockopt_callback);
2637
0
    break;
2638
2639
0
  case CURLOPT_OPENSOCKETFUNCTION:
2640
    /*
2641
     * open/create socket callback function: called instead of socket(),
2642
     * before connect()
2643
     */
2644
0
    s->fopensocket = va_arg(param, curl_opensocket_callback);
2645
0
    break;
2646
2647
0
  case CURLOPT_CLOSESOCKETFUNCTION:
2648
    /*
2649
     * close socket callback function: called instead of close()
2650
     * when shutting down a connection
2651
     */
2652
0
    s->fclosesocket = va_arg(param, curl_closesocket_callback);
2653
0
    break;
2654
2655
0
  case CURLOPT_RESOLVER_START_FUNCTION:
2656
    /*
2657
     * resolver start callback function: called before a new resolver request
2658
     * is started
2659
     */
2660
0
    s->resolver_start = va_arg(param, curl_resolver_start_callback);
2661
0
    break;
2662
2663
#ifdef USE_SSH
2664
#ifdef USE_LIBSSH2
2665
  case CURLOPT_SSH_HOSTKEYFUNCTION:
2666
    /* the callback to check the hostkey without the knownhost file */
2667
    s->ssh_hostkeyfunc = va_arg(param, curl_sshhostkeycallback);
2668
    break;
2669
#endif
2670
2671
  case CURLOPT_SSH_KEYFUNCTION:
2672
    /* setting to NULL is fine since the ssh.c functions themselves will
2673
       then revert to use the internal default */
2674
    s->ssh_keyfunc = va_arg(param, curl_sshkeycallback);
2675
    break;
2676
2677
#endif /* USE_SSH */
2678
2679
0
#ifndef CURL_DISABLE_RTSP
2680
0
  case CURLOPT_INTERLEAVEFUNCTION:
2681
    /* Set the user defined RTP write function */
2682
0
    s->fwrite_rtp = va_arg(param, curl_write_callback);
2683
0
    break;
2684
0
#endif
2685
0
#ifndef CURL_DISABLE_FTP
2686
0
  case CURLOPT_CHUNK_BGN_FUNCTION:
2687
0
    s->chunk_bgn = va_arg(param, curl_chunk_bgn_callback);
2688
0
    break;
2689
0
  case CURLOPT_CHUNK_END_FUNCTION:
2690
0
    s->chunk_end = va_arg(param, curl_chunk_end_callback);
2691
0
    break;
2692
0
  case CURLOPT_FNMATCH_FUNCTION:
2693
0
    s->fnmatch = va_arg(param, curl_fnmatch_callback);
2694
0
    break;
2695
0
#endif
2696
0
#ifndef CURL_DISABLE_HTTP
2697
0
  case CURLOPT_TRAILERFUNCTION:
2698
0
    s->trailer_callback = va_arg(param, curl_trailer_callback);
2699
0
    break;
2700
0
#endif
2701
0
#ifndef CURL_DISABLE_HSTS
2702
0
  case CURLOPT_HSTSREADFUNCTION:
2703
0
    s->hsts_read = va_arg(param, curl_hstsread_callback);
2704
0
    break;
2705
0
  case CURLOPT_HSTSWRITEFUNCTION:
2706
0
    s->hsts_write = va_arg(param, curl_hstswrite_callback);
2707
0
    break;
2708
0
#endif
2709
0
  case CURLOPT_PREREQFUNCTION:
2710
0
    s->fprereq = va_arg(param, curl_prereq_callback);
2711
0
    break;
2712
0
  default:
2713
0
    return CURLE_UNKNOWN_OPTION;
2714
0
  }
2715
0
  return CURLE_OK;
2716
0
}
2717
2718
static CURLcode setopt_offt(struct Curl_easy *data, CURLoption option,
2719
                            curl_off_t offt)
2720
0
{
2721
0
  struct UserDefined *s = &data->set;
2722
0
  switch(option) {
2723
0
  case CURLOPT_TIMEVALUE_LARGE:
2724
    /*
2725
     * This is the value to compare with the remote document with the
2726
     * method set with CURLOPT_TIMECONDITION
2727
     */
2728
0
    s->timevalue = (time_t)offt;
2729
0
    break;
2730
2731
    /* MQTT "borrows" some of the HTTP options */
2732
0
  case CURLOPT_POSTFIELDSIZE_LARGE:
2733
    /*
2734
     * The size of the POSTFIELD data to prevent libcurl to do strlen() to
2735
     * figure it out. Enables binary posts.
2736
     */
2737
0
    if(offt < -1)
2738
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2739
2740
0
    if(s->postfieldsize < offt && s->str_copypostfields) {
2741
      /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
2742
0
      curlx_safefree(s->str_copypostfields);
2743
0
      s->postfields = NULL;
2744
0
    }
2745
0
    s->postfieldsize = offt;
2746
0
    break;
2747
0
  case CURLOPT_INFILESIZE_LARGE:
2748
    /*
2749
     * If known, this should inform curl about the file size of the
2750
     * to-be-uploaded file.
2751
     */
2752
0
    if(offt < -1)
2753
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2754
0
    s->filesize = offt;
2755
0
    break;
2756
0
  case CURLOPT_MAX_SEND_SPEED_LARGE:
2757
    /*
2758
     * When transfer uploads are faster than CURLOPT_MAX_SEND_SPEED_LARGE
2759
     * bytes per second the transfer is throttled..
2760
     */
2761
0
    if(offt < 0)
2762
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2763
0
    s->max_send_speed = offt;
2764
    /* use minimal burst rate of 32k. some protocol batch IO */
2765
0
    Curl_rlimit_change(&data->progress.ul.rlimit, offt,
2766
0
                     CURLMAX(offt, (32 * 1024)));
2767
0
    break;
2768
0
  case CURLOPT_MAX_RECV_SPEED_LARGE:
2769
    /*
2770
     * When receiving data faster than CURLOPT_MAX_RECV_SPEED_LARGE bytes per
2771
     * second the transfer is throttled..
2772
     */
2773
0
    if(offt < 0)
2774
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2775
0
    s->max_recv_speed = offt;
2776
    /* use minimal burst rate of 32k. some protocol batch IO */
2777
0
    Curl_rlimit_change(&data->progress.dl.rlimit, offt,
2778
0
                     CURLMAX(offt, (32 * 1024)));
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
0
  case CURLOPT_MAXFILESIZE_LARGE:
2789
    /*
2790
     * Set the maximum size of a file to download.
2791
     */
2792
0
    if(offt < 0)
2793
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2794
0
    s->max_filesize = offt;
2795
0
    break;
2796
2797
0
  default:
2798
0
    return CURLE_UNKNOWN_OPTION;
2799
0
  }
2800
0
  return CURLE_OK;
2801
0
}
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
0
{
2885
0
  if(option < CURLOPTTYPE_OBJECTPOINT)
2886
0
    return setopt_long(data, option, va_arg(param, long));
2887
0
  else if(option < CURLOPTTYPE_FUNCTIONPOINT) {
2888
    /* unfortunately, different pointer types cannot be identified any other
2889
       way than being listed explicitly */
2890
0
    switch(option) {
2891
0
    case CURLOPT_HTTPHEADER:
2892
0
    case CURLOPT_QUOTE:
2893
0
    case CURLOPT_POSTQUOTE:
2894
0
    case CURLOPT_TELNETOPTIONS:
2895
0
    case CURLOPT_PREQUOTE:
2896
0
    case CURLOPT_HTTP200ALIASES:
2897
0
    case CURLOPT_MAIL_RCPT:
2898
0
    case CURLOPT_RESOLVE:
2899
0
    case CURLOPT_PROXYHEADER:
2900
0
    case CURLOPT_CONNECT_TO:
2901
0
      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
0
    default:
2912
0
      break;
2913
0
    }
2914
    /* the char pointer options */
2915
0
    return setopt_cptr(data, option, va_arg(param, char *));
2916
0
  }
2917
0
  else if(option < CURLOPTTYPE_OFF_T)
2918
0
    return setopt_func(data, option, param);
2919
0
  else if(option < CURLOPTTYPE_BLOB)
2920
0
    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
0
}
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
0
{
2934
0
  struct Curl_eapi_guard guard;
2935
0
  CURLcode result;
2936
2937
0
  if(CURL_EAPI_ENTER(&guard, curl, easy_setopt, &result)) {
2938
0
    struct Curl_easy *data = curl;
2939
0
    va_list arg;
2940
2941
0
    va_start(arg, option);
2942
2943
0
    result = Curl_vsetopt(data, option, arg);
2944
2945
0
    va_end(arg);
2946
0
    if(result == CURLE_BAD_FUNCTION_ARGUMENT)
2947
0
      failf(data, "setopt 0x%x got bad argument", (unsigned int)option);
2948
0
  }
2949
0
  CURL_EAPI_LEAVE(&guard);
2950
0
  return result;
2951
0
}