Coverage Report

Created: 2025-10-10 06:31

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
  unsigned long uarg = (unsigned long)arg;
874
0
  bool set = FALSE;
875
0
  CURLcode result = setopt_bool(data, option, arg, &set);
876
0
  struct UserDefined *s = &data->set;
877
0
  if(set || result)
878
0
    return result;
879
880
0
  switch(option) {
881
0
  case CURLOPT_DNS_CACHE_TIMEOUT:
882
0
    if(arg != -1)
883
0
      return setopt_set_timeout_sec(&s->dns_cache_timeout_ms, arg);
884
0
    s->dns_cache_timeout_ms = -1;
885
0
    break;
886
887
0
  case CURLOPT_CA_CACHE_TIMEOUT:
888
0
    if(Curl_ssl_supports(data, SSLSUPP_CA_CACHE)) {
889
0
      result = value_range(&arg, -1, -1, INT_MAX);
890
0
      if(result)
891
0
        return result;
892
893
0
      s->general_ssl.ca_cache_timeout = (int)arg;
894
0
    }
895
0
    else
896
0
      return CURLE_NOT_BUILT_IN;
897
0
    break;
898
0
  case CURLOPT_MAXCONNECTS:
899
0
    result = value_range(&arg, 1, 1, UINT_MAX);
900
0
    if(result)
901
0
      return result;
902
0
    s->maxconnects = (unsigned int)arg;
903
0
    break;
904
0
  case CURLOPT_SERVER_RESPONSE_TIMEOUT:
905
0
    return setopt_set_timeout_sec(&s->server_response_timeout, arg);
906
907
0
  case CURLOPT_SERVER_RESPONSE_TIMEOUT_MS:
908
0
    return setopt_set_timeout_ms(&s->server_response_timeout, arg);
909
910
0
#ifndef CURL_DISABLE_TFTP
911
0
  case CURLOPT_TFTP_BLKSIZE:
912
0
    result = value_range(&arg, 0, TFTP_BLKSIZE_MIN, TFTP_BLKSIZE_MAX);
913
0
    if(result)
914
0
      return result;
915
0
    s->tftp_blksize = (unsigned short)arg;
916
0
    break;
917
0
#endif
918
0
#ifndef CURL_DISABLE_NETRC
919
0
  case CURLOPT_NETRC:
920
0
    if((arg < CURL_NETRC_IGNORED) || (arg >= CURL_NETRC_LAST))
921
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
922
0
    s->use_netrc = (unsigned char)arg;
923
0
    break;
924
0
#endif
925
0
  case CURLOPT_TIMECONDITION:
926
0
    if((arg < CURL_TIMECOND_NONE) || (arg >= CURL_TIMECOND_LAST))
927
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
928
0
    s->timecondition = (unsigned char)arg;
929
0
    break;
930
0
  case CURLOPT_TIMEVALUE:
931
0
    s->timevalue = (time_t)arg;
932
0
    break;
933
0
  case CURLOPT_SSLVERSION:
934
0
#ifndef CURL_DISABLE_PROXY
935
0
  case CURLOPT_PROXY_SSLVERSION:
936
0
#endif
937
0
    return Curl_setopt_SSLVERSION(data, option, arg);
938
939
0
  case CURLOPT_POSTFIELDSIZE:
940
0
    if(arg < -1)
941
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
942
943
0
    if(s->postfieldsize < arg &&
944
0
       s->postfields == s->str[STRING_COPYPOSTFIELDS]) {
945
      /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
946
0
      Curl_safefree(s->str[STRING_COPYPOSTFIELDS]);
947
0
      s->postfields = NULL;
948
0
    }
949
950
0
    s->postfieldsize = arg;
951
0
    break;
952
0
#ifndef CURL_DISABLE_HTTP
953
0
  case CURLOPT_FOLLOWLOCATION:
954
0
    if(uarg > 3)
955
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
956
0
    s->http_follow_mode = (unsigned char)uarg;
957
0
    break;
958
959
0
  case CURLOPT_MAXREDIRS:
960
0
    result = value_range(&arg, -1, -1, 0x7fff);
961
0
    if(result)
962
0
      return result;
963
0
    s->maxredirs = (short)arg;
964
0
    break;
965
966
0
  case CURLOPT_POSTREDIR:
967
0
    if(arg < CURL_REDIR_GET_ALL)
968
      /* no return error on too high numbers since the bitmask could be
969
         extended in a future */
970
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
971
0
    s->keep_post = arg & CURL_REDIR_POST_ALL;
972
0
    break;
973
974
0
  case CURLOPT_HEADEROPT:
975
0
    s->sep_headers = !!(arg & CURLHEADER_SEPARATE);
976
0
    break;
977
0
  case CURLOPT_HTTPAUTH:
978
0
    return httpauth(data, FALSE, uarg);
979
980
0
  case CURLOPT_HTTP_VERSION:
981
0
    return setopt_HTTP_VERSION(data, arg);
982
983
0
  case CURLOPT_EXPECT_100_TIMEOUT_MS:
984
0
    result = value_range(&arg, 0, 0, 0xffff);
985
0
    if(result)
986
0
      return result;
987
0
    s->expect_100_timeout = (unsigned short)arg;
988
0
    break;
989
990
0
#endif /* ! CURL_DISABLE_HTTP */
991
992
0
#ifndef CURL_DISABLE_MIME
993
0
  case CURLOPT_MIME_OPTIONS:
994
0
    s->mime_formescape = !!(arg & CURLMIMEOPT_FORMESCAPE);
995
0
    break;
996
0
#endif
997
0
#ifndef CURL_DISABLE_PROXY
998
0
  case CURLOPT_PROXYPORT:
999
0
    if((arg < 0) || (arg > 65535))
1000
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1001
0
    s->proxyport = (unsigned short)arg;
1002
0
    break;
1003
1004
0
  case CURLOPT_PROXYAUTH:
1005
0
    return httpauth(data, TRUE, uarg);
1006
1007
0
  case CURLOPT_PROXYTYPE:
1008
0
    if((arg < CURLPROXY_HTTP) || (arg > CURLPROXY_SOCKS5_HOSTNAME))
1009
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1010
0
    s->proxytype = (unsigned char)arg;
1011
0
    break;
1012
1013
0
  case CURLOPT_SOCKS5_AUTH:
1014
0
    if(uarg & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI))
1015
0
      return CURLE_NOT_BUILT_IN;
1016
0
    s->socks5auth = (unsigned char)uarg;
1017
0
    break;
1018
0
#endif /* ! CURL_DISABLE_PROXY */
1019
1020
0
#ifndef CURL_DISABLE_FTP
1021
0
  case CURLOPT_FTP_FILEMETHOD:
1022
0
    if((arg < CURLFTPMETHOD_DEFAULT) || (arg >= CURLFTPMETHOD_LAST))
1023
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1024
0
    s->ftp_filemethod = (unsigned char)arg;
1025
0
    break;
1026
0
  case CURLOPT_FTP_SSL_CCC:
1027
0
    if((arg < CURLFTPSSL_CCC_NONE) || (arg >= CURLFTPSSL_CCC_LAST))
1028
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1029
0
    s->ftp_ccc = (unsigned char)arg;
1030
0
    break;
1031
1032
0
  case CURLOPT_FTPSSLAUTH:
1033
0
    if((arg < CURLFTPAUTH_DEFAULT) || (arg >= CURLFTPAUTH_LAST))
1034
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1035
0
    s->ftpsslauth = (unsigned char)arg;
1036
0
    break;
1037
0
  case CURLOPT_ACCEPTTIMEOUT_MS:
1038
0
    return setopt_set_timeout_ms(&s->accepttimeout, arg);
1039
0
#endif /* ! CURL_DISABLE_FTP */
1040
0
#if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
1041
0
  case CURLOPT_FTP_CREATE_MISSING_DIRS:
1042
0
    if((arg < CURLFTP_CREATE_DIR_NONE) || (arg > CURLFTP_CREATE_DIR_RETRY))
1043
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1044
0
    s->ftp_create_missing_dirs = (unsigned char)arg;
1045
0
    break;
1046
0
#endif /* ! CURL_DISABLE_FTP || USE_SSH */
1047
0
  case CURLOPT_INFILESIZE:
1048
0
    if(arg < -1)
1049
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1050
0
    s->filesize = arg;
1051
0
    break;
1052
0
  case CURLOPT_LOW_SPEED_LIMIT:
1053
0
    if(arg < 0)
1054
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1055
0
    s->low_speed_limit = arg;
1056
0
    break;
1057
0
  case CURLOPT_LOW_SPEED_TIME:
1058
0
    if(arg < 0)
1059
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1060
0
    s->low_speed_time = arg;
1061
0
    break;
1062
0
  case CURLOPT_PORT:
1063
0
    if((arg < 0) || (arg > 65535))
1064
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1065
0
    s->use_port = (unsigned short)arg;
1066
0
    break;
1067
0
  case CURLOPT_TIMEOUT:
1068
0
    return setopt_set_timeout_sec(&s->timeout, arg);
1069
1070
0
  case CURLOPT_TIMEOUT_MS:
1071
0
    return setopt_set_timeout_ms(&s->timeout, arg);
1072
1073
0
  case CURLOPT_CONNECTTIMEOUT:
1074
0
    return setopt_set_timeout_sec(&s->connecttimeout, arg);
1075
1076
0
  case CURLOPT_CONNECTTIMEOUT_MS:
1077
0
    return setopt_set_timeout_ms(&s->connecttimeout, arg);
1078
1079
0
  case CURLOPT_RESUME_FROM:
1080
0
    if(arg < -1)
1081
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1082
0
    s->set_resume_from = arg;
1083
0
    break;
1084
1085
0
#ifndef CURL_DISABLE_BINDLOCAL
1086
0
  case CURLOPT_LOCALPORT:
1087
0
    if((arg < 0) || (arg > 65535))
1088
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1089
0
    s->localport = curlx_sltous(arg);
1090
0
    break;
1091
0
  case CURLOPT_LOCALPORTRANGE:
1092
0
    if((arg < 0) || (arg > 65535))
1093
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1094
0
    s->localportrange = curlx_sltous(arg);
1095
0
    break;
1096
0
#endif
1097
1098
#ifdef HAVE_GSSAPI
1099
  case CURLOPT_GSSAPI_DELEGATION:
1100
    s->gssapi_delegation = (unsigned char)uarg&
1101
      (CURLGSSAPI_DELEGATION_POLICY_FLAG|CURLGSSAPI_DELEGATION_FLAG);
1102
    break;
1103
#endif
1104
1105
0
  case CURLOPT_SSL_FALSESTART:
1106
0
    return CURLE_NOT_BUILT_IN;
1107
0
  case CURLOPT_BUFFERSIZE:
1108
0
    result = value_range(&arg, 0, READBUFFER_MIN, READBUFFER_MAX);
1109
0
    if(result)
1110
0
      return result;
1111
0
    s->buffer_size = (unsigned int)arg;
1112
0
    break;
1113
1114
0
  case CURLOPT_UPLOAD_BUFFERSIZE:
1115
0
    result = value_range(&arg, 0, UPLOADBUFFER_MIN, UPLOADBUFFER_MAX);
1116
0
    if(result)
1117
0
      return result;
1118
0
    s->upload_buffer_size = (unsigned int)arg;
1119
0
    break;
1120
1121
0
  case CURLOPT_MAXFILESIZE:
1122
0
    if(arg < 0)
1123
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1124
0
    s->max_filesize = arg;
1125
0
    break;
1126
1127
0
#ifdef USE_SSL
1128
0
  case CURLOPT_USE_SSL:
1129
0
    if((arg < CURLUSESSL_NONE) || (arg >= CURLUSESSL_LAST))
1130
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1131
0
    s->use_ssl = (unsigned char)arg;
1132
0
    break;
