|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Bounded image/anchor URL scanning and relative-URL resolution. More...
#include "mdl_extract.h"#include <stdio.h>#include <string.h>#include "ra8_attributes.h"#include "mdl_extract_internal.h"Go to the source code of this file.
Enumerations | |
| enum | mdl_scan_limits_t : uint16_t { k_authority_max = 512 } |
| Local scan/resolve limits. More... | |
Functions | |
| static bool | internal_authority_of (const char *base, char *auth, size_t cap) |
| Extract "scheme://host" from base into auth (NUL-terminated). | |
| static bool | internal_resolve_scheme_rel (const char *base, const char *raw, char *out, size_t out_cap) |
| Resolve a scheme-relative ("//host/...") URL against base. | |
| static bool | internal_resolve_root_rel (const char *auth, const char *raw, char *out, size_t out_cap) |
| Resolve a root-relative ("/path") URL against authority auth. | |
| static bool | internal_resolve_path_rel (const char *base, const char *auth, const char *raw, char *out, size_t out_cap) |
| Resolve a path-relative URL against base (authority auth). | |
| bool | mdl_extract_resolve_url (const char *base, const char *raw, char *out, size_t out_cap) |
| Resolve raw (possibly relative) against base into out. | |
| static bool | internal_already_have (const mdl_url_list_t *list, const char *url) |
| True if url is already present in list. | |
| static ra8_err_t | internal_emit_tag_url (const char *base_url, const char *attr1, const char *attr2, const char *keep, const char *tag, size_t tag_len, mdl_url_list_t *out) |
| Read attr1 (or attr2) from one tag, resolve+filter, append. | |
| static ra8_err_t | internal_scan_tags (const char *html, size_t html_len, const char *base_url, const char *tagname, const char *attr1, const char *attr2, const char *keep, mdl_url_list_t *out) |
| Shared scanner for <img>/<a>: emit each tag's resolved URL. | |
| ra8_err_t | mdl_extract_images (const char *html, size_t html_len, const char *base_url, const char *prefer_attr, const char *url_contains, mdl_url_list_t *out) |
| Scan html for <img> image URLs, resolved to absolute form. | |
| ra8_err_t | mdl_extract_anchors (const char *html, size_t html_len, const char *base_url, const char *href_contains, mdl_url_list_t *out) |
| Scan html for <a href> links, resolved to absolute form. | |
Bounded image/anchor URL scanning and relative-URL resolution.
Resolves absolute and relative URL forms, then scans bounded image or anchor tags into caller-owned URL lists. Titled-anchor extraction is isolated in mdl_extract_hits.c.
Definition in file mdl_extract.c.
| enum mdl_scan_limits_t : uint16_t |
Local scan/resolve limits.
| Enumerator | |
|---|---|
| k_authority_max | Max bytes of "scheme://host" prefix. |
Definition at line 18 of file mdl_extract.c.
|
static |
True if url is already present in list.
Scans caller-supplied markup and URLs without allocation. Only fully resolved values that fit bounded result storage are appended.
| [in] | list | Existing bounded URL list. |
| [in] | url | NUL-terminated URL input. |
url already occurs in list. | true | The documented predicate holds or the requested operation completed. |
| false | The predicate does not hold or validation rejected the operation. |
Definition at line 208 of file mdl_extract.c.
References mdl_url_list_t::count, RA8_INTERNAL, strcmp(), and mdl_url_list_t::urls.
Referenced by internal_emit_tag_url().
|
static |
Extract "scheme://host" from base into auth (NUL-terminated).
Scans caller-supplied markup and URLs without allocation. Only fully resolved values that fit bounded result storage are appended.
| [in] | base | NUL-terminated base URL or path. |
| [in,out] | auth | Bounded authority string. |
| [in] | cap | Destination capacity including any terminator. |
auth; otherwise false. | true | The documented predicate holds or the requested operation completed. |
| false | The predicate does not hold or validation rejected the operation. |
Definition at line 40 of file mdl_extract.c.
References memcpy(), RA8_INTERNAL, strchr(), strlen(), and strstr().
Referenced by mdl_extract_resolve_url().
|
static |
Read attr1 (or attr2) from one tag, resolve+filter, append.
| k_ra8_ok | Appended, filtered out, or attr absent (all non-fatal). |
| k_ra8_err_no_mem | List already at k_mdl_max_urls. |
Scans caller-supplied markup and URLs without allocation. Only fully resolved values that fit bounded result storage are appended.
| [in] | base_url | NUL-terminated base URL. |
| [in] | attr1 | Preferred attribute name. |
| [in] | attr2 | Fallback attribute name, if any. |
| [in] | keep | Optional substring filter. |
| [in] | tag | Readable tag byte span. |
| [in] | tag_len | Readable tag length. |
| [out] | out | Caller-owned result storage. |
Definition at line 240 of file mdl_extract.c.
References abs(), mdl_url_list_t::count, internal_already_have(), internal_contains_ok(), internal_copy_fits(), internal_find_attr_value(), k_mdl_max_urls, k_mdl_url_max, k_ra8_err_no_mem, k_ra8_ok, mdl_extract_resolve_url(), RA8_INTERNAL, and mdl_url_list_t::urls.
Referenced by internal_scan_tags().
|
static |
Resolve a path-relative URL against base (authority auth).
Scans caller-supplied markup and URLs without allocation. Only fully resolved values that fit bounded result storage are appended.
| [in] | base | NUL-terminated base URL or path. |
| [in] | auth | Bounded authority string. |
| [in] | raw | Untrusted source text to validate or resolve. |
| [out] | out | Caller-owned result storage. |
| [in] | out_cap | Destination capacity including any terminator. |
out. | true | The documented predicate holds or the requested operation completed. |
| false | The predicate does not hold or validation rejected the operation. |
Definition at line 134 of file mdl_extract.c.
References memcpy(), RA8_INTERNAL, and strlen().
Referenced by mdl_extract_resolve_url().
|
static |
Resolve a root-relative ("/path") URL against authority auth.
Scans caller-supplied markup and URLs without allocation. Only fully resolved values that fit bounded result storage are appended.
| [in] | auth | Bounded authority string. |
| [in] | raw | Untrusted source text to validate or resolve. |
| [out] | out | Caller-owned result storage. |
| [in] | out_cap | Destination capacity including any terminator. |
out. | true | The documented predicate holds or the requested operation completed. |
| false | The predicate does not hold or validation rejected the operation. |
Definition at line 106 of file mdl_extract.c.
Referenced by mdl_extract_resolve_url().
|
static |
Resolve a scheme-relative ("//host/...") URL against base.
Scans caller-supplied markup and URLs without allocation. Only fully resolved values that fit bounded result storage are appended.
| [in] | base | NUL-terminated base URL or path. |
| [in] | raw | Untrusted source text to validate or resolve. |
| [out] | out | Caller-owned result storage. |
| [in] | out_cap | Destination capacity including any terminator. |
out. | true | The documented predicate holds or the requested operation completed. |
| false | The predicate does not hold or validation rejected the operation. |
Definition at line 75 of file mdl_extract.c.
References memcpy(), strlen(), and strstr().
Referenced by mdl_extract_resolve_url().
|
static |
Shared scanner for <img>/<a>: emit each tag's resolved URL.
Scans caller-supplied markup and URLs without allocation. Only fully resolved values that fit bounded result storage are appended.
| [in] | html | Readable markup bytes. |
| [in] | html_len | Readable markup length. |
| [in] | base_url | NUL-terminated base URL. |
| [in] | tagname | Tag-name prefix to scan for. |
| [in] | attr1 | Preferred attribute name. |
| [in] | attr2 | Fallback attribute name, if any. |
| [in] | keep | Optional substring filter. |
| [out] | out | Caller-owned result storage. |
| k_ra8_ok | The operation completed successfully. |
| other | The originating validation, storage, stream, or network error. |
Definition at line 292 of file mdl_extract.c.
References mdl_url_list_t::count, internal_emit_tag_url(), internal_find_ci(), internal_is_name_end(), k_ra8_err_invalid_arg, k_ra8_err_no_mem, k_ra8_ok, memchr(), RA8_INTERNAL, and strlen().
Referenced by mdl_extract_anchors(), and mdl_extract_images().
| ra8_err_t mdl_extract_anchors | ( | const char * | html, |
| size_t | html_len, | ||
| const char * | base_url, | ||
| const char * | href_contains, | ||
| mdl_url_list_t * | out ) |
Scan html for <a href> links, resolved to absolute form.
| [in] | html | HTML bytes (need not be NUL-terminated). |
| [in] | html_len | Length of html in bytes. |
| [in] | base_url | Absolute URL of the page. |
| [in] | href_contains | If non-NULL and non-empty, keep only hrefs whose absolute URL contains this substring. |
| [out] | out | List to fill; out->count is reset first. |
| k_ra8_ok | Scan complete (count may be 0). |
| k_ra8_err_invalid_arg | NULL argument. |
| k_ra8_err_no_mem | Reached k_mdl_max_urls; remainder skipped. |
Uses caller-owned fixed-capacity results and performs no allocation. Inputs stay borrowed and appended values are complete and terminated.
Definition at line 342 of file mdl_extract.c.
References internal_scan_tags().
Referenced by priv_mdl_app_prepare_chapters().
| ra8_err_t mdl_extract_images | ( | const char * | html, |
| size_t | html_len, | ||
| const char * | base_url, | ||
| const char * | prefer_attr, | ||
| const char * | url_contains, | ||
| mdl_url_list_t * | out ) |
Scan html for <img> image URLs, resolved to absolute form.
| [in] | html | HTML bytes (need not be NUL-terminated). |
| [in] | html_len | Length of html in bytes. |
| [in] | base_url | Absolute URL of the page (for relative resolution). |
| [in] | prefer_attr | "data-src" or "src"; the other is tried as fallback. |
| [in] | url_contains | If non-NULL and non-empty, keep only URLs that contain this substring (drops loaders/ads/nav icons). |
| [out] | out | List to fill; out->count is reset first. |
| k_ra8_ok | Scan complete (count may be 0). |
| k_ra8_err_invalid_arg | NULL argument. |
| k_ra8_err_no_mem | Reached k_mdl_max_urls; remainder skipped. |
Uses caller-owned fixed-capacity results and performs no allocation. Inputs stay borrowed and appended values are complete and terminated.
Definition at line 330 of file mdl_extract.c.
References internal_scan_tags(), and strcmp().
Referenced by internal_extract_page_images(), and internal_mdl_fetch_chapter_html().
| bool mdl_extract_resolve_url | ( | const char * | base, |
| const char * | raw, | ||
| char * | out, | ||
| size_t | out_cap ) |
Resolve raw (possibly relative) against base into out.
Resolve a possibly relative HTTP(S) URL against an absolute base URL.
Definition at line 164 of file mdl_extract.c.
References internal_authority_of(), internal_copy_fits(), internal_resolve_path_rel(), internal_resolve_root_rel(), internal_resolve_scheme_rel(), k_authority_max, and strncmp().
Referenced by internal_emit_hit(), internal_emit_tag_url(), and internal_extract_cover().