diff options
author | Michael McVady <femtonaut@gmail.com> | 2023-01-02 08:08:49 -0600 |
---|---|---|
committer | Michael McVady <femtonaut@gmail.com> | 2023-01-02 08:08:49 -0600 |
commit | 34ec321f7c3e54a43905003b9dee8a41ac11aa18 (patch) | |
tree | 547d38028f93b3d1650dc54c055f45a21ee8274f /src | |
parent | a1c84126f36527dc4ac1c7f1f5473ca536d56f48 (diff) |
Hack in post_rq struct
Diffstat (limited to 'src')
-rw-r--r-- | src/clog.c | 59 |
1 files changed, 51 insertions, 8 deletions
@@ -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 |