2 This file is part of GNUnet.
3 Copyright (C) 2010,2011 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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 {
36 * This is a doubly-linked list.
38 struct TransportPlugin *next;
41 * This is a doubly-linked list.
43 struct TransportPlugin *prev;
46 * API of the transport as returned by the plugin's
47 * initialization function.
49 struct GNUNET_TRANSPORT_PluginFunctions *api;
52 * Short name for the plugin (i.e. "tcp").
57 * Name of the library (i.e. "gnunet_plugin_transport_tcp").
62 * Environment this transport service is using
65 struct GNUNET_TRANSPORT_PluginEnvironment env;
69 * Head of DLL of all loaded plugins.
71 static struct TransportPlugin *plugins_head;
74 * Head of DLL of all loaded plugins.
76 static struct TransportPlugin *plugins_tail;
81 * Load and initialize all plugins. The respective functions will be
82 * invoked by the plugins when the respective events happen. The
83 * closure will be set to a 'const char*' containing the name of the
84 * plugin that caused the call.
86 * @param cfg configuration to use
89 GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg)
91 struct TransportPlugin *plug;
92 struct TransportPlugin *next;
97 if (NULL != plugins_head)
98 return; /* already loaded */
100 GNUNET_CONFIGURATION_get_value_string(cfg, "TRANSPORT", "PLUGINS",
103 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"),
105 for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " "))
107 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"),
109 GNUNET_asprintf(&libname, "libgnunet_plugin_transport_%s", pos);
110 plug = GNUNET_new(struct TransportPlugin);
111 plug->short_name = GNUNET_strdup(pos);
112 plug->lib_name = libname;
114 plug->env.cls = plug->short_name;
115 GNUNET_CONTAINER_DLL_insert(plugins_head, plugins_tail, plug);
123 plug->api = GNUNET_PLUGIN_load(plug->lib_name, &plug->env);
124 if (plug->api == NULL)
126 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
127 _("Failed to load transport plugin for `%s'\n"),
129 GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug);
130 GNUNET_free(plug->short_name);
131 GNUNET_free(plug->lib_name);
144 struct TransportPlugin *plug;
146 while (NULL != (plug = plugins_head))
148 GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api));
149 GNUNET_free(plug->lib_name);
150 GNUNET_free(plug->short_name);
151 GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug);
158 * Obtain the plugin API based on a plugin name.
160 * @param name name of the plugin
161 * @return the plugin's API, NULL if the plugin is not loaded
163 struct GNUNET_TRANSPORT_PluginFunctions *
164 GPI_plugins_find(const char *name)
166 struct TransportPlugin *head = plugins_head;
168 char *stripped = GNUNET_strdup(name);
170 char *sep = strchr(stripped, '_');
177 head_stripped = GNUNET_strdup(head->short_name);
178 char *head_sep = strchr(head_stripped, '_');
179 if (NULL != head_sep)
181 if (0 == strcmp(head_stripped, stripped))
183 GNUNET_free(head_stripped);
186 GNUNET_free(head_stripped);
189 GNUNET_free(stripped);
196 /* end of file gnunet-peerinfo_plugins.c */