summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/tox_test.c45
-rw-r--r--other/apidsl/tox.in.h14
-rw-r--r--testing/nTox.c10
-rw-r--r--testing/tox_shell.c2
-rw-r--r--testing/tox_sync.c10
-rw-r--r--toxcore/Messenger.c93
-rw-r--r--toxcore/Messenger.h24
-rw-r--r--toxcore/friend_connection.c6
-rw-r--r--toxcore/friend_connection.h4
-rw-r--r--toxcore/group.c4
-rw-r--r--toxcore/net_crypto.c5
-rw-r--r--toxcore/net_crypto.h5
-rw-r--r--toxcore/tox.c28
-rw-r--r--toxcore/tox.h14
14 files changed, 128 insertions, 136 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index 7efb5465..3928bc9c 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -647,7 +647,7 @@ START_TEST(test_few_clients)
647 ck_assert_msg(err_t == TOX_ERR_FRIEND_QUERY_OK, "Typing fail"); 647 ck_assert_msg(err_t == TOX_ERR_FRIEND_QUERY_OK, "Typing fail");
648 648
649 uint32_t packet_number = 160; 649 uint32_t packet_number = 160;
650 tox_callback_friend_lossless_packet(tox3, &handle_custom_packet, &packet_number); 650 tox_callback_friend_lossless_packet(tox3, &handle_custom_packet);
651 uint8_t data_c[TOX_MAX_CUSTOM_PACKET_SIZE + 1]; 651 uint8_t data_c[TOX_MAX_CUSTOM_PACKET_SIZE + 1];
652 memset(data_c, ((uint8_t)packet_number), sizeof(data_c)); 652 memset(data_c, ((uint8_t)packet_number), sizeof(data_c));
653 int ret = tox_friend_send_lossless_packet(tox2, 0, data_c, sizeof(data_c), 0); 653 int ret = tox_friend_send_lossless_packet(tox2, 0, data_c, sizeof(data_c), 0);
@@ -659,7 +659,7 @@ START_TEST(test_few_clients)
659 custom_packet = 0; 659 custom_packet = 0;
660 tox_iterate(tox1, &to_compare); 660 tox_iterate(tox1, &to_compare);
661 tox_iterate(tox2, &to_compare); 661 tox_iterate(tox2, &to_compare);
662 tox_iterate(tox3, &to_compare); 662 tox_iterate(tox3, &packet_number);
663 663
664 if (custom_packet == 1) { 664 if (custom_packet == 1) {
665 break; 665 break;
@@ -671,7 +671,7 @@ START_TEST(test_few_clients)
671 } 671 }
672 672
673 packet_number = 200; 673 packet_number = 200;
674 tox_callback_friend_lossy_packet(tox3, &handle_custom_packet, &packet_number); 674 tox_callback_friend_lossy_packet(tox3, &handle_custom_packet);
675 memset(data_c, ((uint8_t)packet_number), sizeof(data_c)); 675 memset(data_c, ((uint8_t)packet_number), sizeof(data_c));
676 ret = tox_friend_send_lossy_packet(tox2, 0, data_c, sizeof(data_c), 0); 676 ret = tox_friend_send_lossy_packet(tox2, 0, data_c, sizeof(data_c), 0);
677 ck_assert_msg(ret == 0, "tox_friend_send_lossy_packet bigger fail %i", ret); 677 ck_assert_msg(ret == 0, "tox_friend_send_lossy_packet bigger fail %i", ret);
@@ -682,7 +682,7 @@ START_TEST(test_few_clients)
682 custom_packet = 0; 682 custom_packet = 0;
683 tox_iterate(tox1, &to_compare); 683 tox_iterate(tox1, &to_compare);
684 tox_iterate(tox2, &to_compare); 684 tox_iterate(tox2, &to_compare);
685 tox_iterate(tox3, &to_compare); 685 tox_iterate(tox3, &packet_number);
686 686
687 if (custom_packet == 1) { 687 if (custom_packet == 1) {
688 break; 688 break;
@@ -699,11 +699,11 @@ START_TEST(test_few_clients)
699 file_recv = 0; 699 file_recv = 0;
700 max_sending = UINT64_MAX; 700 max_sending = UINT64_MAX;
701 long long unsigned int f_time = time(NULL); 701 long long unsigned int f_time = time(NULL);
702 tox_callback_file_recv_chunk(tox3, write_file, &to_compare); 702 tox_callback_file_recv_chunk(tox3, write_file);
703 tox_callback_file_recv_control(tox2, file_print_control, &to_compare); 703 tox_callback_file_recv_control(tox2, file_print_control);
704 tox_callback_file_chunk_request(tox2, tox_file_chunk_request, &to_compare); 704 tox_callback_file_chunk_request(tox2, tox_file_chunk_request);
705 tox_callback_file_recv_control(tox3, file_print_control, &to_compare); 705 tox_callback_file_recv_control(tox3, file_print_control);
706 tox_callback_file_recv(tox3, tox_file_receive, &to_compare); 706 tox_callback_file_recv(tox3, tox_file_receive);
707 uint64_t totalf_size = 100 * 1024 * 1024; 707 uint64_t totalf_size = 100 * 1024 * 1024;
708 uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", 708 uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe",
709 sizeof("Gentoo.exe"), 0); 709 sizeof("Gentoo.exe"), 0);
@@ -746,11 +746,11 @@ START_TEST(test_few_clients)
746 746
747 file_sending_done = file_accepted = file_size = sendf_ok = size_recv = 0; 747 file_sending_done = file_accepted = file_size = sendf_ok = size_recv = 0;
748 file_recv = 0; 748 file_recv = 0;
749 tox_callback_file_recv_chunk(tox3, write_file, &to_compare); 749 tox_callback_file_recv_chunk(tox3, write_file);
750 tox_callback_file_recv_control(tox2, file_print_control, &to_compare); 750 tox_callback_file_recv_control(tox2, file_print_control);
751 tox_callback_file_chunk_request(tox2, tox_file_chunk_request, &to_compare); 751 tox_callback_file_chunk_request(tox2, tox_file_chunk_request);
752 tox_callback_file_recv_control(tox3, file_print_control, &to_compare); 752 tox_callback_file_recv_control(tox3, file_print_control);
753 tox_callback_file_recv(tox3, tox_file_receive, &to_compare); 753 tox_callback_file_recv(tox3, tox_file_receive);
754 totalf_size = UINT64_MAX; 754 totalf_size = UINT64_MAX;
755 fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), 755 fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"),
756 0); 756 0);
@@ -794,11 +794,11 @@ START_TEST(test_few_clients)
794 794
795 file_sending_done = file_accepted = file_size = sendf_ok = size_recv = 0; 795 file_sending_done = file_accepted = file_size = sendf_ok = size_recv = 0;
796 file_recv = 0; 796 file_recv = 0;
797 tox_callback_file_recv_chunk(tox3, write_file, &to_compare); 797 tox_callback_file_recv_chunk(tox3, write_file);
798 tox_callback_file_recv_control(tox2, file_print_control, &to_compare); 798 tox_callback_file_recv_control(tox2, file_print_control);
799 tox_callback_file_chunk_request(tox2, tox_file_chunk_request, &to_compare); 799 tox_callback_file_chunk_request(tox2, tox_file_chunk_request);
800 tox_callback_file_recv_control(tox3, file_print_control, &to_compare); 800 tox_callback_file_recv_control(tox3, file_print_control);
801 tox_callback_file_recv(tox3, tox_file_receive, &to_compare); 801 tox_callback_file_recv(tox3, tox_file_receive);
802 totalf_size = 0; 802 totalf_size = 0;
803 fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), 803 fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"),
804 0); 804 0);
@@ -908,6 +908,8 @@ loop_top:
908 908
909 ck_assert_msg(num_f == NUM_FRIENDS, "bad num friends: %u", num_f); 909 ck_assert_msg(num_f == NUM_FRIENDS, "bad num friends: %u", num_f);
910 910
911 uint16_t last_count = 0;
912
911 while (1) { 913 while (1) {
912 uint16_t counter = 0; 914 uint16_t counter = 0;
913 915
@@ -919,6 +921,11 @@ loop_top:
919 } 921 }
920 } 922 }
921 923
924 if (counter != last_count) {
925 printf("got to %u\n", counter);
926 last_count = counter;
927 }
928
922 if (counter == NUM_FRIENDS * 2) { 929 if (counter == NUM_FRIENDS * 2) {
923 break; 930 break;
924 } 931 }
diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h
index 959eb0d6..7953d4f6 100644
--- a/other/apidsl/tox.in.h
+++ b/other/apidsl/tox.in.h
@@ -1366,7 +1366,7 @@ namespace friend {
1366 * This callback is not called when adding friends. It is assumed that when 1366 * This callback is not called when adding friends. It is assumed that when
1367 * adding friends, their connection status is initially offline. 1367 * adding friends, their connection status is initially offline.
1368 */ 1368 */
1369 event connection_status { 1369 event connection_status const {
1370 /** 1370 /**
1371 * @param friend_number The friend number of the friend whose connection status 1371 * @param friend_number The friend number of the friend whose connection status
1372 * changed. 1372 * changed.
@@ -1687,7 +1687,7 @@ namespace file {
1687 * This event is triggered when a file control command is received from a 1687 * This event is triggered when a file control command is received from a
1688 * friend. 1688 * friend.
1689 */ 1689 */
1690 event recv_control { 1690 event recv_control const {
1691 /** 1691 /**
1692 * When receiving ${CONTROL.CANCEL}, the client should release the 1692 * When receiving ${CONTROL.CANCEL}, the client should release the
1693 * resources associated with the file number and consider the transfer failed. 1693 * resources associated with the file number and consider the transfer failed.
@@ -1916,7 +1916,7 @@ namespace file {
1916 /** 1916 /**
1917 * This event is triggered when Core is ready to send more file data. 1917 * This event is triggered when Core is ready to send more file data.
1918 */ 1918 */
1919 event chunk_request { 1919 event chunk_request const {
1920 /** 1920 /**
1921 * If the length parameter is 0, the file transfer is finished, and the client's 1921 * If the length parameter is 0, the file transfer is finished, and the client's
1922 * resources associated with the file number should be released. After a call 1922 * resources associated with the file number should be released. After a call
@@ -1957,7 +1957,7 @@ namespace file {
1957 /** 1957 /**
1958 * This event is triggered when a file transfer request is received. 1958 * This event is triggered when a file transfer request is received.
1959 */ 1959 */
1960 event recv { 1960 event recv const {
1961 /** 1961 /**
1962 * The client should acquire resources to be associated with the file transfer. 1962 * The client should acquire resources to be associated with the file transfer.
1963 * Incoming file transfers start in the PAUSED state. After this callback 1963 * Incoming file transfers start in the PAUSED state. After this callback
@@ -1985,7 +1985,7 @@ namespace file {
1985 * This event is first triggered when a file transfer request is received, and 1985 * This event is first triggered when a file transfer request is received, and
1986 * subsequently when a chunk of file data for an accepted request was received. 1986 * subsequently when a chunk of file data for an accepted request was received.
1987 */ 1987 */
1988 event recv_chunk { 1988 event recv_chunk const {
1989 /** 1989 /**
1990 * When length is 0, the transfer is finished and the client should release the 1990 * When length is 0, the transfer is finished and the client should release the
1991 * resources it acquired for the transfer. After a call with length = 0, the 1991 * resources it acquired for the transfer. After a call with length = 0, the
@@ -2109,7 +2109,7 @@ namespace friend {
2109 } 2109 }
2110 2110
2111 2111
2112 event lossy_packet { 2112 event lossy_packet const {
2113 /** 2113 /**
2114 * @param friend_number The friend number of the friend who sent a lossy packet. 2114 * @param friend_number The friend number of the friend who sent a lossy packet.
2115 * @param data A byte array containing the received packet data. 2115 * @param data A byte array containing the received packet data.
@@ -2119,7 +2119,7 @@ namespace friend {
2119 } 2119 }
2120 2120
2121 2121
2122 event lossless_packet { 2122 event lossless_packet const {
2123 /** 2123 /**
2124 * @param friend_number The friend number of the friend who sent the packet. 2124 * @param friend_number The friend number of the friend who sent the packet.
2125 * @param data A byte array containing the received packet data. 2125 * @param data A byte array containing the received packet data.
diff --git a/testing/nTox.c b/testing/nTox.c
index fe62e047..c014e33f 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -1345,12 +1345,12 @@ int main(int argc, char *argv[])
1345 tox_callback_friend_status_message(m, print_statuschange); 1345 tox_callback_friend_status_message(m, print_statuschange);
1346 tox_callback_group_invite(m, print_invite, NULL); 1346 tox_callback_group_invite(m, print_invite, NULL);
1347 tox_callback_group_message(m, print_groupmessage, NULL); 1347 tox_callback_group_message(m, print_groupmessage, NULL);
1348 tox_callback_file_recv_chunk(m, write_file, NULL); 1348 tox_callback_file_recv_chunk(m, write_file);
1349 tox_callback_file_recv_control(m, file_print_control, NULL); 1349 tox_callback_file_recv_control(m, file_print_control);
1350 tox_callback_file_recv(m, file_request_accept, NULL); 1350 tox_callback_file_recv(m, file_request_accept);
1351 tox_callback_file_chunk_request(m, tox_file_chunk_request, NULL); 1351 tox_callback_file_chunk_request(m, tox_file_chunk_request);
1352 tox_callback_group_namelist_change(m, print_groupnamelistchange, NULL); 1352 tox_callback_group_namelist_change(m, print_groupnamelistchange, NULL);
1353 tox_callback_friend_connection_status(m, print_online, NULL); 1353 tox_callback_friend_connection_status(m, print_online);
1354 1354
1355 initscr(); 1355 initscr();
1356 noecho(); 1356 noecho();
diff --git a/testing/tox_shell.c b/testing/tox_shell.c
index 40890453..944b7353 100644
--- a/testing/tox_shell.c
+++ b/testing/tox_shell.c
@@ -99,7 +99,7 @@ int main(int argc, char *argv[])
99 } 99 }
100 100
101 Tox *tox = tox_new(0, 0); 101 Tox *tox = tox_new(0, 0);
102 tox_callback_friend_connection_status(tox, print_online, NULL); 102 tox_callback_friend_connection_status(tox, print_online);
103 tox_callback_friend_message(tox, print_message); 103 tox_callback_friend_message(tox, print_message);
104 104
105 105
diff --git a/testing/tox_sync.c b/testing/tox_sync.c
index 36b01cf4..d90024b5 100644
--- a/testing/tox_sync.c
+++ b/testing/tox_sync.c
@@ -254,11 +254,11 @@ int main(int argc, char *argv[])
254 } 254 }
255 255
256 Tox *tox = tox_new(0, 0); 256 Tox *tox = tox_new(0, 0);
257 tox_callback_file_recv_chunk(tox, write_file, NULL); 257 tox_callback_file_recv_chunk(tox, write_file);
258 tox_callback_file_recv_control(tox, file_print_control, NULL); 258 tox_callback_file_recv_control(tox, file_print_control);
259 tox_callback_file_recv(tox, file_request_accept, NULL); 259 tox_callback_file_recv(tox, file_request_accept);
260 tox_callback_file_chunk_request(tox, tox_file_chunk_request, NULL); 260 tox_callback_file_chunk_request(tox, tox_file_chunk_request);
261 tox_callback_friend_connection_status(tox, print_online, NULL); 261 tox_callback_friend_connection_status(tox, print_online);
262 262
263 uint16_t port = atoi(argv[argvoffset + 2]); 263 uint16_t port = atoi(argv[argvoffset + 2]);
264 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]); 264 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 44664e3f..8616bd8d 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -36,7 +36,7 @@
36#include "util.h" 36#include "util.h"
37 37
38 38
39static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status); 39static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata);
40static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data, 40static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
41 uint32_t length, uint8_t congestion_control); 41 uint32_t length, uint8_t congestion_control);
42 42
@@ -170,7 +170,8 @@ static int send_offline_packet(Messenger *m, int friendcon_id)
170 170
171static int handle_status(void *object, int i, uint8_t status, void *userdata); 171static int handle_status(void *object, int i, uint8_t status, void *userdata);
172static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata); 172static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata);
173static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length); 173static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
174 void *userdata);
174 175
175static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status) 176static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status)
176{ 177{
@@ -873,11 +874,9 @@ void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, uint32
873 m->read_receipt = function; 874 m->read_receipt = function;
874} 875}
875 876
876void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *), 877void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *))
877 void *userdata)
878{ 878{
879 m->friend_connectionstatuschange = function; 879 m->friend_connectionstatuschange = function;
880 m->friend_connectionstatuschange_userdata = userdata;
881} 880}
882 881
883void m_callback_core_connection(Messenger *m, void (*function)(Messenger *m, unsigned int, void *)) 882void m_callback_core_connection(Messenger *m, void (*function)(Messenger *m, unsigned int, void *))
@@ -892,7 +891,7 @@ void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Mess
892 m->friend_connectionstatuschange_internal_userdata = userdata; 891 m->friend_connectionstatuschange_internal_userdata = userdata;
893} 892}
894 893
895static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber) 894static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userdata)
896{ 895{
897 int last_connection_udp_tcp = m->friendlist[friendnumber].last_connection_udp_tcp; 896 int last_connection_udp_tcp = m->friendlist[friendnumber].last_connection_udp_tcp;
898 897
@@ -912,7 +911,7 @@ static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber)
912 911
913 if (last_connection_udp_tcp != ret) { 912 if (last_connection_udp_tcp != ret) {
914 if (m->friend_connectionstatuschange) { 913 if (m->friend_connectionstatuschange) {
915 m->friend_connectionstatuschange(m, friendnumber, ret, m->friend_connectionstatuschange_userdata); 914 m->friend_connectionstatuschange(m, friendnumber, ret, userdata);
916 } 915 }
917 } 916 }
918 917
@@ -920,7 +919,7 @@ static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber)
920} 919}
921 920
922static void break_files(const Messenger *m, int32_t friendnumber); 921static void break_files(const Messenger *m, int32_t friendnumber);
923static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, uint8_t status) 922static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata)
924{ 923{
925 if (status == NOFRIEND) { 924 if (status == NOFRIEND) {
926 return; 925 return;
@@ -942,7 +941,7 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui
942 941
943 m->friendlist[friendnumber].status = status; 942 m->friendlist[friendnumber].status = status;
944 943
945 check_friend_tcp_udp(m, friendnumber); 944 check_friend_tcp_udp(m, friendnumber, userdata);
946 945
947 if (m->friend_connectionstatuschange_internal) { 946 if (m->friend_connectionstatuschange_internal) {
948 m->friend_connectionstatuschange_internal(m, friendnumber, is_online, 947 m->friend_connectionstatuschange_internal(m, friendnumber, is_online,
@@ -951,9 +950,9 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui
951 } 950 }
952} 951}
953 952
954void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status) 953void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata)
955{ 954{
956 check_friend_connectionstatus(m, friendnumber, status); 955 check_friend_connectionstatus(m, friendnumber, status, userdata);
957 m->friendlist[friendnumber].status = status; 956 m->friendlist[friendnumber].status = status;
958} 957}
959 958
@@ -1010,10 +1009,9 @@ int send_group_invite_packet(const Messenger *m, int32_t friendnumber, const uin
1010 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t filetype, uint64_t filesize, uint8_t *filename, size_t filename_length, void *userdata) 1009 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t filetype, uint64_t filesize, uint8_t *filename, size_t filename_length, void *userdata)
1011 */ 1010 */
1012void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, 1011void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t,
1013 const uint8_t *, size_t, void *), void *userdata) 1012 const uint8_t *, size_t, void *))
1014{ 1013{
1015 m->file_sendrequest = function; 1014 m->file_sendrequest = function;
1016 m->file_sendrequest_userdata = userdata;
1017} 1015}
1018 1016
1019/* Set the callback for file control requests. 1017/* Set the callback for file control requests.
@@ -1021,11 +1019,9 @@ void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uin
1021 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, unsigned int control_type, void *userdata) 1019 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, unsigned int control_type, void *userdata)
1022 * 1020 *
1023 */ 1021 */
1024void callback_file_control(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, unsigned int, void *), 1022void callback_file_control(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, unsigned int, void *))
1025 void *userdata)
1026{ 1023{
1027 m->file_filecontrol = function; 1024 m->file_filecontrol = function;
1028 m->file_filecontrol_userdata = userdata;
1029} 1025}
1030 1026
1031/* Set the callback for file data. 1027/* Set the callback for file data.
@@ -1034,10 +1030,9 @@ void callback_file_control(Messenger *m, void (*function)(Messenger *m, uint32_t
1034 * 1030 *
1035 */ 1031 */
1036void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, 1032void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *,
1037 size_t, void *), void *userdata) 1033 size_t, void *))
1038{ 1034{
1039 m->file_filedata = function; 1035 m->file_filedata = function;
1040 m->file_filedata_userdata = userdata;
1041} 1036}
1042 1037
1043/* Set the callback for file request chunk. 1038/* Set the callback for file request chunk.
@@ -1045,11 +1040,9 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, u
1045 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length, void *userdata) 1040 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length, void *userdata)
1046 * 1041 *
1047 */ 1042 */
1048void callback_file_reqchunk(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *), 1043void callback_file_reqchunk(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *))
1049 void *userdata)
1050{ 1044{
1051 m->file_reqchunk = function; 1045 m->file_reqchunk = function;
1052 m->file_reqchunk_userdata = userdata;
1053} 1046}
1054 1047
1055#define MAX_FILENAME_LENGTH 255 1048#define MAX_FILENAME_LENGTH 255
@@ -1512,7 +1505,7 @@ uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t fi
1512 m->friendlist[friendnumber].file_receiving[filenumber].transferred; 1505 m->friendlist[friendnumber].file_receiving[filenumber].transferred;
1513} 1506}
1514 1507
1515static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber) 1508static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdata)
1516{ 1509{
1517 if (!m->friendlist[friendnumber].num_sending_files) { 1510 if (!m->friendlist[friendnumber].num_sending_files) {
1518 return; 1511 return;
@@ -1539,7 +1532,7 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber)
1539 /* Check if file was entirely sent. */ 1532 /* Check if file was entirely sent. */
1540 if (friend_received_packet(m, friendnumber, ft->last_packet_number) == 0) { 1533 if (friend_received_packet(m, friendnumber, ft->last_packet_number) == 0) {
1541 if (m->file_reqchunk) { 1534 if (m->file_reqchunk) {
1542 (*m->file_reqchunk)(m, friendnumber, i, ft->transferred, 0, m->file_reqchunk_userdata); 1535 (*m->file_reqchunk)(m, friendnumber, i, ft->transferred, 0, userdata);
1543 } 1536 }
1544 1537
1545 ft->status = FILESTATUS_NONE; 1538 ft->status = FILESTATUS_NONE;
@@ -1587,7 +1580,7 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber)
1587 ft->requested += length; 1580 ft->requested += length;
1588 1581
1589 if (m->file_reqchunk) { 1582 if (m->file_reqchunk) {
1590 (*m->file_reqchunk)(m, friendnumber, i, position, length, m->file_reqchunk_userdata); 1583 (*m->file_reqchunk)(m, friendnumber, i, position, length, userdata);
1591 } 1584 }
1592 1585
1593 --free_slots; 1586 --free_slots;
@@ -1621,7 +1614,7 @@ static void break_files(const Messenger *m, int32_t friendnumber)
1621/* return -1 on failure, 0 on success. 1614/* return -1 on failure, 0 on success.
1622 */ 1615 */
1623static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, 1616static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber,
1624 uint8_t control_type, const uint8_t *data, uint16_t length) 1617 uint8_t control_type, const uint8_t *data, uint16_t length, void *userdata)
1625{ 1618{
1626 if (receive_send > 1) { 1619 if (receive_send > 1) {
1627 return -1; 1620 return -1;
@@ -1660,7 +1653,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
1660 } 1653 }
1661 1654
1662 if (m->file_filecontrol) { 1655 if (m->file_filecontrol) {
1663 (*m->file_filecontrol)(m, friendnumber, real_filenumber, control_type, m->file_filecontrol_userdata); 1656 (*m->file_filecontrol)(m, friendnumber, real_filenumber, control_type, userdata);
1664 } 1657 }
1665 } else if (control_type == FILECONTROL_PAUSE) { 1658 } else if (control_type == FILECONTROL_PAUSE) {
1666 if ((ft->paused & FILE_PAUSE_OTHER) || ft->status != FILESTATUS_TRANSFERRING) { 1659 if ((ft->paused & FILE_PAUSE_OTHER) || ft->status != FILESTATUS_TRANSFERRING) {
@@ -1670,12 +1663,12 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
1670 ft->paused |= FILE_PAUSE_OTHER; 1663 ft->paused |= FILE_PAUSE_OTHER;
1671 1664
1672 if (m->file_filecontrol) { 1665 if (m->file_filecontrol) {
1673 (*m->file_filecontrol)(m, friendnumber, real_filenumber, control_type, m->file_filecontrol_userdata); 1666 (*m->file_filecontrol)(m, friendnumber, real_filenumber, control_type, userdata);
1674 } 1667 }
1675 } else if (control_type == FILECONTROL_KILL) { 1668 } else if (control_type == FILECONTROL_KILL) {
1676 1669
1677 if (m->file_filecontrol) { 1670 if (m->file_filecontrol) {
1678 (*m->file_filecontrol)(m, friendnumber, real_filenumber, control_type, m->file_filecontrol_userdata); 1671 (*m->file_filecontrol)(m, friendnumber, real_filenumber, control_type, userdata);
1679 } 1672 }
1680 1673
1681 ft->status = FILESTATUS_NONE; 1674 ft->status = FILESTATUS_NONE;
@@ -1733,7 +1726,8 @@ int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data,
1733 return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length, 0); 1726 return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length, 0);
1734} 1727}
1735 1728
1736static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length) 1729static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
1730 void *userdata)
1737{ 1731{
1738 Messenger *m = object; 1732 Messenger *m = object;
1739 1733
@@ -1752,17 +1746,16 @@ static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_
1752 } 1746 }
1753 1747
1754 if (m->lossy_packethandler) { 1748 if (m->lossy_packethandler) {
1755 m->lossy_packethandler(m, friend_num, packet, length, m->lossy_packethandler_userdata); 1749 m->lossy_packethandler(m, friend_num, packet, length, userdata);
1756 } 1750 }
1757 1751
1758 return 1; 1752 return 1;
1759} 1753}
1760 1754
1761void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, 1755void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m,
1762 uint32_t friendnumber, const uint8_t *data, size_t len, void *object), void *object) 1756 uint32_t friendnumber, const uint8_t *data, size_t len, void *object))
1763{ 1757{
1764 m->lossy_packethandler = packet_handler_callback; 1758 m->lossy_packethandler = packet_handler_callback;
1765 m->lossy_packethandler_userdata = object;
1766} 1759}
1767 1760
1768int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int (*packet_handler_callback)(Messenger *m, 1761int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int (*packet_handler_callback)(Messenger *m,
@@ -1817,7 +1810,8 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin
1817 return 0; 1810 return 0;
1818} 1811}
1819 1812
1820static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length) 1813static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
1814 void *userdata)
1821{ 1815{
1822 Messenger *m = object; 1816 Messenger *m = object;
1823 1817
@@ -1834,17 +1828,16 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin
1834 } 1828 }
1835 1829
1836 if (m->lossless_packethandler) { 1830 if (m->lossless_packethandler) {
1837 m->lossless_packethandler(m, friend_num, packet, length, m->lossless_packethandler_userdata); 1831 m->lossless_packethandler(m, friend_num, packet, length, userdata);
1838 } 1832 }
1839 1833
1840 return 1; 1834 return 1;
1841} 1835}
1842 1836
1843void custom_lossless_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, 1837void custom_lossless_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m,
1844 uint32_t friendnumber, const uint8_t *data, size_t len, void *object), void *object) 1838 uint32_t friendnumber, const uint8_t *data, size_t len, void *object))
1845{ 1839{
1846 m->lossless_packethandler = packet_handler_callback; 1840 m->lossless_packethandler = packet_handler_callback;
1847 m->lossless_packethandler_userdata = object;
1848} 1841}
1849 1842
1850int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) 1843int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length)
@@ -2026,12 +2019,12 @@ void kill_messenger(Messenger *m)
2026 * i: friendlist index of the timed-out friend 2019 * i: friendlist index of the timed-out friend
2027 * t: time 2020 * t: time
2028 */ 2021 */
2029static void check_friend_request_timed_out(Messenger *m, uint32_t i, uint64_t t) 2022static void check_friend_request_timed_out(Messenger *m, uint32_t i, uint64_t t, void *userdata)
2030{ 2023{
2031 Friend *f = &m->friendlist[i]; 2024 Friend *f = &m->friendlist[i];
2032 2025
2033 if (f->friendrequest_lastsent + f->friendrequest_timeout < t) { 2026 if (f->friendrequest_lastsent + f->friendrequest_timeout < t) {
2034 set_friend_status(m, i, FRIEND_ADDED); 2027 set_friend_status(m, i, FRIEND_ADDED, userdata);
2035 /* Double the default timeout every time if friendrequest is assumed 2028 /* Double the default timeout every time if friendrequest is assumed
2036 * to have been sent unsuccessfully. 2029 * to have been sent unsuccessfully.
2037 */ 2030 */
@@ -2047,7 +2040,7 @@ static int handle_status(void *object, int i, uint8_t status, void *userdata)
2047 send_online_packet(m, i); 2040 send_online_packet(m, i);
2048 } else { /* Went offline. */ 2041 } else { /* Went offline. */
2049 if (m->friendlist[i].status == FRIEND_ONLINE) { 2042 if (m->friendlist[i].status == FRIEND_ONLINE) {
2050 set_friend_status(m, i, FRIEND_CONFIRMED); 2043 set_friend_status(m, i, FRIEND_CONFIRMED, userdata);
2051 } 2044 }
2052 } 2045 }
2053 2046
@@ -2067,7 +2060,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2067 2060
2068 if (m->friendlist[i].status != FRIEND_ONLINE) { 2061 if (m->friendlist[i].status != FRIEND_ONLINE) {
2069 if (packet_id == PACKET_ID_ONLINE && len == 1) { 2062 if (packet_id == PACKET_ID_ONLINE && len == 1) {
2070 set_friend_status(m, i, FRIEND_ONLINE); 2063 set_friend_status(m, i, FRIEND_ONLINE, userdata);
2071 send_online_packet(m, i); 2064 send_online_packet(m, i);
2072 } else { 2065 } else {
2073 return -1; 2066 return -1;
@@ -2080,7 +2073,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2080 break; 2073 break;
2081 } 2074 }
2082 2075
2083 set_friend_status(m, i, FRIEND_CONFIRMED); 2076 set_friend_status(m, i, FRIEND_CONFIRMED, userdata);
2084 break; 2077 break;
2085 } 2078 }
2086 2079
@@ -2246,7 +2239,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2246 2239
2247 if (m->file_sendrequest) { 2240 if (m->file_sendrequest) {
2248 (*m->file_sendrequest)(m, i, real_filenumber, file_type, filesize, filename, filename_length, 2241 (*m->file_sendrequest)(m, i, real_filenumber, file_type, filesize, filename, filename_length,
2249 m->file_sendrequest_userdata); 2242 userdata);
2250 } 2243 }
2251 2244
2252 break; 2245 break;
@@ -2265,7 +2258,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2265 break; 2258 break;
2266 } 2259 }
2267 2260
2268 if (handle_filecontrol(m, i, send_receive, filenumber, control_type, data + 3, data_length - 3) == -1) { 2261 if (handle_filecontrol(m, i, send_receive, filenumber, control_type, data + 3, data_length - 3, userdata) == -1) {
2269 break; 2262 break;
2270 } 2263 }
2271 2264
@@ -2308,7 +2301,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2308 } 2301 }
2309 2302
2310 if (m->file_filedata) { 2303 if (m->file_filedata) {
2311 (*m->file_filedata)(m, i, real_filenumber, position, file_data, file_data_length, m->file_filedata_userdata); 2304 (*m->file_filedata)(m, i, real_filenumber, position, file_data, file_data_length, userdata);
2312 } 2305 }
2313 2306
2314 ft->transferred += file_data_length; 2307 ft->transferred += file_data_length;
@@ -2320,7 +2313,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2320 2313
2321 /* Full file received. */ 2314 /* Full file received. */
2322 if (m->file_filedata) { 2315 if (m->file_filedata) {
2323 (*m->file_filedata)(m, i, real_filenumber, position, file_data, file_data_length, m->file_filedata_userdata); 2316 (*m->file_filedata)(m, i, real_filenumber, position, file_data, file_data_length, userdata);
2324 } 2317 }
2325 } 2318 }
2326 2319
@@ -2345,7 +2338,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2345 } 2338 }
2346 2339
2347 default: { 2340 default: {
2348 handle_custom_lossless_packet(object, i, temp, len); 2341 handle_custom_lossless_packet(object, i, temp, len, userdata);
2349 break; 2342 break;
2350 } 2343 }
2351 } 2344 }
@@ -2365,7 +2358,7 @@ static void do_friends(Messenger *m, void *userdata)
2365 m->friendlist[i].info_size); 2358 m->friendlist[i].info_size);
2366 2359
2367 if (fr >= 0) { 2360 if (fr >= 0) {
2368 set_friend_status(m, i, FRIEND_REQUESTED); 2361 set_friend_status(m, i, FRIEND_REQUESTED, userdata);
2369 m->friendlist[i].friendrequest_lastsent = temp_time; 2362 m->friendlist[i].friendrequest_lastsent = temp_time;
2370 } 2363 }
2371 } 2364 }
@@ -2376,7 +2369,7 @@ static void do_friends(Messenger *m, void *userdata)
2376 /* If we didn't connect to friend after successfully sending him a friend request the request is deemed 2369 /* If we didn't connect to friend after successfully sending him a friend request the request is deemed
2377 * unsuccessful so we set the status back to FRIEND_ADDED and try again. 2370 * unsuccessful so we set the status back to FRIEND_ADDED and try again.
2378 */ 2371 */
2379 check_friend_request_timed_out(m, i, temp_time); 2372 check_friend_request_timed_out(m, i, temp_time, userdata);
2380 } 2373 }
2381 } 2374 }
2382 2375
@@ -2405,9 +2398,9 @@ static void do_friends(Messenger *m, void *userdata)
2405 } 2398 }
2406 } 2399 }
2407 2400
2408 check_friend_tcp_udp(m, i); 2401 check_friend_tcp_udp(m, i, userdata);
2409 do_receipts(m, i, userdata); 2402 do_receipts(m, i, userdata);
2410 do_reqchunk_filecb(m, i); 2403 do_reqchunk_filecb(m, i, userdata);
2411 2404
2412 m->friendlist[i].last_seen_time = (uint64_t) time(NULL); 2405 m->friendlist[i].last_seen_time = (uint64_t) time(NULL);
2413 } 2406 }
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index dc809a22..21d9f7b3 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -245,7 +245,6 @@ struct Messenger {
245 void (*friend_typingchange)(struct Messenger *m, uint32_t, _Bool, void *); 245 void (*friend_typingchange)(struct Messenger *m, uint32_t, _Bool, void *);
246 void (*read_receipt)(struct Messenger *m, uint32_t, uint32_t, void *); 246 void (*read_receipt)(struct Messenger *m, uint32_t, uint32_t, void *);
247 void (*friend_connectionstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); 247 void (*friend_connectionstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *);
248 void *friend_connectionstatuschange_userdata;
249 void (*friend_connectionstatuschange_internal)(struct Messenger *m, uint32_t, uint8_t, void *); 248 void (*friend_connectionstatuschange_internal)(struct Messenger *m, uint32_t, uint8_t, void *);
250 void *friend_connectionstatuschange_internal_userdata; 249 void *friend_connectionstatuschange_internal_userdata;
251 250
@@ -255,21 +254,15 @@ struct Messenger {
255 254
256 void (*file_sendrequest)(struct Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, 255 void (*file_sendrequest)(struct Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t,
257 void *); 256 void *);
258 void *file_sendrequest_userdata;
259 void (*file_filecontrol)(struct Messenger *m, uint32_t, uint32_t, unsigned int, void *); 257 void (*file_filecontrol)(struct Messenger *m, uint32_t, uint32_t, unsigned int, void *);
260 void *file_filecontrol_userdata;
261 void (*file_filedata)(struct Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *); 258 void (*file_filedata)(struct Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
262 void *file_filedata_userdata;
263 void (*file_reqchunk)(struct Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *); 259 void (*file_reqchunk)(struct Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *);
264 void *file_reqchunk_userdata;
265 260
266 void (*msi_packet)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *); 261 void (*msi_packet)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);
267 void *msi_packet_userdata; 262 void *msi_packet_userdata;
268 263
269 void (*lossy_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 264 void (*lossy_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
270 void *lossy_packethandler_userdata;
271 void (*lossless_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 265 void (*lossless_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
272 void *lossless_packethandler_userdata;
273 266
274 void (*core_connection_change)(struct Messenger *m, unsigned int, void *); 267 void (*core_connection_change)(struct Messenger *m, unsigned int, void *);
275 unsigned int last_connection_status; 268 unsigned int last_connection_status;
@@ -525,8 +518,7 @@ void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, uint32
525 * being previously online" part. 518 * being previously online" part.
526 * It's assumed that when adding friends, their connection status is offline. 519 * It's assumed that when adding friends, their connection status is offline.
527 */ 520 */
528void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *), 521void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *));
529 void *userdata);
530 522
531/* Same as previous but for internal A/V core usage only */ 523/* Same as previous but for internal A/V core usage only */
532void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, uint32_t, uint8_t, void *), 524void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, uint32_t, uint8_t, void *),
@@ -561,7 +553,7 @@ int send_group_invite_packet(const Messenger *m, int32_t friendnumber, const uin
561 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t filetype, uint64_t filesize, uint8_t *filename, size_t filename_length, void *userdata) 553 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t filetype, uint64_t filesize, uint8_t *filename, size_t filename_length, void *userdata)
562 */ 554 */
563void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, 555void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t,
564 const uint8_t *, size_t, void *), void *userdata); 556 const uint8_t *, size_t, void *));
565 557
566 558
567/* Set the callback for file control requests. 559/* Set the callback for file control requests.
@@ -569,8 +561,7 @@ void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uin
569 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, unsigned int control_type, void *userdata) 561 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, unsigned int control_type, void *userdata)
570 * 562 *
571 */ 563 */
572void callback_file_control(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, unsigned int, void *), 564void callback_file_control(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, unsigned int, void *));
573 void *userdata);
574 565
575/* Set the callback for file data. 566/* Set the callback for file data.
576 * 567 *
@@ -578,15 +569,14 @@ void callback_file_control(Messenger *m, void (*function)(Messenger *m, uint32_t
578 * 569 *
579 */ 570 */
580void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, 571void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *,
581 size_t, void *), void *userdata); 572 size_t, void *));
582 573
583/* Set the callback for file request chunk. 574/* Set the callback for file request chunk.
584 * 575 *
585 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length, void *userdata) 576 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length, void *userdata)
586 * 577 *
587 */ 578 */
588void callback_file_reqchunk(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *), 579void callback_file_reqchunk(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *));
589 void *userdata);
590 580
591 581
592/* Copy the file transfer file id to file_id 582/* Copy the file transfer file id to file_id
@@ -689,7 +679,7 @@ int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int
689 * 679 *
690 */ 680 */
691void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, 681void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m,
692 uint32_t friendnumber, const uint8_t *data, size_t len, void *object), void *object); 682 uint32_t friendnumber, const uint8_t *data, size_t len, void *object));
693 683
694/* High level function to send custom lossy packets. 684/* High level function to send custom lossy packets.
695 * 685 *
@@ -707,7 +697,7 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin
707 * 697 *
708 */ 698 */
709void custom_lossless_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, 699void custom_lossless_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m,
710 uint32_t friendnumber, const uint8_t *data, size_t len, void *object), void *object); 700 uint32_t friendnumber, const uint8_t *data, size_t len, void *object));
711 701
712/* High level function to send custom lossless packets. 702/* High level function to send custom lossless packets.
713 * 703 *
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c
index d2d305aa..9e78a0c5 100644
--- a/toxcore/friend_connection.c
+++ b/toxcore/friend_connection.c
@@ -454,7 +454,7 @@ static int handle_packet(void *object, int number, const uint8_t *data, uint16_t
454 return 0; 454 return 0;
455} 455}
456 456
457static int handle_lossy_packet(void *object, int number, const uint8_t *data, uint16_t length) 457static int handle_lossy_packet(void *object, int number, const uint8_t *data, uint16_t length, void *userdata)
458{ 458{
459 if (length == 0) { 459 if (length == 0) {
460 return -1; 460 return -1;
@@ -472,7 +472,7 @@ static int handle_lossy_packet(void *object, int number, const uint8_t *data, ui
472 for (i = 0; i < MAX_FRIEND_CONNECTION_CALLBACKS; ++i) { 472 for (i = 0; i < MAX_FRIEND_CONNECTION_CALLBACKS; ++i) {
473 if (friend_con->callbacks[i].lossy_data_callback) { 473 if (friend_con->callbacks[i].lossy_data_callback) {
474 friend_con->callbacks[i].lossy_data_callback(friend_con->callbacks[i].lossy_data_callback_object, 474 friend_con->callbacks[i].lossy_data_callback(friend_con->callbacks[i].lossy_data_callback_object,
475 friend_con->callbacks[i].lossy_data_callback_id, data, length); 475 friend_con->callbacks[i].lossy_data_callback_id, data, length, userdata);
476 } 476 }
477 477
478 friend_con = get_conn(fr_c, number); 478 friend_con = get_conn(fr_c, number);
@@ -649,7 +649,7 @@ void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *
649int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index, 649int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index,
650 int (*status_callback)(void *object, int id, uint8_t status, void *userdata), 650 int (*status_callback)(void *object, int id, uint8_t status, void *userdata),
651 int (*data_callback)(void *object, int id, const uint8_t *data, uint16_t len, void *userdata), 651 int (*data_callback)(void *object, int id, const uint8_t *data, uint16_t len, void *userdata),
652 int (*lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), 652 int (*lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata),
653 void *object, int number) 653 void *object, int number)
654{ 654{
655 Friend_Conn *friend_con = get_conn(fr_c, friendcon_id); 655 Friend_Conn *friend_con = get_conn(fr_c, friendcon_id);
diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h
index 6eb4dd84..c5179a6a 100644
--- a/toxcore/friend_connection.h
+++ b/toxcore/friend_connection.h
@@ -87,7 +87,7 @@ typedef struct {
87 void *data_callback_object; 87 void *data_callback_object;
88 int data_callback_id; 88 int data_callback_id;
89 89
90 int (*lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length); 90 int (*lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
91 void *lossy_data_callback_object; 91 void *lossy_data_callback_object;
92 int lossy_data_callback_id; 92 int lossy_data_callback_id;
93 } callbacks[MAX_FRIEND_CONNECTION_CALLBACKS]; 93 } callbacks[MAX_FRIEND_CONNECTION_CALLBACKS];
@@ -161,7 +161,7 @@ int friend_add_tcp_relay(Friend_Connections *fr_c, int friendcon_id, IP_Port ip_
161int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index, 161int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index,
162 int (*status_callback)(void *object, int id, uint8_t status, void *userdata), 162 int (*status_callback)(void *object, int id, uint8_t status, void *userdata),
163 int (*data_callback)(void *object, int id, const uint8_t *data, uint16_t len, void *userdata), 163 int (*data_callback)(void *object, int id, const uint8_t *data, uint16_t len, void *userdata),
164 int (*lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), 164 int (*lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata),
165 void *object, int number); 165 void *object, int number);
166 166
167/* return the crypt_connection_id for the connection. 167/* return the crypt_connection_id for the connection.
diff --git a/toxcore/group.c b/toxcore/group.c
index dbfb31cd..c7844d6d 100644
--- a/toxcore/group.c
+++ b/toxcore/group.c
@@ -662,7 +662,7 @@ static int handle_status(void *object, int friendcon_id, uint8_t status, void *u
662} 662}
663 663
664static int handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata); 664static int handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata);
665static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length); 665static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata);
666 666
667/* Add friend to group chat. 667/* Add friend to group chat.
668 * 668 *
@@ -2174,7 +2174,7 @@ static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16
2174 return -1; 2174 return -1;
2175} 2175}
2176 2176
2177static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length) 2177static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata)
2178{ 2178{
2179 Group_Chats *g_c = object; 2179 Group_Chats *g_c = object;
2180 2180
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index e09d7444..72a34811 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -1443,7 +1443,7 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, con
1443 1443
1444 if (conn->connection_lossy_data_callback) { 1444 if (conn->connection_lossy_data_callback) {
1445 conn->connection_lossy_data_callback(conn->connection_lossy_data_callback_object, 1445 conn->connection_lossy_data_callback(conn->connection_lossy_data_callback_object,
1446 conn->connection_lossy_data_callback_id, real_data, real_length); 1446 conn->connection_lossy_data_callback_id, real_data, real_length, userdata);
1447 } 1447 }
1448 } else { 1448 } else {
1449 return -1; 1449 return -1;
@@ -2168,7 +2168,8 @@ int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*
2168 * return 0 on success. 2168 * return 0 on success.
2169 */ 2169 */
2170int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, 2170int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
2171 int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), void *object, int id) 2171 int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata),
2172 void *object, int id)
2172{ 2173{
2173 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2174 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2174 2175
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index c5eb3ecb..e676b864 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -139,7 +139,7 @@ typedef struct {
139 void *connection_data_callback_object; 139 void *connection_data_callback_object;
140 int connection_data_callback_id; 140 int connection_data_callback_id;
141 141
142 int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length); 142 int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
143 void *connection_lossy_data_callback_object; 143 void *connection_lossy_data_callback_object;
144 int connection_lossy_data_callback_id; 144 int connection_lossy_data_callback_id;
145 145
@@ -287,7 +287,8 @@ int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*
287 * return 0 on success. 287 * return 0 on success.
288 */ 288 */
289int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, 289int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
290 int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), void *object, 290 int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata),
291 void *object,
291 int id); 292 int id);
292 293
293/* Set the function for this friend that will be callbacked with object and number if 294/* Set the function for this friend that will be callbacked with object and number if
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 5a1103df..40746656 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -871,10 +871,10 @@ TOX_CONNECTION tox_friend_get_connection_status(const Tox *tox, uint32_t friend_
871 return ret; 871 return ret;
872} 872}
873 873
874void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback, void *user_data) 874void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback)
875{ 875{
876 Messenger *m = tox; 876 Messenger *m = tox;
877 m_callback_connectionstatus(m, callback, user_data); 877 m_callback_connectionstatus(m, callback);
878} 878}
879 879
880bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) 880bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
@@ -1077,10 +1077,10 @@ bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint6
1077 return 0; 1077 return 0;
1078} 1078}
1079 1079
1080void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback, void *user_data) 1080void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback)
1081{ 1081{
1082 Messenger *m = tox; 1082 Messenger *m = tox;
1083 callback_file_control(m, callback, user_data); 1083 callback_file_control(m, callback);
1084} 1084}
1085 1085
1086bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, 1086bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id,
@@ -1199,22 +1199,22 @@ bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number,
1199 return 0; 1199 return 0;
1200} 1200}
1201 1201
1202void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback, void *user_data) 1202void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback)
1203{ 1203{
1204 Messenger *m = tox; 1204 Messenger *m = tox;
1205 callback_file_reqchunk(m, callback, user_data); 1205 callback_file_reqchunk(m, callback);
1206} 1206}
1207 1207
1208void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback, void *user_data) 1208void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback)
1209{ 1209{
1210 Messenger *m = tox; 1210 Messenger *m = tox;
1211 callback_file_sendrequest(m, callback, user_data); 1211 callback_file_sendrequest(m, callback);
1212} 1212}
1213 1213
1214void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback, void *user_data) 1214void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback)
1215{ 1215{
1216 Messenger *m = tox; 1216 Messenger *m = tox;
1217 callback_file_data(m, callback, user_data); 1217 callback_file_data(m, callback);
1218} 1218}
1219 1219
1220static void set_custom_packet_error(int ret, TOX_ERR_FRIEND_CUSTOM_PACKET *error) 1220static void set_custom_packet_error(int ret, TOX_ERR_FRIEND_CUSTOM_PACKET *error)
@@ -1277,10 +1277,10 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_
1277 return 0; 1277 return 0;
1278} 1278}
1279 1279
1280void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback, void *user_data) 1280void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback)
1281{ 1281{
1282 Messenger *m = tox; 1282 Messenger *m = tox;
1283 custom_lossy_packet_registerhandler(m, callback, user_data); 1283 custom_lossy_packet_registerhandler(m, callback);
1284} 1284}
1285 1285
1286bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, 1286bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
@@ -1309,10 +1309,10 @@ bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uin
1309 return 0; 1309 return 0;
1310} 1310}
1311 1311
1312void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback, void *user_data) 1312void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback)
1313{ 1313{
1314 Messenger *m = tox; 1314 Messenger *m = tox;
1315 custom_lossless_packet_registerhandler(m, callback, user_data); 1315 custom_lossless_packet_registerhandler(m, callback);
1316} 1316}
1317 1317
1318void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id) 1318void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id)
diff --git a/toxcore/tox.h b/toxcore/tox.h
index f0e0b48c..60110ea8 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -1527,7 +1527,7 @@ typedef void tox_friend_connection_status_cb(Tox *tox, uint32_t friend_number, T
1527 * This callback is not called when adding friends. It is assumed that when 1527 * This callback is not called when adding friends. It is assumed that when
1528 * adding friends, their connection status is initially offline. 1528 * adding friends, their connection status is initially offline.
1529 */ 1529 */
1530void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback, void *user_data); 1530void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback);
1531 1531
1532/** 1532/**
1533 * Check whether a friend is currently typing a message. 1533 * Check whether a friend is currently typing a message.
@@ -1889,7 +1889,7 @@ typedef void tox_file_recv_control_cb(Tox *tox, uint32_t friend_number, uint32_t
1889 * This event is triggered when a file control command is received from a 1889 * This event is triggered when a file control command is received from a
1890 * friend. 1890 * friend.
1891 */ 1891 */
1892void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback, void *user_data); 1892void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback);
1893 1893
1894typedef enum TOX_ERR_FILE_SEEK { 1894typedef enum TOX_ERR_FILE_SEEK {
1895 1895
@@ -2193,7 +2193,7 @@ typedef void tox_file_chunk_request_cb(Tox *tox, uint32_t friend_number, uint32_
2193 * 2193 *
2194 * This event is triggered when Core is ready to send more file data. 2194 * This event is triggered when Core is ready to send more file data.
2195 */ 2195 */
2196void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback, void *user_data); 2196void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback);
2197 2197
2198 2198
2199/******************************************************************************* 2199/*******************************************************************************
@@ -2231,7 +2231,7 @@ typedef void tox_file_recv_cb(Tox *tox, uint32_t friend_number, uint32_t file_nu
2231 * 2231 *
2232 * This event is triggered when a file transfer request is received. 2232 * This event is triggered when a file transfer request is received.
2233 */ 2233 */
2234void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback, void *user_data); 2234void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback);
2235 2235
2236/** 2236/**
2237 * When length is 0, the transfer is finished and the client should release the 2237 * When length is 0, the transfer is finished and the client should release the
@@ -2259,7 +2259,7 @@ typedef void tox_file_recv_chunk_cb(Tox *tox, uint32_t friend_number, uint32_t f
2259 * This event is first triggered when a file transfer request is received, and 2259 * This event is first triggered when a file transfer request is received, and
2260 * subsequently when a chunk of file data for an accepted request was received. 2260 * subsequently when a chunk of file data for an accepted request was received.
2261 */ 2261 */
2262void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback, void *user_data); 2262void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback);
2263 2263
2264 2264
2265/******************************************************************************* 2265/*******************************************************************************
@@ -2389,7 +2389,7 @@ typedef void tox_friend_lossy_packet_cb(Tox *tox, uint32_t friend_number, const
2389 * Set the callback for the `friend_lossy_packet` event. Pass NULL to unset. 2389 * Set the callback for the `friend_lossy_packet` event. Pass NULL to unset.
2390 * 2390 *
2391 */ 2391 */
2392void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback, void *user_data); 2392void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback);
2393 2393
2394/** 2394/**
2395 * @param friend_number The friend number of the friend who sent the packet. 2395 * @param friend_number The friend number of the friend who sent the packet.
@@ -2404,7 +2404,7 @@ typedef void tox_friend_lossless_packet_cb(Tox *tox, uint32_t friend_number, con
2404 * Set the callback for the `friend_lossless_packet` event. Pass NULL to unset. 2404 * Set the callback for the `friend_lossless_packet` event. Pass NULL to unset.
2405 * 2405 *
2406 */ 2406 */
2407void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback, void *user_data); 2407void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback);
2408 2408
2409 2409
2410/******************************************************************************* 2410/*******************************************************************************