Artifactspublic-v0

curl

master
ply4 git calls191 ms289 KiB2 cachedprotocol v2
177 lines5.1 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/* <DESC>
25 * Stream-parse a document using the streaming Expat parser.
26 * </DESC>
27 */
28/* Written by David Strauss
29 *
30 * Expat => https://libexpat.github.io/
31 *
32 * gcc -Wall -I/usr/local/include xmlstream.c -lcurl -lexpat -o xmlstream
33 *
34 */
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
39#include <expat.h>
41#include <curl/curl.h>
43struct MemoryStruct {
44 char *memory;
45 size_t size;
46};
48struct ParserStruct {
49 int ok;
50 size_t tags;
51 size_t depth;
52 struct MemoryStruct characters;
53};
55static void startElement(void *userData, const XML_Char *name,
56 const XML_Char **atts)
58 struct ParserStruct *state = (struct ParserStruct *)userData;
59 state->tags++;
60 state->depth++;
62 (void)name;
63 (void)atts;
65 /* Get a clean slate for reading in character data. */
66 free(state->characters.memory);
67 state->characters.memory = NULL;
68 state->characters.size = 0;
71static void characterDataHandler(void *userData, const XML_Char *s, int len)
73 struct ParserStruct *state = (struct ParserStruct *)userData;
74 struct MemoryStruct *mem = &state->characters;
76 char *ptr = realloc(mem->memory, mem->size + (unsigned long)len + 1);
77 if(!ptr) {
78 /* Out of memory. */
79 fprintf(stderr, "Not enough memory (realloc returned NULL).\n");
80 state->ok = 0;
81 return;
82 }
84 mem->memory = ptr;
85 memcpy(&(mem->memory[mem->size]), s, len);
86 mem->size += (unsigned long)len;
87 mem->memory[mem->size] = 0;
90static void endElement(void *userData, const XML_Char *name)
92 struct ParserStruct *state = (struct ParserStruct *)userData;
93 state->depth--;
95 printf("%5lu %10lu %s\n", state->depth, state->characters.size, name);
98static size_t write_cb(void *contents, size_t length, size_t nmemb,
99 void *userp)
101 XML_Parser parser = (XML_Parser)userp;
102 size_t real_size = length * nmemb;
103 struct ParserStruct *state = (struct ParserStruct *)XML_GetUserData(parser);
105 /* Only parse if we are not already in a failure state. */
106 if(state->ok && XML_Parse(parser, contents, (int)real_size, 0) == 0) {
107 enum XML_Error error_code = XML_GetErrorCode(parser);
108 fprintf(stderr, "Parsing response buffer of length %lu failed"
109 " with error code %d (%s).\n",
110 real_size, error_code, XML_ErrorString(error_code));
111 state->ok = 0;
112 }
114 return real_size;
117int main(void)
119 CURL *curl;
121 CURLcode result = curl_global_init(CURL_GLOBAL_ALL);
122 if(result != CURLE_OK)
123 return (int)result;
125 /* Initialize a libcurl handle. */
126 curl = curl_easy_init();
127 if(curl) {
128 XML_Parser parser;
129 struct ParserStruct state;
131 /* Initialize the state structure for parsing. */
132 memset(&state, 0, sizeof(state));
133 state.ok = 1;
135 /* Initialize a namespace-aware parser. */
136 parser = XML_ParserCreateNS(NULL, '\0');
137 XML_SetUserData(parser, &state);
138 XML_SetElementHandler(parser, startElement, endElement);
139 XML_SetCharacterDataHandler(parser, characterDataHandler);
141 curl_easy_setopt(curl, CURLOPT_URL,
142 "https://www.w3schools.com/xml/simple.xml");
143 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
144 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)parser);
146 printf("Depth Characters Closing Tag\n");
148 /* Perform the request and any follow-up parsing. */
149 result = curl_easy_perform(curl);
150 if(result != CURLE_OK) {
151 fprintf(stderr, "curl_easy_perform() failed: %s\n",
152 curl_easy_strerror(result));
153 }
154 else if(state.ok) {
155 /* Expat requiresult one final call to finalize parsing. */
156 if(XML_Parse(parser, NULL, 0, 1) == 0) {
157 enum XML_Error error_code = XML_GetErrorCode(parser);
158 fprintf(stderr, "Finalizing parsing failed with error code %d (%s).\n",
159 error_code, XML_ErrorString(error_code));
160 }
161 else {
162 printf(" --------------\n");
163 printf(" %lu tags total\n", state.tags);
164 }
165 }
167 /* Clean up. */
168 free(state.characters.memory);
169 XML_ParserFree(parser);
171 curl_easy_cleanup(curl);
172 }
174 curl_global_cleanup();
176 return (int)result;
Diagnostics4 git calls · 191 ms
CallStatusSizeTime0191 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
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=186
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
fetch2002.0 KiB186 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2030
git.response.cache=MISS
git.response.duration_ms=186
git.fetch.wants=2ad132f2828b97b6befa210b0edb967cd7d4166a
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=2030
git.pkt.payload.max=2009
git.sideband.band1.bytes=2008
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
a5e21cb2dfbdecd4
Request
9b86b8f0…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format