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