aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPreston Pan <ret2pop@gmail.com>2024-12-24 21:11:06 -0800
committerPreston Pan <ret2pop@gmail.com>2024-12-24 21:11:06 -0800
commite75d6f6b8f4512a5bbfecbfa8c17f0bb687e3d55 (patch)
tree7a96002751a1ca3b173762a13b181ebea4123817 /include
first commit
Diffstat (limited to 'include')
-rw-r--r--include/array.h18
-rw-r--r--include/better_string.h22
-rw-r--r--include/hash_table.h14
-rw-r--r--include/helpers.h12
-rw-r--r--include/ht.h3
-rw-r--r--include/opcodes.h49
-rw-r--r--include/protocol.h14
7 files changed, 132 insertions, 0 deletions
diff --git a/include/array.h b/include/array.h
new file mode 100644
index 0000000..48d82db
--- /dev/null
+++ b/include/array.h
@@ -0,0 +1,18 @@
+#ifndef ARRAY_H
+#define ARRAY_H
+#include <stdlib.h>
+#define DEFAULT_ARR_LEN 10
+typedef struct {
+ void **items;
+ size_t size;
+ size_t capacity;
+} array_t;
+
+array_t *init_array();
+
+void array_push(array_t *a, void *item);
+
+void *array_pop(array_t *a);
+
+void array_free(void *a, void (*freefunc)(void *));
+#endif
diff --git a/include/better_string.h b/include/better_string.h
new file mode 100644
index 0000000..b23010e
--- /dev/null
+++ b/include/better_string.h
@@ -0,0 +1,22 @@
+#ifndef STRING_H
+#define STRING_H
+#include <stdlib.h>
+#define DEFAULT_STR_SIZE 10
+typedef struct {
+ char *buf;
+ size_t len;
+ size_t size;
+} string_t;
+
+string_t *init_string(const char *source);
+
+void string_append(string_t *s, char c);
+
+void string_concat(string_t *s1, string_t *s2);
+
+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/include/hash_table.h b/include/hash_table.h
new file mode 100644
index 0000000..16d8fe9
--- /dev/null
+++ b/include/hash_table.h
@@ -0,0 +1,14 @@
+#ifndef HASH_TABLE_H
+#define HASH_TABLE_H
+typedef struct NODE_STRUCT {
+
+} node_t;
+
+typedef struct {
+
+} sll_t;
+
+typedef struct {
+
+} ht_t;
+#endif
diff --git a/include/helpers.h b/include/helpers.h
new file mode 100644
index 0000000..c685e09
--- /dev/null
+++ b/include/helpers.h
@@ -0,0 +1,12 @@
+#ifndef HELPERS_H
+#define HELPERS_H
+#include <stdlib.h>
+
+void die(const char *msg);
+
+void *safe_calloc(unsigned int i, size_t size);
+
+void *safe_realloc(void *x, size_t size);
+
+void alloc_zero(void *ptr, size_t size);
+#endif
diff --git a/include/ht.h b/include/ht.h
new file mode 100644
index 0000000..9172961
--- /dev/null
+++ b/include/ht.h
@@ -0,0 +1,3 @@
+#ifndef HT_H
+#define HT_H
+#endif
diff --git a/include/opcodes.h b/include/opcodes.h
new file mode 100644
index 0000000..3d5baf8
--- /dev/null
+++ b/include/opcodes.h
@@ -0,0 +1,49 @@
+#ifndef OPCODES_H
+#define OPCODES_H
+
+typedef enum {
+ CO_NOP,
+ CO_JN, /* join */
+ CO_DM,
+ CO_PST, /* post */
+ CO_MSG,
+ CO_REG,
+ CO_NCK, /* nick */
+ CO_PNG, /* pong */
+ CO_LVE, /* leave */
+ CO_QT, /* quit*/
+
+ CO_CLM, /* claim channel */
+ CO_DESC, /* change description */
+ CO_TRSFR, /* ownership transfer of admin */
+ CO_KCK, /* kick */
+ CO_BAN,
+ CO_KNGT, /* knight */
+ CO_DMT, /* demote */
+
+ CO_LOGS, /* allows users to download log file from date specified in unix time */
+
+ CO_UNRECOGNIZED
+} copcode_t;
+
+typedef enum {
+ SO_SUCCESS,
+ SO_FAIL_PARSE,
+ SO_FAIL_NOPERM,
+ SO_FAIL_USER_TAKEN,
+ SO_FAIL_RATE, /* rate limit */
+ SO_PNG, /* ping */
+ SO_BYE,
+} sopcode_t;
+
+void die_lz(int code, const char *msg);
+
+char *decode_client_opcode(int op);
+
+char *decode_server_opcode(int op);
+
+int encode_client_opcode(char *c);
+
+int encode_server_opcode(char *c);
+
+#endif
diff --git a/include/protocol.h b/include/protocol.h
new file mode 100644
index 0000000..7b5eb07
--- /dev/null
+++ b/include/protocol.h
@@ -0,0 +1,14 @@
+#ifndef PROTOCOL_H
+#define PROTOCOL_H
+
+#define MAX_OP_LEN 10
+#define MAX_ARG_LEN 50
+#define MAX_ARGS 5
+#define MAX_BUFSIZE 4096
+#define DEFAULT_PORT 11111
+#define MAX_CONNECTIONS 32768
+#define DEFAULT_TIMEOUT 6000
+#define USERNAME_SIZE 30
+#define KEYLEN 512
+
+#endif