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