ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
mdl_net.c
Go to the documentation of this file.
1
15#include "mdl_net.h"
16
17#include <stddef.h>
18#include <string.h>
19
20#include "mdl_net_internal.h"
21#include "ra8_attributes.h"
22
30
32{
33 if ((status == k_mdl_http_too_many) || (status == k_mdl_http_unavailable)) {
34 return k_ra8_err_busy;
35 }
36 if (status >= k_mdl_http_server_error) {
37 return k_ra8_fail;
38 }
39 if (status >= k_mdl_http_client_error) {
41 }
42 return k_ra8_ok;
43}
44
58{
59 if (resp != nullptr) {
60 memset(resp, 0, sizeof(*resp));
61 }
62}
63
65 const mdl_net_policy_t* policy,
66 mdl_net_iface_t* out_net)
67{
68 if (out_net == nullptr) {
70 }
71 *out_net = (mdl_net_iface_t){};
72 if ((provider == nullptr) || (provider->open == nullptr) || (policy == nullptr)) {
74 }
75 return provider->open(provider->ctx, policy, out_net);
76}
77
79 const char* url,
80 const mdl_net_req_t* req,
81 char* buf,
82 size_t cap,
83 size_t* out_len,
84 mdl_net_resp_t* resp)
85{
87 if (net == nullptr) {
89 }
90 if ((net->vtable == nullptr) || (url == nullptr) || (req == nullptr) || (buf == nullptr) ||
91 (cap == 0U)) {
93 }
94 return net->vtable->get_buf(net->ctx, url, req, buf, cap, out_len, resp);
95}
96
98 const char* url,
99 const mdl_net_req_t* req,
101 size_t* out_len,
102 mdl_net_resp_t* resp)
103{
105 if (net == nullptr) {
107 }
108 if ((net->vtable == nullptr) || (net->vtable->get_body == nullptr) || (url == nullptr) ||
109 (req == nullptr) || (sink == nullptr) || (sink->reset == nullptr) ||
110 (sink->write == nullptr) || (sink->ctx == nullptr)) {
112 }
113 const ra8_err_t reset = sink->reset(sink->ctx);
114 if (reset != k_ra8_ok) {
115 return reset;
116 }
117 return net->vtable->get_body(net->ctx, url, req, sink, out_len, resp);
118}
119
121{
122 if (net == nullptr) {
123 return;
124 }
125 if ((net->vtable != nullptr) && (net->vtable->destroy != nullptr)) {
126 net->vtable->destroy(net->ctx);
127 }
128 *net = (mdl_net_iface_t){};
129}
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).
Definition mdl_net.c:78
void mdl_net_destroy(mdl_net_iface_t *net)
Deinitialise a caller-owned network interface.
Definition mdl_net.c:120
mdl_http_status_t
HTTP statuses that have downloader-specific handling.
Definition mdl_net.c:24
@ k_mdl_http_unavailable
Service Unavailable.
Definition mdl_net.c:28
@ k_mdl_http_client_error
First client-error status.
Definition mdl_net.c:25
@ k_mdl_http_server_error
First server-error status.
Definition mdl_net.c:27
@ k_mdl_http_too_many
Too Many Requests.
Definition mdl_net.c:26
ra8_err_t priv_mdl_net_classify_http(long status)
Classify one observed HTTP response status.
Definition mdl_net.c:31
static void internal_resp_reset(mdl_net_resp_t *resp)
Zero a caller-supplied response block so early returns leave it clean.
Definition mdl_net.c:57
ra8_err_t mdl_net_get_body(mdl_net_iface_t *net, const char *url, const mdl_net_req_t *req, mdl_net_body_sink_t *sink, size_t *out_len, mdl_net_resp_t *resp)
GET url and stream its body through a caller-owned sink.
Definition mdl_net.c:97
ra8_err_t mdl_net_provider_open(const mdl_net_provider_t *provider, const mdl_net_policy_t *policy, mdl_net_iface_t *out_net)
Open a transport through an injected provider.
Definition mdl_net.c:64
Streaming HTTP(S) GET seam (a real function-pointer vtable) for the host manga downloader (v0).
Private HTTP classification shared by downloader network backends.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_err_busy
Resource busy – blocking operation cannot proceed.
Definition ra8_err.h:195
@ k_ra8_fail
Generic unspecified failure.
Definition ra8_err.h:133
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
Definition ra8_err.h:173
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
Caller-owned lifecycle and write seam for one response body.
Definition mdl_net.h:162
mdl_net_body_write_fn write
Consume one response chunk.
Definition mdl_net.h:164
void * ctx
Caller-owned callback state.
Definition mdl_net.h:165
mdl_net_body_reset_fn reset
Clear/abort prior attempt state.
Definition mdl_net.h:163
A network backend handle: an immutable method table plus its state.
Session-wide security policy for the network backend.
Definition mdl_net.h:81
An injected FACTORY for mdl_net_iface_t: which backend, decided once.
Per-request session parameters.
Definition mdl_net.h:43
Per-transfer response metadata surfaced to the politeness governor.
Definition mdl_net.h:120