33typedef enum : uint8_t {
68 if (text ==
nullptr) {
71 const size_t length =
strnlen(text, cap);
75 for (
size_t index = 0U; index < length; index++) {
76 if ((text[index] ==
'\r') || (text[index] ==
'\n')) {
101 (msg->
etag !=
nullptr) && (msg->
etag[0] ==
'\0') &&
132 const size_t length =
strnlen(source, cap);
133 memcpy(destination, source, length + 1U);
161 .data_len = (uint16_t)msg->
data.len,
163 if (msg->
data.len != 0U) {
210 if (msg->
data.len > (UINT64_MAX - msg->
offset)) {
213 const uint64_t end = msg->
offset + msg->
data.len;
214 const bool total_covers_data = (msg->
total_bytes == 0U) || (end <= msg->total_bytes);
215 if (!total_covers_data) {
221 switch (msg->
state) {
223 return (msg->
status == 0) && (msg->
data.len != 0U) && (msg->
sha256.len == 0U);
225 return (msg->
status == 0) && (msg->
data.len == 0U) &&
229 return (msg->
status == 0) && (msg->
data.len == 0U) && (msg->
sha256.len == 0U);
231 return (msg->
status > 0) && (msg->
status <= UINT16_MAX) && (msg->
data.len == 0U) &&
255 const ProtobufCBinaryData* data)
257 ProtobufCAllocator alloc = {};
260 if (msg ==
nullptr) {
263 const bool valid = (msg->
base.n_unknown_fields == 0U) &&
299 const ProtobufCBinaryData* data)
301 ProtobufCAllocator alloc = {};
304 if (msg ==
nullptr) {
312 ((msg->
data.len == 0U) || (msg->
data.data !=
nullptr)) &&
338 ProtobufCAllocator alloc = {};
341 if (msg ==
nullptr) {
344 const bool valid = (msg->
base.n_unknown_fields == 0U) &&
373 const Rpc* msg = (
const Rpc*)msg_v;
374 const RpcRespCustomRpc* body = msg->resp_custom_rpc;
375 if ((body ==
nullptr) || (body->custom_msg_id != take->
operation)) {
383 if ((body->data.data ==
nullptr) || (body->data.len == 0U)) {
386 switch (take->
kind) {
426 RpcReqCustomRpc body = RPC__REQ__CUSTOM_RPC__INIT;
427 body.custom_msg_id = operation;
428 body.data = (ProtobufCBinaryData){.len = data_len, .data = data};
431 req.msg_type = RPC_TYPE__Req;
432 req.msg_id = RPC_ID__Req_CustomRpc;
433 req.payload_case = RPC__PAYLOAD_REQ_CUSTOM_RPC;
434 req.req_custom_rpc = &body;
439 (uint32_t)RPC_ID__Resp_CustomRpc,
447 const uint8_t* packed,
500 if ((request ==
nullptr) || (request->
url ==
nullptr)) {
503 const size_t https_prefix_len =
sizeof(
"https://") - 1U;
506 (
strncmp(request->
url,
"https://", https_prefix_len) != 0) ||
507 (request->
url[https_prefix_len] ==
'\0')) {
518 *out_url_len = url_len;
564 if (http->
referer !=
nullptr) {
579 if ((link ==
nullptr) || (session ==
nullptr)) {
589 memcpy(url_copy, request->
url, url_len + 1U);
595 inner.
url = url_copy;
605 if ((packed == 0U) || (packed >
sizeof(link->
mdl_request)) ||
610 .requested_format = request->
format,
629 if ((link ==
nullptr) || (session ==
nullptr) || (chunk ==
nullptr)) {
648 if ((packed == 0U) || (packed >
sizeof(link->
mdl_request)) ||
654 .requested_bytes = max_bytes,
661 if ((link ==
nullptr) || (session ==
nullptr)) {
673 if ((packed == 0U) || (packed >
sizeof(link->
mdl_request)) ||
Annotation-attribute framework macros for ra8-firmware.
#define RA8_TEST_HELPER
Mark a symbol as externally-linked but only callable from tests.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
struct ra8_c6link ra8_c6link_t
void priv_c6link_arena_bind(ProtobufCAllocator *out, ra8_c6link_t *link)
Bind an allocator descriptor to a link's arena.
Cross-translation-unit contract inside libs/ra8_c6link.
ra8_err_t priv_c6link_resp(ra8_c6link_t *link, uint32_t rpc_id, int32_t resp)
Map a co-processor result code onto an ra8 error, recording it.
ra8_err_t priv_c6link_rpc_call(ra8_c6link_t *link, Rpc *req, uint32_t resp_id, ra8_c6link_take_fn_t take, void *take_ctx)
Issue one request and pump until its answer arrives.
static ra8_err_t internal_mdl_take_chunk(mdl_take_ctx_t *take, const ProtobufCBinaryData *data)
Decode a chunk and enforce correlation and size bounds.
ra8_err_t ra8_c6link_mdl_take_cancelled_test(ra8_c6link_t *link, ra8_mdl_session_t *session, const uint8_t *packed, size_t len)
Judge one cancellation acknowledgement exactly as the client does.
static ra8_err_t internal_mdl_take_accepted(mdl_take_ctx_t *take, const ProtobufCBinaryData *data)
Decode and validate one accepted-job response.
mdl_take_kind_t
Response extractor variants.
@ k_mdl_take_accepted
Extract an Accepted response.
@ k_mdl_take_chunk
Extract a Chunk response.
@ k_mdl_take_cancelled
Extract a Cancelled response.
static ra8_err_t internal_mdl_take_response(void *ctx, const void *msg_v)
Extract one generated media payload from a CustomRpc response.
bool ra8_c6link_mdl_http_response_valid_test(const Ra8__Mdl__Chunk *msg)
Judge one decoded response's HTTP metadata exactly as the client does.
static ra8_err_t internal_mdl_accept_chunk(mdl_take_ctx_t *take, const Ra8__Mdl__Chunk *msg)
Copy one validated generated chunk and advance its active session.
ra8_err_t ra8_c6link_mdl_next(ra8_c6link_t *link, ra8_mdl_session_t *session, uint16_t max_bytes, ra8_mdl_chunk_t *chunk)
Pull the next bounded chunk while acknowledging the prior offset.
static void internal_mdl_http_field_copy(char *destination, const char *source, size_t cap)
Copy one already-bounded HTTP field into fixed response storage.
static ra8_err_t internal_mdl_take_cancelled(mdl_take_ctx_t *take, const uint8_t *data, size_t len)
Decode a cancellation acknowledgement for the active job.
static void internal_mdl_stage_headers(const ra8_mdl_http_policy_t *http, mdl_http_headers_t *out)
Copy every present optional HTTP header into bounded local storage.
static bool internal_mdl_chunk_semantics_valid(const Ra8__Mdl__Chunk *msg)
Validate state-specific fields of one correlated chunk.
bool ra8_c6link_mdl_chunk_semantics_valid_test(const Ra8__Mdl__Chunk *msg)
Judge one decoded response's state semantics exactly as the client does.
static ra8_err_t internal_mdl_call(ra8_c6link_t *link, uint32_t operation, uint8_t *data, size_t data_len, mdl_take_ctx_t *take)
Send one already-encoded generated message through CustomRpc.
ra8_err_t ra8_c6link_mdl_start(ra8_c6link_t *link, const char *url, mdl_format_t format, ra8_mdl_session_t *session)
Start retrieval of one selected artifact and receive its job identifier.
ra8_err_t ra8_c6link_mdl_cancel(ra8_c6link_t *link, ra8_mdl_session_t *session)
Cancel one active remote job and invalidate its local session.
ra8_err_t ra8_c6link_mdl_start_request(ra8_c6link_t *link, const ra8_mdl_request_t *request, ra8_mdl_session_t *session)
Start one typed request while preserving downloader HTTP policy.
static ra8_err_t internal_mdl_start_request_valid(const ra8_mdl_request_t *request, size_t *out_url_len)
Validate every caller-supplied start-request field before staging.
static bool internal_mdl_http_response_valid(const Ra8__Mdl__Chunk *msg)
Validate terminal HTTP metadata carried by a generated Chunk.
bool ra8_c6link_mdl_http_field_valid_test(const char *text, size_t cap)
Judge one decoded HTTP header exactly as the client does.
static bool internal_mdl_http_field_valid(const char *text, size_t cap)
Validate one optional HTTP field against its protocol bound.
Pull-based media download client over ESP-hosted CustomRpc.
Private response-validation seams for the media RPC client.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_protocol_error
Protocol-level error (e.g.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
int strncmp(const char *s1, const char *s2, size_t n)
Compare two strings up to a specified length.
size_t strlen(const char *s)
Calculate string length.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
size_t strnlen(const char *s, size_t maxlen)
Calculate bounded string length.
@ k_ra8_mdl_user_agent_max
Maximum User-Agent size, including NUL.
@ k_ra8_mdl_referer_max
Maximum Referer size, including NUL.
@ k_ra8_mdl_chunk_data_max
Maximum raw body bytes in one chunk.
@ k_ra8_mdl_url_max
Maximum URL buffer size, including NUL.
@ k_ra8_mdl_http_date_max
Maximum HTTP-date size, including NUL.
@ k_ra8_mdl_etag_max
Maximum ETag size, including NUL.
@ k_ra8_mdl_content_type_max
Maximum Content-Type size, including NUL.
@ k_ra8_mdl_sha256_bytes
SHA-256 digest size in bytes.
@ k_ra8_mdl_retry_after_max
Maximum Retry-After size, including NUL.
@ k_ra8_mdl_timeout_ms_max
Maximum caller-selected HTTP timeout in ms.
@ k_ra8_mdl_http_status_max
Highest well-formed HTTP status code.
@ k_ra8_mdl_http_status_min
Lowest well-formed HTTP status code.
@ k_ra8_mdl_protocol_version
Typed HTTP-artifact transfer protocol.
ra8_mdl_state_t
Remote job state.
@ k_ra8_mdl_rpc_start
Start one typed-artifact job.
@ k_ra8_mdl_rpc_cancel
Cancel one active job.
@ k_ra8_mdl_rpc_next
Pull one ordered bounded chunk.
uint32_t protocol_version
uint32_t protocol_version
uint32_t protocol_version
ProtobufCBinaryData sha256
uint32_t protocol_version
uint32_t protocol_version
uint64_t acknowledged_offset
uint32_t protocol_version
Context consumed synchronously by the CustomRpc response extractor.
uint16_t requested_bytes
Maximum accepted response body bytes.
mdl_take_kind_t kind
Expected generated response variant.
ra8_c6link_t * link
Link whose arena decoded the response.
uint32_t operation
Expected CustomRpc operation id.
ra8_mdl_chunk_t * chunk
Optional caller chunk destination.
ra8_mdl_session_t * session
Correlated caller session.
mdl_format_t requested_format
Format the Accepted response must echo.
uint8_t mdl_request[k_ra8_mdl_request_bytes_max]
Packed inner media request awaiting transmission.
One correlated bounded raw-byte response.
ra8_mdl_http_response_t response
Terminal HTTP metadata.
uint8_t data[k_ra8_mdl_chunk_data_max]
Bounded raw body bytes.
uint8_t sha256[k_ra8_mdl_sha256_bytes]
Complete-body SHA-256.
bool has_sha256
Whether sha256 is valid.
Bounded request policy forwarded to the C6 HTTP client.
uint32_t timeout_ms
Whole-request timeout, or zero for default.
const char * if_modified_since
If-Modified-Since value, or null/empty.
const char * if_none_match
If-None-Match value, or null/empty to omit.
const char * user_agent
User-Agent value, or null/empty to omit.
const char * referer
Referer value, or null/empty to omit.
char last_modified[k_ra8_mdl_http_date_max]
Last-Modified or empty.
int32_t status
Final HTTP status.
char retry_after[k_ra8_mdl_retry_after_max]
Retry-After or empty.
char content_type[k_ra8_mdl_content_type_max]
Content-Type or empty.
char etag[k_ra8_mdl_etag_max]
ETag or empty.
Complete typed HTTPS request accepted by protocol version 3.
mdl_format_t format
Exact returned artifact identity.
ra8_mdl_http_policy_t http
Forwarded request policy.
const char * url
Absolute HTTPS source URL.
RA8-local state for one accepted remote artifact job.
uint64_t next_offset
Exact byte offset required from the next response.
uint32_t job_id
Remote-generated non-zero identifier.
bool active
Whether next/cancel is currently valid.
uint32_t next_sequence
Exact sequence required from the next response.
uint32_t max_chunk_bytes
Maximum accepted pull size negotiated at start.