summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/nTox.c14
-rw-r--r--toxcore/Messenger.c53
-rw-r--r--toxcore/Messenger.h15
-rw-r--r--toxcore/group_chats.c13
-rw-r--r--toxcore/group_chats.h12
-rw-r--r--toxcore/tox.c23
-rw-r--r--toxcore/tox.h18
7 files changed, 138 insertions, 10 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index d9206415..7448bf7e 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -974,13 +974,25 @@ void print_invite(Tox *m, int friendnumber, uint8_t *group_public_key, void *use
974 tox_join_groupchat(m, friendnumber, group_public_key)); 974 tox_join_groupchat(m, friendnumber, group_public_key));
975 new_lines(msg); 975 new_lines(msg);
976} 976}
977void print_groupchatpeers(Tox *m, int groupnumber)
978{
979 char msg[256];
980 int num = tox_group_number_peers(m, groupnumber);
981 if (num == -1)
982 return;
977 983
984 uint8_t names[num][TOX_MAX_NAME_LENGTH];
985 tox_group_copy_names(m, groupnumber, names, num);
986 uint32_t i;
987 for (i = 0; i < num; ++i)
988 new_lines(names[i]);
989}
978void print_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length, void *userdata) 990void print_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length, void *userdata)
979{ 991{
980 char msg[256 + length]; 992 char msg[256 + length];
981 uint8_t name[TOX_MAX_NAME_LENGTH]; 993 uint8_t name[TOX_MAX_NAME_LENGTH];
982 int len = tox_group_peername(m, groupnumber, peernumber, name); 994 int len = tox_group_peername(m, groupnumber, peernumber, name);
983 995 //print_groupchatpeers(m, groupnumber);
984 if (len <= 0) 996 if (len <= 0)
985 name[0] = 0; 997 name[0] = 0;
986 998
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 8f6c42f9..889de367 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -707,6 +707,23 @@ int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint
707 707
708/**********GROUP CHATS************/ 708/**********GROUP CHATS************/
709 709
710/* return 1 if the groupnumber is not valid.
711 * return 0 if the groupnumber is valid.
712 */
713static uint8_t groupnumber_not_valid(Messenger *m, int groupnumber)
714{
715 if ((unsigned int)groupnumber >= m->numchats)
716 return 1;
717
718 if (m->chats == NULL)
719 return 1;
720
721 if (m->chats[groupnumber] == NULL)
722 return 1;
723 return 0;
724}
725
726
710/* returns valid ip port of connected friend on success 727/* returns valid ip port of connected friend on success
711 * returns zeroed out IP_Port on failure 728 * returns zeroed out IP_Port on failure
712 */ 729 */
@@ -964,6 +981,7 @@ int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_
964 return -1; 981 return -1;
965} 982}
966 983
984
967/* send a group message 985/* send a group message
968 * return 0 on success 986 * return 0 on success
969 * return -1 on failure 987 * return -1 on failure
@@ -971,13 +989,7 @@ int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_
971 989
972int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length) 990int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length)
973{ 991{
974 if ((unsigned int)groupnumber >= m->numchats) 992 if (groupnumber_not_valid(m, groupnumber))
975 return -1;
976
977 if (m->chats == NULL)
978 return -1;
979
980 if (m->chats[groupnumber] == NULL)
981 return -1; 993 return -1;
982 994
983 if (group_sendmessage(m->chats[groupnumber], message, length) > 0) 995 if (group_sendmessage(m->chats[groupnumber], message, length) > 0)
@@ -986,6 +998,33 @@ int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t
986 return -1; 998 return -1;
987} 999}
988 1000
1001/* Return the number of peers in the group chat on success.
1002 * return -1 on failure
1003 */
1004int group_number_peers(Messenger *m, int groupnumber)
1005{
1006 if (groupnumber_not_valid(m, groupnumber))
1007 return -1;
1008
1009 return group_numpeers(m->chats[groupnumber]);
1010}
1011
1012/* List all the peers in the group chat.
1013 *
1014 * Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
1015 *
1016 * returns the number of peers on success.
1017 *
1018 * return -1 on failure.
1019 */
1020int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t length)
1021{
1022 if (groupnumber_not_valid(m, groupnumber))
1023 return -1;
1024
1025 return group_client_names(m->chats[groupnumber], names, length);
1026}
1027
989static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length) 1028static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length)
990{ 1029{
991 Messenger *m = object; 1030 Messenger *m = object;
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 3b99b3cf..651f3f12 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -497,6 +497,21 @@ int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_
497 497
498int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length); 498int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length);
499 499
500/* Return the number of peers in the group chat on success.
501 * return -1 on failure
502 */
503int group_number_peers(Messenger *m, int groupnumber);
504
505/* List all the peers in the group chat.
506 *
507 * Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
508 *
509 * returns the number of peers on success.
510 *
511 * return -1 on failure.
512 */
513int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t length);
514
500/****************FILE SENDING*****************/ 515/****************FILE SENDING*****************/
501 516
502 517
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c
index 7f28bf9b..34c84c40 100644
--- a/toxcore/group_chats.c
+++ b/toxcore/group_chats.c
@@ -616,6 +616,19 @@ void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat,
616 chat->group_message_userdata = userdata; 616 chat->group_message_userdata = userdata;
617} 617}
618 618
619uint32_t group_numpeers(Group_Chat *chat)
620{
621 return chat->numpeers;
622}
623
624uint32_t group_client_names(Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t length)
625{
626 uint32_t i;
627 for (i = 0; i < chat->numpeers && i < length; ++i) {
628 group_peername(chat, i, names[i]);
629 }
630 return i;
631}
619 632
620Group_Chat *new_groupchat(Networking_Core *net) 633Group_Chat *new_groupchat(Networking_Core *net)
621{ 634{
diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h
index 859b5658..4257b1f5 100644
--- a/toxcore/group_chats.h
+++ b/toxcore/group_chats.h
@@ -128,6 +128,18 @@ uint32_t group_newpeer(Group_Chat *chat, uint8_t *client_id);
128Group_Chat *new_groupchat(Networking_Core *net); 128Group_Chat *new_groupchat(Networking_Core *net);
129 129
130 130
131/* Return the number of peers in the group chat.
132 */
133uint32_t group_numpeers(Group_Chat *chat);
134
135/* List all the peers in the group chat.
136 *
137 * Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
138 *
139 * returns the number of peers.
140 */
141uint32_t group_client_names(Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t length);
142
131/* Kill a group chat 143/* Kill a group chat
132 * 144 *
133 * Frees the memory and everything. 145 * Frees the memory and everything.
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 5e110cbe..b5e754bb 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -477,6 +477,29 @@ 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 peers in the group chat on success.
481 * return -1 on failure
482 */
483int tox_group_number_peers(Tox *tox, int groupnumber)
484{
485 Messenger *m = tox;
486 return group_number_peers(m, groupnumber);
487}
488
489/* List all the peers in the group chat.
490 *
491 * Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
492 *
493 * returns the number of peers on success.
494 *
495 * return -1 on failure.
496 */
497int tox_group_copy_names(Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t length)
498{
499 Messenger *m = tox;
500 return group_names(m, groupnumber, names, length);
501}
502
480/* Return the number of chats in the instance m. 503/* Return the number of chats in the instance m.
481 * You should use this to determine how much memory to allocate 504 * You should use this to determine how much memory to allocate
482 * for copy_chatlist. */ 505 * for copy_chatlist. */
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 97fb912a..a0093ff3 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -398,13 +398,27 @@ int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber);
398 */ 398 */
399int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key); 399int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key);
400 400
401
402/* send a group message 401/* send a group message
403 * return 0 on success 402 * return 0 on success
404 * return -1 on failure 403 * return -1 on failure
405 */ 404 */
406int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length); 405int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length);
407 406
407/* Return the number of peers in the group chat on success.
408 * return -1 on failure
409 */
410int tox_group_number_peers(Tox *tox, int groupnumber);
411
412/* List all the peers in the group chat.
413 *
414 * Copies the names of the peers to the name[length][TOX_MAX_NAME_LENGTH] array.
415 *
416 * returns the number of peers on success.
417 *
418 * return -1 on failure.
419 */
420int tox_group_copy_names(Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t length);
421
408/* Return the number of chats in the instance m. 422/* Return the number of chats in the instance m.
409 * You should use this to determine how much memory to allocate 423 * You should use this to determine how much memory to allocate
410 * for copy_chatlist. */ 424 * for copy_chatlist. */