MCPcopy Create free account
hub / github.com/ElementsProject/lightning / param_id_maybe_addr

Function param_id_maybe_addr

lightningd/connect_control.c:76–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

command_failFunction · 0.70
json_strdupFunction · 0.50
json_to_node_idFunction · 0.50
command_fail_badparamFunction · 0.50

Tested by

no test coverage detected