aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clog.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/clog.c b/src/clog.c
index 4d29cf9..39d539c 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -38,7 +38,7 @@ struct entry_query {
char *query;
struct entry **entries;
- int num_entries;
+ size_t num_entries;
int status;
};
@@ -79,7 +79,7 @@ static void process_md_output(const MD_CHAR *html, MD_SIZE size, void *buf);
static int render_md(const char *in, struct kore_buf *out);
void entry_query_init(struct entry_query *eq, const char *id, const char *query) {
- int i = 0;
+ size_t i = 0;
if (id != NULL) {
eq->id = kore_strdup(id);
@@ -88,6 +88,7 @@ void entry_query_init(struct entry_query *eq, const char *id, const char *query)
eq->id = NULL;
}
+ // FIXME this is dumb as hell
if (query != NULL) {
eq->query = kore_strdup(query);
for (i = 0; i < strlen(eq->query); ++i) {
@@ -108,6 +109,8 @@ void entry_query_init(struct entry_query *eq, const char *id, const char *query)
}
void entry_query_cleanup(struct entry_query *eq) {
+ size_t i = 0;
+
if (eq->id != NULL) {
kore_free((void *) eq->id);
}
@@ -118,7 +121,7 @@ void entry_query_cleanup(struct entry_query *eq) {
}
eq->query = NULL;
- for (int i = 0; i < eq->num_entries; i++) {
+ for (i = 0; i < eq->num_entries; i++) {
if (eq->entries[i]->id != NULL)
kore_free((void *) eq->entries[i]->id);
if (eq->entries[i]->title != NULL)
@@ -136,7 +139,7 @@ void entry_query_cleanup(struct entry_query *eq) {
}
int validate_uuid(const char *uuid) {
- int i = 0;
+ size_t i = 0;
if (strlen(uuid) != 36)
return KORE_RESULT_ERROR;
@@ -211,7 +214,7 @@ int redirect(struct http_request *req) {
int get_index(struct http_request *req) {
struct entry_query eq;
- int row = 0;
+ size_t i = 0;
struct kore_buf *content = NULL;
@@ -232,12 +235,12 @@ int get_index(struct http_request *req) {
kore_buf_append(content, asset_table_header_html, asset_len_table_header_html);
// Iterate over entries and render them.
- for (row = 0; row < eq.num_entries; row++) {
+ for (i = 0; i < eq.num_entries; i++) {
// Append rendered MD entry.
kore_buf_appendf(
content,
(const char *) asset_table_row_html,
- eq.entries[row]->id, eq.entries[row]->title, eq.entries[row]->created_at, eq.entries[row]->updated_at
+ eq.entries[i]->id, eq.entries[i]->title, eq.entries[i]->created_at, eq.entries[i]->updated_at
);
}
@@ -334,7 +337,7 @@ int edit_entry(struct http_request *req) {
kore_log(LOG_DEBUG, "Resource id /entries/%s.", eq.id);
err = validate_uuid(eq.id);
if (err == KORE_RESULT_ERROR) {
- kore_log(LOG_ERR, "Invalid entry id %s XXX.", eq.id);
+ kore_log(LOG_ERR, "Invalid entry id %s.", eq.id);
http_err_resp(req, HTTP_STATUS_NOT_FOUND);
goto out;
}
@@ -385,7 +388,7 @@ int update_entry(struct http_request *req) {
int err = 0;
char *id = NULL;
- char *title = NULL;
+ char *title = NULL;
char *body = NULL;
http_populate_post(req);
@@ -440,7 +443,7 @@ out: ;
int search_entries(struct http_request *req) {
int err = 0;
- int row = 0;
+ size_t i = 0;
char *query = NULL;
@@ -476,12 +479,12 @@ int search_entries(struct http_request *req) {
kore_buf_append(content, asset_table_header_html, asset_len_table_header_html);
// Iterate over entries and render them.
- for (row = 0; row < eq.num_entries; row++) {
+ for (i = 0; i < eq.num_entries; i++) {
// Append rendered MD entry.
kore_buf_appendf(
content,
(const char *) asset_table_row_html,
- eq.entries[row]->id, eq.entries[row]->title, eq.entries[row]->created_at, eq.entries[row]->updated_at
+ eq.entries[i]->id, eq.entries[i]->title, eq.entries[i]->created_at, eq.entries[i]->updated_at
);
}
@@ -503,8 +506,7 @@ out: ;
int sql_select(struct entry_query *eq) {
int err = KORE_RESULT_OK;
- int row = 0;
- int rows = 0;
+ size_t i = 0;
struct entry *entry = NULL;
struct kore_pgsql sql;
@@ -555,17 +557,16 @@ int sql_select(struct entry_query *eq) {
}
// Iterate over entries and render them.
- rows = kore_pgsql_ntuples(&sql);
- eq->num_entries = rows;
- for (row = 0; row < rows; row++) {
+ eq->num_entries = kore_pgsql_ntuples(&sql);
+ for (i = 0; i < eq->num_entries; i++) {
// Fetch & copy data to entry
entry = kore_malloc(sizeof(struct entry));
- entry->id = kore_strdup(kore_pgsql_getvalue(&sql, row, 0));
- entry->title = kore_strdup(kore_pgsql_getvalue(&sql, row, 1));
- entry->created_at = kore_strdup(kore_pgsql_getvalue(&sql, row, 2));
- entry->updated_at = kore_strdup(kore_pgsql_getvalue(&sql, row, 3));
- entry->body = kore_strdup(kore_pgsql_getvalue(&sql, row, 4));
- eq->entries[row] = entry;
+ entry->id = kore_strdup(kore_pgsql_getvalue(&sql, i, 0));
+ entry->title = kore_strdup(kore_pgsql_getvalue(&sql, i, 1));
+ entry->created_at = kore_strdup(kore_pgsql_getvalue(&sql, i, 2));
+ entry->updated_at = kore_strdup(kore_pgsql_getvalue(&sql, i, 3));
+ entry->body = kore_strdup(kore_pgsql_getvalue(&sql, i, 4));
+ eq->entries[i] = entry;
kore_log(
LOG_DEBUG, "id: %s; title %s; created_at %s, updated_at %s",
entry->id, entry->title, entry->created_at, entry->updated_at