nx_print_validate.nx source
↩ module page · 58 lines · 2750 B
1// nx_print_validate.nx -- LIVE, SAFE proof of the submission path. Sends a Validate-Job for an image/urf
2// document to the real Brother and reports whether it WOULD accept the job. Prints NOTHING -- no paper,
3// no toner consumed (Validate-Job per RFC 8011 4.2.3). This is the safe acceptance test for the whole
4// rasterize->submit pipeline before any physical Print-Job. READ-ONLY -> never-brick. license_tier: ORIGINAL
5
6import "nx_syscalls.nx"
7import "nx_ipp_codec.nx"
8import "nx_ipp_transport.nx"
9import "nx_ipp_submit.nx"
10const K_MAGIC_2048: i64 = 2048
11const K_MAGIC_131072: i64 = 131072
12
13func p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
14func pn(v: i64) -> i64 {
15 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
16 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
17 let t: *u8 = sys_mmap(24); var k: i64 = 0
18 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
19 let b: *u8 = sys_mmap(24); var i: i64 = 0
20 while i < k { b[i] = t[k - 1 - i]; i = i + 1 }
21 sys_write(1, b, k); return 0
22}
23func phex16(v: i64) -> i64 {
24 let hx: *u8 = "0123456789abcdef"; var sh: i64 = 12
25 while sh >= 0 { sys_write(1, ((hx as i64) + ((v >> sh) & 0xf)) as *u8, 1); sh = sh - 4 }
26 return 0
27}
28
29func main() -> i64 {
30 let a: i64 = 192
31 let b: i64 = 168
32 let c: i64 = 8
33 let d: i64 = 127
34 p("=== VALIDATE-JOB (safe: prints nothing) -- can our sovereign URF be printed? ===\n")
35
36 let req: *u8 = sys_mmap(K_MAGIC_2048)
37 let rlen: i64 = nx_ipp_build_validate_job(req, a, b, c, d, "/ipp/print", "nishi", "nishi-urf-validate", "image/urf")
38
39 let resp: *u8 = sys_mmap(K_MAGIC_131072)
40 let body: *u8 = sys_mmap(K_MAGIC_131072)
41 let out2: *i64 = sys_mmap(16) as *i64
42 var v: i64 = nx_ipt_post_ipp(a, b, c, d, 631, "/ipp/print", req, rlen, resp, K_MAGIC_131072, body, K_MAGIC_131072, 6, out2)
43 if v != NX_IPT_OK {
44 // retry alternate path
45 v = nx_ipt_post_ipp(a, b, c, d, 631, "/ipp/port1", req, rlen, resp, K_MAGIC_131072, body, K_MAGIC_131072, 6, out2)
46 }
47 p("transport="); p(nx_ipt_verdict_name(v)); p(" http="); pn(out2[0]); p(" ipp_body="); pn(out2[1]); p("\n")
48 if v != NX_IPT_OK { p("RESULT: no clean response (reported, not swallowed).\n"); sys_exit(1); return 1 }
49
50 let st: i64 = nx_ipp_status(body)
51 p("ipp_status=0x"); phex16(st); p(" -> ")
52 if st == NX_IPP_STATUS_OK { p("successful-ok: the Brother WOULD ACCEPT our sovereign image/urf job.\n") }
53 else {
54 if st == 0x040b { p("client-error-document-format-not-supported (it rejected image/urf).\n") }
55 else { p("non-OK status (see code above) -- honestly reported.\n") }
56 }
57 sys_exit(0); return 0
58}