From f2d0e93ce09780231c699b8ac90a403be6821282 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Sat, 28 Aug 2021 00:41:50 +0200 Subject: [PATCH] Added deprecated phase to rpc framework rules changes. Signed-off-by: Vincenzo Palazzo Changelog-Deprecated: RPC framwork now require the "jsonrpc" propriety inside the request. Changelog-Fixed: RPC framwork now required the "jsonrpc" propriety to be specified inside each request. --- lightningd/jsonrpc.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index 3a8c1cc91..a8103e008 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -700,7 +700,7 @@ static void replace_command(struct rpc_command_hook_payload *p, const char *buffer, const jsmntok_t *replacetok) { - const jsmntok_t *method = NULL, *params = NULL, *jsonrpc = NULL; + const jsmntok_t *method = NULL, *params = NULL; const char *bad; /* Must contain "method", "params" and "id" */ @@ -732,10 +732,14 @@ static void replace_command(struct rpc_command_hook_payload *p, goto fail; } - jsonrpc = json_get_member(buffer, replacetok, "jsonrpc"); - if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(buffer, jsonrpc, "2.0")) { - bad = "jsonrpc: \"2.0\" must be specified in the request"; - goto fail; + // deprecated phase to give the possibility to all to migrate and stay safe + // from this more restrictive change. + if (!deprecated_apis) { + const jsmntok_t *jsonrpc = json_get_member(buffer, replacetok, "jsonrpc"); + if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(buffer, jsonrpc, "2.0")) { + bad = "jsonrpc: \"2.0\" must be specified in the request"; + goto fail; + } } was_pending(command_exec(p->cmd->jcon, p->cmd, buffer, replacetok, @@ -870,7 +874,7 @@ REGISTER_PLUGIN_HOOK(rpc_command, static struct command_result * parse_request(struct json_connection *jcon, const jsmntok_t tok[]) { - const jsmntok_t *method, *id, *params, *jsonrpc; + const jsmntok_t *method, *id, *params; struct command *c; struct rpc_command_hook_payload *rpc_hook; bool completed; @@ -884,7 +888,6 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[]) method = json_get_member(jcon->buffer, tok, "method"); params = json_get_member(jcon->buffer, tok, "params"); id = json_get_member(jcon->buffer, tok, "id"); - jsonrpc = json_get_member(jcon->buffer, tok, "jsonrpc"); if (!id) { json_command_malformed(jcon, "null", "No id"); @@ -897,9 +900,15 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[]) return NULL; } - if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(jcon->buffer, jsonrpc, "2.0")) { - json_command_malformed(jcon, "null", "jsonrpc: \"2.0\" must be specified in the request"); - return NULL; + // Adding a deprecated phase to make sure that all the c-lightning wrapper + // can migrate all the frameworks + if (!deprecated_apis) { + const jsmntok_t *jsonrpc = json_get_member(jcon->buffer, tok, "jsonrpc"); + + if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(jcon->buffer, jsonrpc, "2.0")) { + json_command_malformed(jcon, "null", "jsonrpc: \"2.0\" must be specified in the request"); + return NULL; + } } /* Allocate the command off of the `jsonrpc` object and not