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 0000000..e7ff06c Binary files /dev/null and b/bin/c3po differ