| 1406 | } |
| 1407 | |
| 1408 | static struct command_result *json_askrene_create_layer(struct command *cmd, |
| 1409 | const char *buffer, |
| 1410 | const jsmntok_t *params) |
| 1411 | { |
| 1412 | struct askrene *askrene = get_askrene(cmd->plugin); |
| 1413 | struct layer *layer; |
| 1414 | const char *layername; |
| 1415 | struct json_stream *response; |
| 1416 | bool *persistent; |
| 1417 | |
| 1418 | if (!param_check(cmd, buffer, params, |
| 1419 | p_req("layer", param_string, &layername), |
| 1420 | p_opt_def("persistent", param_bool, &persistent, false), |
| 1421 | NULL)) |
| 1422 | return command_param_failed(); |
| 1423 | plugin_log(cmd->plugin, LOG_TRACE, "%s called: %.*s", __func__, |
| 1424 | json_tok_full_len(params), json_tok_full(buffer, params)); |
| 1425 | |
| 1426 | if (strstarts(layername, "auto.")) |
| 1427 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1428 | "Cannot create auto layer"); |
| 1429 | |
| 1430 | if (strstarts(layername, "maxhops=")) |
| 1431 | return command_fail( |
| 1432 | cmd, JSONRPC2_INVALID_PARAMS, |
| 1433 | "Cannot create layer \"maxhops=\", name is reserved"); |
| 1434 | |
| 1435 | /* If it's persistent, creation is a noop if it already exists */ |
| 1436 | layer = find_layer(askrene, layername); |
| 1437 | if (layer && !*persistent) { |
| 1438 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1439 | "Layer already exists"); |
| 1440 | } |
| 1441 | |
| 1442 | if (command_check_only(cmd)) |
| 1443 | return command_check_done(cmd); |
| 1444 | |
| 1445 | if (!layer) |
| 1446 | layer = new_layer(askrene, layername, *persistent); |
| 1447 | |
| 1448 | response = jsonrpc_stream_success(cmd); |
| 1449 | json_add_layers(response, askrene, "layers", layer); |
| 1450 | return command_finished(cmd, response); |
| 1451 | } |
| 1452 | |
| 1453 | static struct command_result *json_askrene_remove_layer(struct command *cmd, |
| 1454 | const char *buffer, |
nothing calls this directly
no test coverage detected