diff options
Diffstat (limited to 'toxcore/group.c')
-rw-r--r-- | toxcore/group.c | 104 |
1 files changed, 5 insertions, 99 deletions
diff --git a/toxcore/group.c b/toxcore/group.c index d6e60dce..8ea626bb 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -28,105 +28,6 @@ | |||
28 | #include "group.h" | 28 | #include "group.h" |
29 | #include "util.h" | 29 | #include "util.h" |
30 | 30 | ||
31 | /* return 1 if the con_number is not valid. | ||
32 | * return 0 if the con_number is valid. | ||
33 | */ | ||
34 | static uint8_t con_number_not_valid(const Group_Chats *g_c, int con_number) | ||
35 | { | ||
36 | if ((unsigned int)con_number >= g_c->num_cons) | ||
37 | return 1; | ||
38 | |||
39 | if (g_c->cons == NULL) | ||
40 | return 1; | ||
41 | |||
42 | if (g_c->cons[con_number].status == GROUPCON_STATUS_NONE) | ||
43 | return 1; | ||
44 | |||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | |||
49 | /* Set the size of the groupchat connections list to num. | ||
50 | * | ||
51 | * return -1 if realloc fails. | ||
52 | * return 0 if it succeeds. | ||
53 | */ | ||
54 | static int realloc_groupcons(Group_Chats *g_c, uint32_t num) | ||
55 | { | ||
56 | if (num == 0) { | ||
57 | free(g_c->cons); | ||
58 | g_c->cons = NULL; | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | Group_Connection *newgroup_cons = realloc(g_c->cons, num * sizeof(Group_Connection)); | ||
63 | |||
64 | if (newgroup_cons == NULL) | ||
65 | return -1; | ||
66 | |||
67 | g_c->cons = newgroup_cons; | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | /* Create a new empty groupchat connection. | ||
72 | * | ||
73 | * return -1 on failure. | ||
74 | * return con_number on success. | ||
75 | */ | ||
76 | static int create_group_con(Group_Chats *g_c) | ||
77 | { | ||
78 | uint32_t i; | ||
79 | |||
80 | for (i = 0; i < g_c->num_cons; ++i) { | ||
81 | if (g_c->cons[i].status == GROUPCON_STATUS_NONE) | ||
82 | return i; | ||
83 | } | ||
84 | |||
85 | int id = -1; | ||
86 | |||
87 | if (realloc_groupcons(g_c, g_c->num_cons + 1) == 0) { | ||
88 | id = g_c->num_cons; | ||
89 | ++g_c->num_cons; | ||
90 | memset(&(g_c->cons[id]), 0, sizeof(Group_Connection)); | ||
91 | } | ||
92 | |||
93 | return id; | ||
94 | } | ||
95 | |||
96 | /* Wipe a groupchat connection. | ||
97 | * | ||
98 | * return -1 on failure. | ||
99 | * return 0 on success. | ||
100 | */ | ||
101 | static int wipe_group_con(Group_Chats *g_c, int con_number) | ||
102 | { | ||
103 | if (con_number_not_valid(g_c, con_number)) | ||
104 | return -1; | ||
105 | |||
106 | uint32_t i; | ||
107 | memset(&(g_c->cons[con_number]), 0 , sizeof(Group_c)); | ||
108 | |||
109 | for (i = g_c->num_cons; i != 0; --i) { | ||
110 | if (g_c->cons[i - 1].status != GROUPCON_STATUS_NONE) | ||
111 | break; | ||
112 | } | ||
113 | |||
114 | if (g_c->num_cons != i) { | ||
115 | g_c->num_cons = i; | ||
116 | realloc_groupcons(g_c, g_c->num_cons); | ||
117 | } | ||
118 | |||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | static Group_Connection *get_con_group(Group_Chats *g_c, int con_number) | ||
123 | { | ||
124 | if (con_number_not_valid(g_c, con_number)) | ||
125 | return 0; | ||
126 | |||
127 | return &g_c->cons[con_number]; | ||
128 | } | ||
129 | |||
130 | /* return 1 if the groupnumber is not valid. | 31 | /* return 1 if the groupnumber is not valid. |
131 | * return 0 if the groupnumber is valid. | 32 | * return 0 if the groupnumber is valid. |
132 | */ | 33 | */ |
@@ -612,6 +513,8 @@ static unsigned int send_message_all_close(const Group_Chats *g_c, int groupnumb | |||
612 | return sent; | 513 | return sent; |
613 | } | 514 | } |
614 | 515 | ||
516 | #define MAX_GROUP_MESSAGE_DATA_LEN (MAX_CRYPTO_DATA_SIZE - (1 + MIN_MESSAGE_PACKET_LEN)) | ||
517 | |||
615 | /* Send data of len with message_id to groupnumber. | 518 | /* Send data of len with message_id to groupnumber. |
616 | * | 519 | * |
617 | * return number of peers it was sent to on success. | 520 | * 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 | |||
620 | static unsigned int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data, | 523 | static unsigned int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data, |
621 | uint16_t len) | 524 | uint16_t len) |
622 | { | 525 | { |
526 | if (len > MAX_GROUP_MESSAGE_DATA_LEN) | ||
527 | return 0; | ||
528 | |||
623 | Group_c *g = get_group_c(g_c, groupnumber); | 529 | Group_c *g = get_group_c(g_c, groupnumber); |
624 | 530 | ||
625 | if (!g) | 531 | if (!g) |