Coverage Report

Created: 2026-04-29 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Utilities/cmcurl/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
#define C_SSLVERSION_VALUE(x)     ((x) & 0xffff)
194
#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
0
#ifndef USE_NTLM
257
0
    auth &= ~CURLAUTH_NTLM; /* no NTLM support */
258
0
#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
{
325
  /*
326
   * Set explicit SSL version to try to connect with, as some SSL
327
   * implementations are lame.
328
   */
329
  {
330
    long version, version_max;
331
    struct ssl_primary_config *primary = &data->set.ssl.primary;
332
#ifndef CURL_DISABLE_PROXY
333
    if(option != CURLOPT_SSLVERSION)
334
      primary = &data->set.proxy_ssl.primary;
335
#else
336
    if(option) {}
337
#endif
338
    version = C_SSLVERSION_VALUE(arg);
339
    version_max = (long)C_SSLVERSION_MAX_VALUE(arg);
340
341
    if(version < CURL_SSLVERSION_DEFAULT ||
342
       version == CURL_SSLVERSION_SSLv2 ||
343
       version == CURL_SSLVERSION_SSLv3 ||
344
       version >= CURL_SSLVERSION_LAST ||
345
       version_max < CURL_SSLVERSION_MAX_NONE ||
346
       version_max >= CURL_SSLVERSION_MAX_LAST)
347
      return CURLE_BAD_FUNCTION_ARGUMENT;
348
    if(version == CURL_SSLVERSION_DEFAULT)
349
      version = CURL_SSLVERSION_TLSv1_2;
350
351
    primary->version = (unsigned char)version;
352
    primary->version_max = (unsigned int)version_max;
353
  }
354
  return CURLE_OK;
355
}
356
#endif /* !USE_SSL */
357
358
#ifndef CURL_DISABLE_RTSP
359
static CURLcode setopt_RTSP_REQUEST(struct Curl_easy *data, long arg)
360
{
361
  /*
362
   * Set the RTSP request method (OPTIONS, SETUP, PLAY, etc...) Would this be
363
   * better if the RTSPREQ_* were moved into here?
364
   */
365
  Curl_RtspReq rtspreq = RTSPREQ_NONE;
366
  switch(arg) {
367
  case CURL_RTSPREQ_OPTIONS:
368
    rtspreq = RTSPREQ_OPTIONS;
369
    break;
370
  case CURL_RTSPREQ_DESCRIBE:
371
    rtspreq = RTSPREQ_DESCRIBE;
372
    break;
373
  case CURL_RTSPREQ_ANNOUNCE:
374
    rtspreq = RTSPREQ_ANNOUNCE;
375
    break;
376
  case CURL_RTSPREQ_SETUP:
377
    rtspreq = RTSPREQ_SETUP;
378
    break;
379
  case CURL_RTSPREQ_PLAY:
380
    rtspreq = RTSPREQ_PLAY;
381
    break;
382
  case CURL_RTSPREQ_PAUSE:
383
    rtspreq = RTSPREQ_PAUSE;
384
    break;
385
  case CURL_RTSPREQ_TEARDOWN:
386
    rtspreq = RTSPREQ_TEARDOWN;
387
    break;
388
  case CURL_RTSPREQ_GET_PARAMETER:
389
    rtspreq = RTSPREQ_GET_PARAMETER;
390
    break;
391
  case CURL_RTSPREQ_SET_PARAMETER:
392
    rtspreq = RTSPREQ_SET_PARAMETER;
393
    break;
394
  case CURL_RTSPREQ_RECORD:
395
    rtspreq = RTSPREQ_RECORD;
396
    break;
397
  case CURL_RTSPREQ_RECEIVE:
398
    rtspreq = RTSPREQ_RECEIVE;
399
    break;
400
  default:
401
    return CURLE_BAD_FUNCTION_ARGUMENT;
402
  }
403
404
  data->set.rtspreq = rtspreq;
405
  return CURLE_OK;
406
}
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
{
414
  config->ssl_options = (unsigned char)(arg & 0xff);
415
  ssl->enable_beast = !!(arg & CURLSSLOPT_ALLOW_BEAST);
416
  ssl->no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
417
  ssl->no_partialchain = !!(arg & CURLSSLOPT_NO_PARTIALCHAIN);
418
  ssl->revoke_best_effort = !!(arg & CURLSSLOPT_REVOKE_BEST_EFFORT);
419
  ssl->native_ca_store = !!(arg & CURLSSLOPT_NATIVE_CA);
420
  ssl->auto_client_cert = !!(arg & CURLSSLOPT_AUTO_CLIENT_CERT);
421
  ssl->earlydata = !!(arg & CURLSSLOPT_EARLYDATA);
422
}
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
#ifndef CURL_DISABLE_TFTP
665
  case CURLOPT_TFTP_NO_OPTIONS:
666
    /*
667
     * Option that prevents libcurl from sending TFTP option requests to the
668
     * server.
669
     */
670
    s->tftp_no_options = enabled;
671
    break;
672
#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
#ifdef USE_SSL
744
    if(Curl_ssl_supports(data, SSLSUPP_CERTINFO))
745
      s->ssl.certinfo = enabled;
746
    else
747
#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
#ifndef CURL_DISABLE_SMTP
779
  case CURLOPT_MAIL_RCPT_ALLOWFAILS:
780
    /* allow RCPT TO command to fail for some recipients */
781
    s->mail_rcpt_allowfails = enabled;
782
    break;
783
#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
#ifdef USE_SSL
977
  CURLcode result = CURLE_OK;
978
  struct UserDefined *s = &data->set;
979
  switch(option) {
980
  case CURLOPT_CA_CACHE_TIMEOUT:
981
    if(Curl_ssl_supports(data, SSLSUPP_CA_CACHE)) {
982
      result = value_range(&arg, -1, -1, INT_MAX);
983
      if(!result)
984
        s->general_ssl.ca_cache_timeout = (int)arg;
985
    }
986
    else
987
      result = CURLE_NOT_BUILT_IN;
988
    break;
989
  case CURLOPT_SSLVERSION:
990
#ifndef CURL_DISABLE_PROXY
991
  case CURLOPT_PROXY_SSLVERSION:
992
#endif
993
    return Curl_setopt_SSLVERSION(data, option, arg);
994
  case CURLOPT_SSL_FALSESTART:
995
    result = CURLE_NOT_BUILT_IN;
996
    break;
997
  case CURLOPT_USE_SSL:
998
    if((arg < CURLUSESSL_NONE) || (arg >= CURLUSESSL_LAST))
999
      result = CURLE_BAD_FUNCTION_ARGUMENT;
1000
    else
1001
      s->use_ssl = (unsigned char)arg;
1002
    break;
1003
  case CURLOPT_SSL_OPTIONS:
1004
    set_ssl_options(&s->ssl, &s->ssl.primary, arg);
1005
    break;
1006
#ifndef CURL_DISABLE_PROXY
1007
  case CURLOPT_PROXY_SSL_OPTIONS:
1008
    set_ssl_options(&s->proxy_ssl, &s->proxy_ssl.primary, arg);
1009
    break;
1010
#endif
1011
  case CURLOPT_SSL_ENABLE_NPN:
1012
    break;
1013
  case CURLOPT_SSLENGINE_DEFAULT:
1014
    Curl_safefree(s->str[STRING_SSL_ENGINE]);
1015
    result = Curl_ssl_set_engine_default(data);
1016
    break;
1017
  default:
1018
    return CURLE_UNKNOWN_OPTION;
1019
  }
