aboutsummaryrefslogtreecommitdiff
path: root/src/clog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/clog.c')
-rw-r--r--src/clog.c92
1 files changed, 18 insertions, 74 deletions
diff --git a/src/clog.c b/src/clog.c
index 4eebe6f..24e08d0 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -47,11 +47,7 @@ void entry_query_cleanup(struct entry_query *eq);
int validate_uuid(const char *uuid);
-int http_ok_resp(
- struct http_request *req,
- enum http_status_code status,
- struct kore_buf *result
-);
+int http_ok_resp(struct http_request *req, enum http_status_code status, struct kore_buf *result);
int http_err_resp(
struct http_request *req,
@@ -136,19 +132,10 @@ int http_ok_resp(
http_response_header(req, "content-type", "text/html; charset=utf-8");
kore_buf_append(resp_buf, asset_index_begin_html, asset_len_index_begin_html);
- kore_buf_append(
- resp_buf,
- body,
- strlen(body)
- );
+ kore_buf_append(resp_buf, body, strlen(body));
kore_buf_append(resp_buf, asset_index_end_html, asset_len_index_end_html);
- http_response(
- req,
- status,
- resp_buf->data,
- resp_buf->offset
- );
+ http_response(req, status, resp_buf->data, resp_buf->offset);
kore_buf_free(resp_buf);
@@ -163,19 +150,10 @@ int http_err_resp(
http_response_header(req, "content-type", "text/html; charset=utf-8");
kore_buf_append(resp_buf, asset_index_begin_html, asset_len_index_begin_html);
- kore_buf_appendf(
- resp_buf,
- (const char *) asset_error_html,
- error_msg[status]
- );
+ kore_buf_appendf(resp_buf, (const char *) asset_error_html, error_msg[status]);
kore_buf_append(resp_buf, asset_index_end_html, asset_len_index_end_html);
- http_response(
- req,
- status,
- resp_buf->data,
- resp_buf->offset
- );
+ http_response(req, status, resp_buf->data, resp_buf->offset);
kore_buf_free(resp_buf);
@@ -196,12 +174,7 @@ int v_example_func(struct http_request *req, char *data) {
int get_entry_form(struct http_request *req) {
struct kore_buf *resp_buf = kore_buf_alloc(0);
- kore_buf_append(
- resp_buf,
- (const char *) asset_entry_edit_html,
- asset_len_entry_edit_html
- );
-
+ kore_buf_appendf(resp_buf, (const char *) asset_entry_edit_html, "", "", "");
http_ok_resp(req, HTTP_STATUS_OK, resp_buf);
kore_buf_free(resp_buf);
@@ -211,8 +184,6 @@ int get_entry_form(struct http_request *req) {
int post_entry_form(struct http_request *req) {
-
- struct kore_buf *html_buf = kore_buf_alloc(0);
struct kore_buf *resp_buf = kore_buf_alloc(0);
char *id = NULL;
@@ -233,38 +204,21 @@ int post_entry_form(struct http_request *req) {
kore_log(LOG_INFO, "form body %s.", body);
}
+ // Append form.
+ kore_buf_appendf(
+ resp_buf, (const char *) asset_entry_edit_html,
+ id ? id : "", title ? title: "", body ? body : ""
+ );
+
// Render MD.
- (void) render_md(body, html_buf);
+ (void) render_md(body, resp_buf);
// if (err == KORE_RESULT_ERROR) {
// kore_log(LOG_ERR, "Error rendering markdown for entry %s.", id);
// continue;
// }
- http_response_header(req, "content-type", "text/html; charset=utf-8");
-
- kore_buf_append(resp_buf, asset_index_begin_html, asset_len_index_begin_html);
-
- // Append rendered MD entry.
- size_t len = 0;
- char *str = NULL;
- str = kore_buf_stringify(html_buf, &len);
- kore_buf_append(
- resp_buf,
- str,
- len
- );
-
- kore_buf_append(resp_buf, asset_index_end_html, asset_len_index_end_html);
-
- http_response(
- req,
- HTTP_STATUS_OK,
- resp_buf->data,
- resp_buf->offset
- );
-
+ http_ok_resp(req, HTTP_STATUS_OK, resp_buf);
- kore_buf_free(html_buf);
kore_buf_free(resp_buf);
return KORE_RESULT_OK;
@@ -569,7 +523,7 @@ int sql_render_entry(struct kore_pgsql *sql, struct entry_query *eq) {
title = kore_pgsql_getvalue(sql, row, 1);
created_at = kore_pgsql_getvalue(sql, row, 2);
body = kore_pgsql_getvalue(sql, row, 3);
- kore_log(LOG_DEBUG, "id: '%s'; title '%s'", id, title);
+ kore_log(LOG_DEBUG, "id: %s; title %s; created_at %s", id, title, created_at);
// Render MD.
err = render_md(body, html_buf);
@@ -767,16 +721,10 @@ static int render_md(const char *in, struct kore_buf *out) {
static unsigned renderer_flags = 0;
parser_flags |= MD_FLAG_TABLES;
+ parser_flags |= MD_FLAG_STRIKETHROUGH;
// render_flags |= MD_HTML_FLAG_DEBUG;
- err = md_html(
- in,
- (MD_SIZE) strlen(in),
- process_md_output,
- (void*) out,
- parser_flags,
- renderer_flags
- );
+ err = md_html(in, (MD_SIZE) strlen(in), process_md_output, (void*) out, parser_flags, renderer_flags);
if(err != 0) {
kore_log(LOG_ERR, "Parsing Markdown failed.");
@@ -787,9 +735,5 @@ static int render_md(const char *in, struct kore_buf *out) {
}
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
- );
+ kore_buf_append((struct kore_buf *) buf, (const void *) html, (size_t) size);
}