code wiki / (root) / nx_archive_site_viewer.nx

nx_archive_site_viewer.nx

buildroot/runtime/nx_archive_site_viewer.nx

18221 B224 linesdepth 21pulls 147 transitivereach 0 importersview sourcekind tooltopic archive
docsdependenciesstructsconstsfunctions

about

nx_archive_site_viewer.nx -- DOMAIN-GENERAL time-machine viewer with LOCAL MEDIA (no broken images). Reads the target host from web_assets/archive/_target.txt (default page3.com), fetches its Wayback CDX, picks the EARLIEST status-200 capture, reconstructs it from the capture's OWN original URL, then FETCHES every referenced image from the archive, stores them under web_assets/archive/<host>/media/, and rewrites the page's <img src> to those local copies (transparent-pixel placeholder for any image the archive doesn't have -> never a broken icon). Output: web_assets/archive/<host>/{index.html,page.html,media/*}. Served by nx_archive_server. Fetch stack, cache-first, status-aware retry. license_tier: ORIGINAL

dependencies 5 imports · 0 importers

nx_syscalls.nx nx_x509_trust_store.nx nx_trust_store_load_from_certdata. nx_https_fetch_follow.nx nx_cdx_parse.nx nx_archive_site_viewer.nx

imports: nx_syscalls.nxnx_x509_trust_store.nxnx_trust_store_load_from_certdata.nxnx_https_fetch_follow.nxnx_cdx_parse.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main gw sys_write sys_mkdir sys_mmap read_file sys_openat_rd sys_read sys_close ap mkpath ap ↻ nx_trust_store_load_from_c sys_mmap ↻ sys_read_file sys_openat_rd ↻ sys_lseek sys_mmap ↻ sys_read ↻ sys_close ↻ nx_nss_certdata_parse sys_mmap ↻ _pat_class_cert _pat_value_octal _pat_end _find_newline _starts_with _parse_octal_line sys_mmap ↻ _is_space _decode_octal_escape _is_octal trust_store_alloc sys_mmap ↻ nx_x509_trust_store_load sys_mmap ↻ x509_parse sys_mmap ↻ asn1_cursor_init asn1_expect_tag

structs

none

consts

13const K_MAGIC_4194304: i64 = 4194304
14const K_MAGIC_1024: i64 = 1024
15const K_MAGIC_4096: i64 = 4096
16const K_MAGIC_2048: i64 = 2048
17const K_MAGIC_65536: i64 = 65536

functions

19func gw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
20func gn(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 t: *u8=sys_mmap(24); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } let o: *u8=sys_mmap(24); var w: i64=0; var q: i64=k-1; while q>=0 { o[w]=t[q]; w=w+1; q=q-1 } sys_write(1,o,w); return 0 }
called by 1: main calls 2: sys_writesys_mmap
21func ap(buf: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8) { buf[off+i]=s[i]; i=i+1 } return off+i }
called by 3: esc_htmlmkpathmain
22func apn(buf: *u8, off: i64, v: i64) -> i64 { if v==0 { buf[off]=0x30 as u8; return off+1 } var m: i64=v; if m<0 { buf[off]=0x2d as u8; off=off+1; m=0-m } let t: *u8=sys_mmap(24); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } var o: i64=off; var q: i64=k-1; while q>=0 { buf[o]=t[q]; o=o+1; q=q-1 } return o }
called by 1: main calls 1: sys_mmap
23func apslice(dst: *u8, off: i64, src: *u8, so: i64, sl: i64) -> i64 { var i: i64=0; while i<sl { dst[off+i]=src[so+i]; i=i+1 } return off+sl }
called by 1: main
24func dstarts(buf: *u8, off: i64, n: i64, lit: *u8, litlen: i64) -> i64 { if off+litlen>n { return 0 } var i: i64=0; while i<litlen { var a: i64=buf[off+i] as i64; if a>=0x41 { if a<=0x5a { a=a+0x20 } } if a != (lit[i] as i64) { return 0 } i=i+1 } return 1 }
called by 2: next_imgsrcmain
25func esc_html(dst: *u8, doff: i64, src: *u8, n: i64) -> i64 { var o: i64=doff; var i: i64=0; while i<n { let c: i64=src[i] as i64; if c==0x3c { o=ap(dst,o,"&lt;" as *u8) } else { if c==0x3e { o=ap(dst,o,"&gt;" as *u8) } else { if c==0x26 { o=ap(dst,o,"&amp;" as *u8) } else { dst[o]=c as u8; o=o+1 } } } i=i+1 } return o }
calls 1: ap
26func save_file(path: *u8, buf: *u8, n: i64) -> i64 { let fd: i64=sys_openat_wr(path, 0x1a4); if fd<0 { return 0 } var off: i64=0; while off<n { let w: i64=sys_write(fd, ((buf as i64)+off) as *u8, n-off); if w<=0 { sys_close(fd); return 0 } off=off+w } sys_close(fd); return 1 }
27func read_file(path: *u8, buf: *u8, cap: i64, lenbox: *i64) -> i64 { let fd: i64=sys_openat_rd(path); if fd<0 { return 0 } let n: i64=sys_read(fd, buf, cap); sys_close(fd); if n<=0 { return 0 } lenbox[0]=n; return n }
called by 1: main calls 3: sys_openat_rdsys_readsys_close
28func is_image(buf: *u8, n: i64) -> i64 { if n<4 { return 0 } let a: i64=buf[0] as i64; let b: i64=buf[1] as i64; let c: i64=buf[2] as i64; let d: i64=buf[3] as i64; if a==0x47 { if b==0x49 { if c==0x46 { return 1 } } } if a==0xff { if b==0xd8 { if c==0xff { return 1 } } } if a==0x89 { if b==0x50 { if c==0x4e { if d==0x47 { return 1 } } } } if a==0x42 { if b==0x4d { return 1 } } return 0 }
29func fetch_retry(url: *u8, store: *TrustStore, out: *u8, cap: i64, st: *i64, tries: i64) -> i64 { var t: i64=0; var n: i64=0-1; while t<tries { n=nx_https_fetch_follow(url, store, out, cap, 6, st); if n>0 { if st[0]==200 { t=tries } else { t=t+1 } } else { t=t+1 } } return n }
called by 1: main
30func mkpath(dst: *u8, a: *u8, b: *u8) -> i64 { var o: i64=ap(dst,0,a); o=ap(dst,o,b); dst[o]=0 as u8; return o }
called by 1: main calls 1: ap
31func next_imgsrc(buf: *u8, n: i64, from: i64, out2: *i64) -> i64 { var i: i64=from; while i<n { if dstarts(buf, i, n, "src=" as *u8, 4)==1 { if i+4<n { if (buf[i+4] as i64)==0x22 { let us: i64=i+5; var ue: i64=us; var go: i64=1; while go==1 { if ue<n { if (buf[ue] as i64)==0x22 { go=0 } else { ue=ue+1 } } else { go=0 } } out2[0]=us; out2[1]=ue-us; return ue+1 } } } i=i+1 } return 0-1 }
called by 1: main calls 1: dstarts
33func ext_of(buf: *u8, off: i64, len: i64, extbuf: *u8) -> i64
called by 1: main
42func main() -> i64