summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c34
1 files changed, 34 insertions, 0 deletions
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)
1052 1052
1053 return 0; 1053 return 0;
1054} 1054}
1055
1056/* Allocate and return a list of valid friend id's. List must be freed by the
1057 * caller.
1058 *
1059 * retun 0 if success.
1060 * return -1 if failure.
1061 */
1062int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length)
1063{
1064 uint32_t i;
1065
1066 *out_list_length = 0;
1067
1068 if (m->numfriends == 0) {
1069 *out_list = NULL;
1070 return 0;
1071 }
1072
1073 *out_list = malloc(m->numfriends * sizeof(int));
1074
1075 if (*out_list == NULL) {
1076 return -1;
1077 }
1078
1079 for (i = 0; i < m->numfriends; i++) {
1080 if (m->friendlist[i].status > 0) {
1081 (*out_list)[i] = i;
1082 (*out_list_length)++;
1083 }
1084 }
1085
1086 return 0;
1087}
1088