Checks token->str for a short node id and auto completes it. */
| 975 | |
| 976 | /* Checks token->str for a short node id and auto completes it. */ |
| 977 | static bool autocomplete_node_id(struct token *token, |
| 978 | struct splice_script_chan **channels, |
| 979 | bool *multiple_nodes, |
| 980 | bool *chan_id_overmatch) |
| 981 | { |
| 982 | struct node_id *match; |
| 983 | struct node_id candidate; |
| 984 | size_t len = strlen(token->str) / 2; |
| 985 | |
| 986 | *multiple_nodes = false; |
| 987 | *chan_id_overmatch = false; |
| 988 | |
| 989 | if (strlen(token->str) < NODEID_MIN_CHARS) |
| 990 | return false; |
| 991 | if (len > PUBKEY_CMPR_LEN) |
| 992 | return false; |
| 993 | if (!hex_decode(token->str, len * 2, |
| 994 | candidate.k, len)) |
| 995 | return false; |
| 996 | |
| 997 | match = NULL; |
| 998 | for (size_t i = 0; i < tal_count(channels); i++) { |
| 999 | if (len <= sizeof(channels[i]->node_id.k) |
| 1000 | && memeq(candidate.k, len, channels[i]->node_id.k, len)) { |
| 1001 | /* must not match multiple node ids */ |
| 1002 | if (match && !node_id_eq(match, &channels[i]->node_id)) { |
| 1003 | *multiple_nodes = true; |
| 1004 | return true; |
| 1005 | } |
| 1006 | match = &channels[i]->node_id; |
| 1007 | } |
| 1008 | /* nodeid query must *not* match any channel ids */ |
| 1009 | if (len <= sizeof(channels[i]->chan_id.id) |
| 1010 | && memeq(candidate.k, len, channels[i]->chan_id.id, len)) |
| 1011 | *chan_id_overmatch = true; |
| 1012 | } |
| 1013 | |
| 1014 | if (!match) |
| 1015 | return false; |
| 1016 | |
| 1017 | assert(!token->node_id); |
| 1018 | token->node_id = tal_dup(token, struct node_id, match); |
| 1019 | |
| 1020 | return true; |
| 1021 | } |
| 1022 | |
| 1023 | static bool autocomplete_chan_id(struct token *token, |
| 1024 | struct splice_script_chan **channels, |
no test coverage detected