#ifndef SCORPIOX_HTTP_H #define SCORPIOX_HTTP_H /* * scorpiox-http.h — PROPOSED fleet extension to scorpiox-io.h (SPEC D1). * * This is a proposal copy that lives in the webdav-client repo. It belongs with the owner of * scorpiox-io.h. scorpiox-io.h itself is NOT modified. * * scorpiox_io offers GET/POST with a NUL-terminated body. HTTP engines beyond simple REST * need: any method, request headers, binary bodies with a length, bounded streaming reads, * auth, and response headers. This vtable carries exactly that, and nothing else: * URL building, headers, parsing and state stay in the C library; the backend is transport. * * Contract: * - request(): 0 = a response arrived (*http_code set; also when on_body asked to stop), * -1 = transport failure (*out_err = malloc'd message, freed with free_buf). * - The backend MUST be synchronous, MUST NOT follow redirects (credentials never leave * the origin), and MUST verify TLS certificates. * - username != NULL: the backend answers a 401 challenge with Basic or Digest. * - on_header is called for the FINAL response only (not for a 401 challenge it answered * itself, not for 100 Continue): first with name ":status" and the decimal status code, * then once per header line, all before the first on_body call. on_body is called for * each body chunk, in order. Either may return non-zero to stop the transfer; * request() then returns 0 with *http_code set. * - struct_size: both structs are append-only; readers check struct_size before * touching a field added later. */ #include #define SCORPIOX_HTTP_ABI 1 typedef struct scorpiox_http_request { unsigned struct_size; /* sizeof(scorpiox_http_request) */ const char *method; /* RFC 9110 token: "GET", "PROPFIND", "MKCOL", ... */ const char *url; /* absolute http(s) URL, already percent-encoded */ const char *const *headers; /* "Name: value" lines without CR/LF; may be NULL */ size_t header_count; const void *body; /* may be NULL (no body) */ size_t body_len; const char *username; /* NULL = no auth */ const char *password; long timeout_ms; /* 0 = backend default */ int (*on_header)(void *user, const char *name, const char *value); int (*on_body)(void *user, const void *data, size_t n); void *user; } scorpiox_http_request; typedef struct scorpiox_http { unsigned struct_size; /* sizeof(scorpiox_http) */ unsigned abi; /* SCORPIOX_HTTP_ABI */ void *ctx; int (*request)(void *ctx, const scorpiox_http_request *rq, long *http_code, char **out_err); void (*free_buf)(void *ctx, void *ptr); } scorpiox_http; #endif /* SCORPIOX_HTTP_H */