/* * spwd.h — scorpiox-scorpioplayer-webdav-client public API (pure C99 WebDAV client). * * Two surfaces over one engine: * - the sprch handler (sprch_get(), RuntimeType "WebDAV"), stateless per call; * - the stateful spwd_* client below (fleet style: global state behind one lock). * * Paths are DECODED paths relative to the base path ("/Movies/My #1.mkv"), never URLs * (SPEC D3). Returned strings are owned by the library and stay valid until the next call * that changes the same state. Write verbs refuse unless spwd_arm_writes(1) (SPEC D18). * See SPEC.md for every decision and its C# citation. */ #ifndef SPWD_H #define SPWD_H #include #include "sprch.h" #include "scorpiox-http.h" #ifdef __cplusplus extern "C" { #endif #if defined(_WIN32) # if defined(SPWD_BUILD) # define SPWD_API __declspec(dllexport) # else # define SPWD_API __declspec(dllimport) # endif #else # define SPWD_API __attribute__((visibility("default"))) #endif #define SPWD_VERSION "1.1.0" /* ---- error taxonomy (SPEC D15) ---- */ #define SPWD_OK 0 #define SPWD_ERR_TRANSPORT -1 #define SPWD_ERR_HTTP -2 #define SPWD_ERR_XML -3 #define SPWD_ERR_AUTH -4 #define SPWD_ERR_NOT_FOUND -5 #define SPWD_ERR_CONFLICT -6 #define SPWD_ERR_NOT_ARMED -7 #define SPWD_ERR_UNSAFE_PATH -8 #define SPWD_ERR_NO_IO -9 #define SPWD_ERR_INVALID_ARG -10 #define SPWD_ERR_OOM -11 #define SPWD_MAX_CHUNK (16u * 1024u * 1024u) /* SPEC D17: one range read */ /* ---- transport (SPEC D1, D2) ---- */ SPWD_API int spwd_set_io(const scorpiox_io *io); /* must be bound to an extension */ SPWD_API int spwd_set_http(const scorpiox_http *http); /* install an extension directly */ SPWD_API int spwd_bind_http(const scorpiox_io *io, const scorpiox_http *http); /* http NULL unbinds */ SPWD_API int spwd_use_curl(void); /* default */ SPWD_API int spwd_use_fake(void); /* offline canned responses */ SPWD_API const scorpiox_io *spwd_io_curl(void); /* NULL when built without libcurl */ SPWD_API const scorpiox_io *spwd_io_fake(void); /* ---- configuration ---- */ SPWD_API int spwd_set_server(const char *url); /* scheme://host[:port][/base] */ SPWD_API int spwd_set_base_path(const char *path); /* default "/" */ SPWD_API int spwd_set_credentials(const char *user, const char *password); /* NULL clears */ SPWD_API int spwd_set_user_agent(const char *ua); /* NULL = WebDAVClient/1.0.0.0 */ SPWD_API int spwd_add_header(const char *name, const char *value); SPWD_API void spwd_clear_headers(void); SPWD_API int spwd_set_propfind_mode(int prop_list); /* 0 = (C#), 1 = */ /* ---- read (safe) ---- */ SPWD_API int spwd_list(const char *path, int depth); /* depth 0, 1 or -1 (infinity) */ SPWD_API int spwd_stat(const char *path); /* Depth 0; result is item 0 */ SPWD_API int spwd_item_count(void); SPWD_API const char *spwd_item_href(int i); /* C# Href: '#'->%23, file '/' trimmed */ SPWD_API const char *spwd_item_path(int i); /* decoded, pass back to any call */ SPWD_API const char *spwd_item_display_name(int i); SPWD_API int spwd_item_is_collection(int i); /* 0/1, -1 out of range */ SPWD_API long long spwd_item_content_length(int i); /* -1 unknown */ SPWD_API const char *spwd_item_content_type(int i); /* "" unknown */ SPWD_API const char *spwd_item_etag(int i); /* "" unknown */ SPWD_API long long spwd_item_last_modified(int i); /* epoch ms UTC, -1 unknown */ SPWD_API long long spwd_item_creation_date(int i); /* epoch ms UTC, -1 unknown */ SPWD_API int spwd_item_is_hidden(int i); SPWD_API int spwd_download_range(const char *path, long long start, long long end); /* end inclusive */ SPWD_API const unsigned char *spwd_data(size_t *len); /* the last range: bounded chunk */ SPWD_API long long spwd_range_total(void); /* from Content-Range, -1 unknown */ SPWD_API int spwd_download_to_file(const char *path, const char *local_file); /* streamed */ /* ---- write: ALL REFUSE UNLESS ARMED (SPEC D18) ---- */ SPWD_API int spwd_arm_writes(int armed); /* default 0 */ SPWD_API int spwd_writes_armed(void); SPWD_API int spwd_upload(const char *path, const unsigned char *data, size_t n); SPWD_API int spwd_upload_range(const char *path, const unsigned char *data, size_t n, long long start, long long end); /* n == end - start + 1 */ SPWD_API int spwd_mkcol(const char *path); SPWD_API int spwd_delete(const char *path); /* trailing '/' = collection */ SPWD_API int spwd_move(const char *src, const char *dst); /* Overwrite: F */ SPWD_API int spwd_copy(const char *src, const char *dst); /* Overwrite: F */ /* ---- results ---- */ SPWD_API int spwd_last_http_code(void); /* 0 when no response */ SPWD_API const char *spwd_last_error(void); /* "" after success; never a secret */ SPWD_API const char *spwd_result_json(void); SPWD_API int spwd_warning_count(void); /* total, may exceed the kept 64 */ SPWD_API const char *spwd_warning(int i); /* "" out of range */ SPWD_API const char *spwd_strerror(int code); SPWD_API const char *spwd_version(void); /* ---- sprch flat wrappers (installed backend) ---- */ SPWD_API int spwd_sprch_validate(const char *settings_json, char *out_json, int cap); SPWD_API int spwd_sprch_list(const char *settings_json, const char *folder_id, char *out_json, int cap); SPWD_API int spwd_sprch_stream_url(const char *settings_json, const char *entry_json, char *out_json, int cap); SPWD_API int spwd_sprch_download(const char *settings_json, const char *config_json, char *out_json, int cap); /* ---- the fake backend (tests, .console --test): no network, ever ---- */ SPWD_API void spwd_fake_reset(void); /* A canned answer for method + url. headers: "Name: value\n" lines or NULL. */ SPWD_API int spwd_fake_set(const char *method, const char *url, int http_code, const char *headers, const char *body); /* A file for GET: range_support 1 honours Range (206 / 416), 0 ignores it (200), * 2 answers 416 to a range crossing EOF (dufs). */ SPWD_API int spwd_fake_file(const char *url, const unsigned char *data, size_t n, int range_support); SPWD_API int spwd_fake_fail(const char *method, const char *url, const char *transport_error); SPWD_API int spwd_fake_calls(const char *method, const char *url); /* NULL = any */ SPWD_API int spwd_fake_writes_sent(void); /* PUT/MKCOL/DELETE/MOVE/COPY received */ SPWD_API const char *spwd_fake_last_request(void); /* JSON */ #ifdef __cplusplus } #endif #endif /* SPWD_H */