/* * spftps.h — scorpiox-scorpioplayer-ftp-file-server (row 38). * * A read-only FTP server: named roots (folders or single files) under one virtual tree, anonymous or * caller-supplied logins, a loopback-only client allow-list by default. See SPEC.md for every rule. * * Return codes: SPFTPS_OK or a negative SPFTPS_E_*. Strings are UTF-8 (paths are bytes). Returned * const char * are per thread and valid until the next call on the same thread that returns a string. */ #ifndef SPFTPS_H #define SPFTPS_H #ifdef __cplusplus extern "C" { #endif #if defined(SPFTPS_STATIC) # define SPFTPS_API #elif defined(_WIN32) # if defined(SPFTPS_BUILD) # define SPFTPS_API __declspec(dllexport) # else # define SPFTPS_API __declspec(dllimport) # endif #else # define SPFTPS_API __attribute__((visibility("default"))) #endif #define SPFTPS_OK 0 #define SPFTPS_E_ARG (-1) /* NULL / malformed argument, bad option */ #define SPFTPS_E_NOTFOUND (-2) /* root path missing, unknown root or user, entry not listable */ #define SPFTPS_E_EXISTS (-3) /* root name taken */ #define SPFTPS_E_STATE (-4) /* start while running */ #define SPFTPS_E_NET (-5) /* socket / bind / listen / thread failure */ #define SPFTPS_E_LIMIT (-6) /* too many roots / users / CIDRs */ #define SPFTPS_E_PATH (-7) /* the path rule refused the argument */ #define SPFTPS_E_BUFFER (-8) /* output does not fit cap */ /* spftps_list_line formats */ #define SPFTPS_FMT_LIST 0 #define SPFTPS_FMT_MLSD 1 #define SPFTPS_FMT_NLST 2 /* ---- identity ---- */ SPFTPS_API const char *spftps_version(void); /* ---- lifecycle ---- */ SPFTPS_API int spftps_start(const char *bind_ip, int port, int pasv_lo, int pasv_hi); SPFTPS_API void spftps_stop(void); SPFTPS_API int spftps_port(void); /* bound control port, 0 = stopped */ SPFTPS_API int spftps_set_option(const char *key, const char *value); /* ---- roots, users, access ---- */ SPFTPS_API int spftps_add_root(const char *name, const char *path); /* folder or single file */ SPFTPS_API int spftps_remove_root(const char *name); SPFTPS_API int spftps_add_user(const char *user, const char *pass); /* none added = anonymous read-only */ SPFTPS_API int spftps_remove_user(const char *user); SPFTPS_API int spftps_allow_cidr(const char *cidr); /* loopback is always allowed */ /* ---- status ---- */ SPFTPS_API int spftps_client_count(void); SPFTPS_API const char *spftps_stats_json(void); /* ---- pure (no socket) ---- */ SPFTPS_API const char *spftps_list_line(const char *name, const char *relpath, int mlsd); SPFTPS_API int spftps_vpath(const char *cwd, const char *arg, char *out, int cap); SPFTPS_API const char *spftps_simulate(const char *script, const char *client_ip); /* ---- results ---- */ SPFTPS_API const char *spftps_last_error(void); #ifdef __cplusplus } #endif #endif /* SPFTPS_H */