diff options
author | Alessio Vanni <vannilla@firemail.cc> | 2021-04-04 16:51:09 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2021-04-05 18:15:14 +0200 |
commit | 45720bde1c56c414fec8a1c3d5775208c3b32139 (patch) | |
tree | 74dc74c8d1639c50901320b688bb3cae81d47266 /src/util/plugin.c | |
parent | 879cfdc43babb80a0c0618dfe3afa960fbed6e7d (diff) | |
download | gnunet-45720bde1c56c414fec8a1c3d5775208c3b32139.tar.gz gnunet-45720bde1c56c414fec8a1c3d5775208c3b32139.zip |
Implement function to load plugins within a specific context
When `GNUNET_OS_init' is called to change the application project data,
lazy-loading plugins will fail as it will not find the requested files.
The function will temporarily swap the project data with the argument value
and will search for plugins, within the installation directory tree inferred
from that structure.
Applications can still use `GNUNET_PLUGIN_load_all' to load their plugins from
within their own installation directory tree, though services are recommended
to use the `in_context' version to avoid falling in the same pit.
Signed-off-by: Martin Schanzenbach <mschanzenbach@posteo.de>
Diffstat (limited to 'src/util/plugin.c')
-rw-r--r-- | src/util/plugin.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/util/plugin.c b/src/util/plugin.c index d169bc911..feb661f24 100644 --- a/src/util/plugin.c +++ b/src/util/plugin.c | |||
@@ -388,6 +388,11 @@ find_libraries (void *cls, | |||
388 | * `basename_ANYTHING_init` and `basename_ANYTHING__done`. These will | 388 | * `basename_ANYTHING_init` and `basename_ANYTHING__done`. These will |
389 | * be called when the library is loaded and unloaded respectively. | 389 | * be called when the library is loaded and unloaded respectively. |
390 | * | 390 | * |
391 | * If you are writing a service to which third-party applications can connect, | ||
392 | * like GNUnet's own GNS service for example, you should use | ||
393 | * #GNUNET_PLUGIN_load_all_in_context instead of this function, passing your | ||
394 | * service's project data as context. | ||
395 | * | ||
391 | * @param basename basename of the plugins to load | 396 | * @param basename basename of the plugins to load |
392 | * @param arg argument to the plugin initialization function | 397 | * @param arg argument to the plugin initialization function |
393 | * @param cb function to call for each plugin found | 398 | * @param cb function to call for each plugin found |
@@ -420,4 +425,32 @@ GNUNET_PLUGIN_load_all (const char *basename, | |||
420 | } | 425 | } |
421 | 426 | ||
422 | 427 | ||
428 | /** | ||
429 | * Load all compatible plugins with the given base name while inside the given | ||
430 | * context (i.e. a specific project data structure.) | ||
431 | * | ||
432 | * Note that the library must export symbols called `basename_ANYTHING_init` | ||
433 | * and `basename_ANYTHING__done`. These will be called when the library is | ||
434 | * loaded and unloaded respectively. | ||
435 | * | ||
436 | * @param ctx the context used to find the plugins | ||
437 | * @param basename basename of the plugins to load | ||
438 | * @param arg argument to the plugin initialization function | ||
439 | * @param cb function to call for each plugin found | ||
440 | * @param cb_cls closure for @a cb | ||
441 | */ | ||
442 | void | ||
443 | GNUNET_PLUGIN_load_all_in_context (const struct GNUNET_OS_ProjectData *ctx, | ||
444 | const char *basename, | ||
445 | void *arg, | ||
446 | GNUNET_PLUGIN_LoaderCallback cb, | ||
447 | void *cb_cls) | ||
448 | { | ||
449 | const struct GNUNET_OS_ProjectData *cpd = GNUNET_OS_project_data_get (); | ||
450 | GNUNET_OS_init (ctx); | ||
451 | GNUNET_PLUGIN_load_all (basename, arg, cb, cb_cls); | ||
452 | GNUNET_OS_init (cpd); | ||
453 | } | ||
454 | |||
455 | |||
423 | /* end of plugin.c */ | 456 | /* end of plugin.c */ |