From c0ba7e6bedec8b82ac84176b4780757045e633c9 Mon Sep 17 00:00:00 2001 From: Ritchie Cunningham Date: Sat, 23 Nov 2024 20:03:28 +0000 Subject: [PATCH] [Add] Made progress with config file system --- Makefile | 1 + base/config/config.c | 42 ++++++++++++++++++++++++++++++++++++++++++ base/config/plugin.c | 3 ++- base/config/plugin.h | 3 +++ bin/base/c3po.conf | 10 ++++++++++ skel/c3po.conf | 10 ++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 bin/base/c3po.conf create mode 100644 skel/c3po.conf diff --git a/Makefile b/Makefile index 1dfe0a0..eb49b52 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ default: mkdir -p bin mkdir -p bin/base + cp skel/* bin/base cd base && make clean: diff --git a/base/config/config.c b/base/config/config.c index 82febc1..411a4f3 100644 --- a/base/config/config.c +++ b/base/config/config.c @@ -1,10 +1,52 @@ #include "config.h" +void configProcess(const char* command, const char* arg1, const char* arg2) { + if(strcmp(command, "plugin") == 0) { + if(strcmp(arg1, "scan") == 0) + pluginCrawl(arg2); + } + + return; +} + +int configRead(const char* path) { + FILE* fp; + char command[64], arg1[128], arg2[128], buff[512]; + + if((fp = fopen(path, "r")) == NULL) { + fprintf(stderr, "[CONFIG] Unable to open configuration file %s. We're screwed\n", path); + return -1; + } + + while(!feof(fp)) { + *buff = 0; + *command = 0; + *arg1 = 0; + *arg2 = 0; + + fgets(buff, 512, fp); + sscanf(buff, "%s %s %s\n", command, arg1, arg2); + configProcess(command, arg1, arg2); + } + + return 0; +} + +void configErrorPush(const char* error) { + /* TODO: Make queue. */ + fprintf(stderr, error); + + return; +} + void* init() { if((config = malloc(sizeof(CONFIG))) == NULL) { fprintf(stderr, "[CONFIG] First malloc failed. Let's just give up :D\n"); return NULL; } + pluginInit(); + configRead("base/c3po.conf"); + return NULL; } diff --git a/base/config/plugin.c b/base/config/plugin.c index 6b04e2f..d71b8b9 100644 --- a/base/config/plugin.c +++ b/base/config/plugin.c @@ -120,7 +120,8 @@ void pluginCrawl(const char* path) { DIR* dir; struct dirent* file; - dir = opendir(path); + if((dir = opendir(path)) == NULL) + return; do { file = readdir(dir); diff --git a/base/config/plugin.h b/base/config/plugin.h index 4a0fbb0..b98ee1a 100644 --- a/base/config/plugin.h +++ b/base/config/plugin.h @@ -26,3 +26,6 @@ typedef struct { struct PLUGIN_NETWORK_ENTRY* network_plug; struct PLUGIN_FILTER_ENTRY* filter_plug; } PLUGIN; + +void pluginInit(); +void pluginCrawl(const char* path); diff --git a/bin/base/c3po.conf b/bin/base/c3po.conf new file mode 100644 index 0000000..66d9fd7 --- /dev/null +++ b/bin/base/c3po.conf @@ -0,0 +1,10 @@ +plugin scan base +plugin scan extra + +network Libera { + server irc.libera.chat + port 6667 + nick C-3PO + + channel #hackers +} diff --git a/skel/c3po.conf b/skel/c3po.conf new file mode 100644 index 0000000..66d9fd7 --- /dev/null +++ b/skel/c3po.conf @@ -0,0 +1,10 @@ +plugin scan base +plugin scan extra + +network Libera { + server irc.libera.chat + port 6667 + nick C-3PO + + channel #hackers +}