interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / interplane-forge / browse / c1_page.om

1234 lines · 20583 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 brhome: repo home at the default branch; 0 hands an empty repo back to the server's home.
663note README first: the friendly header (frepohd), the README (or a plain note and the file list when
664note there is none), then the "For developers: proof and records" section (server/pages.om fpjdev1,
665note fpjdev2) with everything the page held before: the counts, the branch bar, the clone panel, the
666note newest commit and the file list.
667fn brhome to long
668brdefref
669if not brres
670ret 0
671end
672put ftil 0 0
673ftirepo
674frepohd 0
675lsok = brrdfind
676rd = and lsok gt get gbrml 0 0
677if rd
678brrdshow
679else
680if lsok
681fput tbnord
682end
683if not brlist
684fput tbempty
685end
686end
687fpjdev1
688brrefbar
689brlast
690if rd
691if not brlist
692fput tbempty
693end
694end
695fpjdev2
696ret 200
697end
698note brtreepg: /tree/<ref>[/<path>]
699fn brtreepg to long
700if not brres
701ret brerr 404
702end
703k = brotype
704if eq k 0
705ret brerr 404
706end
707if eq k 2
708brloc tbblob
709ret 302
710end
711brti tbtfil
712frepohd 0
713brrefbar
714brcrumb
715brlast
716if not brlist
717fput tbempty
718end
719brrdshow
720ret 200
721end
722note brloc: redirect to <repo>/<t>/<ref>/<path>
723fn brloc t view uchar * to void
724put fkind 0 2
725put fobl 0 0
726flocb
727for i ulong get fownl 0 bound 64
728brlc get fown i
729end
730flocc 47
731for i ulong get frepol 0 bound 128
732brlc get frepo i
733end
734flocc 47
735floct t
736flocc 47
737for i ulong get gbrefl 0
738brlc get gbref i
739end
740n = get gbpl 0
741if gt n 0
742flocc 47
743end
744for i ulong n bound BRBIG
745brlc get gbp i
746end
747end
748fn brlc c uchar to void
749ok = bralnum c
750if or eq c 45 eq c 46
751ok = true
752end
753if or eq c 95 eq c 126
754ok = true
755end
756if eq c 47
757ok = true
758end
759if ok
760flocc c
761ret
762end
763flocc 37
764flocc get tbhex shr c 4
765flocc get tbhex and c 15
766end
767note brext: lower-case extension of gbp's last segment into gbx (empty when none or > 15)
768fn brext to void
769put gbxl 0 0
770n = get gbpl 0
771k = n
772while gt k 0 bound BRBIG
773k = sub k 1
774c = get gbp k
775if eq c 47
776ret
777end
778if eq c 46
779if gt sub n add k 1 15
780ret
781end
782for i ulong sub n add k 1
783put gbx i brlow get gbp add add k 1 i
784end
785put gbxl 0 sub n add k 1
786ret
787end
788end
789end
790fn brisx t view uchar * to bool
791n = get gbxl 0
792if ne n len t
793ret false
794end
795for i ulong n
796if ne get gbx i get t i
797ret false
798end
799end
800ret true
801end
802note brimgct: the content type of an image or pdf extension; 0 when not one
803fn brimgk to ulong
804if brisx tbxpng
805ret 1
806end
807if or brisx tbxjpg brisx tbxjpeg
808ret 2
809end
810if brisx tbxgif
811ret 3
812end
813if brisx tbxwebp
814ret 4
815end
816if brisx tbxsvg
817ret 5
818end
819if brisx tbxico
820ret 6
821end
822if brisx tbxbmp
823ret 7
824end
825if brisx tbxpdf
826ret 8
827end
828ret 0
829end
830note brbin: a NUL in the first 8000 bytes of fxo
831fn brbin to bool
832n = get fxol 0
833if gt n 8000
834n = 8000
835end
836for i ulong n
837if eq get fxo i 0
838ret true
839end
840end
841ret false
842end
843fn brcatb to bool
844fksource
845fka tbcatf
846fka tbblob
847brkshp
848st = fexec BRTMO
849ret eq st 0
850end
851note brblobpg: /blob/<ref>/<path>
852fn brblobpg to long
853if not brres
854ret brerr 404
855end
856if eq get gbpl 0 0
857ret brerr 404
858end
859k = brotype
860if eq k 0
861ret brerr 404
862end
863if eq k 1
864brloc tbtree
865ret 302
866end
867if not brcatb
868ret brerr 404
869end
870put gbbsz 0 get fxol 0
871put gbbig 0 0
872if ne get fxotr 0 0
873put gbbig 0 1
874if brbin
875put gbbig 0 2
876end
877if not brbsz
878ret brerr 404
879end
880end
881brti tbtblob
882frepohd 0
883brrefbar
884brcrumb
885brbinfo
886brbbody
887ret 200
888end
889note brlines: number of lines in fxo
890fn brlines to ulong
891n = get fxol 0
892c = ulong 0
893for i ulong n bound 16777216
894if eq get fxo i 10
895c = add c 1
896end
897end
898if gt n 0
899if ne get fxo sub n 1 10
900c = add c 1
901end
902end
903ret c
904end
905fn brismd to bool
906brext
907ret or brisx tbxmd brisx tbxmkd
908end
909note brbinfo: lines, size and the raw / blame / history / source links (no raw link past BRRAWMX)
910fn brbinfo to void
911fput tbinfo1
912if eq get gbbig 0 0
913fnum brlines
914fput tbinfo2
915end
916fnum get gbbsz 0
917fput tbinfo3
918if le get gbbsz 0 BRRAWMX
919fput tbah
920bruactp tbraw get gbpl 0
921fput tbinfo4
922end
923fput tbah
924bruactp tbblame get gbpl 0
925fput tbinfo5
926fput tbah
927bruactp tbcmts get gbpl 0
928fput tbhist
929if brismd
930fput tbah
931bruactp tbblob get gbpl 0
932if brplain
933fput tbinfo7
934else
935fput tbinfo6
936end
937end
938fput tbdive
939end
940fn brplain to bool
941r = fqget tbplain
942if lt r 1
943ret false
944end
945ret ne get fval 0 48
946end
947fn brbbody to void
948if gt get gbbsz 0 BRRAWMX
949fput tbbig3
950ret
951end
952brext
953k = brimgk
954if and gt k 0 lt k 8
955fput tbimg1
956bruactp tbraw get gbpl 0
957fput tbimg2
958brbase
959fput tbimg3
960ret
961end
962n = get fxol 0
963bn = false
964if eq get gbbig 0 0
965bn = brbin
966else
967bn = eq get gbbig 0 2
968end
969if or bn ne k 0
970fput tbbin1
971bruactp tbraw get gbpl 0
972fput tbbin2
973ret
974end
975if ne get gbbig 0 0
976fput tbbig1
977bruactp tbraw get gbpl 0
978fput tbbig2
979ret
980end
981if or gt n BRSHOW ne get fxotr 0 0
982fput tbbig1
983bruactp tbraw get gbpl 0
984fput tbbig2
985ret
986end
987if and brismd not brplain
988fput tbart1
989brmdfile
990brmd 0 n
991fput tbart2
992ret
993end
994brcode 0 n
995end
996note brbase: html-escaped last segment of gbp
997fn brbase to void
998n = get gbpl 0
999k = n
1000while gt k 0 bound BRBIG
1001if eq get gbp sub k 1 47
1002break
1003end
1004k = sub k 1
1005end
1006brgesc k sub n k
1007end
1008note brcode: fxo[a, e) as a numbered line table with L<n> anchors
1009fn brcode a ulong e ulong to void
1010fput tbcd1
1011s = a
1012ln = ulong 1
1013while lt s e bound BRBIG
1014x = brxfind s e 10
1015fput tbcd2
1016fnum ln
1017fput tbcd3
1018fnum ln
1019fput tbaq
1020fnum ln
1021fput tbcd4
1022fxesc s sub x s
1023fput tbcd5
1024ln = add ln 1
1025s = add x 1
1026end
1027fput tbtab2
1028end
1029note brrawpg: /raw/<ref>/<path>: text/plain is shown; every other type (images, svg, pdf, other
1030note binaries) is sent with Content-Disposition: attachment. Up to len fob from memory; above,
1031note from dl's blob cache as a kind-3 file (brrawbig); above BRRAWMX, 404
1032text tbcache "public, max-age=60"
1033fn brrawpg to long
1034if not brres
1035ret brerr 404
1036end
1037if eq get gbpl 0 0
1038ret brerr 404
1039end
1040k = brotype
1041if ne k 2
1042ret brerr 404
1043end
1044if not brbsz
1045ret brerr 404
1046end
1047sz = get gbbsz 0
1048if gt sz BRRAWMX
1049ret brerr 404
1050end
1051if gt sz len fob
1052ret brrawbig
1053end
1054if not brcatb
1055ret brerr 404
1056end
1057n = get fxol 0
1058if or gt n len fob ne get fxotr 0 0
1059ret brerr 404
1060end
1061brext
1062put fobl 0 0
1063put fkind 0 1
1064fsetsbx
1065brrawct
1066fxput 0 n
1067fsetcc tbcache
1068ret 200
1069end
1070note brrawbig: the blob (gbboid) through dl's blob cache (dlblobf: cat-file into
1071note <data>/archives/<rid>/<blob>.blob, LRU and cold-build caps shared with downloads)
1072fn brrawbig to long
1073if not brboid
1074ret brerr 404
1075end
1076b = new uchar 64 0
1077for i ulong 40
1078put b i get gbboid i
1079end
1080r = dlblobf view part b 0 40
1081if eq r -7
1082ret dlbusy
1083end
1084if lt r 0
1085ret brerr 500
1086end
1087if not brrdhd
1088ret brerr 500
1089end
1090brext
1091put fobl 0 0
1092put fkind 0 3
1093fsetsbx
1094brrawct
1095fsetcc tbcache
1096ret 200
1097end
1098note brrdhd: fxo = the first 8000 bytes of ffile (the cached blob), so brrawct's brbin sees
1099note the blob's own bytes; false when it cannot be read
1100fn brrdhd to bool
1101put fxol 0 0
1102fd = fopen ffile 0 get ffilel 0 524288 0
1103if lt fd 0
1104ret false
1105end
1106ch = new uchar 8192 0
1107n = read int fd ch 0 8000
1108x = fclose int fd
1109if le n 0
1110ret false
1111end
1112m = ulong n
1113for i ulong m
1114put fxo i get ch i
1115end
1116put fxol 0 m
1117ret true
1118end
1119note brbsz: gbbsz = the size of the blob <gbsha>:<gbp> (git cat-file -s)
1120fn brbsz to bool
1121put gbbsz 0 0
1122fksource
1123fka tbcatf
1124fka tbsz
1125brkshp
1126st = fexec BRTMO
1127if ne st 0
1128ret false
1129end
1130v = ulong 0
1131d = ulong 0
1132for i ulong get fxol 0 bound 24
1133c = get fxo i
1134if or lt c 48 gt c 57
1135break
1136end
1137v = add mul v 10 sub ulong c 48
1138d = add d 1
1139end
1140if eq d 0
1141ret false
1142end
1143put gbbsz 0 v
1144ret true
1145end
1146note brboid: gbboid = the blob id of <gbsha>:<gbp> (rev-parse, 40 lowercase hex checked)
1147fn brboid to bool
1148fksource
1149fka tbrevp
1150fka tbverif
1151fka tbq
1152fka tbeoo
1153brkshp
1154st = fexec BRTMO
1155if ne st 0
1156ret false
1157end
1158if lt get fxol 0 40
1159ret false
1160end
1161for i ulong 40
1162c = get fxo i
1163if not brlhex c
1164ret false
1165end
1166put gbboid i c
1167end
1168ret true
1169end
1170fn brrawct to void
1171k = brimgk
1172if eq k 1
1173fsetct tbcpng
1174end
1175if eq k 2
1176fsetct tbcjpg
1177end
1178if eq k 3
1179fsetct tbcgif
1180end
1181if eq k 4
1182fsetct tbcwebp
1183end
1184if eq k 5
1185fsetct tbcsvg
1186end
1187if eq k 6
1188fsetct tbcico
1189end
1190if eq k 7
1191fsetct tbcbmp
1192end
1193if eq k 8
1194fsetct tbcpdf
1195end
1196if ne k 0
1197brattach
1198ret
1199end
1200if not brbin
1201fsetct tbctxt
1202ret
1203end
1204fsetct tbcoct
1205brattach
1206end
1207note brattach: Content-Disposition attachment with the base name, bytes outside [A-Za-z0-9._-] as _
1208fn brattach to void
1209fsetcd tbatt
1210n = get gbpl 0
1211k = n
1212while gt k 0 bound BRBIG
1213if eq get gbp sub k 1 47
1214break
1215end
1216k = sub k 1
1217end
1218m = sub n k
1219if gt m 100
1220m = 100
1221end
1222for i ulong m
1223c = get gbp add k i
1224ok = bralnum c
1225if or eq c 46 or eq c 45 eq c 95
1226ok = true
1227end
1228if not ok
1229c = 95
1230end
1231fcdc c
1232end
1233fcdc 34
1234end