code wiki / _hdl_build / nx_route.nx
nx_route.nx
buildroot/runtime/_hdl_build/nx_route.nx
about
nx_route.nx -- the SOVEREIGN S-CLASS ROUTING ENGINE: one declarative pure function every delivery flows through,
replacing per-path if-chains. URL path + a resource manifest -> a routing DECISION. S-class properties, uniform
for ALL resources (qualitative: clean+canonical+safe; quantitative: one engine, every path handled the same):
* CLEAN extensionless URLs: /vn -> serves vn.html ; /foo -> foo/index.html ; exact assets (/x.png,/x.css) served
* ONE CANONICAL url: /vn.html -> 301 /vn ; /vn/ -> 301 /vn (trailing slash) -> no more "/vn vs /vn.html" mess
* TRAVERSAL-SAFE: any ".." -> 400 (never serves outside the docroot)
* deterministic + pure (path+manifest in, decision out) -> fully gateable with zero live-daemon risk.
codes: 0=SERVE(out=file) 1=REDIRECT-301(out=location) 2=NOT-FOUND 3=BAD-REQUEST(traversal). license_tier: ORIGINAL
dependencies 1 imports · 1 importers
imports: nx_syscalls.nx
imported by: nx_route_gate.nx
structs
| none |
consts
| 10 | const K_MAGIC_1024: i64 = 1024 |
functions
| 12 | func r_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 13 | func r_cpy(dst: *u8, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[i] = s[i]; i = i + 1 } dst[i] = 0 as u8; return i } called by 1: route |
| 14 | func r_cpyn(dst: *u8, s: *u8, n: i64) -> i64 { var i: i64 = 0; while i < n { dst[i] = s[i]; i = i + 1 } dst[i] = 0 as u8; return i } called by 1: route |
| 15 | func r_ends(s: *u8, suf: *u8) -> i64 { let ls: i64 = r_len(s); let lf: i64 = r_len(suf); if lf > ls { return 0 } var i: i64 = 0; while i < lf { if s[ls-lf+i] != suf[i] { return 0 } i = i + 1 } return 1 } |
| 16 | func r_dotdot(s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { if s[i] == (46 as u8) { if s[i+1] == (46 as u8) { return 1 } } i = i + 1 } return 0 } called by 1: route |
| 18 | func r_find(hay: *u8, needle: *u8) -> i64 |
| 25 | func r_mem(manifest: *u8, entry: *u8) -> i64 |
| 32 | func route(path: *u8, manifest: *u8, out: *u8) -> i64 |