interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / collab / co9form.om

493 lines · 10059 bytes Raw Blame History
1note collab/co9form.om (ForgePatches): Phase A forms, POST handlers and the compose page.
2note POST <o>/<r>/issues/<id>/compose (comment), <o>/<r>/patches/<id>/compose (comment or review),
3note <o>/<r>/issues/new and <o>/<r>/patches/new: contract section 5 gate (signed in, else 303 to login;
4note CSRF, else 403; per-IP write limit, else 429), then the checks of docs/collab-write.md, then 303 to
5note <o>/<r>/compose/<cid>. GET compose/<cid> is the preview with the command; compose/<cid>/<file>
6note downloads the text the command reads. The shown commands hold only fixed words, hex ids and the
7note RID; every user byte reaches rad or git only through the downloaded file and "$(...)".
8text tclogin "login"
9text tcnew "new"
10text tccompw "compose"
11text tccompp "/compose/"
12text tcfbody "body"
13text tcftitle "title"
14text tcfverd "verdict"
15text tcfdraft "draft"
16text tcvcom "comment"
17text tcvacc "accept"
18text tcvrej "reject"
19text tcvrev "review"
20text tcer1 "<section class=\"box\"><h2>Not prepared</h2>\n<p class=\"bad\">"
21text tcer2 "</p>\n<p class=\"muted\">Nothing was kept. Go back to correct the text and send it again.</p></section>\n"
22text tcetoo "The text is longer than 60000 bytes."
23text tcebad "The text must be UTF-8 without control characters (tabs and line breaks are fine)."
24text tceempty "The text is empty."
25text tcettl "The title must be one line of 1 to 256 bytes of UTF-8 without control characters."
26text tcebadv "The verdict must be comment, review, accept or reject."
27text tcebadr "The revision is not a revision of this patch, or it was redacted."
28text tcfs1 "<section class=\"box\" id=\"compose\"><h2>"
29text tcfsc "Comment"
30text tcfsp "Comment or review"
31text tcfsni "New issue"
32text tcfsnp "New patch"
33text tcfs2 "</h2>\n"
34text tcfse "</section>\n"
35text tcsgn1 "<p class=\"muted\">Sign in to prepare one. <a href=\""
36text tcsgn2 "\">Sign in with your key</a></p>\n"
37text tcfo1 "<form method=\"post\" action=\""
38text tcfo2 "\">\n<input type=\"hidden\" name=\"csrf\" value=\""
39text tcfo3 "\">\n"
40text tcfrev "<input type=\"hidden\" name=\"rev\" value=\""
41text tcfttl "<p><label>Title<br><input type=\"text\" name=\"title\" maxlength=\"256\" required></label></p>\n"
42text tcfta1 "<p><label>"
43text tcftab "Text (Markdown)"
44text tcftad "Description (Markdown, optional)"
45text tcfta2 "<br><textarea name=\"body\" rows=\"10\" maxlength=\"60000\""
46text tcfreq " required"
47text tcfta3 "></textarea></label></p>\n"
48text tcfv1 "<p><label><input type=\"radio\" name=\"verdict\" value=\"comment\" checked> Comment on revision "
49text tcfv2 "</label><br>\n<label><input type=\"radio\" name=\"verdict\" value=\"review\"> Review without a verdict</label><br>\n<label><input type=\"radio\" name=\"verdict\" value=\"accept\"> Review: accept</label><br>\n<label><input type=\"radio\" name=\"verdict\" value=\"reject\"> Review: reject</label></p>\n"
50text tcfdr "<p><label><input type=\"checkbox\" name=\"draft\" value=\"1\"> Open it as a draft</label></p>\n"
51text tcfsub "<p><button type=\"submit\">Prepare</button></p>\n</form>\n"
52text tcfexp "<p class=\"meta\">The forge checks the text and keeps a preview for this session. Publishing it is closed for now: Interplane does not accept comments, reviews or issues yet.</p>\n"
53text tcfexpp "<p class=\"meta\">The forge never takes your commits. It checks the title and description and keeps a preview for this session. Opening a patch is closed for now: Interplane does not accept pushes yet.</p>\n"
54text tcfnorev "<p class=\"muted\">Every revision of this patch is redacted; there is nothing to comment on.</p>\n"
55text tcnwl1 "<p><a href=\""
56text tcnwli "/issues/new\">Prepare a new issue</a></p>\n"
57text tcnwlp "/patches/new\">Prepare a new patch</a></p>\n"
58text tcpatn "/patches/"
59text tcissn "/issues/"
60text tcslcomp "/compose"
61text tctnwi "New issue - "
62text tctnwp "New patch - "
63text tctpub "Publish - "
64note ---- routing
65note copost k: POST under section k (1 patches, 2 issues); 405 for anything else
66fn copost k ulong to long
67o = get gcoff 0
68n = get frestl 0
69if or gt k 2 le n add o 1
70ret 405
71end
72a = add o 1
73if coseqat a n tcnew
74ret cocnew k
75end
76note the id segment ends at the next slash. n is frestl, at most len frest = 4096, so the scan is
77note bounded at 4096; it was 128, and a POST with a longer segment was trap 4 (exit 104).
78e = a
79while lt e n bound 4096
80if eq get frest e 47
81break
82end
83e = add e 1
84end
85if ge e n
86ret 405
87end
88if eq coseqat add e 1 n tccompw false
89ret 405
90end
91if eq cocpid a e false
92ret 404
93end
94ret cocpost k
95end
96note coseqat a b t: frest[a,b) equals t
97fn coseqat a ulong b ulong t view uchar * to bool
98if ne sub b a len t
99ret false
100end
101for i ulong len t bound 64
102if ne get frest add a i get t i
103ret false
104end
105end
106ret true
107end
108note cocget: GET compose/<cid> (page) or compose/<cid>/<file> (download); 404 unless the compose is
109note live, from this session and this repo
110fn cocget to long
111a = add get gcoff 0 1
112n = get frestl 0
113if lt n add a 32
114ret 404
115end
116s = cozfind a
117if gt s 31
118ret 404
119end
120if eq n add a 32
121ret cocpage s
122end
123if ne get frest add a 32 47
124ret 404
125end
126if cofneq get gczk s add a 33 n
127ret cocdlf s
128end
129ret 404
130end
131note ---- write gate (contract section 5)
132fn cowgate to long
133if eq get fuserl 0 0
134put fkind 0 2
135flocb
136floct tclogin
137ret 303
138end
139if eq socsrfok false
140ret 403
141end
142if eq fratelim false
143ret 429
144end
145ret 0
146end
147fn coerr t view uchar * to void
148put fobl 0 0
149fput tcer1
150fput t
151fput tcer2
152end
153note cobody req: the body field, checked (cotxtok, at most 60000 bytes, at least req); -1 refused
154fn cobody req ulong to long
155r = cobfld tcfbody
156if eq r -2
157coerr tcetoo
158ret -1
159end
160if lt r 0
161r = 0
162end
163m = cotxtok ulong r true
164if lt m 0
165coerr tcebad
166ret -1
167end
168if gt m 60000
169coerr tcetoo
170ret -1
171end
172if lt m long req
173coerr tceempty
174ret -1
175end
176ret m
177end
178note cofveq t n: gcfv[0,n) equals t
179fn cofveq t view uchar * n long to bool
180if ne n long len t
181ret false
182end
183for i ulong len t bound 64
184if ne get gcfv i get t i
185ret false
186end
187end
188ret true
189end
190note coverd: verdict field: 0 comment (also when absent), 1 accept, 2 reject, 3 review, 9 invalid
191fn coverd to ulong
192r = cobfld tcfverd
193if lt r 0
194ret ulong 0
195end
196if cofveq tcvcom r
197ret ulong 0
198end
199if cofveq tcvacc r
200ret ulong 1
201end
202if cofveq tcvrej r
203ret ulong 2
204end
205if cofveq tcvrev r
206ret ulong 3
207end
208ret ulong 9
209end
210note corevf: rev field: absent, the latest unredacted revision; else the one unredacted revision whose
211note id starts with it (4..40 hex); 9999 when there is none
212fn corevf to ulong
213r = cobfld tcrevq
214if lt r 0
215ret coqrev
216end
217if or lt r 4 gt r 40
218ret ulong 9999
219end
220n = ulong r
221m = ulong 0
222w = ulong 9999
223for v ulong get gcrn 0
224if corevm v n
225m = add m 1
226w = v
227end
228end
229if ne m 1
230ret ulong 9999
231end
232if eq get gcrx w 1
233ret ulong 9999
234end
235ret w
236end
237fn corevm v ulong n ulong to bool
238for k ulong n bound 40
239if ne get gcrv add mul v 40 k get gcfv k
240ret false
241end
242end
243ret true
244end
245note ---- POST handlers
246note cocpost k: compose on an existing COB (k 1 patch, 2 issue); 404 when it is not one of this repo
247fn cocpost k ulong to long
248g = cowgate
249if ne g 0
250ret g
251end
252if eq corefs k false
253ret 500
254end
255if eq coresolve false
256ret 404
257end
258if eq coload k false
259ret 404
260end
261note nothing is written to an object that was not read whole
262if ne get gcov 0 0
263fincut
264ret 500
265end
266put gcstil 0 0
267put gcsf 0 0
268put gcsrv 0 99
269if eq k 2
270n = cobody 1
271if lt n 0
272ret 400
273end
274ret cocdone 1 ulong n
275end
276ret cocpatc
277end
278fn cocpatc to long
279v = coverd
280if gt v 3
281coerr tcebadv
282ret 400
283end
284r = corevf
285if gt r 63
286coerr tcebadr
287ret 400
288end
289put gcsrv 0 r
290q = ulong 1
291if or eq v 1 eq v 2
292q = ulong 0
293end
294n = cobody q
295if lt n 0
296ret 400
297end
298put gcsf 0 v
299if eq v 0
300ret cocdone 2 ulong n
301end
302ret cocdone 3 ulong n
303end
304note cocnew k: new issue (k 2) or new patch (k 1): title, optional description, draft (patches)
305fn cocnew k ulong to long
306g = cowgate
307if ne g 0
308ret g
309end
310r = cobfld tcftitle
311if lt r 1
312coerr tcettl
313ret 400
314end
315m = cotxtok ulong r false
316if or lt m 1 gt m 256
317coerr tcettl
318ret 400
319end
320for i ulong ulong m bound 256
321put gcsti i get gcfv i
322end
323put gcstil 0 ulong m
324f = ulong 0
325if eq k 1
326d = cobfld tcfdraft
327if eq d 1
328if eq get gcfv 0 49
329f = ulong 8
330end
331end
332end
333put gcsf 0 f
334put gcsrv 0 99
335n = cobody 0
336if lt n 0
337ret 400
338end
339if eq k 2
340ret cocdone 4 ulong n
341end
342ret cocdone 5 ulong n
343end
344fn cocdone kd ulong n ulong to long
345s = cozsave kd n
346if gt s 31
347ret 500
348end
349put fkind 0 2
350flocrepo
351floct tccompp
352for k ulong 32
353flocc get gczid add mul s 32 k
354end
355ret 303
356end
357note ---- forms
358fn cosignin to void
359fput tcsgn1
360fputb
361fput tclogin
362fput tcsgn2
363end
364fn cofopen to void
365fput tcfo1
366fputrl
367end
368fn cofcsrf to void
369fput tcfo2
370for i ulong get fcsrfl 0 bound 64
371fescc get fcsrf i
372end
373fput tcfo3
374end
375fn cofta lab view uchar * req bool to void
376fput tcfta1
377fput lab
378fput tcfta2
379if req
380fput tcfreq
381end
382fput tcfta3
383end
384note coformc k: the compose form under a patch (k 1) or issue (k 2) page
385fn coformc k ulong to void
386fput tcfs1
387if eq k 1
388fput tcfsp
389else
390fput tcfsc
391end
392fput tcfs2
393if eq get fuserl 0 0
394cosignin
395fput tcfse
396ret
397end
398r = ulong 0
399if eq k 1
400r = coqrev
401if gt r 63
402fput tcfnorev
403fput tcfse
404ret
405end
406end
407cofopen
408if eq k 1
409fput tcpatn
410else
411fput tcissn
412end
413for i ulong 40
414fputc get gcid i
415end
416fput tcslcomp
417cofcsrf
418if eq k 1
419fput tcfrev
420for i ulong 40
421fputc get gcrv add mul r 40 i
422end
423fput tcfo3
424end
425cofta tcftab true
426if eq k 1
427fput tcfv1
428fnum add r 1
429fput tcfv2
430end
431fput tcfsub
432fput tcfexp
433fput tcfse
434end
435note conewl kd: the link to the new-issue or new-patch form under a list
436fn conewl kd ulong to void
437fput tcnwl1
438fputrl
439if eq kd 1
440fput tcnwlp
441else
442fput tcnwli
443end
444end
445note conewpg kd: GET issues/new (kd 4) or patches/new (kd 5)
446fn conewpg kd ulong to long
447put ftil 0 0
448if eq kd 4
449for i ulong len tctnwi
450ftic get tctnwi i
451end
452frepohd 6
453else
454for i ulong len tctnwp
455ftic get tctnwp i
456end
457frepohd 5
458end
459ftirepo
460fput tcfs1
461if eq kd 4
462fput tcfsni
463else
464fput tcfsnp
465end
466fput tcfs2
467if eq get fuserl 0 0
468cosignin
469fput tcfse
470ret 200
471end
472cofopen
473if eq kd 4
474fput tcissn
475else
476fput tcpatn
477end
478fput tcnew
479cofcsrf
480fput tcfttl
481cofta tcftad false
482if eq kd 5
483fput tcfdr
484end
485fput tcfsub
486if eq kd 5
487fput tcfexpp
488else
489fput tcfexp
490end
491fput tcfse
492ret 200
493end