diff --git a/.restyled.yaml b/.restyled.yaml index b538c72a06..b53f949019 100644 --- a/.restyled.yaml +++ b/.restyled.yaml @@ -5,6 +5,7 @@ exclude: restylers: - astyle: + image: restyled/restyler-astyle:d7967bcb8b622a98524b7df1da1b02652114cf9a arguments: ["--options=other/astyle/astylerc"] include: - "**/*.c" @@ -12,7 +13,7 @@ restylers: - autopep8 - black - clang-format: - image: restyled/restyler-clang-format:13.0.1 + image: restyled/restyler-clang-format:v16.0.6 include: - "**/*.cc" - "**/*.hh" diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index cb1761846e..45309d0941 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c @@ -655,7 +655,7 @@ static void test_client_invalid(void) ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]); ip_port_tcp_s.ip = get_loopback(); TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, - self_public_key, f_public_key, f_secret_key, nullptr); + self_public_key, f_public_key, f_secret_key, nullptr); // Run the client's main loop but not the server. mono_time_update(mono_time); @@ -709,7 +709,6 @@ static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t return 0; } - static void test_tcp_connection(void) { const Random *rng = os_random(); diff --git a/auto_tests/announce_test.c b/auto_tests/announce_test.c index 5606d59104..c4f080de4e 100644 --- a/auto_tests/announce_test.c +++ b/auto_tests/announce_test.c @@ -120,7 +120,6 @@ static void basic_announce_tests(void) test_store_data(); } - int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/auto_test_support.c b/auto_tests/auto_test_support.c index 6c3a4cfc49..bdaf592689 100644 --- a/auto_tests/auto_test_support.c +++ b/auto_tests/auto_test_support.c @@ -444,7 +444,6 @@ void print_debug_log(Tox *m, Tox_Log_Level level, const char *file, uint32_t lin } } - void print_debug_logger(void *context, Logger_Level level, const char *file, int line, const char *func, const char *message, void *userdata) { print_debug_log(nullptr, (Tox_Log_Level) level, file, (uint32_t) line, func, message, userdata); diff --git a/auto_tests/auto_test_support.h b/auto_tests/auto_test_support.h index f506d9b2cb..b9132e16bc 100644 --- a/auto_tests/auto_test_support.h +++ b/auto_tests/auto_test_support.h @@ -61,7 +61,7 @@ void print_debug_log(Tox *m, Tox_Log_Level level, const char *file, uint32_t lin // Use this function when setting the log callback on a Logger object void print_debug_logger(void *context, Logger_Level level, const char *file, int line, - const char *func, const char *message, void *userdata); + const char *func, const char *message, void *userdata); Tox *tox_new_log(struct Tox_Options *options, Tox_Err_New *err, void *log_user_data); Tox *tox_new_log_lan(struct Tox_Options *options, Tox_Err_New *err, void *log_user_data, bool lan_discovery); diff --git a/auto_tests/conference_av_test.c b/auto_tests/conference_av_test.c index e8c976aeb2..ac6f1e3db3 100644 --- a/auto_tests/conference_av_test.c +++ b/auto_tests/conference_av_test.c @@ -426,7 +426,6 @@ static void test_groupav(AutoTox *autotoxes) ck_assert_msg(tox_conference_invite(autotoxes[0].tox, 0, 0, nullptr) != 0, "failed to invite friend"); ((State *)autotoxes[0].state)->invited_next = true; - printf("waiting for invitations to be made\n"); uint32_t invited_count = 0; diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c index a300bfc1ff..0ecca27040 100644 --- a/auto_tests/conference_test.c +++ b/auto_tests/conference_test.c @@ -174,7 +174,6 @@ static bool names_propagated(uint32_t tox_count, AutoTox *autotoxes) return true; } - /** * returns a random index at which a list of booleans is false * (some such index is required to exist) @@ -357,7 +356,6 @@ static void test_many_group(AutoTox *autotoxes) nullptr) != 0, "failed to set group title"); - printf("waiting for invitations to be made\n"); uint32_t invited_count = 0; diff --git a/auto_tests/dht_getnodes_api_test.c b/auto_tests/dht_getnodes_api_test.c index 0405750022..7b5ce3db74 100644 --- a/auto_tests/dht_getnodes_api_test.c +++ b/auto_tests/dht_getnodes_api_test.c @@ -128,10 +128,9 @@ static void test_dht_getnodes(AutoTox *autotoxes) tox_events_callback_dht_get_nodes_response(autotoxes[i].dispatch, getnodes_response_cb); printf("Peer %zu dht closenode count total/announce-capable: %d/%d\n", - i, - tox_dht_get_num_closelist(autotoxes[i].tox), - tox_dht_get_num_closelist_announce_capable(autotoxes[i].tox) - ); + i, + tox_dht_get_num_closelist(autotoxes[i].tox), + tox_dht_get_num_closelist_announce_capable(autotoxes[i].tox)); } while (!all_nodes_crawled(autotoxes, NUM_TOXES, public_key_list)) { diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index bde30eecae..e433e410a8 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c @@ -184,7 +184,6 @@ static void test_keys(void) free(in_plaintext2a); free(out_plaintext2a); - uint8_t encrypted2[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; ret = tox_pass_encrypt(string, 44, key_char, 12, encrypted2, &encerr); ck_assert_msg(ret, "generic failure 3: %d", encerr); diff --git a/auto_tests/file_streaming_test.c b/auto_tests/file_streaming_test.c index 3f82dbc376..fa4f210ab7 100644 --- a/auto_tests/file_streaming_test.c +++ b/auto_tests/file_streaming_test.c @@ -126,7 +126,6 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi Tox_Err_File_Send_Chunk error; tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error); - ck_assert_msg(error == TOX_ERR_FILE_SEND_CHUNK_OK, "could not send chunk, error num=%d pos=%d len=%d", (int)error, (int)position, (int)length); @@ -134,7 +133,6 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi sending_pos += length; } - static uint8_t num; static bool file_recv; static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, @@ -225,8 +223,8 @@ static void file_transfer_test(void) tox_callback_file_recv(tox3, tox_file_receive); const uint64_t totalf_size = UINT64_MAX; Tox_File_Number fnum = tox_file_send( - tox2, 0, TOX_FILE_KIND_DATA, totalf_size, nullptr, - (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), nullptr); + tox2, 0, TOX_FILE_KIND_DATA, totalf_size, nullptr, + (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), nullptr); ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); Tox_Err_File_Get gfierr; diff --git a/auto_tests/file_transfer_test.c b/auto_tests/file_transfer_test.c index bee68656cc..aacd0b1037 100644 --- a/auto_tests/file_transfer_test.c +++ b/auto_tests/file_transfer_test.c @@ -150,7 +150,6 @@ static void tox_file_chunk_request(Tox *tox, const Tox_Event_File_Chunk_Request sending_pos += length; } - static uint8_t num; static bool file_recv; static void write_file(Tox *tox, const Tox_Event_File_Recv_Chunk *event, void *user_data) diff --git a/auto_tests/forwarding_test.c b/auto_tests/forwarding_test.c index aae6c30bf3..75e330a73e 100644 --- a/auto_tests/forwarding_test.c +++ b/auto_tests/forwarding_test.c @@ -317,7 +317,6 @@ static void test_forwarding(void) } } - for (uint32_t i = 0; i < NUM_FORWARDER; ++i) { kill_forwarding_subtox(mem, subtoxes[i]); } @@ -325,7 +324,6 @@ static void test_forwarding(void) tox_kill(relay); } - int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/group_general_test.c b/auto_tests/group_general_test.c index 912261e997..292b8d534a 100644 --- a/auto_tests/group_general_test.c +++ b/auto_tests/group_general_test.c @@ -448,7 +448,6 @@ static void group_announce_test(AutoTox *autotoxes) iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); } - printf("All tests passed!\n"); } diff --git a/auto_tests/group_message_test.c b/auto_tests/group_message_test.c index 062d5ef87b..39da2c4893 100644 --- a/auto_tests/group_message_test.c +++ b/auto_tests/group_message_test.c @@ -425,8 +425,8 @@ static void group_message_test(AutoTox *autotoxes) if (state1->peer_joined && !state1->message_sent) { state1->pseudo_msg_id = tox_group_send_message( - tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE, - TEST_MESSAGE_LEN, &err_send); + tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE, + TEST_MESSAGE_LEN, &err_send); ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK); state1->message_sent = true; } diff --git a/auto_tests/group_moderation_test.c b/auto_tests/group_moderation_test.c index 0c6361c1ee..7cb6d36a86 100644 --- a/auto_tests/group_moderation_test.c +++ b/auto_tests/group_moderation_test.c @@ -38,7 +38,6 @@ typedef struct State { char mod_name1[TOX_MAX_NAME_LENGTH]; char mod_name2[TOX_MAX_NAME_LENGTH]; - bool observer_check; size_t observer_event_count; char observer_name1[TOX_MAX_NAME_LENGTH]; diff --git a/auto_tests/group_save_test.c b/auto_tests/group_save_test.c index e5456d96d3..417c0d0b0b 100644 --- a/auto_tests/group_save_test.c +++ b/auto_tests/group_save_test.c @@ -181,7 +181,6 @@ static void group_save_test(AutoTox *autotoxes) tox_group_self_get_public_key(tox0, group_number, founder_pk, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); - Tox_Err_Group_Invite_Friend err_invite; tox_group_invite_friend(tox0, group_number, 0, &err_invite); diff --git a/auto_tests/group_tcp_test.c b/auto_tests/group_tcp_test.c index 66b435b171..919c604616 100644 --- a/auto_tests/group_tcp_test.c +++ b/auto_tests/group_tcp_test.c @@ -178,7 +178,6 @@ static void group_tcp_test(AutoTox *autotoxes) printf("%d peers successfully joined. Waiting for code...\n", NUM_GROUP_TOXES); printf("Tox 0 sending secret code to all peers\n"); - for (size_t i = 0; i < NUM_GROUP_TOXES - 1; ++i) { Tox_Err_Group_Send_Private_Message perr; diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index dc78f3885f..3a81df41b8 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -118,7 +118,6 @@ static int handle_test_3(void *object, const IP_Port *source, const uint8_t *pac return 1; } - if (memcmp(packet + 1, sb_data, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH) != 0) { return 1; } @@ -154,7 +153,6 @@ static int handle_test_3_old(void *object, const IP_Port *source, const uint8_t return 1; } - if (memcmp(packet + 1, sb_data, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH) != 0) { return 1; } diff --git a/auto_tests/proxy_test.c b/auto_tests/proxy_test.c index d6f2d8cff1..d20c14f237 100644 --- a/auto_tests/proxy_test.c +++ b/auto_tests/proxy_test.c @@ -24,10 +24,10 @@ static bool try_bootstrap(Tox *tox1, Tox *tox2, Tox *tox3, Tox *tox4) tox_self_get_connection_status(tox3) != TOX_CONNECTION_NONE && tox_self_get_connection_status(tox4) != TOX_CONNECTION_NONE) { printf("%d %d %d %d\n", - tox_self_get_connection_status(tox1), - tox_self_get_connection_status(tox2), - tox_self_get_connection_status(tox3), - tox_self_get_connection_status(tox4)); + tox_self_get_connection_status(tox1), + tox_self_get_connection_status(tox2), + tox_self_get_connection_status(tox3), + tox_self_get_connection_status(tox4)); return true; } @@ -38,10 +38,10 @@ static bool try_bootstrap(Tox *tox1, Tox *tox2, Tox *tox3, Tox *tox4) if (i % 10 == 0) { printf("%d %d %d %d\n", - tox_self_get_connection_status(tox1), - tox_self_get_connection_status(tox2), - tox_self_get_connection_status(tox3), - tox_self_get_connection_status(tox4)); + tox_self_get_connection_status(tox1), + tox_self_get_connection_status(tox2), + tox_self_get_connection_status(tox3), + tox_self_get_connection_status(tox4)); } c_sleep(tox_iteration_interval(tox1)); diff --git a/auto_tests/save_friend_test.c b/auto_tests/save_friend_test.c index b505703b4b..94e70e01f6 100644 --- a/auto_tests/save_friend_test.c +++ b/auto_tests/save_friend_test.c @@ -75,7 +75,7 @@ int main(void) ck_assert(tox2 != nullptr); tox_events_init(tox1); - Tox_Dispatch* dispatch1 = tox_dispatch_new(nullptr); + Tox_Dispatch *dispatch1 = tox_dispatch_new(nullptr); ck_assert(dispatch1 != nullptr); printf("bootstrapping tox2 off tox1\n"); diff --git a/auto_tests/save_load_test.c b/auto_tests/save_load_test.c index 96901ddcbf..b7f9bdff03 100644 --- a/auto_tests/save_load_test.c +++ b/auto_tests/save_load_test.c @@ -154,7 +154,7 @@ static void test_few_clients(void) ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error); tox_options_free(opts1); tox_events_init(tox1); - Tox_Dispatch* dispatch1 = tox_dispatch_new(nullptr); + Tox_Dispatch *dispatch1 = tox_dispatch_new(nullptr); ck_assert(dispatch1 != nullptr); struct Tox_Options *opts2 = tox_options_new(nullptr); @@ -164,7 +164,7 @@ static void test_few_clients(void) Tox *tox2 = tox_new_log(opts2, &t_n_error, &index[1]); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error); tox_events_init(tox2); - Tox_Dispatch* dispatch2 = tox_dispatch_new(nullptr); + Tox_Dispatch *dispatch2 = tox_dispatch_new(nullptr); ck_assert(dispatch2 != nullptr); struct Tox_Options *opts3 = tox_options_new(nullptr); @@ -175,7 +175,6 @@ static void test_few_clients(void) ck_assert_msg(tox1 && tox2 && tox3, "Failed to create 3 tox instances"); - Time_Data time_data; ck_assert_msg(pthread_mutex_init(&time_data.lock, nullptr) == 0, "Failed to init time_data mutex"); time_data.clock = current_time_monotonic(tox1->mono_time); diff --git a/auto_tests/set_name_test.c b/auto_tests/set_name_test.c index e180227877..b5608ba85b 100644 --- a/auto_tests/set_name_test.c +++ b/auto_tests/set_name_test.c @@ -18,7 +18,7 @@ static void nickchange_callback(Tox *tox, const Tox_Event_Friend_Name *event, void *user_data) { //const uint32_t friend_number = tox_event_friend_name_get_friend_number(event); - const uint8_t* name = tox_event_friend_name_get_name(event); + const uint8_t *name = tox_event_friend_name_get_name(event); const uint32_t name_length = tox_event_friend_name_get_name_length(event); ck_assert_msg(name_length == sizeof(NICKNAME), "Name length not correct: %d != %d", (uint16_t)name_length, diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c index e6ff6582ca..4822a6a765 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c @@ -269,7 +269,6 @@ static void test_many_clients_tcp_b(void) printf("test_many_clients_tcp_b succeeded, took %llu seconds\n", time(nullptr) - cur_time); } - static void tox_suite(void) { /* Each tox connects to a single tox TCP */ diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c index 77c6c98a5c..491e4583c2 100644 --- a/auto_tests/tox_many_test.c +++ b/auto_tests/tox_many_test.c @@ -24,7 +24,6 @@ static void accept_friend_request(Tox *m, const Tox_Event_Friend_Request *event, } } - #define TCP_TEST_NUM_TOXES 90 #define TCP_TEST_NUM_FRIENDS 50 diff --git a/auto_tests/tox_new_test.c b/auto_tests/tox_new_test.c index 99d1935b97..9aaeb191eb 100644 --- a/auto_tests/tox_new_test.c +++ b/auto_tests/tox_new_test.c @@ -2,7 +2,8 @@ #include "../toxcore/ccompat.h" -int main(void) { +int main(void) +{ tox_kill(tox_new(nullptr, nullptr)); return 0; } diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index cdf043232c..541b254f84 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -23,7 +23,6 @@ #define TEST_STOP_RESUME_PAYLOAD 1 #define TEST_PAUSE_RESUME_SEND 1 - #define ck_assert_call_control(a, b, c) do { \ Toxav_Err_Call_Control cc_err; \ bool ok = toxav_call_control(a, b, c, &cc_err); \ @@ -34,7 +33,6 @@ ck_assert(cc_err == TOXAV_ERR_CALL_CONTROL_OK); \ } while (0) - typedef struct { bool incoming; uint32_t state; @@ -46,7 +44,6 @@ static void clear_call_control(CallControl *cc) *cc = empty; } - /** * Callbacks */ @@ -89,7 +86,6 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const } } - /** * Iterate helper */ @@ -207,7 +203,6 @@ static void test_av_flows(void) c_sleep(20); } - { Toxav_Err_New error; alice_av = toxav_new(alice, &error); diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index b1f2f9fa94..2892f7245c 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -74,7 +74,6 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const } } - /** * Iterate helper */ @@ -299,7 +298,6 @@ static void test_av_three_calls(void) } } - do { tox_iterate(bootstrap, nullptr); tox_iterate(alice, nullptr); diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index b3dc942a82..8a15fb5e00 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -50,7 +50,6 @@ static const char *motd_str = ""; //Change this to anything within 256 bytes(but #define PORT 33445 - static bool manage_keys(DHT *dht) { enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE }; @@ -126,7 +125,7 @@ static void print_log(void *context, Logger_Level level, const char *file, int l int main(int argc, char *argv[]) { - if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) { + if (argc == 2 && tox_strncasecmp(argv[1], "-h", 3) == 0) { printf("Usage (connected) : %s [--ipv4|--ipv6] IP PORT KEY\n", argv[0]); printf("Usage (unconnected): %s [--ipv4|--ipv6]\n", argv[0]); return 0; @@ -165,10 +164,10 @@ int main(int argc, char *argv[]) Onion_Announce *onion_a = new_onion_announce(logger, mem, rng, mono_time, dht); #ifdef DHT_NODE_EXTRA_PACKETS - bootstrap_set_callbacks(dht_get_net(dht), (uint32_t)DAEMON_VERSION_NUMBER, (const uint8_t *) motd_str, strlen(motd_str)+1); + bootstrap_set_callbacks(dht_get_net(dht), (uint32_t)DAEMON_VERSION_NUMBER, (const uint8_t *) motd_str, strlen(motd_str) + 1); #endif - if (!(onion && forwarding && onion_a)) { + if (onion == nullptr || forwarding == nullptr || onion_a == nullptr) { printf("Something failed to initialize.\n"); // cppcheck-suppress resourceLeak return 1; @@ -230,8 +229,8 @@ int main(int argc, char *argv[]) const uint16_t port = net_htons((uint16_t)port_conv); uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]); - int res = dht_bootstrap_from_address(dht, argv[argvoffset + 1], - ipv6enabled, port, bootstrap_key); + const bool res = dht_bootstrap_from_address(dht, argv[argvoffset + 1], + ipv6enabled, port, bootstrap_key); free(bootstrap_key); if (!res) { @@ -240,17 +239,17 @@ int main(int argc, char *argv[]) } } - int is_waiting_for_dht_connection = 1; + bool is_waiting_for_dht_connection = true; uint64_t last_lan_discovery = 0; const Broadcast_Info *broadcast = lan_discovery_init(ns); - while (1) { + while (true) { mono_time_update(mono_time); if (is_waiting_for_dht_connection && dht_isconnected(dht)) { printf("Connected to other bootstrap node successfully.\n"); - is_waiting_for_dht_connection = 0; + is_waiting_for_dht_connection = false; } do_dht(dht); diff --git a/other/astyle/astylerc b/other/astyle/astylerc index 9554a3e558..71cf762b27 100644 --- a/other/astyle/astylerc +++ b/other/astyle/astylerc @@ -1,5 +1,6 @@ # Bracket Style Options --style=kr +--attach-namespaces # Tab Options --indent=spaces=4 @@ -9,15 +10,19 @@ # Padding Options --pad-header ---break-blocks --pad-oper +#--unpad-brackets --unpad-paren --align-pointer=name --align-reference=name +#--squeeze-lines=1 +#--squeeze-ws # Formatting Options +--add-braces --convert-tabs ---max-code-length=120 +--max-code-length=200 +--attach-return-type # Other Options --preserve-date diff --git a/other/astyle/format-source b/other/astyle/format-source index cb8b8febda..3118b885b5 100755 --- a/other/astyle/format-source +++ b/other/astyle/format-source @@ -2,36 +2,6 @@ set -ex -SOURCE_DIR="$1" -ASTYLE="$2" - -# Go to the source root. -if [ -z "$SOURCE_DIR" ]; then - SOURCE_DIR=. -fi -cd "$SOURCE_DIR" - -if [ -z "$ASTYLE" ] || ! which "$ASTYLE"; then - ASTYLE=astyle -fi - -if ! which "$ASTYLE"; then - # If we couldn't find or install an astyle binary, don't do anything. - echo "Could not find an astyle binary; please install astyle." - exit 1 -fi - -readarray -t CC_SOURCES <<<"$(find . '(' -name '*.cc' ')')" -CC_SOURCES+=(toxcore/crypto_core.c) -CC_SOURCES+=(toxcore/ping_array.c) - -for bin in clang-format-11 clang-format-7 clang-format-6.0 clang-format-5.0 clang-format; do - if which "$bin"; then - "$bin" -i -style='{BasedOnStyle: Google, ColumnLimit: 100}' "${CC_SOURCES[@]}" - break - fi -done - FIND="find ." FIND="$FIND '(' -name '*.[ch]' ')'" FIND="$FIND -and -not -name '*.api.h'" @@ -40,7 +10,15 @@ FIND="$FIND -and -not -wholename './third_party/*'" FIND="$FIND -and -not -wholename './toxencryptsave/crypto_pwhash*'" readarray -t C_SOURCES <<<"$(eval "$FIND")" +readarray -t CC_SOURCES <<<"$(find . '(' -name '*.cc' -or -name '*.hh' ')')" +#CC_SOURCES+=(toxcore/crypto_core.c) +#CC_SOURCES+=(toxcore/ping_array.c) + +# Format C++ sources with clang-format. +clang-format -i "${CC_SOURCES[@]}" -"$ASTYLE" -n --options=other/astyle/astylerc "${C_SOURCES[@]}" +# Format C sources with astyle. We can't use clang-format, because it strongly +# messes up formatting of non_null annotations. +astyle -n --options=other/astyle/astylerc "${C_SOURCES[@]}" git diff --color=always --exit-code diff --git a/other/bootstrap_daemon/src/command_line_arguments.c b/other/bootstrap_daemon/src/command_line_arguments.c index a2e696c3f6..3b798efbee 100644 --- a/other/bootstrap_daemon/src/command_line_arguments.c +++ b/other/bootstrap_daemon/src/command_line_arguments.c @@ -18,7 +18,6 @@ #include - /** * Prints --help message */ @@ -48,8 +47,8 @@ static void print_help(void) } Cli_Status handle_command_line_arguments( - int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend, - bool *run_in_foreground) + int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend, + bool *run_in_foreground) { if (argc < 2) { log_write(LOG_LEVEL_ERROR, "Error: No arguments provided.\n\n"); diff --git a/other/bootstrap_daemon/src/command_line_arguments.h b/other/bootstrap_daemon/src/command_line_arguments.h index 3595ece3a9..3be39530a6 100644 --- a/other/bootstrap_daemon/src/command_line_arguments.h +++ b/other/bootstrap_daemon/src/command_line_arguments.h @@ -32,7 +32,7 @@ typedef enum Cli_Status { * @param run_in_foreground Sets to the provided by the user foreground option. */ Cli_Status handle_command_line_arguments( - int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend, - bool *run_in_foreground); + int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend, + bool *run_in_foreground); #endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_COMMAND_LINE_ARGUMENTS_H diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index 01aa488c92..cfa96e55a5 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c @@ -50,7 +50,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por // NOLINTNEXTLINE, clang-tidy: error: suspicious comparison of 'sizeof(expr)' to a constant [bugprone-sizeof-expression,-warnings-as-errors] static_assert(sizeof(default_ports) > 0, "At least one default TCP relay port should be provided"); - const size_t default_ports_count = sizeof(default_ports)/sizeof(*default_ports); + const size_t default_ports_count = sizeof(default_ports) / sizeof(*default_ports); for (size_t i = 0; i < default_ports_count; ++i) { log_write(LOG_LEVEL_INFO, "Port #%zu: %u\n", i, default_ports[i]); @@ -134,9 +134,9 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por } } -int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, - int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, - uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd) +bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, + int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, + uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd) { config_t cfg; @@ -156,7 +156,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) { log_write(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); - return 0; + return false; } // Get port @@ -223,7 +223,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k *enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY; } - if (*enable_tcp_relay) { + if (*enable_tcp_relay != 0) { parse_tcp_relay_ports_config(&cfg, tcp_relay_ports, tcp_relay_port_count); } else { *tcp_relay_port_count = 0; @@ -237,7 +237,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k *enable_motd = DEFAULT_ENABLE_MOTD; } - if (*enable_motd) { + if (*enable_motd != 0) { // Get MOTD const char *tmp_motd; @@ -259,14 +259,14 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_PID_FILE_PATH, *pid_file_path); log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path); log_write(LOG_LEVEL_INFO, "'%s': %d\n", NAME_PORT, *port); - log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); - log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback ? "true" : "false"); - log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); + log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 != 0 ? "true" : "false"); + log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback != 0 ? "true" : "false"); + log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery != 0 ? "true" : "false"); - log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false"); + log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay != 0 ? "true" : "false"); // Show info about tcp ports only if tcp relay is enabled - if (*enable_tcp_relay) { + if (*enable_tcp_relay != 0) { if (*tcp_relay_port_count == 0) { log_write(LOG_LEVEL_ERROR, "No TCP ports could be read.\n"); } else { @@ -278,13 +278,13 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k } } - log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd ? "true" : "false"); + log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd != 0 ? "true" : "false"); - if (*enable_motd) { + if (*enable_motd != 0) { log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_MOTD, *motd); } - return 1; + return true; } /** @@ -316,7 +316,7 @@ static uint8_t *bootstrap_hex_string_to_bin(const char *hex_string) return ret; } -int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) +bool bootstrap_from_config(const char *cfg_file_path, DHT *dht, bool enable_ipv6) { const char *const NAME_BOOTSTRAP_NODES = "bootstrap_nodes"; @@ -331,7 +331,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) { log_write(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); - return 0; + return false; } config_setting_t *node_list = config_lookup(&cfg, NAME_BOOTSTRAP_NODES); @@ -340,13 +340,13 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) log_write(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n", NAME_BOOTSTRAP_NODES); config_destroy(&cfg); - return 1; + return true; } if (config_setting_length(node_list) == 0) { log_write(LOG_LEVEL_WARNING, "No bootstrap nodes found. Skipping bootstrapping.\n"); config_destroy(&cfg); - return 1; + return true; } int bs_port; @@ -357,15 +357,15 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) int i = 0; - while (config_setting_length(node_list)) { - int address_resolved; + while (config_setting_length(node_list) != 0) { + bool address_resolved; uint8_t *bs_public_key_bin; node = config_setting_get_elem(node_list, 0); if (node == nullptr) { config_destroy(&cfg); - return 0; + return false; } // Check that all settings are present @@ -421,5 +421,5 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) config_destroy(&cfg); - return 1; + return true; } diff --git a/other/bootstrap_daemon/src/config.h b/other/bootstrap_daemon/src/config.h index ae9aff8c33..be1e57aa51 100644 --- a/other/bootstrap_daemon/src/config.h +++ b/other/bootstrap_daemon/src/config.h @@ -19,19 +19,19 @@ * also, iff `tcp_relay_ports_count` > 0, then you are responsible for freeing `tcp_relay_ports` * and also `motd` iff `enable_motd` is set. * - * @return 1 on success, - * 0 on failure, doesn't modify any data pointed by arguments. + * @return true on success, + * false on failure, doesn't modify any data pointed by arguments. */ -int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, - int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, - uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd); +bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, + int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, + uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd); /** * Bootstraps off nodes listed in the config file. * - * @return 1 on success, some or no bootstrap nodes were added - * 0 on failure, an error occurred while parsing the config file. + * @return true on success, some or no bootstrap nodes were added + * false on failure, an error occurred while parsing the config file. */ -int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6); +bool bootstrap_from_config(const char *cfg_file_path, DHT *dht, bool enable_ipv6); #endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_CONFIG_H diff --git a/other/bootstrap_daemon/src/log.c b/other/bootstrap_daemon/src/log.c index ed3bf03df8..5dde7b52d7 100644 --- a/other/bootstrap_daemon/src/log.c +++ b/other/bootstrap_daemon/src/log.c @@ -58,7 +58,6 @@ bool log_close(void) return true; } - bool log_write(LOG_LEVEL level, const char *format, ...) { if (current_backend == INVALID_BACKEND) { diff --git a/other/bootstrap_daemon/src/log.h b/other/bootstrap_daemon/src/log.h index 4e80fd5774..79126258da 100644 --- a/other/bootstrap_daemon/src/log.h +++ b/other/bootstrap_daemon/src/log.h @@ -47,5 +47,4 @@ bool log_close(void); */ bool log_write(LOG_LEVEL level, const char *format, ...) GNU_PRINTF(2, 3); - #endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_H diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 588c23be4b..44a9c282c4 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -50,7 +50,6 @@ #include "global.h" #include "log.h" - static void sleep_milliseconds(uint32_t ms) { struct timespec req; @@ -61,10 +60,10 @@ static void sleep_milliseconds(uint32_t ms) // Uses the already existing key or creates one if it didn't exist // -// returns 1 on success -// 0 on failure - no keys were read or stored +// returns true on success +// false on failure - no keys were read or stored -static int manage_keys(DHT *dht, const char *keys_file_path) +static bool manage_keys(DHT *dht, const char *keys_file_path) { enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE }; uint8_t keys[KEYS_SIZE]; @@ -77,7 +76,7 @@ static int manage_keys(DHT *dht, const char *keys_file_path) if (read_size != KEYS_SIZE) { fclose(keys_file); - return 0; + return false; } dht_set_self_public_key(dht, keys); @@ -89,21 +88,21 @@ static int manage_keys(DHT *dht, const char *keys_file_path) keys_file = fopen(keys_file_path, "wb"); - if (!keys_file) { - return 0; + if (keys_file == nullptr) { + return false; } const size_t write_size = fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file); if (write_size != KEYS_SIZE) { fclose(keys_file); - return 0; + return false; } } fclose(keys_file); - return 1; + return true; } // Prints public key @@ -164,7 +163,6 @@ static Cli_Status daemonize(LOG_BACKEND log_backend, char *pid_file_path) return CLI_STATUS_ERROR; } - // Change the current working directory if ((chdir("/")) < 0) { log_write(LOG_LEVEL_ERROR, "Couldn't change working directory to '/'. Exiting.\n"); @@ -222,7 +220,7 @@ int main(int argc, char *argv[]) bool run_in_foreground = false; // Choose backend for printing command line argument parsing output based on whether the daemon is being run from a terminal - LOG_BACKEND log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG; + LOG_BACKEND log_backend = isatty(STDOUT_FILENO) != 0 ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG; log_open(log_backend); switch (handle_command_line_arguments(argc, argv, &cfg_file_path, &log_backend, &run_in_foreground)) { @@ -283,7 +281,7 @@ int main(int argc, char *argv[]) free(pid_file_path); IP ip; - ip_init(&ip, enable_ipv6); + ip_init(&ip, enable_ipv6 != 0); Logger *logger = logger_new(); @@ -298,10 +296,10 @@ int main(int argc, char *argv[]) Networking_Core *net = new_networking_ex(logger, mem, ns, &ip, start_port, end_port, nullptr); if (net == nullptr) { - if (enable_ipv6 && enable_ipv4_fallback) { + if (enable_ipv6 != 0 && enable_ipv4_fallback != 0) { log_write(LOG_LEVEL_WARNING, "Couldn't initialize IPv6 networking. Falling back to using IPv4.\n"); enable_ipv6 = 0; - ip_init(&ip, enable_ipv6); + ip_init(&ip, enable_ipv6 != 0); net = new_networking_ex(logger, mem, ns, &ip, start_port, end_port, nullptr); if (net == nullptr) { @@ -336,7 +334,7 @@ int main(int argc, char *argv[]) mono_time_update(mono_time); - DHT *const dht = new_dht(logger, mem, rng, ns, mono_time, net, true, enable_lan_discovery); + DHT *const dht = new_dht(logger, mem, rng, ns, mono_time, net, true, enable_lan_discovery != 0); if (dht == nullptr) { log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n"); @@ -396,7 +394,7 @@ int main(int argc, char *argv[]) Onion *onion = new_onion(logger, mem, mono_time, rng, dht); - if (!onion) { + if (onion == nullptr) { log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n"); kill_gca(group_announce); kill_announcements(announce); @@ -413,7 +411,7 @@ int main(int argc, char *argv[]) Onion_Announce *onion_a = new_onion_announce(logger, mem, rng, mono_time, dht); - if (!onion_a) { + if (onion_a == nullptr) { log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion Announce. Exiting.\n"); kill_gca(group_announce); kill_onion(onion); @@ -431,7 +429,7 @@ int main(int argc, char *argv[]) gca_onion_init(group_announce, onion_a); - if (enable_motd) { + if (enable_motd != 0) { if (bootstrap_set_callbacks(dht_get_net(dht), DAEMON_VERSION_NUMBER, (uint8_t *)motd, strlen(motd) + 1) == 0) { log_write(LOG_LEVEL_INFO, "Set MOTD successfully.\n"); free(motd); @@ -474,7 +472,7 @@ int main(int argc, char *argv[]) TCP_Server *tcp_server = nullptr; - if (enable_tcp_relay) { + if (enable_tcp_relay != 0) { if (tcp_relay_port_count == 0) { log_write(LOG_LEVEL_ERROR, "No TCP relay ports read. Exiting.\n"); kill_onion_announce(onion_a); @@ -490,7 +488,7 @@ int main(int argc, char *argv[]) return 1; } - tcp_server = new_tcp_server(logger, mem, rng, ns, enable_ipv6, + tcp_server = new_tcp_server(logger, mem, rng, ns, enable_ipv6 != 0, tcp_relay_port_count, tcp_relay_ports, dht_get_self_secret_key(dht), onion, forwarding); @@ -506,7 +504,7 @@ int main(int argc, char *argv[]) assert(rlim_suggested >= rlim_min); - if (!getrlimit(RLIMIT_NOFILE, &limit)) { + if (getrlimit(RLIMIT_NOFILE, &limit) == 0) { if (limit.rlim_cur < limit.rlim_max) { // Some systems have a hard limit of over 1000000 open file descriptors, so let's cap it at something reasonable // so that we don't set it to an unreasonably high number. @@ -515,7 +513,7 @@ int main(int argc, char *argv[]) } } - if (!getrlimit(RLIMIT_NOFILE, &limit) && limit.rlim_cur < rlim_min) { + if (getrlimit(RLIMIT_NOFILE, &limit) == 0 && limit.rlim_cur < rlim_min) { log_write(LOG_LEVEL_WARNING, "Current limit on the number of files this process can open (%ju) is rather low for the proper functioning of the TCP server. " "Consider raising the limit to at least %ju or the recommended %ju. " @@ -537,7 +535,7 @@ int main(int argc, char *argv[]) } } - if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) { + if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6 != 0)) { log_write(LOG_LEVEL_INFO, "List of bootstrap nodes read successfully.\n"); } else { log_write(LOG_LEVEL_ERROR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path); @@ -559,11 +557,11 @@ int main(int argc, char *argv[]) uint64_t last_lan_discovery = 0; const uint16_t net_htons_port = net_htons(start_port); - int waiting_for_dht_connection = 1; + bool waiting_for_dht_connection = true; Broadcast_Info *broadcast = nullptr; - if (enable_lan_discovery) { + if (enable_lan_discovery != 0) { broadcast = lan_discovery_init(ns); log_write(LOG_LEVEL_INFO, "Initialized LAN discovery successfully.\n"); } @@ -578,25 +576,25 @@ int main(int argc, char *argv[]) // Prevent the signal handler from being called again before it returns sigfillset(&sa.sa_mask); - if (sigaction(SIGINT, &sa, nullptr)) { + if (sigaction(SIGINT, &sa, nullptr) != 0) { log_write(LOG_LEVEL_WARNING, "Couldn't set signal handler for SIGINT. Continuing without the signal handler set.\n"); } - if (sigaction(SIGTERM, &sa, nullptr)) { + if (sigaction(SIGTERM, &sa, nullptr) != 0) { log_write(LOG_LEVEL_WARNING, "Couldn't set signal handler for SIGTERM. Continuing without the signal handler set.\n"); } - while (!caught_signal) { + while (caught_signal == 0) { mono_time_update(mono_time); do_dht(dht); - if (enable_lan_discovery && mono_time_is_timeout(mono_time, last_lan_discovery, LAN_DISCOVERY_INTERVAL)) { + if (enable_lan_discovery != 0 && mono_time_is_timeout(mono_time, last_lan_discovery, LAN_DISCOVERY_INTERVAL)) { lan_discovery_send(dht_get_net(dht), broadcast, dht_get_self_public_key(dht), net_htons_port); last_lan_discovery = mono_time_get(mono_time); } - if (enable_tcp_relay) { + if (enable_tcp_relay != 0) { do_tcp_server(tcp_server, mono_time); } @@ -604,7 +602,7 @@ int main(int argc, char *argv[]) if (waiting_for_dht_connection && dht_isconnected(dht)) { log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n"); - waiting_for_dht_connection = 0; + waiting_for_dht_connection = false; } sleep_milliseconds(30); diff --git a/other/docker/goblint/sodium.c b/other/docker/goblint/sodium.c index 42cbcc8449..071a6085f7 100644 --- a/other/docker/goblint/sodium.c +++ b/other/docker/goblint/sodium.c @@ -9,26 +9,26 @@ int crypto_sign_keypair(unsigned char *pk, unsigned char *sk) return 0; } int crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk, - const unsigned char *ed25519_pk) + const unsigned char *ed25519_pk) { memset(curve25519_pk, 0, 32); return 0; } int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk, - const unsigned char *ed25519_sk) + const unsigned char *ed25519_sk) { memset(curve25519_sk, 0, 32); return 0; } -void sodium_memzero(void * const pnt, const size_t len) +void sodium_memzero(void *const pnt, const size_t len) { memset(pnt, 0, len); } -int sodium_mlock(void * const addr, const size_t len) +int sodium_mlock(void *const addr, const size_t len) { return 0; } -int sodium_munlock(void * const addr, const size_t len) +int sodium_munlock(void *const addr, const size_t len) { return 0; } @@ -98,7 +98,7 @@ int crypto_hash_sha512(unsigned char *out, const unsigned char *in, { return 0; } -void randombytes(unsigned char * const buf, const unsigned long long buf_len) +void randombytes(unsigned char *const buf, const unsigned long long buf_len) { memset(buf, 0, buf_len); } diff --git a/other/event_tooling/generate_event_c.cpp b/other/event_tooling/generate_event_c.cpp index 9ca15dd8a9..5f624b0192 100644 --- a/other/event_tooling/generate_event_c.cpp +++ b/other/event_tooling/generate_event_c.cpp @@ -186,14 +186,12 @@ void generate_event_impl(const std::string& event_name, const std::vectorevents, state->mem);\n\n"; f << " if (" << event_name_l << " == nullptr) {\n"; f << " state->error = TOX_ERR_EVENTS_ITERATE_MALLOC;\n return nullptr;\n }\n\n"; - f << " return " << event_name_l << ";\n}\n\n"; + f << " return " << event_name_l << ";\n}\n"; f << R"( @@ -477,9 +475,9 @@ void generate_event_impl(const std::string& event_name, const std::vectordht, argv[argvoffset + 1], - ipv6enabled, port, bootstrap_key); + bool res = dht_bootstrap_from_address(m->dht, argv[argvoffset + 1], + ipv6enabled, port, bootstrap_key); free(bootstrap_key); if (!res) { diff --git a/testing/misc_tools.c b/testing/misc_tools.c index e274e5a758..a2b950c1da 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c @@ -138,7 +138,6 @@ int cmdline_parsefor_ipv46(int argc, char **argv, bool *ipv6enabled) return argvoffset; } - static const char *test_rng_name(void) { return "test_rng"; diff --git a/toxav/audio.c b/toxav/audio.c index c4166c0f8c..2cbc02d20a 100644 --- a/toxav/audio.c +++ b/toxav/audio.c @@ -25,8 +25,6 @@ static bool reconfigure_audio_encoder(const Logger *log, OpusEncoder **e, uint32 uint8_t new_ch, uint32_t *old_br, uint32_t *old_sr, uint8_t *old_ch); static bool reconfigure_audio_decoder(ACSession *ac, uint32_t sampling_rate, uint8_t channels); - - ACSession *ac_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, void *cb_data) { @@ -242,8 +240,6 @@ int ac_reconfigure_encoder(ACSession *ac, uint32_t bit_rate, uint32_t sampling_r return 0; } - - struct JitterBuffer { struct RTPMessage **queue; uint32_t size; @@ -365,7 +361,6 @@ static OpusEncoder *create_audio_encoder(const Logger *log, uint32_t bit_rate, u return nullptr; } - /* * Rates from 500 to 512000 bits per second are meaningful as well as the special * values OPUS_BITRATE_AUTO and OPUS_BITRATE_MAX. The value OPUS_BITRATE_MAX can @@ -382,7 +377,6 @@ static OpusEncoder *create_audio_encoder(const Logger *log, uint32_t bit_rate, u goto FAILURE; } - /* * Configures the encoder's use of inband forward error correction. * Note: @@ -398,7 +392,6 @@ static OpusEncoder *create_audio_encoder(const Logger *log, uint32_t bit_rate, u goto FAILURE; } - /* * Configures the encoder's expected packet loss percentage. * Higher values with trigger progressively more loss resistant behavior in @@ -418,7 +411,6 @@ static OpusEncoder *create_audio_encoder(const Logger *log, uint32_t bit_rate, u goto FAILURE; } - /* * Configures the encoder's computational complexity. * diff --git a/toxav/groupav.h b/toxav/groupav.h index ee76d494a6..67778036ee 100644 --- a/toxav/groupav.h +++ b/toxav/groupav.h @@ -34,7 +34,6 @@ int add_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, audio_data_c int join_av_groupchat(const Logger *log, Tox *tox, Group_Chats *g_c, uint32_t peer_number, const uint8_t *data, uint16_t length, audio_data_cb *audio_callback, void *userdata); - /** @brief Send audio to the conference. * * @retval 0 on success. diff --git a/toxav/msi.c b/toxav/msi.c index 460249b73b..1b375410b2 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -27,14 +27,12 @@ typedef enum MSIHeaderID { ID_CAPABILITIES, } MSIHeaderID; - typedef enum MSIRequest { REQU_INIT, REQU_PUSH, REQU_POP, } MSIRequest; - typedef struct MSIHeaderRequest { MSIRequest value; bool exists; @@ -50,14 +48,12 @@ typedef struct MSIHeaderCapabilities { bool exists; } MSIHeaderCapabilities; - typedef struct MSIMessage { MSIHeaderRequest request; MSIHeaderError error; MSIHeaderCapabilities capabilities; } MSIMessage; - static void msg_init(MSIMessage *dest, MSIRequest request); static int msg_parse_in(const Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length); static uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const uint8_t *value, uint8_t value_len, @@ -68,13 +64,12 @@ static bool invoke_callback(MSICall *call, MSICallbackID cb); static MSICall *get_call(MSISession *session, uint32_t friend_number); static MSICall *new_call(MSISession *session, uint32_t friend_number); static void kill_call(MSICall *call); -static void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t connection_status, void *user_data); +static void on_peer_status(Messenger *m, uint32_t friend_number, bool is_online, void *user_data); static void handle_init(MSICall *call, const MSIMessage *msg); static void handle_push(MSICall *call, const MSIMessage *msg); static void handle_pop(MSICall *call, const MSIMessage *msg); static void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, void *user_data); - /* * Public functions */ @@ -318,7 +313,6 @@ int msi_change_capabilities(MSICall *call, uint8_t capabilities) return 0; } - /** * Private functions */ @@ -357,7 +351,6 @@ static bool check_enum_high(const Logger *log, const uint8_t *bytes, uint8_t enu return true; } - static int msg_parse_in(const Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length) { /* Parse raw data received from socket into MSIMessage struct */ @@ -449,7 +442,7 @@ static int send_message(const Messenger *m, uint32_t friend_number, const MSIMes /* Parse and send message */ assert(m != nullptr); - uint8_t parsed [MSI_MAXMSG_SIZE]; + uint8_t parsed[MSI_MAXMSG_SIZE]; uint8_t *it = parsed; uint16_t size = 0; @@ -587,7 +580,7 @@ static MSICall *new_call(MSISession *session, uint32_t friend_number) session->calls_tail = friend_number; session->calls_head = friend_number; } else if (session->calls_tail < friend_number) { /* Appending */ - MSICall **tmp = (MSICall **)realloc(session->calls, (friend_number + 1) * sizeof(MSICall *)); + MSICall **tmp = (MSICall **)realloc(session->calls, (friend_number + 1) * sizeof(MSICall *)); if (tmp == nullptr) { free(rc); @@ -655,11 +648,11 @@ static void kill_call(MSICall *call) free(call); session->calls = nullptr; } -static void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t connection_status, void *user_data) +static void on_peer_status(Messenger *m, uint32_t friend_number, bool is_online, void *user_data) { MSISession *session = (MSISession *)user_data; - if (connection_status != 0) { + if (is_online) { // Friend is online. return; } diff --git a/toxav/msi.h b/toxav/msi.h index 316a3ef184..f034a35c9c 100644 --- a/toxav/msi.h +++ b/toxav/msi.h @@ -38,7 +38,6 @@ typedef enum MSICapabilities { MSI_CAP_R_VIDEO = 32, /* receiving video */ } MSICapabilities; - /** * Call state identifiers. */ @@ -80,7 +79,6 @@ typedef struct MSICall { struct MSICall *prev; } MSICall; - /** * Expected return on success is 0, if any other number is * returned the call is considered errored and will be handled diff --git a/toxav/rtp.c b/toxav/rtp.c index 86e17981f4..8ad4ce670e 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -23,7 +23,6 @@ */ #define VIDEO_KEEP_KEYFRAME_IN_BUFFER_FOR_MS 15 - /** * return -1 on failure, 0 on success * diff --git a/toxav/rtp.h b/toxav/rtp.h index c55c080b84..8acd48d061 100644 --- a/toxav/rtp.h +++ b/toxav/rtp.h @@ -52,7 +52,6 @@ typedef enum RTPFlags { RTP_KEY_FRAME = 1 << 1, } RTPFlags; - struct RTPHeader { /* Standard RTP header */ unsigned ve: 2; /* Version has only 2 bits! */ @@ -100,7 +99,6 @@ struct RTPHeader { uint16_t data_length_lower; }; - struct RTPMessage { /** * This is used in the old code that doesn't deal with large frames, i.e. @@ -167,7 +165,6 @@ typedef struct RTPSession { rtp_m_cb *mcb; } RTPSession; - /** * Serialise an RTPHeader to bytes to be sent over the network. * diff --git a/toxav/toxav.c b/toxav/toxav.c index b80feb030a..6bae7a91d1 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -65,7 +65,6 @@ typedef struct ToxAVCall { struct ToxAVCall *next; } ToxAVCall; - /** Decode time statistics */ typedef struct DecodeTimeStats { /** Measure count */ @@ -857,7 +856,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc sampling_rate = net_htonl(sampling_rate); memcpy(dest, &sampling_rate, sizeof(sampling_rate)); const int vrc = opus_encode(call->audio->encoder, pcm, sample_count, - dest + sizeof(sampling_rate), dest_size - sizeof(sampling_rate)); + dest + sizeof(sampling_rate), dest_size - sizeof(sampling_rate)); if (vrc < 0) { LOGGER_WARNING(av->m->log, "Failed to encode frame %s", opus_strerror(vrc)); @@ -1004,7 +1003,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u memcpy(img.planes[VPX_PLANE_V], v, (width / 2) * (height / 2)); const vpx_codec_err_t vrc = vpx_codec_encode(call->video->encoder, &img, - call->video->frame_counter, 1, vpx_encode_flags, MAX_ENCODE_TIME_US); + call->video->frame_counter, 1, vpx_encode_flags, MAX_ENCODE_TIME_US); vpx_img_free(&img); diff --git a/toxav/toxav.h b/toxav/toxav.h index 5ed674ab20..07d8d0eef7 100644 --- a/toxav/toxav.h +++ b/toxav/toxav.h @@ -83,7 +83,6 @@ typedef struct Tox Tox; */ typedef struct ToxAV ToxAV; - /** @{ * @brief Creation and destruction */ @@ -113,7 +112,6 @@ typedef enum Toxav_Err_New { } Toxav_Err_New; - /** * Start new A/V session. There can only be only one session per Tox instance. */ @@ -135,7 +133,6 @@ Tox *toxav_get_tox(const ToxAV *av); /** @} */ - /** @{ * @brief A/V event loop, single thread */ @@ -156,7 +153,6 @@ void toxav_iterate(ToxAV *av); /** @} */ - /** @{ * @brief A/V event loop, multiple threads */ @@ -195,7 +191,6 @@ void toxav_video_iterate(ToxAV *av); /** @} */ - /** @{ * @brief Call setup */ @@ -241,7 +236,6 @@ typedef enum Toxav_Err_Call { } Toxav_Err_Call; - /** * Call a friend. This will start ringing the friend. * @@ -268,7 +262,6 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint */ typedef void toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data); - /** * Set the callback for the `call` event. Pass NULL to unset. * @@ -312,7 +305,6 @@ typedef enum Toxav_Err_Answer { } Toxav_Err_Answer; - /** * Accept an incoming call. * @@ -331,7 +323,6 @@ bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, ui /** @} */ - /** @{ * @brief Call state graph */ @@ -380,7 +371,6 @@ enum Toxav_Friend_Call_State { }; - /** * The function type for the call_state callback. * @@ -392,7 +382,6 @@ enum Toxav_Friend_Call_State { */ typedef void toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data); - /** * Set the callback for the `call_state` event. Pass NULL to unset. * @@ -401,7 +390,6 @@ void toxav_callback_call_state(ToxAV *av, toxav_call_state_cb *callback, void *u /** @} */ - /** @{ * @brief Call control */ @@ -451,7 +439,6 @@ typedef enum Toxav_Call_Control { } Toxav_Call_Control; - typedef enum Toxav_Err_Call_Control { /** @@ -483,7 +470,6 @@ typedef enum Toxav_Err_Call_Control { } Toxav_Err_Call_Control; - /** * Sends a call control command to a friend. * @@ -497,7 +483,6 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, Toxav_Call_Control co /** @} */ - /** @{ * @brief Controlling bit rates */ @@ -533,8 +518,6 @@ typedef enum Toxav_Err_Bit_Rate_Set { /** @} */ - - /** @{ * @brief A/V sending */ @@ -586,7 +569,6 @@ typedef enum Toxav_Err_Send_Frame { } Toxav_Err_Send_Frame; - /** * Send an audio frame to a friend. * @@ -632,7 +614,6 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_ra */ typedef void toxav_audio_bit_rate_cb(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, void *user_data); - /** * Set the callback for the `audio_bit_rate` event. Pass NULL to unset. * @@ -655,11 +636,11 @@ void toxav_callback_audio_bit_rate(ToxAV *av, toxav_audio_bit_rate_cb *callback, * @param v V (Chroma) plane data. */ bool toxav_video_send_frame( - ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, - const uint8_t y[/*! height * width */], - const uint8_t u[/*! height/2 * width/2 */], - const uint8_t v[/*! height/2 * width/2 */], - Toxav_Err_Send_Frame *error); + ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, + const uint8_t y[/*! height * width */], + const uint8_t u[/*! height/2 * width/2 */], + const uint8_t v[/*! height/2 * width/2 */], + Toxav_Err_Send_Frame *error); /** * Set the bit rate to be used in subsequent video frames. @@ -683,7 +664,6 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_ra */ typedef void toxav_video_bit_rate_cb(ToxAV *av, uint32_t friend_number, uint32_t video_bit_rate, void *user_data); - /** * Set the callback for the `video_bit_rate` event. Pass NULL to unset. * @@ -692,7 +672,6 @@ void toxav_callback_video_bit_rate(ToxAV *av, toxav_video_bit_rate_cb *callback, /** @} */ - /** @{ * @brief A/V receiving */ @@ -712,7 +691,6 @@ void toxav_callback_video_bit_rate(ToxAV *av, toxav_video_bit_rate_cb *callback, typedef void toxav_audio_receive_frame_cb(ToxAV *av, uint32_t friend_number, const int16_t pcm[], size_t sample_count, uint8_t channels, uint32_t sampling_rate, void *user_data); - /** * Set the callback for the `audio_receive_frame` event. Pass NULL to unset. * @@ -742,14 +720,13 @@ void toxav_callback_audio_receive_frame(ToxAV *av, toxav_audio_receive_frame_cb * @param vstride V chroma plane stride. */ typedef void toxav_video_receive_frame_cb( - ToxAV *av, uint32_t friend_number, - uint16_t width, uint16_t height, - const uint8_t y[/*! max(width, abs(ystride)) * height */], - const uint8_t u[/*! max(width/2, abs(ustride)) * (height/2) */], - const uint8_t v[/*! max(width/2, abs(vstride)) * (height/2) */], - int32_t ystride, int32_t ustride, int32_t vstride, - void *user_data); - + ToxAV *av, uint32_t friend_number, + uint16_t width, uint16_t height, + const uint8_t y[/*! max(width, abs(ystride)) * height */], + const uint8_t u[/*! max(width/2, abs(ustride)) * (height/2) */], + const uint8_t v[/*! max(width/2, abs(vstride)) * (height/2) */], + int32_t ystride, int32_t ustride, int32_t vstride, + void *user_data); /** * Set the callback for the `video_receive_frame` event. Pass NULL to unset. @@ -791,8 +768,8 @@ int32_t toxav_add_av_groupchat(Tox *tox, toxav_audio_data_cb *audio_callback, vo * Note that total size of pcm in bytes is equal to `samples * channels * sizeof(int16_t)`. */ int32_t toxav_join_av_groupchat( - Tox *tox, uint32_t friendnumber, const uint8_t data[], uint16_t length, - toxav_audio_data_cb *audio_callback, void *userdata); + Tox *tox, uint32_t friendnumber, const uint8_t data[], uint16_t length, + toxav_audio_data_cb *audio_callback, void *userdata); /** @brief Send audio to the group chat. * @@ -809,8 +786,8 @@ int32_t toxav_join_av_groupchat( * Recommended values are: samples = 960, channels = 1, sample_rate = 48000 */ int32_t toxav_group_send_audio( - Tox *tox, uint32_t groupnumber, const int16_t pcm[], uint32_t samples, uint8_t channels, - uint32_t sample_rate); + Tox *tox, uint32_t groupnumber, const int16_t pcm[], uint32_t samples, uint8_t channels, + uint32_t sample_rate); /** @brief Enable A/V in a groupchat. * @@ -828,8 +805,8 @@ int32_t toxav_group_send_audio( * Note that total size of pcm in bytes is equal to `samples * channels * sizeof(int16_t)`. */ int32_t toxav_groupchat_enable_av( - Tox *tox, uint32_t groupnumber, - toxav_audio_data_cb *audio_callback, void *userdata); + Tox *tox, uint32_t groupnumber, + toxav_audio_data_cb *audio_callback, void *userdata); /** @brief Disable A/V in a groupchat. * diff --git a/toxcore/DHT.c b/toxcore/DHT.c index bdfd879f7b..2567d1b5a8 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -84,7 +84,7 @@ struct DHT_Friend { static const DHT_Friend empty_dht_friend = {{0}}; const Node_format empty_node_format = {{0}}; -static_assert(sizeof (empty_dht_friend.lock_flags) * 8 == DHT_FRIEND_MAX_LOCKS, "Bitfield size and number of locks don't match"); +static_assert(sizeof(empty_dht_friend.lock_flags) * 8 == DHT_FRIEND_MAX_LOCKS, "Bitfield size and number of locks don't match"); typedef struct Cryptopacket_Handler { cryptopacket_handler_cb *function; @@ -363,7 +363,6 @@ int packed_node_size(Family ip_family) return -1; } - int dht_create_packet(const Memory *mem, const Random *rng, const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], const uint8_t *shared_key, const uint8_t type, @@ -613,8 +612,8 @@ static bool client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_t } bool add_to_list( - Node_format *nodes_list, uint32_t length, const uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE], - const IP_Port *ip_port, const uint8_t cmp_pk[CRYPTO_PUBLIC_KEY_SIZE]) + Node_format *nodes_list, uint32_t length, const uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE], + const IP_Port *ip_port, const uint8_t cmp_pk[CRYPTO_PUBLIC_KEY_SIZE]) { for (uint32_t i = 0; i < length; ++i) { Node_format *node = &nodes_list[i]; @@ -644,10 +643,10 @@ bool add_to_list( */ non_null() static void get_close_nodes_inner( - uint64_t cur_time, const uint8_t *public_key, - Node_format *nodes_list, uint32_t *num_nodes_ptr, - Family sa_family, const Client_data *client_list, uint32_t client_list_length, - bool is_lan, bool want_announce) + uint64_t cur_time, const uint8_t *public_key, + Node_format *nodes_list, uint32_t *num_nodes_ptr, + Family sa_family, const Client_data *client_list, uint32_t client_list_length, + bool is_lan, bool want_announce) { if (!net_family_is_ipv4(sa_family) && !net_family_is_ipv6(sa_family) && !net_family_is_unspec(sa_family)) { return; @@ -715,10 +714,10 @@ static void get_close_nodes_inner( */ non_null() static int get_somewhat_close_nodes( - uint64_t cur_time, const uint8_t *public_key, Node_format nodes_list[MAX_SENT_NODES], - Family sa_family, const Client_data *close_clientlist, - const DHT_Friend *friends_list, uint16_t friends_list_size, - bool is_lan, bool want_announce) + uint64_t cur_time, const uint8_t *public_key, Node_format nodes_list[MAX_SENT_NODES], + Family sa_family, const Client_data *close_clientlist, + const DHT_Friend *friends_list, uint16_t friends_list_size, + bool is_lan, bool want_announce) { for (uint16_t i = 0; i < MAX_SENT_NODES; ++i) { nodes_list[i] = empty_node_format; @@ -726,34 +725,34 @@ static int get_somewhat_close_nodes( uint32_t num_nodes = 0; get_close_nodes_inner( - cur_time, public_key, - nodes_list, &num_nodes, - sa_family, close_clientlist, LCLIENT_LIST, - is_lan, want_announce); + cur_time, public_key, + nodes_list, &num_nodes, + sa_family, close_clientlist, LCLIENT_LIST, + is_lan, want_announce); for (uint16_t i = 0; i < friends_list_size; ++i) { const DHT_Friend *dht_friend = &friends_list[i]; get_close_nodes_inner( - cur_time, public_key, - nodes_list, &num_nodes, - sa_family, dht_friend->client_list, MAX_FRIEND_CLIENTS, - is_lan, want_announce); + cur_time, public_key, + nodes_list, &num_nodes, + sa_family, dht_friend->client_list, MAX_FRIEND_CLIENTS, + is_lan, want_announce); } return num_nodes; } int get_close_nodes( - const DHT *dht, const uint8_t *public_key, - Node_format nodes_list[MAX_SENT_NODES], Family sa_family, - bool is_lan, bool want_announce) + const DHT *dht, const uint8_t *public_key, + Node_format nodes_list[MAX_SENT_NODES], Family sa_family, + bool is_lan, bool want_announce) { return get_somewhat_close_nodes( - dht->cur_time, public_key, nodes_list, - sa_family, dht->close_clientlist, - dht->friends_list, dht->num_friends, - is_lan, want_announce); + dht->cur_time, public_key, nodes_list, + sa_family, dht->close_clientlist, + dht->friends_list, dht->num_friends, + is_lan, want_announce); } typedef struct DHT_Cmp_Data { @@ -1522,7 +1521,7 @@ static int handle_sendnodes_ipv6(void *object, const IP_Port *source, const uint non_null(1) nullable(2, 3) static uint32_t dht_friend_lock(DHT_Friend *const dht_friend, dht_ip_cb *ip_callback, - void *data, int32_t number) + void *data, int32_t number) { // find first free slot uint8_t lock_num; @@ -1841,8 +1840,8 @@ bool dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key) return dht_getnodes(dht, ip_port, public_key, dht->self_public_key); } -int dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled, - uint16_t port, const uint8_t *public_key) +bool dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled, + uint16_t port, const uint8_t *public_key) { IP_Port ip_port_v64; IP *ip_extra = nullptr; @@ -1865,10 +1864,10 @@ int dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled, dht_bootstrap(dht, &ip_port_v4, public_key); } - return 1; + return true; } - return 0; + return false; } int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packet, uint16_t length) @@ -1970,7 +1969,6 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n #endif /* !FRIEND_IPLIST_PAD */ } - /** * Callback invoked for each IP/port of each client of a friend. * @@ -2057,7 +2055,6 @@ uint32_t route_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet return 0; } - IP_Port ip_list[MAX_FRIEND_CLIENTS]; const int ip_num = friend_iplist(dht, ip_list, num); @@ -2571,7 +2568,6 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw return nullptr; } - dht->dht_ping_array = ping_array_new(mem, DHT_PING_ARRAY_SIZE, PING_TIMEOUT); if (dht->dht_ping_array == nullptr) { @@ -2662,21 +2658,21 @@ uint32_t dht_size(const DHT *dht) uint32_t numv6 = 0; for (uint32_t i = 0; i < dht->loaded_num_nodes; ++i) { - numv4 += net_family_is_ipv4(dht->loaded_nodes_list[i].ip_port.ip.family); - numv6 += net_family_is_ipv6(dht->loaded_nodes_list[i].ip_port.ip.family); + numv4 += net_family_is_ipv4(dht->loaded_nodes_list[i].ip_port.ip.family) ? 1 : 0; + numv6 += net_family_is_ipv6(dht->loaded_nodes_list[i].ip_port.ip.family) ? 1 : 0; } for (uint32_t i = 0; i < LCLIENT_LIST; ++i) { - numv4 += dht->close_clientlist[i].assoc4.timestamp != 0; - numv6 += dht->close_clientlist[i].assoc6.timestamp != 0; + numv4 += dht->close_clientlist[i].assoc4.timestamp != 0 ? 1 : 0; + numv6 += dht->close_clientlist[i].assoc6.timestamp != 0 ? 1 : 0; } for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER && i < dht->num_friends; ++i) { const DHT_Friend *const fr = &dht->friends_list[i]; for (uint32_t j = 0; j < MAX_FRIEND_CLIENTS; ++j) { - numv4 += fr->client_list[j].assoc4.timestamp != 0; - numv6 += fr->client_list[j].assoc6.timestamp != 0; + numv4 += fr->client_list[j].assoc4.timestamp != 0 ? 1 : 0; + numv6 += fr->client_list[j].assoc6.timestamp != 0 ? 1 : 0; } } @@ -2744,8 +2740,8 @@ void dht_save(const DHT *dht, uint8_t *data) } state_write_section_header( - old_data, DHT_STATE_COOKIE_TYPE, pack_nodes(dht->log, data, sizeof(Node_format) * num, clients, num), - DHT_STATE_TYPE_NODES); + old_data, DHT_STATE_COOKIE_TYPE, pack_nodes(dht->log, data, sizeof(Node_format) * num, clients, num), + DHT_STATE_TYPE_NODES); mem_delete(dht->mem, clients); } @@ -2884,7 +2880,8 @@ bool dht_non_lan_connected(const DHT *dht) return false; } -uint16_t dht_get_num_closelist(const DHT *dht) { +uint16_t dht_get_num_closelist(const DHT *dht) +{ uint16_t num_valid_close_clients = 0; for (uint32_t i = 0; i < LCLIENT_LIST; ++i) { const Client_data *const client = dht_get_close_client(dht, i); @@ -2898,7 +2895,8 @@ uint16_t dht_get_num_closelist(const DHT *dht) { return num_valid_close_clients; } -uint16_t dht_get_num_closelist_announce_capable(const DHT *dht) { +uint16_t dht_get_num_closelist_announce_capable(const DHT *dht) +{ uint16_t num_valid_close_clients_with_cap = 0; for (uint32_t i = 0; i < LCLIENT_LIST; ++i) { const Client_data *const client = dht_get_close_client(dht, i); diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 3e40f1cec2..602e2af6b2 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h @@ -36,7 +36,6 @@ extern "C" { #define EXT_SECRET_KEY_SIZE (ENC_SECRET_KEY_SIZE + SIG_SECRET_KEY_SIZE) #define EXT_PUBLIC_KEY_SIZE (ENC_PUBLIC_KEY_SIZE + SIG_PUBLIC_KEY_SIZE) - /* Maximum size of a signature (may be smaller) */ #define SIGNATURE_SIZE CRYPTO_SIGNATURE_SIZE /** Maximum number of clients stored per friend. */ @@ -350,8 +349,8 @@ unsigned int bit_by_bit_cmp(const uint8_t *pk1, const uint8_t *pk2); */ non_null() bool add_to_list( - Node_format *nodes_list, uint32_t length, const uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE], - const IP_Port *ip_port, const uint8_t cmp_pk[CRYPTO_PUBLIC_KEY_SIZE]); + Node_format *nodes_list, uint32_t length, const uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE], + const IP_Port *ip_port, const uint8_t cmp_pk[CRYPTO_PUBLIC_KEY_SIZE]); /** Return 1 if node can be added to close list, 0 if it can't. */ non_null() @@ -375,10 +374,9 @@ void set_announce_node(DHT *dht, const uint8_t *public_key); */ non_null() int get_close_nodes( - const DHT *dht, const uint8_t *public_key, - Node_format nodes_list[MAX_SENT_NODES], Family sa_family, - bool is_lan, bool want_announce); - + const DHT *dht, const uint8_t *public_key, + Node_format nodes_list[MAX_SENT_NODES], Family sa_family, + bool is_lan, bool want_announce); /** @brief Put up to max_num nodes in nodes from the random friends. * @@ -420,12 +418,12 @@ bool dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key); * @param ipv6enabled if false, the resolving sticks STRICTLY to IPv4 addresses. * Otherwise, the resolving looks for IPv6 addresses first, then IPv4 addresses. * - * @retval 1 if the address could be converted into an IP address - * @retval 0 otherwise + * @retval true if the address could be converted into an IP address + * @retval false otherwise */ non_null() -int dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled, - uint16_t port, const uint8_t *public_key); +bool dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled, + uint16_t port, const uint8_t *public_key); /** @brief Start sending packets after DHT loaded_friends_list and loaded_clients_list are set. * diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index e9e0acba13..bf3ec98b15 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c @@ -45,7 +45,6 @@ #define MAX_INTERFACES 16 - struct Broadcast_Info { uint32_t count; IP ips[MAX_INTERFACES]; @@ -240,8 +239,8 @@ static IP broadcast_ip(Family family_socket, Family family_broadcast) /* `FF02::1` is - according to RFC 4291 - multicast all-nodes link-local */ /* `FE80::*:` MUST be exact, for that we would need to look over all * interfaces and check in which status they are */ - ip.ip.v6.uint8[ 0] = 0xFF; - ip.ip.v6.uint8[ 1] = 0x02; + ip.ip.v6.uint8[0] = 0xFF; + ip.ip.v6.uint8[1] = 0x02; ip.ip.v6.uint8[15] = 0x01; } else if (net_family_is_ipv4(family_broadcast)) { ip.family = net_family_ipv6(); @@ -340,7 +339,6 @@ bool ip_is_lan(const IP *ip) return false; } - bool lan_discovery_send(const Networking_Core *net, const Broadcast_Info *broadcast, const uint8_t *dht_pk, uint16_t port) { @@ -377,7 +375,6 @@ bool lan_discovery_send(const Networking_Core *net, const Broadcast_Info *broadc return res; } - Broadcast_Info *lan_discovery_init(const Network *ns) { return fetch_broadcast_info(ns); diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 16a6506d2d..daf3477232 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -473,7 +473,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber) } if (m->friend_connectionstatuschange_internal != nullptr) { - m->friend_connectionstatuschange_internal(m, friendnumber, 0, m->friend_connectionstatuschange_internal_userdata); + m->friend_connectionstatuschange_internal(m, friendnumber, false, m->friend_connectionstatuschange_internal_userdata); } clear_receipts(m, friendnumber); @@ -592,7 +592,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con memcpy(packet + 1, message, length); const int64_t packet_num = write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, - m->friendlist[friendnumber].friendcon_id), packet, length + 1, false); + m->friendlist[friendnumber].friendcon_id), packet, length + 1, false); if (packet_num == -1) { return -4; @@ -1098,7 +1098,6 @@ static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status /*** CONFERENCES */ - /** @brief Set the callback for conference invites. */ void m_callback_conference_invite(Messenger *m, m_conference_invite_cb *function) { @@ -1121,7 +1120,6 @@ bool send_conference_invite_packet(const Messenger *m, int32_t friendnumber, con return write_cryptpacket_id(m, friendnumber, PACKET_ID_INVITE_CONFERENCE, data, length, false); } - /** @brief Send a group invite packet. * * @retval true if success @@ -1131,10 +1129,8 @@ bool send_group_invite_packet(const Messenger *m, uint32_t friendnumber, const u return write_cryptpacket_id(m, friendnumber, PACKET_ID_INVITE_GROUPCHAT, packet, length, false); } - /*** FILE SENDING */ - /** @brief Set the callback for file send requests. */ void callback_file_sendrequest(Messenger *m, m_file_recv_cb *function) { @@ -1196,8 +1192,8 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u file_number = temp_filenum; const struct File_Transfers *const ft = inbound - ? &m->friendlist[friendnumber].file_receiving[file_number] - : &m->friendlist[friendnumber].file_sending[file_number]; + ? &m->friendlist[friendnumber].file_receiving[file_number] + : &m->friendlist[friendnumber].file_sending[file_number]; if (ft->status == FILESTATUS_NONE) { return -2; @@ -1716,7 +1712,6 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdat } } - /** @brief Run this when the friend disconnects. * Kill all current file transfers. */ @@ -1925,7 +1920,6 @@ int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lo return 0; } - /** @brief High level function to send custom lossy packets. * * TODO(oxij): this name is confusing, because this function sends both av and custom lossy packets. @@ -2465,8 +2459,8 @@ static void do_friends(Messenger *m, void *userdata) for (uint32_t i = 0; i < m->numfriends; ++i) { if (m->friendlist[i].status == FRIEND_ADDED) { const int fr = send_friend_request_packet(m->fr_c, m->friendlist[i].friendcon_id, m->friendlist[i].friendrequest_nospam, - m->friendlist[i].info, - m->friendlist[i].info_size); + m->friendlist[i].info, + m->friendlist[i].info_size); if (fr >= 0) { set_friend_status(m, i, FRIEND_REQUESTED, userdata); @@ -2532,7 +2526,6 @@ static void m_connection_status_callback(Messenger *m, void *userdata) } } - #define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60UL #define IDSTRING_LEN (CRYPTO_PUBLIC_KEY_SIZE * 2 + 1) @@ -2595,7 +2588,7 @@ static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend } announce.base_announce.tcp_relays_count = (uint8_t)tcp_num; - announce.base_announce.ip_port_is_set = (uint8_t)(ip_port_is_set ? 1 : 0); + announce.base_announce.ip_port_is_set = ip_port_is_set; if (ip_port_is_set) { memcpy(&announce.base_announce.ip_port, &chat->self_ip_port, sizeof(IP_Port)); @@ -2725,7 +2718,6 @@ void do_messenger(Messenger *m, void *userdata) } } - /* dht contains additional "friends" (requests) */ const uint32_t num_dhtfriends = dht_get_num_friends(m->dht); VLA(int32_t, m2dht, num_dhtfriends); @@ -2893,7 +2885,6 @@ static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data) return data; } - non_null() static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data) { @@ -2931,7 +2922,6 @@ static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data return data; } - non_null() static uint32_t m_state_plugins_size(const Messenger *m) { @@ -2960,7 +2950,7 @@ bool m_register_state_plugin(Messenger *m, State_Type type, m_state_size_cb *siz { const uint32_t new_length = m->options.state_plugins_length + 1; Messenger_State_Plugin *temp = (Messenger_State_Plugin *)mem_vrealloc( - m->mem, m->options.state_plugins, new_length, sizeof(Messenger_State_Plugin)); + m->mem, m->options.state_plugins, new_length, sizeof(Messenger_State_Plugin)); if (temp == nullptr) { return false; diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index dceada215d..962a4701f7 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h @@ -39,7 +39,6 @@ /* This cannot be bigger than 256 */ #define MAX_CONCURRENT_FILE_PIPES 256 - #define FRIEND_ADDRESS_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) typedef enum Message_Type { @@ -88,7 +87,6 @@ typedef struct Messenger_Options { uint8_t state_plugins_length; } Messenger_Options; - struct Receipts { uint32_t packet_num; uint32_t msg_id; @@ -118,7 +116,6 @@ typedef enum Friend_Add_Error { FAERR_NOMEM = -8, } Friend_Add_Error; - /** Default start timeout in seconds between friend requests. */ #define FRIENDREQUEST_TIMEOUT 5 @@ -176,7 +173,6 @@ typedef enum Filekind { FILEKIND_AVATAR, } Filekind; - typedef void m_self_connection_status_cb(Messenger *m, Onion_Connection_Status connection_status, void *user_data); typedef void m_friend_status_cb(Messenger *m, uint32_t friend_number, unsigned int status, void *user_data); typedef void m_friend_connection_status_cb(Messenger *m, uint32_t friend_number, unsigned int connection_status, @@ -204,7 +200,7 @@ typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t friend_number, uint typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data, size_t length, void *user_data); typedef void m_friend_connectionstatuschange_internal_cb(Messenger *m, uint32_t friend_number, - uint8_t connection_status, void *user_data); + bool is_online, void *user_data); typedef void m_conference_invite_cb(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length, void *user_data); typedef void m_group_invite_cb(const Messenger *m, uint32_t friend_number, const uint8_t *invite_data, size_t length, @@ -369,7 +365,6 @@ void getaddress(const Messenger *m, uint8_t *address); non_null() int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, uint16_t length); - /** @brief Add a friend without sending a friendrequest. * @return the friend number if success. * @retval -3 if user's own key. @@ -459,7 +454,6 @@ non_null(1, 4) nullable(6) int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, const uint8_t *message, uint32_t length, uint32_t *message_id); - /** @brief Set the name and name_length of a friend. * * name must be a string of maximum MAX_NAME_LENGTH length. @@ -550,7 +544,6 @@ non_null() int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf); non_null() uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber); non_null() uint8_t m_get_self_userstatus(const Messenger *m); - /** @brief returns timestamp of last time friendnumber was seen online or 0 if never seen. * if friendnumber is invalid this function will return UINT64_MAX. */ @@ -624,7 +617,6 @@ non_null() void m_callback_connectionstatus(Messenger *m, m_friend_connection_st non_null() void m_callback_connectionstatus_internal_av( Messenger *m, m_friend_connectionstatuschange_internal_cb *function, void *userdata); - /** @brief Set the callback for typing changes. */ non_null() void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *function); @@ -639,7 +631,6 @@ void m_callback_conference_invite(Messenger *m, m_conference_invite_cb *function non_null(1) nullable(2) void m_callback_group_invite(Messenger *m, m_group_invite_cb *function); - /** @brief Send a conference invite packet. * * return true on success @@ -658,14 +649,11 @@ bool send_conference_invite_packet(const Messenger *m, int32_t friendnumber, con non_null() bool send_group_invite_packet(const Messenger *m, uint32_t friendnumber, const uint8_t *packet, uint16_t length); - /*** FILE SENDING */ - /** @brief Set the callback for file send requests. */ non_null() void callback_file_sendrequest(Messenger *m, m_file_recv_cb *function); - /** @brief Set the callback for file control requests. */ non_null() void callback_file_control(Messenger *m, m_file_recv_control_cb *function); @@ -675,7 +663,6 @@ non_null() void callback_file_data(Messenger *m, m_file_recv_chunk_cb *function) /** @brief Set the callback for file request chunk. */ non_null() void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *function); - /** @brief Copy the file transfer file id to file_id * * @retval 0 on success. @@ -790,7 +777,6 @@ non_null() void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy non_null() int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length); - /** @brief Set handlers for custom lossless packets. */ non_null() void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_packet_cb *lossless_packethandler); diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 952cb6bbd3..2b8c6e448f 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -313,7 +313,7 @@ static int generate_handshake(TCP_Client_Connection *tcp_conn) memcpy(tcp_conn->con.last_packet, tcp_conn->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); random_nonce(tcp_conn->con.rng, tcp_conn->con.last_packet + CRYPTO_PUBLIC_KEY_SIZE); const int len = encrypt_data_symmetric(tcp_conn->con.shared_key, tcp_conn->con.last_packet + CRYPTO_PUBLIC_KEY_SIZE, plain, - sizeof(plain), tcp_conn->con.last_packet + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); + sizeof(plain), tcp_conn->con.last_packet + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); if (len != sizeof(plain) + CRYPTO_MAC_SIZE) { return -1; @@ -335,7 +335,7 @@ static int handle_handshake(TCP_Client_Connection *tcp_conn, const uint8_t *data { uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE]; const int len = decrypt_data_symmetric(tcp_conn->con.shared_key, data, data + CRYPTO_NONCE_SIZE, - TCP_SERVER_HANDSHAKE_SIZE - CRYPTO_NONCE_SIZE, plain); + TCP_SERVER_HANDSHAKE_SIZE - CRYPTO_NONCE_SIZE, plain); if (len != sizeof(plain)) { return -1; @@ -421,7 +421,6 @@ int send_oob_packet(const Logger *logger, TCP_Client_Connection *con, const uint return write_packet_tcp_secure_connection(logger, &con->con, packet, packet_size, false); } - /** @brief Set the number that will be used as an argument in the callbacks related to con_id. * * When not set by this function, the number is -1. @@ -581,9 +580,9 @@ void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwa /** Create new TCP connection to ip_port/public_key */ TCP_Client_Connection *new_tcp_connection( - const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns, - const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key, - const TCP_Proxy_Info *proxy_info) + const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns, + const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key, + const TCP_Proxy_Info *proxy_info) { assert(logger != nullptr); assert(mem != nullptr); @@ -874,7 +873,8 @@ non_null(1, 2) nullable(3) static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn, void *userdata) { uint8_t packet[MAX_PACKET_SIZE]; - const int len = read_packet_tcp_secure_connection(logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet), &conn->ip_port); + const int len = read_packet_tcp_secure_connection(logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet), + &conn->ip_port); if (len == 0) { return false; diff --git a/toxcore/TCP_client.h b/toxcore/TCP_client.h index 6be0c86e83..ea2654b953 100644 --- a/toxcore/TCP_client.h +++ b/toxcore/TCP_client.h @@ -62,9 +62,9 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value); /** Create new TCP connection to ip_port/public_key */ non_null(1, 2, 3, 4, 5, 6, 7, 8, 9) nullable(10) TCP_Client_Connection *new_tcp_connection( - const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns, - const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key, - const TCP_Proxy_Info *proxy_info); + const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns, + const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key, + const TCP_Proxy_Info *proxy_info); /** Run the TCP connection */ non_null(1, 2, 3) nullable(4) @@ -153,5 +153,4 @@ int send_oob_packet(const Logger *logger, TCP_Client_Connection *con, const uint non_null() void oob_data_handler(TCP_Client_Connection *con, tcp_oob_data_cb *oob_data_callback, void *object); - #endif /* C_TOXCORE_TOXCORE_TCP_CLIENT_H */ diff --git a/toxcore/TCP_common.c b/toxcore/TCP_common.c index 5842f60551..bd3b7ca4c7 100644 --- a/toxcore/TCP_common.c +++ b/toxcore/TCP_common.c @@ -203,7 +203,7 @@ int write_packet_tcp_secure_connection(const Logger *logger, TCP_Connection *con * return -1 on failure/no data in buffer. */ int read_tcp_packet( - const Logger *logger, const Memory *mem, const Network *ns, Socket sock, uint8_t *data, uint16_t length, const IP_Port *ip_port) + const Logger *logger, const Memory *mem, const Network *ns, Socket sock, uint8_t *data, uint16_t length, const IP_Port *ip_port) { const uint16_t count = net_socket_data_recv_buffer(ns, sock); @@ -267,10 +267,10 @@ static uint16_t read_tcp_length(const Logger *logger, const Memory *mem, const N * @retval -1 on failure (connection must be killed). */ int read_packet_tcp_secure_connection( - const Logger *logger, const Memory *mem, const Network *ns, - Socket sock, uint16_t *next_packet_length, - const uint8_t *shared_key, uint8_t *recv_nonce, uint8_t *data, - uint16_t max_len, const IP_Port *ip_port) + const Logger *logger, const Memory *mem, const Network *ns, + Socket sock, uint16_t *next_packet_length, + const uint8_t *shared_key, uint8_t *recv_nonce, uint8_t *data, + uint16_t max_len, const IP_Port *ip_port) { if (*next_packet_length == 0) { const uint16_t len = read_tcp_length(logger, mem, ns, sock, ip_port); diff --git a/toxcore/TCP_common.h b/toxcore/TCP_common.h index 4c50652687..9fa136609c 100644 --- a/toxcore/TCP_common.h +++ b/toxcore/TCP_common.h @@ -89,8 +89,8 @@ int send_pending_data(const Logger *logger, TCP_Connection *con); */ non_null() int write_packet_tcp_secure_connection( - const Logger *logger, TCP_Connection *con, const uint8_t *data, uint16_t length, - bool priority); + const Logger *logger, TCP_Connection *con, const uint8_t *data, uint16_t length, + bool priority); /** @brief Read length bytes from socket. * @@ -99,7 +99,7 @@ int write_packet_tcp_secure_connection( */ non_null() int read_tcp_packet( - const Logger *logger, const Memory *mem, const Network *ns, Socket sock, uint8_t *data, uint16_t length, const IP_Port *ip_port); + const Logger *logger, const Memory *mem, const Network *ns, Socket sock, uint8_t *data, uint16_t length, const IP_Port *ip_port); /** * @return length of received packet on success. @@ -108,9 +108,9 @@ int read_tcp_packet( */ non_null() int read_packet_tcp_secure_connection( - const Logger *logger, const Memory *mem, const Network *ns, - Socket sock, uint16_t *next_packet_length, - const uint8_t *shared_key, uint8_t *recv_nonce, uint8_t *data, - uint16_t max_len, const IP_Port *ip_port); + const Logger *logger, const Memory *mem, const Network *ns, + Socket sock, uint16_t *next_packet_length, + const uint8_t *shared_key, uint8_t *recv_nonce, uint8_t *data, + uint16_t max_len, const IP_Port *ip_port); #endif /* C_TOXCORE_TOXCORE_TCP_COMMON_H */ diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index 9b644c37fd..c7161a9289 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c @@ -58,17 +58,14 @@ struct TCP_Connections { uint16_t onion_num_conns; }; - static const TCP_Connection_to empty_tcp_connection_to = {0}; static const TCP_con empty_tcp_con = {0}; - const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c) { return tcp_c->self_public_key; } - uint32_t tcp_connections_count(const TCP_Connections *tcp_c) { return tcp_c->tcp_connections_length; @@ -120,7 +117,6 @@ static int realloc_tcp_con(const Memory *mem, TCP_con **array, size_t num) return 0; } - /** * Return true if the connections_number is valid. */ @@ -753,7 +749,7 @@ int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_n } if (tcp_con->status == TCP_CONN_SLEEPING) { - tcp_con->unsleep = 1; + tcp_con->unsleep = true; } } } @@ -949,14 +945,14 @@ static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connec if (tcp_con->onion) { --tcp_c->onion_num_conns; - tcp_con->onion = 0; + tcp_con->onion = false; } tcp_con->lock_count = 0; tcp_con->sleep_count = 0; tcp_con->connected_time = 0; tcp_con->status = TCP_CONN_VALID; - tcp_con->unsleep = 0; + tcp_con->unsleep = false; return 0; } @@ -994,14 +990,14 @@ static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connection if (tcp_con->onion) { --tcp_c->onion_num_conns; - tcp_con->onion = 0; + tcp_con->onion = false; } tcp_con->lock_count = 0; tcp_con->sleep_count = 0; tcp_con->connected_time = 0; tcp_con->status = TCP_CONN_SLEEPING; - tcp_con->unsleep = 0; + tcp_con->unsleep = false; return 0; } @@ -1020,8 +1016,8 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti } tcp_con->connection = new_tcp_connection( - tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &tcp_con->ip_port, - tcp_con->relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info); + tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &tcp_con->ip_port, + tcp_con->relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info); if (tcp_con->connection == nullptr) { kill_tcp_relay_connection(tcp_c, tcp_connections_number); @@ -1032,7 +1028,7 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti tcp_con->sleep_count = 0; tcp_con->connected_time = 0; tcp_con->status = TCP_CONN_VALID; - tcp_con->unsleep = 0; + tcp_con->unsleep = false; return 0; } @@ -1287,7 +1283,7 @@ static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_numbe } if (tcp_c->onion_status && tcp_c->onion_num_conns < NUM_ONION_TCP_CONNECTIONS) { - tcp_con->onion = 1; + tcp_con->onion = true; ++tcp_c->onion_num_conns; } @@ -1318,8 +1314,8 @@ static int add_tcp_relay_instance(TCP_Connections *tcp_c, const IP_Port *ip_port TCP_con *tcp_con = &tcp_c->tcp_connections[tcp_connections_number]; tcp_con->connection = new_tcp_connection( - tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ipp_copy, - relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info); + tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ipp_copy, + relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info); if (tcp_con->connection == nullptr) { return -1; @@ -1373,7 +1369,7 @@ int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connection } if (con_to->status != TCP_CONN_SLEEPING && tcp_con->status == TCP_CONN_SLEEPING) { - tcp_con->unsleep = 1; + tcp_con->unsleep = true; } if (add_tcp_connection_to_conn(con_to, tcp_connections_number) == -1) { @@ -1541,7 +1537,7 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status) if (tcp_con != nullptr) { if (tcp_con->status == TCP_CONN_CONNECTED && !tcp_con->onion) { ++tcp_c->onion_num_conns; - tcp_con->onion = 1; + tcp_con->onion = true; } } @@ -1558,7 +1554,7 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status) if (tcp_con != nullptr) { if (tcp_con->status == TCP_CONN_SLEEPING) { - tcp_con->unsleep = 1; + tcp_con->unsleep = true; } } @@ -1568,7 +1564,7 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status) } } - tcp_c->onion_status = 1; + tcp_c->onion_status = true; } else { for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) { TCP_con *tcp_con = get_tcp_connection(tcp_c, i); @@ -1576,12 +1572,12 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status) if (tcp_con != nullptr) { if (tcp_con->onion) { --tcp_c->onion_num_conns; - tcp_con->onion = 0; + tcp_con->onion = false; } } } - tcp_c->onion_status = 0; + tcp_c->onion_status = false; } return 0; diff --git a/toxcore/TCP_connection.h b/toxcore/TCP_connection.h index d3211915fc..2d35919f10 100644 --- a/toxcore/TCP_connection.h +++ b/toxcore/TCP_connection.h @@ -186,7 +186,6 @@ void set_forwarding_packet_tcp_connection_callback(TCP_Connections *tcp_c, forwarded_response_cb *tcp_forwarded_response_callback, void *object); - typedef int tcp_oob_cb(void *object, const uint8_t *public_key, unsigned int tcp_connections_number, const uint8_t *packet, uint16_t length, void *userdata); diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 9b73a1d36d..3ce72e8e70 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -62,7 +62,6 @@ typedef struct TCP_Secure_Connection { static const TCP_Secure_Connection empty_tcp_secure_connection = {{nullptr}}; - struct TCP_Server { const Logger *logger; const Memory *mem; @@ -188,7 +187,6 @@ static int get_tcp_connection_index(const TCP_Server *tcp_server, const uint8_t return bs_list_find(&tcp_server->accepted_key_list, public_key); } - non_null() static int kill_accepted(TCP_Server *tcp_server, int index); @@ -850,7 +848,6 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint return 0; } - non_null() static int confirm_tcp_connection(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_Secure_Connection *con, const uint8_t *data, uint16_t length) @@ -1115,7 +1112,8 @@ static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, ui LOGGER_TRACE(tcp_server->logger, "handling unconfirmed TCP connection %d", i); uint8_t packet[MAX_PACKET_SIZE]; - const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet), &conn->con.ip_port); + const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, + sizeof(packet), &conn->con.ip_port); if (len == 0) { return -1; @@ -1135,7 +1133,8 @@ static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i) TCP_Secure_Connection *const conn = &tcp_server->accepted_connection_array[i]; uint8_t packet[MAX_PACKET_SIZE]; - const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet), &conn->con.ip_port); + const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, + sizeof(packet), &conn->con.ip_port); LOGGER_TRACE(tcp_server->logger, "processing packet for %d: %d", i, len); if (len == 0) { @@ -1283,7 +1282,6 @@ static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time continue; } - if ((events[n].events & EPOLLIN) == 0) { continue; } diff --git a/toxcore/TCP_server.h b/toxcore/TCP_server.h index ff0bd05d05..1d3933a415 100644 --- a/toxcore/TCP_server.h +++ b/toxcore/TCP_server.h @@ -52,5 +52,4 @@ void do_tcp_server(TCP_Server *tcp_server, const Mono_Time *mono_time); nullable(1) void kill_tcp_server(TCP_Server *tcp_server); - #endif /* C_TOXCORE_TOXCORE_TCP_SERVER_H */ diff --git a/toxcore/announce.c b/toxcore/announce.c index 6b350d3f04..4686959eaf 100644 --- a/toxcore/announce.c +++ b/toxcore/announce.c @@ -165,7 +165,6 @@ static const Announce_Entry *get_stored_const(const Announcements *announce, con return nullptr; } - bool announce_on_stored(const Announcements *announce, const uint8_t *data_public_key, announce_on_retrieve_cb *on_retrieve_callback, void *object) { @@ -355,7 +354,7 @@ static int create_reply_plain_data_search_request(Announcements *announce, to_auth, to_auth_length, p); p += TIMED_AUTH_SIZE; - *p = would_accept_store_request(announce, data_public_key); + *p = would_accept_store_request(announce, data_public_key) ? 1 : 0; ++p; Node_format nodes_list[MAX_SENT_NODES]; @@ -388,11 +387,11 @@ static int create_reply_plain_data_search_request(Announcements *announce, non_null() static int create_reply_plain_data_retrieve_request( - const Announcements *announce, - const IP_Port *source, - const uint8_t *data, uint16_t length, - uint8_t *reply, uint16_t reply_max_length, - const uint8_t *to_auth, uint16_t to_auth_length) + const Announcements *announce, + const IP_Port *source, + const uint8_t *data, uint16_t length, + uint8_t *reply, uint16_t reply_max_length, + const uint8_t *to_auth, uint16_t to_auth_length) { if (length != CRYPTO_PUBLIC_KEY_SIZE + 1 + TIMED_AUTH_SIZE) { return -1; @@ -447,7 +446,7 @@ static int create_reply_plain_store_announce_request(Announcements *announce, VLA(uint8_t, plain, plain_len); - const uint8_t* shared_key = shared_key_cache_lookup(announce->shared_keys, data_public_key); + const uint8_t *shared_key = shared_key_cache_lookup(announce->shared_keys, data_public_key); if (shared_key == nullptr) { /* Error looking up/deriving the shared key */ diff --git a/toxcore/announce.h b/toxcore/announce.h index 2c20c28b22..bd05088d06 100644 --- a/toxcore/announce.h +++ b/toxcore/announce.h @@ -41,7 +41,6 @@ void announce_set_synch_offset(Announcements *announce, int32_t synch_offset); nullable(1) void kill_announcements(Announcements *announce); - /* The declarations below are not public, they are exposed only for tests. */ /** @private diff --git a/toxcore/bin_unpack.c b/toxcore/bin_unpack.c index 4397e39677..3e7e19d61a 100644 --- a/toxcore/bin_unpack.c +++ b/toxcore/bin_unpack.c @@ -168,7 +168,7 @@ bool bin_unpack_u16_b(Bin_Unpack *bu, uint16_t *val) uint8_t hi = 0; uint8_t lo = 0; if (!(bin_unpack_u08_b(bu, &hi) - && bin_unpack_u08_b(bu, &lo))) { + && bin_unpack_u08_b(bu, &lo))) { return false; } *val = ((uint16_t)hi << 8) | lo; @@ -180,7 +180,7 @@ bool bin_unpack_u32_b(Bin_Unpack *bu, uint32_t *val) uint16_t hi = 0; uint16_t lo = 0; if (!(bin_unpack_u16_b(bu, &hi) - && bin_unpack_u16_b(bu, &lo))) { + && bin_unpack_u16_b(bu, &lo))) { return false; } *val = ((uint32_t)hi << 16) | lo; @@ -192,7 +192,7 @@ bool bin_unpack_u64_b(Bin_Unpack *bu, uint64_t *val) uint32_t hi = 0; uint32_t lo = 0; if (!(bin_unpack_u32_b(bu, &hi) - && bin_unpack_u32_b(bu, &lo))) { + && bin_unpack_u32_b(bu, &lo))) { return false; } *val = ((uint64_t)hi << 32) | lo; diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index 0323c8b2cd..c6c774979d 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c @@ -136,11 +136,7 @@ bool crypto_memlock(void *data, size_t length) return false; #else - if (sodium_mlock(data, length) != 0) { - return false; - } - - return true; + return sodium_mlock(data, length) == 0; #endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ } @@ -150,11 +146,7 @@ bool crypto_memunlock(void *data, size_t length) return false; #else - if (sodium_munlock(data, length) != 0) { - return false; - } - - return true; + return sodium_munlock(data, length) == 0; #endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ } diff --git a/toxcore/events/conference_connected.c b/toxcore/events/conference_connected.c index edd9a962a1..dbd9e4b51a 100644 --- a/toxcore/events/conference_connected.c +++ b/toxcore/events/conference_connected.c @@ -14,14 +14,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Conference_Connected { uint32_t conference_number; }; @@ -66,7 +64,6 @@ static bool tox_event_conference_connected_unpack_into( return bin_unpack_u32(bu, &event->conference_number); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -150,16 +147,15 @@ static Tox_Event_Conference_Connected *tox_event_conference_connected_alloc(void return conference_connected; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_conference_connected(Tox *tox, uint32_t conference_number, - void *user_data) +void tox_events_handle_conference_connected( + Tox *tox, uint32_t conference_number, + void *user_data) { Tox_Event_Conference_Connected *conference_connected = tox_event_conference_connected_alloc(user_data); diff --git a/toxcore/events/conference_invite.c b/toxcore/events/conference_invite.c index fbdad0f756..fb1f794bf3 100644 --- a/toxcore/events/conference_invite.c +++ b/toxcore/events/conference_invite.c @@ -18,14 +18,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Conference_Invite { uint32_t friend_number; Tox_Conference_Type type; @@ -134,7 +132,6 @@ static bool tox_event_conference_invite_unpack_into( && bin_unpack_bin(bu, &event->cookie, &event->cookie_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -218,16 +215,15 @@ static Tox_Event_Conference_Invite *tox_event_conference_invite_alloc(void *user return conference_invite; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_conference_invite(Tox *tox, uint32_t friend_number, Tox_Conference_Type type, const uint8_t *cookie, size_t length, - void *user_data) +void tox_events_handle_conference_invite( + Tox *tox, uint32_t friend_number, Tox_Conference_Type type, const uint8_t *cookie, size_t length, + void *user_data) { Tox_Event_Conference_Invite *conference_invite = tox_event_conference_invite_alloc(user_data); diff --git a/toxcore/events/conference_message.c b/toxcore/events/conference_message.c index 806df134cb..74e1123e01 100644 --- a/toxcore/events/conference_message.c +++ b/toxcore/events/conference_message.c @@ -18,14 +18,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Conference_Message { uint32_t conference_number; uint32_t peer_number; @@ -150,7 +148,6 @@ static bool tox_event_conference_message_unpack_into( && bin_unpack_bin(bu, &event->message, &event->message_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -234,16 +231,15 @@ static Tox_Event_Conference_Message *tox_event_conference_message_alloc(void *us return conference_message; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_conference_message(Tox *tox, uint32_t conference_number, uint32_t peer_number, Tox_Message_Type type, const uint8_t *message, size_t length, - void *user_data) +void tox_events_handle_conference_message( + Tox *tox, uint32_t conference_number, uint32_t peer_number, Tox_Message_Type type, const uint8_t *message, size_t length, + void *user_data) { Tox_Event_Conference_Message *conference_message = tox_event_conference_message_alloc(user_data); diff --git a/toxcore/events/conference_peer_list_changed.c b/toxcore/events/conference_peer_list_changed.c index e07f9a104e..050bfb08f8 100644 --- a/toxcore/events/conference_peer_list_changed.c +++ b/toxcore/events/conference_peer_list_changed.c @@ -14,14 +14,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Conference_Peer_List_Changed { uint32_t conference_number; }; @@ -66,7 +64,6 @@ static bool tox_event_conference_peer_list_changed_unpack_into( return bin_unpack_u32(bu, &event->conference_number); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -150,16 +147,15 @@ static Tox_Event_Conference_Peer_List_Changed *tox_event_conference_peer_list_ch return conference_peer_list_changed; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_conference_peer_list_changed(Tox *tox, uint32_t conference_number, - void *user_data) +void tox_events_handle_conference_peer_list_changed( + Tox *tox, uint32_t conference_number, + void *user_data) { Tox_Event_Conference_Peer_List_Changed *conference_peer_list_changed = tox_event_conference_peer_list_changed_alloc(user_data); diff --git a/toxcore/events/conference_peer_name.c b/toxcore/events/conference_peer_name.c index de57aafb2e..fc6c255791 100644 --- a/toxcore/events/conference_peer_name.c +++ b/toxcore/events/conference_peer_name.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Conference_Peer_Name { uint32_t conference_number; uint32_t peer_number; @@ -132,7 +130,6 @@ static bool tox_event_conference_peer_name_unpack_into( && bin_unpack_bin(bu, &event->name, &event->name_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -216,16 +213,15 @@ static Tox_Event_Conference_Peer_Name *tox_event_conference_peer_name_alloc(void return conference_peer_name; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_conference_peer_name(Tox *tox, uint32_t conference_number, uint32_t peer_number, const uint8_t *name, size_t length, - void *user_data) +void tox_events_handle_conference_peer_name( + Tox *tox, uint32_t conference_number, uint32_t peer_number, const uint8_t *name, size_t length, + void *user_data) { Tox_Event_Conference_Peer_Name *conference_peer_name = tox_event_conference_peer_name_alloc(user_data); diff --git a/toxcore/events/conference_title.c b/toxcore/events/conference_title.c index aed5e46c40..d761f51285 100644 --- a/toxcore/events/conference_title.c +++ b/toxcore/events/conference_title.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Conference_Title { uint32_t conference_number; uint32_t peer_number; @@ -132,7 +130,6 @@ static bool tox_event_conference_title_unpack_into( && bin_unpack_bin(bu, &event->title, &event->title_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -216,16 +213,15 @@ static Tox_Event_Conference_Title *tox_event_conference_title_alloc(void *user_d return conference_title; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_conference_title(Tox *tox, uint32_t conference_number, uint32_t peer_number, const uint8_t *title, size_t length, - void *user_data) +void tox_events_handle_conference_title( + Tox *tox, uint32_t conference_number, uint32_t peer_number, const uint8_t *title, size_t length, + void *user_data) { Tox_Event_Conference_Title *conference_title = tox_event_conference_title_alloc(user_data); diff --git a/toxcore/events/dht_get_nodes_response.c b/toxcore/events/dht_get_nodes_response.c index 11ab1c8389..6e03b73ea4 100644 --- a/toxcore/events/dht_get_nodes_response.c +++ b/toxcore/events/dht_get_nodes_response.c @@ -16,14 +16,12 @@ #include "../tox_events.h" #include "../tox_private.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Dht_Get_Nodes_Response { uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; uint8_t *ip; @@ -87,7 +85,9 @@ non_null() static void tox_event_dht_get_nodes_response_construct(Tox_Event_Dht_Get_Nodes_Response *dht_get_nodes_response) { *dht_get_nodes_response = (Tox_Event_Dht_Get_Nodes_Response) { - {0} + { + 0 + } }; } non_null() @@ -194,17 +194,15 @@ static Tox_Event_Dht_Get_Nodes_Response *tox_event_dht_get_nodes_response_alloc( return dht_get_nodes_response; } - /***************************************************** * * :: event handler * *****************************************************/ - void tox_events_handle_dht_get_nodes_response( - Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], - const char *ip, uint16_t port, void *user_data) + Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], + const char *ip, uint16_t port, void *user_data) { Tox_Event_Dht_Get_Nodes_Response *dht_get_nodes_response = tox_event_dht_get_nodes_response_alloc(user_data); diff --git a/toxcore/events/events_alloc.c b/toxcore/events/events_alloc.c index 271dfc0043..24eebb3124 100644 --- a/toxcore/events/events_alloc.c +++ b/toxcore/events/events_alloc.c @@ -63,7 +63,7 @@ bool tox_events_add(Tox_Events *events, const Tox_Event *event) if (events->events_size == events->events_capacity) { const uint32_t new_events_capacity = events->events_capacity * 2 + 1; Tox_Event *new_events = (Tox_Event *)mem_vrealloc( - events->mem, events->events, new_events_capacity, sizeof(Tox_Event)); + events->mem, events->events, new_events_capacity, sizeof(Tox_Event)); if (new_events == nullptr) { return false; diff --git a/toxcore/events/file_chunk_request.c b/toxcore/events/file_chunk_request.c index 1dd2126026..4117ef3c4b 100644 --- a/toxcore/events/file_chunk_request.c +++ b/toxcore/events/file_chunk_request.c @@ -14,14 +14,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_File_Chunk_Request { uint32_t friend_number; uint32_t file_number; @@ -119,7 +117,6 @@ static bool tox_event_file_chunk_request_unpack_into( && bin_unpack_u16(bu, &event->length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -203,16 +200,15 @@ static Tox_Event_File_Chunk_Request *tox_event_file_chunk_request_alloc(void *us return file_chunk_request; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length, - void *user_data) +void tox_events_handle_file_chunk_request( + Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length, + void *user_data) { Tox_Event_File_Chunk_Request *file_chunk_request = tox_event_file_chunk_request_alloc(user_data); diff --git a/toxcore/events/file_recv.c b/toxcore/events/file_recv.c index 8d4315d25d..45cec44b0d 100644 --- a/toxcore/events/file_recv.c +++ b/toxcore/events/file_recv.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_File_Recv { uint32_t friend_number; uint32_t file_number; @@ -164,7 +162,6 @@ static bool tox_event_file_recv_unpack_into( && bin_unpack_bin(bu, &event->filename, &event->filename_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -248,16 +245,15 @@ static Tox_Event_File_Recv *tox_event_file_recv_alloc(void *user_data) return file_recv; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_file_recv(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t kind, uint64_t file_size, const uint8_t *filename, size_t filename_length, - void *user_data) +void tox_events_handle_file_recv( + Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t kind, uint64_t file_size, const uint8_t *filename, size_t filename_length, + void *user_data) { Tox_Event_File_Recv *file_recv = tox_event_file_recv_alloc(user_data); diff --git a/toxcore/events/file_recv_chunk.c b/toxcore/events/file_recv_chunk.c index 2e134e9c47..2edf7c5a7b 100644 --- a/toxcore/events/file_recv_chunk.c +++ b/toxcore/events/file_recv_chunk.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_File_Recv_Chunk { uint32_t friend_number; uint32_t file_number; @@ -148,7 +146,6 @@ static bool tox_event_file_recv_chunk_unpack_into( && bin_unpack_bin(bu, &event->data, &event->data_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -232,16 +229,15 @@ static Tox_Event_File_Recv_Chunk *tox_event_file_recv_chunk_alloc(void *user_dat return file_recv_chunk; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_file_recv_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data, size_t length, - void *user_data) +void tox_events_handle_file_recv_chunk( + Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data, size_t length, + void *user_data) { Tox_Event_File_Recv_Chunk *file_recv_chunk = tox_event_file_recv_chunk_alloc(user_data); diff --git a/toxcore/events/file_recv_control.c b/toxcore/events/file_recv_control.c index c46501f91f..14a34aaf3b 100644 --- a/toxcore/events/file_recv_control.c +++ b/toxcore/events/file_recv_control.c @@ -16,14 +16,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_File_Recv_Control { uint32_t friend_number; uint32_t file_number; @@ -105,7 +103,6 @@ static bool tox_event_file_recv_control_unpack_into( && tox_file_control_unpack(&event->control, bu); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -189,16 +186,15 @@ static Tox_Event_File_Recv_Control *tox_event_file_recv_control_alloc(void *user return file_recv_control; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_file_recv_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control, - void *user_data) +void tox_events_handle_file_recv_control( + Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control, + void *user_data) { Tox_Event_File_Recv_Control *file_recv_control = tox_event_file_recv_control_alloc(user_data); diff --git a/toxcore/events/friend_connection_status.c b/toxcore/events/friend_connection_status.c index a8326ba8ed..330554b05e 100644 --- a/toxcore/events/friend_connection_status.c +++ b/toxcore/events/friend_connection_status.c @@ -16,14 +16,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Friend_Connection_Status { uint32_t friend_number; Tox_Connection connection_status; @@ -89,7 +87,6 @@ static bool tox_event_friend_connection_status_unpack_into( && tox_connection_unpack(&event->connection_status, bu); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -173,16 +170,15 @@ static Tox_Event_Friend_Connection_Status *tox_event_friend_connection_status_al return friend_connection_status; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_friend_connection_status(Tox *tox, uint32_t friend_number, Tox_Connection connection_status, - void *user_data) +void tox_events_handle_friend_connection_status( + Tox *tox, uint32_t friend_number, Tox_Connection connection_status, + void *user_data) { Tox_Event_Friend_Connection_Status *friend_connection_status = tox_event_friend_connection_status_alloc(user_data); diff --git a/toxcore/events/friend_lossless_packet.c b/toxcore/events/friend_lossless_packet.c index 55f0bea380..17e8fad926 100644 --- a/toxcore/events/friend_lossless_packet.c +++ b/toxcore/events/friend_lossless_packet.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Friend_Lossless_Packet { uint32_t friend_number; uint8_t *data; @@ -116,7 +114,6 @@ static bool tox_event_friend_lossless_packet_unpack_into( && bin_unpack_bin(bu, &event->data, &event->data_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -200,16 +197,15 @@ static Tox_Event_Friend_Lossless_Packet *tox_event_friend_lossless_packet_alloc( return friend_lossless_packet; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_friend_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, - void *user_data) +void tox_events_handle_friend_lossless_packet( + Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, + void *user_data) { Tox_Event_Friend_Lossless_Packet *friend_lossless_packet = tox_event_friend_lossless_packet_alloc(user_data); diff --git a/toxcore/events/friend_lossy_packet.c b/toxcore/events/friend_lossy_packet.c index 9d1d3edd6c..6b2e9ed2b0 100644 --- a/toxcore/events/friend_lossy_packet.c +++ b/toxcore/events/friend_lossy_packet.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Friend_Lossy_Packet { uint32_t friend_number; uint8_t *data; @@ -116,7 +114,6 @@ static bool tox_event_friend_lossy_packet_unpack_into( && bin_unpack_bin(bu, &event->data, &event->data_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -200,16 +197,15 @@ static Tox_Event_Friend_Lossy_Packet *tox_event_friend_lossy_packet_alloc(void * return friend_lossy_packet; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_friend_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, - void *user_data) +void tox_events_handle_friend_lossy_packet( + Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, + void *user_data) { Tox_Event_Friend_Lossy_Packet *friend_lossy_packet = tox_event_friend_lossy_packet_alloc(user_data); diff --git a/toxcore/events/friend_message.c b/toxcore/events/friend_message.c index b3a8f1ac5c..befcc74a24 100644 --- a/toxcore/events/friend_message.c +++ b/toxcore/events/friend_message.c @@ -18,14 +18,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Friend_Message { uint32_t friend_number; Tox_Message_Type type; @@ -134,7 +132,6 @@ static bool tox_event_friend_message_unpack_into( && bin_unpack_bin(bu, &event->message, &event->message_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -218,16 +215,15 @@ static Tox_Event_Friend_Message *tox_event_friend_message_alloc(void *user_data) return friend_message; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_friend_message(Tox *tox, uint32_t friend_number, Tox_Message_Type type, const uint8_t *message, size_t length, - void *user_data) +void tox_events_handle_friend_message( + Tox *tox, uint32_t friend_number, Tox_Message_Type type, const uint8_t *message, size_t length, + void *user_data) { Tox_Event_Friend_Message *friend_message = tox_event_friend_message_alloc(user_data); diff --git a/toxcore/events/friend_name.c b/toxcore/events/friend_name.c index 266e5e696a..dfa9b39608 100644 --- a/toxcore/events/friend_name.c +++ b/toxcore/events/friend_name.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Friend_Name { uint32_t friend_number; uint8_t *name; @@ -116,7 +114,6 @@ static bool tox_event_friend_name_unpack_into( && bin_unpack_bin(bu, &event->name, &event->name_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -200,16 +197,15 @@ static Tox_Event_Friend_Name *tox_event_friend_name_alloc(void *user_data) return friend_name; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_friend_name(Tox *tox, uint32_t friend_number, const uint8_t *name, size_t length, - void *user_data) +void tox_events_handle_friend_name( + Tox *tox, uint32_t friend_number, const uint8_t *name, size_t length, + void *user_data) { Tox_Event_Friend_Name *friend_name = tox_event_friend_name_alloc(user_data); diff --git a/toxcore/events/friend_read_receipt.c b/toxcore/events/friend_read_receipt.c index 705d763115..e5f2f9db52 100644 --- a/toxcore/events/friend_read_receipt.c +++ b/toxcore/events/friend_read_receipt.c @@ -14,14 +14,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Friend_Read_Receipt { uint32_t friend_number; uint32_t message_id; @@ -87,7 +85,6 @@ static bool tox_event_friend_read_receipt_unpack_into( && bin_unpack_u32(bu, &event->message_id); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -171,16 +168,15 @@ static Tox_Event_Friend_Read_Receipt *tox_event_friend_read_receipt_alloc(void * return friend_read_receipt; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_friend_read_receipt(Tox *tox, uint32_t friend_number, uint32_t message_id, - void *user_data) +void tox_events_handle_friend_read_receipt( + Tox *tox, uint32_t friend_number, uint32_t message_id, + void *user_data) { Tox_Event_Friend_Read_Receipt *friend_read_receipt = tox_event_friend_read_receipt_alloc(user_data); diff --git a/toxcore/events/friend_request.c b/toxcore/events/friend_request.c index e54aadf6d5..b492c15147 100644 --- a/toxcore/events/friend_request.c +++ b/toxcore/events/friend_request.c @@ -16,14 +16,12 @@ #include "../tox_events.h" #include "../tox_private.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Friend_Request { uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; uint8_t *message; @@ -82,7 +80,9 @@ non_null() static void tox_event_friend_request_construct(Tox_Event_Friend_Request *friend_request) { *friend_request = (Tox_Event_Friend_Request) { - {0} + { + 0 + } }; } non_null() @@ -190,14 +190,12 @@ static Tox_Event_Friend_Request *tox_event_friend_request_alloc(void *user_data) return friend_request; } - /***************************************************** * * :: event handler * *****************************************************/ - void tox_events_handle_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *message, size_t length, void *user_data) { diff --git a/toxcore/events/friend_status.c b/toxcore/events/friend_status.c index f06c7d14be..3d7499722b 100644 --- a/toxcore/events/friend_status.c +++ b/toxcore/events/friend_status.c @@ -16,14 +16,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Friend_Status { uint32_t friend_number; Tox_User_Status status; @@ -89,7 +87,6 @@ static bool tox_event_friend_status_unpack_into( && tox_user_status_unpack(&event->status, bu); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -173,16 +170,15 @@ static Tox_Event_Friend_Status *tox_event_friend_status_alloc(void *user_data) return friend_status; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_friend_status(Tox *tox, uint32_t friend_number, Tox_User_Status status, - void *user_data) +void tox_events_handle_friend_status( + Tox *tox, uint32_t friend_number, Tox_User_Status status, + void *user_data) { Tox_Event_Friend_Status *friend_status = tox_event_friend_status_alloc(user_data); diff --git a/toxcore/events/friend_status_message.c b/toxcore/events/friend_status_message.c index 61ea64d377..ad0519911e 100644 --- a/toxcore/events/friend_status_message.c +++ b/toxcore/events/friend_status_message.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Friend_Status_Message { uint32_t friend_number; uint8_t *message; @@ -116,7 +114,6 @@ static bool tox_event_friend_status_message_unpack_into( && bin_unpack_bin(bu, &event->message, &event->message_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -200,16 +197,15 @@ static Tox_Event_Friend_Status_Message *tox_event_friend_status_message_alloc(vo return friend_status_message; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_friend_status_message(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, - void *user_data) +void tox_events_handle_friend_status_message( + Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, + void *user_data) { Tox_Event_Friend_Status_Message *friend_status_message = tox_event_friend_status_message_alloc(user_data); diff --git a/toxcore/events/friend_typing.c b/toxcore/events/friend_typing.c index 620ae7966f..692b07fb88 100644 --- a/toxcore/events/friend_typing.c +++ b/toxcore/events/friend_typing.c @@ -14,14 +14,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Friend_Typing { uint32_t friend_number; bool typing; @@ -87,7 +85,6 @@ static bool tox_event_friend_typing_unpack_into( && bin_unpack_bool(bu, &event->typing); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -171,16 +168,15 @@ static Tox_Event_Friend_Typing *tox_event_friend_typing_alloc(void *user_data) return friend_typing; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_friend_typing(Tox *tox, uint32_t friend_number, bool typing, - void *user_data) +void tox_events_handle_friend_typing( + Tox *tox, uint32_t friend_number, bool typing, + void *user_data) { Tox_Event_Friend_Typing *friend_typing = tox_event_friend_typing_alloc(user_data); diff --git a/toxcore/events/group_custom_packet.c b/toxcore/events/group_custom_packet.c index 5067790335..a82e2c3a6c 100644 --- a/toxcore/events/group_custom_packet.c +++ b/toxcore/events/group_custom_packet.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Custom_Packet { uint32_t group_number; uint32_t peer_id; @@ -132,7 +130,6 @@ static bool tox_event_group_custom_packet_unpack_into( && bin_unpack_bin(bu, &event->data, &event->data_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -216,16 +213,15 @@ static Tox_Event_Group_Custom_Packet *tox_event_group_custom_packet_alloc(void * return group_custom_packet; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_custom_packet(Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *data, size_t length, - void *user_data) +void tox_events_handle_group_custom_packet( + Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *data, size_t length, + void *user_data) { Tox_Event_Group_Custom_Packet *group_custom_packet = tox_event_group_custom_packet_alloc(user_data); diff --git a/toxcore/events/group_custom_private_packet.c b/toxcore/events/group_custom_private_packet.c index df76711c55..56282f0fb8 100644 --- a/toxcore/events/group_custom_private_packet.c +++ b/toxcore/events/group_custom_private_packet.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Custom_Private_Packet { uint32_t group_number; uint32_t peer_id; @@ -132,7 +130,6 @@ static bool tox_event_group_custom_private_packet_unpack_into( && bin_unpack_bin(bu, &event->data, &event->data_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -216,16 +213,15 @@ static Tox_Event_Group_Custom_Private_Packet *tox_event_group_custom_private_pac return group_custom_private_packet; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_custom_private_packet(Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *data, size_t length, - void *user_data) +void tox_events_handle_group_custom_private_packet( + Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *data, size_t length, + void *user_data) { Tox_Event_Group_Custom_Private_Packet *group_custom_private_packet = tox_event_group_custom_private_packet_alloc(user_data); diff --git a/toxcore/events/group_invite.c b/toxcore/events/group_invite.c index e6f6d3ce17..0691dcd1fe 100644 --- a/toxcore/events/group_invite.c +++ b/toxcore/events/group_invite.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Invite { uint32_t friend_number; uint8_t *invite_data; @@ -160,7 +158,6 @@ static bool tox_event_group_invite_unpack_into( && bin_unpack_bin(bu, &event->group_name, &event->group_name_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -244,16 +241,15 @@ static Tox_Event_Group_Invite *tox_event_group_invite_alloc(void *user_data) return group_invite; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_invite(Tox *tox, uint32_t friend_number, const uint8_t *invite_data, size_t length, const uint8_t *group_name, size_t group_name_length, - void *user_data) +void tox_events_handle_group_invite( + Tox *tox, uint32_t friend_number, const uint8_t *invite_data, size_t length, const uint8_t *group_name, size_t group_name_length, + void *user_data) { Tox_Event_Group_Invite *group_invite = tox_event_group_invite_alloc(user_data); diff --git a/toxcore/events/group_join_fail.c b/toxcore/events/group_join_fail.c index d6e3ffb2bc..b85896858b 100644 --- a/toxcore/events/group_join_fail.c +++ b/toxcore/events/group_join_fail.c @@ -16,14 +16,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Join_Fail { uint32_t group_number; Tox_Group_Join_Fail fail_type; @@ -89,7 +87,6 @@ static bool tox_event_group_join_fail_unpack_into( && tox_group_join_fail_unpack(&event->fail_type, bu); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -173,16 +170,15 @@ static Tox_Event_Group_Join_Fail *tox_event_group_join_fail_alloc(void *user_dat return group_join_fail; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_join_fail(Tox *tox, uint32_t group_number, Tox_Group_Join_Fail fail_type, - void *user_data) +void tox_events_handle_group_join_fail( + Tox *tox, uint32_t group_number, Tox_Group_Join_Fail fail_type, + void *user_data) { Tox_Event_Group_Join_Fail *group_join_fail = tox_event_group_join_fail_alloc(user_data); diff --git a/toxcore/events/group_message.c b/toxcore/events/group_message.c index e685d7a233..a200f84566 100644 --- a/toxcore/events/group_message.c +++ b/toxcore/events/group_message.c @@ -18,14 +18,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Message { uint32_t group_number; uint32_t peer_id; @@ -166,7 +164,6 @@ static bool tox_event_group_message_unpack_into( && bin_unpack_u32(bu, &event->message_id); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -250,16 +247,15 @@ static Tox_Event_Group_Message *tox_event_group_message_alloc(void *user_data) return group_message; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_message(Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type type, const uint8_t *message, size_t length, uint32_t message_id, - void *user_data) +void tox_events_handle_group_message( + Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type type, const uint8_t *message, size_t length, uint32_t message_id, + void *user_data) { Tox_Event_Group_Message *group_message = tox_event_group_message_alloc(user_data); diff --git a/toxcore/events/group_moderation.c b/toxcore/events/group_moderation.c index d9a1a33a19..ba510d5b2a 100644 --- a/toxcore/events/group_moderation.c +++ b/toxcore/events/group_moderation.c @@ -16,14 +16,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Moderation { uint32_t group_number; uint32_t source_peer_id; @@ -121,7 +119,6 @@ static bool tox_event_group_moderation_unpack_into( && tox_group_mod_event_unpack(&event->mod_type, bu); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -205,16 +202,15 @@ static Tox_Event_Group_Moderation *tox_event_group_moderation_alloc(void *user_d return group_moderation; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_moderation(Tox *tox, uint32_t group_number, uint32_t source_peer_id, uint32_t target_peer_id, Tox_Group_Mod_Event mod_type, - void *user_data) +void tox_events_handle_group_moderation( + Tox *tox, uint32_t group_number, uint32_t source_peer_id, uint32_t target_peer_id, Tox_Group_Mod_Event mod_type, + void *user_data) { Tox_Event_Group_Moderation *group_moderation = tox_event_group_moderation_alloc(user_data); diff --git a/toxcore/events/group_password.c b/toxcore/events/group_password.c index 70110eeb96..ad6e86b9d3 100644 --- a/toxcore/events/group_password.c +++ b/toxcore/events/group_password.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Password { uint32_t group_number; uint8_t *password; @@ -116,7 +114,6 @@ static bool tox_event_group_password_unpack_into( && bin_unpack_bin(bu, &event->password, &event->password_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -200,16 +197,15 @@ static Tox_Event_Group_Password *tox_event_group_password_alloc(void *user_data) return group_password; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_password(Tox *tox, uint32_t group_number, const uint8_t *password, size_t length, - void *user_data) +void tox_events_handle_group_password( + Tox *tox, uint32_t group_number, const uint8_t *password, size_t length, + void *user_data) { Tox_Event_Group_Password *group_password = tox_event_group_password_alloc(user_data); diff --git a/toxcore/events/group_peer_exit.c b/toxcore/events/group_peer_exit.c index 16add3b0b2..16d1eba7a6 100644 --- a/toxcore/events/group_peer_exit.c +++ b/toxcore/events/group_peer_exit.c @@ -18,14 +18,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Peer_Exit { uint32_t group_number; uint32_t peer_id; @@ -194,7 +192,6 @@ static bool tox_event_group_peer_exit_unpack_into( && bin_unpack_bin(bu, &event->part_message, &event->part_message_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -278,16 +275,15 @@ static Tox_Event_Group_Peer_Exit *tox_event_group_peer_exit_alloc(void *user_dat return group_peer_exit; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_peer_exit(Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Group_Exit_Type exit_type, const uint8_t *name, size_t name_length, const uint8_t *part_message, size_t part_message_length, - void *user_data) +void tox_events_handle_group_peer_exit( + Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Group_Exit_Type exit_type, const uint8_t *name, size_t name_length, const uint8_t *part_message, size_t part_message_length, + void *user_data) { Tox_Event_Group_Peer_Exit *group_peer_exit = tox_event_group_peer_exit_alloc(user_data); diff --git a/toxcore/events/group_peer_join.c b/toxcore/events/group_peer_join.c index 036a35cb84..af0d006e87 100644 --- a/toxcore/events/group_peer_join.c +++ b/toxcore/events/group_peer_join.c @@ -14,14 +14,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Peer_Join { uint32_t group_number; uint32_t peer_id; @@ -87,7 +85,6 @@ static bool tox_event_group_peer_join_unpack_into( && bin_unpack_u32(bu, &event->peer_id); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -171,16 +168,15 @@ static Tox_Event_Group_Peer_Join *tox_event_group_peer_join_alloc(void *user_dat return group_peer_join; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_peer_join(Tox *tox, uint32_t group_number, uint32_t peer_id, - void *user_data) +void tox_events_handle_group_peer_join( + Tox *tox, uint32_t group_number, uint32_t peer_id, + void *user_data) { Tox_Event_Group_Peer_Join *group_peer_join = tox_event_group_peer_join_alloc(user_data); diff --git a/toxcore/events/group_peer_limit.c b/toxcore/events/group_peer_limit.c index 985e266741..5e2e23558c 100644 --- a/toxcore/events/group_peer_limit.c +++ b/toxcore/events/group_peer_limit.c @@ -14,14 +14,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Peer_Limit { uint32_t group_number; uint32_t peer_limit; @@ -87,7 +85,6 @@ static bool tox_event_group_peer_limit_unpack_into( && bin_unpack_u32(bu, &event->peer_limit); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -171,16 +168,15 @@ static Tox_Event_Group_Peer_Limit *tox_event_group_peer_limit_alloc(void *user_d return group_peer_limit; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_peer_limit(Tox *tox, uint32_t group_number, uint32_t peer_limit, - void *user_data) +void tox_events_handle_group_peer_limit( + Tox *tox, uint32_t group_number, uint32_t peer_limit, + void *user_data) { Tox_Event_Group_Peer_Limit *group_peer_limit = tox_event_group_peer_limit_alloc(user_data); diff --git a/toxcore/events/group_peer_name.c b/toxcore/events/group_peer_name.c index 40e81d4919..f8273e94b4 100644 --- a/toxcore/events/group_peer_name.c +++ b/toxcore/events/group_peer_name.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Peer_Name { uint32_t group_number; uint32_t peer_id; @@ -132,7 +130,6 @@ static bool tox_event_group_peer_name_unpack_into( && bin_unpack_bin(bu, &event->name, &event->name_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -216,16 +213,15 @@ static Tox_Event_Group_Peer_Name *tox_event_group_peer_name_alloc(void *user_dat return group_peer_name; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_peer_name(Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *name, size_t length, - void *user_data) +void tox_events_handle_group_peer_name( + Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *name, size_t length, + void *user_data) { Tox_Event_Group_Peer_Name *group_peer_name = tox_event_group_peer_name_alloc(user_data); diff --git a/toxcore/events/group_peer_status.c b/toxcore/events/group_peer_status.c index dc11ffa28c..4165d90ec2 100644 --- a/toxcore/events/group_peer_status.c +++ b/toxcore/events/group_peer_status.c @@ -16,14 +16,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Peer_Status { uint32_t group_number; uint32_t peer_id; @@ -105,7 +103,6 @@ static bool tox_event_group_peer_status_unpack_into( && tox_user_status_unpack(&event->status, bu); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -189,16 +186,15 @@ static Tox_Event_Group_Peer_Status *tox_event_group_peer_status_alloc(void *user return group_peer_status; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_peer_status(Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_User_Status status, - void *user_data) +void tox_events_handle_group_peer_status( + Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_User_Status status, + void *user_data) { Tox_Event_Group_Peer_Status *group_peer_status = tox_event_group_peer_status_alloc(user_data); diff --git a/toxcore/events/group_privacy_state.c b/toxcore/events/group_privacy_state.c index 15ae05464b..1c683c255c 100644 --- a/toxcore/events/group_privacy_state.c +++ b/toxcore/events/group_privacy_state.c @@ -16,14 +16,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Privacy_State { uint32_t group_number; Tox_Group_Privacy_State privacy_state; @@ -89,7 +87,6 @@ static bool tox_event_group_privacy_state_unpack_into( && tox_group_privacy_state_unpack(&event->privacy_state, bu); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -173,16 +170,15 @@ static Tox_Event_Group_Privacy_State *tox_event_group_privacy_state_alloc(void * return group_privacy_state; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_privacy_state(Tox *tox, uint32_t group_number, Tox_Group_Privacy_State privacy_state, - void *user_data) +void tox_events_handle_group_privacy_state( + Tox *tox, uint32_t group_number, Tox_Group_Privacy_State privacy_state, + void *user_data) { Tox_Event_Group_Privacy_State *group_privacy_state = tox_event_group_privacy_state_alloc(user_data); diff --git a/toxcore/events/group_private_message.c b/toxcore/events/group_private_message.c index 404fb2a223..648f707880 100644 --- a/toxcore/events/group_private_message.c +++ b/toxcore/events/group_private_message.c @@ -18,14 +18,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Private_Message { uint32_t group_number; uint32_t peer_id; @@ -150,7 +148,6 @@ static bool tox_event_group_private_message_unpack_into( && bin_unpack_bin(bu, &event->message, &event->message_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -234,16 +231,15 @@ static Tox_Event_Group_Private_Message *tox_event_group_private_message_alloc(vo return group_private_message; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_private_message(Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type type, const uint8_t *message, size_t length, - void *user_data) +void tox_events_handle_group_private_message( + Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type type, const uint8_t *message, size_t length, + void *user_data) { Tox_Event_Group_Private_Message *group_private_message = tox_event_group_private_message_alloc(user_data); diff --git a/toxcore/events/group_self_join.c b/toxcore/events/group_self_join.c index 5129f142c3..0745e975f8 100644 --- a/toxcore/events/group_self_join.c +++ b/toxcore/events/group_self_join.c @@ -14,14 +14,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Self_Join { uint32_t group_number; }; @@ -66,7 +64,6 @@ static bool tox_event_group_self_join_unpack_into( return bin_unpack_u32(bu, &event->group_number); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -150,16 +147,15 @@ static Tox_Event_Group_Self_Join *tox_event_group_self_join_alloc(void *user_dat return group_self_join; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_self_join(Tox *tox, uint32_t group_number, - void *user_data) +void tox_events_handle_group_self_join( + Tox *tox, uint32_t group_number, + void *user_data) { Tox_Event_Group_Self_Join *group_self_join = tox_event_group_self_join_alloc(user_data); diff --git a/toxcore/events/group_topic.c b/toxcore/events/group_topic.c index d7e0bf37b5..23cdd5d354 100644 --- a/toxcore/events/group_topic.c +++ b/toxcore/events/group_topic.c @@ -16,14 +16,12 @@ #include "../tox.h" #include "../tox_events.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Topic { uint32_t group_number; uint32_t peer_id; @@ -132,7 +130,6 @@ static bool tox_event_group_topic_unpack_into( && bin_unpack_bin(bu, &event->topic, &event->topic_length); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -216,16 +213,15 @@ static Tox_Event_Group_Topic *tox_event_group_topic_alloc(void *user_data) return group_topic; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_topic(Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *topic, size_t length, - void *user_data) +void tox_events_handle_group_topic( + Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *topic, size_t length, + void *user_data) { Tox_Event_Group_Topic *group_topic = tox_event_group_topic_alloc(user_data); diff --git a/toxcore/events/group_topic_lock.c b/toxcore/events/group_topic_lock.c index a859d41251..36fb49393a 100644 --- a/toxcore/events/group_topic_lock.c +++ b/toxcore/events/group_topic_lock.c @@ -16,14 +16,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Topic_Lock { uint32_t group_number; Tox_Group_Topic_Lock topic_lock; @@ -89,7 +87,6 @@ static bool tox_event_group_topic_lock_unpack_into( && tox_group_topic_lock_unpack(&event->topic_lock, bu); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -173,16 +170,15 @@ static Tox_Event_Group_Topic_Lock *tox_event_group_topic_lock_alloc(void *user_d return group_topic_lock; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_topic_lock(Tox *tox, uint32_t group_number, Tox_Group_Topic_Lock topic_lock, - void *user_data) +void tox_events_handle_group_topic_lock( + Tox *tox, uint32_t group_number, Tox_Group_Topic_Lock topic_lock, + void *user_data) { Tox_Event_Group_Topic_Lock *group_topic_lock = tox_event_group_topic_lock_alloc(user_data); diff --git a/toxcore/events/group_voice_state.c b/toxcore/events/group_voice_state.c index 91c13b16c8..fba0300389 100644 --- a/toxcore/events/group_voice_state.c +++ b/toxcore/events/group_voice_state.c @@ -16,14 +16,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Group_Voice_State { uint32_t group_number; Tox_Group_Voice_State voice_state; @@ -89,7 +87,6 @@ static bool tox_event_group_voice_state_unpack_into( && tox_group_voice_state_unpack(&event->voice_state, bu); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -173,16 +170,15 @@ static Tox_Event_Group_Voice_State *tox_event_group_voice_state_alloc(void *user return group_voice_state; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_group_voice_state(Tox *tox, uint32_t group_number, Tox_Group_Voice_State voice_state, - void *user_data) +void tox_events_handle_group_voice_state( + Tox *tox, uint32_t group_number, Tox_Group_Voice_State voice_state, + void *user_data) { Tox_Event_Group_Voice_State *group_voice_state = tox_event_group_voice_state_alloc(user_data); diff --git a/toxcore/events/self_connection_status.c b/toxcore/events/self_connection_status.c index 8ecf169cd7..8d8bc803ea 100644 --- a/toxcore/events/self_connection_status.c +++ b/toxcore/events/self_connection_status.c @@ -16,14 +16,12 @@ #include "../tox_pack.h" #include "../tox_unpack.h" - /***************************************************** * * :: struct and accessors * *****************************************************/ - struct Tox_Event_Self_Connection_Status { Tox_Connection connection_status; }; @@ -68,7 +66,6 @@ static bool tox_event_self_connection_status_unpack_into( return tox_connection_unpack(&event->connection_status, bu); } - /***************************************************** * * :: new/free/add/get/size/unpack @@ -152,16 +149,15 @@ static Tox_Event_Self_Connection_Status *tox_event_self_connection_status_alloc( return self_connection_status; } - /***************************************************** * * :: event handler * *****************************************************/ - -void tox_events_handle_self_connection_status(Tox *tox, Tox_Connection connection_status, - void *user_data) +void tox_events_handle_self_connection_status( + Tox *tox, Tox_Connection connection_status, + void *user_data) { Tox_Event_Self_Connection_Status *self_connection_status = tox_event_self_connection_status_alloc(user_data); diff --git a/toxcore/forwarding.h b/toxcore/forwarding.h index 655779f0a4..bd0ef09e1c 100644 --- a/toxcore/forwarding.h +++ b/toxcore/forwarding.h @@ -83,7 +83,6 @@ bool forward_reply(const Networking_Core *net, const IP_Port *forwarder, const uint8_t *sendback, uint16_t sendback_length, const uint8_t *data, uint16_t length); - /** * @brief Set callback to handle a forwarded request. * To reply to the packet, callback should use `forward_reply()` to send a reply diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index cc521bea06..33bfa40d34 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c @@ -67,7 +67,6 @@ struct Friend_Conn { static const Friend_Conn empty_friend_conn = {0}; - struct Friend_Connections { const Mono_Time *mono_time; const Logger *logger; @@ -106,7 +105,6 @@ const IP_Port *friend_conn_get_dht_ip_port(const Friend_Conn *fc) return &fc->dht_ip_port; } - /** * @retval true if the friendcon_id is valid. * @retval false if the friendcon_id is not valid. @@ -119,7 +117,6 @@ static bool friendconn_id_valid(const Friend_Connections *fr_c, int friendcon_id fr_c->conns[friendcon_id].status != FRIENDCONN_STATUS_NONE; } - /** @brief Set the size of the friend connections list to num. * * @retval false if realloc fails. @@ -249,7 +246,7 @@ static int friend_add_tcp_relay(Friend_Connections *fr_c, int friendcon_id, cons if (!net_family_is_unspec(friend_con->dht_ip_port.ip.family)) { ipp_copy.ip = friend_con->dht_ip_port.ip; } else { - friend_con->hosting_tcp_relay = 0; + friend_con->hosting_tcp_relay = false; } } @@ -373,7 +370,7 @@ static void dht_ip_callback(void *object, int32_t number, const IP_Port *ip_port if (friend_con->hosting_tcp_relay) { friend_add_tcp_relay(fr_c, number, ip_port, friend_con->dht_temp_pk); - friend_con->hosting_tcp_relay = 0; + friend_con->hosting_tcp_relay = false; } } @@ -427,7 +424,7 @@ static int handle_status(void *object, int id, bool status, void *userdata) friend_con->status = FRIENDCONN_STATUS_CONNECTING; friend_con->crypt_connection_id = -1; - friend_con->hosting_tcp_relay = 0; + friend_con->hosting_tcp_relay = false; } if (status_changed) { @@ -858,7 +855,6 @@ int kill_friend_connection(Friend_Connections *fr_c, int friendcon_id) return wipe_friend_conn(fr_c, friendcon_id); } - /** @brief Set friend request callback. * * This function will be called every time a friend request packet is received. @@ -912,8 +908,8 @@ int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint3 /** Create new friend_connections instance. */ Friend_Connections *new_friend_connections( - const Logger *logger, const Mono_Time *mono_time, const Network *ns, - Onion_Client *onion_c, bool local_discovery_enabled) + const Logger *logger, const Mono_Time *mono_time, const Network *ns, + Onion_Client *onion_c, bool local_discovery_enabled) { if (onion_c == nullptr) { return nullptr; diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h index efbb668630..bbd4454729 100644 --- a/toxcore/friend_connection.h +++ b/toxcore/friend_connection.h @@ -45,7 +45,6 @@ /** How often we share our TCP relays with each friend connection */ #define SHARE_RELAYS_INTERVAL (60 * 2) - typedef enum Friendconn_Status { FRIENDCONN_STATUS_NONE, FRIENDCONN_STATUS_CONNECTING, @@ -162,8 +161,8 @@ void set_friend_request_callback(Friend_Connections *fr_c, fr_request_cb *fr_req /** Create new friend_connections instance. */ non_null() Friend_Connections *new_friend_connections( - const Logger *logger, const Mono_Time *mono_time, const Network *ns, - Onion_Client *onion_c, bool local_discovery_enabled); + const Logger *logger, const Mono_Time *mono_time, const Network *ns, + Onion_Client *onion_c, bool local_discovery_enabled); /** main friend_connections loop. */ non_null() diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c index 447dd393bd..8b915449cd 100644 --- a/toxcore/friend_requests.c +++ b/toxcore/friend_requests.c @@ -54,7 +54,6 @@ uint32_t get_nospam(const Friend_Requests *fr) return fr->nospam; } - /** Set the function that will be executed when a friend request for us is received. */ void callback_friendrequest(Friend_Requests *fr, fr_friend_request_cb *function, void *object) { @@ -118,7 +117,6 @@ int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk) return -1; } - non_null() static int friendreq_handlepacket(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length, void *userdata) diff --git a/toxcore/group.c b/toxcore/group.c index 4f6ff9de66..14e61e6ffc 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -244,7 +244,6 @@ static bool is_groupnumber_valid(const Group_Chats *g_c, uint32_t groupnumber) && g_c->chats[groupnumber].status != GROUPCHAT_STATUS_NONE; } - /** @brief Set the size of the groupchat list to num. * * @retval false if realloc fails. @@ -430,7 +429,6 @@ static int get_peer_index(const Group_c *g, uint16_t peer_number) return -1; } - non_null() static uint64_t calculate_comp_value(const uint8_t *pk1, const uint8_t *pk2) { @@ -1039,7 +1037,6 @@ static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, return true; } - /** @brief Set the nick for a peer. * * do_gc_callback indicates whether we want to trigger callbacks set by the client @@ -1401,7 +1398,6 @@ static const Group_Peer *peer_in_list(const Group_c *g, uint32_t peernumber, boo return &list[peernumber]; } - /** * @brief Copy the public key of (frozen, if frozen is true) peernumber who is in * groupnumber to pk. @@ -2012,7 +2008,6 @@ static bool group_leave(const Group_Chats *g_c, uint32_t groupnumber, bool perma } } - /** @brief set the group's title, limited to MAX_NAME_LENGTH. * @retval 0 on success * @retval -1 if groupnumber is invalid. @@ -2385,7 +2380,6 @@ static int handle_packet_rejoin(Group_Chats *g_c, int friendcon_id, const uint8_ return 0; } - // we could send title with invite, but then if it changes between sending and accepting inv, joinee won't see it /** @@ -2399,7 +2393,6 @@ static bool send_peer_introduced(const Group_Chats *g_c, int friendcon_id, uint1 return send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, packet, sizeof(packet)); } - /** * @retval true on success. * @retval false on failure @@ -2554,13 +2547,11 @@ static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const u break; } - case PEER_RESPONSE_ID: { handle_send_peers(g_c, groupnumber, data + 1, length - 1, userdata); break; } - case PEER_TITLE_ID: { if (!g->title_fresh) { settitle(g_c, groupnumber, -1, data + 1, length - 1, userdata); @@ -3760,7 +3751,6 @@ bool conferences_load_state_section(Group_Chats *g_c, const uint8_t *data, uint3 return true; } - /** Create new groupchat instance. */ Group_Chats *new_groupchats(const Mono_Time *mono_time, Messenger *m) { diff --git a/toxcore/group.h b/toxcore/group.h index 78c3dfd0fd..5ce03275ec 100644 --- a/toxcore/group.h +++ b/toxcore/group.h @@ -79,7 +79,6 @@ void g_callback_group_connected(Group_Chats *g_c, g_conference_connected_cb *fun non_null() void g_callback_group_message(Group_Chats *g_c, g_conference_message_cb *function); - /** Set callback function for title changes. */ non_null() void g_callback_group_title(Group_Chats *g_c, title_cb *function); @@ -224,7 +223,6 @@ int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_ non_null() int group_title_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *title, uint8_t title_len); - /** @brief return the group's title size. * @retval -1 of groupnumber is invalid. * @retval -2 if title is too long or empty. diff --git a/toxcore/group_announce.c b/toxcore/group_announce.c index 8066dfa1d0..0eb339a76d 100644 --- a/toxcore/group_announce.c +++ b/toxcore/group_announce.c @@ -343,8 +343,8 @@ int gca_unpack_announces_list(const Logger *log, const uint8_t *data, uint16_t l non_null() static GC_Announces *gca_new_announces( - GC_Announces_List *gc_announces_list, - const GC_Public_Announce *public_announce) + GC_Announces_List *gc_announces_list, + const GC_Public_Announce *public_announce) { GC_Announces *announces = (GC_Announces *)calloc(1, sizeof(GC_Announces)); diff --git a/toxcore/group_announce.h b/toxcore/group_announce.h index 77b9326118..72f2cfc1b8 100644 --- a/toxcore/group_announce.h +++ b/toxcore/group_announce.h @@ -83,7 +83,6 @@ struct GC_Announces_List { uint64_t last_timeout_check; }; - /** @brief Returns a new group announces list. * * The caller is responsible for freeing the memory with `kill_gca`. diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index d7e5750f56..aa010b2e33 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -1810,7 +1810,6 @@ non_null() static bool send_peer_mod_list(const GC_Chat *chat, GC_Connection *gc non_null() static bool send_peer_sanctions_list(const GC_Chat *chat, GC_Connection *gconn); non_null() static bool send_peer_topic(const GC_Chat *chat, GC_Connection *gconn); - /** @brief Creates a sync announce for peer designated by `gconn` and puts it in `announce`, which * must be zeroed by the caller. * @@ -2024,7 +2023,6 @@ static int handle_gc_sync_request(GC_Chat *chat, uint32_t peer_number, const uin non_null() static void copy_self(const GC_Chat *chat, GC_Peer *peer); non_null() static bool send_gc_peer_info_request(const GC_Chat *chat, GC_Connection *gconn); - /** @brief Shares our TCP relays with peer and adds shared relays to our connection with them. * * Returns true on success or if we're not connected to any TCP relays. @@ -4398,7 +4396,6 @@ static int handle_gc_set_observer(const GC_Session *c, GC_Chat *chat, uint32_t p return -2; } - if (ret == 1) { return 0; } @@ -5054,8 +5051,6 @@ int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, uint32_t p return ret ? 0 : -5; } - - /** @brief Handles a custom private packet. * * @retval 0 if packet is handled correctly. @@ -7333,7 +7328,7 @@ static int get_new_group_index(GC_Session *c) c->chats[new_index] = empty_gc_chat; - for (size_t i = 0; i < sizeof(c->chats[new_index].saved_invites)/sizeof(*c->chats[new_index].saved_invites); ++i) { + for (size_t i = 0; i < sizeof(c->chats[new_index].saved_invites) / sizeof(*c->chats[new_index].saved_invites); ++i) { c->chats[new_index].saved_invites[i] = -1; } @@ -7850,7 +7845,6 @@ int gc_invite_friend(const GC_Session *c, GC_Chat *chat, int32_t friend_number, memcpy(packet + length, chat->self_public_key, ENC_PUBLIC_KEY_SIZE); length += ENC_PUBLIC_KEY_SIZE; - memcpy(packet + length, chat->shared_state.group_name, group_name_length); length += group_name_length; diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h index e9ce39862d..390d3cb1be 100644 --- a/toxcore/group_chats.h +++ b/toxcore/group_chats.h @@ -572,7 +572,6 @@ int gc_kick_peer(const Messenger *m, int group_number, uint32_t peer_id); non_null(1) nullable(2) void gc_get_chat_id(const GC_Chat *chat, uint8_t *dest); - /** Group callbacks */ non_null(1) nullable(2) void gc_callback_message(const Messenger *m, gc_message_cb *function); non_null(1) nullable(2) void gc_callback_private_message(const Messenger *m, gc_private_message_cb *function); diff --git a/toxcore/group_common.h b/toxcore/group_common.h index ae789fca0a..0c19cb875f 100644 --- a/toxcore/group_common.h +++ b/toxcore/group_common.h @@ -343,7 +343,7 @@ typedef void gc_private_message_cb(const Messenger *m, uint32_t group_number, ui typedef void gc_custom_packet_cb(const Messenger *m, uint32_t group_number, uint32_t peer_id, const uint8_t *data, size_t length, void *user_data); typedef void gc_custom_private_packet_cb(const Messenger *m, uint32_t group_number, uint32_t peer_id, - const uint8_t *data, size_t length, void *user_data); + const uint8_t *data, size_t length, void *user_data); typedef void gc_moderation_cb(const Messenger *m, uint32_t group_number, uint32_t source_peer_number, uint32_t target_peer_number, unsigned int mod_type, void *user_data); typedef void gc_nick_change_cb(const Messenger *m, uint32_t group_number, uint32_t peer_id, const uint8_t *name, diff --git a/toxcore/group_connection.c b/toxcore/group_connection.c index 000f1d51a9..073c89ec13 100644 --- a/toxcore/group_connection.c +++ b/toxcore/group_connection.c @@ -94,7 +94,7 @@ void gcc_set_recv_message_id(GC_Connection *gconn, uint64_t id) */ non_null(1, 2, 3) nullable(4) static bool create_array_entry(const Logger *log, const Mono_Time *mono_time, GC_Message_Array_Entry *array_entry, - const uint8_t *data, uint16_t length, uint8_t packet_type, uint64_t message_id) + const uint8_t *data, uint16_t length, uint8_t packet_type, uint64_t message_id) { if (!array_entry_is_empty(array_entry)) { LOGGER_WARNING(log, "Failed to create array entry; entry is not empty."); @@ -183,7 +183,6 @@ int gcc_send_lossless_packet(const GC_Chat *chat, GC_Connection *gconn, const ui return 0; } - bool gcc_send_lossless_packet_fragments(const GC_Chat *chat, GC_Connection *gconn, const uint8_t *data, uint16_t length, uint8_t packet_type) { diff --git a/toxcore/group_connection.h b/toxcore/group_connection.h index e34551c182..4a9ccad0b3 100644 --- a/toxcore/group_connection.h +++ b/toxcore/group_connection.h @@ -173,7 +173,6 @@ non_null() bool gcc_send_lossless_packet_fragments(const GC_Chat *chat, GC_Connection *gconn, const uint8_t *data, uint16_t length, uint8_t packet_type); - /** @brief Encrypts `data` of `length` bytes, designated by `message_id`, using the shared key * associated with `gconn` and sends lossless packet over the wire. * @@ -185,7 +184,7 @@ bool gcc_send_lossless_packet_fragments(const GC_Chat *chat, GC_Connection *gcon */ non_null(1, 2) nullable(3) int gcc_encrypt_and_send_lossless_packet(const GC_Chat *chat, const GC_Connection *gconn, const uint8_t *data, - uint16_t length, uint64_t message_id, uint8_t packet_type); + uint16_t length, uint64_t message_id, uint8_t packet_type); /** @brief Called when a peer leaves the group. */ non_null() diff --git a/toxcore/group_moderation.c b/toxcore/group_moderation.c index 47d2d0e659..5081ee9fc9 100644 --- a/toxcore/group_moderation.c +++ b/toxcore/group_moderation.c @@ -396,7 +396,6 @@ int sanctions_list_unpack(Mod_Sanction *sanctions, Mod_Sanction_Creds *creds, ui return num; } - /** @brief Creates a new sanction list hash and puts it in hash. * * The hash is derived from the signature of all entries plus the version number. diff --git a/toxcore/list.c b/toxcore/list.c index 34672e3500..bf3db247f1 100644 --- a/toxcore/list.c +++ b/toxcore/list.c @@ -30,8 +30,7 @@ * - some considerations since the array size is never perfect */ -static int32_t -list_index(uint32_t i) +static int32_t list_index(uint32_t i) { return ~i; } @@ -135,7 +134,6 @@ static bool resize(BS_List *list, uint32_t new_size) return true; } - int bs_list_init(BS_List *list, uint32_t element_size, uint32_t initial_capacity, bs_list_cmp_cb *cmp_callback) { // set initial values diff --git a/toxcore/logger.h b/toxcore/logger.h index eff63fa6d6..830db883aa 100644 --- a/toxcore/logger.h +++ b/toxcore/logger.h @@ -70,7 +70,6 @@ void logger_write( /* @brief Terminate the program with a signal. */ void logger_abort(void); - #define LOGGER_WRITE(log, level, ...) \ do { \ if (level >= MIN_LOGGER_LEVEL) { \ diff --git a/toxcore/mono_time.c b/toxcore/mono_time.c index d1e6adaef0..124f94fc23 100644 --- a/toxcore/mono_time.c +++ b/toxcore/mono_time.c @@ -110,7 +110,6 @@ static uint64_t current_time_monotonic_default(void *user_data) #endif /* !__APPLE__ */ #endif /* !OS_WIN32 */ - Mono_Time *mono_time_new(const Memory *mem, mono_time_current_time_cb *current_time_callback, void *user_data) { Mono_Time *mono_time = (Mono_Time *)mem_alloc(mem, sizeof(Mono_Time)); diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index a5bfc78217..1680b078b7 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -299,7 +299,6 @@ static int open_cookie(const Mono_Time *mono_time, uint8_t *bytes, const uint8_t return 0; } - /** @brief Create a cookie response packet and put it in packet. * @param request_plain must be COOKIE_REQUEST_PLAIN_LENGTH bytes. * @param packet must be of size COOKIE_RESPONSE_LENGTH or bigger. @@ -568,7 +567,6 @@ static bool handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t return true; } - non_null() static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id) { @@ -579,7 +577,6 @@ static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_c return &c->crypto_connections[crypt_connection_id]; } - /** @brief Associate an ip_port to a connection. * * @retval -1 on failure. @@ -749,7 +746,6 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t /*** START: Array Related functions */ - /** @brief Return number of packets in array * Note that holes are counted too. */ @@ -1373,7 +1369,6 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32 return num_sent; } - /** @brief Add a new temp packet to send repeatedly. * * @retval -1 on failure. @@ -1435,7 +1430,6 @@ static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id) return 0; } - /** @brief Send the temp packet. * * @retval -1 on failure. @@ -1823,7 +1817,7 @@ static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num) } Crypto_Connection *newcrypto_connections = (Crypto_Connection *)mem_vrealloc( - c->mem, c->crypto_connections, num, sizeof(Crypto_Connection)); + c->mem, c->crypto_connections, num, sizeof(Crypto_Connection)); if (newcrypto_connections == nullptr) { return -1; @@ -1833,7 +1827,6 @@ static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num) return 0; } - /** @brief Create a new empty crypto connection. * * @retval -1 on failure. @@ -2002,7 +1995,6 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id, return -1; } - /** @brief Set function to be called when someone requests a new connection to us. * * The set function should return -1 on failure and 0 on success. @@ -2229,7 +2221,6 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip return 0; } - non_null(1, 3) nullable(5) static int tcp_data_callback(void *object, int crypt_connection_id, const uint8_t *packet, uint16_t length, void *userdata) @@ -2382,7 +2373,7 @@ int send_tcp_forward_request(const Logger *logger, Net_Crypto *c, const IP_Port { pthread_mutex_lock(&c->tcp_mutex); const int ret = tcp_send_forward_request(logger, c->tcp_c, tcp_forwarder, dht_node, - chain_keys, chain_length, data, data_length); + chain_keys, chain_length, data, data_length); pthread_mutex_unlock(&c->tcp_mutex); return ret; @@ -2523,7 +2514,6 @@ int connection_lossy_data_handler(const Net_Crypto *c, int crypt_connection_id, return 0; } - /** @brief Set the function for this friend that will be callbacked with object and number if * the friend sends us a different dht public key than we have associated to him. * diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index 1183222051..0d817e4315 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h @@ -205,7 +205,6 @@ non_null() int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, connection_data_cb *connection_data_callback, void *object, int id); - /** @brief Set function to be called when connection with crypt_connection_id receives a lossy data packet of length. * * The set function should return -1 on failure and 0 on success. diff --git a/toxcore/network.c b/toxcore/network.c index a8d94a3823..69d44d7a2c 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -532,12 +532,14 @@ static int sys_send(void *obj, int sock, const uint8_t *buf, size_t len) } non_null() -static int sys_sendto(void *obj, int sock, const uint8_t *buf, size_t len, const Network_Addr *addr) { +static int sys_sendto(void *obj, int sock, const uint8_t *buf, size_t len, const Network_Addr *addr) +{ return sendto(sock, (const char *)buf, len, 0, (const struct sockaddr *)&addr->addr, addr->size); } non_null() -static int sys_recvfrom(void *obj, int sock, uint8_t *buf, size_t len, Network_Addr *addr) { +static int sys_recvfrom(void *obj, int sock, uint8_t *buf, size_t len, Network_Addr *addr) +{ socklen_t size = addr->size; const int ret = recvfrom(sock, (char *)buf, len, 0, (struct sockaddr *)&addr->addr, &size); addr->size = size; @@ -811,8 +813,8 @@ int net_send(const Network *ns, const Logger *log, non_null() static int net_sendto( - const Network *ns, - Socket sock, const uint8_t *buf, size_t len, const Network_Addr *addr, const IP_Port *ip_port) + const Network *ns, + Socket sock, const uint8_t *buf, size_t len, const Network_Addr *addr, const IP_Port *ip_port) { return ns->funcs->sendto(ns->obj, sock.sock, buf, len, addr); } @@ -890,7 +892,6 @@ bool set_socket_dualstack(const Network *ns, Socket sock) return net_setsockopt(ns, sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, sizeof(ipv6only)) == 0; } - typedef struct Packet_Handler { packet_handler_cb *function; void *object; @@ -1119,8 +1120,8 @@ void networking_poll(const Networking_Core *net, void *userdata) * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other. */ Networking_Core *new_networking_ex( - const Logger *log, const Memory *mem, const Network *ns, const IP *ip, - uint16_t port_from, uint16_t port_to, unsigned int *error) + const Logger *log, const Memory *mem, const Network *ns, const IP *ip, + uint16_t port_from, uint16_t port_to, unsigned int *error) { /* If both from and to are 0, use default port range * If one is 0 and the other is non-0, use the non-0 value as only port @@ -1263,8 +1264,8 @@ Networking_Core *new_networking_ex( #ifndef ESP_PLATFORM /* multicast local nodes */ struct ipv6_mreq mreq = {{{{0}}}}; - mreq.ipv6mr_multiaddr.s6_addr[ 0] = 0xFF; - mreq.ipv6mr_multiaddr.s6_addr[ 1] = 0x02; + mreq.ipv6mr_multiaddr.s6_addr[0] = 0xFF; + mreq.ipv6mr_multiaddr.s6_addr[1] = 0x02; mreq.ipv6mr_multiaddr.s6_addr[15] = 0x01; mreq.ipv6mr_interface = 0; @@ -1381,7 +1382,6 @@ void kill_networking(Networking_Core *net) mem_delete(net->mem, net); } - bool ip_equal(const IP *a, const IP *b) { if (a == nullptr || b == nullptr) { @@ -2014,7 +2014,7 @@ int32_t net_getipport(const Memory *mem, const char *node, IP_Port **res, int to size_t count = 0; for (struct addrinfo *cur = infos; count < max_count && cur != nullptr; cur = cur->ai_next) { - if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) { + if (cur->ai_socktype != 0 && type > 0 && cur->ai_socktype != type) { continue; } @@ -2043,7 +2043,7 @@ int32_t net_getipport(const Memory *mem, const char *node, IP_Port **res, int to *res = ip_port; for (struct addrinfo *cur = infos; cur != nullptr; cur = cur->ai_next) { - if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) { + if (cur->ai_socktype != 0 && type > 0 && cur->ai_socktype != type) { continue; } diff --git a/toxcore/network.h b/toxcore/network.h index 76ede44039..f174ef9ebc 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -148,7 +148,6 @@ typedef enum Net_Packet_Type { NET_PACKET_MAX = 0xff, /* This type must remain within a single uint8. */ } Net_Packet_Type; - #define TOX_PORTRANGE_FROM 33445 #define TOX_PORTRANGE_TO 33545 #define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM @@ -590,8 +589,8 @@ void net_kill_strerror(char *strerror); */ non_null(1, 2, 3, 4) nullable(7) Networking_Core *new_networking_ex( - const Logger *log, const Memory *mem, const Network *ns, const IP *ip, - uint16_t port_from, uint16_t port_to, unsigned int *error); + const Logger *log, const Memory *mem, const Network *ns, const IP *ip, + uint16_t port_from, uint16_t port_to, unsigned int *error); non_null() Networking_Core *new_networking_no_udp(const Logger *log, const Memory *mem, const Network *ns); diff --git a/toxcore/network_test_util.hh b/toxcore/network_test_util.hh index 9a42707d2a..3fe91441e5 100644 --- a/toxcore/network_test_util.hh +++ b/toxcore/network_test_util.hh @@ -52,11 +52,14 @@ class Test_Network : public Network_Class { int recv(void *obj, int sock, uint8_t *buf, size_t len) override; int recvfrom(void *obj, int sock, uint8_t *buf, size_t len, Network_Addr *addr) override; int send(void *obj, int sock, const uint8_t *buf, size_t len) override; - int sendto(void *obj, int sock, const uint8_t *buf, size_t len, const Network_Addr *addr) override; + int sendto( + void *obj, int sock, const uint8_t *buf, size_t len, const Network_Addr *addr) override; int socket(void *obj, int domain, int type, int proto) override; int socket_nonblock(void *obj, int sock, bool nonblock) override; - int getsockopt(void *obj, int sock, int level, int optname, void *optval, size_t *optlen) override; - int setsockopt(void *obj, int sock, int level, int optname, const void *optval, size_t optlen) override; + int getsockopt( + void *obj, int sock, int level, int optname, void *optval, size_t *optlen) override; + int setsockopt( + void *obj, int sock, int level, int optname, const void *optval, size_t optlen) override; int getaddrinfo(void *obj, int family, Network_Addr **addrs) override; int freeaddrinfo(void *obj, Network_Addr *addrs) override; }; diff --git a/toxcore/onion.c b/toxcore/onion.c index 1339d240bf..9fab57af90 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c @@ -33,7 +33,6 @@ #define KEY_REFRESH_INTERVAL (2 * 60 * 60) - // Settings for the shared key cache #define MAX_KEYS_PER_SLOT 4 #define KEYS_TIMEOUT 600 @@ -80,8 +79,8 @@ static int ip_unpack_from_bytes(IP *target, const uint8_t *data, unsigned int da } const bool valid = disable_family_check || - net_family_is_ipv4(target->family) || - net_family_is_ipv6(target->family); + net_family_is_ipv4(target->family) || + net_family_is_ipv6(target->family); return valid ? 0 : -1; } @@ -109,7 +108,6 @@ static int ipport_unpack(IP_Port *target, const uint8_t *data, unsigned int data return 0; } - /** @brief Create a new onion path. * * Create a new onion path out of nodes (nodes is a list of ONION_PATH_LENGTH nodes) @@ -357,7 +355,7 @@ static int handle_send_initial(void *object, const IP_Port *source, const uint8_ } const int len = decrypt_data_symmetric( - shared_key, &packet[nonce_start], &packet[ciphertext_start], ciphertext_length, plain); + shared_key, &packet[nonce_start], &packet[ciphertext_start], ciphertext_length, plain); if (len != plaintext_length) { LOGGER_TRACE(onion->log, "decrypt failed: %d != %d", len, plaintext_length); @@ -553,7 +551,6 @@ static int handle_send_2(void *object, const IP_Port *source, const uint8_t *pac return 0; } - non_null() static int handle_recv_3(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata) { @@ -578,7 +575,7 @@ static int handle_recv_3(void *object, const IP_Port *source, const uint8_t *pac uint8_t plain[SIZE_IPPORT + RETURN_2]; const int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE, - SIZE_IPPORT + RETURN_2 + CRYPTO_MAC_SIZE, plain); + SIZE_IPPORT + RETURN_2 + CRYPTO_MAC_SIZE, plain); if ((uint32_t)len != sizeof(plain)) { return 1; @@ -631,7 +628,7 @@ static int handle_recv_2(void *object, const IP_Port *source, const uint8_t *pac uint8_t plain[SIZE_IPPORT + RETURN_1]; const int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE, - SIZE_IPPORT + RETURN_1 + CRYPTO_MAC_SIZE, plain); + SIZE_IPPORT + RETURN_1 + CRYPTO_MAC_SIZE, plain); if ((uint32_t)len != sizeof(plain)) { return 1; @@ -683,7 +680,7 @@ static int handle_recv_1(void *object, const IP_Port *source, const uint8_t *pac uint8_t plain[SIZE_IPPORT]; const int len = decrypt_data_symmetric(onion->secret_symmetric_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE, - SIZE_IPPORT + CRYPTO_MAC_SIZE, plain); + SIZE_IPPORT + CRYPTO_MAC_SIZE, plain); if ((uint32_t)len != SIZE_IPPORT) { return 1; @@ -744,14 +741,13 @@ Onion *new_onion(const Logger *log, const Memory *mem, const Mono_Time *mono_tim onion->shared_keys_3 = shared_key_cache_new(log, mono_time, mem, secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT); if (onion->shared_keys_1 == nullptr || - onion->shared_keys_2 == nullptr || - onion->shared_keys_3 == nullptr) { + onion->shared_keys_2 == nullptr || + onion->shared_keys_3 == nullptr) { // cppcheck-suppress mismatchAllocDealloc kill_onion(onion); return nullptr; } - networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_INITIAL, &handle_send_initial, onion); networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_1, &handle_send_1, onion); networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_2, &handle_send_2, onion); diff --git a/toxcore/onion.h b/toxcore/onion.h index d0ff5703bd..a5d3554e7b 100644 --- a/toxcore/onion.h +++ b/toxcore/onion.h @@ -109,7 +109,6 @@ int create_onion_packet(const Random *rng, uint8_t *packet, uint16_t max_packet_ const Onion_Path *path, const IP_Port *dest, const uint8_t *data, uint16_t length); - /** @brief Create a onion packet to be sent over tcp. * * Use Onion_Path path to create packet for data of length to dest. @@ -158,5 +157,4 @@ Onion *new_onion(const Logger *log, const Memory *mem, const Mono_Time *mono_tim nullable(1) void kill_onion(Onion *onion); - #endif /* C_TOXCORE_TOXCORE_ONION_H */ diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index b445852f2d..593d81aa2c 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -193,11 +193,11 @@ int create_data_request(const Random *rng, uint8_t *packet, uint16_t max_packet_ * return 0 on success. */ int send_announce_request( - const Logger *log, const Networking_Core *net, const Random *rng, - const Onion_Path *path, const Node_format *dest, - const uint8_t *public_key, const uint8_t *secret_key, - const uint8_t *ping_id, const uint8_t *client_id, - const uint8_t *data_public_key, uint64_t sendback_data) + const Logger *log, const Networking_Core *net, const Random *rng, + const Onion_Path *path, const Node_format *dest, + const uint8_t *public_key, const uint8_t *secret_key, + const uint8_t *ping_id, const uint8_t *client_id, + const uint8_t *data_public_key, uint64_t sendback_data) { uint8_t request[ONION_ANNOUNCE_REQUEST_MIN_SIZE]; int len = create_announce_request(rng, request, sizeof(request), dest->public_key, public_key, secret_key, ping_id, @@ -238,9 +238,9 @@ int send_announce_request( * return 0 on success. */ int send_data_request( - const Logger *log, const Networking_Core *net, const Random *rng, const Onion_Path *path, const IP_Port *dest, - const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce, - const uint8_t *data, uint16_t length) + const Logger *log, const Networking_Core *net, const Random *rng, const Onion_Path *path, const IP_Port *dest, + const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce, + const uint8_t *data, uint16_t length) { uint8_t request[ONION_MAX_DATA_SIZE]; int len = create_data_request(rng, request, sizeof(request), public_key, encrypt_public_key, nonce, data, length); diff --git a/toxcore/onion_announce.h b/toxcore/onion_announce.h index 94f6d92eea..1158093170 100644 --- a/toxcore/onion_announce.h +++ b/toxcore/onion_announce.h @@ -101,11 +101,11 @@ int create_data_request(const Random *rng, uint8_t *packet, uint16_t max_packet_ */ non_null() int send_announce_request( - const Logger *log, const Networking_Core *net, const Random *rng, - const Onion_Path *path, const Node_format *dest, - const uint8_t *public_key, const uint8_t *secret_key, - const uint8_t *ping_id, const uint8_t *client_id, - const uint8_t *data_public_key, uint64_t sendback_data); + const Logger *log, const Networking_Core *net, const Random *rng, + const Onion_Path *path, const Node_format *dest, + const uint8_t *public_key, const uint8_t *secret_key, + const uint8_t *ping_id, const uint8_t *client_id, + const uint8_t *data_public_key, uint64_t sendback_data); /** @brief Create and send an onion data request packet. * @@ -125,10 +125,9 @@ int send_announce_request( */ non_null() int send_data_request( - const Logger *log, const Networking_Core *net, const Random *rng, const Onion_Path *path, const IP_Port *dest, - const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce, - const uint8_t *data, uint16_t length); - + const Logger *log, const Networking_Core *net, const Random *rng, const Onion_Path *path, const IP_Port *dest, + const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce, + const uint8_t *data, uint16_t length); typedef int pack_extra_data_cb(void *object, const Logger *logger, const Mono_Time *mono_time, uint8_t num_nodes, uint8_t *plain, uint16_t plain_size, diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index bc249a125c..9b0ac96102 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -483,17 +483,6 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa return 0; } -/** Does path with path_num exist. */ -non_null() -static bool path_exists(const Mono_Time *mono_time, const Onion_Client_Paths *onion_paths, uint32_t path_num) -{ - if (path_timed_out(mono_time, onion_paths, path_num)) { - return false; - } - - return onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num; -} - /** Set path timeouts, return the path number. */ non_null() static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t path_num) @@ -1714,7 +1703,6 @@ int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_p return dht_getfriendip(onion_c->dht, dht_public_key, ip_port); } - /** @brief Set if friend is online or not. * * NOTE: This function is there and should be used so that we don't send @@ -1887,7 +1875,6 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) } } - /** Function to call when onion data packet with contents beginning with byte is received. */ void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_cb *cb, void *object) { @@ -1919,6 +1906,33 @@ static bool key_list_contains(const uint8_t *const *keys, uint16_t keys_size, co return false; } +/** Does path with path_num exist. */ +non_null() +static bool path_exists(const Mono_Time *mono_time, const Onion_Client_Paths *onion_paths, uint32_t path_num) +{ + if (path_timed_out(mono_time, onion_paths, path_num)) { + return false; + } + + return onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num; +} + +/** + * A node/path is considered "stable" if it has survived for at least TIME_TO_STABLE + * and the latest packets sent to it are not timing out. + */ +non_null() +static bool path_is_stable(const Mono_Time *mono_time, const Onion_Client_Paths *paths, + uint32_t pathnum, const Onion_Node *node) +{ + return mono_time_is_timeout(mono_time, node->added_time, TIME_TO_STABLE) + && !(node->pings_since_last_response > 0 + && mono_time_is_timeout(mono_time, node->last_pinged, ONION_NODE_TIMEOUT)) + && mono_time_is_timeout(mono_time, paths->path_creation_time[pathnum], TIME_TO_STABLE) + && !(paths->last_path_used_times[pathnum] > 0 + && mono_time_is_timeout(mono_time, paths->last_path_used[pathnum], ONION_PATH_TIMEOUT)); +} + non_null() static void do_announce(Onion_Client *onion_c) { @@ -1942,7 +1956,6 @@ static void do_announce(Onion_Client *onion_c) continue; } - unsigned int interval = ANNOUNCE_INTERVAL_NOT_ANNOUNCED; if (node_list[i].is_stored != 0 @@ -1951,16 +1964,8 @@ static void do_announce(Onion_Client *onion_c) const uint32_t pathnum = node_list[i].path_used % NUMBER_ONION_PATHS; - /* A node/path is considered "stable", and can be pinged less - * aggressively, if it has survived for at least TIME_TO_STABLE - * and the latest packets sent to it are not timing out. - */ - if (mono_time_is_timeout(onion_c->mono_time, node_list[i].added_time, TIME_TO_STABLE) - && !(node_list[i].pings_since_last_response > 0 - && mono_time_is_timeout(onion_c->mono_time, node_list[i].last_pinged, ONION_NODE_TIMEOUT)) - && mono_time_is_timeout(onion_c->mono_time, onion_c->onion_paths_self.path_creation_time[pathnum], TIME_TO_STABLE) - && !(onion_c->onion_paths_self.last_path_used_times[pathnum] > 0 - && mono_time_is_timeout(onion_c->mono_time, onion_c->onion_paths_self.last_path_used[pathnum], ONION_PATH_TIMEOUT))) { + /* If a node/path is considered "stable", it can be pinged less aggressively. */ + if (path_is_stable(onion_c->mono_time, &onion_c->onion_paths_self, pathnum, &node_list[i])) { interval = ANNOUNCE_INTERVAL_STABLE; } } @@ -2029,7 +2034,7 @@ static void do_announce(Onion_Client *onion_c) } else { Ip_Ntoa ip_str; LOGGER_TRACE(onion_c->logger, "not sending repeated announce request to %s:%d", - net_ip_ntoa(&target->ip_port.ip, &ip_str), net_ntohs(target->ip_port.port)); + net_ip_ntoa(&target->ip_port.ip, &ip_str), net_ntohs(target->ip_port.port)); } } } diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index d64bcc30cd..61e4e6fd1c 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h @@ -220,7 +220,6 @@ Onion_Client *new_onion_client(const Logger *logger, const Memory *mem, const Ra nullable(1) void kill_onion_client(Onion_Client *onion_c); - typedef enum Onion_Connection_Status { /** We are not connected to the network. */ ONION_CONNECTION_STATUS_NONE = 0, diff --git a/toxcore/ping.c b/toxcore/ping.c index efb4b02971..303c418cea 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c @@ -28,7 +28,6 @@ /** Ping newly announced nodes to ping per TIME_TO_PING seconds*/ #define TIME_TO_PING 2 - struct Ping { const Mono_Time *mono_time; const Random *rng; @@ -39,7 +38,6 @@ struct Ping { uint64_t last_to_ping; }; - #define PING_PLAIN_SIZE (1 + sizeof(uint64_t)) #define DHT_PING_SIZE (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + PING_PLAIN_SIZE + CRYPTO_MAC_SIZE) #define PING_DATA_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(IP_Port)) @@ -54,7 +52,6 @@ void ping_send_request(Ping *ping, const IP_Port *ipp, const uint8_t *public_key return; } - // generate key to encrypt ping_id with recipient privkey const uint8_t *shared_key = dht_get_shared_key_sent(ping->dht, public_key); // Generate random ping_id. @@ -75,7 +72,6 @@ void ping_send_request(Ping *ping, const IP_Port *ipp, const uint8_t *public_key pk_copy(pk + 1, dht_get_self_public_key(ping->dht)); // Our pubkey random_nonce(ping->rng, pk + 1 + CRYPTO_PUBLIC_KEY_SIZE); // Generate new nonce - rc = encrypt_data_symmetric(shared_key, pk + 1 + CRYPTO_PUBLIC_KEY_SIZE, ping_plain, sizeof(ping_plain), @@ -302,7 +298,6 @@ int32_t ping_add(Ping *ping, const uint8_t *public_key, const IP_Port *ip_port) return -1; } - /** @brief Ping all the valid nodes in the to_ping list every TIME_TO_PING seconds. * This function must be run at least once every TIME_TO_PING seconds. */ @@ -336,7 +331,6 @@ void ping_iterate(Ping *ping) } } - Ping *ping_new(const Memory *mem, const Mono_Time *mono_time, const Random *rng, DHT *dht) { Ping *ping = (Ping *)mem_alloc(mem, sizeof(Ping)); diff --git a/toxcore/shared_key_cache.c b/toxcore/shared_key_cache.c index 3d5769a4a3..80d74aecb4 100644 --- a/toxcore/shared_key_cache.c +++ b/toxcore/shared_key_cache.c @@ -22,7 +22,7 @@ typedef struct Shared_Key { struct Shared_Key_Cache { Shared_Key *keys; - const uint8_t* self_secret_key; + const uint8_t *self_secret_key; uint64_t timeout; /** After this time (in seconds), a key is erased on the next housekeeping cycle */ const Mono_Time *mono_time; const Memory *mem; @@ -31,7 +31,8 @@ struct Shared_Key_Cache { }; non_null() -static bool shared_key_is_empty(const Logger *log, const Shared_Key *k) { +static bool shared_key_is_empty(const Logger *log, const Shared_Key *k) +{ LOGGER_ASSERT(log, k != nullptr, "shared key must not be NULL"); /* * Since time can never be 0, we use that to determine if a key slot is empty. @@ -41,8 +42,9 @@ static bool shared_key_is_empty(const Logger *log, const Shared_Key *k) { } non_null() -static void shared_key_set_empty(const Logger *log, Shared_Key *k) { - crypto_memzero(k, sizeof (Shared_Key)); +static void shared_key_set_empty(const Logger *log, Shared_Key *k) +{ + crypto_memzero(k, sizeof(Shared_Key)); LOGGER_ASSERT(log, shared_key_is_empty(log, k), "shared key must be empty after clearing it"); } @@ -94,8 +96,8 @@ void shared_key_cache_free(Shared_Key_Cache *cache) const size_t cache_size = 256 * cache->keys_per_slot; // Don't leave key material in memory - crypto_memzero(cache->keys, cache_size * sizeof (Shared_Key)); - crypto_memunlock(cache->keys, cache_size * sizeof (Shared_Key)); + crypto_memzero(cache->keys, cache_size * sizeof(Shared_Key)); + crypto_memunlock(cache->keys, cache_size * sizeof(Shared_Key)); mem_delete(cache->mem, cache->keys); mem_delete(cache->mem, cache); } @@ -107,12 +109,12 @@ const uint8_t *shared_key_cache_lookup(Shared_Key_Cache *cache, const uint8_t pu const uint64_t cur_time = mono_time_get(cache->mono_time); // We can't use the first and last bytes because they are masked in curve25519. Selected 8 for good alignment. const uint8_t bucket_idx = public_key[8]; - Shared_Key* bucket_start = &cache->keys[bucket_idx*cache->keys_per_slot]; + Shared_Key *bucket_start = &cache->keys[bucket_idx * cache->keys_per_slot]; - const uint8_t* found = nullptr; + const uint8_t *found = nullptr; // Perform lookup - for(size_t i = 0; i < cache->keys_per_slot; ++i) { + for (size_t i = 0; i < cache->keys_per_slot; ++i) { if (shared_key_is_empty(cache->log, &bucket_start[i])) { continue; } diff --git a/toxcore/shared_key_cache.h b/toxcore/shared_key_cache.h index 18536e07ec..f6e84c3130 100644 --- a/toxcore/shared_key_cache.h +++ b/toxcore/shared_key_cache.h @@ -30,9 +30,9 @@ typedef struct Shared_Key_Cache Shared_Key_Cache; */ non_null() Shared_Key_Cache *shared_key_cache_new( - const Logger *log, const Mono_Time *mono_time, const Memory *mem, - const uint8_t *self_secret_key, - uint64_t timeout, uint8_t keys_per_slot); + const Logger *log, const Mono_Time *mono_time, const Memory *mem, + const uint8_t *self_secret_key, + uint64_t timeout, uint8_t keys_per_slot); /** * @brief Deletes the cache and frees all resources. @@ -50,6 +50,6 @@ void shared_key_cache_free(Shared_Key_Cache *cache); * @return nullptr on error. */ non_null() -const uint8_t* shared_key_cache_lookup(Shared_Key_Cache *cache, const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]); +const uint8_t *shared_key_cache_lookup(Shared_Key_Cache *cache, const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]); #endif /* C_TOXCORE_TOXCORE_SHARED_KEY_CACHE_H */ diff --git a/toxcore/state.c b/toxcore/state.c index 09d82726b3..6835ca0007 100644 --- a/toxcore/state.c +++ b/toxcore/state.c @@ -18,7 +18,6 @@ int state_load(const Logger *log, state_load_cb *state_load_callback, void *oute return -1; } - const uint32_t size_head = sizeof(uint32_t) * 2; while (length >= size_head) { diff --git a/toxcore/timed_auth.c b/toxcore/timed_auth.c index 415cec2bc8..875003257b 100644 --- a/toxcore/timed_auth.c +++ b/toxcore/timed_auth.c @@ -10,7 +10,7 @@ #include "crypto_core.h" #include "mono_time.h" -non_null(1,6) nullable(4) +non_null(1, 6) nullable(4) static void create_timed_auth_to_hash(const Mono_Time *mono_time, uint16_t timeout, bool previous, const uint8_t *data, uint16_t length, uint8_t *to_hash) { diff --git a/toxcore/tox.c b/toxcore/tox.c index 8b26bb022a..5718b61d5b 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -670,7 +670,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) return nullptr; } - Messenger_Options m_options = {0}; + Messenger_Options m_options = {false}; bool load_savedata_sk = false; bool load_savedata_tox = false; @@ -1153,7 +1153,6 @@ Tox_Connection tox_self_get_connection_status(const Tox *tox) return TOX_CONNECTION_NONE; } - void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback) { assert(tox != nullptr); @@ -3105,7 +3104,6 @@ bool tox_group_disconnect(const Tox *tox, uint32_t group_number, Tox_Err_Group_D return false; } - const bool ret = gc_disconnect_from_group(tox->m->group_handler, chat); tox_unlock(tox); @@ -3856,8 +3854,8 @@ bool tox_group_get_password(const Tox *tox, uint32_t group_number, uint8_t *pass } Tox_Group_Message_Id tox_group_send_message( - const Tox *tox, uint32_t group_number, Tox_Message_Type type, const uint8_t *message, - size_t length, Tox_Err_Group_Send_Message *error) + const Tox *tox, uint32_t group_number, Tox_Message_Type type, const uint8_t *message, + size_t length, Tox_Err_Group_Send_Message *error) { assert(tox != nullptr); diff --git a/toxcore/tox.h b/toxcore/tox.h index 2844009556..7223a8477d 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -124,7 +124,6 @@ extern "C" { typedef struct Tox Tox; #endif /* TOX_DEFINED */ - /** @{ * @name API version */ @@ -202,7 +201,6 @@ bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch); /** @} */ - /** @{ * @name Numeric constants * @@ -344,7 +342,6 @@ uint32_t tox_max_hostname_length(void); /** @} */ - /** @{ * @name Global enumerations */ @@ -375,7 +372,6 @@ typedef enum Tox_User_Status { const char *tox_user_status_to_string(Tox_User_Status value); - /** * @brief Represents message types for tox_friend_send_message and conference * messages. @@ -399,7 +395,6 @@ const char *tox_message_type_to_string(Tox_Message_Type value); /** @} */ - /** @{ * @name Startup options */ @@ -428,7 +423,6 @@ typedef enum Tox_Proxy_Type { const char *tox_proxy_type_to_string(Tox_Proxy_Type value); - /** * @brief Type of savedata to create the Tox instance from. */ @@ -453,7 +447,6 @@ typedef enum Tox_Savedata_Type { const char *tox_savedata_type_to_string(Tox_Savedata_Type value); - /** * @brief Severity level of log messages. */ @@ -488,7 +481,6 @@ typedef enum Tox_Log_Level { const char *tox_log_level_to_string(Tox_Log_Level value); - /** * @brief This event is triggered when the toxcore library logs an events_alloc message. * @@ -510,7 +502,6 @@ const char *tox_log_level_to_string(Tox_Log_Level value); typedef void tox_log_cb(Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func, const char *message, void *user_data); - /** * @brief Operating system functions used by Tox. * @@ -520,7 +511,6 @@ typedef void tox_log_cb(Tox *tox, Tox_Log_Level level, const char *file, uint32_ */ typedef struct Tox_System Tox_System; - /** * @brief This struct contains all the startup options for Tox. * @@ -549,7 +539,6 @@ struct Tox_Options { */ bool ipv6_enabled; - /** * Enable the use of UDP communication when available. * @@ -561,7 +550,6 @@ struct Tox_Options { */ bool udp_enabled; - /** * Enable local network peer discovery. * @@ -569,7 +557,6 @@ struct Tox_Options { */ bool local_discovery_enabled; - /** * Enable storing DHT announcements and forwarding corresponding requests. * @@ -582,7 +569,6 @@ struct Tox_Options { */ Tox_Proxy_Type proxy_type; - /** * The IP address or DNS name of the proxy to be used. * @@ -597,7 +583,6 @@ struct Tox_Options { */ const char *proxy_host; - /** * The port to use to connect to the proxy server. * @@ -606,7 +591,6 @@ struct Tox_Options { */ uint16_t proxy_port; - /** * The start port of the inclusive port range to attempt to use. * @@ -621,13 +605,11 @@ struct Tox_Options { */ uint16_t start_port; - /** * The end port of the inclusive port range to attempt to use. */ uint16_t end_port; - /** * The port to use for the TCP server (relay). If 0, the TCP server is * disabled. @@ -641,19 +623,16 @@ struct Tox_Options { */ uint16_t tcp_port; - /** * Enables or disables UDP hole-punching in toxcore. (Default: enabled). */ bool hole_punching_enabled; - /** * The type of savedata to load from. */ Tox_Savedata_Type savedata_type; - /** * The savedata. * @@ -662,25 +641,21 @@ struct Tox_Options { */ const uint8_t *savedata_data; - /** * The length of the savedata. */ size_t savedata_length; - /** * Logging callback for the new tox instance. */ tox_log_cb *log_callback; - /** * User data pointer passed to the logging callback. */ void *log_user_data; - /** * These options are experimental, so avoid writing code that depends on * them. Options marked "experimental" may change their behaviour or go away @@ -702,7 +677,6 @@ struct Tox_Options { }; - bool tox_options_get_ipv6_enabled(const Tox_Options *options); void tox_options_set_ipv6_enabled(Tox_Options *options, bool ipv6_enabled); @@ -804,7 +778,6 @@ typedef enum Tox_Err_Options_New { const char *tox_err_options_new_to_string(Tox_Err_Options_New value); - /** * @brief Allocates a new Tox_Options object and initialises it with the default * options. @@ -829,7 +802,6 @@ void tox_options_free(Tox_Options *options); /** @} */ - /** @{ * @name Creation and destruction */ @@ -898,7 +870,6 @@ typedef enum Tox_Err_New { const char *tox_err_new_to_string(Tox_Err_New value); - /** * @brief Creates and initialises a new Tox instance with the options passed. * @@ -944,7 +915,6 @@ void tox_get_savedata(const Tox *tox, uint8_t savedata[]); /** @} */ - /** @{ * @name Connection lifecycle and event loop */ @@ -977,7 +947,6 @@ typedef enum Tox_Err_Bootstrap { const char *tox_err_bootstrap_to_string(Tox_Err_Bootstrap value); - /** * @brief Sends a "get nodes" request to the given bootstrap node with IP, port, * and public key to setup connections. @@ -1062,7 +1031,6 @@ Tox_Connection tox_self_get_connection_status(const Tox *tox); */ typedef void tox_self_connection_status_cb(Tox *tox, Tox_Connection connection_status, void *user_data); - /** * @brief Set the callback for the `self_connection_status` event. * @@ -1092,7 +1060,6 @@ void tox_iterate(Tox *tox, void *user_data); /** @} */ - /** @{ * @name Internal client information (Tox address/id) */ @@ -1144,7 +1111,6 @@ void tox_self_get_secret_key(const Tox *tox, uint8_t secret_key[TOX_SECRET_KEY_S /** @} */ - /** @{ * @name User-visible client information (nickname/status) */ @@ -1174,7 +1140,6 @@ typedef enum Tox_Err_Set_Info { const char *tox_err_set_info_to_string(Tox_Err_Set_Info value); - /** * @brief Set the nickname for the Tox client. * @@ -1220,7 +1185,7 @@ void tox_self_get_name(const Tox *tox, uint8_t name[]); * user status is set back to empty. */ bool tox_self_set_status_message( - Tox *tox, const uint8_t status_message[], size_t length, Tox_Err_Set_Info *error); + Tox *tox, const uint8_t status_message[], size_t length, Tox_Err_Set_Info *error); /** * @brief Return the length of the current status message as passed to tox_self_set_status_message. @@ -1260,7 +1225,6 @@ Tox_User_Status tox_self_get_status(const Tox *tox); /** @} */ - /** @{ * @name Friend list management */ @@ -1321,7 +1285,6 @@ typedef enum Tox_Err_Friend_Add { const char *tox_err_friend_add_to_string(Tox_Err_Friend_Add value); - /** * @brief Add a friend to the friend list and send a friend request. * @@ -1346,9 +1309,9 @@ const char *tox_err_friend_add_to_string(Tox_Err_Friend_Add value); * @return the friend number on success, an unspecified value on failure. */ Tox_Friend_Number tox_friend_add( - Tox *tox, const uint8_t address[TOX_ADDRESS_SIZE], - const uint8_t message[], size_t length, - Tox_Err_Friend_Add *error); + Tox *tox, const uint8_t address[TOX_ADDRESS_SIZE], + const uint8_t message[], size_t length, + Tox_Err_Friend_Add *error); /** * @brief Add a friend without sending a friend request. @@ -1369,7 +1332,7 @@ Tox_Friend_Number tox_friend_add( * @see tox_friend_add for a more detailed description of friend numbers. */ Tox_Friend_Number tox_friend_add_norequest( - Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Friend_Add *error); + Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Friend_Add *error); typedef enum Tox_Err_Friend_Delete { @@ -1387,7 +1350,6 @@ typedef enum Tox_Err_Friend_Delete { const char *tox_err_friend_delete_to_string(Tox_Err_Friend_Delete value); - /** * @brief Remove a friend from the friend list. * @@ -1403,7 +1365,6 @@ bool tox_friend_delete(Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend /** @} */ - /** @{ * @name Friend list queries */ @@ -1429,7 +1390,6 @@ typedef enum Tox_Err_Friend_By_Public_Key { const char *tox_err_friend_by_public_key_to_string(Tox_Err_Friend_By_Public_Key value); - /** * @brief Return the friend number associated with that Public Key. * @@ -1478,7 +1438,6 @@ typedef enum Tox_Err_Friend_Get_Public_Key { const char *tox_err_friend_get_public_key_to_string(Tox_Err_Friend_Get_Public_Key value); - /** * @brief Copies the Public Key associated with a given friend number to a byte array. * @@ -1489,8 +1448,8 @@ const char *tox_err_friend_get_public_key_to_string(Tox_Err_Friend_Get_Public_Ke * @return true on success. */ bool tox_friend_get_public_key( - const Tox *tox, Tox_Friend_Number friend_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE], - Tox_Err_Friend_Get_Public_Key *error); + const Tox *tox, Tox_Friend_Number friend_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE], + Tox_Err_Friend_Get_Public_Key *error); typedef enum Tox_Err_Friend_Get_Last_Online { @@ -1508,7 +1467,6 @@ typedef enum Tox_Err_Friend_Get_Last_Online { const char *tox_err_friend_get_last_online_to_string(Tox_Err_Friend_Get_Last_Online value); - /** * @brief Return a unix-time timestamp of the last time the friend associated with a given * friend number was seen online. @@ -1518,11 +1476,10 @@ const char *tox_err_friend_get_last_online_to_string(Tox_Err_Friend_Get_Last_Onl * @param friend_number The friend number you want to query. */ uint64_t tox_friend_get_last_online( - const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Get_Last_Online *error); + const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Get_Last_Online *error); /** @} */ - /** @{ * @name Friend-specific state queries (can also be received through callbacks) */ @@ -1553,7 +1510,6 @@ typedef enum Tox_Err_Friend_Query { const char *tox_err_friend_query_to_string(Tox_Err_Friend_Query value); - /** * @brief Return the length of the friend's name. * @@ -1563,7 +1519,7 @@ const char *tox_err_friend_query_to_string(Tox_Err_Friend_Query value); * `friend_name` callback. */ size_t tox_friend_get_name_size( - const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); + const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); /** * @brief Write the name of the friend designated by the given friend number to a byte @@ -1580,7 +1536,7 @@ size_t tox_friend_get_name_size( * @return true on success. */ bool tox_friend_get_name( - const Tox *tox, Tox_Friend_Number friend_number, uint8_t name[], Tox_Err_Friend_Query *error); + const Tox *tox, Tox_Friend_Number friend_number, uint8_t name[], Tox_Err_Friend_Query *error); /** * @param friend_number The friend number of the friend whose name changed. @@ -1590,9 +1546,8 @@ bool tox_friend_get_name( * tox_friend_get_name_size. */ typedef void tox_friend_name_cb( - Tox *tox, Tox_Friend_Number friend_number, - const uint8_t name[], size_t length, void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, + const uint8_t name[], size_t length, void *user_data); /** * @brief Set the callback for the `friend_name` event. @@ -1609,7 +1564,7 @@ void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback); * If the friend number isinvalid, the return value is SIZE_MAX. */ size_t tox_friend_get_status_message_size( - const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); + const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); /** * @brief Write the status message of the friend designated by the given friend number to a byte @@ -1624,8 +1579,8 @@ size_t tox_friend_get_status_message_size( * @param status_message A valid memory region large enough to store the friend's status message. */ bool tox_friend_get_status_message( - const Tox *tox, Tox_Friend_Number friend_number, uint8_t status_message[], - Tox_Err_Friend_Query *error); + const Tox *tox, Tox_Friend_Number friend_number, uint8_t status_message[], + Tox_Err_Friend_Query *error); /** * @param friend_number The friend number of the friend whose status message @@ -1636,9 +1591,8 @@ bool tox_friend_get_status_message( * tox_friend_get_status_message_size. */ typedef void tox_friend_status_message_cb( - Tox *tox, Tox_Friend_Number friend_number, - const uint8_t message[], size_t length, void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, + const uint8_t message[], size_t length, void *user_data); /** * @brief Set the callback for the `friend_status_message` event. @@ -1661,7 +1615,7 @@ void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb * * in the client state. */ Tox_User_Status tox_friend_get_status( - const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); + const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); /** * @param friend_number The friend number of the friend whose user status @@ -1669,8 +1623,7 @@ Tox_User_Status tox_friend_get_status( * @param status The new user status. */ typedef void tox_friend_status_cb( - Tox *tox, Tox_Friend_Number friend_number, Tox_User_Status status, void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, Tox_User_Status status, void *user_data); /** * @brief Set the callback for the `friend_status` event. @@ -1697,7 +1650,7 @@ void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback); * in the client state. */ Tox_Connection tox_friend_get_connection_status( - const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); + const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); /** * @param friend_number The friend number of the friend whose connection status @@ -1706,8 +1659,7 @@ Tox_Connection tox_friend_get_connection_status( * tox_friend_get_connection_status on the passed friend_number. */ typedef void tox_friend_connection_status_cb( - Tox *tox, Tox_Friend_Number friend_number, Tox_Connection connection_status, void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, Tox_Connection connection_status, void *user_data); /** * @brief Set the callback for the `friend_connection_status` event. @@ -1735,7 +1687,7 @@ void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_statu * in the client state. */ bool tox_friend_get_typing( - const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); + const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); /** * @param friend_number The friend number of the friend who started or stopped @@ -1744,8 +1696,7 @@ bool tox_friend_get_typing( * friend_number. */ typedef void tox_friend_typing_cb( - Tox *tox, Tox_Friend_Number friend_number, bool typing, void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, bool typing, void *user_data); /** * @brief Set the callback for the `friend_typing` event. @@ -1758,7 +1709,6 @@ void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback); /** @} */ - /** @{ * @name Sending private messages */ @@ -1779,7 +1729,6 @@ typedef enum Tox_Err_Set_Typing { const char *tox_err_set_typing_to_string(Tox_Err_Set_Typing value); - /** * @brief Set the client's typing status for a friend. * @@ -1791,7 +1740,7 @@ const char *tox_err_set_typing_to_string(Tox_Err_Set_Typing value); * @return true on success. */ bool tox_self_set_typing( - Tox *tox, Tox_Friend_Number friend_number, bool typing, Tox_Err_Set_Typing *error); + Tox *tox, Tox_Friend_Number friend_number, bool typing, Tox_Err_Set_Typing *error); typedef enum Tox_Err_Friend_Send_Message { @@ -1860,8 +1809,8 @@ typedef uint32_t Tox_Friend_Message_Id; * @param length Length of the message to be sent. */ Tox_Friend_Message_Id tox_friend_send_message( - Tox *tox, Tox_Friend_Number friend_number, Tox_Message_Type type, - const uint8_t message[], size_t length, Tox_Err_Friend_Send_Message *error); + Tox *tox, Tox_Friend_Number friend_number, Tox_Message_Type type, + const uint8_t message[], size_t length, Tox_Err_Friend_Send_Message *error); /** * @param friend_number The friend number of the friend who received the message. @@ -1869,8 +1818,7 @@ Tox_Friend_Message_Id tox_friend_send_message( * corresponding to the message sent. */ typedef void tox_friend_read_receipt_cb( - Tox *tox, Tox_Friend_Number friend_number, Tox_Friend_Message_Id message_id, void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, Tox_Friend_Message_Id message_id, void *user_data); /** * @brief Set the callback for the `friend_read_receipt` event. @@ -1884,7 +1832,6 @@ void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *call /** @} */ - /** @{ * @name Receiving private messages and friend requests */ @@ -1895,10 +1842,9 @@ void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *call * @param length The size of the message byte array. */ typedef void tox_friend_request_cb( - Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], - const uint8_t message[], size_t length, - void *user_data); - + Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], + const uint8_t message[], size_t length, + void *user_data); /** * @brief Set the callback for the `friend_request` event. @@ -1915,9 +1861,8 @@ void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback); * @param length The size of the message byte array. */ typedef void tox_friend_message_cb( - Tox *tox, Tox_Friend_Number friend_number, Tox_Message_Type type, - const uint8_t message[], size_t length, void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, Tox_Message_Type type, + const uint8_t message[], size_t length, void *user_data); /** * @brief Set the callback for the `friend_message` event. @@ -1930,7 +1875,6 @@ void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback); /** @} */ - /** @{ * @name File transmission: common between sending and receiving */ @@ -1999,7 +1943,6 @@ enum Tox_File_Kind { }; - typedef enum Tox_File_Control { /** @@ -2026,7 +1969,6 @@ typedef enum Tox_File_Control { const char *tox_file_control_to_string(Tox_File_Control value); - typedef enum Tox_Err_File_Control { /** @@ -2074,7 +2016,6 @@ typedef enum Tox_Err_File_Control { const char *tox_err_file_control_to_string(Tox_Err_File_Control value); - /** * @brief Sends a file control command to a friend for a given file transfer. * @@ -2086,8 +2027,8 @@ const char *tox_err_file_control_to_string(Tox_Err_File_Control value); * @return true on success. */ bool tox_file_control( - Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, Tox_File_Control control, - Tox_Err_File_Control *error); + Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, Tox_File_Control control, + Tox_Err_File_Control *error); /** * @brief When receiving TOX_FILE_CONTROL_CANCEL, the client should release the @@ -2099,9 +2040,8 @@ bool tox_file_control( * @param control The file control command received. */ typedef void tox_file_recv_control_cb( - Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, Tox_File_Control control, - void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, Tox_File_Control control, + void *user_data); /** * @brief Set the callback for the `file_recv_control` event. @@ -2154,7 +2094,6 @@ typedef enum Tox_Err_File_Seek { const char *tox_err_file_seek_to_string(Tox_Err_File_Seek value); - /** * @brief Sends a file seek control command to a friend for a given file transfer. * @@ -2167,7 +2106,7 @@ const char *tox_err_file_seek_to_string(Tox_Err_File_Seek value); * @param position The position that the file should be seeked to. */ bool tox_file_seek( - Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, Tox_Err_File_Seek *error); + Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, Tox_Err_File_Seek *error); typedef enum Tox_Err_File_Get { @@ -2195,7 +2134,6 @@ typedef enum Tox_Err_File_Get { const char *tox_err_file_get_to_string(Tox_Err_File_Get value); - /** * @brief Copy the file id associated to the file transfer to a byte array. * @@ -2208,13 +2146,12 @@ const char *tox_err_file_get_to_string(Tox_Err_File_Get value); * @return true on success. */ bool tox_file_get_file_id( - const Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, - uint8_t file_id[TOX_FILE_ID_LENGTH], - Tox_Err_File_Get *error); + const Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, + uint8_t file_id[TOX_FILE_ID_LENGTH], + Tox_Err_File_Get *error); /** @} */ - /** @{ * @name File transmission: sending */ @@ -2256,7 +2193,6 @@ typedef enum Tox_Err_File_Send { const char *tox_err_file_send_to_string(Tox_Err_File_Send value); - /** * @brief Send a file transmission request. * @@ -2316,9 +2252,9 @@ const char *tox_err_file_send_to_string(Tox_Err_File_Send value); * should not be relied on. */ Tox_File_Number tox_file_send( - Tox *tox, Tox_Friend_Number friend_number, uint32_t kind, uint64_t file_size, - const uint8_t file_id[TOX_FILE_ID_LENGTH], const uint8_t filename[], size_t filename_length, - Tox_Err_File_Send *error); + Tox *tox, Tox_Friend_Number friend_number, uint32_t kind, uint64_t file_size, + const uint8_t file_id[TOX_FILE_ID_LENGTH], const uint8_t filename[], size_t filename_length, + Tox_Err_File_Send *error); typedef enum Tox_Err_File_Send_Chunk { @@ -2374,7 +2310,6 @@ typedef enum Tox_Err_File_Send_Chunk { const char *tox_err_file_send_chunk_to_string(Tox_Err_File_Send_Chunk value); - /** * @brief Send a chunk of file data to a friend. * @@ -2392,8 +2327,8 @@ const char *tox_err_file_send_chunk_to_string(Tox_Err_File_Send_Chunk value); * @return true on success. */ bool tox_file_send_chunk( - Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, - const uint8_t data[], size_t length, Tox_Err_File_Send_Chunk *error); + Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, + const uint8_t data[], size_t length, Tox_Err_File_Send_Chunk *error); /** * If the length parameter is 0, the file transfer is finished, and the client's @@ -2418,9 +2353,8 @@ bool tox_file_send_chunk( * @param length The number of bytes requested for the current chunk. */ typedef void tox_file_chunk_request_cb( - Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, - size_t length, void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, + size_t length, void *user_data); /** * @brief Set the callback for the `file_chunk_request` event. @@ -2433,7 +2367,6 @@ void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callba /** @} */ - /** @{ * @name File transmission: receiving */ @@ -2457,9 +2390,8 @@ void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callba * @param filename_length Size in bytes of the filename. */ typedef void tox_file_recv_cb( - Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint32_t kind, uint64_t file_size, - const uint8_t filename[], size_t filename_length, void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint32_t kind, uint64_t file_size, + const uint8_t filename[], size_t filename_length, void *user_data); /** * @brief Set the callback for the `file_recv` event. @@ -2487,9 +2419,8 @@ void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback); * @param length The length of the received chunk. */ typedef void tox_file_recv_chunk_cb( - Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, - const uint8_t data[], size_t length, void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, + const uint8_t data[], size_t length, void *user_data); /** * @brief Set the callback for the `file_recv_chunk` event. @@ -2503,7 +2434,6 @@ void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback); /** @} */ - /** @{ * @name Conference management */ @@ -2530,7 +2460,6 @@ typedef enum Tox_Conference_Type { const char *tox_conference_type_to_string(Tox_Conference_Type value); - /** * The invitation will remain valid until the inviting friend goes offline * or exits the conference. @@ -2542,9 +2471,8 @@ const char *tox_conference_type_to_string(Tox_Conference_Type value); * @param length The length of the cookie. */ typedef void tox_conference_invite_cb( - Tox *tox, Tox_Friend_Number friend_number, Tox_Conference_Type type, - const uint8_t cookie[], size_t length, void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, Tox_Conference_Type type, + const uint8_t cookie[], size_t length, void *user_data); /** * @brief Set the callback for the `conference_invite` event. @@ -2560,7 +2488,6 @@ void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback */ typedef void tox_conference_connected_cb(Tox *tox, Tox_Conference_Number conference_number, void *user_data); - /** * @brief Set the callback for the `conference_connected` event. * @@ -2580,9 +2507,8 @@ void tox_callback_conference_connected(Tox *tox, tox_conference_connected_cb *ca * @param length The length of the message. */ typedef void tox_conference_message_cb( - Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, - Tox_Message_Type type, const uint8_t message[], size_t length, void *user_data); - + Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, + Tox_Message_Type type, const uint8_t message[], size_t length, void *user_data); /** * @brief Set the callback for the `conference_message` event. @@ -2601,9 +2527,8 @@ void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callba * @param length The title length. */ typedef void tox_conference_title_cb( - Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, - const uint8_t title[], size_t length, void *user_data); - + Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, + const uint8_t title[], size_t length, void *user_data); /** * @brief Set the callback for the `conference_title` event. @@ -2624,9 +2549,8 @@ void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback); * @param length The size of the name byte array. */ typedef void tox_conference_peer_name_cb( - Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, - const uint8_t name[], size_t length, void *user_data); - + Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, + const uint8_t name[], size_t length, void *user_data); /** * @brief Set the callback for the `conference_peer_name` event. @@ -2643,7 +2567,6 @@ void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *ca */ typedef void tox_conference_peer_list_changed_cb(Tox *tox, Tox_Conference_Number conference_number, void *user_data); - /** * @brief Set the callback for the `conference_peer_list_changed` event. * @@ -2669,7 +2592,6 @@ typedef enum Tox_Err_Conference_New { const char *tox_err_conference_new_to_string(Tox_Err_Conference_New value); - /** * @brief Creates a new conference. * @@ -2697,7 +2619,6 @@ typedef enum Tox_Err_Conference_Delete { const char *tox_err_conference_delete_to_string(Tox_Err_Conference_Delete value); - /** * @brief This function deletes a conference. * @@ -2736,7 +2657,6 @@ typedef enum Tox_Err_Conference_Peer_Query { const char *tox_err_conference_peer_query_to_string(Tox_Err_Conference_Peer_Query value); - /** * @brief Return the number of online peers in the conference. * @@ -2745,7 +2665,7 @@ const char *tox_err_conference_peer_query_to_string(Tox_Err_Conference_Peer_Quer * unspecified on failure. */ Tox_Conference_Peer_Number tox_conference_peer_count( - const Tox *tox, Tox_Conference_Number conference_number, Tox_Err_Conference_Peer_Query *error); + const Tox *tox, Tox_Conference_Number conference_number, Tox_Err_Conference_Peer_Query *error); /** * @brief Return the length of the peer's name. @@ -2753,8 +2673,8 @@ Tox_Conference_Peer_Number tox_conference_peer_count( * Return value is unspecified on failure. */ size_t tox_conference_peer_get_name_size( - const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, - Tox_Err_Conference_Peer_Query *error); + const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, + Tox_Err_Conference_Peer_Query *error); /** * @brief Copy the name of peer_number who is in conference_number to name. @@ -2766,8 +2686,8 @@ size_t tox_conference_peer_get_name_size( * @return true on success. */ bool tox_conference_peer_get_name( - const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, - uint8_t name[], Tox_Err_Conference_Peer_Query *error); + const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, + uint8_t name[], Tox_Err_Conference_Peer_Query *error); /** * @brief Copy the public key of peer_number who is in conference_number to public_key. @@ -2777,15 +2697,15 @@ bool tox_conference_peer_get_name( * @return true on success. */ bool tox_conference_peer_get_public_key( - const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, - uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Conference_Peer_Query *error); + const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, + uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Conference_Peer_Query *error); /** * @brief Return true if passed peer_number corresponds to our own. */ bool tox_conference_peer_number_is_ours( - const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, - Tox_Err_Conference_Peer_Query *error); + const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, + Tox_Err_Conference_Peer_Query *error); /** * @brief Return the number of offline peers in the conference. @@ -2796,8 +2716,8 @@ bool tox_conference_peer_number_is_ours( * Return value is unspecified on failure. */ uint32_t tox_conference_offline_peer_count( - const Tox *tox, Tox_Conference_Number conference_number, - Tox_Err_Conference_Peer_Query *error); + const Tox *tox, Tox_Conference_Number conference_number, + Tox_Err_Conference_Peer_Query *error); /** * @brief Return the length of the offline peer's name. @@ -2805,8 +2725,8 @@ uint32_t tox_conference_offline_peer_count( * Return value is unspecified on failure. */ size_t tox_conference_offline_peer_get_name_size( - const Tox *tox, Tox_Conference_Number conference_number, - Tox_Conference_Peer_Number offline_peer_number, Tox_Err_Conference_Peer_Query *error); + const Tox *tox, Tox_Conference_Number conference_number, + Tox_Conference_Peer_Number offline_peer_number, Tox_Err_Conference_Peer_Query *error); /** * @brief Copy the name of offline_peer_number who is in conference_number to name. @@ -2819,8 +2739,8 @@ size_t tox_conference_offline_peer_get_name_size( * @return true on success. */ bool tox_conference_offline_peer_get_name( - const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number offline_peer_number, - uint8_t name[], Tox_Err_Conference_Peer_Query *error); + const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number offline_peer_number, + uint8_t name[], Tox_Err_Conference_Peer_Query *error); /** * @brief Copy the public key of offline_peer_number who is in conference_number to public_key. @@ -2830,15 +2750,15 @@ bool tox_conference_offline_peer_get_name( * @return true on success. */ bool tox_conference_offline_peer_get_public_key( - const Tox *tox, Tox_Conference_Number conference_number, - Tox_Conference_Peer_Number offline_peer_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Conference_Peer_Query *error); + const Tox *tox, Tox_Conference_Number conference_number, + Tox_Conference_Peer_Number offline_peer_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Conference_Peer_Query *error); /** * @brief Return a unix-time timestamp of the last time offline_peer_number was seen to be active. */ uint64_t tox_conference_offline_peer_get_last_active( - const Tox *tox, Tox_Conference_Number conference_number, - Tox_Conference_Peer_Number offline_peer_number, Tox_Err_Conference_Peer_Query *error); + const Tox *tox, Tox_Conference_Number conference_number, + Tox_Conference_Peer_Number offline_peer_number, Tox_Err_Conference_Peer_Query *error); typedef enum Tox_Err_Conference_Set_Max_Offline { @@ -2856,13 +2776,12 @@ typedef enum Tox_Err_Conference_Set_Max_Offline { const char *tox_err_conference_set_max_offline_to_string(Tox_Err_Conference_Set_Max_Offline value); - /** * @brief Set maximum number of offline peers to store, overriding the default. */ bool tox_conference_set_max_offline( - Tox *tox, Tox_Conference_Number conference_number, uint32_t max_offline, - Tox_Err_Conference_Set_Max_Offline *error); + Tox *tox, Tox_Conference_Number conference_number, uint32_t max_offline, + Tox_Err_Conference_Set_Max_Offline *error); typedef enum Tox_Err_Conference_Invite { @@ -2890,7 +2809,6 @@ typedef enum Tox_Err_Conference_Invite { const char *tox_err_conference_invite_to_string(Tox_Err_Conference_Invite value); - /** * @brief Invites a friend to a conference. * @@ -2900,8 +2818,8 @@ const char *tox_err_conference_invite_to_string(Tox_Err_Conference_Invite value) * @return true on success. */ bool tox_conference_invite( - Tox *tox, Tox_Friend_Number friend_number, Tox_Conference_Number conference_number, - Tox_Err_Conference_Invite *error); + Tox *tox, Tox_Friend_Number friend_number, Tox_Conference_Number conference_number, + Tox_Err_Conference_Invite *error); typedef enum Tox_Err_Conference_Join { @@ -2944,7 +2862,6 @@ typedef enum Tox_Err_Conference_Join { const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value); - /** * @brief Joins a conference that the client has been invited to. * @@ -2963,9 +2880,9 @@ const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value); * @return conference number on success, an unspecified value on failure. */ Tox_Conference_Number tox_conference_join( - Tox *tox, Tox_Friend_Number friend_number, - const uint8_t cookie[], size_t length, - Tox_Err_Conference_Join *error); + Tox *tox, Tox_Friend_Number friend_number, + const uint8_t cookie[], size_t length, + Tox_Err_Conference_Join *error); typedef enum Tox_Err_Conference_Send_Message { @@ -2998,7 +2915,6 @@ typedef enum Tox_Err_Conference_Send_Message { const char *tox_err_conference_send_message_to_string(Tox_Err_Conference_Send_Message value); - /** * @brief Send a text chat message to the conference. * @@ -3019,9 +2935,9 @@ const char *tox_err_conference_send_message_to_string(Tox_Err_Conference_Send_Me * @return true on success. */ bool tox_conference_send_message( - Tox *tox, Tox_Conference_Number conference_number, Tox_Message_Type type, - const uint8_t message[], size_t length, - Tox_Err_Conference_Send_Message *error); + Tox *tox, Tox_Conference_Number conference_number, Tox_Message_Type type, + const uint8_t message[], size_t length, + Tox_Err_Conference_Send_Message *error); typedef enum Tox_Err_Conference_Title { @@ -3049,7 +2965,6 @@ typedef enum Tox_Err_Conference_Title { const char *tox_err_conference_title_to_string(Tox_Err_Conference_Title value); - /** * @brief Return the length of the conference title. * @@ -3059,7 +2974,7 @@ const char *tox_err_conference_title_to_string(Tox_Err_Conference_Title value); * `conference_title` callback. */ size_t tox_conference_get_title_size( - const Tox *tox, Tox_Conference_Number conference_number, Tox_Err_Conference_Title *error); + const Tox *tox, Tox_Conference_Number conference_number, Tox_Err_Conference_Title *error); /** * @brief Write the title designated by the given conference number to a byte array. @@ -3075,9 +2990,9 @@ size_t tox_conference_get_title_size( * @return true on success. */ bool tox_conference_get_title( - const Tox *tox, Tox_Conference_Number conference_number, - uint8_t title[], - Tox_Err_Conference_Title *error); + const Tox *tox, Tox_Conference_Number conference_number, + uint8_t title[], + Tox_Err_Conference_Title *error); /** * @brief Set the conference title and broadcast it to the rest of the conference. @@ -3087,9 +3002,9 @@ bool tox_conference_get_title( * @return true on success. */ bool tox_conference_set_title( - Tox *tox, Tox_Conference_Number conference_number, - const uint8_t title[], size_t length, - Tox_Err_Conference_Title *error); + Tox *tox, Tox_Conference_Number conference_number, + const uint8_t title[], size_t length, + Tox_Err_Conference_Title *error); /** * @brief Return the number of conferences in the Tox instance. @@ -3135,13 +3050,12 @@ typedef enum Tox_Err_Conference_Get_Type { const char *tox_err_conference_get_type_to_string(Tox_Err_Conference_Get_Type value); - /** * @brief Get the type (text or A/V) for the conference. */ Tox_Conference_Type tox_conference_get_type( - const Tox *tox, Tox_Conference_Number conference_number, - Tox_Err_Conference_Get_Type *error); + const Tox *tox, Tox_Conference_Number conference_number, + Tox_Err_Conference_Get_Type *error); /** * @brief Get the conference unique ID. @@ -3153,7 +3067,7 @@ Tox_Conference_Type tox_conference_get_type( * @return true on success. */ bool tox_conference_get_id( - const Tox *tox, Tox_Conference_Number conference_number, uint8_t id[TOX_CONFERENCE_ID_SIZE]); + const Tox *tox, Tox_Conference_Number conference_number, uint8_t id[TOX_CONFERENCE_ID_SIZE]); typedef enum Tox_Err_Conference_By_Id { @@ -3176,7 +3090,6 @@ typedef enum Tox_Err_Conference_By_Id { const char *tox_err_conference_by_id_to_string(Tox_Err_Conference_By_Id value); - /** * @brief Return the conference number associated with the specified id. * @@ -3185,7 +3098,7 @@ const char *tox_err_conference_by_id_to_string(Tox_Err_Conference_By_Id value); * @return the conference number on success, an unspecified value on failure. */ Tox_Conference_Number tox_conference_by_id( - const Tox *tox, const uint8_t id[TOX_CONFERENCE_ID_SIZE], Tox_Err_Conference_By_Id *error); + const Tox *tox, const uint8_t id[TOX_CONFERENCE_ID_SIZE], Tox_Err_Conference_By_Id *error); /** * @brief Get the conference unique ID. @@ -3198,7 +3111,7 @@ Tox_Conference_Number tox_conference_by_id( * @deprecated use tox_conference_get_id instead (exactly the same function, just renamed). */ bool tox_conference_get_uid( - const Tox *tox, Tox_Conference_Number conference_number, uint8_t uid[TOX_CONFERENCE_UID_SIZE]); + const Tox *tox, Tox_Conference_Number conference_number, uint8_t uid[TOX_CONFERENCE_UID_SIZE]); typedef enum Tox_Err_Conference_By_Uid { @@ -3221,7 +3134,6 @@ typedef enum Tox_Err_Conference_By_Uid { const char *tox_err_conference_by_uid_to_string(Tox_Err_Conference_By_Uid value); - /** * @brief Return the conference number associated with the specified uid. * @@ -3231,11 +3143,10 @@ const char *tox_err_conference_by_uid_to_string(Tox_Err_Conference_By_Uid value) * @deprecated use tox_conference_by_id instead (exactly the same function, just renamed). */ Tox_Conference_Number tox_conference_by_uid( - const Tox *tox, const uint8_t uid[TOX_CONFERENCE_UID_SIZE], Tox_Err_Conference_By_Uid *error); + const Tox *tox, const uint8_t uid[TOX_CONFERENCE_UID_SIZE], Tox_Err_Conference_By_Uid *error); /** @} */ - /** @{ * @name Low-level custom packet sending and receiving */ @@ -3287,7 +3198,6 @@ typedef enum Tox_Err_Friend_Custom_Packet { const char *tox_err_friend_custom_packet_to_string(Tox_Err_Friend_Custom_Packet value); - /** * @brief Send a custom lossy packet to a friend. * @@ -3309,9 +3219,9 @@ const char *tox_err_friend_custom_packet_to_string(Tox_Err_Friend_Custom_Packet * @return true on success. */ bool tox_friend_send_lossy_packet( - Tox *tox, Tox_Friend_Number friend_number, - const uint8_t data[], size_t length, - Tox_Err_Friend_Custom_Packet *error); + Tox *tox, Tox_Friend_Number friend_number, + const uint8_t data[], size_t length, + Tox_Err_Friend_Custom_Packet *error); /** * @brief Send a custom lossless packet to a friend. @@ -3330,9 +3240,9 @@ bool tox_friend_send_lossy_packet( * @return true on success. */ bool tox_friend_send_lossless_packet( - Tox *tox, Tox_Friend_Number friend_number, - const uint8_t data[], size_t length, - Tox_Err_Friend_Custom_Packet *error); + Tox *tox, Tox_Friend_Number friend_number, + const uint8_t data[], size_t length, + Tox_Err_Friend_Custom_Packet *error); /** * @param friend_number The friend number of the friend who sent a lossy packet. @@ -3340,10 +3250,9 @@ bool tox_friend_send_lossless_packet( * @param length The length of the packet data byte array. */ typedef void tox_friend_lossy_packet_cb( - Tox *tox, Tox_Friend_Number friend_number, - const uint8_t data[], size_t length, - void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, + const uint8_t data[], size_t length, + void *user_data); /** * @brief Set the callback for the `friend_lossy_packet` event. @@ -3358,10 +3267,9 @@ void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *call * @param length The length of the packet data byte array. */ typedef void tox_friend_lossless_packet_cb( - Tox *tox, Tox_Friend_Number friend_number, - const uint8_t data[], size_t length, - void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, + const uint8_t data[], size_t length, + void *user_data); /** * @brief Set the callback for the `friend_lossless_packet` event. @@ -3372,7 +3280,6 @@ void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb /** @} */ - /** @{ * @name Low-level network information */ @@ -3393,7 +3300,6 @@ typedef enum Tox_Err_Get_Port { const char *tox_err_get_port_to_string(Tox_Err_Get_Port value); - /** * @brief Writes the temporary DHT public key of this instance to a byte array. * @@ -3430,16 +3336,12 @@ typedef uint32_t Tox_Group_Number; typedef uint32_t Tox_Group_Peer_Number; typedef uint32_t Tox_Group_Message_Id; - - /******************************************************************************* * * :: Group chat numeric constants * ******************************************************************************/ - - /** * Maximum length of a group topic. */ @@ -3503,15 +3405,12 @@ uint32_t tox_group_chat_id_size(void); uint32_t tox_group_peer_public_key_size(void); - /******************************************************************************* * * :: Group chat state enumerators * ******************************************************************************/ - - /** * Represents the group privacy state. */ @@ -3541,7 +3440,6 @@ typedef enum Tox_Group_Privacy_State { const char *tox_group_privacy_state_to_string(Tox_Group_Privacy_State value); - /** * Represents the state of the group topic lock. */ @@ -3618,16 +3516,12 @@ typedef enum Tox_Group_Role { const char *tox_group_role_to_string(Tox_Group_Role value); - - /******************************************************************************* * * :: Group chat instance management * ******************************************************************************/ - - typedef enum Tox_Err_Group_New { /** @@ -3665,7 +3559,6 @@ typedef enum Tox_Err_Group_New { const char *tox_err_group_new_to_string(Tox_Err_Group_New value); - /** * Creates a new group chat. * @@ -3689,9 +3582,9 @@ const char *tox_err_group_new_to_string(Tox_Err_Group_New value); * @return group_number on success, UINT32_MAX on failure. */ Tox_Group_Number tox_group_new( - Tox *tox, Tox_Group_Privacy_State privacy_state, - const uint8_t group_name[], size_t group_name_length, - const uint8_t name[], size_t name_length, Tox_Err_Group_New *error); + Tox *tox, Tox_Group_Privacy_State privacy_state, + const uint8_t group_name[], size_t group_name_length, + const uint8_t name[], size_t name_length, Tox_Err_Group_New *error); typedef enum Tox_Err_Group_Join { @@ -3735,7 +3628,6 @@ typedef enum Tox_Err_Group_Join { const char *tox_err_group_join_to_string(Tox_Err_Group_Join value); - /** * Joins a group chat with specified Chat ID. * @@ -3754,10 +3646,10 @@ const char *tox_err_group_join_to_string(Tox_Err_Group_Join value); * @return group_number on success, UINT32_MAX on failure. */ Tox_Group_Number tox_group_join( - Tox *tox, const uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE], - const uint8_t name[], size_t name_length, - const uint8_t password[], size_t password_length, - Tox_Err_Group_Join *error); + Tox *tox, const uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE], + const uint8_t name[], size_t name_length, + const uint8_t password[], size_t password_length, + Tox_Err_Group_Join *error); typedef enum Tox_Err_Group_Is_Connected { @@ -3775,7 +3667,6 @@ typedef enum Tox_Err_Group_Is_Connected { const char *tox_err_group_is_connected_to_string(Tox_Err_Group_Is_Connected value); - /** * Returns true if the group chat is currently connected or attempting to connect to other peers * in the group. @@ -3804,7 +3695,6 @@ typedef enum Tox_Err_Group_Disconnect { const char *tox_err_group_disconnect_to_string(Tox_Err_Group_Disconnect value); - /** * Disconnects from a group chat while retaining the group state and credentials. * @@ -3835,7 +3725,6 @@ typedef enum Tox_Err_Group_Reconnect { const char *tox_err_group_reconnect_to_string(Tox_Err_Group_Reconnect value); - /** * Reconnects to a group. * @@ -3873,7 +3762,6 @@ typedef enum Tox_Err_Group_Leave { const char *tox_err_group_leave_to_string(Tox_Err_Group_Leave value); - /** * Leaves a group. * @@ -3889,10 +3777,9 @@ const char *tox_err_group_leave_to_string(Tox_Err_Group_Leave value); * @return true if the group chat instance is successfully deleted. */ bool tox_group_leave( - Tox *tox, Tox_Group_Number group_number, - const uint8_t part_message[], size_t length, - Tox_Err_Group_Leave *error); - + Tox *tox, Tox_Group_Number group_number, + const uint8_t part_message[], size_t length, + Tox_Err_Group_Leave *error); /******************************************************************************* * @@ -3900,8 +3787,6 @@ bool tox_group_leave( * ******************************************************************************/ - - /** * General error codes for self state get and size functions. */ @@ -3921,7 +3806,6 @@ typedef enum Tox_Err_Group_Self_Query { const char *tox_err_group_self_query_to_string(Tox_Err_Group_Self_Query value); - /** * Error codes for self name setting. */ @@ -3956,7 +3840,6 @@ typedef enum Tox_Err_Group_Self_Name_Set { const char *tox_err_group_self_name_set_to_string(Tox_Err_Group_Self_Name_Set value); - /** * Set the client's nickname for the group instance designated by the given group number. * @@ -3969,9 +3852,9 @@ const char *tox_err_group_self_name_set_to_string(Tox_Err_Group_Self_Name_Set va * @return true on success. */ bool tox_group_self_set_name( - Tox *tox, Tox_Group_Number group_number, - const uint8_t name[], size_t length, - Tox_Err_Group_Self_Name_Set *error); + Tox *tox, Tox_Group_Number group_number, + const uint8_t name[], size_t length, + Tox_Err_Group_Self_Name_Set *error); /** * Return the length of the client's current nickname for the group instance designated @@ -3998,8 +3881,8 @@ size_t tox_group_self_get_name_size(const Tox *tox, Tox_Group_Number group_numbe * @return true on success. */ bool tox_group_self_get_name( - const Tox *tox, Tox_Group_Number group_number, - uint8_t name[], Tox_Err_Group_Self_Query *error); + const Tox *tox, Tox_Group_Number group_number, + uint8_t name[], Tox_Err_Group_Self_Query *error); /** * Error codes for self status setting. @@ -4025,7 +3908,6 @@ typedef enum Tox_Err_Group_Self_Status_Set { const char *tox_err_group_self_status_set_to_string(Tox_Err_Group_Self_Status_Set value); - /** * Set the client's status for the group instance. Status must be a Tox_User_Status. * @@ -4069,15 +3951,12 @@ Tox_Group_Peer_Number tox_group_self_get_peer_id(const Tox *tox, Tox_Group_Numbe bool tox_group_self_get_public_key(const Tox *tox, Tox_Group_Number group_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Group_Self_Query *error); - /******************************************************************************* * * :: Peer-specific group state queries. * ******************************************************************************/ - - /** * Error codes for peer info queries. */ @@ -4102,7 +3981,6 @@ typedef enum Tox_Err_Group_Peer_Query { const char *tox_err_group_peer_query_to_string(Tox_Err_Group_Peer_Query value); - /** * Return the length of the peer's name. If the group number or ID is invalid, the * return value is unspecified. @@ -4132,8 +4010,8 @@ size_t tox_group_peer_get_name_size(const Tox *tox, Tox_Group_Number group_numbe * @return true on success. */ bool tox_group_peer_get_name( - const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, - uint8_t name[], Tox_Err_Group_Peer_Query *error); + const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, + uint8_t name[], Tox_Err_Group_Peer_Query *error); /** * Return the peer's user status (away/busy/...). If the ID or group number is @@ -4190,8 +4068,8 @@ Tox_Connection tox_group_peer_get_connection_status(const Tox *tox, Tox_Group_Nu * @return true on success. */ bool tox_group_peer_get_public_key( - const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, - uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Group_Peer_Query *error); + const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, + uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Group_Peer_Query *error); /** * @param group_number The group number of the group the name change is intended for. @@ -4200,9 +4078,8 @@ bool tox_group_peer_get_public_key( * @param length The length of the name. */ typedef void tox_group_peer_name_cb( - Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, - const uint8_t name[], size_t length, void *user_data); - + Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, + const uint8_t name[], size_t length, void *user_data); /** * Set the callback for the `group_peer_name` event. Pass NULL to unset. @@ -4219,7 +4096,6 @@ void tox_callback_group_peer_name(Tox *tox, tox_group_peer_name_cb *callback); typedef void tox_group_peer_status_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_User_Status status, void *user_data); - /** * Set the callback for the `group_peer_status` event. Pass NULL to unset. * @@ -4227,15 +4103,12 @@ typedef void tox_group_peer_status_cb(Tox *tox, Tox_Group_Number group_number, T */ void tox_callback_group_peer_status(Tox *tox, tox_group_peer_status_cb *callback); - /******************************************************************************* * * :: Group chat state queries and events. * ******************************************************************************/ - - /** * General error codes for group state get and size functions. */ @@ -4255,7 +4128,6 @@ typedef enum Tox_Err_Group_State_Queries { const char *tox_err_group_state_queries_to_string(Tox_Err_Group_State_Queries value); - /** * Error codes for group topic setting. */ @@ -4300,7 +4172,6 @@ typedef enum Tox_Err_Group_Topic_Set { const char *tox_err_group_topic_set_to_string(Tox_Err_Group_Topic_Set value); - /** * Set the group topic and broadcast it to the rest of the group. * @@ -4310,9 +4181,9 @@ const char *tox_err_group_topic_set_to_string(Tox_Err_Group_Topic_Set value); * @return true on success. */ bool tox_group_set_topic( - Tox *tox, Tox_Group_Number group_number, - const uint8_t topic[], size_t length, - Tox_Err_Group_Topic_Set *error); + Tox *tox, Tox_Group_Number group_number, + const uint8_t topic[], size_t length, + Tox_Err_Group_Topic_Set *error); /** * Return the length of the group topic. If the group number is invalid, the @@ -4337,8 +4208,8 @@ size_t tox_group_get_topic_size(const Tox *tox, Tox_Group_Number group_number, T * @return true on success. */ bool tox_group_get_topic( - const Tox *tox, Tox_Group_Number group_number, - uint8_t topic[], Tox_Err_Group_State_Queries *error); + const Tox *tox, Tox_Group_Number group_number, + uint8_t topic[], Tox_Err_Group_State_Queries *error); /** * @param group_number The group number of the group the topic change is intended for. @@ -4348,10 +4219,9 @@ bool tox_group_get_topic( * @param length The topic length. */ typedef void tox_group_topic_cb( - Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, - const uint8_t topic[], size_t length, - void *user_data); - + Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, + const uint8_t topic[], size_t length, + void *user_data); /** * Set the callback for the `group_topic` event. Pass NULL to unset. @@ -4377,8 +4247,8 @@ size_t tox_group_get_name_size(const Tox *tox, Tox_Group_Number group_number, To * @return true on success. */ bool tox_group_get_name( - const Tox *tox, Tox_Group_Number group_number, - uint8_t name[], Tox_Err_Group_State_Queries *error); + const Tox *tox, Tox_Group_Number group_number, + uint8_t name[], Tox_Err_Group_State_Queries *error); /** * Write the Chat ID designated by the given group number to a byte array. @@ -4391,8 +4261,8 @@ bool tox_group_get_name( * @return true on success. */ bool tox_group_get_chat_id( - const Tox *tox, Tox_Group_Number group_number, uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE], - Tox_Err_Group_State_Queries *error); + const Tox *tox, Tox_Group_Number group_number, uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE], + Tox_Err_Group_State_Queries *error); /** * Return the number of groups in the Tox chats array. @@ -4418,7 +4288,6 @@ Tox_Group_Privacy_State tox_group_get_privacy_state(const Tox *tox, Tox_Group_Nu typedef void tox_group_privacy_state_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Privacy_State privacy_state, void *user_data); - /** * Set the callback for the `group_privacy_state` event. Pass NULL to unset. * @@ -4444,7 +4313,6 @@ Tox_Group_Voice_State tox_group_get_voice_state(const Tox *tox, Tox_Group_Number typedef void tox_group_voice_state_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Voice_State voice_state, void *user_data); - /** * Set the callback for the `group_privacy_state` event. Pass NULL to unset. * @@ -4470,8 +4338,6 @@ Tox_Group_Topic_Lock tox_group_get_topic_lock(const Tox *tox, Tox_Group_Number g */ typedef void tox_group_topic_lock_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Topic_Lock topic_lock, void *user_data); - - /** * Set the callback for the `group_topic_lock` event. Pass NULL to unset. * @@ -4496,7 +4362,6 @@ uint16_t tox_group_get_peer_limit(const Tox *tox, Tox_Group_Number group_number, */ typedef void tox_group_peer_limit_cb(Tox *tox, Tox_Group_Number group_number, uint32_t peer_limit, void *user_data); - /** * Set the callback for the `group_peer_limit` event. Pass NULL to unset. * @@ -4526,8 +4391,8 @@ size_t tox_group_get_password_size(const Tox *tox, Tox_Group_Number group_number * @return true on success. */ bool tox_group_get_password( - const Tox *tox, Tox_Group_Number group_number, uint8_t password[], - Tox_Err_Group_State_Queries *error); + const Tox *tox, Tox_Group_Number group_number, uint8_t password[], + Tox_Err_Group_State_Queries *error); /** * @param group_number The group number of the group for which the password has changed. @@ -4535,10 +4400,9 @@ bool tox_group_get_password( * @param length The length of the password. */ typedef void tox_group_password_cb( - Tox *tox, Tox_Group_Number group_number, - const uint8_t password[], size_t length, - void *user_data); - + Tox *tox, Tox_Group_Number group_number, + const uint8_t password[], size_t length, + void *user_data); /** * Set the callback for the `group_password` event. Pass NULL to unset. @@ -4547,15 +4411,12 @@ typedef void tox_group_password_cb( */ void tox_callback_group_password(Tox *tox, tox_group_password_cb *callback); - /******************************************************************************* * * :: Group chat message sending * ******************************************************************************/ - - typedef enum Tox_Err_Group_Send_Message { /** @@ -4602,7 +4463,6 @@ typedef enum Tox_Err_Group_Send_Message { const char *tox_err_group_send_message_to_string(Tox_Err_Group_Send_Message value); - /** * Send a text chat message to the group. * @@ -4623,9 +4483,9 @@ const char *tox_err_group_send_message_to_string(Tox_Err_Group_Send_Message valu * returned message ID value will be undefined. */ Tox_Group_Message_Id tox_group_send_message( - const Tox *tox, Tox_Group_Number group_number, Tox_Message_Type type, - const uint8_t message[], size_t length, - Tox_Err_Group_Send_Message *error); + const Tox *tox, Tox_Group_Number group_number, Tox_Message_Type type, + const uint8_t message[], size_t length, + Tox_Err_Group_Send_Message *error); typedef enum Tox_Err_Group_Send_Private_Message { @@ -4678,7 +4538,6 @@ typedef enum Tox_Err_Group_Send_Private_Message { const char *tox_err_group_send_private_message_to_string(Tox_Err_Group_Send_Private_Message value); - /** * Send a text chat message to the specified peer in the specified group. * @@ -4698,9 +4557,9 @@ const char *tox_err_group_send_private_message_to_string(Tox_Err_Group_Send_Priv * @return true on success. */ bool tox_group_send_private_message( - const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, - const uint8_t message[], size_t length, - Tox_Err_Group_Send_Private_Message *error); + const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, + const uint8_t message[], size_t length, + Tox_Err_Group_Send_Private_Message *error); typedef enum Tox_Err_Group_Send_Custom_Packet { @@ -4746,7 +4605,6 @@ typedef enum Tox_Err_Group_Send_Custom_Packet { const char *tox_err_group_send_custom_packet_to_string(Tox_Err_Group_Send_Custom_Packet value); - /** * Send a custom packet to the group. * @@ -4772,10 +4630,9 @@ const char *tox_err_group_send_custom_packet_to_string(Tox_Err_Group_Send_Custom * @return true on success. */ bool tox_group_send_custom_packet( - const Tox *tox, Tox_Group_Number group_number, bool lossless, - const uint8_t data[], size_t length, - Tox_Err_Group_Send_Custom_Packet *error); - + const Tox *tox, Tox_Group_Number group_number, bool lossless, + const uint8_t data[], size_t length, + Tox_Err_Group_Send_Custom_Packet *error); typedef enum Tox_Err_Group_Send_Custom_Private_Packet { @@ -4854,15 +4711,12 @@ bool tox_group_send_custom_private_packet(const Tox *tox, Tox_Group_Number group const uint8_t data[], size_t length, Tox_Err_Group_Send_Custom_Private_Packet *error); - /******************************************************************************* * * :: Group chat message receiving * ******************************************************************************/ - - /** * @param group_number The group number of the group the message is intended for. * @param peer_id The ID of the peer who sent the message. @@ -4872,9 +4726,8 @@ bool tox_group_send_custom_private_packet(const Tox *tox, Tox_Group_Number group * @param length The length of the message. */ typedef void tox_group_message_cb( - Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, - const uint8_t message[], size_t length, Tox_Group_Message_Id message_id, void *user_data); - + Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, + const uint8_t message[], size_t length, Tox_Group_Message_Id message_id, void *user_data); /** * Set the callback for the `group_message` event. Pass NULL to unset. @@ -4890,9 +4743,8 @@ void tox_callback_group_message(Tox *tox, tox_group_message_cb *callback); * @param length The length of the message. */ typedef void tox_group_private_message_cb( - Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, - const uint8_t message[], size_t length, void *user_data); - + Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, + const uint8_t message[], size_t length, void *user_data); /** * Set the callback for the `group_private_message` event. Pass NULL to unset. @@ -4908,9 +4760,8 @@ void tox_callback_group_private_message(Tox *tox, tox_group_private_message_cb * * @param length The length of the data. */ typedef void tox_group_custom_packet_cb( - Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, - const uint8_t data[], size_t length, void *user_data); - + Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, + const uint8_t data[], size_t length, void *user_data); /** * Set the callback for the `group_custom_packet` event. Pass NULL to unset. @@ -4926,9 +4777,8 @@ void tox_callback_group_custom_packet(Tox *tox, tox_group_custom_packet_cb *call * @param length The length of the data. */ typedef void tox_group_custom_private_packet_cb( - Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, - const uint8_t data[], size_t length, void *user_data); - + Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, + const uint8_t data[], size_t length, void *user_data); /** * Set the callback for the `group_custom_private_packet` event. Pass NULL to unset. @@ -4937,15 +4787,12 @@ typedef void tox_group_custom_private_packet_cb( */ void tox_callback_group_custom_private_packet(Tox *tox, tox_group_custom_private_packet_cb *callback); - /******************************************************************************* * * :: Group chat inviting and join/part events * ******************************************************************************/ - - typedef enum Tox_Err_Group_Invite_Friend { /** @@ -4982,7 +4829,6 @@ typedef enum Tox_Err_Group_Invite_Friend { const char *tox_err_group_invite_friend_to_string(Tox_Err_Group_Invite_Friend value); - /** * Invite a friend to a group. * @@ -4994,8 +4840,8 @@ const char *tox_err_group_invite_friend_to_string(Tox_Err_Group_Invite_Friend va * @return true on success. */ bool tox_group_invite_friend( - const Tox *tox, Tox_Group_Number group_number, Tox_Friend_Number friend_number, - Tox_Err_Group_Invite_Friend *error); + const Tox *tox, Tox_Group_Number group_number, Tox_Friend_Number friend_number, + Tox_Err_Group_Invite_Friend *error); typedef enum Tox_Err_Group_Invite_Accept { @@ -5043,7 +4889,6 @@ typedef enum Tox_Err_Group_Invite_Accept { const char *tox_err_group_invite_accept_to_string(Tox_Err_Group_Invite_Accept value); - /** * Accept an invite to a group chat that the client previously received from a friend. The invite * is only valid while the inviter is present in the group. @@ -5060,11 +4905,11 @@ const char *tox_err_group_invite_accept_to_string(Tox_Err_Group_Invite_Accept va * @return the group_number on success, UINT32_MAX on failure. */ Tox_Group_Number tox_group_invite_accept( - Tox *tox, Tox_Friend_Number friend_number, - const uint8_t invite_data[], size_t length, - const uint8_t name[], size_t name_length, - const uint8_t password[], size_t password_length, - Tox_Err_Group_Invite_Accept *error); + Tox *tox, Tox_Friend_Number friend_number, + const uint8_t invite_data[], size_t length, + const uint8_t name[], size_t name_length, + const uint8_t password[], size_t password_length, + Tox_Err_Group_Invite_Accept *error); /** * @param friend_number The friend number of the contact who sent the invite. @@ -5072,11 +4917,10 @@ Tox_Group_Number tox_group_invite_accept( * @param length The length of invite_data. */ typedef void tox_group_invite_cb( - Tox *tox, Tox_Friend_Number friend_number, - const uint8_t invite_data[], size_t length, - const uint8_t group_name[], size_t group_name_length, - void *user_data); - + Tox *tox, Tox_Friend_Number friend_number, + const uint8_t invite_data[], size_t length, + const uint8_t group_name[], size_t group_name_length, + void *user_data); /** * Set the callback for the `group_invite` event. Pass NULL to unset. @@ -5093,7 +4937,6 @@ void tox_callback_group_invite(Tox *tox, tox_group_invite_cb *callback); */ typedef void tox_group_peer_join_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, void *user_data); - /** * Set the callback for the `group_peer_join` event. Pass NULL to unset. * @@ -5141,7 +4984,6 @@ typedef enum Tox_Group_Exit_Type { const char *tox_group_exit_type_to_string(Tox_Group_Exit_Type value); - /** * @param group_number The group number of the group in which a peer has left. * @param peer_id The ID of the peer who left the group. This ID no longer designates a valid peer @@ -5153,10 +4995,9 @@ const char *tox_group_exit_type_to_string(Tox_Group_Exit_Type value); * @param part_message_length The length of the parting message. */ typedef void tox_group_peer_exit_cb( - Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Group_Exit_Type exit_type, - const uint8_t name[], size_t name_length, - const uint8_t part_message[], size_t part_message_length, void *user_data); - + Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Group_Exit_Type exit_type, + const uint8_t name[], size_t name_length, + const uint8_t part_message[], size_t part_message_length, void *user_data); /** * Set the callback for the `group_peer_exit` event. Pass NULL to unset. @@ -5170,7 +5011,6 @@ void tox_callback_group_peer_exit(Tox *tox, tox_group_peer_exit_cb *callback); */ typedef void tox_group_self_join_cb(Tox *tox, Tox_Group_Number group_number, void *user_data); - /** * Set the callback for the `group_self_join` event. Pass NULL to unset. * @@ -5205,14 +5045,12 @@ typedef enum Tox_Group_Join_Fail { const char *tox_group_join_fail_to_string(Tox_Group_Join_Fail value); - /** * @param group_number The group number of the group for which the join has failed. * @param fail_type The type of group rejection. */ typedef void tox_group_join_fail_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Join_Fail fail_type, void *user_data); - /** * Set the callback for the `group_join_fail` event. Pass NULL to unset. * @@ -5220,15 +5058,12 @@ typedef void tox_group_join_fail_cb(Tox *tox, Tox_Group_Number group_number, Tox */ void tox_callback_group_join_fail(Tox *tox, tox_group_join_fail_cb *callback); - /******************************************************************************* * * :: Group chat founder controls (these only work for the group founder) * ******************************************************************************/ - - typedef enum Tox_Err_Group_Founder_Set_Password { /** @@ -5270,7 +5105,6 @@ typedef enum Tox_Err_Group_Founder_Set_Password { const char *tox_err_group_founder_set_password_to_string(Tox_Err_Group_Founder_Set_Password value); - /** * Set or unset the group password. * @@ -5284,9 +5118,9 @@ const char *tox_err_group_founder_set_password_to_string(Tox_Err_Group_Founder_S * @return true on success. */ bool tox_group_founder_set_password( - Tox *tox, Tox_Group_Number group_number, - const uint8_t password[], size_t length, - Tox_Err_Group_Founder_Set_Password *error); + Tox *tox, Tox_Group_Number group_number, + const uint8_t password[], size_t length, + Tox_Err_Group_Founder_Set_Password *error); typedef enum Tox_Err_Group_Founder_Set_Topic_Lock { @@ -5330,7 +5164,6 @@ typedef enum Tox_Err_Group_Founder_Set_Topic_Lock { const char *tox_err_group_founder_set_topic_lock_to_string(Tox_Err_Group_Founder_Set_Topic_Lock value); - /** * Set the group topic lock state. * @@ -5493,7 +5326,6 @@ typedef enum Tox_Err_Group_Founder_Set_Peer_Limit { const char *tox_err_group_founder_set_peer_limit_to_string(Tox_Err_Group_Founder_Set_Peer_Limit value); - /** * Set the group peer limit. * @@ -5508,15 +5340,12 @@ const char *tox_err_group_founder_set_peer_limit_to_string(Tox_Err_Group_Founder bool tox_group_founder_set_peer_limit(Tox *tox, Tox_Group_Number group_number, uint16_t peer_limit, Tox_Err_Group_Founder_Set_Peer_Limit *error); - /******************************************************************************* * * :: Group chat moderation * ******************************************************************************/ - - typedef enum Tox_Err_Group_Set_Ignore { /** @@ -5543,7 +5372,6 @@ typedef enum Tox_Err_Group_Set_Ignore { const char *tox_err_group_set_ignore_to_string(Tox_Err_Group_Set_Ignore value); - /** * Ignore or unignore a peer. * @@ -5599,7 +5427,6 @@ typedef enum Tox_Err_Group_Mod_Set_Role { const char *tox_err_group_mod_set_role_to_string(Tox_Err_Group_Mod_Set_Role value); - /** * Set a peer's role. * @@ -5657,7 +5484,6 @@ typedef enum Tox_Err_Group_Mod_Kick_Peer { const char *tox_err_group_mod_kick_peer_to_string(Tox_Err_Group_Mod_Kick_Peer value); - /** * Kick a peer. * @@ -5702,7 +5528,6 @@ typedef enum Tox_Group_Mod_Event { const char *tox_group_mod_event_to_string(Tox_Group_Mod_Event value); - /** * @param group_number The group number of the group the event is intended for. * @param source_peer_id The ID of the peer who initiated the event. @@ -5710,9 +5535,8 @@ const char *tox_group_mod_event_to_string(Tox_Group_Mod_Event value); * @param mod_type The type of event. */ typedef void tox_group_moderation_cb( - Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number source_peer_id, Tox_Group_Peer_Number target_peer_id, - Tox_Group_Mod_Event mod_type, void *user_data); - + Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number source_peer_id, Tox_Group_Peer_Number target_peer_id, + Tox_Group_Mod_Event mod_type, void *user_data); /** * Set the callback for the `group_moderation` event. Pass NULL to unset. diff --git a/toxcore/tox_api.c b/toxcore/tox_api.c index 5fc83fbbcd..86419a89dd 100644 --- a/toxcore/tox_api.c +++ b/toxcore/tox_api.c @@ -136,12 +136,18 @@ uint32_t tox_dht_node_public_key_size(void) return TOX_DHT_NODE_PUBLIC_KEY_SIZE; } -bool tox_options_get_ipv6_enabled(const Tox_Options *options) { return options->ipv6_enabled; } +bool tox_options_get_ipv6_enabled(const Tox_Options *options) +{ + return options->ipv6_enabled; +} void tox_options_set_ipv6_enabled(Tox_Options *options, bool ipv6_enabled) { options->ipv6_enabled = ipv6_enabled; } -bool tox_options_get_udp_enabled(const Tox_Options *options) { return options->udp_enabled; } +bool tox_options_get_udp_enabled(const Tox_Options *options) +{ + return options->udp_enabled; +} void tox_options_set_udp_enabled(Tox_Options *options, bool udp_enabled) { options->udp_enabled = udp_enabled; @@ -154,27 +160,42 @@ void tox_options_set_proxy_type(Tox_Options *options, Tox_Proxy_Type proxy_type) { options->proxy_type = proxy_type; } -const char *tox_options_get_proxy_host(const Tox_Options *options) { return options->proxy_host; } +const char *tox_options_get_proxy_host(const Tox_Options *options) +{ + return options->proxy_host; +} void tox_options_set_proxy_host(Tox_Options *options, const char *proxy_host) { options->proxy_host = proxy_host; } -uint16_t tox_options_get_proxy_port(const Tox_Options *options) { return options->proxy_port; } +uint16_t tox_options_get_proxy_port(const Tox_Options *options) +{ + return options->proxy_port; +} void tox_options_set_proxy_port(Tox_Options *options, uint16_t proxy_port) { options->proxy_port = proxy_port; } -uint16_t tox_options_get_start_port(const Tox_Options *options) { return options->start_port; } +uint16_t tox_options_get_start_port(const Tox_Options *options) +{ + return options->start_port; +} void tox_options_set_start_port(Tox_Options *options, uint16_t start_port) { options->start_port = start_port; } -uint16_t tox_options_get_end_port(const Tox_Options *options) { return options->end_port; } +uint16_t tox_options_get_end_port(const Tox_Options *options) +{ + return options->end_port; +} void tox_options_set_end_port(Tox_Options *options, uint16_t end_port) { options->end_port = end_port; } -uint16_t tox_options_get_tcp_port(const Tox_Options *options) { return options->tcp_port; } +uint16_t tox_options_get_tcp_port(const Tox_Options *options) +{ + return options->tcp_port; +} void tox_options_set_tcp_port(Tox_Options *options, uint16_t tcp_port) { options->tcp_port = tcp_port; @@ -211,7 +232,10 @@ void tox_options_set_log_callback(Tox_Options *options, tox_log_cb *log_callback { options->log_callback = log_callback; } -void *tox_options_get_log_user_data(const Tox_Options *options) { return options->log_user_data; } +void *tox_options_get_log_user_data(const Tox_Options *options) +{ + return options->log_user_data; +} void tox_options_set_log_user_data(Tox_Options *options, void *log_user_data) { options->log_user_data = log_user_data; @@ -264,7 +288,7 @@ void tox_options_set_savedata_data(Tox_Options *options, const uint8_t *savedata void tox_options_default(Tox_Options *options) { if (options != nullptr) { - const Tox_Options default_options = {0}; + const Tox_Options default_options = {false}; *options = default_options; tox_options_set_ipv6_enabled(options, true); tox_options_set_udp_enabled(options, true); diff --git a/toxcore/tox_event.c b/toxcore/tox_event.c index bb2000d806..b0a65503cd 100644 --- a/toxcore/tox_event.c +++ b/toxcore/tox_event.c @@ -1082,6 +1082,6 @@ static bool tox_event_data_unpack(Tox_Event_Type type, Tox_Event_Data *data, Bin bool tox_event_unpack_into(Tox_Event *event, Bin_Unpack *bu, const Memory *mem) { return bin_unpack_array_fixed(bu, 2, nullptr) // - && tox_event_type_unpack(&event->type, bu) // - && tox_event_data_unpack(event->type, &event->data, bu, mem); + && tox_event_type_unpack(&event->type, bu) // + && tox_event_data_unpack(event->type, &event->data, bu, mem); } diff --git a/toxcore/tox_events.c b/toxcore/tox_events.c index 3ab709301a..a5d995cf50 100644 --- a/toxcore/tox_events.c +++ b/toxcore/tox_events.c @@ -19,14 +19,12 @@ #include "tox_private.h" #include "tox_struct.h" - /***************************************************** * * :: Set up event handlers. * *****************************************************/ - void tox_events_init(Tox *tox) { tox_callback_conference_connected(tox, tox_events_handle_conference_connected); diff --git a/toxcore/tox_private.c b/toxcore/tox_private.c index 107340c3da..0caae95c0e 100644 --- a/toxcore/tox_private.c +++ b/toxcore/tox_private.c @@ -156,7 +156,8 @@ bool tox_dht_get_nodes(const Tox *tox, const uint8_t *public_key, const char *ip return true; } -uint16_t tox_dht_get_num_closelist(const Tox *tox) { +uint16_t tox_dht_get_num_closelist(const Tox *tox) +{ tox_lock(tox); const uint16_t num_total = dht_get_num_closelist(tox->m->dht); tox_unlock(tox); @@ -164,7 +165,8 @@ uint16_t tox_dht_get_num_closelist(const Tox *tox) { return num_total; } -uint16_t tox_dht_get_num_closelist_announce_capable(const Tox *tox){ +uint16_t tox_dht_get_num_closelist_announce_capable(const Tox *tox) +{ tox_lock(tox); const uint16_t num_cap = dht_get_num_closelist_announce_capable(tox->m->dht); tox_unlock(tox); @@ -173,7 +175,7 @@ uint16_t tox_dht_get_num_closelist_announce_capable(const Tox *tox){ } size_t tox_group_peer_get_ip_address_size(const Tox *tox, uint32_t group_number, uint32_t peer_id, - Tox_Err_Group_Peer_Query *error) + Tox_Err_Group_Peer_Query *error) { assert(tox != nullptr); @@ -199,7 +201,7 @@ size_t tox_group_peer_get_ip_address_size(const Tox *tox, uint32_t group_number, } bool tox_group_peer_get_ip_address(const Tox *tox, uint32_t group_number, uint32_t peer_id, uint8_t *ip_addr, - Tox_Err_Group_Peer_Query *error) + Tox_Err_Group_Peer_Query *error) { assert(tox != nullptr); diff --git a/toxcore/tox_private.h b/toxcore/tox_private.h index b6434eb5f5..d36ab026c3 100644 --- a/toxcore/tox_private.h +++ b/toxcore/tox_private.h @@ -56,7 +56,6 @@ void tox_callback_friend_lossless_packet_per_pktid(Tox *tox, tox_friend_lossless void tox_set_av_object(Tox *tox, void *object); void *tox_get_av_object(const Tox *tox); - /******************************************************************************* * * :: DHT network queries. @@ -85,7 +84,6 @@ uint32_t tox_dht_node_public_key_size(void); typedef void tox_dht_get_nodes_response_cb(Tox *tox, const uint8_t *public_key, const char *ip, uint16_t port, void *user_data); - /** * Set the callback for the `dht_get_nodes_response` event. Pass NULL to unset. * @@ -93,7 +91,6 @@ typedef void tox_dht_get_nodes_response_cb(Tox *tox, const uint8_t *public_key, */ void tox_callback_dht_get_nodes_response(Tox *tox, tox_dht_get_nodes_response_cb *callback); - typedef enum Tox_Err_Dht_Get_Nodes { /** * The function returned successfully. @@ -158,7 +155,6 @@ uint16_t tox_dht_get_num_closelist(const Tox *tox); */ uint16_t tox_dht_get_num_closelist_announce_capable(const Tox *tox); - /******************************************************************************* * * :: DHT groupchat queries. @@ -180,7 +176,7 @@ uint32_t tox_group_peer_ip_string_max_length(void); * @param peer_id The ID of the peer whose IP address length we want to retrieve. */ size_t tox_group_peer_get_ip_address_size(const Tox *tox, uint32_t group_number, uint32_t peer_id, - Tox_Err_Group_Peer_Query *error); + Tox_Err_Group_Peer_Query *error); /** * Write the IP address associated with the designated peer_id for the designated group number * to ip_addr. diff --git a/toxcore/tox_unpack.c b/toxcore/tox_unpack.c index 9ee95db77a..b5e05da872 100644 --- a/toxcore/tox_unpack.c +++ b/toxcore/tox_unpack.c @@ -167,20 +167,20 @@ bool tox_user_status_unpack(Tox_User_Status *val, Bin_Unpack *bu) non_null() static bool tox_group_privacy_state_from_int(uint32_t value, Tox_Group_Privacy_State *out) { - switch (value) { - case TOX_GROUP_PRIVACY_STATE_PUBLIC: { - *out = TOX_GROUP_PRIVACY_STATE_PUBLIC; - return true; - } - case TOX_GROUP_PRIVACY_STATE_PRIVATE: { - *out = TOX_GROUP_PRIVACY_STATE_PRIVATE; - return true; - } - default: { - *out = TOX_GROUP_PRIVACY_STATE_PUBLIC; - return false; + switch (value) { + case TOX_GROUP_PRIVACY_STATE_PUBLIC: { + *out = TOX_GROUP_PRIVACY_STATE_PUBLIC; + return true; + } + case TOX_GROUP_PRIVACY_STATE_PRIVATE: { + *out = TOX_GROUP_PRIVACY_STATE_PRIVATE; + return true; + } + default: { + *out = TOX_GROUP_PRIVACY_STATE_PUBLIC; + return false; + } } - } } bool tox_group_privacy_state_unpack(Tox_Group_Privacy_State *val, Bin_Unpack *bu) { @@ -191,24 +191,24 @@ bool tox_group_privacy_state_unpack(Tox_Group_Privacy_State *val, Bin_Unpack *bu non_null() static bool tox_group_voice_state_from_int(uint32_t value, Tox_Group_Voice_State *out) { - switch (value) { - case TOX_GROUP_VOICE_STATE_ALL: { - *out = TOX_GROUP_VOICE_STATE_ALL; - return true; - } - case TOX_GROUP_VOICE_STATE_MODERATOR: { - *out = TOX_GROUP_VOICE_STATE_MODERATOR; - return true; - } - case TOX_GROUP_VOICE_STATE_FOUNDER: { - *out = TOX_GROUP_VOICE_STATE_FOUNDER; - return true; - } - default: { - *out = TOX_GROUP_VOICE_STATE_ALL; - return false; + switch (value) { + case TOX_GROUP_VOICE_STATE_ALL: { + *out = TOX_GROUP_VOICE_STATE_ALL; + return true; + } + case TOX_GROUP_VOICE_STATE_MODERATOR: { + *out = TOX_GROUP_VOICE_STATE_MODERATOR; + return true; + } + case TOX_GROUP_VOICE_STATE_FOUNDER: { + *out = TOX_GROUP_VOICE_STATE_FOUNDER; + return true; + } + default: { + *out = TOX_GROUP_VOICE_STATE_ALL; + return false; + } } - } } bool tox_group_voice_state_unpack(Tox_Group_Voice_State *val, Bin_Unpack *bu) { @@ -220,20 +220,20 @@ bool tox_group_voice_state_unpack(Tox_Group_Voice_State *val, Bin_Unpack *bu) non_null() static bool tox_group_topic_lock_from_int(uint32_t value, Tox_Group_Topic_Lock *out) { - switch (value) { - case TOX_GROUP_TOPIC_LOCK_ENABLED: { - *out = TOX_GROUP_TOPIC_LOCK_ENABLED; - return true; - } - case TOX_GROUP_TOPIC_LOCK_DISABLED: { - *out = TOX_GROUP_TOPIC_LOCK_DISABLED; - return true; - } - default: { - *out = TOX_GROUP_TOPIC_LOCK_ENABLED; - return false; + switch (value) { + case TOX_GROUP_TOPIC_LOCK_ENABLED: { + *out = TOX_GROUP_TOPIC_LOCK_ENABLED; + return true; + } + case TOX_GROUP_TOPIC_LOCK_DISABLED: { + *out = TOX_GROUP_TOPIC_LOCK_DISABLED; + return true; + } + default: { + *out = TOX_GROUP_TOPIC_LOCK_ENABLED; + return false; + } } - } } bool tox_group_topic_lock_unpack(Tox_Group_Topic_Lock *val, Bin_Unpack *bu) { @@ -245,24 +245,24 @@ bool tox_group_topic_lock_unpack(Tox_Group_Topic_Lock *val, Bin_Unpack *bu) non_null() static bool tox_group_join_fail_from_int(uint32_t value, Tox_Group_Join_Fail *out) { - switch (value) { - case TOX_GROUP_JOIN_FAIL_PEER_LIMIT: { - *out = TOX_GROUP_JOIN_FAIL_PEER_LIMIT; - return true; - } - case TOX_GROUP_JOIN_FAIL_INVALID_PASSWORD: { - *out = TOX_GROUP_JOIN_FAIL_INVALID_PASSWORD; - return true; - } - case TOX_GROUP_JOIN_FAIL_UNKNOWN: { - *out = TOX_GROUP_JOIN_FAIL_UNKNOWN; - return true; - } - default: { - *out = TOX_GROUP_JOIN_FAIL_PEER_LIMIT; - return false; + switch (value) { + case TOX_GROUP_JOIN_FAIL_PEER_LIMIT: { + *out = TOX_GROUP_JOIN_FAIL_PEER_LIMIT; + return true; + } + case TOX_GROUP_JOIN_FAIL_INVALID_PASSWORD: { + *out = TOX_GROUP_JOIN_FAIL_INVALID_PASSWORD; + return true; + } + case TOX_GROUP_JOIN_FAIL_UNKNOWN: { + *out = TOX_GROUP_JOIN_FAIL_UNKNOWN; + return true; + } + default: { + *out = TOX_GROUP_JOIN_FAIL_PEER_LIMIT; + return false; + } } - } } bool tox_group_join_fail_unpack(Tox_Group_Join_Fail *val, Bin_Unpack *bu) { @@ -274,28 +274,28 @@ bool tox_group_join_fail_unpack(Tox_Group_Join_Fail *val, Bin_Unpack *bu) non_null() static bool tox_group_mod_event_from_int(uint32_t value, Tox_Group_Mod_Event *out) { - switch (value) { - case TOX_GROUP_MOD_EVENT_KICK: { - *out = TOX_GROUP_MOD_EVENT_KICK; - return true; - } - case TOX_GROUP_MOD_EVENT_OBSERVER: { - *out = TOX_GROUP_MOD_EVENT_OBSERVER; - return true; - } - case TOX_GROUP_MOD_EVENT_USER: { - *out = TOX_GROUP_MOD_EVENT_USER; - return true; - } - case TOX_GROUP_MOD_EVENT_MODERATOR: { - *out = TOX_GROUP_MOD_EVENT_MODERATOR; - return true; - } - default: { - *out = TOX_GROUP_MOD_EVENT_KICK; - return false; + switch (value) { + case TOX_GROUP_MOD_EVENT_KICK: { + *out = TOX_GROUP_MOD_EVENT_KICK; + return true; + } + case TOX_GROUP_MOD_EVENT_OBSERVER: { + *out = TOX_GROUP_MOD_EVENT_OBSERVER; + return true; + } + case TOX_GROUP_MOD_EVENT_USER: { + *out = TOX_GROUP_MOD_EVENT_USER; + return true; + } + case TOX_GROUP_MOD_EVENT_MODERATOR: { + *out = TOX_GROUP_MOD_EVENT_MODERATOR; + return true; + } + default: { + *out = TOX_GROUP_MOD_EVENT_KICK; + return false; + } } - } } bool tox_group_mod_event_unpack(Tox_Group_Mod_Event *val, Bin_Unpack *bu) { @@ -307,36 +307,36 @@ bool tox_group_mod_event_unpack(Tox_Group_Mod_Event *val, Bin_Unpack *bu) non_null() static bool tox_group_exit_type_from_int(uint32_t value, Tox_Group_Exit_Type *out) { - switch (value) { - case TOX_GROUP_EXIT_TYPE_QUIT: { - *out = TOX_GROUP_EXIT_TYPE_QUIT; - return true; - } - case TOX_GROUP_EXIT_TYPE_TIMEOUT: { - *out = TOX_GROUP_EXIT_TYPE_TIMEOUT; - return true; - } - case TOX_GROUP_EXIT_TYPE_DISCONNECTED: { - *out = TOX_GROUP_EXIT_TYPE_DISCONNECTED; - return true; - } - case TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED: { - *out = TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED; - return true; - } - case TOX_GROUP_EXIT_TYPE_KICK: { - *out = TOX_GROUP_EXIT_TYPE_KICK; - return true; - } - case TOX_GROUP_EXIT_TYPE_SYNC_ERROR: { - *out = TOX_GROUP_EXIT_TYPE_SYNC_ERROR; - return true; - } - default: { - *out = TOX_GROUP_EXIT_TYPE_QUIT; - return false; + switch (value) { + case TOX_GROUP_EXIT_TYPE_QUIT: { + *out = TOX_GROUP_EXIT_TYPE_QUIT; + return true; + } + case TOX_GROUP_EXIT_TYPE_TIMEOUT: { + *out = TOX_GROUP_EXIT_TYPE_TIMEOUT; + return true; + } + case TOX_GROUP_EXIT_TYPE_DISCONNECTED: { + *out = TOX_GROUP_EXIT_TYPE_DISCONNECTED; + return true; + } + case TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED: { + *out = TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED; + return true; + } + case TOX_GROUP_EXIT_TYPE_KICK: { + *out = TOX_GROUP_EXIT_TYPE_KICK; + return true; + } + case TOX_GROUP_EXIT_TYPE_SYNC_ERROR: { + *out = TOX_GROUP_EXIT_TYPE_SYNC_ERROR; + return true; + } + default: { + *out = TOX_GROUP_EXIT_TYPE_QUIT; + return false; + } } - } } bool tox_group_exit_type_unpack(Tox_Group_Exit_Type *val, Bin_Unpack *bu) { diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index f7ad23a90a..c43e357528 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c @@ -80,8 +80,8 @@ void tox_pass_key_free(Tox_Pass_Key *key) * @return true on success. */ bool tox_get_salt( - const uint8_t ciphertext[TOX_PASS_ENCRYPTION_EXTRA_LENGTH], - uint8_t salt[TOX_PASS_SALT_LENGTH], Tox_Err_Get_Salt *error) + const uint8_t ciphertext[TOX_PASS_ENCRYPTION_EXTRA_LENGTH], + uint8_t salt[TOX_PASS_SALT_LENGTH], Tox_Err_Get_Salt *error) { if (ciphertext == nullptr || salt == nullptr) { SET_ERROR_PARAMETER(error, TOX_ERR_GET_SALT_NULL); @@ -115,8 +115,8 @@ bool tox_get_salt( * @return new symmetric key on success, NULL on failure. */ Tox_Pass_Key *tox_pass_key_derive( - const uint8_t passphrase[], size_t passphrase_len, - Tox_Err_Key_Derivation *error) + const uint8_t passphrase[], size_t passphrase_len, + Tox_Err_Key_Derivation *error) { const Random *rng = os_random(); @@ -140,8 +140,8 @@ Tox_Pass_Key *tox_pass_key_derive( * @return new symmetric key on success, NULL on failure. */ Tox_Pass_Key *tox_pass_key_derive_with_salt( - const uint8_t passphrase[], size_t passphrase_len, - const uint8_t salt[TOX_PASS_SALT_LENGTH], Tox_Err_Key_Derivation *error) + const uint8_t passphrase[], size_t passphrase_len, + const uint8_t salt[TOX_PASS_SALT_LENGTH], Tox_Err_Key_Derivation *error) { if (salt == nullptr || (passphrase == nullptr && passphrase_len != 0)) { SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_NULL); diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h index 602517062a..b9691551c7 100644 --- a/toxencryptsave/toxencryptsave.h +++ b/toxencryptsave/toxencryptsave.h @@ -14,7 +14,6 @@ #include #include - #ifdef __cplusplus extern "C" { #endif @@ -46,8 +45,6 @@ extern "C" { * ******************************************************************************/ - - /** * The size of the salt part of a pass-key. */ @@ -91,7 +88,6 @@ typedef enum Tox_Err_Key_Derivation { } Tox_Err_Key_Derivation; - typedef enum Tox_Err_Encryption { /** @@ -118,7 +114,6 @@ typedef enum Tox_Err_Encryption { } Tox_Err_Encryption; - typedef enum Tox_Err_Decryption { /** @@ -157,8 +152,6 @@ typedef enum Tox_Err_Decryption { } Tox_Err_Decryption; - - /******************************************************************************* * * BEGIN PART 1 @@ -169,8 +162,6 @@ typedef enum Tox_Err_Decryption { * ******************************************************************************/ - - /** * Encrypts the given data with the given passphrase. * @@ -206,7 +197,6 @@ bool tox_pass_encrypt(const uint8_t plaintext[], size_t plaintext_len, const uin bool tox_pass_decrypt(const uint8_t ciphertext[], size_t ciphertext_len, const uint8_t passphrase[], size_t passphrase_len, uint8_t plaintext[/*! ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Decryption *error); - /******************************************************************************* * * BEGIN PART 2 @@ -216,8 +206,6 @@ bool tox_pass_decrypt(const uint8_t ciphertext[], size_t ciphertext_len, const u * ******************************************************************************/ - - /** * This type represents a pass-key. * @@ -256,8 +244,8 @@ void tox_pass_key_free(Tox_Pass_Key *key); * @return new symmetric key on success, NULL on failure. */ Tox_Pass_Key *tox_pass_key_derive( - const uint8_t passphrase[], size_t passphrase_len, - Tox_Err_Key_Derivation *error); + const uint8_t passphrase[], size_t passphrase_len, + Tox_Err_Key_Derivation *error); /** * Same as above, except use the given salt for deterministic key derivation. @@ -269,8 +257,8 @@ Tox_Pass_Key *tox_pass_key_derive( * @return new symmetric key on success, NULL on failure. */ Tox_Pass_Key *tox_pass_key_derive_with_salt( - const uint8_t passphrase[], size_t passphrase_len, - const uint8_t salt[TOX_PASS_SALT_LENGTH], Tox_Err_Key_Derivation *error); + const uint8_t passphrase[], size_t passphrase_len, + const uint8_t salt[TOX_PASS_SALT_LENGTH], Tox_Err_Key_Derivation *error); /** * Encrypt a plain text with a key produced by tox_pass_key_derive or tox_pass_key_derive_with_salt. @@ -320,7 +308,6 @@ typedef enum Tox_Err_Get_Salt { } Tox_Err_Get_Salt; - /** * Retrieves the salt used to encrypt the given data. * @@ -341,8 +328,8 @@ typedef enum Tox_Err_Get_Salt { * @return true on success. */ bool tox_get_salt( - const uint8_t ciphertext[TOX_PASS_ENCRYPTION_EXTRA_LENGTH], - uint8_t salt[TOX_PASS_SALT_LENGTH], Tox_Err_Get_Salt *error); + const uint8_t ciphertext[TOX_PASS_ENCRYPTION_EXTRA_LENGTH], + uint8_t salt[TOX_PASS_SALT_LENGTH], Tox_Err_Get_Salt *error); /** * Determines whether or not the given data is encrypted by this module. @@ -360,7 +347,6 @@ bool tox_get_salt( */ bool tox_is_data_encrypted(const uint8_t data[TOX_PASS_ENCRYPTION_EXTRA_LENGTH]); - #ifdef __cplusplus } /* extern "C" */ #endif