aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPreston Pan <ret2pop@gmail.com>2024-12-26 21:18:05 -0800
committerPreston Pan <ret2pop@gmail.com>2024-12-26 21:18:05 -0800
commitfd14f6fbf8206589d2a0ad8f0793845cb8faf1d7 (patch)
treeac3f8288b9e5e9d5e3acaf7d07694dc04157233a /include
parente75d6f6b8f4512a5bbfecbfa8c17f0bb687e3d55 (diff)
stuff
Diffstat (limited to 'include')
-rw-r--r--include/array.h4
-rw-r--r--include/better_string.h2
-rw-r--r--include/hash_table.h35
-rw-r--r--include/helpers.h3
-rw-r--r--include/ht.h3
-rw-r--r--include/opcodes.h2
-rw-r--r--include/protocol.h54
-rw-r--r--include/tsv.h16
8 files changed, 110 insertions, 9 deletions
diff --git a/include/array.h b/include/array.h
index 48d82db..0b53f95 100644
--- a/include/array.h
+++ b/include/array.h
@@ -1,7 +1,9 @@
#ifndef ARRAY_H
#define ARRAY_H
+
#include <stdlib.h>
#define DEFAULT_ARR_LEN 10
+
typedef struct {
void **items;
size_t size;
@@ -14,5 +16,7 @@ void array_push(array_t *a, void *item);
void *array_pop(array_t *a);
+void *array_del(array_t *a, unsigned int ind);
+
void array_free(void *a, void (*freefunc)(void *));
#endif
diff --git a/include/better_string.h b/include/better_string.h
index b23010e..09fd928 100644
--- a/include/better_string.h
+++ b/include/better_string.h
@@ -10,7 +10,7 @@ typedef struct {
string_t *init_string(const char *source);
-void string_append(string_t *s, char c);
+void string_push(string_t *s, char c);
void string_concat(string_t *s1, string_t *s2);
diff --git a/include/hash_table.h b/include/hash_table.h
index 16d8fe9..357e38a 100644
--- a/include/hash_table.h
+++ b/include/hash_table.h
@@ -1,14 +1,43 @@
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
+#include <array.h>
+
+#define DEFAULT_HT_SIZE 500
+
+typedef struct PAIR_STRUCT {
+ char *key;
+ 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;
+ size_t size;
} ht_t;
+
+node_t *init_node(char *key, void *v);
+
+void sll_push(sll_t *sll, char *key, void *v);
+
+void sll_delete(sll_t *sll, char *key);
+
+sll_t *sll_free(void *x, void (*freefunc)(void *));
+
+void ht_insert(ht_t *ht, char *key, void *value);
+
+void ht_delete(ht_t *ht, char *key);
+
+void *ht_get(ht_t *ht, char *key);
+
+ht_t *init_ht(size_t size);
#endif
diff --git a/include/helpers.h b/include/helpers.h
index c685e09..276b590 100644
--- a/include/helpers.h
+++ b/include/helpers.h
@@ -1,7 +1,10 @@
#ifndef HELPERS_H
#define HELPERS_H
+
#include <stdlib.h>
+void die_lz(int code, const char *msg);
+
void die(const char *msg);
void *safe_calloc(unsigned int i, size_t size);
diff --git a/include/ht.h b/include/ht.h
deleted file mode 100644
index 9172961..0000000
--- a/include/ht.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#ifndef HT_H
-#define HT_H
-#endif
diff --git a/include/opcodes.h b/include/opcodes.h
index 3d5baf8..ff8400f 100644
--- a/include/opcodes.h
+++ b/include/opcodes.h
@@ -36,8 +36,6 @@ typedef enum {
SO_BYE,
} sopcode_t;
-void die_lz(int code, const char *msg);
-
char *decode_client_opcode(int op);
char *decode_server_opcode(int op);
diff --git a/include/protocol.h b/include/protocol.h
index 7b5eb07..16ba818 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -1,6 +1,14 @@
#ifndef PROTOCOL_H
#define PROTOCOL_H
+#include <time.h>
+#include <stdbool.h>
+
+#include <array.h>
+#include <better_string.h>
+#include <hash_table.h>
+#include <openssl/sha.h>
+
#define MAX_OP_LEN 10
#define MAX_ARG_LEN 50
#define MAX_ARGS 5
@@ -11,4 +19,50 @@
#define USERNAME_SIZE 30
#define KEYLEN 512
+typedef struct {
+ string_t *nick;
+ bool is_guest;
+ int fd;
+
+ /* list of channels where user is in */
+ array_t *channels;
+ array_t *dms;
+ array_t *autojoin;
+ unsigned char passhash[SHA256_DIGEST_LENGTH];
+} user_t;
+
+typedef struct {
+ string_t *nick;
+ string_t *msg;
+ time_t time;
+} message_t;
+
+typedef struct {
+ array_t *messages;
+
+ user_t *admin;
+ array_t *mods;
+
+ bool registered_only;
+
+ bool invite_only;
+ array_t *allowed_users;
+
+ array_t *users;
+
+ string_t *chan_name;
+ string_t *desc;
+} channel_t;
+
+typedef struct {
+ user_t *user1;
+ user_t *user2;
+
+ array_t *messages;
+} dm_t;
+
+string_t *encode_chanstate(ht_t *chans);
+
+string_t *encode_usersstate(ht_t *u);
+
#endif
diff --git a/include/tsv.h b/include/tsv.h
new file mode 100644
index 0000000..5f6a9f6
--- /dev/null
+++ b/include/tsv.h
@@ -0,0 +1,16 @@
+#ifndef TSV_H
+#define TSV_H
+
+#include <better_string.h>
+
+typedef struct {
+ char *source;
+ unsigned int i;
+ char c;
+} tsv_t;
+
+tsv_t *init_tsv(char *source);
+
+string_t *next_tsv(tsv_t *tsv);
+
+#endif