summaryrefslogtreecommitdiff
path: root/table.c
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2023-05-05 23:34:55 -0400
committerTest_User <hax@andrewyu.org>2023-05-05 23:34:55 -0400
commit329ca8e8f40efdd7838d40435b5f113d2877c13c (patch)
treea71b82548acc60185a448261a0088fa7e925e948 /table.c
parent9343cffa8c032d5b44fce89af7fc5d8709acd9aa (diff)
downloadcoupserv-329ca8e8f40efdd7838d40435b5f113d2877c13c.tar.gz
coupserv-329ca8e8f40efdd7838d40435b5f113d2877c13c.zip
Switch to gnutls, add handling of NICK, add responses to unknown/invalid/etc command, change a few other things
Diffstat (limited to 'table.c')
-rw-r--r--table.c42
1 files changed, 9 insertions, 33 deletions
diff --git a/table.c b/table.c
index e9a6fab..5dbc290 100644
--- a/table.c
+++ b/table.c
@@ -53,8 +53,10 @@ static inline int compare(struct string a, struct string b) {
}
static inline uint64_t search(struct table tbl, struct string name, uint8_t *exists) {
- if (tbl.len == 0)
+ if (tbl.len == 0) {
+ *exists = 0;
return 0;
+ }
size_t low = 0, high = tbl.len - 1;
@@ -97,7 +99,7 @@ static inline uint64_t search(struct table tbl, struct string name, uint8_t *exi
}
int set_table_index(struct table *tbl, struct string name, void *ptr) {
- uint8_t exists, err;
+ uint8_t exists;
uint64_t index = search(*tbl, name, &exists);
if (index == tbl->len) {
@@ -135,42 +137,16 @@ int set_table_index(struct table *tbl, struct string name, void *ptr) {
}
void * get_table_index(struct table tbl, struct string name) {
- if (tbl.len == 0)
+ uint8_t exists;
+ uint64_t index = search(tbl, name, &exists);
+ if (!exists)
return 0;
- size_t low = 0, high = tbl.len - 1;
-
- size_t mid = high/2;
-
- while (low != high) {
- int val = compare(tbl.array[mid].name, name);
- if (val == 0) {
- return tbl.array[mid].ptr;
- } else if (val > 0) {
- low = mid + 1;
- if (mid > low)
- return 0;
- if (low > high)
- low = high;
- } else {
- high = mid - 1;
- if (mid < high)
- return 0;
- if (high < low)
- high = low;
- }
-
- mid = low + ((high-low)/2);
- }
-
- if (compare(tbl.array[mid].name, name) == 0)
- return tbl.array[mid].ptr;
- else
- return 0;
+ return tbl.array[index].ptr;
}
void * remove_table_index(struct table *tbl, struct string name) {
- uint8_t exists, err;
+ uint8_t exists;
uint64_t index = search(*tbl, name, &exists);
if (!exists)