| 890 | } |
| 891 | |
| 892 | static 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 | |
| 934 | compact: |
| 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 | |
| 942 | static struct io_plan *rpc_conn_read_response(struct io_conn *conn, |
| 943 | struct plugin *plugin) |
no test coverage detected