/* sprs_backend — local HTTP/range transport seam. * Engine never owns a socket. Fake / curl / URLSession plug here. * Proposed mapping onto future scorpiox_io v2 is in SPEC.md / report. */ #ifndef SPRS_BACKEND_H #define SPRS_BACKEND_H #include #include #ifdef __cplusplus extern "C" { #endif typedef enum { SPRS_XPORT_OK = 0, SPRS_XPORT_DNS = 1, SPRS_XPORT_REFUSED = 2, SPRS_XPORT_TIMEOUT = 3, SPRS_XPORT_RESET = 4, SPRS_XPORT_IO = 5 } sprs_xport_class; typedef struct sprs_range_req { const char *url; int head_only; /* 1 = HEAD */ int64_t range_start; /* inclusive; -1 = no Range header */ int64_t range_end; /* inclusive; -1 = open end (bytes=N-) */ const char *const *extra_headers; int n_extra; } sprs_range_req; typedef struct sprs_stream sprs_stream; typedef struct sprs_backend { void *ctx; /* Open a response. On success *out is non-NULL; caller must close. * Returns 0 on transport success (HTTP status may still be 4xx), * -1 on transport failure (consult xport / err_msg on *out if non-NULL, * or backend last-error). */ int (*open_range)(void *ctx, const sprs_range_req *req, sprs_stream **out); /* May short-read. *got=0 with return 0 means EOF of this response body. */ int (*read)(sprs_stream *s, unsigned char *dst, size_t n, size_t *got); void (*close)(sprs_stream *s); int (*http_status)(const sprs_stream *s); int64_t (*content_length)(const sprs_stream *s); /* this body; -1 unknown */ int64_t (*entity_length)(const sprs_stream *s); /* Content-Range total or CL; -1 */ int (*accept_ranges_bytes)(const sprs_stream *s); /* 1 / 0 / -1 unknown */ int64_t (*range_start)(const sprs_stream *s); /* -1 if not a 206 */ int64_t (*range_end)(const sprs_stream *s); sprs_xport_class (*xport)(const sprs_stream *s); const char *(*err_msg)(const sprs_stream *s); /* bytes actually received from the wire for this stream (for stats) */ int64_t (*bytes_from_wire)(const sprs_stream *s); } sprs_backend; #ifdef __cplusplus } #endif #endif