| 1855 | } |
| 1856 | |
| 1857 | static struct listpeers_peer *json_to_listpeers_peer(const tal_t *ctx, |
| 1858 | const char *buffer, |
| 1859 | const jsmntok_t *tok) |
| 1860 | { |
| 1861 | struct listpeers_peer *res; |
| 1862 | size_t i; |
| 1863 | const jsmntok_t *iter; |
| 1864 | const jsmntok_t *idtok = json_get_member(buffer, tok, "id"), |
| 1865 | *conntok = json_get_member(buffer, tok, "connected"), |
| 1866 | *netaddrtok = json_get_member(buffer, tok, "netaddr"), |
| 1867 | *channelstok = json_get_member(buffer, tok, "channels"); |
| 1868 | |
| 1869 | /* Preliminary sanity checks. */ |
| 1870 | if (idtok == NULL || idtok->type != JSMN_STRING || conntok == NULL || |
| 1871 | conntok->type != JSMN_PRIMITIVE || |
| 1872 | (netaddrtok != NULL && netaddrtok->type != JSMN_ARRAY) || |
| 1873 | channelstok == NULL || channelstok->type != JSMN_ARRAY) |
| 1874 | return NULL; |
| 1875 | |
| 1876 | res = tal(ctx, struct listpeers_peer); |
| 1877 | json_to_node_id(buffer, idtok, &res->id); |
| 1878 | json_to_bool(buffer, conntok, &res->connected); |
| 1879 | |
| 1880 | res->netaddr = tal_arr(res, const char *, 0); |
| 1881 | if (netaddrtok != NULL) { |
| 1882 | json_for_each_arr(i, iter, netaddrtok) { |
| 1883 | tal_arr_expand(&res->netaddr, |
| 1884 | json_strdup(res, buffer, iter)); |
| 1885 | } |
| 1886 | } |
| 1887 | |
| 1888 | res->channels = tal_arr(res, struct listpeers_channel *, 0); |
| 1889 | json_for_each_arr(i, iter, channelstok) { |
| 1890 | struct listpeers_channel *chan = json_to_listpeers_channel(res, buffer, iter); |
| 1891 | assert(chan != NULL); |
| 1892 | tal_arr_expand(&res->channels, chan); |
| 1893 | } |
| 1894 | |
| 1895 | return res; |
| 1896 | } |
| 1897 | |
| 1898 | struct listpeers_result *json_to_listpeers_result(const tal_t *ctx, |
| 1899 | const char *buffer, |
no test coverage detected