/* scorpiox-scorpioplayer-spfs-http-file-server — SPFS HTTP file server (spfss_). * * SCORPIO PLAYER 2027 engine, row 32. Pure C99, zero external deps (vendored yyjson only). * See SPEC.md for every decision (D1..D11) referenced below. * * Process singleton. One server per process. String returns point at static buffers valid * until the next call of the same function: copy them immediately. */ #ifndef SPFSS_H #define SPFSS_H #ifdef _WIN32 # ifdef SPFSS_BUILD # define SPFSS_API __declspec(dllexport) # else # define SPFSS_API __declspec(dllimport) # endif #else # define SPFSS_API __attribute__((visibility("default"))) #endif #ifdef __cplusplus extern "C" { #endif #define SPFSS_OK 0 #define SPFSS_E_ARG (-1) #define SPFSS_E_STATE (-2) #define SPFSS_E_NET (-3) #define SPFSS_E_NOENT (-4) #define SPFSS_E_NOMEM (-5) #define SPFSS_E_LIMIT (-6) #define SPFSS_E_DENIED (-7) #define SPFSS_E_TIMEOUT (-8) /* ---- lifecycle ---- */ SPFSS_API const char *spfss_version(void); /* keys: bind_ip (IPv4 literal of ONE interface; 0.0.0.0 refused), port (default 3321, * 0 = ephemeral), threads (1..16), server_name. NULL value = reset to default. * All before spfss_start. */ SPFSS_API int spfss_config(const char *key, const char *value); SPFSS_API int spfss_start(void); SPFSS_API void spfss_stop(void); SPFSS_API int spfss_is_running(void); SPFSS_API int spfss_port(void); /* the bound port */ /* ---- roots (work before start too; add/remove while running, SPEC D5) ---- */ /* name: 1..128 chars, [A-Za-z0-9._-] (a URL segment); path: folder or single file (D4) */ SPFSS_API int spfss_add_root(const char *name, const char *path); SPFSS_API int spfss_remove_root(const char *name); SPFSS_API int spfss_root_count(void); SPFSS_API const char *spfss_roots_json(void); /* [{"name","path","kind":"file|folder"}] */ /* ---- the change hook (SPEC D11; the host wires the URL, never the engine) ---- */ typedef void (*spfss_change_cb)(const char *name, const char *relpath, void *user); /* cb == NULL clears. Returns the previous registration count (0/1). */ SPFSS_API int spfss_on_change(spfss_change_cb cb, void *user); /* one 30 s-style scan now; fires the callback per root that changed since the last poll */ SPFSS_API void spfss_poll_changes(void); /* ---- pure / socket-free (testable without a server) ---- */ /* the DirectoryBrowser-compatible HTML page of root+rel (SPEC D3/D7); "" + last_error on failure */ SPFSS_API const char *spfss_listing_html(const char *rootname, const char *relpath); /* the row 32/33 JSON page: {"items":[{name,kind,size,mtime_unix,href}],"next":"N"|null} */ SPFSS_API const char *spfss_listing_json(const char *rootname, const char *relpath, int offset, int limit); /* Range header (SPEC D9/D10): 0 = 206 with *a..*b, 1 = no/ignorable header (200 full), * 416 = unsatisfiable (a == -1, the caller answers 416 + Content-Range: bytes star-slash-size), * -1 = malformed (also 416). */ SPFSS_API int spfss_parse_range(const char *hdr, long long size, long long *a, long long *b, int *partial); /* 0 = the relative path is safe to serve, else the HTTP status it maps to (400/404) */ SPFSS_API int spfss_safe_rel(const char *relpath); /* the Content-Type a file is served with (the toolkit's audio/video split + the web table) */ SPFSS_API const char *spfss_mime_for(const char *name); /* the full URL path of one item: "//" percent-encoded */ SPFSS_API const char *spfss_href_for(const char *rootname, const char *relpath, int is_dir); SPFSS_API int spfss_last_code(void); SPFSS_API const char *spfss_last_error(void); #ifdef __cplusplus } #endif #endif /* SPFSS_H */