21#define SOTA_NET_MAX_REDIRECTS 3
26 return status == 301 || status == 302 || status == 303 || status == 307 || status == 308;
41 while (*value ==
' ' || *value ==
'\t') ++value;
42 if (*value <
'0' || *value >
'9')
return 0;
43 for (; *value >=
'0' && *value <=
'9'; ++value) {
44 uint32_t d = (uint32_t)(*value -
'0');
45 s = s > (UINT32_MAX - d) / 10u ? UINT32_MAX : s * 10u + d;
47 while (*value ==
' ' || *value ==
'\t') ++value;
48 return *value ? 0 : s;
59int sota_net_post(
void *user,
const char *url,
const char *token,
const char *body,
60 char *resp,
size_t cap, uint32_t *retry_after_s);
int sota_net_post(void *user, const char *url, const char *token, const char *body, char *resp, size_t cap, uint32_t *retry_after_s)
POST body as JSON to url, with "Authorization: Bearer <token>".
void sota_net_dl_close(void *user)
End the download and free its connection.
int sota_net_dl_read(void *user, uint8_t *buf, size_t cap)
Read the next bytes of the body: a count, 0 once the whole body has arrived, SOTA_NET_AGAIN,...
static int sota_net_is_redirect(int status)
A status sota_net_dl_open() returns for a redirect.
Definition sota_net.h:24
int sota_net_dl_open(void *user, const char *url, int64_t *len, char *location, size_t location_cap)
Start a firmware download: a GET without the Authorization header (the pre-signed URL carries its own...
static uint32_t sota_net_parse_retry_after(const char *value)
A Retry-After header's value in seconds, saturated; 0 when it is not a plain number of seconds (the H...
Definition sota_net.h:38
@ SOTA_NET_ERROR
The connection failed.
Definition sota_net.h:31
@ SOTA_NET_AGAIN
No byte yet: the core calls again, and gives up with download_stalled after http_timeout_ms.
Definition sota_net.h:32