20typedef enum : uint16_t {
95 const time_t now = time(
nullptr);
96 if ((fetched_at < 0) || (now < (time_t)0)) {
99 const int64_t current = (int64_t)now;
100 return (current >= fetched_at) ? (current - fetched_at) : 0;
119 const time_t now = time(
nullptr);
120 return (now < (time_t)0) ? 0 : (int64_t)now;
142 const size_t length =
strlen(source);
143 if (length >= capacity) {
144 destination[0] =
'\0';
147 memcpy(destination, source, length + 1U);
176 uint64_t content_hash,
177 const char* relative_path,
181 .content_hash = content_hash,
183 .response_status = (uint16_t)response->
status};
232 ((record !=
nullptr) && (record->
etag[0] !=
'\0')) ? record->
etag :
nullptr;
237 return fetch(fetch_context, url, &request, buffer, capacity, out_length, response);
338 fetch(fetch_context, url, &request, buffer, capacity, out_length, response);
548 if ((cache ==
nullptr) || (cache->
storage ==
nullptr) || (cache->
index ==
nullptr) ||
549 (cache->
root ==
nullptr) || (url ==
nullptr) || (base_request ==
nullptr) ||
550 (fetch ==
nullptr) || (buffer ==
nullptr) || (capacity == 0U) || (out_length ==
nullptr) ||
551 (response ==
nullptr) || (result ==
nullptr)) {
562 const bool validators =
564 if (lookup.
held && !cache->
refetch && !validators) {
static ra8_err_t internal_cache_prepare(mdl_cache_t *cache, const char *url, char *buffer, size_t capacity, mdl_cache_result_t *result, mdl_cache_lookup_t *lookup)
Load one host index and verify any retained exact-URL entity.
static bool internal_cache_record_response(mdl_cache_index_t *index, mdl_cache_record_t *existing, const char *url, uint64_t url_hash, uint64_t content_hash, const char *relative_path, const mdl_net_resp_t *response)
Update or insert one freshly published body record.
mdl_cache_http_t
HTTP response bounds used by the cache state machine.
@ k_cache_http_not_modified
Conditional reuse response.
@ k_cache_http_success_max
Last successful status.
@ k_cache_http_status_max
Last canonical HTTP status.
@ k_cache_http_success_min
First successful status.
static ra8_err_t internal_cache_fetch(const mdl_cache_record_t *record, const char *url, const mdl_net_req_t *base_request, mdl_cache_fetch_fn fetch, void *fetch_context, char *buffer, size_t capacity, size_t *out_length, mdl_net_resp_t *response)
Issue a cache-controlled request with selected validators.
static int64_t internal_cache_now(void)
Capture the current epoch for one response observation.
static mdl_cache_record_t * internal_cache_find(mdl_cache_index_t *index, const char *url, uint64_t url_hash)
Locate one exact URL record.
static bool internal_cache_copy(char *destination, size_t capacity, const char *source)
Copy a complete bounded string without truncation.
static ra8_err_t internal_cache_finish_304(mdl_cache_t *cache, const mdl_cache_paths_t *paths, mdl_cache_record_t *record, char *buffer, size_t capacity, size_t *out_length, mdl_cache_result_t *result)
Finish a verified HTTP 304 observation.
static ra8_err_t internal_cache_network(mdl_cache_t *cache, const mdl_cache_lookup_t *lookup, const char *url, const mdl_net_req_t *base_request, mdl_cache_fetch_fn fetch, void *fetch_context, char *buffer, size_t capacity, size_t *out_length, mdl_net_resp_t *response, mdl_cache_result_t *result)
Fetch, resolve 304 semantics, and publish one network observation.
ra8_err_t mdl_cache_get_buf(mdl_cache_t *cache, const char *url, const mdl_net_req_t *base_request, mdl_cache_fetch_fn fetch, void *fetch_context, char *buffer, size_t capacity, size_t *out_length, mdl_net_resp_t *response, mdl_cache_result_t *result)
Fetch one document through the per-host persistent cache.
static ra8_err_t internal_cache_retry_unconditional(const char *url, const mdl_net_req_t *base_request, mdl_cache_fetch_fn fetch, void *fetch_context, char *buffer, size_t capacity, size_t *out_length, mdl_net_resp_t *response)
Retry one invalid 304 without conditional headers.
static mdl_cache_record_t * internal_cache_slot(mdl_cache_index_t *index)
Select a record slot, evicting the oldest observation when full.
static int64_t internal_cache_age(int64_t fetched_at)
Compute a nonnegative retained-observation age.
static ra8_err_t internal_cache_publish(mdl_cache_t *cache, const mdl_cache_paths_t *paths, mdl_cache_record_t *existing, const char *url, const char *buffer, size_t length, const mdl_net_resp_t *response, mdl_cache_result_t *result)
Publish and index one successful nonempty response body.
Bounded per-host HTTP document cache for the media downloader.
ra8_err_t(* mdl_cache_fetch_fn)(void *context, const char *url, const mdl_net_req_t *request, char *buffer, size_t capacity, size_t *out_length, mdl_net_resp_t *response)
Injected bounded GET callback used by the cache.
@ k_mdl_cache_record_max
Records retained per host.
Private binary-index and body I/O seams for mdl_cache.
ra8_err_t priv_mdl_cache_load(mdl_cache_t *cache, const char *url, mdl_cache_paths_t *paths, bool *rebuilt)
Prepare a host directory and load or recover its index.
ra8_err_t priv_mdl_cache_publish_body(mdl_storage_t *storage, const mdl_cache_paths_t *paths, uint64_t url_hash, uint64_t content_hash, const char *buffer, size_t length, char *relative_path, size_t relative_capacity)
Publish one new body under its immutable content-derived leaf.
ra8_err_t priv_mdl_cache_read_body(mdl_storage_t *storage, const mdl_cache_paths_t *paths, const mdl_cache_record_t *record, char *buffer, size_t capacity, size_t *out_length)
Read and hash-check one retained body into caller storage.
ra8_err_t priv_mdl_cache_save(mdl_cache_t *cache, const mdl_cache_paths_t *paths)
Transactionally publish the current host index.
Content-identity hashing (FNV-1a 64) for the media downloader's persistent library state.
uint64_t mdl_hash_bytes(const void *data, size_t len)
FNV-1a 64 hash of a byte range.
uint64_t mdl_hash_str(const char *s)
FNV-1a 64 hash of a NUL-terminated string (excluding the NUL).
@ k_mdl_relpath_max
Page path relative to the series dir.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ 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 strcmp(const char *s1, const char *s2)
Compare two null-terminated strings.
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.
Caller-owned workspace for one loaded host index.
mdl_cache_record_t records[k_mdl_cache_record_max]
Retained observations.
uint16_t record_count
Populated rows.
Prepared host paths and verified retained-entity state.
size_t retained_length
Verified retained body size.
bool held
Body exists and hash checks.
mdl_cache_paths_t paths
Derived host namespace.
mdl_cache_record_t * record
Exact URL record, or NULL.
Complete paths and host identity derived for one request.
One exact URL-keyed cached document observation.
char url[k_mdl_url_max]
Exact canonical request URL.
char etag[k_mdl_etag_max]
Last response ETag, or empty.
char last_modified[k_mdl_last_mod_max]
Last-Modified, or empty.
uint64_t url_hash
FNV identity accelerator.
uint16_t response_status
Last observed HTTP status.
int64_t fetched_at
Completion epoch seconds.
char relative_path[k_mdl_relpath_max]
Body leaf beneath the host dir.
Observable outcome of one cache lookup.
bool body_reused
Returned bytes came from verified storage.
bool revalidated
A network request was issued.
bool index_rebuilt
A corrupt index was discarded first.
int64_t age_seconds
Age before this operation, or -1 if unknown.
uint16_t observed_status
Network or retained status.
One non-reentrant cache binding over caller storage.
bool refetch
Force a network revalidation.
const char * root
Canonical cache root.
mdl_storage_t * storage
Injected portable storage binding.
mdl_cache_index_t * index
Caller-owned index workspace.
Per-request session parameters.
const char * if_none_match
If-None-Match conditional header (ETag), or NULL.
const char * if_modified_since
If-Modified-Since header (Last-Modified), or NULL.
Per-transfer response metadata surfaced to the politeness governor.
long status
Finished transfer's HTTP status, 0 if none.
char etag[k_mdl_etag_max]
Raw ETag value, "" when absent.
char last_modified[k_mdl_last_mod_max]
Raw Last-Modified value, "" when absent.