1133
0
  case CURLOPT_SSL_OPTIONS:
1134
0
    set_ssl_options(&s->ssl, &s->ssl.primary, arg);
1135
0
    break;
1136
1137
0
#ifndef CURL_DISABLE_PROXY
1138
0
  case CURLOPT_PROXY_SSL_OPTIONS:
1139
0
    set_ssl_options(&s->proxy_ssl, &s->proxy_ssl.primary, arg);
1140
0
    break;
1141
0
#endif
1142
1143
0
#endif /* USE_SSL */
1144
0
  case CURLOPT_IPRESOLVE:
1145
0
    if((arg < CURL_IPRESOLVE_WHATEVER) || (arg > CURL_IPRESOLVE_V6))
1146
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1147
0
    s->ipver = (unsigned char) arg;
1148
0
    break;
1149
1150
0
  case CURLOPT_CONNECT_ONLY:
1151
0
    if(arg < 0 || arg > 2)
1152
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1153
0
    s->connect_only = !!arg;
1154
0
    s->connect_only_ws = (arg == 2);
1155
0
    break;
1156
1157
1158
#ifdef USE_SSH
1159
  case CURLOPT_SSH_AUTH_TYPES:
1160
    s->ssh_auth_types = (int)arg;
1161
    break;
1162
#endif
1163
1164
0
#if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
1165
0
  case CURLOPT_NEW_FILE_PERMS:
1166
0
    if((arg < 0) || (arg > 0777))
1167
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1168
0
    s->new_file_perms = (unsigned int)arg;
1169
0
    break;
1170
0
#endif
1171
#ifdef USE_SSH
1172
  case CURLOPT_NEW_DIRECTORY_PERMS:
1173
    if((arg < 0) || (arg > 0777))
1174
      return CURLE_BAD_FUNCTION_ARGUMENT;
1175
    s->new_directory_perms = (unsigned int)arg;
1176
    break;
1177
#endif
1178
0
#ifdef USE_IPV6
1179
0
  case CURLOPT_ADDRESS_SCOPE:
1180
0
#if SIZEOF_LONG > 4
1181
0
    if(uarg > UINT_MAX)
1182
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1183
0
#endif
1184
0
    s->scope_id = (unsigned int)uarg;
1185
0
    break;
1186
0
#endif
1187
0
  case CURLOPT_PROTOCOLS:
1188
0
    s->allowed_protocols = (curl_prot_t)arg;
1189
0
    break;
1190
1191
0
  case CURLOPT_REDIR_PROTOCOLS:
1192
0
    s->redir_protocols = (curl_prot_t)arg;
1193
0
    break;
1194
1195
0
#ifndef CURL_DISABLE_RTSP
1196
0
  case CURLOPT_RTSP_REQUEST:
1197
0
    return setopt_RTSP_REQUEST(data, arg);
1198
0
  case CURLOPT_RTSP_CLIENT_CSEQ:
1199
0
    data->state.rtsp_next_client_CSeq = arg;
1200
0
    break;
1201
1202
0
  case CURLOPT_RTSP_SERVER_CSEQ:
1203
0
    data->state.rtsp_next_server_CSeq = arg;
1204
0
    break;
1205
1206
0
#endif /* ! CURL_DISABLE_RTSP */
1207
1208
0
  case CURLOPT_TCP_KEEPIDLE:
1209
0
    result = value_range(&arg, 0, 0, INT_MAX);
1210
0
    if(result)
1211
0
      return result;
1212
0
    s->tcp_keepidle = (int)arg;
1213
0
    break;
1214
0
  case CURLOPT_TCP_KEEPINTVL:
1215
0
    result = value_range(&arg, 0, 0, INT_MAX);
1216
0
    if(result)
1217
0
      return result;
1218
0
    s->tcp_keepintvl = (int)arg;
1219
0
    break;
1220
0
  case CURLOPT_TCP_KEEPCNT:
1221
0
    result = value_range(&arg, 0, 0, INT_MAX);
1222
0
    if(result)
1223
0
      return result;
1224
0
    s->tcp_keepcnt = (int)arg;
1225
0
    break;
1226
0
  case CURLOPT_SSL_ENABLE_NPN:
1227
0
    break;
1228
0
  case CURLOPT_STREAM_WEIGHT:
1229
#if defined(USE_HTTP2) || defined(USE_HTTP3)
1230
    if((arg >= 1) && (arg <= 256))
1231
      s->priority.weight = (int)arg;
1232
    break;
1233
#else
1234
0
    return CURLE_NOT_BUILT_IN;
1235
0
#endif
1236
0
  case CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS:
1237
0
    return setopt_set_timeout_ms(&s->happy_eyeballs_timeout, arg);
1238
1239
0
  case CURLOPT_UPKEEP_INTERVAL_MS:
1240
0
    if(arg < 0)
1241
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1242
0
    s->upkeep_interval_ms = arg;
1243
0
    break;
1244
0
  case CURLOPT_MAXAGE_CONN:
1245
0
    return setopt_set_timeout_sec(&s->conn_max_idle_ms, arg);
1246
1247
0
  case CURLOPT_MAXLIFETIME_CONN:
1248
0
    return setopt_set_timeout_sec(&s->conn_max_age_ms, arg);
1249
1250
0
#ifndef CURL_DISABLE_HSTS
1251
0
  case CURLOPT_HSTS_CTRL:
1252
0
    if(arg & CURLHSTS_ENABLE) {
1253
0
      if(!data->hsts) {
1254
0
        data->hsts = Curl_hsts_init();
1255
0
        if(!data->hsts)
1256
0
          return CURLE_OUT_OF_MEMORY;
1257
0
      }
1258
0
    }
1259
0
    else
1260
0
      Curl_hsts_cleanup(&data->hsts);
1261
0
    break;
1262
0
#endif /* ! CURL_DISABLE_HSTS */
1263
0
#ifndef CURL_DISABLE_ALTSVC
1264
0
  case CURLOPT_ALTSVC_CTRL:
1265
0
    if(!arg) {
1266
0
      DEBUGF(infof(data, "bad CURLOPT_ALTSVC_CTRL input"));
1267
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1268
0
    }
1269
0
    if(!data->asi) {
1270
0
      data->asi = Curl_altsvc_init();
1271
0
      if(!data->asi)
1272
0
        return CURLE_OUT_OF_MEMORY;
1273
0
    }
1274
0
    return Curl_altsvc_ctrl(data->asi, arg);
1275
0
#endif /* ! CURL_DISABLE_ALTSVC */
1276
0
#ifndef CURL_DISABLE_WEBSOCKETS
1277
0
  case CURLOPT_WS_OPTIONS:
1278
0
    s->ws_raw_mode = (bool)(arg & CURLWS_RAW_MODE);
1279
0
    s->ws_no_auto_pong = (bool)(arg & CURLWS_NOAUTOPONG);
1280
0
    break;
1281
0
#endif
1282
0
  case CURLOPT_DNS_USE_GLOBAL_CACHE:
1283
    /* deprecated */
1284
0
    break;
1285
0
  case CURLOPT_SSLENGINE_DEFAULT:
1286
0
    Curl_safefree(s->str[STRING_SSL_ENGINE]);
1287
0
    return Curl_ssl_set_engine_default(data);
1288
0
  case CURLOPT_UPLOAD_FLAGS:
1289
0
    s->upload_flags = (unsigned char)arg;
1290
0
    break;
1291
0
  default:
1292
0
    return CURLE_UNKNOWN_OPTION;
1293
0
  }
1294
0
  return CURLE_OK;
1295
0
}
1296
1297
static CURLcode setopt_slist(struct Curl_easy *data, CURLoption option,
1298
                             struct curl_slist *slist)
1299
0
{
1300
0
  CURLcode result = CURLE_OK;
1301
0
  struct UserDefined *s = &data->set;
1302
0
  switch(option) {
1303
0
#ifndef CURL_DISABLE_PROXY
1304
0
  case CURLOPT_PROXYHEADER:
1305
    /*
1306
     * Set a list with proxy headers to use (or replace internals with)
1307
     *
1308
     * Since CURLOPT_HTTPHEADER was the only way to set HTTP headers for a
1309
     * long time we remain doing it this way until CURLOPT_PROXYHEADER is
1310
     * used. As soon as this option has been used, if set to anything but
1311
     * NULL, custom headers for proxies are only picked from this list.
1312
     *
1313
     * Set this option to NULL to restore the previous behavior.
1314
     */
1315
0
    s->proxyheaders = slist;
1316
0
    break;
1317
0
#endif
1318
0
#ifndef CURL_DISABLE_HTTP
1319
0
  case CURLOPT_HTTP200ALIASES:
1320
    /*
1321
     * Set a list of aliases for HTTP 200 in response header
1322
     */
1323
0
    s->http200aliases = slist;
1324
0
    break;
1325
0
#endif
1326
0
#if !defined(CURL_DISABLE_FTP) || defined(USE_SSH)
1327
0
  case CURLOPT_POSTQUOTE:
1328
    /*
1329
     * List of RAW FTP commands to use after a transfer
1330
     */
1331
0
    s->postquote = slist;
1332
0
    break;
1333
0
  case CURLOPT_PREQUOTE:
1334
    /*
1335
     * List of RAW FTP commands to use prior to RETR (Wesley Laxton)
1336
     */
1337
0
    s->prequote = slist;
1338
0
    break;
1339
0
  case CURLOPT_QUOTE:
1340
    /*
1341
     * List of RAW FTP commands to use before a transfer
1342
     */
1343
0
    s->quote = slist;
1344
0
    break;
1345
0
#endif
1346
0
  case CURLOPT_RESOLVE:
1347
    /*
1348
     * List of HOST:PORT:[addresses] strings to populate the DNS cache with
1349
     * Entries added this way will remain in the cache until explicitly
1350
     * removed or the handle is cleaned up.
1351
     *
1352
     * Prefix the HOST with plus sign (+) to have the entry expire just like
1353
     * automatically added entries.
1354
     *
1355
     * Prefix the HOST with dash (-) to _remove_ the entry from the cache.
1356
     *
1357
     * This API can remove any entry from the DNS cache, but only entries
1358
     * that are not actually in use right now will be pruned immediately.
1359
     */
1360
0
    s->resolve = slist;
1361
0
    data->state.resolve = s->resolve;
1362
0
    break;
1363
0
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_MIME)
1364
0
  case CURLOPT_HTTPHEADER:
1365
    /*
1366
     * Set a list with HTTP headers to use (or replace internals with)
1367
     */
1368
0
    s->headers = slist;
1369
0
    break;
1370
0
#endif
1371
0
#ifndef CURL_DISABLE_TELNET
1372
0
  case CURLOPT_TELNETOPTIONS:
1373
    /*
1374
     * Set a linked list of telnet options
1375
     */
1376
0
    s->telnet_options = slist;
1377
0
    break;
1378
0
#endif
1379
0
#ifndef CURL_DISABLE_SMTP
1380
0
  case CURLOPT_MAIL_RCPT:
1381
    /* Set the list of mail recipients */
1382
0
    s->mail_rcpt = slist;
1383
0
    break;
1384
0
#endif
1385
0
  case CURLOPT_CONNECT_TO:
1386
0
    s->connect_to = slist;
1387
0
    break;
1388
0
  default:
1389
0
    return CURLE_UNKNOWN_OPTION;
1390
0
  }
1391
0
  return result;
1392
0
}
1393
1394
/* assorted pointer type arguments */
1395
static CURLcode setopt_pointers(struct Curl_easy *data, CURLoption option,
1396
                                va_list param)
