param: feedback fixes

Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
Mark Beckwith
2018-08-31 10:22:31 -05:00
committed by Rusty Russell
parent 4ad16b67f1
commit 721f77f528

View File

@@ -111,13 +111,11 @@ bool json_tok_bool(struct command *cmd, const char *name,
{ {
*b = tal(cmd, bool); *b = tal(cmd, bool);
if (tok->type == JSMN_PRIMITIVE) { if (tok->type == JSMN_PRIMITIVE) {
if (tok->end - tok->start == strlen("true") if (memeqstr(buffer + tok->start, tok->end - tok->start, "true")) {
&& memeqstr(buffer + tok->start, strlen("true"), "true")) {
**b = true; **b = true;
return true; return true;
} }
if (tok->end - tok->start == strlen("false") if (memeqstr(buffer + tok->start, tok->end - tok->start, "false")) {
&& memeqstr(buffer + tok->start, strlen("false"), "false")) {
**b = false; **b = false;
return true; return true;
} }
@@ -147,10 +145,11 @@ bool json_tok_escaped_string(struct command *cmd, const char *name,
const char **str) const char **str)
{ {
struct json_escaped *esc = json_to_escaped_string(cmd, buffer, tok); struct json_escaped *esc = json_to_escaped_string(cmd, buffer, tok);
if (esc) if (esc) {
if ((*str = json_escaped_unescape(cmd, esc))) *str = json_escaped_unescape(cmd, esc);
if (*str)
return true; return true;
}
command_fail(cmd, JSONRPC2_INVALID_PARAMS, command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a string, not '%.*s'" "'%s' should be a string, not '%.*s'"
" (note, we don't allow \\u)", " (note, we don't allow \\u)",
@@ -172,13 +171,9 @@ bool json_tok_label(struct command *cmd, const char *name,
const char * buffer, const jsmntok_t *tok, const char * buffer, const jsmntok_t *tok,
struct json_escaped **label) struct json_escaped **label)
{ {
if ((*label = json_to_escaped_string(cmd, buffer, tok))) /* We accept both strings and number literals here. */
return true; *label = json_escaped_string_(cmd, buffer + tok->start, tok->end - tok->start);
if (*label && (tok->type == JSMN_STRING || json_tok_is_num(buffer, tok)))
/* Allow literal numbers */
if (json_tok_is_num(buffer, tok) &&
((*label = json_escaped_string_(cmd, buffer + tok->start,
tok->end - tok->start))))
return true; return true;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, command_fail(cmd, JSONRPC2_INVALID_PARAMS,
@@ -244,7 +239,7 @@ bool json_tok_percent(struct command *cmd, const char *name,
{ {
*num = tal(cmd, double); *num = tal(cmd, double);
if (json_to_double(buffer, tok, *num)) if (json_to_double(buffer, tok, *num))
if (**num >= 0.0 && **num >= 100.0) if (**num >= 0.0 && **num <= 100.0)
return true; return true;
command_fail(cmd, JSONRPC2_INVALID_PARAMS, command_fail(cmd, JSONRPC2_INVALID_PARAMS,