From 162d818a7e61b71155f57247f4aebad6db472553 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Wed, 17 Nov 2021 21:55:35 -0500 Subject: Clean up code formatting --- src/clog.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'src/clog.c') diff --git a/src/clog.c b/src/clog.c index 6ef273f..6fd2843 100644 --- a/src/clog.c +++ b/src/clog.c @@ -14,16 +14,17 @@ int init(int); int page(struct http_request *); -/* Called when our module is loaded (see config) */ -int init(int state) +// Called when this module is loaded (see config) +int +init(int state) { - /* Register our database. */ + // Register the database int err = kore_pgsql_register( - "db", - "host=127.0.0.1 port=5432 user=postgres password=p0stgres dbname=clog sslmode=disable" + "db", + "host=127.0.0.1 port=5432 user=postgres password=p0stgres dbname=clog sslmode=disable" ); - return (err); + return err; } static void @@ -49,13 +50,13 @@ render_md(char *in, struct kore_buf *out) return 1; } -int page(struct http_request *req) +int +page(struct http_request *req) { - struct kore_buf *buf; - buf = kore_buf_alloc(4096); + struct kore_buf *resp_buf = kore_buf_alloc(4096); - kore_buf_append(buf, asset_index_begin_html, asset_len_index_begin_html); + kore_buf_append(resp_buf, asset_index_begin_html, asset_len_index_begin_html); // SQL vars struct kore_pgsql sql; @@ -103,29 +104,33 @@ int page(struct http_request *req) kore_log(LOG_NOTICE, "title: '%s'", title); kore_log(LOG_NOTICE, "body: '%s'", body); - struct kore_buf *html = kore_buf_alloc(4096); - if (!render_md(body, html)) { + struct kore_buf *html_buf = kore_buf_alloc(4096); + if (!render_md(body, html_buf)) { kore_log(LOG_NOTICE, "Error rendering markdown."); - kore_buf_free(html); + kore_buf_free(html_buf); continue; } - kore_log(LOG_NOTICE, "html: '%s'", kore_buf_stringify(html, NULL)); - kore_buf_appendf(buf, "\t%s%s%s\n", id, title, kore_buf_stringify(html, NULL)); - kore_buf_free(html); + kore_buf_appendf( + resp_buf, + "\t%s%s%s\n", + id, + title, + kore_buf_stringify(html_buf, NULL) + ); + kore_buf_free(html_buf); } out: ; - kore_buf_append(buf, asset_index_end_html, asset_len_index_end_html); + kore_buf_append(resp_buf, asset_index_end_html, asset_len_index_end_html); http_response_header(req, "content-type", "text/html; charset=utf-8"); - http_response(req, HTTP_STATUS_OK, buf->data, buf->offset); - // http_response_stream ??? - kore_buf_free(buf); + http_response(req, HTTP_STATUS_OK, resp_buf->data, resp_buf->offset); - // Cleanup the kore_pgsql data structure. + // Cleanup the data structures. kore_pgsql_cleanup(&sql); + kore_buf_free(resp_buf); return (KORE_RESULT_OK); } -- cgit v1.2.3