1020
  return result;
1021
#else  /* USE_SSL */
1022
0
  (void)data;
1023
0
  (void)option;
1024
0
  (void)arg;
1025
0
  return CURLE_UNKNOWN_OPTION;
1026
0
#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
#ifndef CURL_DISABLE_TFTP
1134
  case CURLOPT_TFTP_BLKSIZE:
1135
    result = value_range(&arg, 0, TFTP_BLKSIZE_MIN, TFTP_BLKSIZE_MAX);
1136
    if(!result)
1137
      s->tftp_blksize = (unsigned short)arg;
1138
    break;
1139
#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
#ifndef CURL_DISABLE_RTSP
1185
  case CURLOPT_RTSP_REQUEST:
1186
    return setopt_RTSP_REQUEST(data, arg);
1187
  case CURLOPT_RTSP_CLIENT_CSEQ:
1188
    result = value_range(&arg, 0, 0, INT_MAX);
1189
    if(!result)
1190
      data->state.rtsp_next_client_CSeq = (uint32_t)arg;
1191
    break;
1192
  case CURLOPT_RTSP_SERVER_CSEQ:
1193
    result = value_range(&arg, 0, 0, INT_MAX);
1194
    if(!result)
1195
      data->state.rtsp_next_server_CSeq = (uint32_t)arg;
1196
    break;
1197
#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
#ifndef CURL_DISABLE_WEBSOCKETS
1216
  case CURLOPT_WS_OPTIONS:
1217
    s->ws_raw_mode = (bool)(arg & CURLWS_RAW_MODE);
1218
    s->ws_no_auto_pong = (bool)(arg & CURLWS_NOAUTOPONG);
1219
    break;
1220
#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
#ifndef CURL_DISABLE_HSTS
1270
  case CURLOPT_HSTS_CTRL:
1271
    if(arg & CURLHSTS_ENABLE) {
1272
      if(!data->hsts) {
1273
        data->hsts = Curl_hsts_init();
1274
        if(!data->hsts)
1275
          return CURLE_OUT_OF_MEMORY;
1276
      }
1277
    }
1278
    else
1279
      Curl_hsts_cleanup(&data->hsts);
1280
    break;
1281
#endif
1282
#ifndef CURL_DISABLE_ALTSVC
1283
  case CURLOPT_ALTSVC_CTRL:
1284
    return Curl_altsvc_ctrl(data, arg);
1285
#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 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
#ifndef CURL_DISABLE_TELNET
1397
  case CURLOPT_TELNETOPTIONS:
1398
    /*
1399
     * Set a linked list of telnet options
1400
     */
1401
    s->telnet_options = slist;
1402
    break;
1403
#endif
1404
#ifndef CURL_DISABLE_SMTP
1405
  case CURLOPT_MAIL_RCPT:
1406
    /* Set the list of mail recipients */
1407
    s->mail_rcpt = slist;
1408
    break;
1409
#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
#ifndef CURL_DISABLE_HSTS
1503
      if(data->share->hsts == data->hsts)
1504
        data->hsts = NULL;
1505
#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
#ifndef CURL_DISABLE_HSTS
1539
      if(data->share->hsts) {
1540
        /* first free the private one if any */
1541
        Curl_hsts_cleanup(&data->hsts);
1542
        data->hsts = data->share->hsts;
1543
      }
1544
#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
#ifdef USE_SSL
1783
    if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY))
1784
      return Curl_setstropt(&s->str[STRING_SSL_PINNEDPUBLICKEY_PROXY], ptr);
1785
#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
#ifdef USE_SSL
1822
    if(Curl_ssl_supports(data, SSLSUPP_CA_PATH)) {
1823
      /* This does not work on Windows. */
1824
      s->proxy_ssl.custom_capath = TRUE;
1825
      return Curl_setstropt(&s->str[STRING_SSL_CAPATH_PROXY], ptr);
1826
    }
1827
#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
#ifdef USE_SSL
1901
    if(Curl_ssl_supports(data, SSLSUPP_CA_PATH)) {
1902
      /* This does not work on Windows. */
1903
      s->ssl.custom_capath = TRUE;
1904
      return Curl_setstropt(&s->str[STRING_SSL_CAPATH], ptr);
1905
    }
1906
#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 s->method = HTTPREQ_CUSTOM; here, we continue as if we
2054
       were using the already set type and this changes the actual request
2055
       keyword */
2056
0
  case CURLOPT_SERVICE_NAME:
2057
    /*
2058
     * Set authentication service name for DIGEST-MD5, Kerberos 5 and SPNEGO
2059
     */
2060
0
    return Curl_setstropt(&s->str[STRING_SERVICE_NAME], ptr);
2061
2062
0
  case CURLOPT_HEADERDATA:
2063
    /*
2064
     * Custom pointer to pass the header write callback function
2065
     */
2066
0
    s->writeheader = ptr;
2067
0
    break;
2068
0
  case CURLOPT_READDATA:
2069
    /*
2070
     * FILE pointer to read the file to be uploaded from. Or possibly used as
2071
     * argument to the read callback.
2072
     */
2073
0
    s->in_set = ptr;
2074
0
    break;
2075
0
  case CURLOPT_WRITEDATA:
2076
    /*
2077
     * FILE pointer to write to. Or possibly used as argument to the write
2078
     * callback.
2079
     */
2080
0
    s->out = ptr;
2081
0
    break;
2082
0
  case CURLOPT_DEBUGDATA:
2083
    /*
2084
     * Set to a void * that should receive all error writes. This
2085
     * defaults to CURLOPT_STDERR for normal operations.
2086
     */
2087
0
    s->debugdata = ptr;
2088
0
    break;
2089
0
  case CURLOPT_PROGRESSDATA:
2090
    /*
2091
     * Custom client data to pass to the progress callback
2092
     */
2093
0
    s->progress_client = ptr;
2094
0
    break;
2095
0
  case CURLOPT_SEEKDATA:
2096
    /*
2097
     * Seek control callback. Might be NULL.
2098
     */
2099
0
    s->seek_client = ptr;
2100
0
    break;
2101
0
  case CURLOPT_IOCTLDATA:
