diff options
author | Gregory Mullen (grayhatter) <greg@grayhatter.com> | 2016-08-22 14:44:58 -0700 |
---|---|---|
committer | Gregory Mullen (grayhatter) <greg@grayhatter.com> | 2016-09-06 02:22:04 -0700 |
commit | aad1e0ad3f96786e0fb10d8dd144e5e6ebe93258 (patch) | |
tree | 963477c57148626140286ac278369ef3af60811f | |
parent | e7d3a1a665d1204d15b00fdbe6716b43d8ef3b4a (diff) |
Make friend requests stateless
Messenger is slightly twisty when it comes to sending connection status
callbacks It will very likely need at the very least a partial refactor to
clean it up a bit. Toxcore shouldn't need void *userdata as deep as is
currently does.
(amend 1) Because of the nature of toxcore connection callbacks, I decided to
change this commit from statelessness for connections changes to statelessness
for friend requests. It's simpler this was and doesn't include doing anything
foolish in the time between commits.
group fixup because grayhatter doesn't want to do it
"arguably correct" is not how you write security sensitive code
Clear a compiler warning about types within a function.
-rw-r--r-- | auto_tests/TCP_test.c | 2 | ||||
-rw-r--r-- | auto_tests/encryptsave_test.c | 2 | ||||
-rw-r--r-- | auto_tests/onion_test.c | 2 | ||||
-rw-r--r-- | auto_tests/tox_test.c | 18 | ||||
-rw-r--r-- | auto_tests/toxav_basic_test.c | 2 | ||||
-rw-r--r-- | auto_tests/toxav_many_test.c | 2 | ||||
-rw-r--r-- | other/apidsl/tox.in.h | 2 | ||||
-rw-r--r-- | testing/Messenger_test.c | 2 | ||||
-rw-r--r-- | testing/av_test.c | 2 | ||||
-rw-r--r-- | testing/nTox.c | 2 | ||||
-rw-r--r-- | toxcore/DHT.c | 6 | ||||
-rw-r--r-- | toxcore/DHT.h | 2 | ||||
-rw-r--r-- | toxcore/Messenger.c | 15 | ||||
-rw-r--r-- | toxcore/Messenger.h | 2 | ||||
-rw-r--r-- | toxcore/TCP_connection.c | 5 | ||||
-rw-r--r-- | toxcore/TCP_connection.h | 5 | ||||
-rw-r--r-- | toxcore/friend_connection.c | 29 | ||||
-rw-r--r-- | toxcore/friend_connection.h | 20 | ||||
-rw-r--r-- | toxcore/friend_requests.c | 9 | ||||
-rw-r--r-- | toxcore/friend_requests.h | 3 | ||||
-rw-r--r-- | toxcore/group.c | 16 | ||||
-rw-r--r-- | toxcore/group.h | 2 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 33 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 8 | ||||
-rw-r--r-- | toxcore/onion_client.c | 13 | ||||
-rw-r--r-- | toxcore/onion_client.h | 6 | ||||
-rw-r--r-- | toxcore/tox.c | 6 | ||||
-rw-r--r-- | toxcore/tox.h | 2 |
28 files changed, 110 insertions, 108 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index 4c26926f..8e6adf2e 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c | |||
@@ -633,7 +633,7 @@ END_TEST | |||
633 | 633 | ||
634 | _Bool tcp_oobdata_callback_called; | 634 | _Bool tcp_oobdata_callback_called; |
635 | static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigned int id, const uint8_t *data, | 635 | static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigned int id, const uint8_t *data, |
636 | uint16_t length) | 636 | uint16_t length, void *userdata) |
637 | { | 637 | { |
638 | if (length != 6) { | 638 | if (length != 6) { |
639 | return -1; | 639 | return -1; |
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 99a5792e..02a29016 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -60,7 +60,7 @@ START_TEST(test_save_friend) | |||
60 | Tox *tox2 = tox_new(0, 0); | 60 | Tox *tox2 = tox_new(0, 0); |
61 | ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); | 61 | ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); |
62 | uint32_t to_compare = 974536; | 62 | uint32_t to_compare = 974536; |
63 | tox_callback_friend_request(tox2, accept_friend_request, &to_compare); | 63 | tox_callback_friend_request(tox2, accept_friend_request); |
64 | uint8_t address[TOX_ADDRESS_SIZE]; | 64 | uint8_t address[TOX_ADDRESS_SIZE]; |
65 | tox_self_get_address(tox2, address); | 65 | tox_self_get_address(tox2, address); |
66 | uint32_t test = tox_friend_add(tox1, address, (uint8_t *)"Gentoo", 7, 0); | 66 | uint32_t test = tox_friend_add(tox1, address, (uint8_t *)"Gentoo", 7, 0); |
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index b12c6a3f..58fde2d6 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -342,7 +342,7 @@ _Bool first, last; | |||
342 | uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES]; | 342 | uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES]; |
343 | uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES]; | 343 | uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES]; |
344 | 344 | ||
345 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key) | 345 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) |
346 | { | 346 | { |
347 | if ((NUM_FIRST == number && !first) || (NUM_LAST == number && !last)) { | 347 | if ((NUM_FIRST == number && !first) || (NUM_LAST == number && !last)) { |
348 | Onions *on = object; | 348 | Onions *on = object; |
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index db36e2b1..c7ba45cd 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c | |||
@@ -462,7 +462,7 @@ START_TEST(test_few_clients) | |||
462 | uint32_t to_compare = 974536; | 462 | uint32_t to_compare = 974536; |
463 | connected_t1 = 0; | 463 | connected_t1 = 0; |
464 | tox_callback_self_connection_status(tox1, tox_connection_status); | 464 | tox_callback_self_connection_status(tox1, tox_connection_status); |
465 | tox_callback_friend_request(tox2, accept_friend_request, &to_compare); | 465 | tox_callback_friend_request(tox2, accept_friend_request); |
466 | uint8_t address[TOX_ADDRESS_SIZE]; | 466 | uint8_t address[TOX_ADDRESS_SIZE]; |
467 | tox_self_get_address(tox2, address); | 467 | tox_self_get_address(tox2, address); |
468 | uint32_t test = tox_friend_add(tox3, address, (uint8_t *)"Gentoo", 7, 0); | 468 | uint32_t test = tox_friend_add(tox3, address, (uint8_t *)"Gentoo", 7, 0); |
@@ -849,7 +849,7 @@ START_TEST(test_many_clients) | |||
849 | for (i = 0; i < NUM_TOXES; ++i) { | 849 | for (i = 0; i < NUM_TOXES; ++i) { |
850 | toxes[i] = tox_new(0, 0); | 850 | toxes[i] = tox_new(0, 0); |
851 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); | 851 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); |
852 | tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); | 852 | tox_callback_friend_request(toxes[i], accept_friend_request); |
853 | } | 853 | } |
854 | 854 | ||
855 | { | 855 | { |
@@ -918,7 +918,7 @@ loop_top: | |||
918 | } | 918 | } |
919 | 919 | ||
920 | for (i = 0; i < NUM_TOXES; ++i) { | 920 | for (i = 0; i < NUM_TOXES; ++i) { |
921 | tox_iterate(toxes[i], NULL); | 921 | tox_iterate(toxes[i], &to_comp); |
922 | } | 922 | } |
923 | 923 | ||
924 | c_sleep(50); | 924 | c_sleep(50); |
@@ -954,7 +954,7 @@ START_TEST(test_many_clients_tcp) | |||
954 | 954 | ||
955 | toxes[i] = tox_new(&opts, 0); | 955 | toxes[i] = tox_new(&opts, 0); |
956 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); | 956 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); |
957 | tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); | 957 | tox_callback_friend_request(toxes[i], accept_friend_request); |
958 | uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; | 958 | uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; |
959 | tox_self_get_dht_id(toxes[0], dpk); | 959 | tox_self_get_dht_id(toxes[0], dpk); |
960 | TOX_ERR_BOOTSTRAP error = 0; | 960 | TOX_ERR_BOOTSTRAP error = 0; |
@@ -1018,7 +1018,7 @@ loop_top: | |||
1018 | } | 1018 | } |
1019 | 1019 | ||
1020 | for (i = 0; i < NUM_TOXES_TCP; ++i) { | 1020 | for (i = 0; i < NUM_TOXES_TCP; ++i) { |
1021 | tox_iterate(toxes[i], NULL); | 1021 | tox_iterate(toxes[i], &to_comp); |
1022 | } | 1022 | } |
1023 | 1023 | ||
1024 | c_sleep(50); | 1024 | c_sleep(50); |
@@ -1053,7 +1053,7 @@ START_TEST(test_many_clients_tcp_b) | |||
1053 | 1053 | ||
1054 | toxes[i] = tox_new(&opts, 0); | 1054 | toxes[i] = tox_new(&opts, 0); |
1055 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); | 1055 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); |
1056 | tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); | 1056 | tox_callback_friend_request(toxes[i], accept_friend_request); |
1057 | uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; | 1057 | uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; |
1058 | tox_self_get_dht_id(toxes[(i % NUM_TCP_RELAYS)], dpk); | 1058 | tox_self_get_dht_id(toxes[(i % NUM_TCP_RELAYS)], dpk); |
1059 | ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, TCP_RELAY_PORT + (i % NUM_TCP_RELAYS), dpk, 0), | 1059 | ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, TCP_RELAY_PORT + (i % NUM_TCP_RELAYS), dpk, 0), |
@@ -1117,7 +1117,7 @@ loop_top: | |||
1117 | } | 1117 | } |
1118 | 1118 | ||
1119 | for (i = 0; i < NUM_TOXES_TCP; ++i) { | 1119 | for (i = 0; i < NUM_TOXES_TCP; ++i) { |
1120 | tox_iterate(toxes[i], NULL); | 1120 | tox_iterate(toxes[i], &to_comp); |
1121 | } | 1121 | } |
1122 | 1122 | ||
1123 | c_sleep(30); | 1123 | c_sleep(30); |
@@ -1200,7 +1200,7 @@ group_test_restart: | |||
1200 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | 1200 | for (i = 0; i < NUM_GROUP_TOX; ++i) { |
1201 | toxes[i] = tox_new(0, 0); | 1201 | toxes[i] = tox_new(0, 0); |
1202 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); | 1202 | ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); |
1203 | tox_callback_friend_request(toxes[i], &g_accept_friend_request, &to_comp); | 1203 | tox_callback_friend_request(toxes[i], &g_accept_friend_request); |
1204 | tox_callback_group_invite(toxes[i], &print_group_invite_callback, &to_comp); | 1204 | tox_callback_group_invite(toxes[i], &print_group_invite_callback, &to_comp); |
1205 | } | 1205 | } |
1206 | 1206 | ||
@@ -1231,7 +1231,7 @@ group_test_restart: | |||
1231 | } | 1231 | } |
1232 | 1232 | ||
1233 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | 1233 | for (i = 0; i < NUM_GROUP_TOX; ++i) { |
1234 | tox_iterate(toxes[i], NULL); | 1234 | tox_iterate(toxes[i], &to_comp); |
1235 | } | 1235 | } |
1236 | 1236 | ||
1237 | c_sleep(25); | 1237 | c_sleep(25); |
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index 2540f592..e3c4447e 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c | |||
@@ -171,7 +171,7 @@ START_TEST(test_AV_flows) | |||
171 | uint32_t to_compare = 974536; | 171 | uint32_t to_compare = 974536; |
172 | uint8_t address[TOX_ADDRESS_SIZE]; | 172 | uint8_t address[TOX_ADDRESS_SIZE]; |
173 | 173 | ||
174 | tox_callback_friend_request(Alice, t_accept_friend_request_cb, &to_compare); | 174 | tox_callback_friend_request(Alice, t_accept_friend_request_cb); |
175 | tox_self_get_address(Alice, address); | 175 | tox_self_get_address(Alice, address); |
176 | 176 | ||
177 | 177 | ||
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index e3476512..9a58e648 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c | |||
@@ -237,7 +237,7 @@ START_TEST(test_AV_three_calls) | |||
237 | uint32_t to_compare = 974536; | 237 | uint32_t to_compare = 974536; |
238 | uint8_t address[TOX_ADDRESS_SIZE]; | 238 | uint8_t address[TOX_ADDRESS_SIZE]; |
239 | 239 | ||
240 | tox_callback_friend_request(Alice, t_accept_friend_request_cb, &to_compare); | 240 | tox_callback_friend_request(Alice, t_accept_friend_request_cb); |
241 | tox_self_get_address(Alice, address); | 241 | tox_self_get_address(Alice, address); |
242 | 242 | ||
243 | 243 | ||
diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h index a280348a..a8c7ef69 100644 --- a/other/apidsl/tox.in.h +++ b/other/apidsl/tox.in.h | |||
@@ -1532,7 +1532,7 @@ namespace friend { | |||
1532 | /** | 1532 | /** |
1533 | * This event is triggered when a friend request is received. | 1533 | * This event is triggered when a friend request is received. |
1534 | */ | 1534 | */ |
1535 | event request { | 1535 | event request const { |
1536 | /** | 1536 | /** |
1537 | * @param public_key The Public Key of the user who sent the friend request. | 1537 | * @param public_key The Public Key of the user who sent the friend request. |
1538 | * @param time_delta A delta in seconds between when the message was composed | 1538 | * @param time_delta A delta in seconds between when the message was composed |
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index edfe4fb1..668f046a 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c | |||
@@ -148,7 +148,7 @@ int main(int argc, char *argv[]) | |||
148 | fclose(file); | 148 | fclose(file); |
149 | } | 149 | } |
150 | 150 | ||
151 | m_callback_friendrequest(m, print_request, NULL); | 151 | m_callback_friendrequest(m, print_request); |
152 | m_callback_friendmessage(m, print_message); | 152 | m_callback_friendmessage(m, print_message); |
153 | 153 | ||
154 | printf("OUR ID: "); | 154 | printf("OUR ID: "); |
diff --git a/testing/av_test.c b/testing/av_test.c index 7af50cda..35eb3f60 100644 --- a/testing/av_test.c +++ b/testing/av_test.c | |||
@@ -231,7 +231,7 @@ void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceCC, ToxA | |||
231 | uint32_t to_compare = 974536; | 231 | uint32_t to_compare = 974536; |
232 | uint8_t address[TOX_ADDRESS_SIZE]; | 232 | uint8_t address[TOX_ADDRESS_SIZE]; |
233 | 233 | ||
234 | tox_callback_friend_request(Alice, t_accept_friend_request_cb, &to_compare); | 234 | tox_callback_friend_request(Alice, t_accept_friend_request_cb); |
235 | tox_self_get_address(Alice, address); | 235 | tox_self_get_address(Alice, address); |
236 | 236 | ||
237 | 237 | ||
diff --git a/testing/nTox.c b/testing/nTox.c index 689d2002..ec6b152c 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -1334,7 +1334,7 @@ int main(int argc, char *argv[]) | |||
1334 | 1334 | ||
1335 | save_data_file(m, filename); | 1335 | save_data_file(m, filename); |
1336 | 1336 | ||
1337 | tox_callback_friend_request(m, print_request, NULL); | 1337 | tox_callback_friend_request(m, print_request); |
1338 | tox_callback_friend_message(m, print_message); | 1338 | tox_callback_friend_message(m, print_message); |
1339 | tox_callback_friend_name(m, print_nickchange); | 1339 | tox_callback_friend_name(m, print_nickchange); |
1340 | tox_callback_friend_status_message(m, print_statuschange); | 1340 | tox_callback_friend_status_message(m, print_statuschange); |
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 2fd18c49..ac94a36e 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -1944,7 +1944,7 @@ static int send_NATping(DHT *dht, const uint8_t *public_key, uint64_t ping_id, u | |||
1944 | 1944 | ||
1945 | /* Handle a received ping request for. */ | 1945 | /* Handle a received ping request for. */ |
1946 | static int handle_NATping(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, | 1946 | static int handle_NATping(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, |
1947 | uint16_t length) | 1947 | uint16_t length, void *userdata) |
1948 | { | 1948 | { |
1949 | if (length != sizeof(uint64_t) + 1) { | 1949 | if (length != sizeof(uint64_t) + 1) { |
1950 | return 1; | 1950 | return 1; |
@@ -2243,7 +2243,7 @@ static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num) | |||
2243 | 2243 | ||
2244 | /* Handle a received hardening packet */ | 2244 | /* Handle a received hardening packet */ |
2245 | static int handle_hardening(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, | 2245 | static int handle_hardening(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, |
2246 | uint16_t length) | 2246 | uint16_t length, void *userdata) |
2247 | { | 2247 | { |
2248 | DHT *dht = object; | 2248 | DHT *dht = object; |
2249 | 2249 | ||
@@ -2503,7 +2503,7 @@ static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *pack | |||
2503 | } | 2503 | } |
2504 | 2504 | ||
2505 | return dht->cryptopackethandlers[number].function(dht->cryptopackethandlers[number].object, source, public_key, | 2505 | return dht->cryptopackethandlers[number].function(dht->cryptopackethandlers[number].object, source, public_key, |
2506 | data, len); | 2506 | data, len, userdata); |
2507 | } | 2507 | } |
2508 | 2508 | ||
2509 | /* If request is not for us, try routing it. */ | 2509 | /* If request is not for us, try routing it. */ |
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 8e0e2cc7..9f7f1d9f 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -198,7 +198,7 @@ typedef struct { | |||
198 | /*----------------------------------------------------------------------------------*/ | 198 | /*----------------------------------------------------------------------------------*/ |
199 | 199 | ||
200 | typedef int (*cryptopacket_handler_callback)(void *object, IP_Port ip_port, const uint8_t *source_pubkey, | 200 | typedef int (*cryptopacket_handler_callback)(void *object, IP_Port ip_port, const uint8_t *source_pubkey, |
201 | const uint8_t *data, uint16_t len); | 201 | const uint8_t *data, uint16_t len, void *userdata); |
202 | 202 | ||
203 | typedef struct { | 203 | typedef struct { |
204 | cryptopacket_handler_callback function; | 204 | cryptopacket_handler_callback function; |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 8113a8f0..472ddd9e 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -168,7 +168,7 @@ static int send_offline_packet(Messenger *m, int friendcon_id) | |||
168 | sizeof(packet), 0) != -1; | 168 | sizeof(packet), 0) != -1; |
169 | } | 169 | } |
170 | 170 | ||
171 | static int handle_status(void *object, int i, uint8_t status); | 171 | static int handle_status(void *object, int i, uint8_t status, void *userdata); |
172 | static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata); | 172 | static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata); |
173 | static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length); | 173 | static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length); |
174 | 174 | ||
@@ -450,8 +450,8 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber) | |||
450 | if (m->friendlist[friendnumber].status == FRIEND_ONLINE) { | 450 | if (m->friendlist[friendnumber].status == FRIEND_ONLINE) { |
451 | _Bool direct_connected = 0; | 451 | _Bool direct_connected = 0; |
452 | unsigned int num_online_relays = 0; | 452 | unsigned int num_online_relays = 0; |
453 | crypto_connection_status(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, | 453 | int crypt_conn_id = friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id); |
454 | m->friendlist[friendnumber].friendcon_id), &direct_connected, &num_online_relays); | 454 | crypto_connection_status(m->net_crypto, crypt_conn_id, &direct_connected, &num_online_relays); |
455 | 455 | ||
456 | if (direct_connected) { | 456 | if (direct_connected) { |
457 | return CONNECTION_UDP; | 457 | return CONNECTION_UDP; |
@@ -836,10 +836,9 @@ void m_callback_log(Messenger *m, logger_cb *function, void *userdata) | |||
836 | 836 | ||
837 | /* Set the function that will be executed when a friend request is received. */ | 837 | /* Set the function that will be executed when a friend request is received. */ |
838 | void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const uint8_t *, const uint8_t *, size_t, | 838 | void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const uint8_t *, const uint8_t *, size_t, |
839 | void *), void *userdata) | 839 | void *)) |
840 | { | 840 | { |
841 | void (*handle_friendrequest)(void *, const uint8_t *, const uint8_t *, size_t, void *) = (void *)function; | 841 | callback_friendrequest(&(m->fr), (void (*)(void *, const uint8_t *, const uint8_t *, size_t, void *))function, m); |
842 | callback_friendrequest(&(m->fr), handle_friendrequest, m, userdata); | ||
843 | } | 842 | } |
844 | 843 | ||
845 | /* Set the function that will be executed when a message from a friend is received. */ | 844 | /* Set the function that will be executed when a message from a friend is received. */ |
@@ -2040,7 +2039,7 @@ static void check_friend_request_timed_out(Messenger *m, uint32_t i, uint64_t t) | |||
2040 | } | 2039 | } |
2041 | } | 2040 | } |
2042 | 2041 | ||
2043 | static int handle_status(void *object, int i, uint8_t status) | 2042 | static int handle_status(void *object, int i, uint8_t status, void *userdata) |
2044 | { | 2043 | { |
2045 | Messenger *m = object; | 2044 | Messenger *m = object; |
2046 | 2045 | ||
@@ -2500,7 +2499,7 @@ void do_messenger(Messenger *m, void *userdata) | |||
2500 | 2499 | ||
2501 | do_net_crypto(m->net_crypto, userdata); | 2500 | do_net_crypto(m->net_crypto, userdata); |
2502 | do_onion_client(m->onion_c); | 2501 | do_onion_client(m->onion_c); |
2503 | do_friend_connections(m->fr_c); | 2502 | do_friend_connections(m->fr_c, userdata); |
2504 | do_friends(m, userdata); | 2503 | do_friends(m, userdata); |
2505 | connection_status_cb(m, userdata); | 2504 | connection_status_cb(m, userdata); |
2506 | 2505 | ||
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index a59f8c4e..dc809a22 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -472,7 +472,7 @@ void m_callback_log(Messenger *m, logger_cb *function, void *userdata); | |||
472 | * Function format is function(uint8_t * public_key, uint8_t * data, size_t length) | 472 | * Function format is function(uint8_t * public_key, uint8_t * data, size_t length) |
473 | */ | 473 | */ |
474 | void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const uint8_t *, const uint8_t *, size_t, | 474 | void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const uint8_t *, const uint8_t *, size_t, |
475 | void *), void *userdata); | 475 | void *)); |
476 | 476 | ||
477 | /* Set the function that will be executed when a message from a friend is received. | 477 | /* Set the function that will be executed when a message from a friend is received. |
478 | * Function format is: function(uint32_t friendnumber, unsigned int type, uint8_t * message, uint32_t length) | 478 | * Function format is: function(uint32_t friendnumber, unsigned int type, uint8_t * message, uint32_t length) |
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index 922bf0df..623aeb4f 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c | |||
@@ -375,7 +375,8 @@ void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_data_c | |||
375 | /* Set the callback for TCP onion packets. | 375 | /* Set the callback for TCP onion packets. |
376 | */ | 376 | */ |
377 | void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_oob_callback)(void *object, | 377 | void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_oob_callback)(void *object, |
378 | const uint8_t *public_key, unsigned int tcp_connections_number, const uint8_t *data, uint16_t length), void *object) | 378 | const uint8_t *public_key, unsigned int tcp_connections_number, const uint8_t *data, uint16_t length, void *userdata), |
379 | void *object) | ||
379 | { | 380 | { |
380 | tcp_c->tcp_oob_callback = tcp_oob_callback; | 381 | tcp_c->tcp_oob_callback = tcp_oob_callback; |
381 | tcp_c->tcp_oob_callback_object = object; | 382 | tcp_c->tcp_oob_callback_object = object; |
@@ -985,7 +986,7 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8 | |||
985 | } | 986 | } |
986 | 987 | ||
987 | if (tcp_c->tcp_oob_callback) { | 988 | if (tcp_c->tcp_oob_callback) { |
988 | tcp_c->tcp_oob_callback(tcp_c->tcp_oob_callback_object, public_key, tcp_connections_number, data, length); | 989 | tcp_c->tcp_oob_callback(tcp_c->tcp_oob_callback_object, public_key, tcp_connections_number, data, length, userdata); |
989 | } | 990 | } |
990 | 991 | ||
991 | return 0; | 992 | return 0; |
diff --git a/toxcore/TCP_connection.h b/toxcore/TCP_connection.h index f45e804c..e080c7e2 100644 --- a/toxcore/TCP_connection.h +++ b/toxcore/TCP_connection.h | |||
@@ -94,7 +94,7 @@ typedef struct { | |||
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, void *userdata); |
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, void *userdata); | 100 | int (*tcp_onion_callback)(void *object, const uint8_t *data, uint16_t length, void *userdata); |
@@ -161,7 +161,8 @@ void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_ | |||
161 | /* Set the callback for TCP oob data packets. | 161 | /* Set the callback for TCP oob data packets. |
162 | */ | 162 | */ |
163 | void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_oob_callback)(void *object, | 163 | void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, int (*tcp_oob_callback)(void *object, |
164 | const uint8_t *public_key, unsigned int tcp_connections_number, const uint8_t *data, uint16_t length), void *object); | 164 | const uint8_t *public_key, unsigned int tcp_connections_number, const uint8_t *data, uint16_t length, void *userdata), |
165 | void *object); | ||
165 | 166 | ||
166 | /* Create a new TCP connection to public_key. | 167 | /* Create a new TCP connection to public_key. |
167 | * | 168 | * |
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index 7c8471a0..d2d305aa 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c | |||
@@ -322,7 +322,7 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint | |||
322 | memcpy(friend_con->dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES); | 322 | memcpy(friend_con->dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES); |
323 | } | 323 | } |
324 | 324 | ||
325 | static int handle_status(void *object, int number, uint8_t status) | 325 | static int handle_status(void *object, int number, uint8_t status, void *userdata) |
326 | { | 326 | { |
327 | Friend_Connections *fr_c = object; | 327 | Friend_Connections *fr_c = object; |
328 | Friend_Conn *friend_con = get_conn(fr_c, number); | 328 | Friend_Conn *friend_con = get_conn(fr_c, number); |
@@ -357,7 +357,7 @@ static int handle_status(void *object, int number, uint8_t status) | |||
357 | for (i = 0; i < MAX_FRIEND_CONNECTION_CALLBACKS; ++i) { | 357 | for (i = 0; i < MAX_FRIEND_CONNECTION_CALLBACKS; ++i) { |
358 | if (friend_con->callbacks[i].status_callback) { | 358 | if (friend_con->callbacks[i].status_callback) { |
359 | friend_con->callbacks[i].status_callback(friend_con->callbacks[i].status_callback_object, | 359 | friend_con->callbacks[i].status_callback(friend_con->callbacks[i].status_callback_object, |
360 | friend_con->callbacks[i].status_callback_id, status); | 360 | friend_con->callbacks[i].status_callback_id, status, userdata); |
361 | } | 361 | } |
362 | } | 362 | } |
363 | } | 363 | } |
@@ -366,7 +366,7 @@ static int handle_status(void *object, int number, uint8_t status) | |||
366 | } | 366 | } |
367 | 367 | ||
368 | /* Callback for dht public key changes. */ | 368 | /* Callback for dht public key changes. */ |
369 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key) | 369 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) |
370 | { | 370 | { |
371 | Friend_Connections *fr_c = object; | 371 | Friend_Connections *fr_c = object; |
372 | Friend_Conn *friend_con = get_conn(fr_c, number); | 372 | Friend_Conn *friend_con = get_conn(fr_c, number); |
@@ -385,7 +385,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub | |||
385 | if (friend_con->crypt_connection_id != -1) { | 385 | if (friend_con->crypt_connection_id != -1) { |
386 | crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id); | 386 | crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id); |
387 | friend_con->crypt_connection_id = -1; | 387 | friend_con->crypt_connection_id = -1; |
388 | handle_status(object, number, 0); /* Going offline. */ | 388 | handle_status(object, number, 0, userdata); /* Going offline. */ |
389 | } | 389 | } |
390 | 390 | ||
391 | friend_new_connection(fr_c, number); | 391 | friend_new_connection(fr_c, number); |
@@ -407,7 +407,7 @@ static int handle_packet(void *object, int number, const uint8_t *data, uint16_t | |||
407 | 407 | ||
408 | if (data[0] == PACKET_ID_FRIEND_REQUESTS) { | 408 | if (data[0] == PACKET_ID_FRIEND_REQUESTS) { |
409 | if (fr_c->fr_request_callback) { | 409 | if (fr_c->fr_request_callback) { |
410 | fr_c->fr_request_callback(fr_c->fr_request_object, friend_con->real_public_key, data, length); | 410 | fr_c->fr_request_callback(fr_c->fr_request_object, friend_con->real_public_key, data, length, userdata); |
411 | } | 411 | } |
412 | 412 | ||
413 | return 0; | 413 | return 0; |
@@ -635,9 +635,9 @@ int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, Friend_Con | |||
635 | 635 | ||
636 | /* Set temp dht key for connection. | 636 | /* Set temp dht key for connection. |
637 | */ | 637 | */ |
638 | void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_temp_pk) | 638 | void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_temp_pk, void *userdata) |
639 | { | 639 | { |
640 | dht_pk_callback(fr_c, friendcon_id, dht_temp_pk); | 640 | dht_pk_callback(fr_c, friendcon_id, dht_temp_pk, userdata); |
641 | } | 641 | } |
642 | 642 | ||
643 | /* Set the callbacks for the friend connection. | 643 | /* Set the callbacks for the friend connection. |
@@ -647,11 +647,10 @@ void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t * | |||
647 | * return -1 on failure | 647 | * return -1 on failure |
648 | */ | 648 | */ |
649 | int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index, | 649 | int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index, |
650 | int (*status_callback)(void *object, int id, uint8_t status), int (*data_callback)(void *object, int id, | 650 | int (*status_callback)(void *object, int id, uint8_t status, void *userdata), |
651 | const uint8_t *data, | 651 | int (*data_callback)(void *object, int id, const uint8_t *data, uint16_t len, void *userdata), |
652 | uint16_t length, void *userdata), int (*lossy_data_callback)(void *object, int id, const uint8_t *data, | 652 | int (*lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), |
653 | uint16_t length), void *object, | 653 | void *object, int number) |
654 | int number) | ||
655 | { | 654 | { |
656 | Friend_Conn *friend_con = get_conn(fr_c, friendcon_id); | 655 | Friend_Conn *friend_con = get_conn(fr_c, friendcon_id); |
657 | 656 | ||
@@ -767,7 +766,7 @@ int kill_friend_connection(Friend_Connections *fr_c, int friendcon_id) | |||
767 | * This function will be called every time a friend request packet is received. | 766 | * This function will be called every time a friend request packet is received. |
768 | */ | 767 | */ |
769 | void set_friend_request_callback(Friend_Connections *fr_c, int (*fr_request_callback)(void *, const uint8_t *, | 768 | void set_friend_request_callback(Friend_Connections *fr_c, int (*fr_request_callback)(void *, const uint8_t *, |
770 | const uint8_t *, uint16_t), void *object) | 769 | const uint8_t *, uint16_t, void *), void *object) |
771 | { | 770 | { |
772 | fr_c->fr_request_callback = fr_request_callback; | 771 | fr_c->fr_request_callback = fr_request_callback; |
773 | fr_c->fr_request_object = object; | 772 | fr_c->fr_request_object = object; |
@@ -845,7 +844,7 @@ static void LANdiscovery(Friend_Connections *fr_c) | |||
845 | } | 844 | } |
846 | 845 | ||
847 | /* main friend_connections loop. */ | 846 | /* main friend_connections loop. */ |
848 | void do_friend_connections(Friend_Connections *fr_c) | 847 | void do_friend_connections(Friend_Connections *fr_c, void *userdata) |
849 | { | 848 | { |
850 | uint32_t i; | 849 | uint32_t i; |
851 | uint64_t temp_time = unix_time(); | 850 | uint64_t temp_time = unix_time(); |
@@ -885,7 +884,7 @@ void do_friend_connections(Friend_Connections *fr_c) | |||
885 | /* If we stopped receiving ping packets, kill it. */ | 884 | /* If we stopped receiving ping packets, kill it. */ |
886 | crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id); | 885 | crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id); |
887 | friend_con->crypt_connection_id = -1; | 886 | friend_con->crypt_connection_id = -1; |
888 | handle_status(fr_c, i, 0); /* Going offline. */ | 887 | handle_status(fr_c, i, 0, userdata); /* Going offline. */ |
889 | } | 888 | } |
890 | } | 889 | } |
891 | } | 890 | } |
diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h index a939b17c..6eb4dd84 100644 --- a/toxcore/friend_connection.h +++ b/toxcore/friend_connection.h | |||
@@ -79,7 +79,7 @@ typedef struct { | |||
79 | uint64_t share_relays_lastsent; | 79 | uint64_t share_relays_lastsent; |
80 | 80 | ||
81 | struct { | 81 | struct { |
82 | int (*status_callback)(void *object, int id, uint8_t status); | 82 | int (*status_callback)(void *object, int id, uint8_t status, void *userdata); |
83 | void *status_callback_object; | 83 | void *status_callback_object; |
84 | int status_callback_id; | 84 | int status_callback_id; |
85 | 85 | ||
@@ -109,7 +109,8 @@ typedef struct { | |||
109 | Friend_Conn *conns; | 109 | Friend_Conn *conns; |
110 | uint32_t num_cons; | 110 | uint32_t num_cons; |
111 | 111 | ||
112 | int (*fr_request_callback)(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t len); | 112 | int (*fr_request_callback)(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t len, |
113 | void *userdata); | ||
113 | void *fr_request_object; | 114 | void *fr_request_object; |
114 | 115 | ||
115 | uint64_t last_LANdiscovery; | 116 | uint64_t last_LANdiscovery; |
@@ -142,7 +143,7 @@ int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, Friend_Con | |||
142 | 143 | ||
143 | /* Set temp dht key for connection. | 144 | /* Set temp dht key for connection. |
144 | */ | 145 | */ |
145 | void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_temp_pk); | 146 | void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_temp_pk, void *userdata); |
146 | 147 | ||
147 | /* Add a TCP relay associated to the friend. | 148 | /* Add a TCP relay associated to the friend. |
148 | * | 149 | * |
@@ -158,11 +159,10 @@ int friend_add_tcp_relay(Friend_Connections *fr_c, int friendcon_id, IP_Port ip_ | |||
158 | * return -1 on failure | 159 | * return -1 on failure |
159 | */ | 160 | */ |
160 | int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index, | 161 | 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, | 162 | int (*status_callback)(void *object, int id, uint8_t status, void *userdata), |
162 | const uint8_t *data, | 163 | int (*data_callback)(void *object, int id, const uint8_t *data, uint16_t len, void *userdata), |
163 | uint16_t length, void *userdata), int (*lossy_data_callback)(void *object, int id, const uint8_t *data, | 164 | int (*lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), |
164 | uint16_t length), void *object, | 165 | void *object, int number); |
165 | int number); | ||
166 | 166 | ||
167 | /* return the crypt_connection_id for the connection. | 167 | /* return the crypt_connection_id for the connection. |
168 | * | 168 | * |
@@ -200,13 +200,13 @@ int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint3 | |||
200 | * This function will be called every time a friend request is received. | 200 | * This function will be called every time a friend request is received. |
201 | */ | 201 | */ |
202 | void set_friend_request_callback(Friend_Connections *fr_c, int (*fr_request_callback)(void *, const uint8_t *, | 202 | void set_friend_request_callback(Friend_Connections *fr_c, int (*fr_request_callback)(void *, const uint8_t *, |
203 | const uint8_t *, uint16_t), void *object); | 203 | const uint8_t *, uint16_t, void *), void *object); |
204 | 204 | ||
205 | /* Create new friend_connections instance. */ | 205 | /* Create new friend_connections instance. */ |
206 | Friend_Connections *new_friend_connections(Onion_Client *onion_c); | 206 | Friend_Connections *new_friend_connections(Onion_Client *onion_c); |
207 | 207 | ||
208 | /* main friend_connections loop. */ | 208 | /* main friend_connections loop. */ |
209 | void do_friend_connections(Friend_Connections *fr_c); | 209 | void do_friend_connections(Friend_Connections *fr_c, void *userdata); |
210 | 210 | ||
211 | /* Free everything related with friend_connections. */ | 211 | /* Free everything related with friend_connections. */ |
212 | void kill_friend_connections(Friend_Connections *fr_c); | 212 | void kill_friend_connections(Friend_Connections *fr_c); |
diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c index 122bef3b..3d10213b 100644 --- a/toxcore/friend_requests.c +++ b/toxcore/friend_requests.c | |||
@@ -43,12 +43,11 @@ uint32_t get_nospam(const Friend_Requests *fr) | |||
43 | 43 | ||
44 | /* Set the function that will be executed when a friend request is received. */ | 44 | /* Set the function that will be executed when a friend request is received. */ |
45 | void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const uint8_t *, const uint8_t *, size_t, | 45 | void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const uint8_t *, const uint8_t *, size_t, |
46 | void *), void *object, void *userdata) | 46 | void *), void *object) |
47 | { | 47 | { |
48 | fr->handle_friendrequest = function; | 48 | fr->handle_friendrequest = function; |
49 | fr->handle_friendrequest_isset = 1; | 49 | fr->handle_friendrequest_isset = 1; |
50 | fr->handle_friendrequest_object = object; | 50 | fr->handle_friendrequest_object = object; |
51 | fr->handle_friendrequest_userdata = userdata; | ||
52 | } | 51 | } |
53 | /* Set the function used to check if a friend request should be displayed to the user or not. */ | 52 | /* Set the function used to check if a friend request should be displayed to the user or not. */ |
54 | void set_filter_function(Friend_Requests *fr, int (*function)(const uint8_t *, void *), void *userdata) | 53 | void set_filter_function(Friend_Requests *fr, int (*function)(const uint8_t *, void *), void *userdata) |
@@ -106,7 +105,8 @@ int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk) | |||
106 | } | 105 | } |
107 | 106 | ||
108 | 107 | ||
109 | static int friendreq_handlepacket(void *object, const uint8_t *source_pubkey, const uint8_t *packet, uint16_t length) | 108 | static int friendreq_handlepacket(void *object, const uint8_t *source_pubkey, const uint8_t *packet, uint16_t length, |
109 | void *userdata) | ||
110 | { | 110 | { |
111 | Friend_Requests *fr = object; | 111 | Friend_Requests *fr = object; |
112 | 112 | ||
@@ -142,8 +142,7 @@ static int friendreq_handlepacket(void *object, const uint8_t *source_pubkey, co | |||
142 | memcpy(message, packet + sizeof(fr->nospam), message_len); | 142 | memcpy(message, packet + sizeof(fr->nospam), message_len); |
143 | message[sizeof(message) - 1] = 0; /* Be sure the message is null terminated. */ | 143 | message[sizeof(message) - 1] = 0; /* Be sure the message is null terminated. */ |
144 | 144 | ||
145 | (*fr->handle_friendrequest)(fr->handle_friendrequest_object, source_pubkey, message, message_len, | 145 | (*fr->handle_friendrequest)(fr->handle_friendrequest_object, source_pubkey, message, message_len, userdata); |
146 | fr->handle_friendrequest_userdata); | ||
147 | return 0; | 146 | return 0; |
148 | } | 147 | } |
149 | 148 | ||
diff --git a/toxcore/friend_requests.h b/toxcore/friend_requests.h index ae21f7dc..5fd9bf34 100644 --- a/toxcore/friend_requests.h +++ b/toxcore/friend_requests.h | |||
@@ -33,7 +33,6 @@ typedef struct { | |||
33 | void (*handle_friendrequest)(void *, const uint8_t *, const uint8_t *, size_t, void *); | 33 | void (*handle_friendrequest)(void *, const uint8_t *, const uint8_t *, size_t, void *); |
34 | uint8_t handle_friendrequest_isset; | 34 | uint8_t handle_friendrequest_isset; |
35 | void *handle_friendrequest_object; | 35 | void *handle_friendrequest_object; |
36 | void *handle_friendrequest_userdata; | ||
37 | 36 | ||
38 | int (*filter_function)(const uint8_t *, void *); | 37 | int (*filter_function)(const uint8_t *, void *); |
39 | void *filter_function_userdata; | 38 | void *filter_function_userdata; |
@@ -62,7 +61,7 @@ int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk); | |||
62 | * Function format is function(uint8_t * public_key, uint8_t * data, size_t length, void * userdata) | 61 | * Function format is function(uint8_t * public_key, uint8_t * data, size_t length, void * userdata) |
63 | */ | 62 | */ |
64 | void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const uint8_t *, const uint8_t *, size_t, | 63 | void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const uint8_t *, const uint8_t *, size_t, |
65 | void *), void *object, void *userdata); | 64 | void *), void *object); |
66 | 65 | ||
67 | /* Set the function used to check if a friend request should be displayed to the user or not. | 66 | /* Set the function used to check if a friend request should be displayed to the user or not. |
68 | * Function format is int function(uint8_t * public_key, void * userdata) | 67 | * Function format is int function(uint8_t * public_key, void * userdata) |
diff --git a/toxcore/group.c b/toxcore/group.c index db114529..f1086657 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -327,7 +327,7 @@ static unsigned int pk_in_closest_peers(Group_c *g, uint8_t *real_pk) | |||
327 | 327 | ||
328 | static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier); | 328 | static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier); |
329 | 329 | ||
330 | static int connect_to_closest(Group_Chats *g_c, int groupnumber) | 330 | static int connect_to_closest(Group_Chats *g_c, int groupnumber, void *userdata) |
331 | { | 331 | { |
332 | Group_c *g = get_group_c(g_c, groupnumber); | 332 | Group_c *g = get_group_c(g_c, groupnumber); |
333 | 333 | ||
@@ -383,7 +383,7 @@ static int connect_to_closest(Group_Chats *g_c, int groupnumber) | |||
383 | continue; | 383 | continue; |
384 | } | 384 | } |
385 | 385 | ||
386 | set_dht_temp_pk(g_c->fr_c, friendcon_id, g->closest_peers[i].temp_pk); | 386 | set_dht_temp_pk(g_c->fr_c, friendcon_id, g->closest_peers[i].temp_pk, userdata); |
387 | } | 387 | } |
388 | 388 | ||
389 | add_conn_to_groupchat(g_c, friendcon_id, groupnumber, 1, lock); | 389 | add_conn_to_groupchat(g_c, friendcon_id, groupnumber, 1, lock); |
@@ -647,7 +647,7 @@ static void set_conns_status_groups(Group_Chats *g_c, int friendcon_id, uint8_t | |||
647 | } | 647 | } |
648 | } | 648 | } |
649 | 649 | ||
650 | static int handle_status(void *object, int friendcon_id, uint8_t status) | 650 | static int handle_status(void *object, int friendcon_id, uint8_t status, void *userdata) |
651 | { | 651 | { |
652 | Group_Chats *g_c = object; | 652 | Group_Chats *g_c = object; |
653 | 653 | ||
@@ -661,7 +661,7 @@ static int handle_status(void *object, int friendcon_id, uint8_t status) | |||
661 | return 0; | 661 | return 0; |
662 | } | 662 | } |
663 | 663 | ||
664 | static int handle_packet(void *object, int friendcon_id, uint8_t *data, uint16_t length, void *userdata); | 664 | static int handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata); |
665 | static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length); | 665 | static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length); |
666 | 666 | ||
667 | /* Add friend to group chat. | 667 | /* Add friend to group chat. |
@@ -1465,7 +1465,7 @@ static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16 | |||
1465 | 1465 | ||
1466 | static unsigned int send_peer_kill(Group_Chats *g_c, int friendcon_id, uint16_t group_num); | 1466 | static unsigned int send_peer_kill(Group_Chats *g_c, int friendcon_id, uint16_t group_num); |
1467 | 1467 | ||
1468 | static int handle_packet_online(Group_Chats *g_c, int friendcon_id, uint8_t *data, uint16_t length) | 1468 | static int handle_packet_online(Group_Chats *g_c, int friendcon_id, const uint8_t *data, uint16_t length) |
1469 | { | 1469 | { |
1470 | if (length != ONLINE_PACKET_DATA_SIZE) { | 1470 | if (length != ONLINE_PACKET_DATA_SIZE) { |
1471 | return -1; | 1471 | return -1; |
@@ -2063,7 +2063,7 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const | |||
2063 | send_message_all_close(g_c, groupnumber, data, length, -1/*TODO close_index*/); | 2063 | send_message_all_close(g_c, groupnumber, data, length, -1/*TODO close_index*/); |
2064 | } | 2064 | } |
2065 | 2065 | ||
2066 | static int handle_packet(void *object, int friendcon_id, uint8_t *data, uint16_t length, void *userdata) | 2066 | static int handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata) |
2067 | { | 2067 | { |
2068 | Group_Chats *g_c = object; | 2068 | Group_Chats *g_c = object; |
2069 | 2069 | ||
@@ -2397,7 +2397,7 @@ Group_Chats *new_groupchats(Messenger *m) | |||
2397 | } | 2397 | } |
2398 | 2398 | ||
2399 | /* main groupchats loop. */ | 2399 | /* main groupchats loop. */ |
2400 | void do_groupchats(Group_Chats *g_c) | 2400 | void do_groupchats(Group_Chats *g_c, void *userdata) |
2401 | { | 2401 | { |
2402 | unsigned int i; | 2402 | unsigned int i; |
2403 | 2403 | ||
@@ -2409,7 +2409,7 @@ void do_groupchats(Group_Chats *g_c) | |||
2409 | } | 2409 | } |
2410 | 2410 | ||
2411 | if (g->status == GROUPCHAT_STATUS_CONNECTED) { | 2411 | if (g->status == GROUPCHAT_STATUS_CONNECTED) { |
2412 | connect_to_closest(g_c, i); | 2412 | connect_to_closest(g_c, i, userdata); |
2413 | ping_groupchat(g_c, i); | 2413 | ping_groupchat(g_c, i); |
2414 | groupchat_clear_timedout(g_c, i); | 2414 | groupchat_clear_timedout(g_c, i); |
2415 | } | 2415 | } |
diff --git a/toxcore/group.h b/toxcore/group.h index 8ae0e40e..56151402 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -372,7 +372,7 @@ int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function | |||
372 | Group_Chats *new_groupchats(Messenger *m); | 372 | Group_Chats *new_groupchats(Messenger *m); |
373 | 373 | ||
374 | /* main groupchats loop. */ | 374 | /* main groupchats loop. */ |
375 | void do_groupchats(Group_Chats *g_c); | 375 | void do_groupchats(Group_Chats *g_c, void *userdata); |
376 | 376 | ||
377 | /* Free everything related with group chats. */ | 377 | /* Free everything related with group chats. */ |
378 | void kill_groupchats(Group_Chats *g_c); | 378 | void kill_groupchats(Group_Chats *g_c); |
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 940feb04..0d8fabac 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -1297,7 +1297,7 @@ static int send_kill_packet(Net_Crypto *c, int crypt_connection_id) | |||
1297 | &kill_packet, sizeof(kill_packet)); | 1297 | &kill_packet, sizeof(kill_packet)); |
1298 | } | 1298 | } |
1299 | 1299 | ||
1300 | static void connection_kill(Net_Crypto *c, int crypt_connection_id) | 1300 | static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userdata) |
1301 | { | 1301 | { |
1302 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1302 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1303 | 1303 | ||
@@ -1306,7 +1306,8 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id) | |||
1306 | } | 1306 | } |
1307 | 1307 | ||
1308 | if (conn->connection_status_callback) { | 1308 | if (conn->connection_status_callback) { |
1309 | conn->connection_status_callback(conn->connection_status_callback_object, conn->connection_status_callback_id, 0); | 1309 | conn->connection_status_callback(conn->connection_status_callback_object, conn->connection_status_callback_id, 0, |
1310 | userdata); | ||
1310 | } | 1311 | } |
1311 | 1312 | ||
1312 | crypto_kill(c, crypt_connection_id); | 1313 | crypto_kill(c, crypt_connection_id); |
@@ -1370,7 +1371,7 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, con | |||
1370 | } | 1371 | } |
1371 | 1372 | ||
1372 | if (real_data[0] == PACKET_ID_KILL) { | 1373 | if (real_data[0] == PACKET_ID_KILL) { |
1373 | connection_kill(c, crypt_connection_id); | 1374 | connection_kill(c, crypt_connection_id, userdata); |
1374 | return 0; | 1375 | return 0; |
1375 | } | 1376 | } |
1376 | 1377 | ||
@@ -1379,7 +1380,8 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, con | |||
1379 | conn->status = CRYPTO_CONN_ESTABLISHED; | 1380 | conn->status = CRYPTO_CONN_ESTABLISHED; |
1380 | 1381 | ||
1381 | if (conn->connection_status_callback) { | 1382 | if (conn->connection_status_callback) { |
1382 | conn->connection_status_callback(conn->connection_status_callback_object, conn->connection_status_callback_id, 1); | 1383 | conn->connection_status_callback(conn->connection_status_callback_object, conn->connection_status_callback_id, 1, |
1384 | userdata); | ||
1383 | } | 1385 | } |
1384 | } | 1386 | } |
1385 | 1387 | ||
@@ -1525,7 +1527,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons | |||
1525 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; | 1527 | conn->status = CRYPTO_CONN_NOT_CONFIRMED; |
1526 | } else { | 1528 | } else { |
1527 | if (conn->dht_pk_callback) { | 1529 | if (conn->dht_pk_callback) { |
1528 | conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, dht_public_key); | 1530 | conn->dht_pk_callback(conn->dht_pk_callback_object, conn->dht_pk_callback_number, dht_public_key, userdata); |
1529 | } | 1531 | } |
1530 | } | 1532 | } |
1531 | } else { | 1533 | } else { |
@@ -1729,7 +1731,8 @@ void new_connection_handler(Net_Crypto *c, int (*new_connection_callback)(void * | |||
1729 | * return -1 on failure. | 1731 | * return -1 on failure. |
1730 | * return 0 on success. | 1732 | * return 0 on success. |
1731 | */ | 1733 | */ |
1732 | static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const uint8_t *data, uint16_t length) | 1734 | static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const uint8_t *data, uint16_t length, |
1735 | void *userdata) | ||
1733 | { | 1736 | { |
1734 | New_Connection n_c; | 1737 | New_Connection n_c; |
1735 | n_c.cookie = malloc(COOKIE_LENGTH); | 1738 | n_c.cookie = malloc(COOKIE_LENGTH); |
@@ -1753,7 +1756,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const | |||
1753 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1756 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1754 | 1757 | ||
1755 | if (public_key_cmp(n_c.dht_public_key, conn->dht_public_key) != 0) { | 1758 | if (public_key_cmp(n_c.dht_public_key, conn->dht_public_key) != 0) { |
1756 | connection_kill(c, crypt_connection_id); | 1759 | connection_kill(c, crypt_connection_id, userdata); |
1757 | } else { | 1760 | } else { |
1758 | int ret = -1; | 1761 | int ret = -1; |
1759 | 1762 | ||
@@ -1966,7 +1969,7 @@ static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t | |||
1966 | } | 1969 | } |
1967 | 1970 | ||
1968 | static int tcp_oob_callback(void *object, const uint8_t *public_key, unsigned int tcp_connections_number, | 1971 | static int tcp_oob_callback(void *object, const uint8_t *public_key, unsigned int tcp_connections_number, |
1969 | const uint8_t *data, uint16_t length) | 1972 | const uint8_t *data, uint16_t length, void *userdata) |
1970 | { | 1973 | { |
1971 | if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) { | 1974 | if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) { |
1972 | return -1; | 1975 | return -1; |
@@ -1984,7 +1987,7 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, unsigned in | |||
1984 | source.ip.family = TCP_FAMILY; | 1987 | source.ip.family = TCP_FAMILY; |
1985 | source.ip.ip6.uint32[0] = tcp_connections_number; | 1988 | source.ip.ip6.uint32[0] = tcp_connections_number; |
1986 | 1989 | ||
1987 | if (handle_new_connection_handshake(c, source, data, length) != 0) { | 1990 | if (handle_new_connection_handshake(c, source, data, length, userdata) != 0) { |
1988 | return -1; | 1991 | return -1; |
1989 | } | 1992 | } |
1990 | 1993 | ||
@@ -2119,7 +2122,7 @@ static void do_tcp(Net_Crypto *c, void *userdata) | |||
2119 | * return 0 on success. | 2122 | * return 0 on success. |
2120 | */ | 2123 | */ |
2121 | int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, | 2124 | int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, |
2122 | int (*connection_status_callback)(void *object, int id, uint8_t status), void *object, int id) | 2125 | int (*connection_status_callback)(void *object, int id, uint8_t status, void *userdata), void *object, int id) |
2123 | { | 2126 | { |
2124 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2127 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2125 | 2128 | ||
@@ -2191,7 +2194,7 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, | |||
2191 | * return 0 on success. | 2194 | * return 0 on success. |
2192 | */ | 2195 | */ |
2193 | int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, | 2196 | int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, |
2194 | const uint8_t *dht_public_key), void *object, uint32_t number) | 2197 | const uint8_t *dht_public_key, void *userdata), void *object, uint32_t number) |
2195 | { | 2198 | { |
2196 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 2199 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
2197 | 2200 | ||
@@ -2239,7 +2242,7 @@ static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet | |||
2239 | return 1; | 2242 | return 1; |
2240 | } | 2243 | } |
2241 | 2244 | ||
2242 | if (handle_new_connection_handshake(c, source, packet, length) != 0) { | 2245 | if (handle_new_connection_handshake(c, source, packet, length, userdata) != 0) { |
2243 | return 1; | 2246 | return 1; |
2244 | } | 2247 | } |
2245 | 2248 | ||
@@ -2822,7 +2825,7 @@ Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info) | |||
2822 | return temp; | 2825 | return temp; |
2823 | } | 2826 | } |
2824 | 2827 | ||
2825 | static void kill_timedout(Net_Crypto *c) | 2828 | static void kill_timedout(Net_Crypto *c, void *userdata) |
2826 | { | 2829 | { |
2827 | uint32_t i; | 2830 | uint32_t i; |
2828 | //uint64_t temp_time = current_time_monotonic(); | 2831 | //uint64_t temp_time = current_time_monotonic(); |
@@ -2844,7 +2847,7 @@ static void kill_timedout(Net_Crypto *c) | |||
2844 | continue; | 2847 | continue; |
2845 | } | 2848 | } |
2846 | 2849 | ||
2847 | connection_kill(c, i); | 2850 | connection_kill(c, i, userdata); |
2848 | } | 2851 | } |
2849 | 2852 | ||
2850 | #if 0 | 2853 | #if 0 |
@@ -2868,7 +2871,7 @@ uint32_t crypto_run_interval(const Net_Crypto *c) | |||
2868 | void do_net_crypto(Net_Crypto *c, void *userdata) | 2871 | void do_net_crypto(Net_Crypto *c, void *userdata) |
2869 | { | 2872 | { |
2870 | unix_time_update(); | 2873 | unix_time_update(); |
2871 | kill_timedout(c); | 2874 | kill_timedout(c, userdata); |
2872 | do_tcp(c, userdata); | 2875 | do_tcp(c, userdata); |
2873 | send_crypto_packets(c); | 2876 | send_crypto_packets(c); |
2874 | } | 2877 | } |
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index 52c6265e..c42463fc 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -131,7 +131,7 @@ typedef struct { | |||
131 | Packets_Array send_array; | 131 | Packets_Array send_array; |
132 | Packets_Array recv_array; | 132 | Packets_Array recv_array; |
133 | 133 | ||
134 | int (*connection_status_callback)(void *object, int id, uint8_t status); | 134 | int (*connection_status_callback)(void *object, int id, uint8_t status, void *userdata); |
135 | void *connection_status_callback_object; | 135 | void *connection_status_callback_object; |
136 | int connection_status_callback_id; | 136 | int connection_status_callback_id; |
137 | 137 | ||
@@ -174,7 +174,7 @@ typedef struct { | |||
174 | 174 | ||
175 | pthread_mutex_t mutex; | 175 | pthread_mutex_t mutex; |
176 | 176 | ||
177 | void (*dht_pk_callback)(void *data, int32_t number, const uint8_t *dht_public_key); | 177 | void (*dht_pk_callback)(void *data, int32_t number, const uint8_t *dht_public_key, void *userdata); |
178 | void *dht_pk_callback_object; | 178 | void *dht_pk_callback_object; |
179 | uint32_t dht_pk_callback_number; | 179 | uint32_t dht_pk_callback_number; |
180 | } Crypto_Connection; | 180 | } Crypto_Connection; |
@@ -264,7 +264,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, | |||
264 | * return 0 on success. | 264 | * return 0 on success. |
265 | */ | 265 | */ |
266 | int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, | 266 | int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, |
267 | int (*connection_status_callback)(void *object, int id, uint8_t status), void *object, int id); | 267 | int (*connection_status_callback)(void *object, int id, uint8_t status, void *userdata), void *object, int id); |
268 | 268 | ||
269 | /* Set function to be called when connection with crypt_connection_id receives a lossless data packet of length. | 269 | /* Set function to be called when connection with crypt_connection_id receives a lossless data packet of length. |
270 | * | 270 | * |
@@ -301,7 +301,7 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, | |||
301 | * return 0 on success. | 301 | * return 0 on success. |
302 | */ | 302 | */ |
303 | int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, | 303 | int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, |
304 | const uint8_t *dht_public_key), void *object, uint32_t number); | 304 | const uint8_t *dht_public_key, void *userdata), void *object, uint32_t number); |
305 | 305 | ||
306 | /* returns the number of packet slots left in the sendbuffer. | 306 | /* returns the number of packet slots left in the sendbuffer. |
307 | * return 0 if failure. | 307 | * return 0 if failure. |
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 851a0ee1..092198f2 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -758,12 +758,13 @@ static int handle_data_response(void *object, IP_Port source, const uint8_t *pac | |||
758 | } | 758 | } |
759 | 759 | ||
760 | return onion_c->Onion_Data_Handlers[plain[0]].function(onion_c->Onion_Data_Handlers[plain[0]].object, temp_plain, plain, | 760 | return onion_c->Onion_Data_Handlers[plain[0]].function(onion_c->Onion_Data_Handlers[plain[0]].object, temp_plain, plain, |
761 | sizeof(plain)); | 761 | sizeof(plain), userdata); |
762 | } | 762 | } |
763 | 763 | ||
764 | #define DHTPK_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES) | 764 | #define DHTPK_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES) |
765 | #define DHTPK_DATA_MAX_LENGTH (DHTPK_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES) | 765 | #define DHTPK_DATA_MAX_LENGTH (DHTPK_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES) |
766 | static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length) | 766 | static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length, |
767 | void *userdata) | ||
767 | { | 768 | { |
768 | Onion_Client *onion_c = object; | 769 | Onion_Client *onion_c = object; |
769 | 770 | ||
@@ -793,7 +794,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con | |||
793 | 794 | ||
794 | if (onion_c->friends_list[friend_num].dht_pk_callback) { | 795 | if (onion_c->friends_list[friend_num].dht_pk_callback) { |
795 | onion_c->friends_list[friend_num].dht_pk_callback(onion_c->friends_list[friend_num].dht_pk_callback_object, | 796 | onion_c->friends_list[friend_num].dht_pk_callback(onion_c->friends_list[friend_num].dht_pk_callback_object, |
796 | onion_c->friends_list[friend_num].dht_pk_callback_number, data + 1 + sizeof(uint64_t)); | 797 | onion_c->friends_list[friend_num].dht_pk_callback_number, data + 1 + sizeof(uint64_t), userdata); |
797 | } | 798 | } |
798 | 799 | ||
799 | onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t)); | 800 | onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t)); |
@@ -971,7 +972,7 @@ static int send_dht_dhtpk(const Onion_Client *onion_c, int friend_num, const uin | |||
971 | } | 972 | } |
972 | 973 | ||
973 | static int handle_dht_dhtpk(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, | 974 | static int handle_dht_dhtpk(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, |
974 | uint16_t length) | 975 | uint16_t length, void *userdata) |
975 | { | 976 | { |
976 | Onion_Client *onion_c = object; | 977 | Onion_Client *onion_c = object; |
977 | 978 | ||
@@ -996,7 +997,7 @@ static int handle_dht_dhtpk(void *object, IP_Port source, const uint8_t *source_ | |||
996 | return 1; | 997 | return 1; |
997 | } | 998 | } |
998 | 999 | ||
999 | return handle_dhtpk_announce(onion_c, packet, plain, len); | 1000 | return handle_dhtpk_announce(onion_c, packet, plain, len, userdata); |
1000 | } | 1001 | } |
1001 | /* Send the packets to tell our friends what our DHT public key is. | 1002 | /* Send the packets to tell our friends what our DHT public key is. |
1002 | * | 1003 | * |
@@ -1199,7 +1200,7 @@ int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_rela | |||
1199 | * return 0 on success. | 1200 | * return 0 on success. |
1200 | */ | 1201 | */ |
1201 | int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function)(void *data, int32_t number, | 1202 | int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function)(void *data, int32_t number, |
1202 | const uint8_t *dht_public_key), void *object, uint32_t number) | 1203 | const uint8_t *dht_public_key, void *userdata), void *object, uint32_t number) |
1203 | { | 1204 | { |
1204 | if ((uint32_t)friend_num >= onion_c->num_friends) { | 1205 | if ((uint32_t)friend_num >= onion_c->num_friends) { |
1205 | return -1; | 1206 | return -1; |
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index cdf2c16f..9c37c66f 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h | |||
@@ -114,7 +114,7 @@ typedef struct { | |||
114 | void *tcp_relay_node_callback_object; | 114 | void *tcp_relay_node_callback_object; |
115 | uint32_t tcp_relay_node_callback_number; | 115 | uint32_t tcp_relay_node_callback_number; |
116 | 116 | ||
117 | void (*dht_pk_callback)(void *data, int32_t number, const uint8_t *dht_public_key); | 117 | void (*dht_pk_callback)(void *data, int32_t number, const uint8_t *dht_public_key, void *userdata); |
118 | void *dht_pk_callback_object; | 118 | void *dht_pk_callback_object; |
119 | uint32_t dht_pk_callback_number; | 119 | uint32_t dht_pk_callback_number; |
120 | 120 | ||
@@ -122,7 +122,7 @@ typedef struct { | |||
122 | } Onion_Friend; | 122 | } Onion_Friend; |
123 | 123 | ||
124 | typedef int (*oniondata_handler_callback)(void *object, const uint8_t *source_pubkey, const uint8_t *data, | 124 | typedef int (*oniondata_handler_callback)(void *object, const uint8_t *source_pubkey, const uint8_t *data, |
125 | uint16_t len); | 125 | uint16_t len, void *userdata); |
126 | 126 | ||
127 | typedef struct { | 127 | typedef struct { |
128 | DHT *dht; | 128 | DHT *dht; |
@@ -239,7 +239,7 @@ int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_rela | |||
239 | * return 0 on success. | 239 | * return 0 on success. |
240 | */ | 240 | */ |
241 | int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function)(void *data, int32_t number, | 241 | int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function)(void *data, int32_t number, |
242 | const uint8_t *dht_public_key), void *object, uint32_t number); | 242 | const uint8_t *dht_public_key, void *userdata), void *object, uint32_t number); |
243 | 243 | ||
244 | /* Set a friends DHT public key. | 244 | /* Set a friends DHT public key. |
245 | * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to | 245 | * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 40bfaf70..26fa0de4 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -476,7 +476,7 @@ void tox_iterate(Tox *tox, void *user_data) | |||
476 | { | 476 | { |
477 | Messenger *m = tox; | 477 | Messenger *m = tox; |
478 | do_messenger(m, user_data); | 478 | do_messenger(m, user_data); |
479 | do_groupchats(m->group_chat_object); | 479 | do_groupchats(m->group_chat_object, user_data); |
480 | } | 480 | } |
481 | 481 | ||
482 | void tox_self_get_address(const Tox *tox, uint8_t *address) | 482 | void tox_self_get_address(const Tox *tox, uint8_t *address) |
@@ -963,10 +963,10 @@ void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *call | |||
963 | m_callback_read_receipt(m, callback); | 963 | m_callback_read_receipt(m, callback); |
964 | } | 964 | } |
965 | 965 | ||
966 | void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback, void *user_data) | 966 | void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback) |
967 | { | 967 | { |
968 | Messenger *m = tox; | 968 | Messenger *m = tox; |
969 | m_callback_friendrequest(m, callback, user_data); | 969 | m_callback_friendrequest(m, callback); |
970 | } | 970 | } |
971 | 971 | ||
972 | void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback) | 972 | void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback) |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 5d528e16..3747e228 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -1709,7 +1709,7 @@ typedef void tox_friend_request_cb(Tox *tox, const uint8_t *public_key, const ui | |||
1709 | * | 1709 | * |
1710 | * This event is triggered when a friend request is received. | 1710 | * This event is triggered when a friend request is received. |
1711 | */ | 1711 | */ |
1712 | void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback, void *user_data); | 1712 | void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback); |
1713 | 1713 | ||
1714 | /** | 1714 | /** |
1715 | * @param friend_number The friend number of the friend who sent the message. | 1715 | * @param friend_number The friend number of the friend who sent the message. |