mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Removed useless code from groupchats.
This commit is contained in:
parent
1e44edaf8f
commit
964fcacb32
104
toxcore/group.c
104
toxcore/group.c
|
@ -28,105 +28,6 @@
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
/* return 1 if the con_number is not valid.
|
|
||||||
* return 0 if the con_number is valid.
|
|
||||||
*/
|
|
||||||
static uint8_t con_number_not_valid(const Group_Chats *g_c, int con_number)
|
|
||||||
{
|
|
||||||
if ((unsigned int)con_number >= g_c->num_cons)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (g_c->cons == NULL)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (g_c->cons[con_number].status == GROUPCON_STATUS_NONE)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Set the size of the groupchat connections list to num.
|
|
||||||
*
|
|
||||||
* return -1 if realloc fails.
|
|
||||||
* return 0 if it succeeds.
|
|
||||||
*/
|
|
||||||
static int realloc_groupcons(Group_Chats *g_c, uint32_t num)
|
|
||||||
{
|
|
||||||
if (num == 0) {
|
|
||||||
free(g_c->cons);
|
|
||||||
g_c->cons = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Group_Connection *newgroup_cons = realloc(g_c->cons, num * sizeof(Group_Connection));
|
|
||||||
|
|
||||||
if (newgroup_cons == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
g_c->cons = newgroup_cons;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create a new empty groupchat connection.
|
|
||||||
*
|
|
||||||
* return -1 on failure.
|
|
||||||
* return con_number on success.
|
|
||||||
*/
|
|
||||||
static int create_group_con(Group_Chats *g_c)
|
|
||||||
{
|
|
||||||
uint32_t i;
|
|
||||||
|
|
||||||
for (i = 0; i < g_c->num_cons; ++i) {
|
|
||||||
if (g_c->cons[i].status == GROUPCON_STATUS_NONE)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = -1;
|
|
||||||
|
|
||||||
if (realloc_groupcons(g_c, g_c->num_cons + 1) == 0) {
|
|
||||||
id = g_c->num_cons;
|
|
||||||
++g_c->num_cons;
|
|
||||||
memset(&(g_c->cons[id]), 0, sizeof(Group_Connection));
|
|
||||||
}
|
|
||||||
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wipe a groupchat connection.
|
|
||||||
*
|
|
||||||
* return -1 on failure.
|
|
||||||
* return 0 on success.
|
|
||||||
*/
|
|
||||||
static int wipe_group_con(Group_Chats *g_c, int con_number)
|
|
||||||
{
|
|
||||||
if (con_number_not_valid(g_c, con_number))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
uint32_t i;
|
|
||||||
memset(&(g_c->cons[con_number]), 0 , sizeof(Group_c));
|
|
||||||
|
|
||||||
for (i = g_c->num_cons; i != 0; --i) {
|
|
||||||
if (g_c->cons[i - 1].status != GROUPCON_STATUS_NONE)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_c->num_cons != i) {
|
|
||||||
g_c->num_cons = i;
|
|
||||||
realloc_groupcons(g_c, g_c->num_cons);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Group_Connection *get_con_group(Group_Chats *g_c, int con_number)
|
|
||||||
{
|
|
||||||
if (con_number_not_valid(g_c, con_number))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return &g_c->cons[con_number];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* return 1 if the groupnumber is not valid.
|
/* return 1 if the groupnumber is not valid.
|
||||||
* return 0 if the groupnumber is valid.
|
* return 0 if the groupnumber is valid.
|
||||||
*/
|
*/
|
||||||
|
@ -612,6 +513,8 @@ static unsigned int send_message_all_close(const Group_Chats *g_c, int groupnumb
|
||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAX_GROUP_MESSAGE_DATA_LEN (MAX_CRYPTO_DATA_SIZE - (1 + MIN_MESSAGE_PACKET_LEN))
|
||||||
|
|
||||||
/* Send data of len with message_id to groupnumber.
|
/* Send data of len with message_id to groupnumber.
|
||||||
*
|
*
|
||||||
* return number of peers it was sent to on success.
|
* return number of peers it was sent to on success.
|
||||||
|
@ -620,6 +523,9 @@ static unsigned int send_message_all_close(const Group_Chats *g_c, int groupnumb
|
||||||
static unsigned int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data,
|
static unsigned int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data,
|
||||||
uint16_t len)
|
uint16_t len)
|
||||||
{
|
{
|
||||||
|
if (len > MAX_GROUP_MESSAGE_DATA_LEN)
|
||||||
|
return 0;
|
||||||
|
|
||||||
Group_c *g = get_group_c(g_c, groupnumber);
|
Group_c *g = get_group_c(g_c, groupnumber);
|
||||||
|
|
||||||
if (!g)
|
if (!g)
|
||||||
|
|
|
@ -32,11 +32,6 @@ enum {
|
||||||
GROUPCHAT_STATUS_VALID
|
GROUPCHAT_STATUS_VALID
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
|
||||||
GROUPCON_STATUS_NONE,
|
|
||||||
GROUPCON_STATUS_VALID
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t client_id[crypto_box_PUBLICKEYBYTES];
|
uint8_t client_id[crypto_box_PUBLICKEYBYTES];
|
||||||
uint64_t pingid;
|
uint64_t pingid;
|
||||||
|
@ -83,22 +78,12 @@ typedef struct {
|
||||||
uint16_t peer_number;
|
uint16_t peer_number;
|
||||||
} Group_c;
|
} Group_c;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint8_t status;
|
|
||||||
|
|
||||||
uint8_t real_public_key[crypto_box_PUBLICKEYBYTES];
|
|
||||||
uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES];
|
|
||||||
} Group_Connection;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Messenger *m;
|
Messenger *m;
|
||||||
|
|
||||||
Group_c *chats;
|
Group_c *chats;
|
||||||
uint32_t num_chats;
|
uint32_t num_chats;
|
||||||
|
|
||||||
Group_Connection *cons;
|
|
||||||
uint32_t num_cons;
|
|
||||||
|
|
||||||
void (*invite_callback)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
|
void (*invite_callback)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
|
||||||
void *invite_callback_userdata;
|
void *invite_callback_userdata;
|
||||||
void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *);
|
void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user