2102
    /*
2103
     * I/O control data pointer. Might be NULL.
2104
     */
2105
0
    s->ioctl_client = ptr;
2106
0
    break;
2107
0
  case CURLOPT_SSL_CTX_DATA:
2108
    /*
2109
     * Set an SSL_CTX callback parameter pointer
2110
     */
2111
#ifdef USE_SSL
2112
    if(Curl_ssl_supports(data, SSLSUPP_SSL_CTX)) {
2113
      s->ssl.fsslctxp = ptr;
2114
      break;
2115
    }
2116
    else
2117
#endif
2118
0
      return CURLE_NOT_BUILT_IN;
2119
0
  case CURLOPT_SOCKOPTDATA:
2120
    /*
2121
     * socket callback data pointer. Might be NULL.
2122
     */
2123
0
    s->sockopt_client = ptr;
2124
0
    break;
2125
0
  case CURLOPT_OPENSOCKETDATA:
2126
    /*
2127
     * socket callback data pointer. Might be NULL.
2128
     */
2129
0
    s->opensocket_client = ptr;
2130
0
    break;
2131
0
  case CURLOPT_RESOLVER_START_DATA:
2132
    /*
2133
     * resolver start callback data pointer. Might be NULL.
2134
     */
2135
0
    s->resolver_start_client = ptr;
2136
0
    break;
2137
0
  case CURLOPT_CLOSESOCKETDATA:
2138
    /*
2139
     * socket callback data pointer. Might be NULL.
2140
     */
2141
0
    s->closesocket_client = ptr;
2142
0
    break;
2143
0
  case CURLOPT_PREREQDATA:
2144
0
    s->prereq_userp = ptr;
2145
0
    break;
2146
0
  case CURLOPT_ERRORBUFFER:
2147
    /*
2148
     * Error buffer provided by the caller to get the human readable error
2149
     * string in.
2150
     */
2151
0
    s->errorbuffer = ptr;
2152
0
    break;
2153
2154
0
#ifndef CURL_DISABLE_FTP
2155
0
  case CURLOPT_FTPPORT:
2156
    /*
2157
     * Use FTP PORT, this also specifies which IP address to use
2158
     */
2159
0
    result = Curl_setstropt(&s->str[STRING_FTPPORT], ptr);
2160
0
    s->ftp_use_port = !!(s->str[STRING_FTPPORT]);
2161
0
    break;
2162
2163
0
  case CURLOPT_FTP_ACCOUNT:
2164
0
    return Curl_setstropt(&s->str[STRING_FTP_ACCOUNT], ptr);
2165
2166
0
  case CURLOPT_FTP_ALTERNATIVE_TO_USER:
2167
0
    return Curl_setstropt(&s->str[STRING_FTP_ALTERNATIVE_TO_USER], ptr);
2168
2169
0
  case CURLOPT_KRBLEVEL:
2170
0
    return CURLE_NOT_BUILT_IN; /* removed in 8.17.0 */
2171
0
  case CURLOPT_CHUNK_DATA:
2172
0
    s->wildcardptr = ptr;
2173
0
    break;
2174
0
  case CURLOPT_FNMATCH_DATA:
2175
0
    s->fnmatch_data = ptr;
2176
0
    break;
2177
0
#endif
2178
0
  case CURLOPT_URL:
2179
    /*
2180
     * The URL to fetch.
2181
     */
2182
0
    result = Curl_setstropt(&s->str[STRING_SET_URL], ptr);
2183
0
    Curl_bufref_set(&data->state.url, s->str[STRING_SET_URL], 0, NULL);
2184
0
    break;
2185
2186
0
  case CURLOPT_USERPWD:
2187
    /*
2188
     * user:password to use in the operation
2189
     */
2190
0
    return setstropt_userpwd(ptr, &s->str[STRING_USERNAME],
2191
0
                             &s->str[STRING_PASSWORD]);
2192
2193
0
  case CURLOPT_USERNAME:
2194
    /*
2195
     * authentication username to use in the operation
2196
     */
2197
0
    return Curl_setstropt(&s->str[STRING_USERNAME], ptr);
2198
2199
0
  case CURLOPT_PASSWORD:
2200
    /*
2201
     * authentication password to use in the operation
2202
     */
2203
0
    return Curl_setstropt(&s->str[STRING_PASSWORD], ptr);
2204
2205
0
  case CURLOPT_LOGIN_OPTIONS:
2206
    /*
2207
     * authentication options to use in the operation
2208
     */
2209
0
    return Curl_setstropt(&s->str[STRING_OPTIONS], ptr);
2210
2211
0
  case CURLOPT_XOAUTH2_BEARER:
2212
    /*
2213
     * OAuth 2.0 bearer token to use in the operation
2214
     */
2215
0
    return Curl_setstropt(&s->str[STRING_BEARER], ptr);
2216
0
  case CURLOPT_RANGE:
2217
    /*
2218
     * What range of the file you want to transfer
2219
     */
2220
0
    return Curl_setstropt(&s->str[STRING_SET_RANGE], ptr);
2221
0
  case CURLOPT_CURLU:
2222
    /*
2223
     * pass CURLU to set URL
2224
     */
2225
0
    Curl_bufref_free(&data->state.url);
2226
0
    Curl_safefree(s->str[STRING_SET_URL]);
2227
0
    s->uh = (CURLU *)ptr;
2228
0
    break;
2229
0
  case CURLOPT_SSLCERT:
2230
    /*
2231
     * String that holds filename of the SSL certificate to use
2232
     */
2233
0
    return Curl_setstropt(&s->str[STRING_CERT], ptr);
2234
0
  case CURLOPT_SSLCERTTYPE:
2235
    /*
2236
     * String that holds file type of the SSL certificate to use
2237
     */
2238
0
    return Curl_setstropt(&s->str[STRING_CERT_TYPE], ptr);
2239
0
  case CURLOPT_SSLKEY:
2240
    /*
2241
     * String that holds filename of the SSL key to use
2242
     */
2243
0
    return Curl_setstropt(&s->str[STRING_KEY], ptr);
2244
0
  case CURLOPT_SSLKEYTYPE:
2245
    /*
2246
     * String that holds file type of the SSL key to use
2247
     */
2248
0
    return Curl_setstropt(&s->str[STRING_KEY_TYPE], ptr);
2249
0
  case CURLOPT_KEYPASSWD:
2250
    /*
2251
     * String that holds the SSL or SSH private key password.
2252
     */
2253
0
    return Curl_setstropt(&s->str[STRING_KEY_PASSWD], ptr);
2254
0
  case CURLOPT_SSLENGINE:
2255
    /*
2256
     * String that holds the SSL crypto engine.
2257
     */
