code wiki / (root) / nx_page_dump.nx

nx_page_dump.nx source

↩ module page · 45 lines · 1932 B

1// nx_page_dump.nx -- fetch a few live pages over our sovereign TLS and print 2// the head of each body, so we can see the CURRENT /login, /hub, /video 3// content + style + the real area URLs before rebuilding the hub. Read-only. 4 5import "nx_syscalls.nx" 6import "nx_x509_trust_store.nx" 7import "nx_trust_store_load_from_certdata.nx" 8import "nx_https_fetch_follow.nx" 9const K_MAGIC_4194304: i64 = 4194304 10const K_MAGIC_1400: i64 = 1400 11 12func vp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 13func vpn(v: i64) -> i64 { 14 let b: *u8=sys_mmap(28); var x: i64=v; if x<0 {b[0]=45;sys_write(1,b,1);x=0-x} 15 if x==0 {b[0]=48;sys_write(1,b,1);return 0} 16 var d: i64=0; var y: i64=x; while y>0 {d=d+1;y=y/10} 17 var i: i64=d-1; y=x; while i>=0 {b[i]=(48+(y%10)) as u8; y=y/10; i=i-1} 18 sys_write(1,b,d); return 0 19} 20 21func dump(url: *u8, store: *TrustStore, out: *u8, cap: i64, maxprint: i64) -> i64 { 22 let status: *i64 = sys_mmap(8) as *i64 23 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 24 vp("\n===== " as *u8); vp(url); vp(" (status=" as *u8); vpn(status[0]); vp(" bytes=" as *u8); vpn(n); vp(") =====\n" as *u8) 25 if n > 0 { 26 var p: i64 = n 27 if p > maxprint { p = maxprint } 28 sys_write(1, out, p) 29 vp("\n----- [head truncated] -----\n" as *u8) 30 } 31 return 0 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 { vp("certdata load failed\n" as *u8); return 1 } 37 let store: *TrustStore = r as *TrustStore 38 let cap: i64 = K_MAGIC_4194304 39 let out: *u8 = sys_mmap(cap) 40 41 dump("https://nishifamily.com/login" as *u8, store, out, cap, K_MAGIC_1400) 42 dump("https://nishifamily.com/hub" as *u8, store, out, cap, K_MAGIC_1400) 43 dump("https://nishifamily.com/video/" as *u8, store, out, cap, K_MAGIC_1400) 44 return 0 45}