|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Pure search/discovery policy: percent-encoding, URL templating, and the zero-vs-broken result classifier. More...
Go to the source code of this file.
Enumerations | |
| enum | mdl_search_const_t : uint8_t { k_hi_nibble_shift = 4U , k_nibble_mask = 0x0FU , k_triplet_len = 3U } |
| Query-encoding constants. More... | |
Functions | |
| const char * | mdl_search_placeholder (void) |
| The {q} placeholder a search-URL template must contain. | |
| static bool | internal_is_unreserved (unsigned char c) |
| True for an RFC 3986 unreserved byte (copied verbatim). | |
| static char | internal_hex_digit (unsigned nibble) |
| Upper-case hex digit for a 0..15 nibble. | |
| bool | mdl_query_encode (const char *term, char *out, size_t cap) |
| Percent-encode a raw query term for safe inclusion in a URL. | |
| bool | mdl_search_build_url (const char *tmpl, const char *encoded_term, char *out, size_t cap) |
| Expand a query-URL template by substituting the encoded term for {q}. | |
| mdl_search_outcome_t | mdl_search_classify (const mdl_hit_list_t *hits) |
| Classify a parsed results page into an honest search outcome. | |
| size_t | mdl_search_filter_series_hits (mdl_hit_list_t *hits, const char *chapter_marker) |
| Remove chapter links and duplicate series URLs from discovery hits. | |
Variables | |
| static const char | s_placeholder [] = "{q}" |
| The {q} placeholder token, kept in one place. | |
Pure search/discovery policy: percent-encoding, URL templating, and the zero-vs-broken result classifier.
Provides bounded query encoding and template expansion plus the result-list policy that distinguishes an honest empty result from changed markup. Filtering compacts caller-owned fixed storage in place and preserves discovery order.
Definition in file mdl_search.c.
| enum mdl_search_const_t : uint8_t |
Query-encoding constants.
| Enumerator | |
|---|---|
| k_hi_nibble_shift | Bits to shift for the high hex nibble. |
| k_nibble_mask | Low-nibble mask. |
| k_triplet_len | Bytes a HH escape occupies. |
Definition at line 20 of file mdl_search.c.
|
static |
Upper-case hex digit for a 0..15 nibble.
Masks to the low nibble before indexing the constant digit table.
| [in] | nibble | Value whose low four bits are encoded. |
| other | One byte from 0-9 or A-F. |
Definition at line 69 of file mdl_search.c.
References k_nibble_mask, and RA8_INTERNAL.
Referenced by mdl_query_encode().
|
static |
True for an RFC 3986 unreserved byte (copied verbatim).
Recognises ASCII alphanumeric bytes and the four unreserved marks.
| [in] | c | Byte to classify. |
| true | The byte is RFC 3986 unreserved. |
| false | The byte requires percent-encoding. |
c is one complete input byte. Definition at line 48 of file mdl_search.c.
References RA8_INTERNAL.
Referenced by mdl_query_encode().
| bool mdl_query_encode | ( | const char * | term, |
| char * | out, | ||
| size_t | cap ) |
Percent-encode a raw query term for safe inclusion in a URL.
RFC 3986 encoding: the unreserved set (A-Z a-z 0-9 - . _ ~) is copied verbatim and every other byte – space, &, #, +, /, ?, and each byte of a multi-byte UTF-8 sequence – is written as HH with upper-case hex. Space becomes %20 (valid in both path and query), never +, so the result is unambiguous wherever the template places it.
| [in] | term | Raw term (may contain UTF-8 bytes), NUL-terminated. |
| [out] | out | Destination buffer for the NUL-terminated encoding. |
| [in] | cap | Capacity of out in bytes. |
out. | true | out holds the fully encoded term. |
| false | A NULL argument, cap == 0, or the encoding did not fit. |
term and out are non-NULL; out has room for cap bytes. out contains only unreserved bytes and HH triplets.Definition at line 75 of file mdl_search.c.
References internal_hex_digit(), internal_is_unreserved(), k_hi_nibble_shift, and k_triplet_len.
Referenced by internal_discover_url().
| bool mdl_search_build_url | ( | const char * | tmpl, |
| const char * | encoded_term, | ||
| char * | out, | ||
| size_t | cap ) |
Expand a query-URL template by substituting the encoded term for {q}.
Copies tmpl into out, replacing every {q} placeholder with encoded_term (already percent-encoded by mdl_query_encode). A template with no {q} is rejected – it could never carry the term, so silently fetching a fixed URL would be a lie about having searched.
| [in] | tmpl | Query-URL template holding at least one {q}. |
| [in] | encoded_term | The percent-encoded term to substitute. |
| [out] | out | Destination buffer for the NUL-terminated URL. |
| [in] | cap | Capacity of out in bytes. |
| true | out holds the expanded URL. |
| false | A NULL argument, cap == 0, no {q} in tmpl, or overflow. |
tmpl, encoded_term and out are non-NULL. encoded_term came from mdl_query_encode (URL-safe bytes only). out contains encoded_term at each former {q}.Definition at line 108 of file mdl_search.c.
References memcpy(), s_placeholder, strlen(), and strncmp().
Referenced by internal_discover_url().
| mdl_search_outcome_t mdl_search_classify | ( | const mdl_hit_list_t * | hits | ) |
Classify a parsed results page into an honest search outcome.
The whole point of #304's honesty criterion in one pure decision. With at least one matched hit the outcome is k_mdl_search_have_results. With none, the raw anchor tally decides: a page that rendered links but matched none is a genuine k_mdl_search_zero_results, while a page carrying no resolvable links at all is k_mdl_search_markup_changed – the endpoint returned something we could not read as a results page (its markup drifted, or the request was blocked or answered with non-HTML). A NULL list is treated as unreadable.
| [in] | hits | Parsed hit list from mdl_extract_hits, or NULL. |
hits. | k_mdl_search_have_results | hits->count > 0. |
| k_mdl_search_zero_results | count == 0 and anchors_seen > 0. |
| k_mdl_search_markup_changed | NULL, or count == 0 and no anchors seen. |
hits, when non-NULL, was filled by mdl_extract_hits. Definition at line 149 of file mdl_search.c.
References mdl_hit_list_t::anchors_seen, mdl_hit_list_t::count, k_mdl_search_have_results, k_mdl_search_markup_changed, and k_mdl_search_zero_results.
Referenced by mdl_discover_run().
| size_t mdl_search_filter_series_hits | ( | mdl_hit_list_t * | hits, |
| const char * | chapter_marker ) |
Remove chapter links and duplicate series URLs from discovery hits.
Site result pages commonly mix canonical series links with recent chapter links. A descriptor's chapter marker therefore acts as an exclusion as well as the series-page extraction selector. Exact duplicate URLs are collapsed while preserving first-seen order.
| [in,out] | hits | Parsed hit list to compact in place. |
| [in] | chapter_marker | Chapter URL substring to reject; an empty string disables only the chapter filter. |
| 0 | No entry was removed, or an argument was NULL. |
hits and chapter_marker are non-NULL. hits contains only canonical, unique series candidates. Definition at line 163 of file mdl_search.c.
References mdl_hit_list_t::count, mdl_hit_list_t::hits, strcmp(), strstr(), and mdl_hit_t::url.
Referenced by mdl_discover_run().
| const char * mdl_search_placeholder | ( | void | ) |
The {q} placeholder a search-URL template must contain.
| non-NULL | Always: the constant placeholder string. |
Definition at line 29 of file mdl_search.c.
References s_placeholder.
Referenced by internal_discover_url().
|
static |
The {q} placeholder token, kept in one place.
Definition at line 27 of file mdl_search.c.
Referenced by mdl_search_build_url(), and mdl_search_placeholder().