1397
0
{
1398
0
  CURLcode result = CURLE_OK;
1399
0
  struct UserDefined *s = &data->set;
1400
0
  switch(option) {
1401
0
#ifndef CURL_DISABLE_HTTP
1402
0
#ifndef CURL_DISABLE_FORM_API
1403
0
  case CURLOPT_HTTPPOST:
1404
    /*
1405
     * Set to make us do HTTP POST. Legacy API-style.
1406
     */
1407
0
    s->httppost = va_arg(param, struct curl_httppost *);
1408
0
    s->method = HTTPREQ_POST_FORM;
1409
0
    s->opt_no_body = FALSE; /* this is implied */
1410
0
    Curl_mime_cleanpart(data->state.formp);
1411
0
    Curl_safefree(data->state.formp);
1412
0
    data->state.mimepost = NULL;
1413
0
    break;
1414
0
#endif /* ! CURL_DISABLE_FORM_API */
1415
0
#endif /* ! CURL_DISABLE_HTTP */
1416
0
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) ||       \
1417
0
    !defined(CURL_DISABLE_IMAP)
1418
0
# ifndef CURL_DISABLE_MIME
1419
0
  case CURLOPT_MIMEPOST:
1420
    /*
1421
     * Set to make us do MIME POST
1422
     */
1423
0
    result = Curl_mime_set_subparts(&s->mimepost,
1424
0
                                    va_arg(param, curl_mime *),
1425
0
                                    FALSE);
1426
0
    if(!result) {
1427
0
      s->method = HTTPREQ_POST_MIME;
1428
0
      s->opt_no_body = FALSE; /* this is implied */
1429
0
#ifndef CURL_DISABLE_FORM_API
1430
0
      Curl_mime_cleanpart(data->state.formp);
1431
0
      Curl_safefree(data->state.formp);
1432
0
      data->state.mimepost = NULL;
1433
0
#endif
1434
0
    }
1435
0
    break;
1436
0
#endif /* ! CURL_DISABLE_MIME */
1437
0
#endif /* ! disabled HTTP, SMTP or IMAP */
1438
0
  case CURLOPT_STDERR:
1439
    /*
1440
     * Set to a FILE * that should receive all error writes. This
1441
     * defaults to stderr for normal operations.
1442
     */
1443
0
    s->err = va_arg(param, FILE *);
1444
0
    if(!s->err)
1445
0
      s->err = stderr;
1446
0
    break;
1447
0
  case CURLOPT_SHARE:
1448
0
  {
1449
0
    struct Curl_share *set = va_arg(param, struct Curl_share *);
1450
1451
    /* disconnect from old share, if any */
1452
0
    if(data->share) {
1453
0
      Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
1454
1455
0
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
1456
0
      if(data->share->cookies == data->cookies)
1457
0
        data->cookies = NULL;
1458
0
#endif
1459
1460
0
#ifndef CURL_DISABLE_HSTS
1461
0
      if(data->share->hsts == data->hsts)
1462
0
        data->hsts = NULL;
1463
0
#endif
1464
#ifdef USE_LIBPSL
1465
      if(data->psl == &data->share->psl)
1466
        data->psl = data->multi ? &data->multi->psl : NULL;
1467
#endif
1468
0
      if(data->share->specifier & (1 << CURL_LOCK_DATA_DNS)) {
1469
0
        Curl_resolv_unlink(data, &data->state.dns[0]);
1470
0
        Curl_resolv_unlink(data, &data->state.dns[1]);
1471
0
      }
1472
1473
0
      data->share->dirty--;
1474
1475
0
      Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
1476
0
      data->share = NULL;
1477
0
    }
1478
1479
0
    if(GOOD_SHARE_HANDLE(set))
1480
      /* use new share if it set */
1481
0
      data->share = set;
1482
0
    if(data->share) {
1483
1484
0
      Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
1485
1486
0
      data->share->dirty++;
1487
1488
0
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
1489
0
      if(data->share->cookies) {
1490
        /* use shared cookie list, first free own one if any */
1491
0
        Curl_cookie_cleanup(data->cookies);
1492
        /* enable cookies since we now use a share that uses cookies! */
1493
0
        data->cookies = data->share->cookies;
1494
0
      }
1495
0
#endif   /* CURL_DISABLE_HTTP */
1496
0
#ifndef CURL_DISABLE_HSTS
1497
0
      if(data->share->hsts) {
1498
        /* first free the private one if any */
1499
0
        Curl_hsts_cleanup(&data->hsts);
1500
0
        data->hsts = data->share->hsts;
1501
0
      }
1502
0
#endif
1503
#ifdef USE_LIBPSL
1504
      if(data->share->specifier & (1 << CURL_LOCK_DATA_PSL))
1505
        data->psl = &data->share->psl;
1506
#endif
1507
1508
0
      Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
1509
0
    }
1510
    /* check for host cache not needed,
1511
     * it will be done by curl_easy_perform */
1512
0
  }
1513
0
  break;
1514
1515
#ifdef USE_HTTP2
1516
  case CURLOPT_STREAM_DEPENDS:
1517
  case CURLOPT_STREAM_DEPENDS_E: {
1518
    struct Curl_easy *dep = va_arg(param, struct Curl_easy *);
1519
    if(!dep || GOOD_EASY_HANDLE(dep))
1520
      return Curl_data_priority_add_child(dep, data,
1521
                                          option == CURLOPT_STREAM_DEPENDS_E);
1522
    break;
1523
  }
1524
#endif
1525
1526
0
  default:
1527
0
    return CURLE_UNKNOWN_OPTION;
1528
0
  }
1529
0
  return result;
1530
0
}
1531
1532
#ifndef CURL_DISABLE_COOKIES
1533
static CURLcode cookielist(struct Curl_easy *data,
1534
                           const char *ptr)
1535
0
{
1536
0
  if(!ptr)
1537
0
    return CURLE_OK;
1538
1539
0
  if(curl_strequal(ptr, "ALL")) {
1540
    /* clear all cookies */
1541
0
    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
1542
0
    Curl_cookie_clearall(data->cookies);
1543
0
    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
1544
0
  }
1545
0
  else if(curl_strequal(ptr, "SESS")) {
1546
    /* clear session cookies */
1547
0
    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
1548
0
    Curl_cookie_clearsess(data->cookies);
1549
0
    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
1550
0
  }
1551
0
  else if(curl_strequal(ptr, "FLUSH")) {
1552
    /* flush cookies to file, takes care of the locking */
1553
0
    Curl_flush_cookies(data, FALSE);
1554
0
  }
1555
0
  else if(curl_strequal(ptr, "RELOAD")) {
1556
    /* reload cookies from file */
1557
0
    Curl_cookie_loadfiles(data);
1558
0
  }
1559
0
  else {
1560
0
    if(!data->cookies) {
1561
      /* if cookie engine was not running, activate it */
1562
0
      data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE);
1563
0
      if(!data->cookies)
1564
0
        return CURLE_OUT_OF_MEMORY;
1565
0
    }
1566
1567
    /* general protection against mistakes and abuse */
1568
0
    if(strlen(ptr) > CURL_MAX_INPUT_LENGTH)
1569
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1570
1571
0
    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
1572
0
    if(checkprefix("Set-Cookie:", ptr))
1573
      /* HTTP Header format line */
1574
0
      Curl_cookie_add(data, data->cookies, TRUE, FALSE, ptr + 11, NULL,
1575
0
                      NULL, TRUE);
1576
0
    else
1577
      /* Netscape format line */
1578
0
      Curl_cookie_add(data, data->cookies, FALSE, FALSE, ptr, NULL,
1579
0
                      NULL, TRUE);
1580
0
    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
1581
0
  }
1582
0
  return CURLE_OK;
1583
0
}
1584
1585
static CURLcode cookiefile(struct Curl_easy *data,
1586
                           const char *ptr)
1587
0
{
1588
  /*
1589
   * Set cookie file to read and parse. Can be used multiple times.
1590
   */
1591
0
  if(ptr) {
1592
0
    struct curl_slist *cl;
1593
    /* general protection against mistakes and abuse */
1594
0
    if(strlen(ptr) > CURL_MAX_INPUT_LENGTH)
1595
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
1596
    /* append the cookie filename to the list of filenames, and deal with
1597
       them later */
1598
0
    cl = curl_slist_append(data->state.cookielist, ptr);
1599
0
    if(!cl) {
1600
0
      curl_slist_free_all(data->state.cookielist);
1601
0
      data->state.cookielist = NULL;
1602
0
      return CURLE_OUT_OF_MEMORY;
1603
0
    }
1604
0
    data->state.cookielist = cl; /* store the list for later use */
1605
0
  }
1606
0
  else {
1607
    /* clear the list of cookie files */
1608
0
    curl_slist_free_all(data->state.cookielist);
1609
0
    data->state.cookielist = NULL;
1610
1611
0
    if(!data->share || !data->share->cookies) {
1612
      /* throw away all existing cookies if this is not a shared cookie
1613
         container */
1614
0
      Curl_cookie_clearall(data->cookies);
1615
0
      Curl_cookie_cleanup(data->cookies);
1616
0
    }
1617
    /* disable the cookie engine */
1618
0
    data->cookies = NULL;
1619
0
  }
1620
0
  return CURLE_OK;
1621
0
}
1622
#endif
1623
1624
static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option,
1625
                            char *ptr)
