From 94dbf3210300215b15db4c2cc9de2980044a5324 Mon Sep 17 00:00:00 2001 From: Ritchie Cunningham Date: Sat, 23 Nov 2024 21:25:51 +0000 Subject: [PATCH] [Add] Adding IRC network handling. --- base/config/Makefile | 2 +- base/config/config.c | 15 ++++++++++++++- base/config/config.h | 2 ++ base/config/network.c | 27 +++++++++++++++++++++++++++ base/config/network.h | 24 ++++++++++++++++++++++++ skel/c3po.conf | 1 + 6 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 base/config/network.c create mode 100644 base/config/network.h diff --git a/base/config/Makefile b/base/config/Makefile index 7cb9f8e..7423850 100644 --- a/base/config/Makefile +++ b/base/config/Makefile @@ -1,4 +1,4 @@ -SRC = config.c plugin.c +SRC = config.c plugin.c network.c CFLAGS += -fPIC -shared -Wl,-soname,config.so -O3 LDFLAGS += -ldl diff --git a/base/config/config.c b/base/config/config.c index 411a4f3..5d81462 100644 --- a/base/config/config.c +++ b/base/config/config.c @@ -1,9 +1,20 @@ #include "config.h" void configProcess(const char* command, const char* arg1, const char* arg2) { - if(strcmp(command, "plugin") == 0) { + char network[64]; + + *network = 0; + + if(strcmp(command, "}") == 0) + *network = 0; + else if(strlen(network) != 0) { + /* TODO: Add network setup params. */ + } else if(strcmp(command, "plugin") == 0) { if(strcmp(arg1, "scan") == 0) pluginCrawl(arg2); + } else if(strcmp(command, "network") == 0) { + strncpy(network, arg1, 64); + networkAdd(arg1); } return; @@ -13,6 +24,8 @@ int configRead(const char* path) { FILE* fp; char command[64], arg1[128], arg2[128], buff[512]; + networkInit(); + if((fp = fopen(path, "r")) == NULL) { fprintf(stderr, "[CONFIG] Unable to open configuration file %s. We're screwed\n", path); return -1; diff --git a/base/config/config.h b/base/config/config.h index 046c919..92667bf 100644 --- a/base/config/config.h +++ b/base/config/config.h @@ -9,9 +9,11 @@ #include "api.h" #include "plugin.h" +#include "network.h" typedef struct { PLUGIN plugin; + struct NETWORK_ENTRY* network; } CONFIG; CONFIG* config; diff --git a/base/config/network.c b/base/config/network.c new file mode 100644 index 0000000..62614d0 --- /dev/null +++ b/base/config/network.c @@ -0,0 +1,27 @@ +#include "config.h" + +void networkAdd(const char* name) { + struct NETWORK_ENTRY* network; + + if((network = malloc(sizeof(struct NETWORK_ENTRY))) == NULL) + return; + + strncpy(network->name, name, 64); + *network->host = *network->layer = 0; + network->port = 6667; + strncpy(network->nick, "C-3PO", 64); + network->network_handle = NULL; + network->next = 0; + + network->next = config->network; + config->network = network; + + fprintf(stderr, "Debug: Added network %s\n", name); + + return; +} + +void networkInit() { + config->network = NULL; + return; +} diff --git a/base/config/network.h b/base/config/network.h new file mode 100644 index 0000000..48670ee --- /dev/null +++ b/base/config/network.h @@ -0,0 +1,24 @@ +#pragma once + +struct NETWORK_CHANNEL { + char name[128]; + char key[128]; + int last_sent; + int cap; + struct NETWORK_CHANNEL* next; +}; + +struct NETWORK_ENTRY { + char name[64]; + char host[128]; + int port; + char nick[64]; + char layer[64]; + + void* network_handle; + struct NETWORK_CHANNEL* channel; + struct NETWORK_ENTRY* next; +}; + +void networkAdd(const char* name); +void networkInit(); diff --git a/skel/c3po.conf b/skel/c3po.conf index 66d9fd7..86f6249 100644 --- a/skel/c3po.conf +++ b/skel/c3po.conf @@ -2,6 +2,7 @@ plugin scan base plugin scan extra network Libera { + layer plain server irc.libera.chat port 6667 nick C-3PO