diff options
Diffstat (limited to 'toxcore/group.c')
-rw-r--r-- | toxcore/group.c | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/toxcore/group.c b/toxcore/group.c index 4942d872..a2ebca16 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -221,11 +221,11 @@ static uint64_t calculate_comp_value(const uint8_t *pk1, const uint8_t *pk2) | |||
221 | return (cmp1 - cmp2); | 221 | return (cmp1 - cmp2); |
222 | } | 222 | } |
223 | 223 | ||
224 | enum { | 224 | typedef enum Groupchat_Closest { |
225 | GROUPCHAT_CLOSEST_NONE, | 225 | GROUPCHAT_CLOSEST_NONE, |
226 | GROUPCHAT_CLOSEST_ADDED, | 226 | GROUPCHAT_CLOSEST_ADDED, |
227 | GROUPCHAT_CLOSEST_REMOVED | 227 | GROUPCHAT_CLOSEST_REMOVED |
228 | }; | 228 | } Groupchat_Closest; |
229 | 229 | ||
230 | static int friend_in_close(Group_c *g, int friendcon_id); | 230 | static int friend_in_close(Group_c *g, int friendcon_id); |
231 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, uint32_t groupnumber, uint8_t closest, | 231 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, uint32_t groupnumber, uint8_t closest, |
@@ -1114,9 +1114,7 @@ int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_typ | |||
1114 | * | 1114 | * |
1115 | * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) | 1115 | * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) |
1116 | */ | 1116 | */ |
1117 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, uint32_t, uint32_t, | 1117 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function) |
1118 | void *, | ||
1119 | const uint8_t *, uint16_t)) | ||
1120 | { | 1118 | { |
1121 | g_c->lossy_packethandlers[byte].function = function; | 1119 | g_c->lossy_packethandlers[byte].function = function; |
1122 | } | 1120 | } |
@@ -1127,8 +1125,7 @@ void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*fu | |||
1127 | * | 1125 | * |
1128 | * data of length is what needs to be passed to join_groupchat(). | 1126 | * data of length is what needs to be passed to join_groupchat(). |
1129 | */ | 1127 | */ |
1130 | void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, int, const uint8_t *, | 1128 | void g_callback_group_invite(Group_Chats *g_c, g_conference_invite_cb *function) |
1131 | size_t, void *)) | ||
1132 | { | 1129 | { |
1133 | g_c->invite_callback = function; | 1130 | g_c->invite_callback = function; |
1134 | } | 1131 | } |
@@ -1138,8 +1135,7 @@ void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, ui | |||
1138 | * | 1135 | * |
1139 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, size_t length, void *userdata) | 1136 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, size_t length, void *userdata) |
1140 | */ | 1137 | */ |
1141 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, | 1138 | void g_callback_group_message(Group_Chats *g_c, g_conference_message_cb *function) |
1142 | size_t, void *)) | ||
1143 | { | 1139 | { |
1144 | g_c->message_callback = function; | 1140 | g_c->message_callback = function; |
1145 | } | 1141 | } |
@@ -1149,8 +1145,7 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u | |||
1149 | * It gets called every time a peer changes their nickname. | 1145 | * It gets called every time a peer changes their nickname. |
1150 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata) | 1146 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata) |
1151 | */ | 1147 | */ |
1152 | void g_callback_peer_name(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, | 1148 | void g_callback_peer_name(Group_Chats *g_c, peer_name_cb *function) |
1153 | size_t, void *)) | ||
1154 | { | 1149 | { |
1155 | g_c->peer_name_callback = function; | 1150 | g_c->peer_name_callback = function; |
1156 | } | 1151 | } |
@@ -1160,7 +1155,7 @@ void g_callback_peer_name(Group_Chats *g_c, void (*function)(Messenger *m, uint3 | |||
1160 | * It gets called every time the name list changes(new peer, deleted peer) | 1155 | * It gets called every time the name list changes(new peer, deleted peer) |
1161 | * Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata) | 1156 | * Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata) |
1162 | */ | 1157 | */ |
1163 | void g_callback_peer_list_changed(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, void *)) | 1158 | void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *function) |
1164 | { | 1159 | { |
1165 | g_c->peer_list_changed_callback = function; | 1160 | g_c->peer_list_changed_callback = function; |
1166 | } | 1161 | } |
@@ -1171,8 +1166,7 @@ void g_callback_peer_list_changed(Group_Chats *g_c, void (*function)(Messenger * | |||
1171 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) | 1166 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) |
1172 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) | 1167 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) |
1173 | */ | 1168 | */ |
1174 | void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, | 1169 | void g_callback_group_title(Group_Chats *g_c, title_cb *function) |
1175 | size_t, void *)) | ||
1176 | { | 1170 | { |
1177 | g_c->title_callback = function; | 1171 | g_c->title_callback = function; |
1178 | } | 1172 | } |
@@ -1184,8 +1178,7 @@ void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uin | |||
1184 | * return 0 on success. | 1178 | * return 0 on success. |
1185 | * return -1 on failure. | 1179 | * return -1 on failure. |
1186 | */ | 1180 | */ |
1187 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, | 1181 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, peer_on_join_cb *function) |
1188 | uint32_t)) | ||
1189 | { | 1182 | { |
1190 | Group_c *g = get_group_c(g_c, groupnumber); | 1183 | Group_c *g = get_group_c(g_c, groupnumber); |
1191 | 1184 | ||
@@ -1204,7 +1197,7 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, vo | |||
1204 | * return 0 on success. | 1197 | * return 0 on success. |
1205 | * return -1 on failure. | 1198 | * return -1 on failure. |
1206 | */ | 1199 | */ |
1207 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, void *)) | 1200 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, peer_on_leave_cb *function) |
1208 | { | 1201 | { |
1209 | Group_c *g = get_group_c(g_c, groupnumber); | 1202 | Group_c *g = get_group_c(g_c, groupnumber); |
1210 | 1203 | ||
@@ -1223,7 +1216,7 @@ int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void | |||
1223 | * return 0 on success. | 1216 | * return 0 on success. |
1224 | * return -1 on failure. | 1217 | * return -1 on failure. |
1225 | */ | 1218 | */ |
1226 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t)) | 1219 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, group_on_delete_cb *function) |
1227 | { | 1220 | { |
1228 | Group_c *g = get_group_c(g_c, groupnumber); | 1221 | Group_c *g = get_group_c(g_c, groupnumber); |
1229 | 1222 | ||
@@ -1414,7 +1407,7 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con | |||
1414 | 1407 | ||
1415 | if (groupnumber == -1) { | 1408 | if (groupnumber == -1) { |
1416 | if (g_c->invite_callback) { | 1409 | if (g_c->invite_callback) { |
1417 | g_c->invite_callback(m, friendnumber, *(invite_data + sizeof(uint16_t)), invite_data, invite_length, userdata); | 1410 | g_c->invite_callback(m, friendnumber, invite_data[sizeof(uint16_t)], invite_data, invite_length, userdata); |
1418 | } | 1411 | } |
1419 | 1412 | ||
1420 | return; | 1413 | return; |
@@ -1631,22 +1624,24 @@ static unsigned int send_peers(Group_Chats *g_c, uint32_t groupnumber, int frien | |||
1631 | return 0; | 1624 | return 0; |
1632 | } | 1625 | } |
1633 | 1626 | ||
1634 | uint8_t packet[MAX_CRYPTO_DATA_SIZE - (1 + sizeof(uint16_t))]; | 1627 | uint8_t response_packet[MAX_CRYPTO_DATA_SIZE - (1 + sizeof(uint16_t))]; |
1635 | packet[0] = PEER_RESPONSE_ID; | 1628 | response_packet[0] = PEER_RESPONSE_ID; |
1636 | uint8_t *p = packet + 1; | 1629 | uint8_t *p = response_packet + 1; |
1637 | 1630 | ||
1638 | uint16_t sent = 0; | 1631 | uint16_t sent = 0; |
1639 | unsigned int i; | 1632 | unsigned int i; |
1640 | 1633 | ||
1641 | for (i = 0; i < g->numpeers; ++i) { | 1634 | for (i = 0; i < g->numpeers; ++i) { |
1642 | if ((p - packet) + sizeof(uint16_t) + CRYPTO_PUBLIC_KEY_SIZE * 2 + 1 + g->group[i].nick_len > sizeof(packet)) { | 1635 | if ((p - response_packet) + sizeof(uint16_t) + CRYPTO_PUBLIC_KEY_SIZE * 2 + 1 + g->group[i].nick_len > sizeof( |
1643 | if (send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, packet, (p - packet))) { | 1636 | response_packet)) { |
1637 | if (send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, response_packet, | ||
1638 | (p - response_packet))) { | ||
1644 | sent = i; | 1639 | sent = i; |
1645 | } else { | 1640 | } else { |
1646 | return sent; | 1641 | return sent; |
1647 | } | 1642 | } |
1648 | 1643 | ||
1649 | p = packet + 1; | 1644 | p = response_packet + 1; |
1650 | } | 1645 | } |
1651 | 1646 | ||
1652 | uint16_t peer_num = net_htons(g->group[i].peer_number); | 1647 | uint16_t peer_num = net_htons(g->group[i].peer_number); |
@@ -1663,16 +1658,18 @@ static unsigned int send_peers(Group_Chats *g_c, uint32_t groupnumber, int frien | |||
1663 | } | 1658 | } |
1664 | 1659 | ||
1665 | if (sent != i) { | 1660 | if (sent != i) { |
1666 | if (send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, packet, (p - packet))) { | 1661 | if (send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, response_packet, |
1662 | (p - response_packet))) { | ||
1667 | sent = i; | 1663 | sent = i; |
1668 | } | 1664 | } |
1669 | } | 1665 | } |
1670 | 1666 | ||
1671 | if (g->title_len) { | 1667 | if (g->title_len) { |
1672 | VLA(uint8_t, Packet, 1 + g->title_len); | 1668 | VLA(uint8_t, title_packet, 1 + g->title_len); |
1673 | Packet[0] = PEER_TITLE_ID; | 1669 | title_packet[0] = PEER_TITLE_ID; |
1674 | memcpy(Packet + 1, g->title, g->title_len); | 1670 | memcpy(title_packet + 1, g->title, g->title_len); |
1675 | send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, Packet, SIZEOF_VLA(Packet)); | 1671 | send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, title_packet, |
1672 | SIZEOF_VLA(title_packet)); | ||
1676 | } | 1673 | } |
1677 | 1674 | ||
1678 | return sent; | 1675 | return sent; |
@@ -2528,9 +2525,9 @@ uint32_t count_chatlist(Group_Chats *g_c) | |||
2528 | uint32_t ret = 0; | 2525 | uint32_t ret = 0; |
2529 | uint32_t i; | 2526 | uint32_t i; |
2530 | 2527 | ||
2531 | for (i = 0; i < g_c->num_chats; i++) { | 2528 | for (i = 0; i < g_c->num_chats; ++i) { |
2532 | if (g_c->chats[i].status != GROUPCHAT_STATUS_NONE) { | 2529 | if (g_c->chats[i].status != GROUPCHAT_STATUS_NONE) { |
2533 | ret++; | 2530 | ++ret; |
2534 | } | 2531 | } |
2535 | } | 2532 | } |
2536 | 2533 | ||
@@ -2561,7 +2558,7 @@ uint32_t copy_chatlist(Group_Chats *g_c, uint32_t *out_list, uint32_t list_size) | |||
2561 | 2558 | ||
2562 | if (g_c->chats[i].status > GROUPCHAT_STATUS_NONE) { | 2559 | if (g_c->chats[i].status > GROUPCHAT_STATUS_NONE) { |
2563 | out_list[ret] = i; | 2560 | out_list[ret] = i; |
2564 | ret++; | 2561 | ++ret; |
2565 | } | 2562 | } |
2566 | } | 2563 | } |
2567 | 2564 | ||