2258
0
    if(ptr && ptr[0]) {
2259
0
      result = Curl_setstropt(&s->str[STRING_SSL_ENGINE], ptr);
2260
0
      if(!result) {
2261
0
        result = Curl_ssl_set_engine(data, ptr);
2262
0
      }
2263
0
    }
2264
0
    break;
2265
0
  case CURLOPT_INTERFACE:
2266
    /*
2267
     * Set what interface or address/hostname to bind the socket to when
2268
     * performing an operation and thus what from-IP your connection will use.
2269
     */
2270
0
    return setstropt_interface(ptr,
2271
0
                               &s->str[STRING_DEVICE],
2272
0
                               &s->str[STRING_INTERFACE],
2273
0
                               &s->str[STRING_BINDHOST]);
2274
0
  case CURLOPT_ISSUERCERT:
2275
    /*
2276
     * Set Issuer certificate file
2277
     * to check certificates issuer
2278
     */
2279
0
    if(Curl_ssl_supports(data, SSLSUPP_ISSUERCERT))
2280
0
      return Curl_setstropt(&s->str[STRING_SSL_ISSUERCERT], ptr);
2281
0
    return CURLE_NOT_BUILT_IN;
2282
0
  case CURLOPT_PRIVATE:
2283
    /*
2284
     * Set private data pointer.
2285
     */
2286
0
    s->private_data = ptr;
2287
0
    break;
2288
#ifdef USE_SSL
2289
  case CURLOPT_SSL_EC_CURVES:
2290
    /*
2291
     * Set accepted curves in SSL connection setup.
2292
     * Specify colon-delimited list of curve algorithm names.
2293
     */
2294
    if(Curl_ssl_supports(data, SSLSUPP_SSL_EC_CURVES))
2295
      return Curl_setstropt(&s->str[STRING_SSL_EC_CURVES], ptr);
2296
    return CURLE_NOT_BUILT_IN;
2297
  case CURLOPT_SSL_SIGNATURE_ALGORITHMS:
2298
    /*
2299
     * Set accepted signature algorithms.
2300
     * Specify colon-delimited list of signature scheme names.
2301
     */
2302
    if(Curl_ssl_supports(data, SSLSUPP_SIGNATURE_ALGORITHMS))
2303
      return Curl_setstropt(&s->str[STRING_SSL_SIGNATURE_ALGORITHMS], ptr);
2304
    return CURLE_NOT_BUILT_IN;
2305
  case CURLOPT_PINNEDPUBLICKEY:
2306
    /*
2307
     * Set pinned public key for SSL connection.
2308
     * Specify filename of the public key in DER format.
2309
     */
2310
    if(Curl_ssl_supports(data, SSLSUPP_PINNEDPUBKEY))
2311
      return Curl_setstropt(&s->str[STRING_SSL_PINNEDPUBLICKEY], ptr);
2312
    return CURLE_NOT_BUILT_IN;
2313
#endif
2314
#ifdef USE_SSH
2315
  case CURLOPT_SSH_PUBLIC_KEYFILE:
2316
    /*
2317
     * Use this file instead of the $HOME/.ssh/id_dsa.pub file
2318
     */
2319
    return Curl_setstropt(&s->str[STRING_SSH_PUBLIC_KEY], ptr);
2320
  case CURLOPT_SSH_PRIVATE_KEYFILE:
2321
    /*
2322
     * Use this file instead of the $HOME/.ssh/id_dsa file
2323
     */
2324
    return Curl_setstropt(&s->str[STRING_SSH_PRIVATE_KEY], ptr);
2325
  case CURLOPT_SSH_KEYDATA:
2326
    /*
2327
     * Custom client data to pass to the SSH keyfunc callback
2328
     */
2329
    s->ssh_keyfunc_userp = ptr;
2330
    break;
2331
#if defined(USE_LIBSSH2) || defined(USE_LIBSSH)
2332
  case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5:
2333
    /*
2334
     * Option to allow for the MD5 of the host public key to be checked
2335
     * for validation purposes.
2336
     */
2337
    return Curl_setstropt(&s->str[STRING_SSH_HOST_PUBLIC_KEY_MD5], ptr);
2338
  case CURLOPT_SSH_KNOWNHOSTS:
2339
    /*
2340
     * Store the filename to read known hosts from.
2341
     */
2342
    return Curl_setstropt(&s->str[STRING_SSH_KNOWNHOSTS], ptr);
2343
#endif
2344
#ifdef USE_LIBSSH2
2345
  case CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256:
2346
    /*
2347
     * Option to allow for the SHA256 of the host public key to be checked
2348
     * for validation purposes.
2349
     */
2350
    return Curl_setstropt(&s->str[STRING_SSH_HOST_PUBLIC_KEY_SHA256], ptr);
2351
  case CURLOPT_SSH_HOSTKEYDATA:
2352
    /*
2353
     * Custom client data to pass to the SSH keyfunc callback
2354
     */
2355
    s->ssh_hostkeyfunc_userp = ptr;
2356
    break;
2357
#endif /* USE_LIBSSH2 */
2358
#endif /* USE_SSH */
2359
0
  case CURLOPT_PROTOCOLS_STR:
2360
0
    if(ptr) {
2361
0
      curl_prot_t protos;
2362
0
      result = protocol2num(ptr, &protos);
2363
0
      if(!result)
2364
0
        s->allowed_protocols = protos;
2365
0
    }
2366
0
    else
2367
      /* make a NULL argument reset to default */
2368
0
      s->allowed_protocols = (curl_prot_t)CURLPROTO_64ALL;
2369
0
    break;
2370
0
  case CURLOPT_REDIR_PROTOCOLS_STR:
2371
0
    if(ptr) {
2372
0
      curl_prot_t protos;
2373
0
      result = protocol2num(ptr, &protos);
2374
0
      if(!result)
2375
0
        s->redir_protocols = protos;
2376
0
    }
2377
0
    else
2378
      /* make a NULL argument reset to default */
2379
0
      s->redir_protocols = (curl_prot_t)CURLPROTO_REDIR;
2380
0
    break;
2381
0
  case CURLOPT_DEFAULT_PROTOCOL:
2382
    /* Set the protocol to use when the URL does not include any protocol */
2383
0
    return Curl_setstropt(&s->str[STRING_DEFAULT_PROTOCOL], ptr);
2384
#ifndef CURL_DISABLE_SMTP
2385
  case CURLOPT_MAIL_FROM:
2386
    /* Set the SMTP mail originator */
2387
    return Curl_setstropt(&s->str[STRING_MAIL_FROM], ptr);
2388
  case CURLOPT_MAIL_AUTH:
2389
    /* Set the SMTP auth originator */
2390
    return Curl_setstropt(&s->str[STRING_MAIL_AUTH], ptr);
2391
#endif
2392
0
  case CURLOPT_SASL_AUTHZID:
2393
    /* Authorization identity (identity to act as) */
2394
0
    return Curl_setstropt(&s->str[STRING_SASL_AUTHZID], ptr);
