Coverage Report

Created: 2025-11-09 06:51

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