cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
https.h
Go to the documentation of this file.
1
6#ifndef __CWIST_HTTPS_H__
7#define __CWIST_HTTPS_H__
8
11#include <openssl/ssl.h>
12#include <openssl/err.h>
13#include <pthread.h>
14
15#define HTTPS_THREAD_POOL_SIZE HTTP_THREAD_POOL_SIZE
16
25
26typedef struct cwist_https_context {
27 SSL_CTX *ctx;
30 void *ticket_key;
35 pthread_rwlock_t ctx_lock;
37
38typedef struct cwist_https_connection {
39 int fd;
40 SSL *ssl;
41 char *read_buf;
42 size_t buf_len;
46 bool http2_sequenced_data; /*< Enable CWIST-specific sequenced DATA frames. */
47 bool deferred; /*< True when response processing has been deferred. */
48 /* Idle parking (cwist_https_park). Internal to the HTTPS pool. */
49 bool park_expired; /*< Resumed because the parked idle deadline passed. */
50 void *proto_state; /*< Protocol session kept while parked (HTTP/2). */
51 void (*proto_state_free)(void *state);
52 struct cwist_https_context *pool_ctx; /*< Pool task that serves this connection. */
53 void (*pool_handler)(struct cwist_https_connection *, void *);
56
59 CWIST_HTTPS_PARK_HTTP1 = 0, /*< Expiry closes the connection. */
60 CWIST_HTTPS_PARK_HTTP2 = 1 /*< Expiry resubmits it with park_expired set (GOAWAY). */
62
63typedef struct cwist_app cwist_app;
64
69
85bool cwist_https_park(cwist_https_connection *conn, uint64_t idle_ms, cwist_https_park_class cls);
86
89
95uint64_t cwist_https_idle_timeout_ms(void);
96
102 const char *key_path);
103
110 const char *cert_path, const char *key_path,
111 const cwist_https_options *options,
112 cwist_app *app);
113
118
138 const char *key_path, cwist_app *app);
139
146
151
156
161
167
176
182 void (*handler)(cwist_https_connection *conn, void *),
183 void *user_ctx);
184
188int https_pool_init(void);
189void https_pool_submit(int client_fd, cwist_https_context *ctx,
190 void (*handler)(cwist_https_connection *, void *), void *user_ctx);
192 void (*handler)(cwist_https_connection *, void *), void *user_ctx);
193void https_pool_destroy(void);
194
202void cwist_https_dispatch(int client_fd, cwist_https_context *ctx,
203 void (*handler)(cwist_https_connection *, void *), void *user_ctx);
204
207
208/* --- TLS observability counters (mirrored into the Prometheus /metrics
209 * exposition by the metrics registry; see src/sys/metrics/metrics.c) --- */
210
229
236#endif
mbedTLS TLS backend: error queue subset.
cwist_http_request * cwist_https_receive_request(cwist_https_connection *conn)
Read from the TLS stream until a full HTTP request has been assembled.
Definition https.c:1887
cwist_error_t cwist_https_accept(cwist_https_context *ctx, int client_fd, cwist_https_connection **conn)
Definition https.c:1756
cwist_error_t cwist_https_server_loop(int server_fd, cwist_https_context *ctx, void(*handler)(cwist_https_connection *conn, void *), void *user_ctx)
cwist_error_t cwist_https_send_response(cwist_https_connection *conn, cwist_http_response *res)
Serialize an HTTP response and send it over an active TLS connection.
Definition https.c:2102
cwist_error_t cwist_https_init_context(cwist_https_context **ctx, const char *cert_path, const char *key_path)
Definition https.c:1369
struct cwist_https_connection cwist_https_connection
void cwist_https_close_connection(cwist_https_connection *conn)
Definition https.c:1875
void cwist_https_destroy_context(cwist_https_context *ctx)
Free an HTTPS context and release its OpenSSL resources.
Definition https.c:1558
struct cwist_https_context cwist_https_context
HTTP Protocol Definitions and Helpers.
cwist_https_park_class
Definition https.h:58
@ CWIST_HTTPS_PARK_HTTP2
Definition https.h:60
@ CWIST_HTTPS_PARK_HTTP1
Definition https.h:59
long cwist_https_tls_ciphers_aes128_gcm_total(void)
Handshakes negotiated with TLS_AES_128_GCM_SHA256.
Definition https.c:1613
void https_pool_submit_conn(cwist_https_connection *conn, cwist_https_context *ctx, void(*handler)(cwist_https_connection *, void *), void *user_ctx)
Submit an established connection back to the worker pool (e.g. keep-alive re-arm after async defer)....
Definition https.c:341
cwist_https_protocol
Definition https.h:19
@ CWIST_HTTPS_PROTOCOL_HTTP3
Definition https.h:23
@ CWIST_HTTPS_PROTOCOL_HTTP2
Definition https.h:22
@ CWIST_HTTPS_PROTOCOL_HTTP11
Definition https.h:21
@ CWIST_HTTPS_PROTOCOL_NONE
Definition https.h:20
void https_pool_destroy(void)
Shut down the global HTTPS thread pool: signal workers to exit, join them, close any connections stil...
Definition https.c:370
cwist_https_protocol cwist_https_connection_protocol(const cwist_https_connection *conn)
Definition https.c:1821
cwist_error_t cwist_https_reload_context(cwist_https_context *ctx, const char *cert_path, const char *key_path, cwist_app *app)
Hot-reload the certificate chain and key of a live HTTPS context.
Definition https.c:1508
int https_pool_init(void)
Create the worker threads, mutex, and condition variables of the global HTTPS thread pool....
Definition https.c:268
long cwist_https_tls_handshakes_total(void)
Total TLS handshakes that completed (full + resumed).
Definition https.c:1597
long cwist_https_tls_ciphers_other_total(void)
Handshakes negotiated with any other cipher.
Definition https.c:1625
uint64_t cwist_https_idle_timeout_ms(void)
Idle keep-alive budget for parked HTTP/1.1 TLS connections, in ms. CWIST_HTTPS_IDLE_TIMEOUT_MS overri...
Definition https.c:710
cwist_error_t cwist_https_send_response_head(cwist_https_connection *conn, cwist_http_response *res)
Definition https.c:2197
long cwist_https_tls_handshakes_tls12_total(void)
Handshakes that negotiated TLS 1.2.
Definition https.c:1605
long cwist_https_tls_ciphers_chacha20_total(void)
Handshakes negotiated with TLS_CHACHA20_POLY1305_SHA256.
Definition https.c:1621
cwist_error_t cwist_https_init_context_with_options(cwist_https_context **ctx, const char *cert_path, const char *key_path, const cwist_https_options *options, cwist_app *app)
Definition https.c:1451
bool cwist_https_conn_idle(cwist_https_connection *conn)
True when conn has no buffered TLS bytes and nothing readable.
Definition https.c:683
long cwist_https_pending_handshakes(void)
Number of TLS handshakes currently parked in the shepherd.
Definition https.c:1136
long cwist_https_tls_handshakes_resumed_total(void)
TLS handshakes completed via session resumption/ticket.
Definition https.c:1601
bool cwist_https_connection_uses_http2(const cwist_https_connection *conn)
Gracefully close an HTTPS connection and free its buffers.
Definition https.c:1817
long cwist_https_tls_handshakes_tls13_total(void)
Handshakes that negotiated TLS 1.3.
Definition https.c:1609
bool cwist_https_park(cwist_https_connection *conn, uint64_t idle_ms, cwist_https_park_class cls)
Hand an idle connection back to the HTTPS pool's park set.
Definition https.c:672
long cwist_https_tls_connections_active(void)
Currently established TLS connections (wrap minus teardown).
Definition https.c:1629
void cwist_https_dispatch(int client_fd, cwist_https_context *ctx, void(*handler)(cwist_https_connection *, void *), void *user_ctx)
Accept a TLS connection without parking a worker on the handshake. Completes the handshake inline whe...
Definition https.c:1141
void https_pool_submit(int client_fd, cwist_https_context *ctx, void(*handler)(cwist_https_connection *, void *), void *user_ctx)
Queue a freshly accepted client socket whose TLS handshake still needs to run in a pool worker.
Definition https.c:292
long cwist_https_tls_ciphers_aes256_gcm_total(void)
Handshakes negotiated with TLS_AES_256_GCM_SHA384.
Definition https.c:1617
mbedTLS TLS backend: OpenSSL-shaped seam over the CWIST TLS subset.
struct cwist_mtls_ssl SSL
Definition ssl.h:44
struct cwist_mtls_ctx SSL_CTX
Definition ssl.h:43
Main Application Context.
Definition app.h:155
Integrated error structure used throughout the system.
Definition cwist_err.h:72
HTTP Response Object. Supports standard string body or Zero-Copy pointer body.
Definition http.h:82
void(* proto_state_free)(void *state)
Definition https.h:51
struct cwist_https_context * pool_ctx
Definition https.h:52
bool http2_sequenced_data
Definition https.h:46
cwist_https_protocol negotiated_protocol
Definition https.h:44
void(* pool_handler)(struct cwist_https_connection *, void *)
Definition https.h:53
void * ticket_key
Shared session-ticket key material (forked workers inherit it)
Definition https.h:18
SSL_CTX * ctx
Definition https.h:17
pthread_rwlock_t ctx_lock
Definition https.h:35
Unified error code and type definitions for the CWIST system layer.