lightningd: remove gratuitous param_tok from help and config.

They predate json_string!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-07-04 10:56:36 +09:30 committed by neil saitug
parent ec76ba3895
commit e621b8b24e
3 changed files with 23 additions and 28 deletions

View File

@ -354,11 +354,10 @@ static void json_add_help_command(struct command *cmd,
} }
static const struct json_command *find_command(struct json_command **commands, static const struct json_command *find_command(struct json_command **commands,
const char *buffer, const char *cmdname)
const jsmntok_t *cmdtok)
{ {
for (size_t i = 0; i < tal_count(commands); i++) { for (size_t i = 0; i < tal_count(commands); i++) {
if (json_tok_streq(buffer, cmdtok, commands[i]->name)) if (streq(cmdname, commands[i]->name))
return commands[i]; return commands[i];
} }
return NULL; return NULL;
@ -376,28 +375,26 @@ static struct command_result *json_help(struct command *cmd,
const jsmntok_t *params) const jsmntok_t *params)
{ {
struct json_stream *response; struct json_stream *response;
const jsmntok_t *cmdtok; const char *cmdname;
struct json_command **commands; struct json_command **commands;
const struct json_command *one_cmd; const struct json_command *one_cmd;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("command", param_tok, &cmdtok), p_opt("command", param_string, &cmdname),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
commands = cmd->ld->jsonrpc->commands; commands = cmd->ld->jsonrpc->commands;
if (cmdtok) { if (cmdname) {
one_cmd = find_command(commands, buffer, cmdtok); one_cmd = find_command(commands, cmdname);
if (!one_cmd) if (!one_cmd)
return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND, return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND,
"Unknown command '%.*s'", "Unknown command %s",
cmdtok->end - cmdtok->start, cmdname);
buffer + cmdtok->start);
if (!deprecated_apis && one_cmd->deprecated) if (!deprecated_apis && one_cmd->deprecated)
return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND, return command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND,
"Deprecated command '%.*s'", "Deprecated command %s",
json_tok_full_len(cmdtok), cmdname);
json_tok_full(buffer, cmdtok));
} else } else
one_cmd = NULL; one_cmd = NULL;

View File

@ -1672,14 +1672,14 @@ static struct command_result *json_listconfigs(struct command *cmd,
{ {
size_t i; size_t i;
struct json_stream *response = NULL; struct json_stream *response = NULL;
const jsmntok_t *configtok; const char *configname;
if (!param(cmd, buffer, params, if (!param(cmd, buffer, params,
p_opt("config", param_tok, &configtok), p_opt("config", param_string, &configname),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
if (!configtok) { if (!configname) {
response = json_stream_success(cmd); response = json_stream_success(cmd);
json_add_string(response, "# version", version()); json_add_string(response, "# version", version());
} }
@ -1699,9 +1699,8 @@ static struct command_result *json_listconfigs(struct command *cmd,
if (name[0] != '-') if (name[0] != '-')
continue; continue;
if (configtok if (configname
&& !memeq(buffer + configtok->start, && !memeq(configname, strlen(configname),
configtok->end - configtok->start,
name + 1, len - 1)) name + 1, len - 1))
continue; continue;
@ -1715,11 +1714,10 @@ static struct command_result *json_listconfigs(struct command *cmd,
} }
} }
if (configtok && !response) { if (configname && !response) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Unknown config option '%.*s'", "Unknown config option %s",
json_tok_full_len(configtok), configname);
json_tok_full(buffer, configtok));
} }
return command_success(cmd, response); return command_success(cmd, response);
} }

View File

@ -100,16 +100,16 @@ struct command_result *param_sha256(struct command *cmd UNNEEDED, const char *na
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct sha256 **hash UNNEEDED) struct sha256 **hash UNNEEDED)
{ fprintf(stderr, "param_sha256 called!\n"); abort(); } { fprintf(stderr, "param_sha256 called!\n"); abort(); }
/* Generated stub for param_string */
struct command_result *param_string(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char * buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const char **str UNNEEDED)
{ fprintf(stderr, "param_string called!\n"); abort(); }
/* Generated stub for param_subcommand */ /* Generated stub for param_subcommand */
const char *param_subcommand(struct command *cmd UNNEEDED, const char *buffer UNNEEDED, const char *param_subcommand(struct command *cmd UNNEEDED, const char *buffer UNNEEDED,
const jsmntok_t tokens[] UNNEEDED, const jsmntok_t tokens[] UNNEEDED,
const char *name UNNEEDED, ...) const char *name UNNEEDED, ...)
{ fprintf(stderr, "param_subcommand called!\n"); abort(); } { fprintf(stderr, "param_subcommand called!\n"); abort(); }
/* Generated stub for param_tok */
struct command_result *param_tok(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t * tok UNNEEDED,
const jsmntok_t **out UNNEEDED)
{ fprintf(stderr, "param_tok called!\n"); abort(); }
/* Generated stub for plugin_hook_call_ */ /* Generated stub for plugin_hook_call_ */
bool plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED, bool plugin_hook_call_(struct lightningd *ld UNNEEDED, const struct plugin_hook *hook UNNEEDED,
tal_t *cb_arg STEALS UNNEEDED) tal_t *cb_arg STEALS UNNEEDED)