2395
#ifndef CURL_DISABLE_RTSP
2396
  case CURLOPT_RTSP_SESSION_ID:
2397
    /*
2398
     * Set the RTSP Session ID manually. Useful if the application is
2399
     * resuming a previously established RTSP session
2400
     */
2401
    return Curl_setstropt(&s->str[STRING_RTSP_SESSION_ID], ptr);
2402
  case CURLOPT_RTSP_STREAM_URI:
2403
    /*
2404
     * Set the Stream URI for the RTSP request. Unless the request is
2405
     * for generic server options, the application will need to set this.
2406
     */
2407
    return Curl_setstropt(&s->str[STRING_RTSP_STREAM_URI], ptr);
2408
  case CURLOPT_RTSP_TRANSPORT:
2409
    /*
2410
     * The content of the Transport: header for the RTSP request
2411
     */
2412
    return Curl_setstropt(&s->str[STRING_RTSP_TRANSPORT], ptr);
2413
  case CURLOPT_INTERLEAVEDATA:
2414
    s->rtp_out = ptr;
2415
    break;
2416
#endif /* !CURL_DISABLE_RTSP */
2417
#ifdef USE_TLS_SRP
2418
  case CURLOPT_TLSAUTH_USERNAME:
2419
    return Curl_setstropt(&s->str[STRING_TLSAUTH_USERNAME], ptr);
2420
  case CURLOPT_TLSAUTH_PASSWORD:
2421
    return Curl_setstropt(&s->str[STRING_TLSAUTH_PASSWORD], ptr);
2422
  case CURLOPT_TLSAUTH_TYPE:
2423
    if(ptr && !curl_strequal(ptr, "SRP"))
2424
      result = CURLE_BAD_FUNCTION_ARGUMENT;
2425
    break;
2426
#ifndef CURL_DISABLE_PROXY
2427
  case CURLOPT_PROXY_TLSAUTH_USERNAME:
2428
    return Curl_setstropt(&s->str[STRING_TLSAUTH_USERNAME_PROXY], ptr);
2429
  case CURLOPT_PROXY_TLSAUTH_PASSWORD:
2430
    return Curl_setstropt(&s->str[STRING_TLSAUTH_PASSWORD_PROXY], ptr);
2431
  case CURLOPT_PROXY_TLSAUTH_TYPE:
2432
    if(ptr && !curl_strequal(ptr, "SRP"))
2433
      result = CURLE_BAD_FUNCTION_ARGUMENT;
2434
    break;
2435
#endif
2436
#endif
2437
#ifdef CURLRES_ARES
2438
  case CURLOPT_DNS_SERVERS:
2439
    result = Curl_setstropt(&s->str[STRING_DNS_SERVERS], ptr);
2440
    if(result)
2441
      break;
2442
    return Curl_async_ares_set_dns_servers(data);
2443
2444
  case CURLOPT_DNS_INTERFACE:
2445
    result = Curl_setstropt(&s->str[STRING_DNS_INTERFACE], ptr);
2446
    if(result)
2447
      break;
2448
    return Curl_async_ares_set_dns_interface(data);
2449
2450
  case CURLOPT_DNS_LOCAL_IP4:
2451
    result = Curl_setstropt(&s->str[STRING_DNS_LOCAL_IP4], ptr);
2452
    if(result)
2453
      break;
2454
    return Curl_async_ares_set_dns_local_ip4(data);
2455
2456
  case CURLOPT_DNS_LOCAL_IP6:
2457
    result = Curl_setstropt(&s->str[STRING_DNS_LOCAL_IP6], ptr);
2458
    if(result)
2459
      break;
2460
    return Curl_async_ares_set_dns_local_ip6(data);
2461
2462
#endif
2463
#ifdef USE_UNIX_SOCKETS
2464
  case CURLOPT_UNIX_SOCKET_PATH:
2465
    s->abstract_unix_socket = FALSE;
2466
    return Curl_setstropt(&s->str[STRING_UNIX_SOCKET_PATH], ptr);
2467
2468
  case CURLOPT_ABSTRACT_UNIX_SOCKET:
2469
    s->abstract_unix_socket = TRUE;
2470
    return Curl_setstropt(&s->str[STRING_UNIX_SOCKET_PATH], ptr);
2471
2472
#endif
2473
2474
0
#ifndef CURL_DISABLE_DOH
2475
0
  case CURLOPT_DOH_URL:
2476
0
    result = Curl_setstropt(&s->str[STRING_DOH], ptr);
2477
0
    s->doh = !!(s->str[STRING_DOH]);
2478
0
    break;
2479
0
#endif
2480
#ifndef CURL_DISABLE_HSTS
2481
  case CURLOPT_HSTSREADDATA:
2482
    s->hsts_read_userp = ptr;
2483
    break;
2484
  case CURLOPT_HSTSWRITEDATA:
2485
    s->hsts_write_userp = ptr;
2486
    break;
2487
  case CURLOPT_HSTS: {
2488
    struct curl_slist *h;
2489
    if(!data->hsts) {
2490
      data->hsts = Curl_hsts_init();
2491
      if(!data->hsts)
2492
        return CURLE_OUT_OF_MEMORY;
2493
    }
2494
    if(ptr) {
2495
      result = Curl_setstropt(&s->str[STRING_HSTS], ptr);
2496
      if(result)
2497
        return result;
2498
      /* this needs to build a list of filenames to read from, so that it can
2499
         read them later, as we might get a shared HSTS handle to load them
2500
         into */
2501
      h = curl_slist_append(data->state.hstslist, ptr);
2502
      if(!h) {
2503
        curl_slist_free_all(data->state.hstslist);
2504
        data->state.hstslist = NULL;
2505
        return CURLE_OUT_OF_MEMORY;
2506
      }
2507
      data->state.hstslist = h; /* store the list for later use */
2508
    }
2509
    else {
2510
      /* clear the list of HSTS files */
2511
      curl_slist_free_all(data->state.hstslist);
2512
      data->state.hstslist = NULL;
2513
      if(!data->share || !data->share->hsts)
2514
        /* throw away the HSTS cache unless shared */
2515
        Curl_hsts_cleanup(&data->hsts);
2516
    }
2517
    break;
2518
  }
2519
#endif /* !CURL_DISABLE_HSTS */
2520
#ifndef CURL_DISABLE_ALTSVC
2521
  case CURLOPT_ALTSVC:
2522
    if(!data->asi) {
2523
      data->asi = Curl_altsvc_init();
2524
      if(!data->asi)
2525
        return CURLE_OUT_OF_MEMORY;
2526
    }
2527
    result = Curl_setstropt(&s->str[STRING_ALTSVC], ptr);
2528
    if(result)
2529
      break;
2530
    if(ptr)
2531
      return Curl_altsvc_load(data->asi, ptr);
