/*************************************************************************** * 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 #include #include #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; /** * plugin_load() * laedt ein plugin * * @param char *name * @return false on error * * TODO: pfadname als parameter (config-file?) * TODO: referenz speichern? wo? wie? */ int plugin_load(char *name) { void *tmp; if (!(tmp = dlopen(name, RTLD_NOW))) log_print("unable to load plugin '%s'", name); return 1; } /** * plugin_unload() * entfernt ein plugin * * @param char *name * @return false on error * * TODO: implementieren? oder lieber nicht? */ int plugin_unload(char *name) { return 1; } /** * plugins_scan() * ruft die scan() Funktionen der Plugins auf (wenn vorhanden) * * @return true */ 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; } /** * plugins_parse() * ruft die parse() Funktionen der Plugins auf (wenn vorhanden) * bis ein Plugin das Paket annimmt * * @param struct net_pkt *pkt * @return false wenn kein Plugin das Paket angenommen hat */ 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; } /** * plugins_gc() * ruft die gc() Funktionen der Plugins auf (wenn vorhanden) * * @param unsigned long timeout * @return true */ 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; } /** * register_plugin() * wird von den Plugins beim laden (durch _init())aufgerufen * * @param struct hlswmaster_plugin *me */ 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); } } /** * register_plugin() * wird von den Plugins beim entfernen (durch fini) aufgerufen * * @param struct hlswmaster_plugin *me */ 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(); }