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

Function plugin_hook_register

lightningd/plugin_hook.c:139–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139const char *plugin_hook_register(struct plugin *plugin,
140 const char *method,
141 const char *buf, const jsmntok_t *filterstok,
142 struct plugin_hook **plugin_hook)
143{
144 struct hook_instance *h;
145 struct plugin_hook *hook;
146 const char *err;
147 const char **strfilters;
148 u64 *intfilters;
149
150 hook = plugin_hook_by_name(method);
151 if (!hook)
152 return tal_fmt(plugin, "Unknown hook name %s", method);
153
154 switch (hook->filter_type) {
155 case JSMN_UNDEFINED:
156 if (filterstok)
157 return tal_fmt(plugin, "Hook %s does not allow filters", method);
158 intfilters = NULL;
159 strfilters = NULL;
160 break;
161 case JSMN_PRIMITIVE:
162 strfilters = NULL;
163 err = parse_int_filters(plugin, buf, filterstok, &intfilters);
164 if (err)
165 return err;
166 break;
167 case JSMN_STRING:
168 intfilters = NULL;
169 err = parse_str_filters(plugin, buf, filterstok, &strfilters);
170 if (err)
171 return err;
172 break;
173
174 /* Nothing else is valid (yet?) */
175 default:
176 abort();
177 }
178
179 /* Make sure the hook_elements array is initialized. */
180 if (hook->hooks == NULL) {
181 hook->hooks = notleak(tal_arr(NULL, struct hook_instance *, 0));
182 hook->new_hooks = NULL;
183 hook->num_users = 0;
184 }
185
186 /* Ensure we don't register the same plugin multple times. */
187 for (size_t i=0; i<tal_count(hook->hooks); i++) {
188 if (!hook->hooks[i])
189 continue;
190 if (hook->hooks[i]->plugin == plugin)
191 return tal_fmt(plugin, "Registered for hook %s multiple times",
192 method);
193 }
194
195 /* Ok, we're sure they can register and they aren't yet registered, so
196 * register them. */

Callers 1

plugin_hooks_addFunction · 0.85

Calls 4

plugin_hook_by_nameFunction · 0.85
parse_int_filtersFunction · 0.85
parse_str_filtersFunction · 0.85
abortFunction · 0.85

Tested by

no test coverage detected