#ifndef SCORPIOX_HTTP_H #define SCORPIOX_HTTP_H /* * scorpiox-http.h — the fleet HTTP transport, v1 FINAL. * * Owner: scorpiox-http-transport-libcurl-winhttp-fake-backends. Vendored by copy * (see ADOPTING.md); scorpiox-io.h is NOT modified and stays the frozen v1 face. * * scorpiox_io offers GET/POST with a NUL-terminated body. 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 only. * * Contract (SPEC B1–B12): * - 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). * HTTP 4xx/5xx is NOT a transport failure. * - 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, once. * - on_header is called for the FINAL response only: 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. * - Host, Content-Length and Authorization request lines are built by the backend; * the engine's own lines of those names are ignored. * - struct_size: both structs are append-only; readers check struct_size before * touching a field added later. */ #include #define SCORPIOX_HTTP_ABI 1 /* request flags (append-only; readers honour only what they know) */ #define SCORPIOX_HTTP_REQ_DECOMPRESS 0x1u /* send A-E: gzip,deflate and inflate (B9) */ #define SCORPIOX_HTTP_REQ_NO_STALL 0x2u /* disable the stalled-transfer guard (B10) */ 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 (60 s) */ long connect_timeout_ms; /* 0 = backend default (15 s) */ unsigned flags; /* SCORPIOX_HTTP_REQ_* */ long stall_ms; /* 0 = backend default (60 s); NO_STALL overrides */ 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; /* ---- the fleet answer to "which transport is behind this scorpiox_io?" ---- * An adapter (scorpiox_io_over_http) points io->ctx at a scorpiox_io_http_ctx; engines * that receive a const scorpiox_io * (the frozen sprch.h shape) resolve the extension * with this helper instead of keeping a binding table. */ #define SCORPIOX_IO_HTTP_MAGIC 0x53485848u /* "SHXH" */ typedef struct scorpiox_io_http_ctx { unsigned magic; /* SCORPIOX_IO_HTTP_MAGIC */ unsigned struct_size; /* sizeof(scorpiox_io_http_ctx) */ const scorpiox_http *http; /* the transport behind the io */ void *user; /* backend-private (may be NULL) */ } scorpiox_io_http_ctx; #ifdef __cplusplus extern "C" { #endif /* Returns the transport behind io, or NULL when io->ctx is not a scorpiox_io_http_ctx * (a foreign io: the engine answers NOTSUPPORTED, it must never fall back to its own * transport on iOS). Safe on any io, including NULL. */ struct scorpiox_io; const scorpiox_http *scorpiox_http_of(const struct scorpiox_io *io); #ifdef __cplusplus } #endif #endif /* SCORPIOX_HTTP_H */