forked from Green-Sky/tomato
Squashed 'external/toxcore/c-toxcore/' changes from e29e185c03..f1df709b87
f1df709b87 feat: add ngc events 1b6c907235 refactor: Make event dispatch ordered by receive time. b7f9367f6f test: Upgrade cppcheck, fix some warnings. 766e62bc89 chore: Use `pkg_search_module` directly in cmake. 00ff078f91 cleanup: Use target_link_libraries directly in cmake. c58928cc89 chore: Add `IMPORTED_TARGET` to pkg-config packages. 895a6af122 cleanup: Remove NaCl support. 41dfb1c1c0 fix: unpack enum function names in event impl generator 447666d1a1 chore: Disable targets for cross-compilation. 572924e924 chore: Build a docker image with coverage info in it. 415cb78f5e cleanup: Some portability/warning fixes for Windows builds. 425216d9ec fix: Correct a use-after-free and fix some memory leaks. 4b1cfa3e08 refactor: Change all enum-like `#define` sequences into enums. d3c2704fa9 chore: Fix make_single_file to support core-only. 0ce46b644e refactor: Change the `TCP_PACKET_*` defines into an enum. 22cd38ad50 adopt event impl generation tool to #2392 f31ea1088a add the event impl generation tool 4e603bb613 refactor: Use `enum-from-int` rule from tokstyle. 19d8f180d6 chore: Update github actions `uses`. 6a895be0c7 test: Make esp32 build actually try to instantiate tox. 65d09c9bfb cleanup: Remove test net support. REVERT: e29e185c03 feat: add ngc events git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: f1df709b8792da4c0e946d826b11df77d565064d
This commit is contained in:
@ -757,17 +757,34 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Userstatus userstatus_from_int(uint8_t status)
|
||||
non_null()
|
||||
static bool userstatus_from_int(uint8_t status, Userstatus *out)
|
||||
{
|
||||
switch (status) {
|
||||
case 0:
|
||||
return USERSTATUS_NONE;
|
||||
case 1:
|
||||
return USERSTATUS_AWAY;
|
||||
case 2:
|
||||
return USERSTATUS_BUSY;
|
||||
default:
|
||||
return USERSTATUS_INVALID;
|
||||
case USERSTATUS_NONE: {
|
||||
*out = USERSTATUS_NONE;
|
||||
return true;
|
||||
}
|
||||
|
||||
case USERSTATUS_AWAY: {
|
||||
*out = USERSTATUS_AWAY;
|
||||
return true;
|
||||
}
|
||||
|
||||
case USERSTATUS_BUSY: {
|
||||
*out = USERSTATUS_BUSY;
|
||||
return true;
|
||||
}
|
||||
|
||||
case USERSTATUS_INVALID: {
|
||||
*out = USERSTATUS_INVALID;
|
||||
return true;
|
||||
}
|
||||
|
||||
default: {
|
||||
*out = USERSTATUS_INVALID;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -781,7 +798,7 @@ int m_set_userstatus(Messenger *m, uint8_t status)
|
||||
return 0;
|
||||
}
|
||||
|
||||
m->userstatus = userstatus_from_int(status);
|
||||
userstatus_from_int(status, &m->userstatus);
|
||||
|
||||
for (uint32_t i = 0; i < m->numfriends; ++i) {
|
||||
m->friendlist[i].userstatus_sent = false;
|
||||
@ -937,7 +954,7 @@ static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, co
|
||||
non_null()
|
||||
static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
|
||||
{
|
||||
m->friendlist[friendnumber].userstatus = userstatus_from_int(status);
|
||||
userstatus_from_int(status, &m->friendlist[friendnumber].userstatus);
|
||||
}
|
||||
|
||||
non_null()
|
||||
@ -2095,9 +2112,8 @@ static int m_handle_packet_userstatus(Messenger *m, const int i, const uint8_t *
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Userstatus status = userstatus_from_int(data[0]);
|
||||
|
||||
if (status == USERSTATUS_INVALID) {
|
||||
Userstatus status;
|
||||
if (!userstatus_from_int(data[0], &status)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2343,8 +2359,6 @@ static int m_handle_packet_msi(Messenger *m, const int i, const uint8_t *data, c
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_invite_groupchat(Messenger *m, const int i, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
{
|
||||
#ifndef VANILLA_NACL
|
||||
|
||||
// first two bytes are messenger packet type and group invite type
|
||||
if (data_length < 2 + GC_JOIN_DATA_LENGTH) {
|
||||
return 0;
|
||||
@ -2365,8 +2379,6 @@ static int m_handle_packet_invite_groupchat(Messenger *m, const int i, const uin
|
||||
handle_gc_invite_confirmed_packet(m->group_handler, i, join_data, join_data_len);
|
||||
}
|
||||
|
||||
#endif // VANILLA_NACL
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2547,7 +2559,6 @@ uint32_t messenger_run_interval(const Messenger *m)
|
||||
*
|
||||
* @retval true if success.
|
||||
*/
|
||||
#ifndef VANILLA_NACL
|
||||
non_null()
|
||||
static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend *onion_friend)
|
||||
{
|
||||
@ -2623,7 +2634,6 @@ static void do_gc_onion_friends(const Messenger *m)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // VANILLA_NACL
|
||||
|
||||
/** @brief The main loop that needs to be run at least 20 times per second. */
|
||||
void do_messenger(Messenger *m, void *userdata)
|
||||
@ -2661,11 +2671,9 @@ void do_messenger(Messenger *m, void *userdata)
|
||||
do_onion_client(m->onion_c);
|
||||
do_friend_connections(m->fr_c, userdata);
|
||||
do_friends(m, userdata);
|
||||
#ifndef VANILLA_NACL
|
||||
do_gc(m->group_handler, userdata);
|
||||
do_gca(m->mono_time, m->group_announce);
|
||||
do_gc_onion_friends(m);
|
||||
#endif
|
||||
m_connection_status_callback(m, userdata);
|
||||
|
||||
if (mono_time_get(m->mono_time) > m->lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) {
|
||||
@ -3148,7 +3156,6 @@ static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, ui
|
||||
return STATE_LOAD_STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
#ifndef VANILLA_NACL
|
||||
non_null()
|
||||
static void pack_groupchats(const GC_Session *c, Bin_Pack *bp)
|
||||
{
|
||||
@ -3176,7 +3183,7 @@ static bool pack_groupchats_handler(Bin_Pack *bp, const Logger *log, const void
|
||||
non_null()
|
||||
static uint32_t saved_groups_size(const Messenger *m)
|
||||
{
|
||||
GC_Session *c = m->group_handler;
|
||||
const GC_Session *c = m->group_handler;
|
||||
return bin_pack_obj_size(pack_groupchats_handler, m->log, c);
|
||||
}
|
||||
|
||||
@ -3245,7 +3252,6 @@ static State_Load_Status groups_load(Messenger *m, const uint8_t *data, uint32_t
|
||||
|
||||
return STATE_LOAD_STATUS_CONTINUE;
|
||||
}
|
||||
#endif /* VANILLA_NACL */
|
||||
|
||||
// name state plugin
|
||||
non_null()
|
||||
@ -3433,9 +3439,7 @@ static void m_register_default_plugins(Messenger *m)
|
||||
m_register_state_plugin(m, STATE_TYPE_STATUSMESSAGE, status_message_size, load_status_message,
|
||||
save_status_message);
|
||||
m_register_state_plugin(m, STATE_TYPE_STATUS, status_size, load_status, save_status);
|
||||
#ifndef VANILLA_NACL
|
||||
m_register_state_plugin(m, STATE_TYPE_GROUPS, saved_groups_size, groups_load, groups_save);
|
||||
#endif
|
||||
m_register_state_plugin(m, STATE_TYPE_TCP_RELAY, tcp_relay_size, load_tcp_relays, save_tcp_relays);
|
||||
m_register_state_plugin(m, STATE_TYPE_PATH_NODE, path_node_size, load_path_nodes, save_path_nodes);
|
||||
}
|
||||
@ -3579,14 +3583,14 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
||||
|
||||
if (m->net == nullptr) {
|
||||
friendreq_kill(m->fr);
|
||||
logger_kill(m->log);
|
||||
mem_delete(mem, m);
|
||||
|
||||
if (error != nullptr && net_err == 1) {
|
||||
LOGGER_WARNING(m->log, "network initialisation failed (no ports available)");
|
||||
*error = MESSENGER_ERROR_PORT;
|
||||
}
|
||||
|
||||
logger_kill(m->log);
|
||||
mem_delete(mem, m);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -3613,7 +3617,6 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifndef VANILLA_NACL
|
||||
m->group_announce = new_gca_list();
|
||||
|
||||
if (m->group_announce == nullptr) {
|
||||
@ -3628,11 +3631,13 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#endif /* VANILLA_NACL */
|
||||
|
||||
if (options->dht_announcements_enabled) {
|
||||
m->forwarding = new_forwarding(m->log, m->rng, m->mono_time, m->dht);
|
||||
m->announce = new_announcements(m->log, m->mem, m->rng, m->mono_time, m->forwarding);
|
||||
if (m->forwarding != nullptr) {
|
||||
m->announce = new_announcements(m->log, m->mem, m->rng, m->mono_time, m->forwarding);
|
||||
} else {
|
||||
m->announce = nullptr;
|
||||
}
|
||||
} else {
|
||||
m->forwarding = nullptr;
|
||||
m->announce = nullptr;
|
||||
@ -3652,9 +3657,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
||||
kill_onion(m->onion);
|
||||
kill_onion_announce(m->onion_a);
|
||||
kill_onion_client(m->onion_c);
|
||||
#ifndef VANILLA_NACL
|
||||
kill_gca(m->group_announce);
|
||||
#endif /* VANILLA_NACL */
|
||||
kill_friend_connections(m->fr_c);
|
||||
kill_announcements(m->announce);
|
||||
kill_forwarding(m->forwarding);
|
||||
@ -3667,7 +3670,6 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifndef VANILLA_NACL
|
||||
gca_onion_init(m->group_announce, m->onion_a);
|
||||
|
||||
m->group_handler = new_dht_groupchats(m);
|
||||
@ -3691,8 +3693,6 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#endif /* VANILLA_NACL */
|
||||
|
||||
if (options->tcp_server_port != 0) {
|
||||
m->tcp_server = new_tcp_server(m->log, m->mem, m->rng, m->ns, options->ipv6enabled, 1,
|
||||
&options->tcp_server_port, dht_get_self_secret_key(m->dht),
|
||||
@ -3703,14 +3703,10 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
||||
|
||||
kill_onion(m->onion);
|
||||
kill_onion_announce(m->onion_a);
|
||||
#ifndef VANILLA_NACL
|
||||
kill_dht_groupchats(m->group_handler);
|
||||
#endif
|
||||
kill_friend_connections(m->fr_c);
|
||||
kill_onion_client(m->onion_c);
|
||||
#ifndef VANILLA_NACL
|
||||
kill_gca(m->group_announce);
|
||||
#endif
|
||||
kill_announcements(m->announce);
|
||||
kill_forwarding(m->forwarding);
|
||||
kill_net_crypto(m->net_crypto);
|
||||
@ -3762,14 +3758,10 @@ void kill_messenger(Messenger *m)
|
||||
|
||||
kill_onion(m->onion);
|
||||
kill_onion_announce(m->onion_a);
|
||||
#ifndef VANILLA_NACL
|
||||
kill_dht_groupchats(m->group_handler);
|
||||
#endif
|
||||
kill_friend_connections(m->fr_c);
|
||||
kill_onion_client(m->onion_c);
|
||||
#ifndef VANILLA_NACL
|
||||
kill_gca(m->group_announce);
|
||||
#endif
|
||||
kill_announcements(m->announce);
|
||||
kill_forwarding(m->forwarding);
|
||||
kill_net_crypto(m->net_crypto);
|
||||
@ -3780,11 +3772,11 @@ void kill_messenger(Messenger *m)
|
||||
clear_receipts(m, i);
|
||||
}
|
||||
|
||||
logger_kill(m->log);
|
||||
mem_delete(m->mem, m->friendlist);
|
||||
friendreq_kill(m->fr);
|
||||
|
||||
mem_delete(m->mem, m->options.state_plugins);
|
||||
logger_kill(m->log);
|
||||
mem_delete(m->mem, m);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user