code wiki / (root) / nx_fetch_jellyfin_test.nx

nx_fetch_jellyfin_test.nx source

↩ module page · 116 lines · 4547 B

1// nx_fetch_jellyfin_test.nx -- X-CENSUS-003 live-incumbent-surface fetch. 2// Sovereign HTTPS fetch of the LIVE Jellyfin incumbent surface (the most- 3// named competitor in media_incumbent_ref.tsv), so the competitive census 4// can be SOURCED against the competitor's own published page instead of a 5// static hand-authored union. No Playwright/curl/node. Saves the raw 6// response to knowledge/fetched/jellyfin_sovereign.raw. 7// expect_exit: 0 license_tier: ORIGINAL 8 9import "nx_syscalls.nx" 10import "nx_x509_trust_store.nx" 11import "nx_trust_store_load_from_certdata.nx" 12import "nx_tls13_client_validate_certificate.nx" 13import "nx_tls13_client_session_run.nx" 14import "nx_https_url_for_fetch.nx" 15import "nx_https_url_connect.nx" 16import "nx_https_get.nx" 17import "nx_https_get_complete.nx" 18import "nx_http_response_parse.nx" 19 20func dump_dec(label0: i64, label1: i64, v: i64) -> i64 { 21 let lab: *u8 = sys_mmap(8) 22 lab[0] = label0 as u8; lab[1] = label1 as u8; lab[2] = 0x3D 23 sys_write(2, lab, 3) 24 var av: i64 = v 25 if av < 0 { let neg: *u8 = sys_mmap(8); neg[0]=0x2D; sys_write(2, neg, 1); av = 0 - av } 26 if av == 0 { let z: *u8 = sys_mmap(8); z[0]=0x30; sys_write(2, z, 1) } 27 else { 28 let buf: *u8 = sys_mmap(16) 29 var pos: i64 = 0 30 var x: i64 = av 31 while x > 0 { buf[pos] = (0x30 + (x % 10)) as u8; x = x / 10; pos = pos + 1 } 32 let out: *u8 = sys_mmap(16) 33 var oi: i64 = 0 34 while oi < pos { out[oi] = buf[pos - 1 - oi]; oi = oi + 1 } 35 sys_write(2, out, pos) 36 } 37 let nl: *u8 = sys_mmap(8); nl[0]=0x0A; sys_write(2, nl, 1) 38 return 0 39} 40 41func main() -> i64 { 42 let cpath: *u8 = "/tmp/mozilla_certdata.txt\x00" 43 let r: i64 = nx_trust_store_load_from_certdata(cpath, 512, 4194304) 44 dump_dec(0x4C, 0x4F, r) // LO= 45 if r <= 0 { return 1 } 46 let store: *TrustStore = r as *TrustStore 47 let n: i64 = trust_store_count(store) 48 dump_dec(0x43, 0x41, n) // CA= 49 if n < 50 { return 3 } 50 51 // X-BROWSE-SOV-001: jellyfin.org is a JS SPA (586KB HTML -> 3645B text shell only). 52 // Sovereign-browse strategy = STATIC LIBRARY-MIRROR (Wikipedia), NOT a JS engine. 53 let url: *u8 = "https://en.wikipedia.org/wiki/Jellyfin\x00" 54 55 let cr: *u8 = sys_mmap(32) 56 var i: i64 = 0 57 while i < 32 { cr[i] = (0xC0 + i) as u8; i = i + 1 } 58 let priv: *u8 = sys_mmap(32) 59 i = 0 60 while i < 32 { priv[i] = (0xA0 + i) as u8; i = i + 1 } 61 62 let url_p: *NxUrl = nx_url_new() 63 let target_raw: *u8 = sys_mmap(32) 64 let target: *NxHttpsTarget = target_raw as *NxHttpsTarget 65 target.url = url_p 66 target.port = 0 67 if nx_https_url_for_fetch(url, target) != NX_HTTPS_URL_OK { return 41 } 68 69 let fd_p: *i64 = sys_mmap(16) as *i64 70 if nx_https_url_connect(target, url, sys_now_realtime_sec(), fd_p) != NX_HTTPS_CONNECT_OK { return 42 } 71 let fd: i64 = *fd_p 72 73 let val_ctx_raw: *u8 = sys_mmap(64) 74 let val_ctx: *TlsValidationContext = val_ctx_raw as *TlsValidationContext 75 val_ctx.store = store 76 val_ctx.sni_host = url + target.url.host_off 77 val_ctx.sni_host_len = target.url.host_len 78 val_ctx.now_epoch = sys_now_realtime_sec() 79 80 let sr: i64 = nx_tls13_client_session_run( 81 fd, url + target.url.host_off, target.url.host_len, 82 cr, priv, val_ctx 83 ) 84 dump_dec(0x53, 0x52, sr) // SR= 85 if sr <= 0 { sys_close(fd); return 200 + (0 - sr) } 86 87 let session: *Tls13ClientSession = sr as *Tls13ClientSession 88 let buf: *u8 = sys_mmap(2097152) 89 let path: *u8 = "/wiki/Jellyfin\x00" 90 let gc: i64 = nx_https_get_complete( 91 session, fd, path, 14, 92 url + target.url.host_off, target.url.host_len, 93 buf, 2097152 94 ) 95 sys_close(fd) 96 dump_dec(0x47, 0x43, gc) // GC= 97 if gc < 0 { return 100 + (0 - gc) } 98 99 let rs: *i64 = sys_mmap(128) as *i64 100 let pv: i64 = nx_http_response_parse(buf, gc, rs) 101 dump_dec(0x50, 0x56, pv) // PV= 102 let status: i64 = rs[1] 103 dump_dec(0x53, 0x54, status) // ST= 104 105 let ofd: i64 = sys_openat_wr("knowledge/fetched/jellyfin_sovereign.raw\x00" as *u8, 0x1A4) 106 if ofd <= 0 { return 70 } 107 sys_write(ofd, buf, gc) 108 sys_close(ofd) 109 110 let banner: *u8 = "JELLYFIN-SOVEREIGN-FETCH-OK\n\x00" 111 var bi: i64 = 0 112 while banner[bi] != (0 as u8) { bi = bi + 1 } 113 sys_write(1, banner, bi) 114 if status != 200 { return 51 } 115 return 0 116}