2 * OLSR ad-hoc routing table management protocol
3 * Copyright (C) 2004 Andreas Tønnesen (andreto@ifi.uio.no)
5 * This file is part of the olsr.org OLSR daemon.
7 * olsr.org is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * olsr.org is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with olsr.org; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * $Id: plugin_loader.c,v 1.7 2004/10/20 18:21:00 kattemat Exp $
26 #include "plugin_loader.h"
29 #include "scheduler.h"
31 #include "duplicate_set.h"
37 *Function that loads all registered plugins
39 *@return the number of plugins loaded
44 struct plugin_entry *entry;
47 entry = olsr_cnf->plugins;
50 olsr_printf(1, "Loading plugins...\n\n");
54 if(olsr_load_dl(entry->name) < 0)
55 olsr_printf(1, "-- PLUGIN LOADING FAILED! --\n\n");
57 loaded ++; /* I'm loaded! */
66 *Try to load a shared library and extract
67 *the required information
69 *@param libname the name of the library(file)
71 *@return negative on error
74 olsr_load_dl(char *libname)
76 struct olsr_plugin new_entry, *entry;
77 int *interface_version;
79 olsr_printf(1, "---------- Plugin loader ----------\nLibrary: %s\n", libname);
81 if((new_entry.dlhandle = dlopen(libname, RTLD_NOW)) == NULL)
83 olsr_printf(1, "DL loading failed: %s!\n", dlerror());
88 /* Fetch the multipurpose function */
89 olsr_printf(1, "Checking plugin interface version....");
90 /* Register mp function */
91 if((interface_version = dlsym(new_entry.dlhandle, "plugin_interface_version")) == NULL)
93 olsr_printf(1, "\nPlug-in interface version location failed!\n%s\n", dlerror());
94 dlclose(new_entry.dlhandle);
99 olsr_printf(1, " %d - ", *interface_version);
100 if(*interface_version != PLUGIN_INTERFACE_VERSION)
102 olsr_printf(1, "VERSION MISSMATCH!\n");
103 dlclose(new_entry.dlhandle);
107 olsr_printf(1, "OK\n");
111 /* Fetch the multipurpose function */
112 olsr_printf(1, "Trying to fetch plugin IO function....");
113 /* Register mp function */
114 if((new_entry.plugin_io = dlsym(new_entry.dlhandle, "plugin_io")) == NULL)
116 olsr_printf(1, "\nPlug-in IO function location %s failed!\n%s\n", libname, dlerror());
117 dlclose(new_entry.dlhandle);
120 olsr_printf(1, "OK\n");
123 olsr_printf(1, "Trying to fetch register function....");
125 if((new_entry.register_olsr_data = dlsym(new_entry.dlhandle, "register_olsr_data")) == NULL)
127 olsr_printf(1, "\nCould not find function registration function in plugin!\n", dlerror());
128 dlclose(new_entry.dlhandle);
131 olsr_printf(1, "OK\n");
133 entry = olsr_malloc(sizeof(struct olsr_plugin), "Plugin entry");
135 memcpy(entry, &new_entry, sizeof(struct olsr_plugin));
137 /* Initialize the plugin */
138 init_olsr_plugin(entry);
141 entry->next = olsr_plugins;
142 olsr_plugins = entry;
144 olsr_printf(1, "---------- LIBRARY LOADED ----------\n\n");
152 *Initialize a loaded plugin
153 *This includes sending information
154 *from olsrd to the plugin and
155 *register the functions from the flugin with olsrd
157 *@param entry the plugin to initialize
162 init_olsr_plugin(struct olsr_plugin *entry)
164 struct olsr_plugin_data plugin_data;
166 olsr_printf(1, "Running registration function...\n");
168 plugin_data.ipversion = olsr_cnf->ip_version;
169 plugin_data.main_addr = &main_addr;
171 plugin_data.olsr_plugin_io = &olsr_plugin_io;
173 /* Register data with plugin */
174 entry->register_olsr_data(&plugin_data);
181 *Close all loaded plugins
186 struct olsr_plugin *entry;
188 for(entry = olsr_plugins;
192 dlclose(entry->dlhandle);