Coverage Report

Created: 2026-03-12 06:35

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