2532
    break;
2533
#endif /* !CURL_DISABLE_ALTSVC */
2534
#ifdef USE_ECH
2535
  case CURLOPT_ECH: {
2536
    size_t plen = 0;
2537
2538
    if(!ptr) {
2539
      s->tls_ech = CURLECH_DISABLE;
2540
      break;
2541
    }
2542
    plen = strlen(ptr);
2543
    if(plen > CURL_MAX_INPUT_LENGTH) {
2544
      s->tls_ech = CURLECH_DISABLE;
2545
      return CURLE_BAD_FUNCTION_ARGUMENT;
2546
    }
2547
    /* set tls_ech flag value, preserving CLA_CFG bit */
2548
    if(!strcmp(ptr, "false"))
2549
      s->tls_ech = (s->tls_ech & CURLECH_CLA_CFG) | CURLECH_DISABLE;
2550
    else if(!strcmp(ptr, "grease"))
2551
      s->tls_ech = (s->tls_ech & CURLECH_CLA_CFG) | CURLECH_GREASE;
2552
    else if(!strcmp(ptr, "true"))
2553
      s->tls_ech = (s->tls_ech & CURLECH_CLA_CFG) | CURLECH_ENABLE;
2554
    else if(!strcmp(ptr, "hard"))
2555
      s->tls_ech = (s->tls_ech & CURLECH_CLA_CFG) | CURLECH_HARD;
2556
    else if(plen > 5 && !strncmp(ptr, "ecl:", 4)) {
2557
      result = Curl_setstropt(&s->str[STRING_ECH_CONFIG], ptr + 4);
2558
      if(!result)
2559
        s->tls_ech |= CURLECH_CLA_CFG;
2560
    }
2561
    else if(plen > 4 && !strncmp(ptr, "pn:", 3))
2562
      result = Curl_setstropt(&s->str[STRING_ECH_PUBLIC], ptr + 3);
2563
    break;
2564
  }
2565
#endif
2566
0
  default:
2567
0
    return CURLE_UNKNOWN_OPTION;
2568
0
  }
2569
0
  return result;
2570
0
}
2571
2572
static CURLcode setopt_func(struct Curl_easy *data, CURLoption option,
2573
                            va_list param)
2574
0
{
2575
0
  struct UserDefined *s = &data->set;
2576
0
  switch(option) {
2577
0
  case CURLOPT_PROGRESSFUNCTION:
2578
    /*
2579
     * Progress callback function
2580
     */
2581
0
    s->fprogress = va_arg(param, curl_progress_callback);
2582
0
    if(s->fprogress)
2583
0
      data->progress.callback = TRUE; /* no longer internal */
2584
0
    else
2585
0
      data->progress.callback = FALSE; /* NULL enforces internal */
2586
0
    break;
2587
2588
0
  case CURLOPT_XFERINFOFUNCTION:
2589
    /*
2590
     * Transfer info callback function
2591
     */
2592
0
    s->fxferinfo = va_arg(param, curl_xferinfo_callback);
2593
0
    if(s->fxferinfo)
2594
0
      data->progress.callback = TRUE; /* no longer internal */
2595
0
    else
2596
0
      data->progress.callback = FALSE; /* NULL enforces internal */
2597
2598
0
    break;
2599
0
  case CURLOPT_DEBUGFUNCTION:
2600
    /*
2601
     * stderr write callback.
2602
     */
2603
0
    s->fdebug = va_arg(param, curl_debug_callback);
2604
    /*
2605
     * if the callback provided is NULL, it will use the default callback
2606
     */
2607
0
    break;
2608
0
  case CURLOPT_HEADERFUNCTION:
2609
    /*
2610
     * Set header write callback
2611
     */
2612
0
    s->fwrite_header = va_arg(param, curl_write_callback);
2613
0
    break;
2614
0
  case CURLOPT_WRITEFUNCTION:
2615
    /*
2616
     * Set data write callback
2617
     */
2618
0
    s->fwrite_func = va_arg(param, curl_write_callback);
2619
0
    if(!s->fwrite_func)
2620
0
#if defined(__clang__) && __clang_major__ >= 16
2621
0
#pragma clang diagnostic push
2622
0
#pragma clang diagnostic ignored "-Wcast-function-type-strict"
2623
0
#endif
2624
      /* When set to NULL, reset to our internal default function */
2625
0
      s->fwrite_func = (curl_write_callback)fwrite;
2626
0
#if defined(__clang__) && __clang_major__ >= 16
2627
0
#pragma clang diagnostic pop
2628
0
#endif
2629
0
    break;
2630
0
  case CURLOPT_READFUNCTION:
2631
    /*
2632
     * Read data callback
2633
     */
2634
0
    s->fread_func_set = va_arg(param, curl_read_callback);
2635
0
    if(!s->fread_func_set) {
2636
0
      s->is_fread_set = 0;
2637
0
#if defined(__clang__) && __clang_major__ >= 16
2638
0
#pragma clang diagnostic push
2639
0
#pragma clang diagnostic ignored "-Wcast-function-type-strict"
2640
0
#endif
2641
      /* When set to NULL, reset to our internal default function */
2642
0
      s->fread_func_set = (curl_read_callback)fread;
2643
0
#if defined(__clang__) && __clang_major__ >= 16
2644
0
#pragma clang diagnostic pop
2645
0
#endif
2646
0
    }
2647
0
    else
2648
0
      s->is_fread_set = 1;
2649
0
    break;
2650
0
  case CURLOPT_SEEKFUNCTION:
2651
    /*
2652
     * Seek callback. Might be NULL.
2653
     */
2654
0
    s->seek_func = va_arg(param, curl_seek_callback);
2655
0
    break;
2656
0
  case CURLOPT_IOCTLFUNCTION:
2657
    /*
2658
     * I/O control callback. Might be NULL.
2659
     */
2660
0
    s->ioctl_func = va_arg(param, curl_ioctl_callback);
2661
0
    break;
2662
0
  case CURLOPT_SSL_CTX_FUNCTION:
2663
    /*
2664
     * Set an SSL_CTX callback
2665
     */
2666
#ifdef USE_SSL
2667
    if(Curl_ssl_supports(data, SSLSUPP_SSL_CTX)) {
2668
      s->ssl.fsslctx = va_arg(param, curl_ssl_ctx_callback);
2669
      break;
2670
    }
2671
    else
2672
#endif
2673
0
      return CURLE_NOT_BUILT_IN;
2674
2675
0
  case CURLOPT_SOCKOPTFUNCTION:
2676
    /*
2677
     * socket callback function: called after socket() but before connect()
2678
     */
2679
0
    s->fsockopt = va_arg(param, curl_sockopt_callback);
2680
0
    break;
2681
2682
0
  case CURLOPT_OPENSOCKETFUNCTION:
2683
    /*
2684
     * open/create socket callback function: called instead of socket(),
2685
     * before connect()
2686
     */
2687
0
    s->fopensocket = va_arg(param, curl_opensocket_callback);
2688
0
    break;
2689
2690
0
  case CURLOPT_CLOSESOCKETFUNCTION:
2691
    /*
2692
     * close socket callback function: called instead of close()
2693
     * when shutting down a connection
2694
     */
2695
0
    s->fclosesocket = va_arg(param, curl_closesocket_callback);
2696
0
    break;
2697
2698
0
  case CURLOPT_RESOLVER_START_FUNCTION:
2699
    /*
2700
     * resolver start callback function: called before a new resolver request
2701
     * is started
2702
     */
2703
0
    s->resolver_start = va_arg(param, curl_resolver_start_callback);
2704
0
    break;
2705
2706
#ifdef USE_SSH
2707
#ifdef USE_LIBSSH2
2708
  case CURLOPT_SSH_HOSTKEYFUNCTION:
2709
    /* the callback to check the hostkey without the knownhost file */
2710
    s->ssh_hostkeyfunc = va_arg(param, curl_sshhostkeycallback);
2711
    break;
2712
#endif
2713
2714
  case CURLOPT_SSH_KEYFUNCTION:
2715
    /* setting to NULL is fine since the ssh.c functions themselves will
2716
       then revert to use the internal default */
2717
    s->ssh_keyfunc = va_arg(param, curl_sshkeycallback);
2718
    break;
2719
2720
#endif /* USE_SSH */
2721
2722
#ifndef CURL_DISABLE_RTSP
2723
  case CURLOPT_INTERLEAVEFUNCTION:
2724
    /* Set the user defined RTP write function */
2725
    s->fwrite_rtp = va_arg(param, curl_write_callback);
2726
    break;
2727
#endif
2728
0
#ifndef CURL_DISABLE_FTP
2729
0
  case CURLOPT_CHUNK_BGN_FUNCTION:
2730
0
    s->chunk_bgn = va_arg(param, curl_chunk_bgn_callback);
2731
0
    break;
2732
0
  case CURLOPT_CHUNK_END_FUNCTION:
2733
0
    s->chunk_end = va_arg(param, curl_chunk_end_callback);
2734
0
    break;
2735
0
  case CURLOPT_FNMATCH_FUNCTION:
2736
0
    s->fnmatch = va_arg(param, curl_fnmatch_callback);
2737
0
    break;
2738
0
#endif
2739
0
#ifndef CURL_DISABLE_HTTP
2740
0
  case CURLOPT_TRAILERFUNCTION:
2741
0
    s->trailer_callback = va_arg(param, curl_trailer_callback);
2742
0
    break;
2743
0
#endif
2744
#ifndef CURL_DISABLE_HSTS
2745
  case CURLOPT_HSTSREADFUNCTION:
2746
    s->hsts_read = va_arg(param, curl_hstsread_callback);
2747
    break;
2748
  case CURLOPT_HSTSWRITEFUNCTION:
2749
    s->hsts_write = va_arg(param, curl_hstswrite_callback);
2750
    break;
2751
#endif
2752
0
  case CURLOPT_PREREQFUNCTION:
2753
0
    s->fprereq = va_arg(param, curl_prereq_callback);
2754
0
    break;
2755
0
  default:
2756
0
    return CURLE_UNKNOWN_OPTION;
2757
0
  }
2758
0
  return CURLE_OK;
2759
0
}
2760
2761
static CURLcode setopt_offt(struct Curl_easy *data, CURLoption option,
2762
                            curl_off_t offt)
