code wiki / (root) / nx_doc_serve.nx

nx_doc_serve.nx

buildroot/runtime/nx_doc_serve.nx

6317 B147 linesdepth 2pulls 2 transitivereach 9 importersview sourcekind librarytopic doc
docsdependenciesstructsconstsfunctions

about

nx_doc_serve.nx -- LEGAL RUNG D3: open-the-document-in-the-app-of-choice. module: nishi-core.legal.doc_serve capability: LEGAL_DOC_SERVE Serves a stored document's ORIGINAL bytes so a client can open it in the app of their choice -- inline in the browser (PDF/HTML/text) or downloaded to open in a desktop app (Word/etc). A pure bytes-in/bytes-out HTTP response builder (the proven nx_status_daemon handler pattern): a thin socket loop can wrap it, but the logic + the gate need no socket. The s-class properties (each tested with a negative control in the gate): BYTE-EXACT INTEGRITY -- the served body is bit-identical to the stored bytes. For a legal instrument a single altered byte is a DIFFERENT document, so the body is Content- Length framed (never transcoded, never delimiter- scanned); a body that itself contains CRLFCRLF / NUL round-trips exactly. HEADER-INJECTION SAFE -- the attachment filename is sanitized (control chars stripped) so a malicious "name\r\nSet-Cookie: ..." cannot inject a response header. SAFE-BY-DEFAULT TYPE -- unknown formats are downloaded as octet-stream (never inlined), and X-Content-Type-Options: nosniff stops the browser MIME-sniffing a legal document. PER-TENANT -- the serve layer reads only from the tenant's vault prefix (nx_vault_valid_tid -- no cross-tenant). Composes: nx_doc_vault (D1 tenant-id discipline). license_tier: ORIGINAL lineage_id: nishi_doc_serve_d3

dependencies 1 imports · 6 importers

nx_syscalls.nx nx_doc_serve.nx nx_doc_serve_gate.nx nx_legal_blob_gate.nx nx_legal_portal.nx nx_legal_portal_daemon.nx nx_legal_portal_gate.nx nx_legal_portal_live_gate.nx

imports: nx_syscalls.nx

imported by: nx_doc_serve_gate.nxnx_legal_blob_gate.nxnx_legal_portal.nxnx_legal_portal_daemon.nxnx_legal_portal_gate.nxnx_legal_portal_live_gate.nx

structs

none

consts

33const DF_PDF: i64 = 0
34const DF_DOCX: i64 = 1
35const DF_HTML: i64 = 2
36const DF_TXT: i64 = 3
37const DF_NXDOC: i64 = 4 // our own sovereign document format
38const DF_OCTET: i64 = 5 // unknown -> download as octet-stream
41const DISP_INLINE: i64 = 0 // open in the browser
42const DISP_ATTACHMENT: i64 = 1 // download -> open in the app of choice

functions

45func nx_doc_content_type(fmt: i64) -> *u8
57func nx_doc_default_disposition(fmt: i64) -> i64
called by 2: mainlp_handle
63func ds_cat(out: *u8, o: i64, s: *u8) -> i64 { var k: i64 = 0; while s[k] != (0 as u8) { out[o] = s[k]; o = o + 1; k = k + 1 } return o }
64func ds_num(out: *u8, o: i64, v: i64) -> i64
called by 1: nx_doc_serve_response calls 1: sys_mmap
75func nx_doc_serve_response(out: *u8, doc_bytes: *u8, doc_len: i64, fmt: i64,
108func ds_body_off(resp: *u8, n: i64) -> i64
118func nx_doc_serve_roundtrip_ok(resp: *u8, n: i64, orig: *u8, orig_len: i64) -> i64
called by 4: mainmainmainmain calls 1: ds_body_off
131func nx_doc_serve_contains(resp: *u8, n: i64, needle: *u8) -> i64
called by 1: main