GNUnet  0.10.x
gnunet-peerinfo_plugins.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2010,2011 GNUnet e.V.
4 
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.
9 
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.
14 
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/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
26 #include "platform.h"
29 #include "gnunet_hello_lib.h"
30 
39 
44 
50 
54  char *short_name;
55 
59  char *lib_name;
60 
66 };
67 
72 
77 
78 
79 
88 void
90 {
91  struct TransportPlugin *plug;
92  struct TransportPlugin *next;
93  char *libname;
94  char *plugs;
95  char *pos;
96 
97  if (NULL != plugins_head)
98  return; /* already loaded */
99  if (GNUNET_OK !=
100  GNUNET_CONFIGURATION_get_value_string(cfg, "TRANSPORT", "PLUGINS",
101  &plugs))
102  return;
103  GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"),
104  plugs);
105  for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " "))
106  {
107  GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"),
108  pos);
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;
113  plug->env.cfg = cfg;
114  plug->env.cls = plug->short_name;
115  GNUNET_CONTAINER_DLL_insert(plugins_head, plugins_tail, plug);
116  }
117  GNUNET_free(plugs);
118  next = plugins_head;
119  while (next != NULL)
120  {
121  plug = next;
122  next = plug->next;
123  plug->api = GNUNET_PLUGIN_load(plug->lib_name, &plug->env);
124  if (plug->api == NULL)
125  {
127  _("Failed to load transport plugin for `%s'\n"),
128  plug->lib_name);
129  GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug);
130  GNUNET_free(plug->short_name);
131  GNUNET_free(plug->lib_name);
132  GNUNET_free(plug);
133  }
134  }
135 }
136 
137 
141 void
143 {
144  struct TransportPlugin *plug;
145 
146  while (NULL != (plug = plugins_head))
147  {
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);
152  GNUNET_free(plug);
153  }
154 }
155 
156 
164 GPI_plugins_find(const char *name)
165 {
167 
168  char *stripped = GNUNET_strdup(name);
169  char *head_stripped;
170  char *sep = strchr(stripped, '_');
171 
172  if (NULL != sep)
173  sep[0] = '\0';
174 
175  while (head != NULL)
176  {
177  head_stripped = GNUNET_strdup(head->short_name);
178  char *head_sep = strchr(head_stripped, '_');
179  if (NULL != head_sep)
180  head_sep[0] = '\0';
181  if (0 == strcmp(head_stripped, stripped))
182  {
183  GNUNET_free(head_stripped);
184  break;
185  }
186  GNUNET_free(head_stripped);
187  head = head->next;
188  }
189  GNUNET_free(stripped);
190  if (NULL == head)
191  return NULL;
192  return head->api;
193 }
194 
195 
196 /* end of file gnunet-peerinfo_plugins.c */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * short_name
Short name for the plugin (i.e.
struct TransportPlugin * prev
This is a doubly-linked list.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct TransportPlugin * next
This is a doubly-linked list.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct TransportPlugin * plugins_tail
Head of DLL of all loaded plugins.
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:255
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
void * cls
Closure for the various callbacks.
struct GNUNET_TRANSPORT_PluginEnvironment env
Environment this transport service is using for this plugin.
The transport service will pass a pointer to a struct of this type as the first and only argument to ...
plugin management API
void GPI_plugins_unload()
Unload all plugins.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
const char * name
char * lib_name
Name of the library (i.e.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Entry in doubly-linked list of all of our plugins.
struct GNUNET_TRANSPORT_PluginFunctions * api
API of the transport as returned by the plugin&#39;s initialization function.
configuration data
Definition: configuration.c:83
static struct TransportPlugin * plugins_head
Head of DLL of all loaded plugins.
static struct PendingResolutions * head
Head of list of pending resolution requests.
Definition: gnunet-ats.c:228
void GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg)
Load and initialize all plugins.
struct GNUNET_TRANSPORT_PluginFunctions * GPI_plugins_find(const char *name)
Obtain the plugin API based on a plugin name.
#define GNUNET_log(kind,...)
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:206
#define GNUNET_free(ptr)
Wrapper around free.