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