GNUnet 0.21.0
Plugin library

Plugin loading and unloading. More...

Collaboration diagram for Plugin library:

Typedefs

typedef void *(* GNUNET_PLUGIN_Callback) (void *arg)
 Signature of any function exported by a plugin. More...
 
typedef void(* GNUNET_PLUGIN_LoaderCallback) (void *cls, const char *library_name, void *lib_ret)
 Signature of a function called by GNUNET_PLUGIN_load_all(). More...
 

Functions

enum GNUNET_GenericReturnValue GNUNET_PLUGIN_test (const char *library_name)
 Test if a plugin exists. More...
 
void * GNUNET_PLUGIN_load (const char *library_name, void *arg)
 Setup plugin (runs the "init" callback and returns whatever "init" returned). More...
 
void GNUNET_PLUGIN_load_all (const char *basename, void *arg, GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls)
 Load all compatible plugins with the given base name. More...
 
void GNUNET_PLUGIN_load_all_in_context (const struct GNUNET_OS_ProjectData *ctx, const char *basename, void *arg, GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls)
 Load all compatible plugins with the given base name while inside the given context (i.e. More...
 
void * GNUNET_PLUGIN_unload (const char *library_name, void *arg)
 Unload plugin (runs the "done" callback and returns whatever "done" returned). More...
 

Detailed Description

Plugin loading and unloading.

Typedef Documentation

◆ GNUNET_PLUGIN_Callback

typedef void *(* GNUNET_PLUGIN_Callback) (void *arg)

Signature of any function exported by a plugin.

Parameters
argargument to the function (context)
Returns
some pointer, NULL if the plugin was shutdown or if there was an error, otherwise the plugin's API on success

Definition at line 60 of file gnunet_plugin_lib.h.

◆ GNUNET_PLUGIN_LoaderCallback

typedef void(* GNUNET_PLUGIN_LoaderCallback) (void *cls, const char *library_name, void *lib_ret)

Signature of a function called by GNUNET_PLUGIN_load_all().

Parameters
clsclosure
library_namefull name of the library (to be used with GNUNET_PLUGIN_unload)
lib_retreturn value from the initialization function of the library (same as what GNUNET_PLUGIN_load would have returned for the given library name)

Definition at line 104 of file gnunet_plugin_lib.h.

Function Documentation

◆ GNUNET_PLUGIN_test()

enum GNUNET_GenericReturnValue GNUNET_PLUGIN_test ( const char *  library_name)

Test if a plugin exists.

Note that the library must export a symbol called "library_name_init" for the test to succeed.

Parameters
library_namename of the plugin to test if it is installed
Returns
GNUNET_YES if the plugin exists, GNUNET_NO if not

Definition at line 168 of file plugin.c.

169{
170 void *libhandle;
172 struct PluginList plug;
173
174 if (! initialized)
175 {
177 plugin_init ();
178 }
179 libhandle = lt_dlopenext (library_name);
180 if (NULL == libhandle)
181 return GNUNET_NO;
182 plug.handle = libhandle;
183 plug.name = (char *) library_name;
184 init = resolve_function (&plug,
185 "init");
186 if (NULL == init)
187 {
188 GNUNET_break (0);
189 lt_dlclose (libhandle);
190 return GNUNET_NO;
191 }
192 lt_dlclose (libhandle);
193 return GNUNET_YES;
194}
static char * init
Set to the name of a service to start.
Definition: gnunet-arm.c:74
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void *(* GNUNET_PLUGIN_Callback)(void *arg)
Signature of any function exported by a plugin.
static GNUNET_PLUGIN_Callback resolve_function(struct PluginList *plug, const char *name)
Lookup a function in the plugin.
Definition: plugin.c:141
static void plugin_init(void)
Setup libtool paths.
Definition: plugin.c:76
static int initialized
Have we been initialized?
Definition: plugin.c:59
Linked list of active plugins.
Definition: plugin.c:38

References GNUNET_break, GNUNET_NO, GNUNET_YES, PluginList::handle, init, initialized, PluginList::name, plugin_init(), and resolve_function().

Referenced by run().

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

◆ GNUNET_PLUGIN_load()

void * GNUNET_PLUGIN_load ( const char *  library_name,
void *  arg 
)

Setup plugin (runs the "init" callback and returns whatever "init" returned).

If "init" returns NULL, the plugin is unloaded.

Note that the library must export symbols called "library_name_init" and "library_name_done". These will be called when the library is loaded and unloaded respectively.

Parameters
library_namename of the plugin to load
argargument to the plugin initialization function
Returns
whatever the initialization function returned, NULL on error

Definition at line 198 of file plugin.c.

200{
201 void *libhandle;
202 struct PluginList *plug;
204 void *ret;
205
206 if (! initialized)
207 {
209 plugin_init ();
210 }
211 libhandle = lt_dlopenext (library_name);
212 if (NULL == libhandle)
213 {
215 _ ("`%s' failed for library `%s' with error: %s\n"),
216 "lt_dlopenext",
217 library_name,
218 lt_dlerror ());
219 return NULL;
220 }
221 plug = GNUNET_new (struct PluginList);
222 plug->handle = libhandle;
223 plug->name = GNUNET_strdup (library_name);
224 plug->next = plugins;
225 plugins = plug;
226 init = resolve_function (plug,
227 "init");
228 if ( (NULL == init) ||
229 (NULL == (ret = init (arg))) )
230 {
231 lt_dlclose (libhandle);
232 GNUNET_free (plug->name);
233 plugins = plug->next;
234 GNUNET_free (plug);
235 return NULL;
236 }
237 return ret;
238}
static int ret
Final status code.
Definition: gnunet-arm.c:94
@ GNUNET_ERROR_TYPE_ERROR
#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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static struct PluginList * plugins
List of plugins we have loaded.
Definition: plugin.c:69
#define LOG(kind,...)
Definition: plugin.c:32
char * name
Name of the library.
Definition: plugin.c:47
struct PluginList * next
This is a linked list.
Definition: plugin.c:42
void * handle
System handle.
Definition: plugin.c:52