1626
0
{
1627
0
  CURLcode result = CURLE_OK;
1628
0
  struct UserDefined *s = &data->set;
1629
0
  switch(option) {
1630
0
  case CURLOPT_SSL_CIPHER_LIST:
1631
0
    if(Curl_ssl_supports(data, SSLSUPP_CIPHER_LIST))
1632
      /* set a list of cipher we want to use in the SSL connection */
1633
0
      return Curl_setstropt(&s->str[STRING_SSL_CIPHER_LIST], ptr);
1634
0
    else
1635
0
      return CURLE_NOT_BUILT_IN;
1636
0
#ifndef CURL_DISABLE_PROXY
1637
0
  case CURLOPT_PROXY_SSL_CIPHER_LIST:
1638
0
    if(Curl_ssl_supports(data, SSLSUPP_CIPHER_LIST)) {
1639
      /* set a list of cipher we want to use in the SSL connection for proxy */
1640
0
      return Curl_setstropt(&s->str[STRING_SSL_CIPHER_LIST_PROXY],
1641
0
                            ptr);
1642
0
    }
1643
0
    else
1644
0
      return CURLE_NOT_BUILT_IN;
1645
0
#endif
1646
0
  case CURLOPT_TLS13_CIPHERS:
1647
0
    if(Curl_ssl_supports(data, SSLSUPP_TLS13_CIPHERSUITES)) {
1648
      /* set preferred list of TLS 1.3 cipher suites */
1649
0
      return Curl_setstropt(&s->str[STRING_SSL_CIPHER13_LIST], ptr);
1650
0
    }
1651
0
    else
1652
0
      return CURLE_NOT_BUILT_IN;
1653
0
#ifndef CURL_DISABLE_PROXY
1654
0
  case CURLOPT_PROXY_TLS13_CIPHERS:
1655
0
    if(Curl_ssl_supports(data, SSLSUPP_TLS13_CIPHERSUITES))
1656
      /* set preferred list of TLS 1.3 cipher suites for proxy */
1657
0
      return Curl_setstropt(&s->str[STRING_SSL_CIPHER13_LIST_PROXY],
1658
0
                            ptr);
1659
0
    else
1660
0
      return CURLE_NOT_BUILT_IN;
1661
0
#endif
1662
0
  case CURLOPT_RANDOM_FILE:
1663
0
    break;
1664
0
  case CURLOPT_EGDSOCKET:
1665
0
    break;
1666
0
  case CURLOPT_REQUEST_TARGET:
1667
0
    return Curl_setstropt(&s->str[STRING_TARGET], ptr);
1668
0
#ifndef CURL_DISABLE_NETRC
1669
0
  case CURLOPT_NETRC_FILE:
1670
    /*
1671
     * Use this file instead of the $HOME/.netrc file
1672
     */
1673
0
    return Curl_setstropt(&s->str[STRING_NETRC_FILE], ptr);
1674
0
#endif
1675
1676
0
#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_MQTT)
1677
0
  case CURLOPT_COPYPOSTFIELDS:
1678
    /*
1679
     * A string with POST data. Makes curl HTTP POST. Even if it is NULL.
1680
     * If needed, CURLOPT_POSTFIELDSIZE must have been set prior to
1681
     *  CURLOPT_COPYPOSTFIELDS and not altered later.
1682
     */
1683
0
    if(!ptr || s->postfieldsize == -1)
1684
0
      result = Curl_setstropt(&s->str[STRING_COPYPOSTFIELDS], ptr);
1685
0
    else {
1686
0
      if(s->postfieldsize < 0)
1687
0
        return CURLE_BAD_FUNCTION_ARGUMENT;
1688
#if SIZEOF_CURL_OFF_T > SIZEOF_SIZE_T
1689
      /*
1690
       *  Check that requested length does not overflow the size_t type.
1691
       */
1692
      else if(s->postfieldsize > SIZE_MAX)
1693
        return CURLE_OUT_OF_MEMORY;
1694
#endif
1695
0
      else {
1696
        /* Allocate even when size == 0. This satisfies the need of possible
1697
           later address compare to detect the COPYPOSTFIELDS mode, and to
1698
           mark that postfields is used rather than read function or form
1699
           data.
1700
        */
1701
0
        char *p = Curl_memdup0(ptr, (size_t)s->postfieldsize);
1702
0
        if(!p)
1703
0
          return CURLE_OUT_OF_MEMORY;
1704
0
        else {
1705
0
          free(s->str[STRING_COPYPOSTFIELDS]);
1706
0
          s->str[STRING_COPYPOSTFIELDS] = p;
1707
0
        }
1708
0
      }
1709
0
    }
1710
1711
0
    s->postfields = s->str[STRING_COPYPOSTFIELDS];
1712
0
    s->method = HTTPREQ_POST;
1713
0
    break;
1714
1715
0
  case CURLOPT_POSTFIELDS:
1716
    /*
1717
     * Like above, but use static data instead of copying it.
1718
     */
1719
0
    s->postfields = ptr;
1720
    /* Release old copied data. */
1721
0
    Curl_safefree(s->str[STRING_COPYPOSTFIELDS]);
1722
0
    s->method = HTTPREQ_POST;
1723
0
    break;
1724
0
#endif /* ! CURL_DISABLE_HTTP || ! CURL_DISABLE_MQTT */
1725
1726
0
#ifndef CURL_DISABLE_HTTP
1727
0
  case CURLOPT_ACCEPT_ENCODING:
1728
    /*
1729
     * String to use at the value of Accept-Encoding header.
1730
     *
1731
     * If the encoding is set to "" we use an Accept-Encoding header that
1732
     * encompasses all the encodings we support.
1733
     * If the encoding is set to NULL we do not send an Accept-Encoding header
1734
     * and ignore an received Content-Encoding header.
1735
     *
1736
     */
1737
0
    if(ptr && !*ptr) {
1738
0
      char all[256];
1739
0
      Curl_all_content_encodings(all, sizeof(all));
1740
0
      return Curl_setstropt(&s->str[STRING_ENCODING], all);
1741
0
    }
1742
0
    return Curl_setstropt(&s->str[STRING_ENCODING], ptr);
1743
1744
0
#ifndef CURL_DISABLE_AWS
1745
0
  case CURLOPT_AWS_SIGV4:
1746
    /*
1747
     * String that is merged to some authentication
1748
     * parameters are used by the algorithm.
1749
     */
1750
0
    result = Curl_setstropt(&s->str[STRING_AWS_SIGV4], ptr);
1751
    /*
1752
     * Basic been set by default it need to be unset here
1753
     */
1754
0
    if(s->str[STRING_AWS_SIGV4])
1755
0
      s->httpauth = CURLAUTH_AWS_SIGV4;
1756
0
    break;
1757
0
#endif
1758
0
  case CURLOPT_REFERER:
1759
    /*
1760
     * String to set in the HTTP Referer: field.
1761
     */
1762
0
    if(data->state.referer_alloc) {
1763
0
      Curl_safefree(data->state.referer);
1764
0
      data->state.referer_alloc = FALSE;
1765
0
    }
1766
0
    result = Curl_setstropt(&s->str[STRING_SET_REFERER], ptr);
1767
0
    data->state.referer = s->str[STRING_SET_REFERER];
1768
0
    break;
1769
1770
0
  case CURLOPT_USERAGENT:
1771
    /*
1772
     * String to use in the HTTP User-Agent field
1773
     */
1774
0
    return Curl_setstropt(&s->str[STRING_USERAGENT], ptr);
1775
1776
0
#ifndef CURL_DISABLE_COOKIES
1777
0
  case CURLOPT_COOKIE:
1778
    /*
1779
     * Cookie string to send to the remote server in the request.
1780
     */
1781
0
    return Curl_setstropt(&s->str[STRING_COOKIE], ptr);
1782
1783
0
  case CURLOPT_COOKIEFILE:
1784
0
    return cookiefile(data, ptr);
1785
1786
0
  case CURLOPT_COOKIEJAR:
1787
    /*
1788
     * Set cookie filename to dump all cookies to when we are done.
1789
     */
1790
0
    result = Curl_setstropt(&s->str[STRING_COOKIEJAR], ptr);
1791
0
    if(!result) {
1792
      /*
1793
       * Activate the cookie parser. This may or may not already
1794
       * have been made.
1795
       */
1796
0
      struct CookieInfo *newcookies =
1797
0
        Curl_cookie_init(data, NULL, data->cookies, s->cookiesession);
1798
0
      if(!newcookies)
1799
0
        result = CURLE_OUT_OF_MEMORY;
1800
0
      data->cookies = newcookies;
1801
0
    }
1802
0
    break;
1803
1804
0
  case CURLOPT_COOKIELIST:
1805
0
    return cookielist(data, ptr);
1806
0
#endif /* !CURL_DISABLE_COOKIES */
1807
1808
0
#endif /* ! CURL_DISABLE_HTTP */
1809
1810
0
  case CURLOPT_CUSTOMREQUEST:
1811
    /*
1812
     * Set a custom string to use as request
1813
     */
1814
0
    return Curl_setstropt(&s->str[STRING_CUSTOMREQUEST], ptr);
1815
1816
    /* we do not set
1817
       s->method = HTTPREQ_CUSTOM;
1818
       here, we continue as if we were using the already set type
1819
       and this just changes the actual request keyword */
1820
1821
0
#ifndef CURL_DISABLE_PROXY
1822
0
  case CURLOPT_PROXY:
1823
    /*
1824
     * Set proxy server:port to use as proxy.
1825
     *
1826
     * If the proxy is set to "" (and CURLOPT_SOCKS_PROXY is set to "" or NULL)
1827
     * we explicitly say that we do not want to use a proxy
1828
     * (even though there might be environment variables saying so).
1829
     *
1830
     * Setting it to NULL, means no proxy but allows the environment variables
1831
     * to decide for us (if CURLOPT_SOCKS_PROXY setting it to NULL).
1832
     */
1833
0
    return Curl_setstropt(&s->str[STRING_PROXY], ptr);
1834
1835
0
  case CURLOPT_PRE_PROXY:
1836
    /*
1837
     * Set proxy server:port to use as SOCKS proxy.
1838
     *
1839
     * If the proxy is set to "" or NULL we explicitly say that we do not want
1840
     * to use the socks proxy.
1841
     */
1842
0
    return Curl_setstropt(&s->str[STRING_PRE_PROXY], ptr);
1843
0
#endif   /* CURL_DISABLE_PROXY */
1844
1845
0
#ifndef CURL_DISABLE_PROXY
1846
0
  case CURLOPT_SOCKS5_GSSAPI_SERVICE:
1847
0
  case CURLOPT_PROXY_SERVICE_NAME:
1848
    /*
1849
     * Set proxy authentication service name for Kerberos 5 and SPNEGO
1850
     */
1851
0
    return Curl_setstropt(&s->str[STRING_PROXY_SERVICE_NAME], ptr);
1852
0
#endif
1853
0
  case CURLOPT_SERVICE_NAME:
1854
    /*
1855
     * Set authentication service name for DIGEST-MD5, Kerberos 5 and SPNEGO
1856
     */
1857
0
    return Curl_setstropt(&s->str[STRING_SERVICE_NAME], ptr);
1858
1859
0
  case CURLOPT_HEADERDATA:
1860
    /*
1861
     * Custom pointer to pass the header write callback function
1862
     */
1863
0
    s->writeheader = ptr;
1864
0
    break;
1865
0
  case CURLOPT_READDATA:
1866
    /*
1867
     * FILE pointer to read the file to be uploaded from. Or possibly used as
1868
     * argument to the read callback.
1869
     */
1870
0
    s->in_set = ptr;
1871
0
    break;
1872
0
  case CURLOPT_WRITEDATA:
1873
    /*
1874
     * FILE pointer to write to. Or possibly used as argument to the write
1875
     * callback.
1876
     */
1877
0
    s->out = ptr;
1878
0
    break;
1879
0
  case CURLOPT_DEBUGDATA:
1880
    /*
1881
     * Set to a void * that should receive all error writes. This
1882
     * defaults to CURLOPT_STDERR for normal operations.
1883
     */
1884
0
    s->debugdata = ptr;
1885
0
    break;
1886
0
  case CURLOPT_PROGRESSDATA:
1887
    /*
1888
     * Custom client data to pass to the progress callback
1889
     */
1890
0
    s->progress_client = ptr;
1891
0
    break;
1892
0
  case CURLOPT_SEEKDATA:
1893
    /*
1894
     * Seek control callback. Might be NULL.
1895
     */
1896
0
    s->seek_client = ptr;
1897
0
    break;
1898
0
  case CURLOPT_IOCTLDATA:
1899
    /*
1900
     * I/O control data pointer. Might be NULL.
1901
     */
1902
0
    s->ioctl_client = ptr;
1903
0
    break;
1904
0
  case CURLOPT_SSL_CTX_DATA:
1905
    /*
1906
     * Set an SSL_CTX callback parameter pointer
1907
     */
1908
0
#ifdef USE_SSL
1909
0
    if(Curl_ssl_supports(data, SSLSUPP_SSL_CTX)) {
1910
0
      s->ssl.fsslctxp = ptr;
1911
0
      break;
1912
0
    }
1913
0
    else
1914
0
#endif
1915
0
      return CURLE_NOT_BUILT_IN;
1916
0
  case CURLOPT_SOCKOPTDATA:
1917
    /*
1918
     * socket callback data pointer. Might be NULL.
1919
     */
1920
0
    s->sockopt_client = ptr;
1921
0
    break;
1922
0
  case CURLOPT_OPENSOCKETDATA:
1923
    /*
1924
     * socket callback data pointer. Might be NULL.
1925
     */
1926
0
    s->opensocket_client = ptr;
1927
0
    break;
1928
0
  case CURLOPT_RESOLVER_START_DATA:
1929
    /*
1930
     * resolver start callback data pointer. Might be NULL.
1931
     */
1932
0
    s->resolver_start_client = ptr;
1933
0
    break;
1934
0
  case CURLOPT_CLOSESOCKETDATA:
1935
    /*
1936
     * socket callback data pointer. Might be NULL.
1937
     */
1938
0
    s->closesocket_client = ptr;
1939
0
    break;
1940
0
  case CURLOPT_TRAILERDATA:
1941
0
#ifndef CURL_DISABLE_HTTP
1942
0
    s->trailer_data = ptr;
1943
0
#endif
1944
0
    break;
1945
0
  case CURLOPT_PREREQDATA:
1946
0
    s->prereq_userp = ptr;
1947
0
    break;
1948
1949
0
  case CURLOPT_ERRORBUFFER:
1950
    /*
1951
     * Error buffer provided by the caller to get the human readable error
1952
     * string in.
1953
     */
1954
0
    s->errorbuffer = ptr;
1955
0
    break;
1956
1957
0
#ifndef CURL_DISABLE_FTP
1958
0
  case CURLOPT_FTPPORT:
1959
    /*
1960
     * Use FTP PORT, this also specifies which IP address to use
1961
     */
1962
0
    result = Curl_setstropt(&s->str[STRING_FTPPORT], ptr);
1963
0
    s->ftp_use_port = !!(s->str[STRING_FTPPORT]);
1964
0
    break;
1965
1966
0
  case CURLOPT_FTP_ACCOUNT:
1967
0
    return Curl_setstropt(&s->str[STRING_FTP_ACCOUNT], ptr);
1968
1969
0
  case CURLOPT_FTP_ALTERNATIVE_TO_USER:
1970
0
    return Curl_setstropt(&s->str[STRING_FTP_ALTERNATIVE_TO_USER], ptr);
1971
1972
0
  case CURLOPT_KRBLEVEL:
1973
0
    return CURLE_NOT_BUILT_IN; /* removed in 8.17.0 */
1974
0
#endif
1975
0
  case CURLOPT_URL:
1976
    /*
1977
     * The URL to fetch.
1978
     */
1979
0
    if(data->state.url_alloc) {
1980
0
      Curl_safefree(data->state.url);
1981
0
      data->state.url_alloc = FALSE;
1982
0
    }
1983
0
    result = Curl_setstropt(&s->str[STRING_SET_URL], ptr);
1984
0
    data->state.url = s->str[STRING_SET_URL];
1985
0
    break;
1986
1987
0
  case CURLOPT_USERPWD:
1988
    /*
1989
     * user:password to use in the operation
1990
     */
1991
0
    return setstropt_userpwd(ptr, &s->str[STRING_USERNAME],
1992
0
                             &s->str[STRING_PASSWORD]);
1993
1994
0
  case CURLOPT_USERNAME:
1995
    /*
1996
     * authentication username to use in the operation
1997
     */
1998
0
    return Curl_setstropt(&s->str[STRING_USERNAME], ptr);
1999
2000
0
  case CURLOPT_PASSWORD:
2001
    /*
2002
     * authentication password to use in the operation
2003
     */
2004
0
    return Curl_setstropt(&s->str[STRING_PASSWORD], ptr);
2005
2006
0
  case CURLOPT_LOGIN_OPTIONS:
2007
    /*
2008
     * authentication options to use in the operation
2009
     */
2010
0
    return Curl_setstropt(&s->str[STRING_OPTIONS], ptr);
2011
2012
0
  case CURLOPT_XOAUTH2_BEARER:
2013
    /*
2014
     * OAuth 2.0 bearer token to use in the operation
2015
     */
2016
0
    return Curl_setstropt(&s->str[STRING_BEARER], ptr);
2017
2018
0
#ifndef CURL_DISABLE_PROXY
2019
0
  case CURLOPT_PROXYUSERPWD: {
2020
    /*
2021
     * user:password needed to use the proxy
2022
     */
2023
0
    char *u = NULL;
2024
0
    char *p = NULL;
2025
0
    result = setstropt_userpwd(ptr, &u, &p);
2026
2027
    /* URL decode the components */
2028
0
    if(!result && u) {
2029
0
      Curl_safefree(s->str[STRING_PROXYUSERNAME]);
2030
0
      result = Curl_urldecode(u, 0, &s->str[STRING_PROXYUSERNAME], NULL,
2031
0
                              REJECT_ZERO);
2032
0
    }
2033
0
    if(!result && p) {
2034
0
      Curl_safefree(s->str[STRING_PROXYPASSWORD]);
2035
0
      result = Curl_urldecode(p, 0, &s->str[STRING_PROXYPASSWORD], NULL,
2036
0
                              REJECT_ZERO);
2037
0
    }
2038
0
    free(u);
2039
0
    free(p);
2040
0
  }
2041
0
    break;
2042
0
  case CURLOPT_PROXYUSERNAME:
2043
    /*
2044
     * authentication username to use in the operation
2045
     */
2046
0
    return Curl_setstropt(&s->str[STRING_PROXYUSERNAME], ptr);
2047
2048
0
  case CURLOPT_PROXYPASSWORD:
2049
    /*
2050
     * authentication password to use in the operation
2051
     */
2052
0
    return Curl_setstropt(&s->str[STRING_PROXYPASSWORD], ptr);
2053
2054
0
  case CURLOPT_NOPROXY:
2055
    /*
2056
     * proxy exception list
2057
     */
2058
0
    return Curl_setstropt(&s->str[STRING_NOPROXY], ptr);
2059
0
#endif /* ! CURL_DISABLE_PROXY */
2060
2061
0
  case CURLOPT_RANGE:
2062
    /*
2063
     * What range of the file you want to transfer
2064
     */
2065
0
    return Curl_setstropt(&s->str[STRING_SET_RANGE], ptr);
2066
2067
0
  case CURLOPT_CURLU:
2068
    /*
2069
     * pass CURLU to set URL
2070
     */
2071
0
    if(data->state.url_alloc) {
2072
0
      Curl_safefree(data->state.url);
2073
0
      data->state.url_alloc = FALSE;
2074
0
    }
2075
0
    else
2076
0
      data->state.url = NULL;
2077
0
    Curl_safefree(s->str[STRING_SET_URL]);
2078
0
    s->uh = (CURLU *)ptr;
2079
0
    break;
2080
0
  case CURLOPT_SSLCERT:
2081
    /*
2082
     * String that holds filename of the SSL certificate to use
2083
     */
2084
0
    return Curl_setstropt(&s->str[STRING_CERT], ptr);
2085
2086
0
#ifndef CURL_DISABLE_PROXY
2087
0
  case CURLOPT_PROXY_SSLCERT:
2088
    /*
2089
     * String that holds filename of the SSL certificate to use for proxy
2090
     */
2091
0
    return Curl_setstropt(&s->str[STRING_CERT_PROXY], ptr);
2092
2093
0
#endif
2094
0
  case CURLOPT_SSLCERTTYPE:
2095
    /*
2096
     * String that holds file type of the SSL certificate to use
2097
     */
2098
0
    return Curl_setstropt(&s->str[STRING_CERT_TYPE], ptr);
2099
2100
0
#ifndef CURL_DISABLE_PROXY
2101
0
  case CURLOPT_PROXY_SSLCERTTYPE:
2102
    /*
2103
     * String that holds file type of the SSL certificate to use for proxy
2104
     */
2105
0
    return Curl_setstropt(&s->str[STRING_CERT_TYPE_PROXY], ptr);
2106
2107
0
#endif
2108
0
  case CURLOPT_SSLKEY:
2109
    /*
2110
     * String that holds filename of the SSL key to use
2111
     */
2112
0
    return Curl_setstropt(&s->str[STRING_KEY], ptr);
2113
2114
0
#ifndef CURL_DISABLE_PROXY
2115
0
  case CURLOPT_PROXY_SSLKEY:
2116
    /*
2117
     * String that holds filename of the SSL key to use for proxy
2118
     */
2119
0
    return Curl_setstropt(&s->str[STRING_KEY_PROXY], ptr);
2120
2121
0
#endif
2122
0
  case CURLOPT_SSLKEYTYPE:
2123
    /*
2124
     * String that holds file type of the SSL key to use
2125
     */
2126
0
    return Curl_setstropt(&s->str[STRING_KEY_TYPE], ptr);
2127
2128
0
#ifndef CURL_DISABLE_PROXY
2129
0
  case CURLOPT_PROXY_SSLKEYTYPE:
2130
    /*
2131
     * String that holds file type of the SSL key to use for proxy
2132
     */
2133
0
    return Curl_setstropt(&s->str[STRING_KEY_TYPE_PROXY], ptr);
2134
2135
0
#endif
2136
0
  case CURLOPT_KEYPASSWD:
2137
    /*
2138
     * String that holds the SSL or SSH private key password.
2139
     */
2140
0
    return Curl_setstropt(&s->str[STRING_KEY_PASSWD], ptr);
2141
2142
0
#ifndef CURL_DISABLE_PROXY
2143
0
  case CURLOPT_PROXY_KEYPASSWD:
2144
    /*
2145
     * String that holds the SSL private key password for proxy.
2146
     */
2147
0
    return Curl_setstropt(&s->str[STRING_KEY_PASSWD_PROXY], ptr);
2148
2149
0
#endif
2150
0
  case CURLOPT_SSLENGINE:
2151
    /*
2152
     * String that holds the SSL crypto engine.
2153
     */
2154
0
    if(ptr && ptr[0]) {
2155
0
      result = Curl_setstropt(&s->str[STRING_SSL_ENGINE], ptr);
2156
0
      if(!result) {
2157
0
        result = Curl_ssl_set_engine(data, ptr);
2158
0
      }
2159
0
    }
2160
0
    break;
2161
2162
0
#ifndef CURL_DISABLE_PROXY
2163
0
  case CURLOPT_HAPROXY_CLIENT_IP:
2164
    /*
2165
     * Set the client IP to send through HAProxy PROXY protocol
2166
     */
2167
0
    result = Curl_setstropt(&s->str[STRING_HAPROXY_CLIENT_IP], ptr);
2168
    /* enable the HAProxy protocol */
2169
0
    s->haproxyprotocol = TRUE;
2170
0
    break;
2171
2172
0
#endif
2173
0
  case CURLOPT_INTERFACE:
2174
    /*
2175
     * Set what interface or address/hostname to bind the socket to when
2176
     * performing an operation and thus what from-IP your connection will use.
2177
     */
2178
0
    return setstropt_interface(ptr,
2179
0
                               &s->str[STRING_DEVICE],
2180
0
                               &s->str[STRING_INTERFACE],
2181
0
                               &s->str[STRING_BINDHOST]);
2182
2183
0
  case CURLOPT_PINNEDPUBLICKEY:
2184
    /*
2185
     * Set pinned public key for SSL connection.
2186
     * Specify filename of the public key in DER format.
2187
     */
2188
0
#ifdef USE_SSL
2189
0
    if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY))
