Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
Loading...
Searching...
No Matches
context_internal.h File Reference

Internal layout of csilk_ctx_s — the central per-request data structure. More...

#include <setjmp.h>
#include <uv.h>
#include "csilk/csilk.h"
Include dependency graph for context_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  csilk_method_handler_t
 Method-specific handler mapping with OpenAPI metadata and permission info. More...
 
struct  csilk_storage_item_t
 A single key-value item in the context's custom storage linked list. More...
 
struct  csilk_ctx_t
 Main Request Context — holds all state for the current HTTP request/response cycle. More...
 

Functions

void _csilk_ctx_init (csilk_ctx_t *c, struct csilk_server_s *s, void *client)
 Internal context initialiser.
 

Detailed Description

Internal layout of csilk_ctx_s — the central per-request data structure.

This header defines the actual memory layout of the request context struct. It is included ONLY by internal framework code (src/core/). External handlers receive an opaque csilk_ctx_t* and interact through the public API in csilk.h.

The context is the single most important data structure in csilk. It is created per-connection, reused across keep-alive requests via csilk_ctx_cleanup(), and carries:

  • Parsed HTTP request data (method, path, headers, body, query)
  • HTTP response data (status, headers, body)
  • URL path parameters captured during routing
  • Handler chain state (index, abort flag)
  • Error recovery (setjmp/longjmp buffer for middleware recovery)
  • Arena allocator for request-scoped memory
  • WebSocket/SSE mode flags and callbacks
  • Pluggable driver pointers (storage, crypto, cipher)
  • Zero-copy file serving state (sendfile fd/offset/size)
  • Per-request UUID for tracing

Data Structure Documentation

◆ csilk_method_handler_s

struct csilk_method_handler_s

Method-specific handler mapping with OpenAPI metadata and permission info.

Each entry in this linked list represents one HTTP method + handler chain registered at a specific route path. In addition to the handler function array, it carries optional metadata used by:

  • OpenAPI spec generation (input_type, output_type, summary, description)
  • Permission/ACL checks (perm_required, perm_resource)
Collaboration diagram for csilk_method_handler_t:
Data Fields
const char * description

Detailed description of the operation.

csilk_handler_t * handlers

NULL-terminated array of handler function pointers for this method.

const char * input_type

Registered type name for request body binding (optional, used by csilk_bind_reflect()).

char * method

HTTP method string (e.g., "GET", "POST").

struct csilk_method_handler_s * next

Next method handler in this node's linked list.

const char * output_type

Registered type name for response generation (optional, used by csilk_json_reflect()).

char * path

Metadata for OpenAPI spec generation URL path pattern (e.g., "/users/:id").

const char * perm_required

Permission metadata for interface-level access control Permission required for this route (e.g., "read", "write"), or NULL if no check.

const char * perm_resource

Resource pattern for permission check (e.g., "users:*"), or NULL.

const char * summary

Short summary of the operation.

◆ csilk_storage_item_t

struct csilk_storage_item_t

A single key-value item in the context's custom storage linked list.

Items are allocated from the request arena and form a singly-linked list accessible via csilk_set()/csilk_get(). When a storage driver is set on the context, it takes precedence over this simple linked list.

Data Fields
char * key

Item key name (arena-allocated).

struct csilk_storage_item_s * next

Next item in the linked list (NULL if tail).

void * value

Opaque pointer to user data (not copied, not freed).

Function Documentation

◆ _csilk_ctx_init()

void _csilk_ctx_init ( csilk_ctx_t *  c,
struct csilk_server_s s,
void *  client 
)

Internal context initialiser.

Internal context initialiser.

Sets up default values for all fields. Should be called for both static (embedded in client) and dynamic (H2 stream) contexts.

Parameters
cThe context to initialize.
sThe owning server instance.
clientThe underlying connection object (csilk_client_t*).