diff options
-rw-r--r-- | toxcore/Messenger.c | 12 | ||||
-rw-r--r-- | toxcore/Messenger.h | 7 | ||||
-rw-r--r-- | toxcore/group.c | 52 |
3 files changed, 43 insertions, 28 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 75210830..d5ab6ee1 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -123,6 +123,18 @@ int getclient_id(const Messenger *m, int32_t friendnumber, uint8_t *client_id) | |||
123 | 123 | ||
124 | return -1; | 124 | return -1; |
125 | } | 125 | } |
126 | |||
127 | /* return friend connection id on success. | ||
128 | * return -1 if failure. | ||
129 | */ | ||
130 | int getfriendcon_id(const Messenger *m, int32_t friendnumber) | ||
131 | { | ||
132 | if (friend_not_valid(m, friendnumber)) | ||
133 | return -1; | ||
134 | |||
135 | return m->friendlist[friendnumber].friendcon_id; | ||
136 | } | ||
137 | |||
126 | /* TODO: Another checksum algorithm might be better. | 138 | /* TODO: Another checksum algorithm might be better. |
127 | * | 139 | * |
128 | * return a uint16_t that represents the checksum of address of length len. | 140 | * return a uint16_t that represents the checksum of address of length len. |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 4a5a5ae7..cc09afe3 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -58,7 +58,7 @@ | |||
58 | #define PACKET_ID_FILE_CONTROL 81 | 58 | #define PACKET_ID_FILE_CONTROL 81 |
59 | #define PACKET_ID_FILE_DATA 82 | 59 | #define PACKET_ID_FILE_DATA 82 |
60 | #define PACKET_ID_INVITE_GROUPCHAT 96 | 60 | #define PACKET_ID_INVITE_GROUPCHAT 96 |
61 | #define PACKET_ID_MESSAGE_GROUPCHAT 97 | 61 | #define PACKET_ID_MESSAGE_GROUPCHAT 98 |
62 | 62 | ||
63 | 63 | ||
64 | /* Max number of tcp relays sent to friends */ | 64 | /* Max number of tcp relays sent to friends */ |
@@ -352,6 +352,11 @@ int32_t getfriend_id(const Messenger *m, const uint8_t *client_id); | |||
352 | */ | 352 | */ |
353 | int getclient_id(const Messenger *m, int32_t friendnumber, uint8_t *client_id); | 353 | int getclient_id(const Messenger *m, int32_t friendnumber, uint8_t *client_id); |
354 | 354 | ||
355 | /* return friend connection id on success. | ||
356 | * return -1 if failure. | ||
357 | */ | ||
358 | int getfriendcon_id(const Messenger *m, int32_t friendnumber); | ||
359 | |||
355 | /* Remove a friend. | 360 | /* Remove a friend. |
356 | * | 361 | * |
357 | * return 0 if success | 362 | * return 0 if success |
diff --git a/toxcore/group.c b/toxcore/group.c index d5244f65..ce590015 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -223,6 +223,15 @@ 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_status(void *object, int number, uint8_t status) | ||
227 | { | ||
228 | if (status) { /* Went online */ | ||
229 | |||
230 | } else { /* Went offline */ | ||
231 | |||
232 | } | ||
233 | } | ||
234 | |||
226 | static int handle_packet(void *object, int number, uint8_t *data, uint16_t length); | 235 | static int handle_packet(void *object, int number, uint8_t *data, uint16_t length); |
227 | 236 | ||
228 | /* Add friend to group chat. | 237 | /* Add friend to group chat. |
@@ -230,11 +239,8 @@ static int handle_packet(void *object, int number, uint8_t *data, uint16_t lengt | |||
230 | * return 0 on success | 239 | * return 0 on success |
231 | * return -1 on failure. | 240 | * return -1 on failure. |
232 | */ | 241 | */ |
233 | static int add_friend_to_groupchat(Group_Chats *g_c, int32_t friendnumber, int groupnumber, uint16_t other_groupnum) | 242 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, int groupnumber, uint16_t other_groupnum) |
234 | { | 243 | { |
235 | if (!m_friend_exists(g_c->m, friendnumber)) | ||
236 | return -1; | ||
237 | |||
238 | Group_c *g = get_group_c(g_c, groupnumber); | 244 | Group_c *g = get_group_c(g_c, groupnumber); |
239 | 245 | ||
240 | if (!g) | 246 | if (!g) |
@@ -248,7 +254,7 @@ static int add_friend_to_groupchat(Group_Chats *g_c, int32_t friendnumber, int g | |||
248 | continue; | 254 | continue; |
249 | } | 255 | } |
250 | 256 | ||
251 | if (g->close[i].type == GROUPCHAT_CLOSE_CONNECTION && g->close[i].number == (uint32_t)friendnumber) { | 257 | if (g->close[i].type == GROUPCHAT_CLOSE_CONNECTION && g->close[i].number == (uint32_t)friendcon_id) { |
252 | g->close[i].group_number = other_groupnum; /* update groupnum. */ | 258 | g->close[i].group_number = other_groupnum; /* update groupnum. */ |
253 | return 0; /* Already in list. */ | 259 | return 0; /* Already in list. */ |
254 | } | 260 | } |
@@ -260,12 +266,11 @@ static int add_friend_to_groupchat(Group_Chats *g_c, int32_t friendnumber, int g | |||
260 | return -1; | 266 | return -1; |
261 | 267 | ||
262 | g->close[ind].type = GROUPCHAT_CLOSE_CONNECTION; | 268 | g->close[ind].type = GROUPCHAT_CLOSE_CONNECTION; |
263 | g->close[ind].number = friendnumber; | 269 | g->close[ind].number = friendcon_id; |
264 | g->close[ind].group_number = other_groupnum; | 270 | g->close[ind].group_number = other_groupnum; |
265 | int friendcon_id = g_c->m->friendlist[friendnumber].friendcon_id; | ||
266 | //TODO | 271 | //TODO |
267 | friend_connection_callbacks(g_c->m->fr_c, friendcon_id, GROUPCHAT_CALLBACK_INDEX, 0, &handle_packet, 0, g_c->m, | 272 | friend_connection_callbacks(g_c->m->fr_c, friendcon_id, GROUPCHAT_CALLBACK_INDEX, &handle_status, &handle_packet, 0, |
268 | friendnumber); | 273 | g_c, friendcon_id); |
269 | 274 | ||
270 | return 0; | 275 | return 0; |
271 | } | 276 | } |
@@ -311,7 +316,7 @@ int del_groupchat(Group_Chats *g_c, int groupnumber) | |||
311 | * return 1 on success | 316 | * return 1 on success |
312 | * return 0 on failure | 317 | * return 0 on failure |
313 | */ | 318 | */ |
314 | int send_group_message_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length) | 319 | int send_group_message_packet(const Messenger *m, int friendcon_id, const uint8_t *data, uint16_t length) |
315 | { | 320 | { |
316 | if (length >= MAX_CRYPTO_DATA_SIZE) | 321 | if (length >= MAX_CRYPTO_DATA_SIZE) |
317 | return 0; | 322 | return 0; |
@@ -319,8 +324,8 @@ int send_group_message_packet(const Messenger *m, int32_t friendnumber, const ui | |||
319 | uint8_t packet[1 + length]; | 324 | uint8_t packet[1 + length]; |
320 | packet[0] = PACKET_ID_MESSAGE_GROUPCHAT; | 325 | packet[0] = PACKET_ID_MESSAGE_GROUPCHAT; |
321 | memcpy(packet + 1, data, length); | 326 | memcpy(packet + 1, data, length); |
322 | return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, | 327 | return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet, |
323 | m->friendlist[friendnumber].friendcon_id), packet, sizeof(packet), 0) != -1; | 328 | sizeof(packet), 0) != -1; |
324 | } | 329 | } |
325 | 330 | ||
326 | #define INVITE_PACKET_SIZE (1 + sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) | 331 | #define INVITE_PACKET_SIZE (1 + sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) |
@@ -383,7 +388,7 @@ int join_groupchat(Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, | |||
383 | memcpy(&other_groupnum, data, sizeof(other_groupnum)); | 388 | memcpy(&other_groupnum, data, sizeof(other_groupnum)); |
384 | other_groupnum = htons(other_groupnum); | 389 | other_groupnum = htons(other_groupnum); |
385 | memcpy(g->identifier, data + sizeof(uint16_t), GROUP_IDENTIFIER_LENGTH); | 390 | memcpy(g->identifier, data + sizeof(uint16_t), GROUP_IDENTIFIER_LENGTH); |
386 | add_friend_to_groupchat(g_c, friendnumber, groupnumber, other_groupnum); | 391 | add_conn_to_groupchat(g_c, getfriendcon_id(g_c->m, friendnumber), groupnumber, other_groupnum); |
387 | g->peer_number = rand(); /* TODO */ | 392 | g->peer_number = rand(); /* TODO */ |
388 | return groupnumber; | 393 | return groupnumber; |
389 | } else { | 394 | } else { |
@@ -442,7 +447,7 @@ static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, cons | |||
442 | uint16_t other_groupnum; | 447 | uint16_t other_groupnum; |
443 | memcpy(&other_groupnum, data + 1, sizeof(uint16_t)); | 448 | memcpy(&other_groupnum, data + 1, sizeof(uint16_t)); |
444 | other_groupnum = ntohs(other_groupnum); | 449 | other_groupnum = ntohs(other_groupnum); |
445 | add_friend_to_groupchat(g_c, friendnumber, groupnumber, other_groupnum); | 450 | add_conn_to_groupchat(g_c, getfriendcon_id(m, friendnumber), groupnumber, other_groupnum); |
446 | } | 451 | } |
447 | 452 | ||
448 | break; | 453 | break; |
@@ -467,7 +472,7 @@ static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, cons | |||
467 | memcpy(&other_groupnum, data + 1, sizeof(uint16_t)); | 472 | memcpy(&other_groupnum, data + 1, sizeof(uint16_t)); |
468 | other_groupnum = ntohs(other_groupnum); | 473 | other_groupnum = ntohs(other_groupnum); |
469 | 474 | ||
470 | add_friend_to_groupchat(g_c, friendnumber, groupnum, other_groupnum); | 475 | add_conn_to_groupchat(g_c, getfriendcon_id(m, friendnumber), groupnum, other_groupnum); |
471 | 476 | ||
472 | break; | 477 | break; |
473 | } | 478 | } |
@@ -482,7 +487,7 @@ static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, cons | |||
482 | * returns index on success | 487 | * returns index on success |
483 | * returns -1 on failure. | 488 | * returns -1 on failure. |
484 | */ | 489 | */ |
485 | static int friend_in_close(Group_c *g, int32_t friendnumber) | 490 | static int friend_in_close(Group_c *g, int friendcon_id) |
486 | { | 491 | { |
487 | int i; | 492 | int i; |
488 | 493 | ||
@@ -490,7 +495,7 @@ static int friend_in_close(Group_c *g, int32_t friendnumber) | |||
490 | if (g->close[i].type != GROUPCHAT_CLOSE_CONNECTION) | 495 | if (g->close[i].type != GROUPCHAT_CLOSE_CONNECTION) |
491 | continue; | 496 | continue; |
492 | 497 | ||
493 | if (g->close[i].number != (uint32_t)friendnumber) | 498 | if (g->close[i].number != (uint32_t)friendcon_id) |
494 | continue; | 499 | continue; |
495 | 500 | ||
496 | return i; | 501 | return i; |
@@ -649,10 +654,8 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const | |||
649 | send_message_all_close(g_c, groupnumber, data + sizeof(uint16_t), length - sizeof(uint16_t), close_index); | 654 | send_message_all_close(g_c, groupnumber, data + sizeof(uint16_t), length - sizeof(uint16_t), close_index); |
650 | } | 655 | } |
651 | 656 | ||
652 | static void handle_friend_message_packet(Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length) | 657 | static void handle_message_packet(Group_Chats *g_c, int friendcon_id, const uint8_t *data, uint16_t length) |
653 | { | 658 | { |
654 | Group_Chats *g_c = m->group_chat_object; | ||
655 | |||
656 | if (length < MIN_MESSAGE_PACKET_LEN) | 659 | if (length < MIN_MESSAGE_PACKET_LEN) |
657 | return; | 660 | return; |
658 | 661 | ||
@@ -664,7 +667,7 @@ static void handle_friend_message_packet(Messenger *m, int32_t friendnumber, con | |||
664 | if (!g) | 667 | if (!g) |
665 | return; | 668 | return; |
666 | 669 | ||
667 | int index = friend_in_close(g, friendnumber); | 670 | int index = friend_in_close(g, friendcon_id); |
668 | 671 | ||
669 | if (index == -1) | 672 | if (index == -1) |
670 | return; | 673 | return; |
@@ -678,13 +681,8 @@ static int handle_packet(void *object, int number, uint8_t *data, uint16_t lengt | |||
678 | return -1; | 681 | return -1; |
679 | 682 | ||
680 | switch (data[0]) { | 683 | 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: { | 684 | case PACKET_ID_MESSAGE_GROUPCHAT: { |
687 | handle_friend_message_packet(object, number, data + 1, length - 1); | 685 | handle_message_packet(object, number, data + 1, length - 1); |
688 | break; | 686 | break; |
689 | } | 687 | } |
690 | 688 | ||