.TH "axil" 3 "axil" \" -*- nroff -*- .ad l .nh .SH NAME axil \- axil API .PP \- Core API and configuration types\&. .SH SYNOPSIS .br .PP .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBaxil_config\fP" .br .ti -1c .RI "struct \fBcmd_slot\fP" .br .in -1c .SS "Macros" .in +1c .ti -1c .RI "#define \fBENV_KEY_LEN\fP 128" .br .ti -1c .RI "#define \fBENV_LEN\fP (BUFSIZ * 2)" .br .ti -1c .RI "#define \fBENV_VALUE_LEN\fP (\fBENV_LEN\fP \- \fBENV_KEY_LEN\fP \- 2)" .br .ti -1c .RI "#define \fBTELNET_CMD\fP(fd, \&.\&.\&.)" .br .in -1c .SS "Typedefs" .in +1c .ti -1c .RI "typedef int \fBsocket_t\fP" .br .RI "Socket descriptor type\&. " .ti -1c .RI "typedef int \fBaxil_handler_t\fP(\fBsocket_t\fP cfd, char *body)" .br .ti -1c .RI "typedef \fBsocket_t\fP \fBaxil_ws_upstream_t\fP(\fBsocket_t\fP client_fd)" .br .in -1c .SS "Enumerations" .in +1c .ti -1c .RI "enum \fBdescr_flags\fP { \fBDF_CONNECTED\fP = 1, \fBDF_WEBSOCKET\fP = 4, \fBDF_TO_CLOSE\fP = 8, \fBDF_ACCEPTED\fP = 16, \fBDF_AUTHENTICATED\fP = 32, \fBDF_TUNNEL\fP = 64, \fBDF_WS_WAITING\fP = 128, \fBDF_WS_PROXY_PENDING\fP = 256, \fBDF_EXTERN\fP = 512, \fBDF_HEAD\fP = 1024, \fBDF_DEFERRED\fP = 2048, \fBDF_AUTH_AUTO\fP = 4096, \fBDF_UNIX\fP = 8192 }" .br .ti -1c .RI "enum \fBaxil_srv_flags\fP { \fBAXIL_WAKE\fP = 1, \fBAXIL_SSL\fP = 2, \fBAXIL_ROOT\fP = 4, \fBAXIL_SSL_ONLY\fP = 8, \fBAXIL_DETACH\fP = 16, \fBAXIL_AUTOAUTH\fP = 32, \fBAXIL_LOOPBACK\fP = 64 }" .br .ti -1c .RI "enum \fBaxil_req_flags\fP { \fBAXIL_POST\fP = 1, \fBAXIL_PUT\fP = 2, \fBAXIL_DELETE\fP = 4, \fBAXIL_HEAD\fP = 8, \fBAXIL_OPTIONS\fP = 16 }" .br .ti -1c .RI "enum \fBcmd_flags\fP { \fBCF_NOAUTH\fP = 1, \fBCF_NOTRIM\fP = 2 }" .br .in -1c .SS "Functions" .in +1c .ti -1c .RI "void \fBaxil_register\fP (char *name, axil_cb_t *cb, int flags)" .br .ti -1c .RI "int \fBaxil_main\fP (void)" .br .ti -1c .RI "void \fBaxil_stop\fP (void)" .br .ti -1c .RI "void \fBaxil_register_handler\fP (char *path, \fBaxil_handler_t\fP handler)" .br .ti -1c .RI "int \fBaxil_register_fallback_handler\fP (\fBaxil_handler_t\fP handler)" .br .ti -1c .RI "int \fBaxil_deny_prefix\fP (const char *prefix)" .br .ti -1c .RI "int \fBaxil_proxy_prefix\fP (const char *prefix, const char *host, unsigned short port)" .br .ti -1c .RI "void \fBaxil_ws_handler\fP (char *path, \fBaxil_ws_upstream_t\fP handler)" .br .ti -1c .RI "int \fBaxil_ws_upgrade\fP (\fBsocket_t\fP fd)" .br .ti -1c .RI "int \fBaxil_ws_write\fP (\fBsocket_t\fP fd, const void *data, size_t len)" .br .ti -1c .RI "ssize_t \fBaxil_ws_read\fP (\fBsocket_t\fP fd, void *buf, size_t len)" .br .ti -1c .RI "int \fBaxil_ws_close\fP (\fBsocket_t\fP fd)" .br .ti -1c .RI "int \fBaxil_ws_printf\fP (\fBsocket_t\fP fd, const char *fmt,\&.\&.\&.)" .br .ti -1c .RI "int \fBaxil_post_chroot\fP (void) WEAK" .br .ti -1c .RI "void \fBaxil_post_bind\fP (void) WEAK" .br .ti -1c .RI "void \fBaxil_update\fP (unsigned long long dt) WEAK" .br .ti -1c .RI "void \fBaxil_vim\fP (\fBsocket_t\fP fd, int argc, char *argv[]) WEAK" .br .ti -1c .RI "int \fBaxil_accept\fP (\fBsocket_t\fP fd) WEAK" .br .ti -1c .RI "int \fBaxil_connect\fP (\fBsocket_t\fP fd) WEAK" .br .ti -1c .RI "void \fBaxil_disconnect\fP (\fBsocket_t\fP fd) WEAK" .br .ti -1c .RI "void \fBaxil_command\fP (\fBsocket_t\fP fd, int argc, char *argv[]) WEAK" .br .ti -1c .RI "void \fBaxil_flush\fP (\fBsocket_t\fP fd, int argc, char *argv[]) WEAK" .br .ti -1c .RI "char * \fBaxil_auth_check\fP (\fBsocket_t\fP fd) WEAK" .br .ti -1c .RI "int \fBaxil_write\fP (\fBsocket_t\fP fd, void *data, size_t len)" .br .ti -1c .RI "int \fBaxil_dwritef\fP (\fBsocket_t\fP fd, const char *fmt, va_list va)" .br .ti -1c .RI "int \fBaxil_writef\fP (\fBsocket_t\fP fd, const char *fmt,\&.\&.\&.)" .br .ti -1c .RI "void \fBaxil_wall\fP (const char *msg)" .br .ti -1c .RI "int \fBaxil_flags\fP (\fBsocket_t\fP fd)" .br .ti -1c .RI "unsigned long long \fBaxil_generation\fP (\fBsocket_t\fP fd)" .br .ti -1c .RI "void \fBaxil_close\fP (\fBsocket_t\fP fd)" .br .ti -1c .RI "void \fBaxil_set_flags\fP (\fBsocket_t\fP fd, int flags)" .br .ti -1c .RI "int \fBaxil_auth\fP (\fBsocket_t\fP fd, char *username)" .br .ti -1c .RI "unsigned \fBaxil_env\fP (\fBsocket_t\fP fd)" .br .ti -1c .RI "void \fBaxil_cert_add\fP (char *str)" .br .ti -1c .RI "void \fBaxil_certs_add\fP (char *fname)" .br .ti -1c .RI "ssize_t \fBaxil_mmap\fP (char **mapped, char *file)" .br .ti -1c .RI "char * \fBaxil_mmap_iter\fP (char *start, size_t *pos)" .br .ti -1c .RI "void \fBaxil_env_clear\fP (\fBsocket_t\fP fd)" .br .ti -1c .RI "int \fBaxil_env_get\fP (\fBsocket_t\fP fd, char *target, size_t dest_len, char *key)" .br .ti -1c .RI "int \fBaxil_env_put\fP (\fBsocket_t\fP fd, char *key, char *value)" .br .ti -1c .RI "int \fBaxil_query_parse\fP (char *body)" .br .ti -1c .RI "int \fBaxil_query_param\fP (const char *name, char *buf, size_t buf_len)" .br .ti -1c .RI "int \fBaxil_param\fP (\fBsocket_t\fP fd, const char *name, char *buf, size_t buf_len)" .br .ti -1c .RI "int \fBaxil_param_int\fP (\fBsocket_t\fP fd, const char *name, int default_val)" .br .ti -1c .RI "int \fBaxil_param_bool\fP (\fBsocket_t\fP fd, const char *name, int default_val)" .br .ti -1c .RI "int \fBaxil_req_param\fP (\fBsocket_t\fP fd, const char *body, const char *name, char *buf, size_t buf_len)" .br .ti -1c .RI "int \fBaxil_req_param_int\fP (\fBsocket_t\fP fd, const char *body, const char *name, int default_val)" .br .ti -1c .RI "int \fBaxil_req_param_bool\fP (\fBsocket_t\fP fd, const char *body, const char *name, int default_val)" .br .ti -1c .RI "const char * \fBaxil_status_text\fP (int code)" .br .ti -1c .RI "int \fBaxil_url_encode\fP (const char *in, char *out, size_t outlen)" .br .ti -1c .RI "size_t \fBaxil_url_decode\fP (const char *src, size_t src_len, char *out, size_t out_len)" .br .ti -1c .RI "int \fBaxil_json_escape\fP (const char *in, char *out, size_t outlen)" .br .ti -1c .RI "int \fBaxil_slugify\fP (const char *title, size_t title_len, char *result, size_t result_len)" .br .ti -1c .RI "int \fBaxil_get_pw\fP (\fBsocket_t\fP fd, struct passwd *out)" .br .ti -1c .RI "void \fBaxil_fd_watch\fP (\fBsocket_t\fP fd)" .br .ti -1c .RI "void \fBaxil_fd_unwatch\fP (\fBsocket_t\fP fd)" .br .ti -1c .RI "void \fBaxil_fork_child_reset\fP (void)" .br .ti -1c .RI "int \fBaxil_peer_cred\fP (\fBsocket_t\fP fd, uid_t *uid, gid_t *gid)" .br .ti -1c .RI "int \fBaxil_privsep_key\fP (unsigned char out[32])" .br .ti -1c .RI "int \fBaxil_drop_ids\fP (uid_t *uid, gid_t *gid)" .br .ti -1c .RI "void \fBaxil_header_set\fP (\fBsocket_t\fP fd, const char *key, const char *value)" .br .ti -1c .RI "int \fBaxil_header_get\fP (\fBsocket_t\fP fd, const char *key, char *buf, size_t buf_len)" .br .ti -1c .RI "void \fBaxil_respond\fP (\fBsocket_t\fP fd, int code, const char *body)" .br .ti -1c .RI "void * \fBaxil_respond_defer\fP (\fBsocket_t\fP fd, int code)" .br .ti -1c .RI "void \fBaxil_respond_defer_finish\fP (void *handle, const char *body)" .br .ti -1c .RI "void \fBaxil_respond_defer_done\fP (void *handle)" .br .ti -1c .RI "void \fBaxil_respond_defer_abort\fP (void *handle)" .br .ti -1c .RI "int \fBaxil_respond_file\fP (\fBsocket_t\fP fd, const char *path, const char *allowed_exts)" .br .ti -1c .RI "void \fBaxil_sendfile\fP (\fBsocket_t\fP fd, const char *path)" .br .ti -1c .RI "void \fBaxil_exec\fP (\fBsocket_t\fP cfd, char *const args[], cmd_cb_t callback, void *input, size_t input_len)" .br .ti -1c .RI "int \fBaxil_exec_loop\fP (\fBsocket_t\fP cfd)" .br .in -1c .SS "Variables" .in +1c .ti -1c .RI "char \fBaxil_execbuf\fP [BUFSIZ *64]" .br .in -1c .SH "Detailed Description" .PP Core API and configuration types\&. .SH "Macro Definition Documentation" .PP .SS "#define ENV_KEY_LEN 128" Max key size for request environment\&. .SS "#define ENV_LEN (BUFSIZ * 2)" Maximum environment string size\&. .SS "#define ENV_VALUE_LEN (\fBENV_LEN\fP \- \fBENV_KEY_LEN\fP \- 2)" Max value size for request environment\&. .SS "#define TELNET_CMD( fd, \&.\&.\&.)" \fBValue:\fP .nf do { \\ unsigned char _tc[] = { __VA_ARGS__ }; \\ axil_send_telnet_cmd(fd, _tc, sizeof(_tc)); \\ } while (0) .PP .fi Build and send a TELNET command from a literal byte sequence\&. .SH "Typedef Documentation" .PP .SS "typedef int axil_handler_t(\fBsocket_t\fP cfd, char *body)" HTTP handler callback signature\&. .PP \fRbody\fP points at the request body: exactly \fRContent-Length\fP bytes, NUL-terminated, so strlen(body) gives its length\&. A request without a Content-Length has an empty body\&. A final read can overshoot Content-Length with the start of a following request; those bytes are discarded\&. .SS "typedef \fBsocket_t\fP axil_ws_upstream_t(\fBsocket_t\fP client_fd)" WebSocket tunnel callback: connects to upstream and returns socket\&. axil handles forwarding the HTTP upgrade request, reading the response, and establishing the tunnel\&. .SH "Enumeration Type Documentation" .PP .SS "enum \fBaxil_req_flags\fP" Request flags used internally\&. .PP \fBEnumerator\fP .in +1c .TP \f(BIAXIL_POST \fP Request is POST\&. .TP \f(BIAXIL_PUT \fP Request is PUT\&. .TP \f(BIAXIL_DELETE \fP Request is DELETE\&. .TP \f(BIAXIL_HEAD \fP Request is HEAD\&. .TP \f(BIAXIL_OPTIONS \fP Request is OPTIONS\&. .SS "enum \fBaxil_srv_flags\fP" Server configuration flags\&. .PP \fBEnumerator\fP .in +1c .TP \f(BIAXIL_WAKE \fP Wake on activity\&. .TP \f(BIAXIL_SSL \fP Enable TLS\&. .TP \f(BIAXIL_ROOT \fP Root multiplex mode\&. .TP \f(BIAXIL_SSL_ONLY \fP Redirect HTTP to HTTPS when SSL enabled\&. .TP \f(BIAXIL_DETACH \fP Detach into the background\&. .TP \f(BIAXIL_AUTOAUTH \fP Auto-authenticate all WebSocket connections (dev/testing only)\&. .TP \f(BIAXIL_LOOPBACK \fP Bind listening sockets to 127\&.0\&.0\&.1 instead of INADDR_ANY\&. .SS "enum \fBcmd_flags\fP" Command flags\&. .PP \fBEnumerator\fP .in +1c .TP \f(BICF_NOAUTH \fP Allow command without authentication\&. .TP \f(BICF_NOTRIM \fP Do not trim trailing CR from input\&. .SS "enum \fBdescr_flags\fP" Descriptor state flags\&. .PP \fBEnumerator\fP .in +1c .TP \f(BIDF_CONNECTED \fP Connection established and accepted\&. .TP \f(BIDF_WEBSOCKET \fP WebSocket mode enabled\&. .TP \f(BIDF_TO_CLOSE \fP Marked to close after remaining output\&. .TP \f(BIDF_ACCEPTED \fP Accepted socket (pre-WS)\&. .TP \f(BIDF_AUTHENTICATED \fP Authenticated user\&. .TP \f(BIDF_TUNNEL \fP Part of a tunnel pair\&. .TP \f(BIDF_WS_WAITING \fP Waiting for upstream websocket upgrade response\&. .TP \f(BIDF_EXTERN \fP Externally-watched fd: skip client processing, dispatch via on_fd_tick\&. .TP \f(BIDF_HEAD \fP Request is HEAD: suppress response body\&. .TP \f(BIDF_DEFERRED \fP Response deferred: headers sent, body pending axil_respond_defer_finish/done\&. .TP \f(BIDF_AUTH_AUTO \fP The identity in REMOTE_USER was published by AXIL_AUTOAUTH (-A), not asserted by a user\&. -A authenticates every connection as the server's own account, so any downstream authorization that trusts REMOTE_USER must refuse a descriptor carrying this flag\&. Set only by AXIL_AUTOAUTH, so it cannot survive descriptor reuse\&. .TP \f(BIDF_UNIX \fP Connection accepted on an AF_UNIX listening socket (POSIX-only)\&. .SH "Function Documentation" .PP .SS "int axil_accept (\fBsocket_t\fP fd)\fR [extern]\fP" Called on accept; return value is ignored\&. .SS "int axil_auth (\fBsocket_t\fP fd, char * username)" Authenticate a user for fd, dropping privileges to them (POSIX)\&. .PP Marks the connection authenticated and connected (so \fBaxil_disconnect()\fP fires and the fd is visible to \fBaxil_wall()\fP/DESCR_ITER), publishes REMOTE_USER, and records the user's passwd entry for \fBaxil_get_pw()\fP\&. If the user is unknown to the system, the entry from axil_pw is used instead, so the connection runs with the server's own identity rather than uid 0: validate the name first, e\&.g\&. with \fBaxil_auth_check()\fP\&. .PP The name is copied into a fixed BUFSIZ field and truncated to 8191 bytes if it is longer, with a warning; it is not rejected\&. A truncated name is almost certainly not the account that was intended, so validate length as well as existence before calling\&. .PP Returns 0 on success, 1 if the name is unknown to the system (the connection is still marked authenticated), or -1 with errno EBADF if fd is not in [0, FD_SETSIZE)\&. .PP \fBWarning\fP .RS 4 The 0/1 return is ADVISORY\&. Nothing in this library enforces it: axil_platform_auth_try() calls \fBaxil_auth()\fP and discards the result, and the platform hook it is invoked through is \fRvoid (*)(\fBsocket_t\fP)\fP, so there is nowhere for a verdict to travel\&. A caller that wants to reject an unknown name must check for itself -- compare against your own account list, or pre-validate with \fBaxil_auth_check()\fP -- rather than relying on the 1\&. The privilege fallback to the server's own identity applies either way, so an unenforced 1 degrades to "runs as the server", not to uid 0\&. .RE .PP .SS "char * axil_auth_check (\fBsocket_t\fP fd)\fR [extern]\fP" Return a username to authenticate the connection, or NULL\&. .SS "void axil_cert_add (char * str)" Add a certificate mapping: domain:cert\&.pem:key\&.pem (POSIX-only)\&. .SS "void axil_certs_add (char * fname)" Load certificate mappings from file (POSIX-only)\&. .SS "void axil_close (\fBsocket_t\fP fd)" Close a descriptor\&. .SS "void axil_command (\fBsocket_t\fP fd, int argc, char * argv[])\fR [extern]\fP" Called before a registered command handler\&. .SS "int axil_connect (\fBsocket_t\fP fd)\fR [extern]\fP" Called after a WebSocket upgrade completes via \fBaxil_ws_upgrade()\fP\&. Return non-zero to mark the connection as established (DF_CONNECTED)\&. .SS "int axil_deny_prefix (const char * prefix)" Register a URL path prefix to deny with 403 Forbidden (exact segment or prefix match)\&. Deny rules are evaluated before reverse-proxy routes, static files, and handlers\&. Returns 0 on success, -1 on invalid input or when the deny table is full\&. .SS "void axil_disconnect (\fBsocket_t\fP fd)\fR [extern]\fP" Called on disconnect\&. .PP Fires whenever a descriptor is torn down, not only when a peer hangs up -- \fBaxil_close()\fP and a failed read both reach it\&. It fires for unauthenticated descriptors too, and deliberately so: a module may attach a pty and spawn a child to a raw telnet terminal or a /tty GET, long before any authentication happens, so a hook gated on auth or on DF_CONNECTED would never clean those up\&. Because fd numbers are reused, anything a module keys by fd must be released here or it will attach itself to an unrelated later connection\&. .PP It also fires for a connection that was only ever HTTP-authenticated, which has no pty and no upstream: \fBaxil_auth()\fP marks the descriptor DF_CONNECTED, and that descriptor also enters DESCR_ITER, so \fBaxil_wall()\fP broadcasts to it\&. A module cannot tell an authenticated-but-pty-less connection from any other, so a hook here must tolerate a missing pty and a missing upstream rather than assuming a module connection shape\&. .SS "int axil_drop_ids (uid_t * uid, gid_t * gid)" Retrieve the resolved privilege-drop uid/gid from -u USER (POSIX-only)\&. Returns 0 if -u was configured and resolved before chroot(), -1 otherwise\&. .SS "int axil_dwritef (\fBsocket_t\fP fd, const char * fmt, va_list va)" Write formatted data using a va_list\&. .SS "unsigned axil_env (\fBsocket_t\fP fd)" Return internal env handle for fd (advanced use; stable but not recommended)\&. .SS "void axil_env_clear (\fBsocket_t\fP fd)" Clear request environment for fd\&. .SS "int axil_env_get (\fBsocket_t\fP fd, char * target, size_t dest_len, char * key)" Get environment value by key; returns 0 on success\&. .SS "int axil_env_put (\fBsocket_t\fP fd, char * key, char * value)" Set environment key/value; returns 0 on success\&. .SS "void axil_exec (\fBsocket_t\fP cfd, char *const args[], cmd_cb_t callback, void * input, size_t input_len)" Execute a command and stream output via callback (POSIX-only)\&. Callback ofd is 1 for stdout, 0 for stderr\&. .SS "int axil_exec_loop (\fBsocket_t\fP cfd)" Continue processing a command started with \fBaxil_exec()\fP (POSIX-only)\&. .SS "void axil_fd_unwatch (\fBsocket_t\fP fd)" Remove fd from the server's active and read watch sets (POSIX-only)\&. .SS "void axil_fd_watch (\fBsocket_t\fP fd)" Add fd to the server's active (select) watch set as an externally-managed fd\&. Sets DF_EXTERN so the main loop dispatches it via on_fd_tick rather than treating it as a client connection (POSIX-only)\&. .SS "int axil_flags (\fBsocket_t\fP fd)" Get descriptor flags\&. .SS "void axil_flush (\fBsocket_t\fP fd, int argc, char * argv[])\fR [extern]\fP" Called after a registered command handler\&. .SS "void axil_fork_child_reset (void )" Reset the cleanup flag in a forked child process (POSIX-only)\&. Must be called immediately after fork() in the child\&. .SS "unsigned long long axil_generation (\fBsocket_t\fP fd)" Get the per-connection generation of a descriptor\&. .PP A new value every accept, monotonic, never reused for a different connection\&. Because fd numbers are recycled, a module that keeps state keyed by fd should record this when it creates the state and refuse to act when it no longer matches -- that is what makes a leaked entry inert instead of silently attaching itself to an unrelated connection\&. Store it in whatever type the module's state uses; unsigned long long round-trips exactly\&. .PP Zero means "not a live descriptor", and is what a freshly zeroed slot reads as, so a default-initialised state can never match a real connection\&. .SS "int axil_get_pw (\fBsocket_t\fP fd, struct passwd * out)" Copy the authenticated user's passwd entry for fd into *out (POSIX-only)\&. Returns 0 on success, -1 if fd is not authenticated\&. .SS "int axil_header_get (\fBsocket_t\fP fd, const char * key, char * buf, size_t buf_len)" Get an incoming request header by its natural name (e\&.g\&. "Content-Type")\&. Copies the value into buf (at most buf_len-1 bytes, NUL-terminated)\&. Returns 0 on success, -1 if the header was not present in the request\&. .SS "void axil_header_set (\fBsocket_t\fP fd, const char * key, const char * value)" Add a response header\&. Call before \fBaxil_respond()\fP\&. .SS "int axil_json_escape (const char * in, char * out, size_t outlen)" JSON-escape a string\&. Escapes ", \\, .br , \\r, \\t and control characters\&. Returns 0 on success\&. .SS "int axil_main (void )" Run the main server loop (blocks)\&. .SS "ssize_t axil_mmap (char ** mapped, char * file)" Map a file into memory (POSIX-only)\&. .SS "char * axil_mmap_iter (char * start, size_t * pos)" Iterate mapped lines separated by ' .br ' (POSIX-only)\&. .SS "int axil_param (\fBsocket_t\fP fd, const char * name, char * buf, size_t buf_len)" Look up a parameter by name from parsed query/form body, falling back to route pattern parameters (PATTERN_PARAM_)\&. Returns bytes written, or -1 if the parameter was not found\&. .SS "int axil_param_bool (\fBsocket_t\fP fd, const char * name, int default_val)" Look up a boolean parameter by name via \fBaxil_param()\fP, returning default_val if missing or unparseable\&. Recognizes 1/true/on/yes and 0/false/off/no\&. .SS "int axil_param_int (\fBsocket_t\fP fd, const char * name, int default_val)" Look up an integer parameter by name via \fBaxil_param()\fP, returning default_val if missing or unparseable\&. .SS "int axil_peer_cred (\fBsocket_t\fP fd, uid_t * uid, gid_t * gid)" Query kernel-verified peer credentials on an AF_UNIX client socket (POSIX-only)\&. Returns 0 on success and stores peer uid/gid when non-NULL; returns -1 if fd is invalid, not an AF_UNIX socket, or peer credentials are unavailable\&. .SS "void axil_post_bind (void )\fR [extern]\fP" Called once after listening sockets are bound (and ephemeral port populated in axil_config\&.port) and before the event loop begins\&. .SS "int axil_post_chroot (void )\fR [extern]\fP" Called once after startup's \fR-C\fP chroot/chdir and before any bind\&. .PP libaxil fires it from axil_init(), between the platform's init_pre_bind() (which does the chroot/chdir) and axil_bind()\&. That window is the whole point: the filesystem view has already changed, no socket is listening yet, so a module loading content here resolves every path inside the jail and finishes before the first request can be served\&. The axil binary forwards it to the composable \fRon_axil_post_chroot\fP XY hook (\fBaxil-xy\&.h\fP); a host that does not define this symbol simply never fires it\&. .SS "int axil_privsep_key (unsigned char out[32])" Copy the 32-byte per-boot privsep HMAC key (POSIX-only)\&. Generated before chroot() when running as root with -u USER, readable ONLY while geteuid() == 0 (i\&.e\&. inside on_axil_post_chroot()), and cleansed from memory before setuid() drops privileges\&. Returns 0 on success, -1 otherwise\&. .SS "int axil_proxy_prefix (const char * prefix, const char * host, unsigned short port)" Register an HTTP reverse-proxy route forwarding requests under prefix to host:port or an AF_UNIX upstream ("unix:/path/to/sock" with port == 0 on POSIX)\&. Matches on exact path segment boundaries (longest matching prefix wins)\&. Returns 0 on success, -1 on invalid input or when the proxy table is full\&. .SS "int axil_query_param (const char * name, char * buf, size_t buf_len)" Look up a key previously parsed by \fBaxil_query_parse()\fP\&. Copies the URL-decoded value into buf (at most buf_len-1 bytes, NUL-terminated)\&. Returns the number of bytes written, or -1 if the key was not found\&. .SS "int axil_query_parse (char * body)" Parse a URL-encoded form body (application/x-www-form-urlencoded) into an internal key/value store\&. Call once per request before \fBaxil_query_param()\fP\&. Subsequent calls replace the previous parse result\&. Returns 0 on success, -1 on error\&. .SS "void axil_register (char * name, axil_cb_t * cb, int flags)" Register a command handler by name\&. .SS "int axil_register_fallback_handler (\fBaxil_handler_t\fP handler)" Register a fallback HTTP handler\&. Fallback handlers run after static files, registered handlers, and axil_config\&.default_handler have declined the request\&. Return non-zero when the request was handled\&. Returns 0 on success, -1 when the fallback table is full\&. .SS "void axil_register_handler (char * path, \fBaxil_handler_t\fP handler)" Register an HTTP handler for a path (exact match or pattern)\&. Patterns support :param syntax (e\&.g\&., "/items/:id" or "/a/:type/:id"), terminal catch-alls via * (e\&.g\&., "/items/" followed by "*"), and optional trailing slash matching on path patterns\&. Matched parameters are available via PATTERN_PARAM_ env vars\&. Example: "/items/:id" matches "/items/123", sets PATTERN_PARAM_ID="123" .SS "int axil_req_param (\fBsocket_t\fP fd, const char * body, const char * name, char * buf, size_t buf_len)" Unified request parameter lookup: extracts from parsed query/form params, non-destructively parses non-multipart body on-demand if provided, checks QUERY_STRING, and falls back to route pattern parameters\&. Returns bytes written, or -1 if not found\&. .SS "int axil_req_param_bool (\fBsocket_t\fP fd, const char * body, const char * name, int default_val)" Unified request boolean parameter lookup with fallback default\&. .SS "int axil_req_param_int (\fBsocket_t\fP fd, const char * body, const char * name, int default_val)" Unified request integer parameter lookup with fallback default\&. .SS "void axil_respond (\fBsocket_t\fP fd, int code, const char * body)" Send HTTP status, accumulated headers, body and close the connection\&. The connection is ALWAYS closed (even with body == NULL)\&. For a response completed later from the event loop, use \fBaxil_respond_defer()\fP instead\&. .SS "void * axil_respond_defer (\fBsocket_t\fP fd, int code)" Defer a response: send status line + accumulated headers now and keep the connection open for a later \fBaxil_respond_defer_finish()\fP/done()/abort()\&. Loop-thread only\&. Returns a handle, or NULL on invalid fd / already deferred / WebSocket connection\&. .SS "void axil_respond_defer_abort (void * handle)" Loop-thread only: abandon/abort a deferred response and close the socket (worker failed, client gone)\&. No-op if stale\&. .SS "void axil_respond_defer_done (void * handle)" Loop-thread only: close a deferred connection WITHOUT a body (end of a streamed response already written via axil_write)\&. No-op if stale\&. .SS "void axil_respond_defer_finish (void * handle, const char * body)" Loop-thread only: complete a deferred response by writing \fRbody\fP and closing the connection\&. No-op if the handle is stale (closed/reused fd)\&. .SS "int axil_respond_file (\fBsocket_t\fP fd, const char * path, const char * allowed_exts)" Serve a file from disk with validation against allowlisted extensions\&. Handles MIME type lookup, Content-Length, safe id checking, and streaming\&. Returns 0 on success, -1 on failure (error response sent)\&. .SS "void axil_sendfile (\fBsocket_t\fP fd, const char * path)" Serve a static file with auto-detected MIME type\&. Closes fd on completion\&. .SS "void axil_set_flags (\fBsocket_t\fP fd, int flags)" Set descriptor flags\&. .SS "int axil_slugify (const char * title, size_t title_len, char * result, size_t result_len)" Convert a title string to a URL/filesystem-safe slug\&. Transliterates Unicode to ASCII, lowercases, replaces spaces with underscores, strips non-alphanumeric characters\&. Falls back to "item" if the result would be empty\&. Returns 0 on success\&. .SS "const char * axil_status_text (int code)" Get HTTP status text for a status code\&. Returns "Unknown" for invalid codes\&. .SS "void axil_stop (void )" Signal a running \fBaxil_main()\fP loop to exit cleanly (thread- and signal-safe)\&. .SS "void axil_update (unsigned long long dt)\fR [extern]\fP" Periodic update hook\&. .SS "size_t axil_url_decode (const char * src, size_t src_len, char * out, size_t out_len)" URL-decode a percent-encoded substring\&. Handles XX and +\&. Returns number of bytes written (excluding NUL)\&. .SS "int axil_url_encode (const char * in, char * out, size_t outlen)" URL-encode a string\&. Writes percent-encoded output to out (NUL-terminated)\&. Returns number of bytes written (excluding NUL), or -1 on overflow\&. .SS "void axil_vim (\fBsocket_t\fP fd, int argc, char * argv[])\fR [extern]\fP" Called when a command is not found\&. .SS "void axil_wall (const char * msg)" Broadcast a message to all connected descriptors\&. .SS "int axil_write (\fBsocket_t\fP fd, void * data, size_t len)" Write raw bytes to a descriptor\&. Returns bytes written or -1\&. .SS "int axil_writef (\fBsocket_t\fP fd, const char * fmt, \&.\&.\&.)" Write formatted data\&. .SS "int axil_ws_close (\fBsocket_t\fP fd)" Close websocket connection\&. Returns 0, or -1 with \fRerrno\fP EBADF if \fRfd\fP is outside [0, FD_SETSIZE)\&. .SS "void axil_ws_handler (char * path, \fBaxil_ws_upstream_t\fP handler)" Register a websocket handler for a path\&. When a websocket request arrives for this path, the handler is called with the client socket\&. The handler connects to the upstream and returns the upstream socket\&. axil then forwards the HTTP upgrade, reads the response, and establishes a bidirectional tunnel\&. .SS "int axil_ws_printf (\fBsocket_t\fP fd, const char * fmt, \&.\&.\&.)" Formatted write to websocket\&. Returns the number of bytes written, or -1 on error (same contract as \fBaxil_ws_write()\fP, including the EBADF bound)\&. .SS "ssize_t axil_ws_read (\fBsocket_t\fP fd, void * buf, size_t len)" Read data from websocket\&. Returns bytes read (NUL-terminated), 0 on close, -1 on error\&. A frame larger than \fRlen - 1\fP is refused rather than truncated: -1 with \fRerrno\fP EMSGSIZE\&. A partially received frame returns -1 with \fRerrno\fP EAGAIN and stays open, so the caller must wait for readability\&. .PP \fRfd\fP must be in [0, FD_SETSIZE); anything else returns -1 with \fRerrno\fP EBADF\&. .SS "int axil_ws_upgrade (\fBsocket_t\fP fd)" Upgrade connection to websocket\&. Reads Sec-WebSocket-Key from the request environment, performs the handshake, and calls \fBaxil_connect()\fP on success\&. Modules should call this explicitly from their GET handler when HTTP_SEC_WEBSOCKET_KEY is present in the request environment\&. .PP You must also call axil_fd_watch(fd) immediately afterwards\&. axil drains incoming frames itself -- it has to, or the event loop spins on a socket that stays readable -- but it only hands them to the module once the fd is watched, via the axil_fd_tick() hook\&. Without \fBaxil_fd_watch()\fP every frame is read and discarded, silently: the connection completes its handshake and then ignores the client\&. Frames are never parsed as HTTP requests\&. .SS "int axil_ws_write (\fBsocket_t\fP fd, const void * data, size_t len)" Write data to websocket\&. Returns the size of the frame written, header included, or -1 if the connection failed\&. On a non-blocking socket a frame too large for the socket buffers is queued whole -- header and payload together, so frames cannot interleave -- and flushed by the event loop, so a non-negative result does not mean the bytes have already left the socket\&. .PP \fRfd\fP must be in [0, FD_SETSIZE); anything else returns -1 with \fRerrno\fP EBADF rather than indexing the module's descriptor tables out of bounds\&. .SH "Variable Documentation" .PP .SS "char axil_execbuf[BUFSIZ *64]\fR [extern]\fP" Shared exec buffer (legacy)\&. Prefer callbacks; symbol is stable\&. .SH "Author" .PP Generated automatically by Doxygen for axil from the source code\&.