Reads rpc reply and returns tokens, setting contents to 'error' or * 'result' (depending on *error). */
| 486 | /* Reads rpc reply and returns tokens, setting contents to 'error' or |
| 487 | * 'result' (depending on *error). */ |
| 488 | static const jsmntok_t *read_rpc_reply(const tal_t *ctx, |
| 489 | struct plugin *plugin, |
| 490 | const jsmntok_t **contents, |
| 491 | bool *error, |
| 492 | int *reqlen) |
| 493 | { |
| 494 | const jsmntok_t *toks; |
| 495 | |
| 496 | do { |
| 497 | *reqlen = read_json_from_rpc(plugin); |
| 498 | |
| 499 | toks = json_parse_simple(ctx, |
| 500 | membuf_elems(&plugin->rpc_conn->mb), |
| 501 | *reqlen); |
| 502 | if (!toks) |
| 503 | plugin_err(plugin, "Malformed JSON reply '%.*s'", |
| 504 | *reqlen, membuf_elems(&plugin->rpc_conn->mb)); |
| 505 | /* FIXME: Don't simply ignore notifications here! */ |
| 506 | } while (!json_get_member(membuf_elems(&plugin->rpc_conn->mb), toks, |
| 507 | "id")); |
| 508 | |
| 509 | *contents = json_get_member(membuf_elems(&plugin->rpc_conn->mb), toks, "error"); |
| 510 | if (*contents) |
| 511 | *error = true; |
| 512 | else { |
| 513 | *contents = json_get_member(membuf_elems(&plugin->rpc_conn->mb), toks, |
| 514 | "result"); |
| 515 | if (!*contents) |
| 516 | plugin_err(plugin, "JSON reply with no 'result' nor 'error'? '%.*s'", |
| 517 | *reqlen, membuf_elems(&plugin->rpc_conn->mb)); |
| 518 | *error = false; |
| 519 | } |
| 520 | return toks; |
| 521 | } |
| 522 | |
| 523 | /* Send request, return response, set resp/len to reponse */ |
| 524 | static const jsmntok_t *sync_req(const tal_t *ctx, |
no test coverage detected