diff options
-rw-r--r-- | toxav/groupav.c | 43 | ||||
-rw-r--r-- | toxav/groupav.h | 13 | ||||
-rw-r--r-- | toxav/toxav.api.h | 16 | ||||
-rw-r--r-- | toxav/toxav.h | 18 | ||||
-rw-r--r-- | toxav/toxav_old.c | 17 | ||||
-rw-r--r-- | toxcore/group.c | 138 | ||||
-rw-r--r-- | toxcore/group.h | 77 | ||||
-rw-r--r-- | toxcore/tox.c | 3 |
8 files changed, 174 insertions, 151 deletions
diff --git a/toxav/groupav.c b/toxav/groupav.c index c19c1b3c..e9595b4e 100644 --- a/toxav/groupav.c +++ b/toxav/groupav.c | |||
@@ -164,7 +164,7 @@ typedef struct { | |||
164 | 164 | ||
165 | uint16_t audio_sequnum; | 165 | uint16_t audio_sequnum; |
166 | 166 | ||
167 | void (*audio_data)(Messenger *m, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, | 167 | void (*audio_data)(Messenger *m, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, uint32_t samples, |
168 | uint8_t channels, unsigned int sample_rate, void *userdata); | 168 | uint8_t channels, unsigned int sample_rate, void *userdata); |
169 | void *userdata; | 169 | void *userdata; |
170 | } Group_AV; | 170 | } Group_AV; |
@@ -224,9 +224,8 @@ static int recreate_encoder(Group_AV *group_av) | |||
224 | return 0; | 224 | return 0; |
225 | } | 225 | } |
226 | 226 | ||
227 | static Group_AV *new_group_av(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, int, int, | 227 | static Group_AV *new_group_av(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, uint32_t, |
228 | const int16_t *, | 228 | const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata) |
229 | unsigned int, uint8_t, unsigned int, void *), void *userdata) | ||
230 | { | 229 | { |
231 | if (!g_c) { | 230 | if (!g_c) { |
232 | return nullptr; | 231 | return nullptr; |
@@ -247,7 +246,7 @@ static Group_AV *new_group_av(Logger *log, Group_Chats *g_c, void (*audio_callba | |||
247 | return group_av; | 246 | return group_av; |
248 | } | 247 | } |
249 | 248 | ||
250 | static void group_av_peer_new(void *object, int groupnumber, int friendgroupnumber) | 249 | static void group_av_peer_new(void *object, uint32_t groupnumber, uint32_t friendgroupnumber) |
251 | { | 250 | { |
252 | Group_AV *group_av = (Group_AV *)object; | 251 | Group_AV *group_av = (Group_AV *)object; |
253 | Group_Peer_AV *peer_av = (Group_Peer_AV *)calloc(1, sizeof(Group_Peer_AV)); | 252 | Group_Peer_AV *peer_av = (Group_Peer_AV *)calloc(1, sizeof(Group_Peer_AV)); |
@@ -260,7 +259,7 @@ static void group_av_peer_new(void *object, int groupnumber, int friendgroupnumb | |||
260 | group_peer_set_object(group_av->g_c, groupnumber, friendgroupnumber, peer_av); | 259 | group_peer_set_object(group_av->g_c, groupnumber, friendgroupnumber, peer_av); |
261 | } | 260 | } |
262 | 261 | ||
263 | static void group_av_peer_delete(void *object, int groupnumber, int friendgroupnumber, void *peer_object) | 262 | static void group_av_peer_delete(void *object, uint32_t groupnumber, uint32_t friendgroupnumber, void *peer_object) |
264 | { | 263 | { |
265 | Group_Peer_AV *peer_av = (Group_Peer_AV *)peer_object; | 264 | Group_Peer_AV *peer_av = (Group_Peer_AV *)peer_object; |
266 | 265 | ||
@@ -276,14 +275,15 @@ static void group_av_peer_delete(void *object, int groupnumber, int friendgroupn | |||
276 | free(peer_object); | 275 | free(peer_object); |
277 | } | 276 | } |
278 | 277 | ||
279 | static void group_av_groupchat_delete(void *object, int groupnumber) | 278 | static void group_av_groupchat_delete(void *object, uint32_t groupnumber) |
280 | { | 279 | { |
281 | if (object) { | 280 | if (object) { |
282 | kill_group_av((Group_AV *)object); | 281 | kill_group_av((Group_AV *)object); |
283 | } | 282 | } |
284 | } | 283 | } |
285 | 284 | ||
286 | static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int groupnumber, int friendgroupnumber) | 285 | static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint32_t groupnumber, |
286 | uint32_t friendgroupnumber) | ||
287 | { | 287 | { |
288 | if (!group_av || !peer_av) { | 288 | if (!group_av || !peer_av) { |
289 | return -1; | 289 | return -1; |
@@ -388,7 +388,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g | |||
388 | return -1; | 388 | return -1; |
389 | } | 389 | } |
390 | 390 | ||
391 | static int handle_group_audio_packet(void *object, int groupnumber, int friendgroupnumber, void *peer_object, | 391 | static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_t friendgroupnumber, void *peer_object, |
392 | const uint8_t *packet, uint16_t length) | 392 | const uint8_t *packet, uint16_t length) |
393 | { | 393 | { |
394 | if (!peer_object || !object || length <= sizeof(uint16_t)) { | 394 | if (!peer_object || !object || length <= sizeof(uint16_t)) { |
@@ -426,14 +426,10 @@ static int handle_group_audio_packet(void *object, int groupnumber, int friendgr | |||
426 | * return 0 on success. | 426 | * return 0 on success. |
427 | * return -1 on failure. | 427 | * return -1 on failure. |
428 | */ | 428 | */ |
429 | static int groupchat_enable_av(Logger *log, Group_Chats *g_c, int groupnumber, void (*audio_callback)(Messenger *, int, | 429 | static int groupchat_enable_av(Logger *log, Group_Chats *g_c, uint32_t groupnumber, void (*audio_callback)(Messenger *, |
430 | int, | 430 | uint32_t, |
431 | const int16_t *, unsigned int, uint8_t, unsigned int, void *), void *userdata) | 431 | uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata) |
432 | { | 432 | { |
433 | if (groupnumber == -1) { | ||
434 | return -1; | ||
435 | } | ||
436 | |||
437 | Group_AV *group_av = new_group_av(log, g_c, audio_callback, userdata); | 433 | Group_AV *group_av = new_group_av(log, g_c, audio_callback, userdata); |
438 | 434 | ||
439 | if (group_av == nullptr) { | 435 | if (group_av == nullptr) { |
@@ -457,9 +453,10 @@ static int groupchat_enable_av(Logger *log, Group_Chats *g_c, int groupnumber, v | |||
457 | * return group number on success. | 453 | * return group number on success. |
458 | * return -1 on failure. | 454 | * return -1 on failure. |
459 | */ | 455 | */ |
460 | int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, int, int, const int16_t *, | 456 | int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, uint32_t, |
457 | const int16_t *, | ||
461 | unsigned int, | 458 | unsigned int, |
462 | uint8_t, unsigned int, void *), void *userdata) | 459 | uint8_t, uint32_t, void *), void *userdata) |
463 | { | 460 | { |
464 | int groupnumber = add_groupchat(g_c, GROUPCHAT_TYPE_AV); | 461 | int groupnumber = add_groupchat(g_c, GROUPCHAT_TYPE_AV); |
465 | 462 | ||
@@ -480,8 +477,8 @@ int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messe | |||
480 | * returns group number on success | 477 | * returns group number on success |
481 | * returns -1 on failure. | 478 | * returns -1 on failure. |
482 | */ | 479 | */ |
483 | int join_av_groupchat(Logger *log, Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, uint16_t length, | 480 | int join_av_groupchat(Logger *log, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data, uint16_t length, |
484 | void (*audio_callback)(Messenger *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), | 481 | void (*audio_callback)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), |
485 | void *userdata) | 482 | void *userdata) |
486 | { | 483 | { |
487 | int groupnumber = join_groupchat(g_c, friendnumber, GROUPCHAT_TYPE_AV, data, length); | 484 | int groupnumber = join_groupchat(g_c, friendnumber, GROUPCHAT_TYPE_AV, data, length); |
@@ -503,7 +500,7 @@ int join_av_groupchat(Logger *log, Group_Chats *g_c, int32_t friendnumber, const | |||
503 | * return 0 on success. | 500 | * return 0 on success. |
504 | * return -1 on failure. | 501 | * return -1 on failure. |
505 | */ | 502 | */ |
506 | static int send_audio_packet(Group_Chats *g_c, int groupnumber, uint8_t *packet, uint16_t length) | 503 | static int send_audio_packet(Group_Chats *g_c, uint32_t groupnumber, uint8_t *packet, uint16_t length) |
507 | { | 504 | { |
508 | if (!length) { | 505 | if (!length) { |
509 | return -1; | 506 | return -1; |
@@ -530,8 +527,8 @@ static int send_audio_packet(Group_Chats *g_c, int groupnumber, uint8_t *packet, | |||
530 | * return 0 on success. | 527 | * return 0 on success. |
531 | * return -1 on failure. | 528 | * return -1 on failure. |
532 | */ | 529 | */ |
533 | int group_send_audio(Group_Chats *g_c, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, | 530 | int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, |
534 | unsigned int sample_rate) | 531 | uint32_t sample_rate) |
535 | { | 532 | { |
536 | Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber); | 533 | Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber); |
537 | 534 | ||
diff --git a/toxav/groupav.h b/toxav/groupav.h index 71b0f55a..142edb0e 100644 --- a/toxav/groupav.h +++ b/toxav/groupav.h | |||
@@ -29,17 +29,16 @@ | |||
29 | * return group number on success. | 29 | * return group number on success. |
30 | * return -1 on failure. | 30 | * return -1 on failure. |
31 | */ | 31 | */ |
32 | int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, int, int, const int16_t *, | 32 | int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, uint32_t, |
33 | unsigned int, | 33 | const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata); |
34 | uint8_t, unsigned int, void *), void *userdata); | ||
35 | 34 | ||
36 | /* Join a AV group (you need to have been invited first.) | 35 | /* Join a AV group (you need to have been invited first.) |
37 | * | 36 | * |
38 | * returns group number on success | 37 | * returns group number on success |
39 | * returns -1 on failure. | 38 | * returns -1 on failure. |
40 | */ | 39 | */ |
41 | int join_av_groupchat(Logger *log, Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, uint16_t length, | 40 | int join_av_groupchat(Logger *log, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data, uint16_t length, |
42 | void (*audio_callback)(Messenger *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), | 41 | void (*audio_callback)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), |
43 | void *userdata); | 42 | void *userdata); |
44 | 43 | ||
45 | 44 | ||
@@ -48,6 +47,6 @@ int join_av_groupchat(Logger *log, Group_Chats *g_c, int32_t friendnumber, const | |||
48 | * return 0 on success. | 47 | * return 0 on success. |
49 | * return -1 on failure. | 48 | * return -1 on failure. |
50 | */ | 49 | */ |
51 | int group_send_audio(Group_Chats *g_c, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, | 50 | int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, |
52 | unsigned int sample_rate); | 51 | uint32_t sample_rate); |
53 | 52 | ||
diff --git a/toxav/toxav.api.h b/toxav/toxav.api.h index 71cd5aec..9e6cea68 100644 --- a/toxav/toxav.api.h +++ b/toxav/toxav.api.h | |||
@@ -612,12 +612,12 @@ namespace video { | |||
612 | * return -1 on failure. | 612 | * return -1 on failure. |
613 | * | 613 | * |
614 | * Audio data callback format: | 614 | * Audio data callback format: |
615 | * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) | 615 | * audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata) |
616 | * | 616 | * |
617 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | 617 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). |
618 | */ | 618 | */ |
619 | int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, | 619 | int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, |
620 | unsigned int, void *), void *userdata); | 620 | uint32_t, void *), void *userdata); |
621 | 621 | ||
622 | /* Join a AV group (you need to have been invited first.) | 622 | /* Join a AV group (you need to have been invited first.) |
623 | * | 623 | * |
@@ -625,12 +625,12 @@ int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, co | |||
625 | * returns -1 on failure. | 625 | * returns -1 on failure. |
626 | * | 626 | * |
627 | * Audio data callback format (same as the one for toxav_add_av_groupchat()): | 627 | * Audio data callback format (same as the one for toxav_add_av_groupchat()): |
628 | * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) | 628 | * audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata) |
629 | * | 629 | * |
630 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | 630 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). |
631 | */ | 631 | */ |
632 | int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length, | 632 | int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data, uint16_t length, |
633 | void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), void *userdata); | 633 | void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata); |
634 | 634 | ||
635 | /* Send audio to the group chat. | 635 | /* Send audio to the group chat. |
636 | * | 636 | * |
@@ -645,8 +645,8 @@ int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, | |||
645 | * | 645 | * |
646 | * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 | 646 | * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 |
647 | */ | 647 | */ |
648 | int toxav_group_send_audio(Tox *tox, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, | 648 | int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, |
649 | unsigned int sample_rate); | 649 | uint32_t sample_rate); |
650 | 650 | ||
651 | #ifdef __cplusplus | 651 | #ifdef __cplusplus |
652 | } | 652 | } |
diff --git a/toxav/toxav.h b/toxav/toxav.h index 1f2d6860..911d6b49 100644 --- a/toxav/toxav.h +++ b/toxav/toxav.h | |||
@@ -740,12 +740,13 @@ void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb | |||
740 | * return -1 on failure. | 740 | * return -1 on failure. |
741 | * | 741 | * |
742 | * Audio data callback format: | 742 | * Audio data callback format: |
743 | * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) | 743 | * audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata) |
744 | * | 744 | * |
745 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | 745 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). |
746 | */ | 746 | */ |
747 | int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, | 747 | int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, |
748 | unsigned int, void *), void *userdata); | 748 | uint8_t, |
749 | uint32_t, void *), void *userdata); | ||
749 | 750 | ||
750 | /* Join a AV group (you need to have been invited first.) | 751 | /* Join a AV group (you need to have been invited first.) |
751 | * | 752 | * |
@@ -753,12 +754,13 @@ int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, co | |||
753 | * returns -1 on failure. | 754 | * returns -1 on failure. |
754 | * | 755 | * |
755 | * Audio data callback format (same as the one for toxav_add_av_groupchat()): | 756 | * Audio data callback format (same as the one for toxav_add_av_groupchat()): |
756 | * audio_callback(Tox *tox, int groupnumber, int peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, unsigned int sample_rate, void *userdata) | 757 | * audio_callback(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm, unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata) |
757 | * | 758 | * |
758 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | 759 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). |
759 | */ | 760 | */ |
760 | int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length, | 761 | int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data, uint16_t length, |
761 | void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), void *userdata); | 762 | void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), |
763 | void *userdata); | ||
762 | 764 | ||
763 | /* Send audio to the group chat. | 765 | /* Send audio to the group chat. |
764 | * | 766 | * |
@@ -773,8 +775,8 @@ int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, | |||
773 | * | 775 | * |
774 | * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 | 776 | * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 |
775 | */ | 777 | */ |
776 | int toxav_group_send_audio(Tox *tox, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, | 778 | int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, |
777 | unsigned int sample_rate); | 779 | uint32_t sample_rate); |
778 | 780 | ||
779 | #ifdef __cplusplus | 781 | #ifdef __cplusplus |
780 | } | 782 | } |
diff --git a/toxav/toxav_old.c b/toxav/toxav_old.c index 10d1c72d..d5278623 100644 --- a/toxav/toxav_old.c +++ b/toxav/toxav_old.c | |||
@@ -35,12 +35,12 @@ | |||
35 | * | 35 | * |
36 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | 36 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). |
37 | */ | 37 | */ |
38 | int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, | 38 | int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, uint32_t, uint32_t, const int16_t *, unsigned int, |
39 | uint8_t, unsigned int, void *), void *userdata) | 39 | uint8_t, uint32_t, void *), void *userdata) |
40 | { | 40 | { |
41 | Messenger *m = (Messenger *)tox; | 41 | Messenger *m = (Messenger *)tox; |
42 | return add_av_groupchat(m->log, (Group_Chats *)m->conferences_object, | 42 | return add_av_groupchat(m->log, (Group_Chats *)m->conferences_object, |
43 | (void (*)(Messenger *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *))audio_callback, | 43 | (void (*)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *))audio_callback, |
44 | userdata); | 44 | userdata); |
45 | } | 45 | } |
46 | 46 | ||
@@ -54,13 +54,14 @@ int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, co | |||
54 | * | 54 | * |
55 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). | 55 | * Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)). |
56 | */ | 56 | */ |
57 | int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length, | 57 | int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data, uint16_t length, |
58 | void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), | 58 | void (*audio_callback) |
59 | (void *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), | ||
59 | void *userdata) | 60 | void *userdata) |
60 | { | 61 | { |
61 | Messenger *m = (Messenger *)tox; | 62 | Messenger *m = (Messenger *)tox; |
62 | return join_av_groupchat(m->log, (Group_Chats *)m->conferences_object, friendnumber, data, length, | 63 | return join_av_groupchat(m->log, (Group_Chats *)m->conferences_object, friendnumber, data, length, |
63 | (void (*)(Messenger *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *))audio_callback, | 64 | (void (*)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *))audio_callback, |
64 | userdata); | 65 | userdata); |
65 | } | 66 | } |
66 | 67 | ||
@@ -77,8 +78,8 @@ int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, | |||
77 | * | 78 | * |
78 | * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 | 79 | * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 |
79 | */ | 80 | */ |
80 | int toxav_group_send_audio(Tox *tox, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, | 81 | int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, |
81 | unsigned int sample_rate) | 82 | uint32_t sample_rate) |
82 | { | 83 | { |
83 | Messenger *m = (Messenger *)tox; | 84 | Messenger *m = (Messenger *)tox; |
84 | return group_send_audio((Group_Chats *)m->conferences_object, groupnumber, pcm, samples, channels, sample_rate); | 85 | return group_send_audio((Group_Chats *)m->conferences_object, groupnumber, pcm, samples, channels, sample_rate); |
diff --git a/toxcore/group.c b/toxcore/group.c index 2dc22501..c9e4feff 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -32,9 +32,9 @@ | |||
32 | /* return 1 if the groupnumber is not valid. | 32 | /* return 1 if the groupnumber is not valid. |
33 | * return 0 if the groupnumber is valid. | 33 | * return 0 if the groupnumber is valid. |
34 | */ | 34 | */ |
35 | static uint8_t groupnumber_not_valid(const Group_Chats *g_c, int groupnumber) | 35 | static uint8_t groupnumber_not_valid(const Group_Chats *g_c, uint32_t groupnumber) |
36 | { | 36 | { |
37 | if ((unsigned int)groupnumber >= g_c->num_chats) { | 37 | if (groupnumber >= g_c->num_chats) { |
38 | return 1; | 38 | return 1; |
39 | } | 39 | } |
40 | 40 | ||
@@ -106,7 +106,7 @@ static int create_group_chat(Group_Chats *g_c) | |||
106 | * return -1 on failure. | 106 | * return -1 on failure. |
107 | * return 0 on success. | 107 | * return 0 on success. |
108 | */ | 108 | */ |
109 | static int wipe_group_chat(Group_Chats *g_c, int groupnumber) | 109 | static int wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber) |
110 | { | 110 | { |
111 | if (groupnumber_not_valid(g_c, groupnumber)) { | 111 | if (groupnumber_not_valid(g_c, groupnumber)) { |
112 | return -1; | 112 | return -1; |
@@ -129,7 +129,7 @@ static int wipe_group_chat(Group_Chats *g_c, int groupnumber) | |||
129 | return 0; | 129 | return 0; |
130 | } | 130 | } |
131 | 131 | ||
132 | static Group_c *get_group_c(const Group_Chats *g_c, int groupnumber) | 132 | static Group_c *get_group_c(const Group_Chats *g_c, uint32_t groupnumber) |
133 | { | 133 | { |
134 | if (groupnumber_not_valid(g_c, groupnumber)) { | 134 | if (groupnumber_not_valid(g_c, groupnumber)) { |
135 | return nullptr; | 135 | return nullptr; |
@@ -224,9 +224,10 @@ enum { | |||
224 | }; | 224 | }; |
225 | 225 | ||
226 | static int friend_in_close(Group_c *g, int friendcon_id); | 226 | static int friend_in_close(Group_c *g, int friendcon_id); |
227 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, int groupnumber, uint8_t closest, uint8_t lock); | 227 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, uint32_t groupnumber, uint8_t closest, |
228 | uint8_t lock); | ||
228 | 229 | ||
229 | static int add_to_closest(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk) | 230 | static int add_to_closest(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk) |
230 | { | 231 | { |
231 | Group_c *g = get_group_c(g_c, groupnumber); | 232 | Group_c *g = get_group_c(g_c, groupnumber); |
232 | 233 | ||
@@ -328,7 +329,7 @@ static unsigned int pk_in_closest_peers(Group_c *g, uint8_t *real_pk) | |||
328 | 329 | ||
329 | static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier); | 330 | static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier); |
330 | 331 | ||
331 | static int connect_to_closest(Group_Chats *g_c, int groupnumber, void *userdata) | 332 | static int connect_to_closest(Group_Chats *g_c, uint32_t groupnumber, void *userdata) |
332 | { | 333 | { |
333 | Group_c *g = get_group_c(g_c, groupnumber); | 334 | Group_c *g = get_group_c(g_c, groupnumber); |
334 | 335 | ||
@@ -408,7 +409,7 @@ static int connect_to_closest(Group_Chats *g_c, int groupnumber, void *userdata) | |||
408 | * return peer_index if success or peer already in chat. | 409 | * return peer_index if success or peer already in chat. |
409 | * return -1 if error. | 410 | * return -1 if error. |
410 | */ | 411 | */ |
411 | static int addpeer(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk, | 412 | static int addpeer(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk, |
412 | uint16_t peer_number, void *userdata, bool do_gc_callback) | 413 | uint16_t peer_number, void *userdata, bool do_gc_callback) |
413 | { | 414 | { |
414 | Group_c *g = get_group_c(g_c, groupnumber); | 415 | Group_c *g = get_group_c(g_c, groupnumber); |
@@ -465,7 +466,7 @@ static int addpeer(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, co | |||
465 | return (g->numpeers - 1); | 466 | return (g->numpeers - 1); |
466 | } | 467 | } |
467 | 468 | ||
468 | static int remove_close_conn(Group_Chats *g_c, int groupnumber, int friendcon_id) | 469 | static int remove_close_conn(Group_Chats *g_c, uint32_t groupnumber, int friendcon_id) |
469 | { | 470 | { |
470 | Group_c *g = get_group_c(g_c, groupnumber); | 471 | Group_c *g = get_group_c(g_c, groupnumber); |
471 | 472 | ||
@@ -497,7 +498,7 @@ static int remove_close_conn(Group_Chats *g_c, int groupnumber, int friendcon_id | |||
497 | * return 0 if success | 498 | * return 0 if success |
498 | * return -1 if error. | 499 | * return -1 if error. |
499 | */ | 500 | */ |
500 | static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index, void *userdata) | 501 | static int delpeer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void *userdata) |
501 | { | 502 | { |
502 | Group_c *g = get_group_c(g_c, groupnumber); | 503 | Group_c *g = get_group_c(g_c, groupnumber); |
503 | 504 | ||
@@ -562,7 +563,7 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index, void *user | |||
562 | * return 0 on success. | 563 | * return 0 on success. |
563 | * return -1 if error. | 564 | * return -1 if error. |
564 | */ | 565 | */ |
565 | static int setnick(Group_Chats *g_c, int groupnumber, int peer_index, const uint8_t *nick, uint16_t nick_len, | 566 | static int setnick(Group_Chats *g_c, uint32_t groupnumber, int peer_index, const uint8_t *nick, uint16_t nick_len, |
566 | void *userdata, bool do_gc_callback) | 567 | void *userdata, bool do_gc_callback) |
567 | { | 568 | { |
568 | if (nick_len > MAX_NAME_LENGTH) { | 569 | if (nick_len > MAX_NAME_LENGTH) { |
@@ -595,7 +596,7 @@ static int setnick(Group_Chats *g_c, int groupnumber, int peer_index, const uint | |||
595 | return 0; | 596 | return 0; |
596 | } | 597 | } |
597 | 598 | ||
598 | static int settitle(Group_Chats *g_c, int groupnumber, int peer_index, const uint8_t *title, uint8_t title_len, | 599 | static int settitle(Group_Chats *g_c, uint32_t groupnumber, int peer_index, const uint8_t *title, uint8_t title_len, |
599 | void *userdata) | 600 | void *userdata) |
600 | { | 601 | { |
601 | if (title_len > MAX_NAME_LENGTH || title_len == 0) { | 602 | if (title_len > MAX_NAME_LENGTH || title_len == 0) { |
@@ -623,7 +624,7 @@ static int settitle(Group_Chats *g_c, int groupnumber, int peer_index, const uin | |||
623 | return 0; | 624 | return 0; |
624 | } | 625 | } |
625 | 626 | ||
626 | static void set_conns_type_close(Group_Chats *g_c, int groupnumber, int friendcon_id, uint8_t type) | 627 | static void set_conns_type_close(Group_Chats *g_c, uint32_t groupnumber, int friendcon_id, uint8_t type) |
627 | { | 628 | { |
628 | Group_c *g = get_group_c(g_c, groupnumber); | 629 | Group_c *g = get_group_c(g_c, groupnumber); |
629 | 630 | ||
@@ -681,7 +682,8 @@ static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uin | |||
681 | * return close index on success | 682 | * return close index on success |
682 | * return -1 on failure. | 683 | * return -1 on failure. |
683 | */ | 684 | */ |
684 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, int groupnumber, uint8_t closest, uint8_t lock) | 685 | static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, uint32_t groupnumber, uint8_t closest, |
686 | uint8_t lock) | ||
685 | { | 687 | { |
686 | Group_c *g = get_group_c(g_c, groupnumber); | 688 | Group_c *g = get_group_c(g_c, groupnumber); |
687 | 689 | ||
@@ -755,13 +757,13 @@ int add_groupchat(Group_Chats *g_c, uint8_t type) | |||
755 | return groupnumber; | 757 | return groupnumber; |
756 | } | 758 | } |
757 | 759 | ||
758 | static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num); | 760 | static int group_kill_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num); |
759 | /* Delete a groupchat from the chats array. | 761 | /* Delete a groupchat from the chats array. |
760 | * | 762 | * |
761 | * return 0 on success. | 763 | * return 0 on success. |
762 | * return -1 if groupnumber is invalid. | 764 | * return -1 if groupnumber is invalid. |
763 | */ | 765 | */ |
764 | int del_groupchat(Group_Chats *g_c, int groupnumber) | 766 | int del_groupchat(Group_Chats *g_c, uint32_t groupnumber) |
765 | { | 767 | { |
766 | Group_c *g = get_group_c(g_c, groupnumber); | 768 | Group_c *g = get_group_c(g_c, groupnumber); |
767 | 769 | ||
@@ -804,7 +806,7 @@ int del_groupchat(Group_Chats *g_c, int groupnumber) | |||
804 | * return -1 if groupnumber is invalid. | 806 | * return -1 if groupnumber is invalid. |
805 | * return -2 if peernumber is invalid. | 807 | * return -2 if peernumber is invalid. |
806 | */ | 808 | */ |
807 | int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *pk) | 809 | int group_peer_pubkey(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *pk) |
808 | { | 810 | { |
809 | Group_c *g = get_group_c(g_c, groupnumber); | 811 | Group_c *g = get_group_c(g_c, groupnumber); |
810 | 812 | ||
@@ -826,7 +828,7 @@ int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, u | |||
826 | * return -1 if groupnumber is invalid. | 828 | * return -1 if groupnumber is invalid. |
827 | * return -2 if peernumber is invalid. | 829 | * return -2 if peernumber is invalid. |
828 | */ | 830 | */ |
829 | int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber) | 831 | int group_peername_size(const Group_Chats *g_c, uint32_t groupnumber, int peernumber) |
830 | { | 832 | { |
831 | Group_c *g = get_group_c(g_c, groupnumber); | 833 | Group_c *g = get_group_c(g_c, groupnumber); |
832 | 834 | ||
@@ -852,7 +854,7 @@ int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber) | |||
852 | * return -1 if groupnumber is invalid. | 854 | * return -1 if groupnumber is invalid. |
853 | * return -2 if peernumber is invalid. | 855 | * return -2 if peernumber is invalid. |
854 | */ | 856 | */ |
855 | int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *name) | 857 | int group_peername(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *name) |
856 | { | 858 | { |
857 | Group_c *g = get_group_c(g_c, groupnumber); | 859 | Group_c *g = get_group_c(g_c, groupnumber); |
858 | 860 | ||
@@ -883,7 +885,7 @@ int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint | |||
883 | * | 885 | * |
884 | * return -1 on failure. | 886 | * return -1 on failure. |
885 | */ | 887 | */ |
886 | int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], | 888 | int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], |
887 | uint16_t length) | 889 | uint16_t length) |
888 | { | 890 | { |
889 | Group_c *g = get_group_c(g_c, groupnumber); | 891 | Group_c *g = get_group_c(g_c, groupnumber); |
@@ -904,7 +906,7 @@ int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAM | |||
904 | /* Return the number of peers in the group chat on success. | 906 | /* Return the number of peers in the group chat on success. |
905 | * return -1 if groupnumber is invalid. | 907 | * return -1 if groupnumber is invalid. |
906 | */ | 908 | */ |
907 | int group_number_peers(const Group_Chats *g_c, int groupnumber) | 909 | int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber) |
908 | { | 910 | { |
909 | Group_c *g = get_group_c(g_c, groupnumber); | 911 | Group_c *g = get_group_c(g_c, groupnumber); |
910 | 912 | ||
@@ -921,7 +923,7 @@ int group_number_peers(const Group_Chats *g_c, int groupnumber) | |||
921 | * return -2 if peernumber is invalid. | 923 | * return -2 if peernumber is invalid. |
922 | * return -3 if we are not connected to the group chat. | 924 | * return -3 if we are not connected to the group chat. |
923 | */ | 925 | */ |
924 | int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernumber) | 926 | int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, int peernumber) |
925 | { | 927 | { |
926 | Group_c *g = get_group_c(g_c, groupnumber); | 928 | Group_c *g = get_group_c(g_c, groupnumber); |
927 | 929 | ||
@@ -945,7 +947,7 @@ int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernu | |||
945 | * return -1 on failure. | 947 | * return -1 on failure. |
946 | * return type on success. | 948 | * return type on success. |
947 | */ | 949 | */ |
948 | int group_get_type(const Group_Chats *g_c, int groupnumber) | 950 | int group_get_type(const Group_Chats *g_c, uint32_t groupnumber) |
949 | { | 951 | { |
950 | Group_c *g = get_group_c(g_c, groupnumber); | 952 | Group_c *g = get_group_c(g_c, groupnumber); |
951 | 953 | ||
@@ -1010,7 +1012,7 @@ static unsigned int send_lossy_group_peer(Friend_Connections *fr_c, int friendco | |||
1010 | * return -1 if groupnumber is invalid. | 1012 | * return -1 if groupnumber is invalid. |
1011 | * return -2 if invite packet failed to send. | 1013 | * return -2 if invite packet failed to send. |
1012 | */ | 1014 | */ |
1013 | int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber) | 1015 | int invite_friend(Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber) |
1014 | { | 1016 | { |
1015 | Group_c *g = get_group_c(g_c, groupnumber); | 1017 | Group_c *g = get_group_c(g_c, groupnumber); |
1016 | 1018 | ||
@@ -1046,7 +1048,7 @@ static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t | |||
1046 | * return -5 if group instance failed to initialize. | 1048 | * return -5 if group instance failed to initialize. |
1047 | * return -6 if join packet fails to send. | 1049 | * return -6 if join packet fails to send. |
1048 | */ | 1050 | */ |
1049 | int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length) | 1051 | int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length) |
1050 | { | 1052 | { |
1051 | if (length != sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) { | 1053 | if (length != sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) { |
1052 | return -1; | 1054 | return -1; |
@@ -1109,9 +1111,10 @@ int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type | |||
1109 | * | 1111 | * |
1110 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. | 1112 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. |
1111 | * | 1113 | * |
1112 | * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) | 1114 | * 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) |
1113 | */ | 1115 | */ |
1114 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, int, int, void *, | 1116 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, uint32_t, uint32_t, |
1117 | void *, | ||
1115 | const uint8_t *, uint16_t)) | 1118 | const uint8_t *, uint16_t)) |
1116 | { | 1119 | { |
1117 | g_c->lossy_packethandlers[byte].function = function; | 1120 | g_c->lossy_packethandlers[byte].function = function; |
@@ -1119,7 +1122,7 @@ void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*fu | |||
1119 | 1122 | ||
1120 | /* Set the callback for group invites. | 1123 | /* Set the callback for group invites. |
1121 | * | 1124 | * |
1122 | * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) | 1125 | * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, size_t length, void *userdata) |
1123 | * | 1126 | * |
1124 | * data of length is what needs to be passed to join_groupchat(). | 1127 | * data of length is what needs to be passed to join_groupchat(). |
1125 | */ | 1128 | */ |
@@ -1129,9 +1132,10 @@ void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, ui | |||
1129 | g_c->invite_callback = function; | 1132 | g_c->invite_callback = function; |
1130 | } | 1133 | } |
1131 | 1134 | ||
1135 | // TODO(sudden6): function signatures in comments are incorrect | ||
1132 | /* Set the callback for group messages. | 1136 | /* Set the callback for group messages. |
1133 | * | 1137 | * |
1134 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) | 1138 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, size_t length, void *userdata) |
1135 | */ | 1139 | */ |
1136 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, | 1140 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, |
1137 | size_t, void *)) | 1141 | size_t, void *)) |
@@ -1139,16 +1143,19 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u | |||
1139 | g_c->message_callback = function; | 1143 | g_c->message_callback = function; |
1140 | } | 1144 | } |
1141 | 1145 | ||
1146 | // TODO(sudden6): function signatures in comments are incorrect | ||
1142 | /* Set callback function for peer name list changes. | 1147 | /* Set callback function for peer name list changes. |
1143 | * | 1148 | * |
1144 | * It gets called every time the name list changes(new peer/name, deleted peer) | 1149 | * It gets called every time the name list changes(new peer/name, deleted peer) |
1145 | * Function(Group_Chats *g_c, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata) | 1150 | * Function(Group_Chats *g_c, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata) |
1146 | */ | 1151 | */ |
1147 | void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, int, int, uint8_t, void *)) | 1152 | void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *, uint32_t, uint32_t, uint8_t, |
1153 | void *)) | ||
1148 | { | 1154 | { |
1149 | g_c->group_namelistchange = function; | 1155 | g_c->group_namelistchange = function; |
1150 | } | 1156 | } |
1151 | 1157 | ||
1158 | // TODO(sudden6): function signatures are incorrect | ||
1152 | /* Set callback function for title changes. | 1159 | /* Set callback function for title changes. |
1153 | * | 1160 | * |
1154 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) | 1161 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) |
@@ -1162,12 +1169,13 @@ void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uin | |||
1162 | 1169 | ||
1163 | /* Set a function to be called when a new peer joins a group chat. | 1170 | /* Set a function to be called when a new peer joins a group chat. |
1164 | * | 1171 | * |
1165 | * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber) | 1172 | * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber) |
1166 | * | 1173 | * |
1167 | * return 0 on success. | 1174 | * return 0 on success. |
1168 | * return -1 on failure. | 1175 | * return -1 on failure. |
1169 | */ | 1176 | */ |
1170 | int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int)) | 1177 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, |
1178 | uint32_t)) | ||
1171 | { | 1179 | { |
1172 | Group_c *g = get_group_c(g_c, groupnumber); | 1180 | Group_c *g = get_group_c(g_c, groupnumber); |
1173 | 1181 | ||
@@ -1181,12 +1189,13 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (* | |||
1181 | 1189 | ||
1182 | /* Set a function to be called when a peer leaves a group chat. | 1190 | /* Set a function to be called when a peer leaves a group chat. |
1183 | * | 1191 | * |
1184 | * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object)) | 1192 | * 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)) |
1185 | * | 1193 | * |
1186 | * return 0 on success. | 1194 | * return 0 on success. |
1187 | * return -1 on failure. | 1195 | * return -1 on failure. |
1188 | */ | 1196 | */ |
1189 | int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int, void *)) | 1197 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, uint32_t, |
1198 | void *)) | ||
1190 | { | 1199 | { |
1191 | Group_c *g = get_group_c(g_c, groupnumber); | 1200 | Group_c *g = get_group_c(g_c, groupnumber); |
1192 | 1201 | ||
@@ -1205,7 +1214,7 @@ int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*fun | |||
1205 | * return 0 on success. | 1214 | * return 0 on success. |
1206 | * return -1 on failure. | 1215 | * return -1 on failure. |
1207 | */ | 1216 | */ |
1208 | int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int)) | 1217 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t)) |
1209 | { | 1218 | { |
1210 | Group_c *g = get_group_c(g_c, groupnumber); | 1219 | Group_c *g = get_group_c(g_c, groupnumber); |
1211 | 1220 | ||
@@ -1217,11 +1226,11 @@ int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function | |||
1217 | return 0; | 1226 | return 0; |
1218 | } | 1227 | } |
1219 | 1228 | ||
1220 | static int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data, | 1229 | static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint8_t message_id, const uint8_t *data, |
1221 | uint16_t len); | 1230 | uint16_t len); |
1222 | 1231 | ||
1223 | #define GROUP_MESSAGE_PING_ID 0 | 1232 | #define GROUP_MESSAGE_PING_ID 0 |
1224 | static int group_ping_send(const Group_Chats *g_c, int groupnumber) | 1233 | static int group_ping_send(const Group_Chats *g_c, uint32_t groupnumber) |
1225 | { | 1234 | { |
1226 | if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, nullptr, 0) > 0) { | 1235 | if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, nullptr, 0) > 0) { |
1227 | return 0; | 1236 | return 0; |
@@ -1236,7 +1245,7 @@ static int group_ping_send(const Group_Chats *g_c, int groupnumber) | |||
1236 | * return 0 on success | 1245 | * return 0 on success |
1237 | * return -1 on failure | 1246 | * return -1 on failure |
1238 | */ | 1247 | */ |
1239 | static int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num, const uint8_t *real_pk, | 1248 | static int group_new_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num, const uint8_t *real_pk, |
1240 | uint8_t *temp_pk) | 1249 | uint8_t *temp_pk) |
1241 | { | 1250 | { |
1242 | uint8_t packet[GROUP_MESSAGE_NEW_PEER_LENGTH]; | 1251 | uint8_t packet[GROUP_MESSAGE_NEW_PEER_LENGTH]; |
@@ -1260,7 +1269,7 @@ static int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t | |||
1260 | * return 0 on success | 1269 | * return 0 on success |
1261 | * return -1 on failure | 1270 | * return -1 on failure |
1262 | */ | 1271 | */ |
1263 | static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num) | 1272 | static int group_kill_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num) |
1264 | { | 1273 | { |
1265 | uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH]; | 1274 | uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH]; |
1266 | 1275 | ||
@@ -1280,7 +1289,7 @@ static int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_ | |||
1280 | * return 0 on success | 1289 | * return 0 on success |
1281 | * return -1 on failure | 1290 | * return -1 on failure |
1282 | */ | 1291 | */ |
1283 | static int group_name_send(const Group_Chats *g_c, int groupnumber, const uint8_t *nick, uint16_t nick_len) | 1292 | static int group_name_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *nick, uint16_t nick_len) |
1284 | { | 1293 | { |
1285 | if (nick_len > MAX_NAME_LENGTH) { | 1294 | if (nick_len > MAX_NAME_LENGTH) { |
1286 | return -1; | 1295 | return -1; |
@@ -1301,7 +1310,7 @@ static int group_name_send(const Group_Chats *g_c, int groupnumber, const uint8_ | |||
1301 | * return -2 if title is too long or empty. | 1310 | * return -2 if title is too long or empty. |
1302 | * return -3 if packet fails to send. | 1311 | * return -3 if packet fails to send. |
1303 | */ | 1312 | */ |
1304 | int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len) | 1313 | int group_title_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *title, uint8_t title_len) |
1305 | { | 1314 | { |
1306 | Group_c *g = get_group_c(g_c, groupnumber); | 1315 | Group_c *g = get_group_c(g_c, groupnumber); |
1307 | 1316 | ||
@@ -1336,7 +1345,7 @@ int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *tit | |||
1336 | * return -1 of groupnumber is invalid. | 1345 | * return -1 of groupnumber is invalid. |
1337 | * return -2 if title is too long or empty. | 1346 | * return -2 if title is too long or empty. |
1338 | */ | 1347 | */ |
1339 | int group_title_get_size(const Group_Chats *g_c, int groupnumber) | 1348 | int group_title_get_size(const Group_Chats *g_c, uint32_t groupnumber) |
1340 | { | 1349 | { |
1341 | Group_c *g = get_group_c(g_c, groupnumber); | 1350 | Group_c *g = get_group_c(g_c, groupnumber); |
1342 | 1351 | ||
@@ -1358,7 +1367,7 @@ int group_title_get_size(const Group_Chats *g_c, int groupnumber) | |||
1358 | * return -1 if groupnumber is invalid. | 1367 | * return -1 if groupnumber is invalid. |
1359 | * return -2 if title is too long or empty. | 1368 | * return -2 if title is too long or empty. |
1360 | */ | 1369 | */ |
1361 | int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title) | 1370 | int group_title_get(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *title) |
1362 | { | 1371 | { |
1363 | Group_c *g = get_group_c(g_c, groupnumber); | 1372 | Group_c *g = get_group_c(g_c, groupnumber); |
1364 | 1373 | ||
@@ -1524,6 +1533,11 @@ static int handle_packet_online(Group_Chats *g_c, int friendcon_id, const uint8_ | |||
1524 | } | 1533 | } |
1525 | 1534 | ||
1526 | int groupnumber = get_group_num(g_c, data + sizeof(uint16_t)); | 1535 | int groupnumber = get_group_num(g_c, data + sizeof(uint16_t)); |
1536 | |||
1537 | if (groupnumber == -1) { | ||
1538 | return -1; | ||
1539 | } | ||
1540 | |||
1527 | uint16_t other_groupnum; | 1541 | uint16_t other_groupnum; |
1528 | memcpy(&other_groupnum, data, sizeof(uint16_t)); | 1542 | memcpy(&other_groupnum, data, sizeof(uint16_t)); |
1529 | other_groupnum = net_ntohs(other_groupnum); | 1543 | other_groupnum = net_ntohs(other_groupnum); |
@@ -1600,12 +1614,12 @@ static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t | |||
1600 | /* return number of peers sent on success. | 1614 | /* return number of peers sent on success. |
1601 | * return 0 on failure. | 1615 | * return 0 on failure. |
1602 | */ | 1616 | */ |
1603 | static unsigned int send_peers(Group_Chats *g_c, int groupnumber, int friendcon_id, uint16_t group_num) | 1617 | static unsigned int send_peers(Group_Chats *g_c, uint32_t groupnumber, int friendcon_id, uint16_t group_num) |
1604 | { | 1618 | { |
1605 | Group_c *g = get_group_c(g_c, groupnumber); | 1619 | Group_c *g = get_group_c(g_c, groupnumber); |
1606 | 1620 | ||
1607 | if (!g) { | 1621 | if (!g) { |
1608 | return -1; | 1622 | return 0; |
1609 | } | 1623 | } |
1610 | 1624 | ||
1611 | uint8_t packet[MAX_CRYPTO_DATA_SIZE - (1 + sizeof(uint16_t))]; | 1625 | uint8_t packet[MAX_CRYPTO_DATA_SIZE - (1 + sizeof(uint16_t))]; |
@@ -1655,7 +1669,8 @@ static unsigned int send_peers(Group_Chats *g_c, int groupnumber, int friendcon_ | |||
1655 | return sent; | 1669 | return sent; |
1656 | } | 1670 | } |
1657 | 1671 | ||
1658 | static int handle_send_peers(Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, void *userdata) | 1672 | static int handle_send_peers(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, |
1673 | void *userdata) | ||
1659 | { | 1674 | { |
1660 | if (length == 0) { | 1675 | if (length == 0) { |
1661 | return -1; | 1676 | return -1; |
@@ -1702,7 +1717,7 @@ static int handle_send_peers(Group_Chats *g_c, int groupnumber, const uint8_t *d | |||
1702 | return 0; | 1717 | return 0; |
1703 | } | 1718 | } |
1704 | 1719 | ||
1705 | static void handle_direct_packet(Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, | 1720 | static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, |
1706 | int close_index, void *userdata) | 1721 | int close_index, void *userdata) |
1707 | { | 1722 | { |
1708 | if (length == 0) { | 1723 | if (length == 0) { |
@@ -1758,7 +1773,7 @@ static void handle_direct_packet(Group_Chats *g_c, int groupnumber, const uint8_ | |||
1758 | * | 1773 | * |
1759 | * return number of messages sent. | 1774 | * return number of messages sent. |
1760 | */ | 1775 | */ |
1761 | static unsigned int send_message_all_close(const Group_Chats *g_c, int groupnumber, const uint8_t *data, | 1776 | static unsigned int send_message_all_close(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, |
1762 | uint16_t length, int receiver) | 1777 | uint16_t length, int receiver) |
1763 | { | 1778 | { |
1764 | Group_c *g = get_group_c(g_c, groupnumber); | 1779 | Group_c *g = get_group_c(g_c, groupnumber); |
@@ -1792,7 +1807,8 @@ static unsigned int send_message_all_close(const Group_Chats *g_c, int groupnumb | |||
1792 | * | 1807 | * |
1793 | * return number of messages sent. | 1808 | * return number of messages sent. |
1794 | */ | 1809 | */ |
1795 | static unsigned int send_lossy_all_close(const Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, | 1810 | static unsigned int send_lossy_all_close(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, |
1811 | uint16_t length, | ||
1796 | int receiver) | 1812 | int receiver) |
1797 | { | 1813 | { |
1798 | Group_c *g = get_group_c(g_c, groupnumber); | 1814 | Group_c *g = get_group_c(g_c, groupnumber); |
@@ -1885,7 +1901,7 @@ static unsigned int send_lossy_all_close(const Group_Chats *g_c, int groupnumber | |||
1885 | * return -3 if we are not connected to the group. | 1901 | * return -3 if we are not connected to the group. |
1886 | * reutrn -4 if message failed to send. | 1902 | * reutrn -4 if message failed to send. |
1887 | */ | 1903 | */ |
1888 | static int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data, | 1904 | static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint8_t message_id, const uint8_t *data, |
1889 | uint16_t len) | 1905 | uint16_t len) |
1890 | { | 1906 | { |
1891 | Group_c *g = get_group_c(g_c, groupnumber); | 1907 | Group_c *g = get_group_c(g_c, groupnumber); |
@@ -1930,7 +1946,7 @@ static int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t m | |||
1930 | * return 0 on success | 1946 | * return 0 on success |
1931 | * see: send_message_group() for error codes. | 1947 | * see: send_message_group() for error codes. |
1932 | */ | 1948 | */ |
1933 | int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *message, uint16_t length) | 1949 | int group_message_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *message, uint16_t length) |
1934 | { | 1950 | { |
1935 | int ret = send_message_group(g_c, groupnumber, PACKET_ID_MESSAGE, message, length); | 1951 | int ret = send_message_group(g_c, groupnumber, PACKET_ID_MESSAGE, message, length); |
1936 | 1952 | ||
@@ -1945,7 +1961,7 @@ int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *m | |||
1945 | * return 0 on success | 1961 | * return 0 on success |
1946 | * see: send_message_group() for error codes. | 1962 | * see: send_message_group() for error codes. |
1947 | */ | 1963 | */ |
1948 | int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length) | 1964 | int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *action, uint16_t length) |
1949 | { | 1965 | { |
1950 | int ret = send_message_group(g_c, groupnumber, PACKET_ID_ACTION, action, length); | 1966 | int ret = send_message_group(g_c, groupnumber, PACKET_ID_ACTION, action, length); |
1951 | 1967 | ||
@@ -1961,7 +1977,7 @@ int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *ac | |||
1961 | * return -1 on failure. | 1977 | * return -1 on failure. |
1962 | * return 0 on success. | 1978 | * return 0 on success. |
1963 | */ | 1979 | */ |
1964 | int send_group_lossy_packet(const Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length) | 1980 | int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length) |
1965 | { | 1981 | { |
1966 | // TODO(irungentoo): length check here? | 1982 | // TODO(irungentoo): length check here? |
1967 | Group_c *g = get_group_c(g_c, groupnumber); | 1983 | Group_c *g = get_group_c(g_c, groupnumber); |
@@ -1985,7 +2001,7 @@ int send_group_lossy_packet(const Group_Chats *g_c, int groupnumber, const uint8 | |||
1985 | return 0; | 2001 | return 0; |
1986 | } | 2002 | } |
1987 | 2003 | ||
1988 | static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, | 2004 | static void handle_message_packet_group(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, |
1989 | int close_index, void *userdata) | 2005 | int close_index, void *userdata) |
1990 | { | 2006 | { |
1991 | if (length < sizeof(uint16_t) + sizeof(uint32_t) + 1) { | 2007 | if (length < sizeof(uint16_t) + sizeof(uint32_t) + 1) { |
@@ -2186,6 +2202,7 @@ static int g_handle_packet(void *object, int friendcon_id, const uint8_t *data, | |||
2186 | static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16_t message_number) | 2202 | static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16_t message_number) |
2187 | { | 2203 | { |
2188 | if (peer_index == -1) { | 2204 | if (peer_index == -1) { |
2205 | // TODO(sudden6): invalid return value | ||
2189 | return -1; | 2206 | return -1; |
2190 | } | 2207 | } |
2191 | 2208 | ||
@@ -2206,6 +2223,7 @@ static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16 | |||
2206 | } | 2223 | } |
2207 | 2224 | ||
2208 | if ((uint16_t)(message_number - g->group[peer_index].bottom_lossy_number) > (1 << 15)) { | 2225 | if ((uint16_t)(message_number - g->group[peer_index].bottom_lossy_number) > (1 << 15)) { |
2226 | // TODO(sudden6): invalid return value | ||
2209 | return -1; | 2227 | return -1; |
2210 | } | 2228 | } |
2211 | 2229 | ||
@@ -2304,7 +2322,7 @@ static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uin | |||
2304 | * return 0 on success. | 2322 | * return 0 on success. |
2305 | * return -1 on failure | 2323 | * return -1 on failure |
2306 | */ | 2324 | */ |
2307 | int group_set_object(const Group_Chats *g_c, int groupnumber, void *object) | 2325 | int group_set_object(const Group_Chats *g_c, uint32_t groupnumber, void *object) |
2308 | { | 2326 | { |
2309 | Group_c *g = get_group_c(g_c, groupnumber); | 2327 | Group_c *g = get_group_c(g_c, groupnumber); |
2310 | 2328 | ||
@@ -2321,7 +2339,7 @@ int group_set_object(const Group_Chats *g_c, int groupnumber, void *object) | |||
2321 | * return 0 on success. | 2339 | * return 0 on success. |
2322 | * return -1 on failure | 2340 | * return -1 on failure |
2323 | */ | 2341 | */ |
2324 | int group_peer_set_object(const Group_Chats *g_c, int groupnumber, int peernumber, void *object) | 2342 | int group_peer_set_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, void *object) |
2325 | { | 2343 | { |
2326 | Group_c *g = get_group_c(g_c, groupnumber); | 2344 | Group_c *g = get_group_c(g_c, groupnumber); |
2327 | 2345 | ||
@@ -2342,7 +2360,7 @@ int group_peer_set_object(const Group_Chats *g_c, int groupnumber, int peernumbe | |||
2342 | * return NULL on failure. | 2360 | * return NULL on failure. |
2343 | * return object on success. | 2361 | * return object on success. |
2344 | */ | 2362 | */ |
2345 | void *group_get_object(const Group_Chats *g_c, int groupnumber) | 2363 | void *group_get_object(const Group_Chats *g_c, uint32_t groupnumber) |
2346 | { | 2364 | { |
2347 | Group_c *g = get_group_c(g_c, groupnumber); | 2365 | Group_c *g = get_group_c(g_c, groupnumber); |
2348 | 2366 | ||
@@ -2358,7 +2376,7 @@ void *group_get_object(const Group_Chats *g_c, int groupnumber) | |||
2358 | * return NULL on failure. | 2376 | * return NULL on failure. |
2359 | * return object on success. | 2377 | * return object on success. |
2360 | */ | 2378 | */ |
2361 | void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernumber) | 2379 | void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber) |
2362 | { | 2380 | { |
2363 | Group_c *g = get_group_c(g_c, groupnumber); | 2381 | Group_c *g = get_group_c(g_c, groupnumber); |
2364 | 2382 | ||
@@ -2376,7 +2394,7 @@ void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernum | |||
2376 | /* Interval in seconds to send ping messages */ | 2394 | /* Interval in seconds to send ping messages */ |
2377 | #define GROUP_PING_INTERVAL 20 | 2395 | #define GROUP_PING_INTERVAL 20 |
2378 | 2396 | ||
2379 | static int ping_groupchat(Group_Chats *g_c, int groupnumber) | 2397 | static int ping_groupchat(Group_Chats *g_c, uint32_t groupnumber) |
2380 | { | 2398 | { |
2381 | Group_c *g = get_group_c(g_c, groupnumber); | 2399 | Group_c *g = get_group_c(g_c, groupnumber); |
2382 | 2400 | ||
@@ -2393,7 +2411,7 @@ static int ping_groupchat(Group_Chats *g_c, int groupnumber) | |||
2393 | return 0; | 2411 | return 0; |
2394 | } | 2412 | } |
2395 | 2413 | ||
2396 | static int groupchat_clear_timedout(Group_Chats *g_c, int groupnumber, void *userdata) | 2414 | static int groupchat_clear_timedout(Group_Chats *g_c, uint32_t groupnumber, void *userdata) |
2397 | { | 2415 | { |
2398 | Group_c *g = get_group_c(g_c, groupnumber); | 2416 | Group_c *g = get_group_c(g_c, groupnumber); |
2399 | 2417 | ||
diff --git a/toxcore/group.h b/toxcore/group.h index af37f21e..4324613c 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -103,9 +103,9 @@ typedef struct { | |||
103 | 103 | ||
104 | void *object; | 104 | void *object; |
105 | 105 | ||
106 | void (*peer_on_join)(void *, int, int); | 106 | void (*peer_on_join)(void *, uint32_t, uint32_t); |
107 | void (*peer_on_leave)(void *, int, int, void *); | 107 | void (*peer_on_leave)(void *, uint32_t, uint32_t, void *); |
108 | void (*group_on_delete)(void *, int); | 108 | void (*group_on_delete)(void *, uint32_t); |
109 | } Group_c; | 109 | } Group_c; |
110 | 110 | ||
111 | typedef struct { | 111 | typedef struct { |
@@ -117,17 +117,17 @@ typedef struct { | |||
117 | 117 | ||
118 | void (*invite_callback)(Messenger *m, uint32_t, int, const uint8_t *, size_t, void *); | 118 | void (*invite_callback)(Messenger *m, uint32_t, int, const uint8_t *, size_t, void *); |
119 | void (*message_callback)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *); | 119 | void (*message_callback)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *); |
120 | void (*group_namelistchange)(Messenger *m, int, int, uint8_t, void *); | 120 | void (*group_namelistchange)(Messenger *m, uint32_t, uint32_t, uint8_t, void *); |
121 | void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); | 121 | void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); |
122 | 122 | ||
123 | struct { | 123 | struct { |
124 | int (*function)(void *, int, int, void *, const uint8_t *, uint16_t); | 124 | int (*function)(void *, uint32_t, uint32_t, void *, const uint8_t *, uint16_t); |
125 | } lossy_packethandlers[256]; | 125 | } lossy_packethandlers[256]; |
126 | } Group_Chats; | 126 | } Group_Chats; |
127 | 127 | ||
128 | /* Set the callback for group invites. | 128 | /* Set the callback for group invites. |
129 | * | 129 | * |
130 | * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) | 130 | * Function(Group_Chats *g_c, uint32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) |
131 | * | 131 | * |
132 | * data of length is what needs to be passed to join_groupchat(). | 132 | * data of length is what needs to be passed to join_groupchat(). |
133 | */ | 133 | */ |
@@ -136,7 +136,7 @@ void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, ui | |||
136 | 136 | ||
137 | /* Set the callback for group messages. | 137 | /* Set the callback for group messages. |
138 | * | 138 | * |
139 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) | 139 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) |
140 | */ | 140 | */ |
141 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, | 141 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, |
142 | size_t, void *)); | 142 | size_t, void *)); |
@@ -144,7 +144,7 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u | |||
144 | 144 | ||
145 | /* Set callback function for title changes. | 145 | /* Set callback function for title changes. |
146 | * | 146 | * |
147 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) | 147 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) |
148 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) | 148 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) |
149 | */ | 149 | */ |
150 | void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, | 150 | void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, |
@@ -159,7 +159,8 @@ enum { | |||
159 | CHAT_CHANGE_OCCURRED, | 159 | CHAT_CHANGE_OCCURRED, |
160 | CHAT_CHANGE_PEER_NAME, | 160 | CHAT_CHANGE_PEER_NAME, |
161 | }; | 161 | }; |
162 | void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, int, int, uint8_t, void *)); | 162 | void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, uint8_t, |
163 | void *)); | ||
163 | 164 | ||
164 | /* Creates a new groupchat and puts it in the chats array. | 165 | /* Creates a new groupchat and puts it in the chats array. |
165 | * | 166 | * |
@@ -175,7 +176,7 @@ int add_groupchat(Group_Chats *g_c, uint8_t type); | |||
175 | * return 0 on success. | 176 | * return 0 on success. |
176 | * return -1 if groupnumber is invalid. | 177 | * return -1 if groupnumber is invalid. |
177 | */ | 178 | */ |
178 | int del_groupchat(Group_Chats *g_c, int groupnumber); | 179 | int del_groupchat(Group_Chats *g_c, uint32_t groupnumber); |
179 | 180 | ||
180 | /* Copy the public key of peernumber who is in groupnumber to pk. | 181 | /* Copy the public key of peernumber who is in groupnumber to pk. |
181 | * pk must be CRYPTO_PUBLIC_KEY_SIZE long. | 182 | * pk must be CRYPTO_PUBLIC_KEY_SIZE long. |
@@ -184,7 +185,7 @@ int del_groupchat(Group_Chats *g_c, int groupnumber); | |||
184 | * return -1 if groupnumber is invalid. | 185 | * return -1 if groupnumber is invalid. |
185 | * return -2 if peernumber is invalid. | 186 | * return -2 if peernumber is invalid. |
186 | */ | 187 | */ |
187 | int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *pk); | 188 | int group_peer_pubkey(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *pk); |
188 | 189 | ||
189 | /* | 190 | /* |
190 | * Return the size of peernumber's name. | 191 | * Return the size of peernumber's name. |
@@ -192,7 +193,7 @@ int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, u | |||
192 | * return -1 if groupnumber is invalid. | 193 | * return -1 if groupnumber is invalid. |
193 | * return -2 if peernumber is invalid. | 194 | * return -2 if peernumber is invalid. |
194 | */ | 195 | */ |
195 | int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber); | 196 | int group_peername_size(const Group_Chats *g_c, uint32_t groupnumber, int32_t peernumber); |
196 | 197 | ||
197 | /* Copy the name of peernumber who is in groupnumber to name. | 198 | /* Copy the name of peernumber who is in groupnumber to name. |
198 | * name must be at least MAX_NAME_LENGTH long. | 199 | * name must be at least MAX_NAME_LENGTH long. |
@@ -201,7 +202,7 @@ int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber) | |||
201 | * return -1 if groupnumber is invalid. | 202 | * return -1 if groupnumber is invalid. |
202 | * return -2 if peernumber is invalid. | 203 | * return -2 if peernumber is invalid. |
203 | */ | 204 | */ |
204 | int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *name); | 205 | int group_peername(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *name); |
205 | 206 | ||
206 | /* invite friendnumber to groupnumber | 207 | /* invite friendnumber to groupnumber |
207 | * | 208 | * |
@@ -209,7 +210,7 @@ int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint | |||
209 | * return -1 if groupnumber is invalid. | 210 | * return -1 if groupnumber is invalid. |
210 | * return -2 if invite packet failed to send. | 211 | * return -2 if invite packet failed to send. |
211 | */ | 212 | */ |
212 | int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber); | 213 | int invite_friend(Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber); |
213 | 214 | ||
214 | /* Join a group (you need to have been invited first.) | 215 | /* Join a group (you need to have been invited first.) |
215 | * | 216 | * |
@@ -223,19 +224,20 @@ int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber); | |||
223 | * return -5 if group instance failed to initialize. | 224 | * return -5 if group instance failed to initialize. |
224 | * return -6 if join packet fails to send. | 225 | * return -6 if join packet fails to send. |
225 | */ | 226 | */ |
226 | int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length); | 227 | int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_type, const uint8_t *data, |
228 | uint16_t length); | ||
227 | 229 | ||
228 | /* send a group message | 230 | /* send a group message |
229 | * return 0 on success | 231 | * return 0 on success |
230 | * see: send_message_group() for error codes. | 232 | * see: send_message_group() for error codes. |
231 | */ | 233 | */ |
232 | int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *message, uint16_t length); | 234 | int group_message_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *message, uint16_t length); |
233 | 235 | ||
234 | /* send a group action | 236 | /* send a group action |
235 | * return 0 on success | 237 | * return 0 on success |
236 | * see: send_message_group() for error codes. | 238 | * see: send_message_group() for error codes. |
237 | */ | 239 | */ |
238 | int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length); | 240 | int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *action, uint16_t length); |
239 | 241 | ||
240 | /* set the group's title, limited to MAX_NAME_LENGTH | 242 | /* set the group's title, limited to MAX_NAME_LENGTH |
241 | * return 0 on success | 243 | * return 0 on success |
@@ -243,14 +245,14 @@ int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *ac | |||
243 | * return -2 if title is too long or empty. | 245 | * return -2 if title is too long or empty. |
244 | * return -3 if packet fails to send. | 246 | * return -3 if packet fails to send. |
245 | */ | 247 | */ |
246 | int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len); | 248 | int group_title_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *title, uint8_t title_len); |
247 | 249 | ||
248 | 250 | ||
249 | /* return the group's title size. | 251 | /* return the group's title size. |
250 | * return -1 of groupnumber is invalid. | 252 | * return -1 of groupnumber is invalid. |
251 | * return -2 if title is too long or empty. | 253 | * return -2 if title is too long or empty. |
252 | */ | 254 | */ |
253 | int group_title_get_size(const Group_Chats *g_c, int groupnumber); | 255 | int group_title_get_size(const Group_Chats *g_c, uint32_t groupnumber); |
254 | 256 | ||
255 | /* Get group title from groupnumber and put it in title. | 257 | /* Get group title from groupnumber and put it in title. |
256 | * Title needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. | 258 | * Title needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. |
@@ -259,12 +261,12 @@ int group_title_get_size(const Group_Chats *g_c, int groupnumber); | |||
259 | * return -1 if groupnumber is invalid. | 261 | * return -1 if groupnumber is invalid. |
260 | * return -2 if title is too long or empty. | 262 | * return -2 if title is too long or empty. |
261 | */ | 263 | */ |
262 | int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title); | 264 | int group_title_get(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *title); |
263 | 265 | ||
264 | /* Return the number of peers in the group chat on success. | 266 | /* Return the number of peers in the group chat on success. |
265 | * return -1 if groupnumber is invalid. | 267 | * return -1 if groupnumber is invalid. |
266 | */ | 268 | */ |
267 | int group_number_peers(const Group_Chats *g_c, int groupnumber); | 269 | int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber); |
268 | 270 | ||
269 | /* return 1 if the peernumber corresponds to ours. | 271 | /* return 1 if the peernumber corresponds to ours. |
270 | * return 0 if the peernumber is not ours. | 272 | * return 0 if the peernumber is not ours. |
@@ -272,7 +274,7 @@ int group_number_peers(const Group_Chats *g_c, int groupnumber); | |||
272 | * return -2 if peernumber is invalid. | 274 | * return -2 if peernumber is invalid. |
273 | * return -3 if we are not connected to the group chat. | 275 | * return -3 if we are not connected to the group chat. |
274 | */ | 276 | */ |
275 | int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernumber); | 277 | int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, int peernumber); |
276 | 278 | ||
277 | /* List all the peers in the group chat. | 279 | /* List all the peers in the group chat. |
278 | * | 280 | * |
@@ -284,16 +286,17 @@ int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernu | |||
284 | * | 286 | * |
285 | * return -1 on failure. | 287 | * return -1 on failure. |
286 | */ | 288 | */ |
287 | int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], | 289 | int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], |
288 | uint16_t length); | 290 | uint16_t length); |
289 | 291 | ||
290 | /* Set handlers for custom lossy packets. | 292 | /* Set handlers for custom lossy packets. |
291 | * | 293 | * |
292 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. | 294 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. |
293 | * | 295 | * |
294 | * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) | 296 | * 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) |
295 | */ | 297 | */ |
296 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, int, int, void *, | 298 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, uint32_t, uint32_t, |
299 | void *, | ||
297 | const uint8_t *, uint16_t)); | 300 | const uint8_t *, uint16_t)); |
298 | 301 | ||
299 | /* High level function to send custom lossy packets. | 302 | /* High level function to send custom lossy packets. |
@@ -301,7 +304,7 @@ void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*fu | |||
301 | * return -1 on failure. | 304 | * return -1 on failure. |
302 | * return 0 on success. | 305 | * return 0 on success. |
303 | */ | 306 | */ |
304 | int send_group_lossy_packet(const Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length); | 307 | int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length); |
305 | 308 | ||
306 | /* Return the number of chats in the instance m. | 309 | /* Return the number of chats in the instance m. |
307 | * You should use this to determine how much memory to allocate | 310 | * You should use this to determine how much memory to allocate |
@@ -321,7 +324,7 @@ uint32_t copy_chatlist(Group_Chats *g_c, uint32_t *out_list, uint32_t list_size) | |||
321 | * return -1 on failure. | 324 | * return -1 on failure. |
322 | * return type on success. | 325 | * return type on success. |
323 | */ | 326 | */ |
324 | int group_get_type(const Group_Chats *g_c, int groupnumber); | 327 | int group_get_type(const Group_Chats *g_c, uint32_t groupnumber); |
325 | 328 | ||
326 | /* Send current name (set in messenger) to all online groups. | 329 | /* Send current name (set in messenger) to all online groups. |
327 | */ | 330 | */ |
@@ -332,28 +335,28 @@ void send_name_all_groups(Group_Chats *g_c); | |||
332 | * return 0 on success. | 335 | * return 0 on success. |
333 | * return -1 on failure | 336 | * return -1 on failure |
334 | */ | 337 | */ |
335 | int group_set_object(const Group_Chats *g_c, int groupnumber, void *object); | 338 | int group_set_object(const Group_Chats *g_c, uint32_t groupnumber, void *object); |
336 | 339 | ||
337 | /* Set the object that is tied to the group peer. | 340 | /* Set the object that is tied to the group peer. |
338 | * | 341 | * |
339 | * return 0 on success. | 342 | * return 0 on success. |
340 | * return -1 on failure | 343 | * return -1 on failure |
341 | */ | 344 | */ |
342 | int group_peer_set_object(const Group_Chats *g_c, int groupnumber, int peernumber, void *object); | 345 | int group_peer_set_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, void *object); |
343 | 346 | ||
344 | /* Return the object tide to the group chat previously set by group_set_object. | 347 | /* Return the object tide to the group chat previously set by group_set_object. |
345 | * | 348 | * |
346 | * return NULL on failure. | 349 | * return NULL on failure. |
347 | * return object on success. | 350 | * return object on success. |
348 | */ | 351 | */ |
349 | void *group_get_object(const Group_Chats *g_c, int groupnumber); | 352 | void *group_get_object(const Group_Chats *g_c, uint32_t groupnumber); |
350 | 353 | ||
351 | /* Return the object tide to the group chat peer previously set by group_peer_set_object. | 354 | /* Return the object tide to the group chat peer previously set by group_peer_set_object. |
352 | * | 355 | * |
353 | * return NULL on failure. | 356 | * return NULL on failure. |
354 | * return object on success. | 357 | * return object on success. |
355 | */ | 358 | */ |
356 | void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernumber); | 359 | void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber); |
357 | 360 | ||
358 | /* Set a function to be called when a new peer joins a group chat. | 361 | /* Set a function to be called when a new peer joins a group chat. |
359 | * | 362 | * |
@@ -362,25 +365,27 @@ void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernum | |||
362 | * return 0 on success. | 365 | * return 0 on success. |
363 | * return -1 on failure. | 366 | * return -1 on failure. |
364 | */ | 367 | */ |
365 | int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int)); | 368 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, |
369 | uint32_t)); | ||
366 | 370 | ||
367 | /* Set a function to be called when a peer leaves a group chat. | 371 | /* Set a function to be called when a peer leaves a group chat. |
368 | * | 372 | * |
369 | * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object)) | 373 | * 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)) |
370 | * | 374 | * |
371 | * return 0 on success. | 375 | * return 0 on success. |
372 | * return -1 on failure. | 376 | * return -1 on failure. |
373 | */ | 377 | */ |
374 | int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int, void *)); | 378 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, uint32_t, |
379 | void *)); | ||
375 | 380 | ||
376 | /* Set a function to be called when the group chat is deleted. | 381 | /* Set a function to be called when the group chat is deleted. |
377 | * | 382 | * |
378 | * Function(void *group object (set with group_set_object), int groupnumber) | 383 | * Function(void *group object (set with group_set_object), uint32_t groupnumber) |
379 | * | 384 | * |
380 | * return 0 on success. | 385 | * return 0 on success. |
381 | * return -1 on failure. | 386 | * return -1 on failure. |
382 | */ | 387 | */ |
383 | int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int)); | 388 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t)); |
384 | 389 | ||
385 | /* Create new groupchat instance. */ | 390 | /* Create new groupchat instance. */ |
386 | Group_Chats *new_groupchats(Messenger *m); | 391 | Group_Chats *new_groupchats(Messenger *m); |
diff --git a/toxcore/tox.c b/toxcore/tox.c index c3bcb652..6ca52604 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -1106,7 +1106,8 @@ void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback) | |||
1106 | void tox_callback_conference_namelist_change(Tox *tox, tox_conference_namelist_change_cb *callback) | 1106 | void tox_callback_conference_namelist_change(Tox *tox, tox_conference_namelist_change_cb *callback) |
1107 | { | 1107 | { |
1108 | Messenger *m = tox; | 1108 | Messenger *m = tox; |
1109 | g_callback_group_namelistchange((Group_Chats *)m->conferences_object, (void (*)(struct Messenger *, int, int, uint8_t, | 1109 | g_callback_group_namelistchange((Group_Chats *)m->conferences_object, (void (*)(struct Messenger *, uint32_t, uint32_t, |
1110 | uint8_t, | ||
1110 | void *))callback); | 1111 | void *))callback); |
1111 | } | 1112 | } |
1112 | 1113 | ||