2190
0
      return Curl_setstropt(&s->str[STRING_SSL_PINNEDPUBLICKEY], ptr);
2191
0
#endif
2192
0
    return CURLE_NOT_BUILT_IN;
2193
2194
0
#ifndef CURL_DISABLE_PROXY
2195
0
  case CURLOPT_PROXY_PINNEDPUBLICKEY:
2196
    /*
2197
     * Set pinned public key for SSL connection.
2198
     * Specify filename of the public key in DER format.
2199
     */
2200
0
#ifdef USE_SSL
2201
0
    if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY))
2202
0
      return Curl_setstropt(&s->str[STRING_SSL_PINNEDPUBLICKEY_PROXY],
2203
0
                            ptr);
2204
0
#endif
2205
0
    return CURLE_NOT_BUILT_IN;
2206
0
#endif
2207
0
  case CURLOPT_CAINFO:
2208
    /*
2209
     * Set CA info for SSL connection. Specify filename of the CA certificate
2210
     */
2211
0
    s->ssl.custom_cafile = TRUE;
2212
0
    return Curl_setstropt(&s->str[STRING_SSL_CAFILE], ptr);
2213
2214
0
#ifndef CURL_DISABLE_PROXY
2215
0
  case CURLOPT_PROXY_CAINFO:
2216
    /*
2217
     * Set CA info SSL connection for proxy. Specify filename of the
2218
     * CA certificate
2219
     */
2220
0
    s->proxy_ssl.custom_cafile = TRUE;
2221
0
    return Curl_setstropt(&s->str[STRING_SSL_CAFILE_PROXY], ptr);
