Debian Codegraph @

deps/curl/src/tool_setopt.c

raw
1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2019, Daniel Stenberg, <[email protected]>, 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.haxx.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 ***************************************************************************/
22 #include "tool_setup.h"
23
24 #ifndef CURL_DISABLE_LIBCURL_OPTION
25
26 #define ENABLE_CURLX_PRINTF
27 /* use our own printf() functions */
28 #include "curlx.h"
29
30 #include "tool_cfgable.h"
31 #include "tool_easysrc.h"
32 #include "tool_setopt.h"
33 #include "tool_convert.h"
34
35 #include "memdebug.h" /* keep this as LAST include */
36
37 /* Lookup tables for converting setopt values back to symbols */
38 /* For enums, values may be in any order. */
39 /* For bit masks, put combinations first, then single bits, */
40 /* and finally any "NONE" value. */
41
42 #define NV(e) {#e, e}
43 #define NV1(e, v) {#e, (v)}
44 #define NVEND {NULL, 0} /* sentinel to mark end of list */
45
46 const NameValue setopt_nv_CURLPROXY[] = {
47 NV(CURLPROXY_HTTP),
48 NV(CURLPROXY_HTTP_1_0),
49 NV(CURLPROXY_HTTPS),
50 NV(CURLPROXY_SOCKS4),
51 NV(CURLPROXY_SOCKS5),
52 NV(CURLPROXY_SOCKS4A),
53 NV(CURLPROXY_SOCKS5_HOSTNAME),
54 NVEND,
55 };
56
57 const NameValue setopt_nv_CURL_SOCKS_PROXY[] = {
58 NV(CURLPROXY_SOCKS4),
59 NV(CURLPROXY_SOCKS5),
60 NV(CURLPROXY_SOCKS4A),
61 NV(CURLPROXY_SOCKS5_HOSTNAME),
62 NVEND,
63 };
64
65 const NameValueUnsigned setopt_nv_CURLAUTH[] = {
66 NV(CURLAUTH_ANY), /* combination */
67 NV(CURLAUTH_ANYSAFE), /* combination */
68 NV(CURLAUTH_BASIC),
69 NV(CURLAUTH_DIGEST),
70 NV(CURLAUTH_GSSNEGOTIATE),
71 NV(CURLAUTH_NTLM),
72 NV(CURLAUTH_DIGEST_IE),
73 NV(CURLAUTH_NTLM_WB),
74 NV(CURLAUTH_ONLY),
75 NV(CURLAUTH_NONE),
76 NVEND,
77 };
78
79 const NameValue setopt_nv_CURL_HTTP_VERSION[] = {
80 NV(CURL_HTTP_VERSION_NONE),
81 NV(CURL_HTTP_VERSION_1_0),
82 NV(CURL_HTTP_VERSION_1_1),
83 NV(CURL_HTTP_VERSION_2_0),
84 NV(CURL_HTTP_VERSION_2TLS),
85 NV(CURL_HTTP_VERSION_3),
86 NVEND,
87 };
88
89 const NameValue setopt_nv_CURL_SSLVERSION[] = {
90 NV(CURL_SSLVERSION_DEFAULT),
91 NV(CURL_SSLVERSION_TLSv1),
92 NV(CURL_SSLVERSION_SSLv2),
93 NV(CURL_SSLVERSION_SSLv3),
94 NV(CURL_SSLVERSION_TLSv1_0),
95 NV(CURL_SSLVERSION_TLSv1_1),
96 NV(CURL_SSLVERSION_TLSv1_2),
97 NV(CURL_SSLVERSION_TLSv1_3),
98 NVEND,
99 };
100
101 const NameValue setopt_nv_CURL_TIMECOND[] = {
102 NV(CURL_TIMECOND_IFMODSINCE),
103 NV(CURL_TIMECOND_IFUNMODSINCE),
104 NV(CURL_TIMECOND_LASTMOD),
105 NV(CURL_TIMECOND_NONE),
106 NVEND,
107 };
108
109 const NameValue setopt_nv_CURLFTPSSL_CCC[] = {
110 NV(CURLFTPSSL_CCC_NONE),
111 NV(CURLFTPSSL_CCC_PASSIVE),
112 NV(CURLFTPSSL_CCC_ACTIVE),
113 NVEND,
114 };
115
116 const NameValue setopt_nv_CURLUSESSL[] = {
117 NV(CURLUSESSL_NONE),
118 NV(CURLUSESSL_TRY),
119 NV(CURLUSESSL_CONTROL),
120 NV(CURLUSESSL_ALL),
121 NVEND,
122 };
123
124 const NameValueUnsigned setopt_nv_CURLSSLOPT[] = {
125 NV(CURLSSLOPT_ALLOW_BEAST),
126 NV(CURLSSLOPT_NO_REVOKE),
127 NV(CURLSSLOPT_NO_PARTIALCHAIN),
128 NVEND,
129 };
130
131 const NameValue setopt_nv_CURL_NETRC[] = {
132 NV(CURL_NETRC_IGNORED),
133 NV(CURL_NETRC_OPTIONAL),
134 NV(CURL_NETRC_REQUIRED),
135 NVEND,
136 };
137
138 /* These mappings essentially triplicated - see
139 * tool_libinfo.c and tool_paramhlp.c */
140 const NameValue setopt_nv_CURLPROTO[] = {
141 NV(CURLPROTO_ALL), /* combination */
142 NV(CURLPROTO_DICT),
143 NV(CURLPROTO_FILE),
144 NV(CURLPROTO_FTP),
145 NV(CURLPROTO_FTPS),
146 NV(CURLPROTO_GOPHER),
147 NV(CURLPROTO_HTTP),
148 NV(CURLPROTO_HTTPS),
149 NV(CURLPROTO_IMAP),
150 NV(CURLPROTO_IMAPS),
151 NV(CURLPROTO_LDAP),
152 NV(CURLPROTO_LDAPS),
153 NV(CURLPROTO_POP3),
154 NV(CURLPROTO_POP3S),
155 NV(CURLPROTO_RTSP),
156 NV(CURLPROTO_SCP),
157 NV(CURLPROTO_SFTP),
158 NV(CURLPROTO_SMB),
159 NV(CURLPROTO_SMBS),
160 NV(CURLPROTO_SMTP),
161 NV(CURLPROTO_SMTPS),
162 NV(CURLPROTO_TELNET),
163 NV(CURLPROTO_TFTP),
164 NVEND,
165 };
166
167 /* These options have non-zero default values. */
168 static const NameValue setopt_nv_CURLNONZERODEFAULTS[] = {
169 NV1(CURLOPT_SSL_VERIFYPEER, 1),
170 NV1(CURLOPT_SSL_VERIFYHOST, 1),
171 NV1(CURLOPT_SSL_ENABLE_NPN, 1),
172 NV1(CURLOPT_SSL_ENABLE_ALPN, 1),
173 NV1(CURLOPT_TCP_NODELAY, 1),
174 NV1(CURLOPT_PROXY_SSL_VERIFYPEER, 1),
175 NV1(CURLOPT_PROXY_SSL_VERIFYHOST, 1),
176 NV1(CURLOPT_SOCKS5_AUTH, 1),
177 NVEND
178 };
179
180 /* Format and add code; jump to nomem on malloc error */
181 #define ADD(args) do { \
182 ret = easysrc_add args; \
183 if(ret) \
184 goto nomem; \
185 } while(0)
186 #define ADDF(args) do { \
187 ret = easysrc_addf args; \
188 if(ret) \
189 goto nomem; \
190 } while(0)
191 #define NULL_CHECK(p) do { \
192 if(!p) { \
193 ret = CURLE_OUT_OF_MEMORY; \
194 goto nomem; \
195 } \
196 } while(0)
197
198 #define DECL0(s) ADD((&easysrc_decl, s))
199 #define DECL1(f,a) ADDF((&easysrc_decl, f,a))
200
201 #define DATA0(s) ADD((&easysrc_data, s))
202 #define DATA1(f,a) ADDF((&easysrc_data, f,a))
203 #define DATA2(f,a,b) ADDF((&easysrc_data, f,a,b))
204 #define DATA3(f,a,b,c) ADDF((&easysrc_data, f,a,b,c))
205
206 #define CODE0(s) ADD((&easysrc_code, s))
207 #define CODE1(f,a) ADDF((&easysrc_code, f,a))
208 #define CODE2(f,a,b) ADDF((&easysrc_code, f,a,b))
209 #define CODE3(f,a,b,c) ADDF((&easysrc_code, f,a,b,c))
210
211 #define CLEAN0(s) ADD((&easysrc_clean, s))
212 #define CLEAN1(f,a) ADDF((&easysrc_clean, f,a))
213
214 #define REM0(s) ADD((&easysrc_toohard, s))
215 #define REM1(f,a) ADDF((&easysrc_toohard, f,a))
216 #define REM2(f,a,b) ADDF((&easysrc_toohard, f,a,b))
217
218 /* Escape string to C string syntax. Return NULL if out of memory.
219 * Is this correct for those wacky EBCDIC guys? */
220 static char *c_escape(const char *str, size_t len)
221 {
222 const char *s;
223 unsigned char c;
224 char *escaped, *e;
225
226 if(len == CURL_ZERO_TERMINATED)
227 len = strlen(str);
228
229 /* Check for possible overflow. */
230 if(len > (~(size_t) 0) / 4)
231 return NULL;
232
233 /* Allocate space based on worst-case */
234 escaped = malloc(4 * len + 1);
235 if(!escaped)
236 return NULL;
237
238 e = escaped;
239 for(s = str; (c = *s) != '\0'; s++) {
240 if(c == '\n') {
241 strcpy(e, "\\n");
242 e += 2;
243 }
244 else if(c == '\r') {
245 strcpy(e, "\\r");
246 e += 2;
247 }
248 else if(c == '\t') {
249 strcpy(e, "\\t");
250 e += 2;
251 }
252 else if(c == '\\') {
253 strcpy(e, "\\\\");
254 e += 2;
255 }
256 else if(c == '"') {
257 strcpy(e, "\\\"");
258 e += 2;
259 }
260 else if(! isprint(c)) {
261 msnprintf(e, 5, "\\%03o", (unsigned)c);
262 e += 4;
263 }
264 else
265 *e++ = c;
266 }
267 *e = '\0';
268 return escaped;
269 }
270
271 /* setopt wrapper for enum types */
272 CURLcode tool_setopt_enum(CURL *curl, struct GlobalConfig *config,
273 const char *name, CURLoption tag,
274 const NameValue *nvlist, long lval)
275 {
276 CURLcode ret = CURLE_OK;
277 bool skip = FALSE;
278
279 ret = curl_easy_setopt(curl, tag, lval);
280 if(!lval)
281 skip = TRUE;
282
283 if(config->libcurl && !skip && !ret) {
284 /* we only use this for real if --libcurl was used */
285 const NameValue *nv = NULL;
286 for(nv = nvlist; nv->name; nv++) {
287 if(nv->value == lval) break; /* found it */
288 }
289 if(! nv->name) {
290 /* If no definition was found, output an explicit value.
291 * This could happen if new values are defined and used
292 * but the NameValue list is not updated. */
293 CODE2("curl_easy_setopt(hnd, %s, %ldL);", name, lval);
294 }
295 else {
296 CODE2("curl_easy_setopt(hnd, %s, (long)%s);", name, nv->name);
297 }
298 }
299
300 nomem:
301 return ret;
302 }
303
304 /* setopt wrapper for flags */
305 CURLcode tool_setopt_flags(CURL *curl, struct GlobalConfig *config,
306 const char *name, CURLoption tag,
307 const NameValue *nvlist, long lval)
308 {
309 CURLcode ret = CURLE_OK;
310 bool skip = FALSE;
311
312 ret = curl_easy_setopt(curl, tag, lval);
313 if(!lval)
314 skip = TRUE;
315
316 if(config->libcurl && !skip && !ret) {
317 /* we only use this for real if --libcurl was used */
318 char preamble[80]; /* should accommodate any symbol name */
319 long rest = lval; /* bits not handled yet */
320 const NameValue *nv = NULL;
321 msnprintf(preamble, sizeof(preamble),
322 "curl_easy_setopt(hnd, %s, ", name);
323 for(nv = nvlist; nv->name; nv++) {
324 if((nv->value & ~ rest) == 0) {
325 /* all value flags contained in rest */
326 rest &= ~ nv->value; /* remove bits handled here */
327 CODE3("%s(long)%s%s",
328 preamble, nv->name, rest ? " |" : ");");
329 if(!rest)
330 break; /* handled them all */
331 /* replace with all spaces for continuation line */
332 msnprintf(preamble, sizeof(preamble), "%*s", strlen(preamble), "");
333 }
334 }
335 /* If any bits have no definition, output an explicit value.
336 * This could happen if new bits are defined and used
337 * but the NameValue list is not updated. */
338 if(rest)
339 CODE2("%s%ldL);", preamble, rest);
340 }
341
342 nomem:
343 return ret;
344 }
345
346 /* setopt wrapper for bitmasks */
347 CURLcode tool_setopt_bitmask(CURL *curl, struct GlobalConfig *config,
348 const char *name, CURLoption tag,
349 const NameValueUnsigned *nvlist,
350 long lval)
351 {
352 CURLcode ret = CURLE_OK;
353 bool skip = FALSE;
354
355 ret = curl_easy_setopt(curl, tag, lval);
356 if(!lval)
357 skip = TRUE;
358
359 if(config->libcurl && !skip && !ret) {
360 /* we only use this for real if --libcurl was used */
361 char preamble[80];
362 unsigned long rest = (unsigned long)lval;
363 const NameValueUnsigned *nv = NULL;
364 msnprintf(preamble, sizeof(preamble),
365 "curl_easy_setopt(hnd, %s, ", name);
366 for(nv = nvlist; nv->name; nv++) {
367 if((nv->value & ~ rest) == 0) {
368 /* all value flags contained in rest */
369 rest &= ~ nv->value; /* remove bits handled here */
370 CODE3("%s(long)%s%s",
371 preamble, nv->name, rest ? " |" : ");");
372 if(!rest)
373 break; /* handled them all */
374 /* replace with all spaces for continuation line */
375 msnprintf(preamble, sizeof(preamble), "%*s", strlen(preamble), "");
376 }
377 }
378 /* If any bits have no definition, output an explicit value.
379 * This could happen if new bits are defined and used
380 * but the NameValue list is not updated. */
381 if(rest)
382 CODE2("%s%luUL);", preamble, rest);
383 }
384
385 nomem:
386 return ret;
387 }
388
389 /* Generate code for a struct curl_slist. */
390 static CURLcode libcurl_generate_slist(struct curl_slist *slist, int *slistno)
391 {
392 CURLcode ret = CURLE_OK;
393 char *escaped = NULL;
394
395 /* May need several slist variables, so invent name */
396 *slistno = ++easysrc_slist_count;
397
398 DECL1("struct curl_slist *slist%d;", *slistno);
399 DATA1("slist%d = NULL;", *slistno);
400 CLEAN1("curl_slist_free_all(slist%d);", *slistno);
401 CLEAN1("slist%d = NULL;", *slistno);
402 for(; slist; slist = slist->next) {
403 Curl_safefree(escaped);
404 escaped = c_escape(slist->data, CURL_ZERO_TERMINATED);
405 if(!escaped)
406 return CURLE_OUT_OF_MEMORY;
407 DATA3("slist%d = curl_slist_append(slist%d, \"%s\");",
408 *slistno, *slistno, escaped);
409 }
410
411 nomem:
412 Curl_safefree(escaped);
413 return ret;
414 }
415
416 static CURLcode libcurl_generate_mime(CURL *curl,
417 struct GlobalConfig *config,
418 tool_mime *toolmime,
419 int *mimeno); /* Forward. */
420
421 /* Wrapper to generate source code for a mime part. */
422 static CURLcode libcurl_generate_mime_part(CURL *curl,
423 struct GlobalConfig *config,
424 tool_mime *part,
425 int mimeno)
426 {
427 CURLcode ret = CURLE_OK;
428 int submimeno = 0;
429 char *escaped = NULL;
430 const char *data = NULL;
431 const char *filename = part->filename;
432
433 /* Parts are linked in reverse order. */
434 if(part->prev) {
435 ret = libcurl_generate_mime_part(curl, config, part->prev, mimeno);
436 if(ret)
437 return ret;
438 }
439
440 /* Create the part. */
441 CODE2("part%d = curl_mime_addpart(mime%d);", mimeno, mimeno);
442
443 switch(part->kind) {
444 case TOOLMIME_PARTS:
445 ret = libcurl_generate_mime(curl, config, part, &submimeno);
446 if(!ret) {
447 CODE2("curl_mime_subparts(part%d, mime%d);", mimeno, submimeno);
448 CODE1("mime%d = NULL;", submimeno); /* Avoid freeing in CLEAN. */
449 }
450 break;
451
452 case TOOLMIME_DATA:
453 #ifdef CURL_DOES_CONVERSIONS
454 /* Data will be set in ASCII, thus issue a comment with clear text. */
455 escaped = c_escape(part->data, CURL_ZERO_TERMINATED);
456 NULL_CHECK(escaped);
457 CODE1("/* \"%s\" */", escaped);
458
459 /* Our data is always textual: convert it to ASCII. */
460 {
461 size_t size = strlen(part->data);
462 char *cp = malloc(size + 1);
463
464 NULL_CHECK(cp);
465 memcpy(cp, part->data, size + 1);
466 ret = convert_to_network(cp, size);
467 data = cp;
468 }
469 #else
470 data = part->data;
471 #endif
472 if(!ret) {
473 Curl_safefree(escaped);
474 escaped = c_escape(data, CURL_ZERO_TERMINATED);
475 NULL_CHECK(escaped);
476 CODE2("curl_mime_data(part%d, \"%s\", CURL_ZERO_TERMINATED);",
477 mimeno, escaped);
478 }
479 break;
480
481 case TOOLMIME_FILE:
482 case TOOLMIME_FILEDATA:
483 escaped = c_escape(part->data, CURL_ZERO_TERMINATED);
484 NULL_CHECK(escaped);
485 CODE2("curl_mime_filedata(part%d, \"%s\");", mimeno, escaped);
486 if(part->kind == TOOLMIME_FILEDATA && !filename) {
487 CODE1("curl_mime_filename(part%d, NULL);", mimeno);
488 }
489 break;
490
491 case TOOLMIME_STDIN:
492 if(!filename)
493 filename = "-";
494 /* FALLTHROUGH */
495 case TOOLMIME_STDINDATA:
496 /* Can only be reading stdin in the current context. */
497 CODE1("curl_mime_data_cb(part%d, -1, (curl_read_callback) fread, \\",
498 mimeno);
499 CODE0(" (curl_seek_callback) fseek, NULL, stdin);");
500 break;
501 default:
502 /* Other cases not possible in this context. */
503 break;
504 }
505
506 if(!ret && part->encoder) {
507 Curl_safefree(escaped);
508 escaped = c_escape(part->encoder, CURL_ZERO_TERMINATED);
509 NULL_CHECK(escaped);
510 CODE2("curl_mime_encoder(part%d, \"%s\");", mimeno, escaped);
511 }
512
513 if(!ret && filename) {
514 Curl_safefree(escaped);
515 escaped = c_escape(filename, CURL_ZERO_TERMINATED);
516 NULL_CHECK(escaped);
517 CODE2("curl_mime_filename(part%d, \"%s\");", mimeno, escaped);
518 }
519
520 if(!ret && part->name) {
521 Curl_safefree(escaped);
522 escaped = c_escape(part->name, CURL_ZERO_TERMINATED);
523 NULL_CHECK(escaped);
524 CODE2("curl_mime_name(part%d, \"%s\");", mimeno, escaped);
525 }
526
527 if(!ret && part->type) {
528 Curl_safefree(escaped);
529 escaped = c_escape(part->type, CURL_ZERO_TERMINATED);
530 NULL_CHECK(escaped);
531 CODE2("curl_mime_type(part%d, \"%s\");", mimeno, escaped);
532 }
533
534 if(!ret && part->headers) {
535 int slistno;
536
537 ret = libcurl_generate_slist(part->headers, &slistno);
538 if(!ret) {
539 CODE2("curl_mime_headers(part%d, slist%d, 1);", mimeno, slistno);
540 CODE1("slist%d = NULL;", slistno); /* Prevent CLEANing. */
541 }
542 }
543
544 nomem:
545 #ifdef CURL_DOES_CONVERSIONS
546 if(data)
547 free((char *) data);
548 #endif
549
550 Curl_safefree(escaped);
551 return ret;
552 }
553
554 /* Wrapper to generate source code for a mime structure. */
555 static CURLcode libcurl_generate_mime(CURL *curl,
556 struct GlobalConfig *config,
557 tool_mime *toolmime,
558 int *mimeno)
559 {
560 CURLcode ret = CURLE_OK;
561
562 /* May need several mime variables, so invent name. */
563 *mimeno = ++easysrc_mime_count;
564 DECL1("curl_mime *mime%d;", *mimeno);
565 DATA1("mime%d = NULL;", *mimeno);
566 CODE1("mime%d = curl_mime_init(hnd);", *mimeno);
567 CLEAN1("curl_mime_free(mime%d);", *mimeno);
568 CLEAN1("mime%d = NULL;", *mimeno);
569
570 if(toolmime->subparts) {
571 DECL1("curl_mimepart *part%d;", *mimeno);
572 ret = libcurl_generate_mime_part(curl, config,
573 toolmime->subparts, *mimeno);
574 }
575
576 nomem:
577 return ret;
578 }
579
580 /* setopt wrapper for CURLOPT_MIMEPOST */
581 CURLcode tool_setopt_mimepost(CURL *curl, struct GlobalConfig *config,
582 const char *name, CURLoption tag,
583 curl_mime *mimepost)
584 {
585 CURLcode ret = curl_easy_setopt(curl, tag, mimepost);
586 int mimeno = 0;
587
588 if(!ret && config->libcurl) {
589 ret = libcurl_generate_mime(curl, config,
590 config->current->mimeroot, &mimeno);
591
592 if(!ret)
593 CODE2("curl_easy_setopt(hnd, %s, mime%d);", name, mimeno);
594 }
595
596 nomem:
597 return ret;
598 }
599
600 /* setopt wrapper for curl_slist options */
601 CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *config,
602 const char *name, CURLoption tag,
603 struct curl_slist *list)
604 {
605 CURLcode ret = CURLE_OK;
606
607 ret = curl_easy_setopt(curl, tag, list);
608
609 if(config->libcurl && list && !ret) {
610 int i;
611
612 ret = libcurl_generate_slist(list, &i);
613 if(!ret)
614 CODE2("curl_easy_setopt(hnd, %s, slist%d);", name, i);
615 }
616
617 nomem:
618 return ret;
619 }
620
621 /* generic setopt wrapper for all other options.
622 * Some type information is encoded in the tag value. */
623 CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *config,
624 const char *name, CURLoption tag, ...)
625 {
626 va_list arg;
627 char buf[256];
628 const char *value = NULL;
629 bool remark = FALSE;
630 bool skip = FALSE;
631 bool escape = FALSE;
632 char *escaped = NULL;
633 CURLcode ret = CURLE_OK;
634
635 va_start(arg, tag);
636
637 if(tag < CURLOPTTYPE_OBJECTPOINT) {
638 /* Value is expected to be a long */
639 long lval = va_arg(arg, long);
640 long defval = 0L;
641 const NameValue *nv = NULL;
642 for(nv = setopt_nv_CURLNONZERODEFAULTS; nv->name; nv++) {
643 if(!strcmp(name, nv->name)) {
644 defval = nv->value;
645 break; /* found it */
646 }
647 }
648
649 msnprintf(buf, sizeof(buf), "%ldL", lval);
650 value = buf;
651 ret = curl_easy_setopt(curl, tag, lval);
652 if(lval == defval)
653 skip = TRUE;
654 }
655 else if(tag < CURLOPTTYPE_OFF_T) {
656 /* Value is some sort of object pointer */
657 void *pval = va_arg(arg, void *);
658
659 /* function pointers are never printable */
660 if(tag >= CURLOPTTYPE_FUNCTIONPOINT) {
661 if(pval) {
662 value = "functionpointer";
663 remark = TRUE;
664 }
665 else
666 skip = TRUE;
667 }
668
669 else if(pval && str) {
670 value = (char *)pval;
671 escape = TRUE;
672 }
673 else if(pval) {
674 value = "objectpointer";
675 remark = TRUE;
676 }
677 else
678 skip = TRUE;
679
680 ret = curl_easy_setopt(curl, tag, pval);
681
682 }
683 else {
684 /* Value is expected to be curl_off_t */
685 curl_off_t oval = va_arg(arg, curl_off_t);
686 msnprintf(buf, sizeof(buf),
687 "(curl_off_t)%" CURL_FORMAT_CURL_OFF_T, oval);
688 value = buf;
689 ret = curl_easy_setopt(curl, tag, oval);
690
691 if(!oval)
692 skip = TRUE;
693 }
694
695 va_end(arg);
696
697 if(config->libcurl && !skip && !ret) {
698 /* we only use this for real if --libcurl was used */
699
700 if(remark)
701 REM2("%s set to a %s", name, value);
702 else {
703 if(escape) {
704 escaped = c_escape(value, CURL_ZERO_TERMINATED);
705 NULL_CHECK(escaped);
706 CODE2("curl_easy_setopt(hnd, %s, \"%s\");", name, escaped);
707 }
708 else
709 CODE2("curl_easy_setopt(hnd, %s, %s);", name, value);
710 }
711 }
712
713 nomem:
714 Curl_safefree(escaped);
715 return ret;
716 }
717
718 #else /* CURL_DISABLE_LIBCURL_OPTION */
719
720 #include "tool_cfgable.h"
721 #include "tool_setopt.h"
722
723 #endif /* CURL_DISABLE_LIBCURL_OPTION */
724
725 /*
726 * tool_setopt_skip() allows the curl tool code to avoid setopt options that
727 * are explicitly disabled in the build.
728 */
729 bool tool_setopt_skip(CURLoption tag)
730 {
731 #ifdef CURL_DISABLE_PROXY
732 #define USED_TAG
733 switch(tag) {
734 case CURLOPT_HAPROXYPROTOCOL:
735 case CURLOPT_HTTPPROXYTUNNEL:
736 case CURLOPT_NOPROXY:
737 case CURLOPT_PRE_PROXY:
738 case CURLOPT_PROXY:
739 case CURLOPT_PROXYAUTH:
740 case CURLOPT_PROXY_CAINFO:
741 case CURLOPT_PROXY_CAPATH:
742 case CURLOPT_PROXY_CRLFILE:
743 case CURLOPT_PROXYHEADER:
744 case CURLOPT_PROXY_KEYPASSWD:
745 case CURLOPT_PROXYPASSWORD:
746 case CURLOPT_PROXY_PINNEDPUBLICKEY:
747 case CURLOPT_PROXYPORT:
748 case CURLOPT_PROXY_SERVICE_NAME:
749 case CURLOPT_PROXY_SSLCERT:
750 case CURLOPT_PROXY_SSLCERTTYPE:
751 case CURLOPT_PROXY_SSL_CIPHER_LIST:
752 case CURLOPT_PROXY_SSLKEY:
753 case CURLOPT_PROXY_SSLKEYTYPE:
754 case CURLOPT_PROXY_SSL_OPTIONS:
755 case CURLOPT_PROXY_SSL_VERIFYHOST:
756 case CURLOPT_PROXY_SSL_VERIFYPEER:
757 case CURLOPT_PROXY_SSLVERSION:
758 case CURLOPT_PROXY_TLS13_CIPHERS:
759 case CURLOPT_PROXY_TLSAUTH_PASSWORD:
760 case CURLOPT_PROXY_TLSAUTH_TYPE:
761 case CURLOPT_PROXY_TLSAUTH_USERNAME:
762 case CURLOPT_PROXY_TRANSFER_MODE:
763 case CURLOPT_PROXYTYPE:
764 case CURLOPT_PROXYUSERNAME:
765 case CURLOPT_PROXYUSERPWD:
766 return TRUE;
767 default:
768 break;
769 }
770 #endif
771 #ifdef CURL_DISABLE_FTP
772 #define USED_TAG
773 switch(tag) {
774 case CURLOPT_FTPPORT:
775 case CURLOPT_FTP_ACCOUNT:
776 case CURLOPT_FTP_ALTERNATIVE_TO_USER:
777 case CURLOPT_FTP_FILEMETHOD:
778 case CURLOPT_FTP_SKIP_PASV_IP:
779 case CURLOPT_FTP_USE_EPRT:
780 case CURLOPT_FTP_USE_EPSV:
781 case CURLOPT_FTP_USE_PRET:
782 case CURLOPT_KRBLEVEL:
783 return TRUE;
784 default:
785 break;
786 }
787 #endif
788 #ifdef CURL_DISABLE_RTSP
789 #define USED_TAG
790 switch(tag) {
791 case CURLOPT_INTERLEAVEDATA:
792 return TRUE;
793 default:
794 break;
795 }
796 #endif
797 #if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES)
798 #define USED_TAG
799 switch(tag) {
800 case CURLOPT_COOKIE:
801 case CURLOPT_COOKIEFILE:
802 case CURLOPT_COOKIEJAR:
803 case CURLOPT_COOKIESESSION:
804 return TRUE;
805 default:
806 break;
807 }
808 #endif
809 #if defined(CURL_DISABLE_TELNET)
810 #define USED_TAG
811 switch(tag) {
812 case CURLOPT_TELNETOPTIONS:
813 return TRUE;
814 default:
815 break;
816 }
817 #endif
818 #ifdef CURL_DISABLE_TFTP
819 #define USED_TAG
820 switch(tag) {
821 case CURLOPT_TFTP_BLKSIZE:
822 case CURLOPT_TFTP_NO_OPTIONS:
823 return TRUE;
824 default:
825 break;
826 }
827 #endif
828 #ifdef CURL_DISABLE_NETRC
829 #define USED_TAG
830 switch(tag) {
831 case CURLOPT_NETRC:
832 case CURLOPT_NETRC_FILE:
833 return TRUE;
834 default:
835 break;
836 }
837 #endif
838
839 #ifndef USED_TAG
840 (void)tag;
841 #endif
842 return FALSE;
843 }