master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "tool_setup.h"
26#include "tool_cfgable.h"
27#include "tool_easysrc.h"
28#include "tool_formparse.h"
29#include "tool_setopt.h"
31#ifndef CURL_DISABLE_LIBCURL_OPTION
33#include "tool_msgs.h"
35/* Lookup tables for converting setopt values back to symbols */
36/* For enums, values may be in any order. */
37/* For bit masks, put combinations first, then single bits, */
38/* and finally any "NONE" value. */
40#define NV(e) { #e, e }
41#define NV1(e, v) { #e, (v) }
42#define NVEND { NULL, 0 } /* sentinel to mark end of list */
44const struct NameValue setopt_nv_CURLPROXY[] = {
45 NV(CURLPROXY_HTTP),
46 NV(CURLPROXY_HTTP_1_0),
47 NV(CURLPROXY_HTTPS),
48 NV(CURLPROXY_SOCKS4),
49 NV(CURLPROXY_SOCKS5),
50 NV(CURLPROXY_SOCKS4A),
51 NV(CURLPROXY_SOCKS5_HOSTNAME),
52 NVEND,
53};
55const struct NameValue setopt_nv_CURL_SOCKS_PROXY[] = {
56 NV(CURLPROXY_SOCKS4),
57 NV(CURLPROXY_SOCKS5),
58 NV(CURLPROXY_SOCKS4A),
59 NV(CURLPROXY_SOCKS5_HOSTNAME),
60 NVEND,
61};
63const struct NameValueUnsigned setopt_nv_CURLHSTS[] = {
64 NV(CURLHSTS_ENABLE),
65 NVEND,
66};
68const struct NameValueUnsigned setopt_nv_CURLAUTH[] = {
69 NV(CURLAUTH_ANY), /* combination */
70 NV(CURLAUTH_ANYSAFE), /* combination */
71 NV(CURLAUTH_BASIC),
72 NV(CURLAUTH_DIGEST),
73 NV(CURLAUTH_GSSNEGOTIATE),
74 NV(CURLAUTH_NTLM),
75 NV(CURLAUTH_DIGEST_IE),
76 NV(CURLAUTH_ONLY),
77 NV(CURLAUTH_NONE),
78 NVEND,
79};
81const struct NameValue setopt_nv_CURL_HTTP_VERSION[] = {
82 NV(CURL_HTTP_VERSION_NONE),
83 NV(CURL_HTTP_VERSION_1_0),
84 NV(CURL_HTTP_VERSION_1_1),
85 NV(CURL_HTTP_VERSION_2_0),
86 NV(CURL_HTTP_VERSION_2TLS),
87 NV(CURL_HTTP_VERSION_3),
88 NV(CURL_HTTP_VERSION_3ONLY),
89 NVEND,
90};
92const struct NameValue setopt_nv_CURL_SSLVERSION[] = {
93 NV(CURL_SSLVERSION_DEFAULT),
94 NV(CURL_SSLVERSION_TLSv1),
95 NV(CURL_SSLVERSION_SSLv2),
96 NV(CURL_SSLVERSION_SSLv3),
97 NV(CURL_SSLVERSION_TLSv1_0),
98 NV(CURL_SSLVERSION_TLSv1_1),
99 NV(CURL_SSLVERSION_TLSv1_2),
100 NV(CURL_SSLVERSION_TLSv1_3),
101 NVEND,
102};
104const struct NameValue setopt_nv_CURL_SSLVERSION_MAX[] = {
105 { "", CURL_SSLVERSION_MAX_NONE },
106 NV(CURL_SSLVERSION_MAX_DEFAULT),
107 NV(CURL_SSLVERSION_MAX_TLSv1_0),
108 NV(CURL_SSLVERSION_MAX_TLSv1_1),
109 NV(CURL_SSLVERSION_MAX_TLSv1_2),
110 NV(CURL_SSLVERSION_MAX_TLSv1_3),
111 NVEND,
112};
114const struct NameValue setopt_nv_CURL_TIMECOND[] = {
115 NV(CURL_TIMECOND_IFMODSINCE),
116 NV(CURL_TIMECOND_IFUNMODSINCE),
117 NV(CURL_TIMECOND_LASTMOD),
118 NV(CURL_TIMECOND_NONE),
119 NVEND,
120};
122const struct NameValue setopt_nv_CURLFTPSSL_CCC[] = {
123 NV(CURLFTPSSL_CCC_NONE),
124 NV(CURLFTPSSL_CCC_PASSIVE),
125 NV(CURLFTPSSL_CCC_ACTIVE),
126 NVEND,
127};
129const struct NameValue setopt_nv_CURLUSESSL[] = {
130 NV(CURLUSESSL_NONE),
131 NV(CURLUSESSL_TRY),
132 NV(CURLUSESSL_CONTROL),
133 NV(CURLUSESSL_ALL),
134 NVEND,
135};
137const struct NameValueUnsigned setopt_nv_CURLSSLOPT[] = {
138 NV(CURLSSLOPT_ALLOW_BEAST),
139 NV(CURLSSLOPT_NO_REVOKE),
140 NV(CURLSSLOPT_NO_PARTIALCHAIN),
141 NV(CURLSSLOPT_REVOKE_BEST_EFFORT),
142 NV(CURLSSLOPT_NATIVE_CA),
143 NV(CURLSSLOPT_AUTO_CLIENT_CERT),
144 NVEND,
145};
147const struct NameValue setopt_nv_CURL_NETRC[] = {
148 NV(CURL_NETRC_IGNORED),
149 NV(CURL_NETRC_OPTIONAL),
150 NV(CURL_NETRC_REQUIRED),
151 NVEND,
152};
154const struct NameValue setopt_nv_CURLOPT_FOLLOWLOCATION[] = {
155 NV(0L),
156 NV(CURLFOLLOW_ALL),
157 NV(CURLFOLLOW_OBEYCODE),
158 NV(CURLFOLLOW_FIRSTONLY),
159 NVEND,
160};
162/* These options have non-zero default values. */
163static const struct NameValue setopt_nv_CURLNONZERODEFAULTS[] = {
164 NV1(CURLOPT_SSL_VERIFYPEER, 1),
165 NV1(CURLOPT_SSL_VERIFYHOST, 1),
166 NV1(CURLOPT_SSL_ENABLE_NPN, 1),
167 NV1(CURLOPT_SSL_ENABLE_ALPN, 1),
168 NV1(CURLOPT_TCP_NODELAY, 1),
169 NV1(CURLOPT_PROXY_SSL_VERIFYPEER, 1),
170 NV1(CURLOPT_PROXY_SSL_VERIFYHOST, 1),
171 NV1(CURLOPT_SOCKS5_AUTH, 1),
172 NV1(CURLOPT_UPLOAD_FLAGS, CURLULFLAG_SEEN),
173 NVEND
174};
176/* Escape string to C string syntax. Return NULL if out of memory. */
177#define MAX_STRING_LENGTH_OUTPUT 2000
178#define ZERO_TERMINATED (-1)
180static char *c_escape(const char *str, curl_off_t len)
181{
182 const char *s;
183 unsigned int cutoff = 0;
184 CURLcode result;
185 struct dynbuf escaped;
187 curlx_dyn_init(&escaped, (4 * MAX_STRING_LENGTH_OUTPUT) + 3);
189 if(len == ZERO_TERMINATED)
190 len = strlen(str);
192 if(len > MAX_STRING_LENGTH_OUTPUT) {
193 /* cap ridiculously long strings */
194 len = MAX_STRING_LENGTH_OUTPUT;
195 cutoff = 3;
196 }
198 result = curlx_dyn_addn(&escaped, STRCONST(""));
199 for(s = str; !result && len; s++, len--) {
200 /* escape question marks as well, to prevent generating accidental
201 trigraphs */
202 static const char from[] = "\t\r\n?\"\\";
203 static const char to[] = "\\t\\r\\n\\?\\\"\\\\";
204 const char *p = strchr(from, *s);
206 if(!p && ISPRINT(*s))
207 continue;
209 result = curlx_dyn_addn(&escaped, str, s - str);
210 str = s + 1;
212 if(!result) {
213 if(p && *p)
214 result = curlx_dyn_addn(&escaped, to + (2 * (p - from)), 2);
215 else {
216 result = curlx_dyn_addf(&escaped,
217 /* Octal escape to avoid >2 digit hex. */
218 (len > 1 && ISXDIGIT(s[1])) ?
219 "\\%03o" : "\\x%02x",
220 (unsigned int)*(const unsigned char *)s);
221 }
222 }
223 }
225 if(!result)
226 result = curlx_dyn_addn(&escaped, str, s - str);
228 if(!result)
229 result = curlx_dyn_addn(&escaped, "...", cutoff);
231 if(result)
232 return NULL;
233 return curlx_dyn_ptr(&escaped);
234}
236/* setopt wrapper for enum types */
237CURLcode tool_setopt_enum(CURL *curl, const char *name, CURLoption tag,
238 const struct NameValue *nvlist, long lval)
239{
240 CURLcode result = CURLE_OK;
241 bool skip = FALSE;
243 result = curl_easy_setopt(curl, tag, lval);
244 if(!lval)
245 skip = TRUE;
247 if(global->libcurl && !skip && !result) {
248 /* we only use this for real if --libcurl was used */
249 const struct NameValue *nv = NULL;
250 for(nv = nvlist; nv->name; nv++) {
251 if(nv->value == lval)
252 break; /* found it */
253 }
254 if(!nv->name) {
255 /* If no definition was found, output an explicit value.
256 * This could happen if new values are defined and used
257 * but the NameValue list is not updated. */
258 result = easysrc_addf(&easysrc_code, "curl_easy_setopt(curl, %s, %ldL);",
259 name, lval);
260 }
261 else
262 result =
263 easysrc_addf(&easysrc_code, "curl_easy_setopt(curl, %s, (long)%s);",
264 name, nv->name);
265 }
267#ifdef DEBUGBUILD
268 if(result)
269 warnf("option %s returned error (%d)", name, (int)result);
270#endif
271 return result;
272}
274/* setopt wrapper for CURLOPT_SSLVERSION */
275CURLcode tool_setopt_SSLVERSION(CURL *curl, const char *name, CURLoption tag,
276 long lval)
277{
278 CURLcode result = CURLE_OK;
279 bool skip = FALSE;
281 result = curl_easy_setopt(curl, tag, lval);
282 if(!lval)
283 skip = TRUE;
285 if(global->libcurl && !skip && !result) {
286 /* we only use this for real if --libcurl was used */
287 const struct NameValue *nv = NULL;
288 const struct NameValue *nv2 = NULL;
289 for(nv = setopt_nv_CURL_SSLVERSION; nv->name; nv++) {
290 if(nv->value == (lval & 0xffff))
291 break; /* found it */
292 }
293 for(nv2 = setopt_nv_CURL_SSLVERSION_MAX; nv2->name; nv2++) {
294 if(nv2->value == (lval & ~0xffff))
295 break; /* found it */
296 }
297 if(!nv->name) {
298 /* If no definition was found, output an explicit value.
299 * This could happen if new values are defined and used
300 * but the NameValue list is not updated. */
301 result = easysrc_addf(&easysrc_code, "curl_easy_setopt(curl, %s, %ldL);",
302 name, lval);
303 }
304 else {
305 if(nv2->name && *nv2->name)
306 /* if max is set */
307 result = easysrc_addf(&easysrc_code,
308 "curl_easy_setopt(curl, %s, (long)(%s | %s));",
309 name, nv->name, nv2->name);
310 else
311 /* without a max */
312 result = easysrc_addf(&easysrc_code,
313 "curl_easy_setopt(curl, %s, (long)%s);",
314 name, nv->name);
315 }
316 }
318#ifdef DEBUGBUILD
319 if(result)
320 warnf("option %s returned error (%d)", name, (int)result);
321#endif
322 return result;
323}
325/* setopt wrapper for bitmasks */
326CURLcode tool_setopt_bitmask(CURL *curl, const char *name, CURLoption tag,
327 const struct NameValueUnsigned *nvlist,
328 long lval)
329{
330 bool skip = FALSE;
331 CURLcode result = curl_easy_setopt(curl, tag, lval);
332 if(!lval)
333 skip = TRUE;
335 if(global->libcurl && !skip && !result) {
336 /* we only use this for real if --libcurl was used */
337 char preamble[80];
338 unsigned long rest = (unsigned long)lval;
339 const struct NameValueUnsigned *nv = NULL;
340 curl_msnprintf(preamble, sizeof(preamble),
341 "curl_easy_setopt(curl, %s, ", name);
342 for(nv = nvlist; nv->name; nv++) {
343 if((nv->value & ~rest) == 0) {
344 /* all value flags contained in rest */
345 rest &= ~nv->value; /* remove bits handled here */
346 result = easysrc_addf(&easysrc_code, "%s(long)%s%s",
347 preamble, nv->name, rest ? " |" : ");");
348 if(!rest || result)
349 break; /* handled them all */
350 /* replace with all spaces for continuation line */
351 curl_msnprintf(preamble, sizeof(preamble), "%*s",
352 (int)strlen(preamble), "");
353 }
354 }
355 /* If any bits have no definition, output an explicit value.
356 * This could happen if new bits are defined and used
357 * but the NameValue list is not updated. */
358 if(rest && !result)
359 result = easysrc_addf(&easysrc_code, "%s%luUL);", preamble, rest);
360 }
362 return result;
363}
365/* Generate code for a struct curl_slist. */
366static CURLcode libcurl_generate_slist(struct curl_slist *slist, int *slistno)
367{
368 CURLcode result = CURLE_OK;
370 /* May need several slist variables, so invent name */
371 *slistno = ++easysrc_slist_count;
373 result = easysrc_addf(&easysrc_decl, "struct curl_slist *slist%d;",
374 *slistno);
375 if(!result)
376 result = easysrc_addf(&easysrc_data, "slist%d = NULL;", *slistno);
377 if(!result)
378 result = easysrc_addf(&easysrc_clean, "curl_slist_free_all(slist%d);",
379 *slistno);
380 if(!result)
381 result = easysrc_addf(&easysrc_clean, "slist%d = NULL;", *slistno);
382 if(result)
383 return result;
384 for(; slist && !result; slist = slist->next) {
385 char *escaped = c_escape(slist->data, ZERO_TERMINATED);
386 if(!escaped)
387 return CURLE_OUT_OF_MEMORY;
388 result = easysrc_addf(&easysrc_data,
389 "slist%d = curl_slist_append(slist%d, \"%s\");",
390 *slistno, *slistno, escaped);
391 curlx_free(escaped);
392 }
394 return result;
395}
397static CURLcode libcurl_generate_mime(CURL *curl,
398 struct OperationConfig *config,
399 struct tool_mime *toolmime,
400 int *mimeno); /* Forward. */
402/* Wrapper to generate source code for a mime part. */
403static CURLcode libcurl_generate_mime_part(CURL *curl,
404 struct OperationConfig *config,
405 struct tool_mime *part,
406 int mimeno)
407{
408 CURLcode result = CURLE_OK;
409 int submimeno = 0;
410 const char *data = NULL;
411 const char *filename = part->filename;
412 char *escaped;
414 /* Parts are linked in reverse order. */
415 if(part->prev)
416 result = libcurl_generate_mime_part(curl, config, part->prev, mimeno);
418 /* Create the part. */
419 if(!result)
420 result = easysrc_addf(&easysrc_code, "part%d = curl_mime_addpart(mime%d);",
421 mimeno, mimeno);
422 if(result)
423 return result;
425 switch(part->kind) {
426 case TOOLMIME_PARTS:
427 result = libcurl_generate_mime(curl, config, part, &submimeno);
428 if(!result) {
429 result =
430 easysrc_addf(&easysrc_code, "curl_mime_subparts(part%d, mime%d);",
431 mimeno, submimeno);
432 if(!result)
433 /* Avoid freeing in CLEAN. */
434 result = easysrc_addf(&easysrc_code, "mime%d = NULL;", submimeno);
435 }
436 break;
438 case TOOLMIME_DATA:
439 data = part->data;
440 if(!result) {
441 escaped = c_escape(data, ZERO_TERMINATED);
442 if(!escaped)
443 return CURLE_OUT_OF_MEMORY;
444 result =
445 easysrc_addf(&easysrc_code,
446 "curl_mime_data(part%d, \"%s\", CURL_ZERO_TERMINATED);",
447 mimeno, escaped);
448 curlx_free(escaped);
449 }
450 break;
452 case TOOLMIME_FILE:
453 case TOOLMIME_FILEDATA:
454 escaped = c_escape(part->data, ZERO_TERMINATED);
455 if(!escaped)
456 return CURLE_OUT_OF_MEMORY;
457 result =
458 easysrc_addf(&easysrc_code,
459 "curl_mime_filedata(part%d, \"%s\");", mimeno, escaped);
460 if(part->kind == TOOLMIME_FILEDATA && !filename && !result) {
461 result = easysrc_addf(&easysrc_code,
462 "curl_mime_filename(part%d, NULL);", mimeno);
463 }
464 curlx_free(escaped);
465 break;
467 case TOOLMIME_STDIN:
468 if(!filename)
469 filename = "-";
470 FALLTHROUGH();
471 case TOOLMIME_STDINDATA:
472 /* Can only be reading stdin in the current context. */
473 result = easysrc_addf(&easysrc_code, "curl_mime_data_cb(part%d, -1, "
474 "(curl_read_callback)fread, \\", mimeno);
475 if(!result)
476 result = easysrc_addf(&easysrc_code, " "
477 "(curl_seek_callback)fseek, NULL, stdin);");
478 break;
479 default:
480 /* Other cases not possible in this context. */
481 break;
482 }
484 if(!result && part->encoder) {
485 escaped = c_escape(part->encoder, ZERO_TERMINATED);
486 if(!escaped)
487 return CURLE_OUT_OF_MEMORY;
488 result = easysrc_addf(&easysrc_code, "curl_mime_encoder(part%d, \"%s\");",
489 mimeno, escaped);
490 curlx_free(escaped);
491 }
493 if(!result && filename) {
494 escaped = c_escape(filename, ZERO_TERMINATED);
495 if(!escaped)
496 return CURLE_OUT_OF_MEMORY;
497 result = easysrc_addf(&easysrc_code, "curl_mime_filename(part%d, \"%s\");",
498 mimeno, escaped);
499 curlx_free(escaped);
500 }
502 if(!result && part->name) {
503 escaped = c_escape(part->name, ZERO_TERMINATED);
504 if(!escaped)
505 return CURLE_OUT_OF_MEMORY;
506 result = easysrc_addf(&easysrc_code, "curl_mime_name(part%d, \"%s\");",
507 mimeno, escaped);
508 curlx_free(escaped);
509 }
511 if(!result && part->type) {
512 escaped = c_escape(part->type, ZERO_TERMINATED);
513 if(!escaped)
514 return CURLE_OUT_OF_MEMORY;
515 result = easysrc_addf(&easysrc_code, "curl_mime_type(part%d, \"%s\");",
516 mimeno, escaped);
517 curlx_free(escaped);
518 }
520 if(!result && part->headers) {
521 int slistno;
523 result = libcurl_generate_slist(part->headers, &slistno);
524 if(!result) {
525 result = easysrc_addf(&easysrc_code,
526 "curl_mime_headers(part%d, slist%d, 1);",
527 mimeno, slistno);
528 if(!result)
529 result = easysrc_addf(&easysrc_code, "slist%d = NULL;", slistno);
530 }
531 }
533 return result;
534}
536/* Wrapper to generate source code for a mime structure. */
537static CURLcode libcurl_generate_mime(CURL *curl,
538 struct OperationConfig *config,
539 struct tool_mime *toolmime,
540 int *mimeno)
541{
542 CURLcode result = CURLE_OK;
544 /* May need several mime variables, so invent name. */
545 *mimeno = ++easysrc_mime_count;
546 result = easysrc_addf(&easysrc_decl, "curl_mime *mime%d;", *mimeno);
547 if(!result)
548 result = easysrc_addf(&easysrc_data, "mime%d = NULL;", *mimeno);
549 if(!result)
550 result = easysrc_addf(&easysrc_code, "mime%d = curl_mime_init(curl);",
551 *mimeno);
552 if(!result)
553 result = easysrc_addf(&easysrc_clean, "curl_mime_free(mime%d);", *mimeno);
554 if(!result)
555 result = easysrc_addf(&easysrc_clean, "mime%d = NULL;", *mimeno);
557 if(toolmime->subparts && !result) {
558 result = easysrc_addf(&easysrc_decl, "curl_mimepart *part%d;", *mimeno);
559 if(!result)
560 result = libcurl_generate_mime_part(curl, config,
561 toolmime->subparts, *mimeno);
562 }
564 return result;
565}
567/* setopt wrapper for CURLOPT_MIMEPOST */
568CURLcode tool_setopt_mimepost(CURL *curl, struct OperationConfig *config,
569 const char *name, CURLoption tag,
570 curl_mime *mimepost)
571{
572 CURLcode result = curl_easy_setopt(curl, tag, mimepost);
573 int mimeno = 0;
575 if(!result && global->libcurl) {
576 result = libcurl_generate_mime(curl, config, config->mimeroot, &mimeno);
578 if(!result)
579 result =
580 easysrc_addf(&easysrc_code, "curl_easy_setopt(curl, %s, mime%d);",
581 name, mimeno);
582 }
584 return result;
585}
587/* setopt wrapper for curl_slist options */
588CURLcode tool_setopt_slist(CURL *curl, const char *name, CURLoption tag,
589 struct curl_slist *list)
590{
591 CURLcode result = CURLE_OK;
593 result = curl_easy_setopt(curl, tag, list);
595 if(global->libcurl && list && !result) {
596 int i;
598 result = libcurl_generate_slist(list, &i);
599 if(!result)
600 result =
601 easysrc_addf(&easysrc_code, "curl_easy_setopt(curl, %s, slist%d);",
602 name, i);
603 }
605 return result;
606}
608/* options that set long */
609CURLcode tool_setopt_long(CURL *curl, const char *name, CURLoption tag,
610 long lval)
611{
612 CURLcode result = CURLE_OK;
613 DEBUGASSERT(tag < CURLOPTTYPE_OBJECTPOINT);
615 result = curl_easy_setopt(curl, tag, lval);
616 if(!result && global->libcurl) {
617 const struct NameValue *nv = NULL;
618 long defval = 0L;
619 /* we only use this for real if --libcurl was used */
620 for(nv = setopt_nv_CURLNONZERODEFAULTS; nv->name; nv++) {
621 if(!strcmp(name, nv->name)) {
622 defval = nv->value;
623 break; /* found it */
624 }
625 }
626 if(lval != defval) {
627 result = easysrc_addf(&easysrc_code, "curl_easy_setopt(curl, %s, %ldL);",
628 name, lval);
629 }
630 }
631 return result;
632}
634CURLcode tool_setopt_long_force(CURL *curl, const char *name, CURLoption tag,
635 long lval)
636{
637 CURLcode result = curl_easy_setopt(curl, tag, lval);
638 if(global->libcurl && !result && (!easysrc_is_first() || lval == 0))
639 result = easysrc_addf(&easysrc_code, "curl_easy_setopt(curl, %s, %ldL);",
640 name, lval);
641 return result;
642}
644/* options that set curl_off_t */
645CURLcode tool_setopt_offt(CURL *curl, const char *name, CURLoption tag,
646 curl_off_t lval)
647{
648 CURLcode result = CURLE_OK;
649 DEBUGASSERT((tag >= CURLOPTTYPE_OFF_T) && (tag < CURLOPTTYPE_BLOB));
651 result = curl_easy_setopt(curl, tag, lval);
652 if(global->libcurl && !result && lval) {
653 /* we only use this for real if --libcurl was used */
654 result =
655 easysrc_addf(&easysrc_code, "curl_easy_setopt(curl, %s, (curl_off_t)%"
656 CURL_FORMAT_CURL_OFF_T ");", name, lval);
657 }
659 return result;
660}
662/* setopt wrapper for setting object and function pointers */
663CURLcode tool_setopt_ptr(CURL *curl, const char *name, CURLoption tag, ...)
664{
665 void *pval;
666 va_list arg;
667 CURLcode result;
669 DEBUGASSERT(tag >= CURLOPTTYPE_OBJECTPOINT);
670 DEBUGASSERT((tag < CURLOPTTYPE_OFF_T) || (tag >= CURLOPTTYPE_BLOB));
671 /* we never set _BLOB options in the curl tool */
672 DEBUGASSERT(tag < CURLOPTTYPE_BLOB);
674 va_start(arg, tag);
675 /* argument is an object or function pointer */
676 pval = va_arg(arg, void *);
678 result = curl_easy_setopt(curl, tag, pval);
679 if(global->libcurl && pval && !result) {
680 /* we only use this if --libcurl was used */
681 const char *remark = (tag >= CURLOPTTYPE_FUNCTIONPOINT) ?
682 "function" : "object";
683 result = easysrc_addf(&easysrc_toohard,
684 "%s was set to a%s %s pointer", name,
685 (*remark == 'o' ? "n" : ""), remark);
686 }
688 va_end(arg);
689 return result;
690}
692/* setopt wrapper for setting strings */
693CURLcode tool_setopt_str(CURL *curl, struct OperationConfig *config,
694 const char *name, CURLoption tag,
695 const char *value)
696{
697 CURLcode result;
698 DEBUGASSERT(tag >= CURLOPTTYPE_OBJECTPOINT);
699 DEBUGASSERT((tag < CURLOPTTYPE_OFF_T) || (tag >= CURLOPTTYPE_BLOB));
700 DEBUGASSERT(tag < CURLOPTTYPE_BLOB);
701 DEBUGASSERT(tag < CURLOPTTYPE_FUNCTIONPOINT);
703 result = curl_easy_setopt(curl, tag, value);
704 if(global->libcurl && value && !result) {
705 /* we only use this if --libcurl was used */
706 curl_off_t len = ZERO_TERMINATED;
707 char *escaped;
708 if(tag == CURLOPT_POSTFIELDS)
709 len = curlx_dyn_len(&config->postdata);
710 escaped = c_escape(value, len);
711 if(escaped) {
712 result = easysrc_addf(&easysrc_code,
713 "curl_easy_setopt(curl, %s, \"%s\");",
714 name, escaped);
715 curlx_free(escaped);
716 }
717 else
718 result = CURLE_OUT_OF_MEMORY;
719 }
721 return result;
722}
724#endif /* CURL_DISABLE_LIBCURL_OPTION */
Diagnostics4 git calls · 188 ms
CallStatusSizeTime0188 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit20 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=20 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2005.5 KiB165 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=165 git.response.bytes=5651 git.response.cache=MISS git.response.duration_ms=165 git.fetch.wants=cd41d8d6b87afefaf83179db195f33a9a1e56cb7 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=5651 git.pkt.payload.max=5630 git.sideband.band1.bytes=5629 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e1acb29b542c38
- Request
- 47516490…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format