[Add] Added launcher for c3po

This commit is contained in:
Ritchie Cunningham 2024-11-23 16:32:31 +00:00
parent f1600194c1
commit 2acf288ceb
10 changed files with 144 additions and 2 deletions

View File

@ -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

8
base/c3po/Makefile Normal file
View File

@ -0,0 +1,8 @@
CFLAGS += -Wall -O3
LDFLAGS += -ldl
SRC = c3po.c
default:
$(CC) $(CFLAGS) $(SRC) -o ../../bin/c3po $(LDFLAGS)
clean:

40
base/c3po/c3po.c Normal file
View File

@ -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;
}

15
base/c3po/c3po.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dlfcn.h>
#include <signal.h>
typedef struct {
void* (*init)();
int (*destroy)(void* handle);
void *library;
void *handle;
} C3PO;
C3PO c3po;

8
base/config/config.c Normal file
View File

@ -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;
}
}

17
base/config/config.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <dlfcn.h>
#include <signal.h>
#include "plugin.h"
typedef struct {
#include <dirent.h>
PLUGIN plugin;
} CONFIG;
CONFIG* config;

25
base/config/plugin.c Normal file
View File

@ -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;
}

27
base/config/plugin.h Normal file
View File

@ -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;

View File

@ -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);

BIN
bin/c3po Executable file

Binary file not shown.