aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2021-11-17 21:55:35 -0500
committerMichael McVady <femtonaut@gmail.com>2021-11-17 21:55:35 -0500
commit162d818a7e61b71155f57247f4aebad6db472553 (patch)
tree2729da6f226d0ef81288c9ccc5fb3c12ea23a34e /src
parent117085faf4be738b862b6551ed433c4f530e9ae0 (diff)
Clean up code formatting
Diffstat (limited to 'src')
-rw-r--r--src/clog.c47
1 files changed, 26 insertions, 21 deletions
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<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", id, title, kore_buf_stringify(html, NULL));
- kore_buf_free(html);
+ kore_buf_appendf(
+ resp_buf,
+ "\t<tr><td>%s</td><td>%s</td><td>%s</td></tr>\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);
}