/* * spis.h — scorpiox-scorpioplayer-item-store * * What the player remembers about a user's library: generic settings (local / roaming), * playlists, bookmarks, favourites (opaque capability tokens), per-item properties and * subtitle delays. The C twin of TPlayer SettingService, PlaylistService, BookmarkService, * FavoritesService and PlayListItemPropertiesStore. Decisions D1..D25 live in SPEC.md. * * Conventions: * - int status: SPIS_OK (0) or a negative SPIS_ERR_*; spis_last_error() has the message. * - The library NEVER opens a file (D1). Bytes come and go through the injected backend. * - Every returned const char * is library-owned: valid until the next spis_* call that * mutates the store or returns a string. Copy it immediately. * - Single-threaded; all state is global (D25). * - All strings are UTF-8. Invalid UTF-8 is SPIS_ERR_INVALID_ARG. */ #ifndef SPIS_H #define SPIS_H #include #include #if defined(SPIS_BUILD) # if defined(_WIN32) # define SPIS_API __declspec(dllexport) # else # define SPIS_API __attribute__((visibility("default"))) # endif #else # define SPIS_API #endif #ifdef __cplusplus extern "C" { #endif #define SPIS_VERSION "1.0.0" /* scopes (D2) */ #define SPIS_LOCAL 0 #define SPIS_ROAMING 1 /* value types (D5) */ #define SPIS_T_STR 1 #define SPIS_T_I64 2 #define SPIS_T_F64 3 #define SPIS_T_BOOL 4 /* bookmark types (D15) — on disk, never rely on a default */ #define SPIS_BM_AB 0 #define SPIS_BM_POINT 1 /* change-callback ops (D8) */ #define SPIS_OP_SET 1 #define SPIS_OP_REMOVE 2 #define SPIS_OP_RESET 3 /* errors */ #define SPIS_OK 0 #define SPIS_ERR_NO_SUCH_KEY -1 #define SPIS_ERR_NO_SUCH_CONTAINER -2 #define SPIS_ERR_TYPE_MISMATCH -3 #define SPIS_ERR_NOT_ARMED -4 #define SPIS_ERR_NO_BACKEND -5 #define SPIS_ERR_SERIALIZE -6 #define SPIS_ERR_INVALID_ARG -7 #define SPIS_ERR_OOM -8 #define SPIS_ERR_BACKEND -9 #define SPIS_ERR_NO_SCHEMA -10 /* The confirmation string spis_favourites_reset() demands in addition to the arm flag. */ #define SPIS_FAV_RESET_CONFIRM "REVOKE-ALL-FAVOURITES" /* ---- backend (D1): the host owns bytes on disk, this engine owns structure ------------- * load: return 0 and set *data and *len (host-owned; release() is called when done), * 1 = no blob yet (empty store), anything else = backend error. * release: optional; frees what load returned. * save: persist exactly len bytes for the scope; 0 = ok. */ typedef struct spis_backend { uint32_t struct_size; /* sizeof(spis_backend) */ void *ctx; int (*load)(void *ctx, int scope, const char **data, size_t *len); void (*release)(void *ctx, int scope, const char *data); int (*save)(void *ctx, int scope, const char *data, size_t len); } spis_backend; typedef void (*spis_change_fn)(void *ctx, int scope, const char *container, const char *key, int op); /* Write a new unique id (<= 63 bytes + NUL) into out; return 0. */ typedef int (*spis_uuid_fn)(void *ctx, char *out, size_t cap); /* ---- lifecycle ---- */ SPIS_API const char *spis_version(void); SPIS_API int spis_set_backend(const spis_backend *b); /* NULL = none */ SPIS_API int spis_use_memory_backend(void); /* built-in, for tests */ SPIS_API const char *spis_memory_blob(int scope); /* last saved blob, NULL = none */ SPIS_API int spis_memory_set_blob(int scope, const char *json); /* seed it; NULL = clear */ SPIS_API int spis_set_change_cb(spis_change_fn fn, void *ctx); SPIS_API int spis_load(void); /* both scopes, atomically each */ SPIS_API int spis_save(void); SPIS_API int spis_scope_load_failed(int scope); /* 1 = corrupt, save refuses (D22) */ SPIS_API const char *spis_dump_json(int scope); /* exactly what save() writes */ SPIS_API const char *spis_stats_json(void); SPIS_API void spis_shutdown(void); /* ---- generic key/value (D3..D7) ---- */ SPIS_API int spis_set_str (int scope, const char *container, const char *key, const char *val); SPIS_API int spis_set_i64 (int scope, const char *container, const char *key, int64_t val); SPIS_API int spis_set_f64 (int scope, const char *container, const char *key, double val); SPIS_API int spis_set_bool(int scope, const char *container, const char *key, int val); SPIS_API int spis_get_str (int scope, const char *container, const char *key, const char **out); SPIS_API int spis_get_i64 (int scope, const char *container, const char *key, int64_t *out); SPIS_API int spis_get_f64 (int scope, const char *container, const char *key, double *out); SPIS_API int spis_get_bool(int scope, const char *container, const char *key, int *out); SPIS_API int spis_type_of (int scope, const char *container, const char *key); /* SPIS_T_* or error */ SPIS_API int spis_has (int scope, const char *container, const char *key); /* 1 / 0 */ SPIS_API int spis_remove (int scope, const char *container, const char *key); SPIS_API int spis_key_count(int scope, const char *container); /* >= 0 or error */ SPIS_API const char *spis_key_at(int scope, const char *container, int i); SPIS_API int spis_container_count(int scope); SPIS_API const char *spis_container_at(int scope, int i); /* ---- schema: the generated AppGlobalSettings manifest (D23) ---- */ SPIS_API int spis_schema_load(const char *json); SPIS_API int spis_schema_count(void); SPIS_API int spis_schema_find(const char *name); /* index or -1 */ SPIS_API const char *spis_schema_name(int i); SPIS_API const char *spis_schema_key(int i); SPIS_API const char *spis_schema_type(int i); /* bool|i64|f64|string|timespan_ms|datetime_yyyyMMddHHmmss */ SPIS_API const char *spis_schema_container(int i); SPIS_API int spis_schema_is_roaming(int i); /* 1 / 0 / error */ SPIS_API const char *spis_schema_default_json(int i); /* JSON value; "null" = platform default */ SPIS_API int spis_setting_set_json(const char *name, const char *json_value); SPIS_API const char *spis_setting_get_json(const char *name); /* {"value":…,"source":"stored|default|platform"} */ /* ---- playlists (D11, D12) — ROAMING ---- */ SPIS_API int spis_playlist_add(const char *id, const char *name); /* add or rename */ SPIS_API const char *spis_playlist_new(const char *name); /* id from the uuid source */ SPIS_API int spis_playlist_remove(const char *id); /* cascades to members */ SPIS_API int spis_playlist_count(void); SPIS_API const char *spis_playlist_id(int i); SPIS_API const char *spis_playlist_name(const char *id); SPIS_API int spis_playlist_assign(const char *file_hash, const char *playlist_id); /* one per file */ SPIS_API int spis_playlist_unassign(const char *file_hash); SPIS_API const char *spis_playlist_of(const char *file_hash); SPIS_API int spis_playlist_member_count(const char *playlist_id); SPIS_API const char *spis_playlist_member(const char *playlist_id, int i); SPIS_API const char *spis_playlist_token(const char *file_hash, const char *playlist_id); /* "{StableHash}_{id}" */ /* ---- bookmarks (D13..D16) — ROAMING, indexed by file hash ---- */ SPIS_API const char *spis_bookmark_add_point(const char *file_hash, int64_t ms, const char *key); SPIS_API const char *spis_bookmark_add_ab(const char *file_hash, int64_t start_ms, int64_t end_ms, const char *key); SPIS_API int spis_bookmark_remove(const char *key); SPIS_API int spis_bookmark_count(const char *file_hash); /* NULL = all */ SPIS_API const char *spis_bookmark_key(const char *file_hash, int i); /* NULL file = all */ SPIS_API const char *spis_bookmark_file(const char *key); SPIS_API int spis_bookmark_type(const char *key); /* 0 AB, 1 Point, or error */ SPIS_API int64_t spis_bookmark_start_ms(const char *key); /* -1 = no such bookmark */ SPIS_API int64_t spis_bookmark_end_ms(const char *key); /* -1 = no such bookmark */ SPIS_API const char *spis_bookmark_label(const char *key, const char *fmt); /* generated, never stored */ SPIS_API const char *spis_bookmarks_json(const char *file_hash, int type); /* type -1 = any */ /* ---- favourites (D17, D18) — LOCAL, opaque capability tokens, NOT paths ---- */ SPIS_API int spis_fav_add(const char *token, const char *metadata, const char *display_name); SPIS_API int spis_fav_remove(const char *token); /* raw, then stable-hash form */ SPIS_API int spis_fav_contains(const char *token); /* 1 / 0, both forms */ SPIS_API const char *spis_fav_resolve(const char *token); /* the stored form that matched */ SPIS_API int spis_fav_count(const char *metadata_filter); /* NULL = all */ SPIS_API const char *spis_fav_token(int i); SPIS_API const char *spis_fav_metadata(int i); SPIS_API const char *spis_fav_display_name(int i); SPIS_API int spis_stable_hash(const char *s, int32_t *out); /* GetStableHashCode (D19) */ /* ---- per-item properties (D20) — LOCAL ---- */ SPIS_API const char *spis_item_hash_key(const char *name, const char *uri, int64_t size); SPIS_API int spis_item_prop_set(const char *item_key, const char *prop, const char *val); /* NULL val = remove */ SPIS_API const char *spis_item_prop_get(const char *item_key, const char *prop); /* ---- subtitle delay (D10) — LOCAL container "delayContainer" ---- */ SPIS_API int spis_delay_set(const char *key, int ms); SPIS_API int spis_delay_get(const char *key, int *out); /* ---- ☢️ bulk destruction (D21) — refuses unless armed ---- */ SPIS_API int spis_arm_destructive(int armed); /* default 0 */ SPIS_API int spis_is_armed(void); SPIS_API int spis_reset_scope(int scope); SPIS_API int spis_reset_container(int scope, const char *container); SPIS_API int spis_clear_where(int scope, const char *container, const char *key_prefix); /* removed count */ SPIS_API int spis_playlists_reset(void); SPIS_API int spis_favourites_reset(const char *confirm); /* + SPIS_FAV_RESET_CONFIRM */ /* ---- uuid source (D16) ---- */ SPIS_API int spis_uuid_set_cb(spis_uuid_fn fn, void *ctx); /* NULL = OS random */ SPIS_API int spis_uuid_use_counter(int64_t start); /* deterministic, tests */ /* ---- diagnostics ---- */ SPIS_API const char *spis_last_error(void); SPIS_API const char *spis_error_name(int code); SPIS_API int spis_warning_count(void); SPIS_API const char *spis_warning(int i); SPIS_API void spis_warnings_clear(void); #ifdef __cplusplus } #endif #endif /* SPIS_H */