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

Function rpc_read_response_one

plugins/libplugin.c:892–940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

890}
891
892static bool rpc_read_response_one(struct plugin *plugin)
893{
894 const jsmntok_t *jrtok;
895 bool complete;
896
897 if (!json_parse_input(&plugin->rpc_parser, &plugin->rpc_toks,
898 plugin->rpc_buffer + plugin->rpc_read_offset,
899 plugin->rpc_used - plugin->rpc_read_offset,
900 &complete)) {
901 plugin_err(plugin, "Failed to parse RPC JSON response '%.*s'",
902 (int)(plugin->rpc_used - plugin->rpc_read_offset),
903 plugin->rpc_buffer + plugin->rpc_read_offset);
904 }
905
906 if (!complete) {
907 /* We need more. */
908 goto compact;
909 }
910
911 /* Empty buffer? (eg. just whitespace). */
912 if (tal_count(plugin->rpc_toks) == 1) {
913 jsmn_init(&plugin->rpc_parser);
914 toks_reset(plugin->rpc_toks);
915 goto compact;
916 }
917
918 jrtok = json_get_member(plugin->rpc_buffer + plugin->rpc_read_offset,
919 plugin->rpc_toks, "jsonrpc");
920 if (!jrtok) {
921 plugin_err(plugin, "JSON-RPC message does not contain \"jsonrpc\" field: '%.*s'",
922 (int)(plugin->rpc_used - plugin->rpc_read_offset),
923 plugin->rpc_buffer + plugin->rpc_read_offset);
924 }
925
926 handle_rpc_reply(plugin, plugin->rpc_toks);
927
928 /* Move this object out of the buffer */
929 plugin->rpc_read_offset += plugin->rpc_toks[0].end;
930 jsmn_init(&plugin->rpc_parser);
931 toks_reset(plugin->rpc_toks);
932 return true;
933
934compact:
935 memmove(plugin->rpc_buffer, plugin->rpc_buffer + plugin->rpc_read_offset,
936 plugin->rpc_used - plugin->rpc_read_offset);
937 plugin->rpc_used -= plugin->rpc_read_offset;
938 plugin->rpc_read_offset = 0;
939 return false;
940}
941
942static struct io_plan *rpc_conn_read_response(struct io_conn *conn,
943 struct plugin *plugin)

Callers 1

rpc_conn_read_responseFunction · 0.85

Calls 5

handle_rpc_replyFunction · 0.85
plugin_errFunction · 0.70
json_parse_inputFunction · 0.50
toks_resetFunction · 0.50
json_get_memberFunction · 0.50

Tested by

no test coverage detected