aboutsummaryrefslogtreecommitdiff
path: root/src/clog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/clog.c')
-rw-r--r--src/clog.c85
1 files changed, 17 insertions, 68 deletions
diff --git a/src/clog.c b/src/clog.c
index 6e222b6..b5908a7 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -212,15 +212,25 @@ int redirect(struct http_request *req) {
}
int get_index(struct http_request *req) {
- struct entry_query eq;
-
+ int err = 0;
size_t i = 0;
-
+ const char *query = NULL;
+ struct entry_query eq;
struct kore_buf *content = NULL;
content = kore_buf_alloc(0);
- entry_query_init(&eq, NULL, NULL);
+ http_populate_get(req);
+
+ err = http_argument_get_string(req, "query", &query);
+ if (err == KORE_RESULT_OK) {
+ kore_log(LOG_INFO, "query string: '%s'", query);
+ }
+ else {
+ query = NULL;
+ }
+
+ entry_query_init(&eq, NULL, query);
(void) sql_select(&eq);
if (eq.status != QUERY_STATUS_OK) {
@@ -231,6 +241,9 @@ int get_index(struct http_request *req) {
// Write header.
kore_buf_append(content, asset_header_html, asset_len_header_html);
+ // Write search form.
+ kore_buf_append(content, asset_search_html, asset_len_search_html);
+
// Write table header.
kore_buf_append(content, asset_table_header_html, asset_len_table_header_html);
@@ -439,70 +452,6 @@ out: ;
return KORE_RESULT_OK;
}
-
-int search_entries(struct http_request *req) {
- int err = 0;
-
- size_t i = 0;
-
- char *query = NULL;
-
- struct entry_query eq;
-
- struct kore_buf *content = NULL;
-
- content = kore_buf_alloc(0);
-
- http_populate_get(req);
-
- err = http_argument_get_string(req, "query", &query);
- if (err == KORE_RESULT_OK) {
- kore_log(LOG_INFO, "query string: '%s'", query);
- }
-
- entry_query_init(&eq, NULL, query);
-
- (void) sql_select(&eq);
- if (eq.status != QUERY_STATUS_OK) {
- http_err_resp(req, HTTP_STATUS_INTERNAL_ERROR);
- goto out;
- }
-
- // Write header.
- kore_buf_append(content, asset_header_html, asset_len_header_html);
-
- // Write search form.
- kore_buf_append(content, asset_search_html, asset_len_search_html);
-
- if (eq.num_entries > 0) {
- // Write table header.
- kore_buf_append(content, asset_table_header_html, asset_len_table_header_html);
-
- // Iterate over entries and render them.
- for (i = 0; i < eq.num_entries; i++) {
- // Append rendered MD entry.
- kore_buf_appendf(
- content,
- (const char *) asset_table_row_html,
- eq.entries[i]->id, eq.entries[i]->title, eq.entries[i]->created_at, eq.entries[i]->updated_at
- );
- }
-
- // Write table footer.
- kore_buf_append(content, asset_table_footer_html, asset_len_table_footer_html);
- }
-
- http_ok_resp(req, HTTP_STATUS_OK, content);
-
-out: ;
-
- entry_query_cleanup(&eq);
-
- kore_free(content);
-
- return KORE_RESULT_OK;
-}
-
int sql_select(struct entry_query *eq) {
int err = KORE_RESULT_OK;