Artifactspublic-v0

curl

master
ply4 git calls27 ms290 KiB3 cachedprotocol v2
418 lines10 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#ifndef CURL_DISABLE_FTP
28#include "curl_fnmatch.h"
30#ifndef HAVE_FNMATCH
32#define CURLFNM_CHARSET_LEN (sizeof(char) * 256)
33#define CURLFNM_CHSET_SIZE (CURLFNM_CHARSET_LEN + 15)
35#define CURLFNM_NEGATE CURLFNM_CHARSET_LEN
37#define CURLFNM_ALNUM (CURLFNM_CHARSET_LEN + 1)
38#define CURLFNM_DIGIT (CURLFNM_CHARSET_LEN + 2)
39#define CURLFNM_XDIGIT (CURLFNM_CHARSET_LEN + 3)
40#define CURLFNM_ALPHA (CURLFNM_CHARSET_LEN + 4)
41#define CURLFNM_PRINT (CURLFNM_CHARSET_LEN + 5)
42#define CURLFNM_BLANK (CURLFNM_CHARSET_LEN + 6)
43#define CURLFNM_LOWER (CURLFNM_CHARSET_LEN + 7)
44#define CURLFNM_GRAPH (CURLFNM_CHARSET_LEN + 8)
45#define CURLFNM_SPACE (CURLFNM_CHARSET_LEN + 9)
46#define CURLFNM_UPPER (CURLFNM_CHARSET_LEN + 10)
48typedef enum {
49 CURLFNM_SCHS_DEFAULT = 0,
50 CURLFNM_SCHS_RIGHTBR,
51 CURLFNM_SCHS_RIGHTBRLEFTBR
52} setcharset_state;
54typedef enum {
55 CURLFNM_PKW_INIT = 0,
56 CURLFNM_PKW_DDOT
57} parsekey_state;
59typedef enum {
60 CCLASS_OTHER = 0,
61 CCLASS_DIGIT,
62 CCLASS_UPPER,
63 CCLASS_LOWER
64} char_class;
66#define SETCHARSET_OK 1
67#define SETCHARSET_FAIL 0
69static int parsekeyword(const unsigned char **pattern, unsigned char *charset)
71 parsekey_state state = CURLFNM_PKW_INIT;
72 char keyword[10] = { 0 };
73 size_t i;
74 const unsigned char *p = *pattern;
75 bool found = FALSE;
76 for(i = 0; !found; i++) {
77 char c = (char)*p++;
78 if(i >= sizeof(keyword))
79 return SETCHARSET_FAIL;
80 switch(state) {
81 case CURLFNM_PKW_INIT:
82 if(ISLOWER(c))
83 keyword[i] = c;
84 else if(c == ':')
85 state = CURLFNM_PKW_DDOT;
86 else
87 return SETCHARSET_FAIL;
88 break;
89 case CURLFNM_PKW_DDOT:
90 if(c == ']')
91 found = TRUE;
92 else
93 return SETCHARSET_FAIL;
94 }
95 }
96#undef KEYLEN
98 *pattern = p; /* move caller's pattern pointer */
99 if(!strcmp(keyword, "digit"))
100 charset[CURLFNM_DIGIT] = 1;
101 else if(!strcmp(keyword, "alnum"))
102 charset[CURLFNM_ALNUM] = 1;
103 else if(!strcmp(keyword, "alpha"))
104 charset[CURLFNM_ALPHA] = 1;
105 else if(!strcmp(keyword, "xdigit"))
106 charset[CURLFNM_XDIGIT] = 1;
107 else if(!strcmp(keyword, "print"))
108 charset[CURLFNM_PRINT] = 1;
109 else if(!strcmp(keyword, "graph"))
110 charset[CURLFNM_GRAPH] = 1;
111 else if(!strcmp(keyword, "space"))
112 charset[CURLFNM_SPACE] = 1;
113 else if(!strcmp(keyword, "blank"))
114 charset[CURLFNM_BLANK] = 1;
115 else if(!strcmp(keyword, "upper"))
116 charset[CURLFNM_UPPER] = 1;
117 else if(!strcmp(keyword, "lower"))
118 charset[CURLFNM_LOWER] = 1;
119 else
120 return SETCHARSET_FAIL;
121 return SETCHARSET_OK;
124/* Return the character class. */
125static char_class charclass(unsigned char c)
127 if(ISUPPER(c))
128 return CCLASS_UPPER;
129 if(ISLOWER(c))
130 return CCLASS_LOWER;
131 if(ISDIGIT(c))
132 return CCLASS_DIGIT;
133 return CCLASS_OTHER;
136/* Include a character or a range in set. */
137static void setcharorrange(const unsigned char **pp, unsigned char *charset)
139 const unsigned char *p = (*pp)++;
140 unsigned char c = *p++;
142 charset[c] = 1;
143 if(ISALNUM(c) && *p++ == '-') {
144 char_class cc = charclass(c);
145 unsigned char endrange = *p++;
147 if(endrange == '\\')
148 endrange = *p++;
149 if(endrange >= c && charclass(endrange) == cc) {
150 while(c++ != endrange)
151 if(charclass(c) == cc) /* Chars in class may be not consecutive. */
152 charset[c] = 1;
153 *pp = p;
154 }
155 }
158/* returns 1 (TRUE) if pattern is OK, 0 if is bad ("p" is pattern pointer) */
159static int setcharset(const unsigned char **p, unsigned char *charset)
161 setcharset_state state = CURLFNM_SCHS_DEFAULT;
162 bool something_found = FALSE;
163 unsigned char c;
165 memset(charset, 0, CURLFNM_CHSET_SIZE);
166 for(;;) {
167 c = **p;
168 if(!c)
169 return SETCHARSET_FAIL;
171 switch(state) {
172 case CURLFNM_SCHS_DEFAULT:
173 if(c == ']') {
174 if(something_found)
175 return SETCHARSET_OK;
176 something_found = TRUE;
177 state = CURLFNM_SCHS_RIGHTBR;
178 charset[c] = 1;
179 (*p)++;
180 }
181 else if(c == '[') {
182 const unsigned char *pp = *p + 1;
184 if(*pp++ == ':' && parsekeyword(&pp, charset))
185 *p = pp;
186 else {
187 charset[c] = 1;
188 (*p)++;
189 }
190 something_found = TRUE;
191 }
192 else if(c == '^' || c == '!') {
193 if(!something_found) {
194 if(charset[CURLFNM_NEGATE]) {
195 charset[c] = 1;
196 something_found = TRUE;
197 }
198 else
199 charset[CURLFNM_NEGATE] = 1; /* negate charset */
200 }
201 else
202 charset[c] = 1;
203 (*p)++;
204 }
205 else if(c == '\\') {
206 c = *(++(*p));
207 if(c)
208 setcharorrange(p, charset);
209 else
210 charset['\\'] = 1;
211 something_found = TRUE;
212 }
213 else {
214 setcharorrange(p, charset);
215 something_found = TRUE;
216 }
217 break;
218 case CURLFNM_SCHS_RIGHTBR:
219 if(c == '[') {
220 state = CURLFNM_SCHS_RIGHTBRLEFTBR;
221 charset[c] = 1;
222 (*p)++;
223 }
224 else if(c == ']') {
225 return SETCHARSET_OK;
226 }
227 else if(ISPRINT(c)) {
228 charset[c] = 1;
229 (*p)++;
230 state = CURLFNM_SCHS_DEFAULT;
231 }
232 else
233 /* used 'goto fail' instead of 'return SETCHARSET_FAIL' to avoid a
234 * nonsense warning 'statement not reached' at end of the fnc when
235 * compiling on Solaris */
236 goto fail;
237 break;
238 case CURLFNM_SCHS_RIGHTBRLEFTBR:
239 if(c == ']')
240 return SETCHARSET_OK;
241 state = CURLFNM_SCHS_DEFAULT;
242 charset[c] = 1;
243 (*p)++;
244 break;
245 }
246 }
247fail:
248 return SETCHARSET_FAIL;
251/* match one pattern token against one string character, advancing both */
252static int matchtoken(const unsigned char **pp, const unsigned char **sp)
254 const unsigned char *p = *pp;
255 const unsigned char *s = *sp;
257 switch(*p) {
258 case '?':
259 break;
260 case '\\':
261 if(p[1])
262 p++;
263 if(*s != *p)
264 return 0;
265 break;
266 case '[': {
267 unsigned char charset[CURLFNM_CHSET_SIZE];
268 const unsigned char *pp2 = p + 1; /* Copy in case of syntax error. */
269 bool found = FALSE;
270 if(!setcharset(&pp2, charset))
271 return -1; /* Syntax error in set; mismatch! */
272 if(charset[(unsigned int)*s])
273 found = TRUE;
274 else if(charset[CURLFNM_ALNUM])
275 found = ISALNUM(*s);
276 else if(charset[CURLFNM_ALPHA])
277 found = ISALPHA(*s);
278 else if(charset[CURLFNM_DIGIT])
279 found = ISDIGIT(*s);
280 else if(charset[CURLFNM_XDIGIT])
281 found = ISXDIGIT(*s);
282 else if(charset[CURLFNM_PRINT])
283 found = ISPRINT(*s);
284 else if(charset[CURLFNM_SPACE])
285 found = ISBLANK(*s);
286 else if(charset[CURLFNM_UPPER])
287 found = ISUPPER(*s);
288 else if(charset[CURLFNM_LOWER])
289 found = ISLOWER(*s);
290 else if(charset[CURLFNM_BLANK])
291 found = ISBLANK(*s);
292 else if(charset[CURLFNM_GRAPH])
293 found = ISGRAPH(*s);
295 if(charset[CURLFNM_NEGATE])
296 found = !found;
298 if(!found)
299 return 0;
300 *pp = pp2 + 1;
301 *sp = s + 1;
302 return 1;
303 }
304 default:
305 if(*p != *s)
306 return 0;
307 break;
308 }
309 *pp = p + 1;
310 *sp = s + 1;
311 return 1;
314/* greedy match with backtracking to the most recent '*' */
315static int loop(const unsigned char *pattern, const unsigned char *string)
317 const unsigned char *p = pattern;
318 const unsigned char *s = string;
319 const unsigned char *star_p = NULL;
320 const unsigned char *star_s = NULL;
321 int maxstars = 2;
323 while(*s) {
324 if(*p == '*') {
325 if(!maxstars)
326 return CURL_FNMATCH_NOMATCH;
327 maxstars--;
328 for(;;) {
329 p++;
330 if(!*p)
331 return CURL_FNMATCH_MATCH;
332 if(*p == '?') {
333 if(!*s)
334 return CURL_FNMATCH_NOMATCH;
335 s++;
336 }
337 else if(*p != '*')
338 break;
339 }
340 star_p = p;
341 star_s = s;
342 }
343 else if(*p) {
344 const unsigned char *np = p;
345 const unsigned char *ns = s;
346 int r = matchtoken(&np, &ns);
347 if(r < 0)
348 return CURL_FNMATCH_NOMATCH;
349 if(r) {
350 p = np;
351 s = ns;
352 continue;
353 }
354 if(!star_p)
355 return CURL_FNMATCH_NOMATCH;
356 p = star_p;
357 s = ++star_s;
358 }
359 else if(star_p) {
360 p = star_p;
361 s = ++star_s;
362 }
363 else
364 return CURL_FNMATCH_NOMATCH;
365 }
366 while(*p == '*') {
367 if(!maxstars)
368 return CURL_FNMATCH_NOMATCH;
369 maxstars--;
370 do {
371 p++;
372 if(*p == '?')
373 return CURL_FNMATCH_NOMATCH;
374 } while(*p == '*');
375 }
376 return *p ? CURL_FNMATCH_NOMATCH : CURL_FNMATCH_MATCH;
379/*
380 * @unittest: 1307
381 */
382int Curl_fnmatch(void *ptr, const char *pattern, const char *string)
384 (void)ptr; /* the argument is specified by the curl_fnmatch_callback
385 prototype, but not used by Curl_fnmatch() */
386 if(!pattern || !string) {
387 return CURL_FNMATCH_FAIL;
388 }
389 return loop((const unsigned char *)pattern,
390 (const unsigned char *)string);
392#else /* HAVE_FNMATCH */
394#include <fnmatch.h>
395/*
396 * @unittest: 1307
397 */
398int Curl_fnmatch(void *ptr, const char *pattern, const char *string)
400 (void)ptr; /* the argument is specified by the curl_fnmatch_callback
401 prototype, but not used by Curl_fnmatch() */
402 if(!pattern || !string) {
403 return CURL_FNMATCH_FAIL;
404 }
406 switch(fnmatch(pattern, string, 0)) {
407 case 0:
408 return CURL_FNMATCH_MATCH;
409 case FNM_NOMATCH:
410 return CURL_FNMATCH_NOMATCH;
411 default:
412 return CURL_FNMATCH_FAIL;
413 }
414 /* not reached */
416#endif /* !HAVE_FNMATCH */
418#endif /* !CURL_DISABLE_FTP */
Diagnostics4 git calls · 27 ms
CallStatusSizeTime027 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 · hit2 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=2
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.1 KiB · hit23 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=23
git.response.bytes=3158
git.response.cache=HIT
git.response.duration_ms=23
git.fetch.wants=58475a25f2f6ca4ebbc9d717a2b2b3c95414eaee
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=3158
git.pkt.payload.max=3137
git.sideband.band1.bytes=3136
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
a5e30a2769bdee28
Request
d4fce081…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format