| 650 | } |
| 651 | |
| 652 | static struct command_result *json_setconfig(struct command *cmd, |
| 653 | const char *buffer, |
| 654 | const jsmntok_t *obj UNNEEDED, |
| 655 | const jsmntok_t *params) |
| 656 | { |
| 657 | const struct opt_table *ot; |
| 658 | const char *val; |
| 659 | char *err; |
| 660 | void *arg; |
| 661 | bool *transient; |
| 662 | const jsmntok_t *valtok; |
| 663 | |
| 664 | if (!param_check(cmd, buffer, params, |
| 665 | p_req("config", param_opt_dynamic_config, &ot), |
| 666 | p_opt("val", param_string, &val), |
| 667 | p_opt_def("transient", param_bool, &transient, false), |
| 668 | NULL)) |
| 669 | return command_param_failed(); |
| 670 | |
| 671 | valtok = json_get_member(buffer, params, "val"); |
| 672 | |
| 673 | if (ot->type & OPT_MULTI) { |
| 674 | const char **vals; |
| 675 | const char **names; |
| 676 | const jsmntok_t *t; |
| 677 | size_t i; |
| 678 | |
| 679 | names = opt_names_arr(tmpctx, ot); |
| 680 | |
| 681 | if (valtok && valtok->type != JSMN_ARRAY) |
| 682 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 683 | "%s is a multi option: val must be an array", |
| 684 | ot->names + 2); |
| 685 | |
| 686 | if (valtok) { |
| 687 | vals = tal_arr(cmd, const char *, valtok->size); |
| 688 | json_for_each_arr(i, t, valtok) { |
| 689 | vals[i] = json_strdup(vals, buffer, t); |
| 690 | } |
| 691 | } else { |
| 692 | /* No val means empty array (clear all) */ |
| 693 | vals = tal_arr(cmd, const char *, 0); |
| 694 | } |
| 695 | |
| 696 | if (!*transient) { |
| 697 | const struct configvar *cv; |
| 698 | const char *fname; |
| 699 | |
| 700 | cv = configvar_first(cmd->ld->configvars, names); |
| 701 | |
| 702 | fname = config_not_writable(cmd, cmd, cv); |
| 703 | if (fname) |
| 704 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 705 | "Cannot write to config file %s", |
| 706 | fname); |
| 707 | |
| 708 | /* Check ALL existing config lines haven't changed */ |
| 709 | for (cv = configvar_first(cmd->ld->configvars, names); |
nothing calls this directly
no test coverage detected