| 71 | }; |
| 72 | |
| 73 | static struct command_result *param_id_maybe_addr(struct command *cmd, |
| 74 | const char *name, |
| 75 | const char *buffer, |
| 76 | const jsmntok_t *tok, |
| 77 | struct id_and_addr *id_addr) |
| 78 | { |
| 79 | char *id_str; |
| 80 | char *atptr; |
| 81 | char *ataddr = NULL, *host; |
| 82 | u16 port; |
| 83 | jsmntok_t idtok = *tok; |
| 84 | |
| 85 | /* Check for id@addrport form */ |
| 86 | id_str = json_strdup(cmd, buffer, &idtok); |
| 87 | atptr = strchr(id_str, '@'); |
| 88 | if (atptr) { |
| 89 | int atidx = atptr - id_str; |
| 90 | ataddr = tal_strdup(cmd, atptr + 1); |
| 91 | /* Cut id. */ |
| 92 | idtok.end = idtok.start + atidx; |
| 93 | } |
| 94 | |
| 95 | if (!json_to_node_id(buffer, &idtok, &id_addr->id)) |
| 96 | return command_fail_badparam(cmd, name, buffer, tok, |
| 97 | "should be a node id"); |
| 98 | |
| 99 | if (!atptr) |
| 100 | return NULL; |
| 101 | |
| 102 | /* We could parse port/host in any order, using keyword params. */ |
| 103 | if (id_addr->host) { |
| 104 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 105 | "Can't specify host as both xxx@yyy " |
| 106 | "and separate argument"); |
| 107 | } |
| 108 | |
| 109 | port = 0; |
| 110 | if (!separate_address_and_port(cmd, ataddr, &host, &port)) |
| 111 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 112 | "malformed host @part"); |
| 113 | |
| 114 | id_addr->host = host; |
| 115 | if (port) { |
| 116 | if (id_addr->port) { |
| 117 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 118 | "Can't specify port as both xxx@yyy:port " |
| 119 | "and separate argument"); |
| 120 | } |
| 121 | id_addr->port = tal_dup(cmd, u16, &port); |
| 122 | } |
| 123 | return NULL; |
| 124 | } |
| 125 | |
| 126 | static struct command_result *param_id_addr_string(struct command *cmd, |
| 127 | const char *name, |
nothing calls this directly
no test coverage detected