aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf/clog.conf24
-rw-r--r--src/clog.c49
2 files changed, 53 insertions, 20 deletions
diff --git a/conf/clog.conf b/conf/clog.conf
index b86712f..8a6cf81 100644
--- a/conf/clog.conf
+++ b/conf/clog.conf
@@ -1,27 +1,33 @@
# clog configuration
-server tls {
- bind 127.0.0.1 8888
+# server tls {
+# bind 127.0.0.1 8888
+# }
+
+server notls {
+ bind 127.0.0.1 8889
+ tls no
}
load ./clog.so init
-tls_dhparam dh2048.pem
+# tls_dhparam dh2048.pem
workers 1
seccomp_tracing yes
domain * {
- # attach notls
- attach tls
+ attach notls
- certfile cert/server.pem
- certkey cert/key.pem
+# attach tls
+# certfile cert/server.pem
+# certkey cert/key.pem
filemap /static/ assets/static
- route / page
+ route / posts
+ route ^/posts/[a-z1-9\-]+$ post
- route /posts page
+ route /posts posts
}
diff --git a/src/clog.c b/src/clog.c
index d3fa324..7bf6012 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -12,7 +12,9 @@
#include "../lib/md4c/src/md4c-html.c"
int init(int);
-int page(struct http_request *);
+int post(struct http_request *);
+int posts(struct http_request *);
+int render_posts(struct http_request *, const char *);
static void process_md_output(const MD_CHAR *, MD_SIZE size, void *);
static int render_md(char *, struct kore_buf *);
@@ -27,16 +29,27 @@ init(int state)
database,
"host=127.0.0.1 port=5432 user=postgres password=p0stgres dbname=clog sslmode=disable"
);
-
return err;
}
int
-page(struct http_request *req)
+post(struct http_request *req)
{
+ const char *resource;
+ resource = req->path + strlen("/posts/");
+ kore_log(LOG_DEBUG, "Resource /posts/%s", resource);
+ return render_posts(req, resource);
+}
- // req->status = HTTP_STATUS_INTERNAL_ERROR;
+int
+posts(struct http_request *req)
+{
+ return render_posts(req, NULL);
+}
+int
+render_posts(struct http_request *req, const char *resource)
+{
// Buffer for response
struct kore_buf *resp_buf = kore_buf_alloc(0);
@@ -61,15 +74,29 @@ page(struct http_request *req)
goto out;
}
- // Start writing page.
+ // Start writing HTML.
kore_buf_append(resp_buf, asset_index_begin_html, asset_len_index_begin_html);
// Query for posts, check for error.
- err = kore_pgsql_query(
- &sql,
- "SELECT id, title, created_at::DATE, body FROM posts "
- "ORDER BY updated_at DESC;"
- );
+ if (resource) {
+ // Query post
+ err = kore_pgsql_query_params(
+ &sql,
+ "SELECT id, title, created_at::DATE, body FROM posts "
+ "WHERE id = $1 "
+ "ORDER BY updated_at DESC;",
+ 0,
+ 1,
+ KORE_PGSQL_PARAM_TEXT(resource)
+ );
+ } else {
+ // Query all posts
+ err = kore_pgsql_query(
+ &sql,
+ "SELECT id, title, created_at::DATE, body FROM posts "
+ "ORDER BY updated_at DESC;"
+ );
+ }
if (!err) {
kore_pgsql_logerror(&sql);
goto out;
@@ -138,7 +165,7 @@ render_md(char *in, struct kore_buf *out)
);
if(ret != 0) {
- fprintf(stderr, "Parsing failed.\n");
+ kore_log(LOG_ERR, "Parsing Markdown failed.\n");
return -1;
}