Artifactspublic-v0

curl

master
ply4 git calls32 ms291 KiB3 cachedprotocol v2
598 lines15 KiBexecutableRaw
1#!/usr/bin/env perl
2#***************************************************************************
3# _ _ ____ _
4# Project ___| | | | _ \| |
5# / __| | | | |_) | |
6# | (__| |_| | _ <| |___
7# \___|\___/|_| \_\_____|
8#
9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11# This software is licensed as described in the file COPYING, which
12# you should have received as part of this distribution. The terms
13# are also available at https://curl.se/docs/copyright.html.
15# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16# copies of the Software, and permit persons to whom the Software is
17# furnished to do so, under the terms of the COPYING file.
19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20# KIND, either express or implied.
22# SPDX-License-Identifier: curl
24###########################################################################
26=begin comment
28Converts a curldown file to nroff (man page).
30=end comment
31=cut
33use strict;
34use warnings;
36my $cd2nroff = "0.1"; # to keep check
37my $dir;
38my $extension;
39my $keepfilename;
41while(@ARGV) {
42 if($ARGV[0] eq "-d") {
43 shift @ARGV;
44 $dir = shift @ARGV;
45 }
46 elsif($ARGV[0] eq "-e") {
47 shift @ARGV;
48 $extension = shift @ARGV;
49 }
50 elsif($ARGV[0] eq "-k") {
51 shift @ARGV;
52 $keepfilename = 1;
53 }
54 elsif($ARGV[0] eq "-h") {
55 print <<HELP
56Usage: cd2nroff [options] [file.md]
58-d <dir> Write the output to the filename from the meta-data in the
59 specified directory, instead of writing to stdout
60-e <ext> If -d is used, this option can provide an added "extension", arbitrary
61 text really, to append to the filename.
62-h This help text
63-v Show version then exit
64HELP
65 ;
66 exit 0;
67 }
68 elsif($ARGV[0] eq "-v") {
69 print "cd2nroff version $cd2nroff\n";
70 exit 0;
71 }
72 else {
73 last;
74 }
77use POSIX qw(strftime);
78my @ts;
79if(defined($ENV{SOURCE_DATE_EPOCH})) {
80 @ts = gmtime($ENV{SOURCE_DATE_EPOCH});
82else {
83 @ts = localtime;
85my $date = strftime "%Y-%m-%d", @ts;
87sub outseealso {
88 my (@sa) = @_;
89 my $comma = 0;
90 my @o;
91 push @o, ".SH SEE ALSO\n";
92 for my $s (sort @sa) {
93 push @o, sprintf "%s.BR $s", $comma ? ",\n" : "";
94 $comma = 1;
95 }
96 push @o, "\n";
97 return @o;
100sub outprotocols {
101 my (@p) = @_;
102 my $comma = 0;
103 my @o;
104 my $tls = 0;
105 push @o, ".SH PROTOCOLS\n";
107 my @s = sort @p;
108 push @o, "This functionality affects ";
109 for my $e (sort @s) {
110 if($e eq "TLS") {
111 $tls = 1;
112 }
113 else {
114 push @o, sprintf "%s%s",
115 $comma ? (($e eq $s[-1]) ? " and " : ", "): "",
116 lc($e);
117 $comma = 1;
118 }
119 }
120 if($tls) {
121 push @o, sprintf
122 "%sall TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.",
123 $comma ? " and ": " ";
124 }
125 if($#s == 0) {
126 if($s[0] eq "All") {
127 push @o, " supported protocols";
128 }
129 else {
130 push @o, " only";
131 }
132 }
133 push @o, "\n";
134 return @o;
137sub outtls {
138 my (@t) = @_;
139 my $comma = 0;
140 my @o;
141 if($t[0] eq "All") {
142 push @o, "\nAll TLS backends support this option.";
143 }
144 elsif($t[0] eq "none") {
145 push @o, "\nNo TLS backend supports this option.";
146 }
147 else {
148 push @o, "\nThis option works only with the following TLS backends:\n";
149 my @s = sort @t;
150 for my $e (@s) {
151 push @o, sprintf "%s$e",
152 $comma ? (($e eq $s[-1]) ? " and " : ", "): "";
153 $comma = 1;
154 }
155 }
156 push @o, "\n";
157 return @o;
160my %knownprotos = (
161 'DICT' => 1,
162 'FILE' => 1,
163 'FTP' => 1,
164 'FTPS' => 1,
165 'GOPHER' => 1,
166 'GOPHERS' => 1,
167 'HTTP' => 1,
168 'HTTPS' => 1,
169 'IMAP' => 1,
170 'IMAPS' => 1,
171 'LDAP' => 1,
172 'LDAPS' => 1,
173 'MQTT' => 1,
174 'POP3' => 1,
175 'POP3S' => 1,
176 'RTSP' => 1,
177 'SCP' => 1,
178 'SFTP' => 1,
179 'SMTP' => 1,
180 'SMTPS' => 1,
181 'TELNET' => 1,
182 'TFTP' => 1,
183 'WS' => 1,
184 'WSS' => 1,
185 'TLS' => 1,
186 'TCP' => 1,
187 'QUIC' => 1,
188 'All' => 1
189 );
191my %knowntls = (
192 'GnuTLS' => 1,
193 'mbedTLS' => 1,
194 'OpenSSL' => 1,
195 'Rustls' => 1,
196 'Schannel' => 1,
197 'wolfSSL' => 1,
198 'All' => 1,
199 'none' => 1,
200 );
202sub quoted {
203 my ($d) = @_;
205 # in verbatim/quoted blocks, make backslashes literal
206 $d =~ s/\\/\\\\/g;
208 # lines starting with a period or apostrophe need it escaped
209 $d =~ s/^([.'])/\\&$1/;
210 return $d;
213sub single {
214 my @seealso;
215 my @proto;
216 my @tls;
217 my $d;
218 my ($f) = @_;
219 my $copyright;
220 my $errors = 0;
221 my $fh;
222 my $line;
223 my $list;
224 my $tlslist;
225 my $section;
226 my $source;
227 my $addedin;
228 my $spdx;
229 my $start = 0;
230 my $title;
232 if(defined($f)) {
233 if(!open($fh, "<:crlf", $f)) {
234 print STDERR "cd2nroff failed to open '$f' for reading: $!\n";
235 return 1;
236 }
237 }
238 else {
239 $f = "STDIN";
240 $fh = \*STDIN;
241 binmode($fh, ":crlf");
242 }
243 while(<$fh>) {
244 $line++;
245 if(!$start) {
246 if(/^---/) {
247 # header starts here
248 $start = 1;
249 }
250 next;
251 }
252 if(/^Title: *(.*)/i) {
253 $title = $1;
254 }
255 elsif(/^Section: *(.*)/i) {
256 $section = $1;
257 }
258 elsif(/^Source: *(.*)/i) {
259 $source = $1;
260 }
261 elsif(/^See-also: +(.*)/i) {
262 $list = 1; # 1 for see-also
263 push @seealso, $1;
264 }
265 elsif(/^See-also: */i) {
266 if($seealso[0]) {
267 print STDERR "$f:$line:1:ERROR: bad See-Also, needs list\n";
268 return 2;
269 }
270 $list = 1; # 1 for see-also
271 }
272 elsif(/^Protocol:/i) {
273 $list = 2; # 2 for protocol
274 }
275 elsif(/^TLS-backend:/i) {
276 $list = 3; # 3 for TLS backend
277 }
278 elsif(/^Added-in: *(.*)/i) {
279 $addedin = $1;
280 if(($addedin !~ /^[0-9.]+[0-9]\z/) &&
281 ($addedin ne "n/a")) {
282 print STDERR "$f:$line:1:ERROR: invalid version number in Added-in line: $addedin\n";
283 return 2;
284 }
285 }
286 elsif(/^ +- (.*)/i) {
287 # the only lists we support are see-also and protocol
288 if($list == 1) {
289 push @seealso, $1;
290 }
291 elsif($list == 2) {
292 push @proto, $1;
293 }
294 elsif($list == 3) {
295 push @tls, $1;
296 }
297 else {
298 print STDERR "$f:$line:1:ERROR: list item without owner?\n";
299 return 2;
300 }
301 }
302 # REUSE-IgnoreStart
303 elsif(/^C: (.*)/i) {
304 $copyright = $1;
305 }
306 elsif(/^SPDX-License-Identifier: (.*)/i) {
307 $spdx = $1;
308 }
309 # REUSE-IgnoreEnd
310 elsif(/^---/) {
311 # end of the header section
312 if(!$title) {
313 print STDERR "$f:$line:1:ERROR: no 'Title:' in $f\n";
314 return 1;
315 }
316 if(!$section) {
317 print STDERR "$f:$line:1:ERROR: no 'Section:' in $f\n";
318 return 2;
319 }
320 if(!$source) {
321 print STDERR "$f:$line:1:ERROR: no 'Source:' in $f\n";
322 return 2;
323 }
324 if(($source eq "libcurl") && !$addedin) {
325 print STDERR "$f:$line:1:ERROR: no 'Added-in:' in $f\n";
326 return 2;
327 }
328 if(!$seealso[0]) {
329 print STDERR "$f:$line:1:ERROR: no 'See-also:' present\n";
330 return 2;
331 }
332 if(!$copyright) {
333 print STDERR "$f:$line:1:ERROR: no 'C:' field present\n";
334 return 2;
335 }
336 if(!$spdx) {
337 # REUSE-IgnoreStart
338 print STDERR "$f:$line:1:ERROR: no 'SPDX-License-Identifier:' field present\n";
339 # REUSE-IgnoreEnd
340 return 2;
341 }
342 if($section == 3) {
343 if(!$proto[0]) {
344 printf STDERR "$f:$line:1:ERROR: missing Protocol:\n";
345 exit 2;
346 }
347 my $tls = 0;
348 for my $p (@proto) {
349 if($p eq "TLS") {
350 $tls = 1;
351 }
352 if(!$knownprotos{$p}) {
353 printf STDERR "$f:$line:1:ERROR: invalid protocol used: $p:\n";
354 exit 2;
355 }
356 }
357 # This is for TLS, require TLS-backend:
358 if($tls) {
359 if(!$tls[0]) {
360 printf STDERR "$f:$line:1:ERROR: missing TLS-backend:\n";
361 exit 2;
362 }
363 for my $t (@tls) {
364 if(!$knowntls{$t}) {
365 printf STDERR "$f:$line:1:ERROR: invalid TLS backend: $t:\n";
366 exit 2;
367 }
368 }
369 }
370 }
371 last;
372 }
373 else {
374 chomp;
375 print STDERR "$f:$line:1:ERROR: unrecognized header keyword: '$_'\n";
376 $errors++;
377 }
378 }
380 if(!$start) {
381 print STDERR "$f:$line:1:ERROR: no header present\n";
382 return 2;
383 }
385 my @desc;
386 my $quote = 0;
387 my $blankline = 0;
388 my $header = 0;
390 # cut off the leading path from the filename, if any
391 $f =~ s/^(.*[\\\/])//;
393 push @desc, ".\\\" generated by cd2nroff $cd2nroff from $f\n";
394 push @desc, ".TH $title $section \"$date\" $source\n";
395 while(<$fh>) {
396 $line++;
398 $d = $_;
400 if($quote) {
401 if($quote == 4) {
402 # remove the indentation
403 if($d =~ /^ (.*)/) {
404 $d = quoted($1);
405 push @desc, "$d\n";
406 next;
407 }
408 # end of quote
409 $quote = 0;
410 push @desc, ".fi\n";
412 # fall-through
413 }
414 else {
415 if(/^~~~/) {
416 # end of quote
417 $quote = 0;
418 push @desc, ".fi\n";
419 next;
420 }
421 $d = quoted($d);
422 push @desc, $d;
423 next;
424 }
425 }
427 # remove single line HTML comments
428 $d =~ s/<!--.*?-->//g;
430 # **bold**
431 $d =~ s/\*\*(\S.*?)\*\*/\\fB$1\\fP/g;
432 # *italics*
433 $d =~ s/\*(\w.*?[\w)])\*/\\fI$1\\fP/g;
435 my $back = $d;
437 # remove all backticked pieces
438 $back =~ s/\`(.*?)\`//g;
440 if($back =~ /[^\\][\<\>]/) {
441 print STDERR "$f:$line:1:ERROR: un-escaped < or > used\n";
442 $errors++;
443 }
444 # convert backslash-'<' or '> to the second character
445 $d =~ s/\\([<>])/$1/g;
447 # mentions of curl symbols with man pages use italics by default
448 $d =~ s/((lib|)curl([^ ]*\(3\)))/\\fI$1\\fP/gi;
450 # backticked becomes italics
451 $d =~ s/\`(.*?)\`/\\fI$1\\fP/g;
453 if(/^## (.*)/) {
454 my $word = $1;
455 # if there are enclosing quotes, remove them first
456 $word =~ s/[\"\'\`](.*)[\"\'\`]\z/$1/;
458 # enclose in double quotes if there is a space present
459 if($word =~ / /) {
460 push @desc, ".IP \"$word\"\n";
461 }
462 else {
463 push @desc, ".IP $word\n";
464 }
465 $header = 1;
466 }
467 elsif(/^##/) {
468 # end of IP sequence
469 push @desc, ".PP\n";
470 $header = 1;
471 }
472 elsif(/^# (.*)/) {
473 my $word = $1;
474 # if there are enclosing quotes, remove them first
475 $word =~ s/[\"\'](.*)[\"\']\z/$1/;
477 if($word eq "PROTOCOLS") {
478 print STDERR "$f:$line:1:WARN: PROTOCOLS section in source file\n";
479 }
480 elsif($word eq "AVAILABILITY") {
481 print STDERR "$f:$line:1:WARN: AVAILABILITY section in source file\n";
482 }
483 elsif($word eq "%PROTOCOLS%") {
484 # insert the generated PROTOCOLS section
485 push @desc, outprotocols(@proto);
487 if($proto[0] eq "TLS") {
488 push @desc, outtls(@tls);
489 }
490 $header = 1;
491 next;
492 }
493 elsif($word eq "%AVAILABILITY%") {
494 if($addedin ne "n/a") {
495 # insert the generated AVAILABILITY section
496 push @desc, ".SH AVAILABILITY\n";
497 push @desc, "Added in curl $addedin\n";
498 }
499 $header = 1;
500 next;
501 }
502 push @desc, ".SH $word\n";
503 $header = 1;
504 }
505 elsif(/^~~~c/) {
506 # start of a code section, not indented
507 $quote = 1;
508 push @desc, "\n" if($blankline && !$header);
509 $header = 0;
510 push @desc, ".nf\n";
511 }
512 elsif(/^~~~/) {
513 # start of a quote section; not code, not indented
514 $quote = 1;
515 push @desc, "\n" if($blankline && !$header);
516 $header = 0;
517 push @desc, ".nf\n";
518 }
519 elsif(/^ (.*)/) {
520 # quoted, indented by 4 space
521 $quote = 4;
522 push @desc, "\n" if($blankline && !$header);
523 $header = 0;
524 my $d = quoted($1);
525 push @desc, ".nf\n$d\n";
526 }
527 elsif(/^[ \t]*\n/) {
528 # count and ignore blank lines
529 $blankline++;
530 }
531 else {
532 # do not output newlines if this is the first content after a
533 # header
534 push @desc, "\n" if($blankline && !$header);
535 $blankline = 0;
536 $header = 0;
538 # quote minuses in the output
539 $d =~ s/([^\\])-/$1\\-/g;
540 # replace single quotes
541 $d =~ s/\'/\\(aq/g;
542 # handle double quotes first on the line
543 $d =~ s/^(\s*)\"/$1\\&\"/;
545 # lines starting with a period needs it escaped
546 $d =~ s/^\./\\&./;
548 if($d =~ /^(.*) /) {
549 printf STDERR "$f:$line:%d:ERROR: 2 spaces detected\n",
550 length($1);
551 $errors++;
552 }
553 if($d =~ /^[ \t]*\n/) {
554 # replaced away all contents
555 $blankline = 1;
556 }
557 else {
558 push @desc, $d;
559 }
560 }
561 }
562 if($fh != \*STDIN) {
563 close($fh);
564 }
565 push @desc, outseealso(@seealso);
566 if($dir) {
567 if($keepfilename) {
568 $title = $f;
569 $title =~ s/\.[^.]*$//;
570 }
571 my $outfile = "$dir/$title.$section";
572 if(defined($extension)) {
573 $outfile .= $extension;
574 }
575 if(!open(O, ">", $outfile)) {
576 print STDERR "Failed to open $outfile : $!\n";
577 return 1;
578 }
579 print O @desc;
580 close(O);
581 }
582 else {
583 print @desc;
584 }
585 return $errors;
588if(@ARGV) {
589 for my $f (@ARGV) {
590 my $r = single($f);
591 if($r) {
592 exit $r;
593 }
594 }
596else {
597 exit single();
Diagnostics4 git calls · 32 ms
CallStatusSizeTime032 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
fetch2004.6 KiB · hit27 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=27
git.response.bytes=4672
git.response.cache=HIT
git.response.duration_ms=27
git.fetch.wants=6c30c4def2cd60f58eea6b596593552f0d6069ea
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=4672
git.pkt.payload.max=4651
git.sideband.band1.bytes=4650
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
a5e1dd98bc2aecfa
Request
c7c33bff…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format