2 ctrlproxy: A modular IRC proxy
3 (c) 2002-2004 Jelmer Vernooij <jelmer@nl.linux.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "internals.h"
26 struct plugin *current_plugin = NULL;
27 GList *plugins = NULL;
29 gboolean plugin_loaded(const char *name)
32 for (gl = plugins; gl; gl = gl->next) {
33 struct plugin *p = (struct plugin *)gl->data;
34 if (p && p->ops && p->ops->name && !strcmp(p->ops->name, name))
40 struct plugin *load_plugin(const char *modulesdir, const char *name)
43 struct plugin_ops *ops = NULL;
44 struct plugin *p = g_new0(struct plugin, 1);
45 gchar *path_name = NULL;
47 /* Try to load from .so file */
50 if (g_file_test(name, G_FILE_TEST_EXISTS))path_name = g_strdup(name);
51 else path_name = g_module_build_path(modulesdir, name);
53 m = g_module_open(path_name, 0);
56 log_global(LOG_ERROR, "Unable to open module %s(%s), ignoring", path_name, g_module_error());
62 if (!g_module_symbol(m, "plugin", (gpointer)&ops)) {
63 log_global(LOG_ERROR, "%s: No valid plugin information found",
64 strchr(path_name, '/')?(strrchr(path_name, '/')+1):"error"
72 if (plugin_loaded(ops->name)) {
73 log_global(LOG_WARNING, "%s: Plugin already loaded", ops->name);
84 if (!p->ops->init()) {
85 log_global( LOG_ERROR, "%s: Error during initialization.", p->ops->name);
90 plugins = g_list_append(plugins, p);
95 gboolean init_plugins(const char *plugin_dir)
99 if (!g_module_supported()) {
100 log_global(LOG_WARNING, "DSO's not supported on this platform. Not loading any plugins");
103 GDir *dir = g_dir_open(plugin_dir, 0, NULL);
105 log_global(LOG_WARNING, "Plugin dir does not exist, not loading plugins");
109 while ((name = g_dir_read_name(dir))) {
110 if (strcmp(name + strlen(name) - strlen(G_MODULE_SUFFIX), G_MODULE_SUFFIX) != 0)
113 if (!load_plugin(plugin_dir, name))
123 GList *get_plugin_list() {