aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clog.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/clog.c b/src/clog.c
index 8835d60..71c3c3d 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -23,13 +23,15 @@ KORE_SECCOMP_FILTER("clog",
KORE_SYSCALL_ALLOW(uname)
)
-enum content_type { JSON, HTML };
+enum accept_type { JSON, HTML };
+
+// enum content_type { JSON, X_WWW_FORM_URLENCODED };
enum query_status { QUERY_STATUS_OK, QUERY_STATUS_ERROR, QUERY_STATUS_NOT_FOUND };
struct post_query {
char *id;
- enum content_type type;
+ enum accept_type type;
int status;
struct kore_buf *result;
@@ -41,28 +43,28 @@ static const char *database = "db";
static const char * const error_msg[] = {
[HTTP_STATUS_OK] = "OK", // 200
[HTTP_STATUS_CREATED] = "Resource created successfully.", // 201
- [HTTP_STATUS_BAD_REQUEST] = "There was an error processing the request data.", // 403?
+ [HTTP_STATUS_BAD_REQUEST] = "There was an error processing the request data.", // 400
[HTTP_STATUS_NOT_FOUND] = "Resource not found.", // 404
[HTTP_STATUS_INTERNAL_ERROR] = "There was an error processing the request.", // 500
};
-void post_query_init(struct post_query *pq, enum content_type type, const char *id);
+void post_query_init(struct post_query *pq, enum accept_type type, const char *id);
void post_query_cleanup(struct post_query *pq);
int validate_uuid(const char *uuid);
-enum content_type get_content_type(struct http_request *req);
+enum accept_type get_accept_type(struct http_request *req);
int http_ok_resp(
struct http_request *req,
- enum content_type type,
+ enum accept_type type,
enum http_status_code status,
struct kore_buf *result
);
int http_err_resp(
struct http_request *req,
- enum content_type type,
+ enum accept_type type,
enum http_status_code status
);
@@ -88,7 +90,7 @@ int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq);
static void process_md_output(const MD_CHAR *, MD_SIZE size, void *);
static int render_md(const char *, struct kore_buf *);
-void post_query_init(struct post_query *pq, enum content_type type, const char *id) {
+void post_query_init(struct post_query *pq, enum accept_type type, const char *id) {
if (id != NULL)
pq->id = kore_strdup(id);
else
@@ -133,7 +135,7 @@ int validate_uuid(const char *uuid) {
return KORE_RESULT_OK;
}
-enum content_type get_content_type(struct http_request *req) {
+enum accept_type get_accept_type(struct http_request *req) {
int err = 0;
const char *accept = NULL;
@@ -150,7 +152,7 @@ enum content_type get_content_type(struct http_request *req) {
int http_ok_resp(
struct http_request *req,
- enum content_type type,
+ enum accept_type type,
enum http_status_code status,
struct kore_buf *result
) {
@@ -189,7 +191,7 @@ int http_ok_resp(
int http_err_resp(
struct http_request *req,
- enum content_type type,
+ enum accept_type type,
enum http_status_code status
) {
struct kore_buf *resp_buf = kore_buf_alloc(0);
@@ -304,7 +306,7 @@ int post_form(struct http_request *req) {
int get_posts(struct http_request *req) {
struct post_query pq;
- post_query_init(&pq, get_content_type(req), NULL);
+ post_query_init(&pq, get_accept_type(req), NULL);
(void) sql_select_posts(&pq);
if (pq.status != QUERY_STATUS_OK)
@@ -322,7 +324,7 @@ int get_posts_resource(struct http_request *req) {
struct post_query pq;
- post_query_init(&pq, get_content_type(req), req->path + strlen("/posts/"));
+ post_query_init(&pq, get_accept_type(req), req->path + strlen("/posts/"));
// Check for valid resource UUID
kore_log(LOG_DEBUG, "Resource id /posts/%s.", pq.id);
@@ -353,7 +355,7 @@ int post_posts(struct http_request *req) {
int status = HTTP_STATUS_CREATED;
- enum content_type type = get_content_type(req);
+ enum accept_type type = get_accept_type(req);
const char *id = NULL;
const char *title = NULL;
@@ -424,7 +426,7 @@ int put_posts(struct http_request *req) {
int status = HTTP_STATUS_OK;
- enum content_type type = get_content_type(req);
+ enum accept_type type = get_accept_type(req);
const char *id = NULL;
const char *title = NULL;
@@ -456,7 +458,7 @@ int put_posts(struct http_request *req) {
if (item != NULL) {
title = item->data.string;
kore_log(LOG_INFO, "title = '%s'\n", title);
- } else {
+ } else {
status = HTTP_STATUS_BAD_REQUEST;
kore_log(LOG_ERR, "Error parsing title: %s\n", kore_json_strerror());
goto out;
@@ -553,7 +555,7 @@ out: ;
int delete_posts(struct http_request *req) {
int err = 0;
- enum content_type type = get_content_type(req);
+ enum accept_type type = get_accept_type(req);
const char *id = req->path + strlen("/posts/");
// Check for valid resource UUID