MCPcopy Create free account
hub / github.com/ElementsProject/lightning / plugin_read_json_one

Function plugin_read_json_one

lightningd/plugin.c:600–708  ·  view source on GitHub ↗

* Try to parse a complete message from the plugin's buffer. * * Returns NULL if there was no error. * If it can parse a JSON message, sets *@complete, and returns any error * from the callback. * * If @destroyed was set, it means the plugin called plugin stop on itself. */

Source from the content-addressed store, hash-verified

598 * If @destroyed was set, it means the plugin called plugin stop on itself.
599 */
600static const char *plugin_read_json_one(struct plugin *plugin,
601 bool *complete,
602 bool *destroyed)
603{
604 const jsmntok_t *jrtok, *idtok;
605 struct plugin_destroyed *pd;
606 const char *err;
607
608 *destroyed = false;
609 /* Note that in the case of 'plugin stop' this can free request (since
610 * plugin is parent), so detect that case */
611
612 if (!json_parse_input(&plugin->parser, &plugin->toks,
613 plugin->buffer, plugin->used,
614 complete)) {
615 return tal_fmt(plugin,
616 "Failed to parse JSON response '%.*s'",
617 (int)plugin->used, plugin->buffer);
618 }
619
620 if (!*complete) {
621 /* We need more. */
622 return NULL;
623 }
624
625 /* Empty buffer? (eg. just whitespace). */
626 if (tal_count(plugin->toks) == 1) {
627 plugin->used = 0;
628 jsmn_init(&plugin->parser);
629 toks_reset(plugin->toks);
630 /* We need more. */
631 *complete = false;
632 return NULL;
633 }
634
635 if (plugin->toks->type != JSMN_OBJECT)
636 return tal_fmt(
637 plugin,
638 "JSON-RPC message is not a valid JSON object type");
639
640 jrtok = json_get_member(plugin->buffer, plugin->toks, "jsonrpc");
641 idtok = json_get_member(plugin->buffer, plugin->toks, "id");
642
643 if (!jrtok) {
644 return tal_fmt(
645 plugin,
646 "JSON-RPC message does not contain \"jsonrpc\" field");
647 }
648
649 pd = plugin_detect_destruction(plugin);
650 if (!idtok) {
651 /* A Notification is a Request object without an "id"
652 * member. A Request object that is a Notification
653 * signifies the Client's lack of interest in the
654 * corresponding Response object, and as such no
655 * Response object needs to be returned to the
656 * client. The Server MUST NOT reply to a
657 * Notification, including those that are within a

Callers 1

plugin_read_jsonFunction · 0.85

Calls 7

plugin_response_handleFunction · 0.85
was_plugin_destroyedFunction · 0.85
json_parse_inputFunction · 0.50
toks_resetFunction · 0.50
json_get_memberFunction · 0.50

Tested by

no test coverage detected