summaryrefslogtreecommitdiff
path: root/toxcore/group.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/group.c')
-rw-r--r--toxcore/group.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/toxcore/group.c b/toxcore/group.c
index 5b5455c8..9793ddae 100644
--- a/toxcore/group.c
+++ b/toxcore/group.c
@@ -630,10 +630,12 @@ static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, int groupnu
630 630
631/* Creates a new groupchat and puts it in the chats array. 631/* Creates a new groupchat and puts it in the chats array.
632 * 632 *
633 * type is one of GROUPCHAT_TYPE_*
634 *
633 * return group number on success. 635 * return group number on success.
634 * return -1 on failure. 636 * return -1 on failure.
635 */ 637 */
636int add_groupchat(Group_Chats *g_c) 638int add_groupchat(Group_Chats *g_c, uint8_t type)
637{ 639{
638 int groupnumber = create_group_chat(g_c); 640 int groupnumber = create_group_chat(g_c);
639 641
@@ -644,7 +646,8 @@ int add_groupchat(Group_Chats *g_c)
644 646
645 g->status = GROUPCHAT_STATUS_CONNECTED; 647 g->status = GROUPCHAT_STATUS_CONNECTED;
646 g->number_joined = -1; 648 g->number_joined = -1;
647 new_symmetric_key(g->identifier); 649 new_symmetric_key(g->identifier + 1);
650 g->identifier[0] = type;
648 g->peer_number = 0; /* Founder is peer 0. */ 651 g->peer_number = 0; /* Founder is peer 0. */
649 memcpy(g->real_pk, g_c->m->net_crypto->self_public_key, crypto_box_PUBLICKEYBYTES); 652 memcpy(g->real_pk, g_c->m->net_crypto->self_public_key, crypto_box_PUBLICKEYBYTES);
650 int peer_index = addpeer(g_c, groupnumber, g->real_pk, g_c->m->dht->self_public_key, 0); 653 int peer_index = addpeer(g_c, groupnumber, g->real_pk, g_c->m->dht->self_public_key, 0);
@@ -846,14 +849,19 @@ static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t
846 849
847/* Join a group (you need to have been invited first.) 850/* Join a group (you need to have been invited first.)
848 * 851 *
852 * expected_type is the groupchat type we expect the chat we are joining is.
853 *
849 * returns group number on success 854 * returns group number on success
850 * returns -1 on failure. 855 * returns -1 on failure.
851 */ 856 */
852int join_groupchat(Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, uint16_t length) 857int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length)
853{ 858{
854 if (length != sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) 859 if (length != sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH)
855 return -1; 860 return -1;
856 861
862 if (data[sizeof(uint16_t)] != expected_type)
863 return -1;
864
857 int friendcon_id = getfriendcon_id(g_c->m, friendnumber); 865 int friendcon_id = getfriendcon_id(g_c->m, friendnumber);
858 866
859 if (friendcon_id == -1) 867 if (friendcon_id == -1)
@@ -899,12 +907,12 @@ int join_groupchat(Group_Chats *g_c, int32_t friendnumber, const uint8_t *data,
899 907
900/* Set the callback for group invites. 908/* Set the callback for group invites.
901 * 909 *
902 * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata) 910 * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata)
903 * 911 *
904 * data of length is what needs to be passed to join_groupchat(). 912 * data of length is what needs to be passed to join_groupchat().
905 */ 913 */
906void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, 914void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, uint8_t, const uint8_t *,
907 void *), void *userdata) 915 uint16_t, void *), void *userdata)
908{ 916{
909 g_c->invite_callback = function; 917 g_c->invite_callback = function;
910 g_c->invite_callback_userdata = userdata; 918 g_c->invite_callback_userdata = userdata;
@@ -1086,7 +1094,8 @@ static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, cons
1086 1094
1087 if (groupnumber == -1) { 1095 if (groupnumber == -1) {
1088 if (g_c->invite_callback) 1096 if (g_c->invite_callback)
1089 g_c->invite_callback(m, friendnumber, invite_data, invite_length, g_c->invite_callback_userdata); 1097 g_c->invite_callback(m, friendnumber, *(invite_data + sizeof(uint16_t)), invite_data, invite_length,
1098 g_c->invite_callback_userdata);
1090 1099
1091 return; 1100 return;
1092 } 1101 }
@@ -2002,6 +2011,7 @@ void kill_groupchats(Group_Chats *g_c)
2002 2011
2003 m_callback_group_invite(g_c->m, NULL); 2012 m_callback_group_invite(g_c->m, NULL);
2004 g_c->m->group_chat_object = 0; 2013 g_c->m->group_chat_object = 0;
2014 free(g_c->av_object);
2005 free(g_c); 2015 free(g_c);
2006} 2016}
2007 2017