| 688 | } |
| 689 | |
| 690 | static void replace_command(struct rpc_command_hook_payload *p, |
| 691 | const char *buffer, |
| 692 | const jsmntok_t *replacetok) |
| 693 | { |
| 694 | const jsmntok_t *method = NULL, *params = NULL, *jsonrpc; |
| 695 | const char *bad; |
| 696 | |
| 697 | /* Must contain "method", "params" and "id" */ |
| 698 | if (replacetok->type != JSMN_OBJECT) { |
| 699 | bad = "'replace' must be an object"; |
| 700 | goto fail; |
| 701 | } |
| 702 | |
| 703 | method = json_get_member(buffer, replacetok, "method"); |
| 704 | if (!method) { |
| 705 | bad = "missing 'method'"; |
| 706 | goto fail; |
| 707 | } |
| 708 | params = json_get_member(buffer, replacetok, "params"); |
| 709 | if (!params) { |
| 710 | bad = "missing 'params'"; |
| 711 | goto fail; |
| 712 | } |
| 713 | if (!json_get_member(buffer, replacetok, "id")) { |
| 714 | bad = "missing 'id'"; |
| 715 | goto fail; |
| 716 | } |
| 717 | |
| 718 | p->cmd->json_cmd = find_cmd(p->cmd->ld->jsonrpc, buffer, method); |
| 719 | if (!p->cmd->json_cmd) { |
| 720 | bad = tal_fmt(tmpctx, "redirected to unknown method '%.*s'", |
| 721 | method->end - method->start, |
| 722 | buffer + method->start); |
| 723 | goto fail; |
| 724 | } |
| 725 | |
| 726 | jsonrpc = json_get_member(buffer, replacetok, "jsonrpc"); |
| 727 | if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(buffer, jsonrpc, "2.0")) { |
| 728 | bad = "jsonrpc: \"2.0\" must be specified in the request"; |
| 729 | goto fail; |
| 730 | } |
| 731 | |
| 732 | was_pending(command_exec(p->cmd->jcon, p->cmd, buffer, replacetok, |
| 733 | params)); |
| 734 | return; |
| 735 | |
| 736 | fail: |
| 737 | was_pending(command_fail(p->cmd, JSONRPC2_INVALID_REQUEST, |
| 738 | "Bad response to 'rpc_command' hook: %s", bad)); |
| 739 | } |
| 740 | |
| 741 | static void rpc_command_hook_final(struct rpc_command_hook_payload *p STEALS) |
| 742 | { |
no test coverage detected