MCPcopy Create free account
hub / github.com/ElementsProject/lightning / parse_by_name

Function parse_by_name

common/json_param.c:158–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156}
157
158static struct command_result *parse_by_name(struct command *cmd,
159 struct param *params,
160 const char *buffer,
161 const jsmntok_t tokens[],
162 bool allow_extra)
163{
164 size_t i;
165 const jsmntok_t *t;
166
167 json_for_each_obj(i, t, tokens) {
168 struct param *p = find_param(cmd, params, buffer + t->start,
169 t->end - t->start);
170 if (!p) {
171 if (!allow_extra) {
172 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
173 "unknown parameter: %.*s, this may be caused by a failure to autodetect key=value-style parameters. Please try using the -k flag and explicit key=value pairs of parameters.",
174 t->end - t->start,
175 buffer + t->start);
176 }
177 } else {
178 struct command_result *res;
179
180 if (p->is_set) {
181 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
182 "duplicate json names: %s",
183 p->name);
184 }
185
186 if (p->style == PARAM_OPTIONAL_DEV_WITH_DEFAULT
187 && !command_dev_apis(cmd)) {
188 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
189 "Parameter '%s' is developer-only",
190 p->name);
191 }
192 res = make_callback(cmd, p, buffer, t + 1);
193 if (res)
194 return res;
195 }
196 }
197 return post_check(cmd, params);
198}
199
200static int comp_by_name(const struct param *a, const struct param *b,
201 void *unused)

Callers 1

param_arrFunction · 0.85

Calls 5

find_paramFunction · 0.85
make_callbackFunction · 0.85
post_checkFunction · 0.85
command_failFunction · 0.50
command_dev_apisFunction · 0.50

Tested by

no test coverage detected