diff options
author | Michael McVady <femtonaut@gmail.com> | 2024-01-26 23:18:51 -0600 |
---|---|---|
committer | Michael McVady <femtonaut@gmail.com> | 2024-01-26 23:18:51 -0600 |
commit | f81f88ae569c6724da18868d1abe92036b895fc6 (patch) | |
tree | 2c62f562f9764459ca08a730569fc8d1c3ba6078 /src/clog.c | |
parent | 2d92280f0e7e605911da199757fa33d2b5089b0a (diff) |
Limit results
Diffstat (limited to 'src/clog.c')
-rw-r--r-- | src/clog.c | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -23,6 +23,10 @@ KORE_SECCOMP_FILTER("clog", KORE_SYSCALL_ALLOW(uname) ) +#define STR_HELPER(s) #s +#define STR(s) STR_HELPER(s) +#define MAX_ENTRIES 15 + enum query_status { QUERY_STATUS_OK, QUERY_STATUS_ERROR, QUERY_STATUS_NOT_FOUND }; struct entry { @@ -102,8 +106,7 @@ void entry_query_init(struct entry_query *eq, const char *id, const char *query) eq->query = NULL; } - // FIXME: define MAX_ENTRIES and LIMIT queries with it. - eq->entries = kore_malloc(sizeof(struct entry *) * 100); + eq->entries = kore_malloc(sizeof(struct entry *) * MAX_ENTRIES); eq->num_entries = 0; eq->status = QUERY_STATUS_OK; @@ -142,8 +145,9 @@ void entry_query_cleanup(struct entry_query *eq) { int validate_uuid(const char *uuid) { size_t i = 0; - if (strlen(uuid) != 36) + if (strlen(uuid) != 36) { return KORE_RESULT_ERROR; + } for (i = 0; i <= 36; i++) { if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) { @@ -535,15 +539,21 @@ int sql_select(struct entry_query *eq) { ); } else if (eq->query) { + // Search for entries. err = kore_pgsql_query_params(&sql, q_search_entries, 0, // return string data - 2, // param count - KORE_PGSQL_PARAM_TEXT(eq->query), - KORE_PGSQL_PARAM_TEXT(eq->query) + 3, // param count + KORE_PGSQL_PARAM_TEXT(eq->query), KORE_PGSQL_PARAM_TEXT(eq->query), + KORE_PGSQL_PARAM_TEXT(STR(MAX_ENTRIES)) ); } - else { // Query for index. - err = kore_pgsql_query(&sql, q_select_entries); + else { + // Query for index. + err = kore_pgsql_query_params(&sql, q_select_entries, + 0, // return string data + 1, // param count + KORE_PGSQL_PARAM_TEXT(STR(MAX_ENTRIES)) + ); } if (err == KORE_RESULT_ERROR) { |