hlswmaster/src/plugin.c

105 lines
3.3 KiB
C
Raw Normal View History

2006-02-02 16:24:06 +01:00
/***************************************************************************
* Copyright (C) 03/2005 by Olaf Rempel *
* razzor@kopf-tisch.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <stdlib.h>
#include <dlfcn.h>
#include <pthread.h>
#include "hlswmaster.h"
#include "plugin.h"
#include "netpkt.h"
#include "list.h"
/* liste der geladenen plugins */
LIST_HEAD(plugin_list);
/* sichert die plugin list UND die plugins ab */
static pthread_mutex_t plugin_lock = PTHREAD_MUTEX_INITIALIZER;
int plugin_load(char *name) {
void *tmp;
if (!(tmp = dlopen(name, RTLD_NOW)))
log_print("unable to load plugin '%s'", name);
return 0;
}
int plugin_unload(char *name) {
return 0;
}
int plugins_scan(void) {
struct hlswmaster_plugin *plugin;
pthread_mutex_lock(&plugin_lock);
list_for_each_entry(plugin, &plugin_list, list)
if (plugin->scan && !plugin->scan())
log_print("plugin %s: scan error", plugin->name);
pthread_mutex_unlock(&plugin_lock);
return 1;
}
int plugins_parse(struct net_pkt *pkt) {
struct hlswmaster_plugin *plugin;
pthread_mutex_lock(&plugin_lock);
list_for_each_entry(plugin, &plugin_list, list) {
if (plugin->parse && plugin->parse(pkt)) {
pthread_mutex_unlock(&plugin_lock);
return 1;
}
}
pthread_mutex_unlock(&plugin_lock);
return 0;
}
int plugins_gc(unsigned long timeout) {
struct hlswmaster_plugin *plugin;
pthread_mutex_lock(&plugin_lock);
list_for_each_entry(plugin, &plugin_list, list)
if (plugin->gc)
plugin->gc(timeout);
pthread_mutex_unlock(&plugin_lock);
return 1;
}
/* called vom plugin:_init() after local init */
void register_plugin(struct hlswmaster_plugin *me) {
if (!me->init || (me->init(NULL))) {
pthread_mutex_lock(&plugin_lock);
list_add((struct list_head *)me, &plugin_list);
pthread_mutex_unlock(&plugin_lock);
}
}
/* called vom plugin:_fini() after local finish */
void unregister_plugin(struct hlswmaster_plugin *me) {
pthread_mutex_lock(&plugin_lock);
list_del((struct list_head *)me);
pthread_mutex_unlock(&plugin_lock);
if (me->fini)
me->fini();
}