/* * spftpc.h — scorpiox-scorpioplayer-ftp-file-client (RuntimeType "FTP", row 39). * * The C twin of SP2025 FTPRuntimeConfigHandler + FluentFTP 33.0.3: an sprch_handler plus a small * read-only session API (connect / list / open / read_at). See SPEC.md for every rule. * * Return codes: SPRCH_OK or SPRCH_E_* (sprch.h), plus SPFTPC_E_ARG for the session API. * Strings are UTF-8 both ways. Returned const char * are per thread and valid until the next * call on the same thread that returns a string. */ #ifndef SPFTPC_H #define SPFTPC_H #include "sprch.h" #ifdef __cplusplus extern "C" { #endif #if defined(SPFTPC_STATIC) # define SPFTPC_API #elif defined(_WIN32) # if defined(SPFTPC_BUILD) # define SPFTPC_API __declspec(dllexport) # else # define SPFTPC_API __declspec(dllimport) # endif #else # define SPFTPC_API __attribute__((visibility("default"))) #endif #define SPFTPC_E_ARG (-10) /* session API: bad handle, NULL argument, not connected */ /* spftpc_parse_list_line results (>= 0) */ #define SPFTPC_KIND_FILE 0 #define SPFTPC_KIND_DIR 1 #define SPFTPC_KIND_LINK 2 #define SPFTPC_SKIP 3 /* "total N", ".", "..", MLSD cdir/pdir, device files */ /* dialect hints */ #define SPFTPC_DIALECT_AUTO 0 #define SPFTPC_DIALECT_UNIX 1 #define SPFTPC_DIALECT_DOS 2 #define SPFTPC_DIALECT_EPLF 3 #define SPFTPC_DIALECT_MLSD 4 /* ---- FTP transport vtable (SPEC section 6). Appended members only; abi says which exist. ---- */ #define SPFTPC_TRANSPORT_ABI 1 typedef struct spftpc_transport { unsigned abi; /* SPFTPC_TRANSPORT_ABI */ void *ctx; /* 0 = connected (*conn set), -1 = failure (err set, NUL-terminated) */ int (*connect)(void *ctx, const char *host, int port, int timeout_ms, void **conn, char *err, int errcap); /* writes all len bytes: len, or -1 */ int (*write)(void *ctx, void *conn, const void *buf, int len, int timeout_ms); /* >0 bytes read, 0 = EOF, -1 = error, -2 = timeout */ int (*read)(void *ctx, void *conn, void *buf, int cap, int timeout_ms); void (*close)(void *ctx, void *conn); /* the numeric peer address of conn (the PASV rule): 0 / -1 */ int (*peer_ip)(void *ctx, void *conn, char *out, int cap); /* NULL = no TLS. 0 = the connection now speaks TLS, -1 = failure (err set) */ int (*start_tls)(void *ctx, void *conn, const char *sni, char *err, int errcap); } spftpc_transport; /* ---- identity ---- */ SPFTPC_API const char *spftpc_version(void); SPFTPC_API const char *spftpc_runtime_type(void); SPFTPC_API int spftpc_caps(void); /* ---- sprch ops, flat (out == NULL / cap == 0: the output is kept for spftpc_result_json) ---- */ SPFTPC_API int spftpc_validate(const char *settings_json, char *out_json, int cap); SPFTPC_API int spftpc_list_json(const char *settings_json, const char *folder_id, char *out_json, int cap); SPFTPC_API int spftpc_stream_url(const char *settings_json, const char *entry_json, char *out_json, int cap); SPFTPC_API int spftpc_download(const char *settings_json, const char *config_json, char *out_json, int cap); SPFTPC_API int spftpc_allow_writes(int enable); /* 0 => OK; 1 => E_NOTSUPPORTED (no write op exists) */ /* ---- session API ---- */ SPFTPC_API int spftpc_connect(const char *host, int port, const char *user, const char *pass, int tls); SPFTPC_API int spftpc_list(const char *path); /* item count, or an error */ SPFTPC_API const char *spftpc_item_json(int i); /* NULL when out of range */ SPFTPC_API int spftpc_open(const char *path); /* handle 1..64, or an error */ SPFTPC_API long long spftpc_size(int h); /* bytes, -1 unknown, SPFTPC_E_ARG */ SPFTPC_API int spftpc_read_at(int h, long long off, void *buf, int len); /* bytes, 0 = EOF */ SPFTPC_API void spftpc_close(int h); SPFTPC_API void spftpc_disconnect(void); SPFTPC_API const char *spftpc_session_json(void); /* features of the current session */ /* ---- pure ---- */ SPFTPC_API int spftpc_parse_list_line(const char *line, int dialect_hint); SPFTPC_API int spftpc_parse_listing(const char *body, int dialect_hint, char *out_json, int cap); SPFTPC_API int spftpc_pasv_target(const char *reply, const char *control_ip, char *host_out, int cap); /* port */ SPFTPC_API int spftpc_decode_name(const char *raw, char *out, int cap); /* bytes written, or an error */ /* ---- results ---- */ SPFTPC_API const char *spftpc_last_error(void); SPFTPC_API const char *spftpc_result_json(void); /* ---- transport + tuning ---- */ SPFTPC_API int spftpc_set_transport(const spftpc_transport *t); /* NULL => sockets */ SPFTPC_API int spftpc_use_sockets(void); SPFTPC_API int spftpc_use_fake(void); SPFTPC_API int spftpc_set_limits(int connect_ms, int io_ms, int retries, int retry_delay_ms); /* -1 = keep */ SPFTPC_API int spftpc_set_clock(long long unix_now); /* 0 = the system clock */ /* ---- fake server (offline tests, console --test) ---- */ SPFTPC_API void spftpc_fake_reset(void); SPFTPC_API int spftpc_fake_add(const char *path, int kind, long long size, long long mtime_unix, const char *link_target); SPFTPC_API int spftpc_fake_set(const char *key, const char *value); SPFTPC_API int spftpc_fake_listing(const char *path, const char *raw); SPFTPC_API int spftpc_fake_calls(const char *cmd); /* NULL = every command */ SPFTPC_API const char *spftpc_fake_log(void); SPFTPC_API int spftpc_fake_expect(const char *path, long long off, void *buf, int len); #ifdef __cplusplus } #endif #endif /* SPFTPC_H */