aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/better_string.h7
-rw-r--r--src/include/bsv.h21
-rw-r--r--src/include/hash_table.h31
-rw-r--r--src/include/list.h1
-rw-r--r--src/include/protocol.h98
-rw-r--r--src/include/stdobj.h8
-rw-r--r--src/include/tsv.h16
7 files changed, 137 insertions, 45 deletions
diff --git a/src/include/better_string.h b/src/include/better_string.h
index 0fdc8bd..4fc4315 100644
--- a/src/include/better_string.h
+++ b/src/include/better_string.h
@@ -2,6 +2,7 @@
#define STRING_H
#include <stdlib.h>
+#include <stdbool.h>
#define DEFAULT_STR_SIZE 10
typedef struct {
@@ -12,6 +13,10 @@ typedef struct {
string_t *init_string(const char *source);
+string_t *string_copy(string_t *s);
+
+char *string_copy_raw(string_t *s);
+
void string_push(string_t *s, char c);
void string_concat(string_t *s1, string_t *s2);
@@ -20,6 +25,8 @@ void string_concat_const(string_t *s, const char *src);
char string_pop(string_t *s);
+bool string_cmp(string_t *s1, string_t *s2);
+
void string_free(void *s);
#endif
diff --git a/src/include/bsv.h b/src/include/bsv.h
new file mode 100644
index 0000000..dd8206d
--- /dev/null
+++ b/src/include/bsv.h
@@ -0,0 +1,21 @@
+#ifndef BSV_H
+#define BSV_H
+
+#include "better_string.h"
+
+/*! @brief State for byte delimited values */
+typedef struct BSV_STRUCT {
+ /*! @brief the source bsv separated list */
+ char *source;
+ /*! @brief current index */
+ unsigned int i;
+ char c;
+ char delim;
+} bsv_t;
+
+/*! @brief Initializes memory for new bsv struct */
+bsv_t *init_bsv(char *source, char delim);
+
+/*! @brief get the next byte delimited token */
+string_t *bsv_next(bsv_t *bsv);
+#endif
diff --git a/src/include/hash_table.h b/src/include/hash_table.h
index 8f19635..55136ba 100644
--- a/src/include/hash_table.h
+++ b/src/include/hash_table.h
@@ -2,16 +2,21 @@
#define HASH_TABLE_H
#include "list.h"
#include <stdlib.h>
+
#define DEFAULT_HT_SIZE 500
typedef struct PAIR_STRUCT {
- char *key;
+ union {
+ char *key;
+ int ikey;
+ };
void *v;
} pair_t;
typedef struct {
list_t **buckets;
size_t size;
+ bool is_map;
} ht_t;
pair_t *init_pair(char *key, void *value);
@@ -22,10 +27,34 @@ void *bucket_pop(list_t *b, char *key);
void bucket_free(void *x, void (*freefunc)(void *));
+pair_t *init_long_pair(unsigned long key, void *value);
+
+void *bucket_get_by_long(list_t *b, unsigned long key);
+
+void *bucket_pop_by_long(list_t *b, unsigned long key);
+
+void bucket_free_with_long(void *x, void (*freefunc)(void *));
+
ht_t *init_ht(size_t size);
+ht_t *init_map(size_t size);
+
+void map_insert(ht_t *ht, unsigned long key, void *value);
+
+void *map_pop(ht_t *ht, unsigned long key);
+
+void *map_get(ht_t *ht, unsigned long key);
+
+void map_free(void *x);
+
void ht_insert(ht_t *ht, char *key, void *value);
+/*! @brief returns the old value, mutates ht state with new value */
+void *ht_modify(ht_t *ht, char *key, void *newval);
+
+/*! @brief overwrites old value with new value while freeing the old */
+void ht_overwrite(ht_t *ht, char *key, void *newval, void (*freefunc)(void *));
+
void *ht_pop(ht_t *ht, char *key);
void *ht_get(ht_t *ht, char *key);
diff --git a/src/include/list.h b/src/include/list.h
index 055106a..a9d1539 100644
--- a/src/include/list.h
+++ b/src/include/list.h
@@ -13,6 +13,7 @@ typedef struct {
size_t size;
node_t *head;
node_t *tail;
+ bool type;
} list_t;
node_t *init_node(void *item);
diff --git a/src/include/protocol.h b/src/include/protocol.h
index 31138c2..958ba26 100644
--- a/src/include/protocol.h
+++ b/src/include/protocol.h
@@ -1,9 +1,8 @@
#ifndef PROTOCOL_H
#define PROTOCOL_H
-
-#include <time.h>
-#include <stdio.h>
#include <stdbool.h>
+#include <stdio.h>
+#include <time.h>
#include "array.h"
#include "better_string.h"
@@ -21,48 +20,80 @@
#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 *friends;
+ /* if NULL then guest */
+ unsigned char *passhash;
array_t *autojoin;
- unsigned char passhash[SHA256_DIGEST_LENGTH];
-} user_t;
+ array_t *dms;
+ string_t *name;
+} account_t;
typedef struct {
+ /*! @brief nick who sent the message */
string_t *nick;
+ /*! @brief message content */
string_t *msg;
+ /*! @brief Unix time */
time_t time;
} message_t;
-typedef struct {
- FILE *messages;
-
- user_t *admin;
+/*! @brief describes multiple user chats */
+typedef struct CHANNEL_STRUCT {
+ account_t *admin;
+ /*! @brief account_t array */
array_t *mods;
-
+ /*! @brief No guests */
bool registered_only;
-
- bool invite_only;
+ /*! @brief account_t array
+ * if set, allowed_users creates a private conversation with only
+ * these users
+ */
array_t *allowed_users;
-
+ /*! @brief Explicitly banned users, account_t array */
+ array_t *banned_users;
+ /*! @brief account_t array */
array_t *users;
-
- string_t *chan_name;
+ /*! @brief Description of channel can be set after creation */
string_t *desc;
+ /*! @brief message logs */
+ array_t *msgs;
} channel_t;
-typedef struct {
- user_t *user1;
- user_t *user2;
-
- struct tm *date;
- FILE *msgs;
+/*! @brief struct that contains DM */
+typedef struct DM_STRUCT {
+ account_t *src;
+ array_t *msgs;
} dm_t;
+typedef struct SERVER_STRUCT server_t;
+
+/*! @brief wrapper for server handler that conforms to C spec */
+typedef struct SFUNC_STRUCT {
+ /*! @brief In C spec, function pointers are not the same size as regular pointers */
+ void (*f)(server_t *, list_t *);
+} sfunc_t;
+
+/*! @brief Server state encapsulation */
+struct SERVER_STRUCT {
+ /*! @brief account name => user_t */
+ ht_t *accmap;
+ /*! @brief username => user_t */
+ ht_t *usermap;
+ /*! @brief account name => friends */
+ ht_t *friendmap;
+ /*! @brief fd (int) => string_t */
+ ht_t *fdmap;
+ /*! @brief channel name => channel_t */
+ ht_t *chanmap;
+
+ /*! @brief op name => sfunc_t */
+ ht_t *opmap;
+
+ struct pollfd *fds;
+ int nfds;
+ size_t fd_capacity;
+};
+
string_t *date_str();
bool same_day(struct tm *date1, struct tm *date2);
@@ -71,4 +102,15 @@ string_t *encode_chanstate(ht_t *chans);
string_t *encode_usersstate(ht_t *u);
+message_t *init_message(string_t *nick, string_t *msg, time_t time);
+
+void cop_ok(server_t *s, list_t *args);
+
+void cop_nop(server_t *s, list_t *args);
+
+server_t *init_server(size_t size);
+
+void server_addop(server_t *s, void (*sfunc)(server_t *s, list_t *args));
+
+void server_execop(server_t *s, list_t *stk);
#endif
diff --git a/src/include/stdobj.h b/src/include/stdobj.h
new file mode 100644
index 0000000..d755637
--- /dev/null
+++ b/src/include/stdobj.h
@@ -0,0 +1,8 @@
+#ifndef STDOBJ_H
+#define STDOBJ_H
+#include <stdbool.h>
+#include "array.h"
+#include "better_string.h"
+
+bool array_in(array_t *a, string_t *s);
+#endif
diff --git a/src/include/tsv.h b/src/include/tsv.h
deleted file mode 100644
index 57bb70a..0000000
--- a/src/include/tsv.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#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 *tsv_next(tsv_t *tsv);
-
-#endif