Coverage Report

Created: 2026-01-25 06:10

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