References _, find_typedefs::arg, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_new, GNUNET_strdup, GNUNET_YES, PluginList::handle, init, initialized, LOG, PluginList::name, PluginList::next, plugin_init(), plugins, resolve_function(), and ret.

Referenced by client_connect_cb(), find_libraries(), GNUNET_DATACACHE_create(), load_plugin(), plugins_load(), run(), start_helper(), and tokenizer_cb().

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

◆ GNUNET_PLUGIN_load_all()

void GNUNET_PLUGIN_load_all ( const char *  basename,
void *  arg,
GNUNET_PLUGIN_LoaderCallback  cb,
void *  cb_cls 
)

Load all compatible plugins with the given base name.

Note that the library must export symbols called "basename_ANYTHING_init" and "basename_ANYTHING__done". These will be called when the library is loaded and unloaded respectively.

Parameters
basenamebasename of the plugins to load
argargument to the plugin initialization function
cbfunction to call for each plugin found
cb_clsclosure for cb

Definition at line 359 of file plugin.c.

363{
364 struct LoadAllContext lac;
365 char *path;
366
368 if (NULL == path)
369 {
371 _ ("Could not determine plugin installation path.\n"));
372 return;
373 }
374 lac.basename = basename;
375 lac.arg = arg;
376 lac.cb = cb;
377 lac.cb_cls = cb_cls;
380 &lac);
381 GNUNET_free (path);
382}
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
#define GNUNET_log(kind,...)
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
static int find_libraries(void *cls, const char *filename)
Function called on each plugin in the directory.
Definition: plugin.c:321
Closure for find_libraries().
Definition: plugin.c:288
const char * basename
Prefix the plugin names we find have to match.
Definition: plugin.c:292
void * cb_cls
Closure for cb.
Definition: plugin.c:307
GNUNET_PLUGIN_LoaderCallback cb
Function to call for each plugin.
Definition: plugin.c:302

