code wiki / _hdl_build / nx_adnet_catalog.nx
nx_adnet_catalog.nx source
↩ module page · 223 lines · 12368 B
1// nx_adnet_catalog.nx -- GENERATOR: the LIVING ad-real-estate CATALOGUE + sitemap for the sovereign
2// ad network (operator 2026-07-09: "a state of the art catalogue of digital and physical and real
3// estate and apps ... in living documentation and site maps so people can go between them"). LIVING
4// DOCUMENTATION BY CONSTRUCTION: this organ renders the catalogue FROM the same data files the system
5// runs on -- adnet_properties.txt (the property registry) + adnet_inventory.txt (the LIVE serving
6// inventory) -- so re-running it can never disagree with what actually serves. Emits:
7// knowledge/staging/adnet/adnet_catalog.html (human catalogue + cross-navigation)
8// knowledge/staging/adnet/adnet_sitemap.xml (machine sitemap of every catalogued property)
9// The catalogue page deliberately does NOT opt out of the ad slot: it demonstrates the live unit.
10// expect_exit: 0 license_tier: ORIGINAL
11import "nx_syscalls.nx"
12import "_hdl_build/nx_adnet_slot.nx"
13const K_MAGIC_1400: i64 = 1400
14const K_MAGIC_2048: i64 = 2048
15const K_MAGIC_262144: i64 = 262144
16const K_MAGIC_65536: i64 = 65536
17
18func ac_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
19
20func ac_has(hay: *u8, n: i64, needle: *u8) -> i64 {
21 var nl: i64 = 0
22 while needle[nl] != (0 as u8) { nl = nl + 1 }
23 if nl == 0 { return 0 }
24 var i: i64 = 0
25 while i + nl <= n {
26 var j: i64 = 0
27 var eq: i64 = 1
28 while j < nl { if hay[i + j] != needle[j] { eq = 0; break } j = j + 1 }
29 if eq == 1 { return 1 }
30 i = i + 1
31 }
32 return 0
33}
34
35// render one property-registry section (rows whose kind field matches) as table rows.
36func ac_section(reg: *u8, rn: i64, kind: *u8, out: *u8, o0: i64, cap: i64) -> i64 {
37 var o: i64 = o0
38 let f0: *u8 = sys_mmap(64)
39 let f1: *u8 = sys_mmap(256)
40 let f2: *u8 = sys_mmap(512)
41 let f3: *u8 = sys_mmap(64)
42 let f4: *u8 = sys_mmap(512)
43 var ls: i64 = 0
44 while ls < rn {
45 let le: i64 = ad_eol(reg, ls, rn)
46 if le > ls {
47 if le - ls < K_MAGIC_1400 {
48 let row: *u8 = ((reg as i64) + ls) as *u8
49 aslot_field_b(row, le - ls, 0, f0, 64)
50 if ad_streq(f0, kind) == 1 {
51 if o + K_MAGIC_2048 >= cap { return o }
52 aslot_field_b(row, le - ls, 1, f1, 256)
53 aslot_field_b(row, le - ls, 2, f2, 512)
54 aslot_field_b(row, le - ls, 3, f3, 64)
55 aslot_field_b(row, le - ls, 4, f4, 512)
56 o = ad_cat(out, o, "<tr><td><a href=\"" as *u8)
57 o = aslot_cat_esc(out, o, f2, cap)
58 o = ad_cat(out, o, "\">" as *u8)
59 o = aslot_cat_esc(out, o, f1, cap)
60 o = ad_cat(out, o, "</a></td><td><code>" as *u8)
61 o = aslot_cat_esc(out, o, f2, cap)
62 o = ad_cat(out, o, "</code></td><td><span class=\"b b-" as *u8)
63 o = aslot_cat_esc(out, o, f3, cap)
64 o = ad_cat(out, o, "\">" as *u8)
65 o = aslot_cat_esc(out, o, f3, cap)
66 o = ad_cat(out, o, "</span></td><td>" as *u8)
67 o = aslot_cat_esc(out, o, f4, cap)
68 o = ad_cat(out, o, "</td></tr>" as *u8)
69 }
70 }
71 }
72 ls = le + 1
73 }
74 return o
75}
76
77// sitemap <url> rows for every property whose url is site-relative (starts '/').
78func ac_sitemap(reg: *u8, rn: i64, out: *u8, cap: i64) -> i64 {
79 var o: i64 = 0
80 o = ad_cat(out, o, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n" as *u8)
81 let f2: *u8 = sys_mmap(512)
82 var ls: i64 = 0
83 while ls < rn {
84 let le: i64 = ad_eol(reg, ls, rn)
85 if le > ls {
86 if le - ls < K_MAGIC_1400 {
87 let row: *u8 = ((reg as i64) + ls) as *u8
88 aslot_field_b(row, le - ls, 2, f2, 512)
89 if f2[0] == (47 as u8) {
90 if o + 512 >= cap { return o }
91 o = ad_cat(out, o, "<url><loc>https://nishifamily.com" as *u8)
92 o = aslot_cat_esc(out, o, f2, cap)
93 o = ad_cat(out, o, "</loc></url>\n" as *u8)
94 }
95 }
96 }
97 ls = le + 1
98 }
99 o = ad_cat(out, o, "</urlset>\n" as *u8)
100 return o
101}
102
103// current LIVE inventory table (rendered from the exact file the daemon serves from).
104func ac_inventory(inv: *u8, iln: i64, out: *u8, o0: i64, cap: i64) -> i64 {
105 var o: i64 = o0
106 let id: *u8 = sys_mmap(128)
107 let adv: *u8 = sys_mmap(256)
108 let img: *u8 = sys_mmap(512)
109 let clk: *u8 = sys_mmap(512)
110 let sec: *u8 = sys_mmap(128)
111 var ls: i64 = 0
112 while ls < iln {
113 let le: i64 = ad_eol(inv, ls, iln)
114 if le > ls {
115 if le - ls < K_MAGIC_1400 {
116 let row: *u8 = ((inv as i64) + ls) as *u8
117 if row[0] != (64 as u8) {
118 aslot_field_b(row, le - ls, 0, id, 128)
119 if aslot_id_ok(id) == 1 {
120 if o + K_MAGIC_2048 >= cap { return o }
121 aslot_field_b(row, le - ls, 1, adv, 256)
122 aslot_field_b(row, le - ls, 2, img, 512)
123 aslot_field_b(row, le - ls, 3, clk, 512)
124 aslot_field_b(row, le - ls, 4, sec, 128)
125 o = ad_cat(out, o, "<tr><td><code>" as *u8)
126 o = ad_cat(out, o, id)
127 o = ad_cat(out, o, "</code></td><td>" as *u8)
128 o = aslot_cat_esc(out, o, adv, cap)
129 o = ad_cat(out, o, "</td><td>" as *u8)
130 o = aslot_cat_esc(out, o, sec, cap)
131 o = ad_cat(out, o, "</td><td><a href=\"" as *u8)
132 o = aslot_cat_esc(out, o, img, cap)
133 o = ad_cat(out, o, "\">creative</a></td><td><code>" as *u8)
134 o = aslot_cat_esc(out, o, clk, cap)
135 o = ad_cat(out, o, "</code></td></tr>" as *u8)
136 }
137 }
138 }
139 }
140 ls = le + 1
141 }
142 return o
143}
144
145func ac_wfile(path: *u8, buf: *u8, n: i64) -> i64 {
146 let fd: i64 = sys_openat_wr(path, 0x1A4)
147 if fd < 0 { return 0 }
148 let wr: i64 = sys_write(fd, buf, n)
149 sys_close(fd)
150 if wr != n { return 0 }
151 return 1
152}
153
154func main() -> i64 {
155 let rbox: *i64 = (sys_mmap(8)) as *i64
156 rbox[0] = 0
157 let reg: *u8 = sys_read_file("knowledge/staging/adnet/adnet_properties.txt" as *u8, rbox)
158 let rn: i64 = rbox[0]
159 if (reg as i64) == 0 { ac_puts("CATALOG RED: no property registry\n" as *u8); sys_exit(1); return 1 }
160 let ibox: *i64 = (sys_mmap(8)) as *i64
161 ibox[0] = 0
162 let inv: *u8 = sys_read_file("knowledge/staging/adnet/adnet_inventory.txt" as *u8, ibox)
163 let iln: i64 = ibox[0]
164 if (inv as i64) == 0 { ac_puts("CATALOG RED: no inventory\n" as *u8); sys_exit(1); return 1 }
165
166 let cap: i64 = K_MAGIC_262144
167 let out: *u8 = sys_mmap(cap)
168 var o: i64 = 0
169 o = ad_cat(out, o, "<html><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>Nishi Ad Real Estate - Living Catalogue</title>" as *u8)
170 o = ad_cat(out, o, "<style>body{font-family:system-ui,sans-serif;max-width:960px;margin:4vh auto;padding:0 20px;line-height:1.55;color:var(--fg,black)}table{border-collapse:collapse;width:100%;margin:10px 0 26px}td,th{border:1px solid gray;padding:6px 10px;text-align:left;font-size:.92rem;vertical-align:top}th{background:silver}h2{margin-top:2rem}code{background:gainsboro;padding:1px 5px;border-radius:3px;font-size:.85em}.b{padding:2px 8px;border-radius:10px;font-size:.78rem;font-weight:600;color:white}.b-slot{background:seagreen}.b-gated{background:slategray}.b-policy-off{background:darkgoldenrod}.b-physical-planned{background:steelblue}.nav a{margin-right:16px}</style></head><body>" as *u8)
171 o = ad_cat(out, o, "<h1>Nishi Ad Real Estate - Living Catalogue</h1>" as *u8)
172 o = ad_cat(out, o, "<p>Every property in the Nishi ecosystem, its ad real estate status, and how to navigate between them. LIVING DOCUMENTATION: this page is generated by <code>nx_adnet_catalog</code> from the property registry and the LIVE serving inventory - regenerate to refresh, never hand-edit. One labeled slot per page, first-party only, zero third-party JS, no visitor identity.</p>" as *u8)
173 o = ad_cat(out, o, "<p class=\"nav\"><a href=\"/\">Home</a><a href=\"/synth/adnet_sitemap.xml\">sitemap.xml</a><a href=\"/synth/adnet_inventory.txt\">live inventory</a><a href=\"/compare\">compare plane</a><a href=\"/status.html\">live status</a></p>" as *u8)
174
175 o = ad_cat(out, o, "<h2>Digital properties</h2><table><tr><th>property</th><th>url</th><th>ad real estate</th><th>about</th></tr>" as *u8)
176 o = ac_section(reg, rn, "digital" as *u8, out, o, cap)
177 o = ad_cat(out, o, "</table><h2>Apps</h2><table><tr><th>app</th><th>url</th><th>ad real estate</th><th>about</th></tr>" as *u8)
178 o = ac_section(reg, rn, "app" as *u8, out, o, cap)
179 o = ad_cat(out, o, "</table><h2>Gated (members) surfaces</h2><table><tr><th>surface</th><th>url</th><th>ad real estate</th><th>about</th></tr>" as *u8)
180 o = ac_section(reg, rn, "gated" as *u8, out, o, cap)
181 o = ad_cat(out, o, "</table><h2>External properties</h2><table><tr><th>property</th><th>url</th><th>ad real estate</th><th>about</th></tr>" as *u8)
182 o = ac_section(reg, rn, "external" as *u8, out, o, cap)
183 o = ad_cat(out, o, "</table><h2>Physical real estate</h2><table><tr><th>medium</th><th>lane</th><th>ad real estate</th><th>about</th></tr>" as *u8)
184 o = ac_section(reg, rn, "physical" as *u8, out, o, cap)
185
186 o = ad_cat(out, o, "</table><h2>Current live inventory</h2><p>Rendered from the exact file the edge serves ads from (<a href=\"/synth/adnet_inventory.txt\">adnet_inventory.txt</a>). Click counters are per-AD only.</p><table><tr><th>id</th><th>advertiser</th><th>section</th><th>creative</th><th>click target</th></tr>" as *u8)
187 o = ac_inventory(inv, iln, out, o, cap)
188 o = ad_cat(out, o, "</table><p>Slot mechanics: every served HTML page on an ad-enabled host carries ONE labeled slot injected before its closing body tag (a page can refuse via the page-level opt-out marker; gated surfaces never carry ads). Self-serve intake and CPM/CPC billing are gated organs: <code>nx_adnet_selfserve</code> - <code>nx_adnet_bill</code> - <code>nx_adnet_dash</code>.</p>" as *u8)
189 o = ad_cat(out, o, "<p>Generated by the sovereign stack - no third-party web server, TLS 1.3 bits-up.</p></body></html>" as *u8)
190
191 let smap: *u8 = sys_mmap(K_MAGIC_65536)
192 let sn: i64 = ac_sitemap(reg, rn, smap, K_MAGIC_65536)
193
194 var ok: i64 = 0
195 ok = ok + ac_wfile("knowledge/staging/adnet/adnet_catalog.html" as *u8, out, o)
196 ok = ok + ac_wfile("knowledge/staging/adnet/adnet_sitemap.xml" as *u8, smap, sn)
197
198 // self-verify: read back + every kind section present + a known property + sitemap wellformed
199 var good: i64 = 1
200 let vbox: *i64 = (sys_mmap(8)) as *i64
201 vbox[0] = 0
202 let vc: *u8 = sys_read_file("knowledge/staging/adnet/adnet_catalog.html" as *u8, vbox)
203 if (vc as i64) == 0 { good = 0 } else {
204 if ac_has(vc, vbox[0], "Nishi Torrent" as *u8) == 0 { good = 0 }
205 if ac_has(vc, vbox[0], "Physical real estate" as *u8) == 0 { good = 0 }
206 if ac_has(vc, vbox[0], "Explode Lab" as *u8) == 0 { good = 0 }
207 if ac_has(vc, vbox[0], "ha-torrent" as *u8) == 0 { good = 0 }
208 if ac_has(vc, vbox[0], "<script" as *u8) == 1 { good = 0 }
209 }
210 let sbox: *i64 = (sys_mmap(8)) as *i64
211 sbox[0] = 0
212 let sv: *u8 = sys_read_file("knowledge/staging/adnet/adnet_sitemap.xml" as *u8, sbox)
213 if (sv as i64) == 0 { good = 0 } else {
214 if ac_has(sv, sbox[0], "</urlset>" as *u8) == 0 { good = 0 }
215 if ac_has(sv, sbox[0], "https://nishifamily.com/torrent" as *u8) == 0 { good = 0 }
216 }
217 if ok != 2 { good = 0 }
218
219 if good == 1 { ac_puts("ADNET-CATALOG verdict=GREEN (catalog.html + sitemap.xml emitted + verified)\n" as *u8); sys_exit(0); return 0 }
220 ac_puts("ADNET-CATALOG verdict=RED\n" as *u8)
221 sys_exit(1)
222 return 1
223}