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