nx_iot_hub_serve_gate.nx source
↩ module page · 43 lines · 1856 B
1// nx_iot_hub_serve_gate.nx -- proves the IoT hub server's routing + content logic without binding a
2// socket: path matching (/home/cmd vs other), the html content-type, and that the page it serves is
3// the real zero-JS dashboard with the live devices + resilience promise. expect_exit: 0
4// license_tier: ORIGINAL
5import "nx_iot_hub_serve.nx"
6
7func hg_find(h: *u8, n: i64, pat: *u8) -> i64 {
8 var pl: i64 = 0
9 while pat[pl] != (0 as u8) { pl = pl + 1 }
10 return cp_find(h, n, pat, pl)
11}
12
13func main() -> i64 {
14 // ---- path routing (hub_match) ----
15 let r: *u8 = sys_mmap(64)
16 let s: *u8 = "/home/cmd" as *u8
17 var i: i64 = 0
18 while s[i] != (0 as u8) { r[i] = s[i]; i = i + 1 }
19 if hub_match(r, 0, 9, "/home/cmd" as *u8) != 1 { return 1 } // exact match
20 if hub_match(r, 0, 9, "/other" as *u8) == 1 { return 2 } // non-match
21 // offset match (path inside a larger buffer)
22 let r2: *u8 = sys_mmap(64)
23 let s2: *u8 = "GET /home/cmd HTTP" as *u8
24 i = 0
25 while s2[i] != (0 as u8) { r2[i] = s2[i]; i = i + 1 }
26 if hub_match(r2, 4, 9, "/home/cmd" as *u8) != 1 { return 3 }
27
28 // ---- content type ----
29 let ct: *u8 = sys_mmap(64)
30 let ctn: i64 = hub_ct_html(ct)
31 if ctn != 24 { return 4 }
32 if hg_find(ct, ctn, "text/html" as *u8) < 0 { return 5 }
33
34 // ---- the served page IS the real dashboard ----
35 let page: *u8 = sys_mmap(262144)
36 let pn: i64 = db_render(page)
37 if pn <= 0 { return 6 }
38 if hg_find(page, pn, "<script" as *u8) != (0 - 1) { return 7 } // still zero-JS
39 if hg_find(page, pn, "192.168.10.166" as *u8) < 0 { return 8 } // real device
40 if hg_find(page, pn, "available with internet down" as *u8) < 0 { return 9 } // resilience
41 if hg_find(page, pn, "action=\"/home/cmd\"" as *u8) < 0 { return 10 } // controls route here
42 return 0
43}