| 1342 | } |
| 1343 | |
| 1344 | static struct command_result *json_askrene_create_layer(struct command *cmd, |
| 1345 | const char *buffer, |
| 1346 | const jsmntok_t *params) |
| 1347 | { |
| 1348 | struct askrene *askrene = get_askrene(cmd->plugin); |
| 1349 | struct layer *layer; |
| 1350 | const char *layername; |
| 1351 | struct json_stream *response; |
| 1352 | bool *persistent; |
| 1353 | |
| 1354 | if (!param_check(cmd, buffer, params, |
| 1355 | p_req("layer", param_string, &layername), |
| 1356 | p_opt_def("persistent", param_bool, &persistent, false), |
| 1357 | NULL)) |
| 1358 | return command_param_failed(); |
| 1359 | plugin_log(cmd->plugin, LOG_TRACE, "%s called: %.*s", __func__, |
| 1360 | json_tok_full_len(params), json_tok_full(buffer, params)); |
| 1361 | |
| 1362 | if (strstarts(layername, "auto.")) |
| 1363 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1364 | "Cannot create auto layer"); |
| 1365 | |
| 1366 | /* If it's persistent, creation is a noop if it already exists */ |
| 1367 | layer = find_layer(askrene, layername); |
| 1368 | if (layer && !*persistent) { |
| 1369 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1370 | "Layer already exists"); |
| 1371 | } |
| 1372 | |
| 1373 | if (command_check_only(cmd)) |
| 1374 | return command_check_done(cmd); |
| 1375 | |
| 1376 | if (!layer) |
| 1377 | layer = new_layer(askrene, layername, *persistent); |
| 1378 | |
| 1379 | response = jsonrpc_stream_success(cmd); |
| 1380 | json_add_layers(response, askrene, "layers", layer); |
| 1381 | return command_finished(cmd, response); |
| 1382 | } |
| 1383 | |
| 1384 | static struct command_result *json_askrene_remove_layer(struct command *cmd, |
| 1385 | const char *buffer, |
nothing calls this directly
no test coverage detected