Artifactspublic-v0

curl

master
ply4 git calls61 ms289 KiB3 cachedprotocol v2
230 lines5.6 KiBRaw

String parsing with strparse

The functions take input via a pointer to a pointer, which allows the functions to advance the pointer on success which then by extension allows "chaining" of functions like this example that gets a word, a space and then a second word:

c
if(curlx_str_word(&line, &word1, MAX) ||
   curlx_str_singlespace(&line) ||
   curlx_str_word(&line, &word2, MAX))
  fprintf(stderr, "ERROR\n");

The input pointer must point to a null-terminated buffer area or these functions risk continuing "off the edge".

Strings

The functions that return string information does so by populating a struct Curl_str:

c
struct Curl_str {
  char *str;
  size_t len;
};

Access the struct fields with curlx_str() for the pointer and curlx_strlen() for the length rather than using the struct fields directly.

curlx_str_init

c
void curlx_str_init(struct Curl_str *out)

This initiates a string struct. The parser functions that store info in strings always init the string themselves, so this stand-alone use is often not necessary.

curlx_str_assign

c
void curlx_str_assign(struct Curl_str *out, const char *str, size_t len)

Set a pointer and associated length in the string struct.

curlx_str_word

c
int curlx_str_word(char **linep, struct Curl_str *out, const size_t max);

Get a sequence of bytes until the first space or the end of the string. Return non-zero on error. There is no way to include a space in the word, no sort of escaping. The word must be at least one byte, otherwise it is considered an error.

max is the longest accepted word, or it returns error.

On a successful return, linep is updated to point to the byte immediately following the parsed word.

curlx_str_until

c
int curlx_str_until(char **linep, struct Curl_str *out, const size_t max,
                   char delim);

Like curlx_str_word but instead of parsing to space, it parses to a given custom delimiter non-zero byte delim.

max is the longest accepted word, or it returns error.

The parsed word must be at least one byte, otherwise it is considered an error.

curlx_str_untilnl

c
int curlx_str_untilnl(char **linep, struct Curl_str *out, const size_t max);

Like curlx_str_untilnl but instead parses until it finds a "newline byte". That means either a CR (ASCII 13) or an LF (ASCII 10) octet.

max is the longest accepted word, or it returns error.

The parsed word must be at least one byte, otherwise it is considered an error.

curlx_str_cspn

c
int curlx_str_cspn(const char **linep, struct Curl_str *out, const char *cspn);

Get a sequence of characters until one of the bytes in the cspn string matches. Similar to the strcspn function.

curlx_str_quotedword

c
int curlx_str_quotedword(char **linep, struct Curl_str *out, const size_t max);

Get a "quoted" word. This means everything that is provided within a leading and an ending double quote character. No escaping possible.

max is the longest accepted word, or it returns error.

The parsed word must be at least one byte, otherwise it is considered an error.

curlx_str_single

c
int curlx_str_single(char **linep, char byte);

Advance over a single character provided in byte. Return non-zero on error.

curlx_str_singlespace

c
int curlx_str_singlespace(char **linep);

Advance over a single ASCII space. Return non-zero on error.

curlx_str_passblanks

c
void curlx_str_passblanks(char **linep);

Advance over all spaces and tabs.

curlx_str_trimblanks

c
void curlx_str_trimblanks(struct Curl_str *out);

Trim off blanks (spaces and tabs) from the start and the end of the given string.

curlx_str_number

c
int curlx_str_number(char **linep, curl_size_t *nump, size_t max);

Get an unsigned decimal number not larger than max. Leading zeroes are swallowed. Return non-zero on error. Returns error if there was not a single digit.

curlx_str_numblanks

c
int curlx_str_numblanks(char **linep, curl_size_t *nump);

Get an unsigned 63-bit decimal number. Leading blanks and zeroes are skipped. Returns non-zero on error. Returns error if there was not a single digit.

curlx_str_hex

