From aad1e0ad3f96786e0fb10d8dd144e5e6ebe93258 Mon Sep 17 00:00:00 2001 From: "Gregory Mullen (grayhatter)" Date: Mon, 22 Aug 2016 14:44:58 -0700 Subject: 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. --- auto_tests/TCP_test.c | 2 +- auto_tests/encryptsave_test.c | 2 +- auto_tests/onion_test.c | 2 +- auto_tests/tox_test.c | 18 +++++++++--------- auto_tests/toxav_basic_test.c | 2 +- auto_tests/toxav_many_test.c | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) (limited to 'auto_tests') 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 _Bool tcp_oobdata_callback_called; static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigned int id, const uint8_t *data, - uint16_t length) + uint16_t length, void *userdata) { if (length != 6) { 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) Tox *tox2 = tox_new(0, 0); ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); uint32_t to_compare = 974536; - tox_callback_friend_request(tox2, accept_friend_request, &to_compare); + tox_callback_friend_request(tox2, accept_friend_request); uint8_t address[TOX_ADDRESS_SIZE]; tox_self_get_address(tox2, address); 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; uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES]; uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES]; -static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key) +static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) { if ((NUM_FIRST == number && !first) || (NUM_LAST == number && !last)) { 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) uint32_t to_compare = 974536; connected_t1 = 0; tox_callback_self_connection_status(tox1, tox_connection_status); - tox_callback_friend_request(tox2, accept_friend_request, &to_compare); + tox_callback_friend_request(tox2, accept_friend_request); uint8_t address[TOX_ADDRESS_SIZE]; tox_self_get_address(tox2, address); uint32_t test = tox_friend_add(tox3, address, (uint8_t *)"Gentoo", 7, 0); @@ -849,7 +849,7 @@ START_TEST(test_many_clients) for (i = 0; i < NUM_TOXES; ++i) { toxes[i] = tox_new(0, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); - tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); + tox_callback_friend_request(toxes[i], accept_friend_request); } { @@ -918,7 +918,7 @@ loop_top: } for (i = 0; i < NUM_TOXES; ++i) { - tox_iterate(toxes[i], NULL); + tox_iterate(toxes[i], &to_comp); } c_sleep(50); @@ -954,7 +954,7 @@ START_TEST(test_many_clients_tcp) toxes[i] = tox_new(&opts, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); - tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); + tox_callback_friend_request(toxes[i], accept_friend_request); uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; tox_self_get_dht_id(toxes[0], dpk); TOX_ERR_BOOTSTRAP error = 0; @@ -1018,7 +1018,7 @@ loop_top: } for (i = 0; i < NUM_TOXES_TCP; ++i) { - tox_iterate(toxes[i], NULL); + tox_iterate(toxes[i], &to_comp); } c_sleep(50); @@ -1053,7 +1053,7 @@ START_TEST(test_many_clients_tcp_b) toxes[i] = tox_new(&opts, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); - tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); + tox_callback_friend_request(toxes[i], accept_friend_request); uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; tox_self_get_dht_id(toxes[(i % NUM_TCP_RELAYS)], dpk); 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: } for (i = 0; i < NUM_TOXES_TCP; ++i) { - tox_iterate(toxes[i], NULL); + tox_iterate(toxes[i], &to_comp); } c_sleep(30); @@ -1200,7 +1200,7 @@ group_test_restart: for (i = 0; i < NUM_GROUP_TOX; ++i) { toxes[i] = tox_new(0, 0); ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); - tox_callback_friend_request(toxes[i], &g_accept_friend_request, &to_comp); + tox_callback_friend_request(toxes[i], &g_accept_friend_request); tox_callback_group_invite(toxes[i], &print_group_invite_callback, &to_comp); } @@ -1231,7 +1231,7 @@ group_test_restart: } for (i = 0; i < NUM_GROUP_TOX; ++i) { - tox_iterate(toxes[i], NULL); + tox_iterate(toxes[i], &to_comp); } 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) uint32_t to_compare = 974536; uint8_t address[TOX_ADDRESS_SIZE]; - tox_callback_friend_request(Alice, t_accept_friend_request_cb, &to_compare); + tox_callback_friend_request(Alice, t_accept_friend_request_cb); tox_self_get_address(Alice, address); 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) uint32_t to_compare = 974536; uint8_t address[TOX_ADDRESS_SIZE]; - tox_callback_friend_request(Alice, t_accept_friend_request_cb, &to_compare); + tox_callback_friend_request(Alice, t_accept_friend_request_cb); tox_self_get_address(Alice, address); -- cgit v1.2.3