19#include <ttak/mem_tree/mem_tree.h>
279 const char *openapi_json_path);
334 uint64_t revalidate_hits);
464#define cwist_use_https2(enabled) cwist_app_use_https2((app), (enabled))
465#define cwist_use_https3(enabled) cwist_app_use_https3((app), (enabled))
466#define cwist_use_http2(enabled) cwist_app_use_http2((app), (enabled))
467#define cwist_use_http3(enabled) cwist_app_use_http3((app), (enabled))
580 const char *directory,
const char *cache_control);
586#ifndef CWIST_MULTIPORT_MAX_PORTS
587#define CWIST_MULTIPORT_MAX_PORTS 64
611#define cwist_create_multiport(ports) \
612 cwist_create_multiport_from_array((ports), sizeof(ports) / sizeof((ports)[0]))
711#define CWIST_STREAM_CHUNK (64 * 1024)
Auto-Caching Layer for repetitive requests.
Database operations wrapper (SQLite3).
Convenience size-conversion and utility macros shared across CWIST.
Minimal in-tree Redis client (RESP2) with connection pooling.
struct cwist_redis_pool cwist_redis_pool_t
Redis connection pool handle.
uint32_t cwist_endpoint_opt_t
Bitmask type controlling endpoint behavior.
gRPC over HTTP/2 helpers for CWIST.
HTTP Protocol Definitions and Helpers.
HTTPS/TLS wrapper interface.
WebSocket upgrade and frame handling.
SQLite connection pool for CWIST.
struct cwist_db_pool cwist_db_pool_t
Opaque database connection pool handle.
Background job scheduler / delayed task queue for CWIST.
struct cwist_scheduler cwist_scheduler_t
Opaque background job scheduler handle.
Main Application Context.
bool nuke_enabled
True when NUKE DB integration is active.
bool use_https2
TLS HTTP/2 (h2)
void * redis_pool
Redis connection pool (when enabled).
size_t max_mem_space
Max memory space for static file pool (0 = auto-detected * 2)
void * scheduler
Background job scheduler (when enabled).
cwist_webtransport_handler_func wt_handler
WebTransport session handler.
cwist_error_handler_func error_handler
Global fallback error handler.
int session_max_age
Session cookie max-age in seconds.
cwist_https_context * ssl_ctx
SSL context when TLS is enabled.
struct cwist_fix_server_mem * mem_manager
Memory manager for static asset caching and hot-reloading.
char * session_secret
Session signing secret (HMAC-SHA256).
bool use_http2
Cleartext HTTP/2 (h2c)
cwist_error_handler_entry * error_handlers
Per-status-code error handlers.
bool use_http3
Ephemeral (Zero-config) HTTP/3.
cwist_bdr_t * bdr_ctx
Legacy standalone BDR storage; never replayed by HTTP dispatch.
cwist_route_table * router
Router definition.
cwist_db * db
Shared database handle.
char * session_name
Session cookie name.
cwist_https_request_handler_func https_request_handler
char * tls_groups
Explicit TLS groups override (NULL = automatic)
void * db_pool
Database connection pool (when enabled).
char * db_path
Database path (if set).
bool use_https3
TLS HTTP/3.
struct cwist_rdbms_runtime * rdbms
Mounted RDBMS runtime (auto-detected PostgreSQL/MySQL/MariaDB)
struct cwist_config * config
Application configuration.
bool pqc_layer_enabled
PQC Layer enabled flag.
struct cwist_http3_context * h3_ctx
HTTP/3 QUIC Context.
cwist_middleware_node * middlewares
Head of the middleware chain.
cwist_static_dir * static_dirs
Static directory mappings.
void * grpc_routes
Unary gRPC route registry.
struct cwist_logger * logger
Application logger.
void * assets
Content-hashed in-memory assets (see <cwist/sys/app/assets.h>).
Big Dumb Reply Context. Lock-free read/learn paths; the mutex only serializes janitor work (sweep/tri...
Wrapper for Database Operations. Currently uses SQLite3.
cwist_error_handler_func handler
struct cwist_error_handler_entry * next
cwist_http_status_t status_code
Integrated error structure used throughout the system.
Represents a file loaded into the fixed memory pool.
void * data
Pointer to memory-tracked file contents.
size_t size
Size of the file in bytes.
char etag[40]
Precomputed ETag for conditional requests.
ttak_mem_node_t * node
Tracking node for libttak lifecycle.
time_t last_mod
Last modification time.
char * fs_path
Full filesystem path.
char * path
Relative path (URL path)
char last_mod_hdr[30]
Precomputed HTTP-date (29 chars + NUL)
Fixed Server Memory Manager.
size_t files_capacity
Capacity of the files array.
ttak_mem_tree_t file_tree
Lifetime tracking tree for file buffers.
size_t current_used
Bytes accounted for by active files.
uint64_t retire_grace_ns
Delay before recycling replaced buffers.
cwist_file_t * files
Array of tracked files.
size_t total_capacity
Total capacity (defaults to sum of files * 2)
HTTP/3 server context encapsulating lsquic/BoringSSL settings.
HTTP Response Object. Supports standard string body or Zero-Copy pointer body.
Linked list node for middleware chain.
struct cwist_middleware_node * next
cwist_middleware_ctx_destroy_func destroy
cwist_middleware_func_ex func_ex
cwist_middleware_func func
Counted multiport descriptor created from a normal C array.
bool valid
False when construction failed, e.g. too many ports.
unsigned short ports[CWIST_MULTIPORT_MAX_PORTS]
Additional TCP ports.
size_t count
Number of valid entries in ports.
Mounted RDBMS runtime state.
cwist_rdbms_provider_t provider
int cwist_app_listen(cwist_app *app, int port)
Serve app on port until SIGTERM, SIGINT or cwist_shutdown_request(); blocks the calling thread.
enum cwist_rdbms_provider cwist_rdbms_provider_t
RDBMS provider auto-detection result.
void cwist_app_delete(cwist_app *app, const char *path, cwist_handler_func handler)
cwist_rdbms_provider_t cwist_rdbms_probe_port(int port)
Probe a TCP port for an RDBMS wire protocol.
#define CWIST_MULTIPORT_MAX_PORTS
void(* cwist_webtransport_handler_func)(cwist_http_request *req, cwist_http_response *res, void *stream)
Callback function type for handling WebTransport sessions over HTTP/3.
void cwist_app_enable_metrics(cwist_app *app)
void cwist_app_enable_swagger(cwist_app *app, const char *mount_path, const char *openapi_json_path)
Enables embedded Swagger UI interactive documentation page.
cwist_error_t cwist_app_static_with_cache(cwist_app *app, const char *url_prefix, const char *directory, const char *cache_control)
Serves a directory of static files at a URL prefix with custom Cache-Control. Files are loaded into t...
cwist_error_t cwist_app_use_ex(cwist_app *app, cwist_middleware_func mw, cwist_middleware_func_ex mw_ex, void *user_ctx, cwist_middleware_ctx_destroy_func destroy)
Append an extended middleware to the application chain.
void cwist_app_put_named(cwist_app *app, const char *path, const char *name, cwist_handler_func handler)
cwist_app * cwist_multiport_get_app(cwist_app **app_ref, unsigned short port)
Detach one additional multiport port into its own tunable application.
void cwist_app_delete_opt(cwist_app *app, const char *path, cwist_handler_func handler, cwist_endpoint_opt_t opts)
cwist_stream_req_t * cwist_stream_req_begin(const char *head, size_t head_len)
Begin an incremental request: head is the serialized request line plus headers (everything up to and ...
void cwist_app_ws_opt(cwist_app *app, const char *path, cwist_ws_handler_func handler, cwist_endpoint_opt_t opts)
Register a WebSocket route with explicit endpoint options.
cwist_error_t cwist_app_use_nuke_db(cwist_app *app, const char *db_path, int sync_interval_ms)
Enable NUKE DB and fall back to standard SQLite when RAM bootstrap fails.
cwist_error_t cwist_app_static(cwist_app *app, const char *url_prefix, const char *directory)
Serves a directory of static files at a URL prefix. Files are loaded into the fixed memory pool for Z...
int cwist_stream_req_end(cwist_stream_req_t *req)
Declare the body complete. The fed byte count must equal the declared Content-Length (or both be zero...
void cwist_app_post_named(cwist_app *app, const char *path, const char *name, cwist_handler_func handler)
void(* cwist_handler_func)(cwist_http_request *req, cwist_http_response *res)
Function pointer type for HTTP route handlers.
void cwist_app_get(cwist_app *app, const char *path, cwist_handler_func handler)
Registers a GET route handler.
void cwist_apply_profile(void)
Apply CWIST_PROFILE preset env-var defaults.
void cwist_app_http_handler(int client_fd, void *ctx)
char * cwist_url_for(cwist_app *app, const char *name, cwist_query_map *params)
void cwist_app_configure_bdr(cwist_app *app, size_t max_bytes, time_t max_entry_age_sec, uint64_t revalidate_hits)
Configures the Big Dumb Reply guardrails.
void(* cwist_error_handler_func)(cwist_http_request *req, cwist_http_response *res, cwist_http_status_t status)
Function pointer type for error handlers.
cwist_db_pool_t * cwist_app_get_db_pool(cwist_app *app)
Return the application's database connection pool.
cwist_error_t cwist_app_reload_tls(cwist_app *app, const char *cert_path, const char *key_path)
Hot-reload the TLS certificate chain and key without restarting the listener.
void(* cwist_ws_handler_func)(cwist_websocket *ws)
Function pointer type for WebSocket handlers.
void cwist_app_patch_named(cwist_app *app, const char *path, const char *name, cwist_handler_func handler)
cwist_error_t cwist_app_use_redis(cwist_app *app, const char *host, int port, size_t max_conns)
Configure a Redis connection pool for the application.
void cwist_app_post(cwist_app *app, const char *path, cwist_handler_func handler)
Register a POST handler with default endpoint options.
void(* cwist_middleware_func_ex)(cwist_http_request *req, cwist_http_response *res, cwist_handler_func next, void *user_ctx)
Extended middleware type that also receives a user context.
cwist_error_t cwist_app_use_db(cwist_app *app, const char *db_path)
Open a SQLite database and attach it as the shared application handle.
void cwist_app_put(cwist_app *app, const char *path, cwist_handler_func handler)
int cwist_app_dispatch_stream(cwist_app *app, const char *req_buf, size_t req_len, cwist_stream_write_fn write_fn, void *write_ctx)
Like cwist_app_dispatch_memory(), but streams the serialized response through write_fn instead of ret...
void cwist_app_get_opt(cwist_app *app, const char *path, cwist_handler_func handler, cwist_endpoint_opt_t opts)
Register a GET handler with explicit endpoint options.
cwist_error_t cwist_app_post_ex(cwist_app *app, const char *path, cwist_handler_ex_func handler, void *user_ctx, cwist_handler_ctx_destroy_func destroy)
POST counterpart of cwist_app_get_ex().
void(* cwist_handler_ctx_destroy_func)(void *user_ctx)
Releases a route's user context once the route no longer needs it.
cwist_error_t cwist_app_put_ex(cwist_app *app, const char *path, cwist_handler_ex_func handler, void *user_ctx, cwist_handler_ctx_destroy_func destroy)
PUT counterpart of cwist_app_get_ex().
void cwist_app_set_error_handler(cwist_app *app, cwist_error_handler_func handler)
Install a custom HTTP error callback.
void(* cwist_handler_ex_func)(void *user_ctx, cwist_http_request *req, cwist_http_response *res)
Route handler that also receives the context it was registered with.
int(* cwist_stream_write_fn)(void *ctx, const char *data, size_t len)
cwist_error_t cwist_app_get_ex(cwist_app *app, const char *path, cwist_handler_ex_func handler, void *user_ctx, cwist_handler_ctx_destroy_func destroy)
Registers a GET route whose handler receives a user context.
void cwist_app_post_opt(cwist_app *app, const char *path, cwist_handler_func handler, cwist_endpoint_opt_t opts)
Register a POST handler with explicit endpoint options.
void(* cwist_middleware_ctx_destroy_func)(void *user_ctx)
Destructor for a middleware user context.
void cwist_app_set_tls_groups(cwist_app *app, const char *groups)
Override TLS groups explicitly.
void cwist_app_patch_opt(cwist_app *app, const char *path, cwist_handler_func handler, cwist_endpoint_opt_t opts)
bool cwist_app_auto_rdbms(cwist_app *app, int port)
Auto-detect and mount an RDBMS runtime by probing a TCP port.
void cwist_app_use(cwist_app *app, cwist_middleware_func mw)
Append a middleware callback to the application's execution chain.
cwist_error_t cwist_app_use_db_pool(cwist_app *app, const char *db_path, size_t max_conns)
Open a SQLite connection pool and attach it to the application.
void cwist_app_get_named(cwist_app *app, const char *path, const char *name, cwist_handler_func handler)
void cwist_app_destroy(cwist_app *app)
Destroys the application and frees all resources.
int cwist_stream_req_dispatch(cwist_stream_req_t *req, cwist_app *app, cwist_stream_write_fn write_fn, void *write_ctx)
Dispatch a completed incremental request with a streaming response. Takes ownership of req regardless...
void cwist_app_enable_healthz(cwist_app *app)
cwist_rdbms_provider
RDBMS provider auto-detection result.
void cwist_app_put_opt(cwist_app *app, const char *path, cwist_handler_func handler, cwist_endpoint_opt_t opts)
cwist_error_t cwist_app_use_http2(cwist_app *app, bool enabled)
Enable HTTP/2 cleartext (h2c) over standard TCP.
cwist_scheduler_t * cwist_app_get_scheduler(cwist_app *app)
Return the application's background job scheduler.
cwist_app * cwist_app_create(void)
Creates a new CWIST application instance.
struct cwist_route_table cwist_route_table
cwist_error_t cwist_app_patch_ex(cwist_app *app, const char *path, cwist_handler_ex_func handler, void *user_ctx, cwist_handler_ctx_destroy_func destroy)
PATCH counterpart of cwist_app_get_ex().
cwist_error_t cwist_app_use_http3(cwist_app *app, bool enabled)
Enable HTTP/3 (QUIC) without manual SSL configuration. Auto-generates an ephemeral self-signed certif...
void cwist_app_use_webtransport(cwist_app *app, cwist_webtransport_handler_func handler)
Enable WebTransport over HTTP/3 on the application.
cwist_error_t cwist_app_use_https2(cwist_app *app, bool enabled)
void cwist_app_dispatch(cwist_app *app, cwist_http_request *req, cwist_http_response *res)
Dispatch a request internally through the app's router and middleware. Used by the test client and ad...
void(* cwist_middleware_func)(cwist_http_request *req, cwist_http_response *res, cwist_handler_func next)
Middleware type that receives req/res pair and the next stage in the chain.
void cwist_app_ws_async(cwist_app *app, const char *path, cwist_ws_on_message_t on_message, void *user_data)
Register a callback-shaped non-blocking WebSocket endpoint (C1M mode).
cwist_async_action_t cwist_app_http_handler_async(int client_fd, cwist_http_async_conn_t *conn)
struct cwist_stream_req cwist_stream_req_t
int cwist_app_listen_ex(cwist_app *app, int port, int workers_override, int c1m_override)
cwist_app_listen() with the worker count and server mode given explicitly.
cwist_multiport_t cwist_create_multiport_from_array(const unsigned short *ports, size_t count)
Create a counted multiport descriptor from an explicit pointer and length.
void cwist_app_patch(cwist_app *app, const char *path, cwist_handler_func handler)
void(* cwist_https_request_handler_func)(cwist_https_connection *conn, void *ctx)
int cwist_stream_req_feed(cwist_stream_req_t *req, const char *chunk, size_t len)
Feed one body chunk. Chunks may be any size and may split anywhere; reassembly is the implementation'...
void cwist_app_register_error_handler(cwist_app *app, cwist_http_status_t status, cwist_error_handler_func handler)
void cwist_app_set_max_memspace(cwist_app *app, size_t size)
Sets the maximum memory space for the static file pool.
cwist_error_t cwist_app_delete_ex(cwist_app *app, const char *path, cwist_handler_ex_func handler, void *user_ctx, cwist_handler_ctx_destroy_func destroy)
DELETE counterpart of cwist_app_get_ex().
cwist_error_t cwist_app_use_scheduler(cwist_app *app, size_t worker_count, size_t queue_capacity)
Configure a background job scheduler for the application.
cwist_error_t cwist_app_use_https3(cwist_app *app, bool enabled)
void cwist_app_ws(cwist_app *app, const char *path, cwist_ws_handler_func handler)
Register a WebSocket upgrade endpoint with default options.
int cwist_app_dispatch_memory(cwist_app *app, const char *req_buf, size_t req_len, char **res_buf, size_t *res_len)
Run the full router/middleware/handler pipeline on a raw HTTP/1.x request held in a memory buffer,...
int cwist_app_multiport(cwist_app **app_ref, unsigned short public_port, cwist_multiport_t ports)
Start one app facade across a public port and counted backend port list.
bool cwist_rdbms_mount_runtime(cwist_app *app, cwist_rdbms_provider_t provider, int port)
Mount an RDBMS runtime for the given provider and port.
cwist_error_t cwist_app_use_https(cwist_app *app, const char *cert_path, const char *key_path)
Enable TLS for the application using the supplied certificate pair.
cwist_db * cwist_app_get_db(cwist_app *app)
Return the active shared database wrapper for the application.
void cwist_app_delete_named(cwist_app *app, const char *path, const char *name, cwist_handler_func handler)
void cwist_app_use_pqc_layer(cwist_app *app, bool enabled)
Enable Post-Quantum Cryptography (PQC) hybrid key exchange layer.
struct cwist_static_dir cwist_static_dir
cwist_redis_pool_t * cwist_app_get_redis_pool(cwist_app *app)
Return the application's Redis connection pool.
Unified error code and type definitions for the CWIST system layer.
Reactor-driven, callback-shaped non-blocking WebSocket API (C1M mode).
void(* cwist_ws_on_message_t)(cwist_websocket_async *ws, cwist_ws_frame *frame, void *user_data)
Callback invoked for each complete WebSocket message on the C1M path.