ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
mdl_config.h File Reference

Per-site descriptor loaded from a flat key=value config file. More...

#include <stddef.h>
#include <stdint.h>
#include "mdl_politeness.h"
#include "mdl_storage.h"
#include "ra8_err.h"
Include dependency graph for mdl_config.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mdl_site_t
 One site's scraping rules (all data, no logic). More...

Enumerations

enum  mdl_chapter_order_t : uint8_t {
  k_mdl_order_doc = 0 ,
  k_mdl_order_reverse = 1 ,
  k_mdl_order_asc = 2
}
 How to order chapters extracted from a series page. More...
enum  mdl_config_limits_t : uint16_t {
  k_mdl_name_max = 64 ,
  k_mdl_host_max = 128 ,
  k_mdl_kind_max = 16 ,
  k_mdl_match_max = 128 ,
  k_mdl_attr_max = 16 ,
  k_mdl_contact_max = 128 ,
  k_mdl_search_url_max = 256
}
 Fixed field sizes for a site descriptor. More...

Functions

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.

Detailed Description

Per-site descriptor loaded from a flat key=value config file.

Replaces the Kotlin original's hardcoded when(host) branches: adding a site is dropping in a .conf file, no rebuild. v1 is a deliberately small flat key=value format (# comments, [section] lines ignored) parsed into a fixed-size struct – zero dynamic allocation, every field bounded, so the same descriptor model ports to the RA8 unchanged. The richer TOML schema is a later milestone; this proves the data-driven approach end to end.

Definition in file mdl_config.h.

Enumeration Type Documentation

◆ mdl_chapter_order_t

enum mdl_chapter_order_t : uint8_t

How to order chapters extracted from a series page.

Enumerator
k_mdl_order_doc 

Keep document order.

k_mdl_order_reverse 

Reverse document order (newest-first -> old).

k_mdl_order_asc 

Sort by the number parsed from the URL.

Definition at line 25 of file mdl_config.h.

◆ mdl_config_limits_t

enum mdl_config_limits_t : uint16_t

Fixed field sizes for a site descriptor.

Enumerator
k_mdl_name_max 

Site display name bytes.

k_mdl_host_max 

Host bytes.

k_mdl_kind_max 

"manga"/"manhwa"/... bytes.

k_mdl_match_max 

Selector/substring field bytes.

k_mdl_attr_max 

Image attribute name bytes.

k_mdl_contact_max 

Operator contact string bytes.

k_mdl_search_url_max 

Search/browse URL template bytes.

Definition at line 32 of file mdl_config.h.

Function Documentation

◆ mdl_config_apply_polite()

void mdl_config_apply_polite ( mdl_site_t * site)

Raise a descriptor's per-request delay floors for --polite.

The --polite opt-in lifts the per-image and inter-chapter jitter floors to cautious minimums (never lowering a site that is already slower). Shared by the series and discovery paths so both interpret --polite the same way.

Parameters
[in,out]siteDescriptor whose delay floors are raised in place.
Returns
Nothing.
Precondition
site is non-NULL and was populated by mdl_config_load.
The caller applies this only when --polite was requested.
Postcondition
Each delay floor is at least its polite minimum.
A floor already above its polite minimum is left unchanged.
Note
Not thread-safe: mutates site in place.
Since
0.1.0

Definition at line 625 of file mdl_config.c.

References mdl_site_t::chapter_delay_max, mdl_site_t::chapter_delay_min, mdl_site_t::img_delay_max, mdl_site_t::img_delay_min, internal_config_max_u32(), k_polite_chap_max_ms, k_polite_chap_min_ms, k_polite_img_max_ms, and k_polite_img_min_ms.

Referenced by mdl_app_run_discover(), and mdl_app_run_series().

◆ mdl_config_gov_cfg()

mdl_gov_cfg_t mdl_config_gov_cfg ( const mdl_site_t * site)

Build the politeness-governor tunables for a loaded site descriptor.

Overlays the descriptor's governor fields (rate/burst/backoff/in-flight) onto the conservative mdl_gov_cfg_default baseline, so every run mode – series download, discovery, library update – derives its governor identically from one place rather than re-copying the same six assignments.

Parameters
[in]siteLoaded descriptor (never NULL).
Returns
The governor configuration for site.
Return values
(byvalue) Defaults with the descriptor's governor fields applied.
Precondition
site is non-NULL and was populated by mdl_config_load.
The caller passes the result to a governor init function.
Postcondition
burst >= 1 and max_inflight >= 1 (the init function clamps).
site is unchanged.
Note
Thread-safe: depends only on its argument.
See also
mdl_governor_init
Since
0.1.0

Definition at line 594 of file mdl_config.c.

References mdl_gov_cfg_t::backoff_base_ms, mdl_site_t::backoff_base_ms, mdl_gov_cfg_t::backoff_max_ms, mdl_site_t::backoff_max_ms, mdl_gov_cfg_t::burst, mdl_site_t::burst, mdl_gov_cfg_t::max_inflight, mdl_site_t::max_inflight, mdl_gov_cfg_default(), mdl_gov_cfg_t::rate_per_min, and mdl_site_t::rate_per_min.

Referenced by internal_run_prepared(), and mdl_app_run_discover().

◆ mdl_config_load()

ra8_err_t mdl_config_load ( mdl_storage_t * storage,
const char * path,
mdl_site_t * out )
nodiscard

Load a site descriptor from a flat key=value file.

Parameters
[in,out]storageInitialized portable filesystem binding and exclusive file/I/O workspace.
[in]pathCanonical path beneath the bound filesystem root.
[out]outDescriptor to fill; defaults are applied first, then the file overrides recognised keys.
Return values
k_ra8_okLoaded and every key/value passed validation.
k_ra8_err_invalid_argInvalid binding, pointer, or path.
k_ra8_err_invalid_sizeDescriptor or backend progress bound exceeded.
k_ra8_err_invalid_stateA line, key, value, or required field was invalid.
otherOpen, size, read, or close error propagated by the filesystem.
Precondition
storage was initialized by mdl_storage_init and is exclusively owned.
path is canonical under the injected binding (for example /sites/a.conf).
Postcondition
The portable file handle is consumed on every successful open path, including parse and close failures.
Success publishes a complete validated descriptor in out.
Note
Not thread-safe for a shared storage binding.
Since
0.1.0

Definition at line 557 of file mdl_config.c.

References internal_config_reader_t::file, mdl_storage_t::file_workspace, mdl_storage_t::file_workspace_bytes, mdl_storage_t::fs, fw_fs_close(), fw_fs_file_size(), fw_fs_open(), internal_config_parse(), internal_config_set_defaults(), internal_config_valid(), mdl_storage_t::io_buffer, mdl_storage_t::io_buffer_bytes, k_config_file_max, k_fw_fs_open_read, k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_err_invalid_state, k_ra8_ok, and fw_fs_t::streams.

Referenced by mdl_app_run_discover(), and mdl_app_run_series().