aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / scripts / allen / contacts / allen_contacts_ingest.om
| 1 | note allen-contacts-ingest: seeded Omega port of allen_contacts_ingest.py, which stays the parity oracle. |
| 2 | note Moves consented contact drops from the gateway into the private store. Logs counts, never a field. |
| 3 | note Usage: allen-contacts-ingest ingest [DROP STORE EPOCH]. EPOCH fixes the audit/quarantine stamp (tests). |
| 4 | const OSTO ulong 0 |
| 5 | const NSTO ulong 14 |
| 6 | const OAUD ulong 14 |
| 7 | const NAUD ulong 9 |
| 8 | const OLCK ulong 23 |
| 9 | const NLCK ulong 7 |
| 10 | const OQDR ulong 30 |
| 11 | const NQDR ulong 10 |
| 12 | const OTMP ulong 40 |
| 13 | const NTMP ulong 20 |
| 14 | const OJSN ulong 60 |
| 15 | const NJSN ulong 5 |
| 16 | const OING ulong 65 |
| 17 | const NING ulong 6 |
| 18 | const ODDR ulong 71 |
| 19 | const NDDR ulong 33 |
| 20 | const OSDR ulong 104 |
| 21 | const NSDR ulong 23 |
| 22 | const OFRM ulong 127 |
| 23 | const NFRM ulong 16 |
| 24 | const OHDR ulong 143 |
| 25 | const NHDR ulong 22 |
| 26 | const ONTH ulong 165 |
| 27 | const NNTH ulong 8 |
| 28 | const OINT ulong 173 |
| 29 | const NINT ulong 9 |
| 30 | const OFGT ulong 182 |
| 31 | const NFGT ulong 6 |
| 32 | const OHUM ulong 188 |
| 33 | const NHUM ulong 5 |
| 34 | const OAGT ulong 193 |
| 35 | const NAGT ulong 5 |
| 36 | const OCHT ulong 198 |
| 37 | const NCHT ulong 4 |
| 38 | const OAPI ulong 202 |
| 39 | const NAPI ulong 3 |
| 40 | const OHTP ulong 205 |
| 41 | const NHTP ulong 8 |
| 42 | const OIDP ulong 213 |
| 43 | const NIDP ulong 9 |
| 44 | const OSHP ulong 222 |
| 45 | const NSHP ulong 24 |
| 46 | const ODOT ulong 246 |
| 47 | const NDOT ulong 1 |
| 48 | const OSLS ulong 247 |
| 49 | const NSLS ulong 1 |
| 50 | const ONL ulong 248 |
| 51 | const NNL ulong 1 |
| 52 | const OUSE ulong 249 |
| 53 | const NUSE ulong 55 |
| 54 | const OEDR ulong 304 |
| 55 | const NEDR ulong 47 |
| 56 | const OELK ulong 351 |
| 57 | const NELK ulong 32 |
| 58 | const OEST ulong 383 |
| 59 | const NEST ulong 46 |
| 60 | const OEQT ulong 429 |
| 61 | const NEQT ulong 44 |
| 62 | const OFVR ulong 473 |
| 63 | const NFVR ulong 24 |
| 64 | const OVDP ulong 497 |
| 65 | const NVDP ulong 10 |
| 66 | const OFVT ulong 507 |
| 67 | const NFVT ulong 14 |
| 68 | note Counter slots, in the sorted order the summary line prints them. |
| 69 | const CFM ulong 0 |
| 70 | const CFU ulong 1 |
| 71 | const CVM ulong 2 |
| 72 | const CVU ulong 3 |
| 73 | const CIA ulong 4 |
| 74 | const CIS ulong 5 |
| 75 | const CQD long 6 |
| 76 | const CQI long 7 |
| 77 | const CQN long 8 |
| 78 | const CQO long 9 |
| 79 | const CQF ulong 10 |
| 80 | const CQ ulong 11 |
| 81 | const CRN ulong 12 |
| 82 | const CST ulong 13 |
| 83 | const CTP ulong 14 |
| 84 | const CTS ulong 15 |
| 85 | const MAXD ulong 65536 |
| 86 | const MAXR ulong 65537 |
| 87 | const MAXE ulong 4096 |
| 88 | const QCAP long 1000 |
| 89 | const SCAP ulong 16777216 |
| 90 | note Slots of gu (ulong state). |
| 91 | const GDL ulong 0 |
| 92 | const GSL ulong 1 |
| 93 | const GDN ulong 2 |
| 94 | const GPL ulong 3 |
| 95 | const GNE ulong 4 |
| 96 | const GWSC ulong 5 |
| 97 | const GFW ulong 6 |
| 98 | const GLW ulong 7 |
| 99 | const GOL ulong 8 |
| 100 | const GADV ulong 9 |
| 101 | const GSN ulong 10 |
| 102 | const GNK ulong 11 |
| 103 | const GIDF ulong 12 |
| 104 | const GAL ulong 13 |
| 105 | const GTL ulong 14 |
| 106 | const GLK ulong 15 |
| 107 | const GLE ulong 16 |
| 108 | const GMOD ulong 17 |
| 109 | note Slots of gl (long state). |
| 110 | const LNOW ulong 0 |
| 111 | text lit "contacts.jsonlaudit.log.lock.dquarantine.contacts.jsonl.tmp-.jsoningest/var/lib/allen-chat/contacts-drop/var/lib/allen-contacts forget removed=allen-contacts-ingest: nothingintroduceforgethumanagentchatapihttps://, \"id\": \"\"delete_token_sha256\": \"./\nusage: allen-contacts-ingest ingest [DROP STORE EPOCH]\nallen-contacts: unsafe drop or store directory\nallen-contacts: store is locked\nallen-contacts: store too large or unreadable\nallen-contacts: quarantine directory unsafe\n forget_visitor removed=, \"vid\": \"forget_visitor" |
| 112 | text kin "contact delete_token_sha256 framework github homepage human id kind model name org origin purpose received type v via vid" |
| 113 | text kfo "id received token_sha256 type v" |
| 114 | text kfv "received type v vid" |
| 115 | text cn "forget_matched forget_unmatched forget_visitor_matched forget_visitor_unmatched introduce_already_stored introduce_stored q_duplicate_id q_invalid q_name q_oversize quarantine_full_discarded quarantined removed_nonregular stuck_nonregular temp_pending temp_stale_removed" |
| 116 | global gu ulong 32 |
| 117 | global gl long 8 |
| 118 | global cnt long 16 |
| 119 | global ddir uchar 4096 |
| 120 | global sdir uchar 4096 |
| 121 | global pth uchar 4096 |
| 122 | global pk uchar 8192 |
| 123 | global dbuf uchar 65537 |
| 124 | global sbuf uchar 16777216 |
| 125 | global nbuf uchar 1048576 |
| 126 | global nlen ulong 4096 |
| 127 | global nmt long 4096 |
| 128 | global ordx ulong 4096 |
| 129 | global dents uchar 65536 |
| 130 | global stb uchar 128 |
| 131 | global fs ulong 32 |
| 132 | global fe ulong 32 |
| 133 | global keys uchar 256 |
| 134 | global kof ulong 32 |
| 135 | global kln ulong 32 |
| 136 | global rnd uchar 16 |
| 137 | global ob uchar 2048 |
| 138 | global ab uchar 128 |
| 139 | global tb uchar 32 |
| 140 | |
| 141 | note ---------------------------------------------------------------- small helpers |
| 142 | |
| 143 | fn bump i ulong to void |
| 144 | put cnt i add get cnt i 1 |
| 145 | end |
| 146 | |
| 147 | fn pset to void |
| 148 | put gu GPL 0 |
| 149 | end |
| 150 | |
| 151 | fn pb b uchar to void |
| 152 | n = get gu GPL |
| 153 | put pth n b |
| 154 | put gu GPL add n 1 |
| 155 | end |
| 156 | |
| 157 | fn plit o ulong n ulong to void |
| 158 | for i ulong n |
| 159 | pb get lit add o i |
| 160 | end |
| 161 | end |
| 162 | |
| 163 | fn pdd to void |
| 164 | for i ulong get gu GDL |
| 165 | pb get ddir i |
| 166 | end |
| 167 | end |
| 168 | |
| 169 | fn psd to void |
| 170 | for i ulong get gu GSL |
| 171 | pb get sdir i |
| 172 | end |
| 173 | end |
| 174 | |
| 175 | fn pnam i ulong to void |
| 176 | b = mul i 256 |
| 177 | for j ulong get nlen i |
| 178 | pb get nbuf add b j |
| 179 | end |
| 180 | end |
| 181 | |
| 182 | fn hexch v ulong to uchar |
| 183 | if lt v 10 |
| 184 | ret uchar add v 48 |
| 185 | end |
| 186 | ret uchar add v 87 |
| 187 | end |
| 188 | |
| 189 | fn phex k ulong to long |
| 190 | r = random rnd 0 k 0 |
| 191 | if ne r long k |
| 192 | ret -1 |
| 193 | end |
| 194 | for i ulong k |
| 195 | v = ulong get rnd i |
| 196 | pb hexch shr v 4 |
| 197 | pb hexch and v 15 |
| 198 | end |
| 199 | ret 0 |
| 200 | end |
| 201 | |
| 202 | fn rd32 o ulong to ulong |
| 203 | v = ulong get stb o |
| 204 | v = or v shl ulong get stb add o 1 8 |
| 205 | v = or v shl ulong get stb add o 2 16 |
| 206 | v = or v shl ulong get stb add o 3 24 |
| 207 | ret v |
| 208 | end |
| 209 | |
| 210 | fn rd64 o ulong to long |
| 211 | v = rd32 o |
| 212 | h = rd32 add o 4 |
| 213 | ret bitcast long or v shl h 32 |
| 214 | end |
| 215 | |
| 216 | fn mtns to long |
| 217 | ret add mul rd64 88 1000000000 rd64 96 |
| 218 | end |
| 219 | |
| 220 | fn plstat to long |
| 221 | ret lstat pth 0 get gu GPL stb 0 128 |
| 222 | end |
| 223 | |
| 224 | note ------------------------------------------------------------------ output buffers |
| 225 | |
| 226 | fn ob1 b uchar to void |
| 227 | n = get gu GOL |
| 228 | put ob n b |
| 229 | put gu GOL add n 1 |
| 230 | end |
| 231 | |
| 232 | fn ab1 b uchar to void |
| 233 | n = get gu GAL |
| 234 | put ab n b |
| 235 | put gu GAL add n 1 |
| 236 | end |
| 237 | |
| 238 | fn olit o ulong n ulong to void |
| 239 | for i ulong n |
| 240 | ob1 get lit add o i |
| 241 | end |
| 242 | end |
| 243 | |
| 244 | fn onum v long to void |
| 245 | d = new uchar 24 0 |
| 246 | k = ulong 0 |
| 247 | x = v |
| 248 | while true bound 30 |
| 249 | put d k uchar add rem x 10 48 |
| 250 | k = add k 1 |
| 251 | x = div x 10 |
| 252 | if eq x 0 |
| 253 | break |
| 254 | end |
| 255 | end |
| 256 | while gt k 0 bound 30 |
| 257 | k = sub k 1 |
| 258 | ob1 get d k |
| 259 | end |
| 260 | end |
| 261 | |
| 262 | fn anum v long to void |
| 263 | d = new uchar 24 0 |
| 264 | k = ulong 0 |
| 265 | x = v |
| 266 | while true bound 30 |
| 267 | put d k uchar add rem x 10 48 |
| 268 | k = add k 1 |
| 269 | x = div x 10 |
| 270 | if eq x 0 |
| 271 | break |
| 272 | end |
| 273 | end |
| 274 | while gt k 0 bound 30 |
| 275 | k = sub k 1 |
| 276 | ab1 get d k |
| 277 | end |
| 278 | end |
| 279 | |
| 280 | fn emsg o ulong n ulong to void |
| 281 | w = write 2 lit o n |
| 282 | end |
| 283 | |
| 284 | note -------------------------------------------------------------------------- clock |
| 285 | |
| 286 | fn nowsec to long |
| 287 | t = get gl LNOW |
| 288 | if ge t 0 |
| 289 | ret t |
| 290 | end |
| 291 | ret div realns 1000000000 |
| 292 | end |
| 293 | |
| 294 | fn t2 v long to void |
| 295 | put tb get gu GTL uchar add div v 10 48 |
| 296 | put tb add get gu GTL 1 uchar add rem v 10 48 |
| 297 | put gu GTL add get gu GTL 2 |
| 298 | end |
| 299 | |
| 300 | fn tch b uchar to void |
| 301 | put tb get gu GTL b |
| 302 | put gu GTL add get gu GTL 1 |
| 303 | end |
| 304 | |
| 305 | note Civil date from days since 1970-01-01 (proleptic Gregorian), packed y*10000 + m*100 + d. |
| 306 | fn civil days long to long |
| 307 | z = add days 719468 |
| 308 | era = div z 146097 |
| 309 | doe = sub z mul era 146097 |
| 310 | yoe = div sub add sub doe div doe 1460 div doe 36524 div doe 146096 365 |
| 311 | ret civil2 doe yoe add yoe mul era 400 |
| 312 | end |
| 313 | |
| 314 | fn civil2 doe long yoe long y long to long |
| 315 | doy = sub doe sub add mul 365 yoe div yoe 4 div yoe 100 |
| 316 | mp = div add mul 5 doy 2 153 |
| 317 | d = add sub doy div add mul 153 mp 2 5 1 |
| 318 | m = add mp 3 |
| 319 | yy = y |
| 320 | if ge mp 10 |
| 321 | m = sub mp 9 |
| 322 | yy = add y 1 |
| 323 | end |
| 324 | ret add add mul yy 10000 mul m 100 d |
| 325 | end |
| 326 | |
| 327 | note full: 2026-10-26T15:28:56Z (audit), else 20261026T152856Z (quarantine names). |
| 328 | fn tstamp full bool to void |
| 329 | t = nowsec |
| 330 | put gu GTL 0 |
| 331 | v = civil div t 86400 |
| 332 | y = div v 10000 |
| 333 | t2 div y 100 |
| 334 | t2 rem y 100 |
| 335 | if full |
| 336 | tch 45 |
| 337 | end |
| 338 | t2 div rem v 10000 100 |
| 339 | if full |
| 340 | tch 45 |
| 341 | end |
| 342 | t2 rem v 100 |
| 343 | tch 84 |
| 344 | s = rem t 86400 |
| 345 | t2 div s 3600 |
| 346 | if full |
| 347 | tch 58 |
| 348 | end |
| 349 | t2 div rem s 3600 60 |
| 350 | if full |
| 351 | tch 58 |
| 352 | end |
| 353 | t2 rem s 60 |
| 354 | tch 90 |
| 355 | end |
| 356 | |
| 357 | note ----------------------------------------------------------------- drop bytes access |
| 358 | |
| 359 | fn at p ulong to ulong |
| 360 | if ge p get gu GDN |
| 361 | ret 256 |
| 362 | end |
| 363 | ret ulong get dbuf p |
| 364 | end |
| 365 | |
| 366 | fn ishex b ulong to bool |
| 367 | ret or and ge b 48 le b 57 and ge b 97 le b 102 |
| 368 | end |
| 369 | |
| 370 | fn eqlit p ulong o ulong n ulong to bool |
| 371 | for i ulong n |
| 372 | if ne at add p i ulong get lit add o i |
| 373 | ret false |
| 374 | end |
| 375 | end |
| 376 | ret true |
| 377 | end |
| 378 | |
| 379 | fn spaneq k ulong o ulong n ulong to bool |
| 380 | s = get fs k |
| 381 | if ne sub get fe k s n |
| 382 | ret false |
| 383 | end |
| 384 | ret eqlit s o n |
| 385 | end |
| 386 | |
| 387 | fn hexspan k ulong n ulong to bool |
| 388 | s = get fs k |
| 389 | if ne sub get fe k s n |
| 390 | ret false |
| 391 | end |
| 392 | for i ulong n |
| 393 | if not ishex at add s i |
| 394 | ret false |
| 395 | end |
| 396 | end |
| 397 | ret true |
| 398 | end |
| 399 | |
| 400 | note ---------------------------------------------------------------- strict UTF-8 text |
| 401 | |
| 402 | fn isws c ulong to bool |
| 403 | if or and ge c 9 le c 13 and ge c 28 le c 32 |
| 404 | ret true |
| 405 | end |
| 406 | if or eq c 133 eq c 160 |
| 407 | ret true |
| 408 | end |
| 409 | if or eq c 5760 and ge c 8192 le c 8202 |
| 410 | ret true |
| 411 | end |
| 412 | if or or eq c 8232 eq c 8233 eq c 8239 |
| 413 | ret true |
| 414 | end |
| 415 | ret or eq c 8287 eq c 12288 |
| 416 | end |
| 417 | |
| 418 | fn dmb p ulong e ulong b ulong to long |
| 419 | k = ulong 0 |
| 420 | lo = ulong 128 |
| 421 | hi = ulong 191 |
| 422 | if and ge b 194 le b 223 |
| 423 | k = 1 |
| 424 | end |
| 425 | if or eq b 224 or and ge b 225 le b 236 and ge b 238 le b 239 |
| 426 | k = 2 |
| 427 | end |
| 428 | if eq b 237 |
| 429 | k = 2 |
| 430 | end |
| 431 | if and ge b 240 le b 244 |
| 432 | k = 3 |
| 433 | end |
| 434 | if eq k 0 |
| 435 | ret -1 |
| 436 | end |
| 437 | if eq b 224 |
| 438 | lo = 160 |
| 439 | end |
| 440 | if eq b 237 |
| 441 | hi = 159 |
| 442 | end |
| 443 | if eq b 240 |
| 444 | lo = 144 |
| 445 | end |
| 446 | if eq b 244 |
| 447 | hi = 143 |
| 448 | end |
| 449 | if ge add p k e |
| 450 | ret -1 |
| 451 | end |
| 452 | cp = and b shr ulong 127 add k 1 |
| 453 | for j ulong k |
| 454 | x = at add add p j 1 |
| 455 | if eq j 0 |
| 456 | if or lt x lo gt x hi |
| 457 | ret -1 |
| 458 | end |
| 459 | end |
| 460 | if or lt x 128 gt x 191 |
| 461 | ret -1 |
| 462 | end |
| 463 | cp = or shl cp 6 and x 63 |
| 464 | end |
| 465 | put gu GADV add k 1 |
| 466 | ret long cp |
| 467 | end |
| 468 | |
| 469 | fn dcp p ulong e ulong to long |
| 470 | b = at p |
| 471 | put gu GADV 1 |
| 472 | if eq b 92 |
| 473 | put gu GADV 2 |
| 474 | q = at add p 1 |
| 475 | if eq q 34 |
| 476 | ret 34 |
| 477 | end |
| 478 | if eq q 92 |
| 479 | ret 92 |
| 480 | end |
| 481 | if eq q 110 |
| 482 | ret 10 |
| 483 | end |
| 484 | if eq q 116 |
| 485 | ret 9 |
| 486 | end |
| 487 | ret -1 |
| 488 | end |
| 489 | if or lt b 32 eq b 127 |
| 490 | ret -1 |
| 491 | end |
| 492 | if lt b 128 |
| 493 | ret long b |
| 494 | end |
| 495 | ret dmb p e b |
| 496 | end |
| 497 | |
| 498 | note Code points in [s, e) of dbuf, -1 if invalid; whitespace count and first/last flags in gu. |
| 499 | fn chkstr s ulong e ulong to long |
| 500 | p = s |
| 501 | c = long 0 |
| 502 | ws = ulong 0 |
| 503 | put gu GFW 0 |
| 504 | put gu GLW 0 |
| 505 | while lt p e bound 999999 |
| 506 | cp = dcp p e |
| 507 | if lt cp 0 |
| 508 | ret -1 |
| 509 | end |
| 510 | if isws ulong cp |
| 511 | ws = add ws 1 |
| 512 | if eq c 0 |
| 513 | put gu GFW 1 |
| 514 | end |
| 515 | put gu GLW 1 |
| 516 | else |
| 517 | put gu GLW 0 |
| 518 | end |
| 519 | c = add c 1 |
| 520 | p = add p get gu GADV |
| 521 | end |
| 522 | put gu GWSC ws |
| 523 | ret c |
| 524 | end |
| 525 | |
| 526 | note ------------------------------------------------------------------ fixed-schema parse |
| 527 | |
| 528 | note Schema w: 1 introduce (kin), 2 forget (kfo), 3 forget_visitor (kfv); sorted key names. |
| 529 | fn keyb w ulong i ulong to uchar |
| 530 | if eq w 1 |
| 531 | ret get kin i |
| 532 | end |
| 533 | if eq w 2 |
| 534 | ret get kfo i |
| 535 | end |
| 536 | ret get kfv i |
| 537 | end |
| 538 | |
| 539 | fn loadkeys w ulong to void |
| 540 | n = len kin |
| 541 | if eq w 2 |
| 542 | n = len kfo |
| 543 | end |
| 544 | if eq w 3 |
| 545 | n = len kfv |
| 546 | end |
| 547 | k = ulong 0 |
| 548 | put kof 0 0 |
| 549 | for i ulong n |
| 550 | b = keyb w i |
| 551 | if eq b 32 |
| 552 | put kln k sub i get kof k |
| 553 | k = add k 1 |
| 554 | put kof k add i 1 |
| 555 | else |
| 556 | put keys i b |
| 557 | end |
| 558 | end |
| 559 | put kln k sub n get kof k |
| 560 | put gu GNK add k 1 |
| 561 | end |
| 562 | |
| 563 | note Key k, written as "key": , at p. Returns the position after it or -1. |
| 564 | fn pkey k ulong p ulong to long |
| 565 | q = p |
| 566 | if gt k 0 |
| 567 | if or ne at q 44 ne at add q 1 32 |
| 568 | ret -1 |
| 569 | end |
| 570 | q = add q 2 |
| 571 | end |
| 572 | if ne at q 34 |
| 573 | ret -1 |
| 574 | end |
| 575 | q = add q 1 |
| 576 | o = get kof k |
| 577 | for i ulong get kln k |
| 578 | if ne at add q i ulong get keys add o i |
| 579 | ret -1 |
| 580 | end |
| 581 | end |
| 582 | q = add q get kln k |
| 583 | if or ne at q 34 or ne at add q 1 58 ne at add q 2 32 |
| 584 | ret -1 |
| 585 | end |
| 586 | ret long add q 3 |
| 587 | end |
| 588 | |
| 589 | note Value of key k at p: the number 1 for "v", else a string. Records the raw span. |
| 590 | fn pval k ulong p ulong to long |
| 591 | if and eq get kln k 1 eq get keys get kof k 118 |
| 592 | if ne at p 49 |
| 593 | ret -1 |
| 594 | end |
| 595 | put fs k p |
| 596 | put fe k add p 1 |
| 597 | ret long add p 1 |
| 598 | end |
| 599 | if ne at p 34 |
| 600 | ret -1 |
| 601 | end |
| 602 | q = add p 1 |
| 603 | put fs k q |
| 604 | n = get gu GDN |
| 605 | while lt q n bound 999999 |
| 606 | b = at q |
| 607 | if eq b 34 |
| 608 | put fe k q |
| 609 | ret long add q 1 |
| 610 | end |
| 611 | if eq b 92 |
| 612 | q = add q 2 |
| 613 | else |
| 614 | q = add q 1 |
| 615 | end |
| 616 | end |
| 617 | ret -1 |
| 618 | end |
| 619 | |
| 620 | fn parse w ulong to bool |
| 621 | loadkeys w |
| 622 | if ne at 0 123 |
| 623 | ret false |
| 624 | end |
| 625 | p = long 1 |
| 626 | for k ulong get gu GNK |
| 627 | p = pkey k ulong p |
| 628 | if lt p 0 |
| 629 | ret false |
| 630 | end |
| 631 | p = pval k ulong p |
| 632 | if lt p 0 |
| 633 | ret false |
| 634 | end |
| 635 | end |
| 636 | if ne at ulong p 125 |
| 637 | ret false |
| 638 | end |
| 639 | ret eq add ulong p 1 get gu GDN |
| 640 | end |
| 641 | |
| 642 | note ---------------------------------------------------------------------- validation |
| 643 | |
| 644 | fn txt k ulong cap long to bool |
| 645 | c = chkstr get fs k get fe k |
| 646 | if or lt c 0 gt c cap |
| 647 | ret false |
| 648 | end |
| 649 | if gt c 0 |
| 650 | if or eq get gu GFW 1 eq get gu GLW 1 |
| 651 | ret false |
| 652 | end |
| 653 | end |
| 654 | ret true |
| 655 | end |
| 656 | |
| 657 | fn valtxt to bool |
| 658 | if not and and txt 0 200 txt 2 100 and txt 3 39 txt 4 200 |
| 659 | ret false |
| 660 | end |
| 661 | if not and and txt 5 200 txt 8 100 and txt 9 100 txt 10 100 |
| 662 | ret false |
| 663 | end |
| 664 | ret and txt 11 200 txt 12 1000 |
| 665 | end |
| 666 | |
| 667 | fn homeok to bool |
| 668 | s = get fs 4 |
| 669 | e = get fe 4 |
| 670 | if eq s e |
| 671 | ret true |
| 672 | end |
| 673 | if not eqlit s OHTP NHTP |
| 674 | ret false |
| 675 | end |
| 676 | c = chkstr add s NHTP e |
| 677 | ret and ge c 4 eq get gu GWSC 0 |
| 678 | end |
| 679 | |
| 680 | fn idok k ulong to bool |
| 681 | s = get fs k |
| 682 | if ne sub get fe k s 18 |
| 683 | ret false |
| 684 | end |
| 685 | if or ne at s 99 ne at add s 1 95 |
| 686 | ret false |
| 687 | end |
| 688 | for i ulong 16 |
| 689 | if not ishex at add add s 2 i |
| 690 | ret false |
| 691 | end |
| 692 | end |
| 693 | ret true |
| 694 | end |
| 695 | |
| 696 | fn dig p ulong n ulong to long |
| 697 | v = long 0 |
| 698 | for i ulong n |
| 699 | b = at add p i |
| 700 | if or lt b 48 gt b 57 |
| 701 | ret -1 |
| 702 | end |
| 703 | v = add mul v 10 long sub b 48 |
| 704 | end |
| 705 | ret v |
| 706 | end |
| 707 | |
| 708 | fn dim y long m long to long |
| 709 | if eq m 2 |
| 710 | if and eq rem y 4 0 or ne rem y 100 0 eq rem y 400 0 |
| 711 | ret 29 |
| 712 | end |
| 713 | ret 28 |
| 714 | end |
| 715 | if or or eq m 4 eq m 6 or eq m 9 eq m 11 |
| 716 | ret 30 |
| 717 | end |
| 718 | ret 31 |
| 719 | end |
| 720 | |
| 721 | fn recok k ulong to bool |
| 722 | s = get fs k |
| 723 | if ne sub get fe k s 20 |
| 724 | ret false |
| 725 | end |
| 726 | if or or ne at add s 4 45 ne at add s 7 45 or ne at add s 10 84 ne at add s 19 90 |
| 727 | ret false |
| 728 | end |
| 729 | if or ne at add s 13 58 ne at add s 16 58 |
| 730 | ret false |
| 731 | end |
| 732 | y = dig s 4 |
| 733 | m = dig add s 5 2 |
| 734 | d = dig add s 8 2 |
| 735 | if or or lt y 1 lt m 1 gt m 12 |
| 736 | ret false |
| 737 | end |
| 738 | if or lt d 1 gt d dim y m |
| 739 | ret false |
| 740 | end |
| 741 | ret tmok s |
| 742 | end |
| 743 | |
| 744 | fn rng v long hi long to bool |
| 745 | ret and ge v 0 le v hi |
| 746 | end |
| 747 | |
| 748 | fn tmok s ulong to bool |
| 749 | if not rng dig add s 11 2 23 |
| 750 | ret false |
| 751 | end |
| 752 | if not rng dig add s 14 2 59 |
| 753 | ret false |
| 754 | end |
| 755 | ret rng dig add s 17 2 59 |
| 756 | end |
| 757 | |
| 758 | fn valint to bool |
| 759 | if not spaneq 14 OINT NINT |
| 760 | ret false |
| 761 | end |
| 762 | if not valtxt |
| 763 | ret false |
| 764 | end |
| 765 | if not or spaneq 7 OHUM NHUM spaneq 7 OAGT NAGT |
| 766 | ret false |
| 767 | end |
| 768 | if not or spaneq 16 OCHT NCHT spaneq 16 OAPI NAPI |
| 769 | ret false |
| 770 | end |
| 771 | if and eq get fs 9 get fe 9 eq get fs 0 get fe 0 |
| 772 | ret false |
| 773 | end |
| 774 | if not homeok |
| 775 | ret false |
| 776 | end |
| 777 | if ne get fs 17 get fe 17 |
| 778 | if not hexspan 17 64 |
| 779 | ret false |
| 780 | end |
| 781 | end |
| 782 | ret and and hexspan 1 64 idok 6 recok 13 |
| 783 | end |
| 784 | |
| 785 | fn valfgt to bool |
| 786 | if not spaneq 3 OFGT NFGT |
| 787 | ret false |
| 788 | end |
| 789 | ret and and hexspan 2 64 idok 0 recok 1 |
| 790 | end |
| 791 | |
| 792 | note forget_visitor: received, type, v, vid. The vid must be 64 hex, never empty. |
| 793 | fn valfv to bool |
| 794 | if not spaneq 1 OFVT NFVT |
| 795 | ret false |
| 796 | end |
| 797 | ret and hexspan 3 64 recok 0 |
| 798 | end |
| 799 | |
| 800 | note 1 introduce, 2 forget, 3 forget_visitor, 0 invalid. Sets GIDF, the id (or vid) field. |
| 801 | fn classify to ulong |
| 802 | if parse 1 |
| 803 | put gu GIDF 6 |
| 804 | if valint |
| 805 | ret 1 |
| 806 | end |
| 807 | ret 0 |
| 808 | end |
| 809 | if parse 2 |
| 810 | put gu GIDF 0 |
| 811 | if valfgt |
| 812 | ret 2 |
| 813 | end |
| 814 | ret 0 |
| 815 | end |
| 816 | if parse 3 |
| 817 | put gu GIDF 3 |
| 818 | if valfv |
| 819 | ret 3 |
| 820 | end |
| 821 | end |
| 822 | ret 0 |
| 823 | end |
| 824 | |
| 825 | note ------------------------------------------------------------------------ the store |
| 826 | |
| 827 | fn loadst to long |
| 828 | put gu GSN 0 |
| 829 | pset |
| 830 | plit OSTO NSTO |
| 831 | fd = fopen pth 0 get gu GPL 557056 0 |
| 832 | if eq fd neg long 2 |
| 833 | ret 0 |
| 834 | end |
| 835 | if lt fd 0 |
| 836 | ret -1 |
| 837 | end |
| 838 | n = ulong 0 |
| 839 | while true bound 999 |
| 840 | r = read int fd sbuf n sub SCAP n |
| 841 | if lt r 0 |
| 842 | r = fclose int fd |
| 843 | ret -1 |
| 844 | end |
| 845 | if eq r 0 |
| 846 | break |
| 847 | end |
| 848 | n = add n ulong r |
| 849 | if eq n SCAP |
| 850 | r = fclose int fd |
| 851 | ret -1 |
| 852 | end |
| 853 | end |
| 854 | r = fclose int fd |
| 855 | put gu GSN n |
| 856 | ret 0 |
| 857 | end |
| 858 | |
| 859 | fn lend s ulong to ulong |
| 860 | p = s |
| 861 | n = get gu GSN |
| 862 | while lt p n bound 999999 |
| 863 | if eq get sbuf p 10 |
| 864 | ret p |
| 865 | end |
| 866 | p = add p 1 |
| 867 | end |
| 868 | ret n |
| 869 | end |
| 870 | |
| 871 | fn blank s ulong e ulong to bool |
| 872 | for i ulong sub e s |
| 873 | b = get sbuf add s i |
| 874 | if not or eq b 32 and ge b 9 le b 13 |
| 875 | ret false |
| 876 | end |
| 877 | end |
| 878 | ret true |
| 879 | end |
| 880 | |
| 881 | note Is , "id": "<the drop's id>" at sbuf p ? (28 bytes, caller checks room) |
| 882 | fn idat p ulong to bool |
| 883 | for i ulong NIDP |
| 884 | if ne get sbuf add p i get lit add OIDP i |
| 885 | ret false |
| 886 | end |
| 887 | end |
| 888 | f = get fs get gu GIDF |
| 889 | q = add p NIDP |
| 890 | for i ulong 18 |
| 891 | if ne get sbuf add q i get dbuf add f i |
| 892 | ret false |
| 893 | end |
| 894 | end |
| 895 | ret eq get sbuf add q 18 34 |
| 896 | end |
| 897 | |
| 898 | note Does store line [s, e) carry the drop's id? |
| 899 | fn hasid s ulong e ulong to bool |
| 900 | if lt sub e s 28 |
| 901 | ret false |
| 902 | end |
| 903 | last = sub e 28 |
| 904 | p = s |
| 905 | while le p last bound 999999 |
| 906 | if idat p |
| 907 | ret true |
| 908 | end |
| 909 | p = add p 1 |
| 910 | end |
| 911 | ret false |
| 912 | end |
| 913 | |
| 914 | note Does store line [s, e) end with , "vid": "<the drop's 64-hex vid>"} ? |
| 915 | fn hasvid s ulong e ulong to bool |
| 916 | if lt sub e s 76 |
| 917 | ret false |
| 918 | end |
| 919 | p = sub e 76 |
| 920 | for i ulong NVDP |
| 921 | if ne get sbuf add p i get lit add OVDP i |
| 922 | ret false |
| 923 | end |
| 924 | end |
| 925 | f = get fs get gu GIDF |
| 926 | q = add p NVDP |
| 927 | for i ulong 64 |
| 928 | if ne get sbuf add q i get dbuf add f i |
| 929 | ret false |
| 930 | end |
| 931 | end |
| 932 | ret and eq get sbuf add q 64 34 eq get sbuf add q 65 125 |
| 933 | end |
| 934 | |
| 935 | note The line matches the drop: by id (GMOD 0) or by vid (GMOD 1). |
| 936 | fn hit s ulong e ulong to bool |
| 937 | if eq get gu GMOD 1 |
| 938 | ret hasvid s e |
| 939 | end |
| 940 | ret hasid s e |
| 941 | end |
| 942 | |
| 943 | fn cntvid to long |
| 944 | c = long 0 |
| 945 | s = ulong 0 |
| 946 | n = get gu GSN |
| 947 | while lt s n bound 999999 |
| 948 | e = lend s |
| 949 | if not blank s e |
| 950 | if hasvid s e |
| 951 | c = add c 1 |
| 952 | end |
| 953 | end |
| 954 | s = add e 1 |
| 955 | end |
| 956 | ret c |
| 957 | end |
| 958 | |
| 959 | note Start of the first store line with the drop's id, or -1. The line's end goes to gu GLE. |
| 960 | fn findid to long |
| 961 | s = ulong 0 |
| 962 | n = get gu GSN |
| 963 | while lt s n bound 999999 |
| 964 | e = lend s |
| 965 | if not blank s e |
| 966 | if hasid s e |
| 967 | put gu GLE e |
| 968 | ret long s |
| 969 | end |
| 970 | end |
| 971 | s = add e 1 |
| 972 | end |
| 973 | ret -1 |
| 974 | end |
| 975 | |
| 976 | fn fsyncd o ulong n ulong to long |
| 977 | pset |
| 978 | plit o n |
| 979 | fd = fopen pth 0 get gu GPL 540672 0 |
| 980 | if lt fd 0 |
| 981 | ret fd |
| 982 | end |
| 983 | r = fsync int fd |
| 984 | c = fclose int fd |
| 985 | ret r |
| 986 | end |
| 987 | |
| 988 | fn appendst to long |
| 989 | pset |
| 990 | plit OSTO NSTO |
| 991 | made = false |
| 992 | fd = fopen pth 0 get gu GPL 558081 0 |
| 993 | if eq fd neg long 2 |
| 994 | fd = fopen pth 0 get gu GPL 558273 384 |
| 995 | made = true |
| 996 | end |
| 997 | if lt fd 0 |
| 998 | ret -1 |
| 999 | end |
| 1000 | r = fchmod int fd 384 |
| 1001 | w = write int fd dbuf 0 get gu GDN |
| 1002 | x = write int fd lit ONL 1 |
| 1003 | r = fsync int fd |
| 1004 | c = fclose int fd |
| 1005 | if or ne w long get gu GDN ne x 1 |
| 1006 | ret -1 |
| 1007 | end |
| 1008 | if made |
| 1009 | r = fsyncd ODOT NDOT |
| 1010 | end |
| 1011 | ret 0 |
| 1012 | end |
| 1013 | |
| 1014 | note Write the store lines without the drop's id to fd. Returns how many were left out. |
| 1015 | fn wkeep fd int to long |
| 1016 | gone = long 0 |
| 1017 | s = ulong 0 |
| 1018 | n = get gu GSN |
| 1019 | while lt s n bound 999999 |
| 1020 | e = lend s |
| 1021 | if not blank s e |
| 1022 | if hit s e |
| 1023 | gone = add gone 1 |
| 1024 | else |
| 1025 | w = write fd sbuf s sub e s |
| 1026 | w = write fd lit ONL 1 |
| 1027 | end |
| 1028 | end |
| 1029 | s = add e 1 |
| 1030 | end |
| 1031 | ret gone |
| 1032 | end |
| 1033 | |
| 1034 | note Rename the tmp file (the first tl bytes of pth) over contacts.jsonl, then sync the dir. |
| 1035 | fn rnstore tl ulong to long |
| 1036 | put pk 0 2 |
| 1037 | put pk 1 0 |
| 1038 | put pk 2 uchar tl |
| 1039 | put pk 3 0 |
| 1040 | for i ulong tl |
| 1041 | put pk add 4 i get pth i |
| 1042 | end |
| 1043 | o = add 4 tl |
| 1044 | put pk o uchar NSTO |
| 1045 | put pk add o 1 0 |
| 1046 | for i ulong NSTO |
| 1047 | put pk add add o 2 i get lit add OSTO i |
| 1048 | end |
| 1049 | r = renames pk 0 add add o 2 NSTO 0 |
| 1050 | if ne r 0 |
| 1051 | ret -1 |
| 1052 | end |
| 1053 | ret fsyncd ODOT NDOT |
| 1054 | end |
| 1055 | |
| 1056 | note Rewrite the store without the lines carrying the drop's id. Returns how many went. |
| 1057 | fn rewrite to long |
| 1058 | pset |
| 1059 | plit OTMP NTMP |
| 1060 | if lt phex 8 0 |
| 1061 | ret -1 |
| 1062 | end |
| 1063 | tl = get gu GPL |
| 1064 | fd = fopen pth 0 tl 524481 384 |
| 1065 | if lt fd 0 |
| 1066 | ret -1 |
| 1067 | end |
| 1068 | gone = wkeep int fd |
| 1069 | r = fsync int fd |
| 1070 | c = fclose int fd |
| 1071 | if lt rnstore tl 0 |
| 1072 | ret -1 |
| 1073 | end |
| 1074 | ret gone |
| 1075 | end |
| 1076 | |
| 1077 | note Tombstone line: stamp, event (0 forget, 1 forget_visitor), count. No id, no field. |
| 1078 | fn audit gone long ev ulong to long |
| 1079 | put gu GAL 0 |
| 1080 | tstamp true |
| 1081 | for i ulong get gu GTL |
| 1082 | ab1 get tb i |
| 1083 | end |
| 1084 | if eq ev 0 |
| 1085 | for i ulong NFRM |
| 1086 | ab1 get lit add OFRM i |
| 1087 | end |
| 1088 | else |
| 1089 | for i ulong NFVR |
| 1090 | ab1 get lit add OFVR i |
| 1091 | end |
| 1092 | end |
| 1093 | anum gone |
| 1094 | ab1 10 |
| 1095 | pset |
| 1096 | plit OAUD NAUD |
| 1097 | fd = fopen pth 0 get gu GPL 558145 384 |
| 1098 | if lt fd 0 |
| 1099 | ret -1 |
| 1100 | end |
| 1101 | w = write int fd ab 0 get gu GAL |
| 1102 | r = fsync int fd |
| 1103 | c = fclose int fd |
| 1104 | ret 0 |
| 1105 | end |
| 1106 | |
| 1107 | note ------------------------------------------------------------------------ quarantine |
| 1108 | |
| 1109 | fn reclen p ulong to ulong |
| 1110 | ret add ulong get dents add p 16 shl ulong get dents add p 17 8 |
| 1111 | end |
| 1112 | |
| 1113 | note Is the getdents64 record at p named . or .. ? |
| 1114 | fn isdot p ulong to bool |
| 1115 | b0 = get dents add p 19 |
| 1116 | b1 = get dents add p 20 |
| 1117 | b2 = get dents add p 21 |
| 1118 | ret and eq b0 46 or eq b1 0 and eq b1 46 eq b2 0 |
| 1119 | end |
| 1120 | |
| 1121 | fn qcount to long |
| 1122 | pset |
| 1123 | plit OQDR NQDR |
| 1124 | fd = fopen pth 0 get gu GPL 540672 0 |
| 1125 | if lt fd 0 |
| 1126 | ret -1 |
| 1127 | end |
| 1128 | c = long 0 |
| 1129 | while true bound 99999 |
| 1130 | r = getdnts int fd dents 0 len dents |
| 1131 | if le r 0 |
| 1132 | break |
| 1133 | end |
| 1134 | p = ulong 0 |
| 1135 | while lt p ulong r bound 99999 |
| 1136 | if not isdot p |
| 1137 | c = add c 1 |
| 1138 | end |
| 1139 | p = add p reclen p |
| 1140 | end |
| 1141 | end |
| 1142 | r = fclose int fd |
| 1143 | ret c |
| 1144 | end |
| 1145 | |
| 1146 | fn quar to long |
| 1147 | pset |
| 1148 | plit OQDR NQDR |
| 1149 | r = makedir pth 0 get gu GPL 448 |
| 1150 | if and ne r 0 ne r neg long 17 |
| 1151 | ret -1 |
| 1152 | end |
| 1153 | if ne plstat 0 |
| 1154 | ret -1 |
| 1155 | end |
| 1156 | mode = rd32 16 |
| 1157 | if or ne and mode 61440 16384 or ne rd32 24 ulong getuid ne and mode 63 0 |
| 1158 | ret -1 |
| 1159 | end |
| 1160 | c = qcount |
| 1161 | if lt c 0 |
| 1162 | ret -1 |
| 1163 | end |
| 1164 | if ge c QCAP |
| 1165 | bump CQF |
| 1166 | ret 0 |
| 1167 | end |
| 1168 | pset |
| 1169 | plit OQDR NQDR |
| 1170 | plit OSLS NSLS |
| 1171 | tstamp false |
| 1172 | for i ulong get gu GTL |
| 1173 | pb get tb i |
| 1174 | end |
| 1175 | pb 45 |
| 1176 | if lt phex 4 0 |
| 1177 | ret -1 |
| 1178 | end |
| 1179 | plit OJSN NJSN |
| 1180 | fd = fopen pth 0 get gu GPL 557249 384 |
| 1181 | if lt fd 0 |
| 1182 | ret -1 |
| 1183 | end |
| 1184 | n = get gu GDN |
| 1185 | if gt n MAXD |
| 1186 | n = MAXD |
| 1187 | end |
| 1188 | w = write int fd dbuf 0 n |
| 1189 | r = fsync int fd |
| 1190 | c = fclose int fd |
| 1191 | r = fsyncd OQDR NQDR |
| 1192 | ret 0 |
| 1193 | end |
| 1194 | |
| 1195 | note ------------------------------------------------------------------------ the drops |
| 1196 | |
| 1197 | note Remove the entry at pth without following it: unlink, else rmdir. key counts a removal. |
| 1198 | fn rment key ulong to void |
| 1199 | r = unlink pth 0 get gu GPL |
| 1200 | if eq r neg long 2 |
| 1201 | ret |
| 1202 | end |
| 1203 | if ne r 0 |
| 1204 | r = rmdir pth 0 get gu GPL |
| 1205 | if ne r 0 |
| 1206 | bump CST |
| 1207 | ret |
| 1208 | end |
| 1209 | end |
| 1210 | bump key |
| 1211 | end |
| 1212 | |
| 1213 | fn entpath i ulong to void |
| 1214 | pset |
| 1215 | pdd |
| 1216 | plit OSLS NSLS |
| 1217 | pnam i |
| 1218 | end |
| 1219 | |
| 1220 | fn namok i ulong to bool |
| 1221 | if ne get nlen i 21 |
| 1222 | ret false |
| 1223 | end |
| 1224 | b = mul i 256 |
| 1225 | for j ulong 16 |
| 1226 | if not ishex ulong get nbuf add b j |
| 1227 | ret false |
| 1228 | end |
| 1229 | end |
| 1230 | for j ulong NJSN |
| 1231 | if ne get nbuf add add b 16 j get lit add OJSN j |
| 1232 | ret false |
| 1233 | end |
| 1234 | end |
| 1235 | ret true |
| 1236 | end |
| 1237 | |
| 1238 | note Read the open drop into dbuf (at most MAXR bytes). Returns 1 regular, 0 not. |
| 1239 | fn slurp fd int to ulong |
| 1240 | r = fstat fd stb 0 128 |
| 1241 | if ne r 0 |
| 1242 | ret 0 |
| 1243 | end |
| 1244 | if or ne and rd32 16 61440 32768 ne rd32 20 1 |
| 1245 | ret 0 |
| 1246 | end |
| 1247 | n = ulong 0 |
| 1248 | while lt n MAXR bound 99999 |
| 1249 | r = read fd dbuf n sub MAXR n |
| 1250 | if le r 0 |
| 1251 | break |
| 1252 | end |
| 1253 | n = add n ulong r |
| 1254 | end |
| 1255 | put gu GDN n |
| 1256 | ret 1 |
| 1257 | end |
| 1258 | |
| 1259 | fn dointro to long |
| 1260 | if ne loadst 0 |
| 1261 | ret -1 |
| 1262 | end |
| 1263 | f = findid |
| 1264 | if lt f 0 |
| 1265 | if ne appendst 0 |
| 1266 | ret -1 |
| 1267 | end |
| 1268 | bump CIS |
| 1269 | ret 0 |
| 1270 | end |
| 1271 | s = ulong f |
| 1272 | e = get gu GLE |
| 1273 | same = eq sub e s get gu GDN |
| 1274 | if same |
| 1275 | for i ulong sub e s |
| 1276 | if ne get sbuf add s i get dbuf i |
| 1277 | same = false |
| 1278 | break |
| 1279 | end |
| 1280 | end |
| 1281 | end |
| 1282 | if same |
| 1283 | bump CIA |
| 1284 | ret 0 |
| 1285 | end |
| 1286 | ret CQD |
| 1287 | end |
| 1288 | |
| 1289 | fn shaat p ulong to bool |
| 1290 | for i ulong NSHP |
| 1291 | if ne get sbuf add p i get lit add OSHP i |
| 1292 | ret false |
| 1293 | end |
| 1294 | end |
| 1295 | ret true |
| 1296 | end |
| 1297 | |
| 1298 | note Position of the 64-hex delete_token_sha256 value in the store line found at f, or 0. |
| 1299 | fn shapos f long to ulong |
| 1300 | if lt f 0 |
| 1301 | ret 0 |
| 1302 | end |
| 1303 | p = ulong f |
| 1304 | e = get gu GLE |
| 1305 | while le add add p NSHP 65 e bound 999999 |
| 1306 | if shaat p |
| 1307 | h = add p NSHP |
| 1308 | for i ulong 64 |
| 1309 | if not ishex ulong get sbuf add h i |
| 1310 | ret 0 |
| 1311 | end |
| 1312 | end |
| 1313 | if ne get sbuf add h 64 34 |
| 1314 | ret 0 |
| 1315 | end |
| 1316 | ret h |
| 1317 | end |
| 1318 | p = add p 1 |
| 1319 | end |
| 1320 | ret 0 |
| 1321 | end |
| 1322 | |
| 1323 | note Constant-time compare of the forget token with the target's hash (zeros when none). |
| 1324 | fn tokeq f long to bool |
| 1325 | t = get fs 2 |
| 1326 | h = shapos f |
| 1327 | acc = ulong 0 |
| 1328 | for i ulong 64 |
| 1329 | x = ulong 48 |
| 1330 | if ne h 0 |
| 1331 | x = ulong get sbuf add h i |
| 1332 | end |
| 1333 | acc = or acc xor x ulong get dbuf add t i |
| 1334 | end |
| 1335 | ret eq acc 0 |
| 1336 | end |
| 1337 | |
| 1338 | fn doforget to long |
| 1339 | if ne loadst 0 |
| 1340 | ret -1 |
| 1341 | end |
| 1342 | f = findid |
| 1343 | m = tokeq f |
| 1344 | if and m ge f 0 |
| 1345 | put gu GMOD 0 |
| 1346 | g = rewrite |
| 1347 | if lt g 0 |
| 1348 | ret -1 |
| 1349 | end |
| 1350 | if ne audit g 0 0 |
| 1351 | ret -1 |
| 1352 | end |
| 1353 | bump CFM |
| 1354 | ret 0 |
| 1355 | end |
| 1356 | bump CFU |
| 1357 | ret 0 |
| 1358 | end |
| 1359 | |
| 1360 | note Every record with the drop's vid goes; none of them, or an unchanged store, if none match. |
| 1361 | fn dofv to long |
| 1362 | if ne loadst 0 |
| 1363 | ret -1 |
| 1364 | end |
| 1365 | if eq cntvid 0 |
| 1366 | bump CVU |
| 1367 | ret 0 |
| 1368 | end |
| 1369 | put gu GMOD 1 |
| 1370 | g = rewrite |
| 1371 | if lt g 0 |
| 1372 | ret -1 |
| 1373 | end |
| 1374 | if ne audit g 1 0 |
| 1375 | ret -1 |
| 1376 | end |
| 1377 | bump CVM |
| 1378 | ret 0 |
| 1379 | end |
| 1380 | |
| 1381 | note Process drop i. Returns 0, or -1 on a store failure (fatal, the drop stays). |
| 1382 | fn procent i ulong to long |
| 1383 | entpath i |
| 1384 | fd = fopen pth 0 get gu GPL 559104 0 |
| 1385 | if eq fd neg long 2 |
| 1386 | ret 0 |
| 1387 | end |
| 1388 | if lt fd 0 |
| 1389 | rment CRN |
| 1390 | ret 0 |
| 1391 | end |
| 1392 | reg = slurp int fd |
| 1393 | r = fclose int fd |
| 1394 | if eq reg 0 |
| 1395 | rment CRN |
| 1396 | ret 0 |
| 1397 | end |
| 1398 | why = long 0 |
| 1399 | if not namok i |
| 1400 | why = CQN |
| 1401 | end |
| 1402 | if and eq why 0 gt get gu GDN MAXD |
| 1403 | why = CQO |
| 1404 | end |
| 1405 | if eq why 0 |
| 1406 | k = classify |
| 1407 | if eq k 0 |
| 1408 | why = CQI |
| 1409 | end |
| 1410 | if eq k 1 |
| 1411 | why = dointro |
| 1412 | end |
| 1413 | if eq k 2 |
| 1414 | why = doforget |
| 1415 | end |
| 1416 | if eq k 3 |
| 1417 | why = dofv |
| 1418 | end |
| 1419 | end |
| 1420 | if lt why 0 |
| 1421 | ret -1 |
| 1422 | end |
| 1423 | if gt why 0 |
| 1424 | if ne quar 0 |
| 1425 | ret -2 |
| 1426 | end |
| 1427 | bump CQ |
| 1428 | bump ulong why |
| 1429 | end |
| 1430 | entpath i |
| 1431 | r = unlink pth 0 get gu GPL |
| 1432 | ret 0 |
| 1433 | end |
| 1434 | |
| 1435 | note -------------------------------------------------------------------------- scanning |
| 1436 | |
| 1437 | fn addent p ulong to void |
| 1438 | n = get gu GNE |
| 1439 | nl = ulong 0 |
| 1440 | while ne get dents add add p 19 nl 0 bound 300 |
| 1441 | nl = add nl 1 |
| 1442 | end |
| 1443 | b = mul n 256 |
| 1444 | for j ulong nl |
| 1445 | put nbuf add b j get dents add add p 19 j |
| 1446 | end |
| 1447 | put nlen n nl |
| 1448 | entpath n |
| 1449 | r = plstat |
| 1450 | if ne r 0 |
| 1451 | ret |
| 1452 | end |
| 1453 | put nmt n mtns |
| 1454 | put ordx n n |
| 1455 | put gu GNE add n 1 |
| 1456 | end |
| 1457 | |
| 1458 | fn scan to long |
| 1459 | pset |
| 1460 | pdd |
| 1461 | fd = fopen pth 0 get gu GPL 540672 0 |
| 1462 | if lt fd 0 |
| 1463 | ret -1 |
| 1464 | end |
| 1465 | while lt get gu GNE MAXE bound 99999 |
| 1466 | r = getdnts int fd dents 0 len dents |
| 1467 | if le r 0 |
| 1468 | break |
| 1469 | end |
| 1470 | p = ulong 0 |
| 1471 | while and lt p ulong r lt get gu GNE MAXE bound 99999 |
| 1472 | if not isdot p |
| 1473 | addent p |
| 1474 | end |
| 1475 | p = add p reclen p |
| 1476 | end |
| 1477 | end |
| 1478 | r = fclose int fd |
| 1479 | ret 0 |
| 1480 | end |
| 1481 | |
| 1482 | fn lessent a ulong b ulong to bool |
| 1483 | if ne get nmt a get nmt b |
| 1484 | ret lt get nmt a get nmt b |
| 1485 | end |
| 1486 | la = get nlen a |
| 1487 | lb = get nlen b |
| 1488 | oa = mul a 256 |
| 1489 | o2 = mul b 256 |
| 1490 | for i ulong 256 |
| 1491 | if or ge i la ge i lb |
| 1492 | ret lt la lb |
| 1493 | end |
| 1494 | x = get nbuf add oa i |
| 1495 | y = get nbuf add o2 i |
| 1496 | if ne x y |
| 1497 | ret lt x y |
| 1498 | end |
| 1499 | end |
| 1500 | ret false |
| 1501 | end |
| 1502 | |
| 1503 | fn sortent to void |
| 1504 | n = get gu GNE |
| 1505 | for i ulong n |
| 1506 | j = i |
| 1507 | while gt j 0 bound 5000 |
| 1508 | a = get ordx sub j 1 |
| 1509 | b = get ordx j |
| 1510 | if not lessent b a |
| 1511 | break |
| 1512 | end |
| 1513 | put ordx sub j 1 b |
| 1514 | put ordx j a |
| 1515 | j = sub j 1 |
| 1516 | end |
| 1517 | end |
| 1518 | end |
| 1519 | |
| 1520 | note ----------------------------------------------------------------- lock and directories |
| 1521 | |
| 1522 | fn dirok which ulong mask ulong to bool |
| 1523 | pset |
| 1524 | if eq which 0 |
| 1525 | pdd |
| 1526 | else |
| 1527 | psd |
| 1528 | end |
| 1529 | if ne plstat 0 |
| 1530 | ret false |
| 1531 | end |
| 1532 | mode = rd32 16 |
| 1533 | if ne and mode 61440 16384 |
| 1534 | ret false |
| 1535 | end |
| 1536 | if ne rd32 24 ulong getuid |
| 1537 | ret false |
| 1538 | end |
| 1539 | ret eq and and mode 63 mask 0 |
| 1540 | end |
| 1541 | |
| 1542 | fn lockst to long |
| 1543 | deadln = add monons 10000000000 |
| 1544 | while true bound 999999 |
| 1545 | pset |
| 1546 | plit OLCK NLCK |
| 1547 | r = makedir pth 0 get gu GPL 448 |
| 1548 | if eq r 0 |
| 1549 | put gu GLK 1 |
| 1550 | ret 0 |
| 1551 | end |
| 1552 | if ne r neg long 17 |
| 1553 | ret -1 |
| 1554 | end |
| 1555 | if eq plstat 0 |
| 1556 | if gt sub realns mtns 300000000000 |
| 1557 | r = rmdir pth 0 get gu GPL |
| 1558 | continue |
| 1559 | end |
| 1560 | end |
| 1561 | if ge monons deadln |
| 1562 | ret -1 |
| 1563 | end |
| 1564 | r = sleepns 50000000 |
| 1565 | end |
| 1566 | ret -1 |
| 1567 | end |
| 1568 | |
| 1569 | fn unlock to void |
| 1570 | if eq get gu GLK 1 |
| 1571 | pset |
| 1572 | plit OLCK NLCK |
| 1573 | r = rmdir pth 0 get gu GPL |
| 1574 | put gu GLK 0 |
| 1575 | end |
| 1576 | end |
| 1577 | |
| 1578 | note ---------------------------------------------------------------------- arguments |
| 1579 | |
| 1580 | fn argcp i ulong which ulong to long |
| 1581 | n = long 0 |
| 1582 | if eq which 0 |
| 1583 | n = argread i ddir 0 4095 |
| 1584 | put gu GDL ulong n |
| 1585 | else |
| 1586 | n = argread i sdir 0 4095 |
| 1587 | put gu GSL ulong n |
| 1588 | end |
| 1589 | ret n |
| 1590 | end |
| 1591 | |
| 1592 | fn args to long |
| 1593 | c = argcnt |
| 1594 | if and ne c 2 ne c 5 |
| 1595 | ret -1 |
| 1596 | end |
| 1597 | n = argread 1 tb 0 len tb |
| 1598 | if ne n long NING |
| 1599 | ret -1 |
| 1600 | end |
| 1601 | for i ulong NING |
| 1602 | if ne get tb i get lit add OING i |
| 1603 | ret -1 |
| 1604 | end |
| 1605 | end |
| 1606 | put gl LNOW -1 |
| 1607 | if eq c 2 |
| 1608 | for i ulong NDDR |
| 1609 | put ddir i get lit add ODDR i |
| 1610 | end |
| 1611 | put gu GDL NDDR |
| 1612 | for i ulong NSDR |
| 1613 | put sdir i get lit add OSDR i |
| 1614 | end |
| 1615 | put gu GSL NSDR |
| 1616 | ret 0 |
| 1617 | end |
| 1618 | if le argcp 2 0 0 |
| 1619 | ret -1 |
| 1620 | end |
| 1621 | if le argcp 3 1 0 |
| 1622 | ret -1 |
| 1623 | end |
| 1624 | n = argread 4 tb 0 len tb |
| 1625 | if le n 0 |
| 1626 | ret -1 |
| 1627 | end |
| 1628 | t = long 0 |
| 1629 | for i ulong ulong n |
| 1630 | b = get tb i |
| 1631 | if or lt b 48 gt b 57 |
| 1632 | ret -1 |
| 1633 | end |
| 1634 | t = add mul t 10 long sub b 48 |
| 1635 | end |
| 1636 | put gl LNOW t |
| 1637 | ret 0 |
| 1638 | end |
| 1639 | |
| 1640 | note -------------------------------------------------------------------------- summary |
| 1641 | |
| 1642 | fn summary to void |
| 1643 | put gu GOL 0 |
| 1644 | olit OHDR NHDR |
| 1645 | any = false |
| 1646 | k = ulong 0 |
| 1647 | s = ulong 0 |
| 1648 | for i ulong add len cn 1 |
| 1649 | e = eq i len cn |
| 1650 | if not e |
| 1651 | e = eq get cn i 32 |
| 1652 | end |
| 1653 | if e |
| 1654 | if gt get cnt k 0 |
| 1655 | any = true |
| 1656 | ob1 32 |
| 1657 | for j ulong sub i s |
| 1658 | ob1 get cn add s j |
| 1659 | end |
| 1660 | ob1 61 |
| 1661 | onum get cnt k |
| 1662 | end |
| 1663 | k = add k 1 |
| 1664 | s = add i 1 |
| 1665 | end |
| 1666 | end |
| 1667 | if not any |
| 1668 | olit ONTH NNTH |
| 1669 | end |
| 1670 | ob1 10 |
| 1671 | w = write 1 ob 0 get gu GOL |
| 1672 | end |
| 1673 | |
| 1674 | fn runall to long |
| 1675 | n = get gu GNE |
| 1676 | for k ulong n |
| 1677 | i = get ordx k |
| 1678 | if eq get nbuf mul i 256 46 |
| 1679 | entpath i |
| 1680 | if ne plstat 0 |
| 1681 | continue |
| 1682 | end |
| 1683 | if gt sub realns mtns 60000000000 |
| 1684 | rment CTS |
| 1685 | else |
| 1686 | bump CTP |
| 1687 | end |
| 1688 | continue |
| 1689 | end |
| 1690 | r = procent i |
| 1691 | if ne r 0 |
| 1692 | ret r |
| 1693 | end |
| 1694 | end |
| 1695 | ret 0 |
| 1696 | end |
| 1697 | |
| 1698 | fn main to int |
| 1699 | if ne args 0 |
| 1700 | emsg OUSE NUSE |
| 1701 | ret 64 |
| 1702 | end |
| 1703 | if not dirok 0 39 |
| 1704 | emsg OEDR NEDR |
| 1705 | ret 1 |
| 1706 | end |
| 1707 | if not dirok 1 63 |
| 1708 | emsg OEDR NEDR |
| 1709 | ret 1 |
| 1710 | end |
| 1711 | pset |
| 1712 | psd |
| 1713 | if ne chdir pth 0 get gu GPL 0 |
| 1714 | emsg OEDR NEDR |
| 1715 | ret 1 |
| 1716 | end |
| 1717 | if ne scan 0 |
| 1718 | emsg OEDR NEDR |
| 1719 | ret 1 |
| 1720 | end |
| 1721 | if ne lockst 0 |
| 1722 | emsg OELK NELK |
| 1723 | ret 1 |
| 1724 | end |
| 1725 | sortent |
| 1726 | r = runall |
| 1727 | unlock |
| 1728 | if eq r -2 |
| 1729 | emsg OEQT NEQT |
| 1730 | ret 1 |
| 1731 | end |
| 1732 | if ne r 0 |
| 1733 | emsg OEST NEST |
| 1734 | ret 1 |
| 1735 | end |
| 1736 | summary |
| 1737 | ret 0 |
| 1738 | end |