MCPcopy Create free account
hub / github.com/ElementsProject/lightning / plugin_hook_register

Function plugin_hook_register

lightningd/plugin_hook.c:76–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76struct plugin_hook *plugin_hook_register(struct plugin *plugin, const char *method)
77{
78 struct hook_instance *h;
79 struct plugin_hook *hook = plugin_hook_by_name(method);
80 if (!hook) {
81 /* No such hook name registered */
82 return NULL;
83 }
84
85 /* Make sure the hook_elements array is initialized. */
86 if (hook->hooks == NULL)
87 hook->hooks = notleak(tal_arr(NULL, struct hook_instance *, 0));
88
89 /* Ensure we don't register the same plugin multple times. */
90 for (size_t i=0; i<tal_count(hook->hooks); i++)
91 if (hook->hooks[i]->plugin == plugin)
92 return NULL;
93
94 /* Ok, we're sure they can register and they aren't yet registered, so
95 * register them. */
96 h = tal(plugin, struct hook_instance);
97 h->plugin = plugin;
98 h->before = tal_arr(h, const char *, 0);
99 h->after = tal_arr(h, const char *, 0);
100 tal_add_destructor2(h, destroy_hook_instance, hook);
101
102 tal_arr_expand(&hook->hooks, h);
103 return hook;
104}
105
106/* Mutual recursion */
107static void plugin_hook_call_next(struct plugin_hook_request *ph_req);

Callers 1

plugin_hooks_addFunction · 0.85

Calls 1

plugin_hook_by_nameFunction · 0.85

Tested by

no test coverage detected