GNUnet  0.20.0
gnunet-peerinfo_plugins.h File Reference

plugin management API More...

#include "gnunet_util_lib.h"
Include dependency graph for gnunet-peerinfo_plugins.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


void GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Load transport plugins. More...
void GPI_plugins_unload (void)
 Unload all plugins. More...
struct GNUNET_TRANSPORT_PluginFunctionsGPI_plugins_find (const char *name)
 Obtain the plugin API based on a plugin name. More...

Detailed Description

plugin management API

Christian Grothoff

Definition in file gnunet-peerinfo_plugins.h.

Function Documentation

◆ GPI_plugins_load()

void GPI_plugins_load ( const struct GNUNET_CONFIGURATION_Handle cfg)

Load transport plugins.

cfgconfiguration to use

Load transport plugins.

The respective functions will be invoked by the plugins when the respective events happen. The closure will be set to a 'const char*' containing the name of the plugin that caused the call.

cfgconfiguration to use

Definition at line 89 of file gnunet-peerinfo_plugins.c.

90 {
91  struct TransportPlugin *plug;
92  struct TransportPlugin *next;
93  char *libname;
94  char *plugs;
95  char *pos;
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;
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);
130  GNUNET_free (plug->short_name);
131  GNUNET_free (plug->lib_name);
132  GNUNET_free (plug);
133  }
134  }
135 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct TransportPlugin * plugins_head
Head of DLL of all loaded plugins.
static struct TransportPlugin * plugins_tail
Head of DLL of all loaded plugins.
enum GNUNET_GenericReturnValue 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.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log(kind,...)
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:198
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
void * cls
Closure for the various callbacks.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Entry in doubly-linked list of all of our plugins.
struct TransportPlugin * next
This is a doubly-linked list.
struct GNUNET_TRANSPORT_PluginEnvironment env
Environment this transport service is using for this plugin.
char * short_name
Short name for the plugin (e.g.
char * lib_name
Name of the library (e.g.
struct GNUNET_TRANSPORT_PluginFunctions * api
API of the transport as returned by the plugin's initialization function.

References _, TransportPlugin::api, cfg, GNUNET_TRANSPORT_PluginEnvironment::cfg, GNUNET_TRANSPORT_PluginEnvironment::cls, TransportPlugin::env, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_PLUGIN_load(), GNUNET_strdup, TransportPlugin::lib_name, TransportPlugin::next, plugins_head, plugins_tail, and TransportPlugin::short_name.

Referenced by libgnunet_plugin_dhtu_gnunet_init(), and state_machine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GPI_plugins_unload()

void GPI_plugins_unload ( void  )

Unload all plugins.

Definition at line 142 of file gnunet-peerinfo_plugins.c.

143 {
144  struct TransportPlugin *plug;
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);
152  GNUNET_free (plug);
153  }
154 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:242

References TransportPlugin::api, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_PLUGIN_unload(), TransportPlugin::lib_name, plugins_head, plugins_tail, and TransportPlugin::short_name.

Referenced by libgnunet_plugin_dhtu_gnunet_done(), and shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GPI_plugins_find()

struct GNUNET_TRANSPORT_PluginFunctions* GPI_plugins_find ( const char *  name)

Obtain the plugin API based on a plugin name.

namename of the plugin
the plugin's API, NULL if the plugin is not loaded

Definition at line 164 of file gnunet-peerinfo_plugins.c.

165 {
168  char *stripped = GNUNET_strdup (name);
169  char *head_stripped;
170  char *sep = strchr (stripped, '_');
172  if (NULL != sep)
173  sep[0] = '\0';
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 }
static struct PendingResolutions * head
Head of list of pending resolution requests.
Definition: gnunet-ats.c:230
const char * name
struct PendingResolutions * next
Kept in a DLL.
Definition: gnunet-ats.c:159

References GNUNET_free, GNUNET_strdup, head, name, PendingResolutions::next, and plugins_head.

Referenced by gnunet_try_connect(), parse_hello_uri(), peerinfo_cb(), and print_my_uri().

Here is the caller graph for this function: