ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
mdl_state.h
Go to the documentation of this file.
1
58#pragma once
59
60#include <float.h>
61#include <stddef.h>
62#include <stdint.h>
63
64#if !defined(__STDC_IEC_559__) && !defined(__STDC_IEC_60559_BFP__) && !defined(__clang__) && \
65 !defined(__GNUC__)
66#error "mdl state v3 requires IEC 60559 binary floating-point"
67#endif
68
69static_assert(sizeof(double) == 8U, "mdl state v3 requires binary64 double");
70static_assert(FLT_RADIX == 2, "mdl state v3 requires radix-2 floating-point");
77
78static_assert(DBL_MANT_DIG == k_mdl_binary64_mantissa_bits,
79 "mdl state requires 53-bit binary64 precision");
80static_assert(DBL_MAX_EXP == k_mdl_binary64_max_exponent,
81 "mdl state requires binary64 exponent range");
82static_assert(DBL_MIN_EXP == k_mdl_binary64_min_exponent,
83 "mdl state requires binary64 exponent range");
84
85#include "mdl_config.h"
86#include "mdl_extract.h"
87#include "mdl_net.h"
88#include "mdl_storage.h"
89#include "ra8_err.h"
90
106
112
114typedef enum : uint32_t {
117
139
161
199
219
245 const char* url,
246 const char* title,
247 const char* site_name,
248 const char* site_host,
249 const char* config_path);
250
282 const char* summary,
283 const char* writer,
284 const char* artist,
285 const char* cover_url,
286 const char* cover_path,
287 const char* language,
289
317ra8_err_t mdl_state_load(mdl_storage_t* storage, const char* path, mdl_state_t* st);
318
341[[nodiscard]] ra8_err_t
342mdl_state_load_authenticated(mdl_storage_t* storage, const char* path, mdl_state_t* st);
343
380 const char* path,
381 const mdl_state_t* st,
382 bool* out_published);
383
402[[nodiscard]] ra8_err_t mdl_state_probe(mdl_storage_t* storage, const char* path, bool* out_exists);
403
421
443mdl_state_add_chapter(mdl_state_t* st, const char* id, const char* url, long number);
444
471 const char* id,
472 const char* url,
473 double number,
474 bool number_known);
475
501 const char* title,
502 double number,
503 bool number_known);
504
526bool mdl_state_chapter_complete(const mdl_state_t* st, const char* id);
527
551uint16_t mdl_state_chapter_pages(const mdl_state_t* st, const char* id);
552
570const mdl_page_rec_t* mdl_state_find_page(const mdl_state_t* st, uint64_t url_hash);
571
607 uint64_t url_hash,
608 uint64_t content_hash,
609 const char* rel_path,
610 const char* etag,
611 const char* last_modified,
612 int64_t fetched_at,
613 uint16_t response_status);
614
634 uint64_t url_hash,
635 int64_t fetched_at,
636 uint16_t response_status);
637
660void mdl_state_coverage(const mdl_state_t* st, char* buf, size_t cap);
Per-site descriptor loaded from a flat key=value config file.
@ k_mdl_host_max
Host bytes.
Definition mdl_config.h:34
@ k_mdl_name_max
Site display name bytes.
Definition mdl_config.h:33
Extract image URLs and anchor links from an HTML page (v1 scanner).
@ k_mdl_url_max
Max bytes per URL, including the NUL.
Definition mdl_extract.h:25
Streaming HTTP(S) GET seam (a real function-pointer vtable) for the host manga downloader (v0).
@ k_mdl_last_mod_max
Raw Last-Modified header value buffer bytes.
Definition mdl_net.h:95
@ k_mdl_etag_max
Raw ETag header value buffer bytes.
Definition mdl_net.h:94
uint16_t mdl_state_chapter_pages(const mdl_state_t *st, const char *id)
Recorded page count for a chapter (0 when unknown).
Definition mdl_state.c:321
void mdl_state_coverage(const mdl_state_t *st, char *buf, size_t cap)
Render a one-line coverage summary (chapter span, count, gaps).
Definition mdl_state.c:559
bool mdl_state_set_series_metadata(mdl_state_t *st, const char *summary, const char *writer, const char *artist, const char *cover_url, const char *cover_path, const char *language, mdl_state_reading_direction_t direction)
Set the optional rich metadata persisted for a series.
Definition mdl_state.c:186
mdl_binary64_parameter_t
IEC 60559 binary64 parameters required by the persisted schema.
Definition mdl_state.h:72
@ k_mdl_binary64_min_exponent
Binary64 minimum exponent.
Definition mdl_state.h:75
@ k_mdl_binary64_max_exponent
Binary64 maximum exponent.
Definition mdl_state.h:74
@ k_mdl_binary64_mantissa_bits
Binary64 significand precision.
Definition mdl_state.h:73
mdl_chapter_rec_t * mdl_state_add_chapter(mdl_state_t *st, const char *id, const char *url, long number)
Find or append a chapter record, returning it.
Definition mdl_state.c:257
bool mdl_state_set_chapter_metadata(mdl_chapter_rec_t *chapter, const char *title, double number, bool number_known)
Set a chapter's display title and explicit parsed number.
Definition mdl_state.c:293
mdl_chapter_rec_t * mdl_state_find_chapter(mdl_state_t *st, const char *id)
Find a chapter record by its stable identifier.
Definition mdl_state.c:243
ra8_err_t mdl_state_save(mdl_storage_t *storage, const char *path, const mdl_state_t *st, bool *out_published)
Publish a checksummed successor without sacrificing the newest state.
const mdl_page_rec_t * mdl_state_find_page(const mdl_state_t *st, uint64_t url_hash)
Find a page record by its source-URL hash (the dedup lookup).
Definition mdl_state.c:334
bool mdl_state_note_page_response(mdl_state_t *st, uint64_t url_hash, int64_t fetched_at, uint16_t response_status)
Refresh the observed HTTP result for one existing URL cache entry.
Definition mdl_state.c:393
mdl_chapter_rec_t * mdl_state_add_chapter_numbered(mdl_state_t *st, const char *id, const char *url, double number, bool number_known)
Find or append a chapter with explicit parsed-number presence.
Definition mdl_state.c:262
mdl_state_reading_direction_t
Persisted fixed-layout reading direction.
Definition mdl_state.h:108
@ k_mdl_state_read_ltr
Left-to-right page progression.
Definition mdl_state.h:109
@ k_mdl_state_read_rtl
Right-to-left page progression.
Definition mdl_state.h:110
mdl_state_limit_t
Fixed capacities and the schema version (zero dynamic allocation).
Definition mdl_state.h:92
@ k_mdl_language_max
BCP-47 language bytes.
Definition mdl_state.h:101
@ k_mdl_state_version
Timestamped cache schema written now.
Definition mdl_state.h:96
@ k_mdl_person_max
Writer/artist bytes.
Definition mdl_state.h:100
@ k_mdl_summary_max
Series summary bytes.
Definition mdl_state.h:99
@ k_mdl_cfgpath_max
Site-descriptor path bytes.
Definition mdl_state.h:103
@ k_mdl_state_version_v2
Legacy decimal schema accepted.
Definition mdl_state.h:94
@ k_mdl_chapter_id_max
Chapter identifier bytes (sanitised).
Definition mdl_state.h:97
@ k_mdl_title_max
Series title bytes.
Definition mdl_state.h:98
@ k_mdl_state_version_v3
Legacy cache-metadata schema accepted.
Definition mdl_state.h:95
@ k_mdl_state_version_v1
Legacy integral schema accepted.
Definition mdl_state.h:93
@ k_mdl_max_chapters
Chapters tracked per series.
Definition mdl_state.h:104
@ k_mdl_relpath_max
Page path relative to the series dir.
Definition mdl_state.h:102
bool mdl_state_chapter_complete(const mdl_state_t *st, const char *id)
Whether a chapter is recorded fully fetched and verified.
Definition mdl_state.c:308
ra8_err_t mdl_state_load(mdl_storage_t *storage, const char *path, mdl_state_t *st)
Load a series' newest valid state through injected portable storage.
mdl_state_pool_t
Page pool capacity (kept separate: it needs a 32-bit count).
Definition mdl_state.h:114
@ k_mdl_max_page_recs
Per-page content records per series.
Definition mdl_state.h:115
bool mdl_state_add_page(mdl_state_t *st, uint64_t url_hash, uint64_t content_hash, const char *rel_path, const char *etag, const char *last_modified, int64_t fetched_at, uint16_t response_status)
Add or replace a URL-keyed page cache record.
Definition mdl_state.c:347
ra8_err_t mdl_state_load_authenticated(mdl_storage_t *storage, const char *path, mdl_state_t *st)
Load only an authenticated checksummed state generation.
void mdl_state_init(mdl_state_t *st)
Reset a state object to an empty, current-version library.
Definition mdl_state.c:52
void mdl_state_set_series(mdl_state_t *st, const char *url, const char *title, const char *site_name, const char *site_host, const char *config_path)
Record the series identity and the descriptor used.
Definition mdl_state.c:226
ra8_err_t mdl_state_probe(mdl_storage_t *storage, const char *path, bool *out_exists)
Probe the complete two-generation state marker through portable storage.
Injected portable storage resources for downloader domain code.
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
One chapter's coverage in library state.
Definition mdl_state.h:128
char chapter_id[k_mdl_chapter_id_max]
Stable identifier (URL leaf).
Definition mdl_state.h:129
double number
Parsed number; 0 may be valid.
Definition mdl_state.h:132
int64_t fetched_at
Completion time (epoch s).
Definition mdl_state.h:137
char source_url[k_mdl_url_max]
Chapter page URL.
Definition mdl_state.h:130
uint16_t pages_done
Pages fetched and verified.
Definition mdl_state.h:135
bool number_known
Whether number is known.
Definition mdl_state.h:133
char title[k_mdl_title_max]
Display title, or empty.
Definition mdl_state.h:131
uint16_t page_count
Total pages known (0 = ?).
Definition mdl_state.h:134
bool complete
All pages present + verified.
Definition mdl_state.h:136
One page's dedup/verify record in the series-wide pool.
Definition mdl_state.h:151
char etag[k_mdl_etag_max]
Cached ETag for conditional GET.
Definition mdl_state.h:155
char last_modified[k_mdl_last_mod_max]
Cached Last-Modified response value.
Definition mdl_state.h:157
uint64_t content_hash
FNV-1a 64 of the fetched bytes.
Definition mdl_state.h:153
char rel_path[k_mdl_relpath_max]
Path under the series directory.
Definition mdl_state.h:154
uint64_t url_hash
FNV-1a 64 of the source URL.
Definition mdl_state.h:152
uint16_t response_status
Most recent HTTP status; zero if legacy.
Definition mdl_state.h:159
int64_t fetched_at
Most recent HTTP result time (epoch s).
Definition mdl_state.h:158
One series' complete persistent state (declare at file scope).
Definition mdl_state.h:175
char summary[k_mdl_summary_max]
Series synopsis.
Definition mdl_state.h:182
uint16_t chapter_count
Chapters recorded.
Definition mdl_state.h:191
char cover_path[k_mdl_relpath_max]
Local cover path.
Definition mdl_state.h:186
char series_title[k_mdl_title_max]
Series title.
Definition mdl_state.h:178
mdl_chapter_rec_t chapters[k_mdl_max_chapters]
Per-chapter coverage.
Definition mdl_state.h:195
char series_url[k_mdl_url_max]
Series page URL.
Definition mdl_state.h:177
char site_name[k_mdl_name_max]
Descriptor name.
Definition mdl_state.h:179
mdl_state_reading_direction_t reading_direction
Page progression.
Definition mdl_state.h:189
char language[k_mdl_language_max]
BCP-47 language tag.
Definition mdl_state.h:187
uint16_t version
Schema version.
Definition mdl_state.h:176
char artist[k_mdl_person_max]
Artist/illustrator.
Definition mdl_state.h:184
uint32_t page_rec_count
Page records recorded.
Definition mdl_state.h:193
mdl_page_rec_t pages[k_mdl_max_page_recs]
Per-page identities.
Definition mdl_state.h:197
char site_host[k_mdl_host_max]
Site host.
Definition mdl_state.h:180
char cover_url[k_mdl_url_max]
Remote cover URL.
Definition mdl_state.h:185
char config_path[k_mdl_cfgpath_max]
Descriptor used.
Definition mdl_state.h:181
char writer[k_mdl_person_max]
Writer/author.
Definition mdl_state.h:183
One non-reentrant downloader filesystem dependency bundle.
Definition mdl_storage.h:40