GNUnet  0.10.x
Functions
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.

Functions

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

Author
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.

Parameters
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.

Parameters
cfgconfiguration to use

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

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, and TransportPlugin::short_name.

Referenced by state_machine().

92 {
93  struct TransportPlugin *plug;
94  struct TransportPlugin *next;
95  char *libname;
96  char *plugs;
97  char *pos;
98 
99  if (NULL != plugins_head)
100  return; /* already loaded */
101  if (GNUNET_OK !=
102  GNUNET_CONFIGURATION_get_value_string (cfg, "TRANSPORT", "PLUGINS",
103  &plugs))
104  return;
105  GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"),
106  plugs);
107  for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
108  {
109  GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"),
110  pos);
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;
115  plug->env.cfg = cfg;
116  plug->env.cls = plug->short_name;
118  }
119  GNUNET_free (plugs);
120  next = plugins_head;
121  while (next != NULL)
122  {
123  plug = next;
124  next = plug->next;
125  plug->api = GNUNET_PLUGIN_load (plug->lib_name, &plug->env);
126  if (plug->api == NULL)
127  {
129  _("Failed to load transport plugin for `%s'\n"),
130  plug->lib_name);
132  GNUNET_free (plug->short_name);
133  GNUNET_free (plug->lib_name);
134  GNUNET_free (plug);
135  }
136  }
137 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * short_name
Short name for the plugin (i.e.
#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.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct TransportPlugin * plugins_tail
Head of DLL of all loaded plugins.
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.
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
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's initialization function.
static struct TransportPlugin * plugins_head
Head of DLL of all loaded plugins.
#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:210
#define GNUNET_free(ptr)
Wrapper around free.
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 144 of file gnunet-peerinfo_plugins.c.

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

Referenced by shutdown_task().

145 {
146  struct TransportPlugin *plug;
147 
148  while (NULL != (plug = plugins_head))
149  {
150  GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
151  GNUNET_free (plug->lib_name);
152  GNUNET_free (plug->short_name);
154  GNUNET_free (plug);
155  }
156 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * short_name
Short name for the plugin (i.e.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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:258
char * lib_name
Name of the library (i.e.
Entry in doubly-linked list of all of our plugins.
struct GNUNET_TRANSPORT_PluginFunctions * api
API of the transport as returned by the plugin's initialization function.
static struct TransportPlugin * plugins_head
Head of DLL of all loaded plugins.
#define GNUNET_free(ptr)
Wrapper around free.
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.

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

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

References TransportPlugin::api, GNUNET_free, GNUNET_strdup, head, TransportPlugin::next, plugins_head, and TransportPlugin::short_name.

Referenced by parse_hello_uri(), and print_my_uri().

167 {
169 
170  char *stripped = GNUNET_strdup (name);
171  char *head_stripped;
172  char *sep = strchr (stripped, '_');
173  if (NULL != sep)
174  sep[0] = '\0';
175 
176  while (head != NULL)
177  {
178  head_stripped = GNUNET_strdup(head->short_name);
179  char *head_sep = strchr (head_stripped, '_');
180  if (NULL != head_sep)
181  head_sep[0] = '\0';
182  if (0 == strcmp (head_stripped, stripped))
183  {
184  GNUNET_free (head_stripped);
185  break;
186  }
187  GNUNET_free (head_stripped);
188  head = head->next;
189  }
190  GNUNET_free (stripped);
191  if (NULL == head)
192  return NULL;
193  return head->api;
194 }
char * short_name
Short name for the plugin (i.e.
struct TransportPlugin * next
This is a doubly-linked list.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
const char * name
Entry in doubly-linked list of all of our plugins.
struct GNUNET_TRANSPORT_PluginFunctions * api
API of the transport as returned by the plugin's initialization function.
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:231
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: