| 1468 | } |
| 1469 | |
| 1470 | static const char *plugin_hooks_add(struct plugin *plugin, const char *buffer, |
| 1471 | const jsmntok_t *resulttok) |
| 1472 | { |
| 1473 | const jsmntok_t *t, *hookstok, *beforetok, *aftertok, *filterstok; |
| 1474 | size_t i; |
| 1475 | |
| 1476 | hookstok = json_get_member(buffer, resulttok, "hooks"); |
| 1477 | if (!hookstok) |
| 1478 | return NULL; |
| 1479 | |
| 1480 | json_for_each_arr(i, t, hookstok) { |
| 1481 | char *name; |
| 1482 | struct plugin_hook *hook; |
| 1483 | const char *err; |
| 1484 | |
| 1485 | if (t->type == JSMN_OBJECT) { |
| 1486 | const jsmntok_t *nametok; |
| 1487 | |
| 1488 | nametok = json_get_member(buffer, t, "name"); |
| 1489 | if (!nametok) |
| 1490 | return tal_fmt(plugin, "no name in hook obj %.*s", |
| 1491 | json_tok_full_len(t), |
| 1492 | json_tok_full(buffer, t)); |
| 1493 | name = json_strdup(tmpctx, buffer, nametok); |
| 1494 | beforetok = json_get_member(buffer, t, "before"); |
| 1495 | aftertok = json_get_member(buffer, t, "after"); |
| 1496 | filterstok = json_get_member(buffer, t, "filters"); |
| 1497 | } else { |
| 1498 | /* Simple names also work */ |
| 1499 | name = json_strdup(tmpctx, buffer, t); |
| 1500 | beforetok = aftertok = filterstok = NULL; |
| 1501 | } |
| 1502 | |
| 1503 | err = plugin_hook_register(plugin, name, buffer, filterstok, &hook); |
| 1504 | if (err) |
| 1505 | return err; |
| 1506 | plugin_hook_add_deps(hook, plugin, buffer, beforetok, aftertok); |
| 1507 | tal_free(name); |
| 1508 | } |
| 1509 | return NULL; |
| 1510 | } |
| 1511 | |
| 1512 | static struct plugin_opt *plugin_opt_find(const struct plugin *plugin, |
| 1513 | const char *name) |
no test coverage detected