diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 6 | ||||
-rw-r--r-- | toxcore/LAN_discovery.c | 2 | ||||
-rw-r--r-- | toxcore/Messenger.c | 14 | ||||
-rw-r--r-- | toxcore/Messenger.h | 4 | ||||
-rw-r--r-- | toxcore/TCP_client.c | 23 | ||||
-rw-r--r-- | toxcore/TCP_client.h | 15 | ||||
-rw-r--r-- | toxcore/TCP_connection.c | 26 | ||||
-rw-r--r-- | toxcore/TCP_connection.h | 10 | ||||
-rw-r--r-- | toxcore/friend_connection.c | 10 | ||||
-rw-r--r-- | toxcore/friend_connection.h | 5 | ||||
-rw-r--r-- | toxcore/group.c | 4 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 29 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 6 | ||||
-rw-r--r-- | toxcore/network.c | 4 | ||||
-rw-r--r-- | toxcore/network.h | 5 | ||||
-rw-r--r-- | toxcore/onion.c | 12 | ||||
-rw-r--r-- | toxcore/onion_announce.c | 4 | ||||
-rw-r--r-- | toxcore/onion_client.c | 11 | ||||
-rw-r--r-- | toxcore/ping.c | 4 | ||||
-rw-r--r-- | toxcore/tox.c | 4 | ||||
-rw-r--r-- | toxcore/tox.h | 2 | ||||
-rw-r--r-- | toxcore/util.c | 4 |
22 files changed, 105 insertions, 99 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 504bb0d9..d69be0fc 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -1164,7 +1164,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public | |||
1164 | return sendpacket(dht->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + len); | 1164 | return sendpacket(dht->net, ip_port, data, 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + len); |
1165 | } | 1165 | } |
1166 | 1166 | ||
1167 | static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 1167 | static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
1168 | { | 1168 | { |
1169 | if (length != (1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof( | 1169 | if (length != (1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof( |
1170 | uint64_t) + crypto_box_MACBYTES)) | 1170 | uint64_t) + crypto_box_MACBYTES)) |
@@ -1285,7 +1285,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa | |||
1285 | return 0; | 1285 | return 0; |
1286 | } | 1286 | } |
1287 | 1287 | ||
1288 | static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 1288 | static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
1289 | { | 1289 | { |
1290 | DHT *dht = object; | 1290 | DHT *dht = object; |
1291 | Node_format plain_nodes[MAX_SENT_NODES]; | 1291 | Node_format plain_nodes[MAX_SENT_NODES]; |
@@ -2343,7 +2343,7 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c | |||
2343 | dht->cryptopackethandlers[byte].object = object; | 2343 | dht->cryptopackethandlers[byte].object = object; |
2344 | } | 2344 | } |
2345 | 2345 | ||
2346 | static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 2346 | static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
2347 | { | 2347 | { |
2348 | DHT *dht = object; | 2348 | DHT *dht = object; |
2349 | 2349 | ||
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index 5ab5b0e1..44684e8f 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c | |||
@@ -306,7 +306,7 @@ int LAN_ip(IP ip) | |||
306 | return -1; | 306 | return -1; |
307 | } | 307 | } |
308 | 308 | ||
309 | static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 309 | static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
310 | { | 310 | { |
311 | DHT *dht = object; | 311 | DHT *dht = object; |
312 | 312 | ||
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index c6c503ca..e5779fb6 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -162,7 +162,7 @@ static int send_offline_packet(Messenger *m, int friendcon_id) | |||
162 | } | 162 | } |
163 | 163 | ||
164 | static int handle_status(void *object, int i, uint8_t status); | 164 | static int handle_status(void *object, int i, uint8_t status); |
165 | static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len); | 165 | static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len, void *userdata); |
166 | static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length); | 166 | static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length); |
167 | 167 | ||
168 | static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status) | 168 | static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status) |
@@ -777,11 +777,9 @@ void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, uint3 | |||
777 | m->friend_message_userdata = userdata; | 777 | m->friend_message_userdata = userdata; |
778 | } | 778 | } |
779 | 779 | ||
780 | void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *), | 780 | void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *)) |
781 | void *userdata) | ||
782 | { | 781 | { |
783 | m->friend_namechange = function; | 782 | m->friend_namechange = function; |
784 | m->friend_namechange_userdata = userdata; | ||
785 | } | 783 | } |
786 | 784 | ||
787 | void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *), | 785 | void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *), |
@@ -1904,7 +1902,7 @@ static int handle_status(void *object, int i, uint8_t status) | |||
1904 | return 0; | 1902 | return 0; |
1905 | } | 1903 | } |
1906 | 1904 | ||
1907 | static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len) | 1905 | static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len, void *userdata) |
1908 | { | 1906 | { |
1909 | if (len == 0) | 1907 | if (len == 0) |
1910 | return -1; | 1908 | return -1; |
@@ -1943,7 +1941,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len) | |||
1943 | 1941 | ||
1944 | /* inform of namechange before we overwrite the old name */ | 1942 | /* inform of namechange before we overwrite the old name */ |
1945 | if (m->friend_namechange) | 1943 | if (m->friend_namechange) |
1946 | m->friend_namechange(m, i, data_terminated, data_length, m->friend_namechange_userdata); | 1944 | m->friend_namechange(m, i, data_terminated, data_length, userdata); |
1947 | 1945 | ||
1948 | memcpy(m->friendlist[i].name, data_terminated, data_length); | 1946 | memcpy(m->friendlist[i].name, data_terminated, data_length); |
1949 | m->friendlist[i].name_length = data_length; | 1947 | m->friendlist[i].name_length = data_length; |
@@ -2306,7 +2304,7 @@ void do_messenger(Messenger *m, void *userdata) | |||
2306 | unix_time_update(); | 2304 | unix_time_update(); |
2307 | 2305 | ||
2308 | if (!m->options.udp_disabled) { | 2306 | if (!m->options.udp_disabled) { |
2309 | networking_poll(m->net); | 2307 | networking_poll(m->net, userdata); |
2310 | do_DHT(m->dht); | 2308 | do_DHT(m->dht); |
2311 | } | 2309 | } |
2312 | 2310 | ||
@@ -2314,7 +2312,7 @@ void do_messenger(Messenger *m, void *userdata) | |||
2314 | do_TCP_server(m->tcp_server); | 2312 | do_TCP_server(m->tcp_server); |
2315 | } | 2313 | } |
2316 | 2314 | ||
2317 | do_net_crypto(m->net_crypto); | 2315 | do_net_crypto(m->net_crypto, userdata); |
2318 | do_onion_client(m->onion_c); | 2316 | do_onion_client(m->onion_c); |
2319 | do_friend_connections(m->fr_c); | 2317 | do_friend_connections(m->fr_c); |
2320 | do_friends(m); | 2318 | do_friends(m); |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index dab792c8..5af9e274 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -240,7 +240,6 @@ struct Messenger { | |||
240 | void (*friend_message)(struct Messenger *m, uint32_t, unsigned int, const uint8_t *, size_t, void *); | 240 | void (*friend_message)(struct Messenger *m, uint32_t, unsigned int, const uint8_t *, size_t, void *); |
241 | void *friend_message_userdata; | 241 | void *friend_message_userdata; |
242 | void (*friend_namechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); | 242 | void (*friend_namechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); |
243 | void *friend_namechange_userdata; | ||
244 | void (*friend_statusmessagechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); | 243 | void (*friend_statusmessagechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); |
245 | void *friend_statusmessagechange_userdata; | 244 | void *friend_statusmessagechange_userdata; |
246 | void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); | 245 | void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); |
@@ -485,8 +484,7 @@ void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, uint3 | |||
485 | * Function(uint32_t friendnumber, uint8_t *newname, size_t length) | 484 | * Function(uint32_t friendnumber, uint8_t *newname, size_t length) |
486 | * You are not responsible for freeing newname. | 485 | * You are not responsible for freeing newname. |
487 | */ | 486 | */ |
488 | void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *), | 487 | void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *)); |
489 | void *userdata); | ||
490 | 488 | ||
491 | /* Set the callback for status message changes. | 489 | /* Set the callback for status message changes. |
492 | * Function(uint32_t friendnumber, uint8_t *newstatus, size_t length) | 490 | * Function(uint32_t friendnumber, uint8_t *newstatus, size_t length) |
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 752deecf..824e5dd1 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c | |||
@@ -506,14 +506,14 @@ int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32 | |||
506 | } | 506 | } |
507 | 507 | ||
508 | void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void *object, uint32_t number, | 508 | void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void *object, uint32_t number, |
509 | uint8_t connection_id, const uint8_t *data, uint16_t length), void *object) | 509 | uint8_t connection_id, const uint8_t *data, uint16_t length, void *userdata), void *object) |
510 | { | 510 | { |
511 | con->data_callback = data_callback; | 511 | con->data_callback = data_callback; |
512 | con->data_callback_object = object; | 512 | con->data_callback_object = object; |
513 | } | 513 | } |
514 | 514 | ||
515 | void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, const uint8_t *public_key, | 515 | void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, const uint8_t *public_key, |
516 | const uint8_t *data, uint16_t length), void *object) | 516 | const uint8_t *data, uint16_t length, void *userdata), void *object) |
517 | { | 517 | { |
518 | con->oob_data_callback = oob_data_callback; | 518 | con->oob_data_callback = oob_data_callback; |
519 | con->oob_data_callback_object = object; | 519 | con->oob_data_callback_object = object; |
@@ -600,7 +600,7 @@ int send_onion_request(TCP_Client_Connection *con, const uint8_t *data, uint16_t | |||
600 | } | 600 | } |
601 | 601 | ||
602 | void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, const uint8_t *data, | 602 | void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, const uint8_t *data, |
603 | uint16_t length), void *object) | 603 | uint16_t length, void *userdata), void *object) |
604 | { | 604 | { |
605 | con->onion_callback = onion_callback; | 605 | con->onion_callback = onion_callback; |
606 | con->onion_callback_object = object; | 606 | con->onion_callback_object = object; |
@@ -692,7 +692,7 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public | |||
692 | /* return 0 on success | 692 | /* return 0 on success |
693 | * return -1 on failure | 693 | * return -1 on failure |
694 | */ | 694 | */ |
695 | static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length) | 695 | static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length, void *userdata) |
696 | { | 696 | { |
697 | if (length <= 1) | 697 | if (length <= 1) |
698 | return -1; | 698 | return -1; |
@@ -800,13 +800,13 @@ static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, u | |||
800 | 800 | ||
801 | if (conn->oob_data_callback) | 801 | if (conn->oob_data_callback) |
802 | conn->oob_data_callback(conn->oob_data_callback_object, data + 1, data + 1 + crypto_box_PUBLICKEYBYTES, | 802 | conn->oob_data_callback(conn->oob_data_callback_object, data + 1, data + 1 + crypto_box_PUBLICKEYBYTES, |
803 | length - (1 + crypto_box_PUBLICKEYBYTES)); | 803 | length - (1 + crypto_box_PUBLICKEYBYTES), userdata); |
804 | 804 | ||
805 | return 0; | 805 | return 0; |
806 | } | 806 | } |
807 | 807 | ||
808 | case TCP_PACKET_ONION_RESPONSE: { | 808 | case TCP_PACKET_ONION_RESPONSE: { |
809 | conn->onion_callback(conn->onion_callback_object, data + 1, length - 1); | 809 | conn->onion_callback(conn->onion_callback_object, data + 1, length - 1, userdata); |
810 | return 0; | 810 | return 0; |
811 | } | 811 | } |
812 | 812 | ||
@@ -817,14 +817,15 @@ static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, u | |||
817 | uint8_t con_id = data[0] - NUM_RESERVED_PORTS; | 817 | uint8_t con_id = data[0] - NUM_RESERVED_PORTS; |
818 | 818 | ||
819 | if (conn->data_callback) | 819 | if (conn->data_callback) |
820 | conn->data_callback(conn->data_callback_object, conn->connections[con_id].number, con_id, data + 1, length - 1); | 820 | conn->data_callback(conn->data_callback_object, conn->connections[con_id].number, con_id, data + 1, length - 1, |
821 | userdata); | ||
821 | } | 822 | } |
822 | } | 823 | } |
823 | 824 | ||
824 | return 0; | 825 | return 0; |
825 | } | 826 | } |
826 | 827 | ||
827 | static int do_confirmed_TCP(TCP_Client_Connection *conn) | 828 | static int do_confirmed_TCP(TCP_Client_Connection *conn, void *userdata) |
828 | { | 829 | { |
829 | send_pending_data(conn); | 830 | send_pending_data(conn); |
830 | send_ping_response(conn); | 831 | send_ping_response(conn); |
@@ -856,7 +857,7 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn) | |||
856 | break; | 857 | break; |
857 | } | 858 | } |
858 | 859 | ||
859 | if (handle_TCP_packet(conn, packet, len) == -1) { | 860 | if (handle_TCP_packet(conn, packet, len, userdata) == -1) { |
860 | conn->status = TCP_CLIENT_DISCONNECTED; | 861 | conn->status = TCP_CLIENT_DISCONNECTED; |
861 | break; | 862 | break; |
862 | } | 863 | } |
@@ -867,7 +868,7 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn) | |||
867 | 868 | ||
868 | /* Run the TCP connection | 869 | /* Run the TCP connection |
869 | */ | 870 | */ |
870 | void do_TCP_connection(TCP_Client_Connection *TCP_connection) | 871 | void do_TCP_connection(TCP_Client_Connection *TCP_connection, void *userdata) |
871 | { | 872 | { |
872 | unix_time_update(); | 873 | unix_time_update(); |
873 | 874 | ||
@@ -945,7 +946,7 @@ void do_TCP_connection(TCP_Client_Connection *TCP_connection) | |||
945 | } | 946 | } |
946 | 947 | ||
947 | if (TCP_connection->status == TCP_CLIENT_CONFIRMED) { | 948 | if (TCP_connection->status == TCP_CLIENT_CONFIRMED) { |
948 | do_confirmed_TCP(TCP_connection); | 949 | do_confirmed_TCP(TCP_connection, userdata); |
949 | } | 950 | } |
950 | 951 | ||
951 | if (TCP_connection->kill_at <= unix_time()) { | 952 | if (TCP_connection->kill_at <= unix_time()) { |
diff --git a/toxcore/TCP_client.h b/toxcore/TCP_client.h index 722430e0..37ab30a7 100644 --- a/toxcore/TCP_client.h +++ b/toxcore/TCP_client.h | |||
@@ -87,12 +87,13 @@ typedef struct { | |||
87 | void *response_callback_object; | 87 | void *response_callback_object; |
88 | int (*status_callback)(void *object, uint32_t number, uint8_t connection_id, uint8_t status); | 88 | int (*status_callback)(void *object, uint32_t number, uint8_t connection_id, uint8_t status); |
89 | void *status_callback_object; | 89 | void *status_callback_object; |
90 | int (*data_callback)(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length); | 90 | int (*data_callback)(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length, |
91 | void *userdata); | ||
91 | void *data_callback_object; | 92 | void *data_callback_object; |
92 | int (*oob_data_callback)(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length); | 93 | int (*oob_data_callback)(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata); |
93 | void *oob_data_callback_object; | 94 | void *oob_data_callback_object; |
94 | 95 | ||
95 | int (*onion_callback)(void *object, const uint8_t *data, uint16_t length); | 96 | int (*onion_callback)(void *object, const uint8_t *data, uint16_t length, void *userdata); |
96 | void *onion_callback_object; | 97 | void *onion_callback_object; |
97 | 98 | ||
98 | /* Can be used by user. */ | 99 | /* Can be used by user. */ |
@@ -107,7 +108,7 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public | |||
107 | 108 | ||
108 | /* Run the TCP connection | 109 | /* Run the TCP connection |
109 | */ | 110 | */ |
110 | void do_TCP_connection(TCP_Client_Connection *TCP_connection); | 111 | void do_TCP_connection(TCP_Client_Connection *TCP_connection, void *userdata); |
111 | 112 | ||
112 | /* Kill the TCP connection | 113 | /* Kill the TCP connection |
113 | */ | 114 | */ |
@@ -119,7 +120,7 @@ void kill_TCP_connection(TCP_Client_Connection *TCP_connection); | |||
119 | */ | 120 | */ |
120 | int send_onion_request(TCP_Client_Connection *con, const uint8_t *data, uint16_t length); | 121 | int send_onion_request(TCP_Client_Connection *con, const uint8_t *data, uint16_t length); |
121 | void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, const uint8_t *data, | 122 | void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, const uint8_t *data, |
122 | uint16_t length), void *object); | 123 | uint16_t length, void *userdata), void *object); |
123 | 124 | ||
124 | /* return 1 on success. | 125 | /* return 1 on success. |
125 | * return 0 if could not send packet. | 126 | * return 0 if could not send packet. |
@@ -152,7 +153,7 @@ int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32 | |||
152 | */ | 153 | */ |
153 | int send_data(TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, uint16_t length); | 154 | int send_data(TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, uint16_t length); |
154 | void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void *object, uint32_t number, | 155 | void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void *object, uint32_t number, |
155 | uint8_t connection_id, const uint8_t *data, uint16_t length), void *object); | 156 | uint8_t connection_id, const uint8_t *data, uint16_t length, void *userdata), void *object); |
156 | 157 | ||
157 | /* return 1 on success. | 158 | /* return 1 on success. |
158 | * return 0 if could not send packet. | 159 | * return 0 if could not send packet. |
@@ -160,7 +161,7 @@ void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void | |||
160 | */ | 161 | */ |
161 | int send_oob_packet(TCP_Client_Connection *con, const uint8_t *public_key, const uint8_t *data, uint16_t length); | 162 | int send_oob_packet(TCP_Client_Connection *con, const uint8_t *public_key, const uint8_t *data, uint16_t length); |
162 | void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, const uint8_t *public_key, | 163 | void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, const uint8_t *public_key, |
163 | const uint8_t *data, uint16_t length), void *object); | 164 | const uint8_t *data, uint16_t length, void *userdata), void *object); |
164 | 165 | ||
165 | 166 | ||
166 | #endif | 167 | #endif |
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index 027779dd..d564762a 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c | |||
@@ -346,7 +346,7 @@ int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_num | |||
346 | /* Set the callback for TCP data packets. | 346 | /* Set the callback for TCP data packets. |
347 | */ | 347 | */ |
348 | void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_data_callback)(void *object, int id, | 348 | void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_data_callback)(void *object, int id, |
349 | const uint8_t *data, uint16_t length), void *object) | 349 | const uint8_t *data, uint16_t length, void *userdata), void *object) |
350 | { | 350 | { |
351 | tcp_c->tcp_data_callback = tcp_data_callback; | 351 | tcp_c->tcp_data_callback = tcp_data_callback; |
352 | tcp_c->tcp_data_callback_object = object; | 352 | tcp_c->tcp_data_callback_object = object; |
@@ -364,7 +364,7 @@ void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_oo | |||
364 | /* Set the callback for TCP oob data packets. | 364 | /* Set the callback for TCP oob data packets. |
365 | */ | 365 | */ |
366 | void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_onion_callback)(void *object, | 366 | void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_onion_callback)(void *object, |
367 | const uint8_t *data, uint16_t length), void *object) | 367 | const uint8_t *data, uint16_t length, void *userdata), void *object) |
368 | { | 368 | { |
369 | tcp_c->tcp_onion_callback = tcp_onion_callback; | 369 | tcp_c->tcp_onion_callback = tcp_onion_callback; |
370 | tcp_c->tcp_onion_callback_object = object; | 370 | tcp_c->tcp_onion_callback_object = object; |
@@ -879,7 +879,8 @@ static int tcp_status_callback(void *object, uint32_t number, uint8_t connection | |||
879 | return 0; | 879 | return 0; |
880 | } | 880 | } |
881 | 881 | ||
882 | static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length) | 882 | static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length, |
883 | void *userdata) | ||
883 | { | 884 | { |
884 | 885 | ||
885 | if (length == 0) | 886 | if (length == 0) |
@@ -900,12 +901,13 @@ static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_i | |||
900 | return -1; | 901 | return -1; |
901 | 902 | ||
902 | if (tcp_c->tcp_data_callback) | 903 | if (tcp_c->tcp_data_callback) |
903 | tcp_c->tcp_data_callback(tcp_c->tcp_data_callback_object, con_to->id, data, length); | 904 | tcp_c->tcp_data_callback(tcp_c->tcp_data_callback_object, con_to->id, data, length, userdata); |
904 | 905 | ||
905 | return 0; | 906 | return 0; |
906 | } | 907 | } |
907 | 908 | ||
908 | static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length) | 909 | static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length, |
910 | void *userdata) | ||
909 | { | 911 | { |
910 | if (length == 0) | 912 | if (length == 0) |
911 | return -1; | 913 | return -1; |
@@ -925,7 +927,7 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8 | |||
925 | TCP_Connection_to *con_to = get_connection(tcp_c, connections_number); | 927 | TCP_Connection_to *con_to = get_connection(tcp_c, connections_number); |
926 | 928 | ||
927 | if (con_to && tcp_connection_in_conn(con_to, tcp_connections_number)) { | 929 | if (con_to && tcp_connection_in_conn(con_to, tcp_connections_number)) { |
928 | return tcp_data_callback(object, connections_number, 0, data, length); | 930 | return tcp_data_callback(object, connections_number, 0, data, length, userdata); |
929 | } else { | 931 | } else { |
930 | if (tcp_c->tcp_oob_callback) | 932 | if (tcp_c->tcp_oob_callback) |
931 | tcp_c->tcp_oob_callback(tcp_c->tcp_oob_callback_object, public_key, tcp_connections_number, data, length); | 933 | tcp_c->tcp_oob_callback(tcp_c->tcp_oob_callback_object, public_key, tcp_connections_number, data, length); |
@@ -934,12 +936,12 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8 | |||
934 | return 0; | 936 | return 0; |
935 | } | 937 | } |
936 | 938 | ||
937 | static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length) | 939 | static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length, void *userdata) |
938 | { | 940 | { |
939 | TCP_Connections *tcp_c = object; | 941 | TCP_Connections *tcp_c = object; |
940 | 942 | ||
941 | if (tcp_c->tcp_onion_callback) | 943 | if (tcp_c->tcp_onion_callback) |
942 | tcp_c->tcp_onion_callback(tcp_c->tcp_onion_callback_object, data, length); | 944 | tcp_c->tcp_onion_callback(tcp_c->tcp_onion_callback_object, data, length, userdata); |
943 | 945 | ||
944 | return 0; | 946 | return 0; |
945 | } | 947 | } |
@@ -1265,7 +1267,7 @@ TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info * | |||
1265 | return temp; | 1267 | return temp; |
1266 | } | 1268 | } |
1267 | 1269 | ||
1268 | static void do_tcp_conns(TCP_Connections *tcp_c) | 1270 | static void do_tcp_conns(TCP_Connections *tcp_c, void *userdata) |
1269 | { | 1271 | { |
1270 | unsigned int i; | 1272 | unsigned int i; |
1271 | 1273 | ||
@@ -1274,7 +1276,7 @@ static void do_tcp_conns(TCP_Connections *tcp_c) | |||
1274 | 1276 | ||
1275 | if (tcp_con) { | 1277 | if (tcp_con) { |
1276 | if (tcp_con->status != TCP_CONN_SLEEPING) { | 1278 | if (tcp_con->status != TCP_CONN_SLEEPING) { |
1277 | do_TCP_connection(tcp_con->connection); | 1279 | do_TCP_connection(tcp_con->connection, userdata); |
1278 | 1280 | ||
1279 | /* callbacks can change TCP connection address. */ | 1281 | /* callbacks can change TCP connection address. */ |
1280 | tcp_con = get_tcp_connection(tcp_c, i); | 1282 | tcp_con = get_tcp_connection(tcp_c, i); |
@@ -1343,9 +1345,9 @@ static void kill_nonused_tcp(TCP_Connections *tcp_c) | |||
1343 | } | 1345 | } |
1344 | } | 1346 | } |
1345 | 1347 | ||
1346 | void do_tcp_connections(TCP_Connections *tcp_c) | 1348 | void do_tcp_connections(TCP_Connections *tcp_c, void *userdata) |
1347 | { | 1349 | { |
1348 | do_tcp_conns(tcp_c); | 1350 | do_tcp_conns(tcp_c, userdata); |
1349 | kill_nonused_tcp(tcp_c); | 1351 | kill_nonused_tcp(tcp_c); |
1350 | } | 1352 | } |
1351 | 1353 | ||
diff --git a/toxcore/TCP_connection.h b/toxcore/TCP_connection.h index 7bc34f86..f45e804c 100644 --- a/toxcore/TCP_connection.h +++ b/toxcore/TCP_connection.h | |||
@@ -90,14 +90,14 @@ typedef struct { | |||
90 | TCP_con *tcp_connections; | 90 | TCP_con *tcp_connections; |
91 | uint32_t tcp_connections_length; /* Length of tcp_connections array. */ | 91 | uint32_t tcp_connections_length; /* Length of tcp_connections array. */ |
92 | 92 | ||
93 | int (*tcp_data_callback)(void *object, int id, const uint8_t *data, uint16_t length); | 93 | int (*tcp_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata); |
94 | void *tcp_data_callback_object; | 94 | void *tcp_data_callback_object; |
95 | 95 | ||
96 | int (*tcp_oob_callback)(void *object, const uint8_t *public_key, unsigned int tcp_connections_number, | 96 | int (*tcp_oob_callback)(void *object, const uint8_t *public_key, unsigned int tcp_connections_number, |
97 | const uint8_t *data, uint16_t length); | 97 | const uint8_t *data, uint16_t length); |
98 | void *tcp_oob_callback_object; | 98 | void *tcp_oob_callback_object; |
99 | 99 | ||
100 | int (*tcp_onion_callback)(void *object, const uint8_t *data, uint16_t length); | 100 | int (*tcp_onion_callback)(void *object, const uint8_t *data, uint16_t length, void *userdata); |
101 | void *tcp_onion_callback_object; | 101 | void *tcp_onion_callback_object; |
102 | 102 | ||
103 | TCP_Proxy_Info proxy_info; | 103 | TCP_Proxy_Info proxy_info; |
@@ -151,12 +151,12 @@ int tcp_send_oob_packet(TCP_Connections *tcp_c, unsigned int tcp_connections_num | |||
151 | /* Set the callback for TCP data packets. | 151 | /* Set the callback for TCP data packets. |
152 | */ | 152 | */ |
153 | void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_data_callback)(void *object, int id, | 153 | void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_data_callback)(void *object, int id, |
154 | const uint8_t *data, uint16_t length), void *object); | 154 | const uint8_t *data, uint16_t length, void *userdata), void *object); |
155 | 155 | ||
156 | /* Set the callback for TCP onion packets. | 156 | /* Set the callback for TCP onion packets. |
157 | */ | 157 | */ |
158 | void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_onion_callback)(void *object, | 158 | void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_onion_callback)(void *object, |
159 | const uint8_t *data, uint16_t length), void *object); | 159 | const uint8_t *data, uint16_t length, void *userdata), void *object); |
160 | 160 | ||
161 | /* Set the callback for TCP oob data packets. | 161 | /* Set the callback for TCP oob data packets. |
162 | */ | 162 | */ |
@@ -239,7 +239,7 @@ unsigned int tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_ | |||
239 | */ | 239 | */ |
240 | TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *proxy_info); | 240 | TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *proxy_info); |
241 | 241 | ||
242 | void do_tcp_connections(TCP_Connections *tcp_c); | 242 | void do_tcp_connections(TCP_Connections *tcp_c, void *userdata); |
243 | void kill_tcp_connections(TCP_Connections *tcp_c); | 243 | void kill_tcp_connections(TCP_Connections *tcp_c); |
244 | 244 | ||
245 | #endif | 245 | #endif |
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index e7c8432b..858e54b3 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c | |||
@@ -372,7 +372,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub | |||
372 | onion_set_friend_DHT_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key); | 372 | onion_set_friend_DHT_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key); |
373 | } | 373 | } |
374 | 374 | ||
375 | static int handle_packet(void *object, int number, uint8_t *data, uint16_t length) | 375 | static int handle_packet(void *object, int number, uint8_t *data, uint16_t length, void *userdata) |
376 | { | 376 | { |
377 | if (length == 0) | 377 | if (length == 0) |
378 | return -1; | 378 | return -1; |
@@ -411,8 +411,9 @@ static int handle_packet(void *object, int number, uint8_t *data, uint16_t lengt | |||
411 | 411 | ||
412 | for (i = 0; i < MAX_FRIEND_CONNECTION_CALLBACKS; ++i) { | 412 | for (i = 0; i < MAX_FRIEND_CONNECTION_CALLBACKS; ++i) { |
413 | if (friend_con->callbacks[i].data_callback) | 413 | if (friend_con->callbacks[i].data_callback) |
414 | friend_con->callbacks[i].data_callback(friend_con->callbacks[i].data_callback_object, | 414 | friend_con->callbacks[i].data_callback( |
415 | friend_con->callbacks[i].data_callback_id, data, length); | 415 | friend_con->callbacks[i].data_callback_object, |
416 | friend_con->callbacks[i].data_callback_id, data, length, userdata); | ||
416 | 417 | ||
417 | friend_con = get_conn(fr_c, number); | 418 | friend_con = get_conn(fr_c, number); |
418 | 419 | ||
@@ -604,7 +605,8 @@ void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t * | |||
604 | */ | 605 | */ |
605 | int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index, | 606 | int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index, |
606 | int (*status_callback)(void *object, int id, uint8_t status), int (*data_callback)(void *object, int id, uint8_t *data, | 607 | int (*status_callback)(void *object, int id, uint8_t status), int (*data_callback)(void *object, int id, uint8_t *data, |
607 | uint16_t length), int (*lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), void *object, | 608 | uint16_t length, void *userdata), int (*lossy_data_callback)(void *object, int id, const uint8_t *data, |
609 | uint16_t length), void *object, | ||
608 | int number) | 610 | int number) |
609 | { | 611 | { |
610 | Friend_Conn *friend_con = get_conn(fr_c, friendcon_id); | 612 | Friend_Conn *friend_con = get_conn(fr_c, friendcon_id); |
diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h index 044b8d7f..ecfc55ab 100644 --- a/toxcore/friend_connection.h +++ b/toxcore/friend_connection.h | |||
@@ -83,7 +83,7 @@ typedef struct { | |||
83 | void *status_callback_object; | 83 | void *status_callback_object; |
84 | int status_callback_id; | 84 | int status_callback_id; |
85 | 85 | ||
86 | int (*data_callback)(void *object, int id, uint8_t *data, uint16_t length); | 86 | int (*data_callback)(void *object, int id, uint8_t *data, uint16_t length, void *userdata); |
87 | void *data_callback_object; | 87 | void *data_callback_object; |
88 | int data_callback_id; | 88 | int data_callback_id; |
89 | 89 | ||
@@ -159,7 +159,8 @@ int friend_add_tcp_relay(Friend_Connections *fr_c, int friendcon_id, IP_Port ip_ | |||
159 | */ | 159 | */ |
160 | int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index, | 160 | int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index, |
161 | int (*status_callback)(void *object, int id, uint8_t status), int (*data_callback)(void *object, int id, uint8_t *data, | 161 | int (*status_callback)(void *object, int id, uint8_t status), int (*data_callback)(void *object, int id, uint8_t *data, |
162 | uint16_t length), int (*lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), void *object, | 162 | uint16_t length, void *userdata), int (*lossy_data_callback)(void *object, int id, const uint8_t *data, |
163 | uint16_t length), void *object, | ||
163 | int number); | 164 | int number); |
164 | 165 | ||
165 | /* return the crypt_connection_id for the connection. | 166 | /* return the crypt_connection_id for the connection. |
diff --git a/toxcore/group.c b/toxcore/group.c index 9313a24b..b699e867 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -612,7 +612,7 @@ static int handle_status(void *object, int friendcon_id, uint8_t status) | |||
612 | return 0; | 612 | return 0; |
613 | } | 613 | } |
614 | 614 | ||
615 | static int handle_packet(void *object, int friendcon_id, uint8_t *data, uint16_t length); | 615 | static int handle_packet(void *object, int friendcon_id, uint8_t *data, uint16_t length, void *userdata); |
616 | static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length); | 616 | static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length); |
617 | 617 | ||
618 | /* Add friend to group chat. | 618 | /* Add friend to group chat. |
@@ -1930,7 +1930,7 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const | |||
1930 | send_message_all_close(g_c, groupnumber, data, length, -1/*TODO close_index*/); | 1930 | send_message_all_close(g_c, groupnumber, data, length, -1/*TODO close_index*/); |
1931 | } | 1931 | } |
1932 | 1932 | ||
1933 | static int handle_packet(void *object, int friendcon_id, uint8_t *data, uint16_t length) | 1933 | static int handle_packet(void *object, int friendcon_id, uint8_t *data, uint16_t length, void *userdata) |
1934 | { | 1934 | { |
1935 | Group_Chats *g_c = object; | 1935 | Group_Chats *g_c = object; |
1936 | 1936 | ||
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index f8a85adf..381b0a50 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -191,7 +191,8 @@ static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, ui | |||
191 | 191 | ||
192 | /* Handle the cookie request packet (for raw UDP) | 192 | /* Handle the cookie request packet (for raw UDP) |
193 | */ | 193 | */ |
194 | static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 194 | static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, |
195 | void *userdata) | ||
195 | { | 196 | { |
196 | Net_Crypto *c = object; | 197 | Net_Crypto *c = object; |
197 | uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH]; | 198 | uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH]; |
@@ -1223,7 +1224,7 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id) | |||
1223 | * return 0 on success. | 1224 | * return 0 on success. |
1224 | */ | 1225 | */ |
1225 | static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length, | 1226 | static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length, |
1226 | _Bool udp) | 1227 | _Bool udp, void *userdata) |
1227 | { | 1228 | { |
1228 | if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE) | 1229 | if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE) |
1229 | return -1; | 1230 | return -1; |
@@ -1320,7 +1321,7 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, con | |||
1320 | 1321 | ||
1321 | if (conn->connection_data_callback) | 1322 | if (conn->connection_data_callback) |
1322 | conn->connection_data_callback(conn->connection_data_callback_object, conn->connection_data_callback_id, dt.data, | 1323 | conn->connection_data_callback(conn->connection_data_callback_object, conn->connection_data_callback_id, dt.data, |
1323 | dt.length); | 1324 | dt.length, userdata); |
1324 | 1325 | ||
1325 | /* conn might get killed in callback. */ | 1326 | /* conn might get killed in callback. */ |
1326 | conn = get_crypto_connection(c, crypt_connection_id); | 1327 | conn = get_crypto_connection(c, crypt_connection_id); |
@@ -1360,7 +1361,7 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, con | |||
1360 | * return 0 on success. | 1361 | * return 0 on success. |
1361 | */ | 1362 | */ |
1362 | static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length, | 1363 | static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length, |
1363 | _Bool udp) | 1364 | _Bool udp, void *userdata) |
1364 | { | 1365 | { |
1365 | if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) | 1366 | if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) |
1366 | return -1; | 1367 | return -1; |
@@ -1425,7 +1426,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons | |||
1425 | 1426 | ||
1426 | case NET_PACKET_CRYPTO_DATA: { | 1427 | case NET_PACKET_CRYPTO_DATA: { |
1427 | if (conn->status == CRYPTO_CONN_NOT_CONFIRMED || conn->status == CRYPTO_CONN_ESTABLISHED) { | 1428 | if (conn->status == CRYPTO_CONN_NOT_CONFIRMED || conn->status == CRYPTO_CONN_ESTABLISHED) { |
1428 | return handle_data_packet_helper(c, crypt_connection_id, packet, length, udp); | 1429 | return handle_data_packet_helper(c, crypt_connection_id, packet, length, udp, userdata); |
1429 | } else { | 1430 | } else { |
1430 | return -1; | 1431 | return -1; |
1431 | } | 1432 | } |
@@ -1805,7 +1806,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, | |||
1805 | } | 1806 | } |
1806 | 1807 | ||
1807 | 1808 | ||
1808 | static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t length) | 1809 | static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t length, void *userdata) |
1809 | { | 1810 | { |
1810 | if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) | 1811 | if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) |
1811 | return -1; | 1812 | return -1; |
@@ -1822,7 +1823,7 @@ static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t | |||
1822 | } | 1823 | } |
1823 | 1824 | ||
1824 | pthread_mutex_unlock(&c->tcp_mutex); | 1825 | pthread_mutex_unlock(&c->tcp_mutex); |
1825 | int ret = handle_packet_connection(c, id, data, length, 0); | 1826 | int ret = handle_packet_connection(c, id, data, length, 0, userdata); |
1826 | pthread_mutex_lock(&c->tcp_mutex); | 1827 | pthread_mutex_lock(&c->tcp_mutex); |
1827 | 1828 | ||
1828 | if (ret != 0) | 1829 | if (ret != 0) |
@@ -1937,10 +1938,10 @@ unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, u | |||
1937 | return ret; | 1938 | return ret; |
1938 | } | 1939 | } |
1939 | 1940 | ||
1940 | static void do_tcp(Net_Crypto *c) | 1941 | static void do_tcp(Net_Crypto *c, void *userdata) |
1941 | { | 1942 | { |
1942 | pthread_mutex_lock(&c->tcp_mutex); | 1943 | pthread_mutex_lock(&c->tcp_mutex); |
1943 | do_tcp_connections(c->tcp_c); | 1944 | do_tcp_connections(c->tcp_c, userdata); |
1944 | pthread_mutex_unlock(&c->tcp_mutex); | 1945 | pthread_mutex_unlock(&c->tcp_mutex); |
1945 | 1946 | ||
1946 | uint32_t i; | 1947 | uint32_t i; |
@@ -2001,7 +2002,7 @@ int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, | |||
2001 | * return 0 on success. | 2002 | * return 0 on success. |
2002 | */ | 2003 | */ |
2003 | int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object, | 2004 | int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object, |
2004 | int id, uint8_t *data, uint16_t length), void *object, int id) | 2005 | int id, uint8_t *data, uint16_t length, void *userdata), void *object, int id) |
2005 | { | 2006 | { |
2006 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2007 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2007 | 2008 | ||
@@ -2081,7 +2082,7 @@ static int crypto_id_ip_port(const Net_Crypto *c, IP_Port ip_port) | |||
2081 | * Crypto data packets. | 2082 | * Crypto data packets. |
2082 | * | 2083 | * |
2083 | */ | 2084 | */ |
2084 | static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 2085 | static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
2085 | { | 2086 | { |
2086 | if (length <= CRYPTO_MIN_PACKET_SIZE || length > MAX_CRYPTO_PACKET_SIZE) | 2087 | if (length <= CRYPTO_MIN_PACKET_SIZE || length > MAX_CRYPTO_PACKET_SIZE) |
2087 | return 1; | 2088 | return 1; |
@@ -2099,7 +2100,7 @@ static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet | |||
2099 | return 0; | 2100 | return 0; |
2100 | } | 2101 | } |
2101 | 2102 | ||
2102 | if (handle_packet_connection(c, crypt_connection_id, packet, length, 1) != 0) | 2103 | if (handle_packet_connection(c, crypt_connection_id, packet, length, 1, userdata) != 0) |
2103 | return 1; | 2104 | return 1; |
2104 | 2105 | ||
2105 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2106 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
@@ -2685,11 +2686,11 @@ uint32_t crypto_run_interval(const Net_Crypto *c) | |||
2685 | } | 2686 | } |
2686 | 2687 | ||
2687 | /* Main loop. */ | 2688 | /* Main loop. */ |
2688 | void do_net_crypto(Net_Crypto *c) | 2689 | void do_net_crypto(Net_Crypto *c, void *userdata) |
2689 | { | 2690 | { |
2690 | unix_time_update(); | 2691 | unix_time_update(); |
2691 | kill_timedout(c); | 2692 | kill_timedout(c); |
2692 | do_tcp(c); | 2693 | do_tcp(c, userdata); |
2693 | send_crypto_packets(c); | 2694 | send_crypto_packets(c); |
2694 | } | 2695 | } |
2695 | 2696 | ||
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index c9554bfc..c9ba3640 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -134,7 +134,7 @@ typedef struct { | |||
134 | void *connection_status_callback_object; | 134 | void *connection_status_callback_object; |
135 | int connection_status_callback_id; | 135 | int connection_status_callback_id; |
136 | 136 | ||
137 | int (*connection_data_callback)(void *object, int id, uint8_t *data, uint16_t length); | 137 | int (*connection_data_callback)(void *object, int id, uint8_t *data, uint16_t length, void *userdata); |
138 | void *connection_data_callback_object; | 138 | void *connection_data_callback_object; |
139 | int connection_data_callback_id; | 139 | int connection_data_callback_id; |
140 | 140 | ||
@@ -272,7 +272,7 @@ int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, | |||
272 | * return 0 on success. | 272 | * return 0 on success. |
273 | */ | 273 | */ |
274 | int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object, | 274 | int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object, |
275 | int id, uint8_t *data, uint16_t length), void *object, int id); | 275 | int id, uint8_t *data, uint16_t length, void *userdata), void *object, int id); |
276 | 276 | ||
277 | 277 | ||
278 | /* Set function to be called when connection with crypt_connection_id receives a lossy data packet of length. | 278 | /* Set function to be called when connection with crypt_connection_id receives a lossy data packet of length. |
@@ -414,7 +414,7 @@ Net_Crypto *new_net_crypto(DHT *dht, TCP_Proxy_Info *proxy_info); | |||
414 | uint32_t crypto_run_interval(const Net_Crypto *c); | 414 | uint32_t crypto_run_interval(const Net_Crypto *c); |
415 | 415 | ||
416 | /* Main loop. */ | 416 | /* Main loop. */ |
417 | void do_net_crypto(Net_Crypto *c); | 417 | void do_net_crypto(Net_Crypto *c, void *userdata); |
418 | 418 | ||
419 | void kill_net_crypto(Net_Crypto *c); | 419 | void kill_net_crypto(Net_Crypto *c); |
420 | 420 | ||
diff --git a/toxcore/network.c b/toxcore/network.c index 58ed5c56..17263153 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -412,7 +412,7 @@ void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handl | |||
412 | net->packethandlers[byte].object = object; | 412 | net->packethandlers[byte].object = object; |
413 | } | 413 | } |
414 | 414 | ||
415 | void networking_poll(Networking_Core *net) | 415 | void networking_poll(Networking_Core *net, void *userdata) |
416 | { | 416 | { |
417 | if (net->family == 0) /* Socket not initialized */ | 417 | if (net->family == 0) /* Socket not initialized */ |
418 | return; | 418 | return; |
@@ -431,7 +431,7 @@ void networking_poll(Networking_Core *net) | |||
431 | continue; | 431 | continue; |
432 | } | 432 | } |
433 | 433 | ||
434 | net->packethandlers[data[0]].function(net->packethandlers[data[0]].object, ip_port, data, length); | 434 | net->packethandlers[data[0]].function(net->packethandlers[data[0]].object, ip_port, data, length, userdata); |
435 | } | 435 | } |
436 | } | 436 | } |
437 | 437 | ||
diff --git a/toxcore/network.h b/toxcore/network.h index 8d2ccfce..97927299 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -290,7 +290,8 @@ int addr_resolve_or_parse_ip(const char *address, IP *to, IP *extra); | |||
290 | * Packet data is put into data. | 290 | * Packet data is put into data. |
291 | * Packet length is put into length. | 291 | * Packet length is put into length. |
292 | */ | 292 | */ |
293 | typedef int (*packet_handler_callback)(void *object, IP_Port ip_port, const uint8_t *data, uint16_t len); | 293 | typedef int (*packet_handler_callback)(void *object, IP_Port ip_port, const uint8_t *data, uint16_t len, |
294 | void *userdata); | ||
294 | 295 | ||
295 | typedef struct { | 296 | typedef struct { |
296 | packet_handler_callback function; | 297 | packet_handler_callback function; |
@@ -364,7 +365,7 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint1 | |||
364 | void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handler_callback cb, void *object); | 365 | void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handler_callback cb, void *object); |
365 | 366 | ||
366 | /* Call this several times a second. */ | 367 | /* Call this several times a second. */ |
367 | void networking_poll(Networking_Core *net); | 368 | void networking_poll(Networking_Core *net, void *userdata); |
368 | 369 | ||
369 | /* Initialize networking. | 370 | /* Initialize networking. |
370 | * bind to ip and port. | 371 | * bind to ip and port. |
diff --git a/toxcore/onion.c b/toxcore/onion.c index cec178b9..f0e3eed4 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c | |||
@@ -306,7 +306,7 @@ int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, | |||
306 | return 0; | 306 | return 0; |
307 | } | 307 | } |
308 | 308 | ||
309 | static int handle_send_initial(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 309 | static int handle_send_initial(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
310 | { | 310 | { |
311 | Onion *onion = object; | 311 | Onion *onion = object; |
312 | 312 | ||
@@ -367,7 +367,7 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port | |||
367 | return 0; | 367 | return 0; |
368 | } | 368 | } |
369 | 369 | ||
370 | static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 370 | static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
371 | { | 371 | { |
372 | Onion *onion = object; | 372 | Onion *onion = object; |
373 | 373 | ||
@@ -417,7 +417,7 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui | |||
417 | return 0; | 417 | return 0; |
418 | } | 418 | } |
419 | 419 | ||
420 | static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 420 | static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
421 | { | 421 | { |
422 | Onion *onion = object; | 422 | Onion *onion = object; |
423 | 423 | ||
@@ -466,7 +466,7 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui | |||
466 | } | 466 | } |
467 | 467 | ||
468 | 468 | ||
469 | static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 469 | static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
470 | { | 470 | { |
471 | Onion *onion = object; | 471 | Onion *onion = object; |
472 | 472 | ||
@@ -502,7 +502,7 @@ static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, ui | |||
502 | return 0; | 502 | return 0; |
503 | } | 503 | } |
504 | 504 | ||
505 | static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 505 | static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
506 | { | 506 | { |
507 | Onion *onion = object; | 507 | Onion *onion = object; |
508 | 508 | ||
@@ -538,7 +538,7 @@ static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, ui | |||
538 | return 0; | 538 | return 0; |
539 | } | 539 | } |
540 | 540 | ||
541 | static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 541 | static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
542 | { | 542 | { |
543 | Onion *onion = object; | 543 | Onion *onion = object; |
544 | 544 | ||
diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 676b38da..f6a00f67 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c | |||
@@ -286,7 +286,7 @@ static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, const ui | |||
286 | return in_entries(onion_a, public_key); | 286 | return in_entries(onion_a, public_key); |
287 | } | 287 | } |
288 | 288 | ||
289 | static int handle_announce_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 289 | static int handle_announce_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
290 | { | 290 | { |
291 | Onion_Announce *onion_a = object; | 291 | Onion_Announce *onion_a = object; |
292 | 292 | ||
@@ -380,7 +380,7 @@ static int handle_announce_request(void *object, IP_Port source, const uint8_t * | |||
380 | return 0; | 380 | return 0; |
381 | } | 381 | } |
382 | 382 | ||
383 | static int handle_data_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 383 | static int handle_data_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
384 | { | 384 | { |
385 | Onion_Announce *onion_a = object; | 385 | Onion_Announce *onion_a = object; |
386 | 386 | ||
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index b879f393..b1a5352c 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -617,7 +617,8 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for | |||
617 | return 0; | 617 | return 0; |
618 | } | 618 | } |
619 | 619 | ||
620 | static int handle_announce_response(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 620 | static int handle_announce_response(void *object, IP_Port source, const uint8_t *packet, uint16_t length, |
621 | void *userdata) | ||
621 | { | 622 | { |
622 | Onion_Client *onion_c = object; | 623 | Onion_Client *onion_c = object; |
623 | 624 | ||
@@ -675,7 +676,7 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t | |||
675 | 676 | ||
676 | #define DATA_IN_RESPONSE_MIN_SIZE ONION_DATA_IN_RESPONSE_MIN_SIZE | 677 | #define DATA_IN_RESPONSE_MIN_SIZE ONION_DATA_IN_RESPONSE_MIN_SIZE |
677 | 678 | ||
678 | static int handle_data_response(void *object, IP_Port source, const uint8_t *packet, uint16_t length) | 679 | static int handle_data_response(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
679 | { | 680 | { |
680 | Onion_Client *onion_c = object; | 681 | Onion_Client *onion_c = object; |
681 | 682 | ||
@@ -770,7 +771,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con | |||
770 | return 0; | 771 | return 0; |
771 | } | 772 | } |
772 | 773 | ||
773 | static int handle_tcp_onion(void *object, const uint8_t *data, uint16_t length) | 774 | static int handle_tcp_onion(void *object, const uint8_t *data, uint16_t length, void *userdata) |
774 | { | 775 | { |
775 | if (length == 0) | 776 | if (length == 0) |
776 | return 1; | 777 | return 1; |
@@ -779,9 +780,9 @@ static int handle_tcp_onion(void *object, const uint8_t *data, uint16_t length) | |||
779 | ip_port.ip.family = TCP_FAMILY; | 780 | ip_port.ip.family = TCP_FAMILY; |
780 | 781 | ||
781 | if (data[0] == NET_PACKET_ANNOUNCE_RESPONSE) { | 782 | if (data[0] == NET_PACKET_ANNOUNCE_RESPONSE) { |
782 | return handle_announce_response(object, ip_port, data, length); | 783 | return handle_announce_response(object, ip_port, data, length, userdata); |
783 | } else if (data[0] == NET_PACKET_ONION_DATA_RESPONSE) { | 784 | } else if (data[0] == NET_PACKET_ONION_DATA_RESPONSE) { |
784 | return handle_data_response(object, ip_port, data, length); | 785 | return handle_data_response(object, ip_port, data, length, userdata); |
785 | } | 786 | } |
786 | 787 | ||
787 | return 1; | 788 | return 1; |
diff --git a/toxcore/ping.c b/toxcore/ping.c index f81766cb..dc0a01f3 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c | |||
@@ -129,7 +129,7 @@ static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *public_key | |||
129 | return sendpacket(ping->dht->net, ipp, pk, sizeof(pk)); | 129 | return sendpacket(ping->dht->net, ipp, pk, sizeof(pk)); |
130 | } | 130 | } |
131 | 131 | ||
132 | static int handle_ping_request(void *_dht, IP_Port source, const uint8_t *packet, uint16_t length) | 132 | static int handle_ping_request(void *_dht, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
133 | { | 133 | { |
134 | DHT *dht = _dht; | 134 | DHT *dht = _dht; |
135 | int rc; | 135 | int rc; |
@@ -168,7 +168,7 @@ static int handle_ping_request(void *_dht, IP_Port source, const uint8_t *packet | |||
168 | return 0; | 168 | return 0; |
169 | } | 169 | } |
170 | 170 | ||
171 | static int handle_ping_response(void *_dht, IP_Port source, const uint8_t *packet, uint16_t length) | 171 | static int handle_ping_response(void *_dht, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
172 | { | 172 | { |
173 | DHT *dht = _dht; | 173 | DHT *dht = _dht; |
174 | int rc; | 174 | int rc; |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 4708bc97..f43adabb 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -716,10 +716,10 @@ bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, | |||
716 | return 1; | 716 | return 1; |
717 | } | 717 | } |
718 | 718 | ||
719 | void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *function, void *user_data) | 719 | void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *function) |
720 | { | 720 | { |
721 | Messenger *m = tox; | 721 | Messenger *m = tox; |
722 | m_callback_namechange(m, function, user_data); | 722 | m_callback_namechange(m, function); |
723 | } | 723 | } |
724 | 724 | ||
725 | size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) | 725 | size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) |
diff --git a/toxcore/tox.h b/toxcore/tox.h index ca6869e4..5e6de408 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -1287,7 +1287,7 @@ typedef void tox_friend_name_cb(Tox *tox, uint32_t friend_number, const uint8_t | |||
1287 | * | 1287 | * |
1288 | * This event is triggered when a friend changes their name. | 1288 | * This event is triggered when a friend changes their name. |
1289 | */ | 1289 | */ |
1290 | void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback, void *user_data); | 1290 | void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback); |
1291 | 1291 | ||
1292 | /** | 1292 | /** |
1293 | * Return the length of the friend's status message. If the friend number is | 1293 | * Return the length of the friend's status message. If the friend number is |
diff --git a/toxcore/util.c b/toxcore/util.c index b120957c..7b715990 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -145,8 +145,8 @@ int load_state(load_state_callback_func load_state_callback, void *outer, | |||
145 | 145 | ||
146 | if (lendian_to_host16((cookie_type >> 16)) != cookie_inner) { | 146 | if (lendian_to_host16((cookie_type >> 16)) != cookie_inner) { |
147 | /* something is not matching up in a bad way, give up */ | 147 | /* something is not matching up in a bad way, give up */ |
148 | #ifdef TOX_DEBUG | 148 | #ifdef DEBUG |
149 | fprintf(stderr, "state file garbeled: %04hx != %04hx\n", (cookie_type >> 16), cookie_inner); | 149 | fprintf(stderr, "state file garbled: %04x != %04x\n", (cookie_type >> 16), cookie_inner); |
150 | #endif | 150 | #endif |
151 | return -1; | 151 | return -1; |
152 | } | 152 | } |