2763
0
{
2764
0
  struct UserDefined *s = &data->set;
2765
0
  switch(option) {
2766
0
  case CURLOPT_TIMEVALUE_LARGE:
2767
    /*
2768
     * This is the value to compare with the remote document with the
2769
     * method set with CURLOPT_TIMECONDITION
2770
     */
2771
0
    s->timevalue = (time_t)offt;
2772
0
    break;
2773
2774
    /* MQTT "borrows" some of the HTTP options */
2775
0
  case CURLOPT_POSTFIELDSIZE_LARGE:
2776
    /*
2777
     * The size of the POSTFIELD data to prevent libcurl to do strlen() to
2778
     * figure it out. Enables binary posts.
2779
     */
2780
0
    if(offt < -1)
2781
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2782
2783
0
    if(s->postfieldsize < offt &&
2784
0
       s->postfields == s->str[STRING_COPYPOSTFIELDS]) {
2785
      /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
2786
0
      Curl_safefree(s->str[STRING_COPYPOSTFIELDS]);
2787
0
      s->postfields = NULL;
2788
0
    }
2789
0
    s->postfieldsize = offt;
2790
0
    break;
2791
0
  case CURLOPT_INFILESIZE_LARGE:
2792
    /*
2793
     * If known, this should inform curl about the file size of the
2794
     * to-be-uploaded file.
2795
     */
2796
0
    if(offt < -1)
2797
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2798
0
    s->filesize = offt;
2799
0
    break;
2800
0
  case CURLOPT_MAX_SEND_SPEED_LARGE:
2801
    /*
2802
     * When transfer uploads are faster then CURLOPT_MAX_SEND_SPEED_LARGE
2803
     * bytes per second the transfer is throttled..
2804
     */
2805
0
    if(offt < 0)
2806
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2807
0
    s->max_send_speed = offt;
2808
0
    Curl_rlimit_init(&data->progress.ul.rlimit, offt, offt,
2809
0
                     Curl_pgrs_now(data));
2810
0
    break;
2811
0
  case CURLOPT_MAX_RECV_SPEED_LARGE:
2812
    /*
2813
     * When receiving data faster than CURLOPT_MAX_RECV_SPEED_LARGE bytes per
2814
     * second the transfer is throttled..
2815
     */
2816
0
    if(offt < 0)
2817
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2818
0
    s->max_recv_speed = offt;
2819
0
    Curl_rlimit_init(&data->progress.dl.rlimit, offt, offt,
2820
0
                     Curl_pgrs_now(data));
2821
0
    break;
2822
0
  case CURLOPT_RESUME_FROM_LARGE:
2823
    /*
2824
     * Resume transfer at the given file position
2825
     */
2826
0
    if(offt < -1)
2827
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2828
0
    s->set_resume_from = offt;
2829
0
    break;
2830
0
  case CURLOPT_MAXFILESIZE_LARGE:
2831
    /*
2832
     * Set the maximum size of a file to download.
2833
     */
2834
0
    if(offt < 0)
2835
0
      return CURLE_BAD_FUNCTION_ARGUMENT;
2836
0
    s->max_filesize = offt;
2837
0
    break;
2838
2839
0
  default:
2840
0
    return CURLE_UNKNOWN_OPTION;
2841
0
  }
2842
0
  return CURLE_OK;
2843
0
}
2844
2845
static CURLcode setopt_blob(struct Curl_easy *data, CURLoption option,
2846
                            struct curl_blob *blob)
