| 2305 | } |
| 2306 | |
| 2307 | struct command_result *plugin_set_dynamic_opt(struct command *cmd, |
| 2308 | const struct opt_table *ot, |
| 2309 | const char **vals, |
| 2310 | size_t nvals, |
| 2311 | bool transient, |
| 2312 | struct command_result *(*success) |
| 2313 | (struct command *, |
| 2314 | const struct opt_table *, |
| 2315 | const char **, |
| 2316 | size_t, |
| 2317 | bool)) |
| 2318 | { |
| 2319 | struct plugin_opt *popt; |
| 2320 | struct plugin *plugin; |
| 2321 | struct jsonrpc_request *req; |
| 2322 | struct plugin_set_return *psr; |
| 2323 | |
| 2324 | plugin = plugin_opt_find_any(cmd->ld->plugins, ot, &popt); |
| 2325 | assert(plugin); |
| 2326 | |
| 2327 | assert(ot->type & OPT_DYNAMIC); |
| 2328 | |
| 2329 | psr = tal(cmd, struct plugin_set_return); |
| 2330 | psr->cmd = cmd; |
| 2331 | /* vals is a child of cmd, so no copy needed. */ |
| 2332 | psr->vals = vals; |
| 2333 | psr->nvals = nvals; |
| 2334 | psr->optname = tal_strdup(psr, ot->names + 2); |
| 2335 | psr->success = success; |
| 2336 | psr->transient = transient; |
| 2337 | |
| 2338 | if (command_check_only(cmd)) { |
| 2339 | /* If plugin doesn't support check, we can't check */ |
| 2340 | if (!plugin->can_check) |
| 2341 | return command_check_done(cmd); |
| 2342 | req = jsonrpc_request_start(cmd, "check", |
| 2343 | cmd->id, |
| 2344 | command_logger(cmd), |
| 2345 | NULL, plugin_setconfig_done, |
| 2346 | psr); |
| 2347 | json_add_string(req->stream, "command_to_check", "setconfig"); |
| 2348 | } else { |
| 2349 | req = jsonrpc_request_start(cmd, "setconfig", |
| 2350 | cmd->id, |
| 2351 | command_logger(cmd), |
| 2352 | NULL, plugin_setconfig_done, |
| 2353 | psr); |
| 2354 | } |
| 2355 | json_add_string(req->stream, "config", psr->optname); |
| 2356 | /* Multi options: send array. Scalar: send single value or nothing. */ |
| 2357 | if (ot->type & OPT_MULTI) { |
| 2358 | json_array_start(req->stream, "val"); |
| 2359 | for (size_t i = 0; i < nvals; i++) |
| 2360 | json_add_string(req->stream, NULL, vals[i]); |
| 2361 | json_array_end(req->stream); |
| 2362 | } else if (nvals > 0 && vals[0]) { |
| 2363 | json_add_string(req->stream, "val", vals[0]); |
| 2364 | } |
no test coverage detected