summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-11-19 17:11:49 -0800
committerirungentoo <irungentoo@gmail.com>2013-11-19 17:11:49 -0800
commit6b7f282c47f13a4c69125a8967c3c1a8fee8c761 (patch)
tree20e578641ca11975670321714e52271aa00fba71
parent55fa67e980b3f915fb248cdb38c55d3575de7ab7 (diff)
parentace8c2289ebacf32b0999381f937c0180ae1294e (diff)
Merge pull request #656 from Jman012/master
Added functions tox_count_chatlist and tox_copy_chatlist.
-rw-r--r--toxcore/Messenger.c52
-rw-r--r--toxcore/Messenger.h12
-rw-r--r--toxcore/tox.c19
-rw-r--r--toxcore/tox.h12
4 files changed, 93 insertions, 2 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 19bd7edf..73a1471c 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -2129,12 +2129,12 @@ uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size)
2129 uint32_t ret = 0; 2129 uint32_t ret = 0;
2130 2130
2131 for (i = 0; i < m->numfriends; i++) { 2131 for (i = 0; i < m->numfriends; i++) {
2132 if (i >= list_size) { 2132 if (ret >= list_size) {
2133 break; /* Abandon ship */ 2133 break; /* Abandon ship */
2134 } 2134 }
2135 2135
2136 if (m->friendlist[i].status > 0) { 2136 if (m->friendlist[i].status > 0) {
2137 out_list[i] = i; 2137 out_list[ret] = i;
2138 ret++; 2138 ret++;
2139 } 2139 }
2140 } 2140 }
@@ -2175,3 +2175,51 @@ int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length)
2175 return 0; 2175 return 0;
2176} 2176}
2177 2177
2178/* Return the number of chats in the instance m.
2179 * You should use this to determine how much memory to allocate
2180 * for copy_chatlist. */
2181uint32_t count_chatlist(Messenger *m)
2182{
2183 uint32_t ret = 0;
2184 uint32_t i;
2185
2186 for (i = 0; i < m->numchats; i++) {
2187 if (m->chats[i]) {
2188 ret++;
2189 }
2190 }
2191
2192 return ret;
2193}
2194
2195/* Copy a list of valid chat IDs into the array out_list.
2196 * If out_list is NULL, returns 0.
2197 * Otherwise, returns the number of elements copied.
2198 * If the array was too small, the contents
2199 * of out_list will be truncated to list_size. */
2200uint32_t copy_chatlist(Messenger *m, int *out_list, uint32_t list_size)
2201{
2202 if (!out_list)
2203 return 0;
2204
2205 if (m->numchats == 0) {
2206 return 0;
2207 }
2208
2209 uint32_t i;
2210 uint32_t ret = 0;
2211
2212 for (i = 0; i < m->numchats; i++) {
2213 if (ret >= list_size) {
2214 break; /* Abandon ship */
2215 }
2216
2217 if (m->chats[i]) {
2218 out_list[ret] = i;
2219 ret++;
2220 }
2221 }
2222
2223 return ret;
2224}
2225
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 10ac0eae..3b99b3cf 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -633,5 +633,17 @@ uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size);
633 */ 633 */
634int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length); 634int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length);
635 635
636/* Return the number of chats in the instance m.
637 * You should use this to determine how much memory to allocate
638 * for copy_chatlist. */
639uint32_t count_chatlist(Messenger *m);
640
641/* Copy a list of valid chat IDs into the array out_list.
642 * If out_list is NULL, returns 0.
643 * Otherwise, returns the number of elements copied.
644 * If the array was too small, the contents
645 * of out_list will be truncated to list_size. */
646uint32_t copy_chatlist(Messenger *m, int *out_list, uint32_t list_size);
647
636#endif 648#endif
637 649
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 6a0c6a62..5e110cbe 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -477,6 +477,25 @@ int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t
477 return group_message_send(m, groupnumber, message, length); 477 return group_message_send(m, groupnumber, message, length);
478} 478}
479 479
480/* Return the number of chats in the instance m.
481 * You should use this to determine how much memory to allocate
482 * for copy_chatlist. */
483uint32_t tox_count_chatlist(Tox *tox)
484{
485 Messenger *m = tox;
486 return count_chatlist(m);
487}
488
489/* Copy a list of valid chat IDs into the array out_list.
490 * If out_list is NULL, returns 0.
491 * Otherwise, returns the number of elements copied.
492 * If the array was too small, the contents
493 * of out_list will be truncated to list_size. */
494uint32_t tox_copy_chatlist(Tox *tox, int *out_list, uint32_t list_size)
495{
496 Messenger *m = tox;
497 return copy_chatlist(m, out_list, list_size);
498}
480 499
481 500
482/****************FILE SENDING FUNCTIONS*****************/ 501/****************FILE SENDING FUNCTIONS*****************/
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 5d3916b4..97fb912a 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -404,6 +404,18 @@ int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_
404 * return -1 on failure 404 * return -1 on failure
405 */ 405 */
406int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length); 406int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length);
407
408/* Return the number of chats in the instance m.
409 * You should use this to determine how much memory to allocate
410 * for copy_chatlist. */
411uint32_t tox_count_chatlist(Tox *tox);
412
413/* Copy a list of valid chat IDs into the array out_list.
414 * If out_list is NULL, returns 0.
415 * Otherwise, returns the number of elements copied.
416 * If the array was too small, the contents
417 * of out_list will be truncated to list_size. */
418uint32_t tox_copy_chatlist(Tox *tox, int *out_list, uint32_t list_size);
407 419
408 420
409/****************FILE SENDING FUNCTIONS*****************/ 421/****************FILE SENDING FUNCTIONS*****************/