Artifactspublic-v0

curl

master
ply4 git calls26 ms298 KiB3 cachedprotocol v2
1518 lines39 KiBRaw
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "curl_setup.h"
26#include "curlx/dynbuf.h"
27#include "curl_printf.h"
28#include "curlx/strparse.h"
29#include "curlx/snprintf.h" /* for curlx_win32_snprintf() */
31#define BUFFSIZE 326 /* buffer for long-to-str and float-to-str calcs, should
32 fit negative DBL_MAX (317 letters) */
33#define MAX_PARAMETERS 128 /* number of input arguments */
34#define MAX_SEGMENTS 128 /* number of output segments */
36/* Lower-case digits. */
37const unsigned char Curl_ldigits[] = "0123456789abcdef";
39/* Upper-case digits. */
40const unsigned char Curl_udigits[] = "0123456789ABCDEF";
42#define OUTCHAR(x) \
43 do { \
44 if(stream((unsigned char)(x), userp)) \
45 return TRUE; \
46 (*donep)++; \
47 } while(0)
49/* Data type to read from the arglist */
50typedef enum {
51 MTYPE_STRING,
52 MTYPE_PTR,
53 MTYPE_INTPTR,
54 MTYPE_INT,
55 MTYPE_LONG,
56 MTYPE_LONGLONG,
57 MTYPE_INTU,
58 MTYPE_LONGU,
59 MTYPE_LONGLONGU,
60 MTYPE_DOUBLE,
61 MTYPE_LONGDOUBLE,
62 MTYPE_WIDTH,
63 MTYPE_PRECISION
64} FormatType;
66/* conversion and display flags */
67enum {
68 FLAGS_SPACE = 1 << 0,
69 FLAGS_SHOWSIGN = 1 << 1,
70 FLAGS_LEFT = 1 << 2,
71 FLAGS_ALT = 1 << 3,
72 FLAGS_SHORT = 1 << 4,
73 FLAGS_LONG = 1 << 5,
74 FLAGS_LONGLONG = 1 << 6,
75 FLAGS_LONGDOUBLE = 1 << 7,
76 FLAGS_PAD_NIL = 1 << 8,
77 FLAGS_UNSIGNED = 1 << 9,
78 FLAGS_OCTAL = 1 << 10,
79 FLAGS_HEX = 1 << 11,
80 FLAGS_UPPER = 1 << 12,
81 FLAGS_WIDTH = 1 << 13, /* '*' or '*<num>$' used */
82 FLAGS_WIDTHPARAM = 1 << 14, /* width PARAMETER was specified */
83 FLAGS_PREC = 1 << 15, /* precision was specified */
84 FLAGS_PRECPARAM = 1 << 16, /* precision PARAMETER was specified */
85 FLAGS_CHAR = 1 << 17, /* %c story */
86 FLAGS_FLOATE = 1 << 18, /* %e or %E */
87 FLAGS_FLOATG = 1 << 19, /* %g or %G */
88 FLAGS_SUBSTR = 1 << 20 /* no input, only substring */
89};
91enum {
92 DOLLAR_UNKNOWN,
93 DOLLAR_NOPE,
94 DOLLAR_USE
95};
97/*
98 * Describes an input va_arg type and hold its value.
99 */
100struct va_input {
101 FormatType type; /* FormatType */
102 union {
103 const char *str;
104 void *ptr;
105 int64_t nums; /* signed */
106 uint64_t numu; /* unsigned */
107 double dnum;
108 } val;
109};
111/*
112 * Describes an output segment.
113 */
114struct outsegment {
115 int width; /* width OR width parameter number */
116 int precision; /* precision OR precision parameter number */
117 unsigned int flags;
118 unsigned int input; /* input argument array index */
119 const char *start; /* format string start to output */
120 size_t outlen; /* number of bytes from the format string to output */
121};
123struct nsprintf {
124 char *buffer;
125 size_t length;
126 size_t max;
127};
129/* Output bytes are staged here and appended to the dynbuf in chunks: the
130 dynbuf append overhead (bounds checks, growth, memcpy, null-termination)
131 once per byte dominates formatting. 512 bytes of stack holds a typical
132 request line or header in a single flush. */
133#define ASPRINTF_STAGE_SIZE 512
135struct asprintf {
136 struct dynbuf *b;
137 char merr;
138 size_t nstage;
139 unsigned char stage[ASPRINTF_STAGE_SIZE];
140};
142struct ioprintf {
143 FILE *fd;
144 bool error;
145};
147/* the provided input number is 1-based but this returns the number 0-based.
148 *
149 * returns -1 if no valid number was provided.
150 */
151static int dollarstring(const char *p, const char **end)
153 curl_off_t num;
154 if(curlx_str_number(&p, &num, MAX_PARAMETERS) ||
155 curlx_str_single(&p, '$') || !num)
156 return -1;
157 *end = p;
158 return (int)num - 1;
161#define is_arg_used(x, y) ((x)[(y) / 8] & (1 << ((y) & 7)))
162#define mark_arg_used(x, y) ((x)[(y) / 8] |= (unsigned char)(1 << ((y) & 7)))
164/*
165 * Parse the format string.
166 *
167 * Create two arrays. One describes the inputs, one describes the outputs.
168 *
169 * Returns zero on success.
170 */
172#define PFMT_OK 0
173#define PFMT_DOLLAR 1 /* bad dollar for main param */
174#define PFMT_DOLLARWIDTH 2 /* bad dollar use for width */
175#define PFMT_DOLLARPREC 3 /* bad dollar use for precision */
176#define PFMT_MANYARGS 4 /* too many input arguments used */
177#define PFMT_PREC 5 /* precision overflow */
178#define PFMT_PRECMIX 6 /* bad mix of precision specifiers */
179#define PFMT_WIDTH 7 /* width overflow */
180#define PFMT_INPUTGAP 8 /* gap in arguments */
181#define PFMT_WIDTHARG 9 /* attempted to use same arg twice, for width */
182#define PFMT_PRECARG 10 /* attempted to use same arg twice, for prec */
183#define PFMT_MANYSEGS 11 /* maxed out output segments */
185static int parse_flags(const char **fmtp, unsigned int *flagsp, int use_dollar,
186 int *precp, int *widthp)
188 const char *fmt = *fmtp;
189 bool loopit = TRUE;
190 unsigned int flags = 0;
191 int width = 0;
192 int precision = 0;
194 /* Handle the flags */
195 do {
196 switch(*fmt++) {
197 case ' ':
198 flags |= FLAGS_SPACE;
199 break;
200 case '+':
201 flags |= FLAGS_SHOWSIGN;
202 break;
203 case '-':
204 flags |= FLAGS_LEFT;
205 flags &= ~(unsigned int)FLAGS_PAD_NIL;
206 break;
207 case '#':
208 flags |= FLAGS_ALT;
209 break;
210 case '.':
211 if('*' == *fmt) {
212 /* The precision is picked from a specified parameter */
213 flags |= FLAGS_PRECPARAM;
214 fmt++;
216 if(use_dollar == DOLLAR_USE) {
217 precision = dollarstring(fmt, &fmt);
218 if(precision < 0)
219 /* illegal combo */
220 return PFMT_DOLLARPREC;
221 }
222 else
223 /* get it from the next argument */
224 precision = -1;
225 }
226 else {
227 bool is_neg;
228 curl_off_t num;
229 flags |= FLAGS_PREC;
230 is_neg = ('-' == *fmt);
231 if(is_neg)
232 fmt++;
233 if(curlx_str_number(&fmt, &num, INT_MAX))
234 return PFMT_PREC;
235 precision = (int)num;
236 if(is_neg)
237 precision = -precision;
238 }
239 if((flags & (FLAGS_PREC | FLAGS_PRECPARAM)) ==
240 (FLAGS_PREC | FLAGS_PRECPARAM))
241 /* it is not permitted to use both kinds of precision for the same
242 argument */
243 return PFMT_PRECMIX;
244 break;
245 case 'h':
246 flags |= FLAGS_SHORT;
247 break;
248#ifdef _WIN32
249 case 'I':
250 /* Non-ANSI integer extensions I32 I64 */
251 if((fmt[0] == '3') && (fmt[1] == '2')) {
252 flags |= FLAGS_LONG;
253 fmt += 2;
254 }
255 else if((fmt[0] == '6') && (fmt[1] == '4')) {
256 flags |= FLAGS_LONGLONG;
257 fmt += 2;
258 }
259 else {
260#if SIZEOF_SIZE_T > SIZEOF_LONG
261 flags |= FLAGS_LONGLONG;
262#else
263 flags |= FLAGS_LONG;
264#endif
265 }
266 break;
267#endif /* _WIN32 */
268 case 'l':
269 if(flags & FLAGS_LONG)
270 flags |= FLAGS_LONGLONG;
271 else
272 flags |= FLAGS_LONG;
273 break;
274 case 'L':
275 flags |= FLAGS_LONGDOUBLE;
276 break;
277 case 'q':
278 flags |= FLAGS_LONGLONG;
279 break;
280 case 'z':
281 /* the code below generates a warning if -Wunreachable-code is
282 used */
283#if SIZEOF_SIZE_T > SIZEOF_LONG
284 flags |= FLAGS_LONGLONG;
285#else
286 flags |= FLAGS_LONG;
287#endif
288 break;
289 case 'O':
290#if SIZEOF_CURL_OFF_T > SIZEOF_LONG
291 flags |= FLAGS_LONGLONG;
292#else
293 flags |= FLAGS_LONG;
294#endif
295 break;
296 case '0':
297 if(!(flags & FLAGS_LEFT))
298 flags |= FLAGS_PAD_NIL;
299 FALLTHROUGH();
300 case '1':
301 case '2':
302 case '3':
303 case '4':
304 case '5':
305 case '6':
306 case '7':
307 case '8':
308 case '9': {
309 curl_off_t num;
310 flags |= FLAGS_WIDTH;
311 fmt--;
312 if(curlx_str_number(&fmt, &num, INT_MAX))
313 return PFMT_WIDTH;
314 width = (int)num;
315 break;
316 }
317 case '*': /* read width from argument list */
318 flags |= FLAGS_WIDTHPARAM;
319 if(use_dollar == DOLLAR_USE) {
320 width = dollarstring(fmt, &fmt);
321 if(width < 0)
322 /* illegal combo */
323 return PFMT_DOLLARWIDTH;
324 }
325 else
326 /* pick from the next argument */
327 width = -1;
328 break;
329 default:
330 loopit = FALSE;
331 fmt--;
332 break;
333 } /* switch */
334 } while(loopit); /* do */
335 *flagsp = flags;
336 *precp = precision;
337 *widthp = width;
338 *fmtp = fmt;
339 return PFMT_OK;
342static bool parse_conversion(const char f, unsigned int *flagp,
343 FormatType *typep)
345 unsigned int flags = *flagp;
346 FormatType type;
347 switch(f) {
348 case 'S':
349 flags |= FLAGS_ALT;
350 type = MTYPE_STRING;
351 break;
352 case 's':
353 type = MTYPE_STRING;
354 break;
355 case 'n':
356 type = MTYPE_INTPTR;
357 break;
358 case 'p':
359 type = MTYPE_PTR;
360 break;
361 case 'd':
362 case 'i':
363 if(flags & FLAGS_LONGLONG)
364 type = MTYPE_LONGLONG;
365 else if(flags & FLAGS_LONG)
366 type = MTYPE_LONG;
367 else
368 type = MTYPE_INT;
369 break;
370 case 'u':
371 if(flags & FLAGS_LONGLONG)
372 type = MTYPE_LONGLONGU;
373 else if(flags & FLAGS_LONG)
374 type = MTYPE_LONGU;
375 else
376 type = MTYPE_INTU;
377 flags |= FLAGS_UNSIGNED;
378 break;
379 case 'o':
380 if(flags & FLAGS_LONGLONG)
381 type = MTYPE_LONGLONGU;
382 else if(flags & FLAGS_LONG)
383 type = MTYPE_LONGU;
384 else
385 type = MTYPE_INTU;
386 flags |= FLAGS_OCTAL | FLAGS_UNSIGNED;
387 break;
388 case 'x':
389 if(flags & FLAGS_LONGLONG)
390 type = MTYPE_LONGLONGU;
391 else if(flags & FLAGS_LONG)
392 type = MTYPE_LONGU;
393 else
394 type = MTYPE_INTU;
395 flags |= FLAGS_HEX | FLAGS_UNSIGNED;
396 break;
397 case 'X':
398 if(flags & FLAGS_LONGLONG)
399 type = MTYPE_LONGLONGU;
400 else if(flags & FLAGS_LONG)
401 type = MTYPE_LONGU;
402 else
403 type = MTYPE_INTU;
404 flags |= FLAGS_HEX | FLAGS_UPPER | FLAGS_UNSIGNED;
405 break;
406 case 'c':
407 type = MTYPE_INT;
408 flags |= FLAGS_CHAR;
409 break;
410 case 'f':
411 type = flags & FLAGS_LONGDOUBLE ? MTYPE_LONGDOUBLE : MTYPE_DOUBLE;
412 break;
413 case 'F':
414 type = flags & FLAGS_LONGDOUBLE ? MTYPE_LONGDOUBLE : MTYPE_DOUBLE;
415 flags |= FLAGS_UPPER;
416 break;
417 case 'e':
418 type = flags & FLAGS_LONGDOUBLE ? MTYPE_LONGDOUBLE : MTYPE_DOUBLE;
419 flags |= FLAGS_FLOATE;
420 break;
421 case 'E':
422 type = flags & FLAGS_LONGDOUBLE ? MTYPE_LONGDOUBLE : MTYPE_DOUBLE;
423 flags |= FLAGS_FLOATE | FLAGS_UPPER;
424 break;
425 case 'g':
426 type = flags & FLAGS_LONGDOUBLE ? MTYPE_LONGDOUBLE : MTYPE_DOUBLE;
427 flags |= FLAGS_FLOATG;
428 break;
429 case 'G':
430 type = flags & FLAGS_LONGDOUBLE ? MTYPE_LONGDOUBLE : MTYPE_DOUBLE;
431 flags |= FLAGS_FLOATG | FLAGS_UPPER;
432 break;
433 default:
434 /* invalid instruction, disregard and continue */
435 return TRUE;
436 } /* switch */
438 *flagp |= flags;
439 *typep = type;
440 return FALSE;
443static int parsefmt(const char *format,
444 struct outsegment *out,
445 struct va_input *in,
446 int *opieces,
447 int *ipieces, va_list arglist)
449 const char *fmt = format;
450 int param_num = 0;
451 int max_param = -1;
452 int i;
453 int ocount = 0;
454 unsigned char usedinput[MAX_PARAMETERS / 8];
455 size_t outlen = 0;
456 struct outsegment *optr;
457 int use_dollar = DOLLAR_UNKNOWN;
458 const char *start = fmt;
460 /* clear, set a bit for each used input */
461 memset(usedinput, 0, sizeof(usedinput));
463 while(*fmt) {
464 if(*fmt == '%') {
465 struct va_input *iptr;
466 FormatType type;
467 unsigned int flags = 0;
468 int width = 0;
469 int precision = 0;
470 int param = -1;
471 int rc;
472 fmt++;
473 outlen = (size_t)(fmt - start - 1);
474 if(*fmt == '%') {
475 /* this means a %% that should be output only as %. Create an output
476 segment. */
477 if(outlen) {
478 optr = &out[ocount++];
479 if(ocount > MAX_SEGMENTS)
480 return PFMT_MANYSEGS;
481 optr->input = 0;
482 optr->flags = FLAGS_SUBSTR;
483 optr->start = start;
484 optr->outlen = outlen;
485 }
486 start = fmt;
487 fmt++;
488 continue; /* while */
489 }
491 if(use_dollar != DOLLAR_NOPE) {
492 param = dollarstring(fmt, &fmt);
493 if(param < 0) {
494 if(use_dollar == DOLLAR_USE)
495 /* illegal combo */
496 return PFMT_DOLLAR;
498 /* we got no positional, get the next arg */
499 param = -1;
500 use_dollar = DOLLAR_NOPE;
501 }
502 else
503 use_dollar = DOLLAR_USE;
504 }
506 rc = parse_flags(&fmt, &flags, use_dollar, &precision, &width);
507 if(rc)
508 return rc;
510 if(parse_conversion(*fmt, &flags, &type))
511 continue;
513 if(flags & FLAGS_WIDTHPARAM) {
514 if(width < 0)
515 width = param_num++;
516 else {
517 /* if this identifies a parameter already used, this is illegal */
518 if(is_arg_used(usedinput, width))
519 return PFMT_WIDTHARG;
520 }
521 if(width >= MAX_PARAMETERS)
522 return PFMT_MANYARGS;
523 if(width >= max_param)
524 max_param = width;
526 in[width].type = MTYPE_WIDTH;
527 /* mark as used */
528 mark_arg_used(usedinput, width);
529 }
531 if(flags & FLAGS_PRECPARAM) {
532 if(precision < 0)
533 precision = param_num++;
534 else {
535 /* if this identifies a parameter already used, this is illegal */
536 if(is_arg_used(usedinput, precision))
537 return PFMT_PRECARG;
538 }
539 if(precision >= MAX_PARAMETERS)
540 return PFMT_MANYARGS;
541 if(precision >= max_param)
542 max_param = precision;
544 in[precision].type = MTYPE_PRECISION;
545 mark_arg_used(usedinput, precision);
546 }
548 /* Handle the specifier */
549 if(param < 0)
550 param = param_num++;
551 if(param >= MAX_PARAMETERS)
552 return PFMT_MANYARGS;
553 if(param >= max_param)
554 max_param = param;
556 iptr = &in[param];
557 iptr->type = type;
559 /* mark this input as used */
560 mark_arg_used(usedinput, param);
562 fmt++;
563 optr = &out[ocount++];
564 if(ocount > MAX_SEGMENTS)
565 return PFMT_MANYSEGS;
566 optr->input = (unsigned int)param;
567 optr->flags = flags;
568 optr->width = width;
569 optr->precision = precision;
570 optr->start = start;
571 optr->outlen = outlen;
572 start = fmt;
573 }
574 else
575 fmt++;
576 }
578 /* is there a trailing piece */
579 outlen = (size_t)(fmt - start);
580 if(outlen) {
581 optr = &out[ocount++];
582 if(ocount > MAX_SEGMENTS)
583 return PFMT_MANYSEGS;
584 optr->input = 0;
585 optr->flags = FLAGS_SUBSTR;
586 optr->start = start;
587 optr->outlen = outlen;
588 }
590 /* Read the arg list parameters into our data list */
591 for(i = 0; i < max_param + 1; i++) {
592 struct va_input *iptr = &in[i];
593 if(!is_arg_used(usedinput, i))
594 /* bad input */
595 return PFMT_INPUTGAP;
597 /* based on the type, read the correct argument */
598 switch(iptr->type) {
599 case MTYPE_STRING:
600 iptr->val.str = va_arg(arglist, const char *);
601 break;
603 case MTYPE_INTPTR:
604 case MTYPE_PTR:
605 iptr->val.ptr = va_arg(arglist, void *);
606 break;
608 case MTYPE_LONGLONGU:
609 iptr->val.numu = va_arg(arglist, uint64_t);
610 break;
612 case MTYPE_LONGLONG:
613 iptr->val.nums = va_arg(arglist, int64_t);
614 break;
616 case MTYPE_LONGU:
617 iptr->val.numu = va_arg(arglist, unsigned long);
618 break;
620 case MTYPE_LONG:
621 iptr->val.nums = va_arg(arglist, long);
622 break;
624 case MTYPE_INTU:
625 iptr->val.numu = va_arg(arglist, unsigned int);
626 break;
628 case MTYPE_INT:
629 case MTYPE_WIDTH:
630 case MTYPE_PRECISION:
631 iptr->val.nums = va_arg(arglist, int);
632 break;
634 case MTYPE_DOUBLE:
635 iptr->val.dnum = va_arg(arglist, double);
636 break;
638 case MTYPE_LONGDOUBLE:
639 iptr->val.dnum = (double)va_arg(arglist, long double);
640 break;
642 default:
643 DEBUGASSERT(NULL); /* unexpected */
644 break;
645 }
646 }
647 *ipieces = max_param + 1;
648 *opieces = ocount;
650 return PFMT_OK;
653struct mproperty {
654 int width; /* Width of a field. */
655 int prec; /* Precision of a field. */
656 unsigned int flags;
657};
659/* block output callback: consume up to 'len' bytes, return the number of
660 bytes accepted. Accepting fewer than 'len' bytes aborts formatting, like
661 the byte callback returning failure. May be NULL, in which case output
662 falls back to the per-byte 'stream' callback. */
663typedef size_t (*mp_streamn)(const unsigned char *buf, size_t len, void *f);
665/* commit any output the sink is holding. Returns non-zero on failure. Sinks
666 whose accepted bytes are already committed do not need one. */
667typedef int (*mp_flush)(void *f);
669/* emit a run of bytes through the block callback when available, else byte
670 by byte. Returns TRUE to abort formatting (mirroring OUTCHAR). */
671static bool stream_run(void *userp,
672 int (*stream)(unsigned char, void *),
673 mp_streamn streamn,
674 const unsigned char *buf, size_t len, int *donep)
676 if(!len)
677 return FALSE;
678 if(streamn) {
679 size_t n = streamn(buf, len, userp);
680 *donep += (int)n;
681 return n != len;
682 }
683 while(len--) {
684 if(stream(*buf++, userp))
685 return TRUE;
686 (*donep)++;
687 }
688 return FALSE;
691/* Padding is always spaces or zeros, so it comes from a constant rather than a
692 buffer that has to be filled first. 16 keeps every width used in the tree to
693 a single run; wider padding loops. */
694static const char pad_spaces[] = " ";
695static const char pad_zeros[] = "0000000000000000";
696#define PAD_RUN 16 /* strlen() of both of the above */
698/* emit 'num' copies of the pad byte. Returns TRUE to abort formatting. */
699static bool stream_pad(void *userp,
700 int (*stream)(unsigned char, void *),
701 mp_streamn streamn,
702 unsigned char pad, int num, int *donep)
704 const unsigned char *src;
705 if(num <= 0)
706 return FALSE;
707 if(pad == '0')
708 src = (const unsigned char *)pad_zeros;
709 else
710 src = (const unsigned char *)pad_spaces;
711 while(num > PAD_RUN) {
712 if(stream_run(userp, stream, streamn, src, PAD_RUN, donep))
713 return TRUE;
714 num -= PAD_RUN;
715 }
716 return stream_run(userp, stream, streamn, src, (size_t)num, donep);
719/* emit the leading null-terminated part of a run of at most 'len' bytes.
720 Returns TRUE to abort formatting.
722 A byte loop and not memchr(): 'len' is the requested precision, which
723 out_string() does not clamp to the string length, so "%.64s" on a 10-byte
724 string arrives with len == 64 and memchr() would read past the object. */
725static bool stream_zrun(void *userp,
726 int (*stream)(unsigned char, void *),
727 mp_streamn streamn,
728 const char *str, size_t len, int *donep)
730 size_t n = 0;
731 while(n < len && str[n])
732 n++;
733 return stream_run(userp, stream, streamn,
734 (const unsigned char *)str, n, donep);
737static bool out_double(void *userp,
738 int (*stream)(unsigned char, void *),
739 mp_streamn streamn,
740 struct mproperty *p,
741 double dnum,
742 char *work, int *donep)
744 char fmt[32] = "%";
745 char *fptr = &fmt[1];
746 size_t left = sizeof(fmt) - strlen(fmt);
747 int flags = p->flags;
748 int width = p->width;
749 int prec = p->prec;
751 if(flags & FLAGS_LEFT)
752 *fptr++ = '-';
753 if(flags & FLAGS_SHOWSIGN)
754 *fptr++ = '+';
755 if(flags & FLAGS_SPACE)
756 *fptr++ = ' ';
757 if(flags & FLAGS_ALT)
758 *fptr++ = '#';
760 *fptr = 0;
762 if(width >= 0) {
763 size_t dlen;
764 if(width >= BUFFSIZE)
765 width = BUFFSIZE - 1;
766 /* RECURSIVE USAGE */
767 dlen = (size_t)curl_msnprintf(fptr, left, "%d", width);
768 fptr += dlen;
769 left -= dlen;
770 }
771 if(prec >= 0) {
772 /* for each digit in the integer part, we can have one less
773 precision */
774 int maxprec = BUFFSIZE - 1;
775 double val = dnum;
776 int len;
777 if(prec > maxprec)
778 prec = maxprec - 1;
779 if(width > 0 && prec <= width)
780 maxprec -= width;
781 while(maxprec && (val >= 10.0)) {
782 val /= 10;
783 maxprec--;
784 }
786 if(prec > maxprec)
787 prec = maxprec - 1;
788 if(prec < 0)
789 prec = 0;
790 /* RECURSIVE USAGE */
791 len = curl_msnprintf(fptr, left, ".%d", prec);
792 fptr += len;
793 }
794 if(flags & FLAGS_LONG)
795 *fptr++ = 'l';
797 if(flags & FLAGS_FLOATE)
798 *fptr++ = (char)((flags & FLAGS_UPPER) ? 'E' : 'e');
799 else if(flags & FLAGS_FLOATG)
800 *fptr++ = (char)((flags & FLAGS_UPPER) ? 'G' : 'g');
801 else
802 *fptr++ = (flags & FLAGS_UPPER) ? 'F' : 'f';
804 *fptr = 0; /* and a final null-termination */
806 /* NOTE NOTE NOTE!! Not all sprintf implementations return number of
807 output characters */
808#ifdef CURL_HAVE_DIAG
809#pragma GCC diagnostic push
810#pragma GCC diagnostic ignored "-Wformat-nonliteral"
811#endif
812#ifdef _WIN32
813 curlx_win32_snprintf(work, BUFFSIZE, fmt, dnum);
814#else
815 /* !checksrc! disable BANNEDFUNC 1 */
816 snprintf(work, BUFFSIZE, fmt, dnum);
817#endif
818#ifdef CURL_HAVE_DIAG
819#pragma GCC diagnostic pop
820#endif
821 DEBUGASSERT(strlen(work) < BUFFSIZE);
822 return stream_run(userp, stream, streamn,
823 (const unsigned char *)work, strlen(work), donep);
826static bool out_number(void *userp,
827 int (*stream)(unsigned char, void *),
828 mp_streamn streamn,
829 struct mproperty *p,
830 uint64_t num,
831 int64_t nums,
832 char *work, int *donep)
834 const unsigned char *digits = Curl_ldigits;
835 int flags = p->flags;
836 int width = p->width;
837 int prec = p->prec;
838 bool is_alt = flags & FLAGS_ALT;
839 bool is_neg = FALSE;
840 int base = 10;
842 /* 'workend' points to the final buffer byte position, but with an extra
843 byte as margin to avoid the (FALSE?) warning Coverity gives us
844 otherwise */
845 char *workend = &work[BUFFSIZE - 2];
846 char *w;
848 if(flags & FLAGS_CHAR) {
849 /* Character. */
850 if(!(flags & FLAGS_LEFT)) {
851 if(stream_pad(userp, stream, streamn, ' ', width - 1, donep))
852 return TRUE;
853 width = 1;
854 }
855 OUTCHAR((char)num);
856 if(flags & FLAGS_LEFT) {
857 if(stream_pad(userp, stream, streamn, ' ', width - 1, donep))
858 return TRUE;
859 }
860 return FALSE;
861 }
862 if(flags & FLAGS_OCTAL)
863 /* Octal unsigned integer */
864 base = 8;
866 else if(flags & FLAGS_HEX) {
867 /* Hexadecimal unsigned integer */
868 digits = (flags & FLAGS_UPPER) ? Curl_udigits : Curl_ldigits;
869 base = 16;
870 }
871 else if(flags & FLAGS_UNSIGNED)
872 /* Decimal unsigned integer */
873 ;
875 else {
876 /* Decimal integer. */
877 is_neg = (nums < 0);
878 if(is_neg) {
879 /* signed_num might fail to hold absolute negative minimum by 1 */
880 int64_t signed_num; /* Used to convert negative in positive. */
881 signed_num = nums + (int64_t)1;
882 signed_num = -signed_num;
883 num = (uint64_t)signed_num;
884 num += (uint64_t)1;
885 }
886 }
888 /* Supply a default precision if none was given. */
889 if(prec == -1)
890 prec = 1;
892 /* Put the number in WORK. */
893 w = workend;
894 DEBUGASSERT(base <= 16);
895 switch(base) {
896 case 10:
897 while(num > 0) {
898 *w-- = (char)('0' + (num % 10));
899 num /= 10;
900 }
901 break;
902 default:
903 while(num > 0) {
904 *w-- = digits[num % base];
905 num /= base;
906 }
907 break;
908 }
909 width -= (int)(workend - w);
910 prec -= (int)(workend - w);
912 if(is_alt && base == 8 && prec <= 0) {
913 *w-- = '0';
914 --width;
915 }
917 if(prec > 0) {
918 width -= prec;
919 while(prec-- > 0 && w >= work)
920 *w-- = '0';
921 }
923 if(is_alt && base == 16)
924 width -= 2;
926 if(is_neg || (flags & FLAGS_SHOWSIGN) || (flags & FLAGS_SPACE))
927 --width;
929 if(!(flags & FLAGS_LEFT) && !(flags & FLAGS_PAD_NIL)) {
930 if(stream_pad(userp, stream, streamn, ' ', width, donep))
931 return TRUE;
932 width = 0;
933 }
935 if(is_neg)
936 OUTCHAR('-');
937 else if(flags & FLAGS_SHOWSIGN)
938 OUTCHAR('+');
939 else if(flags & FLAGS_SPACE)
940 OUTCHAR(' ');
942 if(is_alt && base == 16) {
943 OUTCHAR('0');
944 if(flags & FLAGS_UPPER)
945 OUTCHAR('X');
946 else
947 OUTCHAR('x');
948 }
950 if(!(flags & FLAGS_LEFT) && (flags & FLAGS_PAD_NIL)) {
951 if(stream_pad(userp, stream, streamn, '0', width, donep))
952 return TRUE;
953 width = 0;
954 }
956 /* Write the number. */
957 if(stream_run(userp, stream, streamn, (const unsigned char *)w + 1,
958 (size_t)(workend - w), donep))
959 return TRUE;
961 if(flags & FLAGS_LEFT) {
962 if(stream_pad(userp, stream, streamn, ' ', width, donep))
963 return TRUE;
964 }
966 return FALSE;
969static const char nilstr[] = "(nil)";
971static bool out_string(void *userp,
972 int (*stream)(unsigned char, void *),
973 mp_streamn streamn,
974 struct mproperty *p,
975 const char *str,
976 int *donep)
978 int flags = p->flags;
979 int width = p->width;
980 int prec = p->prec;
981 size_t len;
983 if(!str) {
984 /* Write null string if there is space. */
985 if(prec == -1 || prec >= (int)CURL_CSTRLEN(nilstr)) {
986 str = nilstr;
987 len = CURL_CSTRLEN(nilstr);
988 /* Disable quotes around (nil) */
989 flags &= ~(unsigned int)FLAGS_ALT;
990 }
991 else {
992 str = "";
993 len = 0;
994 }
995 }
996 else if(prec != -1)
997 len = (size_t)prec;
998 else if(*str == '\0')
999 len = 0;
1000 else
1001 len = strlen(str);
1003 width -= (len > INT_MAX) ? INT_MAX : (int)len;
1005 if(flags & FLAGS_ALT)
1006 OUTCHAR('"');
1008 if(!(flags & FLAGS_LEFT)) {
1009 if(stream_pad(userp, stream, streamn, ' ', width, donep))
1010 return TRUE;
1011 width = 0;
1014 /* With no precision, len is already the exact length; emit it without
1015 scanning again. With precision, scan up to len but stop at NUL, since
1016 the string may be shorter or the buffer may not be null-terminated. */
1017 if(prec == -1) {
1018 if(stream_run(userp, stream, streamn,
1019 (const unsigned char *)str, len, donep))
1020 return TRUE;
1022 else if(stream_zrun(userp, stream, streamn, str, len, donep))
1023 return TRUE;
1024 if(flags & FLAGS_LEFT) {
1025 if(stream_pad(userp, stream, streamn, ' ', width, donep))
1026 return TRUE;
1029 if(flags & FLAGS_ALT)
1030 OUTCHAR('"');
1032 return FALSE;
1035static bool out_pointer(void *userp,
1036 int (*stream)(unsigned char, void *),
1037 mp_streamn streamn,
1038 struct mproperty *p,
1039 const char *ptr,
1040 char *work,
1041 int *donep)
1043 /* Generic pointer. */
1044 if(ptr) {
1045 size_t num = (size_t)ptr;
1047 /* If the pointer is not NULL, write it as a %#x spec. */
1048 p->flags |= FLAGS_HEX | FLAGS_ALT;
1049 if(out_number(userp, stream, streamn, p, num, 0, work, donep))
1050 return TRUE;
1052 else {
1053 /* Write "(nil)" for a nil pointer. */
1054 int width = p->width;
1055 int flags = p->flags;
1057 width -= (int)CURL_CSTRLEN(nilstr);
1058 if(flags & FLAGS_LEFT) {
1059 if(stream_pad(userp, stream, streamn, ' ', width, donep))
1060 return TRUE;
1061 width = 0;
1063 if(stream_run(userp, stream, streamn, (const unsigned char *)nilstr,
1064 sizeof(nilstr) - 1, donep))
1065 return TRUE;
1066 if(!(flags & FLAGS_LEFT)) {
1067 if(stream_pad(userp, stream, streamn, ' ', width, donep))
1068 return TRUE;
1071 return FALSE;
1075 * formatf() - the general printf function.
1077 * It calls parsefmt() to parse the format string. It populates two arrays;
1078 * one that describes the input arguments and one that describes a number of
1079 * output segments.
1081 * On success, the input array describes the type of all arguments and their
1082 * values.
1084 * The function then iterates over the output segments and outputs them one
1085 * by one until done. Using the appropriate input arguments (if any).
1087 * All output is sent to the 'stream()' callback, one byte at a time.
1088 */
1089static int formatf(void *userp, /* untouched by format(), sent to the
1090 stream() function in the second argument */
1091 /* function pointer called for each output character */
1092 int (*stream)(unsigned char, void *),
1093 /* optional block-output function pointer */
1094 mp_streamn streamn,
1095 /* optional, commits output the sink is holding */
1096 mp_flush flush,
1097 const char *format, /* %-formatted string */
1098 va_list ap_save) /* list of parameters */
1100 int done = 0; /* number of characters written */
1101 int i;
1102 int ocount = 0; /* number of output segments */
1103 int icount = 0; /* number of input arguments */
1105 struct outsegment output[MAX_SEGMENTS];
1106 struct va_input input[MAX_PARAMETERS];
1107 char work[BUFFSIZE + 2];
1109 /* Parse the format string */
1110 if(parsefmt(format, output, input, &ocount, &icount, ap_save))
1111 return 0;
1113 for(i = 0; i < ocount; i++) {
1114 struct outsegment *optr = &output[i];
1115 struct va_input *iptr = &input[optr->input];
1116 struct mproperty p;
1117 size_t outlen = optr->outlen;
1119 if(outlen) {
1120 if(stream_zrun(userp, stream, streamn, optr->start, outlen, &done))
1121 return done;
1122 if(optr->flags & FLAGS_SUBSTR)
1123 /* this is a substring */
1124 continue;
1127 p.flags = optr->flags;
1129 /* pick up the specified width */
1130 if(p.flags & FLAGS_WIDTHPARAM) {
1131 p.width = (int)input[optr->width].val.nums;
1132 if(p.width < 0) {
1133 /* "A negative field width is taken as a '-' flag followed by a
1134 positive field width." */
1135 if(p.width == INT_MIN)
1136 p.width = INT_MAX;
1137 else
1138 p.width = -p.width;
1139 p.flags |= FLAGS_LEFT;
1140 p.flags &= ~(unsigned int)FLAGS_PAD_NIL;
1143 else
1144 p.width = optr->width;
1146 /* pick up the specified precision */
1147 if(p.flags & FLAGS_PRECPARAM) {
1148 p.prec = (int)input[optr->precision].val.nums;
1149 if(p.prec < 0)
1150 /* "A negative precision is taken as if the precision were
1151 omitted." */
1152 p.prec = -1;
1154 else if(p.flags & FLAGS_PREC)
1155 p.prec = optr->precision;
1156 else
1157 p.prec = -1;
1159 switch(iptr->type) {
1160 case MTYPE_INTU:
1161 case MTYPE_LONGU:
1162 case MTYPE_LONGLONGU:
1163 p.flags |= FLAGS_UNSIGNED;
1164 if(out_number(userp, stream, streamn, &p, iptr->val.numu, 0, work,
1165 &done))
1166 return done;
1167 break;
1169 case MTYPE_INT:
1170 case MTYPE_LONG:
1171 case MTYPE_LONGLONG:
1172 if(out_number(userp, stream, streamn, &p, iptr->val.numu,
1173 iptr->val.nums, work, &done))
1174 return done;
1175 break;
1177 case MTYPE_STRING:
1178 if(out_string(userp, stream, streamn, &p, iptr->val.str, &done))
1179 return done;
1180 break;
1182 case MTYPE_PTR:
1183 if(out_pointer(userp, stream, streamn, &p, iptr->val.ptr, work,
1184 &done))
1185 return done;
1186 break;
1188 case MTYPE_DOUBLE:
1189 case MTYPE_LONGDOUBLE:
1190 if(out_double(userp, stream, streamn, &p, iptr->val.dnum, work,
1191 &done))
1192 return done;
1193 break;
1195 case MTYPE_INTPTR:
1196 /* %n is observable by the caller, so commit what is pending first and
1197 perform it only if that succeeded, as a sink that never holds output
1198 would. */
1199 if(flush && flush(userp))
1200 return done;
1201 /* Answer the count of characters written. */
1202 if(p.flags & FLAGS_LONGLONG)
1203 *(int64_t *)iptr->val.ptr = (int64_t)done;
1204 else if(p.flags & FLAGS_LONG)
1205 *(long *)iptr->val.ptr = (long)done;
1206 else if(!(p.flags & FLAGS_SHORT))
1207 *(int *)iptr->val.ptr = done;
1208 else
1209 *(short *)iptr->val.ptr = (short)done;
1210 break;
1212 default:
1213 break;
1216 return done;
1219/* fputc() look-alike */
1220static int addbyter(unsigned char outc, void *f)
1222 struct nsprintf *infop = f;
1223 if(infop->length < infop->max) {
1224 /* only do this if we have not reached max length yet */
1225 *infop->buffer++ = (char)outc; /* store */
1226 infop->length++; /* we are now one byte larger */
1227 return 0; /* fputc() returns like this on success */
1229 return 1;
1232/* block variant of addbyter */
1233static size_t addrun(const unsigned char *buf, size_t len, void *f)
1235 struct nsprintf *infop = f;
1236 size_t fit = infop->max - infop->length;
1237 if(len > fit)
1238 len = fit;
1239 if(len) {
1240 memcpy(infop->buffer, buf, len);
1241 infop->buffer += len;
1242 infop->length += len;
1244 return len;
1247int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format,
1248 va_list args)
1250 int retcode;
1251 struct nsprintf info;
1253 info.buffer = buffer;
1254 info.length = 0;
1255 info.max = maxlength;
1257 retcode = formatf(&info, addbyter, addrun, NULL, format, args);
1258 if(info.max) {
1259 /* we null-terminate this */
1260 if(info.max == info.length) {
1261 /* we are at maximum, scrap the last letter */
1262 info.buffer[-1] = 0;
1263 DEBUGASSERT(retcode);
1264 retcode--; /* do not count the NUL byte */
1266 else
1267 info.buffer[0] = 0;
1269 return retcode;
1272int curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...)
1274 int retcode;
1275 va_list args; /* argument pointer */
1276 va_start(args, format);
1277 retcode = curl_mvsnprintf(buffer, maxlength, format, args);
1278 va_end(args);
1279 return retcode;
1282/* append the staged bytes to the dynbuf. Returns 1 on failure (and sets
1283 merr), 0 on success. */
1284static int alloc_flush(void *f)
1286 struct asprintf *infop = f;
1287 if(infop->nstage) {
1288 CURLcode result = curlx_dyn_addn(infop->b, infop->stage, infop->nstage);
1289 infop->nstage = 0;
1290 if(result) {
1291 infop->merr = result == CURLE_TOO_LARGE ? MERR_TOO_LARGE : MERR_MEM;
1292 return 1; /* fail */
1295 return 0;
1298/* append directly, bypassing the stage. Returns 1 on failure. */
1299static int alloc_addn(struct asprintf *infop, const unsigned char *buf,
1300 size_t len)
1302 CURLcode result = curlx_dyn_addn(infop->b, buf, len);
1303 if(result) {
1304 infop->merr = result == CURLE_TOO_LARGE ? MERR_TOO_LARGE : MERR_MEM;
1305 return 1; /* fail */
1307 return 0;
1310/* TRUE if 'more' additional bytes still fit the dynbuf size limit, counting
1311 what is already staged. curlx_dyn_addn() rejects an append when
1312 len + leng + 1 exceeds it. */
1313static bool alloc_fits(struct asprintf *infop, size_t more)
1315 return (infop->b->leng + infop->nstage + more + 1) <= infop->b->toobig;
1318/* fputc() look-alike */
1319static int alloc_addbyter(unsigned char outc, void *f)
1321 struct asprintf *infop = f;
1322 if(infop->nstage == sizeof(infop->stage) && alloc_flush(infop))
1323 return 1; /* fail */
1324 if(!alloc_fits(infop, 1)) {
1325 /* Does not fit the dynbuf size limit. Flush and append this byte on
1326 its own, so the limit is reported at exactly this byte and formatting
1327 stops where it would without staging. %n depends on that. */
1328 if(alloc_flush(infop))
1329 return 1;
1330 return alloc_addn(infop, &outc, 1);
1332 infop->stage[infop->nstage++] = outc;
1333 return 0;
1336/* block variant of alloc_addbyter */
1337static size_t alloc_addrun(const unsigned char *buf, size_t len, void *f)
1339 struct asprintf *infop = f;
1340 size_t accepted = 0;
1341 while(accepted < len) {
1342 size_t room = sizeof(infop->stage) - infop->nstage;
1343 size_t n;
1344 if(!room) {
1345 if(alloc_flush(infop))
1346 return accepted; /* accepted < len aborts formatting */
1347 room = sizeof(infop->stage);
1349 n = len - accepted;
1350 if(n > room)
1351 n = room;
1352 if(!alloc_fits(infop, n)) {
1353 /* Run does not fit the dynbuf size limit. Stage what does, then
1354 append the first byte that does not on its own, so the limit is
1355 reported at exactly that byte. */
1356 size_t fits = infop->b->toobig - infop->b->leng - infop->nstage - 1;
1357 if(fits) {
1358 memcpy(&infop->stage[infop->nstage], buf + accepted, fits);
1359 infop->nstage += fits;
1360 accepted += fits;
1362 if(alloc_flush(infop))
1363 return accepted;
1364 if(alloc_addn(infop, buf + accepted, 1))
1365 return accepted; /* accepted < len aborts formatting */
1366 accepted++;
1367 continue;
1369 memcpy(&infop->stage[infop->nstage], buf + accepted, n);
1370 infop->nstage += n;
1371 accepted += n;
1373 return accepted;
1376/* appends the formatted string, returns MERR error code */
1377int curlx_dyn_vprintf(struct dynbuf *dyn, const char *format, va_list args)
1379 struct asprintf info;
1380 info.b = dyn;
1381 info.merr = MERR_OK;
1382 info.nstage = 0;
1384 (void)formatf(&info, alloc_addbyter, alloc_addrun, alloc_flush,
1385 format, args);
1386 if(!info.merr)
1387 (void)alloc_flush(&info);
1388 if(info.merr) {
1389 curlx_dyn_free(info.b);
1390 return info.merr;
1392 return 0;
1395char *curl_mvaprintf(const char *format, va_list args)
1397 struct asprintf info;
1398 struct dynbuf dyn;
1399 info.b = &dyn;
1400 curlx_dyn_init(info.b, DYN_APRINTF);
1401 info.merr = MERR_OK;
1402 info.nstage = 0;
1404 (void)formatf(&info, alloc_addbyter, alloc_addrun, alloc_flush,
1405 format, args);
1406 if(!info.merr)
1407 (void)alloc_flush(&info);
1408 if(info.merr) {
1409 curlx_dyn_free(info.b);
1410 return NULL;
1412 if(curlx_dyn_len(info.b))
1413 return curlx_dyn_ptr(info.b);
1414 return curlx_strdup("");
1417char *curl_maprintf(const char *format, ...)
1419 va_list args;
1420 char *s;
1421 va_start(args, format);
1422 s = curl_mvaprintf(format, args);
1423 va_end(args);
1424 return s;
1427static int storebuffer(unsigned char outc, void *f)
1429 char **buffer = f;
1430 **buffer = (char)outc;
1431 (*buffer)++;
1432 return 0;
1435/* block variant of storebuffer */
1436static size_t storerun(const unsigned char *buf, size_t len, void *f)
1438 char **buffer = f;
1439 memcpy(*buffer, buf, len);
1440 *buffer += len;
1441 return len;
1444int curl_msprintf(char *buffer, const char *format, ...)
1446 va_list args; /* argument pointer */
1447 int retcode;
1448 va_start(args, format);
1449 retcode = formatf(&buffer, storebuffer, storerun, NULL, format, args);
1450 va_end(args);
1451 *buffer = 0; /* we null-terminate this */
1452 return retcode;
1455static int fputc_wrapper(unsigned char outc, void *f)
1457 struct ioprintf *i = f;
1458 int out = outc;
1459 FILE *s = i->fd;
1460 int rc = fputc(out, s);
1461 i->error = (rc == EOF);
1462 return (rc == EOF);
1465/* block variant of fputc_wrapper */
1466static size_t fwrite_wrapper(const unsigned char *buf, size_t len, void *f)
1468 struct ioprintf *i = f;
1469 size_t n;
1470 FILE *s = i->fd;
1471 n = fwrite(buf, 1, len, s);
1472 i->error = (n != len);
1473 return n;
1476int curl_mvfprintf(FILE *fd, const char *format, va_list args)
1478 struct ioprintf info;
1479 int n;
1480 info.fd = fd;
1481 info.error = FALSE;
1482 n = formatf(&info, fputc_wrapper, fwrite_wrapper, NULL, format, args);
1483 if(info.error)
1484 return -1;
1485 return n;
1488int curl_mfprintf(FILE *fd, const char *format, ...)
1490 va_list args; /* argument pointer */
1491 int n;
1492 va_start(args, format);
1493 n = curl_mvfprintf(fd, format, args);
1494 va_end(args);
1495 return n;
1498int curl_mprintf(const char *format, ...)
1500 va_list args; /* argument pointer */
1501 int n;
1502 va_start(args, format);
1503 n = curl_mvfprintf(stdout, format, args);
1504 va_end(args);
1505 return n;
1508int curl_mvsprintf(char *buffer, const char *format, va_list args)
1510 int retcode = formatf(&buffer, storebuffer, storerun, NULL, format, args);
1511 *buffer = 0; /* we null-terminate this */
1512 return retcode;
1515int curl_mvprintf(const char *format, va_list args)
1517 return curl_mvfprintf(stdout, format, args);
Diagnostics4 git calls · 26 ms
CallStatusSizeTime026 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
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 · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
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=86
Open pack map
fetch20011 KiB · hit20 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=20
git.response.bytes=11548
git.response.cache=HIT
git.response.duration_ms=20
git.fetch.wants=9f172c377bba838f46eb1f5cad85a20c13686bc5
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=11548
git.pkt.payload.max=11527
git.sideband.band1.bytes=11526
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
a5e2028148d870b8
Request
9454764d…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format