mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
lightningd: add optional ->check callback to struct json_command.
If this is set, instead of mangling the request in-place, we will hand it through raw. Plugins will use this. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
cf72fb418e
commit
16615f4ed5
@ -1666,7 +1666,7 @@ void jsonrpc_request_end(struct jsonrpc_request *r)
|
|||||||
|
|
||||||
static struct command_result *json_check(struct command *cmd,
|
static struct command_result *json_check(struct command *cmd,
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
const jsmntok_t *obj UNNEEDED,
|
const jsmntok_t *obj,
|
||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
jsmntok_t *mod_params;
|
jsmntok_t *mod_params;
|
||||||
@ -1680,22 +1680,29 @@ static struct command_result *json_check(struct command *cmd,
|
|||||||
mod_params = json_tok_copy(cmd, params);
|
mod_params = json_tok_copy(cmd, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Replaces cmd->json_cmd: */
|
||||||
if (!param(cmd, buffer, mod_params,
|
if (!param(cmd, buffer, mod_params,
|
||||||
p_req("command_to_check", param_command, &name_tok),
|
p_req("command_to_check", param_command, &name_tok),
|
||||||
p_opt_any(),
|
p_opt_any(),
|
||||||
NULL))
|
NULL))
|
||||||
return command_param_failed();
|
return command_param_failed();
|
||||||
|
|
||||||
/* Point name_tok to the name, not the value */
|
|
||||||
if (params->type == JSMN_OBJECT)
|
|
||||||
name_tok--;
|
|
||||||
|
|
||||||
json_tok_remove(&mod_params, mod_params, name_tok, 1);
|
|
||||||
|
|
||||||
cmd->mode = CMD_CHECK;
|
cmd->mode = CMD_CHECK;
|
||||||
/* Make *sure* it doesn't try to manip db! */
|
/* Make *sure* it doesn't try to manip db! */
|
||||||
db_set_readonly(ld->wallet->db, true);
|
db_set_readonly(ld->wallet->db, true);
|
||||||
res = cmd->json_cmd->dispatch(cmd, buffer, mod_params, mod_params);
|
|
||||||
|
/* Raw check hook is needed for plugins */
|
||||||
|
if (cmd->json_cmd->check) {
|
||||||
|
res = cmd->json_cmd->check(cmd, buffer, obj, params);
|
||||||
|
} else {
|
||||||
|
/* Point name_tok to the name, not the value */
|
||||||
|
if (params->type == JSMN_OBJECT)
|
||||||
|
name_tok--;
|
||||||
|
|
||||||
|
json_tok_remove(&mod_params, mod_params, name_tok, 1);
|
||||||
|
|
||||||
|
res = cmd->json_cmd->dispatch(cmd, buffer, mod_params, mod_params);
|
||||||
|
}
|
||||||
db_set_readonly(ld->wallet->db, false);
|
db_set_readonly(ld->wallet->db, false);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -64,6 +64,11 @@ struct json_command {
|
|||||||
const char *verbose;
|
const char *verbose;
|
||||||
bool dev_only;
|
bool dev_only;
|
||||||
const char *depr_start, *depr_end;
|
const char *depr_start, *depr_end;
|
||||||
|
/* Special hook if we want raw access for check command */
|
||||||
|
struct command_result *(*check)(struct command *,
|
||||||
|
const char *buffer,
|
||||||
|
const jsmntok_t *obj,
|
||||||
|
const jsmntok_t *params);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct jsonrpc_notification {
|
struct jsonrpc_notification {
|
||||||
|
Loading…
Reference in New Issue
Block a user