aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clog.c41
1 files changed, 19 insertions, 22 deletions
diff --git a/src/clog.c b/src/clog.c
index 4c65a33..30de75a 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -80,7 +80,7 @@ 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) {
size_t i = 0;
- if (id != NULL) {
+ if (id) {
eq->id = kore_strdup(id);
}
else {
@@ -88,7 +88,7 @@ void entry_query_init(struct entry_query *eq, const char *id, const char *query)
}
// FIXME this is dumb as hell
- if (query != NULL) {
+ if (query) {
eq->query = kore_strdup(query);
for (i = 0; i < strlen(eq->query); ++i) {
if (eq->query[i] == ' ') {
@@ -110,26 +110,26 @@ 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) {
+ if (eq->id) {
kore_free((void *) eq->id);
}
eq->id = NULL;
- if (eq->query != NULL) {
+ if (eq->query) {
kore_free((void *) eq->query);
}
eq->query = NULL;
for (i = 0; i < eq->num_entries; i++) {
- if (eq->entries[i]->id != NULL)
+ if (eq->entries[i]->id)
kore_free((void *) eq->entries[i]->id);
- if (eq->entries[i]->title != NULL)
+ if (eq->entries[i]->title)
kore_free((void *) eq->entries[i]->title);
- if (eq->entries[i]->created_at != NULL)
+ if (eq->entries[i]->created_at)
kore_free((void *) eq->entries[i]->created_at);
- if (eq->entries[i]->updated_at != NULL)
+ if (eq->entries[i]->updated_at)
kore_free((void *) eq->entries[i]->updated_at);
- if (eq->entries[i]->body != NULL)
+ if (eq->entries[i]->body)
kore_free((void *) eq->entries[i]->body);
kore_free((void *) eq->entries[i]);
}
@@ -248,15 +248,15 @@ int get_index(struct http_request *req) {
}
else {
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
);
}
+
kore_buf_append(content, asset_table_footer_html, asset_len_table_footer_html);
}
@@ -404,7 +404,7 @@ int update_entry(struct http_request *req) {
http_populate_post(req);
if (http_argument_get_string(req, "title", &title)) {
- kore_log(LOG_INFO, "form title %s.", title);
+ kore_log(LOG_DEBUG, "form title %s.", title);
}
else {
kore_log(LOG_ERR, "Error no title");
@@ -413,7 +413,7 @@ int update_entry(struct http_request *req) {
}
if (http_argument_get_string(req, "body", &body)) {
- kore_log(LOG_INFO, "form body %s.", body);
+ kore_log(LOG_DEBUG, "form body %s.", body);
}
else {
kore_log(LOG_ERR, "Error no body");
@@ -442,9 +442,7 @@ int update_entry(struct http_request *req) {
out: ;
- if (id != NULL) {
- kore_free(id);
- }
+ kore_free(id);
return KORE_RESULT_OK;
}
@@ -469,7 +467,7 @@ int sql_select(struct entry_query *eq) {
}
// Query for entries, check for error.
- if (eq->id != NULL) {
+ if (eq->id) {
// Query an entry.
err = kore_pgsql_query_params(&sql, q_select_entry,
0, // return string data
@@ -477,7 +475,7 @@ int sql_select(struct entry_query *eq) {
KORE_PGSQL_PARAM_TEXT(eq->id)
);
}
- else if (eq->query != NULL) {
+ else if (eq->query) {
err = kore_pgsql_query_params(&sql, q_search_entries,
0, // return string data
2, // param count
@@ -485,8 +483,7 @@ int sql_select(struct entry_query *eq) {
KORE_PGSQL_PARAM_TEXT(eq->query)
);
}
- else {
- // Query for index.
+ else { // Query for index.
err = kore_pgsql_query(&sql, q_select_entries);
}
@@ -497,7 +494,7 @@ int sql_select(struct entry_query *eq) {
}
// TODO: Add test for this; When database is empty, don't return 404 for base request.
- if (eq->id != NULL && kore_pgsql_ntuples(&sql) == 0) {
+ if (eq->id && kore_pgsql_ntuples(&sql) == 0) {
eq->status = QUERY_STATUS_NOT_FOUND;
goto out;
}
@@ -601,7 +598,7 @@ static int render_md(const char *in, struct kore_buf *out) {
in, (MD_SIZE) strlen(in), process_md_output, (void*) out, parser_flags, renderer_flags
);
- if(err != 0) {
+ if (err) {
kore_log(LOG_ERR, "Parsing Markdown failed.");
return KORE_RESULT_ERROR;
}