aegis-runtime-mv
Native Rust agent runtime: Axum WebSocket/SSE/REST gateway, heartbeat scheduler, dependency-aware task workflow, SQLite storage. Attachment of AienOS. Pre-alpha.
Brought by drakestapleton
aegis-runtime-mv / om / main.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note core/aegis/main.om: Standalone AEGIS runtime CLI entrypoint over stdin/stdout (pure OM-2). |
| 3 | note Compose with: |
| 4 | note si/directives/om2.om om/tls/sha2.om core/aegis/dag.om core/aegis/heartbeat.om |
| 5 | note core/aegis/policy.om core/aegis/journal.om core/aegis/gateway.om core/aegis/main.om |
| 6 | note |
| 7 | note Line commands (stdin): |
| 8 | note INIT <max_conc> <agent_ttl> <lease_ttl> |
| 9 | note TOKEN <32..64_ascii_token> |
| 10 | note AGENT <agent_id> <cap> |
| 11 | note REQ <METHOD> <PATH> <TOKEN_OR_-> [BODY...] |
| 12 | note LEASE <task_id> <agent_id> |
| 13 | note RENEW <task_id> <agent_id> <gen> |
| 14 | note DONE <task_id> <agent_id> <gen> |
| 15 | note FAIL <task_id> <agent_id> <gen> <fail_code> |
| 16 | note TICK <tick> |
| 17 | note VERIFY |
| 18 | note QUIT |
| 19 | |
| 20 | text cli_cmd_init "INIT" |
| 21 | text cli_cmd_tok "TOKEN" |
| 22 | text cli_cmd_agent "AGENT" |
| 23 | text cli_cmd_req "REQ" |
| 24 | text cli_cmd_lease "LEASE" |
| 25 | text cli_cmd_renew "RENEW" |
| 26 | text cli_cmd_done "DONE" |
| 27 | text cli_cmd_fail "FAIL" |
| 28 | text cli_cmd_tick "TICK" |
| 29 | text cli_cmd_verify "VERIFY" |
| 30 | text cli_cmd_quit "QUIT" |
| 31 | text cli_dash "-" |
| 32 | text cli_ok "OK\n" |
| 33 | text cli_err "ERR " |
| 34 | text cli_status "STATUS " |
| 35 | text cli_leased "LEASED gen=" |
| 36 | text cli_tick_out "TICK " |
| 37 | text cli_recl " reclaimed=" |
| 38 | text cli_chain_ok "CHAIN OK seq=" |
| 39 | text cli_chain_err "CHAIN ERR " |
| 40 | text cli_nl "\n" |
| 41 | text cli_jrn_cli "cli" |
| 42 | |
| 43 | global cli_line uchar 1024 |
| 44 | global cli_inbuf uchar 1024 |
| 45 | global cli_outbuf uchar 256 |
| 46 | |
| 47 | fn cli_write_all buf view uchar * n ulong to void |
| 48 | off = ulong 0 |
| 49 | while lt off n bound 1024 |
| 50 | k = write 1 buf off sub n off |
| 51 | if le k 0 |
| 52 | break |
| 53 | end |
| 54 | off = add off ulong k |
| 55 | end |
| 56 | end |
| 57 | |
| 58 | fn cli_write_u64 v ulong to void |
| 59 | buf = new uchar 24 0 |
| 60 | if eq v 0 |
| 61 | put buf 0 uchar 48 |
| 62 | cli_write_all part buf 0 1 1 |
| 63 | ret |
| 64 | end |
| 65 | tmp = new uchar 24 0 |
| 66 | cnt = ulong 0 |
| 67 | x = v |
| 68 | while gt x 0 bound 24 |
| 69 | put tmp cnt uchar add 48 rem x 10 |
| 70 | cnt = add cnt 1 |
| 71 | x = div x 10 |
| 72 | end |
| 73 | for i ulong cnt bound 24 |
| 74 | put buf i get tmp sub sub cnt 1 i |
| 75 | end |
| 76 | cli_write_all part buf 0 cnt cnt |
| 77 | end |
| 78 | |
| 79 | fn cli_print_err code ulong to void |
| 80 | cli_write_all cli_err len cli_err |
| 81 | cli_write_u64 code |
| 82 | cli_write_all cli_nl len cli_nl |
| 83 | end |
| 84 | |
| 85 | fn cli_write_gw_resp to void |
| 86 | n = gw_resp_len |
| 87 | off = ulong 0 |
| 88 | while lt off n bound 1024 |
| 89 | k = write 1 gw_resp off sub n off |
| 90 | if le k 0 |
| 91 | break |
| 92 | end |
| 93 | off = add off ulong k |
| 94 | end |
| 95 | cli_write_all cli_nl len cli_nl |
| 96 | end |
| 97 | |
| 98 | note Skip spaces starting at pos in cli_line[0..llen). |
| 99 | fn cli_skip_sp pos ulong llen ulong to ulong |
| 100 | p = pos |
| 101 | while lt p llen bound 1024 |
| 102 | if or eq get cli_line p 32 eq get cli_line p 9 |
| 103 | p = add p 1 |
| 104 | else |
| 105 | break |
| 106 | end |
| 107 | end |
| 108 | ret p |
| 109 | end |
| 110 | |
| 111 | note Find end of whitespace-delimited token starting at pos. |
| 112 | fn cli_tok_end pos ulong llen ulong to ulong |
| 113 | p = pos |
| 114 | while lt p llen bound 1024 |
| 115 | c = get cli_line p |
| 116 | if or eq c 32 or eq c 9 or eq c 10 eq c 13 |
| 117 | break |
| 118 | end |
| 119 | p = add p 1 |
| 120 | end |
| 121 | ret p |
| 122 | end |
| 123 | |
| 124 | fn cli_tok_eq start ulong endp ulong s view uchar * to bool |
| 125 | tlen = sub endp start |
| 126 | if ne tlen len s |
| 127 | ret false |
| 128 | end |
| 129 | for i ulong tlen bound 64 |
| 130 | if ne get cli_line add start i get s i |
| 131 | ret false |
| 132 | end |
| 133 | end |
| 134 | ret true |
| 135 | end |
| 136 | |
| 137 | note Parse decimal u64 from cli_line[start..endp). Writes value to dst[0]; returns true iff valid. |
| 138 | fn cli_parse_u64 start ulong endp ulong dst edit ulong 1 to bool |
| 139 | put dst 0 0 |
| 140 | if ge start endp |
| 141 | ret false |
| 142 | end |
| 143 | n = sub endp start |
| 144 | if gt n 19 |
| 145 | ret false |
| 146 | end |
| 147 | v = ulong 0 |
| 148 | for i ulong n bound 20 |
| 149 | c = get cli_line add start i |
| 150 | if or lt c 48 gt c 57 |
| 151 | ret false |
| 152 | end |
| 153 | v = add mul v 10 ulong sub c 48 |
| 154 | end |
| 155 | put dst 0 v |
| 156 | ret true |
| 157 | end |
| 158 | |
| 159 | fn cli_exec_init p0 ulong llen ulong to void |
| 160 | a1 = new ulong 1 0 |
| 161 | a2 = new ulong 1 0 |
| 162 | a3 = new ulong 1 0 |
| 163 | p = cli_skip_sp p0 llen |
| 164 | e1 = cli_tok_end p llen |
| 165 | if not cli_parse_u64 p e1 a1 |
| 166 | cli_print_err 1 |
| 167 | ret |
| 168 | end |
| 169 | p = cli_skip_sp e1 llen |
| 170 | e2 = cli_tok_end p llen |
| 171 | if not cli_parse_u64 p e2 a2 |
| 172 | cli_print_err 1 |
| 173 | ret |
| 174 | end |
| 175 | p = cli_skip_sp e2 llen |
| 176 | e3 = cli_tok_end p llen |
| 177 | if not cli_parse_u64 p e3 a3 |
| 178 | cli_print_err 1 |
| 179 | ret |
| 180 | end |
| 181 | dag_reset |
| 182 | jrn_reset |
| 183 | gw_reset |
| 184 | rc = hb_init get a1 0 get a2 0 get a3 0 |
| 185 | if ne rc HB_OK |
| 186 | cli_print_err rc |
| 187 | ret |
| 188 | end |
| 189 | cli_write_all cli_ok len cli_ok |
| 190 | end |
| 191 | |
| 192 | fn cli_exec_token p0 ulong llen ulong to void |
| 193 | p = cli_skip_sp p0 llen |
| 194 | e = cli_tok_end p llen |
| 195 | tlen = sub e p |
| 196 | if or eq tlen 0 gt tlen 64 |
| 197 | cli_print_err POL_DENY_BAD_TOKEN |
| 198 | ret |
| 199 | end |
| 200 | tb = new uchar 64 0 |
| 201 | for i ulong tlen bound 64 |
| 202 | put tb i get cli_line add p i |
| 203 | end |
| 204 | rc = pol_set_operator_token part tb 0 tlen |
| 205 | if ne rc POL_ALLOW |
| 206 | cli_print_err rc |
| 207 | ret |
| 208 | end |
| 209 | cli_write_all cli_ok len cli_ok |
| 210 | end |
| 211 | |
| 212 | fn cli_exec_agent p0 ulong llen ulong to void |
| 213 | a1 = new ulong 1 0 |
| 214 | a2 = new ulong 1 0 |
| 215 | p = cli_skip_sp p0 llen |
| 216 | e1 = cli_tok_end p llen |
| 217 | if not cli_parse_u64 p e1 a1 |
| 218 | cli_print_err 1 |
| 219 | ret |
| 220 | end |
| 221 | p = cli_skip_sp e1 llen |
| 222 | e2 = cli_tok_end p llen |
| 223 | if not cli_parse_u64 p e2 a2 |
| 224 | cli_print_err 1 |
| 225 | ret |
| 226 | end |
| 227 | rc = hb_register_agent get a1 0 get a2 0 |
| 228 | if ne rc HB_OK |
| 229 | cli_print_err rc |
| 230 | ret |
| 231 | end |
| 232 | cli_write_all cli_ok len cli_ok |
| 233 | end |
| 234 | |
| 235 | fn cli_req_stage1 p0 ulong llen ulong to long |
| 236 | mb = new uchar 16 0 |
| 237 | pb = new uchar 128 0 |
| 238 | p = cli_skip_sp p0 llen |
| 239 | e1 = cli_tok_end p llen |
| 240 | mlen = sub e1 p |
| 241 | if or eq mlen 0 gt mlen 16 |
| 242 | cli_print_err 400 |
| 243 | ret -1 |
| 244 | end |
| 245 | for i ulong mlen bound 16 |
| 246 | put mb i get cli_line add p i |
| 247 | end |
| 248 | p = cli_skip_sp e1 llen |
| 249 | e2 = cli_tok_end p llen |
| 250 | plen = sub e2 p |
| 251 | if or eq plen 0 gt plen 128 |
| 252 | cli_print_err 400 |
| 253 | ret -1 |
| 254 | end |
| 255 | for i ulong plen bound 128 |
| 256 | put pb i get cli_line add p i |
| 257 | end |
| 258 | rt = gw_req_begin part mb 0 mlen part pb 0 plen |
| 259 | if gt rt 999 |
| 260 | cli_print_err 400 |
| 261 | ret -1 |
| 262 | end |
| 263 | ret long e2 |
| 264 | end |
| 265 | |
| 266 | fn cli_req_stage2 p0 ulong llen ulong to long |
| 267 | tb = new uchar 64 0 |
| 268 | p = cli_skip_sp p0 llen |
| 269 | e3 = cli_tok_end p llen |
| 270 | tlen = sub e3 p |
| 271 | if gt tlen 64 |
| 272 | cli_print_err 401 |
| 273 | ret -1 |
| 274 | end |
| 275 | if cli_tok_eq p e3 cli_dash |
| 276 | tlen = 0 |
| 277 | else |
| 278 | for i ulong tlen bound 64 |
| 279 | put tb i get cli_line add p i |
| 280 | end |
| 281 | end |
| 282 | gw_req_auth 0 ROLE_OPERATOR part tb 0 tlen true |
| 283 | ret long e3 |
| 284 | end |
| 285 | |
| 286 | fn cli_exec_req p0 ulong llen ulong to void |
| 287 | bb = new uchar 512 0 |
| 288 | n1 = cli_req_stage1 p0 llen |
| 289 | if lt n1 0 |
| 290 | ret |
| 291 | end |
| 292 | n2 = cli_req_stage2 ulong n1 llen |
| 293 | if lt n2 0 |
| 294 | ret |
| 295 | end |
| 296 | p = cli_skip_sp ulong n2 llen |
| 297 | blen = sub llen p |
| 298 | if gt blen 512 |
| 299 | blen = 512 |
| 300 | end |
| 301 | for i ulong blen bound 512 |
| 302 | put bb i get cli_line add p i |
| 303 | end |
| 304 | st = gw_req_dispatch part bb 0 blen |
| 305 | cli_write_all cli_status len cli_status |
| 306 | cli_write_u64 st |
| 307 | cli_write_all cli_nl len cli_nl |
| 308 | cli_write_gw_resp |
| 309 | end |
| 310 | |
| 311 | fn cli_lease_apply tid ulong aid ulong to void |
| 312 | gen = new ulong 1 0 |
| 313 | rdy = dag_solve_ready |
| 314 | if gt rdy DAG_MAX_TASKS |
| 315 | cli_print_err 1 |
| 316 | ret |
| 317 | end |
| 318 | if ne dag_get_state tid TASK_READY |
| 319 | cli_print_err DAG_ERR_INVALID_TRANSITION |
| 320 | ret |
| 321 | end |
| 322 | lrc = hb_acquire_lease tid aid gen |
| 323 | if ne lrc HB_OK |
| 324 | cli_print_err lrc |
| 325 | ret |
| 326 | end |
| 327 | src = dag_start_task tid |
| 328 | if ne src DAG_OK |
| 329 | rl = hb_release_lease tid aid get gen 0 |
| 330 | if gt rl 999 |
| 331 | cli_print_err rl |
| 332 | ret |
| 333 | end |
| 334 | cli_print_err src |
| 335 | ret |
| 336 | end |
| 337 | j1 = jrn_append EVT_LEASE_ACQUIRED tid get gen 0 hb_current_tick cli_jrn_cli |
| 338 | if ne j1 JRN_OK |
| 339 | cli_print_err JRN_ERR_FULL |
| 340 | ret |
| 341 | end |
| 342 | j2 = jrn_append EVT_TASK_STARTED tid aid hb_current_tick cli_jrn_cli |
| 343 | if ne j2 JRN_OK |
| 344 | cli_print_err JRN_ERR_FULL |
| 345 | ret |
| 346 | end |
| 347 | cli_write_all cli_leased len cli_leased |
| 348 | cli_write_u64 get gen 0 |
| 349 | cli_write_all cli_nl len cli_nl |
| 350 | end |
| 351 | |
| 352 | fn cli_exec_lease p0 ulong llen ulong to void |
| 353 | a = new ulong 1 0 |
| 354 | p = cli_skip_sp p0 llen |
| 355 | e = cli_tok_end p llen |
| 356 | if not cli_parse_u64 p e a |
| 357 | cli_print_err 1 |
| 358 | ret |
| 359 | end |
| 360 | tid = get a 0 |
| 361 | p = cli_skip_sp e llen |
| 362 | e = cli_tok_end p llen |
| 363 | if not cli_parse_u64 p e a |
| 364 | cli_print_err 1 |
| 365 | ret |
| 366 | end |
| 367 | cli_lease_apply tid get a 0 |
| 368 | end |
| 369 | |
| 370 | fn cli_exec_renew p0 ulong llen ulong to void |
| 371 | a = new ulong 1 0 |
| 372 | p = cli_skip_sp p0 llen |
| 373 | e = cli_tok_end p llen |
| 374 | if not cli_parse_u64 p e a |
| 375 | cli_print_err 1 |
| 376 | ret |
| 377 | end |
| 378 | tid = get a 0 |
| 379 | p = cli_skip_sp e llen |
| 380 | e = cli_tok_end p llen |
| 381 | if not cli_parse_u64 p e a |
| 382 | cli_print_err 1 |
| 383 | ret |
| 384 | end |
| 385 | aid = get a 0 |
| 386 | p = cli_skip_sp e llen |
| 387 | e = cli_tok_end p llen |
| 388 | if not cli_parse_u64 p e a |
| 389 | cli_print_err 1 |
| 390 | ret |
| 391 | end |
| 392 | rc = hb_renew_lease tid aid get a 0 |
| 393 | if ne rc HB_OK |
| 394 | cli_print_err rc |
| 395 | ret |
| 396 | end |
| 397 | cli_write_all cli_ok len cli_ok |
| 398 | end |
| 399 | |
| 400 | fn cli_done_apply tid ulong aid ulong gen ulong to void |
| 401 | vrc = hb_verify_lease tid aid gen |
| 402 | if ne vrc HB_OK |
| 403 | cli_print_err vrc |
| 404 | ret |
| 405 | end |
| 406 | drc = dag_complete_task tid |
| 407 | if ne drc DAG_OK |
| 408 | cli_print_err drc |
| 409 | ret |
| 410 | end |
| 411 | rrc = hb_release_lease tid aid gen |
| 412 | if ne rrc HB_OK |
| 413 | cli_print_err rrc |
| 414 | ret |
| 415 | end |
| 416 | jrc = jrn_append EVT_TASK_DONE tid gen hb_current_tick cli_jrn_cli |
| 417 | if ne jrc JRN_OK |
| 418 | cli_print_err jrc |
| 419 | ret |
| 420 | end |
| 421 | cli_write_all cli_ok len cli_ok |
| 422 | end |
| 423 | |
| 424 | fn cli_exec_done p0 ulong llen ulong to void |
| 425 | a = new ulong 1 0 |
| 426 | p = cli_skip_sp p0 llen |
| 427 | e = cli_tok_end p llen |
| 428 | if not cli_parse_u64 p e a |
| 429 | cli_print_err 1 |
| 430 | ret |
| 431 | end |
| 432 | tid = get a 0 |
| 433 | p = cli_skip_sp e llen |
| 434 | e = cli_tok_end p llen |
| 435 | if not cli_parse_u64 p e a |
| 436 | cli_print_err 1 |
| 437 | ret |
| 438 | end |
| 439 | aid = get a 0 |
| 440 | p = cli_skip_sp e llen |
| 441 | e = cli_tok_end p llen |
| 442 | if not cli_parse_u64 p e a |
| 443 | cli_print_err 1 |
| 444 | ret |
| 445 | end |
| 446 | cli_done_apply tid aid get a 0 |
| 447 | end |
| 448 | |
| 449 | fn cli_fail_apply tid ulong aid ulong gen ulong fc ulong to void |
| 450 | vrc = hb_verify_lease tid aid gen |
| 451 | if ne vrc HB_OK |
| 452 | cli_print_err vrc |
| 453 | ret |
| 454 | end |
| 455 | drc = dag_fail_task tid fc |
| 456 | if ne drc DAG_OK |
| 457 | cli_print_err drc |
| 458 | ret |
| 459 | end |
| 460 | rrc = hb_release_lease tid aid gen |
| 461 | if ne rrc HB_OK |
| 462 | cli_print_err rrc |
| 463 | ret |
| 464 | end |
| 465 | jrc = jrn_append EVT_TASK_FAILED tid fc hb_current_tick cli_jrn_cli |
| 466 | if ne jrc JRN_OK |
| 467 | cli_print_err jrc |
| 468 | ret |
| 469 | end |
| 470 | cli_write_all cli_ok len cli_ok |
| 471 | end |
| 472 | |
| 473 | fn cli_exec_fail p0 ulong llen ulong to void |
| 474 | a = new ulong 1 0 |
| 475 | p = cli_skip_sp p0 llen |
| 476 | e = cli_tok_end p llen |
| 477 | if not cli_parse_u64 p e a |
| 478 | cli_print_err 1 |
| 479 | ret |
| 480 | end |
| 481 | tid = get a 0 |
| 482 | p = cli_skip_sp e llen |
| 483 | e = cli_tok_end p llen |
| 484 | if not cli_parse_u64 p e a |
| 485 | cli_print_err 1 |
| 486 | ret |
| 487 | end |
| 488 | aid = get a 0 |
| 489 | p = cli_skip_sp e llen |
| 490 | e = cli_tok_end p llen |
| 491 | if not cli_parse_u64 p e a |
| 492 | cli_print_err 1 |
| 493 | ret |
| 494 | end |
| 495 | gen = get a 0 |
| 496 | p = cli_skip_sp e llen |
| 497 | e = cli_tok_end p llen |
| 498 | if not cli_parse_u64 p e a |
| 499 | cli_print_err 1 |
| 500 | ret |
| 501 | end |
| 502 | cli_fail_apply tid aid gen get a 0 |
| 503 | end |
| 504 | |
| 505 | fn cli_exec_tick p0 ulong llen ulong to void |
| 506 | a1 = new ulong 1 0 |
| 507 | p = cli_skip_sp p0 llen |
| 508 | e1 = cli_tok_end p llen |
| 509 | if not cli_parse_u64 p e1 a1 |
| 510 | cli_print_err 1 |
| 511 | ret |
| 512 | end |
| 513 | tk = get a1 0 |
| 514 | rc = hb_tick tk |
| 515 | if ne rc HB_OK |
| 516 | cli_print_err rc |
| 517 | ret |
| 518 | end |
| 519 | recl = hb_last_reclaimed |
| 520 | for i ulong recl bound 128 |
| 521 | rtid = hb_get_reclaimed i |
| 522 | if eq dag_get_state rtid TASK_RUNNING |
| 523 | q = dag_requeue_task rtid |
| 524 | if eq q DAG_OK |
| 525 | j1 = jrn_append EVT_LEASE_RECLAIMED rtid tk tk cli_jrn_cli |
| 526 | if ne j1 JRN_OK |
| 527 | cli_print_err j1 |
| 528 | ret |
| 529 | end |
| 530 | end |
| 531 | end |
| 532 | end |
| 533 | j2 = jrn_append EVT_HEARTBEAT_TICK 0 recl tk cli_jrn_cli |
| 534 | if ne j2 JRN_OK |
| 535 | cli_print_err j2 |
| 536 | ret |
| 537 | end |
| 538 | cli_write_all cli_tick_out len cli_tick_out |
| 539 | cli_write_u64 tk |
| 540 | cli_write_all cli_recl len cli_recl |
| 541 | cli_write_u64 recl |
| 542 | cli_write_all cli_nl len cli_nl |
| 543 | end |
| 544 | |
| 545 | fn cli_exec_verify to void |
| 546 | rc = jrn_verify_chain |
| 547 | if ne rc JRN_OK |
| 548 | cli_write_all cli_chain_err len cli_chain_err |
| 549 | cli_write_u64 rc |
| 550 | cli_write_all cli_nl len cli_nl |
| 551 | ret |
| 552 | end |
| 553 | cli_write_all cli_chain_ok len cli_chain_ok |
| 554 | cli_write_u64 jrn_last_seq |
| 555 | cli_write_all cli_nl len cli_nl |
| 556 | end |
| 557 | |
| 558 | note Process one line in cli_line[0..llen). Returns true if QUIT requested. |
| 559 | fn cli_process_line llen ulong to bool |
| 560 | p = cli_skip_sp 0 llen |
| 561 | if ge p llen |
| 562 | ret false |
| 563 | end |
| 564 | e = cli_tok_end p llen |
| 565 | if cli_tok_eq p e cli_cmd_quit |
| 566 | ret true |
| 567 | end |
| 568 | if cli_tok_eq p e cli_cmd_init |
| 569 | cli_exec_init e llen |
| 570 | ret false |
| 571 | end |
| 572 | if cli_tok_eq p e cli_cmd_tok |
| 573 | cli_exec_token e llen |
| 574 | ret false |
| 575 | end |
| 576 | if cli_tok_eq p e cli_cmd_agent |
| 577 | cli_exec_agent e llen |
| 578 | ret false |
| 579 | end |
| 580 | if cli_tok_eq p e cli_cmd_req |
| 581 | cli_exec_req e llen |
| 582 | ret false |
| 583 | end |
| 584 | if cli_tok_eq p e cli_cmd_lease |
| 585 | cli_exec_lease e llen |
| 586 | ret false |
| 587 | end |
| 588 | if cli_tok_eq p e cli_cmd_renew |
| 589 | cli_exec_renew e llen |
| 590 | ret false |
| 591 | end |
| 592 | if cli_tok_eq p e cli_cmd_done |
| 593 | cli_exec_done e llen |
| 594 | ret false |
| 595 | end |
| 596 | if cli_tok_eq p e cli_cmd_fail |
| 597 | cli_exec_fail e llen |
| 598 | ret false |
| 599 | end |
| 600 | if cli_tok_eq p e cli_cmd_tick |
| 601 | cli_exec_tick e llen |
| 602 | ret false |
| 603 | end |
| 604 | if cli_tok_eq p e cli_cmd_verify |
| 605 | cli_exec_verify |
| 606 | ret false |
| 607 | end |
| 608 | cli_print_err 400 |
| 609 | ret false |
| 610 | end |
| 611 | |
| 612 | fn main to int |
| 613 | dag_reset |
| 614 | pol_reset |
| 615 | jrn_reset |
| 616 | gw_reset |
| 617 | init_rc = hb_init 4 3 5 |
| 618 | if ne init_rc HB_OK |
| 619 | ret 1 |
| 620 | end |
| 621 | llen = ulong 0 |
| 622 | done = false |
| 623 | while not done bound 4096 |
| 624 | k = read 0 cli_inbuf 0 1024 |
| 625 | if le k 0 |
| 626 | if gt llen 0 |
| 627 | q = cli_process_line llen |
| 628 | if q |
| 629 | done = true |
| 630 | end |
| 631 | end |
| 632 | break |
| 633 | end |
| 634 | cnt = ulong k |
| 635 | for i ulong cnt bound 1024 |
| 636 | b = get cli_inbuf i |
| 637 | if eq b 10 |
| 638 | if cli_process_line llen |
| 639 | done = true |
| 640 | break |
| 641 | end |
| 642 | llen = 0 |
| 643 | else |
| 644 | if ne b 13 |
| 645 | if lt llen 1024 |
| 646 | put cli_line llen b |
| 647 | llen = add llen 1 |
| 648 | end |
| 649 | end |
| 650 | end |
| 651 | end |
| 652 | end |
| 653 | ret 0 |
| 654 | end |