| 583 | WARN_UNUSED_RESULT; |
| 584 | |
| 585 | static const char *plugin_notification_handle(struct plugin *plugin, |
| 586 | const char *buffer, |
| 587 | const jsmntok_t *toks) |
| 588 | { |
| 589 | const jsmntok_t *methtok, *paramstok; |
| 590 | const char *methname; |
| 591 | struct jsonrpc_notification *n; |
| 592 | methtok = json_get_member(buffer, toks, "method"); |
| 593 | paramstok = json_get_member(buffer, toks, "params"); |
| 594 | |
| 595 | if (!methtok || !paramstok) { |
| 596 | return tal_fmt(plugin, |
| 597 | "Malformed JSON-RPC notification missing " |
| 598 | "\"method\" or \"params\": %.*s", |
| 599 | toks->end - toks->start, |
| 600 | buffer + toks->start); |
| 601 | } |
| 602 | |
| 603 | /* Dispatch incoming notifications. This is currently limited |
| 604 | * to just a few method types, should this ever become |
| 605 | * unwieldy we can switch to the AUTODATA construction to |
| 606 | * register notification handlers in a variety of places. */ |
| 607 | if (json_tok_streq(buffer, methtok, "log")) { |
| 608 | return plugin_log_handle(plugin, buffer, paramstok); |
| 609 | } else if (json_tok_streq(buffer, methtok, "message") |
| 610 | || json_tok_streq(buffer, methtok, "progress")) { |
| 611 | return plugin_notify_handle(plugin, buffer, methtok, paramstok); |
| 612 | } |
| 613 | |
| 614 | methname = json_strdup(tmpctx, buffer, methtok); |
| 615 | |
| 616 | if (!plugin_notification_allowed(plugin, methname)) { |
| 617 | log_unusual(plugin->log, |
| 618 | "Plugin attempted to send a notification to topic " |
| 619 | "\"%s\" it hasn't declared in its manifest, not " |
| 620 | "forwarding to subscribers.", |
| 621 | methname); |
| 622 | } else if (notifications_have_topic(plugin->plugins, methname)) { |
| 623 | n = jsonrpc_notification_start_noparams(NULL, methname); |
| 624 | json_add_string(n->stream, "origin", plugin->shortname); |
| 625 | json_add_tok(n->stream, "params", paramstok, buffer); |
| 626 | jsonrpc_notification_end_noparams(n); |
| 627 | |
| 628 | plugins_notify(plugin->plugins, take(n)); |
| 629 | } |
| 630 | return NULL; |
| 631 | } |
| 632 | |
| 633 | struct plugin_destroyed { |
| 634 | const struct plugin *plugin; |
no test coverage detected