From b9455efd8430d3578376400f986e62223f1504b3 Mon Sep 17 00:00:00 2001 From: Jin^eLD Date: Thu, 5 Sep 2013 00:45:36 +0300 Subject: Function for retreiving a list of friend numbers This should allow clients to sync the Tox friend list with their UI/etc. lists. --- toxcore/Messenger.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'toxcore/Messenger.c') diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index f97a3320..90d4e43d 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -1052,3 +1052,37 @@ int Messenger_load(Messenger *m, uint8_t *data, uint32_t length) return 0; } + +/* Allocate and return a list of valid friend id's. List must be freed by the + * caller. + * + * retun 0 if success. + * return -1 if failure. + */ +int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length) +{ + uint32_t i; + + *out_list_length = 0; + + if (m->numfriends == 0) { + *out_list = NULL; + return 0; + } + + *out_list = malloc(m->numfriends * sizeof(int)); + + if (*out_list == NULL) { + return -1; + } + + for (i = 0; i < m->numfriends; i++) { + if (m->friendlist[i].status > 0) { + (*out_list)[i] = i; + (*out_list_length)++; + } + } + + return 0; +} + -- cgit v1.2.3