diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/group.c | 24 | ||||
-rw-r--r-- | toxcore/group.h | 25 | ||||
-rw-r--r-- | toxcore/tox.c | 10 | ||||
-rw-r--r-- | toxcore/tox.h | 18 |
4 files changed, 55 insertions, 22 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 | */ |
636 | int add_groupchat(Group_Chats *g_c) | 638 | int 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 | */ |
852 | int join_groupchat(Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, uint16_t length) | 857 | int 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 | */ |
906 | void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, | 914 | void 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 | ||
diff --git a/toxcore/group.h b/toxcore/group.h index 1a51f83b..a9e6e8e9 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -33,6 +33,11 @@ enum { | |||
33 | GROUPCHAT_STATUS_CONNECTED | 33 | GROUPCHAT_STATUS_CONNECTED |
34 | }; | 34 | }; |
35 | 35 | ||
36 | enum { | ||
37 | GROUPCHAT_TYPE_TEXT, | ||
38 | GROUPCHAT_TYPE_AV | ||
39 | }; | ||
40 | |||
36 | #define MAX_LOSSY_COUNT 256 | 41 | #define MAX_LOSSY_COUNT 256 |
37 | 42 | ||
38 | typedef struct { | 43 | typedef struct { |
@@ -55,7 +60,7 @@ typedef struct { | |||
55 | 60 | ||
56 | #define DESIRED_CLOSE_CONNECTIONS 4 | 61 | #define DESIRED_CLOSE_CONNECTIONS 4 |
57 | #define MAX_GROUP_CONNECTIONS 16 | 62 | #define MAX_GROUP_CONNECTIONS 16 |
58 | #define GROUP_IDENTIFIER_LENGTH crypto_box_KEYBYTES /* So we can use new_symmetric_key(...) to fill it */ | 63 | #define GROUP_IDENTIFIER_LENGTH (1 + crypto_box_KEYBYTES) /* crypto_box_KEYBYTES so we can use new_symmetric_key(...) to fill it */ |
59 | 64 | ||
60 | enum { | 65 | enum { |
61 | GROUPCHAT_CLOSE_NONE, | 66 | GROUPCHAT_CLOSE_NONE, |
@@ -107,7 +112,7 @@ typedef struct { | |||
107 | Group_c *chats; | 112 | Group_c *chats; |
108 | uint32_t num_chats; | 113 | uint32_t num_chats; |
109 | 114 | ||
110 | void (*invite_callback)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *); | 115 | void (*invite_callback)(Messenger *m, int32_t, uint8_t, const uint8_t *, uint16_t, void *); |
111 | void *invite_callback_userdata; | 116 | void *invite_callback_userdata; |
112 | void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); | 117 | void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); |
113 | void *message_callback_userdata; | 118 | void *message_callback_userdata; |
@@ -119,16 +124,18 @@ typedef struct { | |||
119 | struct { | 124 | struct { |
120 | int (*function)(void *, int, int, void *, const uint8_t *, uint16_t); | 125 | int (*function)(void *, int, int, void *, const uint8_t *, uint16_t); |
121 | } lossy_packethandlers[256]; | 126 | } lossy_packethandlers[256]; |
127 | |||
128 | void *av_object; | ||
122 | } Group_Chats; | 129 | } Group_Chats; |
123 | 130 | ||
124 | /* Set the callback for group invites. | 131 | /* Set the callback for group invites. |
125 | * | 132 | * |
126 | * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata) | 133 | * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) |
127 | * | 134 | * |
128 | * data of length is what needs to be passed to join_groupchat(). | 135 | * data of length is what needs to be passed to join_groupchat(). |
129 | */ | 136 | */ |
130 | void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, | 137 | void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, uint8_t, const uint8_t *, |
131 | void *), void *userdata); | 138 | uint16_t, void *), void *userdata); |
132 | 139 | ||
133 | /* Set the callback for group messages. | 140 | /* Set the callback for group messages. |
134 | * | 141 | * |
@@ -159,10 +166,12 @@ void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenge | |||
159 | 166 | ||
160 | /* Creates a new groupchat and puts it in the chats array. | 167 | /* Creates a new groupchat and puts it in the chats array. |
161 | * | 168 | * |
169 | * type is one of GROUPCHAT_TYPE_* | ||
170 | * | ||
162 | * return group number on success. | 171 | * return group number on success. |
163 | * return -1 on failure. | 172 | * return -1 on failure. |
164 | */ | 173 | */ |
165 | int add_groupchat(Group_Chats *g_c); | 174 | int add_groupchat(Group_Chats *g_c, uint8_t type); |
166 | 175 | ||
167 | /* Delete a groupchat from the chats array. | 176 | /* Delete a groupchat from the chats array. |
168 | * | 177 | * |
@@ -187,10 +196,12 @@ int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber); | |||
187 | 196 | ||
188 | /* Join a group (you need to have been invited first.) | 197 | /* Join a group (you need to have been invited first.) |
189 | * | 198 | * |
199 | * expected_type is the groupchat type we expect the chat we are joining is. | ||
200 | * | ||
190 | * returns group number on success | 201 | * returns group number on success |
191 | * returns -1 on failure. | 202 | * returns -1 on failure. |
192 | */ | 203 | */ |
193 | int join_groupchat(Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, uint16_t length); | 204 | int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length); |
194 | 205 | ||
195 | /* send a group message | 206 | /* send a group message |
196 | * return 0 on success | 207 | * return 0 on success |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 9eef6157..9e9a5057 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -551,12 +551,12 @@ int tox_send_lossless_packet(const Tox *tox, int32_t friendnumber, const uint8_t | |||
551 | 551 | ||
552 | /* Set the callback for group invites. | 552 | /* Set the callback for group invites. |
553 | * | 553 | * |
554 | * Function(Tox *tox, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata) | 554 | * Function(Tox *tox, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) |
555 | * | 555 | * |
556 | * data of length is what needs to be passed to join_groupchat(). | 556 | * data of length is what needs to be passed to join_groupchat(). |
557 | */ | 557 | */ |
558 | void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *), | 558 | void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, const uint8_t *, uint16_t, |
559 | void *userdata) | 559 | void *), void *userdata) |
560 | { | 560 | { |
561 | Messenger *m = tox; | 561 | Messenger *m = tox; |
562 | g_callback_group_invite(m->group_chat_object, function, userdata); | 562 | g_callback_group_invite(m->group_chat_object, function, userdata); |
@@ -603,7 +603,7 @@ void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int | |||
603 | int tox_add_groupchat(Tox *tox) | 603 | int tox_add_groupchat(Tox *tox) |
604 | { | 604 | { |
605 | Messenger *m = tox; | 605 | Messenger *m = tox; |
606 | return add_groupchat(m->group_chat_object); | 606 | return add_groupchat(m->group_chat_object, GROUPCHAT_TYPE_TEXT); |
607 | } | 607 | } |
608 | 608 | ||
609 | /* Delete a groupchat from the chats array. | 609 | /* Delete a groupchat from the chats array. |
@@ -648,7 +648,7 @@ int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) | |||
648 | int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length) | 648 | int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length) |
649 | { | 649 | { |
650 | Messenger *m = tox; | 650 | Messenger *m = tox; |
651 | return join_groupchat(m->group_chat_object, friendnumber, data, length); | 651 | return join_groupchat(m->group_chat_object, friendnumber, GROUPCHAT_TYPE_TEXT, data, length); |
652 | } | 652 | } |
653 | 653 | ||
654 | /* send a group message | 654 | /* send a group message |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 84ba293a..4f93e608 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -417,14 +417,26 @@ int tox_send_lossless_packet(const Tox *tox, int32_t friendnumber, const uint8_t | |||
417 | 417 | ||
418 | /**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/ | 418 | /**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/ |
419 | 419 | ||
420 | /* Group chat types for tox_callback_group_invite function. | ||
421 | * | ||
422 | * TOX_GROUPCHAT_TYPE_TEXT groupchats must be accepted with the tox_join_groupchat() function. | ||
423 | * The function to accept TOX_GROUPCHAT_TYPE_AV is in toxav. | ||
424 | */ | ||
425 | enum { | ||
426 | TOX_GROUPCHAT_TYPE_TEXT, | ||
427 | TOX_GROUPCHAT_TYPE_AV | ||
428 | }; | ||
429 | |||
420 | /* Set the callback for group invites. | 430 | /* Set the callback for group invites. |
421 | * | 431 | * |
422 | * Function(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length, void *userdata) | 432 | * Function(Tox *tox, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) |
423 | * | 433 | * |
424 | * data of length is what needs to be passed to join_groupchat(). | 434 | * data of length is what needs to be passed to join_groupchat(). |
435 | * | ||
436 | * for what type means see the enum right above this comment. | ||
425 | */ | 437 | */ |
426 | void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *), | 438 | void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, const uint8_t *, uint16_t, |
427 | void *userdata); | 439 | void *), void *userdata); |
428 | 440 | ||
429 | /* Set the callback for group messages. | 441 | /* Set the callback for group messages. |
430 | * | 442 | * |