c
int curlx_str_hex(char **linep, curl_size_t *nump, size_t max);

Get an unsigned hexadecimal number not larger than max. Leading zeroes are swallowed. Return non-zero on error. Returns error if there was not a single digit. Does not handled 0x prefix.

curlx_str_octal

c
int curlx_str_octal(char **linep, curl_size_t *nump, size_t max);

Get an unsigned octal number not larger than max. Leading zeroes are swallowed. Return non-zero on error. Returns error if there was not a single digit.

curlx_str_newline

c
int curlx_str_newline(char **linep);

Check for a single CR or LF. Return non-zero on error */

curlx_str_casecompare

c
int curlx_str_casecompare(struct Curl_str *str, const char *check);

Returns true if the provided string in the str argument matches the check string case insensitively.

curlx_str_cmp

c
int curlx_str_cmp(struct Curl_str *str, const char *check);

Returns true if the provided string in the str argument matches the check string case sensitively. This is not the same return code as strcmp.

curlx_str_nudge

c
int curlx_str_nudge(struct Curl_str *str, size_t num);

Removes num bytes from the beginning (left) of the string kept in str. If num is larger than the string, it instead returns an error.

1<!--
2Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
4SPDX-License-Identifier: curl
5-->
7# String parsing with `strparse`
9The functions take input via a pointer to a pointer, which allows the
10functions to advance the pointer on success which then by extension allows
11"chaining" of functions like this example that gets a word, a space and then a
12second word:
14~~~c
15if(curlx_str_word(&line, &word1, MAX) ||
16 curlx_str_singlespace(&line) ||
17 curlx_str_word(&line, &word2, MAX))
18 fprintf(stderr, "ERROR\n");
19~~~
21The input pointer **must** point to a null-terminated buffer area or these
22functions risk continuing "off the edge".
24## Strings
26The functions that return string information does so by populating a
27`struct Curl_str`:
29~~~c
30struct Curl_str {
31 char *str;
32 size_t len;
33};
34~~~
36Access the struct fields with `curlx_str()` for the pointer and `curlx_strlen()`
37for the length rather than using the struct fields directly.
39## `curlx_str_init`
41~~~c
42void curlx_str_init(struct Curl_str *out)
43~~~
45This initiates a string struct. The parser functions that store info in
46strings always init the string themselves, so this stand-alone use is often
47not necessary.
49## `curlx_str_assign`
51~~~c
52void curlx_str_assign(struct Curl_str *out, const char *str, size_t len)
53~~~
55Set a pointer and associated length in the string struct.
57## `curlx_str_word`
59~~~c
60int curlx_str_word(char **linep, struct Curl_str *out, const size_t max);
61~~~
63Get a sequence of bytes until the first space or the end of the string. Return
64non-zero on error. There is no way to include a space in the word, no sort of
65escaping. The word must be at least one byte, otherwise it is considered an
66error.
68`max` is the longest accepted word, or it returns error.
70On a successful return, `linep` is updated to point to the byte immediately
71following the parsed word.
73## `curlx_str_until`
75~~~c
76int curlx_str_until(char **linep, struct Curl_str *out, const size_t max,
77 char delim);
78~~~
80Like `curlx_str_word` but instead of parsing to space, it parses to a given
81custom delimiter non-zero byte `delim`.
83`max` is the longest accepted word, or it returns error.
85The parsed word must be at least one byte, otherwise it is considered an
86error.
88## `curlx_str_untilnl`
90~~~c
91int curlx_str_untilnl(char **linep, struct Curl_str *out, const size_t max);
92~~~
94Like `curlx_str_untilnl` but instead parses until it finds a "newline byte".
95That means either a CR (ASCII 13) or an LF (ASCII 10) octet.
97`max` is the longest accepted word, or it returns error.
99The parsed word must be at least one byte, otherwise it is considered an
100error.
102## `curlx_str_cspn`
104~~~c
105int curlx_str_cspn(const char **linep, struct Curl_str *out, const char *cspn);
106~~~
108Get a sequence of characters until one of the bytes in the `cspn` string
109matches. Similar to the `strcspn` function.
111## `curlx_str_quotedword`
113~~~c
114int curlx_str_quotedword(char **linep, struct Curl_str *out, const size_t max);
115~~~
117Get a "quoted" word. This means everything that is provided within a leading
118and an ending double quote character. No escaping possible.
120`max` is the longest accepted word, or it returns error.
122The parsed word must be at least one byte, otherwise it is considered an
123error.
125## `curlx_str_single`
127~~~c
128int curlx_str_single(char **linep, char byte);
129~~~
131Advance over a single character provided in `byte`. Return non-zero on error.
133## `curlx_str_singlespace`
135~~~c
136int curlx_str_singlespace(char **linep);
137~~~
139Advance over a single ASCII space. Return non-zero on error.
141## `curlx_str_passblanks`
143~~~c
144void curlx_str_passblanks(char **linep);
145~~~
147Advance over all spaces and tabs.
149## `curlx_str_trimblanks`
151~~~c
152void curlx_str_trimblanks(struct Curl_str *out);
153~~~
155Trim off blanks (spaces and tabs) from the start and the end of the given
156string.
158## `curlx_str_number`
160~~~c
161int curlx_str_number(char **linep, curl_size_t *nump, size_t max);
162~~~
164Get an unsigned decimal number not larger than `max`. Leading zeroes are
165swallowed. Return non-zero on error. Returns error if there was not a single
166digit.
168## `curlx_str_numblanks`
170~~~c
171int curlx_str_numblanks(char **linep, curl_size_t *nump);
172~~~
174Get an unsigned 63-bit decimal number. Leading blanks and zeroes are skipped.
175Returns non-zero on error. Returns error if there was not a single digit.
177## `curlx_str_hex`
179~~~c
180int curlx_str_hex(char **linep, curl_size_t *nump, size_t max);
181~~~
183Get an unsigned hexadecimal number not larger than `max`. Leading zeroes are
184swallowed. Return non-zero on error. Returns error if there was not a single
185digit. Does *not* handled `0x` prefix.
187## `curlx_str_octal`
189~~~c
190int curlx_str_octal(char **linep, curl_size_t *nump, size_t max);
191~~~
193Get an unsigned octal number not larger than `max`. Leading zeroes are
194swallowed. Return non-zero on error. Returns error if there was not a single
195digit.
197## `curlx_str_newline`
199~~~c
200int curlx_str_newline(char **linep);
201~~~
203Check for a single CR or LF. Return non-zero on error */
205## `curlx_str_casecompare`
207~~~c
208int curlx_str_casecompare(struct Curl_str *str, const char *check);
209~~~
211Returns true if the provided string in the `str` argument matches the `check`
212string case insensitively.
214## `curlx_str_cmp`
216~~~c
217int curlx_str_cmp(struct Curl_str *str, const char *check);
218~~~
220Returns true if the provided string in the `str` argument matches the `check`
221string case sensitively. This is *not* the same return code as `strcmp`.
223## `curlx_str_nudge`
225~~~c
226int curlx_str_nudge(struct Curl_str *str, size_t num);
227~~~
229Removes `num` bytes from the beginning (left) of the string kept in `str`. If
230`num` is larger than the string, it instead returns an error.
Diagnostics4 git calls · 61 ms
CallStatusSizeTime061 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
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 · 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=56
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
fetch2001.8 KiB · hit56 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1853
git.response.cache=HIT
git.response.duration_ms=56
git.fetch.wants=8d0e8ba515eacc3a88af45b56f69bb78cb99d7df
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=1853
git.pkt.payload.max=1832
git.sideband.band1.bytes=1831
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
a5e2e529fc5a2947
Request
0e2c7528…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format