2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file peerinfo-tool/gnunet-peerinfo_plugins.c
23 * @brief plugin management
24 * @author Christian Grothoff
27 #include "gnunet-peerinfo_plugins.h"
28 #include "gnunet_transport_plugin.h"
29 #include "gnunet_hello_lib.h"
32 * Entry in doubly-linked list of all of our plugins.
34 struct TransportPlugin
37 * This is a doubly-linked list.
39 struct TransportPlugin *next;
42 * This is a doubly-linked list.
44 struct TransportPlugin *prev;
47 * API of the transport as returned by the plugin's
48 * initialization function.
50 struct GNUNET_TRANSPORT_PluginFunctions *api;
53 * Short name for the plugin (i.e. "tcp").
58 * Name of the library (i.e. "gnunet_plugin_transport_tcp").
63 * Environment this transport service is using
66 struct GNUNET_TRANSPORT_PluginEnvironment env;
71 * Head of DLL of all loaded plugins.
73 static struct TransportPlugin *plugins_head;
76 * Head of DLL of all loaded plugins.
78 static struct TransportPlugin *plugins_tail;
83 * Load and initialize all plugins. The respective functions will be
84 * invoked by the plugins when the respective events happen. The
85 * closure will be set to a 'const char*' containing the name of the
86 * plugin that caused the call.
88 * @param cfg configuration to use
91 GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
93 struct TransportPlugin *plug;
94 struct TransportPlugin *next;
99 if (NULL != plugins_head)
100 return; /* already loaded */
102 GNUNET_CONFIGURATION_get_value_string (cfg, "TRANSPORT", "PLUGINS",
105 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"),
107 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
109 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"),
111 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", pos);
112 plug = GNUNET_new (struct TransportPlugin);
113 plug->short_name = GNUNET_strdup (pos);
114 plug->lib_name = libname;
116 plug->env.cls = plug->short_name;
117 GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug);
125 plug->api = GNUNET_PLUGIN_load (plug->lib_name, &plug->env);
126 if (plug->api == NULL)
128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
129 _("Failed to load transport plugin for `%s'\n"),
131 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
132 GNUNET_free (plug->short_name);
133 GNUNET_free (plug->lib_name);
144 GPI_plugins_unload ()
146 struct TransportPlugin *plug;
148 while (NULL != (plug = plugins_head))
150 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
151 GNUNET_free (plug->lib_name);
152 GNUNET_free (plug->short_name);
153 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
160 * Obtain the plugin API based on a plugin name.
162 * @param name name of the plugin
163 * @return the plugin's API, NULL if the plugin is not loaded
165 struct GNUNET_TRANSPORT_PluginFunctions *
166 GPI_plugins_find (const char *name)
168 struct TransportPlugin *head = plugins_head;
170 char *stripped = GNUNET_strdup (name);
172 char *sep = strchr (stripped, '_');
178 head_stripped = GNUNET_strdup(head->short_name);
179 char *head_sep = strchr (head_stripped, '_');
180 if (NULL != head_sep)
182 if (0 == strcmp (head_stripped, stripped))
184 GNUNET_free (head_stripped);
187 GNUNET_free (head_stripped);
190 GNUNET_free (stripped);
197 /* end of file gnunet-peerinfo_plugins.c */