aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/entry_edit.html9
-rw-r--r--conf/clog.conf3
-rw-r--r--src/clog.c92
3 files changed, 24 insertions, 80 deletions
diff --git a/assets/entry_edit.html b/assets/entry_edit.html
index cd2f920..bc2a5e4 100644
--- a/assets/entry_edit.html
+++ b/assets/entry_edit.html
@@ -1,11 +1,12 @@
<form action="/form" method="post">
<dl>
<dt><h3>id</h3></dt>
-<dd><input type="text" id="id" name="id"></input></dd>
+<dd><input type="text" id="id" name="id" value="%s"></input></dd>
<dt><h3>title</h3></dt>
-<dd><input type="text" id="title" name="title"></input></dd>
+<dd><input type="text" id="title" name="title" value="%s"></input></dd>
<dt><h3>body</h3></dt>
-<dd><textarea id="body" name="body"></textarea></dd>
-<dd><input type="submit" value="Edit"></dd>
+<dd><textarea id="body" name="body" rows="50" cols="100">%s</textarea></dd>
+<dd><input type="submit" value="Preview"></dd>
+<dd><input type="submit" value="Save (N/A)"></dd>
</dl>
</form>
diff --git a/conf/clog.conf b/conf/clog.conf
index c45e48d..fdec6ff 100644
--- a/conf/clog.conf
+++ b/conf/clog.conf
@@ -18,7 +18,6 @@ privsep worker {
seccomp_tracing no
validator v_uuid regex ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
-validator v_number regex ^[0-9]*$
validator v_text function v_example_func
domain * {
@@ -67,7 +66,7 @@ domain * {
methods post
validate post id v_uuid
- validate post title v_number
+ validate post title v_text
validate post body v_text
}
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);
}