diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 32 | ||||
-rw-r--r-- | toxcore/Messenger.h | 13 | ||||
-rw-r--r-- | toxcore/group.c | 55 | ||||
-rw-r--r-- | toxcore/group.h | 3 |
4 files changed, 54 insertions, 49 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 04830260..c3f85beb 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -999,14 +999,6 @@ void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_ | |||
999 | m->group_invite = function; | 999 | m->group_invite = function; |
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | /* Set the callback for group messages. | ||
1003 | * | ||
1004 | * Function(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length) | ||
1005 | */ | ||
1006 | void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t)) | ||
1007 | { | ||
1008 | m->group_message = function; | ||
1009 | } | ||
1010 | 1002 | ||
1011 | /* Send a group invite packet. | 1003 | /* Send a group invite packet. |
1012 | * | 1004 | * |
@@ -1018,17 +1010,6 @@ int send_group_invite_packet(const Messenger *m, int32_t friendnumber, const uin | |||
1018 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_INVITE_GROUPCHAT, data, length, 0); | 1010 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_INVITE_GROUPCHAT, data, length, 0); |
1019 | } | 1011 | } |
1020 | 1012 | ||
1021 | /* Send a group message packet. | ||
1022 | * | ||
1023 | * return 1 on success | ||
1024 | * return 0 on failure | ||
1025 | */ | ||
1026 | int send_group_message_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length) | ||
1027 | { | ||
1028 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_MESSAGE_GROUPCHAT, data, length, 0); | ||
1029 | } | ||
1030 | |||
1031 | |||
1032 | /****************FILE SENDING*****************/ | 1013 | /****************FILE SENDING*****************/ |
1033 | 1014 | ||
1034 | 1015 | ||
@@ -1230,7 +1211,8 @@ int file_data(const Messenger *m, int32_t friendnumber, uint8_t filenumber, cons | |||
1230 | return -1; | 1211 | return -1; |
1231 | 1212 | ||
1232 | /* Prevent file sending from filling up the entire buffer preventing messages from being sent. TODO: remove */ | 1213 | /* Prevent file sending from filling up the entire buffer preventing messages from being sent. TODO: remove */ |
1233 | if (crypto_num_free_sendqueue_slots(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id)) < MIN_SLOTS_FREE) | 1214 | if (crypto_num_free_sendqueue_slots(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, |
1215 | m->friendlist[friendnumber].friendcon_id)) < MIN_SLOTS_FREE) | ||
1234 | return -1; | 1216 | return -1; |
1235 | 1217 | ||
1236 | uint8_t packet[MAX_CRYPTO_DATA_SIZE]; | 1218 | uint8_t packet[MAX_CRYPTO_DATA_SIZE]; |
@@ -2125,16 +2107,6 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len) | |||
2125 | break; | 2107 | break; |
2126 | } | 2108 | } |
2127 | 2109 | ||
2128 | case PACKET_ID_MESSAGE_GROUPCHAT: { | ||
2129 | if (data_length == 0) | ||
2130 | break; | ||
2131 | |||
2132 | if (m->group_message) | ||
2133 | (*m->group_message)(m, i, data, data_length); | ||
2134 | |||
2135 | break; | ||
2136 | } | ||
2137 | |||
2138 | case PACKET_ID_FILE_SENDREQUEST: { | 2110 | case PACKET_ID_FILE_SENDREQUEST: { |
2139 | if (data_length < 1 + sizeof(uint64_t) + 1) | 2111 | if (data_length < 1 + sizeof(uint64_t) + 1) |
2140 | break; | 2112 | break; |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 454c31cb..38543b36 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -729,12 +729,6 @@ void m_callback_avatar_data(Messenger *m, void (*function)(Messenger *m, int32_t | |||
729 | */ | 729 | */ |
730 | void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t)); | 730 | void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t)); |
731 | 731 | ||
732 | /* Set the callback for group messages. | ||
733 | * | ||
734 | * Function(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length) | ||
735 | */ | ||
736 | void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t)); | ||
737 | |||
738 | /* Send a group invite packet. | 732 | /* Send a group invite packet. |
739 | * | 733 | * |
740 | * return 1 on success | 734 | * return 1 on success |
@@ -742,13 +736,6 @@ void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int32 | |||
742 | */ | 736 | */ |
743 | int send_group_invite_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length); | 737 | int send_group_invite_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length); |
744 | 738 | ||
745 | /* Send a group message packet. | ||
746 | * | ||
747 | * return 1 on success | ||
748 | * return 0 on failure | ||
749 | */ | ||
750 | int send_group_message_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length); | ||
751 | |||
752 | /****************FILE SENDING*****************/ | 739 | /****************FILE SENDING*****************/ |
753 | 740 | ||
754 | 741 | ||
diff --git a/toxcore/group.c b/toxcore/group.c index 8ea626bb..d5244f65 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -223,6 +223,8 @@ static int addpeer(Group_c *chat, const uint8_t *client_id, uint16_t peer_number | |||
223 | return (chat->numpeers - 1); | 223 | return (chat->numpeers - 1); |
224 | } | 224 | } |
225 | 225 | ||
226 | static int handle_packet(void *object, int number, uint8_t *data, uint16_t length); | ||
227 | |||
226 | /* Add friend to group chat. | 228 | /* Add friend to group chat. |
227 | * | 229 | * |
228 | * return 0 on success | 230 | * return 0 on success |
@@ -246,7 +248,7 @@ static int add_friend_to_groupchat(Group_Chats *g_c, int32_t friendnumber, int g | |||
246 | continue; | 248 | continue; |
247 | } | 249 | } |
248 | 250 | ||
249 | if (g->close[i].type == GROUPCHAT_CLOSE_FRIEND && g->close[i].number == (uint32_t)friendnumber) { | 251 | if (g->close[i].type == GROUPCHAT_CLOSE_CONNECTION && g->close[i].number == (uint32_t)friendnumber) { |
250 | g->close[i].group_number = other_groupnum; /* update groupnum. */ | 252 | g->close[i].group_number = other_groupnum; /* update groupnum. */ |
251 | return 0; /* Already in list. */ | 253 | return 0; /* Already in list. */ |
252 | } | 254 | } |
@@ -257,9 +259,13 @@ static int add_friend_to_groupchat(Group_Chats *g_c, int32_t friendnumber, int g | |||
257 | if (ind == MAX_GROUP_CONNECTIONS) | 259 | if (ind == MAX_GROUP_CONNECTIONS) |
258 | return -1; | 260 | return -1; |
259 | 261 | ||
260 | g->close[ind].type = GROUPCHAT_CLOSE_FRIEND; | 262 | g->close[ind].type = GROUPCHAT_CLOSE_CONNECTION; |
261 | g->close[ind].number = friendnumber; | 263 | g->close[ind].number = friendnumber; |
262 | g->close[ind].group_number = other_groupnum; | 264 | g->close[ind].group_number = other_groupnum; |
265 | int friendcon_id = g_c->m->friendlist[friendnumber].friendcon_id; | ||
266 | //TODO | ||
267 | friend_connection_callbacks(g_c->m->fr_c, friendcon_id, GROUPCHAT_CALLBACK_INDEX, 0, &handle_packet, 0, g_c->m, | ||
268 | friendnumber); | ||
263 | 269 | ||
264 | return 0; | 270 | return 0; |
265 | } | 271 | } |
@@ -300,6 +306,23 @@ int del_groupchat(Group_Chats *g_c, int groupnumber) | |||
300 | return wipe_group_chat(g_c, groupnumber); | 306 | return wipe_group_chat(g_c, groupnumber); |
301 | } | 307 | } |
302 | 308 | ||
309 | /* Send a group message packet. | ||
310 | * | ||
311 | * return 1 on success | ||
312 | * return 0 on failure | ||
313 | */ | ||
314 | int send_group_message_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length) | ||
315 | { | ||
316 | if (length >= MAX_CRYPTO_DATA_SIZE) | ||
317 | return 0; | ||
318 | |||
319 | uint8_t packet[1 + length]; | ||
320 | packet[0] = PACKET_ID_MESSAGE_GROUPCHAT; | ||
321 | memcpy(packet + 1, data, length); | ||
322 | return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, | ||
323 | m->friendlist[friendnumber].friendcon_id), packet, sizeof(packet), 0) != -1; | ||
324 | } | ||
325 | |||
303 | #define INVITE_PACKET_SIZE (1 + sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) | 326 | #define INVITE_PACKET_SIZE (1 + sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) |
304 | #define INVITE_ID 0 | 327 | #define INVITE_ID 0 |
305 | 328 | ||
@@ -464,7 +487,7 @@ static int friend_in_close(Group_c *g, int32_t friendnumber) | |||
464 | int i; | 487 | int i; |
465 | 488 | ||
466 | for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) { | 489 | for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) { |
467 | if (g->close[i].type != GROUPCHAT_CLOSE_FRIEND) | 490 | if (g->close[i].type != GROUPCHAT_CLOSE_CONNECTION) |
468 | continue; | 491 | continue; |
469 | 492 | ||
470 | if (g->close[i].number != (uint32_t)friendnumber) | 493 | if (g->close[i].number != (uint32_t)friendnumber) |
@@ -649,6 +672,31 @@ static void handle_friend_message_packet(Messenger *m, int32_t friendnumber, con | |||
649 | handle_message_packet_group(g_c, groupnumber, data, length, index); | 672 | handle_message_packet_group(g_c, groupnumber, data, length, index); |
650 | } | 673 | } |
651 | 674 | ||
675 | static int handle_packet(void *object, int number, uint8_t *data, uint16_t length) | ||
676 | { | ||
677 | if (length <= 1) | ||
678 | return -1; | ||
679 | |||
680 | switch (data[0]) { | ||
681 | case PACKET_ID_INVITE_GROUPCHAT: { | ||
682 | handle_friend_invite_packet(object, number, data + 1, length - 1); | ||
683 | break; | ||
684 | } | ||
685 | |||
686 | case PACKET_ID_MESSAGE_GROUPCHAT: { | ||
687 | handle_friend_message_packet(object, number, data + 1, length - 1); | ||
688 | break; | ||
689 | } | ||
690 | |||
691 | default: { | ||
692 | return 0; | ||
693 | } | ||
694 | } | ||
695 | |||
696 | return 0; | ||
697 | } | ||
698 | |||
699 | |||
652 | /* Create new groupchat instance. */ | 700 | /* Create new groupchat instance. */ |
653 | Group_Chats *new_groupchats(Messenger *m) | 701 | Group_Chats *new_groupchats(Messenger *m) |
654 | { | 702 | { |
@@ -663,7 +711,6 @@ Group_Chats *new_groupchats(Messenger *m) | |||
663 | temp->m = m; | 711 | temp->m = m; |
664 | m->group_chat_object = temp; | 712 | m->group_chat_object = temp; |
665 | m_callback_group_invite(m, &handle_friend_invite_packet); | 713 | m_callback_group_invite(m, &handle_friend_invite_packet); |
666 | m_callback_group_message(m, &handle_friend_message_packet); | ||
667 | 714 | ||
668 | return temp; | 715 | return temp; |
669 | } | 716 | } |
diff --git a/toxcore/group.h b/toxcore/group.h index ab36ca34..a5b5723c 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -56,8 +56,7 @@ typedef struct { | |||
56 | 56 | ||
57 | enum { | 57 | enum { |
58 | GROUPCHAT_CLOSE_NONE, | 58 | GROUPCHAT_CLOSE_NONE, |
59 | GROUPCHAT_CLOSE_FRIEND, | 59 | GROUPCHAT_CLOSE_CONNECTION |
60 | GROUPCHAT_CLOSE_GROUPCON | ||
61 | }; | 60 | }; |
62 | 61 | ||
63 | typedef struct { | 62 | typedef struct { |