[Add] Plugin crawler.
This commit is contained in:
parent
2acf288ceb
commit
170f543b5c
@ -1,9 +1,11 @@
|
|||||||
default:
|
default:
|
||||||
cd c3po && make
|
cd c3po && make
|
||||||
|
cd config && make
|
||||||
cd network_plain && make
|
cd network_plain && make
|
||||||
cd network_ssl && make
|
cd network_ssl && make
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
cd c3po && make clean
|
cd c3po && make clean
|
||||||
|
cd config && make clean
|
||||||
cd network_plain && make clean
|
cd network_plain && make clean
|
||||||
cd network_ssl && make clean
|
cd network_ssl && make clean
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
SRC = config.c plugin.c
|
||||||
|
CFLAGS += -fPIC -shared -Wl,-soname,config.so -O3
|
||||||
|
LDFLAGS += -ldl
|
||||||
|
|
||||||
|
default:
|
||||||
|
$(CC) $(CFLAGS) $(SRC) -o ../../bin/base/config.so $(LDFLAGS)
|
||||||
|
|
||||||
|
clean:
|
@ -1,14 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define PLUGIN_TYPE_NETWORK 0x1
|
#define PLUGIN_TYPE_NETWORK 0x1
|
||||||
|
#define PLUGIN_TYPE_FILTER 0x2
|
||||||
void configErrorPush(const char* err);
|
void configErrorPush(const char* err);
|
||||||
|
|
||||||
/* This is the common API for plugins. */
|
/* This is the common API for plugins. */
|
||||||
unsigned int pluginType();
|
unsigned int pluginType();
|
||||||
const char* pluginName();
|
const char* pluginName();
|
||||||
|
|
||||||
#if 0
|
|
||||||
#ifndef __NETWORK_H__
|
#ifndef __NETWORK_H__
|
||||||
/* This one's for network plugins. */
|
/* This one's for network plugins. */
|
||||||
void* pluginConnect(const char* host, int port);
|
void* pluginConnect(const char* host, int port);
|
||||||
@ -17,4 +16,3 @@ const char* pluginName();
|
|||||||
int pluginSendData(void* connection, const char* buffer, int buffer_len);
|
int pluginSendData(void* connection, const char* buffer, int buffer_len);
|
||||||
void* pluginSocketDone(void* connection);
|
void* pluginSocketDone(void* connection);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
@ -5,4 +5,6 @@ void* init() {
|
|||||||
fprintf(stderr, "[CONFIG] First malloc failed. Let's just give up :D\n");
|
fprintf(stderr, "[CONFIG] First malloc failed. Let's just give up :D\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "api.h"
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
#include <dirent.h>
|
|
||||||
PLUGIN plugin;
|
PLUGIN plugin;
|
||||||
} CONFIG;
|
} CONFIG;
|
||||||
|
|
||||||
|
@ -6,6 +6,116 @@ void pluginInit() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pluginAddNetwork(void* lib_handle, const char* name) {
|
||||||
|
struct PLUGIN_NETWORK_ENTRY* plugin;
|
||||||
|
|
||||||
|
if((plugin = malloc(sizeof(struct PLUGIN_NETWORK_ENTRY))) == NULL) {
|
||||||
|
dlclose(lib_handle);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin->lib_handle = lib_handle;
|
||||||
|
plugin->name = name;
|
||||||
|
plugin->connect = dlsym(lib_handle, "pluginConnect");
|
||||||
|
plugin->socket = dlsym(lib_handle, "pluginSocketGet");
|
||||||
|
plugin->read = dlsym(lib_handle, "pluginReadData");
|
||||||
|
plugin->write = dlsym(lib_handle, "pluginSendData");
|
||||||
|
plugin->disconnect = dlsym(lib_handle, "pluginSocketDone");
|
||||||
|
|
||||||
|
if(!plugin->connect || !plugin->socket || !plugin->read ||
|
||||||
|
!plugin->write || !plugin->disconnect) {
|
||||||
|
dlclose(lib_handle);
|
||||||
|
free(plugin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin->next = config->plugin.network_plug;
|
||||||
|
config->plugin.network_plug = plugin;
|
||||||
|
|
||||||
|
fprintf(stderr, "Debug: Network plugin %s added\n", name);
|
||||||
|
|
||||||
|
/* This should be good right? */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pluginAddFilter(void* lib_handle, const char* name) {
|
||||||
|
struct PLUGIN_FILTER_ENTRY* plugin;
|
||||||
|
int(*trig_type)();
|
||||||
|
|
||||||
|
if((trig_type = dlsym(lib_handle, "pluginFilterType")) == NULL) {
|
||||||
|
dlclose(lib_handle);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((plugin = malloc(sizeof(struct PLUGIN_NETWORK_ENTRY))) == NULL) {
|
||||||
|
dlclose(lib_handle);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin->lib_handle = lib_handle;
|
||||||
|
plugin->name = name;
|
||||||
|
plugin->trig_type = (trig_type)();
|
||||||
|
|
||||||
|
plugin->init = dlsym(lib_handle, "pluginDoInit");
|
||||||
|
plugin->filter = dlsym(lib_handle, "pluginFilter");
|
||||||
|
plugin->destroy = dlsym(lib_handle, "pluginDestroy");
|
||||||
|
|
||||||
|
if(!plugin->init || !plugin->filter || !plugin->destroy) {
|
||||||
|
dlclose(lib_handle);
|
||||||
|
free(plugin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin->next = config->plugin.filter_plug;
|
||||||
|
config->plugin.filter_plug = plugin;
|
||||||
|
|
||||||
|
fprintf(stderr, "Debug: Filter plugin %s added\n", name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pluginProcess(const char* path, const char* name) {
|
||||||
|
void* lib_handle;
|
||||||
|
char fname[512], *longname, *usename;
|
||||||
|
unsigned int (*pluginType)();
|
||||||
|
const char* (*pluginName)();
|
||||||
|
|
||||||
|
longname = NULL;
|
||||||
|
if(strlen(path) + strlen(name) + 2 > 512) {
|
||||||
|
longname = malloc(strlen(path) + strlen(name) + 2);
|
||||||
|
usename = longname;
|
||||||
|
} else
|
||||||
|
usename = fname;
|
||||||
|
|
||||||
|
sprintf(usename, "%s/%s", path,name);
|
||||||
|
if((lib_handle = dlopen(usename, RTLD_LOCAL | RTLD_NOW)) == NULL) {
|
||||||
|
/* It's not a plugin. Ignore. */
|
||||||
|
free(longname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(longname);
|
||||||
|
pluginType = dlsym(lib_handle, "pluginType");
|
||||||
|
pluginName = dlsym(lib_handle, "pluginName");
|
||||||
|
|
||||||
|
if(pluginType == NULL || pluginName == NULL) {
|
||||||
|
dlclose(lib_handle);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch((pluginType)()) {
|
||||||
|
case PLUGIN_TYPE_NETWORK:
|
||||||
|
pluginAddNetwork(lib_handle, (pluginName)());
|
||||||
|
break;
|
||||||
|
case PLUGIN_TYPE_FILTER:
|
||||||
|
pluginAddFilter(lib_handle, (pluginName)());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dlclose(lib_handle);
|
||||||
|
fprintf(stderr, "[CONFIG] %s/%s is of type not implemented\n", path, name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void pluginCrawl(const char* path) {
|
void pluginCrawl(const char* path) {
|
||||||
DIR* dir;
|
DIR* dir;
|
||||||
struct dirent* file;
|
struct dirent* file;
|
||||||
|
@ -12,16 +12,17 @@ struct PLUGIN_NETWORK_ENTRY {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct PLUGIN_FILTER_ENTRY {
|
struct PLUGIN_FILTER_ENTRY {
|
||||||
void* lib_handle;
|
void* lib_handle;
|
||||||
const char* name;
|
const char* name;
|
||||||
int trig_type;
|
int trig_type;
|
||||||
void *(*init)();
|
void *(*init)();
|
||||||
void (*filter)(void* handle, const char* from, const char* host,
|
void (*filter)(void* handle, const char* from, const char* host,
|
||||||
const char* channel, const char* message);
|
const char* channel, const char* message);
|
||||||
void *(*destroy)(void* handle);
|
void *(*destroy)(void* handle);
|
||||||
|
struct PLUGIN_FILTER_ENTRY* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct PLUGIN_NETWORK_ENTRY* network_plugin;
|
struct PLUGIN_NETWORK_ENTRY* network_plug;
|
||||||
struct PLUGIN_FILTER_ENTRY* filter_plug;
|
struct PLUGIN_FILTER_ENTRY* filter_plug;
|
||||||
} PLUGIN;
|
} PLUGIN;
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user