2847
0
{
2848
0
  struct UserDefined *s = &data->set;
2849
0
  switch(option) {
2850
0
  case CURLOPT_SSLCERT_BLOB:
2851
    /*
2852
     * Blob that holds file content of the SSL certificate to use
2853
     */
2854
0
    return Curl_setblobopt(&s->blobs[BLOB_CERT], blob);
2855
0
#ifndef CURL_DISABLE_PROXY
2856
0
  case CURLOPT_PROXY_SSLCERT_BLOB:
2857
    /*
2858
     * Blob that holds file content of the SSL certificate to use for proxy
2859
     */
2860
0
    return Curl_setblobopt(&s->blobs[BLOB_CERT_PROXY], blob);
2861
0
  case CURLOPT_PROXY_SSLKEY_BLOB:
2862
    /*
2863
     * Blob that holds file content of the SSL key to use for proxy
2864
     */
2865
0
    return Curl_setblobopt(&s->blobs[BLOB_KEY_PROXY], blob);
2866
0
  case CURLOPT_PROXY_CAINFO_BLOB:
2867
    /*
2868
     * Blob that holds CA info for SSL connection proxy.
2869
     * Specify entire PEM of the CA certificate
2870
     */
2871
#ifdef USE_SSL
2872
    if(Curl_ssl_supports(data, SSLSUPP_CAINFO_BLOB))
2873
      return Curl_setblobopt(&s->blobs[BLOB_CAINFO_PROXY], blob);
2874
#endif
2875
0
    return CURLE_NOT_BUILT_IN;
2876
0
  case CURLOPT_PROXY_ISSUERCERT_BLOB:
2877
    /*
2878
     * Blob that holds Issuer certificate to check certificates issuer
2879
     */
2880
0
    return Curl_setblobopt(&s->blobs[BLOB_SSL_ISSUERCERT_PROXY], blob);
2881
0
#endif
2882
0
  case CURLOPT_SSLKEY_BLOB:
2883
    /*
2884
     * Blob that holds file content of the SSL key to use
2885
     */
2886
0
    return Curl_setblobopt(&s->blobs[BLOB_KEY], blob);
2887
0
  case CURLOPT_CAINFO_BLOB:
2888
    /*
2889
     * Blob that holds CA info for SSL connection.
2890
     * Specify entire PEM of the CA certificate
2891
     */
2892
#ifdef USE_SSL
2893
    if(Curl_ssl_supports(data, SSLSUPP_CAINFO_BLOB)) {
2894
      s->ssl.custom_cablob = TRUE;
2895
      return Curl_setblobopt(&s->blobs[BLOB_CAINFO], blob);
2896
    }
2897
#endif
2898
0
    return CURLE_NOT_BUILT_IN;
2899
0
  case CURLOPT_ISSUERCERT_BLOB:
2900
    /*
2901
     * Blob that holds Issuer certificate to check certificates issuer
2902
     */
2903
0
    if(Curl_ssl_supports(data, SSLSUPP_ISSUERCERT_BLOB))
2904
0
      return Curl_setblobopt(&s->blobs[BLOB_SSL_ISSUERCERT], blob);
2905
0
    return CURLE_NOT_BUILT_IN;
2906
2907
0
  default:
2908
0
    return CURLE_UNKNOWN_OPTION;
2909
0
  }
2910
  /* unreachable */
2911
0
}
2912
2913
/*
2914
 * Do not make Curl_vsetopt() static: it is called from
2915
 * projects/OS400/ccsidcurl.c.
2916
 */
2917
CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
2918
0
{
2919
0
  if(option < CURLOPTTYPE_OBJECTPOINT)
2920
0
    return setopt_long(data, option, va_arg(param, long));
2921
0
  else if(option < CURLOPTTYPE_FUNCTIONPOINT) {
2922
    /* unfortunately, different pointer types cannot be identified any other
2923
       way than being listed explicitly */
2924
0
    switch(option) {
2925
0
    case CURLOPT_HTTPHEADER:
2926
0
    case CURLOPT_QUOTE:
2927
0
    case CURLOPT_POSTQUOTE:
2928
0
    case CURLOPT_TELNETOPTIONS:
2929
0
    case CURLOPT_PREQUOTE:
2930
0
    case CURLOPT_HTTP200ALIASES:
2931
0
    case CURLOPT_MAIL_RCPT:
2932
0
    case CURLOPT_RESOLVE:
2933
0
    case CURLOPT_PROXYHEADER:
2934
0
    case CURLOPT_CONNECT_TO:
2935
0
      return setopt_slist(data, option, va_arg(param, struct curl_slist *));
2936
0
    case CURLOPT_HTTPPOST:         /* curl_httppost * */
2937
0
    case CURLOPT_MIMEPOST:         /* curl_mime * */
2938
0
    case CURLOPT_STDERR:           /* FILE * */
2939
0
    case CURLOPT_SHARE:            /* CURLSH * */
2940
0
    case CURLOPT_STREAM_DEPENDS:   /* CURL * */
2941
0
    case CURLOPT_STREAM_DEPENDS_E: /* CURL * */
2942
0
      return setopt_pointers(data, option, param);
2943
0
    default:
2944
0
      break;
2945
0
    }
2946
    /* the char pointer options */
2947
0
    return setopt_cptr(data, option, va_arg(param, char *));
2948
0
  }
2949
0
  else if(option < CURLOPTTYPE_OFF_T)
2950
0
    return setopt_func(data, option, param);
2951
0
  else if(option < CURLOPTTYPE_BLOB)
2952
0
    return setopt_offt(data, option, va_arg(param, curl_off_t));
2953
0
  return setopt_blob(data, option, va_arg(param, struct curl_blob *));
2954
0
}
2955
2956
/*
2957
 * curl_easy_setopt() is the external interface for setting options on an
2958
 * easy handle.
2959
 *
2960
 * NOTE: This is one of few API functions that are allowed to be called from
2961
 * within a callback.
2962
 */
2963
2964
#undef curl_easy_setopt
2965
CURLcode curl_easy_setopt(CURL *d, CURLoption tag, ...)
2966
0
{
2967
0
  va_list arg;
2968
0
  CURLcode result;
2969
0
  struct Curl_easy *data = d;
2970
2971
0
  if(!data)
2972
0
    return CURLE_BAD_FUNCTION_ARGUMENT;
2973
2974
0
  va_start(arg, tag);
2975
2976
0
  result = Curl_vsetopt(data, tag, arg);
2977
2978
0
  va_end(arg);
2979
0
  if(result == CURLE_BAD_FUNCTION_ARGUMENT)
2980
0
    failf(data, "setopt 0x%x got bad argument", tag);
2981
0
  return result;
2982
0
}