/* * scorpiox-scorpioplayer-agent-control-server (spctl_) * Embedded pure-C99 HTTP/1.1 REST + optional MCP Streamable HTTP server DLL * for SCORPIO PLAYER 2027. */ #ifndef SPCTL_H #define SPCTL_H #include #include #ifdef __cplusplus extern "C" { #endif #ifndef SPCTL_EXPORT # if defined(_WIN32) || defined(__CYGWIN__) # ifdef SPCTL_BUILD # define SPCTL_EXPORT __declspec(dllexport) # else # define SPCTL_EXPORT __declspec(dllimport) # endif # elif defined(__GNUC__) && __GNUC__ >= 4 # define SPCTL_EXPORT __attribute__((visibility("default"))) # else # define SPCTL_EXPORT # endif #endif #define SPCTL_VERSION "1.0.0" #define SPCTL_ABI_VERSION 1 typedef enum spctl_err { SPCTL_OK = 0, SPCTL_ERR_INVALID = -1, SPCTL_ERR_NOMEM = -2, SPCTL_ERR_BIND = -3, SPCTL_ERR_STATE = -4, SPCTL_ERR_AUTH = -5, SPCTL_ERR_RATE_LIMIT = -6, SPCTL_ERR_READ_ONLY = -7, SPCTL_ERR_NOT_IMPL = -8, SPCTL_ERR_BACKEND = -9, SPCTL_ERR_INTERNAL = -10, SPCTL_ERR_NOT_FOUND = -11, SPCTL_ERR_BAD_REQUEST = -12 } spctl_err_t; typedef enum spctl_play_mode { SPCTL_PLAY_PAUSE = 0, SPCTL_PLAY_RESUME = 1, SPCTL_PLAY_TOGGLE = 2 } spctl_play_mode_t; typedef struct spctl_server spctl_server; /* * Server configuration (ABI 1). * Initialize with spctl_config_init(&cfg) before modifying fields. */ typedef struct spctl_config { uint32_t struct_size; /* sizeof(spctl_config) */ const char *bind_host; /* NULL/"" -> "127.0.0.1" */ int port; /* 0 = ephemeral, or 1..65535 */ int enable_mcp; /* 0 = disabled (404), 1 = POST /mcp enabled */ int read_only; /* 0 = full control, 1 = read-only */ int require_auth; /* -1 = auto (0 loopback, 1 LAN), 0 = off, 1 = on */ int allow_unauth_lan; /* 0 = refuse non-loopback require_auth=0; 1 = allow */ const char *server_name; /* default "scorpio-player-2027" */ const char *product_version; /* default "1.0.0" */ const char *static_bearer_token; /* optional pre-shared Bearer token */ uint32_t max_body_bytes; /* default 1 MiB (max 16 MiB) */ uint32_t io_timeout_ms; /* default 10000 ms */ uint32_t reserved[8]; } spctl_config; /* * Player backend vtable (ABI 1). * Every callback is optional (NULL -> HTTP 501 / MCP isError). * Buffers written to *out_json / *out_buf are freed by the server using * free_buf(ctx, ptr) if non-NULL, or standard free(ptr) otherwise. */ typedef struct spctl_backend { uint32_t struct_size; /* sizeof(spctl_backend) */ uint32_t abi_version; /* SPCTL_ABI_VERSION (1) */ void *ctx; void (*free_buf)(void *ctx, void *ptr); /* State & Playback */ int (*get_state_json)(void *ctx, char **out_json, size_t *out_len); int (*open_media)(void *ctx, const char *url_or_path, const char *options_json, char **out_json, size_t *out_len); int (*set_playing)(void *ctx, int mode, char **out_json, size_t *out_len); int (*seek)(void *ctx, double seconds, int accurate, char **out_json, size_t *out_len); int (*set_rate)(void *ctx, double rate, char **out_json, size_t *out_len); int (*set_volume)(void *ctx, int volume_0_100, int muted, char **out_json, size_t *out_len); int (*get_tracks_json)(void *ctx, char **out_json, size_t *out_len); int (*select_track)(void *ctx, const char *kind, int index, char **out_json, size_t *out_len); int (*get_chapters_json)(void *ctx, char **out_json, size_t *out_len); int (*jump_chapter)(void *ctx, int index, char **out_json, size_t *out_len); /* Subtitles */ int (*sub_search)(void *ctx, const char *query_json, char **out_json, size_t *out_len); int (*sub_load)(void *ctx, const char *path_or_url, char **out_json, size_t *out_len); int (*sub_set_delay)(void *ctx, int delay_ms, char **out_json, size_t *out_len); /* Library, Sources & Server-Driven Templates */ int (*get_home_json)(void *ctx, char **out_json, size_t *out_len); int (*get_sources_json)(void *ctx, char **out_json, size_t *out_len); int (*browse)(void *ctx, const char *source, const char *path, char **out_json, size_t *out_len); int (*tpl_render)(void *ctx, const char *template_name, int page, char **out_json, size_t *out_len); int (*tpl_click)(void *ctx, const char *path, const char *value_json, char **out_json, size_t *out_len); int (*menu_invoke)(void *ctx, const char *handler_or_path, const char *args_json, char **out_json, size_t *out_len); /* Agent Visual & Diagnostic Debugging */ int (*capture_frame_png)(void *ctx, uint8_t **out_buf, size_t *out_len); int (*capture_ui_png)(void *ctx, uint8_t **out_buf, size_t *out_len); int (*get_logs_json)(void *ctx, int limit, char **out_json, size_t *out_len); int (*custom_action)(void *ctx, const char *name, const char *args_json, char **out_json, size_t *out_len); void *reserved[8]; } spctl_backend; typedef int64_t (*spctl_clock_fn)(void *ctx); /* Version & Metadata */ SPCTL_EXPORT const char *spctl_version(void); SPCTL_EXPORT int spctl_abi_version(void); SPCTL_EXPORT void spctl_config_init(spctl_config *cfg); /* Lifecycle */ SPCTL_EXPORT spctl_server *spctl_create(void); SPCTL_EXPORT void spctl_destroy(spctl_server *s); SPCTL_EXPORT int spctl_set_config(spctl_server *s, const spctl_config *cfg); SPCTL_EXPORT int spctl_set_config_json(spctl_server *s, const char *json); SPCTL_EXPORT int spctl_set_backend(spctl_server *s, const spctl_backend *backend); SPCTL_EXPORT int spctl_install_fake_backend(spctl_server *s); SPCTL_EXPORT int spctl_start(spctl_server *s); SPCTL_EXPORT int spctl_stop(spctl_server *s); SPCTL_EXPORT int spctl_is_running(const spctl_server *s); SPCTL_EXPORT int spctl_bound_port(const spctl_server *s); SPCTL_EXPORT const char *spctl_status_json(spctl_server *s); /* Security, Pairing & Tokens */ SPCTL_EXPORT int spctl_pair_begin(spctl_server *s, char *out_code_buf, size_t out_code_cap, int ttl_seconds); SPCTL_EXPORT int spctl_pair_verify(spctl_server *s, const char *code, const char *client_name, char *out_token_buf, size_t out_token_cap); SPCTL_EXPORT int spctl_add_token(spctl_server *s, const char *token, const char *label, int read_only); SPCTL_EXPORT int spctl_revoke_tokens(spctl_server *s); SPCTL_EXPORT int spctl_active_token_count(const spctl_server *s); SPCTL_EXPORT void spctl_set_clock(spctl_server *s, spctl_clock_fn fn, void *ctx); /* In-Memory HTTP Dispatch (testing, fuzzing, custom transports) */ SPCTL_EXPORT int spctl_dispatch_http(spctl_server *s, const uint8_t *raw_req, size_t raw_req_len, uint8_t **out_resp, size_t *out_resp_len); SPCTL_EXPORT void spctl_free(void *ptr); /* Diagnostics & Self-Test */ SPCTL_EXPORT const char *spctl_last_error(const spctl_server *s); SPCTL_EXPORT int spctl_last_error_code(const spctl_server *s); SPCTL_EXPORT const char *spctl_strerror(int code); SPCTL_EXPORT int spctl_selftest(void); #ifdef __cplusplus } #endif #endif /* SPCTL_H */