22typedef enum : uint32_t {
27typedef enum : uint16_t {
40static const char*
const s_ua_url =
"https://github.com/bsikar/ra8-firmware";
49 if ((out ==
nullptr) || (cap == 0U)) {
52 const bool have = (contact !=
nullptr) && (contact[0] !=
'\0');
63 const char* user_agent,
67 if (session ==
nullptr) {
99 while (prefix[i] !=
'\0') {
101 if ((c >=
'A') && (c <=
'Z')) {
102 c = (char)(c + (
'a' -
'A'));
104 if (c != prefix[i]) {
146 if ((url ==
nullptr) || (out ==
nullptr) || (cap < 2U)) {
149 const char* sep =
strstr(url,
"://");
150 if (sep ==
nullptr) {
153 const char* authority = sep + 3U;
154 const char* start = strpbrk(authority,
"/?#");
156 if ((start ==
nullptr) || (*start ==
'#')) {
165 const char* p = start;
166 while ((*p !=
'\0') && (*p !=
'#')) {
167 if ((n + 1U) >= cap) {
239 "mdl: robots.txt unavailable, rate-limited, or "
278 if (crawl_delay_ms !=
nullptr) {
279 *crawl_delay_ms = 0U;
281 if ((session ==
nullptr) || (url ==
nullptr)) {
288 if (scheme ==
nullptr) {
291 "mdl: cannot apply robots.txt to malformed/non-HTTP URL; "
299 "mdl: cannot identify URL origin for robots.txt; refusing\n");
306 "mdl: URL path/query exceeds robots.txt bound; refusing\n");
317 if (rules ==
nullptr) {
325 if (reason !=
nullptr) {
ra8_err_t mdl_net_get_buf(mdl_net_iface_t *net, const char *url, const mdl_net_req_t *req, char *buf, size_t cap, size_t *out_len, mdl_net_resp_t *resp)
GET url fully into a caller buffer (used for HTML pages).
@ k_http_client_err_min
First HTTP status treated as an error.
@ k_http_server_err_min
First HTTP status that is a server error.
@ k_mdl_robots_path_max
Max bytes per rule path pattern.
mdl_robots_fetch_result_t
Outcome class of a robots.txt fetch, per RFC 9309 convention.
@ k_mdl_robots_fetch_absent
Absent / transport error: allow all.
@ k_mdl_robots_fetch_denied
5xx status: disallow all.
@ k_mdl_robots_fetch_ok
A body was retrieved to parse.
@ k_mdl_robots_host_max
Max host string bytes.
const char * mdl_robots_disallow_reason(const mdl_robots_t *robots, const char *path)
Return the Disallow pattern that forbids path, or NULL if allowed.
const mdl_robots_t * mdl_robots_cache_consult(mdl_robots_cache_t *cache, const char *scheme, const char *host, const char *ua_token, mdl_robots_fetch_fn fetch, void *ctx, char *scratch, size_t scratch_cap)
Return the cached robots rules for host, fetching on first contact.
static const char *const s_ua_url
Project URL reported in the User-Agent for a contact channel.
static mdl_robots_fetch_result_t internal_session_fetch(void *ctx, const char *robots_url, char *buf, size_t cap, size_t *out_len)
robots.txt fetch callback: map an mdl_net GET to a fetch result.
bool mdl_session_url_allowed(mdl_session_t *session, const char *url, uint32_t *crawl_delay_ms)
Decide whether url may be fetched under robots.txt, and its delay.
static bool internal_url_prefix(const char *url, const char *prefix)
ASCII case-insensitive comparison of one URL prefix.
static const char *const s_ua_version
Tool version reported in the User-Agent.
static const char * internal_url_scheme(const char *url)
Return the validated lower-case HTTP(S) scheme, or NULL.
mdl_session_net_t
robots.txt fetch tunables.
@ k_robots_timeout_ms
Per-robots.txt request budget, ms.
void mdl_session_init(mdl_session_t *session, mdl_net_iface_t *net, const char *user_agent, ra8_io_stream_t *diagnostic, bool honor_robots)
Initialise a session over a network backend.
static void internal_report_robots_unavailable(mdl_session_t *session, const char *host, const char *path)
Report a failed robots consultation for one origin and path.
static void internal_report_robots_disallow(mdl_session_t *session, const char *path, const char *host, const char *reason)
Report the robots rule that rejected one path.
static bool internal_robots_target(const char *url, char *out, size_t cap)
Extract path plus query, excluding fragment, for RFC 9309 matching.
mdl_session_status_t
HTTP server-error range treated as "disallow all".
@ k_http_client_err_max
Last 4xx unavailable status.
@ k_http_server_err_max
Last 5xx status.
@ k_http_too_many
Rate limiting: do not bypass robots.
const char * mdl_session_ua_token(void)
The robots.txt product token this tool matches on ("mdl").
static const char *const s_ua_token
Product token used to match robots.txt User-agent groups.
bool mdl_session_build_ua(const char *contact, char *out, size_t cap)
Build the truthful default User-Agent into out.
Session identity (honest User-Agent) and robots.txt gating.
ra8_err_t priv_mdl_stream_text(ra8_err_t prior, ra8_io_stream_t *stream, const char *text)
Append text unless an earlier operation already failed.
Private bounded text helpers over the portable byte-stream contract.
Pure URL / address safety predicates for the libcurl backend.
bool mdl_url_host(const char *url, char *out, size_t cap)
Extract the authority (host and optional port) from an http(s) URL.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
char * strstr(const char *haystack, const char *needle)
Locate substring in string.
A network backend handle: an immutable method table plus its state.
Per-request session parameters.
Per-transfer response metadata surfaced to the politeness governor.
long status
Finished transfer's HTTP status, 0 if none.
Fixed-size per-host robots.txt cache for one run.
Rules and crawl-delay for the group matching our user-agent.
bool have_crawl_delay
A Crawl-delay was seen.
uint32_t crawl_delay_ms
Crawl-delay in ms.
One download session's identity and robots.txt state.
mdl_robots_cache_t cache
Per-host robots cache.
mdl_net_iface_t * net
Backend used for robots.txt fetches.
bool honor_robots
False disables all robots gating.
const char * user_agent
Full UA header (caller-owned).
ra8_io_stream_t * diagnostic
Borrowed diagnostic byte sink.
char scratch[k_mdl_session_scratch]
Fetch scratch.
Caller-allocated byte-stream handle binding a sink to its context.