|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Descriptor-driven series preparation and safe path setup. More...
#include "mdl_app_internal.h"Go to the source code of this file.
Functions | |
| static ra8_err_t | internal_prepare_cache_fetch (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) |
| Dispatch one cache request directly through the active network seam. | |
| ra8_err_t | priv_mdl_app_report_cache (const char *url, const mdl_cache_result_t *result) |
| Report verified cache reuse with its pre-request staleness. | |
| static ra8_err_t | internal_prepare_diag3 (const char *first, const char *second, const char *third) |
| Append three borrowed preparation diagnostics. | |
| static void | internal_swap_rows (mdl_url_list_t *l, size_t a, size_t b) |
| Swap two rows of a URL list. | |
| static void | internal_reverse_list (mdl_url_list_t *l) |
| Reverse a URL list in place. | |
| static bool | internal_sort_by_chapter_num (mdl_url_list_t *l) |
| Sort a URL list by parsed chapter number. | |
| static ra8_err_t | internal_apply_order (mdl_url_list_t *l, mdl_chapter_order_t order) |
| Apply the configured chapter ordering in place. | |
| static void | internal_filter_prefix (mdl_url_list_t *l, const char *prefix) |
| Keep only list entries whose URL starts with a prefix. | |
| static ra8_err_t | internal_warn_no_contact (void) |
| Print the missing-operator-contact warning once. | |
| static ra8_err_t | internal_extract_optional_metadata (const mdl_site_t *site, const char *html, size_t len) |
| Extract the optional summary and creator fields. | |
| static ra8_err_t | internal_extract_cover (const mdl_site_t *site, const char *series_url, const char *html, size_t len) |
| Extract and resolve the configured required cover URL. | |
| static ra8_err_t | internal_extract_series_metadata (const mdl_site_t *site, const char *series_url, const char *html, size_t len) |
| Extract descriptor-driven series metadata from one fetched page. | |
| static ra8_err_t | internal_prepare_filter_chapters (const mdl_site_t *site, const char *series_url) |
| Retain only chapters belonging to the configured series. | |
| ra8_err_t | priv_mdl_app_prepare_chapters (const mdl_site_t *site, const char *series_url, uint32_t timeout, mdl_cache_t *cache) |
| Fetch a series page and build its ordered chapter list. | |
| ra8_err_t | priv_mdl_app_start_session (mdl_net_iface_t *net, const mdl_run_opts_t *opts, const char *cfg_contact, char *ua, size_t ua_cap) |
| Initialize the shared network session identity for one run. | |
| bool | priv_mdl_app_prepare_series_dir (const char *out_dir, const char *series_url, char *slug, size_t slug_cap, char *abs_dir) |
| Create and resolve a series directory beneath an output root. | |
Variables | |
| static char | s_rowtmp [k_mdl_url_max] |
| Scratch row used while reordering the prepared chapter list. | |
Descriptor-driven series preparation and safe path setup.
Fetches and extracts configured series metadata into fixed buffers, sanitizes identities, and prepares paths contained by the library.
Definition in file mdl_app_prepare.c.
|
static |
Apply the configured chapter ordering in place.
Selects document order, reverse order, or validated numeric order.
| [in,out] | l | URL list to reorder. |
| [in] | order | Validated descriptor ordering policy. |
l is non-NULL. order is a valid mdl_chapter_order_t value. | k_ra8_ok | The operation completed successfully. |
| other | The originating validation, storage, stream, or network error. |
Definition at line 208 of file mdl_app_prepare.c.
References internal_reverse_list(), internal_sort_by_chapter_num(), k_mdl_order_asc, k_mdl_order_reverse, k_ra8_ok, priv_mdl_app_context(), priv_mdl_stream_text(), and RA8_INTERNAL.
Referenced by internal_prepare_filter_chapters().
|
static |
Extract and resolve the configured required cover URL.
Coordinates extract cover with fixed application workspaces and propagates validation, storage, or network failure to the selected command runner.
| [in] | site | Validated descriptor containing the cover selector. |
| [in] | series_url | Absolute URL used as the resolution base. |
| [in] | html | Complete fetched series HTML. |
| [in] | len | Number of readable bytes at html. |
| k_ra8_ok | No cover was configured, or it resolved safely. |
| k_ra8_err_validation_failed | The selected cover was not a safe URL. |
| other | The configured selector did not yield a bounded value. |
html spans len bytes. Definition at line 371 of file mdl_app_prepare.c.
References internal_prepare_diag3(), k_mdl_url_max, k_ra8_err_validation_failed, k_ra8_ok, mdl_extract_resolve_url(), mdl_extract_selector(), priv_mdl_app_context(), priv_mdl_stream_text(), and mdl_site_t::series_cover_selector.
Referenced by internal_extract_series_metadata().
|
static |
Extract the optional summary and creator fields.
Coordinates extract optional metadata with fixed application workspaces and propagates validation, storage, or network failure to the selected command runner.
| [in] | site | Validated descriptor containing optional selectors. |
| [in] | html | Complete fetched series HTML. |
| [in] | len | Number of readable bytes at html. |
| k_ra8_ok | Every configured field fit; misses were cleared and warned. |
| k_ra8_err_invalid_size | A selected value exceeded its destination. |
html spans len bytes. < Validated descriptor selector.
< Bounded destination field.
< Destination byte capacity.
< Diagnostic field name.
Definition at line 300 of file mdl_app_prepare.c.
References mdl_series_metadata_t::artist, internal_prepare_diag3(), k_ra8_err_invalid_size, k_ra8_ok, mdl_extract_selector(), priv_mdl_app_context(), priv_mdl_stream_text(), mdl_site_t::series_artist_selector, mdl_site_t::series_author_selector, mdl_app_context_t::series_metadata, mdl_site_t::series_summary_selector, mdl_series_metadata_t::summary, and mdl_series_metadata_t::writer.
Referenced by internal_extract_series_metadata().
|
static |
Extract descriptor-driven series metadata from one fetched page.
A missing/unmatched title falls back loudly to the stable URL leaf; optional descriptive fields warn and remain empty. A configured cover is a required contract: it must be found and resolve to an absolute URL, because silently exporting a book without its promised cover is a false success.
| [in] | site | Validated site descriptor. |
| [in] | series_url | Absolute URL used as the cover-resolution base. |
| [in] | html | Complete fetched series HTML. |
| [in] | len | Number of readable bytes at html. |
| k_ra8_ok | Metadata was extracted, with documented optional fallbacks. |
| k_ra8_err_invalid_size | A selected value exceeded its bounded field. |
| k_ra8_err_validation_failed | A configured cover URL was unsafe. |
| k_ra8_err_no_data | A configured cover selector matched no value. |
html addresses at least len readable bytes. Definition at line 426 of file mdl_app_prepare.c.
References mdl_series_metadata_t::direction, internal_extract_cover(), internal_extract_optional_metadata(), internal_prepare_diag3(), k_mdl_state_read_ltr, k_mdl_state_read_rtl, k_ra8_err_invalid_size, k_ra8_err_no_data, k_ra8_ok, mdl_site_t::language, mdl_extract_selector(), mdl_urlname_last_segment(), memset(), priv_mdl_app_context(), priv_mdl_stream_text(), RA8_INTERNAL, mdl_site_t::reading_direction, mdl_app_context_t::series_metadata, mdl_site_t::series_title_selector, strcmp(), and mdl_series_metadata_t::title_selected.
Referenced by priv_mdl_app_prepare_chapters().
|
static |
Keep only list entries whose URL starts with a prefix.
Compacts matching bounded rows in place while retaining their order.
| [in,out] | l | URL list to filter. |
| [in] | prefix | NUL-terminated absolute URL prefix. |
l and prefix are non-NULL. l. Definition at line 235 of file mdl_app_prepare.c.
References mdl_url_list_t::count, k_mdl_url_max, memcpy(), RA8_INTERNAL, strlen(), strncmp(), and mdl_url_list_t::urls.
Referenced by internal_prepare_filter_chapters().
|
static |
Dispatch one cache request directly through the active network seam.
Adapts the cache callback signature to the already initialized downloader network interface without retaining any argument.
| [in,out] | context | Borrowed mdl_net_iface_t pointer. |
| [in] | url | Exact absolute request URL. |
| [in] | request | Completed request metadata. |
| [out] | buffer | Bounded body destination. |
| [in] | capacity | Writable body capacity. |
| [out] | out_length | Exact accepted bytes. |
| [out] | response | Finished response metadata. |
| k_ra8_ok | The response and exact body length were published. |
| other | The network backend rejected or failed the request. |
buffer spans capacity writable bytes. Definition at line 32 of file mdl_app_prepare.c.
References mdl_net_get_buf(), and RA8_INTERNAL.
Referenced by priv_mdl_app_prepare_chapters().
|
static |
Append three borrowed preparation diagnostics.
Uses caller-owned application and storage state with injected diagnostics. Returns the first failure without publishing partial preparation.
| [in] | first | First text fragment. |
| [in] | second | Second text fragment. |
| [in] | third | Third text fragment. |
| k_ra8_ok | The operation completed successfully. |
| other | The originating validation, storage, stream, or network error. |
Definition at line 107 of file mdl_app_prepare.c.
References mdl_app_context_t::diagnostic, k_ra8_ok, priv_mdl_app_context(), and priv_mdl_stream_text().
Referenced by internal_extract_cover(), internal_extract_optional_metadata(), internal_extract_series_metadata(), and priv_mdl_app_prepare_series_dir().
|
static |
Retain only chapters belonging to the configured series.
Builds the descriptor-selected absolute prefix, removes relation links outside that prefix, and applies the configured ordering.
| [in] | site | Validated site descriptor. |
| [in] | series_url | Absolute series page URL. |
| k_ra8_ok | The retained rows are ordered as configured. |
| k_ra8_err_invalid_size | The bounded prefix cannot be represented. |
Definition at line 500 of file mdl_app_prepare.c.
References mdl_site_t::chapter_order, mdl_site_t::chapter_url_prefix, internal_apply_order(), internal_filter_prefix(), k_dir_path_bytes, k_ra8_err_invalid_size, priv_mdl_app_context(), RA8_INTERNAL, and strlen().
Referenced by priv_mdl_app_prepare_chapters().
|
static |
Reverse a URL list in place.
Exchanges mirrored rows through internal_swap_rows without allocating.
| [in,out] | l | URL list to reverse. |
l is non-NULL. Definition at line 150 of file mdl_app_prepare.c.
References mdl_url_list_t::count, internal_swap_rows(), and RA8_INTERNAL.
Referenced by internal_apply_order().
|
static |
Sort a URL list by parsed chapter number.
Validates every numeric identifier before performing the in-place selection sort, preserving input order when validation fails.
| [in,out] | l | URL list to validate and sort. |
| true | The list is sorted in ascending numeric order. |
| false | At least one identifier was missing and the list is unchanged. |
l is non-NULL. Definition at line 172 of file mdl_app_prepare.c.
References mdl_url_list_t::count, internal_swap_rows(), mdl_urlname_chapter_parse(), mdl_urlname_chapter_value(), min, RA8_INTERNAL, and mdl_url_list_t::urls.
Referenced by internal_apply_order().
|
static |
Swap two rows of a URL list.
Uses the fixed global row scratch so the bounded rows move intact.
| [in,out] | l | URL list to mutate. |
| [in] | a | First row index. |
| [in] | b | Second row index. |
l is non-NULL and owns complete URL rows. a and b are smaller than l->count. Definition at line 128 of file mdl_app_prepare.c.
References k_mdl_url_max, memcpy(), RA8_INTERNAL, s_rowtmp, and mdl_url_list_t::urls.
Referenced by internal_reverse_list(), and internal_sort_by_chapter_num().
|
static |
Print the missing-operator-contact warning once.
Suppresses duplicate warnings across sessions within one process.
| k_ra8_ok | The operation completed successfully. |
| other | The originating validation, storage, stream, or network error. |
Definition at line 264 of file mdl_app_prepare.c.
References k_ra8_ok, priv_mdl_app_context(), priv_mdl_stream_text(), and RA8_INTERNAL.
Referenced by priv_mdl_app_start_session().
| ra8_err_t priv_mdl_app_prepare_chapters | ( | const mdl_site_t * | site, |
| const char * | series_url, | ||
| uint32_t | timeout, | ||
| mdl_cache_t * | cache ) |
Fetch a series page and build its ordered chapter list.
Fetch and extract a series' bounded chapter list.
Enforces session policy, extracts descriptor metadata and anchors, then filters cross-series links and applies configured ordering.
| [in] | site | Validated site descriptor. |
| [in] | series_url | Absolute series page URL. |
| [in] | timeout | Per-request timeout in milliseconds. |
| [in,out] | cache | Bound persistent HTTP cache and index workspace. |
| k_ra8_ok | Metadata and chapter rows were prepared. |
| k_ra8_fail | Session policy refused the series URL. |
| k_ra8_err_invalid_size | A configured prefix or extracted field exceeded its bound. |
| other | Fetch, extraction, validation, or ordering failed. |
site and series_url are non-NULL. timeout is nonzero. Definition at line 547 of file mdl_app_prepare.c.
References mdl_site_t::chapter_url_contains, internal_extract_series_metadata(), internal_prepare_cache_fetch(), internal_prepare_filter_chapters(), k_ra8_fail, k_ra8_ok, mdl_cache_get_buf(), mdl_extract_anchors(), mdl_session_url_allowed(), priv_mdl_app_context(), priv_mdl_app_report_cache(), RA8_PRIV, mdl_app_context_t::session, and mdl_session_t::user_agent.
Referenced by internal_run_series_network().
| bool priv_mdl_app_prepare_series_dir | ( | const char * | out_dir, |
| const char * | series_url, | ||
| char * | slug, | ||
| size_t | slug_cap, | ||
| char * | abs_dir ) |
Create and resolve a series directory beneath an output root.
Prepare a contained canonical directory for one series.
Derives the bounded URL slug, joins it under the canonical output root, creates both directories as needed, rejects a symbolic-link leaf, and proves the resolved series path remains contained.
| [in] | out_dir | Output library root. |
| [in] | series_url | Absolute series URL used to derive the slug. |
| [out] | slug | Destination for the series slug. |
| [in] | slug_cap | Writable capacity of slug. |
| [out] | abs_dir | Destination for the canonical directory path. |
| true | slug and abs_dir contain complete results. |
| false | Joining, creation, or canonicalization failed. |
abs_dir. Definition at line 657 of file mdl_app_prepare.c.
References internal_prepare_diag3(), k_fw_fs_path_cap, k_ra8_ok, mdl_join_dir_under(), mdl_urlname_last_segment(), priv_mdl_app_context(), priv_mdl_app_storage_ensure_directory(), RA8_PRIV, and mdl_app_context_t::storage.
Referenced by internal_run_series_paths().
| ra8_err_t priv_mdl_app_report_cache | ( | const char * | url, |
| const mdl_cache_result_t * | result ) |
Report verified cache reuse with its pre-request staleness.
Report corruption recovery or verified cache reuse with staleness.
| [in] | url | Exact cached URL. |
| [in] | result | Completed cache outcome. |
Definition at line 61 of file mdl_app_prepare.c.
References mdl_cache_result_t::age_seconds, mdl_cache_result_t::body_reused, mdl_app_context_t::diagnostic, mdl_cache_result_t::index_rebuilt, k_ra8_ok, mdl_cache_result_t::observed_status, priv_mdl_app_context(), priv_mdl_stream_text(), priv_mdl_stream_u64(), and RA8_PRIV.
Referenced by internal_cover_cached(), and priv_mdl_app_prepare_chapters().
| ra8_err_t priv_mdl_app_start_session | ( | mdl_net_iface_t * | net, |
| const mdl_run_opts_t * | opts, | ||
| const char * | cfg_contact, | ||
| char * | ua, | ||
| size_t | ua_cap ) |
Initialize the shared network session identity for one run.
Initialize one bounded network-policy session.
Applies CLI-over-descriptor contact precedence and builds the bounded user agent before configuring robots enforcement.
| [in,out] | net | Initialized network interface. |
| [in] | opts | Validated run policy. |
| [in] | cfg_contact | Optional descriptor contact string. |
| [out] | ua | User-agent buffer. |
| [in] | ua_cap | Writable capacity of ua. |
net, opts, and ua are non-NULL. ua_cap is the true writable user-agent capacity. net and the completed identity. Definition at line 612 of file mdl_app_prepare.c.
References mdl_run_opts_t::contact, mdl_run_opts_t::honor_robots, internal_warn_no_contact(), k_ra8_ok, mdl_session_build_ua(), mdl_session_init(), priv_mdl_app_context(), and RA8_PRIV.
Referenced by internal_fetch_artifact(), internal_run_series_network(), mdl_app_run_discover(), and mdl_app_run_page().
|
static |
Scratch row used while reordering the prepared chapter list.
Definition at line 88 of file mdl_app_prepare.c.
Referenced by internal_swap_rows().