SimpleOTA client v1.2.0
Shared core of the SimpleOTA Arduino and ESP-IDF clients
Loading...
Searching...
No Matches
sota_url.h File Reference

The URLs the client may use: the server base URL for check-ins and status posts, and where a download redirect may lead. More...

Go to the source code of this file.

Macros

#define SOTA_DEFAULT_SERVER_URL   "https://simpleota.com"
 The SimpleOTA platform, used when the application sets no base URL.
 
#define SOTA_SERVER_URL_MAX_LEN   256u
 Longest base URL accepted, without the terminating NUL.
 

Enumerations

enum  sota_url_status_t { SOTA_URL_OK = 0 , SOTA_URL_NOT_HTTPS = 1 , SOTA_URL_MALFORMED = 2 }
 Why a server URL was accepted or refused. More...
 

Functions

static bool sota_url_has_scheme (const char *url, const char *scheme)
 True when url starts with scheme, ignoring the case of the URL.
 
static bool sota_url_chars_ok (const char *url)
 True when url has no spaces or control characters, which could split a request line.
 
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 characters.
 
static const char * sota_url_status_name (int status)
 The status as a short token for logs: "ok", "not_https" or "malformed".
 
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.
 
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.
 

Detailed Description

The URLs the client may use: the server base URL for check-ins and status posts, and where a download redirect may lead.

Everything is https://; the offer's own download URL is checked on the apply path.

No platform types, so the host tests can include this header.

Enumeration Type Documentation

◆ sota_url_status_t

Why a server URL was accepted or refused.

Enumerator
SOTA_URL_OK 

Usable.

SOTA_URL_NOT_HTTPS 

A plain http:// URL.

SOTA_URL_MALFORMED 

Empty, too long, no host, or bad characters.

Function Documentation

◆ sota_redirect_target()

static sota_url_status_t sota_redirect_target ( const char *  base,
const char *  location,
char *  out,
size_t  cap 
)
inlinestatic

Where a download redirect from base leads, into out.

location is an absolute https:// URL, or a path starting with '/' on base's host. A redirect to plain HTTP is SOTA_URL_NOT_HTTPS; out is untouched unless the result is SOTA_URL_OK. out must not overlap base or location.

◆ sota_build_api_url()

static bool sota_build_api_url ( const char *  base,
const char *  path,
char *  out,
size_t  out_len 
)
inlinestatic

base + path into out, with trailing slashes of base removed.

Returns false, leaving out untouched, when it does not fit.