diff options
Diffstat (limited to 'protocols/Tox/libtox/src')
66 files changed, 1678 insertions, 1430 deletions
diff --git a/protocols/Tox/libtox/src/third_party/cmp/cmp.c b/protocols/Tox/libtox/src/third_party/cmp/cmp.c index c312efd6c7..c11d23a8a3 100644 --- a/protocols/Tox/libtox/src/third_party/cmp/cmp.c +++ b/protocols/Tox/libtox/src/third_party/cmp/cmp.c @@ -865,7 +865,7 @@ bool cmp_write_pfix(cmp_ctx_t *ctx, uint8_t c) { } bool cmp_write_nfix(cmp_ctx_t *ctx, int8_t c) { - if (c >= -32 && c <= -1) + if (c >= -0x20 && c <= -1) return write_fixed_value(ctx, (uint8_t)c); ctx->error = CMP_ERROR_INPUT_VALUE_TOO_LARGE; @@ -875,7 +875,7 @@ bool cmp_write_nfix(cmp_ctx_t *ctx, int8_t c) { bool cmp_write_sfix(cmp_ctx_t *ctx, int8_t c) { if (c >= 0) return cmp_write_pfix(ctx, (uint8_t)c); - if (c >= -32 && c <= -1) + if (c >= -0x20 && c <= -1) return cmp_write_nfix(ctx, c); ctx->error = CMP_ERROR_INPUT_VALUE_TOO_LARGE; diff --git a/protocols/Tox/libtox/src/toxcore/DHT.c b/protocols/Tox/libtox/src/toxcore/DHT.c index 2567d1b5a8..89c85c3463 100644 --- a/protocols/Tox/libtox/src/toxcore/DHT.c +++ b/protocols/Tox/libtox/src/toxcore/DHT.c @@ -380,12 +380,12 @@ int dht_create_packet(const Memory *mem, const Random *rng, const int encrypted_length = encrypt_data_symmetric(shared_key, nonce, plain, plain_length, encrypted); - if (encrypted_length == -1) { + if (encrypted_length < 0) { mem_delete(mem, encrypted); return -1; } - if (length < 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + encrypted_length) { + if (length < 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + (size_t)encrypted_length) { mem_delete(mem, encrypted); return -1; } @@ -1347,15 +1347,15 @@ static int sendnodes_ipv6(const DHT *dht, const IP_Port *ip_port, const uint8_t plain[0] = num_nodes; memcpy(plain + 1 + nodes_length, sendback_data, length); - const uint32_t crypto_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE; - const uint32_t data_size = 1 + nodes_length + length + crypto_size; + const uint16_t crypto_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE; + const uint16_t data_size = 1 + nodes_length + length + crypto_size; VLA(uint8_t, data, data_size); const int len = dht_create_packet(dht->mem, dht->rng, dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6, plain, 1 + nodes_length + length, data, data_size); - if (len != data_size) { + if (len < 0 || (uint32_t)len != data_size) { return -1; } diff --git a/protocols/Tox/libtox/src/toxcore/Makefile.inc b/protocols/Tox/libtox/src/toxcore/Makefile.inc new file mode 100644 index 0000000000..db3e193243 --- /dev/null +++ b/protocols/Tox/libtox/src/toxcore/Makefile.inc @@ -0,0 +1,170 @@ +lib_LTLIBRARIES += libtoxcore.la + +libtoxcore_la_include_HEADERS = \ + ../toxcore/tox.h + +libtoxcore_la_includedir = $(includedir)/tox + +libtoxcore_la_SOURCES = ../third_party/cmp/cmp.c \ + ../third_party/cmp/cmp.h \ + ../toxcore/attributes.h \ + ../toxcore/bin_pack.c \ + ../toxcore/bin_pack.h \ + ../toxcore/bin_unpack.c \ + ../toxcore/bin_unpack.h \ + ../toxcore/ccompat.c \ + ../toxcore/ccompat.h \ + ../toxcore/events/conference_connected.c \ + ../toxcore/events/conference_invite.c \ + ../toxcore/events/conference_message.c \ + ../toxcore/events/conference_peer_list_changed.c \ + ../toxcore/events/conference_peer_name.c \ + ../toxcore/events/conference_title.c \ + ../toxcore/events/dht_get_nodes_response.c \ + ../toxcore/events/events_alloc.c \ + ../toxcore/events/events_alloc.h \ + ../toxcore/events/file_chunk_request.c \ + ../toxcore/events/file_recv.c \ + ../toxcore/events/file_recv_chunk.c \ + ../toxcore/events/file_recv_control.c \ + ../toxcore/events/friend_connection_status.c \ + ../toxcore/events/friend_lossless_packet.c \ + ../toxcore/events/friend_lossy_packet.c \ + ../toxcore/events/friend_message.c \ + ../toxcore/events/friend_name.c \ + ../toxcore/events/friend_read_receipt.c \ + ../toxcore/events/friend_request.c \ + ../toxcore/events/friend_status.c \ + ../toxcore/events/friend_status_message.c \ + ../toxcore/events/friend_typing.c \ + ../toxcore/events/self_connection_status.c \ + ../toxcore/events/group_custom_packet.c \ + ../toxcore/events/group_custom_private_packet.c \ + ../toxcore/events/group_invite.c \ + ../toxcore/events/group_join_fail.c \ + ../toxcore/events/group_message.c \ + ../toxcore/events/group_moderation.c \ + ../toxcore/events/group_password.c \ + ../toxcore/events/group_peer_exit.c \ + ../toxcore/events/group_peer_join.c \ + ../toxcore/events/group_peer_limit.c \ + ../toxcore/events/group_peer_name.c \ + ../toxcore/events/group_peer_status.c \ + ../toxcore/events/group_privacy_state.c \ + ../toxcore/events/group_private_message.c \ + ../toxcore/events/group_self_join.c \ + ../toxcore/events/group_topic.c \ + ../toxcore/events/group_topic_lock.c \ + ../toxcore/events/group_voice_state.c \ + ../toxcore/DHT.h \ + ../toxcore/DHT.c \ + ../toxcore/mem.h \ + ../toxcore/mem.c \ + ../toxcore/mono_time.h \ + ../toxcore/mono_time.c \ + ../toxcore/network.h \ + ../toxcore/network.c \ + ../toxcore/crypto_core.h \ + ../toxcore/crypto_core.c \ + ../toxcore/crypto_core_pack.h \ + ../toxcore/crypto_core_pack.c \ + ../toxcore/timed_auth.h \ + ../toxcore/timed_auth.c \ + ../toxcore/ping_array.h \ + ../toxcore/ping_array.c \ + ../toxcore/net_crypto.h \ + ../toxcore/net_crypto.c \ + ../toxcore/friend_requests.h \ + ../toxcore/friend_requests.c \ + ../toxcore/LAN_discovery.h \ + ../toxcore/LAN_discovery.c \ + ../toxcore/friend_connection.h \ + ../toxcore/friend_connection.c \ + ../toxcore/Messenger.h \ + ../toxcore/Messenger.c \ + ../toxcore/ping.h \ + ../toxcore/ping.c \ + ../toxcore/shared_key_cache.h \ + ../toxcore/shared_key_cache.c \ + ../toxcore/state.h \ + ../toxcore/state.c \ + ../toxcore/tox.h \ + ../toxcore/tox.c \ + ../toxcore/tox_dispatch.h \ + ../toxcore/tox_dispatch.c \ + ../toxcore/tox_event.h \ + ../toxcore/tox_event.c \ + ../toxcore/tox_events.h \ + ../toxcore/tox_events.c \ + ../toxcore/tox_pack.h \ + ../toxcore/tox_pack.c \ + ../toxcore/tox_unpack.h \ + ../toxcore/tox_unpack.c \ + ../toxcore/tox_private.c \ + ../toxcore/tox_private.h \ + ../toxcore/tox_struct.h \ + ../toxcore/tox_api.c \ + ../toxcore/util.h \ + ../toxcore/util.c \ + ../toxcore/group.h \ + ../toxcore/group.c \ + ../toxcore/group_announce.h \ + ../toxcore/group_announce.c \ + ../toxcore/group_onion_announce.c \ + ../toxcore/group_onion_announce.h \ + ../toxcore/group_chats.h \ + ../toxcore/group_chats.c \ + ../toxcore/group_common.h \ + ../toxcore/group_connection.c \ + ../toxcore/group_connection.h \ + ../toxcore/group_pack.c \ + ../toxcore/group_pack.h \ + ../toxcore/group_moderation.c \ + ../toxcore/group_moderation.h \ + ../toxcore/onion.h \ + ../toxcore/onion.c \ + ../toxcore/logger.h \ + ../toxcore/logger.c \ + ../toxcore/onion_announce.h \ + ../toxcore/onion_announce.c \ + ../toxcore/onion_client.h \ + ../toxcore/onion_client.c \ + ../toxcore/announce.h \ + ../toxcore/announce.c \ + ../toxcore/forwarding.h \ + ../toxcore/forwarding.c \ + ../toxcore/TCP_client.h \ + ../toxcore/TCP_client.c \ + ../toxcore/TCP_common.h \ + ../toxcore/TCP_common.c \ + ../toxcore/TCP_server.h \ + ../toxcore/TCP_server.c \ + ../toxcore/TCP_connection.h \ + ../toxcore/TCP_connection.c \ + ../toxcore/list.c \ + ../toxcore/list.h + +libtoxcore_la_CFLAGS = -I$(top_srcdir) \ + -I$(top_srcdir)/toxcore \ + $(LIBSODIUM_CFLAGS) \ + $(MSGPACK_CFLAGS) \ + $(PTHREAD_CFLAGS) \ + -DCMP_NO_FLOAT=1 + +libtoxcore_la_LDFLAGS = $(LT_LDFLAGS) \ + $(EXTRA_LT_LDFLAGS) \ + $(LIBSODIUM_LDFLAGS) \ + $(MSGPACK_LDFLAGS) \ + $(MATH_LDFLAGS) \ + $(RT_LIBS) \ + $(WINSOCK2_LIBS) + +libtoxcore_la_LIBADD = $(LIBSODIUM_LIBS) \ + $(MSGPACK_LIBS) \ + $(PTHREAD_LIBS) + +if SET_SO_VERSION + +EXTRA_libtoxcore_la_DEPENDENCIES = ../so.version + +endif diff --git a/protocols/Tox/libtox/src/toxcore/Messenger.c b/protocols/Tox/libtox/src/toxcore/Messenger.c index 947edef7e1..7c9730bb63 100644 --- a/protocols/Tox/libtox/src/toxcore/Messenger.c +++ b/protocols/Tox/libtox/src/toxcore/Messenger.c @@ -472,10 +472,6 @@ int m_delfriend(Messenger *m, int32_t friendnumber) return -1; } - if (m->friend_connectionstatuschange_internal != nullptr) { - m->friend_connectionstatuschange_internal(m, friendnumber, false, m->friend_connectionstatuschange_internal_userdata); - } - clear_receipts(m, friendnumber); remove_request_received(m->fr, m->friendlist[friendnumber].real_pk); friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, nullptr, @@ -775,31 +771,31 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length) } non_null() -static bool userstatus_from_int(uint8_t status, Userstatus *out) +static bool userstatus_from_int(uint8_t status, Userstatus *out_enum) { switch (status) { case USERSTATUS_NONE: { - *out = USERSTATUS_NONE; + *out_enum = USERSTATUS_NONE; return true; } case USERSTATUS_AWAY: { - *out = USERSTATUS_AWAY; + *out_enum = USERSTATUS_AWAY; return true; } case USERSTATUS_BUSY: { - *out = USERSTATUS_BUSY; + *out_enum = USERSTATUS_BUSY; return true; } case USERSTATUS_INVALID: { - *out = USERSTATUS_INVALID; + *out_enum = USERSTATUS_INVALID; return true; } default: { - *out = USERSTATUS_INVALID; + *out_enum = USERSTATUS_INVALID; return false; } } @@ -1027,13 +1023,6 @@ void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *funct m->core_connection_change = function; } -void m_callback_connectionstatus_internal_av(Messenger *m, m_friend_connectionstatuschange_internal_cb *function, - void *userdata) -{ - m->friend_connectionstatuschange_internal = function; - m->friend_connectionstatuschange_internal_userdata = userdata; -} - non_null(1) nullable(3) static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userdata) { @@ -1081,11 +1070,6 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui m->friendlist[friendnumber].status = status; check_friend_tcp_udp(m, friendnumber, userdata); - - if (m->friend_connectionstatuschange_internal != nullptr) { - m->friend_connectionstatuschange_internal(m, friendnumber, is_online, - m->friend_connectionstatuschange_internal_userdata); - } } } @@ -1855,23 +1839,6 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound, } } -/** @brief Set the callback for msi packets. */ -void m_callback_msi_packet(Messenger *m, m_msi_packet_cb *function, void *userdata) -{ - m->msi_packet = function; - m->msi_packet_userdata = userdata; -} - -/** @brief Send an msi packet. - * - * @retval true on success - * @retval false on failure - */ -bool m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length) -{ - return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length, false); -} - static int m_handle_lossy_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata) { @@ -1881,17 +1848,6 @@ static int m_handle_lossy_packet(void *object, int friendcon_id, const uint8_t * return 1; } - if (data[0] <= PACKET_ID_RANGE_LOSSY_AV_END) { - const RTP_Packet_Handler *const ph = - &m->friendlist[friendcon_id].lossy_rtp_packethandlers[data[0] % PACKET_ID_RANGE_LOSSY_AV_SIZE]; - - if (ph->function != nullptr) { - return ph->function(m, friendcon_id, data, length, ph->object); - } - - return 1; - } - if (m->lossy_packethandler != nullptr) { m->lossy_packethandler(m, friendcon_id, data[0], data, length, userdata); } @@ -1904,38 +1860,6 @@ void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb m->lossy_packethandler = lossy_packethandler; } -int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lossy_rtp_packet_cb *function, - void *object) -{ - if (!m_friend_exists(m, friendnumber)) { - return -1; - } - - if (byte < PACKET_ID_RANGE_LOSSY_AV_START || byte > PACKET_ID_RANGE_LOSSY_AV_END) { - return -1; - } - - m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_ID_RANGE_LOSSY_AV_SIZE].function = function; - m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_ID_RANGE_LOSSY_AV_SIZE].object = object; - return 0; -} - -/** @brief High level function to send custom lossy packets. - * - * TODO(oxij): this name is confusing, because this function sends both av and custom lossy packets. - * Meanwhile, m_handle_lossy_packet routes custom packets to custom_lossy_packet_registerhandler - * as you would expect from its name. - * - * I.e. custom_lossy_packet_registerhandler's "custom lossy packet" and this "custom lossy packet" - * are not the same set of packets. - * - * @retval -1 if friend invalid. - * @retval -2 if length wrong. - * @retval -3 if first byte invalid. - * @retval -4 if friend offline. - * @retval -5 if packet failed to send because of other error. - * @retval 0 on success. - */ int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) { if (!m_friend_exists(m, friendnumber)) { @@ -1946,7 +1870,6 @@ int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const u return -2; } - // TODO(oxij): send_lossy_cryptpacket makes this check already, similarly for other similar places if (data[0] < PACKET_ID_RANGE_LOSSY_START || data[0] > PACKET_ID_RANGE_LOSSY_END) { return -3; } @@ -1974,7 +1897,10 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin } if (packet[0] < PACKET_ID_RANGE_LOSSLESS_CUSTOM_START || packet[0] > PACKET_ID_RANGE_LOSSLESS_CUSTOM_END) { - return -1; + // allow PACKET_ID_MSI packets to be handled by custom packet handler + if (packet[0] != PACKET_ID_MSI) { + return -1; + } } if (m->lossless_packethandler != nullptr) { @@ -2357,20 +2283,6 @@ static int m_handle_packet_file_data(Messenger *m, const int friendcon_id, const } non_null(1, 3) nullable(5) -static int m_handle_packet_msi(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata) -{ - if (data_length == 0) { - return 0; - } - - if (m->msi_packet != nullptr) { - m->msi_packet(m, friendcon_id, data, data_length, m->msi_packet_userdata); - } - - return 0; -} - -non_null(1, 3) nullable(5) static int m_handle_packet_invite_groupchat(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata) { // first two bytes are messenger packet type and group invite type @@ -2443,7 +2355,7 @@ static int m_handle_packet(void *object, int friendcon_id, const uint8_t *data, case PACKET_ID_FILE_DATA: return m_handle_packet_file_data(m, friendcon_id, payload, payload_length, userdata); case PACKET_ID_MSI: - return m_handle_packet_msi(m, friendcon_id, payload, payload_length, userdata); + return handle_custom_lossless_packet(object, friendcon_id, data, length, userdata); case PACKET_ID_INVITE_GROUPCHAT: return m_handle_packet_invite_groupchat(m, friendcon_id, payload, payload_length, userdata); } @@ -2468,14 +2380,12 @@ static void do_friends(Messenger *m, void *userdata) } } - if (m->friendlist[i].status == FRIEND_REQUESTED - || m->friendlist[i].status == FRIEND_CONFIRMED) { /* friend is not online. */ - if (m->friendlist[i].status == FRIEND_REQUESTED) { - /* If we didn't connect to friend after successfully sending him a friend request the request is deemed - * unsuccessful so we set the status back to FRIEND_ADDED and try again. - */ - check_friend_request_timed_out(m, i, temp_time, userdata); - } + if (m->friendlist[i].status == FRIEND_REQUESTED) { + /* If we didn't connect to friend after successfully sending him a friend + * request the request is deemed unsuccessful so we set the status back to + * FRIEND_ADDED and try again. + */ + check_friend_request_timed_out(m, i, temp_time, userdata); } if (m->friendlist[i].status == FRIEND_ONLINE) { /* friend is online. */ diff --git a/protocols/Tox/libtox/src/toxcore/Messenger.h b/protocols/Tox/libtox/src/toxcore/Messenger.h index cace3340b2..998a009f15 100644 --- a/protocols/Tox/libtox/src/toxcore/Messenger.h +++ b/protocols/Tox/libtox/src/toxcore/Messenger.h @@ -200,20 +200,10 @@ typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t friend_number, uint size_t length, void *user_data); typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data, size_t length, void *user_data); -typedef void m_friend_connectionstatuschange_internal_cb(Messenger *m, uint32_t friend_number, - bool is_online, void *user_data); typedef void m_conference_invite_cb(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length, void *user_data); typedef void m_group_invite_cb(const Messenger *m, uint32_t friend_number, const uint8_t *invite_data, size_t length, const uint8_t *group_name, size_t group_name_length, void *user_data); -typedef void m_msi_packet_cb(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, - void *user_data); -typedef int m_lossy_rtp_packet_cb(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, void *object); - -typedef struct RTP_Packet_Handler { - m_lossy_rtp_packet_cb *function; - void *object; -} RTP_Packet_Handler; typedef struct Friend { uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; @@ -243,8 +233,6 @@ typedef struct Friend { uint32_t num_sending_files; struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES]; - RTP_Packet_Handler lossy_rtp_packethandlers[PACKET_ID_RANGE_LOSSY_AV_SIZE]; - struct Receipts *receipts_start; struct Receipts *receipts_end; } Friend; @@ -301,8 +289,6 @@ struct Messenger { m_friend_typing_cb *friend_typingchange; m_friend_read_receipt_cb *read_receipt; m_friend_connection_status_cb *friend_connectionstatuschange; - m_friend_connectionstatuschange_internal_cb *friend_connectionstatuschange_internal; - void *friend_connectionstatuschange_internal_userdata; struct Group_Chats *conferences_object; m_conference_invite_cb *conference_invite; @@ -314,9 +300,6 @@ struct Messenger { m_file_recv_chunk_cb *file_filedata; m_file_chunk_request_cb *file_reqchunk; - m_msi_packet_cb *msi_packet; - void *msi_packet_userdata; - m_friend_lossy_packet_cb *lossy_packethandler; m_friend_lossless_packet_cb *lossless_packethandler; @@ -614,10 +597,6 @@ non_null() void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb * */ non_null() void m_callback_connectionstatus(Messenger *m, m_friend_connection_status_cb *function); -/** Same as previous but for internal A/V core usage only */ -non_null() void m_callback_connectionstatus_internal_av( - Messenger *m, m_friend_connectionstatuschange_internal_cb *function, void *userdata); - /** @brief Set the callback for typing changes. */ non_null() void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *function); @@ -731,29 +710,6 @@ non_null(1) nullable(5) int send_file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, uint16_t length); -/*** A/V related */ - -/** @brief Set the callback for msi packets. */ -non_null(1) nullable(2, 3) -void m_callback_msi_packet(Messenger *m, m_msi_packet_cb *function, void *userdata); - -/** @brief Send an msi packet. - * - * @retval true on success - * @retval false on failure - */ -non_null() -bool m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length); - -/** @brief Set handlers for lossy rtp packets. - * - * @retval -1 on failure. - * @retval 0 on success. - */ -non_null(1) nullable(4, 5) -int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, - m_lossy_rtp_packet_cb *function, void *object); - /*** CUSTOM PACKETS */ /** @brief Set handlers for custom lossy packets. */ @@ -761,13 +717,6 @@ non_null() void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy /** @brief High level function to send custom lossy packets. * - * TODO(oxij): this name is confusing, because this function sends both av and custom lossy packets. - * Meanwhile, m_handle_lossy_packet routes custom packets to custom_lossy_packet_registerhandler - * as you would expect from its name. - * - * I.e. custom_lossy_packet_registerhandler's "custom lossy packet" and this "custom lossy packet" - * are not the same set of packets. - * * @retval -1 if friend invalid. * @retval -2 if length wrong. * @retval -3 if first byte invalid. diff --git a/protocols/Tox/libtox/src/toxcore/announce.c b/protocols/Tox/libtox/src/toxcore/announce.c index b983cb0574..7bda993232 100644 --- a/protocols/Tox/libtox/src/toxcore/announce.c +++ b/protocols/Tox/libtox/src/toxcore/announce.c @@ -579,7 +579,7 @@ static int create_reply(Announcements *announce, const IP_Port *source, const int plain_reply_max_len = (int)reply_max_length - (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE); - if (plain_reply_max_len < sizeof(uint64_t)) { + if (plain_reply_max_len < (int)sizeof(uint64_t)) { return -1; } diff --git a/protocols/Tox/libtox/src/toxcore/events/conference_connected.c b/protocols/Tox/libtox/src/toxcore/events/conference_connected.c index dbd9e4b51a..8aeb17204b 100644 --- a/protocols/Tox/libtox/src/toxcore/events/conference_connected.c +++ b/protocols/Tox/libtox/src/toxcore/events/conference_connected.c @@ -109,7 +109,10 @@ static Tox_Event_Conference_Connected *tox_events_add_conference_connected(Tox_E event.type = TOX_EVENT_CONFERENCE_CONNECTED; event.data.conference_connected = conference_connected; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_conference_connected_free(conference_connected, mem); + return nullptr; + } return conference_connected; } diff --git a/protocols/Tox/libtox/src/toxcore/events/conference_invite.c b/protocols/Tox/libtox/src/toxcore/events/conference_invite.c index fb1f794bf3..c9b8d14bc1 100644 --- a/protocols/Tox/libtox/src/toxcore/events/conference_invite.c +++ b/protocols/Tox/libtox/src/toxcore/events/conference_invite.c @@ -177,7 +177,10 @@ static Tox_Event_Conference_Invite *tox_events_add_conference_invite(Tox_Events event.type = TOX_EVENT_CONFERENCE_INVITE; event.data.conference_invite = conference_invite; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_conference_invite_free(conference_invite, mem); + return nullptr; + } return conference_invite; } diff --git a/protocols/Tox/libtox/src/toxcore/events/conference_message.c b/protocols/Tox/libtox/src/toxcore/events/conference_message.c index 74e1123e01..e509827e45 100644 --- a/protocols/Tox/libtox/src/toxcore/events/conference_message.c +++ b/protocols/Tox/libtox/src/toxcore/events/conference_message.c @@ -193,7 +193,10 @@ static Tox_Event_Conference_Message *tox_events_add_conference_message(Tox_Event event.type = TOX_EVENT_CONFERENCE_MESSAGE; event.data.conference_message = conference_message; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_conference_message_free(conference_message, mem); + return nullptr; + } return conference_message; } diff --git a/protocols/Tox/libtox/src/toxcore/events/conference_peer_list_changed.c b/protocols/Tox/libtox/src/toxcore/events/conference_peer_list_changed.c index 050bfb08f8..f7efd3f806 100644 --- a/protocols/Tox/libtox/src/toxcore/events/conference_peer_list_changed.c +++ b/protocols/Tox/libtox/src/toxcore/events/conference_peer_list_changed.c @@ -109,7 +109,10 @@ static Tox_Event_Conference_Peer_List_Changed *tox_events_add_conference_peer_li event.type = TOX_EVENT_CONFERENCE_PEER_LIST_CHANGED; event.data.conference_peer_list_changed = conference_peer_list_changed; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_conference_peer_list_changed_free(conference_peer_list_changed, mem); + return nullptr; + } return conference_peer_list_changed; } diff --git a/protocols/Tox/libtox/src/toxcore/events/conference_peer_name.c b/protocols/Tox/libtox/src/toxcore/events/conference_peer_name.c index fc6c255791..930065631f 100644 --- a/protocols/Tox/libtox/src/toxcore/events/conference_peer_name.c +++ b/protocols/Tox/libtox/src/toxcore/events/conference_peer_name.c @@ -175,7 +175,10 @@ static Tox_Event_Conference_Peer_Name *tox_events_add_conference_peer_name(Tox_E event.type = TOX_EVENT_CONFERENCE_PEER_NAME; event.data.conference_peer_name = conference_peer_name; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_conference_peer_name_free(conference_peer_name, mem); + return nullptr; + } return conference_peer_name; } diff --git a/protocols/Tox/libtox/src/toxcore/events/conference_title.c b/protocols/Tox/libtox/src/toxcore/events/conference_title.c index d761f51285..d8e269032e 100644 --- a/protocols/Tox/libtox/src/toxcore/events/conference_title.c +++ b/protocols/Tox/libtox/src/toxcore/events/conference_title.c @@ -175,7 +175,10 @@ static Tox_Event_Conference_Title *tox_events_add_conference_title(Tox_Events *e event.type = TOX_EVENT_CONFERENCE_TITLE; event.data.conference_title = conference_title; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_conference_title_free(conference_title, mem); + return nullptr; + } return conference_title; } diff --git a/protocols/Tox/libtox/src/toxcore/events/dht_get_nodes_response.c b/protocols/Tox/libtox/src/toxcore/events/dht_get_nodes_response.c index 6e03b73ea4..f637b9c93a 100644 --- a/protocols/Tox/libtox/src/toxcore/events/dht_get_nodes_response.c +++ b/protocols/Tox/libtox/src/toxcore/events/dht_get_nodes_response.c @@ -158,7 +158,10 @@ static Tox_Event_Dht_Get_Nodes_Response *tox_events_add_dht_get_nodes_response(T event.type = TOX_EVENT_DHT_GET_NODES_RESPONSE; event.data.dht_get_nodes_response = dht_get_nodes_response; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_dht_get_nodes_response_free(dht_get_nodes_response, mem); + return nullptr; + } return dht_get_nodes_response; } diff --git a/protocols/Tox/libtox/src/toxcore/events/file_chunk_request.c b/protocols/Tox/libtox/src/toxcore/events/file_chunk_request.c index 4117ef3c4b..23e5f5bf18 100644 --- a/protocols/Tox/libtox/src/toxcore/events/file_chunk_request.c +++ b/protocols/Tox/libtox/src/toxcore/events/file_chunk_request.c @@ -162,7 +162,10 @@ static Tox_Event_File_Chunk_Request *tox_events_add_file_chunk_request(Tox_Event event.type = TOX_EVENT_FILE_CHUNK_REQUEST; event.data.file_chunk_request = file_chunk_request; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_file_chunk_request_free(file_chunk_request, mem); + return nullptr; + } return file_chunk_request; } diff --git a/protocols/Tox/libtox/src/toxcore/events/file_recv.c b/protocols/Tox/libtox/src/toxcore/events/file_recv.c index 45cec44b0d..389ce59830 100644 --- a/protocols/Tox/libtox/src/toxcore/events/file_recv.c +++ b/protocols/Tox/libtox/src/toxcore/events/file_recv.c @@ -207,7 +207,10 @@ static Tox_Event_File_Recv *tox_events_add_file_recv(Tox_Events *events, const M event.type = TOX_EVENT_FILE_RECV; event.data.file_recv = file_recv; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_file_recv_free(file_recv, mem); + return nullptr; + } return file_recv; } diff --git a/protocols/Tox/libtox/src/toxcore/events/file_recv_chunk.c b/protocols/Tox/libtox/src/toxcore/events/file_recv_chunk.c index 2edf7c5a7b..619011a4af 100644 --- a/protocols/Tox/libtox/src/toxcore/events/file_recv_chunk.c +++ b/protocols/Tox/libtox/src/toxcore/events/file_recv_chunk.c @@ -191,7 +191,10 @@ static Tox_Event_File_Recv_Chunk *tox_events_add_file_recv_chunk(Tox_Events *eve event.type = TOX_EVENT_FILE_RECV_CHUNK; event.data.file_recv_chunk = file_recv_chunk; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_file_recv_chunk_free(file_recv_chunk, mem); + return nullptr; + } return file_recv_chunk; } diff --git a/protocols/Tox/libtox/src/toxcore/events/file_recv_control.c b/protocols/Tox/libtox/src/toxcore/events/file_recv_control.c index 14a34aaf3b..3c575c09a6 100644 --- a/protocols/Tox/libtox/src/toxcore/events/file_recv_control.c +++ b/protocols/Tox/libtox/src/toxcore/events/file_recv_control.c @@ -148,7 +148,10 @@ static Tox_Event_File_Recv_Control *tox_events_add_file_recv_control(Tox_Events event.type = TOX_EVENT_FILE_RECV_CONTROL; event.data.file_recv_control = file_recv_control; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_file_recv_control_free(file_recv_control, mem); + return nullptr; + } return file_recv_control; } diff --git a/protocols/Tox/libtox/src/toxcore/events/friend_connection_status.c b/protocols/Tox/libtox/src/toxcore/events/friend_connection_status.c index 330554b05e..68c48695ad 100644 --- a/protocols/Tox/libtox/src/toxcore/events/friend_connection_status.c +++ b/protocols/Tox/libtox/src/toxcore/events/friend_connection_status.c @@ -132,7 +132,10 @@ static Tox_Event_Friend_Connection_Status *tox_events_add_friend_connection_stat event.type = TOX_EVENT_FRIEND_CONNECTION_STATUS; event.data.friend_connection_status = friend_connection_status; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_friend_connection_status_free(friend_connection_status, mem); + return nullptr; + } return friend_connection_status; } diff --git a/protocols/Tox/libtox/src/toxcore/events/friend_lossless_packet.c b/protocols/Tox/libtox/src/toxcore/events/friend_lossless_packet.c index 17e8fad926..b783e332f0 100644 --- a/protocols/Tox/libtox/src/toxcore/events/friend_lossless_packet.c +++ b/protocols/Tox/libtox/src/toxcore/events/friend_lossless_packet.c @@ -159,7 +159,10 @@ static Tox_Event_Friend_Lossless_Packet *tox_events_add_friend_lossless_packet(T event.type = TOX_EVENT_FRIEND_LOSSLESS_PACKET; event.data.friend_lossless_packet = friend_lossless_packet; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_friend_lossless_packet_free(friend_lossless_packet, mem); + return nullptr; + } return friend_lossless_packet; } diff --git a/protocols/Tox/libtox/src/toxcore/events/friend_lossy_packet.c b/protocols/Tox/libtox/src/toxcore/events/friend_lossy_packet.c index 6b2e9ed2b0..e3a6ad5f59 100644 --- a/protocols/Tox/libtox/src/toxcore/events/friend_lossy_packet.c +++ b/protocols/Tox/libtox/src/toxcore/events/friend_lossy_packet.c @@ -159,7 +159,10 @@ static Tox_Event_Friend_Lossy_Packet *tox_events_add_friend_lossy_packet(Tox_Eve event.type = TOX_EVENT_FRIEND_LOSSY_PACKET; event.data.friend_lossy_packet = friend_lossy_packet; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_friend_lossy_packet_free(friend_lossy_packet, mem); + return nullptr; + } return friend_lossy_packet; } diff --git a/protocols/Tox/libtox/src/toxcore/events/friend_message.c b/protocols/Tox/libtox/src/toxcore/events/friend_message.c index befcc74a24..dfd1daea39 100644 --- a/protocols/Tox/libtox/src/toxcore/events/friend_message.c +++ b/protocols/Tox/libtox/src/toxcore/events/friend_message.c @@ -177,7 +177,10 @@ static Tox_Event_Friend_Message *tox_events_add_friend_message(Tox_Events *event event.type = TOX_EVENT_FRIEND_MESSAGE; event.data.friend_message = friend_message; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_friend_message_free(friend_message, mem); + return nullptr; + } return friend_message; } diff --git a/protocols/Tox/libtox/src/toxcore/events/friend_name.c b/protocols/Tox/libtox/src/toxcore/events/friend_name.c index dfa9b39608..b5a5129724 100644 --- a/protocols/Tox/libtox/src/toxcore/events/friend_name.c +++ b/protocols/Tox/libtox/src/toxcore/events/friend_name.c @@ -159,7 +159,10 @@ static Tox_Event_Friend_Name *tox_events_add_friend_name(Tox_Events *events, con event.type = TOX_EVENT_FRIEND_NAME; event.data.friend_name = friend_name; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_friend_name_free(friend_name, mem); + return nullptr; + } return friend_name; } diff --git a/protocols/Tox/libtox/src/toxcore/events/friend_read_receipt.c b/protocols/Tox/libtox/src/toxcore/events/friend_read_receipt.c index e5f2f9db52..88808b5825 100644 --- a/protocols/Tox/libtox/src/toxcore/events/friend_read_receipt.c +++ b/protocols/Tox/libtox/src/toxcore/events/friend_read_receipt.c @@ -130,7 +130,10 @@ static Tox_Event_Friend_Read_Receipt *tox_events_add_friend_read_receipt(Tox_Eve event.type = TOX_EVENT_FRIEND_READ_RECEIPT; event.data.friend_read_receipt = friend_read_receipt; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_friend_read_receipt_free(friend_read_receipt, mem); + return nullptr; + } return friend_read_receipt; } diff --git a/protocols/Tox/libtox/src/toxcore/events/friend_request.c b/protocols/Tox/libtox/src/toxcore/events/friend_request.c index b492c15147..6cd8ac66c7 100644 --- a/protocols/Tox/libtox/src/toxcore/events/friend_request.c +++ b/protocols/Tox/libtox/src/toxcore/events/friend_request.c @@ -152,7 +152,10 @@ static Tox_Event_Friend_Request *tox_events_add_friend_request(Tox_Events *event event.type = TOX_EVENT_FRIEND_REQUEST; event.data.friend_request = friend_request; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_friend_request_free(friend_request, mem); + return nullptr; + } return friend_request; } diff --git a/protocols/Tox/libtox/src/toxcore/events/friend_status.c b/protocols/Tox/libtox/src/toxcore/events/friend_status.c index 3d7499722b..5af2d451d7 100644 --- a/protocols/Tox/libtox/src/toxcore/events/friend_status.c +++ b/protocols/Tox/libtox/src/toxcore/events/friend_status.c @@ -132,7 +132,10 @@ static Tox_Event_Friend_Status *tox_events_add_friend_status(Tox_Events *events, event.type = TOX_EVENT_FRIEND_STATUS; event.data.friend_status = friend_status; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_friend_status_free(friend_status, mem); + return nullptr; + } return friend_status; } diff --git a/protocols/Tox/libtox/src/toxcore/events/friend_status_message.c b/protocols/Tox/libtox/src/toxcore/events/friend_status_message.c index ad0519911e..178342f292 100644 --- a/protocols/Tox/libtox/src/toxcore/events/friend_status_message.c +++ b/protocols/Tox/libtox/src/toxcore/events/friend_status_message.c @@ -159,7 +159,10 @@ static Tox_Event_Friend_Status_Message *tox_events_add_friend_status_message(Tox event.type = TOX_EVENT_FRIEND_STATUS_MESSAGE; event.data.friend_status_message = friend_status_message; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_friend_status_message_free(friend_status_message, mem); + return nullptr; + } return friend_status_message; } diff --git a/protocols/Tox/libtox/src/toxcore/events/friend_typing.c b/protocols/Tox/libtox/src/toxcore/events/friend_typing.c index 692b07fb88..96c719570f 100644 --- a/protocols/Tox/libtox/src/toxcore/events/friend_typing.c +++ b/protocols/Tox/libtox/src/toxcore/events/friend_typing.c @@ -130,7 +130,10 @@ static Tox_Event_Friend_Typing *tox_events_add_friend_typing(Tox_Events *events, event.type = TOX_EVENT_FRIEND_TYPING; event.data.friend_typing = friend_typing; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_friend_typing_free(friend_typing, mem); + return nullptr; + } return friend_typing; } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_custom_packet.c b/protocols/Tox/libtox/src/toxcore/events/group_custom_packet.c index a82e2c3a6c..eb4d49d594 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_custom_packet.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_custom_packet.c @@ -175,7 +175,10 @@ static Tox_Event_Group_Custom_Packet *tox_events_add_group_custom_packet(Tox_Eve event.type = TOX_EVENT_GROUP_CUSTOM_PACKET; event.data.group_custom_packet = group_custom_packet; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_custom_packet_free(group_custom_packet, mem); + return nullptr; + } return group_custom_packet; } @@ -220,7 +223,7 @@ static Tox_Event_Group_Custom_Packet *tox_event_group_custom_packet_alloc(void * *****************************************************/ void tox_events_handle_group_custom_packet( - Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *data, size_t length, + Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *data, size_t data_length, void *user_data) { Tox_Event_Group_Custom_Packet *group_custom_packet = tox_event_group_custom_packet_alloc(user_data); @@ -231,5 +234,5 @@ void tox_events_handle_group_custom_packet( tox_event_group_custom_packet_set_group_number(group_custom_packet, group_number); tox_event_group_custom_packet_set_peer_id(group_custom_packet, peer_id); - tox_event_group_custom_packet_set_data(group_custom_packet, data, length); + tox_event_group_custom_packet_set_data(group_custom_packet, data, data_length); } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_custom_private_packet.c b/protocols/Tox/libtox/src/toxcore/events/group_custom_private_packet.c index 56282f0fb8..f7c1634120 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_custom_private_packet.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_custom_private_packet.c @@ -175,7 +175,10 @@ static Tox_Event_Group_Custom_Private_Packet *tox_events_add_group_custom_privat event.type = TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET; event.data.group_custom_private_packet = group_custom_private_packet; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_custom_private_packet_free(group_custom_private_packet, mem); + return nullptr; + } return group_custom_private_packet; } @@ -220,7 +223,7 @@ static Tox_Event_Group_Custom_Private_Packet *tox_event_group_custom_private_pac *****************************************************/ void tox_events_handle_group_custom_private_packet( - Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *data, size_t length, + Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *data, size_t data_length, void *user_data) { Tox_Event_Group_Custom_Private_Packet *group_custom_private_packet = tox_event_group_custom_private_packet_alloc(user_data); @@ -231,5 +234,5 @@ void tox_events_handle_group_custom_private_packet( tox_event_group_custom_private_packet_set_group_number(group_custom_private_packet, group_number); tox_event_group_custom_private_packet_set_peer_id(group_custom_private_packet, peer_id); - tox_event_group_custom_private_packet_set_data(group_custom_private_packet, data, length); + tox_event_group_custom_private_packet_set_data(group_custom_private_packet, data, data_length); } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_invite.c b/protocols/Tox/libtox/src/toxcore/events/group_invite.c index 0691dcd1fe..6372eb598c 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_invite.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_invite.c @@ -203,7 +203,10 @@ static Tox_Event_Group_Invite *tox_events_add_group_invite(Tox_Events *events, c event.type = TOX_EVENT_GROUP_INVITE; event.data.group_invite = group_invite; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_invite_free(group_invite, mem); + return nullptr; + } return group_invite; } @@ -248,7 +251,7 @@ static Tox_Event_Group_Invite *tox_event_group_invite_alloc(void *user_data) *****************************************************/ void tox_events_handle_group_invite( - Tox *tox, uint32_t friend_number, const uint8_t *invite_data, size_t length, const uint8_t *group_name, size_t group_name_length, + Tox *tox, uint32_t friend_number, const uint8_t *invite_data, size_t invite_data_length, const uint8_t *group_name, size_t group_name_length, void *user_data) { Tox_Event_Group_Invite *group_invite = tox_event_group_invite_alloc(user_data); @@ -258,6 +261,6 @@ void tox_events_handle_group_invite( } tox_event_group_invite_set_friend_number(group_invite, friend_number); - tox_event_group_invite_set_invite_data(group_invite, invite_data, length); + tox_event_group_invite_set_invite_data(group_invite, invite_data, invite_data_length); tox_event_group_invite_set_group_name(group_invite, group_name, group_name_length); } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_join_fail.c b/protocols/Tox/libtox/src/toxcore/events/group_join_fail.c index b85896858b..7b95454b84 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_join_fail.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_join_fail.c @@ -132,7 +132,10 @@ static Tox_Event_Group_Join_Fail *tox_events_add_group_join_fail(Tox_Events *eve event.type = TOX_EVENT_GROUP_JOIN_FAIL; event.data.group_join_fail = group_join_fail; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_join_fail_free(group_join_fail, mem); + return nullptr; + } return group_join_fail; } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_message.c b/protocols/Tox/libtox/src/toxcore/events/group_message.c index a200f84566..9ed07e43a6 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_message.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_message.c @@ -27,7 +27,7 @@ struct Tox_Event_Group_Message { uint32_t group_number; uint32_t peer_id; - Tox_Message_Type type; + Tox_Message_Type message_type; uint8_t *message; uint32_t message_length; uint32_t message_id; @@ -60,16 +60,16 @@ uint32_t tox_event_group_message_get_peer_id(const Tox_Event_Group_Message *grou } non_null() -static void tox_event_group_message_set_type(Tox_Event_Group_Message *group_message, - Tox_Message_Type type) +static void tox_event_group_message_set_message_type(Tox_Event_Group_Message *group_message, + Tox_Message_Type message_type) { assert(group_message != nullptr); - group_message->type = type; + group_message->message_type = message_type; } -Tox_Message_Type tox_event_group_message_get_type(const Tox_Event_Group_Message *group_message) +Tox_Message_Type tox_event_group_message_get_message_type(const Tox_Event_Group_Message *group_message) { assert(group_message != nullptr); - return group_message->type; + return group_message->message_type; } non_null(1) nullable(2) @@ -143,7 +143,7 @@ bool tox_event_group_message_pack( return bin_pack_array(bp, 5) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_id) - && tox_message_type_pack(event->type, bp) + && tox_message_type_pack(event->message_type, bp) && bin_pack_bin(bp, event->message, event->message_length) && bin_pack_u32(bp, event->message_id); } @@ -159,7 +159,7 @@ static bool tox_event_group_message_unpack_into( return bin_unpack_u32(bu, &event->group_number) && bin_unpack_u32(bu, &event->peer_id) - && tox_message_type_unpack(&event->type, bu) + && tox_message_type_unpack(&event->message_type, bu) && bin_unpack_bin(bu, &event->message, &event->message_length) && bin_unpack_u32(bu, &event->message_id); } @@ -209,7 +209,10 @@ static Tox_Event_Group_Message *tox_events_add_group_message(Tox_Events *events, event.type = TOX_EVENT_GROUP_MESSAGE; event.data.group_message = group_message; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_message_free(group_message, mem); + return nullptr; + } return group_message; } @@ -254,7 +257,7 @@ static Tox_Event_Group_Message *tox_event_group_message_alloc(void *user_data) *****************************************************/ void tox_events_handle_group_message( - Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type type, const uint8_t *message, size_t length, uint32_t message_id, + Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type message_type, const uint8_t *message, size_t message_length, uint32_t message_id, void *user_data) { Tox_Event_Group_Message *group_message = tox_event_group_message_alloc(user_data); @@ -265,7 +268,7 @@ void tox_events_handle_group_message( tox_event_group_message_set_group_number(group_message, group_number); tox_event_group_message_set_peer_id(group_message, peer_id); - tox_event_group_message_set_type(group_message, type); - tox_event_group_message_set_message(group_message, message, length); + tox_event_group_message_set_message_type(group_message, message_type); + tox_event_group_message_set_message(group_message, message, message_length); tox_event_group_message_set_message_id(group_message, message_id); } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_moderation.c b/protocols/Tox/libtox/src/toxcore/events/group_moderation.c index ba510d5b2a..eb8d3ba41e 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_moderation.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_moderation.c @@ -164,7 +164,10 @@ static Tox_Event_Group_Moderation *tox_events_add_group_moderation(Tox_Events *e event.type = TOX_EVENT_GROUP_MODERATION; event.data.group_moderation = group_moderation; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_moderation_free(group_moderation, mem); + return nullptr; + } return group_moderation; } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_password.c b/protocols/Tox/libtox/src/toxcore/events/group_password.c index ad6e86b9d3..14bda0f766 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_password.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_password.c @@ -159,7 +159,10 @@ static Tox_Event_Group_Password *tox_events_add_group_password(Tox_Events *event event.type = TOX_EVENT_GROUP_PASSWORD; event.data.group_password = group_password; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_password_free(group_password, mem); + return nullptr; + } return group_password; } @@ -204,7 +207,7 @@ static Tox_Event_Group_Password *tox_event_group_password_alloc(void *user_data) *****************************************************/ void tox_events_handle_group_password( - Tox *tox, uint32_t group_number, const uint8_t *password, size_t length, + Tox *tox, uint32_t group_number, const uint8_t *password, size_t password_length, void *user_data) { Tox_Event_Group_Password *group_password = tox_event_group_password_alloc(user_data); @@ -214,5 +217,5 @@ void tox_events_handle_group_password( } tox_event_group_password_set_group_number(group_password, group_number); - tox_event_group_password_set_password(group_password, password, length); + tox_event_group_password_set_password(group_password, password, password_length); } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_peer_exit.c b/protocols/Tox/libtox/src/toxcore/events/group_peer_exit.c index 16d1eba7a6..405b4b6c16 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_peer_exit.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_peer_exit.c @@ -237,7 +237,10 @@ static Tox_Event_Group_Peer_Exit *tox_events_add_group_peer_exit(Tox_Events *eve event.type = TOX_EVENT_GROUP_PEER_EXIT; event.data.group_peer_exit = group_peer_exit; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_peer_exit_free(group_peer_exit, mem); + return nullptr; + } return group_peer_exit; } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_peer_join.c b/protocols/Tox/libtox/src/toxcore/events/group_peer_join.c index af0d006e87..8dc34befee 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_peer_join.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_peer_join.c @@ -130,7 +130,10 @@ static Tox_Event_Group_Peer_Join *tox_events_add_group_peer_join(Tox_Events *eve event.type = TOX_EVENT_GROUP_PEER_JOIN; event.data.group_peer_join = group_peer_join; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_peer_join_free(group_peer_join, mem); + return nullptr; + } return group_peer_join; } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_peer_limit.c b/protocols/Tox/libtox/src/toxcore/events/group_peer_limit.c index 5e2e23558c..157827c560 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_peer_limit.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_peer_limit.c @@ -130,7 +130,10 @@ static Tox_Event_Group_Peer_Limit *tox_events_add_group_peer_limit(Tox_Events *e event.type = TOX_EVENT_GROUP_PEER_LIMIT; event.data.group_peer_limit = group_peer_limit; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_peer_limit_free(group_peer_limit, mem); + return nullptr; + } return group_peer_limit; } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_peer_name.c b/protocols/Tox/libtox/src/toxcore/events/group_peer_name.c index f8273e94b4..063a6ab9a3 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_peer_name.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_peer_name.c @@ -175,7 +175,10 @@ static Tox_Event_Group_Peer_Name *tox_events_add_group_peer_name(Tox_Events *eve event.type = TOX_EVENT_GROUP_PEER_NAME; event.data.group_peer_name = group_peer_name; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_peer_name_free(group_peer_name, mem); + return nullptr; + } return group_peer_name; } @@ -220,7 +223,7 @@ static Tox_Event_Group_Peer_Name *tox_event_group_peer_name_alloc(void *user_dat *****************************************************/ void tox_events_handle_group_peer_name( - Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *name, size_t length, + Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *name, size_t name_length, void *user_data) { Tox_Event_Group_Peer_Name *group_peer_name = tox_event_group_peer_name_alloc(user_data); @@ -231,5 +234,5 @@ void tox_events_handle_group_peer_name( tox_event_group_peer_name_set_group_number(group_peer_name, group_number); tox_event_group_peer_name_set_peer_id(group_peer_name, peer_id); - tox_event_group_peer_name_set_name(group_peer_name, name, length); + tox_event_group_peer_name_set_name(group_peer_name, name, name_length); } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_peer_status.c b/protocols/Tox/libtox/src/toxcore/events/group_peer_status.c index 4165d90ec2..d646caec8c 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_peer_status.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_peer_status.c @@ -148,7 +148,10 @@ static Tox_Event_Group_Peer_Status *tox_events_add_group_peer_status(Tox_Events event.type = TOX_EVENT_GROUP_PEER_STATUS; event.data.group_peer_status = group_peer_status; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_peer_status_free(group_peer_status, mem); + return nullptr; + } return group_peer_status; } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_privacy_state.c b/protocols/Tox/libtox/src/toxcore/events/group_privacy_state.c index 1c683c255c..3fa081c20a 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_privacy_state.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_privacy_state.c @@ -132,7 +132,10 @@ static Tox_Event_Group_Privacy_State *tox_events_add_group_privacy_state(Tox_Eve event.type = TOX_EVENT_GROUP_PRIVACY_STATE; event.data.group_privacy_state = group_privacy_state; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_privacy_state_free(group_privacy_state, mem); + return nullptr; + } return group_privacy_state; } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_private_message.c b/protocols/Tox/libtox/src/toxcore/events/group_private_message.c index 648f707880..9b7f95aa3d 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_private_message.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_private_message.c @@ -27,9 +27,10 @@ struct Tox_Event_Group_Private_Message { uint32_t group_number; uint32_t peer_id; - Tox_Message_Type type; + Tox_Message_Type message_type; uint8_t *message; uint32_t message_length; + uint32_t message_id; }; non_null() @@ -59,16 +60,16 @@ uint32_t tox_event_group_private_message_get_peer_id(const Tox_Event_Group_Priva } non_null() -static void tox_event_group_private_message_set_type(Tox_Event_Group_Private_Message *group_private_message, - Tox_Message_Type type) +static void tox_event_group_private_message_set_message_type(Tox_Event_Group_Private_Message *group_private_message, + Tox_Message_Type message_type) { assert(group_private_message != nullptr); - group_private_message->type = type; + group_private_message->message_type = message_type; } -Tox_Message_Type tox_event_group_private_message_get_type(const Tox_Event_Group_Private_Message *group_private_message) +Tox_Message_Type tox_event_group_private_message_get_message_type(const Tox_Event_Group_Private_Message *group_private_message) { assert(group_private_message != nullptr); - return group_private_message->type; + return group_private_message->message_type; } non_null(1) nullable(2) @@ -111,6 +112,19 @@ const uint8_t *tox_event_group_private_message_get_message(const Tox_Event_Group } non_null() +static void tox_event_group_private_message_set_message_id(Tox_Event_Group_Private_Message *group_private_message, + uint32_t message_id) +{ + assert(group_private_message != nullptr); + group_private_message->message_id = message_id; +} +uint32_t tox_event_group_private_message_get_message_id(const Tox_Event_Group_Private_Message *group_private_message) +{ + assert(group_private_message != nullptr); + return group_private_message->message_id; +} + +non_null() static void tox_event_group_private_message_construct(Tox_Event_Group_Private_Message *group_private_message) { *group_private_message = (Tox_Event_Group_Private_Message) { @@ -126,11 +140,12 @@ static void tox_event_group_private_message_destruct(Tox_Event_Group_Private_Mes bool tox_event_group_private_message_pack( const Tox_Event_Group_Private_Message *event, Bin_Pack *bp) { - return bin_pack_array(bp, 4) + return bin_pack_array(bp, 5) && bin_pack_u32(bp, event->group_number) && bin_pack_u32(bp, event->peer_id) - && tox_message_type_pack(event->type, bp) - && bin_pack_bin(bp, event->message, event->message_length); + && tox_message_type_pack(event->message_type, bp) + && bin_pack_bin(bp, event->message, event->message_length) + && bin_pack_u32(bp, event->message_id); } non_null() @@ -138,14 +153,15 @@ static bool tox_event_group_private_message_unpack_into( Tox_Event_Group_Private_Message *event, Bin_Unpack *bu) { assert(event != nullptr); - if (!bin_unpack_array_fixed(bu, 4, nullptr)) { + if (!bin_unpack_array_fixed(bu, 5, nullptr)) { return false; } return bin_unpack_u32(bu, &event->group_number) && bin_unpack_u32(bu, &event->peer_id) - && tox_message_type_unpack(&event->type, bu) - && bin_unpack_bin(bu, &event->message, &event->message_length); + && tox_message_type_unpack(&event->message_type, bu) + && bin_unpack_bin(bu, &event->message, &event->message_length) + && bin_unpack_u32(bu, &event->message_id); } /***************************************************** @@ -193,7 +209,10 @@ static Tox_Event_Group_Private_Message *tox_events_add_group_private_message(Tox event.type = TOX_EVENT_GROUP_PRIVATE_MESSAGE; event.data.group_private_message = group_private_message; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_private_message_free(group_private_message, mem); + return nullptr; + } return group_private_message; } @@ -238,7 +257,7 @@ static Tox_Event_Group_Private_Message *tox_event_group_private_message_alloc(vo *****************************************************/ void tox_events_handle_group_private_message( - Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type type, const uint8_t *message, size_t length, + Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type message_type, const uint8_t *message, size_t message_length, uint32_t message_id, void *user_data) { Tox_Event_Group_Private_Message *group_private_message = tox_event_group_private_message_alloc(user_data); @@ -249,6 +268,7 @@ void tox_events_handle_group_private_message( tox_event_group_private_message_set_group_number(group_private_message, group_number); tox_event_group_private_message_set_peer_id(group_private_message, peer_id); - tox_event_group_private_message_set_type(group_private_message, type); - tox_event_group_private_message_set_message(group_private_message, message, length); + tox_event_group_private_message_set_message_type(group_private_message, message_type); + tox_event_group_private_message_set_message(group_private_message, message, message_length); + tox_event_group_private_message_set_message_id(group_private_message, message_id); } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_self_join.c b/protocols/Tox/libtox/src/toxcore/events/group_self_join.c index 0745e975f8..6cc3080aa6 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_self_join.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_self_join.c @@ -109,7 +109,10 @@ static Tox_Event_Group_Self_Join *tox_events_add_group_self_join(Tox_Events *eve event.type = TOX_EVENT_GROUP_SELF_JOIN; event.data.group_self_join = group_self_join; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_self_join_free(group_self_join, mem); + return nullptr; + } return group_self_join; } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_topic.c b/protocols/Tox/libtox/src/toxcore/events/group_topic.c index 23cdd5d354..7588d43f7f 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_topic.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_topic.c @@ -175,7 +175,10 @@ static Tox_Event_Group_Topic *tox_events_add_group_topic(Tox_Events *events, con event.type = TOX_EVENT_GROUP_TOPIC; event.data.group_topic = group_topic; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_topic_free(group_topic, mem); + return nullptr; + } return group_topic; } @@ -220,7 +223,7 @@ static Tox_Event_Group_Topic *tox_event_group_topic_alloc(void *user_data) *****************************************************/ void tox_events_handle_group_topic( - Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *topic, size_t length, + Tox *tox, uint32_t group_number, uint32_t peer_id, const uint8_t *topic, size_t topic_length, void *user_data) { Tox_Event_Group_Topic *group_topic = tox_event_group_topic_alloc(user_data); @@ -231,5 +234,5 @@ void tox_events_handle_group_topic( tox_event_group_topic_set_group_number(group_topic, group_number); tox_event_group_topic_set_peer_id(group_topic, peer_id); - tox_event_group_topic_set_topic(group_topic, topic, length); + tox_event_group_topic_set_topic(group_topic, topic, topic_length); } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_topic_lock.c b/protocols/Tox/libtox/src/toxcore/events/group_topic_lock.c index 36fb49393a..431ff38159 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_topic_lock.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_topic_lock.c @@ -132,7 +132,10 @@ static Tox_Event_Group_Topic_Lock *tox_events_add_group_topic_lock(Tox_Events *e event.type = TOX_EVENT_GROUP_TOPIC_LOCK; event.data.group_topic_lock = group_topic_lock; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_topic_lock_free(group_topic_lock, mem); + return nullptr; + } return group_topic_lock; } diff --git a/protocols/Tox/libtox/src/toxcore/events/group_voice_state.c b/protocols/Tox/libtox/src/toxcore/events/group_voice_state.c index fba0300389..d9c592b882 100644 --- a/protocols/Tox/libtox/src/toxcore/events/group_voice_state.c +++ b/protocols/Tox/libtox/src/toxcore/events/group_voice_state.c @@ -132,7 +132,10 @@ static Tox_Event_Group_Voice_State *tox_events_add_group_voice_state(Tox_Events event.type = TOX_EVENT_GROUP_VOICE_STATE; event.data.group_voice_state = group_voice_state; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_group_voice_state_free(group_voice_state, mem); + return nullptr; + } return group_voice_state; } diff --git a/protocols/Tox/libtox/src/toxcore/events/self_connection_status.c b/protocols/Tox/libtox/src/toxcore/events/self_connection_status.c index 8d8bc803ea..b79d70b408 100644 --- a/protocols/Tox/libtox/src/toxcore/events/self_connection_status.c +++ b/protocols/Tox/libtox/src/toxcore/events/self_connection_status.c @@ -111,7 +111,10 @@ static Tox_Event_Self_Connection_Status *tox_events_add_self_connection_status(T event.type = TOX_EVENT_SELF_CONNECTION_STATUS; event.data.self_connection_status = self_connection_status; - tox_events_add(events, &event); + if (!tox_events_add(events, &event)) { + tox_event_self_connection_status_free(self_connection_status, mem); + return nullptr; + } return self_connection_status; } diff --git a/protocols/Tox/libtox/src/toxcore/friend_connection.c b/protocols/Tox/libtox/src/toxcore/friend_connection.c index 33bfa40d34..f017b08888 100644 --- a/protocols/Tox/libtox/src/toxcore/friend_connection.c +++ b/protocols/Tox/libtox/src/toxcore/friend_connection.c @@ -1032,6 +1032,11 @@ void kill_friend_connections(Friend_Connections *fr_c) kill_friend_connection(fr_c, i); } + // there might be allocated NONE connections + if (fr_c->conns != nullptr) { + free(fr_c->conns); + } + lan_discovery_kill(fr_c->broadcast); free(fr_c); } diff --git a/protocols/Tox/libtox/src/toxcore/group.c b/protocols/Tox/libtox/src/toxcore/group.c index 14e61e6ffc..3d96b962de 100644 --- a/protocols/Tox/libtox/src/toxcore/group.c +++ b/protocols/Tox/libtox/src/toxcore/group.c @@ -2520,7 +2520,7 @@ static int handle_send_peers(Group_Chats *g_c, uint32_t groupnumber, const uint8 non_null(1, 3) nullable(6) static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, - int connection_index, void *userdata) + uint32_t connection_index, void *userdata) { if (length == 0) { return; @@ -2832,7 +2832,7 @@ static bool check_message_info(uint32_t message_number, uint8_t message_id, Grou non_null(1, 3) nullable(6) static void handle_message_packet_group(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length, - int connection_index, void *userdata) + uint32_t connection_index, void *userdata) { if (length < sizeof(uint16_t) + sizeof(uint32_t) + 1) { return; diff --git a/protocols/Tox/libtox/src/toxcore/group_chats.c b/protocols/Tox/libtox/src/toxcore/group_chats.c index 96f647cc2e..2d64ae60ec 100644 --- a/protocols/Tox/libtox/src/toxcore/group_chats.c +++ b/protocols/Tox/libtox/src/toxcore/group_chats.c @@ -961,7 +961,7 @@ non_null() static bool broadcast_gc_mod_list(const GC_Chat *chat); non_null() static bool broadcast_gc_shared_state(const GC_Chat *chat); non_null() static bool update_gc_sanctions_list(GC_Chat *chat, const uint8_t *public_sig_key); non_null() static bool update_gc_topic(GC_Chat *chat, const uint8_t *public_sig_key); -non_null() static bool send_gc_set_observer(const GC_Chat *chat, const uint8_t *target_ext_pk, +non_null() static bool send_gc_set_observer(const GC_Chat *chat, const Extended_Public_Key *target_ext_pk, const uint8_t *sanction_data, uint16_t length, bool add_obs); /** Returns true if peer designated by `peer_number` is in the sanctions list as an observer. */ @@ -1119,7 +1119,7 @@ static bool prune_gc_mod_list(GC_Chat *chat) non_null() static bool prune_gc_sanctions_list_inner( GC_Chat *chat, const Mod_Sanction *sanction, - const uint8_t target_ext_pk[ENC_PUBLIC_KEY_SIZE + SIG_PUBLIC_KEY_SIZE]) + const Extended_Public_Key *target_ext_pk) { if (!sanctions_list_remove_observer(&chat->moderation, sanction->target_public_enc_key, nullptr)) { LOGGER_WARNING(chat->log, "Failed to remove entry from observer list"); @@ -1159,10 +1159,10 @@ static bool prune_gc_sanctions_list(GC_Chat *chat) if (peer_number == -1) { const Mod_Sanction *sanction = &chat->moderation.sanctions[i]; - uint8_t target_ext_pk[ENC_PUBLIC_KEY_SIZE + SIG_PUBLIC_KEY_SIZE]; - memcpy(target_ext_pk, sanction->target_public_enc_key, ENC_PUBLIC_KEY_SIZE); - memcpy(target_ext_pk + ENC_PUBLIC_KEY_SIZE, sanction->setter_public_sig_key, SIG_PUBLIC_KEY_SIZE); - return prune_gc_sanctions_list_inner(chat, sanction, target_ext_pk); + Extended_Public_Key target_ext_pk; + memcpy(target_ext_pk.enc, sanction->target_public_enc_key, ENC_PUBLIC_KEY_SIZE); + memcpy(target_ext_pk.sig, sanction->setter_public_sig_key, SIG_PUBLIC_KEY_SIZE); + return prune_gc_sanctions_list_inner(chat, sanction, &target_ext_pk); } } @@ -4457,10 +4457,10 @@ static int handle_gc_set_observer(const GC_Session *c, GC_Chat *chat, uint32_t p * Returns true on success. */ non_null() -static bool send_gc_set_observer(const GC_Chat *chat, const uint8_t *target_ext_pk, const uint8_t *sanction_data, - uint16_t length, bool add_obs) +static bool send_gc_set_observer(const GC_Chat *chat, const Extended_Public_Key *target_ext_pk, + const uint8_t *sanction_data, uint16_t length, bool add_obs) { - const uint16_t packet_len = 1 + EXT_PUBLIC_KEY_SIZE + length; + const uint16_t packet_len = 1 + ENC_PUBLIC_KEY_SIZE + SIG_PUBLIC_KEY_SIZE + length; uint8_t *packet = (uint8_t *)malloc(packet_len); if (packet == nullptr) { @@ -4469,8 +4469,9 @@ static bool send_gc_set_observer(const GC_Chat *chat, const uint8_t *target_ext_ net_pack_bool(&packet[0], add_obs); - memcpy(packet + 1, target_ext_pk, EXT_PUBLIC_KEY_SIZE); - memcpy(packet + 1 + EXT_PUBLIC_KEY_SIZE, sanction_data, length); + memcpy(packet + 1, target_ext_pk->enc, ENC_PUBLIC_KEY_SIZE); + memcpy(packet + 1 + ENC_PUBLIC_KEY_SIZE, target_ext_pk->sig, SIG_PUBLIC_KEY_SIZE); + memcpy(packet + 1 + ENC_PUBLIC_KEY_SIZE + SIG_PUBLIC_KEY_SIZE, sanction_data, length); if (!send_gc_broadcast_message(chat, packet, packet_len, GM_SET_OBSERVER)) { free(packet); @@ -4557,7 +4558,7 @@ static bool mod_gc_set_observer(GC_Chat *chat, uint32_t peer_number, bool add_ob update_gc_peer_roles(chat); - return send_gc_set_observer(chat, gconn->addr.public_key.enc, sanction_data, length, add_obs); + return send_gc_set_observer(chat, &gconn->addr.public_key, sanction_data, length, add_obs); } /** @brief Sets the role of `peer_number` to `new_role`. If necessary this function will first @@ -4910,11 +4911,12 @@ int gc_send_message(const GC_Chat *chat, const uint8_t *message, uint16_t length return -5; } + free(message_raw); + if (message_id != nullptr) { *message_id = pseudo_msg_id; } - free(message_raw); return 0; } @@ -4954,7 +4956,7 @@ static int handle_gc_message(const GC_Session *c, const GC_Chat *chat, const GC_ } int gc_send_private_message(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t type, const uint8_t *message, - uint16_t length) + uint16_t length, uint32_t *message_id) { if (length > MAX_GC_MESSAGE_SIZE) { return -1; @@ -4980,23 +4982,28 @@ int gc_send_private_message(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t typ return -5; } - uint8_t *message_with_type = (uint8_t *)malloc(length + 1); + const uint16_t raw_length = 1 + length + GC_MESSAGE_PSEUDO_ID_SIZE; + uint8_t *message_with_type = (uint8_t *)malloc(raw_length); if (message_with_type == nullptr) { return -6; } message_with_type[0] = type; - memcpy(message_with_type + 1, message, length); - uint8_t *packet = (uint8_t *)malloc(length + 1 + GC_BROADCAST_ENC_HEADER_SIZE); + const uint32_t pseudo_msg_id = random_u32(chat->rng); + net_pack_u32(message_with_type + 1, pseudo_msg_id); + + memcpy(message_with_type + 1 + GC_MESSAGE_PSEUDO_ID_SIZE, message, length); + + uint8_t *packet = (uint8_t *)malloc(raw_length + GC_BROADCAST_ENC_HEADER_SIZE); if (packet == nullptr) { free(message_with_type); return -6; } - const uint16_t packet_len = make_gc_broadcast_header(message_with_type, length + 1, packet, GM_PRIVATE_MESSAGE); + const uint16_t packet_len = make_gc_broadcast_header(message_with_type, raw_length, packet, GM_PRIVATE_MESSAGE); free(message_with_type); @@ -5007,6 +5014,10 @@ int gc_send_private_message(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t typ free(packet); + if (message_id != nullptr) { + *message_id = pseudo_msg_id; + } + return 0; } @@ -5019,7 +5030,7 @@ non_null(1, 2, 3, 4) nullable(6) static int handle_gc_private_message(const GC_Session *c, const GC_Chat *chat, const GC_Peer *peer, const uint8_t *data, uint16_t length, void *userdata) { - if (data == nullptr || length > MAX_GC_MESSAGE_SIZE || length <= 1) { + if (data == nullptr || length > MAX_GC_MESSAGE_SIZE || length <= 1 + GC_MESSAGE_PSEUDO_ID_SIZE) { return -1; } @@ -5034,8 +5045,13 @@ static int handle_gc_private_message(const GC_Session *c, const GC_Chat *chat, c return 0; } + uint32_t message_id; + net_unpack_u32(data + 1, &message_id); + if (c->private_message != nullptr) { - c->private_message(c->messenger, chat->group_number, peer->peer_id, message_type, data + 1, length - 1, userdata); + c->private_message(c->messenger, chat->group_number, peer->peer_id, message_type, + data + 1 + GC_MESSAGE_PSEUDO_ID_SIZE, length - 1 - GC_MESSAGE_PSEUDO_ID_SIZE, + message_id, userdata); } return 0; @@ -5066,10 +5082,6 @@ int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, GC_Peer_Id return -3; } - if (gc_get_self_role(chat) >= GR_OBSERVER) { - return -4; - } - bool ret; if (lossless) { @@ -5078,7 +5090,7 @@ int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, GC_Peer_Id ret = send_lossy_group_packet(chat, gconn, message, length, GP_CUSTOM_PRIVATE_PACKET); } - return ret ? 0 : -5; + return ret ? 0 : -4; } /** @brief Handles a custom private packet. @@ -5098,10 +5110,6 @@ static int handle_gc_custom_private_packet(const GC_Session *c, const GC_Chat *c return -1; } - if (peer->ignore || peer->role >= GR_OBSERVER) { - return 0; - } - if (c->custom_private_packet != nullptr) { c->custom_private_packet(c->messenger, chat->group_number, peer->peer_id, data, length, userdata); } @@ -5119,10 +5127,6 @@ int gc_send_custom_packet(const GC_Chat *chat, bool lossless, const uint8_t *dat return -2; } - if (gc_get_self_role(chat) >= GR_OBSERVER) { - return -3; - } - bool success; if (lossless) { @@ -5131,7 +5135,7 @@ int gc_send_custom_packet(const GC_Chat *chat, bool lossless, const uint8_t *dat success = send_gc_lossy_packet_all_peers(chat, data, length, GP_CUSTOM_PACKET); } - return success ? 0 : -4; + return success ? 0 : -3; } /** @brief Handles a custom packet. @@ -5151,10 +5155,6 @@ static int handle_gc_custom_packet(const GC_Session *c, const GC_Chat *chat, con return -1; } - if (peer->ignore || peer->role >= GR_OBSERVER) { - return 0; - } - if (c->custom_packet != nullptr) { c->custom_packet(c->messenger, chat->group_number, peer->peer_id, data, length, userdata); } @@ -8353,7 +8353,7 @@ bool gc_group_is_valid(const GC_Chat *chat) /** Return true if `group_number` designates an active group in session `c`. */ static bool group_number_valid(const GC_Session *c, int group_number) { - if (group_number < 0 || group_number >= c->chats_index) { + if (group_number < 0 || (uint32_t)group_number >= c->chats_index) { return false; } diff --git a/protocols/Tox/libtox/src/toxcore/group_chats.h b/protocols/Tox/libtox/src/toxcore/group_chats.h index 32a7323dc4..d22ce400e6 100644 --- a/protocols/Tox/libtox/src/toxcore/group_chats.h +++ b/protocols/Tox/libtox/src/toxcore/group_chats.h @@ -181,9 +181,9 @@ int gc_send_message(const GC_Chat *chat, const uint8_t *message, uint16_t length * Returns -5 if the sender has the observer role. * Returns -6 if the packet fails to send. */ -non_null() +non_null(1, 4) nullable(6) int gc_send_private_message(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t type, const uint8_t *message, - uint16_t length); + uint16_t length, uint32_t *message_id); /** @brief Sends a custom packet to the group. If lossless is true, the packet will be lossless. * @@ -192,8 +192,7 @@ int gc_send_private_message(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t typ * Returns 0 on success. * Returns -1 if the message is too long. * Returns -2 if the message pointer is NULL or length is zero. - * Returns -3 if the sender has the observer role. - * Returns -4 if the packet did not successfully send to any peer. + * Returns -3 if the packet did not successfully send to any peer. */ non_null() int gc_send_custom_packet(const GC_Chat *chat, bool lossless, const uint8_t *data, uint16_t length); @@ -206,8 +205,7 @@ int gc_send_custom_packet(const GC_Chat *chat, bool lossless, const uint8_t *dat * @retval -1 if the message is too long. * @retval -2 if the message pointer is NULL or length is zero. * @retval -3 if the supplied peer_id does not designate a valid peer. - * @retval -4 if the sender has the observer role. - * @retval -5 if the packet fails to send. + * @retval -4 if the packet fails to send. */ non_null() int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, GC_Peer_Id peer_id, const uint8_t *message, diff --git a/protocols/Tox/libtox/src/toxcore/group_common.h b/protocols/Tox/libtox/src/toxcore/group_common.h index bb1e6f9a64..daa8fe17c8 100644 --- a/protocols/Tox/libtox/src/toxcore/group_common.h +++ b/protocols/Tox/libtox/src/toxcore/group_common.h @@ -348,7 +348,7 @@ typedef struct Messenger Messenger; typedef void gc_message_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, unsigned int type, const uint8_t *message, size_t length, uint32_t message_id, void *user_data); typedef void gc_private_message_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, unsigned int type, - const uint8_t *message, size_t length, void *user_data); + const uint8_t *message, size_t length, uint32_t message_id, void *user_data); typedef void gc_custom_packet_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, const uint8_t *data, size_t length, void *user_data); typedef void gc_custom_private_packet_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, diff --git a/protocols/Tox/libtox/src/toxcore/group_pack.c b/protocols/Tox/libtox/src/toxcore/group_pack.c index e3af82c67a..c20d6a1213 100644 --- a/protocols/Tox/libtox/src/toxcore/group_pack.c +++ b/protocols/Tox/libtox/src/toxcore/group_pack.c @@ -26,46 +26,46 @@ #include "network.h" #include "util.h" -bool group_privacy_state_from_int(uint8_t value, Group_Privacy_State *out) +bool group_privacy_state_from_int(uint8_t value, Group_Privacy_State *out_enum) { switch (value) { case GI_PUBLIC: { - *out = GI_PUBLIC; + *out_enum = GI_PUBLIC; return true; } case GI_PRIVATE: { - *out = GI_PRIVATE; + *out_enum = GI_PRIVATE; return true; } default: { - *out = GI_PUBLIC; + *out_enum = GI_PUBLIC; return false; } } } -bool group_voice_state_from_int(uint8_t value, Group_Voice_State *out) +bool group_voice_state_from_int(uint8_t value, Group_Voice_State *out_enum) { switch (value) { case GV_ALL: { - *out = GV_ALL; + *out_enum = GV_ALL; return true; } case GV_MODS: { - *out = GV_MODS; + *out_enum = GV_MODS; return true; } case GV_FOUNDER: { - *out = GV_FOUNDER; + *out_enum = GV_FOUNDER; return true; } default: { - *out = GV_ALL; + *out_enum = GV_ALL; return false; } } diff --git a/protocols/Tox/libtox/src/toxcore/group_pack.h b/protocols/Tox/libtox/src/toxcore/group_pack.h index 03252fb86d..4c999132db 100644 --- a/protocols/Tox/libtox/src/toxcore/group_pack.h +++ b/protocols/Tox/libtox/src/toxcore/group_pack.h @@ -34,8 +34,8 @@ non_null() bool gc_load_unpack_group(GC_Chat *chat, Bin_Unpack *bu); non_null() -bool group_privacy_state_from_int(uint8_t value, Group_Privacy_State *out); +bool group_privacy_state_from_int(uint8_t value, Group_Privacy_State *out_enum); non_null() -bool group_voice_state_from_int(uint8_t value, Group_Voice_State *out); +bool group_voice_state_from_int(uint8_t value, Group_Voice_State *out_enum); #endif /* C_TOXCORE_TOXCORE_GROUP_PACK_H */ diff --git a/protocols/Tox/libtox/src/toxcore/net_crypto.c b/protocols/Tox/libtox/src/toxcore/net_crypto.c index 1680b078b7..5aafe8a8a9 100644 --- a/protocols/Tox/libtox/src/toxcore/net_crypto.c +++ b/protocols/Tox/libtox/src/toxcore/net_crypto.c @@ -122,9 +122,6 @@ typedef struct Crypto_Connection { bool maximum_speed_reached; - /* Must be a pointer, because the struct is moved in memory */ - pthread_mutex_t *mutex; - dht_pk_cb *dht_pk_callback; void *dht_pk_callback_object; uint32_t dht_pk_callback_number; @@ -143,10 +140,6 @@ struct Net_Crypto { TCP_Connections *tcp_c; Crypto_Connection *crypto_connections; - pthread_mutex_t tcp_mutex; - - pthread_mutex_t connections_mutex; - unsigned int connection_use_counter; uint32_t crypto_connections_length; /* Length of connections array. */ @@ -691,7 +684,6 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t bool direct_send_attempt = false; - pthread_mutex_lock(conn->mutex); const IP_Port ip_port = return_ip_port_connection(c, crypt_connection_id); // TODO(irungentoo): on bad networks, direct connections might not last indefinitely. @@ -703,11 +695,9 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t if (direct_connected) { if ((uint32_t)sendpacket(dht_get_net(c->dht), &ip_port, data, length) == length) { - pthread_mutex_unlock(conn->mutex); return 0; } - pthread_mutex_unlock(conn->mutex); LOGGER_WARNING(c->log, "sending packet of length %d failed", length); return -1; } @@ -724,19 +714,12 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t } } - pthread_mutex_unlock(conn->mutex); - pthread_mutex_lock(&c->tcp_mutex); const int ret = send_packet_tcp_connection(c->tcp_c, conn->connection_number_tcp, data, length); - pthread_mutex_unlock(&c->tcp_mutex); - - pthread_mutex_lock(conn->mutex); if (ret == 0) { conn->last_tcp_sent = current_time_monotonic(c->mono_time); } - pthread_mutex_unlock(conn->mutex); - if (direct_send_attempt) { return 0; } @@ -1097,7 +1080,6 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_ return -1; } - pthread_mutex_lock(conn->mutex); const uint16_t packet_size = 1 + sizeof(uint16_t) + length + CRYPTO_MAC_SIZE; VLA(uint8_t, packet, packet_size); packet[0] = NET_PACKET_CRYPTO_DATA; @@ -1106,12 +1088,10 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_ if (len + 1 + sizeof(uint16_t) != packet_size) { LOGGER_ERROR(c->log, "encryption failed: %d", len); - pthread_mutex_unlock(conn->mutex); return -1; } increment_nonce(conn->sent_nonce); - pthread_mutex_unlock(conn->mutex); return send_packet_to(c, crypt_connection_id, packet, packet_size); } @@ -1207,9 +1187,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons dt.sent_time = 0; dt.length = length; memcpy(dt.data, data, length); - pthread_mutex_lock(conn->mutex); const int64_t packet_num = add_data_end_of_buffer(c->log, c->mem, &conn->send_array, &dt); - pthread_mutex_unlock(conn->mutex); if (packet_num == -1) { return -1; @@ -1521,18 +1499,7 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda false, userdata); } - while (true) { /* TODO(irungentoo): is this really the best way to do this? */ - pthread_mutex_lock(&c->connections_mutex); - - if (c->connection_use_counter == 0) { - break; - } - - pthread_mutex_unlock(&c->connections_mutex); - } - crypto_kill(c, crypt_connection_id); - pthread_mutex_unlock(&c->connections_mutex); } /** @brief Handle a received data packet. @@ -1635,9 +1602,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const } while (true) { - pthread_mutex_lock(conn->mutex); const int ret = read_data_beg_buffer(c->mem, &conn->recv_array, &dt); - pthread_mutex_unlock(conn->mutex); if (ret == -1) { break; @@ -1835,16 +1800,6 @@ static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num) non_null() static int create_crypto_connection(Net_Crypto *c) { - while (true) { /* TODO(irungentoo): is this really the best way to do this? */ - pthread_mutex_lock(&c->connections_mutex); - - if (c->connection_use_counter == 0) { - break; - } - - pthread_mutex_unlock(&c->connections_mutex); - } - int id = -1; for (uint32_t i = 0; i < c->crypto_connections_length; ++i) { @@ -1863,30 +1818,17 @@ static int create_crypto_connection(Net_Crypto *c) } if (id != -1) { - pthread_mutex_t *mutex = (pthread_mutex_t *)mem_alloc(c->mem, sizeof(pthread_mutex_t)); - - if (mutex == nullptr) { - pthread_mutex_unlock(&c->connections_mutex); - return -1; - } - - if (pthread_mutex_init(mutex, nullptr) != 0) { - mem_delete(c->mem, mutex); - pthread_mutex_unlock(&c->connections_mutex); - return -1; - } - // Memsetting float/double to 0 is non-portable, so we explicitly set them to 0 c->crypto_connections[id].packet_recv_rate = 0.0; c->crypto_connections[id].packet_send_rate = 0.0; c->crypto_connections[id].last_packets_left_rem = 0.0; c->crypto_connections[id].packet_send_rate_requested = 0.0; c->crypto_connections[id].last_packets_left_requested_rem = 0.0; - c->crypto_connections[id].mutex = mutex; + + // TODO(Green-Sky): This enum is likely unneeded and the same as FREE. c->crypto_connections[id].status = CRYPTO_CONN_NO_CONNECTION; } - pthread_mutex_unlock(&c->connections_mutex); return id; } @@ -1914,8 +1856,6 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id) uint32_t i; - pthread_mutex_destroy(c->crypto_connections[crypt_connection_id].mutex); - mem_delete(c->mem, c->crypto_connections[crypt_connection_id].mutex); crypto_memzero(&c->crypto_connections[crypt_connection_id], sizeof(Crypto_Connection)); /* check if we can resize the connections array */ @@ -2098,9 +2038,7 @@ int accept_crypto_connection(Net_Crypto *c, const New_Connection *n_c) return -1; } - pthread_mutex_lock(&c->tcp_mutex); const int connection_number_tcp = new_tcp_connection_to(c->tcp_c, n_c->dht_public_key, crypt_connection_id); - pthread_mutex_unlock(&c->tcp_mutex); if (connection_number_tcp == -1) { wipe_crypto_connection(c, crypt_connection_id); @@ -2117,9 +2055,7 @@ int accept_crypto_connection(Net_Crypto *c, const New_Connection *n_c) conn->status = CRYPTO_CONN_NOT_CONFIRMED; if (create_send_handshake(c, crypt_connection_id, n_c->cookie, n_c->dht_public_key) != 0) { - pthread_mutex_lock(&c->tcp_mutex); kill_tcp_connection_to(c->tcp_c, conn->connection_number_tcp); - pthread_mutex_unlock(&c->tcp_mutex); wipe_crypto_connection(c, crypt_connection_id); return -1; } @@ -2155,9 +2091,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u Crypto_Connection *conn = &c->crypto_connections[crypt_connection_id]; - pthread_mutex_lock(&c->tcp_mutex); const int connection_number_tcp = new_tcp_connection_to(c->tcp_c, dht_public_key, crypt_connection_id); - pthread_mutex_unlock(&c->tcp_mutex); if (connection_number_tcp == -1) { wipe_crypto_connection(c, crypt_connection_id); @@ -2181,9 +2115,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u if (create_cookie_request(c, cookie_request, conn->dht_public_key, conn->cookie_request_number, conn->shared_key) != sizeof(cookie_request) || new_temp_packet(c, crypt_connection_id, cookie_request, sizeof(cookie_request)) != 0) { - pthread_mutex_lock(&c->tcp_mutex); kill_tcp_connection_to(c->tcp_c, conn->connection_number_tcp); - pthread_mutex_unlock(&c->tcp_mutex); wipe_crypto_connection(c, crypt_connection_id); return -1; } @@ -2241,11 +2173,7 @@ static int tcp_data_callback(void *object, int crypt_connection_id, const uint8_ return tcp_handle_cookie_request(c, conn->connection_number_tcp, packet, length); } - // This unlocks the mutex that at this point is locked by do_tcp before - // calling do_tcp_connections. - pthread_mutex_unlock(&c->tcp_mutex); const int ret = handle_packet_connection(c, crypt_connection_id, packet, length, false, userdata); - pthread_mutex_lock(&c->tcp_mutex); if (ret != 0) { return -1; @@ -2295,10 +2223,7 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip return -1; } - pthread_mutex_lock(&c->tcp_mutex); - const int ret = add_tcp_relay_connection(c->tcp_c, conn->connection_number_tcp, ip_port, public_key); - pthread_mutex_unlock(&c->tcp_mutex); - return ret; + return add_tcp_relay_connection(c->tcp_c, conn->connection_number_tcp, ip_port, public_key); } /** @brief Add a tcp relay to the array. @@ -2308,10 +2233,7 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip */ int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_key) { - pthread_mutex_lock(&c->tcp_mutex); - const int ret = add_tcp_relay_global(c->tcp_c, ip_port, public_key); - pthread_mutex_unlock(&c->tcp_mutex); - return ret; + return add_tcp_relay_global(c->tcp_c, ip_port, public_key); } /** @brief Return a random TCP connection number for use in send_tcp_onion_request. @@ -2322,13 +2244,9 @@ int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_k * return TCP connection number on success. * return -1 on failure. */ -int get_random_tcp_con_number(Net_Crypto *c) +int get_random_tcp_con_number(const Net_Crypto *c) { - pthread_mutex_lock(&c->tcp_mutex); - const int ret = get_random_tcp_onion_conn_number(c->tcp_c); - pthread_mutex_unlock(&c->tcp_mutex); - - return ret; + return get_random_tcp_onion_conn_number(c->tcp_c); } /** @brief Put IP_Port of a random onion TCP connection in ip_port. @@ -2336,13 +2254,9 @@ int get_random_tcp_con_number(Net_Crypto *c) * return true on success. * return false on failure. */ -bool get_random_tcp_conn_ip_port(Net_Crypto *c, IP_Port *ip_port) +bool get_random_tcp_conn_ip_port(const Net_Crypto *c, IP_Port *ip_port) { - pthread_mutex_lock(&c->tcp_mutex); - const bool ret = tcp_get_random_conn_ip_port(c->tcp_c, ip_port); - pthread_mutex_unlock(&c->tcp_mutex); - - return ret; + return tcp_get_random_conn_ip_port(c->tcp_c, ip_port); } /** @brief Send an onion packet via the TCP relay corresponding to tcp_connections_number. @@ -2352,11 +2266,7 @@ bool get_random_tcp_conn_ip_port(Net_Crypto *c, IP_Port *ip_port) */ int send_tcp_onion_request(Net_Crypto *c, unsigned int tcp_connections_number, const uint8_t *data, uint16_t length) { - pthread_mutex_lock(&c->tcp_mutex); - const int ret = tcp_send_onion_request(c->tcp_c, tcp_connections_number, data, length); - pthread_mutex_unlock(&c->tcp_mutex); - - return ret; + return tcp_send_onion_request(c->tcp_c, tcp_connections_number, data, length); } /** @@ -2371,12 +2281,8 @@ int send_tcp_forward_request(const Logger *logger, Net_Crypto *c, const IP_Port const uint8_t *chain_keys, uint16_t chain_length, const uint8_t *data, uint16_t data_length) { - pthread_mutex_lock(&c->tcp_mutex); - const int ret = tcp_send_forward_request(logger, c->tcp_c, tcp_forwarder, dht_node, - chain_keys, chain_length, data, data_length); - pthread_mutex_unlock(&c->tcp_mutex); - - return ret; + return tcp_send_forward_request(logger, c->tcp_c, tcp_forwarder, dht_node, + chain_keys, chain_length, data, data_length); } /** @brief Copy a maximum of num random TCP relays we are connected to to tcp_relays. @@ -2386,38 +2292,28 @@ int send_tcp_forward_request(const Logger *logger, Net_Crypto *c, const IP_Port * return number of relays copied to tcp_relays on success. * return 0 on failure. */ -unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, uint16_t num) +unsigned int copy_connected_tcp_relays(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num) { if (num == 0) { return 0; } - pthread_mutex_lock(&c->tcp_mutex); - const unsigned int ret = tcp_copy_connected_relays(c->tcp_c, tcp_relays, num); - pthread_mutex_unlock(&c->tcp_mutex); - - return ret; + return tcp_copy_connected_relays(c->tcp_c, tcp_relays, num); } -uint32_t copy_connected_tcp_relays_index(Net_Crypto *c, Node_format *tcp_relays, uint16_t num, uint32_t idx) +uint32_t copy_connected_tcp_relays_index(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num, uint32_t idx) { if (num == 0) { return 0; } - pthread_mutex_lock(&c->tcp_mutex); - const uint32_t ret = tcp_copy_connected_relays_index(c->tcp_c, tcp_relays, num, idx); - pthread_mutex_unlock(&c->tcp_mutex); - - return ret; + return tcp_copy_connected_relays_index(c->tcp_c, tcp_relays, num, idx); } non_null() static void do_tcp(Net_Crypto *c, void *userdata) { - pthread_mutex_lock(&c->tcp_mutex); do_tcp_connections(c->log, c->tcp_c, userdata); - pthread_mutex_unlock(&c->tcp_mutex); for (uint32_t i = 0; i < c->crypto_connections_length; ++i) { const Crypto_Connection *conn = get_crypto_connection(c, i); @@ -2436,9 +2332,7 @@ static void do_tcp(Net_Crypto *c, void *userdata) continue; } - pthread_mutex_lock(&c->tcp_mutex); set_tcp_connection_to_status(c->tcp_c, conn->connection_number_tcp, !direct_connected); - pthread_mutex_unlock(&c->tcp_mutex); } } @@ -2593,15 +2487,12 @@ static int udp_handle_packet(void *object, const IP_Port *source, const uint8_t return -1; } - pthread_mutex_lock(conn->mutex); - if (net_family_is_ipv4(source->ip.family)) { conn->direct_lastrecv_timev4 = mono_time_get(c->mono_time); } else { conn->direct_lastrecv_timev6 = mono_time_get(c->mono_time); } - pthread_mutex_unlock(conn->mutex); return 0; } @@ -2997,26 +2888,16 @@ int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t return -1; } - pthread_mutex_lock(&c->connections_mutex); - ++c->connection_use_counter; - pthread_mutex_unlock(&c->connections_mutex); - Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); int ret = -1; if (conn != nullptr) { - pthread_mutex_lock(conn->mutex); const uint32_t buffer_start = conn->recv_array.buffer_start; const uint32_t buffer_end = conn->send_array.buffer_end; - pthread_mutex_unlock(conn->mutex); ret = send_data_packet_helper(c, crypt_connection_id, buffer_start, buffer_end, data, length); } - pthread_mutex_lock(&c->connections_mutex); - --c->connection_use_counter; - pthread_mutex_unlock(&c->connections_mutex); - return ret; } @@ -3036,9 +2917,7 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id) send_kill_packet(c, crypt_connection_id); } - pthread_mutex_lock(&c->tcp_mutex); kill_tcp_connection_to(c->tcp_c, conn->connection_number_tcp); - pthread_mutex_unlock(&c->tcp_mutex); bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_portv4, crypt_connection_id); bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_portv6, crypt_connection_id); @@ -3135,13 +3014,6 @@ Net_Crypto *new_net_crypto(const Logger *log, const Memory *mem, const Random *r set_packet_tcp_connection_callback(temp->tcp_c, &tcp_data_callback, temp); set_oob_packet_tcp_connection_callback(temp->tcp_c, &tcp_oob_callback, temp); - if (create_recursive_mutex(&temp->tcp_mutex) != 0 || - pthread_mutex_init(&temp->connections_mutex, nullptr) != 0) { - kill_tcp_connections(temp->tcp_c); - mem_delete(mem, temp); - return nullptr; - } - temp->dht = dht; new_keys(temp); @@ -3215,9 +3087,6 @@ void kill_net_crypto(Net_Crypto *c) crypto_kill(c, i); } - pthread_mutex_destroy(&c->tcp_mutex); - pthread_mutex_destroy(&c->connections_mutex); - kill_tcp_connections(c->tcp_c); bs_list_free(&c->ip_port_list); networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_REQUEST, nullptr, nullptr); diff --git a/protocols/Tox/libtox/src/toxcore/net_crypto.h b/protocols/Tox/libtox/src/toxcore/net_crypto.h index 0d817e4315..8368d46e39 100644 --- a/protocols/Tox/libtox/src/toxcore/net_crypto.h +++ b/protocols/Tox/libtox/src/toxcore/net_crypto.h @@ -40,7 +40,6 @@ /** Packets in this range are reserved for AV use. */ #define PACKET_ID_RANGE_LOSSY_START 192 #define PACKET_ID_RANGE_LOSSY_AV_START 192 -#define PACKET_ID_RANGE_LOSSY_AV_SIZE 8 #define PACKET_ID_RANGE_LOSSY_AV_END 199 /** Packets in this range can be used for anything. */ #define PACKET_ID_RANGE_LOSSY_CUSTOM_START 200 @@ -311,7 +310,7 @@ int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_k * return -1 on failure. */ non_null() -int get_random_tcp_con_number(Net_Crypto *c); +int get_random_tcp_con_number(const Net_Crypto *c); /** @brief Put IP_Port of a random onion TCP connection in ip_port. * @@ -319,7 +318,7 @@ int get_random_tcp_con_number(Net_Crypto *c); * return false on failure. */ non_null() -bool get_random_tcp_conn_ip_port(Net_Crypto *c, IP_Port *ip_port); +bool get_random_tcp_conn_ip_port(const Net_Crypto *c, IP_Port *ip_port); /** @brief Send an onion packet via the TCP relay corresponding to tcp_connections_number. * @@ -351,7 +350,7 @@ int send_tcp_forward_request(const Logger *logger, Net_Crypto *c, const IP_Port * return 0 on failure. */ non_null() -unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, uint16_t num); +unsigned int copy_connected_tcp_relays(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num); /** * Copy a maximum of `max_num` TCP relays we are connected to starting at the index in the TCP relay array @@ -360,7 +359,7 @@ unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, u * Returns the number of relays successfully copied. */ non_null() -uint32_t copy_connected_tcp_relays_index(Net_Crypto *c, Node_format *tcp_relays, uint16_t num, uint32_t idx); +uint32_t copy_connected_tcp_relays_index(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num, uint32_t idx); /** @brief Kill a crypto connection. * diff --git a/protocols/Tox/libtox/src/toxcore/onion_client.c b/protocols/Tox/libtox/src/toxcore/onion_client.c index 9b0ac96102..326575963b 100644 --- a/protocols/Tox/libtox/src/toxcore/onion_client.c +++ b/protocols/Tox/libtox/src/toxcore/onion_client.c @@ -955,7 +955,7 @@ static int handle_announce_response(void *object, const IP_Port *source, const u } uint8_t plain[1 + ONION_PING_ID_SIZE + ONION_ANNOUNCE_RESPONSE_MAX_SIZE - ONION_ANNOUNCE_RESPONSE_MIN_SIZE]; - const int plain_size = 1 + ONION_PING_ID_SIZE + length - ONION_ANNOUNCE_RESPONSE_MIN_SIZE; + const uint32_t plain_size = 1 + ONION_PING_ID_SIZE + length - ONION_ANNOUNCE_RESPONSE_MIN_SIZE; int len; const uint16_t nonce_start = 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH; const uint16_t ciphertext_start = nonce_start + CRYPTO_NONCE_SIZE; diff --git a/protocols/Tox/libtox/src/toxcore/tox.c b/protocols/Tox/libtox/src/toxcore/tox.c index 085fab2ec1..b02eb4e98b 100644 --- a/protocols/Tox/libtox/src/toxcore/tox.c +++ b/protocols/Tox/libtox/src/toxcore/tox.c @@ -524,7 +524,7 @@ static void tox_group_password_handler(const Messenger *m, uint32_t group_number non_null(1, 5) nullable(8) static void tox_group_message_handler(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, unsigned int type, - const uint8_t *message, size_t length, uint32_t message_id, void *user_data) + const uint8_t *message, size_t length, Tox_Group_Message_Id message_id, void *user_data) { struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; @@ -536,16 +536,16 @@ static void tox_group_message_handler(const Messenger *m, uint32_t group_number, } } -non_null(1, 5) nullable(7) +non_null(1, 5) nullable(8) static void tox_group_private_message_handler(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, - unsigned int type, const uint8_t *message, size_t length, void *user_data) + unsigned int type, const uint8_t *message, size_t length, Tox_Group_Message_Id message_id, void *user_data) { struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; if (tox_data->tox->group_private_message_callback != nullptr) { tox_unlock(tox_data->tox); tox_data->tox->group_private_message_callback(tox_data->tox, group_number, gc_peer_id_to_int(peer_id), (Tox_Message_Type)type, message, - length, tox_data->user_data); + length, message_id, tox_data->user_data); tox_lock(tox_data->tox); } } @@ -712,7 +712,8 @@ static int tox_load(Tox *tox, const uint8_t *data, uint32_t length) length - cookie_len, STATE_COOKIE_TYPE); } -Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) +nullable(1, 2, 3) +static Tox *tox_new_system(const struct Tox_Options *options, Tox_Err_New *error, const Tox_System *sys) { struct Tox_Options *default_options = nullptr; @@ -736,7 +737,6 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) const struct Tox_Options *const opts = options != nullptr ? options : default_options; assert(opts != nullptr); - const Tox_System *sys = tox_options_get_operating_system(opts); const Tox_System default_system = tox_default_system(); if (sys == nullptr) { @@ -1020,6 +1020,37 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) return tox; } +Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) +{ + return tox_new_system(options, error, nullptr); +} + +Tox *tox_new_testing(const Tox_Options *options, Tox_Err_New *error, const Tox_Options_Testing *testing, Tox_Err_New_Testing *testing_error) +{ + if (testing == nullptr) { + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_NULL); + SET_ERROR_PARAMETER(testing_error, TOX_ERR_NEW_TESTING_NULL); + return nullptr; + } + + if (testing->operating_system == nullptr) { + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_NULL); + SET_ERROR_PARAMETER(testing_error, TOX_ERR_NEW_TESTING_NULL); + return nullptr; + } + + const Tox_System *sys = testing->operating_system; + + if (sys->rng == nullptr || sys->ns == nullptr || sys->mem == nullptr) { + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_NULL); + SET_ERROR_PARAMETER(testing_error, TOX_ERR_NEW_TESTING_NULL); + return nullptr; + } + + SET_ERROR_PARAMETER(testing_error, TOX_ERR_NEW_TESTING_OK); + return tox_new_system(options, error, sys); +} + void tox_kill(Tox *tox) { if (tox == nullptr) { @@ -1027,7 +1058,7 @@ void tox_kill(Tox *tox) } tox_lock(tox); - LOGGER_ASSERT(tox->m->log, tox->m->msi_packet == nullptr, "Attempted to kill tox while toxav is still alive"); + LOGGER_ASSERT(tox->m->log, tox->toxav_object == nullptr, "Attempted to kill tox while toxav is still alive"); kill_groupchats(tox->m->conferences_object); kill_messenger(tox->m); mono_time_free(tox->sys.mem, tox->mono_time); @@ -2520,6 +2551,12 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co Tox_Err_Conference_Join *error) { assert(tox != nullptr); + + if (cookie == nullptr) { + SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_JOIN_NULL); + return UINT32_MAX; + } + tox_lock(tox); const int ret = join_groupchat(tox->m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length); tox_unlock(tox); @@ -3688,7 +3725,7 @@ bool tox_group_set_topic(Tox *tox, uint32_t group_number, const uint8_t *topic, return false; } -size_t tox_group_get_topic_size(const Tox *tox, uint32_t group_number, Tox_Err_Group_State_Queries *error) +size_t tox_group_get_topic_size(const Tox *tox, uint32_t group_number, Tox_Err_Group_State_Query *error) { assert(tox != nullptr); @@ -3696,12 +3733,12 @@ size_t tox_group_get_topic_size(const Tox *tox, uint32_t group_number, Tox_Err_G const GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND); tox_unlock(tox); return -1; } - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_OK); const size_t ret = gc_get_topic_size(chat); tox_unlock(tox); @@ -3709,7 +3746,7 @@ size_t tox_group_get_topic_size(const Tox *tox, uint32_t group_number, Tox_Err_G return ret; } -bool tox_group_get_topic(const Tox *tox, uint32_t group_number, uint8_t *topic, Tox_Err_Group_State_Queries *error) +bool tox_group_get_topic(const Tox *tox, uint32_t group_number, uint8_t *topic, Tox_Err_Group_State_Query *error) { assert(tox != nullptr); @@ -3717,7 +3754,7 @@ bool tox_group_get_topic(const Tox *tox, uint32_t group_number, uint8_t *topic, const GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND); tox_unlock(tox); return false; } @@ -3725,11 +3762,11 @@ bool tox_group_get_topic(const Tox *tox, uint32_t group_number, uint8_t *topic, gc_get_topic(chat, topic); tox_unlock(tox); - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_OK); return true; } -size_t tox_group_get_name_size(const Tox *tox, uint32_t group_number, Tox_Err_Group_State_Queries *error) +size_t tox_group_get_name_size(const Tox *tox, uint32_t group_number, Tox_Err_Group_State_Query *error) { assert(tox != nullptr); @@ -3737,12 +3774,12 @@ size_t tox_group_get_name_size(const Tox *tox, uint32_t group_number, Tox_Err_Gr const GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND); tox_unlock(tox); return -1; } - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_OK); const size_t ret = gc_get_group_name_size(chat); tox_unlock(tox); @@ -3750,7 +3787,7 @@ size_t tox_group_get_name_size(const Tox *tox, uint32_t group_number, Tox_Err_Gr return ret; } -bool tox_group_get_name(const Tox *tox, uint32_t group_number, uint8_t *name, Tox_Err_Group_State_Queries *error) +bool tox_group_get_name(const Tox *tox, uint32_t group_number, uint8_t *name, Tox_Err_Group_State_Query *error) { assert(tox != nullptr); @@ -3758,7 +3795,7 @@ bool tox_group_get_name(const Tox *tox, uint32_t group_number, uint8_t *name, To const GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND); tox_unlock(tox); return false; } @@ -3766,12 +3803,12 @@ bool tox_group_get_name(const Tox *tox, uint32_t group_number, uint8_t *name, To gc_get_group_name(chat, name); tox_unlock(tox); - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_OK); return true; } -bool tox_group_get_chat_id(const Tox *tox, uint32_t group_number, uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE], Tox_Err_Group_State_Queries *error) +bool tox_group_get_chat_id(const Tox *tox, uint32_t group_number, uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE], Tox_Err_Group_State_Query *error) { assert(tox != nullptr); @@ -3779,12 +3816,12 @@ bool tox_group_get_chat_id(const Tox *tox, uint32_t group_number, uint8_t chat_i const GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND); tox_unlock(tox); return false; } - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_OK); gc_get_chat_id(chat, chat_id); tox_unlock(tox); @@ -3803,7 +3840,7 @@ uint32_t tox_group_get_number_groups(const Tox *tox) } Tox_Group_Privacy_State tox_group_get_privacy_state(const Tox *tox, uint32_t group_number, - Tox_Err_Group_State_Queries *error) + Tox_Err_Group_State_Query *error) { assert(tox != nullptr); @@ -3811,12 +3848,12 @@ Tox_Group_Privacy_State tox_group_get_privacy_state(const Tox *tox, uint32_t gro const GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND); tox_unlock(tox); return (Tox_Group_Privacy_State) - 1; } - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_OK); const uint8_t state = gc_get_privacy_state(chat); tox_unlock(tox); @@ -3824,7 +3861,7 @@ Tox_Group_Privacy_State tox_group_get_privacy_state(const Tox *tox, uint32_t gro return (Tox_Group_Privacy_State)state; } -Tox_Group_Topic_Lock tox_group_get_topic_lock(const Tox *tox, uint32_t group_number, Tox_Err_Group_State_Queries *error) +Tox_Group_Topic_Lock tox_group_get_topic_lock(const Tox *tox, uint32_t group_number, Tox_Err_Group_State_Query *error) { assert(tox != nullptr); @@ -3832,12 +3869,12 @@ Tox_Group_Topic_Lock tox_group_get_topic_lock(const Tox *tox, uint32_t group_num const GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND); tox_unlock(tox); return (Tox_Group_Topic_Lock) - 1; } - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_OK); const Group_Topic_Lock topic_lock = gc_get_topic_lock_state(chat); tox_unlock(tox); @@ -3846,7 +3883,7 @@ Tox_Group_Topic_Lock tox_group_get_topic_lock(const Tox *tox, uint32_t group_num } Tox_Group_Voice_State tox_group_get_voice_state(const Tox *tox, uint32_t group_number, - Tox_Err_Group_State_Queries *error) + Tox_Err_Group_State_Query *error) { assert(tox != nullptr); @@ -3854,12 +3891,12 @@ Tox_Group_Voice_State tox_group_get_voice_state(const Tox *tox, uint32_t group_n const GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND); tox_unlock(tox); return (Tox_Group_Voice_State) - 1; } - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_OK); const Group_Voice_State voice_state = gc_get_voice_state(chat); tox_unlock(tox); @@ -3867,7 +3904,7 @@ Tox_Group_Voice_State tox_group_get_voice_state(const Tox *tox, uint32_t group_n return (Tox_Group_Voice_State)voice_state; } -uint16_t tox_group_get_peer_limit(const Tox *tox, uint32_t group_number, Tox_Err_Group_State_Queries *error) +uint16_t tox_group_get_peer_limit(const Tox *tox, uint32_t group_number, Tox_Err_Group_State_Query *error) { assert(tox != nullptr); @@ -3875,12 +3912,12 @@ uint16_t tox_group_get_peer_limit(const Tox *tox, uint32_t group_number, Tox_Err const GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND); tox_unlock(tox); return -1; } - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_OK); const uint16_t ret = gc_get_max_peers(chat); tox_unlock(tox); @@ -3888,7 +3925,7 @@ uint16_t tox_group_get_peer_limit(const Tox *tox, uint32_t group_number, Tox_Err return ret; } -size_t tox_group_get_password_size(const Tox *tox, uint32_t group_number, Tox_Err_Group_State_Queries *error) +size_t tox_group_get_password_size(const Tox *tox, uint32_t group_number, Tox_Err_Group_State_Query *error) { assert(tox != nullptr); @@ -3896,12 +3933,12 @@ size_t tox_group_get_password_size(const Tox *tox, uint32_t group_number, Tox_Er const GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND); tox_unlock(tox); return -1; } - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_OK); const size_t ret = gc_get_password_size(chat); tox_unlock(tox); @@ -3910,7 +3947,7 @@ size_t tox_group_get_password_size(const Tox *tox, uint32_t group_number, Tox_Er } bool tox_group_get_password(const Tox *tox, uint32_t group_number, uint8_t *password, - Tox_Err_Group_State_Queries *error) + Tox_Err_Group_State_Query *error) { assert(tox != nullptr); @@ -3918,12 +3955,12 @@ bool tox_group_get_password(const Tox *tox, uint32_t group_number, uint8_t *pass const GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND); tox_unlock(tox); return false; } - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERIES_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_STATE_QUERY_OK); gc_get_password(chat, password); tox_unlock(tox); @@ -3932,7 +3969,7 @@ bool tox_group_get_password(const Tox *tox, uint32_t group_number, uint8_t *pass } Tox_Group_Message_Id tox_group_send_message( - const Tox *tox, uint32_t group_number, Tox_Message_Type type, const uint8_t *message, + const Tox *tox, uint32_t group_number, Tox_Message_Type message_type, const uint8_t *message, size_t length, Tox_Err_Group_Send_Message *error) { assert(tox != nullptr); @@ -3953,7 +3990,7 @@ Tox_Group_Message_Id tox_group_send_message( } uint32_t message_id = 0; - const int ret = gc_send_message(chat, message, length, type, &message_id); + const int ret = gc_send_message(chat, message, length, message_type, &message_id); tox_unlock(tox); switch (ret) { @@ -3994,8 +4031,8 @@ Tox_Group_Message_Id tox_group_send_message( return -1; } -bool tox_group_send_private_message(const Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type type, - const uint8_t *message, size_t length, Tox_Err_Group_Send_Private_Message *error) +Tox_Group_Message_Id tox_group_send_private_message(const Tox *tox, uint32_t group_number, uint32_t peer_id, + Tox_Message_Type message_type, const uint8_t *message, size_t length, Tox_Err_Group_Send_Private_Message *error) { assert(tox != nullptr); @@ -4005,59 +4042,60 @@ bool tox_group_send_private_message(const Tox *tox, uint32_t group_number, uint3 if (chat == nullptr) { SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_GROUP_NOT_FOUND); tox_unlock(tox); - return false; + return -1; } if (chat->connection_state == CS_DISCONNECTED) { SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_DISCONNECTED); tox_unlock(tox); - return false; + return -1; } - const int ret = gc_send_private_message(chat, gc_peer_id_from_int(peer_id), type, message, length); + uint32_t message_id = 0; + const int ret = gc_send_private_message(chat, gc_peer_id_from_int(peer_id), message_type, message, length, &message_id); tox_unlock(tox); switch (ret) { case 0: { SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK); - return true; + return message_id; } case -1: { SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_TOO_LONG); - return false; + return -1; } case -2: { SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_EMPTY); - return false; + return -1; } case -3: { SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PEER_NOT_FOUND); - return false; + return -1; } case -4: { SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_BAD_TYPE); - return false; + return -1; } case -5: { SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PERMISSIONS); - return false; + return -1; } case -6: { SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_FAIL_SEND); - return false; + return -1; } } /* can't happen */ LOGGER_FATAL(tox->m->log, "impossible return value: %d", ret); - return false; + return -1; } bool tox_group_send_custom_packet(const Tox *tox, uint32_t group_number, bool lossless, const uint8_t *data, @@ -4100,11 +4138,6 @@ bool tox_group_send_custom_packet(const Tox *tox, uint32_t group_number, bool lo } case -3: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS); - return false; - } - - case -4: { SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PACKET_FAIL_SEND); return false; } @@ -4162,11 +4195,6 @@ bool tox_group_send_custom_private_packet(const Tox *tox, uint32_t group_number, } case -4: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS); - return false; - } - - case -5: { SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_FAIL_SEND); return false; } @@ -4241,6 +4269,11 @@ uint32_t tox_group_invite_accept(Tox *tox, uint32_t friend_number, const uint8_t { assert(tox != nullptr); + if (invite_data == nullptr || name == nullptr) { + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_INVITE_ACCEPT_NULL); + return UINT32_MAX; + } + tox_lock(tox); const int ret = gc_accept_invite(tox->m->group_handler, friend_number, invite_data, length, name, name_length, password, password_length); @@ -4278,7 +4311,7 @@ uint32_t tox_group_invite_accept(Tox *tox, uint32_t friend_number, const uint8_t } case -6: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_INVITE_ACCEPT_CORE); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_INVITE_ACCEPT_FRIEND_NOT_FOUND); return UINT32_MAX; } @@ -4294,8 +4327,8 @@ uint32_t tox_group_invite_accept(Tox *tox, uint32_t friend_number, const uint8_t return UINT32_MAX; } -bool tox_group_founder_set_password(Tox *tox, uint32_t group_number, const uint8_t *password, size_t length, - Tox_Err_Group_Founder_Set_Password *error) +bool tox_group_set_password(Tox *tox, uint32_t group_number, const uint8_t *password, size_t length, + Tox_Err_Group_Set_Password *error) { assert(tox != nullptr); @@ -4303,13 +4336,13 @@ bool tox_group_founder_set_password(Tox *tox, uint32_t group_number, const uint8 GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PASSWORD_GROUP_NOT_FOUND); tox_unlock(tox); return false; } if (chat->connection_state == CS_DISCONNECTED) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_DISCONNECTED); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PASSWORD_DISCONNECTED); tox_unlock(tox); return false; } @@ -4319,27 +4352,27 @@ bool tox_group_founder_set_password(Tox *tox, uint32_t group_number, const uint8 switch (ret) { case 0: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PASSWORD_OK); return true; } case -1: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_PERMISSIONS); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PASSWORD_PERMISSIONS); return false; } case -2: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_TOO_LONG); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PASSWORD_TOO_LONG); return false; } case -3: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_FAIL_SEND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PASSWORD_FAIL_SEND); return false; } case -4: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_MALLOC); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PASSWORD_MALLOC); return false; } } @@ -4350,8 +4383,8 @@ bool tox_group_founder_set_password(Tox *tox, uint32_t group_number, const uint8 return false; } -bool tox_group_founder_set_privacy_state(Tox *tox, uint32_t group_number, Tox_Group_Privacy_State privacy_state, - Tox_Err_Group_Founder_Set_Privacy_State *error) +bool tox_group_set_privacy_state(Tox *tox, uint32_t group_number, Tox_Group_Privacy_State privacy_state, + Tox_Err_Group_Set_Privacy_State *error) { assert(tox != nullptr); @@ -4361,32 +4394,32 @@ bool tox_group_founder_set_privacy_state(Tox *tox, uint32_t group_number, Tox_Gr switch (ret) { case 0: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PRIVACY_STATE_OK); return true; } case -1: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PRIVACY_STATE_GROUP_NOT_FOUND); return false; } case -2: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_PERMISSIONS); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PRIVACY_STATE_PERMISSIONS); return false; } case -3: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_DISCONNECTED); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PRIVACY_STATE_DISCONNECTED); return false; } case -4: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_FAIL_SET); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PRIVACY_STATE_FAIL_SET); return false; } case -5: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_FAIL_SEND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PRIVACY_STATE_FAIL_SEND); return false; } } @@ -4397,8 +4430,8 @@ bool tox_group_founder_set_privacy_state(Tox *tox, uint32_t group_number, Tox_Gr return false; } -bool tox_group_founder_set_topic_lock(Tox *tox, uint32_t group_number, Tox_Group_Topic_Lock topic_lock, - Tox_Err_Group_Founder_Set_Topic_Lock *error) +bool tox_group_set_topic_lock(Tox *tox, uint32_t group_number, Tox_Group_Topic_Lock topic_lock, + Tox_Err_Group_Set_Topic_Lock *error) { assert(tox != nullptr); @@ -4408,37 +4441,37 @@ bool tox_group_founder_set_topic_lock(Tox *tox, uint32_t group_number, Tox_Group switch (ret) { case 0: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_TOPIC_LOCK_OK); return true; } case -1: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_TOPIC_LOCK_GROUP_NOT_FOUND); return false; } case -2: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_INVALID); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_TOPIC_LOCK_INVALID); return false; } case -3: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_PERMISSIONS); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_TOPIC_LOCK_PERMISSIONS); return false; } case -4: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_DISCONNECTED); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_TOPIC_LOCK_DISCONNECTED); return false; } case -5: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_FAIL_SET); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_TOPIC_LOCK_FAIL_SET); return false; } case -6: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_FAIL_SEND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_TOPIC_LOCK_FAIL_SEND); return false; } } @@ -4449,8 +4482,8 @@ bool tox_group_founder_set_topic_lock(Tox *tox, uint32_t group_number, Tox_Group return false; } -bool tox_group_founder_set_voice_state(Tox *tox, uint32_t group_number, Tox_Group_Voice_State voice_state, - Tox_Err_Group_Founder_Set_Voice_State *error) +bool tox_group_set_voice_state(Tox *tox, uint32_t group_number, Tox_Group_Voice_State voice_state, + Tox_Err_Group_Set_Voice_State *error) { assert(tox != nullptr); @@ -4460,32 +4493,32 @@ bool tox_group_founder_set_voice_state(Tox *tox, uint32_t group_number, Tox_Grou switch (ret) { case 0: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_VOICE_STATE_OK); return true; } case -1: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_VOICE_STATE_GROUP_NOT_FOUND); return false; } case -2: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_PERMISSIONS); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_VOICE_STATE_PERMISSIONS); return false; } case -3: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_DISCONNECTED); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_VOICE_STATE_DISCONNECTED); return false; } case -4: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_FAIL_SET); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_VOICE_STATE_FAIL_SET); return false; } case -5: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_FAIL_SEND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_VOICE_STATE_FAIL_SEND); return false; } } @@ -4496,8 +4529,8 @@ bool tox_group_founder_set_voice_state(Tox *tox, uint32_t group_number, Tox_Grou return false; } -bool tox_group_founder_set_peer_limit(Tox *tox, uint32_t group_number, uint16_t peer_limit, - Tox_Err_Group_Founder_Set_Peer_Limit *error) +bool tox_group_set_peer_limit(Tox *tox, uint32_t group_number, uint16_t peer_limit, + Tox_Err_Group_Set_Peer_Limit *error) { assert(tox != nullptr); @@ -4505,13 +4538,13 @@ bool tox_group_founder_set_peer_limit(Tox *tox, uint32_t group_number, uint16_t GC_Chat *chat = gc_get_group(tox->m->group_handler, group_number); if (chat == nullptr) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PEER_LIMIT_GROUP_NOT_FOUND); tox_unlock(tox); return false; } if (chat->connection_state == CS_DISCONNECTED) { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_DISCONNECTED); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PEER_LIMIT_DISCONNECTED); tox_unlock(tox); return false; } @@ -4521,22 +4554,22 @@ bool tox_group_founder_set_peer_limit(Tox *tox, uint32_t group_number, uint16_t switch (ret) { case 0: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PEER_LIMIT_OK); return true; } case -1: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_PERMISSIONS); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PEER_LIMIT_PERMISSIONS); return false; } case -2: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_FAIL_SET); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PEER_LIMIT_FAIL_SET); return false; } case -3: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_FAIL_SEND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_PEER_LIMIT_FAIL_SEND); return false; } } @@ -4587,8 +4620,8 @@ bool tox_group_set_ignore(Tox *tox, uint32_t group_number, uint32_t peer_id, boo return false; } -bool tox_group_mod_set_role(Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Group_Role role, - Tox_Err_Group_Mod_Set_Role *error) +bool tox_group_set_role(Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Group_Role role, + Tox_Err_Group_Set_Role *error) { assert(tox != nullptr); @@ -4598,37 +4631,37 @@ bool tox_group_mod_set_role(Tox *tox, uint32_t group_number, uint32_t peer_id, T switch (ret) { case 0: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_SET_ROLE_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_ROLE_OK); return true; } case -1: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_SET_ROLE_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_ROLE_GROUP_NOT_FOUND); return false; } case -2: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_SET_ROLE_PEER_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_ROLE_PEER_NOT_FOUND); return false; } case -3: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_ROLE_PERMISSIONS); return false; } case -4: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_SET_ROLE_ASSIGNMENT); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_ROLE_ASSIGNMENT); return false; } case -5: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_SET_ROLE_FAIL_ACTION); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_ROLE_FAIL_ACTION); return false; } case -6: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_SET_ROLE_SELF); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SET_ROLE_SELF); return false; } } @@ -4639,8 +4672,8 @@ bool tox_group_mod_set_role(Tox *tox, uint32_t group_number, uint32_t peer_id, T return false; } -bool tox_group_mod_kick_peer(const Tox *tox, uint32_t group_number, uint32_t peer_id, - Tox_Err_Group_Mod_Kick_Peer *error) +bool tox_group_kick_peer(const Tox *tox, uint32_t group_number, uint32_t peer_id, + Tox_Err_Group_Kick_Peer *error) { assert(tox != nullptr); @@ -4650,37 +4683,37 @@ bool tox_group_mod_kick_peer(const Tox *tox, uint32_t group_number, uint32_t pee switch (ret) { case 0: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_KICK_PEER_OK); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_KICK_PEER_OK); return true; } case -1: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_KICK_PEER_GROUP_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_KICK_PEER_GROUP_NOT_FOUND); return false; } case -2: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_KICK_PEER_PEER_NOT_FOUND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_KICK_PEER_PEER_NOT_FOUND); return false; } case -3: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_KICK_PEER_PERMISSIONS); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_KICK_PEER_PERMISSIONS); return false; } case -4: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_KICK_PEER_FAIL_ACTION); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_KICK_PEER_FAIL_ACTION); return false; } case -5: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_KICK_PEER_FAIL_SEND); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_KICK_PEER_FAIL_SEND); return false; } case -6: { - SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_MOD_KICK_PEER_SELF); + SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_KICK_PEER_SELF); return false; } } diff --git a/protocols/Tox/libtox/src/toxcore/tox.h b/protocols/Tox/libtox/src/toxcore/tox.h index fa887fc779..ebeed3b1f5 100644 --- a/protocols/Tox/libtox/src/toxcore/tox.h +++ b/protocols/Tox/libtox/src/toxcore/tox.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-3.0-or-later - * Copyright © 2016-2018 The TokTok team. + * Copyright © 2016-2024 The TokTok team. * Copyright © 2013 Tox project. */ @@ -25,9 +25,8 @@ * could not perform any operation, because one of the required parameters was * NULL. Some functions operate correctly or are defined as effectless on NULL. * - * Some functions additionally return a value outside their - * return type domain, or a bool containing true on success and false on - * failure. + * Some functions additionally return a value outside their return type domain, + * or a bool containing true on success and false on failure. * * All functions that take a Tox instance pointer will cause undefined behaviour * when passed a NULL Tox pointer. @@ -52,17 +51,9 @@ * event listeners, it needs to implement the dispatch functionality itself. * * The last argument to a callback is the user data pointer. It is passed from - * tox_iterate to each callback in sequence. - * - * The user data pointer is never stored or dereferenced by any library code, so - * can be any pointer, including NULL. Callbacks must all operate on the same - * object type. In the apidsl code (tox.in.h), this is denoted with `any`. The - * `any` in tox_iterate must be the same `any` as in all callbacks. In C, - * lacking parametric polymorphism, this is a pointer to void. - * - * Old style callbacks that are registered together with a user data pointer - * receive that pointer as argument when they are called. They can each have - * their own user data pointer of their own type. + * tox_iterate to each callback in sequence. The user data pointer is never + * stored or dereferenced by any library code, so can be any pointer, including + * NULL. * * @section threading Threading implications * @@ -157,7 +148,7 @@ uint32_t tox_version_minor(void); * Incremented when bugfixes are applied without changing any functionality or * API or ABI. */ -#define TOX_VERSION_PATCH 18 +#define TOX_VERSION_PATCH 20 uint32_t tox_version_patch(void); @@ -206,7 +197,7 @@ bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch); * * The values of these are not part of the ABI. Prefer to use the function * versions of them for code that should remain compatible with future versions - * of toxcore. + * of the Tox library. */ /** @@ -468,12 +459,12 @@ typedef enum Tox_Log_Level { TOX_LOG_LEVEL_INFO, /** - * Warnings about events_alloc inconsistency or logic errors. + * Warnings about internal inconsistency or logic errors. */ TOX_LOG_LEVEL_WARNING, /** - * Severe unexpected errors caused by external or events_alloc inconsistency. + * Severe unexpected errors caused by external or internal inconsistency. */ TOX_LOG_LEVEL_ERROR, @@ -482,7 +473,7 @@ typedef enum Tox_Log_Level { const char *tox_log_level_to_string(Tox_Log_Level value); /** - * @brief This event is triggered when the toxcore library logs an events_alloc message. + * @brief This event is triggered when Tox logs an internal message. * * This is mostly useful for debugging. This callback can be called from any * function, not just tox_iterate. This means the user data lifetime must at @@ -506,15 +497,6 @@ typedef void tox_log_cb(Tox *tox, Tox_Log_Level level, const char *file, uint32_ const char *message, void *user_data); /** - * @brief Operating system functions used by Tox. - * - * This struct is opaque and generally shouldn't be used in clients, but in - * combination with tox_private.h, it allows tests to inject non-IO (hermetic) - * versions of low level network, RNG, and time keeping functions. - */ -typedef struct Tox_System Tox_System; - -/** * @brief This struct contains all the startup options for Tox. * * You must tox_options_new to allocate an object of this type. @@ -546,10 +528,11 @@ struct Tox_Options { * Enable the use of UDP communication when available. * * Setting this to false will force Tox to use TCP only. Communications will - * need to be relayed through a TCP relay node, potentially slowing them down. + * need to be relayed through a TCP relay node, potentially slowing them + * down. * - * If a proxy is enabled, UDP will be disabled if either toxcore or the - * proxy don't support proxying UDP messages. + * If a proxy is enabled, UDP will be disabled if either the Tox library or + * the proxy don't support proxying UDP messages. */ bool udp_enabled; @@ -576,10 +559,11 @@ struct Tox_Options { * The IP address or DNS name of the proxy to be used. * * If used, this must be non-NULL and be a valid DNS name. The name must not - * exceed TOX_MAX_HOSTNAME_LENGTH characters, and be in a NUL-terminated C string - * format (TOX_MAX_HOSTNAME_LENGTH includes the NUL byte). + * exceed TOX_MAX_HOSTNAME_LENGTH characters, and be in a NUL-terminated C + * string format (TOX_MAX_HOSTNAME_LENGTH includes the NUL byte). * - * This member is ignored (it can be NULL) if proxy_type is TOX_PROXY_TYPE_NONE. + * This member is ignored (it can be NULL) if proxy_type is + * TOX_PROXY_TYPE_NONE. * * The data pointed at by this member is owned by the user, so must * outlive the options object. @@ -603,8 +587,8 @@ struct Tox_Options { * If either start_port or end_port is 0 while the other is non-zero, the * non-zero port will be the only port in the range. * - * Having start_port > end_port will yield the same behavior as if start_port - * and end_port were swapped. + * Having start_port > end_port will yield the same behavior as if + * start_port and end_port were swapped. */ uint16_t start_port; @@ -627,7 +611,7 @@ struct Tox_Options { uint16_t tcp_port; /** - * Enables or disables UDP hole-punching in toxcore. (Default: enabled). + * Enables or disables UDP hole-punching. (Default: enabled). */ bool hole_punching_enabled; @@ -639,8 +623,8 @@ struct Tox_Options { /** * The savedata. * - * The data pointed at by this member is owned by the user, so must - * outlive the options object. + * The data pointed at by this member is owned by the user, so must outlive + * the options object. */ const uint8_t *savedata_data; @@ -650,7 +634,7 @@ struct Tox_Options { size_t savedata_length; /** - * Logging callback for the new tox instance. + * Logging callback for the new Tox instance. */ tox_log_cb *log_callback; @@ -673,14 +657,9 @@ struct Tox_Options { bool experimental_thread_safety; /** - * Low level operating system functionality such as send/recv, random - * number generation, and memory allocation. - */ - const Tox_System *operating_system; - - /** - * Enable saving DHT-based group chats to Tox save data (via `tox_get_savedata`). - * This format will change in the future, so don't rely on it. + * Enable saving DHT-based group chats to Tox save data (via + * `tox_get_savedata`). This format will change in the future, so don't rely + * on it. * * As an alternative, clients can save the group chat ID in client-owned * savedata. Then, when the client starts, it can use `tox_group_join` @@ -759,10 +738,6 @@ bool tox_options_get_experimental_thread_safety(const Tox_Options *options); void tox_options_set_experimental_thread_safety(Tox_Options *options, bool experimental_thread_safety); -const Tox_System *tox_options_get_operating_system(const Tox_Options *options); - -void tox_options_set_operating_system(Tox_Options *options, const Tox_System *operating_system); - bool tox_options_get_experimental_groups_persistence(const Tox_Options *options); void tox_options_set_experimental_groups_persistence(Tox_Options *options, bool experimental_groups_persistence); @@ -837,15 +812,16 @@ typedef enum Tox_Err_New { TOX_ERR_NEW_NULL, /** - * The function was unable to allocate enough memory to store the events_alloc - * structures for the Tox object. + * The function was unable to allocate enough memory to store the + * internal structures for the Tox object. */ TOX_ERR_NEW_MALLOC, /** * The function was unable to bind to a port. This may mean that all ports * have already been bound, e.g. by other Tox instances, or it may mean - * a permission error. You may be able to gather more information from errno. + * a permission error. You may be able to gather more information from + * errno. */ TOX_ERR_NEW_PORT_ALLOC, @@ -913,7 +889,7 @@ Tox *tox_new(const Tox_Options *options, Tox_Err_New *error); void tox_kill(Tox *tox); /** - * @brief Calculates the number of bytes required to store the tox instance with + * @brief Calculates the number of bytes required to store the Tox instance with * tox_get_savedata. * * This function cannot fail. The result is always greater than 0. @@ -923,11 +899,12 @@ void tox_kill(Tox *tox); size_t tox_get_savedata_size(const Tox *tox); /** - * @brief Store all information associated with the tox instance to a byte array. + * @brief Store all information associated with the Tox instance to a byte + * array. * - * @param savedata A memory region large enough to store the tox instance - * data. Call tox_get_savedata_size to find the number of bytes required. If this parameter - * is NULL, this function has no effect. + * @param savedata A memory region large enough to store the Tox instance + * data. Call tox_get_savedata_size to find the number of bytes required. If + * this parameter is NULL, this function has no effect. */ void tox_get_savedata(const Tox *tox, uint8_t savedata[]); @@ -1065,14 +1042,16 @@ typedef void tox_self_connection_status_cb(Tox *tox, Tox_Connection connection_s void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback); /** - * @brief Return the time in milliseconds before `tox_iterate()` should be called again - * for optimal performance. + * @brief Return the time in milliseconds before `tox_iterate()` should be + * called again for optimal performance. */ uint32_t tox_iteration_interval(const Tox *tox); /** - * @brief The main loop that needs to be run in intervals of `tox_iteration_interval()` - * milliseconds. + * @brief The main loop that needs to be run in intervals of + * `tox_iteration_interval()` milliseconds. + * @param user_data Any pointer a client wishes the Tox instance to pass into + * the event callbacks, including NULL. */ void tox_iterate(Tox *tox, void *user_data); @@ -1172,7 +1151,8 @@ const char *tox_err_set_info_to_string(Tox_Err_Set_Info value); bool tox_self_set_name(Tox *tox, const uint8_t name[], size_t length, Tox_Err_Set_Info *error); /** - * @brief Return the length of the current nickname as passed to tox_self_set_name. + * @brief Return the length of the current nickname as passed to + * tox_self_set_name. * * If no nickname was set before calling this function, the name is empty, * and this function returns 0. @@ -1206,7 +1186,8 @@ bool tox_self_set_status_message( Tox *tox, const uint8_t status_message[], size_t length, Tox_Err_Set_Info *error); /** - * @brief Return the length of the current status message as passed to tox_self_set_status_message. + * @brief Return the length of the current status message as passed to + * tox_self_set_status_message. * * If no status message was set before calling this function, the status * is empty, and this function returns 0. @@ -1216,13 +1197,14 @@ bool tox_self_set_status_message( size_t tox_self_get_status_message_size(const Tox *tox); /** - * @brief Write the status message set by tox_self_set_status_message to a byte array. + * @brief Write the status message set by tox_self_set_status_message to a byte + * array. * * If no status message was set before calling this function, the status is * empty, and this function has no effect. * - * Call tox_self_get_status_message_size to find out how much memory to allocate for - * the result. + * Call tox_self_get_status_message_size to find out how much memory to allocate + * for the result. * * @param status_message A valid memory location large enough to hold the * status message. If this parameter is NULL, the function has no effect. @@ -1279,8 +1261,8 @@ typedef enum Tox_Err_Friend_Add { TOX_ERR_FRIEND_ADD_OWN_KEY, /** - * A friend request has already been sent, or the address belongs to a friend - * that is already on the friend list. + * A friend request has already been sent, or the address belongs to a + * friend that is already on the friend list. */ TOX_ERR_FRIEND_ADD_ALREADY_SENT, @@ -1360,7 +1342,8 @@ typedef enum Tox_Err_Friend_Delete { TOX_ERR_FRIEND_DELETE_OK, /** - * There was no friend with the given friend number. No friends were deleted. + * There was no friend with the given friend number. No friends were + * deleted. */ TOX_ERR_FRIEND_DELETE_FRIEND_NOT_FOUND, @@ -1411,14 +1394,15 @@ const char *tox_err_friend_by_public_key_to_string(Tox_Err_Friend_By_Public_Key /** * @brief Return the friend number associated with that Public Key. * - * @return the friend number on success, an unspecified value on failure. * @param public_key A byte array containing the Public Key. + * + * @return the friend number on success, an unspecified value on failure. */ Tox_Friend_Number tox_friend_by_public_key(const Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Friend_By_Public_Key *error); /** - * @brief Checks if a friend with the given friend number exists and returns true if - * it does. + * @brief Checks if a friend with the given friend number exists and returns + * true if it does. */ bool tox_friend_exists(const Tox *tox, Tox_Friend_Number friend_number); @@ -1433,7 +1417,8 @@ size_t tox_self_get_friend_list_size(const Tox *tox); /** * @brief Copy a list of valid friend numbers into an array. * - * Call tox_self_get_friend_list_size to determine the number of elements to allocate. + * Call tox_self_get_friend_list_size to determine the number of elements to + * allocate. * * @param friend_list A memory region with enough space to hold the friend * list. If this parameter is NULL, this function has no effect. @@ -1457,7 +1442,8 @@ typedef enum Tox_Err_Friend_Get_Public_Key { const char *tox_err_friend_get_public_key_to_string(Tox_Err_Friend_Get_Public_Key value); /** - * @brief Copies the Public Key associated with a given friend number to a byte array. + * @brief Copies the Public Key associated with a given friend number to a byte + * array. * * @param friend_number The friend number you want the Public Key of. * @param public_key A memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If @@ -1486,8 +1472,8 @@ typedef enum Tox_Err_Friend_Get_Last_Online { const char *tox_err_friend_get_last_online_to_string(Tox_Err_Friend_Get_Last_Online value); /** - * @brief Return a unix-time timestamp of the last time the friend associated with a given - * friend number was seen online. + * @brief Return a unix-time timestamp of the last time the friend associated + * with a given friend number was seen online. * * This function will return UINT64_MAX on error. * @@ -1514,8 +1500,9 @@ typedef enum Tox_Err_Friend_Query { /** * The pointer parameter for storing the query result (name, message) was - * NULL. Unlike the `_self_` variants of these functions, which have no effect - * when a parameter is NULL, these functions return an error in that case. + * NULL. Unlike the `_self_` variants of these functions, which have no + * effect when a parameter is NULL, these functions return an error in that + * case. */ TOX_ERR_FRIEND_QUERY_NULL, @@ -1540,8 +1527,8 @@ size_t tox_friend_get_name_size( const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); /** - * @brief Write the name of the friend designated by the given friend number to a byte - * array. + * @brief Write the name of the friend designated by the given friend number to + * a byte array. * * Call tox_friend_get_name_size to determine the allocation size for the `name` * parameter. @@ -1579,22 +1566,23 @@ void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback); /** * @brief Return the length of the friend's status message. * - * If the friend number isinvalid, the return value is SIZE_MAX. + * If the friend number is invalid, the return value is SIZE_MAX. */ size_t tox_friend_get_status_message_size( const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); /** - * @brief Write the status message of the friend designated by the given friend number to a byte - * array. + * @brief Write the status message of the friend designated by the given friend + * number to a byte array. * - * Call tox_friend_get_status_message_size to determine the allocation size for the `status_message` - * parameter. + * Call tox_friend_get_status_message_size to determine the allocation size for + * the `status_message` parameter. * - * The data written to `status_message` is equal to the data received by the last - * `friend_status_message` callback. + * The data written to `status_message` is equal to the data received by the + * last `friend_status_message` callback. * - * @param status_message A valid memory region large enough to store the friend's status message. + * @param status_message A valid memory region large enough to store the + * friend's status message. */ bool tox_friend_get_status_message( const Tox *tox, Tox_Friend_Number friend_number, uint8_t status_message[], @@ -1604,7 +1592,8 @@ bool tox_friend_get_status_message( * @param friend_number The friend number of the friend whose status message * changed. * @param message A byte array containing the same data as - * tox_friend_get_status_message would write to its `status_message` parameter. + * tox_friend_get_status_message would write to its `status_message` + * parameter. * @param length A value equal to the return value of * tox_friend_get_status_message_size. */ @@ -1814,7 +1803,8 @@ typedef uint32_t Tox_Friend_Message_Id; * then reassemble the fragments. Messages may not be empty. * * The return value of this function is the message ID. If a read receipt is - * received, the triggered `friend_read_receipt` event will be passed this message ID. + * received, the triggered `friend_read_receipt` event will be passed this + * message ID. * * Message IDs are unique per friend. The first message ID is 0. Message IDs are * incremented by 1 each time a message is sent. If UINT32_MAX messages were @@ -1831,7 +1821,8 @@ Tox_Friend_Message_Id tox_friend_send_message( const uint8_t message[], size_t length, Tox_Err_Friend_Send_Message *error); /** - * @param friend_number The friend number of the friend who received the message. + * @param friend_number The friend number of the friend who received the + * message. * @param message_id The message ID as returned from tox_friend_send_message * corresponding to the message sent. */ @@ -1875,6 +1866,7 @@ void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback); /** * @param friend_number The friend number of the friend who sent the message. + * @param type The type of the message (normal, action, ...). * @param message The message data they sent. * @param length The size of the message byte array. */ @@ -1906,10 +1898,10 @@ typedef uint32_t Tox_File_Number; * primarily for validating cached avatars. This use is highly recommended to * avoid unnecessary avatar updates. * - * If hash is NULL or data is NULL while length is not 0 the function returns false, - * otherwise it returns true. + * If hash is NULL or data is NULL while length is not 0 the function returns + * false, otherwise it returns true. * - * This function is a wrapper to events_alloc message-digest functions. + * This function is a wrapper to internal message-digest functions. * * @param hash A valid memory location the hash data. It must be at least * TOX_HASH_LENGTH bytes in size. @@ -1923,17 +1915,17 @@ bool tox_hash(uint8_t hash[TOX_HASH_LENGTH], const uint8_t data[], size_t length /** * @brief A list of pre-defined file kinds. * - * Toxcore itself does not behave differently for different file kinds. These - * are a hint to the client telling it what use the sender intended for the - * file. The `kind` parameter in the send function and recv callback are + * The Tox library itself does not behave differently for different file kinds. + * These are a hint to the client telling it what use the sender intended for + * the file. The `kind` parameter in the send function and recv callback are * `uint32_t`, not Tox_File_Kind, because clients can invent their own file * kind. Unknown file kinds should be treated as TOX_FILE_KIND_DATA. */ enum Tox_File_Kind { /** - * Arbitrary file data. Clients can choose to handle it based on the file name - * or magic or any other way they choose. + * Arbitrary file data. Clients can choose to handle it based on the file + * name or magic or any other way they choose. */ TOX_FILE_KIND_DATA, @@ -1941,21 +1933,21 @@ enum Tox_File_Kind { * Avatar file_id. This consists of tox_hash(image). * Avatar data. This consists of the image data. * - * Avatars can be sent at any time the client wishes. Generally, a client will - * send the avatar to a friend when that friend comes online, and to all - * friends when the avatar changed. A client can save some traffic by - * remembering which friend received the updated avatar already and only send - * it if the friend has an out of date avatar. + * Avatars can be sent at any time the client wishes. Generally, a client + * will send the avatar to a friend when that friend comes online, and to + * all friends when the avatar changed. A client can save some traffic by + * remembering which friend received the updated avatar already and only + * send it if the friend has an out of date avatar. * * Clients who receive avatar send requests can reject it (by sending * TOX_FILE_CONTROL_CANCEL before any other controls), or accept it (by - * sending TOX_FILE_CONTROL_RESUME). The file_id of length TOX_HASH_LENGTH bytes - * (same length as TOX_FILE_ID_LENGTH) will contain the hash. A client can compare - * this hash with a saved hash and send TOX_FILE_CONTROL_CANCEL to terminate the avatar - * transfer if it matches. + * sending TOX_FILE_CONTROL_RESUME). The file_id of length TOX_HASH_LENGTH + * bytes (same length as TOX_FILE_ID_LENGTH) will contain the hash. A client + * can compare this hash with a saved hash and send TOX_FILE_CONTROL_CANCEL + * to terminate the avatar transfer if it matches. * - * When file_size is set to 0 in the transfer request it means that the client - * has no avatar. + * When file_size is set to 0 in the transfer request it means that the + * client has no avatar. */ TOX_FILE_KIND_AVATAR, @@ -1964,16 +1956,17 @@ enum Tox_File_Kind { typedef enum Tox_File_Control { /** - * Sent by the receiving side to accept a file send request. Also sent after a - * TOX_FILE_CONTROL_PAUSE command to continue sending or receiving. + * Sent by the receiving side to accept a file send request. Also sent after + * a TOX_FILE_CONTROL_PAUSE command to continue sending or receiving. */ TOX_FILE_CONTROL_RESUME, /** * Sent by clients to pause the file transfer. The initial state of a file - * transfer is always paused on the receiving side and running on the sending - * side. If both the sending and receiving side pause the transfer, then both - * need to send TOX_FILE_CONTROL_RESUME for the transfer to resume. + * transfer is always paused on the receiving side and running on the + * sending side. If both the sending and receiving side pause the transfer, + * then both need to send TOX_FILE_CONTROL_RESUME for the transfer to + * resume. */ TOX_FILE_CONTROL_PAUSE, @@ -2005,7 +1998,8 @@ typedef enum Tox_Err_File_Control { TOX_ERR_FILE_CONTROL_FRIEND_NOT_CONNECTED, /** - * No file transfer with the given file number was found for the given friend. + * No file transfer with the given file number was found for the given + * friend. */ TOX_ERR_FILE_CONTROL_NOT_FOUND, @@ -2089,7 +2083,8 @@ typedef enum Tox_Err_File_Seek { TOX_ERR_FILE_SEEK_FRIEND_NOT_CONNECTED, /** - * No file transfer with the given file number was found for the given friend. + * No file transfer with the given file number was found for the given + * friend. */ TOX_ERR_FILE_SEEK_NOT_FOUND, @@ -2113,7 +2108,8 @@ typedef enum Tox_Err_File_Seek { const char *tox_err_file_seek_to_string(Tox_Err_File_Seek value); /** - * @brief Sends a file seek control command to a friend for a given file transfer. + * @brief Sends a file seek control command to a friend for a given file + * transfer. * * This function can only be called to resume a file transfer right before * TOX_FILE_CONTROL_RESUME is sent. @@ -2144,7 +2140,8 @@ typedef enum Tox_Err_File_Get { TOX_ERR_FILE_GET_FRIEND_NOT_FOUND, /** - * No file transfer with the given file number was found for the given friend. + * No file transfer with the given file number was found for the given + * friend. */ TOX_ERR_FILE_GET_NOT_FOUND, @@ -2158,8 +2155,8 @@ const char *tox_err_file_get_to_string(Tox_Err_File_Get value); * @param friend_number The friend number of the friend the file is being * transferred to or received from. * @param file_number The friend-specific identifier for the file transfer. - * @param file_id A memory region of at least TOX_FILE_ID_LENGTH bytes. If - * this parameter is NULL, this function has no effect. + * @param file_id A memory region of at least TOX_FILE_ID_LENGTH bytes. If this + * parameter is NULL, this function has no effect. * * @return true on success. */ @@ -2202,8 +2199,8 @@ typedef enum Tox_Err_File_Send { TOX_ERR_FILE_SEND_NAME_TOO_LONG, /** - * Too many ongoing transfers. The maximum number of concurrent file transfers - * is 256 per friend per direction (sending and receiving). + * Too many ongoing transfers. The maximum number of concurrent file + * transfers is 256 per friend per direction (sending and receiving). */ TOX_ERR_FILE_SEND_TOO_MANY, @@ -2214,8 +2211,8 @@ const char *tox_err_file_send_to_string(Tox_Err_File_Send value); /** * @brief Send a file transmission request. * - * Maximum filename length is TOX_MAX_FILENAME_LENGTH bytes. The filename - * should generally just be a file name, not a path with directory names. + * Maximum filename length is TOX_MAX_FILENAME_LENGTH bytes. The filename should + * generally just be a file name, not a path with directory names. * * If a non-UINT64_MAX file size is provided, it can be used by both sides to * determine the sending progress. File size can be set to UINT64_MAX for @@ -2224,8 +2221,8 @@ const char *tox_err_file_send_to_string(Tox_Err_File_Send value); * File transmission occurs in chunks, which are requested through the * `file_chunk_request` event. * - * When a friend goes offline, all file transfers associated with the friend are - * purged from core. + * When a friend goes offline, all file transfers associated with the friend get + * purged. * * If the file contents change during a transfer, the behaviour is unspecified * in general. What will actually happen depends on the mode in which the file @@ -2234,15 +2231,16 @@ const char *tox_err_file_send_to_string(Tox_Err_File_Send value); * - If the file size was increased * - and sending mode was streaming (file_size = UINT64_MAX), the behaviour * will be as expected. - * - and sending mode was file (file_size != UINT64_MAX), the file_chunk_request - * callback will receive length = 0 when Core thinks the file transfer has - * finished. If the client remembers the file size as it was when sending the - * request, it will terminate the transfer normally. If the client re-reads the - * size, it will think the friend cancelled the transfer. + * - and sending mode was file (file_size != UINT64_MAX), the + * file_chunk_request callback will receive length = 0 when Tox thinks the + * file transfer has finished. If the client remembers the file size as it + * was when sending the request, it will terminate the transfer normally. If + * the client re-reads the size, it will think the friend cancelled the + * transfer. * - If the file size was decreased * - and sending mode was streaming, the behaviour is as expected. * - and sending mode was file, the callback will return 0 at the new - * (earlier) end-of-file, signalling to the friend that the transfer was + * (earlier) end-of-file, signaling to the friend that the transfer was * cancelled. * - If the file contents were modified * - at a position before the current read, the two files (local and remote) @@ -2255,19 +2253,20 @@ const char *tox_err_file_send_to_string(Tox_Err_File_Send value); * @param friend_number The friend number of the friend the file send request * should be sent to. * @param kind The meaning of the file to be sent. - * @param file_size Size in bytes of the file the client wants to send, UINT64_MAX if - * unknown or streaming. - * @param file_id A file identifier of length TOX_FILE_ID_LENGTH that can be used to - * uniquely identify file transfers across core restarts. If NULL, a random one will - * be generated by core. It can then be obtained by using `tox_file_get_file_id()`. + * @param file_size Size in bytes of the file the client wants to send, + * UINT64_MAX if unknown or streaming. + * @param file_id A file identifier of length TOX_FILE_ID_LENGTH that can be + * used to uniquely identify file transfers across Tox restarts. If NULL, a + * random one will be generated by the library. It can then be obtained by + * using `tox_file_get_file_id()`. * @param filename Name of the file. Does not need to be the actual name. This * name will be sent along with the file send request. * @param filename_length Size in bytes of the filename. * * @return A file number used as an identifier in subsequent callbacks. This * number is per friend. File numbers are reused after a transfer terminates. - * On failure, this function returns an unspecified value. Any pattern in file numbers - * should not be relied on. + * On failure, this function returns an unspecified value. Any pattern in file + * numbers should not be relied on. */ Tox_File_Number tox_file_send( Tox *tox, Tox_Friend_Number friend_number, uint32_t kind, uint64_t file_size, @@ -2297,20 +2296,23 @@ typedef enum Tox_Err_File_Send_Chunk { TOX_ERR_FILE_SEND_CHUNK_FRIEND_NOT_CONNECTED, /** - * No file transfer with the given file number was found for the given friend. + * No file transfer with the given file number was found for the given + * friend. */ TOX_ERR_FILE_SEND_CHUNK_NOT_FOUND, /** * File transfer was found but isn't in a transferring state: (paused, done, - * broken, etc...) (happens only when not called from the request chunk callback). + * broken, etc...) (happens only when not called from the request chunk + * callback). */ TOX_ERR_FILE_SEND_CHUNK_NOT_TRANSFERRING, /** - * Attempted to send more or less data than requested. The requested data size is - * adjusted according to maximum transmission unit and the expected end of - * the file. Trying to send less or more than requested will return this error. + * Attempted to send more or less data than requested. The requested data + * size is adjusted according to maximum transmission unit and the expected + * end of the file. Trying to send less or more than requested will return + * this error. */ TOX_ERR_FILE_SEND_CHUNK_INVALID_LENGTH, @@ -2334,10 +2336,11 @@ const char *tox_err_file_send_chunk_to_string(Tox_Err_File_Send_Chunk value); * This function is called in response to the `file_chunk_request` callback. The * length parameter should be equal to the one received though the callback. * If it is zero, the transfer is assumed complete. For files with known size, - * Core will know that the transfer is complete after the last byte has been + * Tox will know that the transfer is complete after the last byte has been * received, so it is not necessary (though not harmful) to send a zero-length - * chunk to terminate. For streams, core will know that the transfer is finished - * if a chunk with length less than the length requested in the callback is sent. + * chunk to terminate. For streams, Tox will know that the transfer is finished + * if a chunk with length less than the length requested in the callback is + * sent. * * @param friend_number The friend number of the receiving friend for this file. * @param file_number The file transfer identifier returned by tox_file_send. @@ -2379,7 +2382,7 @@ typedef void tox_file_chunk_request_cb( * * Pass NULL to unset. * - * This event is triggered when Core is ready to send more file data. + * This event is triggered when Tox is ready to send more file data. */ void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback); @@ -2458,6 +2461,7 @@ void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback); typedef uint32_t Tox_Conference_Number; typedef uint32_t Tox_Conference_Peer_Number; +typedef uint32_t Tox_Conference_Offline_Peer_Number; /** * @brief Conference types for the conference_invite event. @@ -2465,7 +2469,8 @@ typedef uint32_t Tox_Conference_Peer_Number; typedef enum Tox_Conference_Type { /** - * Text-only conferences that must be accepted with the tox_conference_join function. + * Text-only conferences that must be accepted with the tox_conference_join + * function. */ TOX_CONFERENCE_TYPE_TEXT, @@ -2502,7 +2507,8 @@ typedef void tox_conference_invite_cb( void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback); /** - * @param conference_number The conference number of the conference to which we have connected. + * @param conference_number The conference number of the conference to which we + * have connected. */ typedef void tox_conference_connected_cb(Tox *tox, Tox_Conference_Number conference_number, void *user_data); @@ -2555,7 +2561,8 @@ typedef void tox_conference_title_cb( * * This event is triggered when a peer changes the conference title. * - * If peer_number == UINT32_MAX, then author is unknown (e.g. initial joining the conference). + * If peer_number == UINT32_MAX, then author is unknown (e.g. initial joining + * the conference). */ void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback); @@ -2640,7 +2647,8 @@ const char *tox_err_conference_delete_to_string(Tox_Err_Conference_Delete value) /** * @brief This function deletes a conference. * - * @param conference_number The conference number of the conference to be deleted. + * @param conference_number The conference number of the conference to be + * deleted. * * @return true on success. */ @@ -2682,7 +2690,7 @@ const char *tox_err_conference_peer_query_to_string(Tox_Err_Conference_Peer_Quer * peer_number for the functions querying these peers. Return value is * unspecified on failure. */ -Tox_Conference_Peer_Number tox_conference_peer_count( +uint32_t tox_conference_peer_count( const Tox *tox, Tox_Conference_Number conference_number, Tox_Err_Conference_Peer_Query *error); /** @@ -2697,7 +2705,8 @@ size_t tox_conference_peer_get_name_size( /** * @brief Copy the name of peer_number who is in conference_number to name. * - * Call tox_conference_peer_get_name_size to determine the allocation size for the `name` parameter. + * Call tox_conference_peer_get_name_size to determine the allocation size for + * the `name` parameter. * * @param name A valid memory region large enough to store the peer's name. * @@ -2708,7 +2717,8 @@ bool tox_conference_peer_get_name( uint8_t name[], Tox_Err_Conference_Peer_Query *error); /** - * @brief Copy the public key of peer_number who is in conference_number to public_key. + * @brief Copy the public key of peer_number who is in conference_number to + * public_key. * * public_key must be TOX_PUBLIC_KEY_SIZE long. * @@ -2744,10 +2754,11 @@ uint32_t tox_conference_offline_peer_count( */ size_t tox_conference_offline_peer_get_name_size( const Tox *tox, Tox_Conference_Number conference_number, - Tox_Conference_Peer_Number offline_peer_number, Tox_Err_Conference_Peer_Query *error); + Tox_Conference_Offline_Peer_Number offline_peer_number, Tox_Err_Conference_Peer_Query *error); /** - * @brief Copy the name of offline_peer_number who is in conference_number to name. + * @brief Copy the name of offline_peer_number who is in conference_number to + * name. * * Call tox_conference_offline_peer_get_name_size to determine the allocation * size for the `name` parameter. @@ -2757,11 +2768,12 @@ size_t tox_conference_offline_peer_get_name_size( * @return true on success. */ bool tox_conference_offline_peer_get_name( - const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number offline_peer_number, + const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Offline_Peer_Number offline_peer_number, uint8_t name[], Tox_Err_Conference_Peer_Query *error); /** - * @brief Copy the public key of offline_peer_number who is in conference_number to public_key. + * @brief Copy the public key of offline_peer_number who is in conference_number + * to public_key. * * public_key must be TOX_PUBLIC_KEY_SIZE long. * @@ -2769,14 +2781,15 @@ bool tox_conference_offline_peer_get_name( */ bool tox_conference_offline_peer_get_public_key( const Tox *tox, Tox_Conference_Number conference_number, - Tox_Conference_Peer_Number offline_peer_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Conference_Peer_Query *error); + Tox_Conference_Offline_Peer_Number offline_peer_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Conference_Peer_Query *error); /** - * @brief Return a unix-time timestamp of the last time offline_peer_number was seen to be active. + * @brief Return a unix-time timestamp of the last time offline_peer_number was + * seen to be active. */ uint64_t tox_conference_offline_peer_get_last_active( const Tox *tox, Tox_Conference_Number conference_number, - Tox_Conference_Peer_Number offline_peer_number, Tox_Err_Conference_Peer_Query *error); + Tox_Conference_Offline_Peer_Number offline_peer_number, Tox_Err_Conference_Peer_Query *error); typedef enum Tox_Err_Conference_Set_Max_Offline { @@ -2831,7 +2844,8 @@ const char *tox_err_conference_invite_to_string(Tox_Err_Conference_Invite value) * @brief Invites a friend to a conference. * * @param friend_number The friend number of the friend we want to invite. - * @param conference_number The conference number of the conference we want to invite the friend to. + * @param conference_number The conference number of the conference we want to + * invite the friend to. * * @return true on success. */ @@ -2852,7 +2866,8 @@ typedef enum Tox_Err_Conference_Join { TOX_ERR_CONFERENCE_JOIN_INVALID_LENGTH, /** - * The conference is not the expected type. This indicates an invalid cookie. + * The conference is not the expected type. This indicates an invalid + * cookie. */ TOX_ERR_CONFERENCE_JOIN_WRONG_TYPE, @@ -2876,6 +2891,11 @@ typedef enum Tox_Err_Conference_Join { */ TOX_ERR_CONFERENCE_JOIN_FAIL_SEND, + /** + * The cookie passed was NULL. + */ + TOX_ERR_CONFERENCE_JOIN_NULL, + } Tox_Err_Conference_Join; const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value); @@ -2887,7 +2907,7 @@ const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value); * to it until a handshaking procedure has been completed. A * `conference_connected` event will then occur for the conference. The client * will then remain connected to the conference until the conference is deleted, - * even across core restarts. Many operations on a conference will fail with a + * even across Tox restarts. Many operations on a conference will fail with a * corresponding error if attempted on a conference to which the client is not * yet connected. * @@ -2995,9 +3015,11 @@ size_t tox_conference_get_title_size( const Tox *tox, Tox_Conference_Number conference_number, Tox_Err_Conference_Title *error); /** - * @brief Write the title designated by the given conference number to a byte array. + * @brief Write the title designated by the given conference number to a byte + * array. * - * Call tox_conference_get_title_size to determine the allocation size for the `title` parameter. + * Call tox_conference_get_title_size to determine the allocation size for the + * `title` parameter. * * The data written to `title` is equal to the data received by the last * `conference_title` callback. @@ -3013,7 +3035,8 @@ bool tox_conference_get_title( Tox_Err_Conference_Title *error); /** - * @brief Set the conference title and broadcast it to the rest of the conference. + * @brief Set the conference title and broadcast it to the rest of the + * conference. * * Title length cannot be longer than TOX_MAX_NAME_LENGTH. * @@ -3027,7 +3050,8 @@ bool tox_conference_set_title( /** * @brief Return the number of conferences in the Tox instance. * - * This should be used to determine how much memory to allocate for `tox_conference_get_chatlist`. + * This should be used to determine how much memory to allocate for + * `tox_conference_get_chatlist`. */ size_t tox_conference_get_chatlist_size(const Tox *tox); @@ -3037,8 +3061,8 @@ size_t tox_conference_get_chatlist_size(const Tox *tox); * Determine how much space to allocate for the array with the * `tox_conference_get_chatlist_size` function. * - * Note that `tox_get_savedata` saves all connected conferences; - * when toxcore is created from savedata in which conferences were saved, those + * Note that `tox_get_savedata` saves all connected conferences; when a Tox + * instance is created from savedata in which conferences were saved, those * conferences will be connected at startup, and will be listed by * `tox_conference_get_chatlist`. * @@ -3048,7 +3072,8 @@ size_t tox_conference_get_chatlist_size(const Tox *tox); void tox_conference_get_chatlist(const Tox *tox, Tox_Conference_Number chatlist[]); /** - * @brief Returns the type of conference (Tox_Conference_Type) that conference_number is. + * @brief Returns the type of conference (Tox_Conference_Type) that + * conference_number is. * * Return value is unspecified on failure. */ @@ -3123,10 +3148,12 @@ Tox_Conference_Number tox_conference_by_id( * * If uid is NULL, this function has no effect. * - * @param uid A memory region large enough to store TOX_CONFERENCE_UID_SIZE bytes. + * @param uid A memory region large enough to store TOX_CONFERENCE_UID_SIZE + * bytes. * * @return true on success. - * @deprecated use tox_conference_get_id instead (exactly the same function, just renamed). + * @deprecated use tox_conference_get_id instead (exactly the same function, + * just renamed). */ bool tox_conference_get_uid( const Tox *tox, Tox_Conference_Number conference_number, uint8_t uid[TOX_CONFERENCE_UID_SIZE]); @@ -3155,10 +3182,12 @@ const char *tox_err_conference_by_uid_to_string(Tox_Err_Conference_By_Uid value) /** * @brief Return the conference number associated with the specified uid. * - * @param uid A byte array containing the conference id (TOX_CONFERENCE_UID_SIZE). + * @param uid A byte array containing the conference id + * (TOX_CONFERENCE_UID_SIZE). * * @return the conference number on success, an unspecified value on failure. - * @deprecated use tox_conference_by_id instead (exactly the same function, just renamed). + * @deprecated use tox_conference_by_id instead (exactly the same function, + * just renamed). */ Tox_Conference_Number tox_conference_by_uid( const Tox *tox, const uint8_t uid[TOX_CONFERENCE_UID_SIZE], Tox_Err_Conference_By_Uid *error); @@ -3192,8 +3221,9 @@ typedef enum Tox_Err_Friend_Custom_Packet { TOX_ERR_FRIEND_CUSTOM_PACKET_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. + * The first byte of data was not one of the permitted values; + * for lossy packets the first byte must be in the range 192-254, + * and for lossless packets it must be either 69 or in the range 160-191. */ TOX_ERR_FRIEND_CUSTOM_PACKET_INVALID, @@ -3244,7 +3274,7 @@ bool tox_friend_send_lossy_packet( /** * @brief Send a custom lossless packet to a friend. * - * The first byte of data must be in the range 69, 160-191. Maximum length of a + * The first byte of data must be either 69 or in the range 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) @@ -3263,6 +3293,9 @@ bool tox_friend_send_lossless_packet( Tox_Err_Friend_Custom_Packet *error); /** + * tox_callback_friend_lossy_packet is the compatibility function to + * set the callback for all packet IDs except those reserved for ToxAV. + * * @param friend_number The friend number of the friend who sent a lossy packet. * @param data A byte array containing the received packet data. * @param length The length of the packet data byte array. @@ -3322,7 +3355,8 @@ const char *tox_err_get_port_to_string(Tox_Err_Get_Port value); * @brief Writes the temporary DHT public key of this instance to a byte array. * * 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. + * 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. @@ -3435,22 +3469,24 @@ uint32_t tox_group_peer_public_key_size(void); typedef enum Tox_Group_Privacy_State { /** - * The group is considered to be public. Anyone may join the group using the Chat ID. + * The group is considered to be public. Anyone may join the group using + * the Chat ID. * - * If the group is in this state, even if the Chat ID is never explicitly shared - * with someone outside of the group, information including the Chat ID, IP addresses, - * and peer ID's (but not Tox ID's) is visible to anyone with access to a node - * storing a DHT entry for the given group. + * If the group is in this state, even if the Chat ID is never explicitly + * shared with someone outside of the group, information including the Chat + * ID, IP addresses, and peer ID's (but not Tox ID's) is visible to anyone + * with access to a node storing a DHT entry for the given group. */ TOX_GROUP_PRIVACY_STATE_PUBLIC, /** - * The group is considered to be private. The only way to join the group is by having - * someone in your contact list send you an invite. + * The group is considered to be private. The only way to join the group is + * by having someone in your contact list send you an invite. * - * If the group is in this state, no group information (mentioned above) is present in the DHT; - * the DHT is not used for any purpose at all. If a public group is set to private, - * all DHT information related to the group will expire shortly. + * If the group is in this state, no group information (mentioned above) is + * present in the DHT; the DHT is not used for any purpose at all. If a + * public group is set to private, all DHT information related to the group + * will expire shortly. */ TOX_GROUP_PRIVACY_STATE_PRIVATE, @@ -3460,16 +3496,20 @@ const char *tox_group_privacy_state_to_string(Tox_Group_Privacy_State value); /** * Represents the state of the group topic lock. + * + * The default is enabled. */ typedef enum Tox_Group_Topic_Lock { /** - * The topic lock is enabled. Only peers with the founder and moderator roles may set the topic. + * The topic lock is enabled. Only peers with the founder and moderator + * roles may set the topic. */ TOX_GROUP_TOPIC_LOCK_ENABLED, /** - * The topic lock is disabled. All peers except those with the observer role may set the topic. + * The topic lock is disabled. All peers except those with the observer role + * may set the topic. */ TOX_GROUP_TOPIC_LOCK_DISABLED, @@ -3478,8 +3518,9 @@ typedef enum Tox_Group_Topic_Lock { const char *tox_group_topic_lock_to_string(Tox_Group_Topic_Lock value); /** - * Represents the group voice state, which determines which Group Roles have permission to speak - * in the group chat. The voice state does not have any effect private messages or topic setting. + * Represents the group voice state, which determines which Group Roles have + * permission to speak in the group chat. The voice state does not have any + * effect private messages or topic setting. */ typedef enum Tox_Group_Voice_State { /** @@ -3503,14 +3544,15 @@ const char *tox_group_voice_state_to_string(Tox_Group_Voice_State value); /** * Represents group roles. * - * Roles are hierarchical in that each role has a set of privileges plus all the privileges - * of the roles below it. + * Roles are hierarchical in that each role has a set of privileges plus all the + * privileges of the roles below it. */ typedef enum Tox_Group_Role { /** - * May kick all other peers as well as set their role to anything (except founder). - * Founders may also set the group password, toggle the privacy state, and set the peer limit. + * May kick all other peers as well as set their role to anything (except + * founder). Founders may also set the group password, toggle the privacy + * state, and set the peer limit. */ TOX_GROUP_ROLE_FOUNDER, @@ -3526,7 +3568,8 @@ typedef enum Tox_Group_Role { TOX_GROUP_ROLE_USER, /** - * May observe the group and ignore peers; may not communicate with other peers or with the group. + * May observe the group and ignore peers; may not communicate with other + * peers or with the group. */ TOX_GROUP_ROLE_OBSERVER, @@ -3548,7 +3591,8 @@ typedef enum Tox_Err_Group_New { TOX_ERR_GROUP_NEW_OK, /** - * name exceeds TOX_MAX_NAME_LENGTH or group_name exceeded TOX_GROUP_MAX_GROUP_NAME_LENGTH. + * name exceeds TOX_MAX_NAME_LENGTH or group_name exceeded + * TOX_GROUP_MAX_GROUP_NAME_LENGTH. */ TOX_ERR_GROUP_NEW_TOO_LONG, @@ -3563,13 +3607,14 @@ typedef enum Tox_Err_Group_New { TOX_ERR_GROUP_NEW_INIT, /** - * The group state failed to initialize. This usually indicates that something went wrong - * related to cryptographic signing. + * The group state failed to initialize. This usually indicates that + * something went wrong related to cryptographic signing. */ TOX_ERR_GROUP_NEW_STATE, /** - * The group failed to announce to the DHT. This indicates a network related error. + * The group failed to announce to the DHT. This indicates a network related + * error. */ TOX_ERR_GROUP_NEW_ANNOUNCE, @@ -3584,18 +3629,19 @@ const char *tox_err_group_new_to_string(Tox_Err_Group_New value); * * The caller of this function has Founder role privileges. * - * The client should initiate its peer list with self info after calling this function, as - * the peer_join callback will not be triggered. + * The client should initiate its peer list with self info after calling this + * function, as the peer_join callback will not be triggered. * - * @param privacy_state The privacy state of the group. If this is set to TOX_GROUP_PRIVACY_STATE_PUBLIC, - * the group will attempt to announce itself to the DHT and anyone with the Chat ID may join. - * Otherwise a friend invite will be required to join the group. + * @param privacy_state The privacy state of the group. If this is set to + * TOX_GROUP_PRIVACY_STATE_PUBLIC, the group will attempt to announce itself + * to the DHT and anyone with the Chat ID may join. Otherwise a friend invite + * will be required to join the group. * @param group_name The name of the group. The name must be non-NULL. - * @param group_name_length The length of the group name. This must be greater than zero and no larger than - * TOX_GROUP_MAX_GROUP_NAME_LENGTH. + * @param group_name_length The length of the group name. This must be greater + * than zero and no larger than TOX_GROUP_MAX_GROUP_NAME_LENGTH. * @param name The name of the peer creating the group. - * @param name_length The length of the peer's name. This must be greater than zero and no larger - * than TOX_MAX_NAME_LENGTH. + * @param name_length The length of the peer's name. This must be greater than + * zero and no larger than TOX_MAX_NAME_LENGTH. * * @return group_number on success, UINT32_MAX on failure. */ @@ -3617,8 +3663,9 @@ typedef enum Tox_Err_Group_Join { TOX_ERR_GROUP_JOIN_INIT, /** - * The chat_id pointer is set to NULL or a group with chat_id already exists. This usually - * happens if the client attempts to create multiple sessions for the same group. + * The chat_id pointer is set to NULL or a group with chat_id already + * exists. This usually happens if the client attempts to create multiple + * sessions for the same group. */ TOX_ERR_GROUP_JOIN_BAD_CHAT_ID, @@ -3633,7 +3680,8 @@ typedef enum Tox_Err_Group_Join { TOX_ERR_GROUP_JOIN_TOO_LONG, /** - * Failed to set password. This usually occurs if the password exceeds TOX_GROUP_MAX_PASSWORD_SIZE. + * Failed to set password. This usually occurs if the password exceeds + * TOX_GROUP_MAX_PASSWORD_SIZE. */ TOX_ERR_GROUP_JOIN_PASSWORD, @@ -3649,17 +3697,20 @@ const char *tox_err_group_join_to_string(Tox_Err_Group_Join value); /** * Joins a group chat with specified Chat ID. * - * This function creates a new group chat object, adds it to the chats array, and sends - * a DHT announcement to find peers in the group associated with chat_id. Once a peer has been - * found a join attempt will be initiated. - * - * @param chat_id The Chat ID of the group you wish to join. This must be TOX_GROUP_CHAT_ID_SIZE bytes. - * @param password The password required to join the group. Set to NULL if no password is required. - * @param password_length The length of the password. If length is equal to zero, - * the password parameter is ignored. length must be no larger than TOX_GROUP_MAX_PASSWORD_SIZE. + * This function creates a new group chat object, adds it to the chats array, + * and sends a DHT announcement to find peers in the group associated with + * chat_id. Once a peer has been found a join attempt will be initiated. + * + * @param chat_id The Chat ID of the group you wish to join. This must be + * TOX_GROUP_CHAT_ID_SIZE bytes. + * @param password The password required to join the group. Set to NULL if no + * password is required. + * @param password_length The length of the password. If length is equal to + * zero, the password parameter is ignored. length must be no larger than + * TOX_GROUP_MAX_PASSWORD_SIZE. * @param name The name of the peer joining the group. - * @param name_length The length of the peer's name. This must be greater than zero and no larger - * than TOX_MAX_NAME_LENGTH. + * @param name_length The length of the peer's name. This must be greater than + * zero and no larger than TOX_MAX_NAME_LENGTH. * * @return group_number on success, UINT32_MAX on failure. */ @@ -3686,8 +3737,8 @@ typedef enum Tox_Err_Group_Is_Connected { const char *tox_err_group_is_connected_to_string(Tox_Err_Group_Is_Connected value); /** - * Returns true if the group chat is currently connected or attempting to connect to other peers - * in the group. + * Returns true if the group chat is currently connected or attempting to + * connect to other peers in the group. * * @param group_number The group number of the designated group. */ @@ -3714,7 +3765,8 @@ typedef enum Tox_Err_Group_Disconnect { const char *tox_err_group_disconnect_to_string(Tox_Err_Group_Disconnect value); /** - * Disconnects from a group chat while retaining the group state and credentials. + * Disconnects from a group chat while retaining the group state and + * credentials. * * Returns true if we successfully disconnect from the group. * @@ -3746,8 +3798,9 @@ const char *tox_err_group_reconnect_to_string(Tox_Err_Group_Reconnect value); /** * Reconnects to a group. * - * This function disconnects from all peers in the group, then attempts to reconnect with the group. - * The caller's state is not changed (i.e. name, status, role, chat public key etc.). + * This function disconnects from all peers in the group, then attempts to + * reconnect with the group. The caller's state is not changed (i.e. name, + * status, role, chat public key etc.). * * @param group_number The group number of the group we wish to reconnect to. * @@ -3783,14 +3836,16 @@ const char *tox_err_group_leave_to_string(Tox_Err_Group_Leave value); /** * Leaves a group. * - * This function sends a parting packet containing a custom (non-obligatory) message to all - * peers in a group, and deletes the group from the chat array. All group state information is permanently - * lost, including keys and role credentials. + * This function sends a parting packet containing a custom (non-obligatory) + * message to all peers in a group, and deletes the group from the chat array. + * All group state information is permanently lost, including keys and role + * credentials. * * @param group_number The group number of the group we wish to leave. - * @param part_message The parting message to be sent to all the peers. Set to NULL if we do not wish to - * send a parting message. - * @param length The length of the parting message. Set to 0 if we do not wish to send a parting message. + * @param part_message The parting message to be sent to all the peers. Set to + * NULL if we do not wish to send a parting message. + * @param length The length of the parting message. Set to 0 if we do not wish + * to send a parting message. * * @return true if the group chat instance is successfully deleted. */ @@ -3859,10 +3914,11 @@ typedef enum Tox_Err_Group_Self_Name_Set { const char *tox_err_group_self_name_set_to_string(Tox_Err_Group_Self_Name_Set value); /** - * Set the client's nickname for the group instance designated by the given group number. + * Set the client's nickname for the group instance designated by the given + * group number. * - * Nickname length cannot exceed TOX_MAX_NAME_LENGTH. If length is equal to zero or name is a NULL - * pointer, the function call will fail. + * Nickname length cannot exceed TOX_MAX_NAME_LENGTH. If length is equal to + * zero or name is a NULL pointer, the function call will fail. * * @param name A byte array containing the new nickname. * @param length The size of the name byte array. @@ -3875,8 +3931,8 @@ bool tox_group_self_set_name( Tox_Err_Group_Self_Name_Set *error); /** - * Return the length of the client's current nickname for the group instance designated - * by group_number as passed to tox_group_self_set_name. + * Return the length of the client's current nickname for the group instance + * designated by group_number as passed to tox_group_self_set_name. * * If no nickname was set before calling this function, the name is empty, * and this function returns 0. @@ -3891,7 +3947,8 @@ size_t tox_group_self_get_name_size(const Tox *tox, Tox_Group_Number group_numbe * If no nickname was set before calling this function, the name is empty, * and this function has no effect. * - * Call tox_group_self_get_name_size to find out how much memory to allocate for the result. + * Call tox_group_self_get_name_size to find out how much memory to allocate for + * the result. * * @param name A valid memory location large enough to hold the nickname. * If this parameter is NULL, the function has no effect. @@ -3927,7 +3984,8 @@ typedef enum Tox_Err_Group_Self_Status_Set { const char *tox_err_group_self_status_set_to_string(Tox_Err_Group_Self_Status_Set value); /** - * Set the client's status for the group instance. Status must be a Tox_User_Status. + * Set the client's status for the group instance. Status must be a + * Tox_User_Status. * * @return true on success. */ @@ -3953,13 +4011,16 @@ Tox_Group_Role tox_group_self_get_role(const Tox *tox, Tox_Group_Number group_nu Tox_Group_Peer_Number tox_group_self_get_peer_id(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_Self_Query *error); /** - * Write the client's group public key designated by the given group number to a byte array. + * Write the client's group public key designated by the given group number to + * a byte array. * - * This key will be permanently tied to the client's identity for this particular group until - * the client explicitly leaves the group. This key is the only way for other peers to reliably - * identify the client across client restarts. + * This key will be permanently tied to the client's identity for this + * particular group until the client explicitly leaves the group. This key is + * the only way for other peers to reliably identify the client across client + * restarts. * - * `public_key` should have room for at least TOX_GROUP_PEER_PUBLIC_KEY_SIZE bytes. + * `public_key` should have room for at least TOX_GROUP_PEER_PUBLIC_KEY_SIZE + * bytes. * * @param public_key A valid memory region large enough to store the public key. * If this parameter is NULL, this function call has no effect. @@ -4000,8 +4061,8 @@ typedef enum Tox_Err_Group_Peer_Query { const char *tox_err_group_peer_query_to_string(Tox_Err_Group_Peer_Query value); /** - * Return the length of the peer's name. If the group number or ID is invalid, the - * return value is unspecified. + * Return the length of the peer's name. If the group number or ID is invalid, + * the return value is unspecified. * * @param group_number The group number of the group we wish to query. * @param peer_id The ID of the peer whose name length we want to retrieve. @@ -4016,7 +4077,8 @@ size_t tox_group_peer_get_name_size(const Tox *tox, Tox_Group_Number group_numbe * Write the name of the peer designated by the given ID to a byte * array. * - * Call tox_group_peer_get_name_size to determine the allocation size for the `name` parameter. + * Call tox_group_peer_get_name_size to determine the allocation size for the + * `name` parameter. * * The data written to `name` is equal to the data received by the last * `group_peer_name` callback. @@ -4045,8 +4107,8 @@ Tox_User_Status tox_group_peer_get_status(const Tox *tox, Tox_Group_Number group Tox_Err_Group_Peer_Query *error); /** - * Return the peer's role (user/moderator/founder...). If the ID or group number is - * invalid, the return value is unspecified. + * Return the peer's role (user/moderator/founder...). If the ID or group number + * is invalid, the return value is unspecified. * * @param group_number The group number of the group we wish to query. * @param peer_id The ID of the peer whose role we wish to query. @@ -4060,8 +4122,9 @@ Tox_Group_Role tox_group_peer_get_role(const Tox *tox, Tox_Group_Number group_nu /** * Return the type of connection we have established with a peer. * - * If `peer_id` designates ourself, the return value indicates whether we're capable - * of making UDP connections with other peers, or are limited to TCP connections. + * If `peer_id` designates ourself, the return value indicates whether we're + * capable of making UDP connections with other peers, or are limited to TCP + * connections. * * @param group_number The group number of the group we wish to query. * @param peer_id The ID of the peer whose connection status we wish to query. @@ -4070,13 +4133,15 @@ Tox_Connection tox_group_peer_get_connection_status(const Tox *tox, Tox_Group_Nu Tox_Err_Group_Peer_Query *error); /** - * Write the group public key with the designated peer_id for the designated group number to public_key. + * Write the group public key with the designated peer_id for the designated + * group number to public_key. * - * This key will be permanently tied to a particular peer until they explicitly leave the group and is - * the only way to reliably identify the same peer across client restarts. + * This key will be permanently tied to a particular peer until they explicitly + * leave the group and is the only way to reliably identify the same peer across + * client restarts. * - * `public_key` should have room for at least TOX_GROUP_PEER_PUBLIC_KEY_SIZE bytes. If `public_key` is null - * this function has no effect. + * `public_key` should have room for at least TOX_GROUP_PEER_PUBLIC_KEY_SIZE + * bytes. If `public_key` is NULL this function has no effect. * * @param group_number The group number of the group we wish to query. * @param peer_id The ID of the peer whose public key we wish to retrieve. @@ -4090,14 +4155,15 @@ bool tox_group_peer_get_public_key( uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Group_Peer_Query *error); /** - * @param group_number The group number of the group the name change is intended for. + * @param group_number The group number of the group the name change is intended + * for. * @param peer_id The ID of the peer who has changed their name. * @param name The name data. - * @param length The length of the name. + * @param name_length The length of the name. */ typedef void tox_group_peer_name_cb( Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, - const uint8_t name[], size_t length, void *user_data); + const uint8_t name[], size_t name_length, void *user_data); /** * Set the callback for the `group_peer_name` event. Pass NULL to unset. @@ -4107,7 +4173,8 @@ typedef void tox_group_peer_name_cb( void tox_callback_group_peer_name(Tox *tox, tox_group_peer_name_cb *callback); /** - * @param group_number The group number of the group the status change is intended for. + * @param group_number The group number of the group the status change is + * intended for. * @param peer_id The ID of the peer who has changed their status. * @param status The new status of the peer. */ @@ -4130,21 +4197,21 @@ void tox_callback_group_peer_status(Tox *tox, tox_group_peer_status_cb *callback /** * General error codes for group state get and size functions. */ -typedef enum Tox_Err_Group_State_Queries { +typedef enum Tox_Err_Group_State_Query { /** * The function returned successfully. */ - TOX_ERR_GROUP_STATE_QUERIES_OK, + TOX_ERR_GROUP_STATE_QUERY_OK, /** * The group number passed did not designate a valid group. */ - TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND, + TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND, -} Tox_Err_Group_State_Queries; +} Tox_Err_Group_State_Query; -const char *tox_err_group_state_queries_to_string(Tox_Err_Group_State_Queries value); +const char *tox_err_group_state_query_to_string(Tox_Err_Group_State_Query value); /** * Error codes for group topic setting. @@ -4172,7 +4239,8 @@ typedef enum Tox_Err_Group_Topic_Set { TOX_ERR_GROUP_TOPIC_SET_PERMISSIONS, /** - * The packet could not be created. This error is usually related to cryptographic signing. + * The packet could not be created. This error is usually related to + * cryptographic signing. */ TOX_ERR_GROUP_TOPIC_SET_FAIL_CREATE, @@ -4193,8 +4261,8 @@ const char *tox_err_group_topic_set_to_string(Tox_Err_Group_Topic_Set value); /** * Set the group topic and broadcast it to the rest of the group. * - * topic length cannot be longer than TOX_GROUP_MAX_TOPIC_LENGTH. If length is equal to zero or - * topic is set to NULL, the topic will be unset. + * Topic length cannot be longer than TOX_GROUP_MAX_TOPIC_LENGTH. If the length + * is equal to zero or topic is set to NULL, the topic will be unset. * * @return true on success. */ @@ -4210,12 +4278,13 @@ bool tox_group_set_topic( * The return value is equal to the `length` argument received by the last * `group_topic` callback. */ -size_t tox_group_get_topic_size(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Queries *error); +size_t tox_group_get_topic_size(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Query *error); /** * Write the topic designated by the given group number to a byte array. * - * Call tox_group_get_topic_size to determine the allocation size for the `topic` parameter. + * Call tox_group_get_topic_size to determine the allocation size for the + * `topic` parameter. * * The data written to `topic` is equal to the data received by the last * `group_topic` callback. @@ -4227,18 +4296,19 @@ size_t tox_group_get_topic_size(const Tox *tox, Tox_Group_Number group_number, T */ bool tox_group_get_topic( const Tox *tox, Tox_Group_Number group_number, - uint8_t topic[], Tox_Err_Group_State_Queries *error); + uint8_t topic[], Tox_Err_Group_State_Query *error); /** - * @param group_number The group number of the group the topic change is intended for. - * @param peer_id The ID of the peer who changed the topic. If the peer who set the topic - * is not present in our peer list this value will be set to 0. + * @param group_number The group number of the group the topic change is + * intended for. + * @param peer_id The ID of the peer who changed the topic. If the peer who set + * the topic is not present in our peer list this value will be set to 0. * @param topic The topic data. - * @param length The topic length. + * @param topic_length The topic length. */ typedef void tox_group_topic_cb( Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, - const uint8_t topic[], size_t length, + const uint8_t topic[], size_t topic_length, void *user_data); /** @@ -4252,12 +4322,14 @@ void tox_callback_group_topic(Tox *tox, tox_group_topic_cb *callback); * Return the length of the group name. If the group number is invalid, the * return value is unspecified. */ -size_t tox_group_get_name_size(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Queries *error); +size_t tox_group_get_name_size(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Query *error); /** - * Write the name of the group designated by the given group number to a byte array. + * Write the name of the group designated by the given group number to a byte + * array. * - * Call tox_group_get_name_size to determine the allocation size for the `name` parameter. + * Call tox_group_get_name_size to determine the allocation size for the `name` + * parameter. * * @param name A valid memory region large enough to store the group name. * If this parameter is NULL, this function call has no effect. @@ -4266,7 +4338,7 @@ size_t tox_group_get_name_size(const Tox *tox, Tox_Group_Number group_number, To */ bool tox_group_get_name( const Tox *tox, Tox_Group_Number group_number, - uint8_t name[], Tox_Err_Group_State_Queries *error); + uint8_t name[], Tox_Err_Group_State_Query *error); /** * Write the Chat ID designated by the given group number to a byte array. @@ -4280,7 +4352,7 @@ bool tox_group_get_name( */ bool tox_group_get_chat_id( const Tox *tox, Tox_Group_Number group_number, uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE], - Tox_Err_Group_State_Queries *error); + Tox_Err_Group_State_Query *error); /** * Return the number of groups in the Tox chats array. @@ -4288,19 +4360,21 @@ bool tox_group_get_chat_id( uint32_t tox_group_get_number_groups(const Tox *tox); /** - * Return the privacy state of the group designated by the given group number. If group number - * is invalid, the return value is unspecified. + * Return the privacy state of the group designated by the given group number. + * If group number is invalid, the return value is unspecified. * * The value returned is equal to the data received by the last * `group_privacy_state` callback. * - * @see the `Group chat founder controls` section for the respective set function. + * @see the `Group chat Founder controls` section for the respective set + * function. */ Tox_Group_Privacy_State tox_group_get_privacy_state(const Tox *tox, Tox_Group_Number group_number, - Tox_Err_Group_State_Queries *error); + Tox_Err_Group_State_Query *error); /** - * @param group_number The group number of the group the privacy state is intended for. + * @param group_number The group number of the group the privacy state is + * intended for. * @param privacy_state The new privacy state. */ typedef void tox_group_privacy_state_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Privacy_State privacy_state, @@ -4314,18 +4388,21 @@ typedef void tox_group_privacy_state_cb(Tox *tox, Tox_Group_Number group_number, void tox_callback_group_privacy_state(Tox *tox, tox_group_privacy_state_cb *callback); /** - * Return the voice state of the group designated by the given group number. If group number - * is invalid, the return value is unspecified. + * Return the voice state of the group designated by the given group number. If + * group number is invalid, the return value is unspecified. * - * The value returned is equal to the data received by the last `group_voice_state` callback. + * The value returned is equal to the data received by the last + * `group_voice_state` callback. * - * @see the `Group chat founder controls` section for the respective set function. + * @see the `Group chat Founder controls` section for the respective set + * function. */ Tox_Group_Voice_State tox_group_get_voice_state(const Tox *tox, Tox_Group_Number group_number, - Tox_Err_Group_State_Queries *error); + Tox_Err_Group_State_Query *error); /** - * @param group_number The group number of the group the voice state change is intended for. + * @param group_number The group number of the group the voice state change is + * intended for. * @param voice_state The new voice state. */ typedef void tox_group_voice_state_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Voice_State voice_state, @@ -4339,19 +4416,22 @@ typedef void tox_group_voice_state_cb(Tox *tox, Tox_Group_Number group_number, T void tox_callback_group_voice_state(Tox *tox, tox_group_voice_state_cb *callback); /** - * Return the topic lock status of the group designated by the given group number. If group number + * Return the topic lock status of the group designated by the given group + * number. If group number * is invalid, the return value is unspecified. * * The value returned is equal to the data received by the last * `group_topic_lock` callback. * - * @see the `Group chat founder contols` section for the respective set function. + * @see the `Group chat Founder controls` section for the respective set + * function. */ Tox_Group_Topic_Lock tox_group_get_topic_lock(const Tox *tox, Tox_Group_Number group_number, - Tox_Err_Group_State_Queries *error); + Tox_Err_Group_State_Query *error); /** - * @param group_number The group number of the group for which the topic lock has changed. + * @param group_number The group number of the group for which the topic lock + * has changed. * @param topic_lock The new topic lock state. */ typedef void tox_group_topic_lock_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Topic_Lock topic_lock, void *user_data); @@ -4364,18 +4444,21 @@ typedef void tox_group_topic_lock_cb(Tox *tox, Tox_Group_Number group_number, To void tox_callback_group_topic_lock(Tox *tox, tox_group_topic_lock_cb *callback); /** - * Return the maximum number of peers allowed for the group designated by the given group number. - * If the group number is invalid, the return value is unspecified. + * Return the maximum number of peers allowed for the group designated by the + * given group number. If the group number is invalid, the return value is + * unspecified. * * The value returned is equal to the data received by the last * `group_peer_limit` callback. * - * @see the `Group chat founder controls` section for the respective set function. + * @see the `Group chat Founder controls` section for the respective set + * function. */ -uint16_t tox_group_get_peer_limit(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Queries *error); +uint16_t tox_group_get_peer_limit(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Query *error); /** - * @param group_number The group number of the group for which the peer limit has changed. + * @param group_number The group number of the group for which the peer limit + * has changed. * @param peer_limit The new peer limit for the group. */ typedef void tox_group_peer_limit_cb(Tox *tox, Tox_Group_Number group_number, uint32_t peer_limit, void *user_data); @@ -4383,7 +4466,8 @@ typedef void tox_group_peer_limit_cb(Tox *tox, Tox_Group_Number group_number, ui /** * Set the callback for the `group_peer_limit` event. Pass NULL to unset. * - * This event is triggered when the group founder changes the maximum peer limit. + * This event is triggered when the group founder changes the maximum peer + * limit. */ void tox_callback_group_peer_limit(Tox *tox, tox_group_peer_limit_cb *callback); @@ -4391,35 +4475,39 @@ void tox_callback_group_peer_limit(Tox *tox, tox_group_peer_limit_cb *callback); * Return the length of the group password. If the group number is invalid, the * return value is unspecified. */ -size_t tox_group_get_password_size(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Queries *error); +size_t tox_group_get_password_size(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Query *error); /** - * Write the password for the group designated by the given group number to a byte array. + * Write the password for the group designated by the given group number to a + * byte array. * - * Call tox_group_get_password_size to determine the allocation size for the `password` parameter. + * Call tox_group_get_password_size to determine the allocation size for the + * `password` parameter. * - * The data received is equal to the data received by the last - * `group_password` callback. + * The data received is equal to the data received by the last `group_password` + * callback. * - * @see the `Group chat founder controls` section for the respective set function. + * @see the `Group chat Founder controls` section for the respective set + * function. * - * @param password A valid memory region large enough to store the group password. - * If this parameter is NULL, this function call has no effect. + * @param password A valid memory region large enough to store the group + * password. If this parameter is NULL, this function call has no effect. * * @return true on success. */ bool tox_group_get_password( const Tox *tox, Tox_Group_Number group_number, uint8_t password[], - Tox_Err_Group_State_Queries *error); + Tox_Err_Group_State_Query *error); /** - * @param group_number The group number of the group for which the password has changed. + * @param group_number The group number of the group for which the password has + * changed. * @param password The new group password. - * @param length The length of the password. + * @param password_length The length of the password. */ typedef void tox_group_password_cb( Tox *tox, Tox_Group_Number group_number, - const uint8_t password[], size_t length, + const uint8_t password[], size_t password_length, void *user_data); /** @@ -4453,7 +4541,7 @@ typedef enum Tox_Err_Group_Send_Message { TOX_ERR_GROUP_SEND_MESSAGE_TOO_LONG, /** - * The message pointer is null or length is zero. + * The message pointer is NULL or length is zero. */ TOX_ERR_GROUP_SEND_MESSAGE_EMPTY, @@ -4487,12 +4575,13 @@ const char *tox_err_group_send_message_to_string(Tox_Err_Group_Send_Message valu * This function creates a group message packet and pushes it into the send * queue. * - * The message length may not exceed TOX_GROUP_MAX_MESSAGE_LENGTH. Larger messages - * must be split by the client and sent as separate messages. Other clients can - * then reassemble the fragments. Messages may not be empty. + * The message length may not exceed TOX_GROUP_MAX_MESSAGE_LENGTH. Larger + * messages must be split by the client and sent as separate messages. Other + * clients can then reassemble the fragments. Messages may not be empty. * - * @param group_number The group number of the group the message is intended for. - * @param type Message type (normal, action, ...). + * @param group_number The group number of the group the message is intended + * for. + * @param message_type Message type (normal, action, ...). * @param message A non-NULL pointer to the first element of a byte array * containing the message text. * @param length Length of the message to be sent. @@ -4501,7 +4590,7 @@ const char *tox_err_group_send_message_to_string(Tox_Err_Group_Send_Message valu * returned message ID value will be undefined. */ Tox_Group_Message_Id tox_group_send_message( - const Tox *tox, Tox_Group_Number group_number, Tox_Message_Type type, + const Tox *tox, Tox_Group_Number group_number, Tox_Message_Type message_type, const uint8_t message[], size_t length, Tox_Err_Group_Send_Message *error); @@ -4528,11 +4617,16 @@ typedef enum Tox_Err_Group_Send_Private_Message { TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_TOO_LONG, /** - * The message pointer is null or length is zero. + * The message pointer is NULL or length is zero. */ TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_EMPTY, /** + * The message type is invalid. + */ + TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_BAD_TYPE, + + /** * The caller does not have the required permissions to send group messages. */ TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PERMISSIONS, @@ -4547,11 +4641,6 @@ typedef enum Tox_Err_Group_Send_Private_Message { */ TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_DISCONNECTED, - /** - * The message type is invalid. - */ - TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_BAD_TYPE, - } Tox_Err_Group_Send_Private_Message; const char *tox_err_group_send_private_message_to_string(Tox_Err_Group_Send_Private_Message value); @@ -4559,23 +4648,25 @@ const char *tox_err_group_send_private_message_to_string(Tox_Err_Group_Send_Priv /** * Send a text chat message to the specified peer in the specified group. * - * This function creates a group private message packet and pushes it into the send - * queue. + * This function creates a group private message packet and pushes it into the + * send queue. * - * The message length may not exceed TOX_GROUP_MAX_MESSAGE_LENGTH. Larger messages - * must be split by the client and sent as separate messages. Other clients can - * then reassemble the fragments. Messages may not be empty. + * The message length may not exceed TOX_GROUP_MAX_MESSAGE_LENGTH. Larger + * messages must be split by the client and sent as separate messages. Other + * clients can then reassemble the fragments. Messages may not be empty. * - * @param group_number The group number of the group the message is intended for. + * @param group_number The group number of the group the message is intended + * for. * @param peer_id The ID of the peer the message is intended for. + * @param message_type The type of message (normal, action, ...). * @param message A non-NULL pointer to the first element of a byte array * containing the message text. * @param length Length of the message to be sent. * * @return true on success. */ -bool tox_group_send_private_message( - const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, +Tox_Group_Message_Id tox_group_send_private_message( + const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type message_type, const uint8_t message[], size_t length, Tox_Err_Group_Send_Private_Message *error); @@ -4599,16 +4690,11 @@ typedef enum Tox_Err_Group_Send_Custom_Packet { TOX_ERR_GROUP_SEND_CUSTOM_PACKET_TOO_LONG, /** - * The message pointer is null or length is zero. + * The message pointer is NULL or length is zero. */ TOX_ERR_GROUP_SEND_CUSTOM_PACKET_EMPTY, /** - * The caller does not have the required permissions to send group messages. - */ - TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS, - - /** * The group is disconnected. */ TOX_ERR_GROUP_SEND_CUSTOM_PACKET_DISCONNECTED, @@ -4626,15 +4712,17 @@ const char *tox_err_group_send_custom_packet_to_string(Tox_Err_Group_Send_Custom /** * Send a custom packet to the group. * - * If lossless is true the packet will be lossless. Lossless packet behaviour is comparable - * to TCP (reliability, arrive in order) but with packets instead of a stream. + * If lossless is true the packet will be lossless. Lossless packet behaviour is + * comparable to TCP (reliability, arrive in order) but with packets instead of + * a stream. * - * If lossless is false, the packet will be lossy. Lossy packets behave like UDP packets, - * meaning they might never reach the other side or might arrive more than once (if someone - * is messing with the connection) or might arrive in the wrong order. + * If lossless is false, the packet will be lossy. Lossy packets behave like UDP + * packets, meaning they might never reach the other side or might arrive more + * than once (if someone is messing with the connection) or might arrive in the + * wrong order. * - * Unless latency is an issue or message reliability is not important, it is recommended that you use - * lossless packets. + * Unless latency is an issue or message reliability is not important, it is + * recommended that you use lossless packets. * * The message length may not exceed TOX_MAX_CUSTOM_PACKET_SIZE. Larger packets * must be split by the client and sent as separate packets. Other clients can @@ -4672,7 +4760,7 @@ typedef enum Tox_Err_Group_Send_Custom_Private_Packet { TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_TOO_LONG, /** - * The message pointer is null or length is zero. + * The message pointer is NULL or length is zero. */ TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_EMPTY, @@ -4682,11 +4770,6 @@ typedef enum Tox_Err_Group_Send_Custom_Private_Packet { TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PEER_NOT_FOUND, /** - * The caller does not have the required permissions to send group messages. - */ - TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS, - - /** * The packet failed to send. */ TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_FAIL_SEND, @@ -4703,15 +4786,17 @@ const char *tox_err_group_send_custom_private_packet_to_string(Tox_Err_Group_Sen /** * Send a custom private packet to a designated peer in the group. * - * If lossless is true the packet will be lossless. Lossless packet behaviour is comparable - * to TCP (reliability, arrive in order) but with packets instead of a stream. + * If lossless is true the packet will be lossless. Lossless packet behaviour is + * comparable to TCP (reliability, arrive in order) but with packets instead of + * a stream. * - * If lossless is false, the packet will be lossy. Lossy packets behave like UDP packets, - * meaning they might never reach the other side or might arrive more than once (if someone - * is messing with the connection) or might arrive in the wrong order. + * If lossless is false, the packet will be lossy. Lossy packets behave like UDP + * packets, meaning they might never reach the other side or might arrive more + * than once (if someone is messing with the connection) or might arrive in the + * wrong order. * - * Unless latency is an issue or message reliability is not important, it is recommended that you use - * lossless packets. + * Unless latency is an issue or message reliability is not important, it is + * recommended that you use lossless packets. * * The packet length may not exceed TOX_MAX_CUSTOM_PACKET_SIZE. Larger packets * must be split by the client and sent as separate packets. Other clients can @@ -4736,16 +4821,18 @@ bool tox_group_send_custom_private_packet(const Tox *tox, Tox_Group_Number group ******************************************************************************/ /** - * @param group_number The group number of the group the message is intended for. + * @param group_number The group number of the group the message is intended + * for. * @param peer_id The ID of the peer who sent the message. - * @param type The type of message (normal, action, ...). + * @param message_type The type of message (normal, action, ...). * @param message The message data. - * @param message_id A pseudo message id that clients can use to uniquely identify this group message. - * @param length The length of the message. + * @param message_length The length of the message. + * @param message_id A pseudo message id that clients can use to uniquely + * identify this group message. */ typedef void tox_group_message_cb( - Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, - const uint8_t message[], size_t length, Tox_Group_Message_Id message_id, void *user_data); + Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type message_type, + const uint8_t message[], size_t message_length, Tox_Group_Message_Id message_id, void *user_data); /** * Set the callback for the `group_message` event. Pass NULL to unset. @@ -4755,14 +4842,18 @@ typedef void tox_group_message_cb( void tox_callback_group_message(Tox *tox, tox_group_message_cb *callback); /** - * @param group_number The group number of the group the private message is intended for. + * @param group_number The group number of the group the private message is + * intended for. * @param peer_id The ID of the peer who sent the private message. + * @param message_type The type of message (normal, action, ...). * @param message The message data. - * @param length The length of the message. + * @param message_length The length of the message. + * @param message_id A pseudo message id that clients can use to uniquely + * identify this group message. */ typedef void tox_group_private_message_cb( - Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, - const uint8_t message[], size_t length, void *user_data); + Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type message_type, + const uint8_t message[], size_t message_length, Tox_Group_Message_Id message_id, void *user_data); /** * Set the callback for the `group_private_message` event. Pass NULL to unset. @@ -4775,11 +4866,11 @@ void tox_callback_group_private_message(Tox *tox, tox_group_private_message_cb * * @param group_number The group number of the group the packet is intended for. * @param peer_id The ID of the peer who sent the packet. * @param data The packet data. - * @param length The length of the data. + * @param data_length The length of the data. */ typedef void tox_group_custom_packet_cb( Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, - const uint8_t data[], size_t length, void *user_data); + const uint8_t data[], size_t data_length, void *user_data); /** * Set the callback for the `group_custom_packet` event. Pass NULL to unset. @@ -4792,14 +4883,15 @@ void tox_callback_group_custom_packet(Tox *tox, tox_group_custom_packet_cb *call * @param group_number The group number of the group the packet is intended for. * @param peer_id The ID of the peer who sent the packet. * @param data The packet data. - * @param length The length of the data. + * @param data_length The length of the data. */ typedef void tox_group_custom_private_packet_cb( Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, - const uint8_t data[], size_t length, void *user_data); + const uint8_t data[], size_t data_length, void *user_data); /** - * Set the callback for the `group_custom_private_packet` event. Pass NULL to unset. + * Set the callback for the `group_custom_private_packet` event. Pass NULL to + * unset. * * This event is triggered when the client receives a custom private packet. */ @@ -4829,7 +4921,8 @@ typedef enum Tox_Err_Group_Invite_Friend { TOX_ERR_GROUP_INVITE_FRIEND_FRIEND_NOT_FOUND, /** - * Creation of the invite packet failed. This indicates a network related error. + * Creation of the invite packet failed. This indicates a network related + * error. */ TOX_ERR_GROUP_INVITE_FRIEND_INVITE_FAIL, @@ -4850,10 +4943,13 @@ const char *tox_err_group_invite_friend_to_string(Tox_Err_Group_Invite_Friend va /** * Invite a friend to a group. * - * This function creates an invite request packet and pushes it to the send queue. + * This function creates an invite request packet and pushes it to the send + * queue. * - * @param group_number The group number of the group the message is intended for. - * @param friend_number The friend number of the friend the invite is intended for. + * @param group_number The group number of the group the message is intended + * for. + * @param friend_number The friend number of the friend the invite is intended + * for. * * @return true on success. */ @@ -4889,36 +4985,44 @@ typedef enum Tox_Err_Group_Invite_Accept { TOX_ERR_GROUP_INVITE_ACCEPT_EMPTY, /** - * Failed to set password. This usually occurs if the password exceeds TOX_GROUP_MAX_PASSWORD_SIZE. + * Failed to set password. This usually occurs if the password exceeds + * TOX_GROUP_MAX_PASSWORD_SIZE. */ TOX_ERR_GROUP_INVITE_ACCEPT_PASSWORD, /** - * There was a core error when initiating the group. + * The friend number passed did not designate a valid friend. */ - TOX_ERR_GROUP_INVITE_ACCEPT_CORE, + TOX_ERR_GROUP_INVITE_ACCEPT_FRIEND_NOT_FOUND, /** * Packet failed to send. */ TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND, + /** + * Invite data or name is NULL. + */ + TOX_ERR_GROUP_INVITE_ACCEPT_NULL, + } Tox_Err_Group_Invite_Accept; const char *tox_err_group_invite_accept_to_string(Tox_Err_Group_Invite_Accept value); /** - * Accept an invite to a group chat that the client previously received from a friend. The invite - * is only valid while the inviter is present in the group. + * Accept an invite to a group chat that the client previously received from a + * friend. The invite is only valid while the inviter is present in the group. * * @param invite_data The invite data received from the `group_invite` event. * @param length The length of the invite data. * @param name The name of the peer joining the group. - * @param name_length The length of the peer's name. This must be greater than zero and no larger - * than TOX_MAX_NAME_LENGTH. - * @param password The password required to join the group. Set to NULL if no password is required. - * @param password_length The length of the password. If password_length is equal to zero, the password - * parameter will be ignored. password_length must be no larger than TOX_GROUP_MAX_PASSWORD_SIZE. + * @param name_length The length of the peer's name. This must be greater than + * zero and no larger than TOX_MAX_NAME_LENGTH. + * @param password The password required to join the group. Set to NULL if no + * password is required. + * @param password_length The length of the password. If password_length is + * equal to zero, the password parameter will be ignored. password_length + * must be no larger than TOX_GROUP_MAX_PASSWORD_SIZE. * * @return the group_number on success, UINT32_MAX on failure. */ @@ -4932,26 +5036,30 @@ Tox_Group_Number tox_group_invite_accept( /** * @param friend_number The friend number of the contact who sent the invite. * @param invite_data The invite data. - * @param length The length of invite_data. + * @param invite_data_length The length of invite_data. + * @param group_name The name of the group. In conferences, this is "title". + * @param group_name_length The length of the group name. */ typedef void tox_group_invite_cb( Tox *tox, Tox_Friend_Number friend_number, - const uint8_t invite_data[], size_t length, + const uint8_t invite_data[], size_t invite_data_length, const uint8_t group_name[], size_t group_name_length, void *user_data); /** * Set the callback for the `group_invite` event. Pass NULL to unset. * - * This event is triggered when the client receives a group invite from a friend. The client must store - * invite_data which is used to join the group via tox_group_invite_accept. + * This event is triggered when the client receives a group invite from a + * friend. The client must store invite_data which is used to join the group + * via tox_group_invite_accept. */ void tox_callback_group_invite(Tox *tox, tox_group_invite_cb *callback); /** - * @param group_number The group number of the group in which a new peer has joined. - * @param peer_id The permanent ID of the new peer. This id should not be relied on for - * client behaviour and should be treated as a random value. + * @param group_number The group number of the group in which a new peer has + * joined. + * @param peer_id The permanent ID of the new peer. This id should not be relied + * on for client behaviour and should be treated as a random value. */ typedef void tox_group_peer_join_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, void *user_data); @@ -4963,7 +5071,8 @@ typedef void tox_group_peer_join_cb(Tox *tox, Tox_Group_Number group_number, Tox void tox_callback_group_peer_join(Tox *tox, tox_group_peer_join_cb *callback); /** - * Represents peer exit events. These should be used with the `group_peer_exit` event. + * Represents peer exit events. These should be used with the `group_peer_exit` + * event. */ typedef enum Tox_Group_Exit_Type { @@ -4983,8 +5092,9 @@ typedef enum Tox_Group_Exit_Type { TOX_GROUP_EXIT_TYPE_DISCONNECTED, /** - * Your connection with all peers has been severed. This will occur when you are kicked from - * a group, rejoin a group, or manually disconnect from a group. + * Your connection with all peers has been severed. This will occur when you + * are kicked from a group, rejoin a group, or manually disconnect from a + * group. */ TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED, @@ -5004,8 +5114,8 @@ const char *tox_group_exit_type_to_string(Tox_Group_Exit_Type value); /** * @param group_number The group number of the group in which a peer has left. - * @param peer_id The ID of the peer who left the group. This ID no longer designates a valid peer - * and cannot be used for API calls. + * @param peer_id The ID of the peer who left the group. This ID no longer + * designates a valid peer and cannot be used for API calls. * @param exit_type The type of exit event. One of Tox_Group_Exit_Type. * @param name The nickname of the peer who left the group. * @param name_length The length of the peer name. @@ -5032,14 +5142,14 @@ typedef void tox_group_self_join_cb(Tox *tox, Tox_Group_Number group_number, voi /** * Set the callback for the `group_self_join` event. Pass NULL to unset. * - * This event is triggered when the client has successfully joined a group. Use this to initialize - * any group information the client may need. + * This event is triggered when the client has successfully joined a group. Use + * this to initialize any group information the client may need. */ void tox_callback_group_self_join(Tox *tox, tox_group_self_join_cb *callback); /** - * Represents types of failed group join attempts. These are used in the tox_callback_group_rejected - * callback when a peer fails to join a group. + * Represents types of failed group join attempts. These are used in the + * tox_callback_group_rejected callback when a peer fails to join a group. */ typedef enum Tox_Group_Join_Fail { @@ -5054,8 +5164,8 @@ typedef enum Tox_Group_Join_Fail { TOX_GROUP_JOIN_FAIL_INVALID_PASSWORD, /** - * The join attempt failed due to an unspecified error. This often occurs when the group is - * not found in the DHT. + * The join attempt failed due to an unspecified error. This often occurs + * when the group is not found in the DHT. */ TOX_GROUP_JOIN_FAIL_UNKNOWN, @@ -5064,7 +5174,8 @@ typedef enum Tox_Group_Join_Fail { const char *tox_group_join_fail_to_string(Tox_Group_Join_Fail value); /** - * @param group_number The group number of the group for which the join has failed. + * @param group_number The group number of the group for which the join has + * failed. * @param fail_type The type of group rejection. */ typedef void tox_group_join_fail_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Join_Fail fail_type, void *user_data); @@ -5078,289 +5189,306 @@ void tox_callback_group_join_fail(Tox *tox, tox_group_join_fail_cb *callback); /******************************************************************************* * - * :: Group chat founder controls (these only work for the group founder) + * :: Group chat Founder controls * ******************************************************************************/ -typedef enum Tox_Err_Group_Founder_Set_Password { +typedef enum Tox_Err_Group_Set_Password { /** * The function returned successfully. */ - TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK, + TOX_ERR_GROUP_SET_PASSWORD_OK, /** * The group number passed did not designate a valid group. */ - TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_GROUP_NOT_FOUND, + TOX_ERR_GROUP_SET_PASSWORD_GROUP_NOT_FOUND, /** * The caller does not have the required permissions to set the password. */ - TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_PERMISSIONS, + TOX_ERR_GROUP_SET_PASSWORD_PERMISSIONS, /** * Password length exceeded TOX_GROUP_MAX_PASSWORD_SIZE. */ - TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_TOO_LONG, + TOX_ERR_GROUP_SET_PASSWORD_TOO_LONG, /** * The packet failed to send. */ - TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_FAIL_SEND, + TOX_ERR_GROUP_SET_PASSWORD_FAIL_SEND, /** * The function failed to allocate enough memory for the operation. */ - TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_MALLOC, + TOX_ERR_GROUP_SET_PASSWORD_MALLOC, /** * The group is disconnected. */ - TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_DISCONNECTED, + TOX_ERR_GROUP_SET_PASSWORD_DISCONNECTED, -} Tox_Err_Group_Founder_Set_Password; +} Tox_Err_Group_Set_Password; -const char *tox_err_group_founder_set_password_to_string(Tox_Err_Group_Founder_Set_Password value); +const char *tox_err_group_set_password_to_string(Tox_Err_Group_Set_Password value); /** * Set or unset the group password. * - * This function sets the groups password, creates a new group shared state including the change, - * and distributes it to the rest of the group. + * This function allows Founders to set or unset a group password. It will + * create a new group shared state including the change and distribute it to the + * rest of the group. * - * @param group_number The group number of the group for which we wish to set the password. - * @param password The password we want to set. Set password to NULL to unset the password. - * @param length The length of the password. length must be no longer than TOX_GROUP_MAX_PASSWORD_SIZE. + * @param group_number The group number of the group for which we wish to set + * the password. + * @param password The password we want to set. Set password to NULL to unset + * the password. + * @param length The length of the password. length must be no longer than + * TOX_GROUP_MAX_PASSWORD_SIZE. * * @return true on success. */ -bool tox_group_founder_set_password( +bool tox_group_set_password( Tox *tox, Tox_Group_Number group_number, const uint8_t password[], size_t length, - Tox_Err_Group_Founder_Set_Password *error); + Tox_Err_Group_Set_Password *error); -typedef enum Tox_Err_Group_Founder_Set_Topic_Lock { +typedef enum Tox_Err_Group_Set_Topic_Lock { /** * The function returned successfully. */ - TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK, + TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, /** * The group number passed did not designate a valid group. */ - TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_GROUP_NOT_FOUND, + TOX_ERR_GROUP_SET_TOPIC_LOCK_GROUP_NOT_FOUND, /** * Tox_Group_Topic_Lock is an invalid type. */ - TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_INVALID, + TOX_ERR_GROUP_SET_TOPIC_LOCK_INVALID, /** * The caller does not have the required permissions to set the topic lock. */ - TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_PERMISSIONS, + TOX_ERR_GROUP_SET_TOPIC_LOCK_PERMISSIONS, /** - * The topic lock could not be set. This may occur due to an error related to - * cryptographic signing of the new shared state. + * The topic lock could not be set. This may occur due to an error related + * to cryptographic signing of the new shared state. */ - TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_FAIL_SET, + TOX_ERR_GROUP_SET_TOPIC_LOCK_FAIL_SET, /** * The packet failed to send. */ - TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_FAIL_SEND, + TOX_ERR_GROUP_SET_TOPIC_LOCK_FAIL_SEND, /** * The group is disconnected. */ - TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_DISCONNECTED, + TOX_ERR_GROUP_SET_TOPIC_LOCK_DISCONNECTED, -} Tox_Err_Group_Founder_Set_Topic_Lock; +} Tox_Err_Group_Set_Topic_Lock; -const char *tox_err_group_founder_set_topic_lock_to_string(Tox_Err_Group_Founder_Set_Topic_Lock value); +const char *tox_err_group_set_topic_lock_to_string(Tox_Err_Group_Set_Topic_Lock value); /** * Set the group topic lock state. * - * This function sets the group's topic lock state to enabled or disabled, creates a new shared - * state including the change, and distributes it to the rest of the group. + * This function allows Founders to enable or disable the group's topic lock. It + * will create a new shared state including the change and distribute it to the + * rest of the group. * - * When the topic lock is enabled, only the group founder and moderators may set the topic. - * When disabled, all peers except those with the observer role may set the topic. + * When the topic lock is enabled, only the group founder and moderators may set + * the topic. When disabled, all peers except those with the observer role may + * set the topic. * - * @param group_number The group number of the group for which we wish to change the topic lock state. + * @param group_number The group number of the group for which we wish to change + * the topic lock state. * @param topic_lock The state we wish to set the topic lock to. * * @return true on success. */ -bool tox_group_founder_set_topic_lock(Tox *tox, Tox_Group_Number group_number, Tox_Group_Topic_Lock topic_lock, - Tox_Err_Group_Founder_Set_Topic_Lock *error); +bool tox_group_set_topic_lock(Tox *tox, Tox_Group_Number group_number, Tox_Group_Topic_Lock topic_lock, + Tox_Err_Group_Set_Topic_Lock *error); -typedef enum Tox_Err_Group_Founder_Set_Voice_State { +typedef enum Tox_Err_Group_Set_Voice_State { /** * The function returned successfully. */ - TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK, + TOX_ERR_GROUP_SET_VOICE_STATE_OK, /** * The group number passed did not designate a valid group. */ - TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_GROUP_NOT_FOUND, + TOX_ERR_GROUP_SET_VOICE_STATE_GROUP_NOT_FOUND, /** - * The caller does not have the required permissions to set the privacy state. + * The caller does not have the required permissions to set the privacy + * state. */ - TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_PERMISSIONS, + TOX_ERR_GROUP_SET_VOICE_STATE_PERMISSIONS, /** - * The voice state could not be set. This may occur due to an error related to - * cryptographic signing of the new shared state. + * The voice state could not be set. This may occur due to an error related + * to cryptographic signing of the new shared state. */ - TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_FAIL_SET, + TOX_ERR_GROUP_SET_VOICE_STATE_FAIL_SET, /** * The packet failed to send. */ - TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_FAIL_SEND, + TOX_ERR_GROUP_SET_VOICE_STATE_FAIL_SEND, /** * The group is disconnected. */ - TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_DISCONNECTED, + TOX_ERR_GROUP_SET_VOICE_STATE_DISCONNECTED, -} Tox_Err_Group_Founder_Set_Voice_State; +} Tox_Err_Group_Set_Voice_State; -const char *tox_err_group_founder_set_voice_state_to_string(Tox_Err_Group_Founder_Set_Voice_State value); +const char *tox_err_group_set_voice_state_to_string(Tox_Err_Group_Set_Voice_State value); /** * Set the group voice state. * - * This function sets the group's voice state, creates a new group shared state - * including the change, and distributes it to the rest of the group. + * This function allows Founders to set the group's voice state. It will create + * a new group shared state including the change and distribute it to the rest + * of the group. * - * If an attempt is made to set the voice state to the same state that the group is already - * in, the function call will be successful and no action will be taken. + * If an attempt is made to set the voice state to the same state that the group + * is already in, the function call will be successful and no action will be + * taken. * - * @param group_number The group number of the group for which we wish to change the voice state. + * @param group_number The group number of the group for which we wish to change + * the voice state. * @param voice_state The voice state we wish to set the group to. * * @return true on success. */ -bool tox_group_founder_set_voice_state(Tox *tox, Tox_Group_Number group_number, Tox_Group_Voice_State voice_state, - Tox_Err_Group_Founder_Set_Voice_State *error); +bool tox_group_set_voice_state(Tox *tox, Tox_Group_Number group_number, Tox_Group_Voice_State voice_state, + Tox_Err_Group_Set_Voice_State *error); -typedef enum Tox_Err_Group_Founder_Set_Privacy_State { +typedef enum Tox_Err_Group_Set_Privacy_State { /** * The function returned successfully. */ - TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK, + TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, /** * The group number passed did not designate a valid group. */ - TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_GROUP_NOT_FOUND, + TOX_ERR_GROUP_SET_PRIVACY_STATE_GROUP_NOT_FOUND, /** - * The caller does not have the required permissions to set the privacy state. + * The caller does not have the required permissions to set the privacy + * state. */ - TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_PERMISSIONS, + TOX_ERR_GROUP_SET_PRIVACY_STATE_PERMISSIONS, /** - * The privacy state could not be set. This may occur due to an error related to - * cryptographic signing of the new shared state. + * The privacy state could not be set. This may occur due to an error + * related to cryptographic signing of the new shared state. */ - TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_FAIL_SET, + TOX_ERR_GROUP_SET_PRIVACY_STATE_FAIL_SET, /** * The packet failed to send. */ - TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_FAIL_SEND, + TOX_ERR_GROUP_SET_PRIVACY_STATE_FAIL_SEND, /** * The group is disconnected. */ - TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_DISCONNECTED, + TOX_ERR_GROUP_SET_PRIVACY_STATE_DISCONNECTED, -} Tox_Err_Group_Founder_Set_Privacy_State; +} Tox_Err_Group_Set_Privacy_State; -const char *tox_err_group_founder_set_privacy_state_to_string(Tox_Err_Group_Founder_Set_Privacy_State value); +const char *tox_err_group_set_privacy_state_to_string(Tox_Err_Group_Set_Privacy_State value); /** * Set the group privacy state. * - * This function sets the group's privacy state, creates a new group shared state - * including the change, and distributes it to the rest of the group. + * This function allows Founders to set the group's privacy state. It will + * create a new group shared state including the change and distribute it to the + * rest of the group. * - * If an attempt is made to set the privacy state to the same state that the group is already - * in, the function call will be successful and no action will be taken. + * If an attempt is made to set the privacy state to the same state that the + * group is already in, the function call will be successful and no action will + * be taken. * - * @param group_number The group number of the group for which we wish to change the privacy state. + * @param group_number The group number of the group for which we wish to change + * the privacy state. * @param privacy_state The privacy state we wish to set the group to. * * @return true on success. */ -bool tox_group_founder_set_privacy_state(Tox *tox, Tox_Group_Number group_number, Tox_Group_Privacy_State privacy_state, - Tox_Err_Group_Founder_Set_Privacy_State *error); +bool tox_group_set_privacy_state(Tox *tox, Tox_Group_Number group_number, Tox_Group_Privacy_State privacy_state, + Tox_Err_Group_Set_Privacy_State *error); -typedef enum Tox_Err_Group_Founder_Set_Peer_Limit { +typedef enum Tox_Err_Group_Set_Peer_Limit { /** * The function returned successfully. */ - TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK, + TOX_ERR_GROUP_SET_PEER_LIMIT_OK, /** * The group number passed did not designate a valid group. */ - TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_GROUP_NOT_FOUND, + TOX_ERR_GROUP_SET_PEER_LIMIT_GROUP_NOT_FOUND, /** * The caller does not have the required permissions to set the peer limit. */ - TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_PERMISSIONS, + TOX_ERR_GROUP_SET_PEER_LIMIT_PERMISSIONS, /** - * The peer limit could not be set. This may occur due to an error related to - * cryptographic signing of the new shared state. + * The peer limit could not be set. This may occur due to an error related + * to cryptographic signing of the new shared state. */ - TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_FAIL_SET, + TOX_ERR_GROUP_SET_PEER_LIMIT_FAIL_SET, /** * The packet failed to send. */ - TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_FAIL_SEND, + TOX_ERR_GROUP_SET_PEER_LIMIT_FAIL_SEND, /** * The group is disconnected. */ - TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_DISCONNECTED, + TOX_ERR_GROUP_SET_PEER_LIMIT_DISCONNECTED, -} Tox_Err_Group_Founder_Set_Peer_Limit; +} Tox_Err_Group_Set_Peer_Limit; -const char *tox_err_group_founder_set_peer_limit_to_string(Tox_Err_Group_Founder_Set_Peer_Limit value); +const char *tox_err_group_set_peer_limit_to_string(Tox_Err_Group_Set_Peer_Limit value); /** * Set the group peer limit. * - * This function sets a limit for the number of peers who may be in the group, creates a new - * group shared state including the change, and distributes it to the rest of the group. + * This function allows Founders to set a limit for the number of peers who may + * be in the group. It will create a new group shared state including the change + * and distribute it to the rest of the group. * - * @param group_number The group number of the group for which we wish to set the peer limit. + * @param group_number The group number of the group for which we wish to set + * the peer limit. * @param peer_limit The maximum number of peers to allow in the group. * * @return true on success. */ -bool tox_group_founder_set_peer_limit(Tox *tox, Tox_Group_Number group_number, uint16_t peer_limit, - Tox_Err_Group_Founder_Set_Peer_Limit *error); +bool tox_group_set_peer_limit(Tox *tox, Tox_Group_Number group_number, uint16_t peer_limit, + Tox_Err_Group_Set_Peer_Limit *error); /******************************************************************************* * - * :: Group chat moderation + * :: Group chat moderation controls * ******************************************************************************/ @@ -5393,7 +5521,8 @@ const char *tox_err_group_set_ignore_to_string(Tox_Err_Group_Set_Ignore value); /** * Ignore or unignore a peer. * - * @param group_number The group number of the group in which you wish to ignore a peer. + * @param group_number The group number of the group in which you wish to ignore + * a peer. * @param peer_id The ID of the peer who shall be ignored or unignored. * @param ignore True to ignore the peer, false to unignore the peer. * @@ -5402,123 +5531,134 @@ const char *tox_err_group_set_ignore_to_string(Tox_Err_Group_Set_Ignore value); bool tox_group_set_ignore(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, bool ignore, Tox_Err_Group_Set_Ignore *error); -typedef enum Tox_Err_Group_Mod_Set_Role { +typedef enum Tox_Err_Group_Set_Role { /** * The function returned successfully. */ - TOX_ERR_GROUP_MOD_SET_ROLE_OK, + TOX_ERR_GROUP_SET_ROLE_OK, /** * The group number passed did not designate a valid group. */ - TOX_ERR_GROUP_MOD_SET_ROLE_GROUP_NOT_FOUND, + TOX_ERR_GROUP_SET_ROLE_GROUP_NOT_FOUND, /** - * The ID passed did not designate a valid peer. Note: you cannot set your own role. + * The ID passed did not designate a valid peer. Note: you cannot set your + * own role. */ - TOX_ERR_GROUP_MOD_SET_ROLE_PEER_NOT_FOUND, + TOX_ERR_GROUP_SET_ROLE_PEER_NOT_FOUND, /** * The caller does not have the required permissions for this action. */ - TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS, + TOX_ERR_GROUP_SET_ROLE_PERMISSIONS, /** - * The role assignment is invalid. This will occur if you try to set a peer's role to - * the role they already have. + * The role assignment is invalid. This will occur if you try to set a + * peer's role to the role they already have. */ - TOX_ERR_GROUP_MOD_SET_ROLE_ASSIGNMENT, + TOX_ERR_GROUP_SET_ROLE_ASSIGNMENT, /** - * The role was not successfully set. This may occur if the packet failed to send, or - * if the role limit has been reached. + * The role was not successfully set. This may occur if the packet failed to + * send, or if the role limit has been reached. */ - TOX_ERR_GROUP_MOD_SET_ROLE_FAIL_ACTION, + TOX_ERR_GROUP_SET_ROLE_FAIL_ACTION, /** * The caller attempted to set their own role. */ - TOX_ERR_GROUP_MOD_SET_ROLE_SELF, + TOX_ERR_GROUP_SET_ROLE_SELF, -} Tox_Err_Group_Mod_Set_Role; +} Tox_Err_Group_Set_Role; -const char *tox_err_group_mod_set_role_to_string(Tox_Err_Group_Mod_Set_Role value); +const char *tox_err_group_set_role_to_string(Tox_Err_Group_Set_Role value); /** * Set a peer's role. * - * This function will first remove the peer's previous role and then assign them a new role. - * It will also send a packet to the rest of the group, requesting that they perform - * the role reassignment. Note: peers cannot be set to the founder role. + * This function will first remove the peer's previous role and then assign them + * a new role. It will also send a packet to the rest of the group, requesting + * that they perform the role reassignment. * - * @param group_number The group number of the group the in which you wish set the peer's role. + * Only Founders may promote peers to the Moderator role, and only Founders and + * Moderators may set peers to the Observer or User role. Moderators may not set + * the role of other Moderators or the Founder. Peers may not be promoted to the + * Founder role. + * + * @param group_number The group number of the group the in which you wish set + * the peer's role. * @param peer_id The ID of the peer whose role you wish to set. * @param role The role you wish to set the peer to. * * @return true on success. */ -bool tox_group_mod_set_role(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Group_Role role, - Tox_Err_Group_Mod_Set_Role *error); +bool tox_group_set_role(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Group_Role role, + Tox_Err_Group_Set_Role *error); -typedef enum Tox_Err_Group_Mod_Kick_Peer { +typedef enum Tox_Err_Group_Kick_Peer { /** * The function returned successfully. */ - TOX_ERR_GROUP_MOD_KICK_PEER_OK, + TOX_ERR_GROUP_KICK_PEER_OK, /** * The group number passed did not designate a valid group. */ - TOX_ERR_GROUP_MOD_KICK_PEER_GROUP_NOT_FOUND, + TOX_ERR_GROUP_KICK_PEER_GROUP_NOT_FOUND, /** * The ID passed did not designate a valid peer. */ - TOX_ERR_GROUP_MOD_KICK_PEER_PEER_NOT_FOUND, + TOX_ERR_GROUP_KICK_PEER_PEER_NOT_FOUND, /** * The caller does not have the required permissions for this action. */ - TOX_ERR_GROUP_MOD_KICK_PEER_PERMISSIONS, + TOX_ERR_GROUP_KICK_PEER_PERMISSIONS, /** * The peer could not be kicked from the group. */ - TOX_ERR_GROUP_MOD_KICK_PEER_FAIL_ACTION, + TOX_ERR_GROUP_KICK_PEER_FAIL_ACTION, /** * The packet failed to send. */ - TOX_ERR_GROUP_MOD_KICK_PEER_FAIL_SEND, + TOX_ERR_GROUP_KICK_PEER_FAIL_SEND, /** * The caller attempted to set their own role. */ - TOX_ERR_GROUP_MOD_KICK_PEER_SELF, + TOX_ERR_GROUP_KICK_PEER_SELF, -} Tox_Err_Group_Mod_Kick_Peer; +} Tox_Err_Group_Kick_Peer; -const char *tox_err_group_mod_kick_peer_to_string(Tox_Err_Group_Mod_Kick_Peer value); +const char *tox_err_group_kick_peer_to_string(Tox_Err_Group_Kick_Peer value); /** * Kick a peer. * - * This function will remove a peer from the caller's peer list and send a packet to all - * group members requesting them to do the same. Note: This function will not trigger - * the `group_peer_exit` event for the caller. + * This function allows peers with the Founder or Moderator role to silently + * instruct all other peers in the group to remove a particular peer from their + * peer list. + * + * Note: This function will not trigger the `group_peer_exit` event for the + * caller. * * @param group_number The group number of the group the action is intended for. * @param peer_id The ID of the peer who will be kicked. * * @return true on success. */ -bool tox_group_mod_kick_peer(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, - Tox_Err_Group_Mod_Kick_Peer *error); +bool tox_group_kick_peer(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, + Tox_Err_Group_Kick_Peer *error); /** - * Represents moderation events. These should be used with the `group_moderation` event. + * Represents moderation events. These should be used with the + * `group_moderation` event. */ typedef enum Tox_Group_Mod_Event { @@ -5559,12 +5699,13 @@ typedef void tox_group_moderation_cb( /** * Set the callback for the `group_moderation` event. Pass NULL to unset. * - * This event is triggered when a moderator or founder executes a moderation event, with - * the exception of the peer who initiates the event. It is also triggered when the - * observer and moderator lists are silently modified (this may occur during group syncing). + * This event is triggered when a moderator or founder executes a moderation + * event, with the exception of the peer who initiates the event. It is also + * triggered when the observer and moderator lists are silently modified (this + * may occur during group syncing). * - * If either peer id does not designate a valid peer in the group chat, the client should - * manually update all peer roles. + * If either peer id does not designate a valid peer in the group chat, the + * client should manually update all peer roles. */ void tox_callback_group_moderation(Tox *tox, tox_group_moderation_cb *callback); diff --git a/protocols/Tox/libtox/src/toxcore/tox_api.c b/protocols/Tox/libtox/src/toxcore/tox_api.c index 02791674b5..18d861c18e 100644 --- a/protocols/Tox/libtox/src/toxcore/tox_api.c +++ b/protocols/Tox/libtox/src/toxcore/tox_api.c @@ -265,14 +265,6 @@ void tox_options_set_experimental_thread_safety( { options->experimental_thread_safety = experimental_thread_safety; } -const Tox_System *tox_options_get_operating_system(const Tox_Options *options) -{ - return options->operating_system; -} -void tox_options_set_operating_system(Tox_Options *options, const Tox_System *operating_system) -{ - options->operating_system = operating_system; -} bool tox_options_get_experimental_groups_persistence(const Tox_Options *options) { return options->experimental_groups_persistence; @@ -895,6 +887,9 @@ const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value) case TOX_ERR_CONFERENCE_JOIN_FAIL_SEND: return "TOX_ERR_CONFERENCE_JOIN_FAIL_SEND"; + + case TOX_ERR_CONFERENCE_JOIN_NULL: + return "TOX_ERR_CONFERENCE_JOIN_NULL"; } return "<invalid Tox_Err_Conference_Join>"; @@ -1253,17 +1248,17 @@ const char *tox_err_group_peer_query_to_string(Tox_Err_Group_Peer_Query value) return "<invalid Tox_Err_Group_Peer_Query>"; } -const char *tox_err_group_state_queries_to_string(Tox_Err_Group_State_Queries value) +const char *tox_err_group_state_query_to_string(Tox_Err_Group_State_Query value) { switch (value) { - case TOX_ERR_GROUP_STATE_QUERIES_OK: - return "TOX_ERR_GROUP_STATE_QUERIES_OK"; + case TOX_ERR_GROUP_STATE_QUERY_OK: + return "TOX_ERR_GROUP_STATE_QUERY_OK"; - case TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND: - return "TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND"; + case TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND: + return "TOX_ERR_GROUP_STATE_QUERY_GROUP_NOT_FOUND"; } - return "<invalid Tox_Err_Group_State_Queries>"; + return "<invalid Tox_Err_Group_State_Query>"; } const char *tox_err_group_topic_set_to_string(Tox_Err_Group_Topic_Set value) { @@ -1340,6 +1335,9 @@ const char *tox_err_group_send_private_message_to_string(Tox_Err_Group_Send_Priv case TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_EMPTY: return "TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_EMPTY"; + case TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_BAD_TYPE: + return "TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_BAD_TYPE"; + case TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PERMISSIONS: return "TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PERMISSIONS"; @@ -1348,9 +1346,6 @@ const char *tox_err_group_send_private_message_to_string(Tox_Err_Group_Send_Priv case TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_DISCONNECTED: return "TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_DISCONNECTED"; - - case TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_BAD_TYPE: - return "TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_BAD_TYPE"; } return "<invalid Tox_Err_Group_Send_Private_Message>"; @@ -1370,9 +1365,6 @@ const char *tox_err_group_send_custom_packet_to_string(Tox_Err_Group_Send_Custom case TOX_ERR_GROUP_SEND_CUSTOM_PACKET_EMPTY: return "TOX_ERR_GROUP_SEND_CUSTOM_PACKET_EMPTY"; - case TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS: - return "TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS"; - case TOX_ERR_GROUP_SEND_CUSTOM_PACKET_DISCONNECTED: return "TOX_ERR_GROUP_SEND_CUSTOM_PACKET_DISCONNECTED"; @@ -1400,9 +1392,6 @@ const char *tox_err_group_send_custom_private_packet_to_string(Tox_Err_Group_Sen case TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PEER_NOT_FOUND: return "TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PEER_NOT_FOUND"; - case TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS: - return "TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS"; - case TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_FAIL_SEND: return "TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_FAIL_SEND"; @@ -1457,11 +1446,14 @@ const char *tox_err_group_invite_accept_to_string(Tox_Err_Group_Invite_Accept va case TOX_ERR_GROUP_INVITE_ACCEPT_PASSWORD: return "TOX_ERR_GROUP_INVITE_ACCEPT_PASSWORD"; - case TOX_ERR_GROUP_INVITE_ACCEPT_CORE: - return "TOX_ERR_GROUP_INVITE_ACCEPT_CORE"; + case TOX_ERR_GROUP_INVITE_ACCEPT_FRIEND_NOT_FOUND: + return "TOX_ERR_GROUP_INVITE_ACCEPT_FRIEND_NOT_FOUND"; case TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND: return "TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND"; + + case TOX_ERR_GROUP_INVITE_ACCEPT_NULL: + return "TOX_ERR_GROUP_INVITE_ACCEPT_NULL"; } return "<invalid Tox_Err_Group_Invite_Accept>"; @@ -1505,131 +1497,131 @@ const char *tox_group_join_fail_to_string(Tox_Group_Join_Fail value) return "<invalid Tox_Group_Join_Fail>"; } -const char *tox_err_group_founder_set_password_to_string(Tox_Err_Group_Founder_Set_Password value) +const char *tox_err_group_set_password_to_string(Tox_Err_Group_Set_Password value) { switch (value) { - case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK: - return "TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK"; + case TOX_ERR_GROUP_SET_PASSWORD_OK: + return "TOX_ERR_GROUP_SET_PASSWORD_OK"; - case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_GROUP_NOT_FOUND: - return "TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_GROUP_NOT_FOUND"; + case TOX_ERR_GROUP_SET_PASSWORD_GROUP_NOT_FOUND: + return "TOX_ERR_GROUP_SET_PASSWORD_GROUP_NOT_FOUND"; - case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_PERMISSIONS: - return "TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_PERMISSIONS"; + case TOX_ERR_GROUP_SET_PASSWORD_PERMISSIONS: + return "TOX_ERR_GROUP_SET_PASSWORD_PERMISSIONS"; - case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_TOO_LONG: - return "TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_TOO_LONG"; + case TOX_ERR_GROUP_SET_PASSWORD_TOO_LONG: + return "TOX_ERR_GROUP_SET_PASSWORD_TOO_LONG"; - case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_FAIL_SEND: - return "TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_FAIL_SEND"; + case TOX_ERR_GROUP_SET_PASSWORD_FAIL_SEND: + return "TOX_ERR_GROUP_SET_PASSWORD_FAIL_SEND"; - case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_MALLOC: - return "TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_MALLOC"; + case TOX_ERR_GROUP_SET_PASSWORD_MALLOC: + return "TOX_ERR_GROUP_SET_PASSWORD_MALLOC"; - case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_DISCONNECTED: - return "TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_DISCONNECTED"; + case TOX_ERR_GROUP_SET_PASSWORD_DISCONNECTED: + return "TOX_ERR_GROUP_SET_PASSWORD_DISCONNECTED"; } - return "<invalid Tox_Err_Group_Founder_Set_Password>"; + return "<invalid Tox_Err_Group_Set_Password>"; } -const char *tox_err_group_founder_set_topic_lock_to_string(Tox_Err_Group_Founder_Set_Topic_Lock value) +const char *tox_err_group_set_topic_lock_to_string(Tox_Err_Group_Set_Topic_Lock value) { switch (value) { - case TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK: - return "TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK"; + case TOX_ERR_GROUP_SET_TOPIC_LOCK_OK: + return "TOX_ERR_GROUP_SET_TOPIC_LOCK_OK"; - case TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_GROUP_NOT_FOUND: - return "TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_GROUP_NOT_FOUND"; + case TOX_ERR_GROUP_SET_TOPIC_LOCK_GROUP_NOT_FOUND: + return "TOX_ERR_GROUP_SET_TOPIC_LOCK_GROUP_NOT_FOUND"; - case TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_INVALID: - return "TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_INVALID"; + case TOX_ERR_GROUP_SET_TOPIC_LOCK_INVALID: + return "TOX_ERR_GROUP_SET_TOPIC_LOCK_INVALID"; - case TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_PERMISSIONS: - return "TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_PERMISSIONS"; + case TOX_ERR_GROUP_SET_TOPIC_LOCK_PERMISSIONS: + return "TOX_ERR_GROUP_SET_TOPIC_LOCK_PERMISSIONS"; - case TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_FAIL_SET: - return "TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_FAIL_SET"; + case TOX_ERR_GROUP_SET_TOPIC_LOCK_FAIL_SET: + return "TOX_ERR_GROUP_SET_TOPIC_LOCK_FAIL_SET"; - case TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_FAIL_SEND: - return "TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_FAIL_SEND"; + case TOX_ERR_GROUP_SET_TOPIC_LOCK_FAIL_SEND: + return "TOX_ERR_GROUP_SET_TOPIC_LOCK_FAIL_SEND"; - case TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_DISCONNECTED: - return "TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_DISCONNECTED"; + case TOX_ERR_GROUP_SET_TOPIC_LOCK_DISCONNECTED: + return "TOX_ERR_GROUP_SET_TOPIC_LOCK_DISCONNECTED"; } - return "<invalid Tox_Err_Group_Founder_Set_Topic_Lock>"; + return "<invalid Tox_Err_Group_Set_Topic_Lock>"; } -const char *tox_err_group_founder_set_voice_state_to_string(Tox_Err_Group_Founder_Set_Voice_State value) +const char *tox_err_group_set_voice_state_to_string(Tox_Err_Group_Set_Voice_State value) { switch (value) { - case TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK: - return "TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK"; + case TOX_ERR_GROUP_SET_VOICE_STATE_OK: + return "TOX_ERR_GROUP_SET_VOICE_STATE_OK"; - case TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_GROUP_NOT_FOUND: - return "TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_GROUP_NOT_FOUND"; + case TOX_ERR_GROUP_SET_VOICE_STATE_GROUP_NOT_FOUND: + return "TOX_ERR_GROUP_SET_VOICE_STATE_GROUP_NOT_FOUND"; - case TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_PERMISSIONS: - return "TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_PERMISSIONS"; + case TOX_ERR_GROUP_SET_VOICE_STATE_PERMISSIONS: + return "TOX_ERR_GROUP_SET_VOICE_STATE_PERMISSIONS"; - case TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_FAIL_SET: - return "TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_FAIL_SET"; + case TOX_ERR_GROUP_SET_VOICE_STATE_FAIL_SET: + return "TOX_ERR_GROUP_SET_VOICE_STATE_FAIL_SET"; - case TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_FAIL_SEND: - return "TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_FAIL_SEND"; + case TOX_ERR_GROUP_SET_VOICE_STATE_FAIL_SEND: + return "TOX_ERR_GROUP_SET_VOICE_STATE_FAIL_SEND"; - case TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_DISCONNECTED: - return "TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_DISCONNECTED"; + case TOX_ERR_GROUP_SET_VOICE_STATE_DISCONNECTED: + return "TOX_ERR_GROUP_SET_VOICE_STATE_DISCONNECTED"; } - return "<invalid Tox_Err_Group_Founder_Set_Voice_State>"; + return "<invalid Tox_Err_Group_Set_Voice_State>"; } -const char *tox_err_group_founder_set_privacy_state_to_string(Tox_Err_Group_Founder_Set_Privacy_State value) +const char *tox_err_group_set_privacy_state_to_string(Tox_Err_Group_Set_Privacy_State value) { switch (value) { - case TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK: - return "TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK"; + case TOX_ERR_GROUP_SET_PRIVACY_STATE_OK: + return "TOX_ERR_GROUP_SET_PRIVACY_STATE_OK"; - case TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_GROUP_NOT_FOUND: - return "TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_GROUP_NOT_FOUND"; + case TOX_ERR_GROUP_SET_PRIVACY_STATE_GROUP_NOT_FOUND: + return "TOX_ERR_GROUP_SET_PRIVACY_STATE_GROUP_NOT_FOUND"; - case TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_PERMISSIONS: - return "TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_PERMISSIONS"; + case TOX_ERR_GROUP_SET_PRIVACY_STATE_PERMISSIONS: + return "TOX_ERR_GROUP_SET_PRIVACY_STATE_PERMISSIONS"; - case TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_FAIL_SET: - return "TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_FAIL_SET"; + case TOX_ERR_GROUP_SET_PRIVACY_STATE_FAIL_SET: + return "TOX_ERR_GROUP_SET_PRIVACY_STATE_FAIL_SET"; - case TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_FAIL_SEND: - return "TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_FAIL_SEND"; + case TOX_ERR_GROUP_SET_PRIVACY_STATE_FAIL_SEND: + return "TOX_ERR_GROUP_SET_PRIVACY_STATE_FAIL_SEND"; - case TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_DISCONNECTED: - return "TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_DISCONNECTED"; + case TOX_ERR_GROUP_SET_PRIVACY_STATE_DISCONNECTED: + return "TOX_ERR_GROUP_SET_PRIVACY_STATE_DISCONNECTED"; } - return "<invalid Tox_Err_Group_Founder_Set_Privacy_State>"; + return "<invalid Tox_Err_Group_Set_Privacy_State>"; } -const char *tox_err_group_founder_set_peer_limit_to_string(Tox_Err_Group_Founder_Set_Peer_Limit value) +const char *tox_err_group_set_peer_limit_to_string(Tox_Err_Group_Set_Peer_Limit value) { switch (value) { - case TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK: - return "TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK"; + case TOX_ERR_GROUP_SET_PEER_LIMIT_OK: + return "TOX_ERR_GROUP_SET_PEER_LIMIT_OK"; - case TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_GROUP_NOT_FOUND: - return "TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_GROUP_NOT_FOUND"; + case TOX_ERR_GROUP_SET_PEER_LIMIT_GROUP_NOT_FOUND: + return "TOX_ERR_GROUP_SET_PEER_LIMIT_GROUP_NOT_FOUND"; - case TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_PERMISSIONS: - return "TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_PERMISSIONS"; + case TOX_ERR_GROUP_SET_PEER_LIMIT_PERMISSIONS: + return "TOX_ERR_GROUP_SET_PEER_LIMIT_PERMISSIONS"; - case TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_FAIL_SET: - return "TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_FAIL_SET"; + case TOX_ERR_GROUP_SET_PEER_LIMIT_FAIL_SET: + return "TOX_ERR_GROUP_SET_PEER_LIMIT_FAIL_SET"; - case TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_FAIL_SEND: - return "TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_FAIL_SEND"; + case TOX_ERR_GROUP_SET_PEER_LIMIT_FAIL_SEND: + return "TOX_ERR_GROUP_SET_PEER_LIMIT_FAIL_SEND"; - case TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_DISCONNECTED: - return "TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_DISCONNECTED"; + case TOX_ERR_GROUP_SET_PEER_LIMIT_DISCONNECTED: + return "TOX_ERR_GROUP_SET_PEER_LIMIT_DISCONNECTED"; } - return "<invalid Tox_Err_Group_Founder_Set_Peer_Limit>"; + return "<invalid Tox_Err_Group_Set_Peer_Limit>"; } const char *tox_err_group_set_ignore_to_string(Tox_Err_Group_Set_Ignore value) { @@ -1649,59 +1641,59 @@ const char *tox_err_group_set_ignore_to_string(Tox_Err_Group_Set_Ignore value) return "<invalid Tox_Err_Group_Set_Ignore>"; } -const char *tox_err_group_mod_set_role_to_string(Tox_Err_Group_Mod_Set_Role value) +const char *tox_err_group_set_role_to_string(Tox_Err_Group_Set_Role value) { switch (value) { - case TOX_ERR_GROUP_MOD_SET_ROLE_OK: - return "TOX_ERR_GROUP_MOD_SET_ROLE_OK"; + case TOX_ERR_GROUP_SET_ROLE_OK: + return "TOX_ERR_GROUP_SET_ROLE_OK"; - case TOX_ERR_GROUP_MOD_SET_ROLE_GROUP_NOT_FOUND: - return "TOX_ERR_GROUP_MOD_SET_ROLE_GROUP_NOT_FOUND"; + case TOX_ERR_GROUP_SET_ROLE_GROUP_NOT_FOUND: + return "TOX_ERR_GROUP_SET_ROLE_GROUP_NOT_FOUND"; - case TOX_ERR_GROUP_MOD_SET_ROLE_PEER_NOT_FOUND: - return "TOX_ERR_GROUP_MOD_SET_ROLE_PEER_NOT_FOUND"; + case TOX_ERR_GROUP_SET_ROLE_PEER_NOT_FOUND: + return "TOX_ERR_GROUP_SET_ROLE_PEER_NOT_FOUND"; - case TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS: - return "TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS"; + case TOX_ERR_GROUP_SET_ROLE_PERMISSIONS: + return "TOX_ERR_GROUP_SET_ROLE_PERMISSIONS"; - case TOX_ERR_GROUP_MOD_SET_ROLE_ASSIGNMENT: - return "TOX_ERR_GROUP_MOD_SET_ROLE_ASSIGNMENT"; + case TOX_ERR_GROUP_SET_ROLE_ASSIGNMENT: + return "TOX_ERR_GROUP_SET_ROLE_ASSIGNMENT"; - case TOX_ERR_GROUP_MOD_SET_ROLE_FAIL_ACTION: - return "TOX_ERR_GROUP_MOD_SET_ROLE_FAIL_ACTION"; + case TOX_ERR_GROUP_SET_ROLE_FAIL_ACTION: + return "TOX_ERR_GROUP_SET_ROLE_FAIL_ACTION"; - case TOX_ERR_GROUP_MOD_SET_ROLE_SELF: - return "TOX_ERR_GROUP_MOD_SET_ROLE_SELF"; + case TOX_ERR_GROUP_SET_ROLE_SELF: + return "TOX_ERR_GROUP_SET_ROLE_SELF"; } - return "<invalid Tox_Err_Group_Mod_Set_Role>"; + return "<invalid Tox_Err_Group_Set_Role>"; } -const char *tox_err_group_mod_kick_peer_to_string(Tox_Err_Group_Mod_Kick_Peer value) +const char *tox_err_group_kick_peer_to_string(Tox_Err_Group_Kick_Peer value) { switch (value) { - case TOX_ERR_GROUP_MOD_KICK_PEER_OK: - return "TOX_ERR_GROUP_MOD_KICK_PEER_OK"; + case TOX_ERR_GROUP_KICK_PEER_OK: + return "TOX_ERR_GROUP_KICK_PEER_OK"; - case TOX_ERR_GROUP_MOD_KICK_PEER_GROUP_NOT_FOUND: - return "TOX_ERR_GROUP_MOD_KICK_PEER_GROUP_NOT_FOUND"; + case TOX_ERR_GROUP_KICK_PEER_GROUP_NOT_FOUND: + return "TOX_ERR_GROUP_KICK_PEER_GROUP_NOT_FOUND"; - case TOX_ERR_GROUP_MOD_KICK_PEER_PEER_NOT_FOUND: - return "TOX_ERR_GROUP_MOD_KICK_PEER_PEER_NOT_FOUND"; + case TOX_ERR_GROUP_KICK_PEER_PEER_NOT_FOUND: + return "TOX_ERR_GROUP_KICK_PEER_PEER_NOT_FOUND"; - case TOX_ERR_GROUP_MOD_KICK_PEER_PERMISSIONS: - return "TOX_ERR_GROUP_MOD_KICK_PEER_PERMISSIONS"; + case TOX_ERR_GROUP_KICK_PEER_PERMISSIONS: + return "TOX_ERR_GROUP_KICK_PEER_PERMISSIONS"; - case TOX_ERR_GROUP_MOD_KICK_PEER_FAIL_ACTION: - return "TOX_ERR_GROUP_MOD_KICK_PEER_FAIL_ACTION"; + case TOX_ERR_GROUP_KICK_PEER_FAIL_ACTION: + return "TOX_ERR_GROUP_KICK_PEER_FAIL_ACTION"; - case TOX_ERR_GROUP_MOD_KICK_PEER_FAIL_SEND: - return "TOX_ERR_GROUP_MOD_KICK_PEER_FAIL_SEND"; + case TOX_ERR_GROUP_KICK_PEER_FAIL_SEND: + return "TOX_ERR_GROUP_KICK_PEER_FAIL_SEND"; - case TOX_ERR_GROUP_MOD_KICK_PEER_SELF: - return "TOX_ERR_GROUP_MOD_KICK_PEER_SELF"; + case TOX_ERR_GROUP_KICK_PEER_SELF: + return "TOX_ERR_GROUP_KICK_PEER_SELF"; } - return "<invalid Tox_Err_Group_Mod_Kick_Peer>"; + return "<invalid Tox_Err_Group_Kick_Peer>"; } const char *tox_group_mod_event_to_string(Tox_Group_Mod_Event value) { diff --git a/protocols/Tox/libtox/src/toxcore/tox_dispatch.h b/protocols/Tox/libtox/src/toxcore/tox_dispatch.h index 2588065a4d..29ac66a412 100644 --- a/protocols/Tox/libtox/src/toxcore/tox_dispatch.h +++ b/protocols/Tox/libtox/src/toxcore/tox_dispatch.h @@ -2,6 +2,13 @@ * Copyright © 2022 The TokTok team. */ +/** + * WARNING: This is an experimental API and is subject to change. + * + * At this point, it probably won't change very much anymore, but we may have + * small breaking changes before a stable release. + */ + #ifndef C_TOXCORE_TOXCORE_TOX_DISPATCH_H #define C_TOXCORE_TOXCORE_TOX_DISPATCH_H diff --git a/protocols/Tox/libtox/src/toxcore/tox_event.c b/protocols/Tox/libtox/src/toxcore/tox_event.c index b0a65503cd..f702d629fc 100644 --- a/protocols/Tox/libtox/src/toxcore/tox_event.c +++ b/protocols/Tox/libtox/src/toxcore/tox_event.c @@ -725,216 +725,216 @@ bool tox_event_pack(const Tox_Event *event, Bin_Pack *bp) } non_null() -static bool tox_event_type_from_int(uint32_t value, Tox_Event_Type *out) +static bool tox_event_type_from_int(uint32_t value, Tox_Event_Type *out_enum) { switch (value) { case TOX_EVENT_SELF_CONNECTION_STATUS: { - *out = TOX_EVENT_SELF_CONNECTION_STATUS; + *out_enum = TOX_EVENT_SELF_CONNECTION_STATUS; return true; } case TOX_EVENT_FRIEND_REQUEST: { - *out = TOX_EVENT_FRIEND_REQUEST; + *out_enum = TOX_EVENT_FRIEND_REQUEST; return true; } case TOX_EVENT_FRIEND_CONNECTION_STATUS: { - *out = TOX_EVENT_FRIEND_CONNECTION_STATUS; + *out_enum = TOX_EVENT_FRIEND_CONNECTION_STATUS; return true; } case TOX_EVENT_FRIEND_LOSSY_PACKET: { - *out = TOX_EVENT_FRIEND_LOSSY_PACKET; + *out_enum = TOX_EVENT_FRIEND_LOSSY_PACKET; return true; } case TOX_EVENT_FRIEND_LOSSLESS_PACKET: { - *out = TOX_EVENT_FRIEND_LOSSLESS_PACKET; + *out_enum = TOX_EVENT_FRIEND_LOSSLESS_PACKET; return true; } case TOX_EVENT_FRIEND_NAME: { - *out = TOX_EVENT_FRIEND_NAME; + *out_enum = TOX_EVENT_FRIEND_NAME; return true; } case TOX_EVENT_FRIEND_STATUS: { - *out = TOX_EVENT_FRIEND_STATUS; + *out_enum = TOX_EVENT_FRIEND_STATUS; return true; } case TOX_EVENT_FRIEND_STATUS_MESSAGE: { - *out = TOX_EVENT_FRIEND_STATUS_MESSAGE; + *out_enum = TOX_EVENT_FRIEND_STATUS_MESSAGE; return true; } case TOX_EVENT_FRIEND_MESSAGE: { - *out = TOX_EVENT_FRIEND_MESSAGE; + *out_enum = TOX_EVENT_FRIEND_MESSAGE; return true; } case TOX_EVENT_FRIEND_READ_RECEIPT: { - *out = TOX_EVENT_FRIEND_READ_RECEIPT; + *out_enum = TOX_EVENT_FRIEND_READ_RECEIPT; return true; } case TOX_EVENT_FRIEND_TYPING: { - *out = TOX_EVENT_FRIEND_TYPING; + *out_enum = TOX_EVENT_FRIEND_TYPING; return true; } case TOX_EVENT_FILE_CHUNK_REQUEST: { - *out = TOX_EVENT_FILE_CHUNK_REQUEST; + *out_enum = TOX_EVENT_FILE_CHUNK_REQUEST; return true; } case TOX_EVENT_FILE_RECV: { - *out = TOX_EVENT_FILE_RECV; + *out_enum = TOX_EVENT_FILE_RECV; return true; } case TOX_EVENT_FILE_RECV_CHUNK: { - *out = TOX_EVENT_FILE_RECV_CHUNK; + *out_enum = TOX_EVENT_FILE_RECV_CHUNK; return true; } case TOX_EVENT_FILE_RECV_CONTROL: { - *out = TOX_EVENT_FILE_RECV_CONTROL; + *out_enum = TOX_EVENT_FILE_RECV_CONTROL; return true; } case TOX_EVENT_CONFERENCE_INVITE: { - *out = TOX_EVENT_CONFERENCE_INVITE; + *out_enum = TOX_EVENT_CONFERENCE_INVITE; return true; } case TOX_EVENT_CONFERENCE_CONNECTED: { - *out = TOX_EVENT_CONFERENCE_CONNECTED; + *out_enum = TOX_EVENT_CONFERENCE_CONNECTED; return true; } case TOX_EVENT_CONFERENCE_PEER_LIST_CHANGED: { - *out = TOX_EVENT_CONFERENCE_PEER_LIST_CHANGED; + *out_enum = TOX_EVENT_CONFERENCE_PEER_LIST_CHANGED; return true; } case TOX_EVENT_CONFERENCE_PEER_NAME: { - *out = TOX_EVENT_CONFERENCE_PEER_NAME; + *out_enum = TOX_EVENT_CONFERENCE_PEER_NAME; return true; } case TOX_EVENT_CONFERENCE_TITLE: { - *out = TOX_EVENT_CONFERENCE_TITLE; + *out_enum = TOX_EVENT_CONFERENCE_TITLE; return true; } case TOX_EVENT_CONFERENCE_MESSAGE: { - *out = TOX_EVENT_CONFERENCE_MESSAGE; + *out_enum = TOX_EVENT_CONFERENCE_MESSAGE; return true; } case TOX_EVENT_GROUP_PEER_NAME: { - *out = TOX_EVENT_GROUP_PEER_NAME; + *out_enum = TOX_EVENT_GROUP_PEER_NAME; return true; } case TOX_EVENT_GROUP_PEER_STATUS: { - *out = TOX_EVENT_GROUP_PEER_STATUS; + *out_enum = TOX_EVENT_GROUP_PEER_STATUS; return true; } case TOX_EVENT_GROUP_TOPIC: { - *out = TOX_EVENT_GROUP_TOPIC; + *out_enum = TOX_EVENT_GROUP_TOPIC; return true; } case TOX_EVENT_GROUP_PRIVACY_STATE: { - *out = TOX_EVENT_GROUP_PRIVACY_STATE; + *out_enum = TOX_EVENT_GROUP_PRIVACY_STATE; return true; } case TOX_EVENT_GROUP_VOICE_STATE: { - *out = TOX_EVENT_GROUP_VOICE_STATE; + *out_enum = TOX_EVENT_GROUP_VOICE_STATE; return true; } case TOX_EVENT_GROUP_TOPIC_LOCK: { - *out = TOX_EVENT_GROUP_TOPIC_LOCK; + *out_enum = TOX_EVENT_GROUP_TOPIC_LOCK; return true; } case TOX_EVENT_GROUP_PEER_LIMIT: { - *out = TOX_EVENT_GROUP_PEER_LIMIT; + *out_enum = TOX_EVENT_GROUP_PEER_LIMIT; return true; } case TOX_EVENT_GROUP_PASSWORD: { - *out = TOX_EVENT_GROUP_PASSWORD; + *out_enum = TOX_EVENT_GROUP_PASSWORD; return true; } case TOX_EVENT_GROUP_MESSAGE: { - *out = TOX_EVENT_GROUP_MESSAGE; + *out_enum = TOX_EVENT_GROUP_MESSAGE; return true; } case TOX_EVENT_GROUP_PRIVATE_MESSAGE: { - *out = TOX_EVENT_GROUP_PRIVATE_MESSAGE; + *out_enum = TOX_EVENT_GROUP_PRIVATE_MESSAGE; return true; } case TOX_EVENT_GROUP_CUSTOM_PACKET: { - *out = TOX_EVENT_GROUP_CUSTOM_PACKET; + *out_enum = TOX_EVENT_GROUP_CUSTOM_PACKET; return true; } case TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET: { - *out = TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET; + *out_enum = TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET; return true; } case TOX_EVENT_GROUP_INVITE: { - *out = TOX_EVENT_GROUP_INVITE; + *out_enum = TOX_EVENT_GROUP_INVITE; return true; } case TOX_EVENT_GROUP_PEER_JOIN: { - *out = TOX_EVENT_GROUP_PEER_JOIN; + *out_enum = TOX_EVENT_GROUP_PEER_JOIN; return true; } case TOX_EVENT_GROUP_PEER_EXIT: { - *out = TOX_EVENT_GROUP_PEER_EXIT; + *out_enum = TOX_EVENT_GROUP_PEER_EXIT; return true; } case TOX_EVENT_GROUP_SELF_JOIN: { - *out = TOX_EVENT_GROUP_SELF_JOIN; + *out_enum = TOX_EVENT_GROUP_SELF_JOIN; return true; } case TOX_EVENT_GROUP_JOIN_FAIL: { - *out = TOX_EVENT_GROUP_JOIN_FAIL; + *out_enum = TOX_EVENT_GROUP_JOIN_FAIL; return true; } case TOX_EVENT_GROUP_MODERATION: { - *out = TOX_EVENT_GROUP_MODERATION; + *out_enum = TOX_EVENT_GROUP_MODERATION; return true; } case TOX_EVENT_DHT_GET_NODES_RESPONSE: { - *out = TOX_EVENT_DHT_GET_NODES_RESPONSE; + *out_enum = TOX_EVENT_DHT_GET_NODES_RESPONSE; return true; } case TOX_EVENT_INVALID: { - *out = TOX_EVENT_INVALID; + *out_enum = TOX_EVENT_INVALID; return true; } default: { - *out = TOX_EVENT_INVALID; + *out_enum = TOX_EVENT_INVALID; return false; } } diff --git a/protocols/Tox/libtox/src/toxcore/tox_events.h b/protocols/Tox/libtox/src/toxcore/tox_events.h index 3edaa7d06b..6bbf13e8ef 100644 --- a/protocols/Tox/libtox/src/toxcore/tox_events.h +++ b/protocols/Tox/libtox/src/toxcore/tox_events.h @@ -2,6 +2,13 @@ * Copyright © 2022-2024 The TokTok team. */ +/** + * WARNING: This is an experimental API and is subject to change. + * + * At this point, it probably won't change very much anymore, but we may have + * small breaking changes before a stable release. + */ + #ifndef C_TOXCORE_TOXCORE_TOX_EVENTS_H #define C_TOXCORE_TOXCORE_TOX_EVENTS_H @@ -248,7 +255,7 @@ uint32_t tox_event_group_message_get_group_number( const Tox_Event_Group_Message *group_message); uint32_t tox_event_group_message_get_peer_id( const Tox_Event_Group_Message *group_message); -Tox_Message_Type tox_event_group_message_get_type( +Tox_Message_Type tox_event_group_message_get_message_type( const Tox_Event_Group_Message *group_message); const uint8_t *tox_event_group_message_get_message( const Tox_Event_Group_Message *group_message); @@ -262,12 +269,14 @@ uint32_t tox_event_group_private_message_get_group_number( const Tox_Event_Group_Private_Message *group_private_message); uint32_t tox_event_group_private_message_get_peer_id( const Tox_Event_Group_Private_Message *group_private_message); -Tox_Message_Type tox_event_group_private_message_get_type( +Tox_Message_Type tox_event_group_private_message_get_message_type( const Tox_Event_Group_Private_Message *group_private_message); const uint8_t *tox_event_group_private_message_get_message( const Tox_Event_Group_Private_Message *group_private_message); uint32_t tox_event_group_private_message_get_message_length( const Tox_Event_Group_Private_Message *group_private_message); +uint32_t tox_event_group_private_message_get_message_id( + const Tox_Event_Group_Private_Message *group_private_message); typedef struct Tox_Event_Group_Custom_Packet Tox_Event_Group_Custom_Packet; uint32_t tox_event_group_custom_packet_get_group_number( @@ -568,6 +577,8 @@ void tox_events_free(Tox_Events *events); uint32_t tox_events_bytes_size(const Tox_Events *events); bool tox_events_get_bytes(const Tox_Events *events, uint8_t *bytes); +typedef struct Tox_System Tox_System; + Tox_Events *tox_events_load(const Tox_System *sys, const uint8_t *bytes, uint32_t bytes_size); bool tox_events_equal(const Tox_System *sys, const Tox_Events *a, const Tox_Events *b); diff --git a/protocols/Tox/libtox/src/toxcore/tox_private.h b/protocols/Tox/libtox/src/toxcore/tox_private.h index d36ab026c3..c872bfea47 100644 --- a/protocols/Tox/libtox/src/toxcore/tox_private.h +++ b/protocols/Tox/libtox/src/toxcore/tox_private.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-3.0-or-later - * Copyright © 2016-2020 The TokTok team. + * Copyright © 2016-2024 The TokTok team. * Copyright © 2013 Tox project. */ @@ -18,38 +18,49 @@ extern "C" { typedef uint64_t tox_mono_time_cb(void *user_data); -struct Tox_System { +typedef struct Tox_System { tox_mono_time_cb *mono_time_callback; void *mono_time_user_data; const struct Random *rng; const struct Network *ns; const struct Memory *mem; -}; +} Tox_System; Tox_System tox_default_system(void); +const Tox_System *tox_get_system(Tox *tox); + +typedef struct Tox_Options_Testing { + const struct Tox_System *operating_system; +} Tox_Options_Testing; + +typedef enum Tox_Err_New_Testing { + TOX_ERR_NEW_TESTING_OK, + TOX_ERR_NEW_TESTING_NULL, +} Tox_Err_New_Testing; + +Tox *tox_new_testing(const Tox_Options *options, Tox_Err_New *error, const Tox_Options_Testing *testing, Tox_Err_New_Testing *testing_error); + void tox_lock(const Tox *tox); void tox_unlock(const Tox *tox); -const Tox_System *tox_get_system(Tox *tox); - /** - * Set the callback for the `friend_lossy_packet` event for a specific packet ID. - * Pass NULL to unset. + * 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) + * 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. + * 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` + * 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); @@ -78,7 +89,7 @@ uint32_t tox_dht_node_public_key_size(void); /** * @param public_key The node's public key. - * @param ip The node's IP address, represented as a null terminated string. + * @param ip The node's IP address, represented as a NUL-terminated C string. * @param port The node's port. */ typedef void tox_dht_get_nodes_response_cb(Tox *tox, const uint8_t *public_key, const char *ip, uint16_t port, @@ -98,7 +109,8 @@ typedef enum Tox_Err_Dht_Get_Nodes { TOX_ERR_DHT_GET_NODES_OK, /** - * UDP is disabled in tox options; the DHT can only be queried when UDP is enabled. + * UDP is disabled in Tox options; the DHT can only be queried when UDP is + * enabled. */ TOX_ERR_DHT_GET_NODES_UDP_DISABLED, @@ -118,21 +130,24 @@ typedef enum Tox_Err_Dht_Get_Nodes { TOX_ERR_DHT_GET_NODES_BAD_IP, /** - * The getnodes request failed. This usually means the packet failed to send. + * The getnodes request failed. This usually means the packet failed to + * send. */ TOX_ERR_DHT_GET_NODES_FAIL, } Tox_Err_Dht_Get_Nodes; /** * This function sends a getnodes request to a DHT node for its peers that - * are "close" to the passed target public key according to the distance metric used - * by the DHT implementation. + * are "close" to the passed target public key according to the distance metric + * used by the DHT implementation. * - * @param public_key The public key of the node that we wish to query. This key must be - * at least `TOX_DHT_NODE_PUBLIC_KEY_SIZE` bytes in length. - * @param ip A NULL terminated string representing the IP address of the node we wish to query. + * @param public_key The public key of the node that we wish to query. This key + * must be at least `TOX_DHT_NODE_PUBLIC_KEY_SIZE` bytes in length. + * @param ip A NUL-terminated C string representing the IP address of the node + * we wish to query. * @param port The port of the node we wish to query. - * @param target_public_key The public key for which we want to find close nodes. + * @param target_public_key The public key for which we want to find close + * nodes. * * @return true on success. */ @@ -140,7 +155,6 @@ bool tox_dht_get_nodes(const Tox *tox, const uint8_t *public_key, const char *ip const uint8_t *target_public_key, Tox_Err_Dht_Get_Nodes *error); /** - * This function returns the ratio of close dht nodes that are known to support announce/store. * This function returns the number of DHT nodes in the closelist. * * @return number @@ -148,8 +162,8 @@ bool tox_dht_get_nodes(const Tox *tox, const uint8_t *public_key, const char *ip uint16_t tox_dht_get_num_closelist(const Tox *tox); /** - * This function returns the number of DHT nodes in the closelist, - * that are capable to store annouce data (introduced in version 0.2.18). + * This function returns the number of DHT nodes in the closelist + * that are capable of storing announce data (introduced in version 0.2.18). * * @return number */ @@ -169,30 +183,32 @@ uint16_t tox_dht_get_num_closelist_announce_capable(const Tox *tox); uint32_t tox_group_peer_ip_string_max_length(void); /** - * Return the length of the peer's IP address in string form. If the group number or ID - * is invalid, the return value is unspecified. + * Return the length of the peer's IP address in string form. If the group + * number or ID is invalid, the return value is unspecified. * * @param group_number The group number of the group we wish to query. - * @param peer_id The ID of the peer whose IP address length we want to retrieve. + * @param peer_id The ID of the peer whose IP address length we want to + * retrieve. */ size_t tox_group_peer_get_ip_address_size(const Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Err_Group_Peer_Query *error); /** - * Write the IP address associated with the designated peer_id for the designated group number - * to ip_addr. + * Write the IP address associated with the designated peer_id for the + * designated group number to ip_addr. * - * If the peer is forcing TCP connections a placeholder value will be written instead, - * indicating that their real IP address is unknown to us. + * If the peer is forcing TCP connections a placeholder value will be written + * instead, indicating that their real IP address is unknown to us. * - * If `peer_id` designates ourself, it will write either our own IP address or a placeholder value, - * depending on whether or not we're forcing TCP connections. + * If `peer_id` designates ourself, it will write either our own IP address or a + * placeholder value, depending on whether or not we're forcing TCP connections. * - * Call tox_group_peer_get_ip_address_size to determine the allocation size for the `ip_addr` parameter. + * Call tox_group_peer_get_ip_address_size to determine the allocation size for + * the `ip_addr` parameter. * * @param group_number The group number of the group we wish to query. * @param peer_id The ID of the peer whose public key we wish to retrieve. - * @param ip_addr A valid memory region large enough to store the IP address string. - * If this parameter is NULL, this function call has no effect. + * @param ip_addr A valid memory region large enough to store the IP address + * string. If this parameter is NULL, this function call has no effect. * * @return true on success. */ diff --git a/protocols/Tox/libtox/src/toxcore/tox_unpack.c b/protocols/Tox/libtox/src/toxcore/tox_unpack.c index b5e05da872..5caef02c07 100644 --- a/protocols/Tox/libtox/src/toxcore/tox_unpack.c +++ b/protocols/Tox/libtox/src/toxcore/tox_unpack.c @@ -11,21 +11,21 @@ #include "tox.h" non_null() -static bool tox_conference_type_from_int(uint32_t value, Tox_Conference_Type *out) +static bool tox_conference_type_from_int(uint32_t value, Tox_Conference_Type *out_enum) { switch (value) { case TOX_CONFERENCE_TYPE_TEXT: { - *out = TOX_CONFERENCE_TYPE_TEXT; + *out_enum = TOX_CONFERENCE_TYPE_TEXT; return true; } case TOX_CONFERENCE_TYPE_AV: { - *out = TOX_CONFERENCE_TYPE_AV; + *out_enum = TOX_CONFERENCE_TYPE_AV; return true; } default: { - *out = TOX_CONFERENCE_TYPE_TEXT; + *out_enum = TOX_CONFERENCE_TYPE_TEXT; return false; } } @@ -38,26 +38,26 @@ bool tox_conference_type_unpack(Tox_Conference_Type *val, Bin_Unpack *bu) } non_null() -static bool tox_connection_from_int(uint32_t value, Tox_Connection *out) +static bool tox_connection_from_int(uint32_t value, Tox_Connection *out_enum) { switch (value) { case TOX_CONNECTION_NONE: { - *out = TOX_CONNECTION_NONE; + *out_enum = TOX_CONNECTION_NONE; return true; } case TOX_CONNECTION_TCP: { - *out = TOX_CONNECTION_TCP; + *out_enum = TOX_CONNECTION_TCP; return true; } case TOX_CONNECTION_UDP: { - *out = TOX_CONNECTION_UDP; + *out_enum = TOX_CONNECTION_UDP; return true; } default: { - *out = TOX_CONNECTION_NONE; + *out_enum = TOX_CONNECTION_NONE; return false; } } @@ -71,26 +71,26 @@ bool tox_connection_unpack(Tox_Connection *val, Bin_Unpack *bu) } non_null() -static bool tox_file_control_from_int(uint32_t value, Tox_File_Control *out) +static bool tox_file_control_from_int(uint32_t value, Tox_File_Control *out_enum) { switch (value) { case TOX_FILE_CONTROL_RESUME: { - *out = TOX_FILE_CONTROL_RESUME; + *out_enum = TOX_FILE_CONTROL_RESUME; return true; } case TOX_FILE_CONTROL_PAUSE: { - *out = TOX_FILE_CONTROL_PAUSE; + *out_enum = TOX_FILE_CONTROL_PAUSE; return true; } case TOX_FILE_CONTROL_CANCEL: { - *out = TOX_FILE_CONTROL_CANCEL; + *out_enum = TOX_FILE_CONTROL_CANCEL; return true; } default: { - *out = TOX_FILE_CONTROL_RESUME; + *out_enum = TOX_FILE_CONTROL_RESUME; return false; } } @@ -104,21 +104,21 @@ bool tox_file_control_unpack(Tox_File_Control *val, Bin_Unpack *bu) } non_null() -static bool tox_message_type_from_int(uint32_t value, Tox_Message_Type *out) +static bool tox_message_type_from_int(uint32_t value, Tox_Message_Type *out_enum) { switch (value) { case TOX_MESSAGE_TYPE_NORMAL: { - *out = TOX_MESSAGE_TYPE_NORMAL; + *out_enum = TOX_MESSAGE_TYPE_NORMAL; return true; } case TOX_MESSAGE_TYPE_ACTION: { - *out = TOX_MESSAGE_TYPE_ACTION; + *out_enum = TOX_MESSAGE_TYPE_ACTION; return true; } default: { - *out = TOX_MESSAGE_TYPE_NORMAL; + *out_enum = TOX_MESSAGE_TYPE_NORMAL; return false; } } @@ -132,26 +132,26 @@ bool tox_message_type_unpack(Tox_Message_Type *val, Bin_Unpack *bu) } non_null() -static bool tox_user_status_from_int(uint32_t value, Tox_User_Status *out) +static bool tox_user_status_from_int(uint32_t value, Tox_User_Status *out_enum) { switch (value) { case TOX_USER_STATUS_NONE: { - *out = TOX_USER_STATUS_NONE; + *out_enum = TOX_USER_STATUS_NONE; return true; } case TOX_USER_STATUS_AWAY: { - *out = TOX_USER_STATUS_AWAY; + *out_enum = TOX_USER_STATUS_AWAY; return true; } case TOX_USER_STATUS_BUSY: { - *out = TOX_USER_STATUS_BUSY; + *out_enum = TOX_USER_STATUS_BUSY; return true; } default: { - *out = TOX_USER_STATUS_NONE; + *out_enum = TOX_USER_STATUS_NONE; return false; } } @@ -165,19 +165,19 @@ bool tox_user_status_unpack(Tox_User_Status *val, Bin_Unpack *bu) } non_null() -static bool tox_group_privacy_state_from_int(uint32_t value, Tox_Group_Privacy_State *out) +static bool tox_group_privacy_state_from_int(uint32_t value, Tox_Group_Privacy_State *out_enum) { switch (value) { case TOX_GROUP_PRIVACY_STATE_PUBLIC: { - *out = TOX_GROUP_PRIVACY_STATE_PUBLIC; + *out_enum = TOX_GROUP_PRIVACY_STATE_PUBLIC; return true; } case TOX_GROUP_PRIVACY_STATE_PRIVATE: { - *out = TOX_GROUP_PRIVACY_STATE_PRIVATE; + *out_enum = TOX_GROUP_PRIVACY_STATE_PRIVATE; return true; } default: { - *out = TOX_GROUP_PRIVACY_STATE_PUBLIC; + *out_enum = TOX_GROUP_PRIVACY_STATE_PUBLIC; return false; } } @@ -189,23 +189,23 @@ bool tox_group_privacy_state_unpack(Tox_Group_Privacy_State *val, Bin_Unpack *bu && tox_group_privacy_state_from_int(u32, val); } non_null() -static bool tox_group_voice_state_from_int(uint32_t value, Tox_Group_Voice_State *out) +static bool tox_group_voice_state_from_int(uint32_t value, Tox_Group_Voice_State *out_enum) { switch (value) { case TOX_GROUP_VOICE_STATE_ALL: { - *out = TOX_GROUP_VOICE_STATE_ALL; + *out_enum = TOX_GROUP_VOICE_STATE_ALL; return true; } case TOX_GROUP_VOICE_STATE_MODERATOR: { - *out = TOX_GROUP_VOICE_STATE_MODERATOR; + *out_enum = TOX_GROUP_VOICE_STATE_MODERATOR; return true; } case TOX_GROUP_VOICE_STATE_FOUNDER: { - *out = TOX_GROUP_VOICE_STATE_FOUNDER; + *out_enum = TOX_GROUP_VOICE_STATE_FOUNDER; return true; } default: { - *out = TOX_GROUP_VOICE_STATE_ALL; + *out_enum = TOX_GROUP_VOICE_STATE_ALL; return false; } } @@ -218,19 +218,19 @@ bool tox_group_voice_state_unpack(Tox_Group_Voice_State *val, Bin_Unpack *bu) } non_null() -static bool tox_group_topic_lock_from_int(uint32_t value, Tox_Group_Topic_Lock *out) +static bool tox_group_topic_lock_from_int(uint32_t value, Tox_Group_Topic_Lock *out_enum) { switch (value) { case TOX_GROUP_TOPIC_LOCK_ENABLED: { - *out = TOX_GROUP_TOPIC_LOCK_ENABLED; + *out_enum = TOX_GROUP_TOPIC_LOCK_ENABLED; return true; } case TOX_GROUP_TOPIC_LOCK_DISABLED: { - *out = TOX_GROUP_TOPIC_LOCK_DISABLED; + *out_enum = TOX_GROUP_TOPIC_LOCK_DISABLED; return true; } default: { - *out = TOX_GROUP_TOPIC_LOCK_ENABLED; + *out_enum = TOX_GROUP_TOPIC_LOCK_ENABLED; return false; } } @@ -243,23 +243,23 @@ bool tox_group_topic_lock_unpack(Tox_Group_Topic_Lock *val, Bin_Unpack *bu) } non_null() -static bool tox_group_join_fail_from_int(uint32_t value, Tox_Group_Join_Fail *out) +static bool tox_group_join_fail_from_int(uint32_t value, Tox_Group_Join_Fail *out_enum) { switch (value) { case TOX_GROUP_JOIN_FAIL_PEER_LIMIT: { - *out = TOX_GROUP_JOIN_FAIL_PEER_LIMIT; + *out_enum = TOX_GROUP_JOIN_FAIL_PEER_LIMIT; return true; } case TOX_GROUP_JOIN_FAIL_INVALID_PASSWORD: { - *out = TOX_GROUP_JOIN_FAIL_INVALID_PASSWORD; + *out_enum = TOX_GROUP_JOIN_FAIL_INVALID_PASSWORD; return true; } case TOX_GROUP_JOIN_FAIL_UNKNOWN: { - *out = TOX_GROUP_JOIN_FAIL_UNKNOWN; + *out_enum = TOX_GROUP_JOIN_FAIL_UNKNOWN; return true; } default: { - *out = TOX_GROUP_JOIN_FAIL_PEER_LIMIT; + *out_enum = TOX_GROUP_JOIN_FAIL_PEER_LIMIT; return false; } } @@ -272,27 +272,27 @@ bool tox_group_join_fail_unpack(Tox_Group_Join_Fail *val, Bin_Unpack *bu) } non_null() -static bool tox_group_mod_event_from_int(uint32_t value, Tox_Group_Mod_Event *out) +static bool tox_group_mod_event_from_int(uint32_t value, Tox_Group_Mod_Event *out_enum) { switch (value) { case TOX_GROUP_MOD_EVENT_KICK: { - *out = TOX_GROUP_MOD_EVENT_KICK; + *out_enum = TOX_GROUP_MOD_EVENT_KICK; return true; } case TOX_GROUP_MOD_EVENT_OBSERVER: { - *out = TOX_GROUP_MOD_EVENT_OBSERVER; + *out_enum = TOX_GROUP_MOD_EVENT_OBSERVER; return true; } case TOX_GROUP_MOD_EVENT_USER: { - *out = TOX_GROUP_MOD_EVENT_USER; + *out_enum = TOX_GROUP_MOD_EVENT_USER; return true; } case TOX_GROUP_MOD_EVENT_MODERATOR: { - *out = TOX_GROUP_MOD_EVENT_MODERATOR; + *out_enum = TOX_GROUP_MOD_EVENT_MODERATOR; return true; } default: { - *out = TOX_GROUP_MOD_EVENT_KICK; + *out_enum = TOX_GROUP_MOD_EVENT_KICK; return false; } } @@ -305,35 +305,35 @@ bool tox_group_mod_event_unpack(Tox_Group_Mod_Event *val, Bin_Unpack *bu) } non_null() -static bool tox_group_exit_type_from_int(uint32_t value, Tox_Group_Exit_Type *out) +static bool tox_group_exit_type_from_int(uint32_t value, Tox_Group_Exit_Type *out_enum) { switch (value) { case TOX_GROUP_EXIT_TYPE_QUIT: { - *out = TOX_GROUP_EXIT_TYPE_QUIT; + *out_enum = TOX_GROUP_EXIT_TYPE_QUIT; return true; } case TOX_GROUP_EXIT_TYPE_TIMEOUT: { - *out = TOX_GROUP_EXIT_TYPE_TIMEOUT; + *out_enum = TOX_GROUP_EXIT_TYPE_TIMEOUT; return true; } case TOX_GROUP_EXIT_TYPE_DISCONNECTED: { - *out = TOX_GROUP_EXIT_TYPE_DISCONNECTED; + *out_enum = TOX_GROUP_EXIT_TYPE_DISCONNECTED; return true; } case TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED: { - *out = TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED; + *out_enum = TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED; return true; } case TOX_GROUP_EXIT_TYPE_KICK: { - *out = TOX_GROUP_EXIT_TYPE_KICK; + *out_enum = TOX_GROUP_EXIT_TYPE_KICK; return true; } case TOX_GROUP_EXIT_TYPE_SYNC_ERROR: { - *out = TOX_GROUP_EXIT_TYPE_SYNC_ERROR; + *out_enum = TOX_GROUP_EXIT_TYPE_SYNC_ERROR; return true; } default: { - *out = TOX_GROUP_EXIT_TYPE_QUIT; + *out_enum = TOX_GROUP_EXIT_TYPE_QUIT; return false; } } diff --git a/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.c b/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.c index c43e357528..b785c26732 100644 --- a/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.c +++ b/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.c @@ -67,7 +67,8 @@ void tox_pass_key_free(Tox_Pass_Key *key) * produce the same key as was previously used. Any data encrypted with this * module can be used as input. * - * The cipher text must be at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes in length. + * The cipher text must be at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes in + * length. * The salt must be TOX_PASS_SALT_LENGTH bytes in length. * If the passed byte arrays are smaller than required, the behaviour is * undefined. @@ -182,10 +183,11 @@ Tox_Pass_Key *tox_pass_key_derive_with_salt( } /** - * Encrypt a plain text with a key produced by tox_pass_key_derive or tox_pass_key_derive_with_salt. + * Encrypt a plain text with a key produced by tox_pass_key_derive or + * tox_pass_key_derive_with_salt. * - * The output array must be at least `plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH` - * bytes long. + * The output array must be at least + * `plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH` bytes long. * * @param plaintext A byte array of length `plaintext_len`. * @param plaintext_len The length of the plain text array. Bigger than 0. @@ -229,8 +231,8 @@ bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t plaintext[], si ciphertext += crypto_box_NONCEBYTES; /* now encrypt */ - if (encrypt_data_symmetric(key->key, nonce, plaintext, plaintext_len, ciphertext) - != plaintext_len + crypto_box_MACBYTES) { + const int32_t encrypted_len = encrypt_data_symmetric(key->key, nonce, plaintext, plaintext_len, ciphertext); + if (encrypted_len < 0 || (size_t)encrypted_len != plaintext_len + crypto_box_MACBYTES) { SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_FAILED); return false; } @@ -242,9 +244,9 @@ bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t plaintext[], si /** * Encrypts the given data with the given passphrase. * - * The output array must be at least `plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH` - * bytes long. This delegates to tox_pass_key_derive and - * tox_pass_key_encrypt. + * The output array must be at least + * `plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH` bytes long. This delegates + * to tox_pass_key_derive and tox_pass_key_encrypt. * * @param plaintext A byte array of length `plaintext_len`. * @param plaintext_len The length of the plain text array. Bigger than 0. @@ -280,7 +282,8 @@ bool tox_pass_encrypt(const uint8_t plaintext[], size_t plaintext_len, const uin * tox_pass_key_derive or tox_pass_key_derive_with_salt. * * @param ciphertext A byte array of length `ciphertext_len`. - * @param ciphertext_len The length of the cipher text array. At least TOX_PASS_ENCRYPTION_EXTRA_LENGTH. + * @param ciphertext_len The length of the cipher text array. At least + * TOX_PASS_ENCRYPTION_EXTRA_LENGTH. * @param plaintext The plain text array to write the decrypted data to. * * @return true on success. @@ -313,8 +316,8 @@ bool tox_pass_key_decrypt(const Tox_Pass_Key *key, const uint8_t ciphertext[], s ciphertext += crypto_box_NONCEBYTES; /* decrypt the ciphertext */ - if (decrypt_data_symmetric(key->key, nonce, ciphertext, decrypt_length + crypto_box_MACBYTES, plaintext) - != decrypt_length) { + const int32_t decrypted_len = decrypt_data_symmetric(key->key, nonce, ciphertext, decrypt_length + crypto_box_MACBYTES, plaintext); + if (decrypted_len < 0 || (size_t)decrypted_len != decrypt_length) { SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_FAILED); return false; } @@ -326,11 +329,13 @@ bool tox_pass_key_decrypt(const Tox_Pass_Key *key, const uint8_t ciphertext[], s /** * Decrypts the given data with the given passphrase. * - * The output array must be at least `ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH` - * bytes long. This delegates to tox_pass_key_decrypt. + * The output array must be at least + * `ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH` bytes long. This + * delegates to tox_pass_key_decrypt. * * @param ciphertext A byte array of length `ciphertext_len`. - * @param ciphertext_len The length of the cipher text array. At least TOX_PASS_ENCRYPTION_EXTRA_LENGTH. + * @param ciphertext_len The length of the cipher text array. At least + * TOX_PASS_ENCRYPTION_EXTRA_LENGTH. * @param passphrase The user-provided password. Can be empty. * @param passphrase_len The length of the password. * @param plaintext The plain text array to write the decrypted data to. diff --git a/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.h b/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.h index b9691551c7..e4cf116c97 100644 --- a/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.h +++ b/protocols/Tox/libtox/src/toxencryptsave/toxencryptsave.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-3.0-or-later - * Copyright © 2016-2018 The TokTok team. + * Copyright © 2016-2024 The TokTok team. * Copyright © 2013-2016 Tox Developers. */ @@ -165,9 +165,9 @@ typedef enum Tox_Err_Decryption { /** * Encrypts the given data with the given passphrase. * - * The output array must be at least `plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH` - * bytes long. This delegates to tox_pass_key_derive and - * tox_pass_key_encrypt. + * The output array must be at least + * `plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH` bytes long. This delegates + * to tox_pass_key_derive and tox_pass_key_encrypt. * * @param plaintext A byte array of length `plaintext_len`. * @param plaintext_len The length of the plain text array. Bigger than 0. @@ -183,11 +183,13 @@ bool tox_pass_encrypt(const uint8_t plaintext[], size_t plaintext_len, const uin /** * Decrypts the given data with the given passphrase. * - * The output array must be at least `ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH` - * bytes long. This delegates to tox_pass_key_decrypt. + * The output array must be at least + * `ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH` bytes long. This + * delegates to tox_pass_key_decrypt. * * @param ciphertext A byte array of length `ciphertext_len`. - * @param ciphertext_len The length of the cipher text array. At least TOX_PASS_ENCRYPTION_EXTRA_LENGTH. + * @param ciphertext_len The length of the cipher text array. At least + * TOX_PASS_ENCRYPTION_EXTRA_LENGTH. * @param passphrase The user-provided password. Can be empty. * @param passphrase_len The length of the password. * @param plaintext The plain text array to write the decrypted data to. @@ -215,7 +217,8 @@ bool tox_pass_decrypt(const uint8_t ciphertext[], size_t ciphertext_len, const u * user-provided password. * * The Tox_Pass_Key structure is hidden in the implementation. It can be created - * using tox_pass_key_derive or tox_pass_key_derive_with_salt and must be deallocated using tox_pass_key_free. + * using tox_pass_key_derive or tox_pass_key_derive_with_salt and must be + * deallocated using tox_pass_key_free. */ #ifndef TOX_PASS_KEY_DEFINED #define TOX_PASS_KEY_DEFINED @@ -261,10 +264,11 @@ Tox_Pass_Key *tox_pass_key_derive_with_salt( const uint8_t salt[TOX_PASS_SALT_LENGTH], Tox_Err_Key_Derivation *error); /** - * Encrypt a plain text with a key produced by tox_pass_key_derive or tox_pass_key_derive_with_salt. + * Encrypt a plain text with a key produced by tox_pass_key_derive or + * tox_pass_key_derive_with_salt. * - * The output array must be at least `plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH` - * bytes long. + * The output array must be at least + * `plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH` bytes long. * * @param plaintext A byte array of length `plaintext_len`. * @param plaintext_len The length of the plain text array. Bigger than 0. @@ -280,7 +284,8 @@ bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t plaintext[], si * tox_pass_key_derive or tox_pass_key_derive_with_salt. * * @param ciphertext A byte array of length `ciphertext_len`. - * @param ciphertext_len The length of the cipher text array. At least TOX_PASS_ENCRYPTION_EXTRA_LENGTH. + * @param ciphertext_len The length of the cipher text array. At least + * TOX_PASS_ENCRYPTION_EXTRA_LENGTH. * @param plaintext The plain text array to write the decrypted data to. * * @return true on success. @@ -315,7 +320,8 @@ typedef enum Tox_Err_Get_Salt { * produce the same key as was previously used. Any data encrypted with this * module can be used as input. * - * The cipher text must be at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes in length. + * The cipher text must be at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes in + * length. * The salt must be TOX_PASS_SALT_LENGTH bytes in length. * If the passed byte arrays are smaller than required, the behaviour is * undefined. |