diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clog.c | 146 |
1 files changed, 0 insertions, 146 deletions
@@ -58,9 +58,6 @@ int redirect(struct http_request *req); int get_entries(struct http_request *req); int get_entry(struct http_request *req); -int post_entry(struct http_request *req); -int put_entry(struct http_request *req); -int delete_entry(struct http_request *req); int v_example_func(struct http_request *req, char *data); @@ -182,53 +179,6 @@ int get_entry_form(struct http_request *req) { return KORE_RESULT_OK; } - -int post_entry_form(struct http_request *req) { - int err = 0; - - struct kore_buf *resp_buf = NULL; - - char *id = NULL; - char *title = NULL; - char *body = NULL; - - http_populate_post(req); - - if (http_argument_get_string(req, "id", &id)) { - kore_log(LOG_INFO, "form id %s.", id); - } - - if (http_argument_get_string(req, "title", &title)) { - kore_log(LOG_INFO, "form title %s.", title); - } - - if (http_argument_get_string(req, "body", &body)) { - kore_log(LOG_INFO, "form body %s.", body); - } - - resp_buf = kore_buf_alloc(0); - - // Append form. - kore_buf_appendf( - resp_buf, (const char *) asset_entry_edit_html, - id ? id : "", title ? title: "", body ? body : "" - ); - - // Render MD. - err = render_md(body, resp_buf); - if (err == KORE_RESULT_ERROR) { - kore_buf_append(resp_buf, "Error rendering markdown.", 25); - kore_log(LOG_ERR, "Error rendering markdown."); - } - - http_ok_resp(req, HTTP_STATUS_OK, resp_buf); - - kore_buf_free(resp_buf); - - return KORE_RESULT_OK; -} - - int get_entries(struct http_request *req) { struct entry_query eq; @@ -345,73 +295,6 @@ out: ; return KORE_RESULT_OK; } -int put_entry(struct http_request *req) { - int err = 0; - - int status = HTTP_STATUS_OK; - - const char *id = NULL; - const char *title = NULL; - const char *body = NULL; - - struct kore_json_item *item = NULL; - struct kore_json json; - - kore_json_init(&json, req->http_body->data, req->http_body->length); - - id = req->path + strlen("/entries/"); - - // Check for valid resource UUID - kore_log(LOG_DEBUG, "Resource id /entries/%s.", id); - err = validate_uuid(id); - if (err == KORE_RESULT_ERROR) { - kore_log(LOG_ERR, "Invalid entry id %s.", id); - http_err_resp(req, HTTP_STATUS_NOT_FOUND); - goto out; - } - - if (!kore_json_parse(&json)) { - status = HTTP_STATUS_BAD_REQUEST; - kore_log(LOG_ERR, "error parsing json: %s\n", kore_json_strerror()); - goto out; - } - - item = kore_json_find_string(json.root, "title"); - if (item != NULL) { - title = item->data.string; - kore_log(LOG_INFO, "title = '%s'\n", title); - } else { - status = HTTP_STATUS_BAD_REQUEST; - kore_log(LOG_ERR, "Error parsing title: %s\n", kore_json_strerror()); - goto out; - } - - item = kore_json_find_string(json.root, "body"); - if (item != NULL) { - body = item->data.string; - kore_log(LOG_INFO, "body = '%s'\n", body); - } else { - status = HTTP_STATUS_BAD_REQUEST; - kore_log(LOG_ERR, "Error parsing body: %s\n", kore_json_strerror()); - goto out; - } - - err = sql_update_entry(id, title, body); - - if (err == KORE_RESULT_ERROR) { - status = HTTP_STATUS_INTERNAL_ERROR; - goto out; - } - -out: ; - - http_err_resp(req, status); - - kore_json_cleanup(&json); - - return KORE_RESULT_OK; -} - int sql_select_entries(struct entry_query *eq) { int err = KORE_RESULT_OK; @@ -472,35 +355,6 @@ out: ; return err; } -int delete_entry(struct http_request *req) { - int err = 0; - - const char *id = req->path + strlen("/entries/"); - - // Check for valid resource UUID - kore_log(LOG_DEBUG, "Resource id /entries/%s.", id); - err = validate_uuid(id); - if (err == KORE_RESULT_ERROR) { - kore_log(LOG_ERR, "Invalid entry id %s.", id); - http_err_resp(req, HTTP_STATUS_NOT_FOUND); - goto out; - } - - err = sql_delete_entry(id); - // FIXME: should 404 if id doesn't exist. - // if (eq.status == QUERY_STATUS_NOT_FOUND) - // http_err_resp(req, HTTP_STATUS_NOT_FOUND); - if (err == KORE_RESULT_ERROR) - http_err_resp(req, HTTP_STATUS_INTERNAL_ERROR); - else - // TODO: test this; the test should explode. - http_err_resp(req, HTTP_STATUS_OK); - -out: ; - - return KORE_RESULT_OK; -} - int sql_render_entry(struct kore_pgsql *sql, struct entry_query *eq) { int err = KORE_RESULT_OK; |