References _, find_typedefs::arg, LoadAllContext::arg, LoadAllContext::basename, LoadAllContext::cb, LoadAllContext::cb_cls, find_libraries(), GNUNET_DISK_directory_scan(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_OS_installation_get_path(), and GNUNET_OS_IPK_LIBDIR.

Referenced by GNUNET_PLUGIN_load_all_in_context().

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

◆ GNUNET_PLUGIN_load_all_in_context()

void GNUNET_PLUGIN_load_all_in_context ( const struct GNUNET_OS_ProjectData ctx,
const char *  basename,
void *  arg,
GNUNET_PLUGIN_LoaderCallback  cb,
void *  cb_cls 
)

Load all compatible plugins with the given base name while inside the given context (i.e.

a specific project data structure.)

Note that the library must export symbols called basename_ANYTHING_init and basename_ANYTHING__done. These will be called when the library is loaded and unloaded respectively.

Parameters
ctxthe context used to find the plugins
basenamebasename of the plugins to load
argargument to the plugin initialization function
cbfunction to call for each plugin found
cb_clsclosure for cb

Definition at line 386 of file plugin.c.

391{
393
395 GNUNET_PLUGIN_load_all (basename,
396 arg,
397 cb,
398 cb_cls);
399 GNUNET_OS_init (cpd);
400}
static struct GNUNET_FS_Handle * ctx
void GNUNET_OS_init(const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem with project data.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
void GNUNET_PLUGIN_load_all(const char *basename, void *arg, GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls)
Load all compatible plugins with the given base name.
Definition: plugin.c:359
Project-specific data used to help the OS subsystem find installation paths.

References find_typedefs::arg, ctx, GNUNET_OS_init(), GNUNET_OS_project_data_get(), and GNUNET_PLUGIN_load_all().

Referenced by GNUNET_BLOCK_context_create(), and init().

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

◆ GNUNET_PLUGIN_unload()

void * GNUNET_PLUGIN_unload ( const char *  library_name,
void *  arg 
)

Unload plugin (runs the "done" callback and returns whatever "done" returned).

The plugin is then unloaded.

Parameters
library_namename of the plugin to unload
argargument to the plugin shutdown function
Returns
whatever the shutdown function returned, typically NULL or a "char *" representing the error message

Definition at line 242 of file plugin.c.

244{
245 struct PluginList *pos;
246 struct PluginList *prev;
248 void *ret;
249
250 prev = NULL;
251 pos = plugins;
252 while ( (NULL != pos) &&
253 (0 != strcmp (pos->name,
254 library_name)) )
255 {
256 prev = pos;
257 pos = pos->next;
258 }
259 if (NULL == pos)
260 return NULL;
261
262 done = resolve_function (pos,
263 "done");
264 ret = NULL;
265 if (NULL == prev)
266 plugins = pos->next;
267 else
268 prev->next = pos->next;
269 if (NULL != done)
270 ret = done (arg);
271 if (NULL == getenv ("VALGRINDING_PLUGINS"))
272 lt_dlclose (pos->handle);
273 GNUNET_free (pos->name);
274 GNUNET_free (pos);
275 if (NULL == plugins)
276 {
277 plugin_fini ();
279 }
280 return ret;
281}
char * getenv()
static void plugin_fini(void)
Shutdown libtool.
Definition: plugin.c:120

References find_typedefs::arg, getenv(), GNUNET_free, GNUNET_NO, PluginList::handle, initialized, PluginList::name, PluginList::next, plugin_fini(), plugins, resolve_function(), and ret.

Referenced by __attribute__(), cleanup_task(), client_disconnect_cb(), do_shutdown(), GNUNET_BLOCK_context_destroy(), GNUNET_DATACACHE_destroy(), run(), shutdown_task(), and unload_plugin().

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