/* * spfsc.h — scorpiox-scorpioplayer-spfs-http-file-client public API. * * RuntimeType "SPFS": a ScorpioMediaServer HTTP file server (Windows 2.0.0.0, Linux CLI * 3.0.0.0, the row 32 C server) as a read-only media source and a #26 storage backend: * validate (/api/Version), shared roots (/api/Folders keys), directory browsing (row 32 * JSON when the server answers ?format=json, else the ASP.NET DirectoryBrowser HTML) and a * range-readable URL per file for #20 (remote-seek-stream). * * Two faces over the same engine (SPEC.md section 2): * - sprch_get(): the sprch_handler (sprch.h), stateless, settings = legacy RuntimeSettings. * - spfsc_*: a flat, stateful P/Invoke surface. spfsc_validate / spfsc_folders / spfsc_list / * spfsc_parse_listing_html replace "the current listing"; spfsc_item_json(i) reads it. * Single-threaded, like spffa (the handler face is the one to use from several threads). * * Strings returned by spfsc_* are owned by the library and valid until the next call that * replaces them (the same export, or one that replaces the current listing). Copy them. * No returned string ever contains ServerKey or an /api/Folders value. */ #ifndef SPFSC_H #define SPFSC_H #include "sprch.h" #include "scorpiox-http.h" #ifdef __cplusplus extern "C" { #endif #if defined(_WIN32) # if defined(SPFSC_BUILD) # define SPFSC_API __declspec(dllexport) # else # define SPFSC_API __declspec(dllimport) # endif #else # define SPFSC_API __attribute__((visibility("default"))) #endif #define SPFSC_VERSION "1.1.0" #define SPFSC_RUNTIME_TYPE "SPFS" /* ---- pure helpers (no transport, no state beyond the returned string) ---- */ /* ServerUrl + ServerPort + UseHttps -> "http(s)://host:port" (SPEC D1). server_url may be a * bare host, host:port, a full URL (only its host, and its port when port is empty, are kept), * or an IPv6 address with or without brackets. port NULL / "" = not set. NULL when unusable * (spfsc_last_error says why). */ SPFSC_API const char *spfsc_full_url(const char *server_url, const char *port, int use_https); /* Culture-free size cell: "1,234" "1.234" "1 234" "12,34,567" -> 1234...; -1 = not a size. */ SPFSC_API long long spfsc_parse_size(const char *s); /* Date cell -> Unix seconds UTC. -1 = not a date, -2 = numeric day/month order undecidable * from this string alone (every number <= 12, '/' separated): see spfsc_parse_mtime_order. */ SPFSC_API long long spfsc_parse_mtime(const char *s); /* order: "dmy" or "mdy" decides a day/month pair; anything else behaves like spfsc_parse_mtime. */ SPFSC_API long long spfsc_parse_mtime_order(const char *s, const char *order); /* Parse one DirectoryBrowser (or nginx / Apache) page offline; items as spfsc_list gives them * with folder "" and the page URL as the directory. Count, or a negative SPRCH_E_*. */ SPFSC_API int spfsc_parse_listing_html(const char *html, const char *page_url); /* ---- stateful client (the installed transport) ---- */ /* ServerKey for every later request: sent as "Authorization: Bearer " (SPEC D4). * NULL or "" clears it. Never echoed anywhere. */ SPFSC_API int spfsc_set_key(const char *key); /* GET {full_url}/api/Version: SPRCH_OK iff it parses as a version >= 1.1.0.0 (the legacy * test). timeout_ms <= 0 = 5000 (the legacy value). */ SPFSC_API int spfsc_validate(const char *full_url, int timeout_ms); /* {"full_url","version","json_listing":true|false|null,"key_sent":bool} of the last validate / * list on that server ("{}" before any). json_listing null = no listing seen yet. */ SPFSC_API const char *spfsc_server_json(void); /* GET {full_url}/api/Folders: the keys become the current listing (folders). Count or <0. */ SPFSC_API int spfsc_folders(const char *full_url); /* Browse {full_url}/{folder}/{relpath}/ (relpath "" or NULL = the folder root). Count or <0. */ SPFSC_API int spfsc_list(const char *full_url, const char *folder, const char *relpath); /* Item i of the current listing: {"name","path","folder","kind","size","mtime_ms","mtime_unix", * "url","id","legacy_id"}; NULL when i is out of range. */ SPFSC_API const char *spfsc_item_json(int i); SPFSC_API int spfsc_count(void); /* Metadata of the last operation: {"op","code","source":"json"|"html"|"api",...}. */ SPFSC_API const char *spfsc_result_json(void); SPFSC_API const char *spfsc_last_error(void); /* "" after success; never a secret */ /* ---- sprch face through the installed transport (the handler takes a scorpiox_io) ---- */ SPFSC_API int spfsc_handler_validate(const char *settings_json, char *out_json, int cap); SPFSC_API int spfsc_handler_list(const char *settings_json, const char *folder_id, char *out_json, int cap); SPFSC_API int spfsc_handler_stream_url(const char *settings_json, const char *entry_json, char *out_json, int cap); SPFSC_API int spfsc_handler_download(const char *settings_json, const char *config_json, char *out_json, int cap); /* ---- identity ---- */ SPFSC_API const char *spfsc_version(void); SPFSC_API const char *spfsc_runtime_type(void); SPFSC_API int spfsc_caps(void); /* ---- transport selection ---- */ SPFSC_API int spfsc_set_io(const scorpiox_io *io); /* NULL restores the default; copied */ /* Pair a scorpiox_io with its scorpiox_http extension (URLSession, WinHTTP, ...), matched by * (http_get, ctx). Without one: no Authorization header, no Range probe (SPEC D5). */ SPFSC_API int spfsc_bind_http(const scorpiox_io *io, const scorpiox_http *http); SPFSC_API int spfsc_use_curl(void); /* SPRCH_E_NOTSUPPORTED if built without */ SPFSC_API int spfsc_use_fake(void); /* ---- fake transport (tests, console --test; never touches the network) ---- */ SPFSC_API void spfsc_fake_reset(void); /* headers: "Name: value" lines separated by '\n', may be NULL. */ SPFSC_API int spfsc_fake_set(const char *url, int http_code, const char *headers, const char *body); SPFSC_API int spfsc_fake_fail(const char *url, const char *transport_error); SPFSC_API int spfsc_fake_calls(const char *url); /* NULL = total */ /* {"calls":n,"range":"bytes=0-0"|null,"bearer":bool} of the last request to url */ SPFSC_API const char *spfsc_fake_last_request(const char *url); /* ---- internal (static builds, tests, CLI) ---- */ const scorpiox_io *spfsc_io_curl(void); const scorpiox_http *spfsc_http_curl(void); const scorpiox_io *spfsc_io_fake(void); const scorpiox_http *spfsc_http_fake(void); const scorpiox_io *spfsc_io_current(void); #ifdef __cplusplus } #endif #endif /* SPFSC_H */