#ifndef SPTF_H #define SPTF_H /* * sptf.h -- scorpiox-scorpioplayer-template-fetch: fetch, hash-diff, inflate, validate and cache * the server-driven UI template bundle. Moves bytes; never parses a template. See SPEC.md. * * Strings are UTF-8. Returned pointers are owned by the library and stay valid until the next * call that mutates state (SPEC S7). Not thread-safe: serialise calls. */ #include #include "scorpiox-io.h" #ifdef __cplusplus extern "C" { #endif #if defined(_WIN32) # if defined(SPTF_BUILD) # define SPTF_API __declspec(dllexport) # else # define SPTF_API __declspec(dllimport) # endif #else # define SPTF_API __attribute__((visibility("default"))) #endif #define SPTF_VERSION "1.0.0" /* error taxonomy (SPEC 9) */ #define SPTF_OK 0 #define SPTF_ERR_TRANSPORT -1 #define SPTF_ERR_HTTP -2 #define SPTF_ERR_ZLIB -3 #define SPTF_ERR_JSON -4 #define SPTF_ERR_CACHE_IO -5 #define SPTF_ERR_UNSAFE_KEY -6 #define SPTF_ERR_NO_IO -7 #define SPTF_ERR_INVALID_ARG -8 #define SPTF_ERR_OOM -9 /* which source won for a key (SPEC S2) */ #define SPTF_ORIGIN_SERVER 1 #define SPTF_ORIGIN_DISK 2 #define SPTF_ORIGIN_BUNDLE 3 /* limits (SPEC 5, J5) */ #define SPTF_MAX_COMPRESSED (32u * 1024u * 1024u) #define SPTF_MAX_INFLATED (64u * 1024u * 1024u) #define SPTF_RATIO_LIMIT 100u #define SPTF_RATIO_FLOOR (4u * 1024u * 1024u) #define SPTF_MAX_ENTRIES 100000 SPTF_API const char *sptf_version(void); /* transport (SPEC 8) */ SPTF_API int sptf_set_io(const scorpiox_io *io); /* NULL uninstalls */ SPTF_API const scorpiox_io *sptf_io_curl(void); /* NULL when built without libcurl */ SPTF_API const scorpiox_io *sptf_io_fake(void); SPTF_API void sptf_fake_reset(void); SPTF_API int sptf_fake_set(const char *method, const char *url, long code, const unsigned char *body, size_t len); SPTF_API int sptf_fake_fail(const char *method, const char *url, const char *message); SPTF_API long sptf_fake_calls(void); SPTF_API const char *sptf_fake_last_body(void); /* last request body, or "" */ /* configuration */ SPTF_API int sptf_set_host(const char *host); /* default https://gcp.scorpioplayer.com */ SPTF_API int sptf_set_cache_dir(const char *path); /* must exist; never derived in C */ SPTF_API int sptf_set_user_id(const char *user_id); /* "" = anonymous */ /* lifecycle */ SPTF_API int sptf_restore(void); /* disk -> memory */ SPTF_API int sptf_load_bundle(const unsigned char *zlib_bytes, size_t len); SPTF_API int sptf_refresh(void); /* hash-diff POST */ SPTF_API int sptf_refresh_full(void); /* empty hash map: everything */ SPTF_API void sptf_clear(void); /* drop memory state; disk untouched */ /* entries */ SPTF_API int sptf_count(void); SPTF_API const char *sptf_key(int i); SPTF_API const char *sptf_content(const char *key); SPTF_API long long sptf_content_len(const char *key); /* -1 = unknown key */ SPTF_API long long sptf_hash(const char *key); /* stable hash >= 0, -1 = unknown */ SPTF_API int sptf_origin(const char *key); /* SPTF_ORIGIN_*, 0 = unknown */ /* last refresh (SPEC 10) */ SPTF_API long long sptf_last_refresh_sent(void); SPTF_API long long sptf_last_refresh_received(void); SPTF_API long long sptf_last_refresh_inflated(void); SPTF_API int sptf_last_refresh_changed(void); SPTF_API int sptf_last_refresh_unchanged(void); SPTF_API long sptf_last_http_code(void); /* diagnostics */ SPTF_API const char *sptf_result_json(void); SPTF_API const char *sptf_last_error(void); SPTF_API int sptf_warning_count(void); SPTF_API const char *sptf_warning(int i); #ifdef __cplusplus } #endif #endif /* SPTF_H */