20#ifndef __CWIST_WASM_COMPONENT_H__
21#define __CWIST_WASM_COMPONENT_H__
42static inline int cwist_wasm_component_dispatch(
cwist_app *app,
const uint8_t *req_buf,
43 size_t req_len, uint8_t **res_buf,
45 if (!res_buf || !res_len)
return -1;
53static inline void cwist_wasm_component_dispose(
void *ptr) {
69static inline int cwist_wasm_component_dispatch_stream(
cwist_app *app,
const uint8_t *req_buf,
85#define CWIST_WASM_COMPONENT_DEFINE_GUEST(app_ptr) \
86 bool exports_c4punks_cwist_guest_dispatch( \
87 cwist_guest_list_u8_t *request, cwist_guest_list_u8_t *ret, \
88 exports_c4punks_cwist_guest_dispatch_error_t *err) { \
89 uint8_t *res_buf = NULL; \
91 if (cwist_wasm_component_dispatch((app_ptr), request->ptr, request->len, &res_buf, \
93 err->tag = EXPORTS_C4PUNKS_CWIST_GUEST_DISPATCH_ERROR_INVALID_REQUEST; \
100 bool exports_c4punks_cwist_guest_use_session( \
101 cwist_guest_string_t *maybe_secret, exports_c4punks_cwist_guest_session_error_t *err) { \
102 char secret_buf[256]; \
103 const char *secret = NULL; \
104 if (maybe_secret) { \
105 if (maybe_secret->len >= sizeof(secret_buf)) { \
106 err->tag = EXPORTS_C4PUNKS_CWIST_GUEST_SESSION_ERROR_REJECTED; \
109 memcpy(secret_buf, maybe_secret->ptr, maybe_secret->len); \
110 secret_buf[maybe_secret->len] = '\0'; \
111 secret = secret_buf; \
113 if (cwist_app_use_session((app_ptr), secret) != 0) { \
114 err->tag = EXPORTS_C4PUNKS_CWIST_GUEST_SESSION_ERROR_REJECTED; \
Memory allocation wrappers backed by libttak.
void cwist_free(void *ptr)
Free memory obtained via cwist_alloc/cwist_strdup/etc.
Main Application Context.
Core Application Structure and Lifecycle Management.
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...
int(* cwist_stream_write_fn)(void *ctx, const char *data, size_t len)
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,...