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