rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
wa_guard.c File Reference

Which requests the Wi-Fi page answers. See wa_guard.h. More...

#include "wa_guard.h"
#include "wa_session.h"
#include <stdio.h>
#include <string.h>
#include <strings.h>

Macros

#define HOST_MAX   (WA_NAME_MAX + 7u)
 Bytes of the longest name the guard compares with, "rcbench-1A2B.local.", and its terminator.

Functions

static bool same (const char *s, size_t n, const char *want)
 Whether n bytes at s are want, letters compared without regard to case.
static bool host_name_ok (const char *s, size_t n, const wa_self_t *self)
 Whether n bytes at s, a host without its port, name the panel.
static bool host_part_ok (const char *s, size_t n, const wa_self_t *self)
 Whether n bytes at s, a host with an optional port, name the panel.
bool wa_host_ok (const char *host, const wa_self_t *self)
 Whether host, a Host header's value, names the panel.
static bool url_ok (const char *url, bool path, const wa_self_t *self)
 Whether url is "http://" and an allowed host, followed by nothing or, with path, by "/", "?" or "#".
bool wa_origin_ok (const char *origin, const char *referer, const wa_self_t *self)
 Whether a write comes from the panel's own page.
wa_guard_t wa_guard (wa_req_kind_t kind, const wa_req_t *req, const wa_self_t *self)
 The guard: Host first, then the body, then a write's Origin and the upload's header.
const char * wa_guard_status (wa_guard_t g)
 The HTTP status line of a refusal, "421 Misdirected Request" and the like.

Detailed Description

Which requests the Wi-Fi page answers. See wa_guard.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ host_name_ok()

bool host_name_ok ( const char * s,
size_t n,
const wa_self_t * self )
static

Whether n bytes at s, a host without its port, name the panel.

Parameters
sthe host
nits bytes
selfthe panel
Returns
true for the name, the name with ".local" or ".local.", or the address in dotted form

◆ host_part_ok()

bool host_part_ok ( const char * s,
size_t n,
const wa_self_t * self )
static

Whether n bytes at s, a host with an optional port, name the panel.

Parameters
sthe host part of a Host, an Origin or a Referer
nits bytes
selfthe panel
Returns
true for host_name_ok() and no port or port WA_HTTP_PORT

◆ same()

bool same ( const char * s,
size_t n,
const char * want )
static

Whether n bytes at s are want, letters compared without regard to case.

Parameters
sthe bytes
nhow many
wantthe text, NUL-terminated
Returns
true when equal

◆ url_ok()

bool url_ok ( const char * url,
bool path,
const wa_self_t * self )
static

Whether url is "http://" and an allowed host, followed by nothing or, with path, by "/", "?" or "#".

Parameters
urlan Origin or a Referer
patha Referer: a path may follow
selfthe panel
Returns
true for the panel's own page

◆ wa_guard()

wa_guard_t wa_guard ( wa_req_kind_t kind,
const wa_req_t * req,
const wa_self_t * self )

The guard: Host first, then the body, then a write's Origin and the upload's header.

Parameters
kindwhat the request is
reqits headers
selfthe panel
Returns
WA_GUARD_OK, or the first check that refuses it

◆ wa_guard_status()

const char * wa_guard_status ( wa_guard_t g)

The HTTP status line of a refusal, "421 Misdirected Request" and the like.

Parameters
gthe answer; WA_GUARD_OK gives "200 OK"
Returns
a constant string

◆ wa_host_ok()

bool wa_host_ok ( const char * host,
const wa_self_t * self )

Whether host, a Host header's value, names the panel.

Parameters
hostthe value; NULL refuses
selfthe panel
Returns
true for the panel's name, as above, or its address

◆ wa_origin_ok()

bool wa_origin_ok ( const char * origin,
const char * referer,
const wa_self_t * self )

Whether a write comes from the panel's own page.

Parameters
originthe Origin header, or NULL
refererthe Referer header, read only when origin is NULL
selfthe panel
Returns
true for "http://" and a host wa_host_ok() takes, and after it nothing (Origin) or "/", "?", "#" or nothing (Referer)