commit 3a1e3719af911ad6724e616075570254c314f8f6
parent 6e9b10d992f241e3049be148f11ba4957c48a2e4
Author: Sophie <info@soophie.de>
Date: Sun, 15 Dec 2024 19:38:17 +0000
feat: Added additional data property to ctl_ctx_t struct
Diffstat:
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/libctl.h b/src/libctl.h
@@ -11,11 +11,12 @@ struct ctl_ctx {
http_request_t *request;
char *title;
ctl_fn_t fn;
+ void *data;
};
void ctl_init(ctl_fn_t fn);
-http_response_t ctl_serve_page(http_request_t *request, const char *title, ctl_fn_t fn);
-http_response_t ctl_serve_component(http_request_t *request, ctl_fn_t fn);
+http_response_t ctl_serve_page(http_request_t *request, const char *title, ctl_fn_t fn, void *data);
+http_response_t ctl_serve_component(http_request_t *request, ctl_fn_t fn, void *data);
#ifdef LIB_CTL_IMPL
@@ -25,12 +26,13 @@ void ctl_init(ctl_fn_t fn) {
ctl_fn = fn;
}
-http_response_t ctl_serve_page(http_request_t *request, const char *title, ctl_fn_t fn) {
+http_response_t ctl_serve_page(http_request_t *request, const char *title, ctl_fn_t fn, void *data) {
char *html = NULL;
ctl_ctx_t ctx = {
.request = request,
.title = title,
.fn = fn,
+ .data = data,
};
ctl_fn(&html, ctx);
http_response_t response = http_response_create(HTTP_STATUS_OK);
@@ -40,10 +42,11 @@ http_response_t ctl_serve_page(http_request_t *request, const char *title, ctl_f
return response;
}
-http_response_t ctl_serve_component(http_request_t *request, ctl_fn_t fn) {
+http_response_t ctl_serve_component(http_request_t *request, ctl_fn_t fn, void *data) {
char *html = NULL;
ctl_ctx_t ctx = {
.request = request,
+ .data = data,
};
fn(&html, ctx);
http_response_t response = http_response_create(HTTP_STATUS_OK);