nx_printer_conform.nx source
↩ module page · 70 lines · 3958 B
1// nx_printer_conform.nx -- IPP conformance / capability-gap profiler. Surfaces the ACTIONABLE conformance
2// gaps a vendor UI hides: what the printer advertises vs what it actually does. From a Get-Printer-Attributes
3// response it flags four real, actionable gaps:
4// - only-old-IPP (ipp-versions-supported lacks "2.0" -> missing IPP Everywhere features)
5// - no-PDF (document-format-supported lacks application/pdf -> the client MUST rasterize)
6// - duplex-default-waste (sides-supported has two-sided BUT sides-default = one-sided -> silent paper waste)
7// - monochrome (color-supported = false)
8//
9// PURE model (caller-provided scratch, no syscalls) -> never-brick #26 by construction.
10// no_silent_failure: a structurally malformed message yields UNKNOWN (-1), never a confident gap list.
11// Sovereign: imports only nx_ipp_codec. genealogy_id: project-printer-management-ipp-sclass-2026-06-20
12// license_tier: ORIGINAL
13
14import "nx_ipp_codec.nx"
15
16const NX_CONF_GAP_IPP_OLD: i64 = 1 // ipp-versions-supported lacks "2.0"
17const NX_CONF_GAP_NO_PDF: i64 = 2 // document-format-supported lacks application/pdf
18const NX_CONF_GAP_DUPLEX_WASTE: i64 = 4 // sides-supported has two-sided but sides-default = one-sided
19const NX_CONF_GAP_NO_COLOR: i64 = 8 // color-supported = false (monochrome)
20
21// sides-default == "one-sided" ? 1 yes / 0 no / -1 absent. scratch3 = caller i64[3].
22func nx_conf_default_one_sided(buf: *u8, n: i64, scratch3: *i64) -> i64 {
23 let p_tag: *i64 = scratch3
24 let p_voff: *i64 = ((scratch3 as i64) + 8) as *i64
25 let p_vlen: *i64 = ((scratch3 as i64) + 16) as *i64
26 let v: i64 = nx_ipp_find(buf, n, "sides-default" as *u8, p_tag, p_voff, p_vlen)
27 if v != NX_IPP_OK { return 0 - 1 }
28 if p_vlen[0] != 9 { return 0 }
29 return nx_ipp_name_eq(buf, p_voff[0], "one-sided" as *u8, 9)
30}
31
32// color-supported boolean: 1 color / 0 mono / -1 absent. scratch3 = caller i64[3].
33func nx_conf_color(buf: *u8, n: i64, scratch3: *i64) -> i64 {
34 let p_tag: *i64 = scratch3
35 let p_voff: *i64 = ((scratch3 as i64) + 8) as *i64
36 let p_vlen: *i64 = ((scratch3 as i64) + 16) as *i64
37 let v: i64 = nx_ipp_find(buf, n, "color-supported" as *u8, p_tag, p_voff, p_vlen)
38 if v != NX_IPP_OK { return 0 - 1 }
39 if p_tag[0] != NX_IPP_VT_BOOLEAN { return 0 - 1 }
40 if p_vlen[0] != 1 { return 0 - 1 }
41 return buf[p_voff[0]] as i64
42}
43
44// Compute the conformance-gap bitmask. Returns -1 (UNKNOWN) if the message is structurally malformed -- a
45// truncated/overrun response must NOT yield confident "gaps". scratch3 = caller i64[3].
46func nx_conf_gaps(buf: *u8, n: i64, scratch3: *i64) -> i64 {
47 let p_tag: *i64 = scratch3
48 let p_voff: *i64 = ((scratch3 as i64) + 8) as *i64
49 let p_vlen: *i64 = ((scratch3 as i64) + 16) as *i64
50 if nx_ipp_find(buf, n, "printer-state" as *u8, p_tag, p_voff, p_vlen) == NX_IPP_MALFORMED { return 0 - 1 }
51 var gaps: i64 = 0
52 if nx_ipp_set_contains(buf, n, "ipp-versions-supported" as *u8, "2.0" as *u8) == 0 { gaps = gaps | NX_CONF_GAP_IPP_OLD }
53 if nx_ipp_set_contains(buf, n, "document-format-supported" as *u8, "application/pdf" as *u8) == 0 { gaps = gaps | NX_CONF_GAP_NO_PDF }
54 if nx_ipp_set_contains(buf, n, "sides-supported" as *u8, "two-sided-long-edge" as *u8) == 1 {
55 if nx_conf_default_one_sided(buf, n, scratch3) == 1 { gaps = gaps | NX_CONF_GAP_DUPLEX_WASTE }
56 }
57 if nx_conf_color(buf, n, scratch3) == 0 { gaps = gaps | NX_CONF_GAP_NO_COLOR }
58 return gaps
59}
60
61// Number of gaps surfaced (popcount of the 4 flags). Returns -1 if UNKNOWN.
62func nx_conf_gap_count(gaps: i64) -> i64 {
63 if gaps < 0 { return 0 - 1 }
64 var c: i64 = 0
65 if (gaps & NX_CONF_GAP_IPP_OLD) != 0 { c = c + 1 }
66 if (gaps & NX_CONF_GAP_NO_PDF) != 0 { c = c + 1 }
67 if (gaps & NX_CONF_GAP_DUPLEX_WASTE) != 0 { c = c + 1 }
68 if (gaps & NX_CONF_GAP_NO_COLOR) != 0 { c = c + 1 }
69 return c
70}