|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Pure search/discovery policy: query encoding, URL templating, and the honest zero-vs-broken result classifier. More...
Go to the source code of this file.
Enumerations | |
| enum | mdl_search_outcome_t : uint8_t { k_mdl_search_have_results = 0 , k_mdl_search_zero_results = 1 , k_mdl_search_markup_changed = 2 } |
| The honest outcome of a parsed search/browse results page. More... | |
Functions | |
| const char * | mdl_search_placeholder (void) |
| The {q} placeholder a search-URL template must contain. | |
| 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. | |
Pure search/discovery policy: query encoding, URL templating, and the honest zero-vs-broken result classifier.
The network-free half of --search / --browse (#304). Three small, side-effect-free functions the discovery orchestrator (mdl_discover_run) composes with a governed page fetch and mdl_extract_hits:
Keeping these pure makes the whole discovery parse path unit-testable against a captured fixture with no network, which is exactly what #304 requires.
Definition in file mdl_search.h.
| enum mdl_search_outcome_t : uint8_t |
The honest outcome of a parsed search/browse results page.
The distinction #304 demands: an empty list must never look like a successful search. mdl_search_classify maps the parsed hits plus the raw anchor tally onto exactly one of these, and the CLI prints a distinct message for each.
Definition at line 57 of file mdl_search.h.
| 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().