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 / tools / rx_operator.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | note |
| 4 | note rx_operator.om: operator client for a running production world |
| 5 | note (docs/r16-operator-control.md). Pure seeded OM-2 replacement for tools/rx_operator.c. |
| 6 | om2 |
| 7 | |
| 8 | text t_usage "usage: rx_operator (--control <dir> | --cred <file>) (status|stop [reason]|resume|revoke-cap|revoke|shutdown | --raw <line>)\n" |
| 9 | text t_f_ctrl "--control" |
| 10 | text t_f_cred "--cred" |
| 11 | text t_f_raw "--raw" |
| 12 | text t_cred_suf "/operator.cred" |
| 13 | text t_sock_suf "/operator.sock" |
| 14 | text t_cred_hdr "aien-operator-credential v1\n" |
| 15 | text t_k_sock "socket " |
| 16 | text t_k_subj "subject " |
| 17 | text t_k_cred "cred " |
| 18 | text t_k_cap "cap " |
| 19 | text t_at_dl "@deadline@" |
| 20 | text t_req_pfx "aien-operator v1 " |
| 21 | text t_req_subj " subject=" |
| 22 | text t_req_gen " gen=" |
| 23 | text t_req_sec " secret=" |
| 24 | text t_req_cap " cap=" |
| 25 | text t_req_dl " deadline=" |
| 26 | text t_req_rsn " reason=" |
| 27 | text t_rep_ok "aien-operator v1 OK " |
| 28 | text t_rep_snd "aien-operator v1 STOPPED_NOT_DURABLE " |
| 29 | text t_e_nocred "rx_operator: no credential at " |
| 30 | text t_e_notcred "rx_operator: not an operator credential file: " |
| 31 | text t_e_incomp "rx_operator: incomplete credential: " |
| 32 | text t_e_long "rx_operator: socket path too long\n" |
| 33 | text t_e_noworld "rx_operator: no world is serving " |
| 34 | text t_e_send "rx_operator: send failed (reading any reply)\n" |
| 35 | text t_e_norep "rx_operator: no reply\n" |
| 36 | text t_nl "\n" |
| 37 | |
| 38 | global g_ctrl uchar 512 |
| 39 | global g_cred uchar 512 |
| 40 | global g_raw uchar 1024 |
| 41 | global g_cmd uchar 256 |
| 42 | global g_rsn uchar 512 |
| 43 | global g_tmp uchar 1024 |
| 44 | global g_lens ulong 6 |
| 45 | |
| 46 | global g_path uchar 512 |
| 47 | global g_fbuf uchar 4096 |
| 48 | global g_sock uchar 256 |
| 49 | global g_sec uchar 80 |
| 50 | global g_meta ulong 8 |
| 51 | global g_req uchar 1024 |
| 52 | global g_addr uchar 110 |
| 53 | global g_rep uchar 2048 |
| 54 | |
| 55 | fn wr_txt fd int s view uchar * to void |
| 56 | off = ulong 0 |
| 57 | n = len s |
| 58 | while lt off n bound 4096 |
| 59 | k = write fd s off sub n off |
| 60 | if eq k neg long 4 |
| 61 | continue |
| 62 | end |
| 63 | if le k 0 |
| 64 | ret |
| 65 | end |
| 66 | off = add off ulong k |
| 67 | end |
| 68 | end |
| 69 | |
| 70 | fn wnl fd int to void |
| 71 | wr_txt fd t_nl |
| 72 | end |
| 73 | |
| 74 | fn wr_gpath fd int n ulong to void |
| 75 | off = ulong 0 |
| 76 | while lt off n bound 512 |
| 77 | k = write fd g_path off sub n off |
| 78 | if eq k neg long 4 |
| 79 | continue |
| 80 | end |
| 81 | if le k 0 |
| 82 | ret |
| 83 | end |
| 84 | off = add off ulong k |
| 85 | end |
| 86 | end |
| 87 | |
| 88 | fn wr_gsock fd int n ulong to void |
| 89 | off = ulong 0 |
| 90 | while lt off n bound 256 |
| 91 | k = write fd g_sock off sub n off |
| 92 | if eq k neg long 4 |
| 93 | continue |
| 94 | end |
| 95 | if le k 0 |
| 96 | ret |
| 97 | end |
| 98 | off = add off ulong k |
| 99 | end |
| 100 | end |
| 101 | |
| 102 | fn wr_grep fd int n ulong to void |
| 103 | off = ulong 0 |
| 104 | while lt off n bound 2048 |
| 105 | k = write fd g_rep off sub n off |
| 106 | if eq k neg long 4 |
| 107 | continue |
| 108 | end |
| 109 | if le k 0 |
| 110 | ret |
| 111 | end |
| 112 | off = add off ulong k |
| 113 | end |
| 114 | end |
| 115 | |
| 116 | fn usage_ret to int |
| 117 | wr_txt 2 t_usage |
| 118 | ret 2 |
| 119 | end |
| 120 | |
| 121 | fn eq_tmp s view uchar * n ulong to bool |
| 122 | if ne n len s |
| 123 | ret false |
| 124 | end |
| 125 | for i ulong len s bound 1024 |
| 126 | if ne get g_tmp i get s i |
| 127 | ret false |
| 128 | end |
| 129 | end |
| 130 | ret true |
| 131 | end |
| 132 | |
| 133 | fn parse_args to int |
| 134 | ac = argcnt |
| 135 | for j ulong 6 |
| 136 | put g_lens j 0 |
| 137 | end |
| 138 | i = ulong 1 |
| 139 | while lt i ulong ac bound 64 |
| 140 | n = argread i g_tmp 0 1023 |
| 141 | if lt n 0 |
| 142 | ret usage_ret |
| 143 | end |
| 144 | un = ulong n |
| 145 | if eq_tmp t_f_ctrl un |
| 146 | i = add i 1 |
| 147 | if ge i ulong ac |
| 148 | ret usage_ret |
| 149 | end |
| 150 | n2 = argread i g_ctrl 0 511 |
| 151 | if le n2 0 |
| 152 | ret usage_ret |
| 153 | end |
| 154 | put g_lens 0 ulong n2 |
| 155 | else |
| 156 | if eq_tmp t_f_cred un |
| 157 | i = add i 1 |
| 158 | if ge i ulong ac |
| 159 | ret usage_ret |
| 160 | end |
| 161 | n2 = argread i g_cred 0 511 |
| 162 | if le n2 0 |
| 163 | ret usage_ret |
| 164 | end |
| 165 | put g_lens 1 ulong n2 |
| 166 | else |
| 167 | if eq_tmp t_f_raw un |
| 168 | i = add i 1 |
| 169 | if ge i ulong ac |
| 170 | ret usage_ret |
| 171 | end |
| 172 | n2 = argread i g_raw 0 1023 |
| 173 | if lt n2 0 |
| 174 | ret usage_ret |
| 175 | end |
| 176 | put g_lens 2 add ulong n2 1 |
| 177 | else |
| 178 | if eq get g_lens 3 0 |
| 179 | if or eq un 0 ge un 256 |
| 180 | ret usage_ret |
| 181 | end |
| 182 | for k ulong un bound 256 |
| 183 | put g_cmd k get g_tmp k |
| 184 | end |
| 185 | put g_lens 3 un |
| 186 | else |
| 187 | if eq get g_lens 4 0 |
| 188 | if or eq un 0 ge un 512 |
| 189 | ret usage_ret |
| 190 | end |
| 191 | for k ulong un bound 512 |
| 192 | put g_rsn k get g_tmp k |
| 193 | end |
| 194 | put g_lens 4 un |
| 195 | else |
| 196 | ret usage_ret |
| 197 | end |
| 198 | end |
| 199 | end |
| 200 | end |
| 201 | end |
| 202 | i = add i 1 |
| 203 | end |
| 204 | has_ctrl = ne get g_lens 0 0 |
| 205 | has_cred = ne get g_lens 1 0 |
| 206 | has_raw = ne get g_lens 2 0 |
| 207 | has_cmd = ne get g_lens 3 0 |
| 208 | if and not has_ctrl not has_cred |
| 209 | ret usage_ret |
| 210 | end |
| 211 | if and not has_raw not has_cmd |
| 212 | ret usage_ret |
| 213 | end |
| 214 | if and has_raw has_cmd |
| 215 | ret usage_ret |
| 216 | end |
| 217 | ret 0 |
| 218 | end |
| 219 | |
| 220 | fn is_sp c uchar to bool |
| 221 | ret or eq c 32 eq c 9 |
| 222 | end |
| 223 | |
| 224 | fn line_starts off ulong ln ulong pfx view uchar * to bool |
| 225 | if lt ln len pfx |
| 226 | ret false |
| 227 | end |
| 228 | for i ulong len pfx bound 64 |
| 229 | if ne get g_fbuf add off i get pfx i |
| 230 | ret false |
| 231 | end |
| 232 | end |
| 233 | ret true |
| 234 | end |
| 235 | |
| 236 | fn parse_u64_span off ulong endp ulong out_idx ulong to long |
| 237 | p = off |
| 238 | while lt p endp bound 256 |
| 239 | if not is_sp get g_fbuf p |
| 240 | break |
| 241 | end |
| 242 | p = add p 1 |
| 243 | end |
| 244 | if ge p endp |
| 245 | ret neg long 1 |
| 246 | end |
| 247 | c0 = get g_fbuf p |
| 248 | if or lt c0 48 gt c0 57 |
| 249 | ret neg long 1 |
| 250 | end |
| 251 | v = ulong 0 |
| 252 | while lt p endp bound 256 |
| 253 | c = get g_fbuf p |
| 254 | if or lt c 48 gt c 57 |
| 255 | break |
| 256 | end |
| 257 | v = add mul v 10 ulong sub c 48 |
| 258 | p = add p 1 |
| 259 | end |
| 260 | put g_meta out_idx v |
| 261 | ret long p |
| 262 | end |
| 263 | |
| 264 | fn copy_tok_sock off ulong endp ulong to long |
| 265 | p = off |
| 266 | while lt p endp bound 256 |
| 267 | if not is_sp get g_fbuf p |
| 268 | break |
| 269 | end |
| 270 | p = add p 1 |
| 271 | end |
| 272 | n = ulong 0 |
| 273 | while lt p endp bound 256 |
| 274 | c = get g_fbuf p |
| 275 | if or is_sp c or eq c 10 eq c 13 |
| 276 | break |
| 277 | end |
| 278 | if lt add n 1 256 |
| 279 | put g_sock n c |
| 280 | n = add n 1 |
| 281 | end |
| 282 | p = add p 1 |
| 283 | end |
| 284 | if eq n 0 |
| 285 | ret neg long 1 |
| 286 | end |
| 287 | put g_sock n 0 |
| 288 | ret long n |
| 289 | end |
| 290 | |
| 291 | fn copy_tok_sec off ulong endp ulong to long |
| 292 | p = off |
| 293 | while lt p endp bound 256 |
| 294 | if not is_sp get g_fbuf p |
| 295 | break |
| 296 | end |
| 297 | p = add p 1 |
| 298 | end |
| 299 | n = ulong 0 |
| 300 | while lt p endp bound 256 |
| 301 | c = get g_fbuf p |
| 302 | if or is_sp c or eq c 10 eq c 13 |
| 303 | break |
| 304 | end |
| 305 | if lt add n 1 80 |
| 306 | put g_sec n c |
| 307 | n = add n 1 |
| 308 | end |
| 309 | p = add p 1 |
| 310 | end |
| 311 | if eq n 0 |
| 312 | ret neg long 1 |
| 313 | end |
| 314 | put g_sec n 0 |
| 315 | ret long n |
| 316 | end |
| 317 | |
| 318 | fn load_cred to int |
| 319 | plen = ulong 0 |
| 320 | if ne get g_lens 1 0 |
| 321 | clen = get g_lens 1 |
| 322 | for i ulong clen bound 512 |
| 323 | put g_path i get g_cred i |
| 324 | end |
| 325 | plen = clen |
| 326 | else |
| 327 | clen = get g_lens 0 |
| 328 | if gt add clen len t_cred_suf 511 |
| 329 | ret usage_ret |
| 330 | end |
| 331 | for i ulong clen bound 512 |
| 332 | put g_path i get g_ctrl i |
| 333 | end |
| 334 | for i ulong len t_cred_suf |
| 335 | put g_path add clen i get t_cred_suf i |
| 336 | end |
| 337 | plen = add clen len t_cred_suf |
| 338 | end |
| 339 | fd = fopen g_path 0 plen 0 0 |
| 340 | if lt fd 0 |
| 341 | wr_txt 2 t_e_nocred |
| 342 | wr_gpath 2 plen |
| 343 | wnl 2 |
| 344 | ret 2 |
| 345 | end |
| 346 | tot = ulong 0 |
| 347 | while lt tot 4095 bound 128 |
| 348 | k = read int fd g_fbuf tot sub 4095 tot |
| 349 | if eq k neg long 4 |
| 350 | continue |
| 351 | end |
| 352 | if le k 0 |
| 353 | break |
| 354 | end |
| 355 | tot = add tot ulong k |
| 356 | end |
| 357 | cl = fclose int fd |
| 358 | if lt tot len t_cred_hdr |
| 359 | wr_txt 2 t_e_notcred |
| 360 | wr_gpath 2 plen |
| 361 | wnl 2 |
| 362 | ret 2 |
| 363 | end |
| 364 | if not line_starts 0 tot t_cred_hdr |
| 365 | wr_txt 2 t_e_notcred |
| 366 | wr_gpath 2 plen |
| 367 | wnl 2 |
| 368 | ret 2 |
| 369 | end |
| 370 | for j ulong 8 |
| 371 | put g_meta j 0 |
| 372 | end |
| 373 | have = ulong 0 |
| 374 | pos = len t_cred_hdr |
| 375 | while lt pos tot bound 256 |
| 376 | endp = pos |
| 377 | while lt endp tot bound 4096 |
| 378 | if eq get g_fbuf endp 10 |
| 379 | break |
| 380 | end |
| 381 | endp = add endp 1 |
| 382 | end |
| 383 | ln = sub endp pos |
| 384 | if line_starts pos ln t_k_sock |
| 385 | sn = copy_tok_sock add pos len t_k_sock endp |
| 386 | if gt sn 0 |
| 387 | put g_meta 4 ulong sn |
| 388 | have = or have 1 |
| 389 | end |
| 390 | else |
| 391 | if line_starts pos ln t_k_subj |
| 392 | np = parse_u64_span add pos len t_k_subj endp 0 |
| 393 | if ge np 0 |
| 394 | have = or have 2 |
| 395 | end |
| 396 | else |
| 397 | if line_starts pos ln t_k_cred |
| 398 | np = parse_u64_span add pos len t_k_cred endp 1 |
| 399 | if ge np 0 |
| 400 | sn = copy_tok_sec ulong np endp |
| 401 | if gt sn 0 |
| 402 | put g_meta 5 ulong sn |
| 403 | have = or have 4 |
| 404 | end |
| 405 | end |
| 406 | else |
| 407 | if line_starts pos ln t_k_cap |
| 408 | np = parse_u64_span add pos len t_k_cap endp 2 |
| 409 | if ge np 0 |
| 410 | np2 = parse_u64_span ulong np endp 3 |
| 411 | if ge np2 0 |
| 412 | have = or have 8 |
| 413 | end |
| 414 | end |
| 415 | end |
| 416 | end |
| 417 | end |
| 418 | end |
| 419 | pos = add endp 1 |
| 420 | end |
| 421 | if ne have 15 |
| 422 | wr_txt 2 t_e_incomp |
| 423 | wr_gpath 2 plen |
| 424 | wnl 2 |
| 425 | ret 2 |
| 426 | end |
| 427 | if ne get g_lens 0 0 |
| 428 | clen = get g_lens 0 |
| 429 | if gt add clen len t_sock_suf 255 |
| 430 | wr_txt 2 t_e_long |
| 431 | ret 2 |
| 432 | end |
| 433 | for i ulong clen bound 256 |
| 434 | put g_sock i get g_ctrl i |
| 435 | end |
| 436 | for i ulong len t_sock_suf |
| 437 | put g_sock add clen i get t_sock_suf i |
| 438 | end |
| 439 | put g_meta 4 add clen len t_sock_suf |
| 440 | end |
| 441 | ret 0 |
| 442 | end |
| 443 | |
| 444 | fn req_add_txt pos ulong s view uchar * to long |
| 445 | n = len s |
| 446 | if gt add pos n 1023 |
| 447 | ret neg long 1 |
| 448 | end |
| 449 | for i ulong n bound 64 |
| 450 | put g_req add pos i get s i |
| 451 | end |
| 452 | ret long add pos n |
| 453 | end |
| 454 | |
| 455 | fn req_add_u64 pos ulong v ulong to long |
| 456 | d = new uchar 24 0 |
| 457 | nd = ulong 0 |
| 458 | x = v |
| 459 | while true bound 24 |
| 460 | put d nd uchar add 48 rem x 10 |
| 461 | nd = add nd 1 |
| 462 | x = div x 10 |
| 463 | if eq x 0 |
| 464 | break |
| 465 | end |
| 466 | end |
| 467 | if gt add pos nd 1023 |
| 468 | ret neg long 1 |
| 469 | end |
| 470 | p = pos |
| 471 | for i ulong nd bound 24 |
| 472 | put g_req p get d sub sub nd 1 i |
| 473 | p = add p 1 |
| 474 | end |
| 475 | ret long p |
| 476 | end |
| 477 | |
| 478 | fn req_add_raw pos ulong off ulong n ulong to long |
| 479 | if gt add pos n 1023 |
| 480 | ret neg long 1 |
| 481 | end |
| 482 | for i ulong n bound 1024 |
| 483 | put g_req add pos i get g_raw add off i |
| 484 | end |
| 485 | ret long add pos n |
| 486 | end |
| 487 | |
| 488 | fn find_at_dl rlen ulong to long |
| 489 | ml = len t_at_dl |
| 490 | if lt rlen ml |
| 491 | ret neg long 1 |
| 492 | end |
| 493 | lim = add sub rlen ml 1 |
| 494 | for i ulong lim bound 1024 |
| 495 | ok = true |
| 496 | for j ulong ml |
| 497 | if ne get g_raw add i j get t_at_dl j |
| 498 | ok = false |
| 499 | break |
| 500 | end |
| 501 | end |
| 502 | if ok |
| 503 | ret long i |
| 504 | end |
| 505 | end |
| 506 | ret neg long 1 |
| 507 | end |
| 508 | |
| 509 | fn build_req dl ulong to long |
| 510 | if ne get g_lens 2 0 |
| 511 | rlen = sub get g_lens 2 1 |
| 512 | hit = find_at_dl rlen |
| 513 | p = long 0 |
| 514 | if ge hit 0 |
| 515 | uhit = ulong hit |
| 516 | p = req_add_raw 0 0 uhit |
| 517 | if lt p 0 |
| 518 | ret neg long 1 |
| 519 | end |
| 520 | p = req_add_u64 ulong p dl |
| 521 | if lt p 0 |
| 522 | ret neg long 1 |
| 523 | end |
| 524 | rest = add uhit len t_at_dl |
| 525 | p = req_add_raw ulong p rest sub rlen rest |
| 526 | if lt p 0 |
| 527 | ret neg long 1 |
| 528 | end |
| 529 | else |
| 530 | p = req_add_raw 0 0 rlen |
| 531 | if lt p 0 |
| 532 | ret neg long 1 |
| 533 | end |
| 534 | end |
| 535 | put g_req ulong p 10 |
| 536 | ret add p 1 |
| 537 | end |
| 538 | p = req_add_txt 0 t_req_pfx |
| 539 | if lt p 0 |
| 540 | ret neg long 1 |
| 541 | end |
| 542 | cl = get g_lens 3 |
| 543 | if gt add ulong p cl 1023 |
| 544 | ret neg long 1 |
| 545 | end |
| 546 | for i ulong cl bound 256 |
| 547 | put g_req add ulong p i get g_cmd i |
| 548 | end |
| 549 | p = add p long cl |
| 550 | p = req_add_txt ulong p t_req_subj |
| 551 | if lt p 0 |
| 552 | ret neg long 1 |
| 553 | end |
| 554 | p = req_add_u64 ulong p get g_meta 0 |
| 555 | if lt p 0 |
| 556 | ret neg long 1 |
| 557 | end |
| 558 | p = req_add_txt ulong p t_req_gen |
| 559 | if lt p 0 |
| 560 | ret neg long 1 |
| 561 | end |
| 562 | p = req_add_u64 ulong p get g_meta 1 |
| 563 | if lt p 0 |
| 564 | ret neg long 1 |
| 565 | end |
| 566 | p = req_add_txt ulong p t_req_sec |
| 567 | if lt p 0 |
| 568 | ret neg long 1 |
| 569 | end |
| 570 | sl = get g_meta 5 |
| 571 | if gt add ulong p sl 1023 |
| 572 | ret neg long 1 |
| 573 | end |
| 574 | for i ulong sl bound 80 |
| 575 | put g_req add ulong p i get g_sec i |
| 576 | end |
| 577 | p = add p long sl |
| 578 | p = req_add_txt ulong p t_req_cap |
| 579 | if lt p 0 |
| 580 | ret neg long 1 |
| 581 | end |
| 582 | p = req_add_u64 ulong p get g_meta 2 |
| 583 | if lt p 0 |
| 584 | ret neg long 1 |
| 585 | end |
| 586 | if ge ulong p 1023 |
| 587 | ret neg long 1 |
| 588 | end |
| 589 | put g_req ulong p 58 |
| 590 | p = add p 1 |
| 591 | p = req_add_u64 ulong p get g_meta 3 |
| 592 | if lt p 0 |
| 593 | ret neg long 1 |
| 594 | end |
| 595 | p = req_add_txt ulong p t_req_dl |
| 596 | if lt p 0 |
| 597 | ret neg long 1 |
| 598 | end |
| 599 | p = req_add_u64 ulong p dl |
| 600 | if lt p 0 |
| 601 | ret neg long 1 |
| 602 | end |
| 603 | if ne get g_lens 4 0 |
| 604 | p = req_add_txt ulong p t_req_rsn |
| 605 | if lt p 0 |
| 606 | ret neg long 1 |
| 607 | end |
| 608 | rl = get g_lens 4 |
| 609 | if gt add ulong p rl 1023 |
| 610 | ret neg long 1 |
| 611 | end |
| 612 | for i ulong rl bound 512 |
| 613 | put g_req add ulong p i get g_rsn i |
| 614 | end |
| 615 | p = add p long rl |
| 616 | end |
| 617 | put g_req ulong p 10 |
| 618 | ret add p 1 |
| 619 | end |
| 620 | |
| 621 | fn zero_secrets to void |
| 622 | for i ulong 80 |
| 623 | put g_sec i 0 |
| 624 | end |
| 625 | for i ulong 1024 |
| 626 | put g_req i 0 |
| 627 | end |
| 628 | end |
| 629 | |
| 630 | fn rep_starts got ulong pfx view uchar * to bool |
| 631 | if lt got len pfx |
| 632 | ret false |
| 633 | end |
| 634 | for i ulong len pfx bound 64 |
| 635 | if ne get g_rep i get pfx i |
| 636 | ret false |
| 637 | end |
| 638 | end |
| 639 | ret true |
| 640 | end |
| 641 | |
| 642 | fn send_and_recv fd int urlen ulong to ulong |
| 643 | off = ulong 0 |
| 644 | while lt off urlen bound 1024 |
| 645 | w = send fd g_req off sub urlen off 16384 |
| 646 | if eq w neg long 4 |
| 647 | continue |
| 648 | end |
| 649 | if le w 0 |
| 650 | wr_txt 2 t_e_send |
| 651 | break |
| 652 | end |
| 653 | off = add off ulong w |
| 654 | end |
| 655 | zero_secrets |
| 656 | sh = shutdown fd 1 |
| 657 | got = ulong 0 |
| 658 | tend = add ulong monons 60000000000 |
| 659 | while lt got 2047 bound 4096 |
| 660 | cur = ulong monons |
| 661 | if ge cur tend |
| 662 | break |
| 663 | end |
| 664 | remns = sub tend cur |
| 665 | wi = waitio fd 1 long remns |
| 666 | if eq wi neg long 4 |
| 667 | continue |
| 668 | end |
| 669 | if le wi 0 |
| 670 | break |
| 671 | end |
| 672 | r = read fd g_rep got sub 2047 got |
| 673 | if eq r neg long 4 |
| 674 | continue |
| 675 | end |
| 676 | if le r 0 |
| 677 | break |
| 678 | end |
| 679 | got = add got ulong r |
| 680 | end |
| 681 | ret got |
| 682 | end |
| 683 | |
| 684 | fn main to int |
| 685 | rc = parse_args |
| 686 | if ne rc 0 |
| 687 | ret rc |
| 688 | end |
| 689 | rc = load_cred |
| 690 | if ne rc 0 |
| 691 | ret rc |
| 692 | end |
| 693 | now = ulong monons |
| 694 | dl = add now 55000000000 |
| 695 | rlen = build_req dl |
| 696 | for i ulong 80 |
| 697 | put g_sec i 0 |
| 698 | end |
| 699 | if le rlen 0 |
| 700 | zero_secrets |
| 701 | ret usage_ret |
| 702 | end |
| 703 | slen = get g_meta 4 |
| 704 | if ge slen 108 |
| 705 | zero_secrets |
| 706 | wr_txt 2 t_e_long |
| 707 | ret 2 |
| 708 | end |
| 709 | for i ulong 110 |
| 710 | put g_addr i 0 |
| 711 | end |
| 712 | put g_addr 0 1 |
| 713 | put g_addr 1 0 |
| 714 | for i ulong slen bound 108 |
| 715 | put g_addr add 2 i get g_sock i |
| 716 | end |
| 717 | fd = socknew 1 524289 0 |
| 718 | if lt fd 0 |
| 719 | zero_secrets |
| 720 | wr_txt 2 t_e_noworld |
| 721 | wr_gsock 2 slen |
| 722 | wnl 2 |
| 723 | ret 2 |
| 724 | end |
| 725 | if ne connect int fd g_addr 0 add 2 add slen 1 0 |
| 726 | zero_secrets |
| 727 | cl = fclose int fd |
| 728 | wr_txt 2 t_e_noworld |
| 729 | wr_gsock 2 slen |
| 730 | wnl 2 |
| 731 | ret 2 |
| 732 | end |
| 733 | got = send_and_recv int fd ulong rlen |
| 734 | cl = fclose int fd |
| 735 | if eq got 0 |
| 736 | wr_txt 2 t_e_norep |
| 737 | ret 2 |
| 738 | end |
| 739 | wr_grep 1 got |
| 740 | if ne get g_rep sub got 1 10 |
| 741 | wnl 1 |
| 742 | end |
| 743 | if rep_starts got t_rep_ok |
| 744 | ret 0 |
| 745 | end |
| 746 | if rep_starts got t_rep_snd |
| 747 | ret 3 |
| 748 | end |
| 749 | ret 1 |
| 750 | end |