summaryrefslogtreecommitdiff
path: root/toxcore/group.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-09-27 20:01:41 -0400
committerirungentoo <irungentoo@gmail.com>2014-09-27 20:01:41 -0400
commit230a65c91fa6e58f32d67cc21547fe507eedaeee (patch)
treec6372e3c34a324e3c4ea65ff8ecf2e9c00fb6947 /toxcore/group.c
parent964fcacb321c24dc51a9df2380021a9c59521c52 (diff)
Removed send_group_message_packet and its callback function from
Messenger.
Diffstat (limited to 'toxcore/group.c')
-rw-r--r--toxcore/group.c55
1 files changed, 51 insertions, 4 deletions
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
226static 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 */
314int 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
675static 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. */
653Group_Chats *new_groupchats(Messenger *m) 701Group_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}