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 / open / route.om
| 1 | note open/route.om: Open Humanity's shelf of open builds, inside forged. Prefix oh* (functions), |
| 2 | note go* (globals), to* (texts). Composed after the salvage and social slices, whose form reader, |
| 3 | note write precheck and session it uses (slformvalid, slgetform, slffeq, sowpre, soratev, soerr). |
| 4 | note A person signed in with a Radicle key names the Radicle id (RID) of a project that is not |
| 5 | note finished, or not right yet. forged does not fetch anything: it has no network and cannot run |
| 6 | note rad. It appends one line to <data>open/queue and the intake service (open/intake.om, its own |
| 7 | note program outside the sandbox) seeds and fetches the project within limits and rewrites |
| 8 | note <data>open/list.tsv, which this unit shows. |
| 9 | note GET <base>open/ the shelf: every project the intake accepted, marked unfinished and not |
| 10 | note verified; JSON when the request asks for it |
| 11 | note GET <base>open/<rid> one listed project: its row and the snapshot the intake took (head, |
| 12 | note last commits, top-level files, README); JSON interplane/open-build/1 |
| 13 | note GET <base>open.json and <base>open/<rid>.json the same JSON under names of their own |
| 14 | note POST <base>open/ action=bring (rid, note, consent=yes) or action=withdraw (rid) |
| 15 | note Queue lines: B <tab> rid <tab> did <tab> note and W <tab> rid <tab> did |
| 16 | note list.tsv rows: rid, state, did, date, kilobytes, name, description, note. States "open" and |
| 17 | note "held" and "stored" are listed for everyone; any other state is shown only to the key that |
| 18 | note brought the project. |
| 19 | note Every field is escaped on output. Every write under open/ needs room by the intake's measure (ohroom). |
| 20 | note One-command bring and get (contract: one-command-contract.md, slice HUB): |
| 21 | note POST <base>open/up action=chunk (sha, seq, data) or action=finish (files, bytes, name, note, |
| 22 | note consent=yes, sig); text/plain answers; the same write gate as every forge |
| 23 | note write. Queue line: U <tab> sha <tab> did <tab> files <tab> bytes <tab> |
| 24 | note name <tab> note |
| 25 | note GET <base>open/up/<sha>.json the status of the signed-in key's upload of that archive |
| 26 | note GET <base>open/<rid>.tar the snapshot of a shelf project (git archive of HEAD) the intake |
| 27 | note wrote to <data>open/a/<rid>.tar; 404 when there is none |
| 28 | note GET <base>open/alarms.json the intake's alarms (<data>open/alarms.json) |
| 29 | note GET <base>bring.sh, <base>get.sh and <base>withdraw.sh <data>open/tools/bring.sh, get.sh |
| 30 | note and withdraw.sh; 404 when absent |
| 31 | note The shelf and page JSON carry stored_by_hub, download and download_sha256; a stored row says |
| 32 | note who signed what. |
| 33 | text tohtmlct "text/html; charset=utf-8" |
| 34 | text topath "/open/" |
| 35 | text topat2 "/open" |
| 36 | text topjsn "/open.json" |
| 37 | text toejs ".json" |
| 38 | text tonavl "open/\">Open builds</a>" |
| 39 | text toag1 "<p>For agents: this list as JSON at <code>" |
| 40 | text toag2 "open.json</code>, each project at <code>" |
| 41 | text toag3 "open/<rid>.json</code>. The same JSON answers at the page addresses with <code>Accept: application/json</code>.</p>" |
| 42 | text todir "open/" |
| 43 | text toq "queue" |
| 44 | text tolist "list.tsv" |
| 45 | text toti "Open builds" |
| 46 | text torid "rid" |
| 47 | text tonote "note" |
| 48 | text tocons "consent" |
| 49 | text toyes "yes" |
| 50 | text toact "action" |
| 51 | text tobring "bring" |
| 52 | text towith "withdraw" |
| 53 | text tostop "open" |
| 54 | text toheld "held" |
| 55 | text tob58 "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" |
| 56 | text torad "rad:" |
| 57 | text tologin "login" |
| 58 | text tomsg1 "The form was refused. Give the id of your project, tick the permission box, and keep the note under 200 bytes." |
| 59 | text tomsgq "The intake queue is full. Nothing was saved. Try again later." |
| 60 | text toh1 "<div class=\"sl\"><h1>Open builds</h1><p>Bring the project that is not finished, or not right yet. It stays open here so other builders and their agents can pick it up. Nothing on this shelf is verified until a revision carries a receipt.</p>" |
| 61 | text toh2 "<article class=\"sl-card\"><h2>Bring a project</h2><p>Bringing new projects is closed until Interplane's own store accepts them. There is no limit on how many projects one person brings and no size limit. This computer keeps part of its disk free for its own work; a bring that would use that part is refused with the reason (this computer is nearly full; try again later), and nothing is stored. Any signed-in key can bring a project while the operator keeps intake open; if it is limited to a list of keys, a key that is not on the list sees the refusal here. The operator can take down a listing, or every listing of a key. You can withdraw yours at any time.</p>" |
| 62 | text toh3 "<p><a href=\"" |
| 63 | text toh4 "\">Sign in with your key</a> to bring a project.</p></article>" |
| 64 | text tof1 "<form method=\"post\" action=\"" |
| 65 | text tof2 "\"><input type=\"hidden\" name=\"csrf\" value=\"" |
| 66 | text tof3 "\"><input type=\"hidden\" name=\"action\" value=\"bring\"><p><label>Project id <input name=\"rid\" maxlength=\"48\" required></label></p><p><label>What is unfinished, in one line <input name=\"note\" maxlength=\"200\"></label></p><p><label><input type=\"checkbox\" name=\"consent\" value=\"yes\" required> I have the right to share this project and it carries an open license.</label></p><p><button type=\"submit\">Bring it</button></p></form></article>" |
| 67 | text tol1 "<h2>On the shelf</h2>" |
| 68 | text tol0 "<p>The shelf is waiting for its first project. Unfinished is welcome.</p>" |
| 69 | text toc1 "<article class=\"sl-card\"><h3>" |
| 70 | text toc2 "</h3><p>" |
| 71 | text toc3 "</p>" |
| 72 | text tounf1 "<p><strong>Unfinished:</strong> " |
| 73 | text tounf2 "</p>" |
| 74 | text toc5 "<p>Not verified. Brought by " |
| 75 | text toc6 " on " |
| 76 | text toc7 ", " |
| 77 | text toc8 " KiB.</p>" |
| 78 | text toc9 "</article>" |
| 79 | text tow1 "\"><input type=\"hidden\" name=\"action\" value=\"withdraw\"><input type=\"hidden\" name=\"rid\" value=\"" |
| 80 | text tow2 "\"><button type=\"submit\">Withdraw</button></form>" |
| 81 | text tor1 "<article class=\"sl-card\"><h3>" |
| 82 | text tor2 "</h3><p>Only you see this. Intake result: " |
| 83 | text tor3 "</p></article>" |
| 84 | text toend "</div>" |
| 85 | text tocl1 "<a href=\"" |
| 86 | text tocl2 "\">" |
| 87 | text tocl3 "</a>" |
| 88 | text topdir "p/" |
| 89 | text toptxt ".txt" |
| 90 | text top1 "<div class=\"sl\"><p><a href=\"" |
| 91 | text top2 "\">Open builds</a></p><h1>" |
| 92 | text top3 "</h1><p>" |
| 93 | text top4 "</p>" |
| 94 | text top5 "<p>No public Git URL yet: Interplane does not serve Git clones yet.</p>" |
| 95 | text tdv1 "<section class=\"pj-dev\" id=\"For-developers\"><h2>For developers</h2><dl class=\"pj-terms\"><dt>Download</dt><dd>" |
| 96 | text tdvtar ".tar\">" |
| 97 | text tdvtar2 ".tar</a>, SHA-256 <code>" |
| 98 | text tdvcode "</code>" |
| 99 | text tdvnone "None yet." |
| 100 | text tdv4 "</dd><dt>Brought by</dt><dd><code>" |
| 101 | text tdv5 "</code></dd><dt>Their public key</dt><dd><code>" |
| 102 | text tdv6 "</code></dd>" |
| 103 | text tdv7 "</code></dd>" |
| 104 | text tdvhub "<dt>The hub's key</dt><dd><code>" |
| 105 | text tdv8 "</dl><p>Stored by the Interplane hub. The hub's key" |
| 106 | text tdv9 " (" |
| 107 | text tdv10 ")" |
| 108 | text tdv11 " created this repository and signs its history: that shows the hub stored these exact bytes, not who wrote them. The person who brought it signed the list of files (<code>.interplane/brought.txt</code>, signature <code>.interplane/brought.sig</code>) with a key made on their own computer: that shows the same key vouched for exactly these files; it does not show who that person is or that they wrote the code. To check it: <code>ssh-keygen -Y check-novalidate -n interplane-bring -f <their public key> -s .interplane/brought.sig</code>, reading the first five lines of <code>brought.txt</code> on standard input.</p></section>" |
| 109 | text tdidp8 "did:key:" |
| 110 | text tdvsshn "ssh-ed25519" |
| 111 | text top6 "<p>Not verified. Brought by " |
| 112 | text top7 " on " |
| 113 | text top8 ". What follows is a snapshot taken when the project was listed.</p>" |
| 114 | text toph "<p>Head <code>" |
| 115 | text tophe "</code></p>" |
| 116 | text topc "<h2>Latest commits</h2><ul>" |
| 117 | text topt "<h2>Files</h2><ul>" |
| 118 | text topr "<h2>README</h2><pre>" |
| 119 | text topul "</ul>" |
| 120 | text toppre "</pre>" |
| 121 | text topli "<li>" |
| 122 | text toplie "</li>" |
| 123 | text topno "<p>No snapshot of this project yet.</p>" |
| 124 | text topj1 "{\"schema\":\"interplane/open-build/1\",\"rid\":\"" |
| 125 | text topj2 "\",\"verified\":false,\"head\":\"" |
| 126 | text topj3 "\",\"commits\":[" |
| 127 | text topj4 "],\"files\":[" |
| 128 | text topj5 "],\"readme\":\"" |
| 129 | text topj6 "\",\"parts\":[" |
| 130 | text topj7 "]}\n" |
| 131 | text topa1 "<h2>Parts taken from this project</h2><p>Submissions whose origin is this project. A source is shown as it was submitted. An Omega part is only published after its declared example was reproduced; the receipt is on its page.</p><ul>" |
| 132 | text topa2 " (Omega part, verified)" |
| 133 | text topa3 " (source, not verified)" |
| 134 | text topa4 "<h2>Parts taken from this project</h2><p>None yet. Submit one source from it at <a href=\"" |
| 135 | text topa5 "salvage/new\">Bring your build</a> with the origin <code>" |
| 136 | text topa6 "</code>. A derived Omega part whose example is reproduced is listed here with its receipt.</p>" |
| 137 | text topk1 "{\"id\":\"" |
| 138 | text topk2 "\",\"title\":\"" |
| 139 | text topk3 "\",\"kind\":\"omega-part\",\"verified\":true}" |
| 140 | text topk4 "\",\"kind\":\"source\",\"verified\":false}" |
| 141 | text toj1 "{\"schema\":\"interplane/open-builds/1\",\"note\":\"unfinished projects brought to this shelf; nothing here is verified\",\"projects\":[" |
| 142 | text toj2 "{\"rid\":\"" |
| 143 | text toj3 "\",\"brought_by\":\"" |
| 144 | text toj4 "\",\"date\":\"" |
| 145 | text toj5 "\",\"kib\":" |
| 146 | text toj6 ",\"name\":\"" |
| 147 | text toj7 "\",\"description\":\"" |
| 148 | text toj8 "\",\"unfinished\":\"" |
| 149 | text toj9 "\",\"verified\":false}" |
| 150 | text toj10 "]}\n" |
| 151 | text toctj "application/json; charset=utf-8" |
| 152 | text tohex "0123456789abcdef" |
| 153 | text tou00 "\\u00" |
| 154 | note toterms: the terms ohterm looks for, lower case, split by |. Read by code only, never sent. |
| 155 | text toterms "radicle|heartwood|rad:z|rad clone|rad init|rad sync|rad id|rad patch|rad auth|/rad/" |
| 156 | text tocopy ": copy kept from its GitHub history" |
| 157 | text todnone "No description yet." |
| 158 | global gorid uchar 48 |
| 159 | global goridl ulong 1 |
| 160 | global godid uchar 96 |
| 161 | global godidl ulong 1 |
| 162 | global gonote uchar 208 |
| 163 | global gonotel ulong 1 |
| 164 | global gol uchar 65536 |
| 165 | global goll ulong 1 |
| 166 | global goc uchar 65536 |
| 167 | global gost ulong 4 |
| 168 | global gobody ulong 3 |
| 169 | global gojs ulong 1 |
| 170 | global gop uchar 65536 |
| 171 | global gopl ulong 1 |
| 172 | global gotit uchar 208 |
| 173 | global gotitl ulong 1 |
| 174 | global gosha uchar 64 |
| 175 | global godh uchar 16 |
| 176 | global goname uchar 64 |
| 177 | global gonamel ulong 1 |
| 178 | global gosig uchar 65544 |
| 179 | global gosigl ulong 1 |
| 180 | global gonx ulong 2 |
| 181 | global gosat ulong 1 |
| 182 | global goscnt ulong 1 |
| 183 | global gospv ulong 3 |
| 184 | text tospace "space" |
| 185 | text tospf "free " |
| 186 | text tospr " reserve " |
| 187 | text tospa " at " |
| 188 | text tomfull "503 this computer is nearly full; try again later\n" |
| 189 | text tomnr "503 the hub is not ready to take files; try again later\n" |
| 190 | text tomroom "This computer is nearly full. Nothing was saved. Try again later." |
| 191 | text toup "/open/up" |
| 192 | text toupd "/open/up/" |
| 193 | text toalj "/open/alarms.json" |
| 194 | text tobrsh "/bring.sh" |
| 195 | text togtsh "/get.sh" |
| 196 | text towdsh "/withdraw.sh" |
| 197 | text toupdir "up/" |
| 198 | text toadir "a/" |
| 199 | text totools "tools/" |
| 200 | text tobrf "bring.sh" |
| 201 | text togtf "get.sh" |
| 202 | text towdf "withdraw.sh" |
| 203 | text toalf "alarms.json" |
| 204 | text tob64 ".b64" |
| 205 | text tosig ".sig" |
| 206 | text totar ".tar" |
| 207 | text tosha ".sha256" |
| 208 | text toproj "project" |
| 209 | text totxt "text/plain; charset=utf-8" |
| 210 | text totarct "application/x-tar" |
| 211 | text tocda "attachment; filename=\"" |
| 212 | text tofsha "sha" |
| 213 | text tofseq "seq" |
| 214 | text tofdata "data" |
| 215 | text tofchnk "chunk" |
| 216 | text toffin "finish" |
| 217 | text toffile "files" |
| 218 | text tofbyte "bytes" |
| 219 | text tofname "name" |
| 220 | text tofsig "sig" |
| 221 | text tonext "next " |
| 222 | text toqd "queued " |
| 223 | text tostor "stored" |
| 224 | text tosgb "-----BEGIN SSH SIGNATURE-----" |
| 225 | text tosge "-----END SSH SIGNATURE-----" |
| 226 | text tosbh "<p>Stored by the Interplane hub: the hub's key signs the repository's history. The person who brought it signed the list of files.</p>" |
| 227 | text toj9a "\",\"verified\":false" |
| 228 | text tosbh1 ",\"stored_by_hub\":" |
| 229 | text totrue "true" |
| 230 | text tofalse "false" |
| 231 | text todl1 ",\"download\":\"" |
| 232 | text todl2 ".tar\",\"download_sha256\":\"" |
| 233 | text todl0 ",\"download\":null,\"download_sha256\":null" |
| 234 | text topj2b ",\"head\":\"" |
| 235 | text tous1 "{\"schema\":\"interplane/open-upload/1\",\"state\":\"" |
| 236 | text tous2 "\",\"rid\":null,\"page\":null}\n" |
| 237 | text torecv "receiving" |
| 238 | text toqueue "queued" |
| 239 | text tom403 "403 sign in first, then send the session cookie and the csrf field\n" |
| 240 | text tom400 "400 the form was refused\n" |
| 241 | text tom503 "503 the queue or the storage is full; try again later\n" |
| 242 | text tom429 "429 too many writes; wait and send the same chunk again\n" |
| 243 | text tom404 "404 no upload of this archive under your key\n" |
| 244 | note ohb58: c is a base58 character |
| 245 | fn ohb58 c uchar to bool |
| 246 | for i ulong len tob58 bound 64 |
| 247 | if eq get tob58 i c |
| 248 | ret true |
| 249 | end |
| 250 | end |
| 251 | ret false |
| 252 | end |
| 253 | note ohrid: the form value gcfv[0, n) as a RID into gorid: an optional "rad:", then z and base58, |
| 254 | note 20 to 44 characters in all |
| 255 | fn ohrid n ulong to bool |
| 256 | a = ulong 0 |
| 257 | if ge n 4 |
| 258 | same = true |
| 259 | for i ulong 4 |
| 260 | if ne get gcfv i get torad i |
| 261 | same = false |
| 262 | end |
| 263 | end |
| 264 | if same |
| 265 | a = ulong 4 |
| 266 | end |
| 267 | end |
| 268 | m = sub n a |
| 269 | if or lt m 20 gt m 44 |
| 270 | ret false |
| 271 | end |
| 272 | if ne get gcfv a 122 |
| 273 | ret false |
| 274 | end |
| 275 | for i ulong m bound 44 |
| 276 | c = get gcfv add a i |
| 277 | if not ohb58 c |
| 278 | ret false |
| 279 | end |
| 280 | put gorid i c |
| 281 | end |
| 282 | put goridl 0 m |
| 283 | ret true |
| 284 | end |
| 285 | note ohdid: the signed-in key's DID into godid. False when signed out or the string is not plain. |
| 286 | fn ohdid to bool |
| 287 | who = get gscur 0 |
| 288 | if eq who 0 |
| 289 | ret false |
| 290 | end |
| 291 | n = get gssl who |
| 292 | if or eq n 0 gt n 96 |
| 293 | ret false |
| 294 | end |
| 295 | o = get gsso who |
| 296 | for i ulong n bound 96 |
| 297 | c = get gsstr add o i |
| 298 | if or le c 32 ge c 127 |
| 299 | ret false |
| 300 | end |
| 301 | put godid i c |
| 302 | end |
| 303 | put godidl 0 n |
| 304 | ret true |
| 305 | end |
| 306 | note ohnote: the form value gcfv[0, n) into gonote: at most 200 bytes, control bytes become spaces |
| 307 | fn ohnote n ulong to bool |
| 308 | if gt n 200 |
| 309 | ret false |
| 310 | end |
| 311 | for i ulong n bound 200 |
| 312 | c = get gcfv i |
| 313 | if or lt c 32 eq c 127 |
| 314 | c = uchar 32 |
| 315 | end |
| 316 | put gonote i c |
| 317 | end |
| 318 | put gonotel 0 n |
| 319 | ret true |
| 320 | end |
| 321 | note ohfile: ffile = <data>open/<name> |
| 322 | fn ohfile name view uchar * to void |
| 323 | put ffilel 0 0 |
| 324 | for i ulong len tfdata bound 128 |
| 325 | ffilc get tfdata i |
| 326 | end |
| 327 | for i ulong len todir bound 16 |
| 328 | ffilc get todir i |
| 329 | end |
| 330 | for i ulong len name bound 16 |
| 331 | ffilc get name i |
| 332 | end |
| 333 | end |
| 334 | note ohappend: one queue line of the given kind (66 B or 87 W). 0 done, else the status to answer. |
| 335 | fn ohappend kind uchar to long |
| 336 | b = new uchar 400 0 |
| 337 | rm = ohroom 400 |
| 338 | if or eq rm 1 eq rm 3 |
| 339 | ret 507 |
| 340 | end |
| 341 | ohfile tostop |
| 342 | put ffilel 0 sub get ffilel 0 len tostop |
| 343 | r = makedir ffile 0 get ffilel 0 448 |
| 344 | ohfile toq |
| 345 | fd = fopen ffile 0 get ffilel 0 558145 384 |
| 346 | if lt fd 0 |
| 347 | ret 503 |
| 348 | end |
| 349 | sz = ohsize int fd |
| 350 | n = ulong 0 |
| 351 | put b 0 kind |
| 352 | put b 1 9 |
| 353 | n = ulong 2 |
| 354 | for i ulong get goridl 0 bound 44 |
| 355 | put b add n i get gorid i |
| 356 | end |
| 357 | n = add n get goridl 0 |
| 358 | put b n 9 |
| 359 | n = add n 1 |
| 360 | for i ulong get godidl 0 bound 96 |
| 361 | put b add n i get godid i |
| 362 | end |
| 363 | n = add n get godidl 0 |
| 364 | if eq kind 66 |
| 365 | put b n 9 |
| 366 | n = add n 1 |
| 367 | for i ulong get gonotel 0 bound 200 |
| 368 | put b add n i get gonote i |
| 369 | end |
| 370 | n = add n get gonotel 0 |
| 371 | end |
| 372 | put b n 10 |
| 373 | n = add n 1 |
| 374 | w = write int fd b 0 n |
| 375 | if ne w long n |
| 376 | if ge sz 0 |
| 377 | r = ftrunc int fd sz |
| 378 | end |
| 379 | x = fclose int fd |
| 380 | ret 503 |
| 381 | end |
| 382 | x = fclose int fd |
| 383 | ohused n |
| 384 | ret 0 |
| 385 | end |
| 386 | note ohgo: 303 to <base>open/ |
| 387 | fn ohgo to long |
| 388 | flocb |
| 389 | floct todir |
| 390 | put fkind 0 2 |
| 391 | ret 303 |
| 392 | end |
| 393 | fn ohpost to long |
| 394 | r = sowpre |
| 395 | if ne r 0 |
| 396 | ret r |
| 397 | end |
| 398 | soratev get gscur 0 get gsnow 0 |
| 399 | if not slformvalid |
| 400 | ret soerr 400 tomsg1 |
| 401 | end |
| 402 | if ne slgetform tsfcsrf 32 |
| 403 | ret soerr 400 tomsg1 |
| 404 | end |
| 405 | if not ohdid |
| 406 | ret 403 |
| 407 | end |
| 408 | n = slgetform torid |
| 409 | if le n 0 |
| 410 | ret soerr 400 tomsg1 |
| 411 | end |
| 412 | if not ohrid ulong n |
| 413 | ret soerr 400 tomsg1 |
| 414 | end |
| 415 | if slffeq toact towith |
| 416 | r = ohappend 87 |
| 417 | if eq r 507 |
| 418 | ret soerr 503 tomroom |
| 419 | end |
| 420 | if ne r 0 |
| 421 | ret soerr 503 tomsgq |
| 422 | end |
| 423 | ret ohgo |
| 424 | end |
| 425 | if not slffeq toact tobring |
| 426 | ret soerr 400 tomsg1 |
| 427 | end |
| 428 | if not slffeq tocons toyes |
| 429 | ret soerr 400 tomsg1 |
| 430 | end |
| 431 | n = slgetform tonote |
| 432 | if lt n 0 |
| 433 | ret soerr 400 tomsg1 |
| 434 | end |
| 435 | if not ohnote ulong n |
| 436 | ret soerr 400 tomsg1 |
| 437 | end |
| 438 | r = ohappend 66 |
| 439 | if eq r 507 |
| 440 | ret soerr 503 tomroom |
| 441 | end |
| 442 | if ne r 0 |
| 443 | ret soerr 503 tomsgq |
| 444 | end |
| 445 | ret ohgo |
| 446 | end |
| 447 | note ---- room: forged cannot measure free space itself (the pinned omc has no statfs host word), so |
| 448 | note it reads the intake's measure, <data>open/space: "free <digits> reserve <digits> at <digits>\n" |
| 449 | note (at most 80 bytes, a regular file, opened O_NOFOLLOW|O_NONBLOCK, parsed strictly). forged |
| 450 | note counts the bytes it writes under open/ after that measure (a new "at" starts the count again), |
| 451 | note so a stale file cannot let it write past the reserve. The folder is forged's own, so this is |
| 452 | note advisory for forged only; the intake checks the reserve again before it uses any of it. |
| 453 | note ohroom: room for n more bytes: 0 yes, 1 no room, 2 no measure (no file), 3 malformed |
| 454 | fn ohroom n ulong to ulong |
| 455 | b = new uchar 96 0 |
| 456 | ohfb tospace |
| 457 | fd = fopen ffile 0 get ffilel 0 559104 0 |
| 458 | if lt fd 0 |
| 459 | ret 2 |
| 460 | end |
| 461 | k = long -1 |
| 462 | if ohreg int fd |
| 463 | k = read int fd b 0 96 |
| 464 | end |
| 465 | x = fclose int fd |
| 466 | if or lt k 1 gt k 80 |
| 467 | ret 3 |
| 468 | end |
| 469 | if not ohspace b ulong k |
| 470 | ret 3 |
| 471 | end |
| 472 | if ne get gospv 2 get gosat 0 |
| 473 | put gosat 0 get gospv 2 |
| 474 | put goscnt 0 0 |
| 475 | end |
| 476 | fr = get gospv 0 |
| 477 | rs = get gospv 1 |
| 478 | if lt fr rs |
| 479 | ret 1 |
| 480 | end |
| 481 | if lt sub fr rs add get goscnt 0 n |
| 482 | ret 1 |
| 483 | end |
| 484 | ret 0 |
| 485 | end |
| 486 | fn ohused n ulong to void |
| 487 | put goscnt 0 add get goscnt 0 n |
| 488 | end |
| 489 | fn ohreg fd int to bool |
| 490 | st = new uchar 128 0 |
| 491 | r = fstat fd st 0 128 |
| 492 | if ne r 0 |
| 493 | ret false |
| 494 | end |
| 495 | m = or ulong get st 16 shl ulong get st 17 8 |
| 496 | ret eq and m 61440 32768 |
| 497 | end |
| 498 | note ohspace: b[0, k) is exactly the space line: its three numbers into gospv |
| 499 | fn ohspace b view uchar 96 k ulong to bool |
| 500 | p = ohsplit b k 0 tospf |
| 501 | if lt p 0 |
| 502 | ret false |
| 503 | end |
| 504 | p = ohspnum b k ulong p 0 |
| 505 | if lt p 0 |
| 506 | ret false |
| 507 | end |
| 508 | p = ohsplit b k ulong p tospr |
| 509 | if lt p 0 |
| 510 | ret false |
| 511 | end |
| 512 | p = ohspnum b k ulong p 1 |
| 513 | if lt p 0 |
| 514 | ret false |
| 515 | end |
| 516 | p = ohsplit b k ulong p tospa |
| 517 | if lt p 0 |
| 518 | ret false |
| 519 | end |
| 520 | p = ohspnum b k ulong p 2 |
| 521 | if lt p 0 |
| 522 | ret false |
| 523 | end |
| 524 | if ne ulong p sub k 1 |
| 525 | ret false |
| 526 | end |
| 527 | ret eq get b ulong p 10 |
| 528 | end |
| 529 | note ohsplit: t at b[p]; the index after it, or -1 |
| 530 | fn ohsplit b view uchar 96 k ulong p ulong t view uchar * to long |
| 531 | if gt add p len t k |
| 532 | ret -1 |
| 533 | end |
| 534 | for i ulong len t bound 16 |
| 535 | if ne get b add p i get t i |
| 536 | ret -1 |
| 537 | end |
| 538 | end |
| 539 | ret long add p len t |
| 540 | end |
| 541 | note ohspnum: 1 to 19 digits at b[p] into gospv i (realns has 19); the index after them, or -1 |
| 542 | fn ohspnum b view uchar 96 k ulong p ulong i ulong to long |
| 543 | v = ulong 0 |
| 544 | q = p |
| 545 | while lt q k bound 96 |
| 546 | c = get b q |
| 547 | if or lt c 48 gt c 57 |
| 548 | break |
| 549 | end |
| 550 | v = add mul v 10 ulong sub c 48 |
| 551 | q = add q 1 |
| 552 | if gt sub q p 19 |
| 553 | ret -1 |
| 554 | end |
| 555 | end |
| 556 | if eq q p |
| 557 | ret -1 |
| 558 | end |
| 559 | put gospv i v |
| 560 | ret long q |
| 561 | end |
| 562 | fn ohnoroom r ulong to void |
| 563 | if eq r 1 |
| 564 | ohtx tomfull |
| 565 | ret |
| 566 | end |
| 567 | ohtx tomnr |
| 568 | end |
| 569 | note ---- the shelf's "Unfinished:" line is left out when the note is empty (no placeholder) |
| 570 | note ohunf: "<p><strong>Unfinished:</strong> <note></p>" for the row s..e, or nothing |
| 571 | fn ohunf s ulong e ulong to void |
| 572 | a = ohfld s e 7 |
| 573 | b = ohfe a e |
| 574 | if le ohdend a b a |
| 575 | ret |
| 576 | end |
| 577 | fput tounf1 |
| 578 | ohdsc s e 7 200 false |
| 579 | fput tounf2 |
| 580 | end |
| 581 | note ---- the developer section of a project the hub stored (classes of the curated project page, |
| 582 | note server/pages.om, in forge.css): download and its SHA-256, the bringer's |
| 583 | note DID and public key (ssh form, encoded from the did:key), the hub's key as the intake read it from |
| 584 | note the node (rad self --did, snapshot line N; left out when the snapshot has none), and what each |
| 585 | note signature shows. Every value is escaped. |
| 586 | fn ohdev s ulong e ulong to void |
| 587 | fput tdv1 |
| 588 | h = new uchar 64 0 |
| 589 | if ohdlsha h |
| 590 | fput tocl1 |
| 591 | fputb |
| 592 | fput todir |
| 593 | ohesc s e 0 44 |
| 594 | fput tdvtar |
| 595 | ohesc s e 0 44 |
| 596 | fput tdvtar2 |
| 597 | for i ulong 64 |
| 598 | fescc get h i |
| 599 | end |
| 600 | fput tdvcode |
| 601 | else |
| 602 | fput tdvnone |
| 603 | end |
| 604 | fput tdv4 |
| 605 | ohesc s e 2 96 |
| 606 | fput tdv5 |
| 607 | ohsshkey s e |
| 608 | fput tdv6 |
| 609 | hub = ohnode |
| 610 | if hub |
| 611 | fput tdvhub |
| 612 | ohnodeout |
| 613 | fput tdv7 |
| 614 | end |
| 615 | fput tdv8 |
| 616 | if hub |
| 617 | fput tdv9 |
| 618 | ohnodeout |
| 619 | fput tdv10 |
| 620 | end |
| 621 | fput tdv11 |
| 622 | end |
| 623 | note ohnode: the snapshot has an N line (the hub's DID); ohnodeout writes it escaped |
| 624 | fn ohnode to bool |
| 625 | ret gt ohpcnt 78 0 |
| 626 | end |
| 627 | fn ohnodeout to void |
| 628 | lim = get gopl 0 |
| 629 | s = ulong 0 |
| 630 | while lt s lim bound 65536 |
| 631 | e = ohpeol s |
| 632 | if ohpk 78 s e |
| 633 | ohpesc add s 2 e |
| 634 | ret |
| 635 | end |
| 636 | s = add e 1 |
| 637 | end |
| 638 | end |
| 639 | note ohsshkey: the row's did:key as "ssh-ed25519 <base64 of the wire blob>", escaped; nothing when the |
| 640 | note did is not an Ed25519 did:key |
| 641 | fn ohsshkey s ulong e ulong to void |
| 642 | a = ohfld s e 2 |
| 643 | b = ohfe a e |
| 644 | d = new uchar 96 0 |
| 645 | n = sub b a |
| 646 | if or le n 9 gt n 96 |
| 647 | ret |
| 648 | end |
| 649 | for i ulong n bound 96 |
| 650 | put d i get gol add a i |
| 651 | end |
| 652 | for i ulong len tdidp8 bound 16 |
| 653 | if ne get d i get tdidp8 i |
| 654 | ret |
| 655 | end |
| 656 | end |
| 657 | pk = new uchar 32 0 |
| 658 | if not sodidpk part d 8 sub n 8 pk |
| 659 | ret |
| 660 | end |
| 661 | ohsshout pk |
| 662 | end |
| 663 | fn ohsshout pk view uchar 32 to void |
| 664 | blob = new uchar 51 0 |
| 665 | put blob 3 11 |
| 666 | for i ulong 11 |
| 667 | put blob add i 4 get tdvsshn i |
| 668 | end |
| 669 | put blob 18 32 |
| 670 | for i ulong 32 |
| 671 | put blob add i 19 get pk i |
| 672 | end |
| 673 | o = new uchar 80 0 |
| 674 | m = sob64 blob o |
| 675 | fput tdvsshn |
| 676 | fputc 32 |
| 677 | for i ulong m bound 80 |
| 678 | fescc get o i |
| 679 | end |
| 680 | end |
| 681 | note ---- the list, a row at a time. It has no size limit: <data>open/list.tsv is read in chunks of |
| 682 | note 65,536 bytes into goc (pread at gost 3) and each row goes to gol (goll bytes from 0), so the |
| 683 | note row helpers take s = 0 and e = goll. gol holds the first 4,096 bytes of each field (every tab |
| 684 | note is kept, so the fields keep their places); every field shown is cut shorter than that anyway |
| 685 | note (ohesc, ohjs: at most 400), so a row of any length is listed. The intake keeps every row whole |
| 686 | note in the file; its list_row_bytes alarm measures the longest. A failed read sets fobtr: the |
| 687 | note reply is a whole 500, never a cut list. gost: 0 fd + 1 (0 closed), 1 next byte of goc, 2 |
| 688 | note bytes in goc, 3 the file offset of goc. |
| 689 | fn ohlopen to void |
| 690 | ohlclose |
| 691 | ohfile tolist |
| 692 | fd = fopen ffile 0 get ffilel 0 557056 0 |
| 693 | if lt fd 0 |
| 694 | ret |
| 695 | end |
| 696 | put gost 0 add ulong fd 1 |
| 697 | put gost 1 0 |
| 698 | put gost 2 0 |
| 699 | put gost 3 0 |
| 700 | end |
| 701 | fn ohlclose to void |
| 702 | f = get gost 0 |
| 703 | if gt f 0 |
| 704 | x = fclose int sub f 1 |
| 705 | end |
| 706 | put gost 0 0 |
| 707 | end |
| 708 | fn ohlfill to bool |
| 709 | pos = add get gost 3 get gost 2 |
| 710 | k = long -4 |
| 711 | while eq k -4 bound 1000000 |
| 712 | k = pread int sub get gost 0 1 goc 0 65536 long pos |
| 713 | end |
| 714 | if lt k 0 |
| 715 | put fobtr 0 1 |
| 716 | ret false |
| 717 | end |
| 718 | if eq k 0 |
| 719 | ret false |
| 720 | end |
| 721 | put gost 3 pos |
| 722 | put gost 2 ulong k |
| 723 | put gost 1 0 |
| 724 | ret true |
| 725 | end |
| 726 | note ohlnext: the next row into gol; false at the end of the list (the file is closed then) |
| 727 | fn ohlnext to bool |
| 728 | if eq get gost 0 0 |
| 729 | ret false |
| 730 | end |
| 731 | n = ulong 0 |
| 732 | fl = ulong 0 |
| 733 | got = false |
| 734 | while true bound 9223372036854775807 |
| 735 | p = get gost 1 |
| 736 | if ge p get gost 2 |
| 737 | if ohlfill |
| 738 | continue |
| 739 | end |
| 740 | if ne get fobtr 0 0 |
| 741 | ohlclose |
| 742 | put goll 0 0 |
| 743 | ret false |
| 744 | end |
| 745 | if not got |
| 746 | ohlclose |
| 747 | ret false |
| 748 | end |
| 749 | break |
| 750 | end |
| 751 | put gost 1 add p 1 |
| 752 | got = true |
| 753 | c = get goc p |
| 754 | if eq c 10 |
| 755 | break |
| 756 | end |
| 757 | if eq c 9 |
| 758 | fl = ulong 0 |
| 759 | end |
| 760 | if and lt fl 4096 lt n 65536 |
| 761 | put gol n c |
| 762 | n = add n 1 |
| 763 | end |
| 764 | if ne c 9 |
| 765 | fl = add fl 1 |
| 766 | end |
| 767 | end |
| 768 | put goll 0 n |
| 769 | ret true |
| 770 | end |
| 771 | note ohfld: start of field k of the row s..e (e when the row has fewer fields) |
| 772 | fn ohfld s ulong e ulong k ulong to ulong |
| 773 | p = s |
| 774 | j = ulong 0 |
| 775 | while lt j k bound 16 |
| 776 | while lt p e bound 262144 |
| 777 | if eq get gol p 9 |
| 778 | break |
| 779 | end |
| 780 | p = add p 1 |
| 781 | end |
| 782 | if lt p e |
| 783 | p = add p 1 |
| 784 | end |
| 785 | j = add j 1 |
| 786 | end |
| 787 | ret p |
| 788 | end |
| 789 | fn ohfe a ulong e ulong to ulong |
| 790 | p = a |
| 791 | while lt p e bound 262144 |
| 792 | if eq get gol p 9 |
| 793 | ret p |
| 794 | end |
| 795 | p = add p 1 |
| 796 | end |
| 797 | ret e |
| 798 | end |
| 799 | note ohesc / ohjs: field k of the row s..e, HTML-escaped or as JSON string bytes, at most cap bytes |
| 800 | fn ohesc s ulong e ulong k ulong cap ulong to void |
| 801 | a = ohfld s e k |
| 802 | b = ohfe a e |
| 803 | if gt sub b a cap |
| 804 | b = add a cap |
| 805 | end |
| 806 | ohescr a b |
| 807 | end |
| 808 | note ohescr: gol[a, b) HTML-escaped |
| 809 | fn ohescr a ulong b ulong to void |
| 810 | i = a |
| 811 | while lt i b bound 262144 |
| 812 | c = get gol i |
| 813 | if ge c 32 |
| 814 | fescc c |
| 815 | end |
| 816 | i = add i 1 |
| 817 | end |
| 818 | end |
| 819 | fn ohjs s ulong e ulong k ulong cap ulong to void |
| 820 | a = ohfld s e k |
| 821 | b = ohfe a e |
| 822 | if gt sub b a cap |
| 823 | b = add a cap |
| 824 | end |
| 825 | ohjsr a b |
| 826 | end |
| 827 | note ohjsr: gol[a, b) as JSON string bytes |
| 828 | fn ohjsr a ulong b ulong to void |
| 829 | i = a |
| 830 | while lt i b bound 262144 |
| 831 | c = get gol i |
| 832 | if or eq c 34 eq c 92 |
| 833 | fputc 92 |
| 834 | fputc c |
| 835 | else |
| 836 | if lt c 32 |
| 837 | fput tou00 |
| 838 | fputc get tohex ulong shr c 4 |
| 839 | fputc get tohex ulong and c 15 |
| 840 | else |
| 841 | fputc c |
| 842 | end |
| 843 | end |
| 844 | i = add i 1 |
| 845 | end |
| 846 | end |
| 847 | note ohterm: gol[a, b) (w 0, the list row) or gop[a, b) (w 1, the snapshot) holds a term of |
| 848 | note toterms, case-insensitive. Radicle was removed on 2026-11-14 and the shelf must not point |
| 849 | note anyone to it, but list.tsv rows and snapshots written before then still carry its wording |
| 850 | note (38 descriptions read "public Radicle home while GitHub is suspended (rad init ...)"). The |
| 851 | note stored data stays as it is: every description, note, state and snapshot line is checked |
| 852 | note here when it is shown (ohdend, ohdsc, ohpshow). |
| 853 | fn ohterm w ulong a ulong b ulong to bool |
| 854 | nt = len toterms |
| 855 | t = ulong 0 |
| 856 | while lt t nt bound 64 |
| 857 | k = ulong 0 |
| 858 | while lt add t k nt bound 64 |
| 859 | if eq get toterms add t k 124 |
| 860 | break |
| 861 | end |
| 862 | k = add k 1 |
| 863 | end |
| 864 | i = a |
| 865 | while le add i k b bound 262144 |
| 866 | m = ulong 0 |
| 867 | while lt m k bound 16 |
| 868 | c = uchar 0 |
| 869 | if eq w 0 |
| 870 | c = get gol add i m |
| 871 | else |
| 872 | c = get gop add i m |
| 873 | end |
| 874 | if and ge c 65 le c 90 |
| 875 | c = add c 32 |
| 876 | end |
| 877 | if ne c get toterms add t m |
| 878 | break |
| 879 | end |
| 880 | m = add m 1 |
| 881 | end |
| 882 | if eq m k |
| 883 | ret true |
| 884 | end |
| 885 | i = add i 1 |
| 886 | end |
| 887 | t = add add t k 1 |
| 888 | end |
| 889 | ret false |
| 890 | end |
| 891 | note ohdend: the end of the part of the list field gol[a, b) that may be shown: b when it has no |
| 892 | note term; else the place of its first ": " when the part before it has none (shown with tocopy); |
| 893 | note else a (nothing of it is shown) |
| 894 | fn ohdend a ulong b ulong to ulong |
| 895 | if not ohterm 0 a b |
| 896 | ret b |
| 897 | end |
| 898 | p = a |
| 899 | while lt add p 1 b bound 262144 |
| 900 | if and eq get gol p 58 eq get gol add p 1 32 |
| 901 | if ohterm 0 a p |
| 902 | ret a |
| 903 | end |
| 904 | ret p |
| 905 | end |
| 906 | p = add p 1 |
| 907 | end |
| 908 | ret a |
| 909 | end |
| 910 | note ohdsc: field k (1 state, 6 description, 7 note) of the row s..e as ohesc (json false) or ohjs |
| 911 | note (json true) show it, through ohdend: a cut part is followed by tocopy (not for a state); a |
| 912 | note description with nothing left is todnone, a note or state with nothing left is empty |
| 913 | fn ohdsc s ulong e ulong k ulong cap ulong json bool to void |
| 914 | a = ohfld s e k |
| 915 | b = ohfe a e |
| 916 | r = ohdend a b |
| 917 | c = r |
| 918 | if gt sub c a cap |
| 919 | c = add a cap |
| 920 | end |
| 921 | if json |
| 922 | ohjsr a c |
| 923 | else |
| 924 | ohescr a c |
| 925 | end |
| 926 | if and gt r a lt r b |
| 927 | if ne k 1 |
| 928 | fput tocopy |
| 929 | end |
| 930 | ret |
| 931 | end |
| 932 | if and eq r a lt a b |
| 933 | if eq k 6 |
| 934 | fput todnone |
| 935 | end |
| 936 | end |
| 937 | end |
| 938 | note ohis: field k of the row equals t |
| 939 | fn ohis s ulong e ulong k ulong t view uchar * to bool |
| 940 | a = ohfld s e k |
| 941 | b = ohfe a e |
| 942 | if ne sub b a len t |
| 943 | ret false |
| 944 | end |
| 945 | for i ulong len t bound 64 |
| 946 | if ne get gol add a i get t i |
| 947 | ret false |
| 948 | end |
| 949 | end |
| 950 | ret true |
| 951 | end |
| 952 | note ohpub: the row is on the shelf: state open (fetched by the intake), held (the node already |
| 953 | note had the project) or stored (brought with the one-command tool; the hub created it) |
| 954 | fn ohpub s ulong e ulong to bool |
| 955 | if ohis s e 1 tostop |
| 956 | ret true |
| 957 | end |
| 958 | if ohis s e 1 toheld |
| 959 | ret true |
| 960 | end |
| 961 | ret ohis s e 1 tostor |
| 962 | end |
| 963 | note ohmine: the row's did (field 2) is the signed-in key (godid) |
| 964 | fn ohmine s ulong e ulong to bool |
| 965 | n = get godidl 0 |
| 966 | if eq n 0 |
| 967 | ret false |
| 968 | end |
| 969 | a = ohfld s e 2 |
| 970 | b = ohfe a e |
| 971 | if ne sub b a n |
| 972 | ret false |
| 973 | end |
| 974 | for i ulong n bound 96 |
| 975 | if ne get gol add a i get godid i |
| 976 | ret false |
| 977 | end |
| 978 | end |
| 979 | ret true |
| 980 | end |
| 981 | note ohrow: a row needs its 8 fields and a well-formed rid |
| 982 | fn ohrow s ulong e ulong to bool |
| 983 | a = ohfld s e 7 |
| 984 | if gt a e |
| 985 | ret false |
| 986 | end |
| 987 | if eq a e |
| 988 | if lt e 1 |
| 989 | ret false |
| 990 | end |
| 991 | if ne get gol sub e 1 9 |
| 992 | ret false |
| 993 | end |
| 994 | end |
| 995 | b = ohfe s e |
| 996 | n = sub b s |
| 997 | if or lt n 20 gt n 44 |
| 998 | ret false |
| 999 | end |
| 1000 | for i ulong n bound 44 |
| 1001 | if not ohb58 get gol add s i |
| 1002 | ret false |
| 1003 | end |
| 1004 | end |
| 1005 | ret true |
| 1006 | end |
| 1007 | fn ohcard s ulong e ulong to void |
| 1008 | fput toc1 |
| 1009 | fput tocl1 |
| 1010 | fputb |
| 1011 | fput todir |
| 1012 | ohesc s e 0 44 |
| 1013 | fput tocl2 |
| 1014 | ohesc s e 5 120 |
| 1015 | fput tocl3 |
| 1016 | fput toc2 |
| 1017 | ohdsc s e 6 400 false |
| 1018 | fput toc3 |
| 1019 | ohunf s e |
| 1020 | fput toc5 |
| 1021 | ohesc s e 2 96 |
| 1022 | fput toc6 |
| 1023 | ohesc s e 3 10 |
| 1024 | fput toc7 |
| 1025 | ohesc s e 4 10 |
| 1026 | fput toc8 |
| 1027 | if ohis s e 1 tostor |
| 1028 | fput tosbh |
| 1029 | end |
| 1030 | if ohmine s e |
| 1031 | fput tof1 |
| 1032 | fputb |
| 1033 | fput todir |
| 1034 | fput tof2 |
| 1035 | socsrfout |
| 1036 | fput tow1 |
| 1037 | ohesc s e 0 44 |
| 1038 | fput tow2 |
| 1039 | end |
| 1040 | fput toc9 |
| 1041 | end |
| 1042 | fn ohrefused s ulong e ulong to void |
| 1043 | fput tor1 |
| 1044 | ohesc s e 0 44 |
| 1045 | fput tor2 |
| 1046 | ohdsc s e 1 80 false |
| 1047 | fput tor3 |
| 1048 | end |
| 1049 | note ohnum: field 4 (kilobytes) as a number |
| 1050 | fn ohnum s ulong e ulong to ulong |
| 1051 | a = ohfld s e 4 |
| 1052 | b = ohfe a e |
| 1053 | v = ulong 0 |
| 1054 | i = a |
| 1055 | while lt i b bound 12 |
| 1056 | c = get gol i |
| 1057 | if and ge c 48 le c 57 |
| 1058 | v = add mul v 10 ulong sub c 48 |
| 1059 | end |
| 1060 | i = add i 1 |
| 1061 | end |
| 1062 | ret v |
| 1063 | end |
| 1064 | fn ohjson to long |
| 1065 | put gobody 0 0 |
| 1066 | put gobody 1 1 |
| 1067 | put gobody 2 0 |
| 1068 | put fkind 0 5 |
| 1069 | fsetct toctj |
| 1070 | ret 200 |
| 1071 | end |
| 1072 | note ohjrow: one shelf JSON row (the comma is emitted by the generator) |
| 1073 | fn ohjrow s ulong e ulong to void |
| 1074 | fput toj2 |
| 1075 | ohjs s e 0 44 |
| 1076 | fput toj3 |
| 1077 | ohjs s e 2 96 |
| 1078 | fput toj4 |
| 1079 | ohjs s e 3 10 |
| 1080 | fput toj5 |
| 1081 | fnum ohnum s e |
| 1082 | fput toj6 |
| 1083 | ohjs s e 5 120 |
| 1084 | fput toj7 |
| 1085 | ohdsc s e 6 400 true |
| 1086 | fput toj8 |
| 1087 | ohdsc s e 7 200 true |
| 1088 | fput toj9a |
| 1089 | ohdlj s e |
| 1090 | fputc 125 |
| 1091 | end |
| 1092 | note ohnav: the forge row entry (server/pages.om fhead) |
| 1093 | fn ohnav to void |
| 1094 | fput tocl1 |
| 1095 | fputb |
| 1096 | fput tonavl |
| 1097 | end |
| 1098 | note ohwj: the request wants JSON: it used a .json name (gojs) or says so in Accept. The .json |
| 1099 | note names exist because a cache in front of forged may key on the address alone. |
| 1100 | fn ohwj to bool |
| 1101 | if ne get gojs 0 0 |
| 1102 | ret true |
| 1103 | end |
| 1104 | ret fjwant |
| 1105 | end |
| 1106 | fn ohpage to long |
| 1107 | put godidl 0 0 |
| 1108 | signed = ohdid |
| 1109 | if ohwj |
| 1110 | ret ohjson |
| 1111 | end |
| 1112 | put gobody 0 0 |
| 1113 | put gobody 1 0 |
| 1114 | put gobody 2 0 |
| 1115 | put fkind 0 5 |
| 1116 | fsetti toti |
| 1117 | fsetct tohtmlct |
| 1118 | ret 200 |
| 1119 | end |
| 1120 | note ohintro: the page fragment's prefix (called by ohbody after the layout header) |
| 1121 | fn ohintro to void |
| 1122 | fput toh1 |
| 1123 | fput toh2 |
| 1124 | if ne get godidl 0 0 |
| 1125 | fput tof1 |
| 1126 | fputb |
| 1127 | fput todir |
| 1128 | fput tof2 |
| 1129 | socsrfout |
| 1130 | fput tof3 |
| 1131 | else |
| 1132 | fput toh3 |
| 1133 | fputb |
| 1134 | fput tologin |
| 1135 | fput toh4 |
| 1136 | end |
| 1137 | fput tol1 |
| 1138 | end |
| 1139 | fn ohoutro to void |
| 1140 | if eq get gobody 2 0 |
| 1141 | fput tol0 |
| 1142 | end |
| 1143 | fput toag1 |
| 1144 | fputb |
| 1145 | fput toag2 |
| 1146 | fputb |
| 1147 | fput toag3 |
| 1148 | fput toend |
| 1149 | end |
| 1150 | note ohbody: the next bounded batch of the shelf response, not a bounded shelf. fsend5 sends it |
| 1151 | note chunked then asks for another batch, until the file ends. Each row is complete in a batch: |
| 1152 | note the HTML translation pass sees whole elements. A row uses at most a few KiB after escaping; |
| 1153 | note the 1 MiB high-water mark leaves room for one more row, not a limit on the response. |
| 1154 | note gobody: 0 phase (0 layout and intro, 1 rows, 2 tail/layout footer, 3 done), 1 JSON, 2 rows. |
| 1155 | fn ohbody to bool |
| 1156 | put fobl 0 0 |
| 1157 | if eq get gobody 0 3 |
| 1158 | ret false |
| 1159 | end |
| 1160 | if eq get gobody 0 0 |
| 1161 | ohlopen |
| 1162 | if ne get gobody 1 0 |
| 1163 | fput toj1 |
| 1164 | else |
| 1165 | if not ftxwant |
| 1166 | fhead |
| 1167 | end |
| 1168 | ohintro |
| 1169 | end |
| 1170 | put gobody 0 1 |
| 1171 | ret true |
| 1172 | end |
| 1173 | if eq get gobody 0 1 |
| 1174 | while ohlnext bound 9223372036854775807 |
| 1175 | s = ulong 0 |
| 1176 | e = get goll 0 |
| 1177 | if ohrow s e |
| 1178 | if ohpub s e |
| 1179 | if ne get gobody 1 0 |
| 1180 | if gt get gobody 2 0 |
| 1181 | fputc 44 |
| 1182 | end |
| 1183 | ohjrow s e |
| 1184 | else |
| 1185 | ohcard s e |
| 1186 | end |
| 1187 | put gobody 2 add get gobody 2 1 |
| 1188 | else |
| 1189 | if and eq get gobody 1 0 ohmine s e |
| 1190 | ohrefused s e |
| 1191 | end |
| 1192 | end |
| 1193 | end |
| 1194 | if ge get fobl 0 1048576 |
| 1195 | ret true |
| 1196 | end |
| 1197 | end |
| 1198 | put gobody 0 2 |
| 1199 | if ne get fobtr 0 0 |
| 1200 | ret false |
| 1201 | end |
| 1202 | if gt get fobl 0 0 |
| 1203 | ret true |
| 1204 | end |
| 1205 | end |
| 1206 | if ne get gobody 1 0 |
| 1207 | fput toj10 |
| 1208 | else |
| 1209 | ohoutro |
| 1210 | if not ftxwant |
| 1211 | ffoot |
| 1212 | end |
| 1213 | end |
| 1214 | put gobody 0 3 |
| 1215 | ret true |
| 1216 | end |
| 1217 | fn ohbodyend to void |
| 1218 | ohlclose |
| 1219 | end |
| 1220 | note ---- the project page: <base>open/<rid> |
| 1221 | note Drawn from the shelf row (name, description, note, who, when) and the snapshot the intake wrote |
| 1222 | note at <data>open/p/<rid>.txt: lines "kind <tab> text" with kind H (head and date), C (a commit), |
| 1223 | note T (a top-level file: type letter, tab, name) or R (a README line). Only a rid whose row is on |
| 1224 | note the shelf (open or held) has a page; every byte is escaped here, whatever the file holds. |
| 1225 | note ohprid: the path after /open/ as a rid into gorid |
| 1226 | fn ohprid to bool |
| 1227 | a = len topath |
| 1228 | n = sub get fpathl 0 a |
| 1229 | if gt n 5 |
| 1230 | same = true |
| 1231 | for i ulong 5 |
| 1232 | if ne fpathat add sub add a n 5 i get toejs i |
| 1233 | same = false |
| 1234 | end |
| 1235 | end |
| 1236 | if same |
| 1237 | n = sub n 5 |
| 1238 | put gojs 0 1 |
| 1239 | end |
| 1240 | end |
| 1241 | if or lt n 20 gt n 44 |
| 1242 | ret false |
| 1243 | end |
| 1244 | for i ulong n bound 44 |
| 1245 | c = fpathat add a i |
| 1246 | if not ohb58 c |
| 1247 | ret false |
| 1248 | end |
| 1249 | put gorid i c |
| 1250 | end |
| 1251 | if ne get gorid 0 122 |
| 1252 | ret false |
| 1253 | end |
| 1254 | put goridl 0 n |
| 1255 | ret true |
| 1256 | end |
| 1257 | fn ohpis s ulong e ulong to bool |
| 1258 | b = ohfe s e |
| 1259 | n = get goridl 0 |
| 1260 | if ne sub b s n |
| 1261 | ret false |
| 1262 | end |
| 1263 | for i ulong n bound 44 |
| 1264 | if ne get gol add s i get gorid i |
| 1265 | ret false |
| 1266 | end |
| 1267 | end |
| 1268 | ret true |
| 1269 | end |
| 1270 | note ohprow: the shelf row (open, held or stored) of gorid into gol (true), else false |
| 1271 | fn ohprow to bool |
| 1272 | ohlopen |
| 1273 | while ohlnext bound 9223372036854775807 |
| 1274 | s = ulong 0 |
| 1275 | e = get goll 0 |
| 1276 | if ohrow s e |
| 1277 | if ohpub s e |
| 1278 | if ohpis s e |
| 1279 | ohlclose |
| 1280 | ret true |
| 1281 | end |
| 1282 | end |
| 1283 | end |
| 1284 | end |
| 1285 | ret false |
| 1286 | end |
| 1287 | note ohpload: <data>open/p/<rid>.txt into gop (at most 65,535 bytes; a longer file is shown cut) |
| 1288 | fn ohpload to void |
| 1289 | put gopl 0 0 |
| 1290 | put ffilel 0 0 |
| 1291 | for i ulong len tfdata bound 128 |
| 1292 | ffilc get tfdata i |
| 1293 | end |
| 1294 | for i ulong len todir bound 16 |
| 1295 | ffilc get todir i |
| 1296 | end |
| 1297 | for i ulong len topdir bound 8 |
| 1298 | ffilc get topdir i |
| 1299 | end |
| 1300 | for i ulong get goridl 0 bound 44 |
| 1301 | ffilc get gorid i |
| 1302 | end |
| 1303 | for i ulong len toptxt bound 8 |
| 1304 | ffilc get toptxt i |
| 1305 | end |
| 1306 | fd = fopen ffile 0 get ffilel 0 557056 0 |
| 1307 | if lt fd 0 |
| 1308 | ret |
| 1309 | end |
| 1310 | n = ulong 0 |
| 1311 | k = long 1 |
| 1312 | while gt k 0 bound 65536 |
| 1313 | k = read int fd gop n sub 65535 n |
| 1314 | if gt k 0 |
| 1315 | n = add n ulong k |
| 1316 | end |
| 1317 | end |
| 1318 | x = fclose int fd |
| 1319 | put gopl 0 n |
| 1320 | end |
| 1321 | fn ohpeol a ulong to ulong |
| 1322 | lim = get gopl 0 |
| 1323 | i = a |
| 1324 | while lt i lim bound 65536 |
| 1325 | if eq get gop i 10 |
| 1326 | ret i |
| 1327 | end |
| 1328 | i = add i 1 |
| 1329 | end |
| 1330 | ret lim |
| 1331 | end |
| 1332 | note ohpesc: gop[a, b) escaped for HTML; a tab becomes a space |
| 1333 | fn ohpesc a ulong b ulong to void |
| 1334 | i = a |
| 1335 | while lt i b bound 65536 |
| 1336 | c = get gop i |
| 1337 | if eq c 9 |
| 1338 | c = uchar 32 |
| 1339 | end |
| 1340 | if ge c 32 |
| 1341 | fescc c |
| 1342 | end |
| 1343 | i = add i 1 |
| 1344 | end |
| 1345 | end |
| 1346 | note ohpjs: gop[a, b) as JSON string bytes; a tab becomes a space |
| 1347 | fn ohpjs a ulong b ulong to void |
| 1348 | i = a |
| 1349 | while lt i b bound 65536 |
| 1350 | c = get gop i |
| 1351 | if eq c 9 |
| 1352 | c = uchar 32 |
| 1353 | end |
| 1354 | if or eq c 34 eq c 92 |
| 1355 | fputc 92 |
| 1356 | fputc c |
| 1357 | else |
| 1358 | if lt c 32 |
| 1359 | fput tou00 |
| 1360 | fputc get tohex ulong shr c 4 |
| 1361 | fputc get tohex ulong and c 15 |
| 1362 | else |
| 1363 | fputc c |
| 1364 | end |
| 1365 | end |
| 1366 | i = add i 1 |
| 1367 | end |
| 1368 | end |
| 1369 | note ohpk: gop[s, e) is a snapshot line of this kind |
| 1370 | fn ohpk kind uchar s ulong e ulong to bool |
| 1371 | if lt e add s 2 |
| 1372 | ret false |
| 1373 | end |
| 1374 | if ne get gop s kind |
| 1375 | ret false |
| 1376 | end |
| 1377 | ret eq get gop add s 1 9 |
| 1378 | end |
| 1379 | note ohpshow: gop[s, e) is a snapshot line of this kind whose text has no ohterm term (a line |
| 1380 | note that has one is left out) |
| 1381 | fn ohpshow kind uchar s ulong e ulong to bool |
| 1382 | if not ohpk kind s e |
| 1383 | ret false |
| 1384 | end |
| 1385 | ret not ohterm 1 add s 2 e |
| 1386 | end |
| 1387 | fn ohpcnt kind uchar to ulong |
| 1388 | lim = get gopl 0 |
| 1389 | n = ulong 0 |
| 1390 | s = ulong 0 |
| 1391 | while lt s lim bound 65536 |
| 1392 | e = ohpeol s |
| 1393 | if ohpshow kind s e |
| 1394 | n = add n 1 |
| 1395 | end |
| 1396 | s = add e 1 |
| 1397 | end |
| 1398 | ret n |
| 1399 | end |
| 1400 | note ohpitem: one snapshot line as HTML |
| 1401 | fn ohpitem kind uchar s ulong e ulong to void |
| 1402 | if eq kind 84 |
| 1403 | if lt e add s 4 |
| 1404 | ret |
| 1405 | end |
| 1406 | fput topli |
| 1407 | ohpesc add s 4 e |
| 1408 | if eq get gop add s 2 116 |
| 1409 | fputc 47 |
| 1410 | end |
| 1411 | fput toplie |
| 1412 | ret |
| 1413 | end |
| 1414 | if eq kind 67 |
| 1415 | fput topli |
| 1416 | ohpesc add s 2 e |
| 1417 | fput toplie |
| 1418 | ret |
| 1419 | end |
| 1420 | ohpesc add s 2 e |
| 1421 | if eq kind 82 |
| 1422 | fputc 10 |
| 1423 | end |
| 1424 | end |
| 1425 | note ohpsec: every snapshot line of one kind, with its heading; nothing when there is none |
| 1426 | fn ohpsec kind uchar to void |
| 1427 | if eq ohpcnt kind 0 |
| 1428 | ret |
| 1429 | end |
| 1430 | if eq kind 72 |
| 1431 | fput toph |
| 1432 | end |
| 1433 | if eq kind 67 |
| 1434 | fput topc |
| 1435 | end |
| 1436 | if eq kind 84 |
| 1437 | fput topt |
| 1438 | end |
| 1439 | if eq kind 82 |
| 1440 | fput topr |
| 1441 | end |
| 1442 | lim = get gopl 0 |
| 1443 | s = ulong 0 |
| 1444 | while lt s lim bound 65536 |
| 1445 | e = ohpeol s |
| 1446 | if ohpshow kind s e |
| 1447 | ohpitem kind s e |
| 1448 | end |
| 1449 | s = add e 1 |
| 1450 | end |
| 1451 | if eq kind 72 |
| 1452 | fput tophe |
| 1453 | end |
| 1454 | if or eq kind 67 eq kind 84 |
| 1455 | fput topul |
| 1456 | end |
| 1457 | if eq kind 82 |
| 1458 | fput toppre |
| 1459 | end |
| 1460 | end |
| 1461 | note ohpjarr: the lines of a kind as JSON strings (a file: its name, a folder with a slash) |
| 1462 | fn ohpjarr kind uchar to void |
| 1463 | lim = get gopl 0 |
| 1464 | n = ulong 0 |
| 1465 | s = ulong 0 |
| 1466 | while lt s lim bound 65536 |
| 1467 | e = ohpeol s |
| 1468 | if ohpshow kind s e |
| 1469 | if gt n 0 |
| 1470 | fputc 44 |
| 1471 | end |
| 1472 | fputc 34 |
| 1473 | if eq kind 84 |
| 1474 | if ge e add s 4 |
| 1475 | ohpjs add s 4 e |
| 1476 | if eq get gop add s 2 116 |
| 1477 | fputc 47 |
| 1478 | end |
| 1479 | end |
| 1480 | else |
| 1481 | ohpjs add s 2 e |
| 1482 | end |
| 1483 | fputc 34 |
| 1484 | n = add n 1 |
| 1485 | end |
| 1486 | s = add e 1 |
| 1487 | end |
| 1488 | end |
| 1489 | note ohpjtxt: the lines of a kind in one JSON string: only the first one, or all joined by \n |
| 1490 | fn ohpjtxt kind uchar first bool to void |
| 1491 | lim = get gopl 0 |
| 1492 | s = ulong 0 |
| 1493 | while lt s lim bound 65536 |
| 1494 | e = ohpeol s |
| 1495 | if ohpshow kind s e |
| 1496 | ohpjs add s 2 e |
| 1497 | if first |
| 1498 | ret |
| 1499 | end |
| 1500 | fputc 92 |
| 1501 | fputc 110 |
| 1502 | end |
| 1503 | s = add e 1 |
| 1504 | end |
| 1505 | end |
| 1506 | note ---- parts taken from the project: the link between the shelf and the submission journey |
| 1507 | note A submission (salvage/) names where it came from in its origin field. A source whose origin |
| 1508 | note is exactly <rid> or rad:<rid>, and an Omega part derived from such a source, are listed on the |
| 1509 | note project page. The salvage slice publishes a derived part only with a passing receipt, so a |
| 1510 | note listed part is a verified one; a source is listed as not verified. The project itself stays |
| 1511 | note "Not verified": this is a list of facts, not a verdict on the project. Only the newest 200 |
| 1512 | note submissions are looked at. Nothing is listed while the salvage store is off. |
| 1513 | note ohtit: the title of the loaded record into gotit |
| 1514 | fn ohtit to void |
| 1515 | n = get gllen 1 |
| 1516 | if gt n 200 |
| 1517 | n = ulong 200 |
| 1518 | end |
| 1519 | o = get gloff 1 |
| 1520 | for i ulong n bound 200 |
| 1521 | put gotit i get glrec add o i |
| 1522 | end |
| 1523 | put gotitl 0 n |
| 1524 | end |
| 1525 | note ohorig: the origin field of the loaded record is exactly <gorid>, or rad:<gorid> as sources |
| 1526 | note named it before the shelf showed the bare id |
| 1527 | fn ohorig to bool |
| 1528 | n = get gllen 2 |
| 1529 | m = get goridl 0 |
| 1530 | if eq n m |
| 1531 | q = get gloff 2 |
| 1532 | for i ulong m bound 44 |
| 1533 | if ne get glrec add q i get gorid i |
| 1534 | ret false |
| 1535 | end |
| 1536 | end |
| 1537 | ret true |
| 1538 | end |
| 1539 | if ne n add 4 m |
| 1540 | ret false |
| 1541 | end |
| 1542 | o = get gloff 2 |
| 1543 | for i ulong 4 |
| 1544 | if ne get glrec add o i get torad i |
| 1545 | ret false |
| 1546 | end |
| 1547 | end |
| 1548 | for i ulong m bound 44 |
| 1549 | if ne get glrec add add o 4 i get gorid i |
| 1550 | ret false |
| 1551 | end |
| 1552 | end |
| 1553 | ret true |
| 1554 | end |
| 1555 | note ohmatch: 0 the public submission id is not from this project, 1 it is a source from it, 2 it |
| 1556 | note is a published Omega part derived from a source from it. Its title is left in gotit. |
| 1557 | fn ohmatch id view uchar * to ulong |
| 1558 | pid = new uchar 64 0 |
| 1559 | if not slpublic id |
| 1560 | ret 0 |
| 1561 | end |
| 1562 | ohtit |
| 1563 | if eq get glrec 8 1 |
| 1564 | if ohorig |
| 1565 | ret 1 |
| 1566 | end |
| 1567 | ret 0 |
| 1568 | end |
| 1569 | if ne get glrec 8 2 |
| 1570 | ret 0 |
| 1571 | end |
| 1572 | if ne get gllen 6 64 |
| 1573 | ret 0 |
| 1574 | end |
| 1575 | o = get gloff 6 |
| 1576 | for i ulong 64 |
| 1577 | put pid i get glrec add o i |
| 1578 | end |
| 1579 | if not slload pid |
| 1580 | ret 0 |
| 1581 | end |
| 1582 | if ne get glrec 8 1 |
| 1583 | ret 0 |
| 1584 | end |
| 1585 | if ohorig |
| 1586 | ret 2 |
| 1587 | end |
| 1588 | ret 0 |
| 1589 | end |
| 1590 | fn ohtjs to void |
| 1591 | for i ulong get gotitl 0 bound 200 |
| 1592 | c = get gotit i |
| 1593 | if or eq c 34 eq c 92 |
| 1594 | fputc 92 |
| 1595 | fputc c |
| 1596 | else |
| 1597 | if lt c 32 |
| 1598 | fput tou00 |
| 1599 | fputc get tohex ulong shr c 4 |
| 1600 | fputc get tohex ulong and c 15 |
| 1601 | else |
| 1602 | fputc c |
| 1603 | end |
| 1604 | end |
| 1605 | end |
| 1606 | end |
| 1607 | fn ohpart id view uchar * k ulong json bool shown ulong to void |
| 1608 | if json |
| 1609 | if gt shown 0 |
| 1610 | fputc 44 |
| 1611 | end |
| 1612 | fput topk1 |
| 1613 | for i ulong 64 |
| 1614 | fputc get id i |
| 1615 | end |
| 1616 | fput topk2 |
| 1617 | ohtjs |
| 1618 | if eq k 2 |
| 1619 | fput topk3 |
| 1620 | else |
| 1621 | fput topk4 |
| 1622 | end |
| 1623 | ret |
| 1624 | end |
| 1625 | if eq shown 0 |
| 1626 | fput topa1 |
| 1627 | end |
| 1628 | fput topli |
| 1629 | fput tlhref |
| 1630 | fputb |
| 1631 | fput tlslug |
| 1632 | for i ulong 64 |
| 1633 | fputc get id i |
| 1634 | end |
| 1635 | fput tlendh |
| 1636 | for i ulong get gotitl 0 bound 200 |
| 1637 | fescc get gotit i |
| 1638 | end |
| 1639 | fput tlenda |
| 1640 | if eq k 2 |
| 1641 | fput topa2 |
| 1642 | else |
| 1643 | fput topa3 |
| 1644 | end |
| 1645 | fput toplie |
| 1646 | end |
| 1647 | fn ohparts json bool to void |
| 1648 | id = new uchar 64 0 |
| 1649 | if not slboot |
| 1650 | ret |
| 1651 | end |
| 1652 | n = get glidxn 0 |
| 1653 | shown = ulong 0 |
| 1654 | for it ulong 200 |
| 1655 | if eq n 0 |
| 1656 | break |
| 1657 | end |
| 1658 | n = sub n 1 |
| 1659 | for i ulong 64 |
| 1660 | put id i get glidx add mul n 65 i |
| 1661 | end |
| 1662 | k = ohmatch id |
| 1663 | if gt k 0 |
| 1664 | ohpart id k json shown |
| 1665 | shown = add shown 1 |
| 1666 | end |
| 1667 | end |
| 1668 | if json |
| 1669 | ret |
| 1670 | end |
| 1671 | if eq shown 0 |
| 1672 | fput topa4 |
| 1673 | fputb |
| 1674 | fput topa5 |
| 1675 | for i ulong get goridl 0 bound 44 |
| 1676 | fescc get gorid i |
| 1677 | end |
| 1678 | fput topa6 |
| 1679 | else |
| 1680 | fput topul |
| 1681 | end |
| 1682 | end |
| 1683 | fn ohpjson s ulong e ulong to long |
| 1684 | put fkind 0 1 |
| 1685 | fsetct toctj |
| 1686 | fput topj1 |
| 1687 | ohjs s e 0 44 |
| 1688 | fput toj3 |
| 1689 | ohjs s e 2 96 |
| 1690 | fput toj4 |
| 1691 | ohjs s e 3 10 |
| 1692 | fput toj5 |
| 1693 | fnum ohnum s e |
| 1694 | fput toj6 |
| 1695 | ohjs s e 5 120 |
| 1696 | fput toj7 |
| 1697 | ohdsc s e 6 400 true |
| 1698 | fput toj8 |
| 1699 | ohdsc s e 7 200 true |
| 1700 | fput toj9a |
| 1701 | ohdlj s e |
| 1702 | fput topj2b |
| 1703 | ohpjtxt 72 true |
| 1704 | fput topj3 |
| 1705 | ohpjarr 67 |
| 1706 | fput topj4 |
| 1707 | ohpjarr 84 |
| 1708 | fput topj5 |
| 1709 | ohpjtxt 82 false |
| 1710 | fput topj6 |
| 1711 | ohparts true |
| 1712 | fput topj7 |
| 1713 | ret 200 |
| 1714 | end |
| 1715 | fn ohproj to long |
| 1716 | if not fget |
| 1717 | ret 405 |
| 1718 | end |
| 1719 | if not ohprid |
| 1720 | ret 404 |
| 1721 | end |
| 1722 | if not ohprow |
| 1723 | ret 404 |
| 1724 | end |
| 1725 | s = ulong 0 |
| 1726 | e = get goll 0 |
| 1727 | ohpload |
| 1728 | if ohwj |
| 1729 | ret ohpjson s e |
| 1730 | end |
| 1731 | put fkind 0 0 |
| 1732 | fsetti toti |
| 1733 | fput top1 |
| 1734 | fputb |
| 1735 | fput todir |
| 1736 | fput top2 |
| 1737 | ohesc s e 5 120 |
| 1738 | fput top3 |
| 1739 | ohdsc s e 6 400 false |
| 1740 | fput top4 |
| 1741 | ohunf s e |
| 1742 | fput top5 |
| 1743 | fput top6 |
| 1744 | ohesc s e 2 96 |
| 1745 | fput top7 |
| 1746 | ohesc s e 3 10 |
| 1747 | fput top8 |
| 1748 | if eq get gopl 0 0 |
| 1749 | fput topno |
| 1750 | end |
| 1751 | ohpsec 72 |
| 1752 | ohpsec 67 |
| 1753 | ohpsec 84 |
| 1754 | ohpsec 82 |
| 1755 | if ohis s e 1 tostor |
| 1756 | ohdev s e |
| 1757 | end |
| 1758 | ohparts false |
| 1759 | fput toend |
| 1760 | ret 200 |
| 1761 | end |
| 1762 | note ohroute: 0 = not an open-builds path |
| 1763 | fn ohroute to long |
| 1764 | put gojs 0 0 |
| 1765 | if fpeq tobrsh |
| 1766 | ret ohtool tobrf |
| 1767 | end |
| 1768 | if fpeq togtsh |
| 1769 | ret ohtool togtf |
| 1770 | end |
| 1771 | if fpeq towdsh |
| 1772 | ret ohtool towdf |
| 1773 | end |
| 1774 | if fpeq topjsn |
| 1775 | if not fget |
| 1776 | ret 405 |
| 1777 | end |
| 1778 | put gojs 0 1 |
| 1779 | ret ohpage |
| 1780 | end |
| 1781 | if fpeq topat2 |
| 1782 | flocb |
| 1783 | floct todir |
| 1784 | put fkind 0 2 |
| 1785 | ret 301 |
| 1786 | end |
| 1787 | if not fpre topath |
| 1788 | ret 0 |
| 1789 | end |
| 1790 | if fpeq toup |
| 1791 | ret ohup |
| 1792 | end |
| 1793 | if fpre toupd |
| 1794 | ret ohupst |
| 1795 | end |
| 1796 | if fpeq toalj |
| 1797 | ret ohalarm |
| 1798 | end |
| 1799 | if ohistar |
| 1800 | ret ohtar |
| 1801 | end |
| 1802 | if not fpeq topath |
| 1803 | ret ohproj |
| 1804 | end |
| 1805 | if eq get fmeth 0 3 |
| 1806 | ret ohpost |
| 1807 | end |
| 1808 | if not fget |
| 1809 | ret 405 |
| 1810 | end |
| 1811 | ret ohpage |
| 1812 | end |
| 1813 | note ---- one-command bring: the upload (contract one-command-contract.md, slice HUB) |
| 1814 | note The spool of one upload is <data>open/up/<sha>.<didhash>.b64, didhash the first 8 bytes of |
| 1815 | note sha256(did) in hex, so a key only ever appends to its own spool. One line per chunk, in seq |
| 1816 | note order: the base64url data, a tab, the seq and the archive bytes received so far as 10 decimal |
| 1817 | note digits each, a line feed. The last 22 bytes of the file are always the newest seq and total, so |
| 1818 | note a chunk costs one short read whatever the size of the spool. finish writes |
| 1819 | note <sha>.<didhash>.sig (the armored signature of the bring statement) and one queue line. The |
| 1820 | note intake (outside this sandbox) checks everything again and writes <sha>.<didhash>.json, the |
| 1821 | note status. Nothing here decodes, unpacks or runs what was brought. |
| 1822 | note ohtx: a text/plain answer |
| 1823 | fn ohtx t view uchar * to void |
| 1824 | put fobl 0 0 |
| 1825 | put fkind 0 1 |
| 1826 | fsetct totxt |
| 1827 | fput t |
| 1828 | end |
| 1829 | fn ohnext n ulong to void |
| 1830 | ohtx tonext |
| 1831 | fnum n |
| 1832 | fputc 10 |
| 1833 | end |
| 1834 | note ohpre: the text answer for a status of the write gate (sowpre) |
| 1835 | fn ohpre r long to void |
| 1836 | if eq r 429 |
| 1837 | ohtx tom429 |
| 1838 | ret |
| 1839 | end |
| 1840 | if eq r 503 |
| 1841 | ohtx tom503 |
| 1842 | ret |
| 1843 | end |
| 1844 | if eq r 403 |
| 1845 | ohtx tom403 |
| 1846 | ret |
| 1847 | end |
| 1848 | ohtx tom400 |
| 1849 | end |
| 1850 | note ohfb: ffile = <data>open/ then t |
| 1851 | fn ohfb t view uchar * to void |
| 1852 | put ffilel 0 0 |
| 1853 | for i ulong len tfdata bound 128 |
| 1854 | ffilc get tfdata i |
| 1855 | end |
| 1856 | for i ulong len todir bound 16 |
| 1857 | ffilc get todir i |
| 1858 | end |
| 1859 | for i ulong len t bound 16 |
| 1860 | ffilc get t i |
| 1861 | end |
| 1862 | end |
| 1863 | note ohupf: ffile = <data>open/up/<sha>.<didhash> then ext |
| 1864 | fn ohupf ext view uchar * to void |
| 1865 | ohfb toupdir |
| 1866 | for i ulong 64 |
| 1867 | ffilc get gosha i |
| 1868 | end |
| 1869 | ffilc 46 |
| 1870 | for i ulong 16 |
| 1871 | ffilc get godh i |
| 1872 | end |
| 1873 | for i ulong len ext bound 16 |
| 1874 | ffilc get ext i |
| 1875 | end |
| 1876 | end |
| 1877 | note ohupmk: <data>open/ and <data>open/up/ exist (made 0700) |
| 1878 | fn ohupmk to void |
| 1879 | ohfb toupdir |
| 1880 | put ffilel 0 sub get ffilel 0 len toupdir |
| 1881 | r = makedir ffile 0 get ffilel 0 448 |
| 1882 | ohfb toupdir |
| 1883 | r = makedir ffile 0 get ffilel 0 448 |
| 1884 | end |
| 1885 | fn ohhex c uchar to bool |
| 1886 | ret or and ge c 48 le c 57 and ge c 97 le c 102 |
| 1887 | end |
| 1888 | fn ohb64c c uchar to bool |
| 1889 | if and ge c 65 le c 90 |
| 1890 | ret true |
| 1891 | end |
| 1892 | if and ge c 97 le c 122 |
| 1893 | ret true |
| 1894 | end |
| 1895 | if and ge c 48 le c 57 |
| 1896 | ret true |
| 1897 | end |
| 1898 | ret or eq c 45 eq c 95 |
| 1899 | end |
| 1900 | fn ohws c uchar to bool |
| 1901 | ret or or eq c 32 eq c 10 or eq c 9 eq c 13 |
| 1902 | end |
| 1903 | fn ohsigc c uchar to bool |
| 1904 | if ohb64c c |
| 1905 | ret true |
| 1906 | end |
| 1907 | ret or or eq c 43 eq c 47 or or eq c 61 eq c 32 eq c 10 |
| 1908 | end |
| 1909 | note ohsha: the form value gcfv[0, n) is 64 lowercase hex: into gosha |
| 1910 | fn ohsha n long to bool |
| 1911 | if ne n 64 |
| 1912 | ret false |
| 1913 | end |
| 1914 | for i ulong 64 |
| 1915 | c = get gcfv i |
| 1916 | if not ohhex c |
| 1917 | ret false |
| 1918 | end |
| 1919 | put gosha i c |
| 1920 | end |
| 1921 | ret true |
| 1922 | end |
| 1923 | note ohdec: gcfv[0, n) as a decimal number of 1 to 18 digits; -1 when it is not one |
| 1924 | fn ohdec n long to long |
| 1925 | if or lt n 1 gt n 18 |
| 1926 | ret -1 |
| 1927 | end |
| 1928 | v = long 0 |
| 1929 | for i ulong ulong n bound 18 |
| 1930 | c = get gcfv i |
| 1931 | if or lt c 48 gt c 57 |
| 1932 | ret -1 |
| 1933 | end |
| 1934 | v = add mul v 10 long sub c 48 |
| 1935 | end |
| 1936 | ret v |
| 1937 | end |
| 1938 | note ohname: gcfv[0, n) is a project name of the contract: 1 to 64 bytes of [a-z0-9-], no '-' |
| 1939 | note first, last or twice in a row (what the tool makes of a folder name): into goname |
| 1940 | fn ohname n long to bool |
| 1941 | if or lt n 1 gt n 64 |
| 1942 | ret false |
| 1943 | end |
| 1944 | p = uchar 45 |
| 1945 | for i ulong ulong n bound 64 |
| 1946 | c = get gcfv i |
| 1947 | ok = or and ge c 97 le c 122 and ge c 48 le c 57 |
| 1948 | if eq c 45 |
| 1949 | if eq p 45 |
| 1950 | ret false |
| 1951 | end |
| 1952 | ok = true |
| 1953 | end |
| 1954 | if not ok |
| 1955 | ret false |
| 1956 | end |
| 1957 | put goname i c |
| 1958 | p = c |
| 1959 | end |
| 1960 | if eq p 45 |
| 1961 | ret false |
| 1962 | end |
| 1963 | put gonamel 0 ulong n |
| 1964 | ret true |
| 1965 | end |
| 1966 | note ohsig: gcfv[0, n) is an armored SSH signature (its BEGIN and END lines, base64 and line feeds |
| 1967 | note between; white space around it is dropped): into gosig with one line feed at the end |
| 1968 | fn ohsig n long to bool |
| 1969 | if lt n 1 |
| 1970 | ret false |
| 1971 | end |
| 1972 | a = ulong 0 |
| 1973 | b = ulong n |
| 1974 | for i ulong ulong n bound 65536 |
| 1975 | if not ohws get gcfv a |
| 1976 | break |
| 1977 | end |
| 1978 | a = add a 1 |
| 1979 | end |
| 1980 | for i ulong ulong n bound 65536 |
| 1981 | if le b a |
| 1982 | break |
| 1983 | end |
| 1984 | if not ohws get gcfv sub b 1 |
| 1985 | break |
| 1986 | end |
| 1987 | b = sub b 1 |
| 1988 | end |
| 1989 | k = sub b a |
| 1990 | if lt k add len tosgb len tosge |
| 1991 | ret false |
| 1992 | end |
| 1993 | for i ulong len tosgb |
| 1994 | if ne get gcfv add a i get tosgb i |
| 1995 | ret false |
| 1996 | end |
| 1997 | end |
| 1998 | for i ulong len tosge |
| 1999 | if ne get gcfv add sub b len tosge i get tosge i |
| 2000 | ret false |
| 2001 | end |
| 2002 | end |
| 2003 | for i ulong k bound 65536 |
| 2004 | c = get gcfv add a i |
| 2005 | if not ohsigc c |
| 2006 | ret false |
| 2007 | end |
| 2008 | put gosig i c |
| 2009 | end |
| 2010 | put gosig k 10 |
| 2011 | put gosigl 0 add k 1 |
| 2012 | ret true |
| 2013 | end |
| 2014 | note ohdh: godh = hex of the first 8 bytes of sha256(godid) |
| 2015 | fn ohdh to void |
| 2016 | m = new uchar 96 0 |
| 2017 | o = new uchar 32 0 |
| 2018 | n = get godidl 0 |
| 2019 | for i ulong n bound 96 |
| 2020 | put m i get godid i |
| 2021 | end |
| 2022 | k = sha2_digest 256 part m 0 n o |
| 2023 | for i ulong 8 |
| 2024 | c = get o i |
| 2025 | put godh mul i 2 get tohex ulong shr c 4 |
| 2026 | put godh add mul i 2 1 get tohex ulong and c 15 |
| 2027 | end |
| 2028 | end |
| 2029 | fn ohsize fd int to long |
| 2030 | st = new uchar 128 0 |
| 2031 | r = fstat fd st 0 128 |
| 2032 | if ne r 0 |
| 2033 | ret -1 |
| 2034 | end |
| 2035 | sz = ulong 0 |
| 2036 | for i ulong 8 |
| 2037 | sz = or sz shl ulong get st add 48 i mul i 8 |
| 2038 | end |
| 2039 | ret long sz |
| 2040 | end |
| 2041 | note ohtail: the next seq and the total so far of the spool fd of size sz into gonx; false when the |
| 2042 | note file does not end in a well-formed record |
| 2043 | fn ohtail fd int sz ulong to bool |
| 2044 | put gonx 0 0 |
| 2045 | put gonx 1 0 |
| 2046 | if eq sz 0 |
| 2047 | ret true |
| 2048 | end |
| 2049 | if lt sz 45 |
| 2050 | ret false |
| 2051 | end |
| 2052 | b = new uchar 42 0 |
| 2053 | k = pread fd b 0 42 long sub sz 42 |
| 2054 | if ne k 42 |
| 2055 | ret false |
| 2056 | end |
| 2057 | if or ne get b 20 9 ne get b 41 10 |
| 2058 | ret false |
| 2059 | end |
| 2060 | s = ulong 0 |
| 2061 | t = ulong 0 |
| 2062 | for i ulong 20 |
| 2063 | c = get b i |
| 2064 | d = get b add i 21 |
| 2065 | if or or lt c 48 gt c 57 or lt d 48 gt d 57 |
| 2066 | ret false |
| 2067 | end |
| 2068 | if or gt s 999999999999999999 gt t 999999999999999999 |
| 2069 | ret false |
| 2070 | end |
| 2071 | s = add mul s 10 ulong sub c 48 |
| 2072 | t = add mul t 10 ulong sub d 48 |
| 2073 | end |
| 2074 | put gonx 0 add s 1 |
| 2075 | put gonx 1 t |
| 2076 | ret true |
| 2077 | end |
| 2078 | note oh20: v as 20 decimal digits at b[o]: every ulong fits (2^64 - 1 has 20), so the running |
| 2079 | note total of a spool never wraps (it was 10 digits, which wrapped at 10^10 bytes) |
| 2080 | fn oh20 b edit uchar * o ulong v ulong to void |
| 2081 | x = v |
| 2082 | for i ulong 20 |
| 2083 | put b sub add o 19 i uchar add 48 rem x 10 |
| 2084 | x = div x 10 |
| 2085 | end |
| 2086 | end |
| 2087 | fn ohexist to bool |
| 2088 | ret eq faccess ffile 0 get ffilel 0 0 0 |
| 2089 | end |
| 2090 | note ohchunk: action=chunk. 409 "next <n>" when seq is not the next one (or the upload is finished), |
| 2091 | note 503 when the chunk would take the data filesystem below its reserve (ohroom) or the spool |
| 2092 | note cannot be written. There is no size limit and no 413: the data reserve bounds the spool. |
| 2093 | fn ohchunk to long |
| 2094 | seq = ohdec slgetform tofseq |
| 2095 | if lt seq 0 |
| 2096 | ohtx tom400 |
| 2097 | ret 400 |
| 2098 | end |
| 2099 | m = slgetform tofdata |
| 2100 | if or lt m 2 gt m 60000 |
| 2101 | ohtx tom400 |
| 2102 | ret 400 |
| 2103 | end |
| 2104 | if eq rem m 4 1 |
| 2105 | ohtx tom400 |
| 2106 | ret 400 |
| 2107 | end |
| 2108 | for i ulong ulong m bound 60000 |
| 2109 | if not ohb64c get gcfv i |
| 2110 | ohtx tom400 |
| 2111 | ret 400 |
| 2112 | end |
| 2113 | end |
| 2114 | rm = ohroom add ulong m 43 |
| 2115 | if ne rm 0 |
| 2116 | ohnoroom rm |
| 2117 | ret 503 |
| 2118 | end |
| 2119 | r4 = rem ulong m 4 |
| 2120 | dec = mul div ulong m 4 3 |
| 2121 | if gt r4 0 |
| 2122 | dec = add dec sub r4 1 |
| 2123 | end |
| 2124 | ohupmk |
| 2125 | ohupf tob64 |
| 2126 | fl = int 558082 |
| 2127 | if eq seq 0 |
| 2128 | fl = int 558146 |
| 2129 | end |
| 2130 | fd = fopen ffile 0 get ffilel 0 fl 384 |
| 2131 | if lt fd 0 |
| 2132 | if gt seq 0 |
| 2133 | ohnext 0 |
| 2134 | ret 409 |
| 2135 | end |
| 2136 | ohtx tom503 |
| 2137 | ret 503 |
| 2138 | end |
| 2139 | r = ohchunk2 int fd ulong seq ulong m dec |
| 2140 | x = fclose int fd |
| 2141 | ret r |
| 2142 | end |
| 2143 | fn ohchunk2 fd int seq ulong m ulong dec ulong to long |
| 2144 | sz = ohsize fd |
| 2145 | if lt sz 0 |
| 2146 | ohtx tom503 |
| 2147 | ret 503 |
| 2148 | end |
| 2149 | if not ohtail fd ulong sz |
| 2150 | ohtx tom503 |
| 2151 | ret 503 |
| 2152 | end |
| 2153 | nx = get gonx 0 |
| 2154 | ohupf tosig |
| 2155 | if ohexist |
| 2156 | ohnext nx |
| 2157 | ret 409 |
| 2158 | end |
| 2159 | if ne seq nx |
| 2160 | ohnext nx |
| 2161 | ret 409 |
| 2162 | end |
| 2163 | tot = add get gonx 1 dec |
| 2164 | if eq seq 0 |
| 2165 | ohupf toejs |
| 2166 | r = unlink ffile 0 get ffilel 0 |
| 2167 | end |
| 2168 | b = new uchar 60048 0 |
| 2169 | for i ulong m bound 60000 |
| 2170 | put b i get gcfv i |
| 2171 | end |
| 2172 | put b m 9 |
| 2173 | oh20 b add m 1 seq |
| 2174 | put b add m 21 9 |
| 2175 | oh20 b add m 22 tot |
| 2176 | put b add m 42 10 |
| 2177 | w = write fd b 0 add m 43 |
| 2178 | if ne w long add m 43 |
| 2179 | r = ftrunc fd sz |
| 2180 | ohtx tom503 |
| 2181 | ret 503 |
| 2182 | end |
| 2183 | ohused add m 43 |
| 2184 | ohnext add seq 1 |
| 2185 | ret 200 |
| 2186 | end |
| 2187 | note ohqnum: v in decimal at b[o]; the index after it |
| 2188 | fn ohqnum b edit uchar * o ulong v ulong to ulong |
| 2189 | d = new uchar 20 0 |
| 2190 | k = ulong 0 |
| 2191 | x = v |
| 2192 | if eq x 0 |
| 2193 | put d 0 48 |
| 2194 | k = ulong 1 |
| 2195 | end |
| 2196 | while gt x 0 bound 20 |
| 2197 | put d k uchar add 48 rem x 10 |
| 2198 | x = div x 10 |
| 2199 | k = add k 1 |
| 2200 | end |
| 2201 | for i ulong k bound 20 |
| 2202 | put b add o i get d sub sub k 1 i |
| 2203 | end |
| 2204 | ret add o k |
| 2205 | end |
| 2206 | note ohqup: the queue line U <tab> sha <tab> did <tab> files <tab> bytes <tab> name <tab> note; |
| 2207 | note 0 done, else 503 (the queue's 1 MiB cap, as for B and W lines) |
| 2208 | fn ohqup files ulong byt ulong to long |
| 2209 | b = new uchar 640 0 |
| 2210 | ohfb toq |
| 2211 | fd = fopen ffile 0 get ffilel 0 558145 384 |
| 2212 | if lt fd 0 |
| 2213 | ret 503 |
| 2214 | end |
| 2215 | note the size first: a short write (a full disk) is cut back to it, so no fragment joins the next line |
| 2216 | sz = ohsize int fd |
| 2217 | put b 0 85 |
| 2218 | put b 1 9 |
| 2219 | for i ulong 64 |
| 2220 | put b add 2 i get gosha i |
| 2221 | end |
| 2222 | put b 66 9 |
| 2223 | n = ulong 67 |
| 2224 | for i ulong get godidl 0 bound 96 |
| 2225 | put b add n i get godid i |
| 2226 | end |
| 2227 | n = add n get godidl 0 |
| 2228 | put b n 9 |
| 2229 | n = ohqnum b add n 1 files |
| 2230 | put b n 9 |
| 2231 | n = ohqnum b add n 1 byt |
| 2232 | put b n 9 |
| 2233 | n = add n 1 |
| 2234 | for i ulong get gonamel 0 bound 64 |
| 2235 | put b add n i get goname i |
| 2236 | end |
| 2237 | n = add n get gonamel 0 |
| 2238 | put b n 9 |
| 2239 | n = add n 1 |
| 2240 | for i ulong get gonotel 0 bound 200 |
| 2241 | put b add n i get gonote i |
| 2242 | end |
| 2243 | n = add n get gonotel 0 |
| 2244 | put b n 10 |
| 2245 | n = add n 1 |
| 2246 | w = write int fd b 0 n |
| 2247 | if ne w long n |
| 2248 | if ge sz 0 |
| 2249 | r = ftrunc int fd sz |
| 2250 | end |
| 2251 | x = fclose int fd |
| 2252 | ret 503 |
| 2253 | end |
| 2254 | x = fclose int fd |
| 2255 | ohused n |
| 2256 | ret 0 |
| 2257 | end |
| 2258 | fn ohqd to void |
| 2259 | ohtx toqd |
| 2260 | for i ulong 64 |
| 2261 | fputc get gosha i |
| 2262 | end |
| 2263 | fputc 10 |
| 2264 | end |
| 2265 | note ohfin: action=finish. The chunks must add up to bytes (fewer: 409 "next <n>"). A finish that |
| 2266 | note was already queued answers "queued" again and queues nothing. |
| 2267 | fn ohfin to long |
| 2268 | if not slffeq tocons toyes |
| 2269 | ohtx tom400 |
| 2270 | ret 400 |
| 2271 | end |
| 2272 | files = ohdec slgetform toffile |
| 2273 | byt = ohdec slgetform tofbyte |
| 2274 | if or lt files 0 lt byt 1 |
| 2275 | ohtx tom400 |
| 2276 | ret 400 |
| 2277 | end |
| 2278 | if not ohname slgetform tofname |
| 2279 | ohtx tom400 |
| 2280 | ret 400 |
| 2281 | end |
| 2282 | put gonotel 0 0 |
| 2283 | n = slgetform tonote |
| 2284 | if ge n 0 |
| 2285 | if not ohnote ulong n |
| 2286 | ohtx tom400 |
| 2287 | ret 400 |
| 2288 | end |
| 2289 | end |
| 2290 | if not ohsig slgetform tofsig |
| 2291 | ohtx tom400 |
| 2292 | ret 400 |
| 2293 | end |
| 2294 | ohupf tob64 |
| 2295 | fd = fopen ffile 0 get ffilel 0 557056 0 |
| 2296 | if lt fd 0 |
| 2297 | ohtx tom404 |
| 2298 | ret 404 |
| 2299 | end |
| 2300 | sz = ohsize int fd |
| 2301 | ok = false |
| 2302 | if gt sz 0 |
| 2303 | ok = ohtail int fd ulong sz |
| 2304 | end |
| 2305 | x = fclose int fd |
| 2306 | if not ok |
| 2307 | ohtx tom503 |
| 2308 | ret 503 |
| 2309 | end |
| 2310 | ret ohfin2 ulong files ulong byt |
| 2311 | end |
| 2312 | fn ohfin2 files ulong byt ulong to long |
| 2313 | tot = get gonx 1 |
| 2314 | if lt tot byt |
| 2315 | ohnext get gonx 0 |
| 2316 | ret 409 |
| 2317 | end |
| 2318 | if gt tot byt |
| 2319 | ohtx tom400 |
| 2320 | ret 400 |
| 2321 | end |
| 2322 | ohupf tosig |
| 2323 | if ohexist |
| 2324 | ohqd |
| 2325 | ret 200 |
| 2326 | end |
| 2327 | rm = ohroom add get gosigl 0 640 |
| 2328 | if ne rm 0 |
| 2329 | ohnoroom rm |
| 2330 | ret 503 |
| 2331 | end |
| 2332 | ohupf tosig |
| 2333 | fd = fopen ffile 0 get ffilel 0 557249 384 |
| 2334 | if lt fd 0 |
| 2335 | ohtx tom503 |
| 2336 | ret 503 |
| 2337 | end |
| 2338 | w = write int fd gosig 0 get gosigl 0 |
| 2339 | ohused get gosigl 0 |
| 2340 | x = fclose int fd |
| 2341 | if ne w long get gosigl 0 |
| 2342 | r = unlink ffile 0 get ffilel 0 |
| 2343 | ohtx tom503 |
| 2344 | ret 503 |
| 2345 | end |
| 2346 | r = ohqup files byt |
| 2347 | if ne r 0 |
| 2348 | ohupf tosig |
| 2349 | r = unlink ffile 0 get ffilel 0 |
| 2350 | ohtx tom503 |
| 2351 | ret 503 |
| 2352 | end |
| 2353 | ohqd |
| 2354 | ret 200 |
| 2355 | end |
| 2356 | note ohup: POST <base>open/up. Signed out is 403 here (the tool reads a status, not a page); then |
| 2357 | note the forge write gate (CSRF, the per-IP and per-key write limits, the store), unchanged. |
| 2358 | fn ohup to long |
| 2359 | if ne get fmeth 0 3 |
| 2360 | ret 405 |
| 2361 | end |
| 2362 | if eq get gscur 0 0 |
| 2363 | ohtx tom403 |
| 2364 | ret 403 |
| 2365 | end |
| 2366 | r = sowpre |
| 2367 | if ne r 0 |
| 2368 | ohpre r |
| 2369 | ret r |
| 2370 | end |
| 2371 | soratev get gscur 0 get gsnow 0 |
| 2372 | if not slformvalid |
| 2373 | ohtx tom400 |
| 2374 | ret 400 |
| 2375 | end |
| 2376 | if ne slgetform tsfcsrf 32 |
| 2377 | ohtx tom403 |
| 2378 | ret 403 |
| 2379 | end |
| 2380 | put godidl 0 0 |
| 2381 | if not ohdid |
| 2382 | ohtx tom403 |
| 2383 | ret 403 |
| 2384 | end |
| 2385 | if not ohsha slgetform tofsha |
| 2386 | ohtx tom400 |
| 2387 | ret 400 |
| 2388 | end |
| 2389 | ohdh |
| 2390 | if slffeq toact tofchnk |
| 2391 | ret ohchunk |
| 2392 | end |
| 2393 | if slffeq toact toffin |
| 2394 | ret ohfin |
| 2395 | end |
| 2396 | ohtx tom400 |
| 2397 | ret 400 |
| 2398 | end |
| 2399 | fn ohust t view uchar * to void |
| 2400 | put fobl 0 0 |
| 2401 | put fkind 0 1 |
| 2402 | fsetct toctj |
| 2403 | fput tous1 |
| 2404 | fput t |
| 2405 | fput tous2 |
| 2406 | end |
| 2407 | note ohupst: GET <base>open/up/<sha>.json for the signed-in key: the intake's status file when there |
| 2408 | note is one (stored or refused), else queued (finished) or receiving (chunks only); 404 for none |
| 2409 | fn ohupst to long |
| 2410 | if not fget |
| 2411 | ret 405 |
| 2412 | end |
| 2413 | a = len toupd |
| 2414 | if ne get fpathl 0 add a 69 |
| 2415 | ret 404 |
| 2416 | end |
| 2417 | for i ulong 64 |
| 2418 | c = fpathat add a i |
| 2419 | if not ohhex c |
| 2420 | ret 404 |
| 2421 | end |
| 2422 | put gosha i c |
| 2423 | end |
| 2424 | for i ulong 5 |
| 2425 | if ne fpathat add add a 64 i get toejs i |
| 2426 | ret 404 |
| 2427 | end |
| 2428 | end |
| 2429 | put godidl 0 0 |
| 2430 | if not ohdid |
| 2431 | ohtx tom403 |
| 2432 | ret 403 |
| 2433 | end |
| 2434 | ohdh |
| 2435 | ohupf toejs |
| 2436 | if ohexist |
| 2437 | put fkind 0 3 |
| 2438 | fsetct toctj |
| 2439 | ret 200 |
| 2440 | end |
| 2441 | ohupf tosig |
| 2442 | if ohexist |
| 2443 | ohust toqueue |
| 2444 | ret 200 |
| 2445 | end |
| 2446 | ohupf tob64 |
| 2447 | if ohexist |
| 2448 | ohust torecv |
| 2449 | ret 200 |
| 2450 | end |
| 2451 | ohtx tom404 |
| 2452 | ret 404 |
| 2453 | end |
| 2454 | note ---- get: <base>open/<rid>.tar, the snapshot the intake wrote for a shelf row |
| 2455 | fn ohistar to bool |
| 2456 | n = get fpathl 0 |
| 2457 | a = len topath |
| 2458 | if le n add a 4 |
| 2459 | ret false |
| 2460 | end |
| 2461 | for i ulong 4 |
| 2462 | if ne fpathat add sub n 4 i get totar i |
| 2463 | ret false |
| 2464 | end |
| 2465 | end |
| 2466 | ret true |
| 2467 | end |
| 2468 | note ohaf: ffile = <data>open/a/<gorid> then ext |
| 2469 | fn ohaf ext view uchar * to void |
| 2470 | ohfb toadir |
| 2471 | for i ulong get goridl 0 bound 44 |
| 2472 | ffilc get gorid i |
| 2473 | end |
| 2474 | for i ulong len ext bound 16 |
| 2475 | ffilc get ext i |
| 2476 | end |
| 2477 | end |
| 2478 | note ohcdn: Content-Disposition attachment; filename="<name>.tar" from the row's name: lowercase |
| 2479 | note letters and digits kept, every other run of bytes one '-', "project" when nothing is left |
| 2480 | fn ohnamec c uchar to bool |
| 2481 | ret or and ge c 97 le c 122 and ge c 48 le c 57 |
| 2482 | end |
| 2483 | fn ohcdn s ulong e ulong to void |
| 2484 | w = new uchar 64 0 |
| 2485 | a = ohfld s e 5 |
| 2486 | b = ohfe a e |
| 2487 | k = ulong 0 |
| 2488 | i = a |
| 2489 | while and lt i b lt k 64 bound 262144 |
| 2490 | c = get gol i |
| 2491 | if and ge c 65 le c 90 |
| 2492 | c = uchar add c 32 |
| 2493 | end |
| 2494 | if not ohnamec c |
| 2495 | c = uchar 45 |
| 2496 | end |
| 2497 | if eq c 45 |
| 2498 | if gt k 0 |
| 2499 | if ne get w sub k 1 45 |
| 2500 | put w k c |
| 2501 | k = add k 1 |
| 2502 | end |
| 2503 | end |
| 2504 | else |
| 2505 | put w k c |
| 2506 | k = add k 1 |
| 2507 | end |
| 2508 | i = add i 1 |
| 2509 | end |
| 2510 | if gt k 0 |
| 2511 | if eq get w sub k 1 45 |
| 2512 | k = sub k 1 |
| 2513 | end |
| 2514 | end |
| 2515 | fsetcd tocda |
| 2516 | if eq k 0 |
| 2517 | for j ulong len toproj |
| 2518 | fcdc get toproj j |
| 2519 | end |
| 2520 | end |
| 2521 | for j ulong k bound 64 |
| 2522 | fcdc get w j |
| 2523 | end |
| 2524 | for j ulong len totar |
| 2525 | fcdc get totar j |
| 2526 | end |
| 2527 | fcdc 34 |
| 2528 | end |
| 2529 | fn ohtar to long |
| 2530 | if not fget |
| 2531 | ret 405 |
| 2532 | end |
| 2533 | a = len topath |
| 2534 | n = sub sub get fpathl 0 a 4 |
| 2535 | if or lt n 20 gt n 44 |
| 2536 | ret 404 |
| 2537 | end |
| 2538 | for i ulong n bound 44 |
| 2539 | c = fpathat add a i |
| 2540 | if not ohb58 c |
| 2541 | ret 404 |
| 2542 | end |
| 2543 | put gorid i c |
| 2544 | end |
| 2545 | if ne get gorid 0 122 |
| 2546 | ret 404 |
| 2547 | end |
| 2548 | put goridl 0 n |
| 2549 | if not ohprow |
| 2550 | ret 404 |
| 2551 | end |
| 2552 | s = ulong 0 |
| 2553 | e = get goll 0 |
| 2554 | ohaf totar |
| 2555 | put fkind 0 3 |
| 2556 | fsetct totarct |
| 2557 | ohcdn s e |
| 2558 | ret 200 |
| 2559 | end |
| 2560 | note ohdlsha: the snapshot <data>open/a/<gorid>.tar exists and <gorid>.sha256 holds 64 hex: into h |
| 2561 | fn ohdlsha h edit uchar 64 to bool |
| 2562 | ohaf totar |
| 2563 | if not ohexist |
| 2564 | ret false |
| 2565 | end |
| 2566 | ohaf tosha |
| 2567 | fd = fopen ffile 0 get ffilel 0 557056 0 |
| 2568 | if lt fd 0 |
| 2569 | ret false |
| 2570 | end |
| 2571 | k = read int fd h 0 64 |
| 2572 | x = fclose int fd |
| 2573 | if ne k 64 |
| 2574 | ret false |
| 2575 | end |
| 2576 | for i ulong 64 |
| 2577 | if not ohhex get h i |
| 2578 | ret false |
| 2579 | end |
| 2580 | end |
| 2581 | ret true |
| 2582 | end |
| 2583 | note ohdlj: the JSON fields stored_by_hub, download and download_sha256 of the row s..e |
| 2584 | fn ohdlj s ulong e ulong to void |
| 2585 | fput tosbh1 |
| 2586 | if ohis s e 1 tostor |
| 2587 | fput totrue |
| 2588 | else |
| 2589 | fput tofalse |
| 2590 | end |
| 2591 | b = ohfe s e |
| 2592 | n = sub b s |
| 2593 | if or lt n 20 gt n 44 |
| 2594 | fput todl0 |
| 2595 | ret |
| 2596 | end |
| 2597 | for i ulong n bound 44 |
| 2598 | put gorid i get gol add s i |
| 2599 | end |
| 2600 | put goridl 0 n |
| 2601 | h = new uchar 64 0 |
| 2602 | if not ohdlsha h |
| 2603 | fput todl0 |
| 2604 | ret |
| 2605 | end |
| 2606 | fput todl1 |
| 2607 | fputb |
| 2608 | fput todir |
| 2609 | for i ulong n bound 44 |
| 2610 | fputc get gorid i |
| 2611 | end |
| 2612 | fput todl2 |
| 2613 | for i ulong 64 |
| 2614 | fputc get h i |
| 2615 | end |
| 2616 | fputc 34 |
| 2617 | end |
| 2618 | note ---- files the intake and the operator leave for forged to serve as they are |
| 2619 | fn ohtool name view uchar * to long |
| 2620 | if not fget |
| 2621 | ret 405 |
| 2622 | end |
| 2623 | ohfb totools |
| 2624 | for i ulong len name bound 16 |
| 2625 | ffilc get name i |
| 2626 | end |
| 2627 | put fkind 0 3 |
| 2628 | fsetct totxt |
| 2629 | ret 200 |
| 2630 | end |
| 2631 | fn ohalarm to long |
| 2632 | if not fget |
| 2633 | ret 405 |
| 2634 | end |
| 2635 | ohfb toalf |
| 2636 | put fkind 0 3 |
| 2637 | fsetct toctj |
| 2638 | ret 200 |
| 2639 | end |