Coverage Report

Created: 2026-02-26 06:32

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