|
|
|
@ -2,6 +2,19 @@
|
|
|
|
|
#include "plugin.h"
|
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
|
|
static plugin* plugin_new(const gchar *name) {
|
|
|
|
|
plugin *p = g_slice_new0(plugin);
|
|
|
|
|
p->name = name;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void plugin_free(plugin *p) {
|
|
|
|
|
if (!p) return;
|
|
|
|
|
|
|
|
|
|
g_slice_free(plugin, p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static server_option* find_option(server *srv, const char *key) {
|
|
|
|
|
return (server_option*) g_hash_table_lookup(srv->options, key);
|
|
|
|
|
}
|
|
|
|
@ -65,3 +78,60 @@ void release_option(server *srv, option_set *mark) { /** Does not free the optio
|
|
|
|
|
}
|
|
|
|
|
mark->value = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean plugin_register(server *srv, const gchar *name, PluginInit init) {
|
|
|
|
|
plugin *p;
|
|
|
|
|
|
|
|
|
|
if (!init) {
|
|
|
|
|
ERROR(srv, "Module '%s' needs an init function", name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (g_hash_table_lookup(srv->plugins, name)) {
|
|
|
|
|
ERROR(srv, "Module '%s' already registered", name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = plugin_new(name);
|
|
|
|
|
g_hash_table_insert(srv->plugins, (gchar*) p->name, p);
|
|
|
|
|
|
|
|
|
|
init(srv, p);
|
|
|
|
|
|
|
|
|
|
if (p->options) {
|
|
|
|
|
size_t i;
|
|
|
|
|
server_option *so;
|
|
|
|
|
const plugin_option *po;
|
|
|
|
|
|
|
|
|
|
for (i = 0; (po = &p->options[i])->key; i++) {
|
|
|
|
|
if (NULL != (so = (server_option*)g_hash_table_lookup(srv->options, po->key))) {
|
|
|
|
|
ERROR(srv, "Option '%s' already registered by plugin '%s', unloading '%s'",
|
|
|
|
|
po->key,
|
|
|
|
|
so->p ? so->p->name : "<none>",
|
|
|
|
|
p->name);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
so = g_slice_new0(server_option);
|
|
|
|
|
so->type = po->type;
|
|
|
|
|
so->parse_option = po->parse_option;
|
|
|
|
|
so->free_option = po->free_option;
|
|
|
|
|
so->index = g_hash_table_size(srv->options);
|
|
|
|
|
so->module_index = i;
|
|
|
|
|
so->p = p;
|
|
|
|
|
g_hash_table_insert(srv->options, (gchar*) po->key, so);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (po->key) {
|
|
|
|
|
while (i-- > 0) {
|
|
|
|
|
po = &p->options[i];
|
|
|
|
|
g_slice_free(server_option, g_hash_table_lookup(srv->options, po->key));
|
|
|
|
|
g_hash_table_remove(srv->options, po->key);
|
|
|
|
|
}
|
|
|
|
|
g_hash_table_remove(srv->plugins, p->name);
|
|
|
|
|
if (p->free) p->free(srv, p);
|
|
|
|
|
plugin_free(p);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|