aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/better_string.h1
-rw-r--r--src/include/hash_table.h32
-rw-r--r--src/include/helpers.h1
-rw-r--r--src/include/list.h36
-rw-r--r--src/include/opcodes.h4
-rw-r--r--src/include/protocol.h10
6 files changed, 62 insertions, 22 deletions
diff --git a/src/include/better_string.h b/src/include/better_string.h
index 41c0cfd..0fdc8bd 100644
--- a/src/include/better_string.h
+++ b/src/include/better_string.h
@@ -21,4 +21,5 @@ void string_concat_const(string_t *s, const char *src);
char string_pop(string_t *s);
void string_free(void *s);
+
#endif
diff --git a/src/include/hash_table.h b/src/include/hash_table.h
index ea21e37..8f19635 100644
--- a/src/include/hash_table.h
+++ b/src/include/hash_table.h
@@ -1,6 +1,6 @@
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
-
+#include "list.h"
#include <stdlib.h>
#define DEFAULT_HT_SIZE 500
@@ -9,35 +9,29 @@ typedef struct PAIR_STRUCT {
void *v;
} pair_t;
-typedef struct NODE_STRUCT {
- char *key;
- void *v;
- struct NODE_STRUCT *next;
-} node_t;
-
-typedef struct {
- node_t *head;
- node_t *tail;
-} sll_t;
-
typedef struct {
- sll_t **buckets;
+ list_t **buckets;
size_t size;
} ht_t;
-node_t *init_node(char *key, void *v);
+pair_t *init_pair(char *key, void *value);
+
+void *bucket_get(list_t *b, char *key);
-void sll_push(sll_t *sll, char *key, void *v);
+void *bucket_pop(list_t *b, char *key);
-void sll_delete(sll_t *sll, char *key);
+void bucket_free(void *x, void (*freefunc)(void *));
-sll_t *sll_free(void *x, void (*freefunc)(void *));
+ht_t *init_ht(size_t size);
void ht_insert(ht_t *ht, char *key, void *value);
-void ht_delete(ht_t *ht, char *key);
+void *ht_pop(ht_t *ht, char *key);
void *ht_get(ht_t *ht, char *key);
-ht_t *init_ht(size_t size);
+void ht_free(void *x, void (*freefunc)(void *));
+
+/* djb2 hash function */
+unsigned long hash(char *key);
#endif
diff --git a/src/include/helpers.h b/src/include/helpers.h
index 5d46909..9f9dff7 100644
--- a/src/include/helpers.h
+++ b/src/include/helpers.h
@@ -14,4 +14,5 @@ void *safe_realloc(void *x, size_t size);
void alloc_zero(void *ptr, size_t size);
void nothing(void *);
+
#endif
diff --git a/src/include/list.h b/src/include/list.h
new file mode 100644
index 0000000..055106a
--- /dev/null
+++ b/src/include/list.h
@@ -0,0 +1,36 @@
+#ifndef LIST_H
+#define LIST_H
+#include <stdlib.h>
+#include <stdbool.h>
+
+typedef struct NODE_STRUCT {
+ void *item;
+ struct NODE_STRUCT *next;
+ struct NODE_STRUCT *prev;
+} node_t;
+
+typedef struct {
+ size_t size;
+ node_t *head;
+ node_t *tail;
+} list_t;
+
+node_t *init_node(void *item);
+
+void node_free(void *x, void (*freefunc)(void *));
+
+list_t *init_list();
+
+void list_push_front(list_t *l, void *x);
+
+void list_push_back(list_t *l, void *x);
+
+void *list_pop_back(list_t *l);
+
+void *list_pop_front(list_t *l);
+
+bool list_is_empty(list_t *l);
+
+void list_free(void *x, void (*freefunc)(void *));
+
+#endif
diff --git a/src/include/opcodes.h b/src/include/opcodes.h
index ff8400f..9456574 100644
--- a/src/include/opcodes.h
+++ b/src/include/opcodes.h
@@ -2,6 +2,7 @@
#define OPCODES_H
typedef enum {
+ CO_OK,
CO_NOP,
CO_JN, /* join */
CO_DM,
@@ -27,7 +28,8 @@ typedef enum {
} copcode_t;
typedef enum {
- SO_SUCCESS,
+ SO_OK,
+ SO_ULOG, /* update client log state */
SO_FAIL_PARSE,
SO_FAIL_NOPERM,
SO_FAIL_USER_TAKEN,
diff --git a/src/include/protocol.h b/src/include/protocol.h
index 204a507..31138c2 100644
--- a/src/include/protocol.h
+++ b/src/include/protocol.h
@@ -2,6 +2,7 @@
#define PROTOCOL_H
#include <time.h>
+#include <stdio.h>
#include <stdbool.h>
#include "array.h"
@@ -38,7 +39,7 @@ typedef struct {
} message_t;
typedef struct {
- array_t *messages;
+ FILE *messages;
user_t *admin;
array_t *mods;
@@ -58,9 +59,14 @@ typedef struct {
user_t *user1;
user_t *user2;
- array_t *messages;
+ struct tm *date;
+ FILE *msgs;
} dm_t;
+string_t *date_str();
+
+bool same_day(struct tm *date1, struct tm *date2);
+
string_t *encode_chanstate(ht_t *chans);
string_t *encode_usersstate(ht_t *u);