diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/group.c | 104 | ||||
-rw-r--r-- | toxcore/group.h | 15 |
2 files changed, 5 insertions, 114 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) |
diff --git a/toxcore/group.h b/toxcore/group.h index 67b824fb..ab36ca34 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -32,11 +32,6 @@ enum { | |||
32 | GROUPCHAT_STATUS_VALID | 32 | GROUPCHAT_STATUS_VALID |
33 | }; | 33 | }; |
34 | 34 | ||
35 | enum { | ||
36 | GROUPCON_STATUS_NONE, | ||
37 | GROUPCON_STATUS_VALID | ||
38 | }; | ||
39 | |||
40 | typedef struct { | 35 | typedef struct { |
41 | uint8_t client_id[crypto_box_PUBLICKEYBYTES]; | 36 | uint8_t client_id[crypto_box_PUBLICKEYBYTES]; |
42 | uint64_t pingid; | 37 | uint64_t pingid; |
@@ -84,21 +79,11 @@ typedef struct { | |||
84 | } Group_c; | 79 | } Group_c; |
85 | 80 | ||
86 | typedef struct { | 81 | typedef struct { |
87 | uint8_t status; | ||
88 | |||
89 | uint8_t real_public_key[crypto_box_PUBLICKEYBYTES]; | ||
90 | uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES]; | ||
91 | } Group_Connection; | ||
92 | |||
93 | typedef struct { | ||
94 | Messenger *m; | 82 | Messenger *m; |
95 | 83 | ||
96 | Group_c *chats; | 84 | Group_c *chats; |
97 | uint32_t num_chats; | 85 | uint32_t num_chats; |
98 | 86 | ||
99 | Group_Connection *cons; | ||
100 | uint32_t num_cons; | ||
101 | |||
102 | void (*invite_callback)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *); | 87 | void (*invite_callback)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *); |
103 | void *invite_callback_userdata; | 88 | void *invite_callback_userdata; |
104 | void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); | 89 | void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); |