24typedef enum : uint16_t {
74 return (n >= 0) && ((size_t)n < cap);
96 if (meta !=
nullptr) {
179 return (output_error ==
k_ra8_ok) ? 0U : 1U;
184 const char* series_dir,
205 const int ln = snprintf(leaf,
sizeof(leaf),
"%s.%s", chap_id, ext);
222 return (output_error ==
k_ra8_ok) ? 0U : 1U;
227 const char* series_dir,
233 return mdl_pack_one_meta(storage, format, series_dir, chap_id,
nullptr, ws, output, diagnostic);
306 return (output_error ==
k_ra8_ok) ? 0U : 1U;
335 const char* series_dir,
336 const char* combined_rel,
344 const char* mark = incomplete ?
" (INCOMPLETE)" :
"";
346 if (!
mdl_path_join(series_dir, combined_rel, dir,
sizeof(dir))) {
366 const int ln = incomplete ? snprintf(leaf,
sizeof(leaf),
"%s.INCOMPLETE.%s", combined_rel, ext)
367 : snprintf(leaf,
sizeof(leaf),
"%s.%s", combined_rel, ext);
383 return (output_error ==
k_ra8_ok) ? 0U : 1U;
388 bool allow_incomplete,
389 const char* series_dir,
390 const char* combined_rel,
402 if (!allow_incomplete) {
405 " combine: NOT packaged -- run is "
412 " page(s) failed); pass --allow-incomplete to force "
413 "a marked archive\n");
414 return (output_error ==
k_ra8_ok) ? 0U : 1U;
430 bool allow_incomplete,
431 const char* series_dir,
432 const char* combined_rel,
Package a downloaded chapter folder into a reader-openable container.
bool mdl_format_is_dir_output(mdl_format_t fmt)
Whether fmt writes per-page sibling files rather than one container.
struct mdl_export_workspace mdl_export_workspace_t
Caller-owned bounded arena for all exporter scratch state.
const char * mdl_format_ext(mdl_format_t fmt)
File extension (without dot) for a format, e.g.
ra8_err_t mdl_export_chapter_meta_ws(mdl_storage_t *storage, mdl_format_t fmt, const char *chapter_dir, const char *out_path, const mdl_export_meta_t *meta, mdl_export_workspace_t *ws)
Package a chapter with explicit metadata and caller-owned workspace.
ra8_err_t mdl_meta_load_dir(mdl_storage_t *storage, mdl_export_meta_t *meta, const char *dir)
Load metadata from a directory by looking for metadata files.
bool priv_mdl_fetch_run_incomplete(const mdl_fetch_stats_t *stats)
Whether a finished run left anything unfetched (chapter or page).
State-aware chapter/page download orchestrator for the media downloader.
Module-private fetch-loop decisions promoted for host unit tests and the CLI's end-of-run reporting.
static void internal_pack_report_failure(ra8_io_stream_t *diagnostic, const char *chap_id, const char *ext, ra8_err_t rc)
Report one chapter's export failure with its error code.
static size_t internal_pack_dir_output(mdl_storage_t *storage, mdl_format_t format, const char *dir, const char *chap_id, const char *ext, const mdl_export_meta_t *meta, mdl_export_workspace_t *ws, ra8_io_stream_t *output, ra8_io_stream_t *diagnostic)
Package one chapter into a directory-output format (e.g.
static size_t internal_pack_combined_dir(mdl_storage_t *storage, mdl_format_t format, const char *series_dir, const char *combined_rel, bool incomplete, const mdl_export_meta_t *meta, mdl_export_workspace_t *ws, ra8_io_stream_t *output, ra8_io_stream_t *diagnostic)
Package a combined chapter folder into the selected format.
size_t mdl_pack_one(mdl_storage_t *storage, mdl_format_t format, const char *series_dir, const char *chap_id, mdl_export_workspace_t *ws, ra8_io_stream_t *output, ra8_io_stream_t *diagnostic)
Package one downloaded chapter folder into format.
mdl_pack_size_t
Path buffer sizes for a composed archive leaf and directory.
@ k_pack_leaf_bytes
Composed archive/dir leaf name.
@ k_pack_dir_bytes
Directory-path buffer.
size_t mdl_pack_combined_meta(mdl_storage_t *storage, mdl_format_t format, bool allow_incomplete, const char *series_dir, const char *combined_rel, const mdl_fetch_stats_t *stats, const mdl_export_meta_t *meta, mdl_export_workspace_t *ws, ra8_io_stream_t *output, ra8_io_stream_t *diagnostic)
Package a combined page folder into format with rich metadata.
static mdl_export_meta_t internal_pack_metadata(mdl_storage_t *storage, const mdl_export_meta_t *meta, const char *dir)
Copy explicit metadata or load it from a combined directory.
static size_t internal_pack_combined_dir_output(mdl_storage_t *storage, mdl_format_t format, const char *dir, const char *ext, const char *mark, const mdl_export_meta_t *meta, mdl_export_workspace_t *ws, ra8_io_stream_t *output, ra8_io_stream_t *diagnostic)
Combine-package one directory into a directory-output format.
static void internal_pack_report_combine_failure(ra8_io_stream_t *diagnostic, ra8_err_t rc)
Report a combine-export failure with its error code.
static bool internal_pack_snprintf_fit(int n, size_t cap)
Test whether an snprintf result fully fit its destination.
size_t mdl_pack_combined(mdl_storage_t *storage, mdl_format_t format, bool allow_incomplete, const char *series_dir, const char *combined_rel, const mdl_fetch_stats_t *stats, mdl_export_workspace_t *ws, ra8_io_stream_t *output, ra8_io_stream_t *diagnostic)
Package a combined page directory when completion policy permits.
size_t mdl_pack_one_meta(mdl_storage_t *storage, mdl_format_t format, const char *series_dir, const char *chap_id, const mdl_export_meta_t *meta, mdl_export_workspace_t *ws, ra8_io_stream_t *output, ra8_io_stream_t *diagnostic)
Package one downloaded chapter folder into format with rich metadata.
static ra8_err_t internal_pack_text3(ra8_io_stream_t *stream, const char *first, const char *second, const char *third)
Append three borrowed packaging fragments to one stream.
Archive packaging of downloaded page folders for the mdl CLI.
Neutralise untrusted names before they reach a filesystem or XML sink.
bool mdl_path_join(const char *parent, const char *seg, char *out, size_t cap)
Join one safe child segment under a parent directory path.
ra8_err_t priv_mdl_stream_hex(ra8_err_t prior, ra8_io_stream_t *stream, uint32_t value)
Append one hexadecimal error/status value after prior success.
ra8_err_t priv_mdl_stream_text(ra8_err_t prior, ra8_io_stream_t *stream, const char *text)
Append text unless an earlier operation already failed.
ra8_err_t priv_mdl_stream_u64(ra8_err_t prior, ra8_io_stream_t *stream, uint64_t value)
Append one unsigned integer unless an earlier append failed.
Private bounded text helpers over the portable byte-stream contract.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Tallies a fetch run reports back (all zero-initialised by the run).
size_t chapters_completed
Chapters finished (all pages present) this run.
size_t chapters_failed
Chapters left partial by a page failure.
size_t pages_failed
Page fetches that failed or robots refused.
One non-reentrant downloader filesystem dependency bundle.
Caller-allocated byte-stream handle binding a sink to its context.