| 97 | } |
| 98 | |
| 99 | static struct command_result *parse_by_position(struct command *cmd, |
| 100 | struct param *params, |
| 101 | const char *buffer, |
| 102 | const jsmntok_t tokens[], |
| 103 | bool allow_extra) |
| 104 | { |
| 105 | struct command_result *res; |
| 106 | const jsmntok_t *tok; |
| 107 | size_t i; |
| 108 | |
| 109 | json_for_each_arr(i, tok, tokens) { |
| 110 | /* check for unexpected trailing params */ |
| 111 | if (i == tal_count(params)) { |
| 112 | if (!allow_extra) { |
| 113 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 114 | "too many parameters:" |
| 115 | " got %u, expected %zu", |
| 116 | tokens->size, |
| 117 | tal_count(params)); |
| 118 | } |
| 119 | break; |
| 120 | } |
| 121 | |
| 122 | if (!json_tok_is_null(buffer, tok)) { |
| 123 | if (params[i].style == PARAM_OPTIONAL_DEV_WITH_DEFAULT |
| 124 | && !command_dev_apis(cmd)) { |
| 125 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 126 | "Parameter %zu is developer-only", i); |
| 127 | } |
| 128 | res = make_callback(cmd, params+i, buffer, tok); |
| 129 | if (res) |
| 130 | return res; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | return post_check(cmd, params); |
| 135 | } |
| 136 | |
| 137 | static struct param *find_param(struct command *cmd, |
| 138 | struct param *params, const char *start, |
no test coverage detected