summaryrefslogtreecommitdiff
path: root/toxcore/group.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/group.h')
-rw-r--r--toxcore/group.h197
1 files changed, 197 insertions, 0 deletions
diff --git a/toxcore/group.h b/toxcore/group.h
new file mode 100644
index 00000000..a5b5723c
--- /dev/null
+++ b/toxcore/group.h
@@ -0,0 +1,197 @@
1/* group.h
2 *
3 * Slightly better groupchats implementation.
4 *
5 * Copyright (C) 2014 Tox project All Rights Reserved.
6 *
7 * This file is part of Tox.
8 *
9 * Tox is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Tox is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24
25#ifndef GROUP_H
26#define GROUP_H
27
28#include "Messenger.h"
29
30enum {
31 GROUPCHAT_STATUS_NONE,
32 GROUPCHAT_STATUS_VALID
33};
34
35typedef struct {
36 uint8_t client_id[crypto_box_PUBLICKEYBYTES];
37 uint64_t pingid;
38 uint64_t last_pinged;
39
40 uint64_t last_recv;
41 uint64_t last_recv_msgping;
42 uint32_t last_message_number;
43
44 uint8_t nick[MAX_NAME_LENGTH];
45 uint16_t nick_len;
46
47 uint8_t deleted;
48 uint64_t deleted_time;
49
50 uint16_t peer_number;
51} Group_Peer;
52
53#define DESIRED_CLOSE_CONNECTIONS 3
54#define MAX_GROUP_CONNECTIONS 16
55#define GROUP_IDENTIFIER_LENGTH crypto_box_KEYBYTES /* So we can use new_symmetric_key(...) to fill it */
56
57enum {
58 GROUPCHAT_CLOSE_NONE,
59 GROUPCHAT_CLOSE_CONNECTION
60};
61
62typedef struct {
63 uint8_t status;
64
65 Group_Peer *group;
66 uint32_t numpeers;
67
68 struct {
69 uint8_t type; /* GROUPCHAT_CLOSE_* */
70 uint32_t number;
71 uint16_t group_number;
72 } close[MAX_GROUP_CONNECTIONS];
73
74 uint8_t identifier[GROUP_IDENTIFIER_LENGTH];
75
76 uint32_t message_number;
77 uint16_t peer_number;
78} Group_c;
79
80typedef struct {
81 Messenger *m;
82
83 Group_c *chats;
84 uint32_t num_chats;
85
86 void (*invite_callback)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
87 void *invite_callback_userdata;
88 void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *);
89 void *message_callback_userdata;
90} Group_Chats;
91
92/* Set the callback for group invites.
93 *
94 * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata)
95 *
96 * data of length is what needs to be passed to join_groupchat().
97 */
98void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t,
99 void *), void *userdata);
100
101/* Set the callback for group messages.
102 *
103 * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
104 */
105void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t,
106 void *), void *userdata);
107
108/* Set the callback for group actions.
109 *
110 * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
111 */
112void g_callback_group_action(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t,
113 void *), void *userdata);
114
115/* Set callback function for peer name list changes.
116 *
117 * It gets called every time the name list changes(new peer/name, deleted peer)
118 * Function(Group_Chats *g_c, int groupnumber, void *userdata)
119 */
120void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, int, int, uint8_t, void *),
121 void *userdata);
122
123/* Creates a new groupchat and puts it in the chats array.
124 *
125 * return group number on success.
126 * return -1 on failure.
127 */
128int add_groupchat(Group_Chats *g_c);
129
130/* Delete a groupchat from the chats array.
131 *
132 * return 0 on success.
133 * return -1 if failure.
134 */
135int del_groupchat(Group_Chats *g_c, int groupnumber);
136
137/* Copy the name of peernumber who is in groupnumber to name.
138 * name must be at least MAX_NAME_LENGTH long.
139 *
140 * return length of name if success
141 * return -1 if failure
142 */
143int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *name);
144
145/* invite friendnumber to groupnumber
146 * return 0 on success
147 * return -1 on failure
148 */
149int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber);
150
151/* Join a group (you need to have been invited first.)
152 *
153 * returns group number on success
154 * returns -1 on failure.
155 */
156int join_groupchat(Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, uint16_t length);
157
158/* send a group message
159 * return 0 on success
160 * return -1 on failure
161 */
162int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *message, uint16_t length);
163
164/* send a group action
165 * return 0 on success
166 * return -1 on failure
167 */
168int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length);
169
170/* Return the number of peers in the group chat on success.
171 * return -1 on failure
172 */
173int group_number_peers(const Group_Chats *g_c, int groupnumber);
174
175/* List all the peers in the group chat.
176 *
177 * Copies the names of the peers to the name[length][MAX_NAME_LENGTH] array.
178 *
179 * Copies the lengths of the names to lengths[length]
180 *
181 * returns the number of peers on success.
182 *
183 * return -1 on failure.
184 */
185int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[],
186 uint16_t length);
187
188/* Create new groupchat instance. */
189Group_Chats *new_groupchats(Messenger *m);
190
191/* main groupchats loop. */
192void do_groupchats(Group_Chats *g_c);
193
194/* Free everything related with group chats. */
195void kill_groupchats(Group_Chats *g_c);
196
197#endif