| 365 | } |
| 366 | |
| 367 | static struct command_result *try_command(struct command *cmd, |
| 368 | struct commando *incoming STEALS) |
| 369 | { |
| 370 | const jsmntok_t *toks, *method, *params, *runetok, *id, *filter; |
| 371 | const char *buf = (const char *)incoming->contents; |
| 372 | struct cond_info *cinfo; |
| 373 | struct rune *rune; |
| 374 | struct out_req *req; |
| 375 | |
| 376 | toks = json_parse_simple(incoming, buf, tal_bytelen(buf)); |
| 377 | if (!toks) { |
| 378 | return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE, |
| 379 | "Invalid JSON"); |
| 380 | } |
| 381 | |
| 382 | if (toks[0].type != JSMN_OBJECT) { |
| 383 | return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE, |
| 384 | "Not a JSON object"); |
| 385 | } |
| 386 | method = json_get_member(buf, toks, "method"); |
| 387 | if (!method) { |
| 388 | return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE, |
| 389 | "No method"); |
| 390 | } |
| 391 | params = json_get_member(buf, toks, "params"); |
| 392 | if (params && (params->type != JSMN_OBJECT && params->type != JSMN_ARRAY)) { |
| 393 | return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE, |
| 394 | "Params must be object or array"); |
| 395 | } |
| 396 | filter = json_get_member(buf, toks, "filter"); |
| 397 | id = json_get_member(buf, toks, "id"); |
| 398 | if (!id) { |
| 399 | return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE, |
| 400 | "missing id field"); |
| 401 | } |
| 402 | runetok = json_get_member(buf, toks, "rune"); |
| 403 | if (!runetok) { |
| 404 | return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE, |
| 405 | "Missing rune"); |
| 406 | } |
| 407 | rune = rune_from_base64n(tmpctx, buf + runetok->start, |
| 408 | runetok->end - runetok->start); |
| 409 | if (!rune) { |
| 410 | return commando_error(cmd, incoming, COMMANDO_ERROR_REMOTE, |
| 411 | "Invalid rune"); |
| 412 | } |
| 413 | /* Gather all the info we need to execute this command (steals toks). */ |
| 414 | cinfo = new_cond_info(incoming, incoming, toks, method, params, id, filter); |
| 415 | |
| 416 | /* Don't count this towards incomings anymore */ |
| 417 | destroy_commando(incoming, &incoming_commands); |
| 418 | tal_del_destructor2(incoming, destroy_commando, &incoming_commands); |
| 419 | |
| 420 | req = jsonrpc_request_start(cmd, "checkrune", |
| 421 | checkrune_done, checkrune_failed, |
| 422 | cinfo); |
| 423 | json_add_node_id(req->js, "nodeid", &incoming->peer); |
| 424 | json_add_tok(req->js, "rune", runetok, cinfo->buf); |
no test coverage detected