Artifactspublic-v0

curl

master
ply4 git calls26 ms290 KiB3 cachedprotocol v2
322 lines8.8 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 "curlx/strparse.h"
26void curlx_str_init(struct Curl_str *out)
28 out->str = NULL;
29 out->len = 0;
32void curlx_str_assign(struct Curl_str *out, const char *str, size_t len)
34 out->str = str;
35 out->len = len;
38/* remove bytes from the end of the string, never remove more bytes than what
39 the string holds! */
40void curlx_str_trim(struct Curl_str *out, size_t len)
42 DEBUGASSERT(out);
43 DEBUGASSERT(out->len >= len);
44 out->len -= len;
47/* Get a word until the first DELIM or end of string. At least one byte long.
48 return non-zero on error. If 'max' is zero, it will always return error. */
49int curlx_str_until(const char **linep, struct Curl_str *out,
50 const size_t max, char delim)
52 const char *s;
53 size_t len = 0;
54 DEBUGASSERT(linep);
55 DEBUGASSERT(*linep);
56 DEBUGASSERT(out);
57 DEBUGASSERT(delim);
58 s = *linep;
60 curlx_str_init(out);
61 while(*s && (*s != delim)) {
62 s++;
63 if(++len > max) {
64 return STRE_BIG;
65 }
66 }
67 if(!len)
68 return STRE_SHORT;
69 out->str = *linep;
70 out->len = len;
71 *linep = s; /* point to the first byte after the word */
72 return STRE_OK;
75/* Get a word until the first space or end of string. At least one byte long.
76 return non-zero on error */
77int curlx_str_word(const char **linep, struct Curl_str *out, const size_t max)
79 return curlx_str_until(linep, out, max, ' ');
82/* Get a word until a newline byte or end of string. At least one byte long.
83 return non-zero on error */
84int curlx_str_untilnl(const char **linep, struct Curl_str *out,
85 const size_t max)
87 const char *s = *linep;
88 size_t len = 0;
89 DEBUGASSERT(linep && *linep && out && max);
91 curlx_str_init(out);
92 while(*s && !ISNEWLINE(*s)) {
93 s++;
94 if(++len > max)
95 return STRE_BIG;
96 }
97 if(!len)
98 return STRE_SHORT;
99 out->str = *linep;
100 out->len = len;
101 *linep = s; /* point to the first byte after the word */
102 return STRE_OK;
105/* Get a "quoted" word. Escaped quotes are supported.
106 return non-zero on error */
107int curlx_str_quotedword(const char **linep, struct Curl_str *out,
108 const size_t max)
110 const char *s = *linep;
111 size_t len = 0;
112 DEBUGASSERT(linep && *linep && out && max);
114 curlx_str_init(out);
115 if(*s != '\"')
116 return STRE_BEGQUOTE;
117 s++;
118 while(*s && (*s != '\"')) {
119 if(*s == '\\' && s[1]) {
120 s++;
121 if(++len > max)
122 return STRE_BIG;
123 }
124 s++;
125 if(++len > max)
126 return STRE_BIG;
127 }
128 if(*s != '\"')
129 return STRE_ENDQUOTE;
130 out->str = (*linep) + 1;
131 out->len = len;
132 *linep = s + 1;
133 return STRE_OK;
136/* Advance over a single character.
137 return non-zero on error */
138int curlx_str_single(const char **linep, char byte)
140 DEBUGASSERT(linep && *linep);
141 if(**linep != byte)
142 return STRE_BYTE;
143 (*linep)++; /* move over it */
144 return STRE_OK;
147/* Advance over a single space.
148 return non-zero on error */
149int curlx_str_singlespace(const char **linep)
151 return curlx_str_single(linep, ' ');
154/* given an ASCII character and max ascii, return TRUE if valid */
155#define valid_digit(x, m) \
156 (((x) >= '0') && ((x) <= (m)) && curlx_hexasciitable[(x) - '0'])
158/* We use 16 for the zero index (and the necessary bitwise AND in the loop)
159 to be able to have a non-zero value there to make valid_digit() able to
160 use the info */
161const unsigned char curlx_hexasciitable[] = {
162 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 0x30: 0 - 9 */
163 0, 0, 0, 0, 0, 0, 0,
164 10, 11, 12, 13, 14, 15, /* 0x41: A - F */
165 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
166 10, 11, 12, 13, 14, 15 /* 0x61: a - f */
167};
169/* no support for 0x prefix nor leading spaces */
170static int str_num_base(const char **linep, curl_off_t *nump, curl_off_t max,
171 int base) /* 8, 10 or 16, nothing else */
173 curl_off_t num = 0;
174 const char *p;
175 int m = (base == 10) ? '9' : /* the largest digit possible */
176 (base == 16) ? 'f' : '7';
177 DEBUGASSERT(linep && *linep && nump);
178 DEBUGASSERT((base == 8) || (base == 10) || (base == 16));
179 DEBUGASSERT(max >= 0); /* mostly to catch SIZE_MAX, which is too large */
180 *nump = 0;
181 p = *linep;
182 if(!valid_digit(*p, m))
183 return STRE_NO_NUM;
184 if(max < base) {
185 /* special-case low max scenario because check needs to be different */
186 do {
187 int n = curlx_hexval(*p++);
188 num = (num * base) + n;
189 if(num > max)
190 return STRE_OVERFLOW;
191 } while(valid_digit(*p, m));
192 }
193 else {
194 curl_off_t cutoff = (max - (base - 1)) / base;
195 while(valid_digit(*p, m)) {
196 if(num <= cutoff)
197 num = (num * base) + curlx_hexval(*p++);
198 else {
199 int n = curlx_hexval(*p++);
200 if(num > ((max - n) / base))
201 return STRE_OVERFLOW;
202 num = (num * base) + n;
203 }
204 }
205 }
206 *nump = num;
207 *linep = p;
208 return STRE_OK;
211/* Get an unsigned decimal number with no leading space or minus. Leading
212 zeroes are accepted. return non-zero on error */
213int curlx_str_number(const char **linep, curl_off_t *nump, curl_off_t max)
215 return str_num_base(linep, nump, max, 10);
218/* Get an unsigned hexadecimal number with no leading space or minus and no
219 "0x" support. Leading zeroes are accepted. return non-zero on error */
220int curlx_str_hex(const char **linep, curl_off_t *nump, curl_off_t max)
222 return str_num_base(linep, nump, max, 16);
225/* Get an unsigned octal number with no leading space or minus and no "0"
226 prefix support. Leading zeroes are accepted. return non-zero on error */
227int curlx_str_octal(const char **linep, curl_off_t *nump, curl_off_t max)
229 return str_num_base(linep, nump, max, 8);
232/*
233 * Parse a positive number up to 63-bit number written in ASCII. Skip leading
234 * blanks. No support for prefixes.
235 */
236int curlx_str_numblanks(const char **str, curl_off_t *num)
238 curlx_str_passblanks(str);
239 return curlx_str_number(str, num, CURL_OFF_T_MAX);
242/* CR or LF
243 return non-zero on error */
244int curlx_str_newline(const char **linep)
246 DEBUGASSERT(linep && *linep);
247 if(ISNEWLINE(**linep)) {
248 (*linep)++;
249 return STRE_OK; /* yessir */
250 }
251 return STRE_NEWLINE;
254#ifndef WITHOUT_LIBCURL
255/* case insensitive compare that the parsed string matches the given string.
256 Returns non-zero on match. */
257int curlx_str_casecompare(struct Curl_str *str, const char *check)
259 size_t clen = check ? strlen(check) : 0;
260 return ((str->len == clen) && curl_strnequal(str->str, check, clen));
262#endif
264/* case sensitive string compare. Returns non-zero on match. */
265int curlx_str_cmp(struct Curl_str *str, const char *check)
267 if(check) {
268 size_t clen = strlen(check);
269 return ((str->len == clen) && !strncmp(str->str, check, clen));
270 }
271 return !!str->len;
274/* Trim off 'num' number of bytes from the beginning (left side) of the
275 string. If 'num' is larger than the string, return error. */
276int curlx_str_nudge(struct Curl_str *str, size_t num)
278 if(num <= str->len) {
279 str->str += num;
280 str->len -= num;
281 return STRE_OK;
282 }
283 return STRE_OVERFLOW;
286/* Get the following character sequence that consists only of bytes not
287 present in the 'reject' string. Like strcspn(). */
288int curlx_str_cspn(const char **linep, struct Curl_str *out,
289 const char *reject)
291 const char *s = *linep;
292 size_t len;
293 DEBUGASSERT(linep && *linep);
295 len = strcspn(s, reject);
296 if(len) {
297 out->str = s;
298 out->len = len;
299 *linep = &s[len];
300 return STRE_OK;
301 }
302 curlx_str_init(out);
303 return STRE_SHORT;
306/* remove ISBLANK()s from both ends of the string */
307void curlx_str_trimblanks(struct Curl_str *out)
309 while(out->len && ISBLANK(*out->str))
310 curlx_str_nudge(out, 1);
312 /* trim trailing spaces and tabs */
313 while(out->len && ISBLANK(out->str[out->len - 1]))
314 out->len--;
317/* increase the pointer until it has moved over all blanks */
318void curlx_str_passblanks(const char **linep)
320 while(ISBLANK(**linep))
321 (*linep)++; /* move over it */
Diagnostics4 git calls · 26 ms
CallStatusSizeTime026 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 · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
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
fetch2003.0 KiB · hit21 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=21
git.response.bytes=3036
git.response.cache=HIT
git.response.duration_ms=21
git.fetch.wants=a17aa3c137e096f7794c729ab9e710b0ed4ec7da
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=3036
git.pkt.payload.max=3015
git.sideband.band1.bytes=3014
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
a5e2ce00f81befad
Request
065a070a…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format