diff options
author | George Hazan <ghazan@miranda.im> | 2020-05-03 12:35:27 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-05-03 12:35:27 +0300 |
commit | e85b4c67372900013faa7793db0f7e664d5bca2e (patch) | |
tree | a30aea519d9c2672ed4a50d32a6ad43acd285497 /protocols/Tox | |
parent | cb012794fa0ed74ed57607048dcafc6b06419ba7 (diff) |
fixes #2374 (Update libtox to 0.2.12)
Diffstat (limited to 'protocols/Tox')
31 files changed, 507 insertions, 298 deletions
diff --git a/protocols/Tox/libtox/docs/CHANGELOG.md b/protocols/Tox/libtox/docs/CHANGELOG.md index 91c807793c..8973c4ee69 100644 --- a/protocols/Tox/libtox/docs/CHANGELOG.md +++ b/protocols/Tox/libtox/docs/CHANGELOG.md @@ -1,8 +1,55 @@ +## v0.2.12 + +### Merged PRs: + +- [#1457](https://github.com/TokTok/c-toxcore/pull/1457) Disable non-hermetic tests by default. +- [#1456](https://github.com/TokTok/c-toxcore/pull/1456) Limit the number of friends you can have to ~4 billion. +- [#1452](https://github.com/TokTok/c-toxcore/pull/1452) Add execution trace option for debugging. +- [#1447](https://github.com/TokTok/c-toxcore/pull/1447) Udp dht group chats +- [#1444](https://github.com/TokTok/c-toxcore/pull/1444) Set up release-drafter to automatically draft the next release. +- [#1443](https://github.com/TokTok/c-toxcore/pull/1443) Allow test coverage to fluctuate 2% up and down, but not below 80%. +- [#1442](https://github.com/TokTok/c-toxcore/pull/1442) Add CODEOWNERS and settings.yml files. +- [#1441](https://github.com/TokTok/c-toxcore/pull/1441) [ImgBot] Optimize images +- [#1439](https://github.com/TokTok/c-toxcore/pull/1439) Fix continuous integration builds. +- [#1437](https://github.com/TokTok/c-toxcore/pull/1437) Rework the toxchat/bootstrap-node Docker image. +- [#1435](https://github.com/TokTok/c-toxcore/pull/1435) Enable TCP relay test in Bazel and autotools build. +- [#1434](https://github.com/TokTok/c-toxcore/pull/1434) Skip invalid TCP relays and DHT nodes when loading save data. +- [#1433](https://github.com/TokTok/c-toxcore/pull/1433) Fix saving of combination of loaded and connected TCP relays +- [#1430](https://github.com/TokTok/c-toxcore/pull/1430) Invert `not_valid` functions and name them `is_valid`. +- [#1429](https://github.com/TokTok/c-toxcore/pull/1429) Fix things not being initialized if creating a TCP-only network +- [#1426](https://github.com/TokTok/c-toxcore/pull/1426) Remove tokstyle exemptions from build files. +- [#1425](https://github.com/TokTok/c-toxcore/pull/1425) Stop using the "inline namespace" feature of apidsl. +- [#1424](https://github.com/TokTok/c-toxcore/pull/1424) Add new semi-private API functions to set per-packet-id custom handlers. +- [#1423](https://github.com/TokTok/c-toxcore/pull/1423) Give CI workflow a better name: clang-sanitizers +- [#1422](https://github.com/TokTok/c-toxcore/pull/1422) Use public API for sending in RTP +- [#1421](https://github.com/TokTok/c-toxcore/pull/1421) Install ci-tools and get tokstyle via the script it provides. +- [#1420](https://github.com/TokTok/c-toxcore/pull/1420) Use tox public API for sending packets in toxav BWController +- [#1419](https://github.com/TokTok/c-toxcore/pull/1419) Remove newlines from the end of LOGGER format strings. +- [#1418](https://github.com/TokTok/c-toxcore/pull/1418) Change ToxAVCall struct mutex to a more distinct name +- [#1417](https://github.com/TokTok/c-toxcore/pull/1417) Create own instance of Mono_Time for ToxAV +- [#1416](https://github.com/TokTok/c-toxcore/pull/1416) Stop using Messenger's mono_time in bandwidth controller. +- [#1415](https://github.com/TokTok/c-toxcore/pull/1415) Fix 2 memory leaks in ToxAV. +- [#1414](https://github.com/TokTok/c-toxcore/pull/1414) Show function names in asan/tsan stack traces on CircleCI. +- [#1413](https://github.com/TokTok/c-toxcore/pull/1413) Make afl_toxsave.c a bit more portable; fix memory leak. +- [#1411](https://github.com/TokTok/c-toxcore/pull/1411) Fixes towards building on MSVC. +- [#1409](https://github.com/TokTok/c-toxcore/pull/1409) Mark conference test as small. +- [#1407](https://github.com/TokTok/c-toxcore/pull/1407) Add minimal save generator +- [#1406](https://github.com/TokTok/c-toxcore/pull/1406) Migrate format-source script to new apidsl web app. +- [#1404](https://github.com/TokTok/c-toxcore/pull/1404) Smarter setup of bazel remote cache on Cirrus CI. +- [#1331](https://github.com/TokTok/c-toxcore/pull/1331) Add basic test adapter for AFL + +### Closed issues: + +- [#1365](https://github.com/TokTok/c-toxcore/issues/1365) Add the option to use LAN discovery even when using a proxy for remote connections +- [#1353](https://github.com/TokTok/c-toxcore/issues/1353) libtoxdns.a and libtoxav.a +- [#86](https://github.com/TokTok/c-toxcore/issues/86) Freenet as Offline Messaging Backend + ## v0.2.11 ### Merged PRs: +- [#1405](https://github.com/TokTok/c-toxcore/pull/1405) Release 0.2.11 - [#1403](https://github.com/TokTok/c-toxcore/pull/1403) Install libsodium from apt instead of from source. - [#1402](https://github.com/TokTok/c-toxcore/pull/1402) Remove bazel build from Travis. - [#1400](https://github.com/TokTok/c-toxcore/pull/1400) Disable bazel remote cache on CI. @@ -109,7 +156,7 @@ - [#1242](https://github.com/TokTok/c-toxcore/pull/1242) Fix critical stack overflow arising from VLA usage - [#1239](https://github.com/TokTok/c-toxcore/pull/1239) Add some hopefully helpful documentation to the functions in mono_time.h - [#1235](https://github.com/TokTok/c-toxcore/pull/1235) Change method of PK production for FAKE friend in DHT -- [#1234](https://github.com/TokTok/c-toxcore/pull/1234) Increase NOFILE limit for tox-bootstrapd +- [#1234](https://github.com/TokTok/c-toxcore/pull/1234) Increase NOFILE limit for tox-bootstrapd - [#1231](https://github.com/TokTok/c-toxcore/pull/1231) Use `bool` for IPv6 flag in test programs and `DHT_bootstrap`. - [#1230](https://github.com/TokTok/c-toxcore/pull/1230) Add `LOGGER_ASSERT` for checking fatal error conditions. - [#1229](https://github.com/TokTok/c-toxcore/pull/1229) Include `CTest` in CMakeLists.txt to get valgrind support. @@ -357,7 +404,7 @@ - [#975](https://github.com/TokTok/c-toxcore/pull/975) Factor out the actual test code from conference_test. - [#972](https://github.com/TokTok/c-toxcore/pull/972) Add a test that reproduces the NULL peer nick bug. - [#968](https://github.com/TokTok/c-toxcore/pull/968) Make tox.c unambiguously parseable. -- [#967](https://github.com/TokTok/c-toxcore/pull/967) lan_discovery_test and version_test cleanup +- [#967](https://github.com/TokTok/c-toxcore/pull/967) lan_discovery_test and version_test cleanup - [#966](https://github.com/TokTok/c-toxcore/pull/966) Use run_auto_test.h test fixture for some auto-tests. - [#965](https://github.com/TokTok/c-toxcore/pull/965) Add `#include <cstdio>` for `std::printf`. - [#964](https://github.com/TokTok/c-toxcore/pull/964) Add some tests for our ring_buffer implementation. diff --git a/protocols/Tox/libtox/src/toxcore/DHT.c b/protocols/Tox/libtox/src/toxcore/DHT.c index 191ebc0ed5..b3017259b2 100644 --- a/protocols/Tox/libtox/src/toxcore/DHT.c +++ b/protocols/Tox/libtox/src/toxcore/DHT.c @@ -2721,6 +2721,11 @@ DHT *new_dht(const Logger *log, Mono_Time *mono_time, Networking_Core *net, bool dht->dht_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT); dht->dht_harden_ping_array = ping_array_new(DHT_PING_ARRAY_SIZE, PING_TIMEOUT); + if (dht->dht_ping_array == nullptr || dht->dht_harden_ping_array == nullptr) { + kill_dht(dht); + return nullptr; + } + for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) { uint8_t random_public_key_bytes[CRYPTO_PUBLIC_KEY_SIZE]; uint8_t random_secret_key_bytes[CRYPTO_SECRET_KEY_SIZE]; @@ -2924,7 +2929,7 @@ static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *dat } default: - LOGGER_ERROR(dht->log, "Load state (DHT): contains unrecognized part (len %u, type %u)\n", + LOGGER_ERROR(dht->log, "Load state (DHT): contains unrecognized part (len %u, type %u)", length, type); break; } diff --git a/protocols/Tox/libtox/src/toxcore/LAN_discovery.api.h b/protocols/Tox/libtox/src/toxcore/LAN_discovery.api.h index 5c25b67b98..ad3d60ed7a 100644 --- a/protocols/Tox/libtox/src/toxcore/LAN_discovery.api.h +++ b/protocols/Tox/libtox/src/toxcore/LAN_discovery.api.h @@ -21,7 +21,7 @@ namespace lan_discovery { /** * Interval in seconds between LAN discovery packet sending. */ -const INTERVAL = 10; +#define LAN_DISCOVERY_INTERVAL 10 /** * Send a LAN discovery pcaket to the broadcast address with port port. diff --git a/protocols/Tox/libtox/src/toxcore/LAN_discovery.h b/protocols/Tox/libtox/src/toxcore/LAN_discovery.h index 7e049b9961..6b55e3193b 100644 --- a/protocols/Tox/libtox/src/toxcore/LAN_discovery.h +++ b/protocols/Tox/libtox/src/toxcore/LAN_discovery.h @@ -26,8 +26,6 @@ typedef struct IP IP; */ #define LAN_DISCOVERY_INTERVAL 10 -uint32_t lan_discovery_interval(void); - /** * Send a LAN discovery pcaket to the broadcast address with port port. */ diff --git a/protocols/Tox/libtox/src/toxcore/Messenger.c b/protocols/Tox/libtox/src/toxcore/Messenger.c index ddd04518a5..556acc272f 100644 --- a/protocols/Tox/libtox/src/toxcore/Messenger.c +++ b/protocols/Tox/libtox/src/toxcore/Messenger.c @@ -28,16 +28,14 @@ static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_ uint32_t length, uint8_t congestion_control); static void m_register_default_plugins(Messenger *m); -// friend_not_valid determines if the friendnumber passed is valid in the Messenger object -static uint8_t friend_not_valid(const Messenger *m, int32_t friendnumber) +/** + * Determines if the friendnumber passed is valid in the Messenger object. + * + * @param friendnumber The index in the friend list. + */ +static bool friend_is_valid(const Messenger *m, int32_t friendnumber) { - if ((unsigned int)friendnumber < m->numfriends) { - if (m->friendlist[friendnumber].status != 0) { - return 0; - } - } - - return 1; + return (unsigned int)friendnumber < m->numfriends && m->friendlist[friendnumber].status != 0; } /* Set the size of the friend list to numfriends. @@ -88,7 +86,7 @@ int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk) */ int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -101,7 +99,7 @@ int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk) */ int getfriendcon_id(const Messenger *m, int32_t friendnumber) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -140,7 +138,7 @@ void getaddress(const Messenger *m, uint8_t *address) static int send_online_packet(Messenger *m, int32_t friendnumber) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return 0; } @@ -163,6 +161,12 @@ static int m_handle_lossy_packet(void *object, int friend_num, const uint8_t *pa static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status) { + if (m->numfriends == UINT32_MAX) { + LOGGER_ERROR(m->log, "Friend list full: we have more than 4 billion friends"); + /* This is technically incorrect, but close enough. */ + return FAERR_NOMEM; + } + /* Resize the friend list if necessary. */ if (realloc_friendlist(m, m->numfriends + 1) != 0) { return FAERR_NOMEM; @@ -301,7 +305,7 @@ int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk) static int clear_receipts(Messenger *m, int32_t friendnumber) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -320,7 +324,7 @@ static int clear_receipts(Messenger *m, int32_t friendnumber) static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num, uint32_t msg_id) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -349,7 +353,7 @@ static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num, */ static int friend_received_packet(const Messenger *m, int32_t friendnumber, uint32_t number) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -359,7 +363,7 @@ static int friend_received_packet(const Messenger *m, int32_t friendnumber, uint static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -397,7 +401,7 @@ static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata) */ int m_delfriend(Messenger *m, int32_t friendnumber) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -435,7 +439,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber) int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -463,7 +467,7 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber) int m_friend_exists(const Messenger *m, int32_t friendnumber) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return 0; } @@ -487,7 +491,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con return -5; } - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { LOGGER_ERROR(m->log, "Friend number %d is invalid", friendnumber); return -1; } @@ -548,7 +552,7 @@ static int m_sendname(const Messenger *m, int32_t friendnumber, const uint8_t *n */ int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -617,7 +621,7 @@ uint16_t getself_name(const Messenger *m, uint8_t *name) */ int getname(const Messenger *m, int32_t friendnumber, uint8_t *name) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -627,7 +631,7 @@ int getname(const Messenger *m, int32_t friendnumber, uint8_t *name) int m_get_name_size(const Messenger *m, int32_t friendnumber) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -689,7 +693,7 @@ int m_set_userstatus(Messenger *m, uint8_t status) */ int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -701,7 +705,7 @@ int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber) */ int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -730,7 +734,7 @@ int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf) uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return USERSTATUS_INVALID; } @@ -750,7 +754,7 @@ uint8_t m_get_self_userstatus(const Messenger *m) uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return UINT64_MAX; } @@ -763,7 +767,7 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing) return -1; } - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -779,7 +783,7 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing) int m_get_istyping(const Messenger *m, int32_t friendnumber) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -804,7 +808,7 @@ static int send_user_istyping(const Messenger *m, int32_t friendnumber, uint8_t static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -952,7 +956,7 @@ static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data, uint32_t length, uint8_t congestion_control) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return 0; } @@ -1033,7 +1037,7 @@ void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *function) */ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint8_t *file_id) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -1082,7 +1086,7 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint32_t file_type, uint64_t filesize, const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return 0; } @@ -1116,7 +1120,7 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize, const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -1195,7 +1199,7 @@ static int send_file_control_packet(const Messenger *m, int32_t friendnumber, ui */ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, unsigned int control) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -1296,7 +1300,7 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, */ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -1352,7 +1356,7 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -1384,7 +1388,7 @@ static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, u int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, uint16_t length) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -1446,38 +1450,6 @@ int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin return -6; } -/* Give the number of bytes left to be sent/received. - * - * send_receive is 0 if we want the sending files, 1 if we want the receiving. - * - * return number of bytes remaining to be sent/received on success - * return 0 on failure - */ -uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive) -{ - if (friend_not_valid(m, friendnumber)) { - return 0; - } - - const struct File_Transfers *const sending = &m->friendlist[friendnumber].file_sending[filenumber]; - - if (send_receive == 0) { - if (sending->status == FILESTATUS_NONE) { - return 0; - } - - return sending->size - sending->transferred; - } - - const struct File_Transfers *const receiving = &m->friendlist[friendnumber].file_receiving[filenumber]; - - if (receiving->status == FILESTATUS_NONE) { - return 0; - } - - return receiving->size - receiving->transferred; -} - /** * Iterate over all file transfers and request chunks (from the client) for each * of them. @@ -1776,7 +1748,7 @@ static int m_handle_lossy_packet(void *object, int friend_num, const uint8_t *pa { Messenger *m = (Messenger *)object; - if (friend_not_valid(m, friend_num)) { + if (!friend_is_valid(m, friend_num)) { return 1; } @@ -1806,7 +1778,7 @@ void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lossy_rtp_packet_cb *function, void *object) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -1829,7 +1801,7 @@ int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lo */ int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -1859,7 +1831,7 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin { Messenger *m = (Messenger *)object; - if (friend_not_valid(m, friend_num)) { + if (!friend_is_valid(m, friend_num)) { return -1; } @@ -1881,7 +1853,7 @@ void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_pack int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) { - if (friend_not_valid(m, friendnumber)) { + if (!friend_is_valid(m, friendnumber)) { return -1; } @@ -1889,7 +1861,8 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const return -2; } - if (data[0] < PACKET_ID_RANGE_LOSSLESS_CUSTOM_START || data[0] > PACKET_ID_RANGE_LOSSLESS_CUSTOM_END) { + if ((data[0] < PACKET_ID_RANGE_LOSSLESS_CUSTOM_START || data[0] > PACKET_ID_RANGE_LOSSLESS_CUSTOM_END) + && data[0] != PACKET_ID_MSI) { return -3; } @@ -1994,8 +1967,8 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig m->net_crypto = new_net_crypto(m->log, m->mono_time, m->dht, &options->proxy_info); if (m->net_crypto == nullptr) { - kill_networking(m->net); kill_dht(m->dht); + kill_networking(m->net); friendreq_kill(m->fr); logger_kill(m->log); free(m); @@ -2007,7 +1980,7 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig m->onion_c = new_onion_client(m->mono_time, m->net_crypto); m->fr_c = new_friend_connections(m->mono_time, m->onion_c, options->local_discovery_enabled); - if (!(m->onion && m->onion_a && m->onion_c)) { + if (!(m->onion && m->onion_a && m->onion_c && m->fr_c)) { kill_friend_connections(m->fr_c); kill_onion(m->onion); kill_onion_announce(m->onion_a); @@ -2651,7 +2624,7 @@ void do_messenger(Messenger *m, void *userdata) } if (m->numfriends != dht_get_num_friends(m->dht)) { - LOGGER_TRACE(m->log, "Friend num in DHT %u != friend num in msger %u\n", dht_get_num_friends(m->dht), m->numfriends); + LOGGER_TRACE(m->log, "Friend num in DHT %u != friend num in msger %u", dht_get_num_friends(m->dht), m->numfriends); } Friend *msgfptr; @@ -3139,13 +3112,14 @@ static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data) Node_format relays[NUM_SAVED_TCP_RELAYS]; uint8_t *temp_data = data; data = state_write_section_header(temp_data, STATE_COOKIE_TYPE, 0, STATE_TYPE_TCP_RELAY); - uint32_t num = copy_connected_tcp_relays(m->net_crypto, relays, NUM_SAVED_TCP_RELAYS); if (m->num_loaded_relays > 0) { memcpy(relays, m->loaded_relays, sizeof(Node_format) * m->num_loaded_relays); - num = min_u32(num + m->num_loaded_relays, NUM_SAVED_TCP_RELAYS); } + uint32_t num = m->num_loaded_relays; + num += copy_connected_tcp_relays(m->net_crypto, relays + num, NUM_SAVED_TCP_RELAYS - num); + int l = pack_nodes(data, NUM_SAVED_TCP_RELAYS * packed_node_size(net_family_tcp_ipv6), relays, num); if (l > 0) { @@ -3160,7 +3134,14 @@ static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data) static State_Load_Status load_tcp_relays(Messenger *m, const uint8_t *data, uint32_t length) { if (length != 0) { - m->num_loaded_relays = unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, nullptr, data, length, 1); + const int num = unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, nullptr, data, length, 1); + + if (num == -1) { + m->num_loaded_relays = 0; + return STATE_LOAD_STATUS_CONTINUE; + } + + m->num_loaded_relays = num; m->has_added_relays = false; } @@ -3198,6 +3179,10 @@ static State_Load_Status load_path_nodes(Messenger *m, const uint8_t *data, uint if (length != 0) { const int num = unpack_nodes(nodes, NUM_SAVED_PATH_NODES, nullptr, data, length, 0); + if (num == -1) { + return STATE_LOAD_STATUS_CONTINUE; + } + for (int i = 0; i < num; ++i) { onion_add_bs_path_node(m->onion_c, nodes[i].ip_port, nodes[i].public_key); } diff --git a/protocols/Tox/libtox/src/toxcore/Messenger.h b/protocols/Tox/libtox/src/toxcore/Messenger.h index 74c19e09c8..31526b631d 100644 --- a/protocols/Tox/libtox/src/toxcore/Messenger.h +++ b/protocols/Tox/libtox/src/toxcore/Messenger.h @@ -651,15 +651,6 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, uint16_t length); -/* Give the number of bytes left to be sent/received. - * - * send_receive is 0 if we want the sending files, 1 if we want the receiving. - * - * return number of bytes remaining to be sent/received on success - * return 0 on failure - */ -uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive); - /** A/V related */ /* Set the callback for msi packets. diff --git a/protocols/Tox/libtox/src/toxcore/TCP_connection.c b/protocols/Tox/libtox/src/toxcore/TCP_connection.c index 3dd8652ead..adef31751f 100644 --- a/protocols/Tox/libtox/src/toxcore/TCP_connection.c +++ b/protocols/Tox/libtox/src/toxcore/TCP_connection.c @@ -100,44 +100,44 @@ static int realloc_TCP_con(TCP_con **array, size_t num) } -/* return 1 if the connections_number is not valid. - * return 0 if the connections_number is valid. +/** + * Return true if the connections_number is valid. */ -static bool connections_number_not_valid(const TCP_Connections *tcp_c, int connections_number) +static bool connections_number_is_valid(const TCP_Connections *tcp_c, int connections_number) { if ((unsigned int)connections_number >= tcp_c->connections_length) { - return 1; + return false; } if (tcp_c->connections == nullptr) { - return 1; + return false; } if (tcp_c->connections[connections_number].status == TCP_CONN_NONE) { - return 1; + return false; } - return 0; + return true; } -/* return 1 if the tcp_connections_number is not valid. - * return 0 if the tcp_connections_number is valid. +/** + * Return true if the tcp_connections_number is valid. */ -static bool tcp_connections_number_not_valid(const TCP_Connections *tcp_c, int tcp_connections_number) +static bool tcp_connections_number_is_valid(const TCP_Connections *tcp_c, int tcp_connections_number) { if ((unsigned int)tcp_connections_number >= tcp_c->tcp_connections_length) { - return 1; + return false; } if (tcp_c->tcp_connections == nullptr) { - return 1; + return false; } if (tcp_c->tcp_connections[tcp_connections_number].status == TCP_CONN_NONE) { - return 1; + return false; } - return 0; + return true; } /* Create a new empty connection. @@ -199,7 +199,7 @@ static int create_tcp_connection(TCP_Connections *tcp_c) */ static int wipe_connection(TCP_Connections *tcp_c, int connections_number) { - if (connections_number_not_valid(tcp_c, connections_number)) { + if (!connections_number_is_valid(tcp_c, connections_number)) { return -1; } @@ -227,7 +227,7 @@ static int wipe_connection(TCP_Connections *tcp_c, int connections_number) */ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_number) { - if (tcp_connections_number_not_valid(tcp_c, tcp_connections_number)) { + if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) { return -1; } @@ -250,7 +250,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int connections_number) { - if (connections_number_not_valid(tcp_c, connections_number)) { + if (!connections_number_is_valid(tcp_c, connections_number)) { return nullptr; } @@ -259,7 +259,7 @@ static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int conne static TCP_con *get_tcp_connection(const TCP_Connections *tcp_c, int tcp_connections_number) { - if (tcp_connections_number_not_valid(tcp_c, tcp_connections_number)) { + if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) { return nullptr; } diff --git a/protocols/Tox/libtox/src/toxcore/ccompat.h b/protocols/Tox/libtox/src/toxcore/ccompat.h index ba8c7fe8da..8ff6563d9e 100644 --- a/protocols/Tox/libtox/src/toxcore/ccompat.h +++ b/protocols/Tox/libtox/src/toxcore/ccompat.h @@ -4,6 +4,8 @@ #ifndef C_TOXCORE_TOXCORE_CCOMPAT_H #define C_TOXCORE_TOXCORE_CCOMPAT_H +//!TOKSTYLE- + // Variable length arrays. // VLA(type, name, size) allocates a variable length array with automatic // storage duration. VLA_SIZE(name) evaluates to the runtime size of that array @@ -48,4 +50,6 @@ #define GNU_PRINTF(f, a) #endif +//!TOKSTYLE+ + #endif // C_TOXCORE_TOXCORE_CCOMPAT_H diff --git a/protocols/Tox/libtox/src/toxcore/crypto_core.api.h b/protocols/Tox/libtox/src/toxcore/crypto_core.api.h index 44f541fc18..0db3a42001 100644 --- a/protocols/Tox/libtox/src/toxcore/crypto_core.api.h +++ b/protocols/Tox/libtox/src/toxcore/crypto_core.api.h @@ -69,7 +69,7 @@ const CRYPTO_SHA512_SIZE = 64; * "aaaa" and "baaa" also takes 4 time. With a regular `memcmp`, the latter may * take 1 time, because it immediately knows that the two strings are not equal. */ -static int32_t crypto_memcmp(const void *p1, const void *p2, size_t length); +static int32_t crypto_memcmp(const uint8_t *p1, const uint8_t *p2, size_t length); /** * A `bzero`-like function which won't be optimised away by the compiler. Some diff --git a/protocols/Tox/libtox/src/toxcore/crypto_core.c b/protocols/Tox/libtox/src/toxcore/crypto_core.c index 5538b1b8ee..2fa4750ff4 100644 --- a/protocols/Tox/libtox/src/toxcore/crypto_core.c +++ b/protocols/Tox/libtox/src/toxcore/crypto_core.c @@ -12,12 +12,13 @@ #include "config.h" #endif -#include "ccompat.h" #include "crypto_core.h" #include <stdlib.h> #include <string.h> +#include "ccompat.h" + #ifndef VANILLA_NACL /* We use libsodium by default. */ #include <sodium.h> diff --git a/protocols/Tox/libtox/src/toxcore/crypto_core.h b/protocols/Tox/libtox/src/toxcore/crypto_core.h index 07412e7e8c..425c3244f0 100644 --- a/protocols/Tox/libtox/src/toxcore/crypto_core.h +++ b/protocols/Tox/libtox/src/toxcore/crypto_core.h @@ -83,7 +83,7 @@ uint32_t crypto_sha512_size(void); * "aaaa" and "baaa" also takes 4 time. With a regular `memcmp`, the latter may * take 1 time, because it immediately knows that the two strings are not equal. */ -int32_t crypto_memcmp(const void *p1, const void *p2, size_t length); +int32_t crypto_memcmp(const uint8_t *p1, const uint8_t *p2, size_t length); /** * A `bzero`-like function which won't be optimised away by the compiler. Some diff --git a/protocols/Tox/libtox/src/toxcore/crypto_core_mem.c b/protocols/Tox/libtox/src/toxcore/crypto_core_mem.c index b8f4223e65..b8c0bd9b98 100644 --- a/protocols/Tox/libtox/src/toxcore/crypto_core_mem.c +++ b/protocols/Tox/libtox/src/toxcore/crypto_core_mem.c @@ -37,8 +37,7 @@ void crypto_memzero(void *data, size_t length) { #ifndef VANILLA_NACL sodium_memzero(data, length); -#else -#ifdef _WIN32 +#elif defined(_WIN32) SecureZeroMemory(data, length); #elif defined(HAVE_MEMSET_S) @@ -53,32 +52,33 @@ void crypto_memzero(void *data, size_t length) #elif defined(HAVE_EXPLICIT_BZERO) explicit_bzero(data, length); #else - volatile unsigned char *volatile pnt = - (volatile unsigned char *volatile) data; + //!TOKSTYLE- + volatile uint8_t *volatile pnt = data; + //!TOKSTYLE+ size_t i = (size_t) 0U; while (i < length) { - pnt[i++] = 0U; + pnt[i] = 0U; + ++i; } #endif -#endif } -int32_t crypto_memcmp(const void *p1, const void *p2, size_t length) +int32_t crypto_memcmp(const uint8_t *p1, const uint8_t *p2, size_t length) { #ifndef VANILLA_NACL return sodium_memcmp(p1, p2, length); #else - const volatile unsigned char *volatile b1 = - (const volatile unsigned char *volatile) p1; - const volatile unsigned char *volatile b2 = - (const volatile unsigned char *volatile) p2; + //!TOKSTYLE- + const volatile uint8_t *volatile b1 = p1; + const volatile uint8_t *volatile b2 = p2; + //!TOKSTYLE+ size_t i; - unsigned char d = (unsigned char) 0U; + uint8_t d = (uint8_t) 0U; - for (i = 0U; i < length; i++) { + for (i = 0U; i < length; ++i) { d |= b1[i] ^ b2[i]; } diff --git a/protocols/Tox/libtox/src/toxcore/group.c b/protocols/Tox/libtox/src/toxcore/group.c index 3e04f181c8..a946e7b8e7 100644 --- a/protocols/Tox/libtox/src/toxcore/group.c +++ b/protocols/Tox/libtox/src/toxcore/group.c @@ -1301,36 +1301,6 @@ int group_set_max_frozen(const Group_Chats *g_c, uint32_t groupnumber, uint32_t return 0; } -/* List all the (frozen, if frozen is true) peers in the group chat. - * - * Copies the names of the peers to the `name[length][MAX_NAME_LENGTH]` array. - * - * Copies the lengths of the names to `lengths[length]` - * - * returns the number of peers on success. - * - * return -1 on failure. - */ -int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], - uint16_t length, bool frozen) -{ - const Group_c *g = get_group_c(g_c, groupnumber); - - if (!g) { - return -1; - } - - const uint32_t num = frozen ? g->numfrozen : g->numpeers; - - unsigned int i; - - for (i = 0; i < num && i < length; ++i) { - lengths[i] = group_peername(g_c, groupnumber, i, names[i], frozen); - } - - return i; -} - /* Return the number of (frozen, if frozen is true) peers in the group chat on * success. * return -1 if groupnumber is invalid. diff --git a/protocols/Tox/libtox/src/toxcore/group.h b/protocols/Tox/libtox/src/toxcore/group.h index 1e054de3c6..eb8db55f10 100644 --- a/protocols/Tox/libtox/src/toxcore/group.h +++ b/protocols/Tox/libtox/src/toxcore/group.h @@ -355,19 +355,6 @@ int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber, bool frozen */ int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber); -/* List all the (frozen, if frozen is true) peers in the group chat. - * - * Copies the names of the peers to the `name[length][MAX_NAME_LENGTH]` array. - * - * Copies the lengths of the names to `lengths[length]` - * - * returns the number of peers on success. - * - * return -1 on failure. - */ -int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], - uint16_t length, bool frozen); - /* Set handlers for custom lossy packets. */ void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function); diff --git a/protocols/Tox/libtox/src/toxcore/list.c b/protocols/Tox/libtox/src/toxcore/list.c index cb3c71cc2a..fca8cea898 100644 --- a/protocols/Tox/libtox/src/toxcore/list.c +++ b/protocols/Tox/libtox/src/toxcore/list.c @@ -248,13 +248,3 @@ int bs_list_remove(BS_List *list, const uint8_t *data, int id) return 1; } - -int bs_list_trim(BS_List *list) -{ - if (!resize(list, list->n)) { - return 0; - } - - list->capacity = list->n; - return 1; -} diff --git a/protocols/Tox/libtox/src/toxcore/list.h b/protocols/Tox/libtox/src/toxcore/list.h index 9d65b53fc6..afe4240b76 100644 --- a/protocols/Tox/libtox/src/toxcore/list.h +++ b/protocols/Tox/libtox/src/toxcore/list.h @@ -57,12 +57,4 @@ int bs_list_add(BS_List *list, const uint8_t *data, int id); */ int bs_list_remove(BS_List *list, const uint8_t *data, int id); -/* Removes the memory overhead - * - * return value: - * 1 : success - * 0 : failure - */ -int bs_list_trim(BS_List *list); - #endif diff --git a/protocols/Tox/libtox/src/toxcore/net_crypto.c b/protocols/Tox/libtox/src/toxcore/net_crypto.c index fb69b7685f..2851053bbf 100644 --- a/protocols/Tox/libtox/src/toxcore/net_crypto.c +++ b/protocols/Tox/libtox/src/toxcore/net_crypto.c @@ -174,23 +174,23 @@ DHT *nc_get_dht(const Net_Crypto *c) return c->dht; } -static uint8_t crypt_connection_id_not_valid(const Net_Crypto *c, int crypt_connection_id) +static bool crypt_connection_id_is_valid(const Net_Crypto *c, int crypt_connection_id) { if ((uint32_t)crypt_connection_id >= c->crypto_connections_length) { - return 1; + return false; } if (c->crypto_connections == nullptr) { - return 1; + return false; } const Crypto_Conn_State status = c->crypto_connections[crypt_connection_id].status; if (status == CRYPTO_CONN_NO_CONNECTION || status == CRYPTO_CONN_FREE) { - return 1; + return false; } - return 0; + return true; } /* cookie timeout in seconds */ @@ -555,7 +555,7 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id) { - if (crypt_connection_id_not_valid(c, crypt_connection_id)) { + if (!crypt_connection_id_is_valid(c, crypt_connection_id)) { return nullptr; } @@ -1858,7 +1858,7 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id) static int getcryptconnection_id(const Net_Crypto *c, const uint8_t *public_key) { for (uint32_t i = 0; i < c->crypto_connections_length; ++i) { - if (crypt_connection_id_not_valid(c, i)) { + if (!crypt_connection_id_is_valid(c, i)) { continue; } diff --git a/protocols/Tox/libtox/src/toxcore/network.c b/protocols/Tox/libtox/src/toxcore/network.c index d3284c4d26..e5a5833109 100644 --- a/protocols/Tox/libtox/src/toxcore/network.c +++ b/protocols/Tox/libtox/src/toxcore/network.c @@ -759,7 +759,7 @@ Networking_Core *new_networking_ex(const Logger *log, IP ip, uint16_t port_from, /* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */ if (!net_family_is_ipv4(ip.family) && !net_family_is_ipv6(ip.family)) { - LOGGER_ERROR(log, "invalid address family: %u\n", ip.family.value); + LOGGER_ERROR(log, "invalid address family: %u", ip.family.value); return nullptr; } @@ -956,6 +956,10 @@ Networking_Core *new_networking_ex(const Logger *log, IP ip, uint16_t port_from, Networking_Core *new_networking_no_udp(const Logger *log) { + if (networking_at_startup() != 0) { + return nullptr; + } + /* this is the easiest way to completely disable UDP without changing too much code. */ Networking_Core *net = (Networking_Core *)calloc(1, sizeof(Networking_Core)); diff --git a/protocols/Tox/libtox/src/toxcore/ping.c b/protocols/Tox/libtox/src/toxcore/ping.c index d2677ee786..305cce47c4 100644 --- a/protocols/Tox/libtox/src/toxcore/ping.c +++ b/protocols/Tox/libtox/src/toxcore/ping.c @@ -364,6 +364,10 @@ Ping *ping_new(const Mono_Time *mono_time, DHT *dht) void ping_kill(Ping *ping) { + if (ping == nullptr) { + return; + } + networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, nullptr, nullptr); networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, nullptr, nullptr); ping_array_kill(ping->ping_array); diff --git a/protocols/Tox/libtox/src/toxcore/ping_array.api.h b/protocols/Tox/libtox/src/toxcore/ping_array.api.h index 81ede8fa8f..d36e56dcf6 100644 --- a/protocols/Tox/libtox/src/toxcore/ping_array.api.h +++ b/protocols/Tox/libtox/src/toxcore/ping_array.api.h @@ -20,7 +20,7 @@ extern "C" { class mono_Time { struct this; } -class ping_Array { +class ping { class array { struct this; @@ -55,7 +55,7 @@ uint64_t add(const mono_Time::this *mono_time, const uint8_t *data, uint32_t len */ int32_t check(const mono_Time::this *mono_time, uint8_t[length] data, uint64_t ping_id); -} +} } %{ #ifdef __cplusplus diff --git a/protocols/Tox/libtox/src/toxcore/ping_array.c b/protocols/Tox/libtox/src/toxcore/ping_array.c index a93d48dd5c..201b507d4c 100644 --- a/protocols/Tox/libtox/src/toxcore/ping_array.c +++ b/protocols/Tox/libtox/src/toxcore/ping_array.c @@ -75,6 +75,10 @@ static void clear_entry(Ping_Array *array, uint32_t index) void ping_array_kill(Ping_Array *array) { + if (array == nullptr) { + return; + } + while (array->last_deleted != array->last_added) { const uint32_t index = array->last_deleted % array->total_size; clear_entry(array, index); diff --git a/protocols/Tox/libtox/src/toxcore/ping_array.h b/protocols/Tox/libtox/src/toxcore/ping_array.h index 589573c80f..70c517de9e 100644 --- a/protocols/Tox/libtox/src/toxcore/ping_array.h +++ b/protocols/Tox/libtox/src/toxcore/ping_array.h @@ -39,14 +39,14 @@ struct Ping_Array *ping_array_new(uint32_t size, uint32_t timeout); /** * Free all the allocated memory in a Ping_Array. */ -void ping_array_kill(struct Ping_Array *_array); +void ping_array_kill(struct Ping_Array *array); /** * Add a data with length to the Ping_Array list and return a ping_id. * * @return ping_id on success, 0 on failure. */ -uint64_t ping_array_add(struct Ping_Array *_array, const struct Mono_Time *mono_time, const uint8_t *data, +uint64_t ping_array_add(struct Ping_Array *array, const struct Mono_Time *mono_time, const uint8_t *data, uint32_t length); /** @@ -56,7 +56,7 @@ uint64_t ping_array_add(struct Ping_Array *_array, const struct Mono_Time *mono_ * * @return length of data copied on success, -1 on failure. */ -int32_t ping_array_check(struct Ping_Array *_array, const struct Mono_Time *mono_time, uint8_t *data, size_t length, +int32_t ping_array_check(struct Ping_Array *array, const struct Mono_Time *mono_time, uint8_t *data, size_t length, uint64_t ping_id); #ifdef __cplusplus diff --git a/protocols/Tox/libtox/src/toxcore/state.c b/protocols/Tox/libtox/src/toxcore/state.c index 67cc68ada4..13ae8e7189 100644 --- a/protocols/Tox/libtox/src/toxcore/state.c +++ b/protocols/Tox/libtox/src/toxcore/state.c @@ -11,7 +11,7 @@ int state_load(const Logger *log, state_load_cb *state_load_callback, void *oute const uint8_t *data, uint32_t length, uint16_t cookie_inner) { if (state_load_callback == nullptr || data == nullptr) { - LOGGER_ERROR(log, "state_load() called with invalid args.\n"); + LOGGER_ERROR(log, "state_load() called with invalid args."); return -1; } @@ -30,13 +30,13 @@ int state_load(const Logger *log, state_load_cb *state_load_callback, void *oute if (length < length_sub) { /* file truncated */ - LOGGER_ERROR(log, "state file too short: %u < %u\n", length, length_sub); + LOGGER_ERROR(log, "state file too short: %u < %u", length, length_sub); return -1; } if (lendian_to_host16((cookie_type >> 16)) != cookie_inner) { /* something is not matching up in a bad way, give up */ - LOGGER_ERROR(log, "state file garbled: %04x != %04x\n", cookie_type >> 16, cookie_inner); + LOGGER_ERROR(log, "state file garbled: %04x != %04x", cookie_type >> 16, cookie_inner); return -1; } @@ -58,7 +58,7 @@ int state_load(const Logger *log, state_load_cb *state_load_callback, void *oute } if (length != 0) { - LOGGER_ERROR(log, "unparsed data in state file of length %u\n", length); + LOGGER_ERROR(log, "unparsed data in state file of length %u", length); return -1; } diff --git a/protocols/Tox/libtox/src/toxcore/tox.api.h b/protocols/Tox/libtox/src/toxcore/tox.api.h index c0901d0afe..3655617181 100644 --- a/protocols/Tox/libtox/src/toxcore/tox.api.h +++ b/protocols/Tox/libtox/src/toxcore/tox.api.h @@ -14,6 +14,8 @@ #include <stddef.h> #include <stdint.h> +//!TOKSTYLE- + #ifdef __cplusplus extern "C" { #endif @@ -167,7 +169,7 @@ const VERSION_MINOR = 2; * The patch or revision number. Incremented when bugfixes are applied without * changing any functionality or API or ABI. */ -const VERSION_PATCH = 11; +const VERSION_PATCH = 12; /** * A macro to check at preprocessing time whether the client code is compatible @@ -854,7 +856,7 @@ enum class CONNECTION { } -inline namespace self { +namespace self { CONNECTION connection_status { /** @@ -908,7 +910,7 @@ void iterate(any user_data); ******************************************************************************/ -inline namespace self { +namespace self { uint8_t[ADDRESS_SIZE] address { /** @@ -986,7 +988,7 @@ error for set_info { } -inline namespace self { +namespace self { uint8_t[length <= MAX_NAME_LENGTH] name { /** @@ -1226,7 +1228,7 @@ namespace friend { } -inline namespace self { +namespace self { uint32_t[size] friend_list { /** @@ -1514,8 +1516,14 @@ namespace friend { * ******************************************************************************/ +error for set_typing { + /** + * The friend number did not designate a valid friend. + */ + FRIEND_NOT_FOUND, +} -inline namespace self { +namespace self { bool typing { /** @@ -1528,12 +1536,7 @@ inline namespace self { * * @return true on success. */ - set(uint32_t friend_number) { - /** - * The friend number did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - } + set(uint32_t friend_number) with error for set_typing; } } @@ -2279,9 +2282,9 @@ namespace conference { namespace peer { /** - * Return the number of online peers in the conference. The unsigned - * integers less than this number are the valid values of peer_number for - * the functions querying these peers. Return value is unspecified on + * Return the number of online peers in the conference. The unsigned + * integers less than this number are the valid values of peer_number for + * the functions querying these peers. Return value is unspecified on * failure. */ const uint32_t count(uint32_t conference_number) @@ -2330,8 +2333,8 @@ namespace conference { namespace offline_peer { /** - * Return the number of offline peers in the conference. The unsigned - * integers less than this number are the valid values of offline_peer_number for + * Return the number of offline peers in the conference. The unsigned + * integers less than this number are the valid values of offline_peer_number for * the functions querying these peers. Return value is unspecified on failure. */ const uint32_t count(uint32_t conference_number) @@ -2655,41 +2658,41 @@ namespace conference { namespace friend { - inline namespace send { + error for custom_packet { + NULL, + /** + * The friend number did not designate a valid friend. + */ + FRIEND_NOT_FOUND, + /** + * This client is currently not connected to the friend. + */ + FRIEND_NOT_CONNECTED, + /** + * The first byte of data was not in the specified range for the packet type. + * This range is 192-254 for lossy, and 69, 160-191 for lossless packets. + */ + INVALID, + /** + * Attempted to send an empty packet. + */ + EMPTY, + /** + * Packet data length exceeded $MAX_CUSTOM_PACKET_SIZE. + */ + TOO_LONG, + /** + * Packet queue is full. + */ + SENDQ, + } - error for custom_packet { - NULL, - /** - * The friend number did not designate a valid friend. - */ - FRIEND_NOT_FOUND, - /** - * This client is currently not connected to the friend. - */ - FRIEND_NOT_CONNECTED, - /** - * The first byte of data was not in the specified range for the packet type. - * This range is 200-254 for lossy, and 160-191 for lossless packets. - */ - INVALID, - /** - * Attempted to send an empty packet. - */ - EMPTY, - /** - * Packet data length exceeded $MAX_CUSTOM_PACKET_SIZE. - */ - TOO_LONG, - /** - * Packet queue is full. - */ - SENDQ, - } + namespace send { /** * Send a custom lossy packet to a friend. * - * The first byte of data must be in the range 200-254. Maximum length of a + * The first byte of data must be in the range 192-254. Maximum length of a * custom packet is $MAX_CUSTOM_PACKET_SIZE. * * Lossy packets behave like UDP packets, meaning they might never reach the @@ -2713,7 +2716,7 @@ namespace friend { /** * Send a custom lossless packet to a friend. * - * The first byte of data must be in the range 160-191. Maximum length of a + * The first byte of data must be in the range 69, 160-191. Maximum length of a * custom packet is $MAX_CUSTOM_PACKET_SIZE. * * Lossless packet behaviour is comparable to TCP (reliability, arrive in order) @@ -2762,7 +2765,14 @@ namespace friend { ******************************************************************************/ -inline namespace self { +error for get_port { + /** + * The instance was not bound to any port. + */ + NOT_BOUND, +} + +namespace self { uint8_t[PUBLIC_KEY_SIZE] dht_id { /** @@ -2781,13 +2791,6 @@ inline namespace self { } - error for get_port { - /** - * The instance was not bound to any port. - */ - NOT_BOUND, - } - uint16_t udp_port { /** @@ -2853,5 +2856,7 @@ typedef TOX_CONNECTION Tox_Connection; typedef TOX_FILE_CONTROL Tox_File_Control; typedef TOX_CONFERENCE_TYPE Tox_Conference_Type; +//!TOKSTYLE+ + #endif // C_TOXCORE_TOXCORE_TOX_H %} diff --git a/protocols/Tox/libtox/src/toxcore/tox.c b/protocols/Tox/libtox/src/toxcore/tox.c index b70be7a3e0..d2d3ed344f 100644 --- a/protocols/Tox/libtox/src/toxcore/tox.c +++ b/protocols/Tox/libtox/src/toxcore/tox.c @@ -17,6 +17,7 @@ #endif #include "tox.h" +#include "tox_private.h" #include <assert.h> #include <stdlib.h> @@ -89,8 +90,10 @@ struct Tox { tox_conference_title_cb *conference_title_callback; tox_conference_peer_name_cb *conference_peer_name_callback; tox_conference_peer_list_changed_cb *conference_peer_list_changed_callback; - tox_friend_lossy_packet_cb *friend_lossy_packet_callback; - tox_friend_lossless_packet_cb *friend_lossless_packet_callback; + tox_friend_lossy_packet_cb *friend_lossy_packet_callback_per_pktid[UINT8_MAX + 1]; + tox_friend_lossless_packet_cb *friend_lossless_packet_callback_per_pktid[UINT8_MAX + 1]; + + void *toxav_object; // workaround to store a ToxAV object (setter and getter functions are available) }; static void lock(const Tox *tox) @@ -309,20 +312,28 @@ static void tox_conference_peer_list_changed_handler(Messenger *m, uint32_t conf static void tox_friend_lossy_packet_handler(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data, size_t length, void *user_data) { + assert(data != nullptr); + assert(length > 0); + struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; - if (tox_data->tox->friend_lossy_packet_callback != nullptr) { - tox_data->tox->friend_lossy_packet_callback(tox_data->tox, friend_number, data, length, tox_data->user_data); + if (tox_data->tox->friend_lossy_packet_callback_per_pktid[packet_id] != nullptr) { + tox_data->tox->friend_lossy_packet_callback_per_pktid[packet_id](tox_data->tox, friend_number, data, length, + tox_data->user_data); } } static void tox_friend_lossless_packet_handler(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data, size_t length, void *user_data) { + assert(data != nullptr); + assert(length > 0); + struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; - if (tox_data->tox->friend_lossless_packet_callback != nullptr) { - tox_data->tox->friend_lossless_packet_callback(tox_data->tox, friend_number, data, length, tox_data->user_data); + if (tox_data->tox->friend_lossless_packet_callback_per_pktid[packet_id] != nullptr) { + tox_data->tox->friend_lossless_packet_callback_per_pktid[packet_id](tox_data->tox, friend_number, data, length, + tox_data->user_data); } } @@ -350,7 +361,7 @@ static State_Load_Status state_load_callback(void *outer, const uint8_t *data, u return STATE_LOAD_STATUS_END; } - LOGGER_ERROR(tox->m->log, "Load state: contains unrecognized part (len %u, type %u)\n", + LOGGER_ERROR(tox->m->log, "Load state: contains unrecognized part (len %u, type %u)", length, type); return STATE_LOAD_STATUS_CONTINUE; @@ -635,6 +646,7 @@ static void end_save(uint8_t *data) size_t tox_get_savedata_size(const Tox *tox) { + assert(tox != nullptr); lock(tox); size_t ret = 2 * sizeof(uint32_t) + messenger_size(tox->m) @@ -646,6 +658,8 @@ size_t tox_get_savedata_size(const Tox *tox) void tox_get_savedata(const Tox *tox, uint8_t *savedata) { + assert(tox != nullptr); + if (savedata == nullptr) { return; } @@ -671,6 +685,8 @@ void tox_get_savedata(const Tox *tox, uint8_t *savedata) bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error) { + assert(tox != nullptr); + if (!host || !public_key) { SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); return 0; @@ -718,6 +734,8 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error) { + assert(tox != nullptr); + if (!host || !public_key) { SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); return 0; @@ -763,6 +781,7 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t Tox_Connection tox_self_get_connection_status(const Tox *tox) { + assert(tox != nullptr); lock(tox); const unsigned int ret = onion_connection_status(tox->m->onion_c); unlock(tox); @@ -781,11 +800,13 @@ Tox_Connection tox_self_get_connection_status(const Tox *tox) void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback) { + assert(tox != nullptr); tox->self_connection_status_callback = callback; } uint32_t tox_iteration_interval(const Tox *tox) { + assert(tox != nullptr); lock(tox); uint32_t ret = messenger_run_interval(tox->m); unlock(tox); @@ -794,6 +815,7 @@ uint32_t tox_iteration_interval(const Tox *tox) void tox_iterate(Tox *tox, void *user_data) { + assert(tox != nullptr); lock(tox); mono_time_update(tox->mono_time); @@ -807,6 +829,8 @@ void tox_iterate(Tox *tox, void *user_data) void tox_self_get_address(const Tox *tox, uint8_t *address) { + assert(tox != nullptr); + if (address) { lock(tox); getaddress(tox->m, address); @@ -816,6 +840,7 @@ void tox_self_get_address(const Tox *tox, uint8_t *address) void tox_self_set_nospam(Tox *tox, uint32_t nospam) { + assert(tox != nullptr); lock(tox); set_nospam(tox->m->fr, net_htonl(nospam)); unlock(tox); @@ -823,6 +848,7 @@ void tox_self_set_nospam(Tox *tox, uint32_t nospam) uint32_t tox_self_get_nospam(const Tox *tox) { + assert(tox != nullptr); lock(tox); uint32_t ret = net_ntohl(get_nospam(tox->m->fr)); unlock(tox); @@ -831,6 +857,8 @@ uint32_t tox_self_get_nospam(const Tox *tox) void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) { + assert(tox != nullptr); + if (public_key) { lock(tox); memcpy(public_key, nc_get_self_public_key(tox->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE); @@ -840,6 +868,8 @@ void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key) { + assert(tox != nullptr); + if (secret_key) { lock(tox); memcpy(secret_key, nc_get_self_secret_key(tox->m->net_crypto), CRYPTO_SECRET_KEY_SIZE); @@ -849,6 +879,8 @@ void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key) bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set_Info *error) { + assert(tox != nullptr); + if (!name && length != 0) { SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); return 0; @@ -871,6 +903,7 @@ bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set size_t tox_self_get_name_size(const Tox *tox) { + assert(tox != nullptr); lock(tox); size_t ret = m_get_self_name_size(tox->m); unlock(tox); @@ -879,6 +912,8 @@ size_t tox_self_get_name_size(const Tox *tox) void tox_self_get_name(const Tox *tox, uint8_t *name) { + assert(tox != nullptr); + if (name) { lock(tox); getself_name(tox->m, name); @@ -888,6 +923,8 @@ void tox_self_get_name(const Tox *tox, uint8_t *name) bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t length, Tox_Err_Set_Info *error) { + assert(tox != nullptr); + if (!status_message && length != 0) { SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); return 0; @@ -908,6 +945,7 @@ bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t size_t tox_self_get_status_message_size(const Tox *tox) { + assert(tox != nullptr); lock(tox); size_t ret = m_get_self_statusmessage_size(tox->m); unlock(tox); @@ -916,6 +954,8 @@ size_t tox_self_get_status_message_size(const Tox *tox) void tox_self_get_status_message(const Tox *tox, uint8_t *status_message) { + assert(tox != nullptr); + if (status_message) { lock(tox); m_copy_self_statusmessage(tox->m, status_message); @@ -925,6 +965,7 @@ void tox_self_get_status_message(const Tox *tox, uint8_t *status_message) void tox_self_set_status(Tox *tox, Tox_User_Status status) { + assert(tox != nullptr); lock(tox); m_set_userstatus(tox->m, status); unlock(tox); @@ -932,6 +973,7 @@ void tox_self_set_status(Tox *tox, Tox_User_Status status) Tox_User_Status tox_self_get_status(const Tox *tox) { + assert(tox != nullptr); lock(tox); const uint8_t status = m_get_self_userstatus(tox->m); unlock(tox); @@ -979,6 +1021,8 @@ static void set_friend_error(const Logger *log, int32_t ret, Tox_Err_Friend_Add uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length, Tox_Err_Friend_Add *error) { + assert(tox != nullptr); + if (!address || !message) { SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL); return UINT32_MAX; @@ -1000,6 +1044,8 @@ uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_Friend_Add *error) { + assert(tox != nullptr); + if (!public_key) { SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL); return UINT32_MAX; @@ -1021,6 +1067,7 @@ uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_F bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *error) { + assert(tox != nullptr); lock(tox); const int ret = m_delfriend(tox->m, friend_number); unlock(tox); @@ -1037,6 +1084,8 @@ bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete * uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox_Err_Friend_By_Public_Key *error) { + assert(tox != nullptr); + if (!public_key) { SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_BY_PUBLIC_KEY_NULL); return UINT32_MAX; @@ -1058,6 +1107,8 @@ uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key, Tox_Err_Friend_Get_Public_Key *error) { + assert(tox != nullptr); + if (!public_key) { return 0; } @@ -1077,6 +1128,7 @@ bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t * bool tox_friend_exists(const Tox *tox, uint32_t friend_number) { + assert(tox != nullptr); lock(tox); bool ret = m_friend_exists(tox->m, friend_number); unlock(tox); @@ -1085,6 +1137,7 @@ bool tox_friend_exists(const Tox *tox, uint32_t friend_number) uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Get_Last_Online *error) { + assert(tox != nullptr); lock(tox); const uint64_t timestamp = m_get_last_online(tox->m, friend_number); unlock(tox); @@ -1100,6 +1153,7 @@ uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_ size_t tox_self_get_friend_list_size(const Tox *tox) { + assert(tox != nullptr); lock(tox); size_t ret = count_friendlist(tox->m); unlock(tox); @@ -1108,6 +1162,8 @@ size_t tox_self_get_friend_list_size(const Tox *tox) void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list) { + assert(tox != nullptr); + if (friend_list) { lock(tox); // TODO(irungentoo): size parameter? @@ -1118,6 +1174,7 @@ void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list) size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = m_get_name_size(tox->m, friend_number); unlock(tox); @@ -1133,6 +1190,8 @@ size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_ bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, Tox_Err_Friend_Query *error) { + assert(tox != nullptr); + if (!name) { SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL); return 0; @@ -1153,11 +1212,13 @@ bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback) { + assert(tox != nullptr); tox->friend_name_callback = callback; } size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = m_get_statusmessage_size(tox->m, friend_number); unlock(tox); @@ -1174,6 +1235,8 @@ size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8_t *status_message, Tox_Err_Friend_Query *error) { + assert(tox != nullptr); + if (!status_message) { SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL); return false; @@ -1198,11 +1261,13 @@ bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8 void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback) { + assert(tox != nullptr); tox->friend_status_message_callback = callback; } Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = m_get_userstatus(tox->m, friend_number); unlock(tox); @@ -1218,11 +1283,13 @@ Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, To void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback) { + assert(tox != nullptr); tox->friend_status_callback = callback; } Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = m_get_friend_connectionstatus(tox->m, friend_number); unlock(tox); @@ -1238,11 +1305,13 @@ Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_ void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback) { + assert(tox != nullptr); tox->friend_connection_status_callback = callback; } bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = m_get_istyping(tox->m, friend_number); unlock(tox); @@ -1258,11 +1327,13 @@ bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Frien void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback) { + assert(tox != nullptr); tox->friend_typing_callback = callback; } bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, Tox_Err_Set_Typing *error) { + assert(tox != nullptr); lock(tox); if (m_set_usertyping(tox->m, friend_number, typing) == -1) { @@ -1313,6 +1384,8 @@ static void set_message_error(const Logger *log, int ret, Tox_Err_Friend_Send_Me uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_Type type, const uint8_t *message, size_t length, Tox_Err_Friend_Send_Message *error) { + assert(tox != nullptr); + if (!message) { SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_NULL); return 0; @@ -1333,16 +1406,19 @@ uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_T void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *callback) { + assert(tox != nullptr); tox->friend_read_receipt_callback = callback; } void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback) { + assert(tox != nullptr); tox->friend_request_callback = callback; } void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback) { + assert(tox != nullptr); tox->friend_message_callback = callback; } @@ -1359,6 +1435,7 @@ bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length) bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control, Tox_Err_File_Control *error) { + assert(tox != nullptr); lock(tox); const int ret = file_control(tox->m, friend_number, file_number, control); unlock(tox); @@ -1409,6 +1486,7 @@ bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, To bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, Tox_Err_File_Seek *error) { + assert(tox != nullptr); lock(tox); const int ret = file_seek(tox->m, friend_number, file_number, position); unlock(tox); @@ -1451,12 +1529,15 @@ bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint6 void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback) { + assert(tox != nullptr); tox->file_recv_control_callback = callback; } bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, Tox_Err_File_Get *error) { + assert(tox != nullptr); + if (!file_id) { SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NULL); return 0; @@ -1483,6 +1564,8 @@ bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id, const uint8_t *filename, size_t filename_length, Tox_Err_File_Send *error) { + assert(tox != nullptr); + if (filename_length && !filename) { SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL); return UINT32_MAX; @@ -1530,6 +1613,7 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data, size_t length, Tox_Err_File_Send_Chunk *error) { + assert(tox != nullptr); lock(tox); const int ret = file_data(tox->m, friend_number, file_number, position, data, length); unlock(tox); @@ -1575,51 +1659,61 @@ bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback) { + assert(tox != nullptr); tox->file_chunk_request_callback = callback; } void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback) { + assert(tox != nullptr); tox->file_recv_callback = callback; } void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback) { + assert(tox != nullptr); tox->file_recv_chunk_callback = callback; } void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback) { + assert(tox != nullptr); tox->conference_invite_callback = callback; } void tox_callback_conference_connected(Tox *tox, tox_conference_connected_cb *callback) { + assert(tox != nullptr); tox->conference_connected_callback = callback; } void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback) { + assert(tox != nullptr); tox->conference_message_callback = callback; } void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback) { + assert(tox != nullptr); tox->conference_title_callback = callback; } void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *callback) { + assert(tox != nullptr); tox->conference_peer_name_callback = callback; } void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_list_changed_cb *callback) { + assert(tox != nullptr); tox->conference_peer_list_changed_callback = callback; } uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error) { + assert(tox != nullptr); lock(tox); const int ret = add_groupchat(tox->m->conferences_object, GROUPCHAT_TYPE_TEXT); unlock(tox); @@ -1635,6 +1729,7 @@ uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error) bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error) { + assert(tox != nullptr); lock(tox); const int ret = del_groupchat(tox->m->conferences_object, conference_number, true); unlock(tox); @@ -1650,6 +1745,7 @@ bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Confere uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = group_number_peers(tox->m->conferences_object, conference_number, false); unlock(tox); @@ -1666,6 +1762,7 @@ uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, T size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number, Tox_Err_Conference_Peer_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = group_peername_size(tox->m->conferences_object, conference_number, peer_number, false); unlock(tox); @@ -1687,6 +1784,7 @@ size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_num bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name, Tox_Err_Conference_Peer_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = group_peername(tox->m->conferences_object, conference_number, peer_number, name, false); unlock(tox); @@ -1708,6 +1806,7 @@ bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, ui bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *public_key, Tox_Err_Conference_Peer_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = group_peer_pubkey(tox->m->conferences_object, conference_number, peer_number, public_key, false); unlock(tox); @@ -1729,6 +1828,7 @@ bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_numb bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number, Tox_Err_Conference_Peer_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = group_peernumber_is_ours(tox->m->conferences_object, conference_number, peer_number); unlock(tox); @@ -1754,6 +1854,7 @@ bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_numb uint32_t tox_conference_offline_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = group_number_peers(tox->m->conferences_object, conference_number, true); unlock(tox); @@ -1771,6 +1872,7 @@ size_t tox_conference_offline_peer_get_name_size(const Tox *tox, uint32_t confer uint32_t offline_peer_number, Tox_Err_Conference_Peer_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = group_peername_size(tox->m->conferences_object, conference_number, offline_peer_number, true); unlock(tox); @@ -1793,6 +1895,7 @@ bool tox_conference_offline_peer_get_name(const Tox *tox, uint32_t conference_nu uint8_t *name, Tox_Err_Conference_Peer_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = group_peername(tox->m->conferences_object, conference_number, offline_peer_number, name, true); unlock(tox); @@ -1815,6 +1918,7 @@ bool tox_conference_offline_peer_get_public_key(const Tox *tox, uint32_t confere uint32_t offline_peer_number, uint8_t *public_key, Tox_Err_Conference_Peer_Query *error) { + assert(tox != nullptr); lock(tox); const int ret = group_peer_pubkey(tox->m->conferences_object, conference_number, offline_peer_number, public_key, true); unlock(tox); @@ -1837,6 +1941,7 @@ uint64_t tox_conference_offline_peer_get_last_active(const Tox *tox, uint32_t co uint32_t offline_peer_number, Tox_Err_Conference_Peer_Query *error) { + assert(tox != nullptr); uint64_t last_active = UINT64_MAX; lock(tox); const int ret = group_frozen_last_active(tox->m->conferences_object, conference_number, offline_peer_number, @@ -1861,6 +1966,7 @@ bool tox_conference_set_max_offline(Tox *tox, uint32_t conference_number, uint32_t max_offline_peers, Tox_Err_Conference_Set_Max_Offline *error) { + assert(tox != nullptr); lock(tox); const int ret = group_set_max_frozen(tox->m->conferences_object, conference_number, max_offline_peers); unlock(tox); @@ -1877,6 +1983,7 @@ bool tox_conference_set_max_offline(Tox *tox, uint32_t conference_number, bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number, Tox_Err_Conference_Invite *error) { + assert(tox != nullptr); lock(tox); const int ret = invite_friend(tox->m->conferences_object, friend_number, conference_number); unlock(tox); @@ -1902,6 +2009,7 @@ bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length, Tox_Err_Conference_Join *error) { + assert(tox != nullptr); lock(tox); const int ret = join_groupchat(tox->m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length); unlock(tox); @@ -1939,6 +2047,7 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Message_Type type, const uint8_t *message, size_t length, Tox_Err_Conference_Send_Message *error) { + assert(tox != nullptr); lock(tox); int ret = 0; @@ -1974,6 +2083,7 @@ bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Messa size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error) { + assert(tox != nullptr); lock(tox); const int ret = group_title_get_size(tox->m->conferences_object, conference_number); unlock(tox); @@ -1995,6 +2105,7 @@ size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title, Tox_Err_Conference_Title *error) { + assert(tox != nullptr); lock(tox); const int ret = group_title_get(tox->m->conferences_object, conference_number, title); unlock(tox); @@ -2016,6 +2127,7 @@ bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_ bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length, Tox_Err_Conference_Title *error) { + assert(tox != nullptr); lock(tox); const int ret = group_title_send(tox->m->conferences_object, conference_number, title, length); unlock(tox); @@ -2040,6 +2152,7 @@ bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_ size_t tox_conference_get_chatlist_size(const Tox *tox) { + assert(tox != nullptr); lock(tox); size_t ret = count_chatlist(tox->m->conferences_object); unlock(tox); @@ -2048,6 +2161,7 @@ size_t tox_conference_get_chatlist_size(const Tox *tox) void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist) { + assert(tox != nullptr); lock(tox); const size_t list_size = count_chatlist(tox->m->conferences_object); copy_chatlist(tox->m->conferences_object, chatlist, list_size); @@ -2057,6 +2171,7 @@ void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist) Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Get_Type *error) { + assert(tox != nullptr); lock(tox); const int ret = group_get_type(tox->m->conferences_object, conference_number); unlock(tox); @@ -2073,6 +2188,7 @@ Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_ /* id is TOX_CONFERENCE_ID_SIZE bytes */ bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id) { + assert(tox != nullptr); lock(tox); bool ret = conference_get_id(tox->m->conferences_object, conference_number, id); unlock(tox); @@ -2083,11 +2199,14 @@ bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t * /* uid is TOX_CONFERENCE_ID_SIZE bytes */ bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid) { + assert(tox != nullptr); return tox_conference_get_id(tox, conference_number, uid); } uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Conference_By_Id *error) { + assert(tox != nullptr); + if (!id) { SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_ID_NULL); return UINT32_MAX; @@ -2109,6 +2228,7 @@ uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Confere // TODO(iphydf): Delete in 0.3.0. uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Conference_By_Uid *error) { + assert(tox != nullptr); Tox_Err_Conference_By_Id id_error; const uint32_t res = tox_conference_by_id(tox, uid, &id_error); @@ -2161,6 +2281,8 @@ static void set_custom_packet_error(int ret, Tox_Err_Friend_Custom_Packet *error bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, Tox_Err_Friend_Custom_Packet *error) { + assert(tox != nullptr); + if (!data) { SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); return 0; @@ -2171,9 +2293,7 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_ return 0; } - // TODO(oxij): this feels ugly, this is needed only because m_send_custom_lossy_packet in Messenger.c - // sends both AV and custom packets despite its name and this API hides those AV packets - if (data[0] <= PACKET_ID_RANGE_LOSSY_AV_END) { + if (data[0] < PACKET_ID_RANGE_LOSSY_START || data[0] > PACKET_ID_RANGE_LOSSY_END) { SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_INVALID); return 0; } @@ -2193,12 +2313,28 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_ void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback) { - tox->friend_lossy_packet_callback = callback; + assert(tox != nullptr); + + /* start at PACKET_ID_RANGE_LOSSY_CUSTOM_START so ToxAV Packets are excluded */ + for (uint8_t i = PACKET_ID_RANGE_LOSSY_CUSTOM_START; i <= PACKET_ID_RANGE_LOSSY_END; ++i) { + tox->friend_lossy_packet_callback_per_pktid[i] = callback; + } +} + +void tox_callback_friend_lossy_packet_per_pktid(Tox *tox, tox_friend_lossy_packet_cb *callback, uint8_t pktid) +{ + assert(tox != nullptr); + + if (pktid >= PACKET_ID_RANGE_LOSSY_START && pktid <= PACKET_ID_RANGE_LOSSY_END) { + tox->friend_lossy_packet_callback_per_pktid[pktid] = callback; + } } bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, Tox_Err_Friend_Custom_Packet *error) { + assert(tox != nullptr); + if (!data) { SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); return 0; @@ -2224,11 +2360,27 @@ bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uin void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback) { - tox->friend_lossless_packet_callback = callback; + assert(tox != nullptr); + + for (uint8_t i = PACKET_ID_RANGE_LOSSLESS_CUSTOM_START; i <= PACKET_ID_RANGE_LOSSLESS_CUSTOM_END; ++i) { + tox->friend_lossless_packet_callback_per_pktid[i] = callback; + } +} + +void tox_callback_friend_lossless_packet_per_pktid(Tox *tox, tox_friend_lossless_packet_cb *callback, uint8_t pktid) +{ + assert(tox != nullptr); + + if ((pktid >= PACKET_ID_RANGE_LOSSLESS_CUSTOM_START && pktid <= PACKET_ID_RANGE_LOSSLESS_CUSTOM_END) + || pktid == PACKET_ID_MSI) { + tox->friend_lossless_packet_callback_per_pktid[pktid] = callback; + } } void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id) { + assert(tox != nullptr); + if (dht_id) { lock(tox); memcpy(dht_id, dht_get_self_public_key(tox->m->dht), CRYPTO_PUBLIC_KEY_SIZE); @@ -2236,8 +2388,26 @@ void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id) } } +void tox_set_av_object(Tox *tox, void *object) +{ + assert(tox != nullptr); + lock(tox); + tox->toxav_object = object; + unlock(tox); +} + +void *tox_get_av_object(const Tox *tox) +{ + assert(tox != nullptr); + lock(tox); + void *object = tox->toxav_object; + unlock(tox); + return object; +} + uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error) { + assert(tox != nullptr); lock(tox); const uint16_t port = net_htons(net_port(tox->m->net)); unlock(tox); @@ -2253,6 +2423,7 @@ uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error) uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error) { + assert(tox != nullptr); lock(tox); if (tox->m->tcp_server) { diff --git a/protocols/Tox/libtox/src/toxcore/tox.h b/protocols/Tox/libtox/src/toxcore/tox.h index fd57e20d42..c9c0967a7f 100644 --- a/protocols/Tox/libtox/src/toxcore/tox.h +++ b/protocols/Tox/libtox/src/toxcore/tox.h @@ -13,6 +13,8 @@ #include <stddef.h> #include <stdint.h> +//!TOKSTYLE- + #ifdef __cplusplus extern "C" { #endif @@ -168,7 +170,7 @@ uint32_t tox_version_minor(void); * The patch or revision number. Incremented when bugfixes are applied without * changing any functionality or API or ABI. */ -#define TOX_VERSION_PATCH 11 +#define TOX_VERSION_PATCH 12 uint32_t tox_version_patch(void); @@ -3065,7 +3067,7 @@ typedef enum TOX_ERR_FRIEND_CUSTOM_PACKET { /** * The first byte of data was not in the specified range for the packet type. - * This range is 200-254 for lossy, and 160-191 for lossless packets. + * This range is 192-254 for lossy, and 69, 160-191 for lossless packets. */ TOX_ERR_FRIEND_CUSTOM_PACKET_INVALID, @@ -3090,7 +3092,7 @@ typedef enum TOX_ERR_FRIEND_CUSTOM_PACKET { /** * Send a custom lossy packet to a friend. * - * The first byte of data must be in the range 200-254. Maximum length of a + * The first byte of data must be in the range 192-254. Maximum length of a * custom packet is TOX_MAX_CUSTOM_PACKET_SIZE. * * Lossy packets behave like UDP packets, meaning they might never reach the @@ -3113,7 +3115,7 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_ /** * Send a custom lossless packet to a friend. * - * The first byte of data must be in the range 160-191. Maximum length of a + * The first byte of data must be in the range 69, 160-191. Maximum length of a * custom packet is TOX_MAX_CUSTOM_PACKET_SIZE. * * Lossless packet behaviour is comparable to TCP (reliability, arrive in order) @@ -3168,20 +3170,6 @@ void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb -/** - * Writes the temporary DHT public key of this instance to a byte array. - * - * This can be used in combination with an externally accessible IP address and - * the bound port (from tox_self_get_udp_port) to run a temporary bootstrap node. - * - * Be aware that every time a new instance is created, the DHT public key - * changes, meaning this cannot be used to run a permanent bootstrap node. - * - * @param dht_id A memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If this - * parameter is NULL, this function has no effect. - */ -void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id); - typedef enum TOX_ERR_GET_PORT { /** @@ -3198,6 +3186,20 @@ typedef enum TOX_ERR_GET_PORT { /** + * Writes the temporary DHT public key of this instance to a byte array. + * + * This can be used in combination with an externally accessible IP address and + * the bound port (from tox_self_get_udp_port) to run a temporary bootstrap node. + * + * Be aware that every time a new instance is created, the DHT public key + * changes, meaning this cannot be used to run a permanent bootstrap node. + * + * @param dht_id A memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If this + * parameter is NULL, this function has no effect. + */ +void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id); + +/** * Return the UDP port this Tox instance is bound to. */ uint16_t tox_self_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error); @@ -3251,4 +3253,6 @@ typedef TOX_CONNECTION Tox_Connection; typedef TOX_FILE_CONTROL Tox_File_Control; typedef TOX_CONFERENCE_TYPE Tox_Conference_Type; +//!TOKSTYLE+ + #endif // C_TOXCORE_TOXCORE_TOX_H diff --git a/protocols/Tox/libtox/src/toxcore/tox_api.c b/protocols/Tox/libtox/src/toxcore/tox_api.c index 8503f237c9..63b4bea335 100644 --- a/protocols/Tox/libtox/src/toxcore/tox_api.c +++ b/protocols/Tox/libtox/src/toxcore/tox_api.c @@ -7,6 +7,7 @@ #define SET_ERROR_PARAMETER(param, x) do { if (param) { *param = x; } } while (0) +//!TOKSTYLE- #define CONST_FUNCTION(lowercase, uppercase) \ uint32_t tox_##lowercase(void) \ @@ -60,6 +61,8 @@ ACCESSORS(void *, log_, user_data) ACCESSORS(bool,, local_discovery_enabled) ACCESSORS(bool,, experimental_thread_safety) +//!TOKSTYLE+ + const uint8_t *tox_options_get_savedata_data(const struct Tox_Options *options) { return options->savedata_data; diff --git a/protocols/Tox/libtox/src/toxcore/tox_private.h b/protocols/Tox/libtox/src/toxcore/tox_private.h new file mode 100644 index 0000000000..593282f7c8 --- /dev/null +++ b/protocols/Tox/libtox/src/toxcore/tox_private.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + * Copyright © 2016-2020 The TokTok team. + * Copyright © 2013 Tox project. + */ + +#ifndef C_TOXCORE_TOXCORE_TOX_PRIVATE_H +#define C_TOXCORE_TOXCORE_TOX_PRIVATE_H + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Set the callback for the `friend_lossy_packet` event for a specific packet ID. + * Pass NULL to unset. + * + * allowed packet ID range: + * from `PACKET_ID_RANGE_LOSSY_START` to `PACKET_ID_RANGE_LOSSY_END` (both inclusive) + */ +void tox_callback_friend_lossy_packet_per_pktid(Tox *tox, tox_friend_lossy_packet_cb *callback, uint8_t pktid); + +/** + * Set the callback for the `friend_lossless_packet` event for a specific packet ID. + * Pass NULL to unset. + * + * allowed packet ID range: + * from `PACKET_ID_RANGE_LOSSLESS_CUSTOM_START` to `PACKET_ID_RANGE_LOSSLESS_CUSTOM_END` (both inclusive) + * and + * `PACKET_ID_MSI` + */ +void tox_callback_friend_lossless_packet_per_pktid(Tox *tox, tox_friend_lossless_packet_cb *callback, uint8_t pktid); + +void tox_set_av_object(Tox *tox, void *object); +void *tox_get_av_object(const Tox *tox); + +#ifdef __cplusplus +} +#endif + +#endif // C_TOXCORE_TOXCORE_TOX_PRIVATE_H diff --git a/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c b/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c index e2de3e5f74..3aab156f9d 100644 --- a/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +++ b/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c @@ -201,7 +201,7 @@ crypto_pwhash_scryptsalsa208sha256_str_verify(const char str[crypto_pwhash_scryp return -1; } escrypt_free_local(&escrypt_local); - ret = crypto_memcmp(wanted, str, sizeof wanted); + ret = crypto_memcmp((const uint8_t *) wanted, (const uint8_t *) str, sizeof wanted); crypto_memzero(wanted, sizeof wanted); return ret; diff --git a/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c b/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c index 7f01523861..38a536a61a 100644 --- a/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +++ b/protocols/Tox/libtox/src/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c @@ -398,4 +398,4 @@ escrypt_kdf_sse(escrypt_local_t * local, #endif /* ISO C requires a translation unit to contain at least one declaration */ -extern int non_empty_tu_decl; +typedef int non_empty_tu_decl; diff --git a/protocols/Tox/libtox/src/toxencryptsave/defines.h b/protocols/Tox/libtox/src/toxencryptsave/defines.h index 0bc1d9ed5e..8a490344a7 100644 --- a/protocols/Tox/libtox/src/toxencryptsave/defines.h +++ b/protocols/Tox/libtox/src/toxencryptsave/defines.h @@ -1,7 +1,7 @@ #ifndef C_TOXCORE_TOXENCRYPTSAVE_DEFINES_H #define C_TOXCORE_TOXENCRYPTSAVE_DEFINES_H -#define TOX_ENC_SAVE_MAGIC_NUMBER "toxEsave" +#define TOX_ENC_SAVE_MAGIC_NUMBER ((const uint8_t *)"toxEsave") #define TOX_ENC_SAVE_MAGIC_LENGTH 8 #endif |