diff --git a/lightningd/plugin_hook.c b/lightningd/plugin_hook.c index 54e7098ee..bd620db70 100644 --- a/lightningd/plugin_hook.c +++ b/lightningd/plugin_hook.c @@ -39,6 +39,32 @@ bool plugin_hook_register(struct plugin *plugin, const char *method) 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. * diff --git a/lightningd/plugin_hook.h b/lightningd/plugin_hook.h index 76d9b6fea..4869d69e9 100644 --- a/lightningd/plugin_hook.h +++ b/lightningd/plugin_hook.h @@ -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); +/* 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 * final command appended. */ void plugin_hook_db_sync(struct db *db, const char **changes, const char *final);