| 1436 | } |
| 1437 | |
| 1438 | static const char *plugin_subscriptions_add(struct plugin *plugin, |
| 1439 | const char *buffer, |
| 1440 | const jsmntok_t *resulttok) |
| 1441 | { |
| 1442 | size_t i; |
| 1443 | const jsmntok_t *s, *subscriptions = |
| 1444 | json_get_member(buffer, resulttok, "subscriptions"); |
| 1445 | |
| 1446 | if (!subscriptions) { |
| 1447 | plugin->subscriptions = NULL; |
| 1448 | return NULL; |
| 1449 | } |
| 1450 | plugin->subscriptions = tal_arr(plugin, struct plugin_subscription, 0); |
| 1451 | if (subscriptions->type != JSMN_ARRAY) { |
| 1452 | return tal_fmt(plugin, "\"result.subscriptions\" is not an array"); |
| 1453 | } |
| 1454 | |
| 1455 | json_for_each_arr(i, s, subscriptions) { |
| 1456 | struct plugin_subscription sub; |
| 1457 | if (s->type != JSMN_STRING) { |
| 1458 | return tal_fmt(plugin, |
| 1459 | "result.subscriptions[%zu] is not a string: '%.*s'", i, |
| 1460 | json_tok_full_len(s), |
| 1461 | json_tok_full(buffer, s)); |
| 1462 | } |
| 1463 | |
| 1464 | /* We add all subscriptions while parsing the |
| 1465 | * manifest, without checking that they exist, since |
| 1466 | * later plugins may also emit notifications of custom |
| 1467 | * types that we don't know about yet. */ |
| 1468 | sub.topic = json_strdup(plugin, buffer, s); |
| 1469 | sub.owner = plugin; |
| 1470 | tal_arr_expand(&plugin->subscriptions, sub); |
| 1471 | } |
| 1472 | |
| 1473 | /* Now they won't move with reallocation, we can add to htable */ |
| 1474 | for (i = 0; i < tal_count(plugin->subscriptions); i++) { |
| 1475 | plugin_subscription_htable_add(plugin->plugins->subscriptions, |
| 1476 | &plugin->subscriptions[i]); |
| 1477 | } |
| 1478 | |
| 1479 | return NULL; |
| 1480 | } |
| 1481 | |
| 1482 | static const char *plugin_hooks_add(struct plugin *plugin, const char *buffer, |
| 1483 | const jsmntok_t *resulttok) |
no test coverage detected