2222
2223
0
#endif
2224
0
  case CURLOPT_CAPATH:
2225
    /*
2226
     * Set CA path info for SSL connection. Specify directory name of the CA
2227
     * certificates which have been prepared using openssl c_rehash utility.
2228
     */
2229
0
#ifdef USE_SSL
2230
0
    if(Curl_ssl_supports(data, SSLSUPP_CA_PATH)) {
2231
      /* This does not work on Windows. */
2232
0
      s->ssl.custom_capath = TRUE;
2233
0
      return Curl_setstropt(&s->str[STRING_SSL_CAPATH], ptr);
2234
0
    }
2235
0
#endif
2236
0
    return CURLE_NOT_BUILT_IN;
2237
0
#ifndef CURL_DISABLE_PROXY
2238
0
  case CURLOPT_PROXY_CAPATH:
2239
    /*
2240
     * Set CA path info for SSL connection proxy. Specify directory name of the
2241
     * CA certificates which have been prepared using openssl c_rehash utility.
2242
     */
2243
0
#ifdef USE_SSL
2244
0
    if(Curl_ssl_supports(data, SSLSUPP_CA_PATH)) {
2245
      /* This does not work on Windows. */
2246
0
      s->proxy_ssl.custom_capath = TRUE;
2247
0
      return Curl_setstropt(&s->str[STRING_SSL_CAPATH_PROXY], ptr);
2248
0
    }
2249
0
#endif
2250
0
    return CURLE_NOT_BUILT_IN;
2251
0
#endif
2252
0
  case CURLOPT_CRLFILE:
2253
    /*
2254
     * Set CRL file info for SSL connection. Specify filename of the CRL
2255
     * to check certificates revocation
2256
     */
2257
0
    return Curl_setstropt(&s->str[STRING_SSL_CRLFILE], ptr);
2258
2259
0
#ifndef CURL_DISABLE_PROXY
2260
0
  case CURLOPT_PROXY_CRLFILE:
2261
    /*
2262
     * Set CRL file info for SSL connection for proxy. Specify filename of the
2263
     * CRL to check certificates revocation
2264
     */
2265
0
    return Curl_setstropt(&s->str[STRING_SSL_CRLFILE_PROXY], ptr);
2266
2267
0
#endif
2268
0
  case CURLOPT_ISSUERCERT:
2269
    /*
2270
     * Set Issuer certificate file
2271
     * to check certificates issuer
2272
     */
2273
0
    return Curl_setstropt(&s->str[STRING_SSL_ISSUERCERT], ptr);
2274
2275
0
#ifndef CURL_DISABLE_PROXY
2276
0
  case CURLOPT_PROXY_ISSUERCERT:
2277
    /*
2278
     * Set Issuer certificate file
2279
     * to check certificates issuer
2280
     */
2281
0
    return Curl_setstropt(&s->str[STRING_SSL_ISSUERCERT_PROXY], ptr);
2282
2283
0
#endif
2284
0
  case CURLOPT_PRIVATE:
2285
    /*
2286
     * Set private data pointer.
2287
     */
2288
0
    s->private_data = ptr;
2289
0
    break;
2290
2291
0
#ifdef USE_SSL
2292
0
  case CURLOPT_SSL_EC_CURVES:
2293
    /*
2294
     * Set accepted curves in SSL connection setup.
2295
     * Specify colon-delimited list of curve algorithm names.
2296
     */
2297
0
    return Curl_setstropt(&s->str[STRING_SSL_EC_CURVES], ptr);
2298
2299
0
  case CURLOPT_SSL_SIGNATURE_ALGORITHMS:
2300
    /*
2301
     * Set accepted signature algorithms.
2302
     * Specify colon-delimited list of signature scheme names.
2303
     */
2304
0
    if(Curl_ssl_supports(data, SSLSUPP_SIGNATURE_ALGORITHMS))
2305
0
      return Curl_setstropt(&s->str[STRING_SSL_SIGNATURE_ALGORITHMS],
2306
0
                            ptr);
2307
0
    return CURLE_NOT_BUILT_IN;
2308
0
#endif
2309
#ifdef USE_SSH
2310
  case CURLOPT_SSH_PUBLIC_KEYFILE:
2311
    /*
2312
     * Use this file instead of the $HOME/.ssh/id_dsa.pub file
2313
     */
2314
    return Curl_setstropt(&s->str[STRING_SSH_PUBLIC_KEY], ptr);
2315
2316
  case CURLOPT_SSH_PRIVATE_KEYFILE:
2317
    /*
2318
     * Use this file instead of the $HOME/.ssh/id_dsa file
2319
     */
2320
    return Curl_setstropt(&s->str[STRING_SSH_PRIVATE_KEY], ptr);
2321
2322
#if defined(USE_LIBSSH2) || defined(USE_LIBSSH)
2323
  case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5:
2324
    /*
2325
     * Option to allow for the MD5 of the host public key to be checked
2326
     * for validation purposes.
2327
     */
2328
    return Curl_setstropt(&s->str[STRING_SSH_HOST_PUBLIC_KEY_MD5], ptr);
2329
2330
  case CURLOPT_SSH_KNOWNHOSTS:
2331
    /*
2332
     * Store the filename to read known hosts from.
2333
     */
2334
    return Curl_setstropt(&s->str[STRING_SSH_KNOWNHOSTS], ptr);
2335
#endif
2336
  case CURLOPT_SSH_KEYDATA:
2337
    /*
2338
     * Custom client data to pass to the SSH keyfunc callback
2339
     */
2340
    s->ssh_keyfunc_userp = ptr;
2341
    break;
2342
#ifdef USE_LIBSSH2
2343
  case CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256:
2344
    /*
2345
     * Option to allow for the SHA256 of the host public key to be checked
2346
     * for validation purposes.
2347
     */
2348
    return Curl_setstropt(&s->str[STRING_SSH_HOST_PUBLIC_KEY_SHA256],
2349
                          ptr);
2350
2351
  case CURLOPT_SSH_HOSTKEYDATA:
2352
    /*
2353
     * Custom client data to pass to the SSH keyfunc callback
2354
     */
2355
    s->ssh_hostkeyfunc_userp = ptr;
2356
    break;
2357
#endif /* USE_LIBSSH2 */
2358
#endif /* USE_SSH */
2359
0
  case CURLOPT_PROTOCOLS_STR:
2360
0
    if(ptr)
2361
0
      return protocol2num(ptr, &s->allowed_protocols);
2362
    /* make a NULL argument reset to default */
2363
0
    s->allowed_protocols = (curl_prot_t) CURLPROTO_ALL;
2364
0
    break;
2365
2366
0
  case CURLOPT_REDIR_PROTOCOLS_STR:
2367
0
    if(ptr)
2368
0
      return protocol2num(ptr, &s->redir_protocols);
2369
    /* make a NULL argument reset to default */
2370
0
    s->redir_protocols = (curl_prot_t) CURLPROTO_REDIR;
2371
0
    break;
2372
2373
0
  case CURLOPT_DEFAULT_PROTOCOL:
2374
    /* Set the protocol to use when the URL does not include any protocol */
2375
0
    return Curl_setstropt(&s->str[STRING_DEFAULT_PROTOCOL], ptr);
2376
2377
0
#ifndef CURL_DISABLE_SMTP
2378
0
  case CURLOPT_MAIL_FROM:
2379
    /* Set the SMTP mail originator */
2380
0
    return Curl_setstropt(&s->str[STRING_MAIL_FROM], ptr);
2381
2382
0
  case CURLOPT_MAIL_AUTH:
2383
    /* Set the SMTP auth originator */
2384
0
    return Curl_setstropt(&s->str[STRING_MAIL_AUTH], ptr);
2385
0
#endif
2386
0
  case CURLOPT_SASL_AUTHZID:
2387
    /* Authorization identity (identity to act as) */
2388
0
    return Curl_setstropt(&s->str[STRING_SASL_AUTHZID], ptr);
2389
2390
0
#ifndef CURL_DISABLE_RTSP
2391
0
  case CURLOPT_RTSP_SESSION_ID:
2392
    /*
2393
     * Set the RTSP Session ID manually. Useful if the application is
2394
     * resuming a previously established RTSP session
2395
     */
2396
0
    return Curl_setstropt(&s->str[STRING_RTSP_SESSION_ID], ptr);
2397
2398
0
  case CURLOPT_RTSP_STREAM_URI:
2399
    /*
2400
     * Set the Stream URI for the RTSP request. Unless the request is
2401
     * for generic server options, the application will need to set this.
2402
     */
2403
0
    return Curl_setstropt(&s->str[STRING_RTSP_STREAM_URI], ptr);
2404
2405
0
  case CURLOPT_RTSP_TRANSPORT:
2406
    /*
2407
     * The content of the Transport: header for the RTSP request
2408
     */
2409
0
    return Curl_setstropt(&s->str[STRING_RTSP_TRANSPORT], ptr);
2410
2411
0
  case CURLOPT_INTERLEAVEDATA:
2412
0
    s->rtp_out = ptr;
2413
0
    break;
2414
0
#endif /* ! CURL_DISABLE_RTSP */
2415
0
#ifndef CURL_DISABLE_FTP
2416
0
  case CURLOPT_CHUNK_DATA:
2417
0
    s->wildcardptr = ptr;
2418
0
    break;
2419
0
  case CURLOPT_FNMATCH_DATA:
2420
0
    s->fnmatch_data = ptr;
2421
0
    break;
2422
0
#endif
2423
0
#ifdef USE_TLS_SRP
2424
0
  case CURLOPT_TLSAUTH_USERNAME:
2425
0
    return Curl_setstropt(&s->str[STRING_TLSAUTH_USERNAME], ptr);
2426
2427
0
#ifndef CURL_DISABLE_PROXY
2428
0
  case CURLOPT_PROXY_TLSAUTH_USERNAME:
2429
0
    return Curl_setstropt(&s->str[STRING_TLSAUTH_USERNAME_PROXY], ptr);
2430
2431
0
#endif
2432
0
  case CURLOPT_TLSAUTH_PASSWORD:
2433
0
    return Curl_setstropt(&s->str[STRING_TLSAUTH_PASSWORD], ptr);
2434
2435
0
#ifndef CURL_DISABLE_PROXY
2436
0
  case CURLOPT_PROXY_TLSAUTH_PASSWORD:
2437
0
    return Curl_setstropt(&s->str[STRING_TLSAUTH_PASSWORD_PROXY], ptr);
2438
0
#endif
2439
0
  case CURLOPT_TLSAUTH_TYPE:
2440
0
    if(ptr && !curl_strequal(ptr, "SRP"))
2441
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2442
0
    break;
2443
0
#ifndef CURL_DISABLE_PROXY
2444
0
  case CURLOPT_PROXY_TLSAUTH_TYPE:
2445
0
    if(ptr && !curl_strequal(ptr, "SRP"))
2446
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2447
0
    break;
2448
0
#endif
2449
0
#endif
2450
#ifdef CURLRES_ARES
2451
  case CURLOPT_DNS_SERVERS:
2452
    result = Curl_setstropt(&s->str[STRING_DNS_SERVERS], ptr);
2453
    if(result)
2454
      return result;
2455
    return Curl_async_ares_set_dns_servers(data);
2456
2457
  case CURLOPT_DNS_INTERFACE:
2458
    result = Curl_setstropt(&s->str[STRING_DNS_INTERFACE], ptr);
2459
    if(result)
2460
      return result;
2461
    return Curl_async_ares_set_dns_interface(data);
2462
2463
  case CURLOPT_DNS_LOCAL_IP4:
2464
    result = Curl_setstropt(&s->str[STRING_DNS_LOCAL_IP4], ptr);
2465
    if(result)
2466
      return result;
2467
    return Curl_async_ares_set_dns_local_ip4(data);
