From 0b7bfb198191e1d4e4f74046662c7c48edd61b0d Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Tue, 21 Feb 2023 22:41:03 -0600 Subject: Add title link to posts --- src/clog.c | 51 +++++++++++++++++---------------------------------- src/init.c | 6 ++---- 2 files changed, 19 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/clog.c b/src/clog.c index af51155..459d77d 100644 --- a/src/clog.c +++ b/src/clog.c @@ -86,8 +86,7 @@ int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq); static void process_md_output(const MD_CHAR *, MD_SIZE size, void *); static int render_md(const char *, struct kore_buf *); -void -post_query_init(struct post_query *pq, enum content_type type, const char *id) { +void post_query_init(struct post_query *pq, enum content_type type, const char *id) { if (id != NULL) pq->id = kore_strdup(id); else @@ -99,8 +98,7 @@ post_query_init(struct post_query *pq, enum content_type type, const char *id) { pq->result = kore_buf_alloc(0); } -void -post_query_cleanup(struct post_query *pq) { +void post_query_cleanup(struct post_query *pq) { if (pq->id != NULL) kore_free((void *) pq->id); pq->id = NULL; @@ -110,8 +108,7 @@ post_query_cleanup(struct post_query *pq) { pq->result = NULL; } -int -validate_uuid(const char *uuid) { +int validate_uuid(const char *uuid) { int i = 0; if (strlen(uuid) != 36) @@ -135,8 +132,7 @@ validate_uuid(const char *uuid) { return KORE_RESULT_OK; } -enum content_type -get_content_type(struct http_request *req) { +enum content_type get_content_type(struct http_request *req) { int err = 0; const char *accept = NULL; @@ -151,8 +147,7 @@ get_content_type(struct http_request *req) { return HTML; } -int -http_ok_resp( +int http_ok_resp( struct http_request *req, enum content_type type, enum http_status_code status, @@ -191,8 +186,7 @@ http_ok_resp( return KORE_RESULT_OK; } -int -http_err_resp( +int http_err_resp( struct http_request *req, enum content_type type, enum http_status_code status @@ -229,17 +223,14 @@ http_err_resp( return KORE_RESULT_OK; } - -int -redirect(struct http_request *req) { +int redirect(struct http_request *req) { http_response_header(req, "Location", "/"); http_response(req, HTTP_STATUS_MOVED_PERMANENTLY, NULL, 0); return KORE_RESULT_OK; } -int -get_posts(struct http_request *req) { +int get_posts(struct http_request *req) { struct post_query pq; post_query_init(&pq, get_content_type(req), NULL); @@ -255,8 +246,7 @@ get_posts(struct http_request *req) { return KORE_RESULT_OK; } -int -get_posts_resource(struct http_request *req) { +int get_posts_resource(struct http_request *req) { int err = 0; struct post_query pq; @@ -287,8 +277,7 @@ out: ; return KORE_RESULT_OK; } -int -post_posts(struct http_request *req) { +int post_posts(struct http_request *req) { int err = 0; int status = HTTP_STATUS_CREATED; @@ -364,8 +353,7 @@ out: ; return KORE_RESULT_OK; } -int -sql_select_posts(struct post_query *pq) { +int sql_select_posts(struct post_query *pq) { int err = KORE_RESULT_OK; struct kore_pgsql sql; @@ -427,8 +415,7 @@ out: ; return err; } -int -delete_posts_resource(struct http_request *req) { +int delete_posts_resource(struct http_request *req) { int err = 0; enum content_type type = get_content_type(req); @@ -508,6 +495,7 @@ int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq) { kore_buf_appendf( pq->result, (const char *) asset_post_html, + id, title, created_at, kore_buf_stringify(html_buf, NULL) @@ -520,8 +508,7 @@ int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq) { return KORE_RESULT_OK; } -int -sql_insert_posts(const char *id, const char *title, const char *body) { +int sql_insert_posts(const char *id, const char *title, const char *body) { int err = KORE_RESULT_OK; struct kore_pgsql sql; @@ -554,8 +541,7 @@ out: ; return err; } -int -sql_delete_posts(const char *id) { +int sql_delete_posts(const char *id) { int err = KORE_RESULT_OK; struct kore_pgsql sql; @@ -586,8 +572,7 @@ out: ; return err; } -static int -render_md(const char *in, struct kore_buf *out) { +static int render_md(const char *in, struct kore_buf *out) { // Not a kore err. int err = 0; @@ -611,12 +596,10 @@ render_md(const char *in, struct kore_buf *out) { return KORE_RESULT_OK; } -static void -process_md_output(const MD_CHAR *html, MD_SIZE size, void *buf) { +static void process_md_output(const MD_CHAR *html, MD_SIZE size, void *buf) { kore_buf_append( (struct kore_buf *) buf, (const void *) html, (size_t) size ); } - diff --git a/src/init.c b/src/init.c index c6697ee..ea3daf3 100644 --- a/src/init.c +++ b/src/init.c @@ -6,8 +6,7 @@ void kore_parent_configure(int, char **); static const char *database = "db"; -void -kore_parent_configure(int argc, char **argv) { +void kore_parent_configure(int argc, char **argv) { int err = 0; kore_default_getopt(argc, argv); @@ -19,8 +18,7 @@ kore_parent_configure(int argc, char **argv) { } } -int -init_db(void) { +int init_db(void) { int err = 0; const char *pg_config = NULL; -- cgit v1.2.3