71 "mdl: network init failed\n");
89 .term = request->
term,
101 if ((rc != 0) || (picked[0] ==
'\0')) {
105 run.series_url = picked;
132 const char* descriptor_dir,
138 if ((url ==
nullptr) || (url[0] ==
'\0') || (descriptor_dir ==
nullptr) ||
139 (descriptor_dir[0] !=
'/')) {
142 "mdl: --init-site requires a URL\n");
147 "mdl: --init-site could not extract host from '",
152 const char* hptr = (
strncmp(host,
"www.", 4) == 0) ? host + 4 : host;
154 for (; (hptr[i] !=
'\0') && (hptr[i] !=
'.') && (i + 1U <
k_mdl_name_max); ++i) {
158 if (slug[0] ==
'\0') {
162 if ((name[0] >=
'a') && (name[0] <=
'z')) {
163 name[0] = (char)(name[0] -
'a' +
'A');
166 const int leaf_bytes = snprintf(leaf,
sizeof(leaf),
"%s.conf", slug);
167 return (leaf_bytes > 0) && ((size_t)leaf_bytes <
sizeof(leaf)) &&
183 "mdl: descriptor directory is unsafe '",
192 "mdl: refusing to overwrite existing site descriptor '",
199 "mdl: failed to publish site descriptor '",
213 " to tune scraping selectors, then test with:\n mdl --config ");
265 " [CORRUPT ARTIFACT] ",
267 " (not a regular file)\n");
330 bool present =
false;
332 if ((error !=
k_ra8_ok) || !present) {
335 if (entry.
name[0] ==
'.') {
345 " [VERIFY FAIL] cannot finish reading ",
380 const int pn = snprintf(page_path,
sizeof(page_path),
"%s/%s", series_dir, rec->
rel_path);
382 if ((pn < 0) || ((
size_t)pn >=
sizeof(page_path)) ||
386 " [MISSING/UNSAFE] ",
401 " (hash mismatch)\n");
440 ": .mdl_state file unreadable or corrupt\n");
485 bool present =
false;
487 if ((error !=
k_ra8_ok) || !present) {
496 bool marker_exists =
false;
498 !
mdl_path_join(child,
".mdl_state", child_state,
sizeof(child_state)) ||
556 const char* dir = target_dir;
559 if ((dir ==
nullptr) || (dir[0] !=
'/') ||
563 "mdl: verify target '",
564 (dir !=
nullptr) ? dir :
"",
565 "' is not a readable directory\n");
569 bool state_exists =
false;
570 if (
mdl_path_join(dir,
".mdl_state", state_path,
sizeof(state_path)) &&
588 "mdl: no tracked series or recognized artifacts under '",
ra8_err_t fw_fs_stat(const fw_fs_namespace_t *names, const char *path, fw_fs_stat_t *out)
Query a path; a miss is success with out->exists == false.
ra8_err_t fw_fs_dir_next(fw_fs_dir_t *directory, fw_fs_dirent_value_t *out, bool *out_entry)
Copy one stable directory entry from an open cursor.
ra8_err_t fw_fs_dir_close(fw_fs_dir_t *directory)
Close and consume an open directory cursor, including on close error.
ra8_err_t fw_fs_dir_open(const fw_fs_namespace_t *names, const char *path, fw_fs_dir_t *directory, void *workspace, uint32_t workspace_size)
Open one directory cursor into caller-owned backend workspace.
@ k_fw_fs_node_directory
Directory.
@ k_fw_fs_node_file
Regular byte stream.
@ k_fw_fs_path_cap
Largest portable path including its NUL.
mdl_app_context_t * priv_mdl_app_context(void)
The working set the composition root bound with mdl_app_bind.
int mdl_app_run_series(const mdl_series_run_t *run)
Execute one prepared series download.
int mdl_app_run_discover(const mdl_discover_run_t *request, const mdl_run_opts_t *opts, const mdl_series_run_t *base)
Run search or browse discovery and optionally download one result.
static bool internal_verify_page_rec(const char *series_dir, const mdl_page_rec_t *rec, verify_stats_t *st)
Verify one tracked page's presence and content hash.
static void internal_verify_artifacts(const char *dir, verify_stats_t *st)
Structurally validate recognized artifacts in one directory.
static void internal_verify_artifact_entry(const char *dir, const fw_fs_dirent_value_t *entry, verify_stats_t *st)
Classify one recognized artifact directory entry.
static void internal_admin_latch(ra8_err_t error)
Latch the first administration presenter failure.
static void internal_verify_series_dir(const char *series_dir, const char *state_path, verify_stats_t *st)
Verify persisted pages and artifacts for one tracked series.
int mdl_app_run_verify(const char *target_dir)
Verify one library or artifact tree without mutating it.
int mdl_app_run_init_site(const char *url, const char *descriptor_dir)
Create a starter descriptor for one validated site URL.
static bool internal_init_site_identity(const char *url, const char *descriptor_dir, char *host, char *slug, char *name, char *out_path)
Derive bounded descriptor identity and destination fields.
static void internal_verify_library_root(const char *canonical, verify_stats_t *stats)
Verify root-level artifacts and every tracked child series.
static ra8_err_t internal_verify_print_summary(ra8_io_stream_t *output, const verify_stats_t *st)
Stream the verification totals summary line.
static mdl_hit_list_t s_results
Bounded titled discovery hits for the active query.
static void internal_admin_text3(ra8_io_stream_t *stream, const char *first, const char *second, const char *third)
Append three borrowed administration fragments and latch failure.
Module-private contract shared by the application-mode translation units.
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 one bounded network-policy session.
@ k_leaf_name_bytes
Composed archive/dir leaf name.
ra8_err_t priv_mdl_app_storage_ensure_directory(mdl_storage_t *storage, const char *path)
Ensure one canonical portable path names a real directory.
ra8_err_t priv_mdl_app_storage_publish_site(mdl_storage_t *storage, const char *destination, const char *url, const char *host, const char *name)
Render and create one starter site descriptor transactionally.
ra8_err_t mdl_config_load(mdl_storage_t *storage, const char *path, mdl_site_t *out)
Load a site descriptor from a flat key=value file.
mdl_gov_cfg_t mdl_config_gov_cfg(const mdl_site_t *site)
Build the politeness-governor tunables for a loaded site descriptor.
void mdl_config_apply_polite(mdl_site_t *site)
Raise a descriptor's per-request delay floors for --polite.
@ k_mdl_host_max
Host bytes.
@ k_mdl_name_max
Site display name bytes.
int mdl_discover_run(const mdl_discover_req_t *req, size_t pick, char *out_url, size_t out_cap)
Run one search/browse discovery: fetch, parse, present, and select.
@ k_mdl_discover_browse
browse_url latest-updates page, no term.
@ k_mdl_discover_search
search_url with a {q} term substitution.
ra8_err_t mdl_hash_file(mdl_storage_t *storage, const char *path, uint64_t *out)
FNV-1a 64 hash of a file's full contents.
void mdl_net_destroy(mdl_net_iface_t *net)
Deinitialise a caller-owned network interface.
ra8_err_t mdl_net_provider_open(const mdl_net_provider_t *provider, const mdl_net_policy_t *policy, mdl_net_iface_t *out_net)
Open a transport through an injected provider.
void mdl_governor_init(mdl_governor_t *g, const mdl_gov_cfg_t *cfg, uint64_t seed)
Initialise a governor on the real host clock and blocking sleep.
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.
@ k_mdl_ua_max
Built User-Agent buffer bytes.
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.
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.
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.
bool mdl_url_host(const char *url, char *out, size_t cap)
Extract the authority (host and optional port) from an http(s) URL.
ra8_err_t mdl_verify_file(mdl_storage_t *storage, mdl_format_t format, const char *path, mdl_export_workspace_t *workspace, mdl_verify_report_t *report)
Validate a completed artifact using caller-owned scratch only.
bool mdl_format_is_verifiable(mdl_format_t format)
Report whether a format has an in-process structural validator.
ra8_err_t mdl_format_from_path(const char *path, mdl_format_t *out_format)
Infer an artifact format from its complete path suffix.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_err_exists
Item already exists – cannot create again.
@ 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.
int strncmp(const char *s1, const char *s2, size_t n)
Compare two strings up to a specified length.
Caller-owned open directory cursor; fields are private to the facade.
Stable caller-owned value returned by fw_fs_dir_next.
fw_fs_node_type_t type
Entry kind.
char name[k_fw_fs_path_cap]
Copied NUL-terminated leaf.
Result of a portable metadata query.
bool exists
False means a clean lookup miss.
fw_fs_node_type_t type
Kind of node at the path.
mdl_session_t session
Network policy session.
ra8_io_stream_t * output
Borrowed command output sink.
ra8_err_t io_error
First presenter sink failure.
ra8_io_stream_t * diagnostic
Borrowed diagnostic sink.
char page[k_page_buf_bytes]
Whole-page HTML buffer.
mdl_state_t state
Persistent tracked state.
Injected dependencies and inputs for one discovery run.
One search or browse request against a configured site descriptor.
const char * term
Search term; unused when browsing.
uint32_t timeout
Per-request budget, ms.
const char * cfg_path
Site descriptor path.
bool browse
Browse latest updates instead of search.
size_t pick
1-based hit to download; 0 lists only.
uint64_t seed
Governor jitter seed.
Per-site politeness tunables the governor is initialised with.
Closed-loop per-host politeness governor (rate + backoff + concurrency).
Bounded list of titled hits plus the raw anchor tally.
A network backend handle: an immutable method table plus its state.
One page's dedup/verify record in the series-wide pool.
uint64_t content_hash
FNV-1a 64 of the fetched bytes.
char rel_path[k_mdl_relpath_max]
Path under the series directory.
Cross-cutting policy and injected transport threaded into every mode.
mdl_net_policy_t policy
Backend security policy.
bool polite
True to raise per-host delays.
const mdl_net_provider_t * net
Injected transport factory.
Parameters of one series download, as values rather than arguments.
One site's scraping rules (all data, no logic).
char contact[k_mdl_contact_max]
Operator contact for the UA.
uint32_t page_rec_count
Page records recorded.
mdl_page_rec_t pages[k_mdl_max_page_recs]
Per-page identities.
Caller-allocated byte-stream handle binding a sink to its context.
Stats accumulated during a library/series verification run.
size_t pages_corrupt
Page files failing hash match.
size_t archives_corrupt
Archive files empty/corrupt.
size_t archives_checked
Archive files checked.
size_t pages_missing
Page files missing from disk.
size_t fs_errors
Directory/path operations that failed.
size_t state_errors
State files that could not be parsed.
size_t archives_valid
Structurally valid artifacts.
size_t pages_valid
Pages matching content hash on disk.
size_t series_checked
Tracked series verified.