summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c34
-rw-r--r--toxcore/Messenger.h7
-rw-r--r--toxcore/tox.c11
-rw-r--r--toxcore/tox.h8
4 files changed, 60 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
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index fedf2879..649ca894 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -377,5 +377,12 @@ void Messenger_save(Messenger *m, uint8_t *data);
377/* Load the messenger from data of size length. */ 377/* Load the messenger from data of size length. */
378int Messenger_load(Messenger *m, uint8_t *data, uint32_t length); 378int Messenger_load(Messenger *m, uint8_t *data, uint32_t length);
379 379
380/* Allocate and return a list of valid friend id's. List must be freed by the
381 * caller.
382 *
383 * retun 0 if success.
384 * return -1 if failure.
385 */
386int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length);
380 387
381#endif 388#endif
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 23ca6572..e55f51ca 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -247,6 +247,17 @@ void tox_set_sends_receipts(void *tox, int friendnumber, int yesno)
247 m_set_sends_receipts(m, friendnumber, yesno); 247 m_set_sends_receipts(m, friendnumber, yesno);
248} 248}
249 249
250/* Allocate and return a list of valid friend id's. List must be freed by the
251 * caller.
252 *
253 * retun 0 if success.
254 * return -1 if failure.
255 */
256int tox_get_friendlist(void *tox, int **out_list, uint32_t *out_list_length)
257{
258 Messenger *m = tox;
259 return get_friendlist(m, out_list, out_list_length);
260}
250 261
251/* Set the function that will be executed when a friend request is received. 262/* Set the function that will be executed when a friend request is received.
252 * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) 263 * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
diff --git a/toxcore/tox.h b/toxcore/tox.h
index b17ca36f..bd13b998 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -221,6 +221,14 @@ TOX_USERSTATUS tox_get_selfuserstatus(Tox *tox);
221 */ 221 */
222void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno); 222void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno);
223 223
224/* Allocate and return a list of valid friend id's. List must be freed by the
225 * caller.
226 *
227 * retun 0 if success.
228 * return -1 if failure.
229 */
230int tox_get_friendlist(void *tox, int **out_list, uint32_t *out_list_length);
231
224/* Set the function that will be executed when a friend request is received. 232/* Set the function that will be executed when a friend request is received.
225 * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) 233 * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
226 */ 234 */