diff options
author | Jin^eLD <jin@mediatomb.cc> | 2013-09-05 00:45:36 +0300 |
---|---|---|
committer | Jin^eLD <jin@mediatomb.cc> | 2013-09-05 01:30:28 +0300 |
commit | b9455efd8430d3578376400f986e62223f1504b3 (patch) | |
tree | afff930b4067b5fb0edf5b3b5963f4a26db434ff /toxcore/Messenger.c | |
parent | 31f43799e11ea824db79de2458a4ac29e6f22c3d (diff) |
Function for retreiving a list of friend numbers
This should allow clients to sync the Tox friend list with their UI/etc.
lists.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 34 |
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 | */ | ||
1062 | int 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 | |||