Artifactspublic-v0

curl

master
ply4 git calls320 ms291 KiB2 cachedprotocol v2
447 lines12 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 "first.h"
26#define EAT_SPACE(p) while(*(p) && ISSPACE(*(p))) (p)++
28#define EAT_WORD(p) while(*(p) && !ISSPACE(*(p)) && ('>' != *(p))) (p)++
30#ifdef DEBUG_GETPART
31#define show(x) printf x
32#else
33#define show(x) Curl_nop_stmt
34#endif
36/*
37 * line_length()
38 *
39 * Counts the number of characters in a line including a new line.
40 * Unlike strlen() it does not stop at NUL bytes.
41 *
42 */
43static size_t line_length(const char *buffer, int bytestocheck)
45 size_t length = 1;
47 while(*buffer != '\n' && --bytestocheck) {
48 length++;
49 buffer++;
50 }
51 if(*buffer != '\n') {
52 /*
53 * We did not find a new line so the last byte must be a
54 * '\0' character inserted by fgets() which we should not
55 * count.
56 */
57 length--;
58 }
60 return length;
63/*
64 * readline()
65 *
66 * Reads a complete line from a file into a dynamically allocated buffer.
67 *
68 * Calling function may call this multiple times with same 'buffer'
69 * and 'bufsize' pointers to avoid multiple buffer allocations. Buffer
70 * is reallocated and 'bufsize' increased until whole line fits in
71 * buffer before returning it.
72 *
73 * Calling function is responsible to free allocated buffer.
74 *
75 * This function may return:
76 * GPE_OUT_OF_MEMORY
77 * GPE_END_OF_FILE
78 * GPE_OK
79 */
80static int readline(char **buffer, size_t *bufsize, size_t *length,
81 FILE *stream)
83 size_t offset = 0;
84 char *newptr;
86 if(!*buffer) {
87 *buffer = calloc(1, 128);
88 if(!*buffer)
89 return GPE_OUT_OF_MEMORY;
90 *bufsize = 128;
91 }
93 for(;;) {
94 int bytestoread = curlx_uztosi(*bufsize - offset);
96 if(!fgets(*buffer + offset, bytestoread, stream)) {
97 *length = 0;
98 return (offset != 0) ? GPE_OK : GPE_END_OF_FILE;
99 }
101 *length = offset + line_length(*buffer + offset, bytestoread);
102 if(*(*buffer + *length - 1) == '\n')
103 break;
104 offset = *length;
105 if(*length < *bufsize - 1)
106 continue;
108 newptr = realloc(*buffer, *bufsize * 2);
109 if(!newptr)
110 return GPE_OUT_OF_MEMORY;
111 memset(&newptr[*bufsize], 0, *bufsize);
112 *buffer = newptr;
113 *bufsize *= 2;
114 }
116 return GPE_OK;
119/*
120 * appenddata()
121 *
122 * This appends data from a given source buffer to the end of the used part of
123 * a destination buffer. Arguments relative to the destination buffer are, the
124 * address of a pointer to the destination buffer 'dst_buf', the length of data
125 * in destination buffer excluding potential string null-terminator 'dst_len',
126 * the allocated size of destination buffer 'dst_alloc'. All three destination
127 * buffer arguments may be modified by this function. Arguments relative to the
128 * source buffer are, a pointer to the source buffer 'src_buf' and indication
129 * whether the source buffer is base64 encoded or not 'src_b64'.
130 *
131 * If the source buffer is indicated to be base64 encoded, this appends the
132 * decoded data, binary or whatever, to the destination. The source buffer
133 * may not hold binary data, only a null-terminated string is valid content.
134 *
135 * Destination buffer is enlarged and relocated as needed.
136 *
137 * Calling function is responsible to provide preallocated destination
138 * buffer and also to deallocate it when no longer needed.
139 *
140 * This function may return:
141 * GPE_OUT_OF_MEMORY
142 * GPE_OK
143 */
144static int appenddata(char **dst_buf, /* dest buffer */
145 size_t *dst_len, /* dest buffer data length */
146 size_t *dst_alloc, /* dest buffer allocated size */
147 const char *src_buf, /* source buffer */
148 size_t src_len, /* source buffer length */
149 int src_b64) /* != 0 if source is base64
150 encoded */
152 size_t need_alloc = 0;
154 if(!src_len)
155 return GPE_OK;
157 need_alloc = src_len + *dst_len + 1;
159 if(src_b64) {
160 if(src_buf[src_len - 1] == '\r')
161 src_len--;
163 if(src_buf[src_len - 1] == '\n')
164 src_len--;
165 }
167 /* enlarge destination buffer if required */
168 if(need_alloc > *dst_alloc) {
169 size_t newsize = need_alloc * 2;
170 char *newptr = realloc(*dst_buf, newsize);
171 if(!newptr) {
172 return GPE_OUT_OF_MEMORY;
173 }
174 *dst_alloc = newsize;
175 *dst_buf = newptr;
176 }
178 /* memcpy to support binary blobs */
179 memcpy(*dst_buf + *dst_len, src_buf, src_len);
180 *dst_len += src_len;
181 *(*dst_buf + *dst_len) = '\0';
183 return GPE_OK;
186static int decodedata(char **buf, /* dest buffer */
187 size_t *len) /* dest buffer data length */
189 CURLcode result = CURLE_OK;
190 unsigned char *buf64 = NULL;
191 size_t src_len = 0;
193 if(!*len)
194 return GPE_OK;
196 /* base64 decode the given buffer */
197 result = curlx_base64_decode(*buf, &buf64, &src_len);
198 if(result)
199 return GPE_OUT_OF_MEMORY;
201 if(!src_len) {
202 /*
203 * currently there is no way to tell apart an OOM condition in
204 * curlx_base64_decode() from zero length decoded data. For now,
205 * let's assume it is an OOM condition, currently we have
206 * no input for this function that decodes to zero length data.
207 */
208 free(buf64);
210 return GPE_OUT_OF_MEMORY;
211 }
213 /* memcpy to support binary blobs */
214 memcpy(*buf, buf64, src_len);
215 *len = src_len;
216 *(*buf + src_len) = '\0';
218 free(buf64);
220 return GPE_OK;
223/*
224 * getpart()
225 *
226 * This returns whole contents of specified XML-like section and subsection
227 * from the given file. This is mostly used to retrieve a specific part from
228 * a test definition file for consumption by test suite servers.
229 *
230 * Data is returned in a dynamically allocated buffer, a pointer to this data
231 * and the size of the data is stored at the addresses that caller specifies.
232 *
233 * If the returned data is a string the returned size is the length of
234 * the string excluding null-termination. Otherwise it is the size
235 * of the returned binary data.
236 *
237 * Calling function is responsible to free returned buffer.
238 *
239 * This function may return:
240 * GPE_NO_BUFFER_SPACE
241 * GPE_OUT_OF_MEMORY
242 * GPE_OK
243 */
244int getpart(char **outbuf, size_t *outlen,
245 const char *main, const char *sub, FILE *stream)
247#define MAX_TAG_LEN 200
248 char curouter[MAX_TAG_LEN + 1]; /* current outermost section */
249 char curmain[MAX_TAG_LEN + 1]; /* current main section */
250 char cursub[MAX_TAG_LEN + 1]; /* current sub section */
251 char ptag[MAX_TAG_LEN + 1]; /* potential tag */
252 char patt[MAX_TAG_LEN + 1]; /* potential attributes */
253 char *buffer = NULL;
254 char *ptr;
255 char *end;
256 union {
257 ssize_t sig;
258 size_t uns;
259 } len;
260 size_t bufsize = 0;
261 size_t outalloc = 256;
262 size_t datalen;
263 int in_wanted_part = 0;
264 int base64 = 0;
265 int nonewline = 0;
266 int error;
268 enum {
269 STATE_OUTSIDE = 0,
270 STATE_OUTER = 1,
271 STATE_INMAIN = 2,
272 STATE_INSUB = 3,
273 STATE_ILLEGAL = 4
274 } state = STATE_OUTSIDE;
276 *outlen = 0;
277 *outbuf = malloc(outalloc);
278 if(!*outbuf)
279 return GPE_OUT_OF_MEMORY;
280 *(*outbuf) = '\0';
282 curouter[0] = curmain[0] = cursub[0] = ptag[0] = patt[0] = '\0';
284 while((error = readline(&buffer, &bufsize, &datalen, stream)) == GPE_OK) {
286 ptr = buffer;
287 EAT_SPACE(ptr);
289 if('<' != *ptr) {
290 if(in_wanted_part) {
291 show(("=> %s", buffer));
292 error = appenddata(outbuf, outlen, &outalloc, buffer, datalen, base64);
293 if(error)
294 break;
295 }
296 continue;
297 }
299 ptr++;
301 if('/' == *ptr) {
302 /*
303 * closing section tag
304 */
306 ptr++;
307 end = ptr;
308 EAT_WORD(end);
309 len.sig = end - ptr;
310 if(len.sig > MAX_TAG_LEN) {
311 error = GPE_NO_BUFFER_SPACE;
312 break;
313 }
314 memcpy(ptag, ptr, len.uns);
315 ptag[len.uns] = '\0';
317 if((STATE_INSUB == state) && !strcmp(cursub, ptag)) {
318 /* end of current sub section */
319 state = STATE_INMAIN;
320 cursub[0] = '\0';
321 if(in_wanted_part) {
322 /* Do we need to base64 decode the data? */
323 if(base64) {
324 error = decodedata(outbuf, outlen);
325 if(error)
326 return error;
327 }
328 if(nonewline)
329 (*outlen)--;
330 break;
331 }
332 }
333 else if((STATE_INMAIN == state) && !strcmp(curmain, ptag)) {
334 /* end of current main section */
335 state = STATE_OUTER;
336 curmain[0] = '\0';
337 if(in_wanted_part) {
338 /* Do we need to base64 decode the data? */
339 if(base64) {
340 error = decodedata(outbuf, outlen);
341 if(error)
342 return error;
343 }
344 if(nonewline)
345 (*outlen)--;
346 break;
347 }
348 }
349 else if((STATE_OUTER == state) && !strcmp(curouter, ptag)) {
350 /* end of outermost file section */
351 state = STATE_OUTSIDE;
352 curouter[0] = '\0';
353 if(in_wanted_part)
354 break;
355 }
356 }
357 else if(!in_wanted_part) {
358 /*
359 * opening section tag
360 */
362 /* get potential tag */
363 end = ptr;
364 EAT_WORD(end);
365 len.sig = end - ptr;
366 if(len.sig > MAX_TAG_LEN) {
367 error = GPE_NO_BUFFER_SPACE;
368 break;
369 }
370 memcpy(ptag, ptr, len.uns);
371 ptag[len.uns] = '\0';
373 /* ignore comments, doctypes and xml declarations */
374 if(('!' == ptag[0]) || ('?' == ptag[0])) {
375 show(("* ignoring (%s)", buffer));
376 continue;
377 }
379 /* get all potential attributes */
380 ptr = end;
381 EAT_SPACE(ptr);
382 end = ptr;
383 while(*end && ('>' != *end))
384 end++;
385 len.sig = end - ptr;
386 if(len.sig > MAX_TAG_LEN) {
387 error = GPE_NO_BUFFER_SPACE;
388 break;
389 }
390 memcpy(patt, ptr, len.uns);
391 patt[len.uns] = '\0';
393 if(STATE_OUTSIDE == state) {
394 /* outermost element (<testcase>) */
395 curlx_strcopy(curouter, sizeof(curouter), ptag, strlen(ptag));
396 state = STATE_OUTER;
397 continue;
398 }
399 else if(STATE_OUTER == state) {
400 /* start of a main section */
401 curlx_strcopy(curmain, sizeof(curmain), ptag, strlen(ptag));
402 state = STATE_INMAIN;
403 continue;
404 }
405 else if(STATE_INMAIN == state) {
406 /* start of a sub section */
407 curlx_strcopy(cursub, sizeof(cursub), ptag, strlen(ptag));
408 state = STATE_INSUB;
409 if(!strcmp(curmain, main) && !strcmp(cursub, sub)) {
410 /* start of wanted part */
411 in_wanted_part = 1;
412 if(strstr(patt, "base64="))
413 /* bit rough test, but "mostly" functional, */
414 /* treat wanted part data as base64 encoded */
415 base64 = 1;
416 if(strstr(patt, "nonewline=")) {
417 show(("* setting nonewline\n"));
418 nonewline = 1;
419 }
420 }
421 continue;
422 }
423 }
425 if(in_wanted_part) {
426 show(("=> %s", buffer));
427 error = appenddata(outbuf, outlen, &outalloc, buffer, datalen, base64);
428 if(error)
429 break;
430 }
432 } /* while */
434 free(buffer);
436 if(error != GPE_OK) {
437 if(error == GPE_END_OF_FILE)
438 error = GPE_OK;
439 else {
440 free(*outbuf);
441 *outbuf = NULL;
442 *outlen = 0;
443 }
444 }
446 return error;
Diagnostics4 git calls · 320 ms
CallStatusSizeTime0320 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 · hit26 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=26
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.9 KiB292 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=292
git.response.bytes=4035
git.response.cache=MISS
git.response.duration_ms=292
git.fetch.wants=463e829497bd25f73be71cb2b7d0c69ecaaaff39
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=4035
git.pkt.payload.max=4014
git.sideband.band1.bytes=4013
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
a5e2d169bddccf3a
Request
59bc350e…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format