Noir::CHttpSupport
Shared parsing for the C embedded HTTP servers (Mongoose, CivetWeb,
libmicrohttpd). C has no route DSL: a URI is a string literal handed to a
registration call, or compared against the request URI inside one big
handler, and a handler is a plain function. These helpers resolve those
literals (including #define NAME "/path"), find a handler's body, and
read the method and parameter evidence out of it. Offsets are bytes, as in
CppCalleeExtractor.
Constants
#define NAME "/p" (or PREFIX "/p"), static const char NAME[] = "/p";,
const char *NAME = "/p";
The function in a handler argument: fn, &fn, (Cast) &fn, and
Mongoose 6's fn MG_UD_ARG(NULL).
strcmp(ri->request_method, "POST"), mg_match(hm->method, mg_str("POST"), NULL),
strcmp("GET", method), strcmp(method, MHD_HTTP_METHOD_POST). Negated
compares count too: if (0 != strcmp(method, "GET")) return MHD_NO; is
how a handler says it only serves GET.
Possessive throughout: a long identifier must not be re-split into shorter adjacent "identifiers" when the match fails.
Mongoose mg_http_get_var(&hm->query, "q", ...) and CivetWeb
mg_get_var(qs, len, "q", ...): the source buffer says query vs form.
Instance methods
Memoized CppCalleeExtractor.function_body: every route of a big
dispatcher calls the same helpers.
Top-level arguments of the call whose ( is at open_paren, plus the
byte offset of its ).
A route found as a URI comparison inside a handler. The method comes
from the if condition, else from the branch it guards, else GET;
params come from the branch and the helpers it calls.
One endpoint per method (GET when the handler never looks), carrying the
params read in scope and, when asked, the callees of body.
The function named by a handler argument.
A route served by a whole handler (body, nil when unresolved): the
methods it compares the request method against, the params it and its
helpers read.
1-based line of a byte offset; line_number_for recounts from the start
of the file, which a dispatcher with hundreds of routes pays per route.
The URI pattern as a Noir URL: Mongoose # and CivetWeb ** (match
anything) become *, CivetWeb's $ end anchor is dropped. Nil for
non-path patterns (**.php$, "").
A string argument: literals, mg_str("..."), #defined names and
adjacent concatenations of those (AREA_URL "page"). Nil for anything
computed at runtime.