From 2acf288cebfb5aa5a16f858d8649efe6311ddfd2 Mon Sep 17 00:00:00 2001 From: Ritchie Cunningham Date: Sat, 23 Nov 2024 16:32:31 +0000 Subject: [PATCH] [Add] Added launcher for c3po --- base/Makefile | 2 ++ base/c3po/Makefile | 8 ++++++++ base/c3po/c3po.c | 40 +++++++++++++++++++++++++++++++++++++ base/c3po/c3po.h | 15 ++++++++++++++ base/config/config.c | 8 ++++++++ base/config/config.h | 17 ++++++++++++++++ base/config/plugin.c | 25 +++++++++++++++++++++++ base/config/plugin.h | 27 +++++++++++++++++++++++++ base/network_ssl/network.c | 4 ++-- bin/c3po | Bin 0 -> 16304 bytes 10 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 base/c3po/Makefile create mode 100644 base/c3po/c3po.c create mode 100644 base/c3po/c3po.h create mode 100644 base/config/config.c create mode 100644 base/config/config.h create mode 100644 base/config/plugin.c create mode 100644 base/config/plugin.h create mode 100755 bin/c3po diff --git a/base/Makefile b/base/Makefile index 22f9ee8..e2110b8 100644 --- a/base/Makefile +++ b/base/Makefile @@ -1,7 +1,9 @@ default: + cd c3po && make cd network_plain && make cd network_ssl && make clean: + cd c3po && make clean cd network_plain && make clean cd network_ssl && make clean diff --git a/base/c3po/Makefile b/base/c3po/Makefile new file mode 100644 index 0000000..446e77e --- /dev/null +++ b/base/c3po/Makefile @@ -0,0 +1,8 @@ +CFLAGS += -Wall -O3 +LDFLAGS += -ldl +SRC = c3po.c + +default: + $(CC) $(CFLAGS) $(SRC) -o ../../bin/c3po $(LDFLAGS) + +clean: diff --git a/base/c3po/c3po.c b/base/c3po/c3po.c new file mode 100644 index 0000000..599758c --- /dev/null +++ b/base/c3po/c3po.c @@ -0,0 +1,40 @@ +#include "c3po.h" + +void loadSymbols() { + c3po.init = dlsym(c3po.library, "init"); + c3po.destroy = dlsym(c3po.library, "destroy"); + + return; +} + +void reload(int signal) { + (c3po.destroy)(c3po.handle); + dlclose(c3po.library); + + if((c3po.library = dlopen("base/config.so", RTLD_NOW | RTLD_GLOBAL)) == NULL) { + fprintf(stderr, "Fatal Err: base/config.so is no longer loadable.\n"); + exit(-1); + } + + c3po.handle = (c3po.init)(); + + exit(-1); + return; +} + +int main(int argc, char** argv) { + signal(SIGUSR1, reload); + signal(SIGSEGV, reload); + + if((c3po.library = dlopen("base/config.so", RTLD_NOW | RTLD_GLOBAL)) == NULL) { + fprintf(stderr, "Fatal Err: Unable to load base/config.so. c3po is nothing without it\n"); + return -1; + } + + loadSymbols(); + c3po.handle = (c3po.init)(); + + fprintf(stderr, "init() returned. This shouldn't be possible.\n"); + + return -1; +} diff --git a/base/c3po/c3po.h b/base/c3po/c3po.h new file mode 100644 index 0000000..d29334c --- /dev/null +++ b/base/c3po/c3po.h @@ -0,0 +1,15 @@ +#pragma once +#include +#include +#include +#include +#include + +typedef struct { + void* (*init)(); + int (*destroy)(void* handle); + void *library; + void *handle; +} C3PO; + +C3PO c3po; diff --git a/base/config/config.c b/base/config/config.c new file mode 100644 index 0000000..5c3690d --- /dev/null +++ b/base/config/config.c @@ -0,0 +1,8 @@ +#include "config.h" + +void* init() { + if((config = malloc(sizeof(CONFIG))) == NULL) { + fprintf(stderr, "[CONFIG] First malloc failed. Let's just give up :D\n"); + return NULL; + } +} diff --git a/base/config/config.h b/base/config/config.h new file mode 100644 index 0000000..83134f6 --- /dev/null +++ b/base/config/config.h @@ -0,0 +1,17 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include + +#include "plugin.h" + +typedef struct { +#include + PLUGIN plugin; +} CONFIG; + +CONFIG* config; diff --git a/base/config/plugin.c b/base/config/plugin.c new file mode 100644 index 0000000..4e5cec1 --- /dev/null +++ b/base/config/plugin.c @@ -0,0 +1,25 @@ +#include "config.h" + +void pluginInit() { + config->plugin.network_plug = NULL; + config->plugin.filter_plug = NULL; + return; +} + +void pluginCrawl(const char* path) { + DIR* dir; + struct dirent* file; + + dir = opendir(path); + + do { + file = readdir(dir); + if(file == NULL) + break; + pluginProcess(path, file->d_name); + } while(1); + + closedir(dir); + + return; +} diff --git a/base/config/plugin.h b/base/config/plugin.h new file mode 100644 index 0000000..fd10689 --- /dev/null +++ b/base/config/plugin.h @@ -0,0 +1,27 @@ +#pragma once + +struct PLUGIN_NETWORK_ENTRY { + void* lib_handle; + const char* name; + void* (*connect)(const char* host, int port); + int (*socket)(void* handle); + int (*read)(void* handle, char* buffer, int buffer_len); + int (*write)(void* handle, char* buffer, int buffer_len); + void* (*disconnect)(void* handle); + struct PLUGIN_NETWORK_ENTRY* next; +}; + +struct PLUGIN_FILTER_ENTRY { + void* lib_handle; + const char* name; + int trig_type; + void *(*init)(); + void (*filter)(void* handle, const char* from, const char* host, + const char* channel, const char* message); + void *(*destroy)(void* handle); +}; + +typedef struct { + struct PLUGIN_NETWORK_ENTRY* network_plugin; + struct PLUGIN_FILTER_ENTRY* filter_plug; +} PLUGIN; diff --git a/base/network_ssl/network.c b/base/network_ssl/network.c index e846fe7..352c635 100644 --- a/base/network_ssl/network.c +++ b/base/network_ssl/network.c @@ -17,7 +17,7 @@ void* pluginConnect(const char* host, int port) { return NULL; } - connection->ctx == SSL_CTX_new(SSLv23_client_method()); + connection->ctx = SSL_CTX_new(SSLv23_client_method()); if((connection->bio = BIO_new_ssl_connect(connection->ctx)) == NULL) { configErrorPush("Unable to allocate a BIO"); @@ -25,7 +25,7 @@ void* pluginConnect(const char* host, int port) { return NULL; } - BIO_get_SSL(connection->bio, &connection->ssl); + BIO_get_ssl(connection->bio, &connection->ssl); SSL_set_mode(connection->ssl, SSL_MODE_AUTO_RETRY); BIO_set_conn_hostname(connection->bio, host); BIO_set_conn_int_port(connection->bio, &port); diff --git a/bin/c3po b/bin/c3po new file mode 100755 index 0000000000000000000000000000000000000000..e7ff06c02444a9922dcc78c4d6a909d84000e0e5 GIT binary patch literal 16304 zcmeHOYiu0V6~4QP!GXkH2U46+l7SLP+InN>)g;Jeo!HJAB_Sk^+KQIR+B^1cwcg#% z&Neocs9S@oD5RKHZBa#~z>k&+38AVL6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