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

Function ld_read_json_one

plugins/libplugin.c:1523–1560  ·  view source on GitHub ↗

* Try to parse a complete message from lightningd's buffer, and return true * if we could handle it. */

Source from the content-addressed store, hash-verified

1521 * if we could handle it.
1522 */
1523static bool ld_read_json_one(struct plugin *plugin)
1524{
1525 bool complete;
1526
1527 if (!json_parse_input(&plugin->parser, &plugin->toks,
1528 plugin->buffer, plugin->used,
1529 &complete)) {
1530 plugin_err(plugin, "Failed to parse JSON response '%.*s'",
1531 (int)plugin->used, plugin->buffer);
1532 return false;
1533 }
1534
1535 if (!complete) {
1536 /* We need more. */
1537 return false;
1538 }
1539
1540 /* Empty buffer? (eg. just whitespace). */
1541 if (tal_count(plugin->toks) == 1) {
1542 toks_reset(plugin->toks);
1543 jsmn_init(&plugin->parser);
1544 plugin->used = 0;
1545 return false;
1546 }
1547
1548 /* FIXME: Spark doesn't create proper jsonrpc 2.0! So we don't
1549 * check for "jsonrpc" here. */
1550 ld_command_handle(plugin, plugin->toks);
1551
1552 /* Move this object out of the buffer */
1553 memmove(plugin->buffer, plugin->buffer + plugin->toks[0].end,
1554 tal_count(plugin->buffer) - plugin->toks[0].end);
1555 plugin->used -= plugin->toks[0].end;
1556 toks_reset(plugin->toks);
1557 jsmn_init(&plugin->parser);
1558
1559 return true;
1560}
1561
1562static struct io_plan *ld_read_json(struct io_conn *conn,
1563 struct plugin *plugin)

Callers 1

ld_read_jsonFunction · 0.85

Calls 4

ld_command_handleFunction · 0.85
plugin_errFunction · 0.70
json_parse_inputFunction · 0.50
toks_resetFunction · 0.50

Tested by

no test coverage detected