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

Function json_setconfig

lightningd/configs.c:653–819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 14

param_checkFunction · 0.85
json_get_memberFunction · 0.85
opt_names_arrFunction · 0.85
configvar_firstFunction · 0.85
config_not_writableFunction · 0.85
configvar_nextFunction · 0.85
grab_and_checkFunction · 0.85
is_plugin_optFunction · 0.85
plugin_set_dynamic_optFunction · 0.85
setconfig_successFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70

Tested by

no test coverage detected