diff options
Diffstat (limited to 'protocols/Tox/libtox/src/toxcore/tox.c')
-rw-r--r-- | protocols/Tox/libtox/src/toxcore/tox.c | 318 |
1 files changed, 179 insertions, 139 deletions
diff --git a/protocols/Tox/libtox/src/toxcore/tox.c b/protocols/Tox/libtox/src/toxcore/tox.c index 085fab2ec1..8e1b43903d 100644 --- a/protocols/Tox/libtox/src/toxcore/tox.c +++ b/protocols/Tox/libtox/src/toxcore/tox.c @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-3.0-or-later - * Copyright © 2016-2018 The TokTok team. + * Copyright © 2016-2025 The TokTok team. * Copyright © 2013 Tox project. */ @@ -32,8 +32,10 @@ #include "network.h" #include "onion_client.h" #include "state.h" +#include "tox_log_level.h" +#include "tox_options.h" #include "tox_private.h" -#include "tox_struct.h" +#include "tox_struct.h" // IWYU pragma: keep #include "util.h" #include "../toxencryptsave/defines.h" @@ -79,7 +81,7 @@ struct Tox_Userdata { static logger_cb tox_log_handler; non_null(1, 3, 5, 6) nullable(7) -static void tox_log_handler(void *context, Logger_Level level, const char *file, int line, const char *func, +static void tox_log_handler(void *context, Logger_Level level, const char *file, uint32_t line, const char *func, const char *message, void *userdata) { Tox *tox = (Tox *)context; @@ -360,20 +362,22 @@ static void tox_conference_peer_list_changed_handler(Messenger *m, uint32_t conf } } -static dht_get_nodes_response_cb tox_dht_get_nodes_response_handler; +static dht_nodes_response_cb tox_dht_nodes_response_handler; non_null(1, 2) nullable(3) -static void tox_dht_get_nodes_response_handler(const DHT *dht, const Node_format *node, void *user_data) +static void tox_dht_nodes_response_handler(const DHT *dht, const Node_format *node, void *user_data) { struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data; - if (tox_data->tox->dht_get_nodes_response_callback == nullptr) { + if (tox_data->tox->dht_nodes_response_callback == nullptr) { return; } Ip_Ntoa ip_str; + net_ip_ntoa(&node->ip_port.ip, &ip_str); + tox_unlock(tox_data->tox); - tox_data->tox->dht_get_nodes_response_callback( - tox_data->tox, node->public_key, net_ip_ntoa(&node->ip_port.ip, &ip_str), net_ntohs(node->ip_port.port), + tox_data->tox->dht_nodes_response_callback( + tox_data->tox, node->public_key, ip_str.buf, ip_str.length, net_ntohs(node->ip_port.port), tox_data->user_data); tox_lock(tox_data->tox); } @@ -524,7 +528,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 +540,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 +716,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 +741,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) { @@ -752,6 +756,8 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) Messenger_Options m_options = {false}; + m_options.dns_enabled = !tox_options_get_experimental_disable_dns(opts); + bool load_savedata_sk = false; bool load_savedata_tox = false; @@ -855,9 +861,10 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) } const char *const proxy_host = tox_options_get_proxy_host(opts); + const bool dns_enabled = !tox_options_get_experimental_disable_dns(opts); if (proxy_host == nullptr - || !addr_resolve_or_parse_ip(tox->sys.ns, proxy_host, &m_options.proxy_info.ip_port.ip, nullptr)) { + || !addr_resolve_or_parse_ip(tox->sys.ns, tox->sys.mem, proxy_host, &m_options.proxy_info.ip_port.ip, nullptr, dns_enabled)) { SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_HOST); // TODO(irungentoo): TOX_ERR_NEW_PROXY_NOT_FOUND if domain. mem_delete(sys->mem, tox); @@ -926,7 +933,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) return nullptr; } - tox->m->conferences_object = new_groupchats(tox->mono_time, tox->m); + tox->m->conferences_object = new_groupchats(tox->mono_time, sys->mem, tox->m); if (tox->m->conferences_object == nullptr) { kill_messenger(tox->m); @@ -983,7 +990,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) callback_file_reqchunk(tox->m, tox_file_chunk_request_handler); callback_file_sendrequest(tox->m, tox_file_recv_handler); callback_file_data(tox->m, tox_file_recv_chunk_handler); - dht_callback_get_nodes_response(tox->m->dht, tox_dht_get_nodes_response_handler); + dht_callback_nodes_response(tox->m->dht, tox_dht_nodes_response_handler); g_callback_group_invite(tox->m->conferences_object, tox_conference_invite_handler); g_callback_group_connected(tox->m->conferences_object, tox_conference_connected_handler); g_callback_group_message(tox->m->conferences_object, tox_conference_message_handler); @@ -1020,6 +1027,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 +1065,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); @@ -1108,7 +1146,7 @@ static int32_t resolve_bootstrap_node(Tox *tox, const char *host, uint16_t port, return -1; } - const int32_t count = net_getipport(tox->sys.mem, host, root, TOX_SOCK_DGRAM); + const int32_t count = net_getipport(tox->sys.ns, tox->sys.mem, host, root, TOX_SOCK_DGRAM, tox->m->options.dns_enabled); if (count < 1) { LOGGER_DEBUG(tox->m->log, "could not resolve bootstrap node '%s'", host); @@ -2520,6 +2558,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); @@ -3209,7 +3253,7 @@ bool tox_group_reconnect(Tox *tox, uint32_t group_number, Tox_Err_Group_Reconnec return false; } - const int ret = gc_rejoin_group(tox->m->group_handler, chat); + const int ret = gc_rejoin_group(tox->m->group_handler, chat, nullptr, 0); tox_unlock(tox); switch (ret) { @@ -3688,7 +3732,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 +3740,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 +3753,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 +3761,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 +3769,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 +3781,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 +3794,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 +3802,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 +3810,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 +3823,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 +3847,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 +3855,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 +3868,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 +3876,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 +3890,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 +3898,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 +3911,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 +3919,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 +3932,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 +3940,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 +3954,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 +3962,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 +3976,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 +3997,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 +4038,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 +4049,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 +4145,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 +4202,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 +4276,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 +4318,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 +4334,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 +4343,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 +4359,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 +4390,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 +4401,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 +4437,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 +4448,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 +4489,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 +4500,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 +4536,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 +4545,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 +4561,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 +4627,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 +4638,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 +4679,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 +4690,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; } } |