mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 13:25:43 +01:00
lightningd/plugin_hook: make it possible to unregister a hook
This adds 'plugin_unregister_hook' and 'plugin_unregister_hook_all' functions to unregister a given hook a plugin registered, or all hooks a plugin registered for. Since hooks can only be registered once, it's useful in the case a new plugin is added which would be prefered for hook registration over an already loaded plugin.
This commit is contained in:
parent
ce12a37a2b
commit
d299420fbe
@ -39,6 +39,32 @@ bool plugin_hook_register(struct plugin *plugin, const char *method)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool plugin_hook_unregister(struct plugin *plugin, const char *method)
|
||||||
|
{
|
||||||
|
struct plugin_hook *hook = plugin_hook_by_name(method);
|
||||||
|
if (!hook) {
|
||||||
|
/* No such hook name registered */
|
||||||
|
return false;
|
||||||
|
} else if (hook->plugin == NULL) {
|
||||||
|
/* This name is not registered */
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
hook->plugin = NULL;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void plugin_hook_unregister_all(struct plugin *plugin)
|
||||||
|
{
|
||||||
|
static struct plugin_hook **hooks = NULL;
|
||||||
|
static size_t num_hooks;
|
||||||
|
if (!hooks)
|
||||||
|
hooks = autodata_get(hooks, &num_hooks);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < num_hooks; i++)
|
||||||
|
if (hooks[i]->plugin == plugin)
|
||||||
|
hooks[i]->plugin = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback to be passed to the jsonrpc_request.
|
* Callback to be passed to the jsonrpc_request.
|
||||||
*
|
*
|
||||||
|
@ -102,6 +102,12 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
|
|||||||
|
|
||||||
bool plugin_hook_register(struct plugin *plugin, const char *method);
|
bool plugin_hook_register(struct plugin *plugin, const char *method);
|
||||||
|
|
||||||
|
/* Unregister a hook a plugin has registered for */
|
||||||
|
bool plugin_hook_unregister(struct plugin *plugin, const char *method);
|
||||||
|
|
||||||
|
/* Unregister all hooks a plugin has registered for */
|
||||||
|
void plugin_hook_unregister_all(struct plugin *plugin);
|
||||||
|
|
||||||
/* Special sync plugin hook for db: changes[] are SQL statements, with optional
|
/* Special sync plugin hook for db: changes[] are SQL statements, with optional
|
||||||
* final command appended. */
|
* final command appended. */
|
||||||
void plugin_hook_db_sync(struct db *db, const char **changes, const char *final);
|
void plugin_hook_db_sync(struct db *db, const char **changes, const char *final);
|
||||||
|
Loading…
Reference in New Issue
Block a user