| 269 | } |
| 270 | |
| 271 | static struct command_result *execute_command(struct command *cmd, |
| 272 | struct cond_info *cinfo) |
| 273 | { |
| 274 | struct out_req *req; |
| 275 | |
| 276 | /* We handle success and failure the same */ |
| 277 | req = jsonrpc_request_whole_object_start(cmd, |
| 278 | json_strdup(tmpctx, cinfo->buf, cinfo->method), |
| 279 | cinfo->cmdid_prefix, |
| 280 | cmd_done, cinfo->incoming); |
| 281 | if (cinfo->params) { |
| 282 | size_t i; |
| 283 | const jsmntok_t *t; |
| 284 | |
| 285 | /* FIXME: This is ugly! */ |
| 286 | if (cinfo->params->type == JSMN_OBJECT) { |
| 287 | json_object_start(req->js, "params"); |
| 288 | json_for_each_obj(i, t, cinfo->params) { |
| 289 | json_add_jsonstr(req->js, |
| 290 | json_strdup(tmpctx, cinfo->buf, t), |
| 291 | json_tok_full(cinfo->buf, t+1), |
| 292 | json_tok_full_len(t+1)); |
| 293 | } |
| 294 | json_object_end(req->js); |
| 295 | } else { |
| 296 | assert(cinfo->params->type == JSMN_ARRAY); |
| 297 | json_array_start(req->js, "params"); |
| 298 | json_for_each_arr(i, t, cinfo->params) { |
| 299 | json_add_jsonstr(req->js, |
| 300 | NULL, |
| 301 | json_tok_full(cinfo->buf, t), |
| 302 | json_tok_full_len(t)); |
| 303 | } |
| 304 | json_array_end(req->js); |
| 305 | } |
| 306 | } else { |
| 307 | json_object_start(req->js, "params"); |
| 308 | json_object_end(req->js); |
| 309 | } |
| 310 | |
| 311 | if (cinfo->filter) { |
| 312 | json_add_jsonstr(req->js, "filter", |
| 313 | json_tok_full(cinfo->buf, cinfo->filter), |
| 314 | json_tok_full_len(cinfo->filter)); |
| 315 | } |
| 316 | return send_outreq(req); |
| 317 | } |
| 318 | |
| 319 | static struct command_result *checkrune_done(struct command *cmd, |
| 320 | const char *method, |
no test coverage detected