2468
2469
  case CURLOPT_DNS_LOCAL_IP6:
2470
    result = Curl_setstropt(&s->str[STRING_DNS_LOCAL_IP6], ptr);
2471
    if(result)
2472
      return result;
2473
    return Curl_async_ares_set_dns_local_ip6(data);
2474
2475
#endif
2476
0
#ifdef USE_UNIX_SOCKETS
2477
0
  case CURLOPT_UNIX_SOCKET_PATH:
2478
0
    s->abstract_unix_socket = FALSE;
2479
0
    return Curl_setstropt(&s->str[STRING_UNIX_SOCKET_PATH], ptr);
2480
2481
0
  case CURLOPT_ABSTRACT_UNIX_SOCKET:
2482
0
    s->abstract_unix_socket = TRUE;
2483
0
    return Curl_setstropt(&s->str[STRING_UNIX_SOCKET_PATH], ptr);
2484
2485
0
#endif
2486
2487
0
#ifndef CURL_DISABLE_DOH
2488
0
  case CURLOPT_DOH_URL:
2489
0
    result = Curl_setstropt(&s->str[STRING_DOH], ptr);
2490
0
    s->doh = !!(s->str[STRING_DOH]);
2491
0
    break;
2492
0
#endif
2493
0
#ifndef CURL_DISABLE_HSTS
2494
0
  case CURLOPT_HSTSREADDATA:
2495
0
    s->hsts_read_userp = ptr;
2496
0
    break;
2497
0
  case CURLOPT_HSTSWRITEDATA:
2498
0
    s->hsts_write_userp = ptr;
2499
0
    break;
2500
0
  case CURLOPT_HSTS: {
2501
0
    struct curl_slist *h;
2502
0
    if(!data->hsts) {
2503
0
      data->hsts = Curl_hsts_init();
2504
0
      if(!data->hsts)
2505
0
        return CURLE_OUT_OF_MEMORY;
2506
0
    }
2507
0
    if(ptr) {
2508
0
      result = Curl_setstropt(&s->str[STRING_HSTS], ptr);
2509
0
      if(result)
2510
0
        return result;
2511
      /* this needs to build a list of filenames to read from, so that it can
2512
         read them later, as we might get a shared HSTS handle to load them
2513
         into */
2514
0
      h = curl_slist_append(data->state.hstslist, ptr);
2515
0
      if(!h) {
2516
0
        curl_slist_free_all(data->state.hstslist);
2517
0
        data->state.hstslist = NULL;
2518
0
        return CURLE_OUT_OF_MEMORY;
2519
0
      }
2520
0
      data->state.hstslist = h; /* store the list for later use */
2521
0
    }
2522
0
    else {
2523
      /* clear the list of HSTS files */
2524
0
      curl_slist_free_all(data->state.hstslist);
2525
0
      data->state.hstslist = NULL;
2526
0
      if(!data->share || !data->share->hsts)
2527
        /* throw away the HSTS cache unless shared */
2528
0
        Curl_hsts_cleanup(&data->hsts);
2529
0
    }
2530
0
    break;
2531
0
  }
2532
0
#endif /* ! CURL_DISABLE_HSTS */
2533
0
#ifndef CURL_DISABLE_ALTSVC
2534
0
  case CURLOPT_ALTSVC:
2535
0
    if(!data->asi) {
2536
0
      data->asi = Curl_altsvc_init();
2537
0
      if(!data->asi)
2538
0
        return CURLE_OUT_OF_MEMORY;
2539
0
    }
2540
0
    result = Curl_setstropt(&s->str[STRING_ALTSVC], ptr);
2541
0
    if(result)
2542
0
      return result;
2543
0
    if(ptr)
2544
0
      (void)Curl_altsvc_load(data->asi, ptr);
2545
0
    break;
2546
0
#endif /* ! CURL_DISABLE_ALTSVC */
2547
#ifdef USE_ECH
2548
  case CURLOPT_ECH: {
2549
    size_t plen = 0;
2550
2551
    if(!ptr) {
2552
      s->tls_ech = CURLECH_DISABLE;
2553
      return CURLE_OK;
2554
    }
2555
    plen = strlen(ptr);
2556
    if(plen > CURL_MAX_INPUT_LENGTH) {
2557
      s->tls_ech = CURLECH_DISABLE;
2558
      return CURLE_BAD_FUNCTION_ARGUMENT;
2559
    }
2560
    /* set tls_ech flag value, preserving CLA_CFG bit */
2561
    if(!strcmp(ptr, "false"))
2562
      s->tls_ech = CURLECH_DISABLE |
2563
        (s->tls_ech & CURLECH_CLA_CFG);
2564
    else if(!strcmp(ptr, "grease"))
2565
      s->tls_ech = CURLECH_GREASE |
2566
        (s->tls_ech & CURLECH_CLA_CFG);
2567
    else if(!strcmp(ptr, "true"))
2568
      s->tls_ech = CURLECH_ENABLE |
2569
        (s->tls_ech & CURLECH_CLA_CFG);
2570
    else if(!strcmp(ptr, "hard"))
2571
      s->tls_ech = CURLECH_HARD |
2572
        (s->tls_ech & CURLECH_CLA_CFG);
2573
    else if(plen > 5 && !strncmp(ptr, "ecl:", 4)) {
2574
      result = Curl_setstropt(&s->str[STRING_ECH_CONFIG], ptr + 4);
2575
      if(result)
2576
        return result;
2577
      s->tls_ech |= CURLECH_CLA_CFG;
2578
    }
2579
    else if(plen > 4 && !strncmp(ptr, "pn:", 3)) {
2580
      result = Curl_setstropt(&s->str[STRING_ECH_PUBLIC], ptr + 3);
2581
      if(result)
2582
        return result;
2583
    }
2584
    break;
2585
  }
2586
#endif
2587
0
  default:
2588
0
    return CURLE_UNKNOWN_OPTION;
2589
0
  }
2590
0
  return result;
2591
0
}
2592
2593
static CURLcode setopt_func(struct Curl_easy *data, CURLoption option,
2594
                            va_list param)
2595
0
{
2596
0
  struct UserDefined *s = &data->set;
2597
0
  switch(option) {
2598
0
  case CURLOPT_PROGRESSFUNCTION:
2599
    /*
2600
     * Progress callback function
2601
     */
2602
0
    s->fprogress = va_arg(param, curl_progress_callback);
2603
0
    if(s->fprogress)
2604
0
      data->progress.callback = TRUE; /* no longer internal */
2605
0
    else
2606
0
      data->progress.callback = FALSE; /* NULL enforces internal */
2607
0
    break;
2608
2609
0
  case CURLOPT_XFERINFOFUNCTION:
2610
    /*
2611
     * Transfer info callback function
2612
     */
2613
0
    s->fxferinfo = va_arg(param, curl_xferinfo_callback);
2614
0
    if(s->fxferinfo)
2615
0
      data->progress.callback = TRUE; /* no longer internal */
2616
0
    else
2617
0
      data->progress.callback = FALSE; /* NULL enforces internal */
2618
2619
0
    break;
2620
0
  case CURLOPT_DEBUGFUNCTION:
2621
    /*
2622
     * stderr write callback.
2623
     */
2624
0
    s->fdebug = va_arg(param, curl_debug_callback);
2625
    /*
2626
     * if the callback provided is NULL, it will use the default callback
2627
     */
2628
0
    break;
2629
0
  case CURLOPT_HEADERFUNCTION:
2630
    /*
2631
     * Set header write callback
2632
     */
2633
0
    s->fwrite_header = va_arg(param, curl_write_callback);
2634
0
    break;
2635
0
  case CURLOPT_WRITEFUNCTION:
2636
    /*
2637
     * Set data write callback
2638
     */
2639
0
    s->fwrite_func = va_arg(param, curl_write_callback);
2640
0
    if(!s->fwrite_func)
2641
0
#if defined(__clang__) && __clang_major__ >= 16
2642
0
#pragma clang diagnostic push
2643
0
#pragma clang diagnostic ignored "-Wcast-function-type-strict"
2644
0
#endif
2645
      /* When set to NULL, reset to our internal default function */
2646
0
      s->fwrite_func = (curl_write_callback)fwrite;
2647
0
#if defined(__clang__) && __clang_major__ >= 16
2648
0
#pragma clang diagnostic pop
2649
0
#endif
2650
0
    break;
2651
0
  case CURLOPT_READFUNCTION:
2652
    /*
2653
     * Read data callback
2654
     */
2655
0
    s->fread_func_set = va_arg(param, curl_read_callback);
2656
0
    if(!s->fread_func_set) {
2657
0
      s->is_fread_set = 0;
2658
0
#if defined(__clang__) && __clang_major__ >= 16
2659
0
#pragma clang diagnostic push
2660
0
#pragma clang diagnostic ignored "-Wcast-function-type-strict"
2661
0
#endif
2662
      /* When set to NULL, reset to our internal default function */
2663
0
      s->fread_func_set = (curl_read_callback)fread;
2664
0
#if defined(__clang__) && __clang_major__ >= 16
2665
0
#pragma clang diagnostic pop
2666
0
#endif
2667
0
    }
2668
0
    else
2669
0
      s->is_fread_set = 1;
2670
0
    break;
2671
0
  case CURLOPT_SEEKFUNCTION:
2672
    /*
2673
     * Seek callback. Might be NULL.
2674
     */
2675
0
    s->seek_func = va_arg(param, curl_seek_callback);
2676
0
    break;
2677
0
  case CURLOPT_IOCTLFUNCTION:
2678
    /*
2679
     * I/O control callback. Might be NULL.
2680
     */
2681
0
    s->ioctl_func = va_arg(param, curl_ioctl_callback);
2682
0
    break;
2683
0
  case CURLOPT_SSL_CTX_FUNCTION:
2684
    /*
2685
     * Set an SSL_CTX callback
2686
     */
2687
0
#ifdef USE_SSL
2688
0
    if(Curl_ssl_supports(data, SSLSUPP_SSL_CTX)) {
2689
0
      s->ssl.fsslctx = va_arg(param, curl_ssl_ctx_callback);
2690
0
      break;
2691
0
    }
2692
0
    else
2693
0
#endif
2694
0
      return CURLE_NOT_BUILT_IN;
2695
2696
0
  case CURLOPT_SOCKOPTFUNCTION:
2697
    /*
2698
     * socket callback function: called after socket() but before connect()
2699
     */
2700
0
    s->fsockopt = va_arg(param, curl_sockopt_callback);
2701
0
    break;
2702
2703
0
  case CURLOPT_OPENSOCKETFUNCTION:
2704
    /*
2705
     * open/create socket callback function: called instead of socket(),
2706
     * before connect()
2707
     */
2708
0
    s->fopensocket = va_arg(param, curl_opensocket_callback);
2709
0
    break;
2710
2711
0
  case CURLOPT_CLOSESOCKETFUNCTION:
2712
    /*
2713
     * close socket callback function: called instead of close()
2714
     * when shutting down a connection
2715
     */
2716
0
    s->fclosesocket = va_arg(param, curl_closesocket_callback);
2717
0
    break;
2718
2719
0
  case CURLOPT_RESOLVER_START_FUNCTION:
2720
    /*
2721
     * resolver start callback function: called before a new resolver request
2722
     * is started
2723
     */
2724
0
    s->resolver_start = va_arg(param, curl_resolver_start_callback);
2725
0
    break;
2726
2727
#ifdef USE_SSH
2728
#ifdef USE_LIBSSH2
2729
  case CURLOPT_SSH_HOSTKEYFUNCTION:
2730
    /* the callback to check the hostkey without the knownhost file */
2731
    s->ssh_hostkeyfunc = va_arg(param, curl_sshhostkeycallback);
2732
    break;
2733
#endif
2734
2735
  case CURLOPT_SSH_KEYFUNCTION:
2736
    /* setting to NULL is fine since the ssh.c functions themselves will
2737
       then revert to use the internal default */
2738
    s->ssh_keyfunc = va_arg(param, curl_sshkeycallback);
2739
    break;
2740
2741
#endif /* USE_SSH */
2742
2743
0
#ifndef CURL_DISABLE_RTSP
2744
0
  case CURLOPT_INTERLEAVEFUNCTION:
2745
    /* Set the user defined RTP write function */
2746
0
    s->fwrite_rtp = va_arg(param, curl_write_callback);
2747
0
    break;
2748
0
#endif
2749
0
#ifndef CURL_DISABLE_FTP
2750
0
  case CURLOPT_CHUNK_BGN_FUNCTION:
2751
0
    s->chunk_bgn = va_arg(param, curl_chunk_bgn_callback);
2752
0
    break;
2753
0
  case CURLOPT_CHUNK_END_FUNCTION:
2754
0
    s->chunk_end = va_arg(param, curl_chunk_end_callback);
2755
0
    break;
2756
0
  case CURLOPT_FNMATCH_FUNCTION:
2757
0
    s->fnmatch = va_arg(param, curl_fnmatch_callback);
2758
0
    break;
2759
0
#endif
2760
0
#ifndef CURL_DISABLE_HTTP
2761
0
  case CURLOPT_TRAILERFUNCTION:
2762
0
    s->trailer_callback = va_arg(param, curl_trailer_callback);
2763
0
    break;
2764
0
#endif
2765
0
#ifndef CURL_DISABLE_HSTS
2766
0
  case CURLOPT_HSTSREADFUNCTION:
2767
0
    s->hsts_read = va_arg(param, curl_hstsread_callback);
2768
0
    break;
2769
0
  case CURLOPT_HSTSWRITEFUNCTION:
2770
0
    s->hsts_write = va_arg(param, curl_hstswrite_callback);
2771
0
    break;
2772
0
#endif
2773
0
  case CURLOPT_PREREQFUNCTION:
2774
0
    s->fprereq = va_arg(param, curl_prereq_callback);
2775
0
    break;
2776
0
  default:
2777
0
    return CURLE_UNKNOWN_OPTION;
2778
0
  }
2779
0
  return CURLE_OK;
2780
0
}
2781
2782
static CURLcode setopt_offt(struct Curl_easy *data, CURLoption option,
2783
                            curl_off_t offt)
