aboutsummaryrefslogtreecommitdiff
path: root/src/include/protocol.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/protocol.h')
-rw-r--r--src/include/protocol.h98
1 files changed, 70 insertions, 28 deletions
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