code wiki / (root) / nx_recycler_critique_fetch.nx

nx_recycler_critique_fetch.nx source

↩ module page · 53 lines · 3697 B

1// nx_recycler_critique_fetch.nx -- R5 intake: extend the recycler from security CVEs to the broader CRITIQUES / 2// negative-statements of other systems (the literal Amazon-Basics move: mine what people complain about in competing 3// products). It fetches real, documented critique-CLASS pages (Wikipedia, the allowed source) -- each a well-known 4// complaint about OTHER languages/runtimes that maps to a Nishi design decision: undefined behavior, (lack of) memory 5// safety, dependency hell, software bloat, garbage-collection pauses. Saved sovereignly to knowledge/fetched/ 6// recyc_crit_*.raw so every critique EXISTS SEPARATE as a real artifact (rule 4). Idempotent. expect_exit: 0 ORIGINAL 7import "nx_syscalls.nx" 8import "nx_x509_trust_store.nx" 9import "nx_trust_store_load_from_certdata.nx" 10import "nx_https_fetch_follow.nx" 11const K_MAGIC_4194304: i64 = 4194304 12const K_MAGIC_8388608: i64 = 8388608 13 14func gf_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 15func gf_putn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let d: *u8=sys_mmap(24); var k: i64=0; while m>0 { d[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } var i: i64=k-1; while i>=0 { let o: *u8=sys_mmap(1); o[0]=d[i]; sys_write(1,o,1); i=i-1 } return 0 } 16func have_file(path: *u8) -> i64 { let fd: i64=sys_openat_rd(path); if fd<0 { return 0 } sys_close(fd); return 1 } 17 18func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 19 if have_file(opath)==1 { gf_puts(opath); gf_puts(" [have-skip]\n" as *u8); return 1 } 20 let status: *i64 = sys_mmap(8) as *i64 21 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 22 gf_puts(url); gf_puts(" status=" as *u8); gf_putn(status[0]); gf_puts(" bytes=" as *u8); gf_putn(n) 23 if n<=0 { gf_puts(" FETCH-FAIL\n" as *u8); return 0 } 24 var gz: i64=0 25 if n>=2 { if out[0]==0x1f as u8 { if out[1]==0x8b as u8 { gz=1 } } } 26 if gz==1 { gf_puts(" [GZIP-skip]\n" as *u8); return 0 } 27 let fd: i64=sys_openat_wr(opath, 0x1a4) 28 if fd<0 { gf_puts(" SAVE-FAIL\n" as *u8); return 0 } 29 sys_write(fd, out, n); sys_close(fd) 30 gf_puts(" SAVED\n" as *u8) 31 return 1 32} 33 34func main() -> i64 { 35 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 36 if r<=0 { gf_puts("CRIT: certdata load failed\n" as *u8); return 1 } 37 let store: *TrustStore = r as *TrustStore 38 gf_puts("CA roots=" as *u8); gf_putn(trust_store_count(store)); gf_puts("\n" as *u8) 39 let cap: i64 = K_MAGIC_8388608 40 let out: *u8 = sys_mmap(cap) 41 var ok: i64 = 0 42 43 gf_puts("== RECYCLER R5 INTAKE: critique-classes of OTHER systems (mine complaints -> our differentiation) ==\n" as *u8) 44 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Undefined_behavior" as *u8, "knowledge/fetched/recyc_crit_ub.raw" as *u8, store, out, cap) 45 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Memory_safety" as *u8, "knowledge/fetched/recyc_crit_memsafety.raw" as *u8, store, out, cap) 46 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Dependency_hell" as *u8, "knowledge/fetched/recyc_crit_dephell.raw" as *u8, store, out, cap) 47 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Software_bloat" as *u8, "knowledge/fetched/recyc_crit_bloat.raw" as *u8, store, out, cap) 48 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)" as *u8, "knowledge/fetched/recyc_crit_gc.raw" as *u8, store, out, cap) 49 50 gf_puts("RECYCLER-CRIT-INTAKE sources_ok=" as *u8); gf_putn(ok); gf_puts("/5\n" as *u8) 51 if ok>=1 { return 0 } 52 return 1 53}