2784
0
{
2785
0
  struct UserDefined *s = &data->set;
2786
0
  switch(option) {
2787
0
  case CURLOPT_TIMEVALUE_LARGE:
2788
    /*
2789
     * This is the value to compare with the remote document with the
2790
     * method set with CURLOPT_TIMECONDITION
2791
     */
2792
0
    s->timevalue = (time_t)offt;
2793
0
    break;
2794
2795
    /* MQTT "borrows" some of the HTTP options */
2796
0
  case CURLOPT_POSTFIELDSIZE_LARGE:
2797
    /*
2798
     * The size of the POSTFIELD data to prevent libcurl to do strlen() to
2799
     * figure it out. Enables binary posts.
2800
     */
2801
0
    if(offt < -1)
2802
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2803
2804
0
    if(s->postfieldsize < offt &&
2805
0
       s->postfields == s->str[STRING_COPYPOSTFIELDS]) {
2806
      /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
2807
0
      Curl_safefree(s->str[STRING_COPYPOSTFIELDS]);
2808
0
      s->postfields = NULL;
2809
0
    }
2810
0
    s->postfieldsize = offt;
2811
0
    break;
2812
0
  case CURLOPT_INFILESIZE_LARGE:
2813
    /*
2814
     * If known, this should inform curl about the file size of the
2815
     * to-be-uploaded file.
2816
     */
2817
0
    if(offt < -1)
2818
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2819
0
    s->filesize = offt;
2820
0
    break;
2821
0
  case CURLOPT_MAX_SEND_SPEED_LARGE:
2822
    /*
2823
     * When transfer uploads are faster then CURLOPT_MAX_SEND_SPEED_LARGE
2824
     * bytes per second the transfer is throttled..
2825
     */
2826
0
    if(offt < 0)
2827
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2828
0
    s->max_send_speed = offt;
2829
0
    break;
2830
0
  case CURLOPT_MAX_RECV_SPEED_LARGE:
2831
    /*
2832
     * When receiving data faster than CURLOPT_MAX_RECV_SPEED_LARGE bytes per
2833
     * second the transfer is throttled..
2834
     */
2835
0
    if(offt < 0)
2836
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2837
0
    s->max_recv_speed = offt;
2838
0
    break;
2839
0
  case CURLOPT_RESUME_FROM_LARGE:
2840
    /*
2841
     * Resume transfer at the given file position
2842
     */
2843
0
    if(offt < -1)
2844
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2845
0
    s->set_resume_from = offt;
2846
0
    break;
2847
0
  case CURLOPT_MAXFILESIZE_LARGE:
2848
    /*
2849
     * Set the maximum size of a file to download.
2850
     */
2851
0
    if(offt < 0)
2852
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2853
0
    s->max_filesize = offt;
2854
0
    break;
2855
2856
0
  default:
2857
0
    return CURLE_UNKNOWN_OPTION;
2858
0
  }
2859
0
  return CURLE_OK;
2860
0
}
2861
2862
static CURLcode setopt_blob(struct Curl_easy *data, CURLoption option,
2863
                            struct curl_blob *blob)
2864
0
{
2865
0
  struct UserDefined *s = &data->set;
2866
0
  switch(option) {
2867
0
  case CURLOPT_SSLCERT_BLOB:
2868
    /*
2869
     * Blob that holds file content of the SSL certificate to use
2870
     */
2871
0
    return Curl_setblobopt(&s->blobs[BLOB_CERT], blob);
2872
0
#ifndef CURL_DISABLE_PROXY
2873
0
  case CURLOPT_PROXY_SSLCERT_BLOB:
2874
    /*
2875
     * Blob that holds file content of the SSL certificate to use for proxy
2876
     */
2877
0
    return Curl_setblobopt(&s->blobs[BLOB_CERT_PROXY], blob);
2878
0
  case CURLOPT_PROXY_SSLKEY_BLOB:
2879
    /*
2880
     * Blob that holds file content of the SSL key to use for proxy
2881
     */
2882
0
    return Curl_setblobopt(&s->blobs[BLOB_KEY_PROXY], blob);
2883
0
  case CURLOPT_PROXY_CAINFO_BLOB:
2884
    /*
2885
     * Blob that holds CA info for SSL connection proxy.
2886
     * Specify entire PEM of the CA certificate
2887
     */
2888
0
#ifdef USE_SSL
2889
0
    if(Curl_ssl_supports(data, SSLSUPP_CAINFO_BLOB))
2890
0
      return Curl_setblobopt(&s->blobs[BLOB_CAINFO_PROXY], blob);
2891
0
#endif
2892
0
    return CURLE_NOT_BUILT_IN;
2893
0
  case CURLOPT_PROXY_ISSUERCERT_BLOB:
2894
    /*
2895
     * Blob that holds Issuer certificate to check certificates issuer
2896
     */
2897
0
    return Curl_setblobopt(&s->blobs[BLOB_SSL_ISSUERCERT_PROXY],
2898
0
                           blob);
2899
0
#endif
2900
0
  case CURLOPT_SSLKEY_BLOB:
2901
    /*
2902
     * Blob that holds file content of the SSL key to use
2903
     */
2904
0
    return Curl_setblobopt(&s->blobs[BLOB_KEY], blob);
2905
0
  case CURLOPT_CAINFO_BLOB:
2906
    /*
2907
     * Blob that holds CA info for SSL connection.
2908
     * Specify entire PEM of the CA certificate
2909
     */
2910
0
#ifdef USE_SSL
2911
0
    if(Curl_ssl_supports(data, SSLSUPP_CAINFO_BLOB)) {
2912
0
      s->ssl.custom_cablob = TRUE;
2913
0
      return Curl_setblobopt(&s->blobs[BLOB_CAINFO], blob);
2914
0
    }
2915
0
#endif
2916
0
    return CURLE_NOT_BUILT_IN;
2917
0
  case CURLOPT_ISSUERCERT_BLOB:
2918
    /*
2919
     * Blob that holds Issuer certificate to check certificates issuer
2920
     */
2921
0
    return Curl_setblobopt(&s->blobs[BLOB_SSL_ISSUERCERT], blob);
2922
2923
0
  default:
2924
0
    return CURLE_UNKNOWN_OPTION;
2925
0
  }
2926
  /* unreachable */
2927
0
}
2928
2929
/*
2930
 * Do not make Curl_vsetopt() static: it is called from
2931
 * packages/OS400/ccsidcurl.c.
2932
 */
2933
CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
2934
0
{
2935
0
  if(option < CURLOPTTYPE_OBJECTPOINT)
2936
0
    return setopt_long(data, option, va_arg(param, long));
2937
0
  else if(option < CURLOPTTYPE_FUNCTIONPOINT) {
2938
    /* unfortunately, different pointer types cannot be identified any other
2939
       way than being listed explicitly */
2940
0
    switch(option) {
2941
0
    case CURLOPT_HTTPHEADER:
2942
0
    case CURLOPT_QUOTE:
2943
0
    case CURLOPT_POSTQUOTE:
2944
0
    case CURLOPT_TELNETOPTIONS:
2945
0
    case CURLOPT_PREQUOTE:
2946
0
    case CURLOPT_HTTP200ALIASES:
2947
0
    case CURLOPT_MAIL_RCPT:
2948
0
    case CURLOPT_RESOLVE:
2949
0
    case CURLOPT_PROXYHEADER:
2950
0
    case CURLOPT_CONNECT_TO:
2951
0
      return setopt_slist(data, option, va_arg(param, struct curl_slist *));
2952
0
    case CURLOPT_HTTPPOST:         /* curl_httppost * */
2953
0
    case CURLOPT_MIMEPOST:         /* curl_mime * */
2954
0
    case CURLOPT_STDERR:           /* FILE * */
2955
0
    case CURLOPT_SHARE:            /* CURLSH * */
2956
0
    case CURLOPT_STREAM_DEPENDS:   /* CURL * */
2957
0
    case CURLOPT_STREAM_DEPENDS_E: /* CURL * */
2958
0
      return setopt_pointers(data, option, param);
2959
0
    default:
2960
0
      break;
2961
0
    }
2962
    /* the char pointer options */
2963
0
    return setopt_cptr(data, option, va_arg(param, char *));
2964
0
  }
2965
0
  else if(option < CURLOPTTYPE_OFF_T)
2966
0
    return setopt_func(data, option, param);
2967
0
  else if(option < CURLOPTTYPE_BLOB)
2968
0
    return setopt_offt(data, option, va_arg(param, curl_off_t));
2969
0
  return setopt_blob(data, option, va_arg(param, struct curl_blob *));
2970
0
}
2971
2972
/*
2973
 * curl_easy_setopt() is the external interface for setting options on an
2974
 * easy handle.
2975
 *
2976
 * NOTE: This is one of few API functions that are allowed to be called from
2977
 * within a callback.
2978
 */
2979
2980
#undef curl_easy_setopt
2981
CURLcode curl_easy_setopt(CURL *d, CURLoption tag, ...)
2982
0
{
2983
0
  va_list arg;
2984
0
  CURLcode result;
2985
0
  struct Curl_easy *data = d;
2986
2987
0
  if(!data)
2988
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
2989
2990
0
  va_start(arg, tag);
2991
2992
0
  result = Curl_vsetopt(data, tag, arg);
2993
2994
0
  va_end(arg);
2995
0
  if(result == CURLE_BAD_FUNCTION_ARGUMENT)
2996
0
    failf(data, "setopt 0x%x got bad argument", tag);
2997
0
  return result;
2998
0
}