summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index cb588adf..32e81389 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1653,6 +1653,54 @@ int Messenger_load(Messenger *m, uint8_t *data, uint32_t length)
1653 return Messenger_load_old(m, data, length); 1653 return Messenger_load_old(m, data, length);
1654} 1654}
1655 1655
1656/* Return the number of friends in the instance m.
1657 * You should use this to determine how much memory to allocate
1658 * for copy_friendlist. */
1659uint32_t count_friendlist(Messenger *m)
1660{
1661 uint32_t ret = 0;
1662 uint32_t i;
1663
1664 for (i = 0; i < m->numfriends; i++) {
1665 if (m->friendlist[i].status > 0) {
1666 ret++;
1667 }
1668 }
1669
1670 return ret;
1671}
1672
1673/* Copy a list of valid friend IDs into the array out_list.
1674 * If out_list is NULL, returns 0.
1675 * Otherwise, returns the number of elements copied.
1676 * If the array was too small, the contents
1677 * of out_list will be truncated to list_size. */
1678uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size)
1679{
1680 if (!out_list)
1681 return 0;
1682
1683 if (m->numfriends == 0) {
1684 return 0;
1685 }
1686
1687 uint32_t i;
1688 uint32_t ret = 0;
1689
1690 for (i = 0; i < m->numfriends; i++) {
1691 if (i >= list_size) {
1692 break; /* Abandon ship */
1693 }
1694
1695 if (m->friendlist[i].status > 0) {
1696 out_list[i] = i;
1697 ret++;
1698 }
1699 }
1700
1701 return ret;
1702}
1703
1656/* Allocate and return a list of valid friend id's. List must be freed by the 1704/* Allocate and return a list of valid friend id's. List must be freed by the
1657 * caller. 1705 * caller.
1658 * 1706 *