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

Function param_id_maybe_addr

lightningd/connect_control.c:73–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71};
72
73static 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
126static struct command_result *param_id_addr_string(struct command *cmd,
127 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