|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Search / browse discovery: governed fetch of a results page, parse, honest presentation, and optional select-for-download. More...
#include <stddef.h>#include <stdint.h>#include "mdl_config.h"#include "mdl_extract.h"#include "mdl_politeness.h"#include "mdl_session.h"Go to the source code of this file.
Data Structures | |
| struct | mdl_discover_req_t |
| Injected dependencies and inputs for one discovery run. More... | |
Enumerations | |
| enum | mdl_discover_mode_t : uint8_t { k_mdl_discover_search = 0 , k_mdl_discover_browse = 1 } |
| Which discovery endpoint of a site descriptor to query. More... | |
Functions | |
| 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. | |
Search / browse discovery: governed fetch of a results page, parse, honest presentation, and optional select-for-download.
The network-facing half of #304, kept out of main.c so the entry point stays a thin dispatcher and so the pure parse policy (::mdl_search) is tested on its own. Given an already-built session (honest User-Agent + robots cache) and politeness governor, mdl_discover_run builds the query URL from the site descriptor, gates it against robots.txt, fetches it through the same governor every other request uses (search is never a rate-limit bypass), parses the results with mdl_extract_hits, and prints one of three honest outcomes: a numbered list, a genuine "no results", or "the markup changed".
When a 1-based pick index is supplied it also copies the chosen series URL out for the caller to feed straight into a download – the combined search-and-select flow that removes the copy-paste step.
Definition in file mdl_discover.h.
| enum mdl_discover_mode_t : uint8_t |
Which discovery endpoint of a site descriptor to query.
| Enumerator | |
|---|---|
| k_mdl_discover_search | search_url with a {q} term substitution. |
| k_mdl_discover_browse | browse_url latest-updates page, no term. |
Definition at line 38 of file mdl_discover.h.
| 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.
Builds the results URL for req->mode from the site descriptor (encoding the term and expanding {q} for search; using browse_url verbatim for browse), refuses when the descriptor supplies no such endpoint, gates the URL against robots.txt, and fetches it through req->gov with bounded governed retries. It then parses the response with mdl_extract_hits and classifies it with mdl_search_classify, printing a distinct message for each honest outcome so an empty result is never dressed up as a successful search. When pick is non-zero it names the pick-th hit (1-based) and copies its series URL into out_url for a follow-on download.
| [in] | req | Injected dependencies and inputs (never NULL). |
| [in] | pick | 1-based hit to select, or 0 to only list results. |
| [out] | out_url | Receives the selected series URL, or "" when nothing was selected. May be NULL only when pick is 0. |
| [in] | out_cap | Capacity of out_url in bytes (>= 1 when out_url set). |
| 0 | Listed results (possibly zero) or selected a hit successfully. |
| 1 | The request failed, or the page could not be read as results, or a pick was requested with no results to choose from. |
| 2 | A capability/usage error: no such discovery endpoint configured, an empty/oversized term, or a pick index out of range. |
req and its session/gov/site/page_buf/hits are non-NULL. out_url has room for out_cap bytes when pick is non-zero. req->hits holds the parsed hits for the run. pick != 0.Definition at line 471 of file mdl_discover.c.
References mdl_site_t::chapter_url_contains, mdl_discover_req_t::diagnostic, mdl_discover_req_t::gov, mdl_discover_req_t::hits, internal_discover_fetch(), internal_discover_text3(), internal_discover_url(), internal_mode_word(), internal_present_and_pick(), mdl_discover_req_t::io_error, k_disc_url_max, k_mdl_reason_max, k_ra8_ok, mdl_extract_hits(), mdl_search_classify(), mdl_search_filter_series_hits(), mdl_discover_req_t::mode, mdl_discover_req_t::output, mdl_discover_req_t::page_buf, priv_mdl_fetch_reason(), priv_mdl_stream_text(), mdl_site_t::search_result_contains, mdl_discover_req_t::session, and mdl_discover_req_t::site.
Referenced by mdl_app_run_discover().