diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 5 | ||||
-rw-r--r-- | toxcore/Messenger.c | 4 | ||||
-rw-r--r-- | toxcore/crypto_core.c | 6 | ||||
-rw-r--r-- | toxcore/crypto_core_mem.c | 2 | ||||
-rw-r--r-- | toxcore/crypto_core_test.cc | 4 | ||||
-rw-r--r-- | toxcore/ping.c | 4 | ||||
-rw-r--r-- | toxcore/ping_array.c | 4 | ||||
-rw-r--r-- | toxcore/ping_array_test.cc | 3 | ||||
-rw-r--r-- | toxcore/tox.c | 127 | ||||
-rw-r--r-- | toxcore/util_test.cc | 4 |
10 files changed, 151 insertions, 12 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 7525e695..b3017259 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -2721,6 +2721,11 @@ DHT *new_dht(const Logger *log, Mono_Time *mono_time, Networking_Core *net, bool | |||
2721 | dht->dht_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT); | 2721 | dht->dht_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT); |
2722 | dht->dht_harden_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT); | 2722 | dht->dht_harden_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT); |
2723 | 2723 | ||
2724 | if (dht->dht_ping_array == nullptr || dht->dht_harden_ping_array == nullptr) { | ||
2725 | kill_dht(dht); | ||
2726 | return nullptr; | ||
2727 | } | ||
2728 | |||
2724 | for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) { | 2729 | for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) { |
2725 | uint8_t random_public_key_bytes[CRYPTO_PUBLIC_KEY_SIZE]; | 2730 | uint8_t random_public_key_bytes[CRYPTO_PUBLIC_KEY_SIZE]; |
2726 | uint8_t random_secret_key_bytes[CRYPTO_SECRET_KEY_SIZE]; | 2731 | uint8_t random_secret_key_bytes[CRYPTO_SECRET_KEY_SIZE]; |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 6b691ad8..82c31147 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1999,8 +1999,8 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig | |||
1999 | m->net_crypto = new_net_crypto(m->log, m->mono_time, m->dht, &options->proxy_info); | 1999 | m->net_crypto = new_net_crypto(m->log, m->mono_time, m->dht, &options->proxy_info); |
2000 | 2000 | ||
2001 | if (m->net_crypto == nullptr) { | 2001 | if (m->net_crypto == nullptr) { |
2002 | kill_networking(m->net); | ||
2003 | kill_dht(m->dht); | 2002 | kill_dht(m->dht); |
2003 | kill_networking(m->net); | ||
2004 | friendreq_kill(m->fr); | 2004 | friendreq_kill(m->fr); |
2005 | logger_kill(m->log); | 2005 | logger_kill(m->log); |
2006 | free(m); | 2006 | free(m); |
@@ -2012,7 +2012,7 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig | |||
2012 | m->onion_c = new_onion_client(m->mono_time, m->net_crypto); | 2012 | m->onion_c = new_onion_client(m->mono_time, m->net_crypto); |
2013 | m->fr_c = new_friend_connections(m->mono_time, m->onion_c, options->local_discovery_enabled); | 2013 | m->fr_c = new_friend_connections(m->mono_time, m->onion_c, options->local_discovery_enabled); |
2014 | 2014 | ||
2015 | if (!(m->onion && m->onion_a && m->onion_c)) { | 2015 | if (!(m->onion && m->onion_a && m->onion_c && m->fr_c)) { |
2016 | kill_friend_connections(m->fr_c); | 2016 | kill_friend_connections(m->fr_c); |
2017 | kill_onion(m->onion); | 2017 | kill_onion(m->onion); |
2018 | kill_onion_announce(m->onion_a); | 2018 | kill_onion_announce(m->onion_a); |
diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index 5538b1b8..403e0872 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c | |||
@@ -12,12 +12,12 @@ | |||
12 | #include "config.h" | 12 | #include "config.h" |
13 | #endif | 13 | #endif |
14 | 14 | ||
15 | #include "ccompat.h" | ||
16 | #include "crypto_core.h" | ||
17 | |||
18 | #include <stdlib.h> | 15 | #include <stdlib.h> |
19 | #include <string.h> | 16 | #include <string.h> |
20 | 17 | ||
18 | #include "ccompat.h" | ||
19 | #include "crypto_core.h" | ||
20 | |||
21 | #ifndef VANILLA_NACL | 21 | #ifndef VANILLA_NACL |
22 | /* We use libsodium by default. */ | 22 | /* We use libsodium by default. */ |
23 | #include <sodium.h> | 23 | #include <sodium.h> |
diff --git a/toxcore/crypto_core_mem.c b/toxcore/crypto_core_mem.c index 86f3d0c9..b8c0bd9b 100644 --- a/toxcore/crypto_core_mem.c +++ b/toxcore/crypto_core_mem.c | |||
@@ -29,8 +29,6 @@ | |||
29 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) | 29 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) |
30 | #include <windows.h> | 30 | #include <windows.h> |
31 | #include <wincrypt.h> | 31 | #include <wincrypt.h> |
32 | #elif defined(HAVE_EXPLICIT_BZERO) | ||
33 | #include <string.h> | ||
34 | #endif | 32 | #endif |
35 | #endif | 33 | #endif |
36 | 34 | ||
diff --git a/toxcore/crypto_core_test.cc b/toxcore/crypto_core_test.cc index 66569506..9f60fb83 100644 --- a/toxcore/crypto_core_test.cc +++ b/toxcore/crypto_core_test.cc | |||
@@ -1,10 +1,10 @@ | |||
1 | #include "crypto_core.h" | 1 | #include "crypto_core.h" |
2 | 2 | ||
3 | #include <gtest/gtest.h> | ||
4 | |||
3 | #include <algorithm> | 5 | #include <algorithm> |
4 | #include <vector> | 6 | #include <vector> |
5 | 7 | ||
6 | #include <gtest/gtest.h> | ||
7 | |||
8 | namespace { | 8 | namespace { |
9 | 9 | ||
10 | enum { | 10 | enum { |
diff --git a/toxcore/ping.c b/toxcore/ping.c index d2677ee7..305cce47 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c | |||
@@ -364,6 +364,10 @@ Ping *ping_new(const Mono_Time *mono_time, DHT *dht) | |||
364 | 364 | ||
365 | void ping_kill(Ping *ping) | 365 | void ping_kill(Ping *ping) |
366 | { | 366 | { |
367 | if (ping == nullptr) { | ||
368 | return; | ||
369 | } | ||
370 | |||
367 | networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, nullptr, nullptr); | 371 | networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, nullptr, nullptr); |
368 | networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, nullptr, nullptr); | 372 | networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, nullptr, nullptr); |
369 | ping_array_kill(ping->ping_array); | 373 | ping_array_kill(ping->ping_array); |
diff --git a/toxcore/ping_array.c b/toxcore/ping_array.c index a93d48dd..201b507d 100644 --- a/toxcore/ping_array.c +++ b/toxcore/ping_array.c | |||
@@ -75,6 +75,10 @@ static void clear_entry(Ping_Array *array, uint32_t index) | |||
75 | 75 | ||
76 | void ping_array_kill(Ping_Array *array) | 76 | void ping_array_kill(Ping_Array *array) |
77 | { | 77 | { |
78 | if (array == nullptr) { | ||
79 | return; | ||
80 | } | ||
81 | |||
78 | while (array->last_deleted != array->last_added) { | 82 | while (array->last_deleted != array->last_added) { |
79 | const uint32_t index = array->last_deleted % array->total_size; | 83 | const uint32_t index = array->last_deleted % array->total_size; |
80 | clear_entry(array, index); | 84 | clear_entry(array, index); |
diff --git a/toxcore/ping_array_test.cc b/toxcore/ping_array_test.cc index fca5009a..09836efa 100644 --- a/toxcore/ping_array_test.cc +++ b/toxcore/ping_array_test.cc | |||
@@ -1,8 +1,9 @@ | |||
1 | #include "ping_array.h" | 1 | #include "ping_array.h" |
2 | 2 | ||
3 | #include <gtest/gtest.h> | ||
4 | |||
3 | #include <memory> | 5 | #include <memory> |
4 | 6 | ||
5 | #include <gtest/gtest.h> | ||
6 | #include "mono_time.h" | 7 | #include "mono_time.h" |
7 | 8 | ||
8 | namespace { | 9 | namespace { |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 7126631e..d2d3ed34 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -646,6 +646,7 @@ static void end_save(uint8_t *data) | |||
646 | 646 | ||
647 | size_t tox_get_savedata_size(const Tox *tox) | 647 | size_t tox_get_savedata_size(const Tox *tox) |
648 | { | 648 | { |
649 | assert(tox != nullptr); | ||
649 | lock(tox); | 650 | lock(tox); |
650 | size_t ret = 2 * sizeof(uint32_t) | 651 | size_t ret = 2 * sizeof(uint32_t) |
651 | + messenger_size(tox->m) | 652 | + messenger_size(tox->m) |
@@ -657,6 +658,8 @@ size_t tox_get_savedata_size(const Tox *tox) | |||
657 | 658 | ||
658 | void tox_get_savedata(const Tox *tox, uint8_t *savedata) | 659 | void tox_get_savedata(const Tox *tox, uint8_t *savedata) |
659 | { | 660 | { |
661 | assert(tox != nullptr); | ||
662 | |||
660 | if (savedata == nullptr) { | 663 | if (savedata == nullptr) { |
661 | return; | 664 | return; |
662 | } | 665 | } |
@@ -682,6 +685,8 @@ void tox_get_savedata(const Tox *tox, uint8_t *savedata) | |||
682 | 685 | ||
683 | bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error) | 686 | bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error) |
684 | { | 687 | { |
688 | assert(tox != nullptr); | ||
689 | |||
685 | if (!host || !public_key) { | 690 | if (!host || !public_key) { |
686 | SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); | 691 | SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); |
687 | return 0; | 692 | return 0; |
@@ -729,6 +734,8 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub | |||
729 | bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, | 734 | bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, |
730 | Tox_Err_Bootstrap *error) | 735 | Tox_Err_Bootstrap *error) |
731 | { | 736 | { |
737 | assert(tox != nullptr); | ||
738 | |||
732 | if (!host || !public_key) { | 739 | if (!host || !public_key) { |
733 | SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); | 740 | SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); |
734 | return 0; | 741 | return 0; |
@@ -774,6 +781,7 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t | |||
774 | 781 | ||
775 | Tox_Connection tox_self_get_connection_status(const Tox *tox) | 782 | Tox_Connection tox_self_get_connection_status(const Tox *tox) |
776 | { | 783 | { |
784 | assert(tox != nullptr); | ||
777 | lock(tox); | 785 | lock(tox); |
778 | const unsigned int ret = onion_connection_status(tox->m->onion_c); | 786 | const unsigned int ret = onion_connection_status(tox->m->onion_c); |
779 | unlock(tox); | 787 | unlock(tox); |
@@ -792,11 +800,13 @@ Tox_Connection tox_self_get_connection_status(const Tox *tox) | |||
792 | 800 | ||
793 | void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback) | 801 | void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback) |
794 | { | 802 | { |
803 | assert(tox != nullptr); | ||
795 | tox->self_connection_status_callback = callback; | 804 | tox->self_connection_status_callback = callback; |
796 | } | 805 | } |
797 | 806 | ||
798 | uint32_t tox_iteration_interval(const Tox *tox) | 807 | uint32_t tox_iteration_interval(const Tox *tox) |
799 | { | 808 | { |
809 | assert(tox != nullptr); | ||
800 | lock(tox); | 810 | lock(tox); |
801 | uint32_t ret = messenger_run_interval(tox->m); | 811 | uint32_t ret = messenger_run_interval(tox->m); |
802 | unlock(tox); | 812 | unlock(tox); |
@@ -805,6 +815,7 @@ uint32_t tox_iteration_interval(const Tox *tox) | |||
805 | 815 | ||
806 | void tox_iterate(Tox *tox, void *user_data) | 816 | void tox_iterate(Tox *tox, void *user_data) |
807 | { | 817 | { |
818 | assert(tox != nullptr); | ||
808 | lock(tox); | 819 | lock(tox); |
809 | 820 | ||
810 | mono_time_update(tox->mono_time); | 821 | mono_time_update(tox->mono_time); |
@@ -818,6 +829,8 @@ void tox_iterate(Tox *tox, void *user_data) | |||
818 | 829 | ||
819 | void tox_self_get_address(const Tox *tox, uint8_t *address) | 830 | void tox_self_get_address(const Tox *tox, uint8_t *address) |
820 | { | 831 | { |
832 | assert(tox != nullptr); | ||
833 | |||
821 | if (address) { | 834 | if (address) { |
822 | lock(tox); | 835 | lock(tox); |
823 | getaddress(tox->m, address); | 836 | getaddress(tox->m, address); |
@@ -827,6 +840,7 @@ void tox_self_get_address(const Tox *tox, uint8_t *address) | |||
827 | 840 | ||
828 | void tox_self_set_nospam(Tox *tox, uint32_t nospam) | 841 | void tox_self_set_nospam(Tox *tox, uint32_t nospam) |
829 | { | 842 | { |
843 | assert(tox != nullptr); | ||
830 | lock(tox); | 844 | lock(tox); |
831 | set_nospam(tox->m->fr, net_htonl(nospam)); | 845 | set_nospam(tox->m->fr, net_htonl(nospam)); |
832 | unlock(tox); | 846 | unlock(tox); |
@@ -834,6 +848,7 @@ void tox_self_set_nospam(Tox *tox, uint32_t nospam) | |||
834 | 848 | ||
835 | uint32_t tox_self_get_nospam(const Tox *tox) | 849 | uint32_t tox_self_get_nospam(const Tox *tox) |
836 | { | 850 | { |
851 | assert(tox != nullptr); | ||
837 | lock(tox); | 852 | lock(tox); |
838 | uint32_t ret = net_ntohl(get_nospam(tox->m->fr)); | 853 | uint32_t ret = net_ntohl(get_nospam(tox->m->fr)); |
839 | unlock(tox); | 854 | unlock(tox); |
@@ -842,6 +857,8 @@ uint32_t tox_self_get_nospam(const Tox *tox) | |||
842 | 857 | ||
843 | void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) | 858 | void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) |
844 | { | 859 | { |
860 | assert(tox != nullptr); | ||
861 | |||
845 | if (public_key) { | 862 | if (public_key) { |
846 | lock(tox); | 863 | lock(tox); |
847 | memcpy(public_key, nc_get_self_public_key(tox->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE); | 864 | memcpy(public_key, nc_get_self_public_key(tox->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE); |
@@ -851,6 +868,8 @@ void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) | |||
851 | 868 | ||
852 | void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key) | 869 | void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key) |
853 | { | 870 | { |
871 | assert(tox != nullptr); | ||
872 | |||
854 | if (secret_key) { | 873 | if (secret_key) { |
855 | lock(tox); | 874 | lock(tox); |
856 | memcpy(secret_key, nc_get_self_secret_key(tox->m->net_crypto), CRYPTO_SECRET_KEY_SIZE); | 875 | memcpy(secret_key, nc_get_self_secret_key(tox->m->net_crypto), CRYPTO_SECRET_KEY_SIZE); |
@@ -860,6 +879,8 @@ void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key) | |||
860 | 879 | ||
861 | bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set_Info *error) | 880 | bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set_Info *error) |
862 | { | 881 | { |
882 | assert(tox != nullptr); | ||
883 | |||
863 | if (!name && length != 0) { | 884 | if (!name && length != 0) { |
864 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); | 885 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); |
865 | return 0; | 886 | return 0; |
@@ -882,6 +903,7 @@ bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set | |||
882 | 903 | ||
883 | size_t tox_self_get_name_size(const Tox *tox) | 904 | size_t tox_self_get_name_size(const Tox *tox) |
884 | { | 905 | { |
906 | assert(tox != nullptr); | ||
885 | lock(tox); | 907 | lock(tox); |
886 | size_t ret = m_get_self_name_size(tox->m); | 908 | size_t ret = m_get_self_name_size(tox->m); |
887 | unlock(tox); | 909 | unlock(tox); |
@@ -890,6 +912,8 @@ size_t tox_self_get_name_size(const Tox *tox) | |||
890 | 912 | ||
891 | void tox_self_get_name(const Tox *tox, uint8_t *name) | 913 | void tox_self_get_name(const Tox *tox, uint8_t *name) |
892 | { | 914 | { |
915 | assert(tox != nullptr); | ||
916 | |||
893 | if (name) { | 917 | if (name) { |
894 | lock(tox); | 918 | lock(tox); |
895 | getself_name(tox->m, name); | 919 | getself_name(tox->m, name); |
@@ -899,6 +923,8 @@ void tox_self_get_name(const Tox *tox, uint8_t *name) | |||
899 | 923 | ||
900 | bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t length, Tox_Err_Set_Info *error) | 924 | bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t length, Tox_Err_Set_Info *error) |
901 | { | 925 | { |
926 | assert(tox != nullptr); | ||
927 | |||
902 | if (!status_message && length != 0) { | 928 | if (!status_message && length != 0) { |
903 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); | 929 | SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); |
904 | return 0; | 930 | return 0; |
@@ -919,6 +945,7 @@ bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t | |||
919 | 945 | ||
920 | size_t tox_self_get_status_message_size(const Tox *tox) | 946 | size_t tox_self_get_status_message_size(const Tox *tox) |
921 | { | 947 | { |
948 | assert(tox != nullptr); | ||
922 | lock(tox); | 949 | lock(tox); |
923 | size_t ret = m_get_self_statusmessage_size(tox->m); | 950 | size_t ret = m_get_self_statusmessage_size(tox->m); |
924 | unlock(tox); | 951 | unlock(tox); |
@@ -927,6 +954,8 @@ size_t tox_self_get_status_message_size(const Tox *tox) | |||
927 | 954 | ||
928 | void tox_self_get_status_message(const Tox *tox, uint8_t *status_message) | 955 | void tox_self_get_status_message(const Tox *tox, uint8_t *status_message) |
929 | { | 956 | { |
957 | assert(tox != nullptr); | ||
958 | |||
930 | if (status_message) { | 959 | if (status_message) { |
931 | lock(tox); | 960 | lock(tox); |
932 | m_copy_self_statusmessage(tox->m, status_message); | 961 | m_copy_self_statusmessage(tox->m, status_message); |
@@ -936,6 +965,7 @@ void tox_self_get_status_message(const Tox *tox, uint8_t *status_message) | |||
936 | 965 | ||
937 | void tox_self_set_status(Tox *tox, Tox_User_Status status) | 966 | void tox_self_set_status(Tox *tox, Tox_User_Status status) |
938 | { | 967 | { |
968 | assert(tox != nullptr); | ||
939 | lock(tox); | 969 | lock(tox); |
940 | m_set_userstatus(tox->m, status); | 970 | m_set_userstatus(tox->m, status); |
941 | unlock(tox); | 971 | unlock(tox); |
@@ -943,6 +973,7 @@ void tox_self_set_status(Tox *tox, Tox_User_Status status) | |||
943 | 973 | ||
944 | Tox_User_Status tox_self_get_status(const Tox *tox) | 974 | Tox_User_Status tox_self_get_status(const Tox *tox) |
945 | { | 975 | { |
976 | assert(tox != nullptr); | ||
946 | lock(tox); | 977 | lock(tox); |
947 | const uint8_t status = m_get_self_userstatus(tox->m); | 978 | const uint8_t status = m_get_self_userstatus(tox->m); |
948 | unlock(tox); | 979 | unlock(tox); |
@@ -990,6 +1021,8 @@ static void set_friend_error(const Logger *log, int32_t ret, Tox_Err_Friend_Add | |||
990 | uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length, | 1021 | uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length, |
991 | Tox_Err_Friend_Add *error) | 1022 | Tox_Err_Friend_Add *error) |
992 | { | 1023 | { |
1024 | assert(tox != nullptr); | ||
1025 | |||
993 | if (!address || !message) { | 1026 | if (!address || !message) { |
994 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL); | 1027 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL); |
995 | return UINT32_MAX; | 1028 | return UINT32_MAX; |
@@ -1011,6 +1044,8 @@ uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message | |||
1011 | 1044 | ||
1012 | uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_Friend_Add *error) | 1045 | uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_Friend_Add *error) |
1013 | { | 1046 | { |
1047 | assert(tox != nullptr); | ||
1048 | |||
1014 | if (!public_key) { | 1049 | if (!public_key) { |
1015 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL); | 1050 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL); |
1016 | return UINT32_MAX; | 1051 | return UINT32_MAX; |
@@ -1032,6 +1067,7 @@ uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_F | |||
1032 | 1067 | ||
1033 | bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *error) | 1068 | bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *error) |
1034 | { | 1069 | { |
1070 | assert(tox != nullptr); | ||
1035 | lock(tox); | 1071 | lock(tox); |
1036 | const int ret = m_delfriend(tox->m, friend_number); | 1072 | const int ret = m_delfriend(tox->m, friend_number); |
1037 | unlock(tox); | 1073 | unlock(tox); |
@@ -1048,6 +1084,8 @@ bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete * | |||
1048 | 1084 | ||
1049 | uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox_Err_Friend_By_Public_Key *error) | 1085 | uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox_Err_Friend_By_Public_Key *error) |
1050 | { | 1086 | { |
1087 | assert(tox != nullptr); | ||
1088 | |||
1051 | if (!public_key) { | 1089 | if (!public_key) { |
1052 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_BY_PUBLIC_KEY_NULL); | 1090 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_BY_PUBLIC_KEY_NULL); |
1053 | return UINT32_MAX; | 1091 | return UINT32_MAX; |
@@ -1069,6 +1107,8 @@ uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox | |||
1069 | bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key, | 1107 | bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key, |
1070 | Tox_Err_Friend_Get_Public_Key *error) | 1108 | Tox_Err_Friend_Get_Public_Key *error) |
1071 | { | 1109 | { |
1110 | assert(tox != nullptr); | ||
1111 | |||
1072 | if (!public_key) { | 1112 | if (!public_key) { |
1073 | return 0; | 1113 | return 0; |
1074 | } | 1114 | } |
@@ -1088,6 +1128,7 @@ bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t * | |||
1088 | 1128 | ||
1089 | bool tox_friend_exists(const Tox *tox, uint32_t friend_number) | 1129 | bool tox_friend_exists(const Tox *tox, uint32_t friend_number) |
1090 | { | 1130 | { |
1131 | assert(tox != nullptr); | ||
1091 | lock(tox); | 1132 | lock(tox); |
1092 | bool ret = m_friend_exists(tox->m, friend_number); | 1133 | bool ret = m_friend_exists(tox->m, friend_number); |
1093 | unlock(tox); | 1134 | unlock(tox); |
@@ -1096,6 +1137,7 @@ bool tox_friend_exists(const Tox *tox, uint32_t friend_number) | |||
1096 | 1137 | ||
1097 | uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Get_Last_Online *error) | 1138 | uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Get_Last_Online *error) |
1098 | { | 1139 | { |
1140 | assert(tox != nullptr); | ||
1099 | lock(tox); | 1141 | lock(tox); |
1100 | const uint64_t timestamp = m_get_last_online(tox->m, friend_number); | 1142 | const uint64_t timestamp = m_get_last_online(tox->m, friend_number); |
1101 | unlock(tox); | 1143 | unlock(tox); |
@@ -1111,6 +1153,7 @@ uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_ | |||
1111 | 1153 | ||
1112 | size_t tox_self_get_friend_list_size(const Tox *tox) | 1154 | size_t tox_self_get_friend_list_size(const Tox *tox) |
1113 | { | 1155 | { |
1156 | assert(tox != nullptr); | ||
1114 | lock(tox); | 1157 | lock(tox); |
1115 | size_t ret = count_friendlist(tox->m); | 1158 | size_t ret = count_friendlist(tox->m); |
1116 | unlock(tox); | 1159 | unlock(tox); |
@@ -1119,6 +1162,8 @@ size_t tox_self_get_friend_list_size(const Tox *tox) | |||
1119 | 1162 | ||
1120 | void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list) | 1163 | void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list) |
1121 | { | 1164 | { |
1165 | assert(tox != nullptr); | ||
1166 | |||
1122 | if (friend_list) { | 1167 | if (friend_list) { |
1123 | lock(tox); | 1168 | lock(tox); |
1124 | // TODO(irungentoo): size parameter? | 1169 | // TODO(irungentoo): size parameter? |
@@ -1129,6 +1174,7 @@ void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list) | |||
1129 | 1174 | ||
1130 | size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) | 1175 | size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) |
1131 | { | 1176 | { |
1177 | assert(tox != nullptr); | ||
1132 | lock(tox); | 1178 | lock(tox); |
1133 | const int ret = m_get_name_size(tox->m, friend_number); | 1179 | const int ret = m_get_name_size(tox->m, friend_number); |
1134 | unlock(tox); | 1180 | unlock(tox); |
@@ -1144,6 +1190,8 @@ size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_ | |||
1144 | 1190 | ||
1145 | bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, Tox_Err_Friend_Query *error) | 1191 | bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, Tox_Err_Friend_Query *error) |
1146 | { | 1192 | { |
1193 | assert(tox != nullptr); | ||
1194 | |||
1147 | if (!name) { | 1195 | if (!name) { |
1148 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL); | 1196 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL); |
1149 | return 0; | 1197 | return 0; |
@@ -1164,11 +1212,13 @@ bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, | |||
1164 | 1212 | ||
1165 | void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback) | 1213 | void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback) |
1166 | { | 1214 | { |
1215 | assert(tox != nullptr); | ||
1167 | tox->friend_name_callback = callback; | 1216 | tox->friend_name_callback = callback; |
1168 | } | 1217 | } |
1169 | 1218 | ||
1170 | size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) | 1219 | size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) |
1171 | { | 1220 | { |
1221 | assert(tox != nullptr); | ||
1172 | lock(tox); | 1222 | lock(tox); |
1173 | const int ret = m_get_statusmessage_size(tox->m, friend_number); | 1223 | const int ret = m_get_statusmessage_size(tox->m, friend_number); |
1174 | unlock(tox); | 1224 | unlock(tox); |
@@ -1185,6 +1235,8 @@ size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number | |||
1185 | bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8_t *status_message, | 1235 | bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8_t *status_message, |
1186 | Tox_Err_Friend_Query *error) | 1236 | Tox_Err_Friend_Query *error) |
1187 | { | 1237 | { |
1238 | assert(tox != nullptr); | ||
1239 | |||
1188 | if (!status_message) { | 1240 | if (!status_message) { |
1189 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL); | 1241 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL); |
1190 | return false; | 1242 | return false; |
@@ -1209,11 +1261,13 @@ bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8 | |||
1209 | 1261 | ||
1210 | void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback) | 1262 | void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback) |
1211 | { | 1263 | { |
1264 | assert(tox != nullptr); | ||
1212 | tox->friend_status_message_callback = callback; | 1265 | tox->friend_status_message_callback = callback; |
1213 | } | 1266 | } |
1214 | 1267 | ||
1215 | Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) | 1268 | Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) |
1216 | { | 1269 | { |
1270 | assert(tox != nullptr); | ||
1217 | lock(tox); | 1271 | lock(tox); |
1218 | const int ret = m_get_userstatus(tox->m, friend_number); | 1272 | const int ret = m_get_userstatus(tox->m, friend_number); |
1219 | unlock(tox); | 1273 | unlock(tox); |
@@ -1229,11 +1283,13 @@ Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, To | |||
1229 | 1283 | ||
1230 | void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback) | 1284 | void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback) |
1231 | { | 1285 | { |
1286 | assert(tox != nullptr); | ||
1232 | tox->friend_status_callback = callback; | 1287 | tox->friend_status_callback = callback; |
1233 | } | 1288 | } |
1234 | 1289 | ||
1235 | Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) | 1290 | Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) |
1236 | { | 1291 | { |
1292 | assert(tox != nullptr); | ||
1237 | lock(tox); | 1293 | lock(tox); |
1238 | const int ret = m_get_friend_connectionstatus(tox->m, friend_number); | 1294 | const int ret = m_get_friend_connectionstatus(tox->m, friend_number); |
1239 | unlock(tox); | 1295 | unlock(tox); |
@@ -1249,11 +1305,13 @@ Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_ | |||
1249 | 1305 | ||
1250 | void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback) | 1306 | void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback) |
1251 | { | 1307 | { |
1308 | assert(tox != nullptr); | ||
1252 | tox->friend_connection_status_callback = callback; | 1309 | tox->friend_connection_status_callback = callback; |
1253 | } | 1310 | } |
1254 | 1311 | ||
1255 | bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) | 1312 | bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) |
1256 | { | 1313 | { |
1314 | assert(tox != nullptr); | ||
1257 | lock(tox); | 1315 | lock(tox); |
1258 | const int ret = m_get_istyping(tox->m, friend_number); | 1316 | const int ret = m_get_istyping(tox->m, friend_number); |
1259 | unlock(tox); | 1317 | unlock(tox); |
@@ -1269,11 +1327,13 @@ bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Frien | |||
1269 | 1327 | ||
1270 | void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback) | 1328 | void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback) |
1271 | { | 1329 | { |
1330 | assert(tox != nullptr); | ||
1272 | tox->friend_typing_callback = callback; | 1331 | tox->friend_typing_callback = callback; |
1273 | } | 1332 | } |
1274 | 1333 | ||
1275 | bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, Tox_Err_Set_Typing *error) | 1334 | bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, Tox_Err_Set_Typing *error) |
1276 | { | 1335 | { |
1336 | assert(tox != nullptr); | ||
1277 | lock(tox); | 1337 | lock(tox); |
1278 | 1338 | ||
1279 | if (m_set_usertyping(tox->m, friend_number, typing) == -1) { | 1339 | if (m_set_usertyping(tox->m, friend_number, typing) == -1) { |
@@ -1324,6 +1384,8 @@ static void set_message_error(const Logger *log, int ret, Tox_Err_Friend_Send_Me | |||
1324 | uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_Type type, const uint8_t *message, | 1384 | uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_Type type, const uint8_t *message, |
1325 | size_t length, Tox_Err_Friend_Send_Message *error) | 1385 | size_t length, Tox_Err_Friend_Send_Message *error) |
1326 | { | 1386 | { |
1387 | assert(tox != nullptr); | ||
1388 | |||
1327 | if (!message) { | 1389 | if (!message) { |
1328 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_NULL); | 1390 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_NULL); |
1329 | return 0; | 1391 | return 0; |
@@ -1344,16 +1406,19 @@ uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_T | |||
1344 | 1406 | ||
1345 | void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *callback) | 1407 | void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *callback) |
1346 | { | 1408 | { |
1409 | assert(tox != nullptr); | ||
1347 | tox->friend_read_receipt_callback = callback; | 1410 | tox->friend_read_receipt_callback = callback; |
1348 | } | 1411 | } |
1349 | 1412 | ||
1350 | void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback) | 1413 | void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback) |
1351 | { | 1414 | { |
1415 | assert(tox != nullptr); | ||
1352 | tox->friend_request_callback = callback; | 1416 | tox->friend_request_callback = callback; |
1353 | } | 1417 | } |
1354 | 1418 | ||
1355 | void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback) | 1419 | void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback) |
1356 | { | 1420 | { |
1421 | assert(tox != nullptr); | ||
1357 | tox->friend_message_callback = callback; | 1422 | tox->friend_message_callback = callback; |
1358 | } | 1423 | } |
1359 | 1424 | ||
@@ -1370,6 +1435,7 @@ bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length) | |||
1370 | bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control, | 1435 | bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control, |
1371 | Tox_Err_File_Control *error) | 1436 | Tox_Err_File_Control *error) |
1372 | { | 1437 | { |
1438 | assert(tox != nullptr); | ||
1373 | lock(tox); | 1439 | lock(tox); |
1374 | const int ret = file_control(tox->m, friend_number, file_number, control); | 1440 | const int ret = file_control(tox->m, friend_number, file_number, control); |
1375 | unlock(tox); | 1441 | unlock(tox); |
@@ -1420,6 +1486,7 @@ bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, To | |||
1420 | bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, | 1486 | bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, |
1421 | Tox_Err_File_Seek *error) | 1487 | Tox_Err_File_Seek *error) |
1422 | { | 1488 | { |
1489 | assert(tox != nullptr); | ||
1423 | lock(tox); | 1490 | lock(tox); |
1424 | const int ret = file_seek(tox->m, friend_number, file_number, position); | 1491 | const int ret = file_seek(tox->m, friend_number, file_number, position); |
1425 | unlock(tox); | 1492 | unlock(tox); |
@@ -1462,12 +1529,15 @@ bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint6 | |||
1462 | 1529 | ||
1463 | void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback) | 1530 | void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback) |
1464 | { | 1531 | { |
1532 | assert(tox != nullptr); | ||
1465 | tox->file_recv_control_callback = callback; | 1533 | tox->file_recv_control_callback = callback; |
1466 | } | 1534 | } |
1467 | 1535 | ||
1468 | bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, | 1536 | bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, |
1469 | Tox_Err_File_Get *error) | 1537 | Tox_Err_File_Get *error) |
1470 | { | 1538 | { |
1539 | assert(tox != nullptr); | ||
1540 | |||
1471 | if (!file_id) { | 1541 | if (!file_id) { |
1472 | SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NULL); | 1542 | SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NULL); |
1473 | return 0; | 1543 | return 0; |
@@ -1494,6 +1564,8 @@ bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_ | |||
1494 | uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id, | 1564 | uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id, |
1495 | const uint8_t *filename, size_t filename_length, Tox_Err_File_Send *error) | 1565 | const uint8_t *filename, size_t filename_length, Tox_Err_File_Send *error) |
1496 | { | 1566 | { |
1567 | assert(tox != nullptr); | ||
1568 | |||
1497 | if (filename_length && !filename) { | 1569 | if (filename_length && !filename) { |
1498 | SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL); | 1570 | SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL); |
1499 | return UINT32_MAX; | 1571 | return UINT32_MAX; |
@@ -1541,6 +1613,7 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t | |||
1541 | bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data, | 1613 | bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data, |
1542 | size_t length, Tox_Err_File_Send_Chunk *error) | 1614 | size_t length, Tox_Err_File_Send_Chunk *error) |
1543 | { | 1615 | { |
1616 | assert(tox != nullptr); | ||
1544 | lock(tox); | 1617 | lock(tox); |
1545 | const int ret = file_data(tox->m, friend_number, file_number, position, data, length); | 1618 | const int ret = file_data(tox->m, friend_number, file_number, position, data, length); |
1546 | unlock(tox); | 1619 | unlock(tox); |
@@ -1586,51 +1659,61 @@ bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, | |||
1586 | 1659 | ||
1587 | void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback) | 1660 | void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback) |
1588 | { | 1661 | { |
1662 | assert(tox != nullptr); | ||
1589 | tox->file_chunk_request_callback = callback; | 1663 | tox->file_chunk_request_callback = callback; |
1590 | } | 1664 | } |
1591 | 1665 | ||
1592 | void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback) | 1666 | void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback) |
1593 | { | 1667 | { |
1668 | assert(tox != nullptr); | ||
1594 | tox->file_recv_callback = callback; | 1669 | tox->file_recv_callback = callback; |
1595 | } | 1670 | } |
1596 | 1671 | ||
1597 | void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback) | 1672 | void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback) |
1598 | { | 1673 | { |
1674 | assert(tox != nullptr); | ||
1599 | tox->file_recv_chunk_callback = callback; | 1675 | tox->file_recv_chunk_callback = callback; |
1600 | } | 1676 | } |
1601 | 1677 | ||
1602 | void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback) | 1678 | void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback) |
1603 | { | 1679 | { |
1680 | assert(tox != nullptr); | ||
1604 | tox->conference_invite_callback = callback; | 1681 | tox->conference_invite_callback = callback; |
1605 | } | 1682 | } |
1606 | 1683 | ||
1607 | void tox_callback_conference_connected(Tox *tox, tox_conference_connected_cb *callback) | 1684 | void tox_callback_conference_connected(Tox *tox, tox_conference_connected_cb *callback) |
1608 | { | 1685 | { |
1686 | assert(tox != nullptr); | ||
1609 | tox->conference_connected_callback = callback; | 1687 | tox->conference_connected_callback = callback; |
1610 | } | 1688 | } |
1611 | 1689 | ||
1612 | void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback) | 1690 | void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback) |
1613 | { | 1691 | { |
1692 | assert(tox != nullptr); | ||
1614 | tox->conference_message_callback = callback; | 1693 | tox->conference_message_callback = callback; |
1615 | } | 1694 | } |
1616 | 1695 | ||
1617 | void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback) | 1696 | void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback) |
1618 | { | 1697 | { |
1698 | assert(tox != nullptr); | ||
1619 | tox->conference_title_callback = callback; | 1699 | tox->conference_title_callback = callback; |
1620 | } | 1700 | } |
1621 | 1701 | ||
1622 | void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *callback) | 1702 | void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *callback) |
1623 | { | 1703 | { |
1704 | assert(tox != nullptr); | ||
1624 | tox->conference_peer_name_callback = callback; | 1705 | tox->conference_peer_name_callback = callback; |
1625 | } | 1706 | } |
1626 | 1707 | ||
1627 | void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_list_changed_cb *callback) | 1708 | void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_list_changed_cb *callback) |
1628 | { | 1709 | { |
1710 | assert(tox != nullptr); | ||
1629 | tox->conference_peer_list_changed_callback = callback; | 1711 | tox->conference_peer_list_changed_callback = callback; |
1630 | } | 1712 | } |
1631 | 1713 | ||
1632 | uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error) | 1714 | uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error) |
1633 | { | 1715 | { |
1716 | assert(tox != nullptr); | ||
1634 | lock(tox); | 1717 | lock(tox); |
1635 | const int ret = add_groupchat(tox->m->conferences_object, GROUPCHAT_TYPE_TEXT); | 1718 | const int ret = add_groupchat(tox->m->conferences_object, GROUPCHAT_TYPE_TEXT); |
1636 | unlock(tox); | 1719 | unlock(tox); |
@@ -1646,6 +1729,7 @@ uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error) | |||
1646 | 1729 | ||
1647 | bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error) | 1730 | bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error) |
1648 | { | 1731 | { |
1732 | assert(tox != nullptr); | ||
1649 | lock(tox); | 1733 | lock(tox); |
1650 | const int ret = del_groupchat(tox->m->conferences_object, conference_number, true); | 1734 | const int ret = del_groupchat(tox->m->conferences_object, conference_number, true); |
1651 | unlock(tox); | 1735 | unlock(tox); |
@@ -1661,6 +1745,7 @@ bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Confere | |||
1661 | 1745 | ||
1662 | uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error) | 1746 | uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error) |
1663 | { | 1747 | { |
1748 | assert(tox != nullptr); | ||
1664 | lock(tox); | 1749 | lock(tox); |
1665 | const int ret = group_number_peers(tox->m->conferences_object, conference_number, false); | 1750 | const int ret = group_number_peers(tox->m->conferences_object, conference_number, false); |
1666 | unlock(tox); | 1751 | unlock(tox); |
@@ -1677,6 +1762,7 @@ uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, T | |||
1677 | size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number, | 1762 | size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number, |
1678 | Tox_Err_Conference_Peer_Query *error) | 1763 | Tox_Err_Conference_Peer_Query *error) |
1679 | { | 1764 | { |
1765 | assert(tox != nullptr); | ||
1680 | lock(tox); | 1766 | lock(tox); |
1681 | const int ret = group_peername_size(tox->m->conferences_object, conference_number, peer_number, false); | 1767 | const int ret = group_peername_size(tox->m->conferences_object, conference_number, peer_number, false); |
1682 | unlock(tox); | 1768 | unlock(tox); |
@@ -1698,6 +1784,7 @@ size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_num | |||
1698 | bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name, | 1784 | bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name, |
1699 | Tox_Err_Conference_Peer_Query *error) | 1785 | Tox_Err_Conference_Peer_Query *error) |
1700 | { | 1786 | { |
1787 | assert(tox != nullptr); | ||
1701 | lock(tox); | 1788 | lock(tox); |
1702 | const int ret = group_peername(tox->m->conferences_object, conference_number, peer_number, name, false); | 1789 | const int ret = group_peername(tox->m->conferences_object, conference_number, peer_number, name, false); |
1703 | unlock(tox); | 1790 | unlock(tox); |
@@ -1719,6 +1806,7 @@ bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, ui | |||
1719 | bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number, | 1806 | bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number, |
1720 | uint8_t *public_key, Tox_Err_Conference_Peer_Query *error) | 1807 | uint8_t *public_key, Tox_Err_Conference_Peer_Query *error) |
1721 | { | 1808 | { |
1809 | assert(tox != nullptr); | ||
1722 | lock(tox); | 1810 | lock(tox); |
1723 | const int ret = group_peer_pubkey(tox->m->conferences_object, conference_number, peer_number, public_key, false); | 1811 | const int ret = group_peer_pubkey(tox->m->conferences_object, conference_number, peer_number, public_key, false); |
1724 | unlock(tox); | 1812 | unlock(tox); |
@@ -1740,6 +1828,7 @@ bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_numb | |||
1740 | bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number, | 1828 | bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number, |
1741 | Tox_Err_Conference_Peer_Query *error) | 1829 | Tox_Err_Conference_Peer_Query *error) |
1742 | { | 1830 | { |
1831 | assert(tox != nullptr); | ||
1743 | lock(tox); | 1832 | lock(tox); |
1744 | const int ret = group_peernumber_is_ours(tox->m->conferences_object, conference_number, peer_number); | 1833 | const int ret = group_peernumber_is_ours(tox->m->conferences_object, conference_number, peer_number); |
1745 | unlock(tox); | 1834 | unlock(tox); |
@@ -1765,6 +1854,7 @@ bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_numb | |||
1765 | uint32_t tox_conference_offline_peer_count(const Tox *tox, uint32_t conference_number, | 1854 | uint32_t tox_conference_offline_peer_count(const Tox *tox, uint32_t conference_number, |
1766 | Tox_Err_Conference_Peer_Query *error) | 1855 | Tox_Err_Conference_Peer_Query *error) |
1767 | { | 1856 | { |
1857 | assert(tox != nullptr); | ||
1768 | lock(tox); | 1858 | lock(tox); |
1769 | const int ret = group_number_peers(tox->m->conferences_object, conference_number, true); | 1859 | const int ret = group_number_peers(tox->m->conferences_object, conference_number, true); |
1770 | unlock(tox); | 1860 | unlock(tox); |
@@ -1782,6 +1872,7 @@ size_t tox_conference_offline_peer_get_name_size(const Tox *tox, uint32_t confer | |||
1782 | uint32_t offline_peer_number, | 1872 | uint32_t offline_peer_number, |
1783 | Tox_Err_Conference_Peer_Query *error) | 1873 | Tox_Err_Conference_Peer_Query *error) |
1784 | { | 1874 | { |
1875 | assert(tox != nullptr); | ||
1785 | lock(tox); | 1876 | lock(tox); |
1786 | const int ret = group_peername_size(tox->m->conferences_object, conference_number, offline_peer_number, true); | 1877 | const int ret = group_peername_size(tox->m->conferences_object, conference_number, offline_peer_number, true); |
1787 | unlock(tox); | 1878 | unlock(tox); |
@@ -1804,6 +1895,7 @@ bool tox_conference_offline_peer_get_name(const Tox *tox, uint32_t conference_nu | |||
1804 | uint8_t *name, | 1895 | uint8_t *name, |
1805 | Tox_Err_Conference_Peer_Query *error) | 1896 | Tox_Err_Conference_Peer_Query *error) |
1806 | { | 1897 | { |
1898 | assert(tox != nullptr); | ||
1807 | lock(tox); | 1899 | lock(tox); |
1808 | const int ret = group_peername(tox->m->conferences_object, conference_number, offline_peer_number, name, true); | 1900 | const int ret = group_peername(tox->m->conferences_object, conference_number, offline_peer_number, name, true); |
1809 | unlock(tox); | 1901 | unlock(tox); |
@@ -1826,6 +1918,7 @@ bool tox_conference_offline_peer_get_public_key(const Tox *tox, uint32_t confere | |||
1826 | uint32_t offline_peer_number, | 1918 | uint32_t offline_peer_number, |
1827 | uint8_t *public_key, Tox_Err_Conference_Peer_Query *error) | 1919 | uint8_t *public_key, Tox_Err_Conference_Peer_Query *error) |
1828 | { | 1920 | { |
1921 | assert(tox != nullptr); | ||
1829 | lock(tox); | 1922 | lock(tox); |
1830 | const int ret = group_peer_pubkey(tox->m->conferences_object, conference_number, offline_peer_number, public_key, true); | 1923 | const int ret = group_peer_pubkey(tox->m->conferences_object, conference_number, offline_peer_number, public_key, true); |
1831 | unlock(tox); | 1924 | unlock(tox); |
@@ -1848,6 +1941,7 @@ uint64_t tox_conference_offline_peer_get_last_active(const Tox *tox, uint32_t co | |||
1848 | uint32_t offline_peer_number, | 1941 | uint32_t offline_peer_number, |
1849 | Tox_Err_Conference_Peer_Query *error) | 1942 | Tox_Err_Conference_Peer_Query *error) |
1850 | { | 1943 | { |
1944 | assert(tox != nullptr); | ||
1851 | uint64_t last_active = UINT64_MAX; | 1945 | uint64_t last_active = UINT64_MAX; |
1852 | lock(tox); | 1946 | lock(tox); |
1853 | const int ret = group_frozen_last_active(tox->m->conferences_object, conference_number, offline_peer_number, | 1947 | const int ret = group_frozen_last_active(tox->m->conferences_object, conference_number, offline_peer_number, |
@@ -1872,6 +1966,7 @@ bool tox_conference_set_max_offline(Tox *tox, uint32_t conference_number, | |||
1872 | uint32_t max_offline_peers, | 1966 | uint32_t max_offline_peers, |
1873 | Tox_Err_Conference_Set_Max_Offline *error) | 1967 | Tox_Err_Conference_Set_Max_Offline *error) |
1874 | { | 1968 | { |
1969 | assert(tox != nullptr); | ||
1875 | lock(tox); | 1970 | lock(tox); |
1876 | const int ret = group_set_max_frozen(tox->m->conferences_object, conference_number, max_offline_peers); | 1971 | const int ret = group_set_max_frozen(tox->m->conferences_object, conference_number, max_offline_peers); |
1877 | unlock(tox); | 1972 | unlock(tox); |
@@ -1888,6 +1983,7 @@ bool tox_conference_set_max_offline(Tox *tox, uint32_t conference_number, | |||
1888 | bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number, | 1983 | bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number, |
1889 | Tox_Err_Conference_Invite *error) | 1984 | Tox_Err_Conference_Invite *error) |
1890 | { | 1985 | { |
1986 | assert(tox != nullptr); | ||
1891 | lock(tox); | 1987 | lock(tox); |
1892 | const int ret = invite_friend(tox->m->conferences_object, friend_number, conference_number); | 1988 | const int ret = invite_friend(tox->m->conferences_object, friend_number, conference_number); |
1893 | unlock(tox); | 1989 | unlock(tox); |
@@ -1913,6 +2009,7 @@ bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference | |||
1913 | uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length, | 2009 | uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length, |
1914 | Tox_Err_Conference_Join *error) | 2010 | Tox_Err_Conference_Join *error) |
1915 | { | 2011 | { |
2012 | assert(tox != nullptr); | ||
1916 | lock(tox); | 2013 | lock(tox); |
1917 | const int ret = join_groupchat(tox->m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length); | 2014 | const int ret = join_groupchat(tox->m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length); |
1918 | unlock(tox); | 2015 | unlock(tox); |
@@ -1950,6 +2047,7 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co | |||
1950 | bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Message_Type type, const uint8_t *message, | 2047 | bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Message_Type type, const uint8_t *message, |
1951 | size_t length, Tox_Err_Conference_Send_Message *error) | 2048 | size_t length, Tox_Err_Conference_Send_Message *error) |
1952 | { | 2049 | { |
2050 | assert(tox != nullptr); | ||
1953 | lock(tox); | 2051 | lock(tox); |
1954 | int ret = 0; | 2052 | int ret = 0; |
1955 | 2053 | ||
@@ -1985,6 +2083,7 @@ bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Messa | |||
1985 | 2083 | ||
1986 | size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error) | 2084 | size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error) |
1987 | { | 2085 | { |
2086 | assert(tox != nullptr); | ||
1988 | lock(tox); | 2087 | lock(tox); |
1989 | const int ret = group_title_get_size(tox->m->conferences_object, conference_number); | 2088 | const int ret = group_title_get_size(tox->m->conferences_object, conference_number); |
1990 | unlock(tox); | 2089 | unlock(tox); |
@@ -2006,6 +2105,7 @@ size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, | |||
2006 | bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title, | 2105 | bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title, |
2007 | Tox_Err_Conference_Title *error) | 2106 | Tox_Err_Conference_Title *error) |
2008 | { | 2107 | { |
2108 | assert(tox != nullptr); | ||
2009 | lock(tox); | 2109 | lock(tox); |
2010 | const int ret = group_title_get(tox->m->conferences_object, conference_number, title); | 2110 | const int ret = group_title_get(tox->m->conferences_object, conference_number, title); |
2011 | unlock(tox); | 2111 | unlock(tox); |
@@ -2027,6 +2127,7 @@ bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_ | |||
2027 | bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length, | 2127 | bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length, |
2028 | Tox_Err_Conference_Title *error) | 2128 | Tox_Err_Conference_Title *error) |
2029 | { | 2129 | { |
2130 | assert(tox != nullptr); | ||
2030 | lock(tox); | 2131 | lock(tox); |
2031 | const int ret = group_title_send(tox->m->conferences_object, conference_number, title, length); | 2132 | const int ret = group_title_send(tox->m->conferences_object, conference_number, title, length); |
2032 | unlock(tox); | 2133 | unlock(tox); |
@@ -2051,6 +2152,7 @@ bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_ | |||
2051 | 2152 | ||
2052 | size_t tox_conference_get_chatlist_size(const Tox *tox) | 2153 | size_t tox_conference_get_chatlist_size(const Tox *tox) |
2053 | { | 2154 | { |
2155 | assert(tox != nullptr); | ||
2054 | lock(tox); | 2156 | lock(tox); |
2055 | size_t ret = count_chatlist(tox->m->conferences_object); | 2157 | size_t ret = count_chatlist(tox->m->conferences_object); |
2056 | unlock(tox); | 2158 | unlock(tox); |
@@ -2059,6 +2161,7 @@ size_t tox_conference_get_chatlist_size(const Tox *tox) | |||
2059 | 2161 | ||
2060 | void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist) | 2162 | void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist) |
2061 | { | 2163 | { |
2164 | assert(tox != nullptr); | ||
2062 | lock(tox); | 2165 | lock(tox); |
2063 | const size_t list_size = count_chatlist(tox->m->conferences_object); | 2166 | const size_t list_size = count_chatlist(tox->m->conferences_object); |
2064 | copy_chatlist(tox->m->conferences_object, chatlist, list_size); | 2167 | copy_chatlist(tox->m->conferences_object, chatlist, list_size); |
@@ -2068,6 +2171,7 @@ void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist) | |||
2068 | Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number, | 2171 | Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number, |
2069 | Tox_Err_Conference_Get_Type *error) | 2172 | Tox_Err_Conference_Get_Type *error) |
2070 | { | 2173 | { |
2174 | assert(tox != nullptr); | ||
2071 | lock(tox); | 2175 | lock(tox); |
2072 | const int ret = group_get_type(tox->m->conferences_object, conference_number); | 2176 | const int ret = group_get_type(tox->m->conferences_object, conference_number); |
2073 | unlock(tox); | 2177 | unlock(tox); |
@@ -2084,6 +2188,7 @@ Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_ | |||
2084 | /* id is TOX_CONFERENCE_ID_SIZE bytes */ | 2188 | /* id is TOX_CONFERENCE_ID_SIZE bytes */ |
2085 | bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id) | 2189 | bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id) |
2086 | { | 2190 | { |
2191 | assert(tox != nullptr); | ||
2087 | lock(tox); | 2192 | lock(tox); |
2088 | bool ret = conference_get_id(tox->m->conferences_object, conference_number, id); | 2193 | bool ret = conference_get_id(tox->m->conferences_object, conference_number, id); |
2089 | unlock(tox); | 2194 | unlock(tox); |
@@ -2094,11 +2199,14 @@ bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t * | |||
2094 | /* uid is TOX_CONFERENCE_ID_SIZE bytes */ | 2199 | /* uid is TOX_CONFERENCE_ID_SIZE bytes */ |
2095 | bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid) | 2200 | bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid) |
2096 | { | 2201 | { |
2202 | assert(tox != nullptr); | ||
2097 | return tox_conference_get_id(tox, conference_number, uid); | 2203 | return tox_conference_get_id(tox, conference_number, uid); |
2098 | } | 2204 | } |
2099 | 2205 | ||
2100 | uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Conference_By_Id *error) | 2206 | uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Conference_By_Id *error) |
2101 | { | 2207 | { |
2208 | assert(tox != nullptr); | ||
2209 | |||
2102 | if (!id) { | 2210 | if (!id) { |
2103 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_ID_NULL); | 2211 | SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_ID_NULL); |
2104 | return UINT32_MAX; | 2212 | return UINT32_MAX; |
@@ -2120,6 +2228,7 @@ uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Confere | |||
2120 | // TODO(iphydf): Delete in 0.3.0. | 2228 | // TODO(iphydf): Delete in 0.3.0. |
2121 | uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Conference_By_Uid *error) | 2229 | uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Conference_By_Uid *error) |
2122 | { | 2230 | { |
2231 | assert(tox != nullptr); | ||
2123 | Tox_Err_Conference_By_Id id_error; | 2232 | Tox_Err_Conference_By_Id id_error; |
2124 | const uint32_t res = tox_conference_by_id(tox, uid, &id_error); | 2233 | const uint32_t res = tox_conference_by_id(tox, uid, &id_error); |
2125 | 2234 | ||
@@ -2172,6 +2281,8 @@ static void set_custom_packet_error(int ret, Tox_Err_Friend_Custom_Packet *error | |||
2172 | bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, | 2281 | bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, |
2173 | Tox_Err_Friend_Custom_Packet *error) | 2282 | Tox_Err_Friend_Custom_Packet *error) |
2174 | { | 2283 | { |
2284 | assert(tox != nullptr); | ||
2285 | |||
2175 | if (!data) { | 2286 | if (!data) { |
2176 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); | 2287 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); |
2177 | return 0; | 2288 | return 0; |
@@ -2202,6 +2313,8 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_ | |||
2202 | 2313 | ||
2203 | void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback) | 2314 | void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback) |
2204 | { | 2315 | { |
2316 | assert(tox != nullptr); | ||
2317 | |||
2205 | /* start at PACKET_ID_RANGE_LOSSY_CUSTOM_START so ToxAV Packets are excluded */ | 2318 | /* start at PACKET_ID_RANGE_LOSSY_CUSTOM_START so ToxAV Packets are excluded */ |
2206 | for (uint8_t i = PACKET_ID_RANGE_LOSSY_CUSTOM_START; i <= PACKET_ID_RANGE_LOSSY_END; ++i) { | 2319 | for (uint8_t i = PACKET_ID_RANGE_LOSSY_CUSTOM_START; i <= PACKET_ID_RANGE_LOSSY_END; ++i) { |
2207 | tox->friend_lossy_packet_callback_per_pktid[i] = callback; | 2320 | tox->friend_lossy_packet_callback_per_pktid[i] = callback; |
@@ -2210,6 +2323,8 @@ void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *call | |||
2210 | 2323 | ||
2211 | void tox_callback_friend_lossy_packet_per_pktid(Tox *tox, tox_friend_lossy_packet_cb *callback, uint8_t pktid) | 2324 | void tox_callback_friend_lossy_packet_per_pktid(Tox *tox, tox_friend_lossy_packet_cb *callback, uint8_t pktid) |
2212 | { | 2325 | { |
2326 | assert(tox != nullptr); | ||
2327 | |||
2213 | if (pktid >= PACKET_ID_RANGE_LOSSY_START && pktid <= PACKET_ID_RANGE_LOSSY_END) { | 2328 | if (pktid >= PACKET_ID_RANGE_LOSSY_START && pktid <= PACKET_ID_RANGE_LOSSY_END) { |
2214 | tox->friend_lossy_packet_callback_per_pktid[pktid] = callback; | 2329 | tox->friend_lossy_packet_callback_per_pktid[pktid] = callback; |
2215 | } | 2330 | } |
@@ -2218,6 +2333,8 @@ void tox_callback_friend_lossy_packet_per_pktid(Tox *tox, tox_friend_lossy_packe | |||
2218 | bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, | 2333 | bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, |
2219 | Tox_Err_Friend_Custom_Packet *error) | 2334 | Tox_Err_Friend_Custom_Packet *error) |
2220 | { | 2335 | { |
2336 | assert(tox != nullptr); | ||
2337 | |||
2221 | if (!data) { | 2338 | if (!data) { |
2222 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); | 2339 | SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); |
2223 | return 0; | 2340 | return 0; |
@@ -2243,6 +2360,8 @@ bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uin | |||
2243 | 2360 | ||
2244 | void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback) | 2361 | void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback) |
2245 | { | 2362 | { |
2363 | assert(tox != nullptr); | ||
2364 | |||
2246 | for (uint8_t i = PACKET_ID_RANGE_LOSSLESS_CUSTOM_START; i <= PACKET_ID_RANGE_LOSSLESS_CUSTOM_END; ++i) { | 2365 | for (uint8_t i = PACKET_ID_RANGE_LOSSLESS_CUSTOM_START; i <= PACKET_ID_RANGE_LOSSLESS_CUSTOM_END; ++i) { |
2247 | tox->friend_lossless_packet_callback_per_pktid[i] = callback; | 2366 | tox->friend_lossless_packet_callback_per_pktid[i] = callback; |
2248 | } | 2367 | } |
@@ -2250,6 +2369,8 @@ void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb | |||
2250 | 2369 | ||
2251 | void tox_callback_friend_lossless_packet_per_pktid(Tox *tox, tox_friend_lossless_packet_cb *callback, uint8_t pktid) | 2370 | void tox_callback_friend_lossless_packet_per_pktid(Tox *tox, tox_friend_lossless_packet_cb *callback, uint8_t pktid) |
2252 | { | 2371 | { |
2372 | assert(tox != nullptr); | ||
2373 | |||
2253 | if ((pktid >= PACKET_ID_RANGE_LOSSLESS_CUSTOM_START && pktid <= PACKET_ID_RANGE_LOSSLESS_CUSTOM_END) | 2374 | if ((pktid >= PACKET_ID_RANGE_LOSSLESS_CUSTOM_START && pktid <= PACKET_ID_RANGE_LOSSLESS_CUSTOM_END) |
2254 | || pktid == PACKET_ID_MSI) { | 2375 | || pktid == PACKET_ID_MSI) { |
2255 | tox->friend_lossless_packet_callback_per_pktid[pktid] = callback; | 2376 | tox->friend_lossless_packet_callback_per_pktid[pktid] = callback; |
@@ -2258,6 +2379,8 @@ void tox_callback_friend_lossless_packet_per_pktid(Tox *tox, tox_friend_lossless | |||
2258 | 2379 | ||
2259 | void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id) | 2380 | void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id) |
2260 | { | 2381 | { |
2382 | assert(tox != nullptr); | ||
2383 | |||
2261 | if (dht_id) { | 2384 | if (dht_id) { |
2262 | lock(tox); | 2385 | lock(tox); |
2263 | memcpy(dht_id, dht_get_self_public_key(tox->m->dht), CRYPTO_PUBLIC_KEY_SIZE); | 2386 | memcpy(dht_id, dht_get_self_public_key(tox->m->dht), CRYPTO_PUBLIC_KEY_SIZE); |
@@ -2267,6 +2390,7 @@ void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id) | |||
2267 | 2390 | ||
2268 | void tox_set_av_object(Tox *tox, void *object) | 2391 | void tox_set_av_object(Tox *tox, void *object) |
2269 | { | 2392 | { |
2393 | assert(tox != nullptr); | ||
2270 | lock(tox); | 2394 | lock(tox); |
2271 | tox->toxav_object = object; | 2395 | tox->toxav_object = object; |
2272 | unlock(tox); | 2396 | unlock(tox); |
@@ -2274,6 +2398,7 @@ void tox_set_av_object(Tox *tox, void *object) | |||
2274 | 2398 | ||
2275 | void *tox_get_av_object(const Tox *tox) | 2399 | void *tox_get_av_object(const Tox *tox) |
2276 | { | 2400 | { |
2401 | assert(tox != nullptr); | ||
2277 | lock(tox); | 2402 | lock(tox); |
2278 | void *object = tox->toxav_object; | 2403 | void *object = tox->toxav_object; |
2279 | unlock(tox); | 2404 | unlock(tox); |
@@ -2282,6 +2407,7 @@ void *tox_get_av_object(const Tox *tox) | |||
2282 | 2407 | ||
2283 | uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error) | 2408 | uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error) |
2284 | { | 2409 | { |
2410 | assert(tox != nullptr); | ||
2285 | lock(tox); | 2411 | lock(tox); |
2286 | const uint16_t port = net_htons(net_port(tox->m->net)); | 2412 | const uint16_t port = net_htons(net_port(tox->m->net)); |
2287 | unlock(tox); | 2413 | unlock(tox); |
@@ -2297,6 +2423,7 @@ uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error) | |||
2297 | 2423 | ||
2298 | uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error) | 2424 | uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error) |
2299 | { | 2425 | { |
2426 | assert(tox != nullptr); | ||
2300 | lock(tox); | 2427 | lock(tox); |
2301 | 2428 | ||
2302 | if (tox->m->tcp_server) { | 2429 | if (tox->m->tcp_server) { |
diff --git a/toxcore/util_test.cc b/toxcore/util_test.cc index ff57f3fb..744c7745 100644 --- a/toxcore/util_test.cc +++ b/toxcore/util_test.cc | |||
@@ -1,9 +1,9 @@ | |||
1 | #include "util.h" | 1 | #include "util.h" |
2 | 2 | ||
3 | #include "crypto_core.h" | ||
4 | |||
5 | #include <gtest/gtest.h> | 3 | #include <gtest/gtest.h> |
6 | 4 | ||
5 | #include "crypto_core.h" | ||
6 | |||
7 | namespace { | 7 | namespace { |
8 | 8 | ||
9 | TEST(Util, TwoRandomIdsAreNotEqual) { | 9 | TEST(Util, TwoRandomIdsAreNotEqual) { |