summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2023-08-10 01:12:30 -0400
committerTest_User <hax@andrewyu.org>2023-08-10 01:12:30 -0400
commit031d6a3d88c714cd11884e73248f0c24090d50e1 (patch)
treee7e90ba77dea37ccee34cd7f2e0838e2dec8e956
parentffc06e4614772a681114d4059a072f599ee378f8 (diff)
downloadcoupserv-031d6a3d88c714cd11884e73248f0c24090d50e1.tar.gz
coupserv-031d6a3d88c714cd11884e73248f0c24090d50e1.zip
Log-related stuff
-rw-r--r--Makefile8
-rw-r--r--client_network.c32
-rw-r--r--main.c58
-rw-r--r--network.h4
-rw-r--r--tls.c28
-rw-r--r--tls.h4
6 files changed, 123 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 74178eb..4ddf248 100644
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,14 @@
#INCLUDEFLAGS =
+ifeq ($(VERBOSE), 1)
+ CFLAGS += -DLOGALL=1
+endif
+
+ifeq ($(COLORIZE), 1)
+ CFLAGS += -DCOLORIZE=1
+endif
+
CFLAGS += $(INCLUDEFLAGS) -D_REENTRANT -ggdb3 -Wall -Wextra -Wsign-conversion -Wno-unused-parameter $(shell pkg-config gnutls --cflags)
LDFLAGS = -lpthread $(shell pkg-config gnutls --libs)
diff --git a/client_network.c b/client_network.c
index 3ddad6e..fe03eba 100644
--- a/client_network.c
+++ b/client_network.c
@@ -533,3 +533,35 @@ int initclientnetwork(void) {
return 0;
}
+
+#if LOGALL
+ssize_t SENDCLIENT(struct string msg) {
+ if (!msg.len)
+ return 0;
+
+ static char printprefix = 1;
+ if (printprefix) {
+#if COLORIZE
+ WRITES(1, STRING("\x1b[31m[Us->Client] \x1b[32m"));
+#else
+ WRITES(1, STRING("[Us->Client] "));
+#endif
+
+ printprefix = 0;
+ }
+
+ WRITES(1, msg);
+
+ if (msg.data[msg.len - 1] == '\n') {
+ printprefix = 1;
+#if COLORIZE
+ WRITES(1, STRING("\x1b[0m\n"));
+#else
+ WRITES(1, STRING("\n"));
+#endif
+ }
+
+
+ return WRITES(client_fd, msg);
+}
+#endif
diff --git a/main.c b/main.c
index b0c94a8..eca82be 100644
--- a/main.c
+++ b/main.c
@@ -90,8 +90,6 @@ void *client_loop(void *ign) {
continue;
while (1) {
- WRITES(1, STRING("Recvd: "));
- write(1, full_msg.data, msg_len+1); // +1: \n
if (full_msg.data[msg_len - 1] == '\r')
msg_len--;
@@ -170,16 +168,37 @@ void *client_loop(void *ign) {
int (*func)(uint64_t argc, struct string *argv) = get_table_index(client_network_commands, command);
+#if LOGALL
+#if COLORIZE
+ WRITES(1, STRING("\x1b[34m[Client->Us] \x1b[33m"));
+#else
+ WRITES(1, STRING("[Client->Us] "));
+#endif
+#if COLORIZE
+ write(1, full_msg.data, msg_len);
+ WRITES(1, STRING("\x1b[0m\n"));
+#else
+ write(1, full_msg.data, msg_len+1); // +1: \n
+#endif
+#endif
+
if (func == 0) {
+#if !LOGALL
+ WRITES(2, STRING("[Client] "));
+ write(2, full_msg.data, msg_len+1); // +1: \n
+#endif
WRITES(2, STRING("WARNING: Command is unknown, ignoring...\n"));
+ WRITES(2, STRING("\n"));
} else {
+#if LOGALL
+ WRITES(1, STRING("\n"));
+#endif
int err = func(argc, argv);
if (err) {
WRITES(1, STRING("Disconnecting client by result of the network command handler...\n"));
goto disconnect_client;
}
}
- write(1, "\n", 1);
if (full_msg.data[msg_len] == '\r')
msg_len++;
@@ -274,15 +293,12 @@ int main(void) {
continue;
while (1) {
- WRITES(1, STRING("Recvd: "));
- write(1, full_msg.data, msg_len+1); // +1: \n
-
uint64_t offset = 0;
while (offset < msg_len && full_msg.data[offset] == ' ')
offset++;
if (msg_len == offset) {
- puts("Protocol violation: Empty message.");
+ WRITES(2, STRING("Protocol violation: Empty message.\n"));
return 2;
}
@@ -299,7 +315,7 @@ int main(void) {
}
}
if (!found || source.len + 1 == msg_len) {
- puts("Protocol violation: Sender but no command.");
+ WRITES(2, STRING("Protocol violation: Sender but no command."));
return 2;
}
} else {
@@ -311,7 +327,7 @@ int main(void) {
offset++;
if (offset == msg_len) {
- puts("Protocol violation: No command.");
+ WRITES(2, STRING("Protocol violation: No command."));
return 2;
}
@@ -381,17 +397,37 @@ int main(void) {
int (*func)(struct string source, uint64_t argc, struct string *argv) = get_table_index(server_network_commands, command);
+#if LOGALL
+#if COLORIZE
+ WRITES(1, STRING("\x1b[35m[Server->Us] \x1b[36m"));
+#else
+ WRITES(1, STRING("[Server->Us] "));
+#endif
+#if COLORIZE
+ write(1, full_msg.data, msg_len);
+ WRITES(1, STRING("\x1b[0m\n"));
+#else
+ write(1, full_msg.data, msg_len+1); // +1: \n
+#endif
+#endif
+
if (func == 0) {
+#if !LOGALL
+ WRITES(2, STRING("[Server] "));
+ write(2, full_msg.data, msg_len+1); // +1: \n
+#endif
WRITES(2, STRING("WARNING: Command is unknown, ignoring...\n"));
+ WRITES(2, STRING("\n"));
} else {
- write(1, "\n", 1);
+#if LOGALL
+ WRITES(1, STRING("\n"));
+#endif
int err = func(source, argc, argv);
if (err) {
WRITES(1, STRING("Disconnecting by result of the network command handler...\n"));
return 0;
}
}
- write(1, "\n", 1);
memmove(full_msg.data, full_msg.data+msg_len+1, full_msg.len - msg_len - 1);
full_msg.len -= msg_len+1;
diff --git a/network.h b/network.h
index 124b21d..539d052 100644
--- a/network.h
+++ b/network.h
@@ -106,7 +106,11 @@ extern int initclientnetwork(void);
extern char channel_mode_types[UCHAR_MAX];
+#if LOGALL
+extern ssize_t SENDCLIENT(struct string msg);
+#else
#define SENDCLIENT(x) write(client_fd, x.data, x.len)
+#endif
extern int privmsg(struct string source, struct string target, struct string message);
extern int add_local_client(struct string uid, struct string nick_arg, struct string vhost_arg, struct string ident_arg, struct string realname_arg, time_t timestamp);
diff --git a/tls.c b/tls.c
index 314a889..a3f3200 100644
--- a/tls.c
+++ b/tls.c
@@ -90,3 +90,31 @@ int connect_tls(void) {
}
extern inline size_t RECV(char *buf, size_t buflen, char *timeout); // Should force it to get compiled into tls.o
+
+#if LOGALL
+ssize_t SEND(struct string msg) {
+ static char printprefix = 1;
+ if (printprefix) {
+#if COLORIZE
+ WRITES(1, STRING("\x1b[33m[Us->Server] \x1b[34m"));
+#else
+ WRITES(1, STRING("[Us->Server] "));
+#endif
+
+ printprefix = 0;
+ }
+
+ WRITES(1, msg);
+
+ if (msg.data[msg.len - 1] == '\n') {
+ printprefix = 1;
+#if COLORIZE
+ WRITES(1, STRING("\x1b[0m\n"));
+#else
+ WRITES(1, STRING("\n"));
+#endif
+ }
+
+ return gnutls_record_send(session, msg.data, msg.len);
+}
+#endif
diff --git a/tls.h b/tls.h
index 577251b..79aedd7 100644
--- a/tls.h
+++ b/tls.h
@@ -28,7 +28,11 @@
#include <gnutls/gnutls.h>
+#if LOGALL
+extern ssize_t SEND(struct string msg);
+#else
#define SEND(x) gnutls_record_send(session, x.data, x.len)
+#endif
extern gnutls_session_t session;