/* scorpiox-scorpioplayer-sftp-file-server — read-only SFTP v3 server engine (SPEC.md). * * One server per process (singleton API). Functions return 0 on success and a negative value * on error unless documented otherwise; spsftps_last_error() explains it. Returned const char* * point to static storage valid until the next call on any thread; copy them immediately. * * Read-only by construction: no write-class request is ever executed (see SPEC.md §2). */ #ifndef SPSFTPS_H #define SPSFTPS_H #ifdef __cplusplus extern "C" { #endif #if defined(SPSFTPS_STATIC) # define SPSFTPS_API #elif defined(_WIN32) # ifdef SPSFTPS_BUILD # define SPSFTPS_API __declspec(dllexport) # else # define SPSFTPS_API __declspec(dllimport) # endif #else # define SPSFTPS_API __attribute__((visibility("default"))) #endif /* ---- error codes ---- */ #define SPSFTPS_OK 0 #define SPSFTPS_E_ARG -1 /* bad argument */ #define SPSFTPS_E_STATE -2 /* wrong state (already running / not running) */ #define SPSFTPS_E_IO -3 /* socket / file / transport error */ #define SPSFTPS_E_KEY -4 /* host key / authorized key could not be parsed */ #define SPSFTPS_E_LIMIT -5 /* table full */ #define SPSFTPS_E_NOTFOUND -6 /* no such root / user */ #define SPSFTPS_E_EXISTS -7 /* root name already registered */ /* ---- lifecycle ---- */ /* bind_ip: numeric IP ("127.0.0.1", "::1", "0.0.0.0"). port 0 = ephemeral (see spsftps_port). * host_key_path: OpenSSH "openssh-key-v1" ed25519 private key; generated (mode 0600) if missing. * NULL = generate a throw-away key for this process only. */ SPSFTPS_API int spsftps_start(const char *bind_ip, int port, const char *host_key_path); SPSFTPS_API void spsftps_stop(void); SPSFTPS_API int spsftps_is_running(void); SPSFTPS_API int spsftps_port(void); /* bound port, 0 = stopped */ SPSFTPS_API const char *spsftps_host_fingerprint(void); /* "SHA256:..." */ SPSFTPS_API const char *spsftps_version(void); SPSFTPS_API const char *spsftps_last_error(void); /* ---- share roots: folder or single regular file, added/removed at runtime ---- * name: [A-Za-z0-9._-]{1,63}, must not start with '.'. Virtual "/" lists the roots. */ SPSFTPS_API int spsftps_add_root(const char *name, const char *path); SPSFTPS_API int spsftps_remove_root(const char *name); SPSFTPS_API int spsftps_root_count(void); /* ---- credentials (never OS accounts) ---- */ SPSFTPS_API int spsftps_add_user(const char *user, const char *pass); SPSFTPS_API int spsftps_add_pubkey(const char *user, const char *authorized_keys_line); SPSFTPS_API int spsftps_remove_user(const char *user); SPSFTPS_API int spsftps_clear_users(void); /* ---- network policy: default allow-list is loopback only ---- */ SPSFTPS_API int spsftps_allow_cidr(const char *cidr); SPSFTPS_API int spsftps_clear_cidr(void); SPSFTPS_API int spsftps_set_limits(int max_connections, int idle_timeout_s, int login_grace_s); /* ---- introspection ---- */ SPSFTPS_API int spsftps_client_count(void); SPSFTPS_API const char *spsftps_stats_json(void); /* ---- test hooks (no network). The console --test and the unit tests drive these. ---- * spsftps_exercise_hex: feed hex-encoded SFTP packets (uint32 length + body, back to back) * into a fresh in-process session as user "test" and return the hex-encoded reply bytes. * Returns NULL on bad hex or a malformed frame (spsftps_last_error says why). */ SPSFTPS_API const char *spsftps_exercise_hex(const char *request_hex); /* spsftps_resolve_virtual: canonical virtual path of an existing path inside a root, or NULL. */ SPSFTPS_API const char *spsftps_resolve_virtual(const char *vpath); #ifdef __cplusplus } #endif #endif /* SPSFTPS_H */