Coverage Report

Created: 2025-10-30 06:17

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