Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/patch/p4take.om # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / patch / p4take.om` 1179 lines ยท 20408 bytes Raw Blame History 1 note patch/p4take.om: POST ///patches/new. The checks in order, each refusal one line 2 note of text with nothing kept: session and CSRF (pagate); the repo field and the repository's git 3 note store; base a commit reachable from the default branch the public list names; sizes and shapes 4 note of title, description, mbox and sig; the signature by the session's key over the statement; then 5 note the mbox is applied once on base in a throwaway work tree and, only if that is clean (no file is 6 note binary, by git's marks and by the bytes of the applied diff, and no submodule is added), stored. 7 note ---- the mbox scan 8 note pamln s e t: the line gpmb[s, e) starts with t 9 fn pamln s ulong e ulong t view uchar * to bool 10 if lt sub e s len t 11 ret false 12 end 13 for i ulong len t bound 64 14 if ne get gpmb add s i get t i 15 ret false 16 end 17 end 18 ret true 19 end 20 note pafrom: the line is "From <40 lowercase hex> Mon Sep 17 00:00:00 2001", format-patch's first 21 note line of every commit 22 fn pafrom s ulong e ulong to bool 23 if ne sub e s 70 24 ret false 25 end 26 if not pamln s e tpfrom 27 ret false 28 end 29 for i ulong 40 30 if lt sohexv get gpmb add add s 5 i 0 31 ret false 32 end 33 end 34 ret pamln add s 45 e tpfrom2 35 end 36 fn paeol s ulong n ulong to ulong 37 j = s 38 while lt j n bound `4194304` 39 if eq get gpmb j 10 40 ret j 41 end 42 j = add j 1 43 end 44 ret n 45 end 46 note padd: gpmb[j] and gpmb[j+1] are both a dot, inside [s, e) 47 fn padd j ulong e ulong to bool 48 if ge add j 1 e 49 ret false 50 end 51 if ne get gpmb j 46 52 ret false 53 end 54 ret eq get gpmb add j 1 46 55 end 56 note pasep: the byte bounds a path segment (/, space, quote) 57 fn pasep c uchar to bool 58 ret or or eq c 47 eq c 32 eq c 34 59 end 60 note paddseg j s e: the ".." at gpmb[j] is a whole segment of the path part gpmb[s, e): the byte 61 note before it (when there is one) and the byte after it (when there is one) each bound a segment 62 fn paddseg j ulong s ulong e ulong to bool 63 if gt j s 64 if not pasep get gpmb sub j 1 65 ret false 66 end 67 end 68 if lt add j 2 e 69 ret pasep get gpmb add j 2 70 end 71 ret true 72 end 73 note paout s e: the path part gpmb[s, e) of a diff header names a way out of the repository: a ".." 74 note segment, an empty segment (//) or a leading / 75 fn paout s ulong e ulong to bool 76 if ge s e 77 ret false 78 end 79 if eq get gpmb s 47 80 ret true 81 end 82 j = s 83 while lt j e bound `4194304` 84 if padd j e 85 if paddseg j s e 86 ret true 87 end 88 end 89 if eq get gpmb j 47 90 if lt add j 1 e 91 if eq get gpmb add j 1 47 92 ret true 93 end 94 end 95 end 96 j = add j 1 97 end 98 ret false 99 end 100 note padiffl: a line of a diff: 2 a binary patch, 3 a header naming a path outside, else 0 101 fn padiffl s ulong e ulong to ulong 102 if pamln s e tpgbp 103 if eq sub e s len tpgbp 104 ret 2 105 end 106 end 107 if pamln s e tpbf 108 ret 2 109 end 110 if pamln s e tprnf 111 if paout add s len tprnf e 112 ret 3 113 end 114 end 115 if pamln s e tprnt 116 if paout add s len tprnt e 117 ret 3 118 end 119 end 120 ret 0 121 end 122 note pascan: one pass over the lines of the mbox. gpncm = commits (From lines); gpgrd = 2 for a 123 note binary patch or 3 for an outside path, otherwise 0. False when the first line 124 note is not a From line: not format-patch output. 125 fn pascan to bool 126 n = get gpmbl 0 127 put gpncm 0 0 128 put gpgrd 0 0 129 s = ulong 0 130 ind = false 131 for it ulong `4194304` 132 if ge s n 133 break 134 end 135 e = paeol s n 136 if pafrom s e 137 put gpncm 0 add get gpncm 0 1 138 ind = false 139 else 140 if eq s 0 141 ret false 142 end 143 g = ulong 0 144 if pamln s e tpdg 145 ind = true 146 if paout add s len tpdg e 147 g = 3 148 end 149 else 150 if ind 151 g = padiffl s e 152 end 153 end 154 if and ne g 0 eq get gpgrd 0 0 155 put gpgrd 0 g 156 end 157 end 158 s = add e 1 159 end 160 ret gt get gpncm 0 0 161 end 162 note ---- base 163 note pabasec: 0 base is a commit on the main branch; else the refusal's status with its text written 164 fn pabasec to long 165 fkgit 166 fka tpcatf 167 fka tpde 168 fkopen 169 pakbase 170 fkt tpcmt 171 r = fexec PATMO 172 if lt r 0 173 ret parefu 500 tpmint 174 end 175 if ne r 0 176 ret parefu 422 tpmunk 177 end 178 fkgit 179 fka tpgmb 180 fka tpisa 181 fkopen 182 pakbase 183 fkopen 184 fkt tprh 185 i = get fridx 0 186 o = get fabo i 187 for k ulong get fabl i bound 64 188 fkc get fabr add o k 189 end 190 r = fexec PATMO 191 if eq r 0 192 ret 0 193 end 194 if eq r 1 195 ret parefu 422 tpmnotm 196 end 197 ret parefu 500 tpmint 198 end 199 note ---- the statement and the id 200 fn pastc c uchar to void 201 n = get gpstl 0 202 if lt n 511 203 put gpst n c 204 put gpstl 0 add n 1 205 end 206 end 207 fn pasthex h view uchar 32 to void 208 x = new uchar 64 0 209 sohex h x 210 for i ulong 64 211 pastc get x i 212 end 213 pastc 10 214 end 215 note pastmt: gpst = "interplane-patch 1\n/\n\n\n\n", all hex lowercase; gpid = the first 16 hex of its SHA-256 217 fn pastmt to void 218 put gpstl 0 0 219 for i ulong len tpst1 220 pastc get tpst1 i 221 end 222 for i ulong len tfowner 223 pastc get tfowner i 224 end 225 pastc 47 226 r = get fridx 0 227 for k ulong get fanl r bound 128 228 pastc frnbyte r k 229 end 230 pastc 10 231 for i ulong 40 232 pastc get gpbase i 233 end 234 pastc 10 235 h = new uchar 32 0 236 pahs 0 get gpmbl 0 h 237 pasthex h 238 pahs 7 add add get gpttll 0 1 get gpdscl 0 h 239 pasthex h 240 pahs 1 get gpstl 0 h 241 x = new uchar 64 0 242 sohex h x 243 for i ulong 16 244 put gpid i get x i 245 end 246 end 247 note ---- the signature: ssh-keygen -Y verify -f -I forge-user -n interplane-patch 248 note -s with the statement on standard input (the argv exec and temp files of the 249 note sign-in check, social/20crypt.om and 40auth.om). The one allowed signer is the session's key. 250 note paspk: the `ed25519` key of the session's did:key into pk 251 fn paspk pk edit uchar 32 to bool 252 d = get gscur 0 253 o = get gsso d 254 l = get gssl d 255 w = len tsdidp 256 if or le l w gt sub l w 64 257 ret false 258 end 259 z = new uchar 64 0 260 for i ulong sub l w bound 64 261 put z i get gsstr add add o w i 262 end 263 ret sodidpk part z 0 sub l w pk 264 end 265 note pasigw: the three temp files: a allowed signers, s signature, m statement 266 fn pasigw pk view uchar 32 to bool 267 al = new uchar 128 0 268 k = sopkline pk al 269 if not sotmpw 97 part al 0 k 270 ret false 271 end 272 sg = new uchar 4096 0 273 n = get gpsigl 0 274 for i ulong n bound 4096 275 put sg i get gpsig i 276 end 277 if not sotmpw 115 part sg 0 n 278 ret false 279 end 280 m = new uchar 512 0 281 n = get gpstl 0 282 for i ulong n bound 512 283 put m i get gpst i 284 end 285 ret sotmpw 109 part m 0 n 286 end 287 fn pasigrun to long 288 sotmpp 109 289 mfd = fopen gspth 0 get gspthl 0 524288 0 290 if lt mfd 0 291 ret -500 292 end 293 soavb 294 soava tssshkg 295 soava tsY 296 soava tsverify 297 soava tsdf 298 sotmpp 97 299 soavpth 300 soava tsdI 301 soava tsprinc 302 soava tsdn 303 soava tpns 304 soava tsds 305 sotmpp 115 306 soavpth 307 r = sorunv mfd 5000 308 x = fclose int mfd 309 if eq r -2 310 ret -500 311 end 312 if eq r -1 313 ret -500 314 end 315 ret r 316 end 317 note pasigck: 0 the signature verifies; else the refusal's status with its text written 318 fn pasigck to long 319 if not sovlim 320 ret parefu 429 tpmrate 321 end 322 pk = new uchar 32 0 323 if not paspk pk 324 ret parefu 500 tpmint 325 end 326 st = new uchar 8 0 327 if not sorand st 328 ret parefu 500 tpmint 329 end 330 for i ulong 8 331 put gsstem i get st i 332 end 333 r = long -500 334 if pasigw pk 335 r = pasigrun 336 end 337 sotmprm 97 338 sotmprm 115 339 sotmprm 109 340 if eq r 0 341 ret 0 342 end 343 if lt r 0 344 ret parefu 500 tpmint 345 end 346 ret parefu 403 tpmsig 347 end 348 note ---- apply once on base in a throwaway work tree 349 note pastem: gpstm = 16 random hex digits naming this request's work and staging folders 350 fn pastem to bool 351 r = new uchar 8 0 352 if not sorand r 353 ret false 354 end 355 x = new uchar 16 0 356 sohex r x 357 for i ulong 16 358 put gpstm i get x i 359 end 360 ret true 361 end 362 note pawinit: make patch-work/pw/ with an empty git repository w whose objects are borrowed from 363 note the repository's store (objects/info/alternates): the store is only read, and nothing the work 364 note folder makes is ever written into it (the intake's pawork, and the bundle diff of patch/p5imp.om) 365 fn pawinit to bool 366 papb 367 papt tptmp 368 x = pamkdir 369 papw part tpdot 0 0 370 r = makedir gpp 0 get gppl 0 448 371 if lt r 0 372 ret false 373 end 374 fkb 375 fka tfgit 376 pakc1 tpk17 377 fka tpinit 378 fka tpq 379 fka tptpl 380 fkopen 381 papw tpww 382 pakp 383 r = fexec PATMO 384 if ne r 0 385 ret false 386 end 387 palb 388 papgs 389 if gt get gppl 0 240 390 ret false 391 end 392 for i ulong get gppl 0 bound 240 393 palc get gpp i 394 end 395 for i ulong len tpobj 396 palc get tpobj i 397 end 398 papw tpwalt 399 ret pawf 5 get gplnl 0 400 end 401 note pawork: the work folder of pawinit with the mbox as m 402 fn pawork to bool 403 if not pawinit 404 ret false 405 end 406 papw tpwm 407 ret pawf 0 get gpmbl 0 408 end 409 note pasteq: the stored statement of item gpid is byte-equal to this request's gpst[0, gpstl) 410 fn pasteq to bool 411 pafp tpfst 412 n = frdall 413 if ne n long get gpstl 0 414 ret false 415 end 416 for i ulong get gpstl 0 bound 512 417 if ne get fxo i get gpst i 418 ret false 419 end 420 end 421 ret true 422 end 423 note pahex40: fxo[0, 40) is 40 lowercase hex digits followed by a line feed; copied into gphead 424 fn pahex40 to bool 425 if ne get fxol 0 41 426 ret false 427 end 428 for i ulong 40 429 c = get fxo i 430 if lt sohexv c 0 431 ret false 432 end 433 put gphead i c 434 end 435 ret eq get fxo 40 10 436 end 437 note panum: the decimal number in fxo[0, n) before its line feed, `999999999` when it is not one 438 fn panum to ulong 439 n = get fxol 0 440 if or lt n 2 gt n 10 441 ret `999999999` 442 end 443 v = ulong 0 444 for i ulong sub n 1 bound 16 445 c = get fxo i 446 if not fisdig c 447 ret `999999999` 448 end 449 v = add mul v 10 ulong sub c 48 450 end 451 ret v 452 end 453 note pabinat s: fxo[s, s+4) is "-\t-\t" (the caller keeps s+4 inside the output) 454 fn pabinat s ulong to bool 455 a = and eq get fxo s 45 eq get fxo add s 1 9 456 b = and eq get fxo add s 2 45 eq get fxo add s 3 9 457 ret and a b 458 end 459 note pabinns: fxo holds `git diff --numstat --no-renames`: a line starts with "-\t-\t", git's mark of 460 note a binary file. The mbox scan (padiffl) sees only the bytes as sent; git am decodes a mail body 461 note sent base64 or quoted-printable first, so only git's own view after the apply covers every way in. 462 fn pabinns to bool 463 n = get fxol 0 464 s = ulong 0 465 for it ulong `16777216` 466 if ge s n 467 break 468 end 469 if le add s 4 n 470 if pabinat s 471 ret true 472 end 473 end 474 e = s 475 while lt e n bound `16777216` 476 if eq get fxo e 10 477 break 478 end 479 e = add e 1 480 end 481 s = add e 1 482 end 483 ret false 484 end 485 note pafxln s e t: the line fxo[s, e) starts with t 486 fn pafxln s ulong e ulong t view uchar * to bool 487 if lt sub e s len t 488 ret false 489 end 490 for i ulong len t bound 64 491 if ne get fxo add s i get t i 492 ret false 493 end 494 end 495 ret true 496 end 497 note Read the same normalized diff as Git, before applying any of the mail messages. 498 text tpmspl "mailsplit" 499 text tpmio "mailinfo" 500 text tpmd "/mails" 501 text tpmslash "/mails/" 502 text tpmsg "/mails/message" 503 text tpmpt "/mails/patch" 504 text tpmo "-o" 505 text tpmdig "-d4" 506 fn pamaid num ulong to void 507 papw tpmslash 508 d = ulong 1000 509 for i ulong 4 510 papc uchar add rem div num d 10 48 511 d = div d 10 512 end 513 end 514 fn pafxcpy to bool 515 n = get fxol 0 516 s = ulong 0 517 header = false 518 while lt s n bound `16777216` 519 e = s 520 while lt e n bound `16777216` 521 if eq get fxo e 10 522 break 523 end 524 e = add e 1 525 end 526 if pafxln s e tpdg 527 header = true 528 end 529 if and header or pafxln s e tpcpf pafxln s e tpcpt 530 ret true 531 end 532 s = add e 1 533 end 534 ret false 535 end 536 fn pamread idx ulong tmo long to long 537 pamaid idx 538 fd = fopen gpp 0 get gppl 0 524288 0 539 if lt fd 0 540 ret 500 541 end 542 pakwt 543 fka tpmio 544 fkopen 545 papw tpmsg 546 pakp 547 fkopen 548 papw tpmpt 549 pakp 550 r = fexecin tmo int fd 551 x = fclose int fd 552 if ne r 0 553 ret 422 554 end 555 papw tpmpt 556 fpb 557 for i ulong get gppl 0 bound 4096 558 fpc get gpp i 559 end 560 r = frdall 561 if or lt r 0 ne get fxotr 0 0 562 ret 422 563 end 564 put fxol 0 ulong r 565 if pafxcpy 566 ret 409 567 end 568 ret 0 569 end 570 fn pamail to long 571 papw tpmd 572 if not pamkdir 573 ret parefu 500 tpmint 574 end 575 dl = add long monons PATMO 576 pakwt 577 fka tpmspl 578 fka tpmdig 579 fkopen 580 fkt tpmo 581 papw tpmd 582 pakp 583 fkopen 584 papw tpwm 585 pakp 586 r = fexec PATMO 587 if or ne r 0 ne get fxotr 0 0 588 ret parefu 422 tpmappl 589 end 590 n = panum 591 if or ne n get gpncm 0 gt n 100 592 ret parefu 422 tpmcnt 593 end 594 for i ulong n bound 100 595 left = sub dl long monons 596 if le left 0 597 ret parefu 422 tpmappl 598 end 599 r = pamread add i 1 left 600 if eq r 409 601 ret parefu 422 tpmcopy 602 end 603 if ne r 0 604 ret parefu 422 tpmappl 605 end 606 end 607 ret 0 608 end 609 note pabinfx: the bytes of the full diff fxo[0, fxol) (paapply3's last git run) hold a NUL byte, a line 610 note that is exactly "GIT binary patch" or a line that starts "Binary files ". Every line of a diff's 611 note body starts with a space, + or -, so those two at column 0 are git's own markers. The bytes decide: 612 note git's own binary test reads only a file's first 8000 bytes (pabinns cannot see a later NUL). 613 fn pabinfx to bool 614 n = get fxol 0 615 s = ulong 0 616 for it ulong `16777216` 617 if ge s n 618 break 619 end 620 e = s 621 while lt e n bound `16777216` 622 c = get fxo e 623 if eq c 0 624 ret true 625 end 626 if eq c 10 627 break 628 end 629 e = add e 1 630 end 631 if pafxln s e tpbf 632 ret true 633 end 634 if eq sub e s len tpgbp 635 if pafxln s e tpgbp 636 ret true 637 end 638 end 639 s = add e 1 640 end 641 ret false 642 end 643 note paraw: fxo holds `git diff --raw --no-renames`: gpnfl = its lines (files changed); false when a 644 note line's new mode is 160000 (a submodule) or a line is not a raw line 645 fn paraw to bool 646 n = get fxol 0 647 c = ulong 0 648 s = ulong 0 649 for it ulong `16777216` 650 if ge s n 651 break 652 end 653 if gt add s 14 n 654 ret false 655 end 656 if ne get fxo s 58 657 ret false 658 end 659 if pasubm add s 8 660 ret false 661 end 662 c = add c 1 663 e = s 664 while lt e n bound `16777216` 665 if eq get fxo e 10 666 break 667 end 668 e = add e 1 669 end 670 s = add e 1 671 end 672 put gpnfl 0 c 673 ret true 674 end 675 note pasubm: fxo[p, p+6) is the mode 160000 676 fn pasubm p ulong to bool 677 if ne get fxo p 49 678 ret false 679 end 680 if ne get fxo add p 1 54 681 ret false 682 end 683 for i ulong 4 684 if ne get fxo add add p 2 i 48 685 ret false 686 end 687 end 688 ret true 689 end 690 note pakrange: one argument "..HEAD" 691 fn pakrange to void 692 fkopen 693 pakbase 694 fkt tpdots 695 fkt tphead 696 end 697 note paapply2: the git runs in the work tree: read-tree base, HEAD at base, am, then head, commit 698 note count, raw diff (files, submodules), numstat (binary files) and the full diff left in fxo, whose 699 note bytes are checked too (pabinfx). 0, or the refusal's status. 700 fn paapply2 to long 701 pakwt 702 fka tprdt 703 fkopen 704 pakbase 705 r = fexec PATMO 706 if ne r 0 707 ret parefu 500 tpmint 708 end 709 pakwt 710 fka tpupr 711 fka tpnod 712 fka tphead 713 fkopen 714 pakbase 715 r = fexec PATMO 716 if ne r 0 717 ret parefu 500 tpmint 718 end 719 pakwt 720 fka tpam 721 fka tpqq 722 fka tpamd 723 fka tpamk 724 fka tpamn 725 fka tpam3 726 fkopen 727 papw tpwm 728 pakp 729 r = fexec PATMO 730 if ne r 0 731 ret parefu 422 tpmappl 732 end 733 pakwt 734 fka tprevp 735 fka tphead 736 r = fexec PATMO 737 if ne r 0 738 ret parefu 500 tpmint 739 end 740 if not pahex40 741 ret parefu 500 tpmint 742 end 743 pakwt 744 fka tprevl 745 fka tpcnt 746 pakrange 747 r = fexec PATMO 748 if ne r 0 749 ret parefu 500 tpmint 750 end 751 if ne panum get gpncm 0 752 ret parefu 422 tpmcnt 753 end 754 ret paapply3 755 end 756 fn paapply3 to long 757 pakwt 758 fka tpdiff 759 fka tpnoext 760 fka tpnotc 761 fka tpraw 762 fka tpnorn 763 fkopen 764 pakbase 765 fka tphead 766 r = fexec PATMO 767 if or ne r 0 ne get fxotr 0 0 768 ret parefu 500 tpmint 769 end 770 if not paraw 771 ret parefu 422 tpmsub 772 end 773 pakwt 774 fka tpdiff 775 fka tpnoext 776 fka tpnotc 777 fka tpnumst 778 fka tpnorn 779 fkopen 780 pakbase 781 fka tphead 782 r = fexec PATMO 783 if or ne r 0 ne get fxotr 0 0 784 ret parefu 500 tpmint 785 end 786 if pabinns 787 ret parefu 422 tpmbin 788 end 789 pakwt 790 fka tpdiff 791 fka tpnoext 792 fka tpnotc 793 fka tpfull 794 fka tpdM 795 fkopen 796 pakbase 797 fka tphead 798 r = fexec PATMO 799 if ne r 0 800 ret parefu 500 tpmint 801 end 802 if ne get fxotr 0 0 803 ret parefu 413 tpmdbig 804 end 805 if pabinfx 806 ret parefu 422 tpmbin 807 end 808 ret 0 809 end 810 note ---- the store: patches//// with mbox, statement, signature, head, 811 note status, title, description, meta and diff. Written into a staging folder beside it and renamed 812 note into place, so an id folder is always whole and is never written again; the repository's index 813 note file gets one line "\n" per patch, appended. 814 fn pamkst to bool 815 papb 816 papt tpsdir 817 if not pamkdir 818 ret false 819 end 820 papt tfowner 821 if not pamkdir 822 ret false 823 end 824 papc 47 825 paprn 826 if not pamkdir 827 ret false 828 end 829 papnew part tpdot 0 0 830 r = makedir gpp 0 get gppl 0 448 831 ret ge r 0 832 end 833 note pameta: the meta file's six lines: author DID, creation time (s), commits, files, mbox bytes, 834 note mbox SHA-256 (the statement's fourth line) 835 fn pameta to bool 836 palb 837 d = get gscur 0 838 o = get gsso d 839 for i ulong get gssl d bound 128 840 palc get gsstr add o i 841 end 842 palc 10 843 paln get gsnow 0 844 palc 10 845 paln get gpncm 0 846 palc 10 847 paln get gpnfl 0 848 palc 10 849 paln get gpmbl 0 850 palc 10 851 n = get gpstl 0 852 for i ulong 64 853 palc get gpst add sub n 130 i 854 end 855 palc 10 856 papnew tpfme 857 ret pawf 5 get gplnl 0 858 end 859 note pahdln: gpln = the head commit and a line feed 860 fn pahdln to void 861 palb 862 for i ulong 40 863 palc get gphead i 864 end 865 palc 10 866 end 867 note pawall9: the nine files into the staging folder; the diff is fxo[0, fxol) (paapply3 left it) 868 fn pawall9 to bool 869 papnew tpfdf 870 if not pawf 6 get fxol 0 871 ret false 872 end 873 papnew tpfmb 874 if not pawf 0 get gpmbl 0 875 ret false 876 end 877 papnew tpfst 878 if not pawf 1 get gpstl 0 879 ret false 880 end 881 papnew tpfsg 882 if not pawf 2 get gpsigl 0 883 ret false 884 end 885 papnew tpftt 886 if not pawf 3 get gpttll 0 887 ret false 888 end 889 papnew tpfds 890 if not pawf 4 get gpdscl 0 891 ret false 892 end 893 if not pameta 894 ret false 895 end 896 pahdln 897 papnew tpfhd 898 if not pawf 5 get gplnl 0 899 ret false 900 end 901 papnew tpfss 902 ret pawtxt tpopen 903 end 904 note padrop: remove the staging folder and the files it may hold 905 fn padrop1 t view uchar * to void 906 papnew t 907 x = unlink gpp 0 get gppl 0 908 end 909 fn padrop to void 910 padrop1 tpfdf 911 padrop1 tpfmb 912 padrop1 tpfst 913 padrop1 tpfsg 914 padrop1 tpftt 915 padrop1 tpfds 916 padrop1 tpfme 917 padrop1 tpfhd 918 padrop1 tpfss 919 papnew part tpdot 0 0 920 x = rmdir gpp 0 get gppl 0 921 end 922 note paidxhas: the index (read into fxo) lists gpid 923 fn paidxhas to bool 924 paprepo 925 papt tpindex 926 fpb 927 for i ulong get gppl 0 bound 4096 928 fpc get gpp i 929 end 930 n = frdall 931 if lt n 17 932 ret false 933 end 934 for r ulong div ulong n 17 bound `1048576` 935 if paidxeq mul r 17 936 ret true 937 end 938 end 939 ret false 940 end 941 fn paidxeq o ulong to bool 942 for i ulong 16 943 if ne get fxo add o i get gpid i 944 ret false 945 end 946 end 947 ret true 948 end 949 note paidxadd: append "\n" to the index (created 0600), written through 950 fn paidxadd to bool 951 paprepo 952 papt tpindex 953 fd = fopen gpp 0 get gppl 0 558145 384 954 if lt fd 0 955 ret false 956 end 957 b = new uchar 4096 0 958 for i ulong 16 959 put b i get gpid i 960 end 961 put b 16 10 962 ok = pawall int fd b 17 963 s = fsync int fd 964 x = fclose int fd 965 ret and ok ge s 0 966 end 967 note pakeep: staging folder -> / (rename), then the index line. false when nothing was kept. 968 fn pakeep to bool 969 if not pamkst 970 ret false 971 end 972 if not pawall9 973 padrop 974 ret false 975 end 976 soavb 977 papnew part tpdot 0 0 978 paavp 979 papid part tpdot 0 0 980 paavp 981 r = renames gspk 0 get gspkl 0 1 982 if lt r 0 983 padrop 984 ret false 985 end 986 ret paidxadd 987 end 988 note paavp: one record of the packed list gspk (social/20crypt.om) holding gpp without a final / 989 fn paavp to void 990 soavopen 991 n = get gppl 0 992 if gt n 0 993 if eq get gpp sub n 1 47 994 n = sub n 1 995 end 996 end 997 for i ulong n bound 4096 998 soavc get gpp i 999 end 1000 end 1001 note paok st w: the text answer of a kept (201, "accepted") or already known (200, "exists") patch: 1002 note its id and the path of its page 1003 fn paok st ulong w view uchar * to long 1004 patext 1005 fput w 1006 fput tpaid 1007 for i ulong 16 1008 fputc get gpid i 1009 end 1010 fputc 10 1011 fput tpapth 1012 fputrl 1013 fput tppats 1014 fputc 47 1015 for i ulong 16 1016 fputc get gpid i 1017 end 1018 fputc 10 1019 ret long st 1020 end 1021 note paapply: work folder, the git runs, the store; the work folder is removed whatever happened 1022 text tpfsbin "/usr/bin/stat" 1023 text tpfstype "-f" 1024 text tpfsfmt "--format=%a %S" 1025 text tpnosp "patch storage is temporarily unavailable" 1026 const PAPRES ulong `1073741824` 1027 note Keep a reserve for the rest of the forge. Compare blocks without multiplying arbitrary values. 1028 fn pafree to bool 1029 fkb 1030 fka tpfsbin 1031 fka tpfstype 1032 fka tpfsfmt 1033 fka tfdata 1034 r = fexec `1000000000` 1035 if or ne r 0 ne get fxotr 0 0 1036 ret false 1037 end 1038 n = get fxol 0 1039 a = ulong 0 1040 size = ulong 0 1041 p = ulong 0 1042 for i ulong n bound 48 1043 c = get fxo i 1044 if eq c 32 1045 p = add i 1 1046 break 1047 end 1048 if or ge i 18 not fisdig c 1049 ret false 1050 end 1051 a = add mul a 10 ulong sub c 48 1052 end 1053 if or le p 1 ge p n 1054 ret false 1055 end 1056 for i ulong sub n p bound 48 1057 c = get fxo add p i 1058 if eq c 10 1059 break 1060 end 1061 if or ge i 18 not fisdig c 1062 ret false 1063 end 1064 size = add mul size 10 ulong sub c 48 1065 end 1066 if eq size 0 1067 ret false 1068 end 1069 ret gt a div PAPRES size 1070 end 1071 fn paapply to long 1072 if not pafree 1073 ret parefu 503 tpnosp 1074 end 1075 if not pastem 1076 ret parefu 500 tpmint 1077 end 1078 r = long 0 1079 if pawork 1080 r = pamail 1081 if eq r 0 1082 r = paapply2 1083 end 1084 else 1085 r = parefu 500 tpmint 1086 end 1087 kept = false 1088 if eq r 0 1089 kept = pakeep 1090 end 1091 if not parmtree 1092 flog tplrm 1093 end 1094 if ne r 0 1095 ret r 1096 end 1097 if not kept 1098 ret parefu 503 tpmwr 1099 end 1100 ret paok 201 tpacc 1101 end 1102 note pasizes: title, description, mbox and sig, each to its own global; 0 or the refusal 1103 fn pasizes to long 1104 if not patitle 1105 ret parefu 400 tpmttl 1106 end 1107 if not padescr 1108 ret parefu 400 tpmdsc 1109 end 1110 r = pambdec 1111 if eq r 413 1112 ret parefu 413 tpmbig 1113 end 1114 if ne r 0 1115 ret parefu 400 tpmb64 1116 end 1117 if not pascan 1118 ret parefu 400 tpmnfp 1119 end 1120 if gt get gpncm 0 100 1121 ret parefu 413 tpmmany 1122 end 1123 if not pasigin 1124 ret parefu 400 tpmsigf 1125 end 1126 ret 0 1127 end 1128 note patake: POST ///patches/new 1129 fn patake to long 1130 r = pagate 1131 if ne r 0 1132 ret r 1133 end 1134 if not pafall 1135 ret parefu 400 tpmform 1136 end 1137 if not parepok 1138 ret parefu 400 tpmrepo 1139 end 1140 papgs 1141 if not paexist 1142 ret parefu 404 tpmnogs 1143 end 1144 if not pabasef 1145 ret parefu 400 tpmbase 1146 end 1147 r = pabasec 1148 if ne r 0 1149 ret r 1150 end 1151 r = pasizes 1152 if ne r 0 1153 ret r 1154 end 1155 pastmt 1156 r = pasigck 1157 if ne r 0 1158 ret r 1159 end 1160 papid part tpdot 0 0 1161 if paexist 1162 if not pasteq 1163 ret parefu 409 tpm409 1164 end 1165 if not paidxhas 1166 if not paidxadd 1167 ret parefu 503 tpmwr 1168 end 1169 end 1170 ret paok 200 tpexi 1171 end 1172 if eq get gpgrd 0 2 1173 ret parefu 422 tpmbin 1174 end 1175 if eq get gpgrd 0 3 1176 ret parefu 422 tpmpath 1177 end 1178 ret paapply 1179 end