interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / tools / bring / src / 40net.om
| 1 | note Network flows. The only network path is /usr/bin/curl with an argument list. |
| 2 | text tcurl "/usr/bin/curl" |
| 3 | text tsshk "/usr/bin/ssh-keygen" |
| 4 | text tdevnul "/dev/null" |
| 5 | text tdefb "https://interplane.io" |
| 6 | text tbenv "INTERPLANE_BASE=" |
| 7 | text thomee "HOME=" |
| 8 | text thttps "https://" |
| 9 | text thttp "http://" |
| 10 | text tloop1 "http://127.0.0.1:" |
| 11 | text tloop2 "http://localhost:" |
| 12 | text tprots "=https" |
| 13 | text tproth "=http" |
| 14 | text tbadb "INTERPLANE_BASE must be https://..., or http:// on 127.0.0.1 or localhost" |
| 15 | text tq "-q" |
| 16 | text tss "-sS" |
| 17 | text tproto "--proto" |
| 18 | text tpredir "--proto-redir" |
| 19 | text tmaxr "--max-redirs" |
| 20 | text tzero "0" |
| 21 | text tdh "-D" |
| 22 | text tdo "-o" |
| 23 | text tdw "-w" |
| 24 | text thcode "%{http_code}" |
| 25 | text tdhh "-H" |
| 26 | text tatsign "@" |
| 27 | text tdata "--data-binary" |
| 28 | text treqh "reqh" |
| 29 | text thdr "hdr" |
| 30 | text tbody "body" |
| 31 | text tcode "code" |
| 32 | text tcerr "cerr" |
| 33 | text tform "form" |
| 34 | text tstmt "stmt" |
| 35 | text tstsig "stmt.sig" |
| 36 | text tchal "chal" |
| 37 | text tchsig "chal.sig" |
| 38 | text tgettar "get.tar" |
| 39 | text torig "Origin: " |
| 40 | text tcook "Cookie: " |
| 41 | text tctype "\nContent-Type: application/x-www-form-urlencoded" |
| 42 | text tsemi "; " |
| 43 | text tpre "__Host-forge_pre=" |
| 44 | text tsess "__Host-forge_session=" |
| 45 | text tsetc "set-cookie: " |
| 46 | text tlogin "/login" |
| 47 | text topenp "/open/" |
| 48 | text tup "/open/up" |
| 49 | text tupj "/open/up/" |
| 50 | text tjson ".json" |
| 51 | text tcsrf "name=\"csrf\" value=\"" |
| 52 | text tnonce "name=\"nonce\" value=\"" |
| 53 | text tts "name=\"ts\" value=\"" |
| 54 | text tquote "\"" |
| 55 | text tfcsrf "csrf=" |
| 56 | text tfnonce "&nonce=" |
| 57 | text tfts "&ts=" |
| 58 | text tfdid "&did=" |
| 59 | text tfsig "&sig=" |
| 60 | text tachunk "&action=chunk&sha=" |
| 61 | text tafin "&action=finish&sha=" |
| 62 | text tfseq "&seq=" |
| 63 | text tfdata "&data=" |
| 64 | text tffiles "&files=" |
| 65 | text tfbytes "&bytes=" |
| 66 | text tfname "&name=" |
| 67 | text tfcons "&consent=yes" |
| 68 | text tnext "next " |
| 69 | text tqueued "queued " |
| 70 | text tchal1 "interplane-forge-login:" |
| 71 | text tcolon1 ":" |
| 72 | text tsig1 "-Y" |
| 73 | text tsign "sign" |
| 74 | text tf "-f" |
| 75 | text tn "-n" |
| 76 | text tnsf "interplane-forge" |
| 77 | text tnsb "interplane-bring" |
| 78 | text ttype "-t" |
| 79 | text ted "ed25519" |
| 80 | text tnpw "-N" |
| 81 | text tcmt "-C" |
| 82 | text tinter "interplane" |
| 83 | text tdir "/.interplane" |
| 84 | text tkeynm "/.interplane/key" |
| 85 | text tpubnm "/.interplane/key.pub" |
| 86 | text tssh "ssh-ed25519 " |
| 87 | text tst1 "interplane-bring 1\nsha256 " |
| 88 | text tst2 "\nfiles " |
| 89 | text tst3 "\nbytes " |
| 90 | text tst4 "\nname " |
| 91 | text tstate "\"state\":\"" |
| 92 | text trid "\"rid\":\"rad:" |
| 93 | text tpage "\"page\":\"" |
| 94 | text tdl "\"download\":\"" |
| 95 | text tdlsha "\"download_sha256\":\"" |
| 96 | text tjname "\"name\":\"" |
| 97 | text tstored "stored" |
| 98 | text trefused "refused" |
| 99 | text tsent "Sent " |
| 100 | text tof " of " |
| 101 | text tbsuf " bytes" |
| 102 | text twait "Interplane has the files and is publishing them. This can take a minute.\n" |
| 103 | text tpubd "Your project page: " |
| 104 | text tdev "Developer details: Radicle ID rad:" |
| 105 | text tclone ", rad clone rad:" |
| 106 | text tsaved "Saved in ./" |
| 107 | text trad "rad:" |
| 108 | |
| 109 | text tnetbad "could not reach Interplane (curl failed)" |
| 110 | text thttpbad "Interplane answered with HTTP " |
| 111 | text tbadrsp "Interplane sent an answer this program does not understand" |
| 112 | text t413 "Interplane answered 413: a request was too large for a proxy in front of it (the hub has no project size limit)" |
| 113 | text t503 "Interplane cannot take uploads right now (queue or storage full); try again later" |
| 114 | text tbusy "The download server is busy; trying again in 10 seconds.\n" |
| 115 | text t403 "Interplane refused the session (sign-in, CSRF or origin)" |
| 116 | text tref "Interplane refused the project: " |
| 117 | text tkeyerr "could not make or read the key in ~/.interplane" |
| 118 | text tsigerr "ssh-keygen could not sign" |
| 119 | text tnohome "HOME is not set" |
| 120 | text tshabad "the download does not match its published SHA-256; nothing was unpacked" |
| 121 | text tridbad "not a project page address or Radicle ID" |
| 122 | text tnodl "this project has no download" |
| 123 | text tnokey "only the computer that brought a project can withdraw it, and this computer has no Interplane key (~/.interplane/key); nothing sent" |
| 124 | text tnotmine "this project was brought by another key; only the computer that brought it can withdraw it; nothing sent" |
| 125 | text tnoshelf "this project is not on the Interplane shelf" |
| 126 | text tjby "\"brought_by\":\"" |
| 127 | text twd1 "Project: " |
| 128 | text twd2 "Brought by: " |
| 129 | text twdq "Withdrawing takes your project off the Interplane shelf, stops this site serving it and stops the Interplane hub sharing it on Radicle. It cannot remove copies that other computers already fetched: publishing was permanent.\nType yes to withdraw it, anything else to stop:\n" |
| 130 | text twdact "&action=withdraw&rid=rad%3A" |
| 131 | text twdwait "Interplane is taking the project off the shelf. This can take a minute.\n" |
| 132 | text twdone "Withdrawn.\n" |
| 133 | text tsgnout "Interplane signed you out before the withdraw was sent; nothing was withdrawn. Run the line again." |
| 134 | text tlocn "location:" |
| 135 | text tloginp "/login" |
| 136 | text tcss "://" |
| 137 | global gbase uchar 4096 |
| 138 | global gbasel ulong 1 |
| 139 | global ghome uchar 4096 |
| 140 | global ghomel ulong 1 |
| 141 | global gpre uchar 4096 |
| 142 | global gprel ulong 1 |
| 143 | global gsess uchar 4096 |
| 144 | global gsessl ulong 1 |
| 145 | global gcsrf uchar 4096 |
| 146 | global gcsrfl ulong 1 |
| 147 | global gval uchar 4096 |
| 148 | global ghttp uchar 1 |
| 149 | global gsha uchar 64 |
| 150 | global gname uchar 64 |
| 151 | global gnamel ulong 1 |
| 152 | global gtotal ulong 1 |
| 153 | |
| 154 | fn envget key view uchar * o edit uchar * to long |
| 155 | b = new uchar 65536 0 |
| 156 | nn = pl_envc |
| 157 | for i ulong ulong nn bound 9223372036854775807 |
| 158 | r = pl_env i b |
| 159 | if gt r 0 |
| 160 | if bat part b 0 ulong r 0 key |
| 161 | k = sub ulong r len key |
| 162 | for j ulong k bound 9223372036854775807 |
| 163 | put o j get b add len key j |
| 164 | end |
| 165 | ret long k |
| 166 | end |
| 167 | end |
| 168 | end |
| 169 | ret -1 |
| 170 | end |
| 171 | fn setbase to void |
| 172 | o = new uchar 4096 0 |
| 173 | n = envget tbenv o |
| 174 | if lt n 0 |
| 175 | n = long cpy o 0 tdefb |
| 176 | end |
| 177 | k = ulong n |
| 178 | while and gt k 0 eq get o sub k 1 47 bound 4096 |
| 179 | k = sub k 1 |
| 180 | end |
| 181 | h = bat part o 0 k 0 thttps |
| 182 | if not h |
| 183 | if not or bat part o 0 k 0 tloop1 bat part o 0 k 0 tloop2 |
| 184 | die tbadb |
| 185 | end |
| 186 | put ghttp 0 1 |
| 187 | end |
| 188 | if or le k 8 gt k 4000 |
| 189 | die tbadb |
| 190 | end |
| 191 | for i ulong k bound 4096 |
| 192 | c = get o i |
| 193 | if or le c 32 ge c 127 |
| 194 | die tbadb |
| 195 | end |
| 196 | if or eq c 34 eq c 92 |
| 197 | die tbadb |
| 198 | end |
| 199 | put gbase i c |
| 200 | end |
| 201 | put gbasel 0 k |
| 202 | hm = new uchar 4096 0 |
| 203 | m = envget thomee hm |
| 204 | if le m 0 |
| 205 | die tnohome |
| 206 | end |
| 207 | for i ulong ulong m bound 4096 |
| 208 | put ghome i get hm i |
| 209 | end |
| 210 | put ghomel 0 ulong m |
| 211 | end |
| 212 | fn tmpfd nm view uchar * to int |
| 213 | ret topen nm 2 |
| 214 | end |
| 215 | fn nullfd to int |
| 216 | fd = pl_open tdevnul 4 0 |
| 217 | if lt fd 0 |
| 218 | die terrio |
| 219 | end |
| 220 | ret int fd |
| 221 | end |
| 222 | note runs an argv. stdout goes to tmp file outnm, stderr to cerr. |
| 223 | fn runprog a view uchar * outnm view uchar * to long |
| 224 | i = nullfd |
| 225 | o = tmpfd outnm |
| 226 | e = tmpfd tcerr |
| 227 | r = pl_run part a 0 get gavn 0 i o e |
| 228 | pl_close i |
| 229 | pl_close o |
| 230 | pl_close e |
| 231 | ret r |
| 232 | end |
| 233 | fn avtmp a edit uchar * nm view uchar * to void |
| 234 | p = new uchar 4096 0 |
| 235 | k = tpath nm p |
| 236 | avadd a part p 0 k |
| 237 | end |
| 238 | fn wrcookie fd int to void |
| 239 | mustwrite fd tcook |
| 240 | first = true |
| 241 | if gt get gprel 0 0 |
| 242 | mustwrite fd tpre |
| 243 | wglob fd 2 |
| 244 | first = false |
| 245 | end |
| 246 | if gt get gsessl 0 0 |
| 247 | if not first |
| 248 | mustwrite fd tsemi |
| 249 | end |
| 250 | mustwrite fd tsess |
| 251 | wglob fd 3 |
| 252 | end |
| 253 | end |
| 254 | fn showcerr to void |
| 255 | fd = topen tcerr 0 |
| 256 | b = new uchar 4096 0 |
| 257 | while true bound 9223372036854775807 |
| 258 | r = read int fd b 0 len b |
| 259 | if le r 0 |
| 260 | break |
| 261 | end |
| 262 | warn part b 0 ulong r |
| 263 | end |
| 264 | pl_close int fd |
| 265 | end |
| 266 | note GET when post is false; POST sends the form temp file. Returns HTTP status. |
| 267 | fn http path view uchar * post bool outnm view uchar * to ulong |
| 268 | reqhfile post |
| 269 | a = new uchar 4096 0 |
| 270 | curlargs a post outnm |
| 271 | u = new uchar 8192 0 |
| 272 | un = gcopy 0 u |
| 273 | un = cpy u un path |
| 274 | avadd a part u 0 un |
| 275 | r = runprog a tcode |
| 276 | if ne r 0 |
| 277 | showcerr |
| 278 | die tnetbad |
| 279 | end |
| 280 | ret readcode |
| 281 | end |
| 282 | note busy: 503, 502, 504 and 429 mean the server is busy (dl's cold-build cache answers 503 with |
| 283 | note Retry-After for up to a minute; the write gate answers 429 and 503). |
| 284 | fn busy c ulong to bool |
| 285 | ret or or eq c 503 eq c 502 or eq c 504 eq c 429 |
| 286 | end |
| 287 | note waitbusy: the plain busy line, then 10 seconds |
| 288 | fn waitbusy to void |
| 289 | warn tbusy |
| 290 | for i ulong 10 |
| 291 | pl_sleep |
| 292 | end |
| 293 | end |
| 294 | note hget: a GET that waits out a busy server for as long as it stays busy (no count, the owner's |
| 295 | note no-hard-caps rule; the bound is the language's loop bound, not a give-up count). Any other code |
| 296 | note is returned to the caller unchanged. |
| 297 | fn hget path view uchar * outnm view uchar * to ulong |
| 298 | while true bound 9223372036854775807 |
| 299 | c = http path false outnm |
| 300 | if not busy c |
| 301 | ret c |
| 302 | end |
| 303 | waitbusy |
| 304 | end |
| 305 | ret 0 |
| 306 | end |
| 307 | fn reqhfile post bool to void |
| 308 | fd = tmpfd treqh |
| 309 | mustwrite fd torig |
| 310 | wglob fd 0 |
| 311 | mustwrite fd tnl |
| 312 | if or gt get gprel 0 0 gt get gsessl 0 0 |
| 313 | wrcookie fd |
| 314 | end |
| 315 | if post |
| 316 | mustwrite fd tctype |
| 317 | end |
| 318 | mustwrite fd tnl |
| 319 | pl_close fd |
| 320 | end |
| 321 | fn curlargs a edit uchar * post bool outnm view uchar * to void |
| 322 | avinit a |
| 323 | avadd a tcurl |
| 324 | avadd a tq |
| 325 | avadd a tss |
| 326 | avadd a tproto |
| 327 | if eq get ghttp 0 1 |
| 328 | avadd a tproth |
| 329 | avadd a tpredir |
| 330 | avadd a tproth |
| 331 | else |
| 332 | avadd a tprots |
| 333 | avadd a tpredir |
| 334 | avadd a tprots |
| 335 | end |
| 336 | avadd a tmaxr |
| 337 | avadd a tzero |
| 338 | avadd a tdh |
| 339 | avtmp a thdr |
| 340 | avadd a tdo |
| 341 | avtmp a outnm |
| 342 | avadd a tdw |
| 343 | avadd a thcode |
| 344 | avadd a tdhh |
| 345 | avat a treqh |
| 346 | if post |
| 347 | avadd a tdata |
| 348 | avat a tform |
| 349 | end |
| 350 | end |
| 351 | note avat: one argument "@<temp path of nm>" (curl reads that file) |
| 352 | fn avat a edit uchar * nm view uchar * to void |
| 353 | p = new uchar 4096 0 |
| 354 | k = tpath nm p |
| 355 | q = new uchar 4097 0 |
| 356 | put q 0 64 |
| 357 | for i ulong k bound 4096 |
| 358 | put q add i 1 get p i |
| 359 | end |
| 360 | avadd a part q 0 add k 1 |
| 361 | end |
| 362 | fn readcode to ulong |
| 363 | c = new uchar 8 0 |
| 364 | fd = topen tcode 0 |
| 365 | n = read int fd c 0 8 |
| 366 | pl_close fd |
| 367 | if ne n 3 |
| 368 | die tbadrsp |
| 369 | end |
| 370 | v = new ulong 1 0 |
| 371 | if not pdec part c 0 3 v |
| 372 | die tbadrsp |
| 373 | end |
| 374 | ret get v 0 |
| 375 | end |
| 376 | note fval: the bytes after marker up to term in temp file nm (into gval); -1 absent, -2 too long or |
| 377 | note malformed. The file is read through a 64 KiB window that keeps its last 8 KiB, so a response |
| 378 | note of any size is scanned; a value is a wire field (cookie, csrf, sha, rid, path) of at most 4096 bytes. |
| 379 | fn fval nm view uchar * mk view uchar * term uchar to long |
| 380 | fd = topen nm 0 |
| 381 | b = new uchar 73728 0 |
| 382 | n = ulong 0 |
| 383 | while true bound 9223372036854775807 |
| 384 | r = read int fd b n 65536 |
| 385 | if lt r 0 |
| 386 | die terrio |
| 387 | end |
| 388 | tot = add n ulong r |
| 389 | v = fscan part b 0 tot mk term eq r 0 |
| 390 | if ne v -3 |
| 391 | pl_close int fd |
| 392 | ret v |
| 393 | end |
| 394 | n = fkeep b tot |
| 395 | end |
| 396 | ret -1 |
| 397 | end |
| 398 | note fkeep: move the last 8192 bytes of b[0, tot) to the front; returns the kept count |
| 399 | fn fkeep b edit uchar * tot ulong to ulong |
| 400 | if le tot 8192 |
| 401 | ret tot |
| 402 | end |
| 403 | s = sub tot 8192 |
| 404 | for x ulong 8192 |
| 405 | put b x get b add s x |
| 406 | end |
| 407 | ret 8192 |
| 408 | end |
| 409 | note fscan: -3 when more input is needed (no marker yet, or a value runs to the window's end) |
| 410 | fn fscan b view uchar * mk view uchar * term uchar eof bool to long |
| 411 | i = ulong 0 |
| 412 | while le add i len mk len b bound 9223372036854775807 |
| 413 | if bat b i mk |
| 414 | ret fvalat b add i len mk term eof |
| 415 | end |
| 416 | i = add i 1 |
| 417 | end |
| 418 | if eof |
| 419 | ret -1 |
| 420 | end |
| 421 | ret -3 |
| 422 | end |
| 423 | fn fvalat b view uchar * j ulong term uchar eof bool to long |
| 424 | k = ulong 0 |
| 425 | p = j |
| 426 | while lt p len b bound 9223372036854775807 |
| 427 | c = get b p |
| 428 | if eq c term |
| 429 | ret long k |
| 430 | end |
| 431 | if or ge k 4096 or lt c 32 eq c 92 |
| 432 | ret -2 |
| 433 | end |
| 434 | put gval k c |
| 435 | k = add k 1 |
| 436 | p = add p 1 |
| 437 | end |
| 438 | if not eof |
| 439 | ret -3 |
| 440 | end |
| 441 | if eq term 10 |
| 442 | ret long k |
| 443 | end |
| 444 | ret -2 |
| 445 | end |
| 446 | fn mustval mk view uchar * term uchar o edit uchar * to ulong |
| 447 | r = fval tbody mk term |
| 448 | if lt r 0 |
| 449 | die tbadrsp |
| 450 | end |
| 451 | if gt ulong r len o |
| 452 | die tbadrsp |
| 453 | end |
| 454 | for i ulong ulong r bound 4096 |
| 455 | put o i get gval i |
| 456 | end |
| 457 | ret ulong r |
| 458 | end |
| 459 | note cookie value from response headers (case-insensitive header name). |
| 460 | fn getcookie nm view uchar * which ulong to void |
| 461 | fd = topen thdr 0 |
| 462 | o = new uchar 4096 0 |
| 463 | b = new uchar 1 0 |
| 464 | line = new uchar 8192 0 |
| 465 | n = ulong 0 |
| 466 | while true bound 9223372036854775807 |
| 467 | r = read int fd b 0 1 |
| 468 | if lt r 0 |
| 469 | die terrio |
| 470 | end |
| 471 | eol = or eq r 0 eq get b 0 10 |
| 472 | if not eol |
| 473 | if lt n len line |
| 474 | put line n get b 0 |
| 475 | end |
| 476 | n = add n 1 |
| 477 | end |
| 478 | if eol |
| 479 | m = n |
| 480 | if gt m len line |
| 481 | m = len line |
| 482 | end |
| 483 | cookieln part line 0 m nm which |
| 484 | n = ulong 0 |
| 485 | if eq r 0 |
| 486 | break |
| 487 | end |
| 488 | end |
| 489 | end |
| 490 | pl_close int fd |
| 491 | end |
| 492 | fn cookieln line view uchar * nm view uchar * which ulong to void |
| 493 | if not bati line 0 tsetc |
| 494 | ret |
| 495 | end |
| 496 | if not bat line len tsetc nm |
| 497 | ret |
| 498 | end |
| 499 | o = new uchar 4096 0 |
| 500 | s = add len tsetc len nm |
| 501 | k = ulong 0 |
| 502 | while lt add s k len line bound 4096 |
| 503 | c = get line add s k |
| 504 | if or eq c 59 le c 32 |
| 505 | break |
| 506 | end |
| 507 | if ge c 127 |
| 508 | break |
| 509 | end |
| 510 | put o k c |
| 511 | k = add k 1 |
| 512 | end |
| 513 | gset which part o 0 k |
| 514 | end |
| 515 | fn checkhttp c ulong to void |
| 516 | if eq c 413 |
| 517 | die t413 |
| 518 | end |
| 519 | if eq c 503 |
| 520 | die t503 |
| 521 | end |
| 522 | if eq c 403 |
| 523 | die t403 |
| 524 | end |
| 525 | e = new uchar 24 0 |
| 526 | k = decw c e 0 |
| 527 | die2 thttpbad part e 0 k |
| 528 | end |
| 529 | fn joinhome nm view uchar * o edit uchar 4096 to ulong |
| 530 | n = gcopy 1 o |
| 531 | ret cpy o n nm |
| 532 | end |
| 533 | fn makekey to void |
| 534 | p = new uchar 4096 0 |
| 535 | k = joinhome tdir p |
| 536 | r = pl_mkdir part p 0 k 448 |
| 537 | st = new uchar 256 0 |
| 538 | if lt pl_stat part p 0 k st 0 |
| 539 | die tkeyerr |
| 540 | end |
| 541 | if ne and pl_mode st 61440 16384 |
| 542 | die tkeyerr |
| 543 | end |
| 544 | k = joinhome tkeynm p |
| 545 | a = new uchar 4096 0 |
| 546 | if lt pl_stat part p 0 k st 0 |
| 547 | avinit a |
| 548 | avadd a tsshk |
| 549 | avadd a tq |
| 550 | avadd a ttype |
| 551 | avadd a ted |
| 552 | avadd a tnpw |
| 553 | avadd a part tnpw 0 0 |
| 554 | avadd a tcmt |
| 555 | avadd a tinter |
| 556 | avadd a tf |
| 557 | avadd a part p 0 k |
| 558 | if ne runprog a tbody 0 |
| 559 | showcerr |
| 560 | die tkeyerr |
| 561 | end |
| 562 | end |
| 563 | end |
| 564 | fn readpk pk edit uchar 32 to void |
| 565 | p = new uchar 4096 0 |
| 566 | k = joinhome tpubnm p |
| 567 | fd = pl_open part p 0 k 0 0 |
| 568 | if lt fd 0 |
| 569 | die tkeyerr |
| 570 | end |
| 571 | b = new uchar 4096 0 |
| 572 | n = read int fd b 0 len b |
| 573 | pl_close int fd |
| 574 | if or le n long len tssh not bat part b 0 ulong n 0 tssh |
| 575 | die tkeyerr |
| 576 | end |
| 577 | s = len tssh |
| 578 | e = s |
| 579 | while and lt e ulong n ne get b e 32 bound 4096 |
| 580 | if eq get b e 10 |
| 581 | break |
| 582 | end |
| 583 | e = add e 1 |
| 584 | end |
| 585 | blob = new uchar 64 0 |
| 586 | m = b64d part b s sub e s blob |
| 587 | if ne m 51 |
| 588 | die tkeyerr |
| 589 | end |
| 590 | if or ne rd32 blob 0 184549376 ne get blob 18 32 |
| 591 | die tkeyerr |
| 592 | end |
| 593 | for i ulong 32 |
| 594 | put pk i get blob add 19 i |
| 595 | end |
| 596 | end |
| 597 | fn sign nm view uchar * ns view uchar * to void |
| 598 | p = new uchar 4096 0 |
| 599 | kp = new uchar 4096 0 |
| 600 | kn = joinhome tkeynm kp |
| 601 | sn = new uchar 4096 0 |
| 602 | k = tpath nm sn |
| 603 | a = new uchar 4096 0 |
| 604 | avinit a |
| 605 | avadd a tsshk |
| 606 | avadd a tsig1 |
| 607 | avadd a tsign |
| 608 | avadd a tf |
| 609 | avadd a part kp 0 kn |
| 610 | avadd a tn |
| 611 | avadd a ns |
| 612 | avadd a part sn 0 k |
| 613 | if ne runprog a tbody 0 |
| 614 | showcerr |
| 615 | die tsigerr |
| 616 | end |
| 617 | end |
| 618 | fn formput fd int t view uchar * to void |
| 619 | mustwrite fd t |
| 620 | end |
| 621 | fn formsig fd int nm view uchar * to void |
| 622 | src = topen nm 0 |
| 623 | b = new uchar 4096 0 |
| 624 | o = new uchar 12288 0 |
| 625 | while true bound 9223372036854775807 |
| 626 | r = read int src b 0 len b |
| 627 | if lt r 0 |
| 628 | die terrio |
| 629 | end |
| 630 | if eq r 0 |
| 631 | break |
| 632 | end |
| 633 | k = formw part b 0 ulong r o 0 |
| 634 | mustwrite fd part o 0 k |
| 635 | end |
| 636 | pl_close int src |
| 637 | end |
| 638 | note signin0 pk: sign in (GET /login, the signed challenge, POST /login); the session cookie is kept |
| 639 | fn signin0 pk view uchar 32 to void |
| 640 | put gprel 0 0 |
| 641 | put gsessl 0 0 |
| 642 | c = http tlogin false tbody |
| 643 | if ne c 200 |
| 644 | checkhttp c |
| 645 | end |
| 646 | getcookie tpre 2 |
| 647 | if eq get gprel 0 0 |
| 648 | die tbadrsp |
| 649 | end |
| 650 | cs = new uchar 4096 0 |
| 651 | csl = mustval tcsrf 34 cs |
| 652 | no = new uchar 4096 0 |
| 653 | nol = mustval tnonce 34 no |
| 654 | tv = new uchar 4096 0 |
| 655 | tvl = mustval tts 34 tv |
| 656 | fd = tmpfd tchal |
| 657 | mustwrite fd tchal1 |
| 658 | mustwrite fd part no 0 nol |
| 659 | mustwrite fd tcolon1 |
| 660 | mustwrite fd part tv 0 tvl |
| 661 | pl_close fd |
| 662 | sign tchal tnsf |
| 663 | d = new uchar 128 0 |
| 664 | dl = didkey pk d |
| 665 | fd = tmpfd tform |
| 666 | mustwrite fd tfcsrf |
| 667 | formenc fd part cs 0 csl |
| 668 | mustwrite fd tfnonce |
| 669 | formenc fd part no 0 nol |
| 670 | mustwrite fd tfts |
| 671 | formenc fd part tv 0 tvl |
| 672 | mustwrite fd tfdid |
| 673 | formenc fd part d 0 dl |
| 674 | mustwrite fd tfsig |
| 675 | formsig fd tchsig |
| 676 | pl_close fd |
| 677 | c = http tlogin true tbody |
| 678 | if and ne c 303 ne c 200 |
| 679 | checkhttp c |
| 680 | end |
| 681 | getcookie tsess 3 |
| 682 | if eq get gsessl 0 0 |
| 683 | die t403 |
| 684 | end |
| 685 | end |
| 686 | note csrfof p: the session's write csrf, read from the page p |
| 687 | fn csrfof p view uchar * to void |
| 688 | c = http p false tbody |
| 689 | if ne c 200 |
| 690 | checkhttp c |
| 691 | end |
| 692 | cs2 = new uchar 4096 0 |
| 693 | k2 = mustval tcsrf 34 cs2 |
| 694 | gset 4 part cs2 0 k2 |
| 695 | end |
| 696 | note signin pk: sign in, then take the write csrf from GET /open/ (bring, withdraw). interplane patch |
| 697 | note takes it from /settings instead (50patch.om): a store-reading forge answers /open/ with its 503 |
| 698 | note "moving" page, and the session's settings page carries the same token on every build |
| 699 | fn signin pk view uchar 32 to void |
| 700 | signin0 pk |
| 701 | csrfof topenp |
| 702 | end |
| 703 | fn formenc fd int s view uchar * to void |
| 704 | o = new uchar 12288 0 |
| 705 | k = formw s o 0 |
| 706 | mustwrite fd part o 0 k |
| 707 | end |
| 708 | fn csrfform fd int to void |
| 709 | mustwrite fd tfcsrf |
| 710 | cs = new uchar 4096 0 |
| 711 | k = gcopy 4 cs |
| 712 | formenc fd part cs 0 k |
| 713 | end |
| 714 | fn nextval c ulong to ulong |
| 715 | b = new uchar 64 0 |
| 716 | fd = topen tbody 0 |
| 717 | n = read int fd b 0 len b |
| 718 | pl_close int fd |
| 719 | if or lt n long len tnext not bat part b 0 ulong n 0 tnext |
| 720 | die tbadrsp |
| 721 | end |
| 722 | e = ulong n |
| 723 | while and gt e len tnext or eq get b sub e 1 10 eq get b sub e 1 13 bound 64 |
| 724 | e = sub e 1 |
| 725 | end |
| 726 | v = new ulong 1 0 |
| 727 | if not pdec part b len tnext sub e len tnext v |
| 728 | die tbadrsp |
| 729 | end |
| 730 | ret get v 0 |
| 731 | end |
| 732 | fn wdec fd int v ulong to void |
| 733 | d = new uchar 24 0 |
| 734 | k = decw v d 0 |
| 735 | mustwrite fd part d 0 k |
| 736 | end |
| 737 | fn progress done ulong total ulong to void |
| 738 | x = done |
| 739 | if gt x total |
| 740 | x = total |
| 741 | end |
| 742 | cr = new uchar 1 0 |
| 743 | put cr 0 13 |
| 744 | warn cr |
| 745 | warn tsent |
| 746 | warnd x |
| 747 | warn tof |
| 748 | warnd total |
| 749 | warn tbsuf |
| 750 | end |
| 751 | note sendchunks: 45000-byte chunks in seq order. 200 and 409 both name the next seq the server |
| 752 | note wants; 429 waits a second and retries the same chunk for as long as the server says 429; |
| 753 | note 503 (queue or storage full) says so in a line, waits 10 seconds and resends the same chunk. |
| 754 | fn sendchunks tar int sh view uchar * total ulong to void |
| 755 | nch = div add total 44999 45000 |
| 756 | seq = ulong 0 |
| 757 | while lt seq nch bound 9223372036854775807 |
| 758 | progress mul seq 45000 total |
| 759 | chunkform tar sh seq total |
| 760 | c = http tup true tbody |
| 761 | if eq c 429 |
| 762 | pl_sleep |
| 763 | continue |
| 764 | end |
| 765 | if eq c 503 |
| 766 | warn tnl |
| 767 | waitbusy |
| 768 | continue |
| 769 | end |
| 770 | if and ne c 200 ne c 409 |
| 771 | checkhttp c |
| 772 | end |
| 773 | nx = nextval c |
| 774 | if gt nx nch |
| 775 | die tbadrsp |
| 776 | end |
| 777 | seq = nx |
| 778 | end |
| 779 | progress total total |
| 780 | warn tnl |
| 781 | end |
| 782 | fn chunkform tar int sh view uchar * seq ulong total ulong to void |
| 783 | b = new uchar 45000 0 |
| 784 | e = new uchar 60000 0 |
| 785 | pos = mul seq 45000 |
| 786 | k = sub total pos |
| 787 | if gt k 45000 |
| 788 | k = ulong 45000 |
| 789 | end |
| 790 | r = pl_readat tar part b 0 k pos |
| 791 | if ne r long k |
| 792 | die terrio |
| 793 | end |
| 794 | el = b64u part b 0 k e |
| 795 | fd = tmpfd tform |
| 796 | csrfform fd |
| 797 | mustwrite fd tachunk |
| 798 | mustwrite fd sh |
| 799 | mustwrite fd tfseq |
| 800 | wdec fd seq |
| 801 | mustwrite fd tfdata |
| 802 | mustwrite fd part e 0 el |
| 803 | pl_close fd |
| 804 | end |
| 805 | note bringflow: runs only after the exact "yes". Key, archive, statement and its signature, sign-in, |
| 806 | note chunks, finish, status poll, final lines. |
| 807 | fn bringflow folder view uchar * to void |
| 808 | setbase |
| 809 | makekey |
| 810 | pk = new uchar 32 0 |
| 811 | readpk pk |
| 812 | mkarch |
| 813 | mkname |
| 814 | mkstmt |
| 815 | sign tstmt tnsb |
| 816 | signin pk |
| 817 | sh = new uchar 64 0 |
| 818 | k = shacopy sh |
| 819 | tr = topen ttar 0 |
| 820 | sendchunks tr sh get gtotal 0 |
| 821 | pl_close tr |
| 822 | finish sh |
| 823 | pollup sh |
| 824 | finalln |
| 825 | end |
| 826 | fn shacopy o edit uchar 64 to ulong |
| 827 | for i ulong 64 |
| 828 | put o i get gsha i |
| 829 | end |
| 830 | ret 64 |
| 831 | end |
| 832 | fn mkarch to void |
| 833 | arf = tmpfd ttar |
| 834 | archive arf |
| 835 | pl_close arf |
| 836 | tr = topen ttar 0 |
| 837 | d = new uchar 32 0 |
| 838 | shafd tr d |
| 839 | st = new uchar 256 0 |
| 840 | if lt pl_fstat tr st 0 |
| 841 | die terrio |
| 842 | end |
| 843 | put gtotal 0 pl_size st |
| 844 | pl_close tr |
| 845 | h = new uchar 64 0 |
| 846 | k = hexw d h 0 |
| 847 | for i ulong 64 |
| 848 | put gsha i get h i |
| 849 | end |
| 850 | end |
| 851 | note mkname: the statement name from the last component of the folder's absolute path |
| 852 | fn mkname to void |
| 853 | cw = new uchar 4096 0 |
| 854 | cl = pl_cwd cw |
| 855 | base = ulong 0 |
| 856 | for i ulong cl bound 4096 |
| 857 | if eq get cw i 47 |
| 858 | base = add i 1 |
| 859 | end |
| 860 | end |
| 861 | nm = new uchar 64 0 |
| 862 | nl = projname part cw base sub cl base nm |
| 863 | for i ulong nl bound 64 |
| 864 | put gname i get nm i |
| 865 | end |
| 866 | put gnamel 0 nl |
| 867 | end |
| 868 | fn wname fd int to void |
| 869 | nm = new uchar 64 0 |
| 870 | n = get gnamel 0 |
| 871 | for i ulong n bound 64 |
| 872 | put nm i get gname i |
| 873 | end |
| 874 | mustwrite fd part nm 0 n |
| 875 | end |
| 876 | fn mkstmt to void |
| 877 | sh = new uchar 64 0 |
| 878 | k = shacopy sh |
| 879 | fd = tmpfd tstmt |
| 880 | mustwrite fd tst1 |
| 881 | mustwrite fd sh |
| 882 | mustwrite fd tst2 |
| 883 | wdec fd get gcount 0 |
| 884 | mustwrite fd tst3 |
| 885 | wdec fd get gtotal 0 |
| 886 | mustwrite fd tst4 |
| 887 | wname fd |
| 888 | mustwrite fd tnl |
| 889 | pl_close fd |
| 890 | end |
| 891 | fn finish sh view uchar * to void |
| 892 | fd = tmpfd tform |
| 893 | csrfform fd |
| 894 | mustwrite fd tafin |
| 895 | mustwrite fd sh |
| 896 | mustwrite fd tffiles |
| 897 | wdec fd get gcount 0 |
| 898 | mustwrite fd tfbytes |
| 899 | wdec fd get gtotal 0 |
| 900 | mustwrite fd tfname |
| 901 | wname fd |
| 902 | mustwrite fd tfcons |
| 903 | mustwrite fd tfsig |
| 904 | formsig fd tstsig |
| 905 | pl_close fd |
| 906 | c = http tup true tbody |
| 907 | while or eq c 503 eq c 429 bound 9223372036854775807 |
| 908 | if eq c 429 |
| 909 | pl_sleep |
| 910 | else |
| 911 | waitbusy |
| 912 | end |
| 913 | c = http tup true tbody |
| 914 | end |
| 915 | if ne c 200 |
| 916 | checkhttp c |
| 917 | end |
| 918 | q = new uchar 4096 0 |
| 919 | ql = mustval tqueued 10 q |
| 920 | if lt ql 64 |
| 921 | die tbadrsp |
| 922 | end |
| 923 | if not bat part q 0 ql 0 sh |
| 924 | die tbadrsp |
| 925 | end |
| 926 | end |
| 927 | fn pollup sh view uchar * to void |
| 928 | p = new uchar 4096 0 |
| 929 | pn = cpy p 0 tupj |
| 930 | pn = cpy p pn sh |
| 931 | pn = cpy p pn tjson |
| 932 | said = false |
| 933 | s = new uchar 4096 0 |
| 934 | while true bound 9223372036854775807 |
| 935 | c = hget part p 0 pn tbody |
| 936 | if ne c 200 |
| 937 | checkhttp c |
| 938 | end |
| 939 | sl = mustval tstate 34 s |
| 940 | if beq part s 0 sl tstored |
| 941 | break |
| 942 | end |
| 943 | if bat part s 0 sl 0 trefused |
| 944 | die2 tref part s 0 sl |
| 945 | end |
| 946 | if not said |
| 947 | say twait |
| 948 | said = true |
| 949 | end |
| 950 | pl_sleep |
| 951 | end |
| 952 | end |
| 953 | fn finalln to void |
| 954 | rid = new uchar 4096 0 |
| 955 | rl = mustval trid 34 rid |
| 956 | pg = new uchar 4096 0 |
| 957 | gl = mustval tpage 34 pg |
| 958 | if eq gl 0 |
| 959 | die tbadrsp |
| 960 | end |
| 961 | if ne get pg 0 47 |
| 962 | die tbadrsp |
| 963 | end |
| 964 | bb = new uchar 4096 0 |
| 965 | bl = gcopy 0 bb |
| 966 | say tpubd |
| 967 | say part bb 0 bl |
| 968 | sayp part pg 0 gl |
| 969 | say tnl |
| 970 | say tdev |
| 971 | sayp part rid 0 rl |
| 972 | say tclone |
| 973 | sayp part rid 0 rl |
| 974 | say tnl |
| 975 | end |
| 976 | fn b58ok c uchar to bool |
| 977 | for i ulong 58 |
| 978 | if eq get tb58 i c |
| 979 | ret true |
| 980 | end |
| 981 | end |
| 982 | ret false |
| 983 | end |
| 984 | note ridarg: the RID in a page address (<base>/open/<rid>), rad:<rid> or a bare <rid>, checked and |
| 985 | note copied into o; anything else stops with tridbad |
| 986 | fn ridarg arg view uchar * o edit uchar * to ulong |
| 987 | s = ulong 0 |
| 988 | pfx = new uchar 8192 0 |
| 989 | pn = gcopy 0 pfx |
| 990 | pn = cpy pfx pn topenp |
| 991 | if bat arg 0 part pfx 0 pn |
| 992 | s = pn |
| 993 | else |
| 994 | if bat arg 0 trad |
| 995 | s = len trad |
| 996 | end |
| 997 | end |
| 998 | e = len arg |
| 999 | while and gt e s eq get arg sub e 1 47 bound 9223372036854775807 |
| 1000 | e = sub e 1 |
| 1001 | end |
| 1002 | ret ridcopy part arg s sub e s o |
| 1003 | end |
| 1004 | fn ridcopy rid view uchar * o edit uchar * to ulong |
| 1005 | if or lt len rid 20 gt len rid 60 |
| 1006 | die tridbad |
| 1007 | end |
| 1008 | if ne get rid 0 122 |
| 1009 | die tridbad |
| 1010 | end |
| 1011 | for i ulong len rid bound 60 |
| 1012 | if not b58ok get rid i |
| 1013 | die tridbad |
| 1014 | end |
| 1015 | put o i get rid i |
| 1016 | end |
| 1017 | ret len rid |
| 1018 | end |
| 1019 | fn ridjson rid view uchar * p edit uchar * to ulong |
| 1020 | n = cpy p 0 topenp |
| 1021 | n = cpy p n rid |
| 1022 | ret cpy p n tjson |
| 1023 | end |
| 1024 | note getflow: r is made before setbase: ng front-ir (macOS build) reports "not lowered" for a new |
| 1025 | note right after a leading setbase here; omc accepts both orders (PLATFORMS.md, ng defects) |
| 1026 | fn getflow arg view uchar * to void |
| 1027 | r = new uchar 64 0 |
| 1028 | setbase |
| 1029 | n = ridarg arg r |
| 1030 | getflow2 part r 0 n |
| 1031 | end |
| 1032 | fn getflow2 rid view uchar * to void |
| 1033 | p = new uchar 4096 0 |
| 1034 | n = ridjson rid p |
| 1035 | c = hget part p 0 n tbody |
| 1036 | if ne c 200 |
| 1037 | checkhttp c |
| 1038 | end |
| 1039 | dl = new uchar 4096 0 |
| 1040 | if lt fval tbody tdl 34 0 |
| 1041 | die tnodl |
| 1042 | end |
| 1043 | dn = mustval tdl 34 dl |
| 1044 | getmeta |
| 1045 | getfile part dl 0 dn |
| 1046 | end |
| 1047 | note wdflow: interplane withdraw. The key must already exist (it is never made here); the shelf JSON |
| 1048 | note names the project and its bringer; a bringer that is not this key's DID stops before anything |
| 1049 | note is sent; then the plain text and one line from /dev/tty. Only after the exact yes: sign-in (with |
| 1050 | note the csrf from GET /open/), POST /open/ action=withdraw, and the JSON polled until 404 (off the |
| 1051 | note shelf). False when the answer was not yes: nothing was sent. |
| 1052 | fn wdflow arg view uchar * to bool |
| 1053 | setbase |
| 1054 | haskey |
| 1055 | r = new uchar 64 0 |
| 1056 | n = ridarg arg r |
| 1057 | pk = new uchar 32 0 |
| 1058 | readpk pk |
| 1059 | p = new uchar 4096 0 |
| 1060 | pn = ridjson part r 0 n p |
| 1061 | wdcheck pk part p 0 pn |
| 1062 | if not consent twdq |
| 1063 | ret false |
| 1064 | end |
| 1065 | signin pk |
| 1066 | wdpost part r 0 n |
| 1067 | wdpoll part p 0 pn |
| 1068 | say twdone |
| 1069 | ret true |
| 1070 | end |
| 1071 | fn haskey to void |
| 1072 | p = new uchar 4096 0 |
| 1073 | st = new uchar 256 0 |
| 1074 | k = joinhome tkeynm p |
| 1075 | if lt pl_stat part p 0 k st 0 |
| 1076 | die tnokey |
| 1077 | end |
| 1078 | k = joinhome tpubnm p |
| 1079 | if lt pl_stat part p 0 k st 0 |
| 1080 | die tnokey |
| 1081 | end |
| 1082 | end |
| 1083 | note wdcheck: the shelf row's name and brought_by, shown; brought_by must be this key's DID |
| 1084 | fn wdcheck pk view uchar 32 p view uchar * to void |
| 1085 | c = hget p tbody |
| 1086 | if eq c 404 |
| 1087 | die tnoshelf |
| 1088 | end |
| 1089 | if ne c 200 |
| 1090 | checkhttp c |
| 1091 | end |
| 1092 | nm = new uchar 4096 0 |
| 1093 | nl = mustval tjname 34 nm |
| 1094 | by = new uchar 4096 0 |
| 1095 | bl = mustval tjby 34 by |
| 1096 | say twd1 |
| 1097 | sayp part nm 0 nl |
| 1098 | say tnl |
| 1099 | say twd2 |
| 1100 | sayp part by 0 bl |
| 1101 | say tnl |
| 1102 | d = new uchar 128 0 |
| 1103 | dl = didkey pk d |
| 1104 | if not beq part by 0 bl part d 0 dl |
| 1105 | die tnotmine |
| 1106 | end |
| 1107 | end |
| 1108 | fn wdpost rid view uchar * to void |
| 1109 | fd = tmpfd tform |
| 1110 | csrfform fd |
| 1111 | mustwrite fd twdact |
| 1112 | mustwrite fd rid |
| 1113 | pl_close fd |
| 1114 | c = http topenp true tbody |
| 1115 | while busy c bound 9223372036854775807 |
| 1116 | if eq c 429 |
| 1117 | pl_sleep |
| 1118 | else |
| 1119 | waitbusy |
| 1120 | end |
| 1121 | c = http topenp true tbody |
| 1122 | end |
| 1123 | if ne c 303 |
| 1124 | checkhttp c |
| 1125 | end |
| 1126 | lo = new uchar 4096 0 |
| 1127 | ln = hdrloc lo |
| 1128 | if wdopen part lo 0 ln |
| 1129 | ret |
| 1130 | end |
| 1131 | if gt bfind part lo 0 ln tloginp 0 -1 |
| 1132 | warn tsgnout |
| 1133 | warn tnl |
| 1134 | cleanup |
| 1135 | exit 1 |
| 1136 | end |
| 1137 | checkhttp c |
| 1138 | end |
| 1139 | note wdopen: the withdraw was taken only when the 303 goes to the shelf: Location is <base>/open/, |
| 1140 | note absolute or as the base's path (the hub writes its base path, e.g. /open/) |
| 1141 | fn wdopen loc view uchar * to bool |
| 1142 | bb = new uchar 4096 0 |
| 1143 | bl = gcopy 0 bb |
| 1144 | bl = cpy bb bl topenp |
| 1145 | if beq loc part bb 0 bl |
| 1146 | ret true |
| 1147 | end |
| 1148 | p = bfind part bb 0 bl tcss 0 |
| 1149 | if lt p 0 |
| 1150 | ret false |
| 1151 | end |
| 1152 | q = add ulong p len tcss |
| 1153 | while and lt q bl ne get bb q 47 bound 4096 |
| 1154 | q = add q 1 |
| 1155 | end |
| 1156 | ret beq loc part bb q sub bl q |
| 1157 | end |
| 1158 | note hdrloc: the Location header of the last answer (temp file hdr) into o; its length, 0 when none |
| 1159 | fn hdrloc o edit uchar * to ulong |
| 1160 | fd = topen thdr 0 |
| 1161 | b = new uchar 1 0 |
| 1162 | line = new uchar 8192 0 |
| 1163 | n = ulong 0 |
| 1164 | k = ulong 0 |
| 1165 | while true bound 9223372036854775807 |
| 1166 | r = read int fd b 0 1 |
| 1167 | if lt r 0 |
| 1168 | die terrio |
| 1169 | end |
| 1170 | eol = or eq r 0 eq get b 0 10 |
| 1171 | if not eol |
| 1172 | if lt n len line |
| 1173 | put line n get b 0 |
| 1174 | end |
| 1175 | n = add n 1 |
| 1176 | end |
| 1177 | if eol |
| 1178 | if gt n len line |
| 1179 | n = len line |
| 1180 | end |
| 1181 | v = locln part line 0 n o |
| 1182 | if gt v 0 |
| 1183 | k = v |
| 1184 | end |
| 1185 | n = ulong 0 |
| 1186 | if eq r 0 |
| 1187 | break |
| 1188 | end |
| 1189 | end |
| 1190 | end |
| 1191 | pl_close int fd |
| 1192 | ret k |
| 1193 | end |
| 1194 | fn locln line view uchar * o edit uchar * to ulong |
| 1195 | if not bati line 0 tlocn |
| 1196 | ret 0 |
| 1197 | end |
| 1198 | s = len tlocn |
| 1199 | while and lt s len line eq get line s 32 bound 8192 |
| 1200 | s = add s 1 |
| 1201 | end |
| 1202 | k = ulong 0 |
| 1203 | while and lt add s k len line lt k len o bound 8192 |
| 1204 | c = get line add s k |
| 1205 | if le c 32 |
| 1206 | break |
| 1207 | end |
| 1208 | put o k c |
| 1209 | k = add k 1 |
| 1210 | end |
| 1211 | ret k |
| 1212 | end |
| 1213 | fn wdpoll p view uchar * to void |
| 1214 | said = false |
| 1215 | while true bound 9223372036854775807 |
| 1216 | c = hget p tbody |
| 1217 | if eq c 404 |
| 1218 | ret |
| 1219 | end |
| 1220 | if ne c 200 |
| 1221 | checkhttp c |
| 1222 | end |
| 1223 | if not said |
| 1224 | say twdwait |
| 1225 | said = true |
| 1226 | end |
| 1227 | pl_sleep |
| 1228 | end |
| 1229 | end |
| 1230 | note getmeta: download_sha256 into gsha, the folder name (the statement rule) into gname |
| 1231 | fn getmeta to void |
| 1232 | want = new uchar 4096 0 |
| 1233 | wn = mustval tdlsha 34 want |
| 1234 | if ne wn 64 |
| 1235 | die tbadrsp |
| 1236 | end |
| 1237 | for i ulong 64 |
| 1238 | c = get want i |
| 1239 | if not or isdig c and ge c 97 le c 102 |
| 1240 | die tbadrsp |
| 1241 | end |
| 1242 | put gsha i c |
| 1243 | end |
| 1244 | nm0 = new uchar 4096 0 |
| 1245 | nn0 = mustval tjname 34 nm0 |
| 1246 | nm = new uchar 64 0 |
| 1247 | nl = projname part nm0 0 nn0 nm |
| 1248 | for i ulong nl bound 64 |
| 1249 | put gname i get nm i |
| 1250 | end |
| 1251 | put gnamel 0 nl |
| 1252 | end |
| 1253 | fn getfile dl view uchar * to void |
| 1254 | if or lt len dl 7 not bat dl 0 topenp |
| 1255 | die tbadrsp |
| 1256 | end |
| 1257 | for i ulong len dl bound 4096 |
| 1258 | c8 = get dl i |
| 1259 | if not or unres c8 eq c8 47 |
| 1260 | die tbadrsp |
| 1261 | end |
| 1262 | end |
| 1263 | if gt bfind dl tdotdot 0 -1 |
| 1264 | die tbadrsp |
| 1265 | end |
| 1266 | c = hget dl tgettar |
| 1267 | if ne c 200 |
| 1268 | checkhttp c |
| 1269 | end |
| 1270 | tr = topen tgettar 0 |
| 1271 | d = new uchar 32 0 |
| 1272 | shafd tr d |
| 1273 | h = new uchar 64 0 |
| 1274 | k = hexw d h 0 |
| 1275 | want = new uchar 64 0 |
| 1276 | k = shacopy want |
| 1277 | if not beq h want |
| 1278 | die tshabad |
| 1279 | end |
| 1280 | r = pl_seek tr 0 |
| 1281 | tarwalk tr false |
| 1282 | r = pl_seek tr 0 |
| 1283 | unpackin tr |
| 1284 | pl_close tr |
| 1285 | end |
| 1286 | fn unpackin tr int to void |
| 1287 | nm = new uchar 64 0 |
| 1288 | n = get gnamel 0 |
| 1289 | for i ulong n bound 64 |
| 1290 | put nm i get gname i |
| 1291 | end |
| 1292 | if ne pl_mkdir part nm 0 n 493 0 |
| 1293 | die texists |
| 1294 | end |
| 1295 | if lt pl_cd part nm 0 n 0 |
| 1296 | die texists |
| 1297 | end |
| 1298 | tarwalk tr true |
| 1299 | say tsaved |
| 1300 | say part nm 0 n |
| 1301 | say tnl |
| 1302 | end |
| 1303 | fn gcopy which ulong o edit uchar * to ulong |
| 1304 | n = ulong 0 |
| 1305 | if eq which 0 |
| 1306 | n = get gbasel 0 |
| 1307 | for i ulong n bound 4096 |
| 1308 | put o i get gbase i |
| 1309 | end |
| 1310 | end |
| 1311 | if eq which 1 |
| 1312 | n = get ghomel 0 |
| 1313 | for i ulong n bound 4096 |
| 1314 | put o i get ghome i |
| 1315 | end |
| 1316 | end |
| 1317 | if eq which 2 |
| 1318 | n = get gprel 0 |
| 1319 | for i ulong n bound 4096 |
| 1320 | put o i get gpre i |
| 1321 | end |
| 1322 | end |
| 1323 | if eq which 3 |
| 1324 | n = get gsessl 0 |
| 1325 | for i ulong n bound 4096 |
| 1326 | put o i get gsess i |
| 1327 | end |
| 1328 | end |
| 1329 | if eq which 4 |
| 1330 | n = get gcsrfl 0 |
| 1331 | for i ulong n bound 4096 |
| 1332 | put o i get gcsrf i |
| 1333 | end |
| 1334 | end |
| 1335 | ret n |
| 1336 | end |
| 1337 | fn gset which ulong s view uchar * to void |
| 1338 | if gt len s 4096 |
| 1339 | die tbadrsp |
| 1340 | end |
| 1341 | for i ulong len s bound 4096 |
| 1342 | if eq which 2 |
| 1343 | put gpre i get s i |
| 1344 | end |
| 1345 | if eq which 3 |
| 1346 | put gsess i get s i |
| 1347 | end |
| 1348 | if eq which 4 |
| 1349 | put gcsrf i get s i |
| 1350 | end |
| 1351 | end |
| 1352 | if eq which 2 |
| 1353 | put gprel 0 len s |
| 1354 | end |
| 1355 | if eq which 3 |
| 1356 | put gsessl 0 len s |
| 1357 | end |
| 1358 | if eq which 4 |
| 1359 | put gcsrfl 0 len s |
| 1360 | end |
| 1361 | end |
| 1362 | fn wglob fd int which ulong to void |
| 1363 | o = new uchar 4096 0 |
| 1364 | n = gcopy which o |
| 1365 | mustwrite fd part o 0 n |
| 1366 | end |