aboutsummaryrefslogtreecommitdiff
path: root/src/clog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/clog.c')
-rw-r--r--src/clog.c59
1 files changed, 51 insertions, 8 deletions
diff --git a/src/clog.c b/src/clog.c
index 269aee5..905236b 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -20,19 +20,36 @@ KORE_SECCOMP_FILTER("clog",
KORE_SYSCALL_ALLOW(uname)
)
+struct post_req {
+ struct http_request *req;
+ const char *resource;
+ // FIXME: use enum
+ unsigned int type; // 0 JSON; 1 HTML
+};
+
+void post_req_init(struct post_req *p);
+
int redirect(struct http_request *);
int post(struct http_request *);
int posts(struct http_request *);
+
int render_posts_html(struct http_request *, const char *);
int render_posts_json(struct http_request *, const char *);
+
static void process_md_output(const MD_CHAR *, MD_SIZE size, void *);
static int render_md(const char *, struct kore_buf *);
static const char *database = "db";
-
static const char *accept_json = "application/json";
+void post_req_init(struct post_req *p)
+{
+ p->req = NULL;
+ p->resource = NULL;
+ p->type = 1;
+}
+
int
redirect(struct http_request *req)
{
@@ -48,10 +65,12 @@ post(struct http_request *req)
int err = 0;
const char *accept = NULL;
- const char *resource = NULL;
- resource = req->path + strlen("/posts/");
- kore_log(LOG_DEBUG, "Resource /posts/%s", resource);
+ struct post_req request;
+
+ post_req_init(&request);
+
+ request.req = req;
err = http_request_header(req, "accept", &accept);
if (err == KORE_RESULT_OK)
@@ -59,11 +78,22 @@ post(struct http_request *req)
kore_log(LOG_DEBUG, "Accept: %s", accept);
if (strncmp(accept, accept_json, sizeof(*accept_json)) == 0)
{
- return render_posts_json(req, resource);
+ request.type = 0;
}
}
- return render_posts_html(req, resource);
+ request.resource = req->path + strlen("/posts/");
+ kore_log(LOG_DEBUG, "Resource /posts/%s", request.resource);
+
+ if (request.type == 0)
+ {
+ return render_posts_json(request.req, request.resource);
+ }
+ else
+ {
+ return render_posts_html(request.req, request.resource);
+ }
+
}
int
@@ -73,17 +103,30 @@ posts(struct http_request *req)
const char *accept = NULL;
+ struct post_req request;
+
+ post_req_init(&request);
+
+ request.req = req;
+
err = http_request_header(req, "accept", &accept);
if (err == KORE_RESULT_OK)
{
kore_log(LOG_DEBUG, "Accept: %s", accept);
if (strncmp(accept, accept_json, sizeof(*accept_json)) == 0)
{
- return render_posts_json(req, NULL);
+ request.type = 0;
}
}
- return render_posts_html(req, NULL);
+ if (request.type == 0)
+ {
+ return render_posts_json(request.req, request.resource);
+ }
+ else
+ {
+ return render_posts_html(request.req, request.resource);
+ }
}
int