interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / browse / c1_page.om

1248 lines · 20842 bytes Raw Blame History
1note browse/c1_page.om: shared page pieces, the repo home, /tree, /blob and /raw (ForgeBrowse).
2note Every handler validates first and writes nothing before it decides; a failure returns the
3note status with fob empty, so the server renders its own error page.
4global gbf ulong 16
5global gbfn ulong 1
6global gbrm uchar 256
7global gbrml ulong 1
8global gbrmk ulong 1
9global gbx uchar 16
10global gbxl ulong 1
11global gbpg ulong 1
12global gbboid uchar 40
13global gbbsz ulong 1
14note gbbig: the blob is larger than fxo (16 MiB); fxo then holds cat-file -s, not the file
15global gbbig ulong 1
16const BRMAXE ulong 5000
17const BRSHOW ulong 2097152
18note BRRAWMX: the largest blob /raw/ serves (the contract's kind-3 file cap, 512 MiB)
19const BRRAWMX ulong 536870912
20text tbsz "-s"
21text tblstr "ls-tree"
22text tbz "-z"
23text tbll "-l"
24text tbcatf "cat-file"
25text tbt "-t"
26text tbblob "blob"
27text tbtree "tree"
28text tbraw "raw"
29text tbblame "blame"
30text tbcmts "commits"
31text tbcmt "commit"
32text tblog "log"
33text tbn1 "-n"
34text tbone "1"
35text tbdd "--"
36text tbfmtc "--format=%H%x1f%an%x1f%at%x1f%s"
37text tbskip "--skip="
38text tbplain "plain"
39text tbpage "page"
40text tbcr1 "<p class=\"crumbs\"><a href=\""
41text tbsl " / "
42text tbb "<b>"
43text tbbe "</b>"
44text tbpe "</p>\n"
45text tbbar1 "<div class=\"bar\"><span class=\"ref\">"
46text tbkbr "branch"
47text tbktag "tag"
48text tbkcmt "commit"
49text tbcode " <code>"
50text tbcodee "</code></span> "
51text tbbrs "/branches\">Branches</a> "
52text tbtgs "/tags\">Tags</a> "
53text tbhist "\">History</a> "
54text tbdive "</div>\n"
55text tblat1 "<div class=\"box latest\"><a class=\"mono\" href=\""
56text tblat2 "</a> "
57text tblat3 " <span class=\"meta\">"
58text tblat4 " committed "
59text tblat5 "</span></div>\n"
60text tbtab1 "<table class=\"files\"><tbody>\n"
61text tbtab2 "</tbody></table>\n"
62text tbtr1 "<tr><td><a class=\"dir\" href=\""
63text tbtr1f "<tr><td><a class=\"file\" href=\""
64text tbtrs "/</a></td><td></td></tr>\n"
65text tbtrf "</a></td><td class=\"sz\">"
66text tbtre "</td></tr>\n"
67text tbtrsm "<tr><td><span class=\"muted\">"
68text tbtrsm2 " @ "
69text tbtrsm3 "</span></td><td></td></tr>\n"
70text tbup "<tr><td><a class=\"dir\" href=\""
71text tbup2 "\">..</a></td><td></td></tr>\n"
72text tbmany "<p class=\"muted\">Listing cut at 5000 entries.</p>\n"
73text tbempty "<p class=\"muted\">This directory is empty.</p>\n"
74text tbrd1 "<div class=\"box readme\"><p class=\"meta\">"
75text tbrd2 "</p>\n<article class=\"md\">\n"
76text tbrd3 "</article></div>\n"
77text tbrd4 "</p>\n<pre>"
78text tbrd5 "</pre></div>\n"
79text tbreadme "readme"
80text tbxmd "md"
81text tbxmkd "markdown"
82text tbxtxt "txt"
83text tbinfo1 "<div class=\"bar\"><span class=\"meta\">"
84text tbinfo2 " lines &#183; "
85text tbinfo3 " bytes</span> "
86text tbinfo4 "\">Raw</a> "
87text tbinfo5 "\">Blame</a> "
88text tbinfo6 "?plain=1\">Source</a> "
89text tbinfo7 "\">Rendered</a> "
90text tbimg1 "<p class=\"img\"><img src=\""
91text tbimg2 "\" alt=\""
92text tbimg3 "\"></p>\n"
93text tbbin1 "<p class=\"muted\">Binary file not shown. <a href=\""
94text tbbin2 "\">Download</a></p>\n"
95text tbbig1 "<p class=\"muted\">This file is too large to show here. <a href=\""
96text tbbig2 "\">View it raw</a>.</p>\n"
97text tbcd1 "<table class=\"code\"><tbody>\n"
98text tbcd2 "<tr id=\"L"
99text tbcd3 "\"><td class=\"ln\"><a href=\"#L"
100text tbcd4 "</a></td><td class=\"lc\">"
101text tbcd5 "</td></tr>\n"
102text tbart1 "<article class=\"md\">\n"
103text tbart2 "</article>\n"
104text tbctxt "text/plain; charset=utf-8"
105text tbcoct "application/octet-stream"
106text tbcpng "image/png"
107text tbcjpg "image/jpeg"
108text tbcgif "image/gif"
109text tbcwebp "image/webp"
110text tbcsvg "image/svg+xml"
111text tbcico "image/x-icon"
112text tbcbmp "image/bmp"
113text tbcpdf "application/pdf"
114text tbxpng "png"
115text tbxjpg "jpg"
116text tbxjpeg "jpeg"
117text tbxgif "gif"
118text tbxwebp "webp"
119text tbxsvg "svg"
120text tbxico "ico"
121text tbxbmp "bmp"
122text tbxpdf "pdf"
123text tbatt "attachment; filename=\""
124text tbbig3 "<p class=\"muted\">This file is too large to show here.</p>\n"
125text tbh2 "<h2>"
126text tbh2e "</h2>\n"
127text tbtfil "Files"
128text tbtblob "File"
129text tbtsep " - "
130note ---- small shared helpers
131note brerr: drop any output and answer st (the server renders the error page)
132fn brerr st ulong to long
133put fobl 0 0
134put fkind 0 0
135ret long st
136end
137note brknum: append the decimal v to the open argv argument
138fn brknum v ulong to void
139w = v
140p = ulong 1
141while le mul p 10 w bound 20
142p = mul p 10
143end
144while gt p 0 bound 21
145fkc uchar add div w p 48
146w = rem w p
147p = div p 10
148end
149end
150note brsplit: split fxo[a, e) at byte c into gbf (start, end pairs, at most 8); returns the count
151fn brsplit a ulong e ulong c uchar to ulong
152k = ulong 0
153s = a
154i = a
155while lt i e bound BRBIG
156if eq get fxo i c
157if lt k 7
158put gbf mul k 2 s
159put gbf add mul k 2 1 i
160k = add k 1
161s = add i 1
162end
163end
164i = add i 1
165end
166put gbf mul k 2 s
167put gbf add mul k 2 1 e
168k = add k 1
169put gbfn 0 k
170ret k
171end
172fn brfa k ulong to ulong
173ret get gbf mul k 2
174end
175fn brfl k ulong to ulong
176if ge k get gbfn 0
177ret 0
178end
179ret sub get gbf add mul k 2 1 get gbf mul k 2
180end
181note brfne: fields j and k hold different bytes (a committer named differently from the author)
182fn brfne j ulong k ulong to bool
183n = brfl j
184if ne n brfl k
185ret true
186end
187a = brfa j
188b = brfa k
189for i ulong n bound BRBIG
190if ne get fxo add a i get fxo add b i
191ret true
192end
193end
194ret false
195end
196note brfesc: html-escape field k; brfurl: url-encode field k
197fn brfesc k ulong to void
198fxesc brfa k brfl k
199end
200fn brfurl k ulong to void
201bruxo brfa k brfl k
202end
203note brti: page title "<t>[: <path>] - owner/repo"; the path is cut at 120 bytes. The loop count
204note must be capped here: a count past the bound is trap 4, which ends the server.
205fn brti t view uchar * to void
206fsetti t
207n = get gbpl 0
208if gt n 0
209ftic 58
210ftic 32
211for i ulong hmin n 120 bound 120
212ftic get gbp i
213end
214end
215for i ulong len tbtsep
216ftic get tbtsep i
217end
218ftirepo
219end
220note brucmt: <repo>/commit/<fxo[a, a+n)>
221fn brucmt a ulong n ulong to void
222brurepo
223fputc 47
224fput tbcmt
225fputc 47
226bruxo a n
227end
228note brfrat: gbfr[o..] starts with t
229fn brfrat o ulong t view uchar * to bool
230n = get gbfrl 0
231k = len t
232if gt add o k n
233ret false
234end
235for i ulong k
236if ne get gbfr add o i get t i
237ret false
238end
239end
240ret true
241end
242fn brrkind to ulong
243if or brfrat 0 tbrts brfrat 65 tbrts
244ret 2
245end
246if brfrat 0 tbrhs
247ret 1
248end
249if brfrat 65 tbrhs
250ret 1
251end
252ret 3
253end
254note brrefbar: the ref, branch and tag links, the history link for the current path
255fn brrefbar to void
256fput tbbar1
257k = brrkind
258if eq k 1
259fput tbkbr
260end
261if eq k 2
262fput tbktag
263end
264if eq k 3
265fput tbkcmt
266end
267fput tbcode
268brrefesc
269fput tbcodee
270fput tbah
271brurepo
272fput tbbrs
273fput tbah
274brurepo
275fput tbtgs
276fput tbah
277bruactp tbcmts get gbpl 0
278fput tbhist
279fput tbdive
280end
281note brcrumb: repo / dir / dir / name, each but the last a tree link
282fn brcrumb to void
283fput tbcr1
284bruact tbtree
285fput tbaq
286fputrnm
287fput tbae
288n = get gbpl 0
289s = ulong 0
290i = ulong 0
291while le i n bound BRBIG
292lastb = eq i n
293if not lastb
294lastb = eq get gbp i 47
295end
296if lastb
297if gt i s
298fput tbsl
299brcrumb1 s i
300end
301s = add i 1
302end
303i = add i 1
304end
305fput tbpe
306end
307fn brcrumb1 s ulong i ulong to void
308if eq i get gbpl 0
309fput tbb
310brgesc s sub i s
311fput tbbe
312ret
313end
314fput tbah
315bruactp tbtree i
316fput tbaq
317brgesc s sub i s
318fput tbae
319end
320note brlast: the newest commit touching gbp at gbsha, in a box
321fn brlast to void
322fksource
323fka tblog
324fka tbn1
325fka tbone
326fka tbfmtc
327fkopen
328brksha
329if gt get gbpl 0 0
330fka tbdd
331fkopen
332brkp
333end
334st = fexec BRTMO
335n = get fxol 0
336if or ne st 0 eq n 0
337ret
338end
339e = brxfind 0 n 10
340k = brsplit 0 e 31
341if lt k 4
342ret
343end
344fput tblat1
345brucmt brfa 0 brfl 0
346fput tbaq
347fxput brfa 0 7
348fput tblat2
349brfesc 3
350fput tblat3
351brfesc 1
352fput tblat4
353brdate brxdec brfa 2 add brfa 2 brfl 2
354fput tblat5
355end
356note brotype: object type of <sha>:<path>: 1 tree, 2 blob, 0 missing
357fn brotype to ulong
358if eq get gbpl 0 0
359ret 1
360end
361fksource
362fka tbcatf
363fka tbt
364brkshp
365st = fexec BRTMO
366if ne st 0
367ret 0
368end
369n = get fxol 0
370if brxat 0 n tbtree
371ret 1
372end
373if brxat 0 n tbblob
374ret 2
375end
376ret 0
377end
378note ---- tree listing
379fn brlsx to bool
380fksource
381fka tblstr
382fka tbz
383fka tbll
384if gt get gbpl 0 0
385brkshp
386else
387fkopen
388brksha
389end
390st = fexec BRTMO
391note a listing longer than fxo is not shown as the directory: entries past the cut would be missing
392note (the trees pass and the files pass both read it) and the last name could be cut. The whole 500 of
393note fincut, as for the other lists; the 5000-entry display cap below stays marked on the page.
394if ne get fxotr 0 0
395fincut
396ret false
397end
398ret eq st 0
399end
400note brtent: one ls-tree -z -l entry fxo[s, e): "<mode> <type> <sha> <size>\t<name>"; pass 1 trees, pass 2 rest
401fn brtent s ulong e ulong pass ulong to bool
402t = add s 7
403if ge t e
404ret false
405end
406tab = brxfind s e 9
407if ge tab e
408ret false
409end
410c = get fxo t
411istree = eq c 116
412want = eq pass 1
413if and istree not want
414ret false
415end
416if and not istree want
417ret false
418end
419na = add tab 1
420nl = sub e na
421if istree
422brtdir na nl
423ret true
424end
425if eq c 99
426brtsub na nl add t 7
427ret true
428end
429brreadme na nl
430brtfile na nl add t 46 tab
431ret true
432end
433fn brtpre to void
434n = get gbpl 0
435bruactp tbtree n
436end
437fn brtdir na ulong nl ulong to void
438fput tbtr1
439brtpre
440fputc 47
441bruxo na nl
442fput tbaq
443fxesc na nl
444fput tbtrs
445end
446fn brtsub na ulong nl ulong sa ulong to void
447fput tbtrsm
448fxesc na nl
449fput tbtrsm2
450fxesc sa 7
451fput tbtrsm3
452end
453fn brtfile na ulong nl ulong sa ulong tab ulong to void
454fput tbtr1f
455bruactp tbblob get gbpl 0
456fputc 47
457bruxo na nl
458fput tbaq
459fxesc na nl
460fput tbtrf
461s = sa
462while lt s tab bound 64
463if ne get fxo s 32
464break
465end
466s = add s 1
467end
468fxput s sub tab s
469fput tbtre
470end
471note brreadme: remember the best README name seen (markdown 1 beats plain 2)
472fn brreadme na ulong nl ulong to void
473if or lt nl 6 gt nl 200
474ret
475end
476for i ulong 6
477if ne brlow get fxo add na i get tbreadme i
478ret
479end
480end
481k = ulong 2
482if gt nl 6
483if ne get fxo add na 6 46
484ret
485end
486if or brxlext add na 7 add na nl tbxmd brxlext add na 7 add na nl tbxmkd
487k = 1
488end
489end
490m = get gbrmk 0
491if and ne m 0 le m k
492ret
493end
494for i ulong nl
495put gbrm i get fxo add na i
496end
497put gbrml 0 nl
498put gbrmk 0 k
499end
500note brxlext: fxo[a, e) equals the lower-case t, ignoring case
501fn brxlext a ulong e ulong t view uchar * to bool
502if ne sub e a len t
503ret false
504end
505for i ulong len t
506if ne brlow get fxo add a i get t i
507ret false
508end
509end
510ret true
511end
512note brlist: the directory listing of <sha>:<gbp>; false when ls-tree failed
513fn brlist to bool
514put gbrml 0 0
515put gbrmk 0 0
516if not brlsx
517ret false
518end
519n = get fxol 0
520fput tbtab1
521if gt get gbpl 0 0
522fput tbup
523brtup
524fput tbup2
525end
526c = ulong 0
527for q ulong 2
528pass = add q 1
529s = ulong 0
530while lt s n bound BRBIG
531e = brxfind s n 0
532if brtent s e pass
533c = add c 1
534end
535if ge c BRMAXE
536break
537end
538s = add e 1
539end
540end
541fput tbtab2
542if ge c BRMAXE
543fput tbmany
544end
545if eq c 0
546fput tbempty
547end
548ret true
549end
550note brtup: link to the parent directory
551fn brtup to void
552n = get gbpl 0
553k = n
554while gt k 0 bound BRBIG
555k = sub k 1
556if eq get gbp k 47
557break
558end
559end
560bruactp tbtree k
561end
562note brrdshow: fetch and render the README found by brlist (in directory gbp)
563fn brrdshow to void
564n = get gbrml 0
565if eq n 0
566ret
567end
568fksource
569fka tbcatf
570fka tbblob
571fkopen
572brksha
573fkc 58
574if gt get gbpl 0 0
575brkp
576fkc 47
577end
578for i ulong n
579fkc get gbrm i
580end
581st = fexec BRTMO
582if ne st 0
583ret
584end
585m = get fxol 0
586if gt m BRSHOW
587m = BRSHOW
588end
589fput tbrd1
590for i ulong n
591fescc get gbrm i
592end
593if eq get gbrmk 0 1
594fput tbrd2
595brmdir
596brmd 0 m
597fput tbrd3
598ret
599end
600fput tbrd4
601fxesc 0 m
602fput tbrd5
603end
604note brmdir: gbmd = gbp (the Markdown link base directory)
605fn brmdir to void
606n = get gbpl 0
607for i ulong n
608put gbmd i get gbp i
609end
610put gbmdl 0 n
611end
612note brmdfile: gbmd = directory of gbp (a file path)
613fn brmdfile to void
614n = get gbpl 0
615k = n
616while gt k 0 bound BRBIG
617k = sub k 1
618if eq get gbp k 47
619break
620end
621end
622for i ulong k
623put gbmd i get gbp i
624end
625put gbmdl 0 k
626end
627note ---- pages
628note brrdfind: find the README of <sha>:<gbp> the way brlist does (brreadme on every file entry),
629note without writing the listing; false when ls-tree failed
630fn brrdfind to bool
631put gbrml 0 0
632put gbrmk 0 0
633if not brlsx
634ret false
635end
636n = get fxol 0
637s = ulong 0
638while lt s n bound BRBIG
639e = brxfind s n 0
640brrdent s e
641s = add e 1
642end
643ret true
644end
645fn brrdent s ulong e ulong to void
646t = add s 7
647if ge t e
648ret
649end
650tab = brxfind s e 9
651if ge tab e
652ret
653end
654c = get fxo t
655if or eq c 116 eq c 99
656ret
657end
658na = add tab 1
659brreadme na sub e na
660end
661text tbnord "<p class=\"pj-nordme\">This project has no README yet. A README is the page where a project says what it is and how to use it. Here are its files:</p>\n"
662note brpinhd: share the resolved commit with the header only for this render.
663fn brpinhd to void
664for i ulong 40
665put fpin i get gbsha i
666end
667frepohd 0
668put fpin 0 0
669end
670note brhome: repo home at the default branch; 0 hands an empty repo back to the server's home.
671note README first: the friendly header (frepohd), the README (or a plain note and the file list when
672note there is none), then the "For developers: proof and records" section (server/pages.om fpjdev1,
673note fpjdev2) with everything the page held before: the counts, the branch bar, the clone panel, the
674note newest commit and the file list.
675fn brhome to long
676brdefref
677if not brres
678ret 0
679end
680put ftil 0 0
681ftirepo
682for i ulong 40
683put gbref i get gbsha i
684put gbfr i get gbsha i
685end
686put gbrefl 0 40
687put gbfrl 0 40
688brpinhd
689lsok = brrdfind
690rd = and lsok gt get gbrml 0 0
691if rd
692brrdshow
693else
694if lsok
695fput tbnord
696end
697if not brlist
698fput tbempty
699end
700end
701fpjdev1
702brrefbar
703brlast
704if rd
705if not brlist
706fput tbempty
707end
708end
709fpjdev2
710ret 200
711end
712note brtreepg: /tree/<ref>[/<path>]
713fn brtreepg to long
714if not brres
715ret brerr 404
716end
717k = brotype
718if eq k 0
719ret brerr 404
720end
721if eq k 2
722brloc tbblob
723ret 302
724end
725brti tbtfil
726brpinhd
727brrefbar
728brcrumb
729brlast
730if not brlist
731fput tbempty
732end
733brrdshow
734ret 200
735end
736note brloc: redirect to <repo>/<t>/<ref>/<path>
737fn brloc t view uchar * to void
738put fkind 0 2
739put fobl 0 0
740flocb
741for i ulong get fownl 0 bound 64
742brlc get fown i
743end
744flocc 47
745for i ulong get frepol 0 bound 128
746brlc get frepo i
747end
748flocc 47
749floct t
750flocc 47
751for i ulong get gbrefl 0
752brlc get gbref i
753end
754n = get gbpl 0
755if gt n 0
756flocc 47
757end
758for i ulong n bound BRBIG
759brlc get gbp i
760end
761end
762fn brlc c uchar to void
763ok = bralnum c
764if or eq c 45 eq c 46
765ok = true
766end
767if or eq c 95 eq c 126
768ok = true
769end
770if eq c 47
771ok = true
772end
773if ok
774flocc c
775ret
776end
777flocc 37
778flocc get tbhex shr c 4
779flocc get tbhex and c 15
780end
781note brext: lower-case extension of gbp's last segment into gbx (empty when none or > 15)
782fn brext to void
783put gbxl 0 0
784n = get gbpl 0
785k = n
786while gt k 0 bound BRBIG
787k = sub k 1
788c = get gbp k
789if eq c 47
790ret
791end
792if eq c 46
793if gt sub n add k 1 15
794ret
795end
796for i ulong sub n add k 1
797put gbx i brlow get gbp add add k 1 i
798end
799put gbxl 0 sub n add k 1
800ret
801end
802end
803end
804fn brisx t view uchar * to bool
805n = get gbxl 0
806if ne n len t
807ret false
808end
809for i ulong n
810if ne get gbx i get t i
811ret false
812end
813end
814ret true
815end
816note brimgct: the content type of an image or pdf extension; 0 when not one
817fn brimgk to ulong
818if brisx tbxpng
819ret 1
820end
821if or brisx tbxjpg brisx tbxjpeg
822ret 2
823end
824if brisx tbxgif
825ret 3
826end
827if brisx tbxwebp
828ret 4
829end
830if brisx tbxsvg
831ret 5
832end
833if brisx tbxico
834ret 6
835end
836if brisx tbxbmp
837ret 7
838end
839if brisx tbxpdf
840ret 8
841end
842ret 0
843end
844note brbin: a NUL in the first 8000 bytes of fxo
845fn brbin to bool
846n = get fxol 0
847if gt n 8000
848n = 8000
849end
850for i ulong n
851if eq get fxo i 0
852ret true
853end
854end
855ret false
856end
857fn brcatb to bool
858fksource
859fka tbcatf
860fka tbblob
861brkshp
862st = fexec BRTMO
863ret eq st 0
864end
865note brblobpg: /blob/<ref>/<path>
866fn brblobpg to long
867if not brres
868ret brerr 404
869end
870if eq get gbpl 0 0
871ret brerr 404
872end
873k = brotype
874if eq k 0
875ret brerr 404
876end
877if eq k 1
878brloc tbtree
879ret 302
880end
881if not brcatb
882ret brerr 404
883end
884put gbbsz 0 get fxol 0
885put gbbig 0 0
886if ne get fxotr 0 0
887put gbbig 0 1
888if brbin
889put gbbig 0 2
890end
891if not brbsz
892ret brerr 404
893end
894end
895brti tbtblob
896frepohd 0
897brrefbar
898brcrumb
899brbinfo
900brbbody
901ret 200
902end
903note brlines: number of lines in fxo
904fn brlines to ulong
905n = get fxol 0
906c = ulong 0
907for i ulong n bound 16777216
908if eq get fxo i 10
909c = add c 1
910end
911end
912if gt n 0
913if ne get fxo sub n 1 10
914c = add c 1
915end
916end
917ret c
918end
919fn brismd to bool
920brext
921ret or brisx tbxmd brisx tbxmkd
922end
923note brbinfo: lines, size and the raw / blame / history / source links (no raw link past BRRAWMX)
924fn brbinfo to void
925fput tbinfo1
926if eq get gbbig 0 0
927fnum brlines
928fput tbinfo2
929end
930fnum get gbbsz 0
931fput tbinfo3
932if le get gbbsz 0 BRRAWMX
933fput tbah
934bruactp tbraw get gbpl 0
935fput tbinfo4
936end
937fput tbah
938bruactp tbblame get gbpl 0
939fput tbinfo5
940fput tbah
941bruactp tbcmts get gbpl 0
942fput tbhist
943if brismd
944fput tbah
945bruactp tbblob get gbpl 0
946if brplain
947fput tbinfo7
948else
949fput tbinfo6
950end
951end
952fput tbdive
953end
954fn brplain to bool
955r = fqget tbplain
956if lt r 1
957ret false
958end
959ret ne get fval 0 48
960end
961fn brbbody to void
962if gt get gbbsz 0 BRRAWMX
963fput tbbig3
964ret
965end
966brext
967k = brimgk
968if and gt k 0 lt k 8
969fput tbimg1
970bruactp tbraw get gbpl 0
971fput tbimg2
972brbase
973fput tbimg3
974ret
975end
976n = get fxol 0
977bn = false
978if eq get gbbig 0 0
979bn = brbin
980else
981bn = eq get gbbig 0 2
982end
983if or bn ne k 0
984fput tbbin1
985bruactp tbraw get gbpl 0
986fput tbbin2
987ret
988end
989if ne get gbbig 0 0
990fput tbbig1
991bruactp tbraw get gbpl 0
992fput tbbig2
993ret
994end
995if or gt n BRSHOW ne get fxotr 0 0
996fput tbbig1
997bruactp tbraw get gbpl 0
998fput tbbig2
999ret
1000end
1001if and brismd not brplain
1002fput tbart1
1003brmdfile
1004brmd 0 n
1005fput tbart2
1006ret
1007end
1008brcode 0 n
1009end
1010note brbase: html-escaped last segment of gbp
1011fn brbase to void
1012n = get gbpl 0
1013k = n
1014while gt k 0 bound BRBIG
1015if eq get gbp sub k 1 47
1016break
1017end
1018k = sub k 1
1019end
1020brgesc k sub n k
1021end
1022note brcode: fxo[a, e) as a numbered line table with L<n> anchors
1023fn brcode a ulong e ulong to void
1024fput tbcd1
1025s = a
1026ln = ulong 1
1027while lt s e bound BRBIG
1028x = brxfind s e 10
1029fput tbcd2
1030fnum ln
1031fput tbcd3
1032fnum ln
1033fput tbaq
1034fnum ln
1035fput tbcd4
1036fxesc s sub x s
1037fput tbcd5
1038ln = add ln 1
1039s = add x 1
1040end
1041fput tbtab2
1042end
1043note brrawpg: /raw/<ref>/<path>: text/plain is shown; every other type (images, svg, pdf, other
1044note binaries) is sent with Content-Disposition: attachment. Up to len fob from memory; above,
1045note from dl's blob cache as a kind-3 file (brrawbig); above BRRAWMX, 404
1046text tbcache "public, max-age=60"
1047fn brrawpg to long
1048if not brres
1049ret brerr 404
1050end
1051if eq get gbpl 0 0
1052ret brerr 404
1053end
1054k = brotype
1055if ne k 2
1056ret brerr 404
1057end
1058if not brbsz
1059ret brerr 404
1060end
1061sz = get gbbsz 0
1062if gt sz BRRAWMX
1063ret brerr 404
1064end
1065if gt sz len fob
1066ret brrawbig
1067end
1068if not brcatb
1069ret brerr 404
1070end
1071n = get fxol 0
1072if or gt n len fob ne get fxotr 0 0
1073ret brerr 404
1074end
1075brext
1076put fobl 0 0
1077put fkind 0 1
1078fsetsbx
1079brrawct
1080fxput 0 n
1081fsetcc tbcache
1082ret 200
1083end
1084note brrawbig: the blob (gbboid) through dl's blob cache (dlblobf: cat-file into
1085note <data>/archives/<rid>/<blob>.blob, LRU and cold-build caps shared with downloads)
1086fn brrawbig to long
1087if not brboid
1088ret brerr 404
1089end
1090b = new uchar 64 0
1091for i ulong 40
1092put b i get gbboid i
1093end
1094r = dlblobf view part b 0 40
1095if eq r -7
1096ret dlbusy
1097end
1098if lt r 0
1099ret brerr 500
1100end
1101if not brrdhd
1102ret brerr 500
1103end
1104brext
1105put fobl 0 0
1106put fkind 0 3
1107fsetsbx
1108brrawct
1109fsetcc tbcache
1110ret 200
1111end
1112note brrdhd: fxo = the first 8000 bytes of ffile (the cached blob), so brrawct's brbin sees
1113note the blob's own bytes; false when it cannot be read
1114fn brrdhd to bool
1115put fxol 0 0
1116fd = fopen ffile 0 get ffilel 0 524288 0
1117if lt fd 0
1118ret false
1119end
1120ch = new uchar 8192 0
1121n = read int fd ch 0 8000
1122x = fclose int fd
1123if le n 0
1124ret false
1125end
1126m = ulong n
1127for i ulong m
1128put fxo i get ch i
1129end
1130put fxol 0 m
1131ret true
1132end
1133note brbsz: gbbsz = the size of the blob <gbsha>:<gbp> (git cat-file -s)
1134fn brbsz to bool
1135put gbbsz 0 0
1136fksource
1137fka tbcatf
1138fka tbsz
1139brkshp
1140st = fexec BRTMO
1141if ne st 0
1142ret false
1143end
1144v = ulong 0
1145d = ulong 0
1146for i ulong get fxol 0 bound 24
1147c = get fxo i
1148if or lt c 48 gt c 57
1149break
1150end
1151v = add mul v 10 sub ulong c 48
1152d = add d 1
1153end
1154if eq d 0
1155ret false
1156end
1157put gbbsz 0 v
1158ret true
1159end
1160note brboid: gbboid = the blob id of <gbsha>:<gbp> (rev-parse, 40 lowercase hex checked)
1161fn brboid to bool
1162fksource
1163fka tbrevp
1164fka tbverif
1165fka tbq
1166fka tbeoo
1167brkshp
1168st = fexec BRTMO
1169if ne st 0
1170ret false
1171end
1172if lt get fxol 0 40
1173ret false
1174end
1175for i ulong 40
1176c = get fxo i
1177if not brlhex c
1178ret false
1179end
1180put gbboid i c
1181end
1182ret true
1183end
1184fn brrawct to void
1185k = brimgk
1186if eq k 1
1187fsetct tbcpng
1188end
1189if eq k 2
1190fsetct tbcjpg
1191end
1192if eq k 3
1193fsetct tbcgif
1194end
1195if eq k 4
1196fsetct tbcwebp
1197end
1198if eq k 5
1199fsetct tbcsvg
1200end
1201if eq k 6
1202fsetct tbcico
1203end
1204if eq k 7
1205fsetct tbcbmp
1206end
1207if eq k 8
1208fsetct tbcpdf
1209end
1210if ne k 0
1211brattach
1212ret
1213end
1214if not brbin
1215fsetct tbctxt
1216ret
1217end
1218fsetct tbcoct
1219brattach
1220end
1221note brattach: Content-Disposition attachment with the base name, bytes outside [A-Za-z0-9._-] as _
1222fn brattach to void
1223fsetcd tbatt
1224n = get gbpl 0
1225k = n
1226while gt k 0 bound BRBIG
1227if eq get gbp sub k 1 47
1228break
1229end
1230k = sub k 1
1231end
1232m = sub n k
1233if gt m 100
1234m = 100
1235end
1236for i ulong m
1237c = get gbp add k i
1238ok = bralnum c
1239if or eq c 46 or eq c 45 eq c 95
1240ok = true
1241end
1242if not ok
1243c = 95
1244end
1245fcdc c
1246end
1247fcdc 34
1248end