forked from Green-Sky/tomato
Squashed 'external/toxcore/c-toxcore/' changes from 11ab1d2a723..d9b8fa6098d
d9b8fa6098d fix: Fake broadcast address for 127.x.x.x aa649165a57 chore: Add code for future netprof TCP testing 9e5693de5ac chore: add to_string functions for netprof enums 52d915e6a90 cleanup: Heap allocate network profile objects 80fabd4a729 feat: Implement Tox network profiler 05abe083cb6 cleanup: Some random cleanups, mostly related to mem. 5cca24513b8 cleanup: Check that onion IP/Port packing worked. e092ecd1244 cleanup: Use tox memory allocator in some more places. 3cfe41c7587 fix: Avoid `memcpy`-ing structs into onion ping id data. e32ac001938 fix: Add more information on why the frame was not sent. ab887003687 fix: Allow TCP connections to fail `connect` calls. 7603170e663 refactor: Use tox memory in group connection allocations. 5bd8a85eb89 cleanup: Align internal logger with external on type of source line. e9bf524d9e1 cleanup: Add missing `#include` to sort_test.cc. d10c966b998 feat: Add `to_string` functions for toxencryptsave errors. 7bfd0dc8003 docs: Update the docs for group join functions 380dde9f2ae test: Add more logging to TCP connection constructor. 0f12f384c8c cleanup: Reduce stack frame sizes to below 4096 bytes. bc43cec0626 chore: Happy new year! fbe78f1702e cleanup: Add a `TOX_HIDE_DEPRECATED` check to hide deprecated symbols. 44d9da07e77 refactor: Use tox memory for group moderation/pack allocations. 7f26d520168 refactor: Use tox memory in group chats allocations. 2f62f3d0e77 refactor: Use tox Memory for group allocations. 8a968162041 chore: Add dispatch/events headers to bazel export. 2bbfb35abf6 docs: Output the error code string instead of int. in toxav logging d55d0e4eaef cleanup: Remove redundant code for checking if group exists 2a6dc643338 chore: Upgrade dependencies for websockify. fc0650601c1 fix: Allow peers to reconnect to group chats using a password git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: d9b8fa6098de6c074038b6664d2572627540b148
This commit is contained in:
@ -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 © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
#include "group.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h> // calloc, free
|
||||
#include <string.h>
|
||||
|
||||
#include "DHT.h"
|
||||
@ -149,6 +148,7 @@ typedef struct Group_c {
|
||||
} Group_c;
|
||||
|
||||
struct Group_Chats {
|
||||
const Memory *mem;
|
||||
const Mono_Time *mono_time;
|
||||
|
||||
Messenger *m;
|
||||
@ -248,19 +248,19 @@ static bool is_groupnumber_valid(const Group_Chats *g_c, uint32_t groupnumber)
|
||||
|
||||
/** @brief Set the size of the groupchat list to num.
|
||||
*
|
||||
* @retval false if realloc fails.
|
||||
* @retval false if mem_vrealloc fails.
|
||||
* @retval true if it succeeds.
|
||||
*/
|
||||
non_null()
|
||||
static bool realloc_conferences(Group_Chats *g_c, uint16_t num)
|
||||
{
|
||||
if (num == 0) {
|
||||
free(g_c->chats);
|
||||
mem_delete(g_c->mem, g_c->chats);
|
||||
g_c->chats = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
Group_c *newgroup_chats = (Group_c *)realloc(g_c->chats, num * sizeof(Group_c));
|
||||
Group_c *newgroup_chats = (Group_c *)mem_vrealloc(g_c->mem, g_c->chats, num, sizeof(Group_c));
|
||||
|
||||
if (newgroup_chats == nullptr) {
|
||||
return false;
|
||||
@ -302,10 +302,10 @@ static int32_t create_group_chat(Group_Chats *g_c)
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void wipe_group_c(Group_c *g)
|
||||
static void wipe_group_c(const Memory *mem, Group_c *g)
|
||||
{
|
||||
free(g->frozen);
|
||||
free(g->group);
|
||||
mem_delete(mem, g->frozen);
|
||||
mem_delete(mem, g->group);
|
||||
crypto_memzero(g, sizeof(Group_c));
|
||||
}
|
||||
|
||||
@ -320,7 +320,7 @@ static bool wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber)
|
||||
return false;
|
||||
}
|
||||
|
||||
wipe_group_c(&g_c->chats[groupnumber]);
|
||||
wipe_group_c(g_c->mem, &g_c->chats[groupnumber]);
|
||||
|
||||
uint16_t i;
|
||||
|
||||
@ -669,7 +669,7 @@ static int get_frozen_index(const Group_c *g, uint16_t peer_number)
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool delete_frozen(Group_c *g, uint32_t frozen_index)
|
||||
static bool delete_frozen(const Memory *mem, Group_c *g, uint32_t frozen_index)
|
||||
{
|
||||
if (frozen_index >= g->numfrozen) {
|
||||
return false;
|
||||
@ -678,14 +678,14 @@ static bool delete_frozen(Group_c *g, uint32_t frozen_index)
|
||||
--g->numfrozen;
|
||||
|
||||
if (g->numfrozen == 0) {
|
||||
free(g->frozen);
|
||||
mem_delete(mem, g->frozen);
|
||||
g->frozen = nullptr;
|
||||
} else {
|
||||
if (g->numfrozen != frozen_index) {
|
||||
g->frozen[frozen_index] = g->frozen[g->numfrozen];
|
||||
}
|
||||
|
||||
Group_Peer *const frozen_temp = (Group_Peer *)realloc(g->frozen, g->numfrozen * sizeof(Group_Peer));
|
||||
Group_Peer *const frozen_temp = (Group_Peer *)mem_vrealloc(mem, g->frozen, g->numfrozen, sizeof(Group_Peer));
|
||||
|
||||
if (frozen_temp == nullptr) {
|
||||
return false;
|
||||
@ -726,7 +726,7 @@ static int note_peer_active(Group_Chats *g_c, uint32_t groupnumber, uint16_t pee
|
||||
|
||||
/* Now thaw the peer */
|
||||
|
||||
Group_Peer *temp = (Group_Peer *)realloc(g->group, (g->numpeers + 1) * sizeof(Group_Peer));
|
||||
Group_Peer *temp = (Group_Peer *)mem_vrealloc(g_c->mem, g->group, g->numpeers + 1, sizeof(Group_Peer));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return -1;
|
||||
@ -743,7 +743,7 @@ static int note_peer_active(Group_Chats *g_c, uint32_t groupnumber, uint16_t pee
|
||||
|
||||
++g->numpeers;
|
||||
|
||||
delete_frozen(g, frozen_index);
|
||||
delete_frozen(g_c->mem, g, frozen_index);
|
||||
|
||||
if (g_c->peer_list_changed_callback != nullptr) {
|
||||
g_c->peer_list_changed_callback(g_c->m, groupnumber, userdata);
|
||||
@ -779,7 +779,7 @@ static void delete_any_peer_with_pk(Group_Chats *g_c, uint32_t groupnumber, cons
|
||||
const int frozen_index = frozen_in_group(g, real_pk);
|
||||
|
||||
if (frozen_index >= 0) {
|
||||
delete_frozen(g, frozen_index);
|
||||
delete_frozen(g_c->mem, g, frozen_index);
|
||||
}
|
||||
}
|
||||
|
||||
@ -839,7 +839,7 @@ static int addpeer(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_p
|
||||
|
||||
delete_any_peer_with_pk(g_c, groupnumber, real_pk, userdata);
|
||||
|
||||
Group_Peer *temp = (Group_Peer *)realloc(g->group, (g->numpeers + 1) * sizeof(Group_Peer));
|
||||
Group_Peer *temp = (Group_Peer *)mem_vrealloc(g_c->mem, g->group, g->numpeers + 1, sizeof(Group_Peer));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return -1;
|
||||
@ -930,14 +930,14 @@ static bool delpeer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void
|
||||
void *peer_object = g->group[peer_index].object;
|
||||
|
||||
if (g->numpeers == 0) {
|
||||
free(g->group);
|
||||
mem_delete(g_c->mem, g->group);
|
||||
g->group = nullptr;
|
||||
} else {
|
||||
if (g->numpeers != (uint32_t)peer_index) {
|
||||
g->group[peer_index] = g->group[g->numpeers];
|
||||
}
|
||||
|
||||
Group_Peer *temp = (Group_Peer *)realloc(g->group, g->numpeers * sizeof(Group_Peer));
|
||||
Group_Peer *temp = (Group_Peer *)mem_vrealloc(g_c->mem, g->group, g->numpeers, sizeof(Group_Peer));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return false;
|
||||
@ -1034,7 +1034,7 @@ static bool delete_old_frozen(Group_c *g, const Memory *mem)
|
||||
}
|
||||
|
||||
if (g->maxfrozen == 0) {
|
||||
free(g->frozen);
|
||||
mem_delete(mem, g->frozen);
|
||||
g->frozen = nullptr;
|
||||
g->numfrozen = 0;
|
||||
return true;
|
||||
@ -1042,7 +1042,7 @@ static bool delete_old_frozen(Group_c *g, const Memory *mem)
|
||||
|
||||
merge_sort(g->frozen, g->numfrozen, mem, &group_peer_cmp_funcs);
|
||||
|
||||
Group_Peer *temp = (Group_Peer *)realloc(g->frozen, g->maxfrozen * sizeof(Group_Peer));
|
||||
Group_Peer *temp = (Group_Peer *)mem_vrealloc(mem, g->frozen, g->maxfrozen, sizeof(Group_Peer));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return false;
|
||||
@ -1067,7 +1067,7 @@ static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index,
|
||||
return false;
|
||||
}
|
||||
|
||||
Group_Peer *temp = (Group_Peer *)realloc(g->frozen, (g->numfrozen + 1) * sizeof(Group_Peer));
|
||||
Group_Peer *temp = (Group_Peer *)mem_vrealloc(g_c->mem, g->frozen, g->numfrozen + 1, sizeof(Group_Peer));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return false;
|
||||
@ -1085,7 +1085,7 @@ static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index,
|
||||
|
||||
++g->numfrozen;
|
||||
|
||||
delete_old_frozen(g, g_c->m->mem);
|
||||
delete_old_frozen(g, g_c->mem);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1572,7 +1572,7 @@ int group_set_max_frozen(const Group_Chats *g_c, uint32_t groupnumber, uint32_t
|
||||
}
|
||||
|
||||
g->maxfrozen = maxfrozen;
|
||||
delete_old_frozen(g, g_c->m->mem);
|
||||
delete_old_frozen(g, g_c->mem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -3665,7 +3665,7 @@ static uint32_t load_group(Group_c *g, const Group_Chats *g_c, const uint8_t *da
|
||||
}
|
||||
|
||||
// This is inefficient, but allows us to check data consistency before allocating memory
|
||||
Group_Peer *tmp_frozen = (Group_Peer *)realloc(g->frozen, (j + 1) * sizeof(Group_Peer));
|
||||
Group_Peer *tmp_frozen = (Group_Peer *)mem_vrealloc(g_c->mem, g->frozen, j + 1, sizeof(Group_Peer));
|
||||
|
||||
if (tmp_frozen == nullptr) {
|
||||
// Memory allocation failure
|
||||
@ -3805,18 +3805,19 @@ bool conferences_load_state_section(Group_Chats *g_c, const uint8_t *data, uint3
|
||||
}
|
||||
|
||||
/** Create new groupchat instance. */
|
||||
Group_Chats *new_groupchats(const Mono_Time *mono_time, Messenger *m)
|
||||
Group_Chats *new_groupchats(const Mono_Time *mono_time, const Memory *mem, Messenger *m)
|
||||
{
|
||||
if (m == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Group_Chats *temp = (Group_Chats *)calloc(1, sizeof(Group_Chats));
|
||||
Group_Chats *temp = (Group_Chats *)mem_alloc(mem, sizeof(Group_Chats));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
temp->mem = mem;
|
||||
temp->mono_time = mono_time;
|
||||
temp->m = m;
|
||||
temp->fr_c = m->fr_c;
|
||||
@ -3867,7 +3868,7 @@ void kill_groupchats(Group_Chats *g_c)
|
||||
m_callback_conference_invite(g_c->m, nullptr);
|
||||
set_global_status_callback(g_c->m->fr_c, nullptr, nullptr);
|
||||
g_c->m->conferences_object = nullptr;
|
||||
free(g_c);
|
||||
mem_delete(g_c->mem, g_c);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user