/* scorpiox-scorpioplayer-spms-v3-tcp-media-server — SPMS v3 binary TCP media server (spms3s_). * * SCORPIO PLAYER 2027 engine. Pure C99, zero external deps (vendored yyjson only). * See SPEC.md for every decision (D1..D20) 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 SPMS3S_H #define SPMS3S_H #ifdef _WIN32 # ifdef SPMS3S_BUILD # define SPMS3S_API __declspec(dllexport) # else # define SPMS3S_API __declspec(dllimport) # endif #else # define SPMS3S_API __attribute__((visibility("default"))) #endif #ifdef __cplusplus extern "C" { #endif #define SPMS3S_OK 0 #define SPMS3S_E_ARG (-1) #define SPMS3S_E_STATE (-2) #define SPMS3S_E_NET (-3) #define SPMS3S_E_NOENT (-4) #define SPMS3S_E_NOMEM (-5) #define SPMS3S_E_LIMIT (-6) #define SPMS3S_E_DENIED (-7) #define SPMS3S_E_TIMEOUT (-8) /* ---- lifecycle ---- */ SPMS3S_API const char *spms3s_version(void); /* keys: platform, action_byteorder(auto|big|little), idle_timeout_ms, read_timeout_ms, * max_string, max_read, sub_max_bytes. NULL value = reset to default. * "platform" must be set before start (it goes into the handshake JSON, D2). */ SPMS3S_API int spms3s_config(const char *key, const char *value); /* bind_ip: an IPv4 literal of ONE interface (0.0.0.0 refused, D12). port 0 = ephemeral. */ SPMS3S_API int spms3s_start(const char *bind_ip, int port, const char *const *roots, int nroots); SPMS3S_API void spms3s_stop(void); /* joins the listener + all sessions */ SPMS3S_API int spms3s_is_running(void); SPMS3S_API int spms3s_port(void); /* bound port */ SPMS3S_API int spms3s_add_root(const char *path); /* root index >= 0, or <0; file or folder */ SPMS3S_API int spms3s_remove_root(const char *path); SPMS3S_API int spms3s_root_count(void); SPMS3S_API const char *spms3s_root_json(int i); /* {"name","path","kind"} */ SPMS3S_API int spms3s_connection_count(void); /* ---- pure / socket-free ---- */ SPMS3S_API const char *spms3s_handshake_json(void); /* {"Version":3,"Platform":...} (D2) */ /* resolve a client path/id against a root (D3): 0 ok (out = the validated host path), * <0 refused (SPMS3S_E_DENIED/E_ARG/E_NOENT). outlen includes the NUL. */ SPMS3S_API int spms3s_resolve(const char *root, const char *client_path, char *out, int outlen); /* listing of a folder id (files=0) or of the files directly under it (files=1) as the wire JSON. * sub_id "" = the roots themselves. Returns a static buffer; last_code carries the failure. */ SPMS3S_API const char *spms3s_listing_json(const char *root_path, const char *sub_id, int files); /* the Subtitle reply for a ScorpioServerFile JSON arg (D9); "" on refusal. */ SPMS3S_API const char *spms3s_subtitles_json(const char *root_path, const char *file_json); /* the exact bytes a Read/SeekRead reply carries for (fd-backed) data: caller supplies the * source buffer and its length; the render zero-pads to count (D6). Returns bytes written * (== count) or <0. outlen must be >= count. */ SPMS3S_API int spms3s_frame_read_bytes(const unsigned char *src, int srclen, unsigned count, unsigned char *out, int outlen); /* render a SeekRead request (count then position, D7) the way a client would send it — * 12 bytes big-endian; used by the tests, the fuzzer and the console. Returns 12 or <0. */ SPMS3S_API int spms3s_frame_seekread(unsigned count, unsigned long long position, unsigned char *out, int outlen); SPMS3S_API const char *spms3s_frame_action_name(int action); SPMS3S_API int spms3s_last_code(void); SPMS3S_API const char *spms3s_last_error(void); #ifdef __cplusplus } #endif #endif /* SPMS3S_H */