19#define SOTA_DEFAULT_SERVER_URL "https://simpleota.com"
21#define SOTA_SERVER_URL_MAX_LEN 256u
33 for (; *scheme; ++url, ++scheme) {
34 char c = *url >=
'A' && *url <=
'Z' ? (char)(*url -
'A' +
'a') : *url;
35 if (c != *scheme)
return false;
45 unsigned char c = (
unsigned char)*url;
46 if (c <= 0x20u || c == 0x7fu)
return false;
58 size_t len = strlen(url);
64 const char *slash = strchr(url + 8,
'/');
82 char *out,
size_t cap)
88 if (location[0] ==
'/' && location[1] !=
'/') {
90 const char *slash = strchr(base + 8,
'/');
91 origin = slash ? (size_t)(slash - base) : strlen(base);
94 }
else if (!
sota_url_has_scheme(location,
"https://") || location[8] ==
'/' || !location[8]) {
97 size_t len = strlen(location);
99 memcpy(out, base, origin);
100 memcpy(out + origin, location, len + 1);
111 if (!base || !path || !out || out_len == 0)
return false;
112 size_t n = strlen(base);
113 while (n > 8u && base[n - 1] ==
'/') --n;
114 size_t plen = strlen(path);
115 if (n >= out_len || plen > (out_len - 1u) - n)
return false;
116 memcpy(out, base, n);
117 memcpy(out + n, path, plen + 1u);
static sota_url_status_t sota_redirect_target(const char *base, const char *location, char *out, size_t cap)
Where a download redirect from base leads, into out.
Definition sota_url.h:81
static bool sota_url_chars_ok(const char *url)
True when url has no spaces or control characters, which could split a request line.
Definition sota_url.h:42
static bool sota_build_api_url(const char *base, const char *path, char *out, size_t out_len)
base + path into out, with trailing slashes of base removed.
Definition sota_url.h:108
sota_url_status_t
Why a server URL was accepted or refused.
Definition sota_url.h:24
@ SOTA_URL_OK
Usable.
Definition sota_url.h:25
@ SOTA_URL_NOT_HTTPS
A plain http:// URL.
Definition sota_url.h:26
@ SOTA_URL_MALFORMED
Empty, too long, no host, or bad characters.
Definition sota_url.h:27
static sota_url_status_t sota_validate_server_url(const char *url)
An https:// URL with a host, at most SOTA_SERVER_URL_MAX_LEN characters, and no spaces or control cha...
Definition sota_url.h:55
static bool sota_url_has_scheme(const char *url, const char *scheme)
True when url starts with scheme, ignoring the case of the URL.
Definition sota_url.h:31
#define SOTA_SERVER_URL_MAX_LEN
Longest base URL accepted, without the terminating NUL.
Definition sota_url.h:21
static const char * sota_url_status_name(int status)
The status as a short token for logs: "ok", "not_https" or "malformed".
Definition sota_url.h:69