diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clog.c | 30 |
1 files changed, 8 insertions, 22 deletions
@@ -52,9 +52,6 @@ static const char * const error_msg[] = { [HTTP_STATUS_INTERNAL_ERROR] = "There was an error processing the request.", // 500 }; -// void entry_init(); -// void entry_cleanup(); - void entry_query_init(struct entry_query *eq, const char *id); void entry_query_cleanup(struct entry_query *eq); @@ -71,8 +68,6 @@ int get_entry(struct http_request *req); int edit_entry(struct http_request *req); int update_entry(struct http_request *req); -// int v_example_func(struct http_request *req, char *data); - int sql_select(struct entry_query *eq); int sql_update(const char *id, const char *title, const char *body); // int sql_delete(const char *id); @@ -152,9 +147,9 @@ int http_ok_resp( const char *body = kore_buf_stringify(content, NULL); http_response_header(req, "content-type", "text/html; charset=utf-8"); - kore_buf_append(resp_buf, asset_index_begin_html, asset_len_index_begin_html); + kore_buf_append(resp_buf, asset_header_html, asset_len_header_html); kore_buf_append(resp_buf, body, strlen(body)); - kore_buf_append(resp_buf, asset_index_end_html, asset_len_index_end_html); + kore_buf_append(resp_buf, asset_footer_html, asset_len_footer_html); http_response(req, status, resp_buf->data, resp_buf->offset); @@ -170,9 +165,9 @@ int http_err_resp( struct kore_buf *resp_buf = kore_buf_alloc(0); http_response_header(req, "content-type", "text/html; charset=utf-8"); - kore_buf_append(resp_buf, asset_index_begin_html, asset_len_index_begin_html); + kore_buf_append(resp_buf, asset_header_html, asset_len_header_html); kore_buf_appendf(resp_buf, (const char *) asset_error_html, error_msg[status]); - kore_buf_append(resp_buf, asset_index_end_html, asset_len_index_end_html); + kore_buf_append(resp_buf, asset_footer_html, asset_len_footer_html); http_response(req, status, resp_buf->data, resp_buf->offset); @@ -205,29 +200,21 @@ int get_index(struct http_request *req) { } // Write table header. - kore_buf_append( - content, - (const char *) "<h1>clog.bunkergate.org</h1>\r\n<table><tr><th>title</th><th>created</th><th>updated</th></tr>\r\n", - 94 - ); + kore_buf_append(content, asset_index_header_html, asset_len_index_header_html); // Iterate over entries and render them. for (row = 0; row < eq.num_entries; row++) { // Append rendered MD entry. kore_buf_appendf( content, - (const char *) "<tr><td><a href=\"/entries/%s\">%s</a></td><td>%s</td><td>%s</td></tr>\r\n", + (const char *) asset_index_row_html, eq.entries[row]->id, eq.entries[row]->title, eq.entries[row]->created_at, eq.entries[row]->updated_at ); - } // Write table footer. - kore_buf_append( - content, - (const char *) "</table>\r\n", - 10 - ); + kore_buf_append(content, asset_index_footer_html, asset_len_index_footer_html); + http_ok_resp(req, HTTP_STATUS_OK, content); @@ -403,7 +390,6 @@ int update_entry(struct http_request *req) { } err = sql_update(id, title, body); - // err = KORE_RESULT_ERROR; if (err == KORE_RESULT_ERROR) { kore_log(LOG_ERR, "Error updating entry id %s.", id); http_err_resp(req, HTTP_STATUS_INTERNAL_ERROR); |