diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-08-30 17:50:59 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-08-30 19:31:40 +0100 |
commit | fa3b51266bdc13a6b5fafdc2518f89b03e5f084f (patch) | |
tree | 582c9e7a2ca197aab4fc90b1ec26821ae1765e30 /toxcore/tox_group.c | |
parent | 4692cea75e82d05c4facf97c8853819281f376cf (diff) |
Add missing #includes to headers and rename tox_old to tox_group.
Also, no longer #include the group code into tox.c. Instead, compile it
separately in tox_group.c. This is a bit less surprising to someone looking
around the code. Having some implementations in a .h file is certainly a bit
surprising to a disciplined C programmer, especially when there is no technical
reason to do it.
Diffstat (limited to 'toxcore/tox_group.c')
-rw-r--r-- | toxcore/tox_group.c | 272 |
1 files changed, 272 insertions, 0 deletions
diff --git a/toxcore/tox_group.c b/toxcore/tox_group.c new file mode 100644 index 00000000..2228ed88 --- /dev/null +++ b/toxcore/tox_group.c | |||
@@ -0,0 +1,272 @@ | |||
1 | /* tox.c | ||
2 | * | ||
3 | * The Tox public API. | ||
4 | * | ||
5 | * Copyright (C) 2013 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 | #ifdef HAVE_CONFIG_H | ||
25 | #include "config.h" | ||
26 | #endif | ||
27 | |||
28 | #include "Messenger.h" | ||
29 | #include "group.h" | ||
30 | |||
31 | #define TOX_DEFINED | ||
32 | typedef struct Messenger Tox; | ||
33 | |||
34 | #include "tox.h" | ||
35 | |||
36 | /**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/ | ||
37 | |||
38 | /* Set the callback for group invites. | ||
39 | * | ||
40 | * Function(Tox *tox, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) | ||
41 | * | ||
42 | * data of length is what needs to be passed to join_groupchat(). | ||
43 | */ | ||
44 | void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, const uint8_t *, uint16_t, | ||
45 | void *), void *userdata) | ||
46 | { | ||
47 | Messenger *m = tox; | ||
48 | g_callback_group_invite(m->group_chat_object, function, userdata); | ||
49 | } | ||
50 | |||
51 | /* Set the callback for group messages. | ||
52 | * | ||
53 | * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * message, uint16_t length, void *userdata) | ||
54 | */ | ||
55 | void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint16_t, void *), | ||
56 | void *userdata) | ||
57 | { | ||
58 | Messenger *m = tox; | ||
59 | g_callback_group_message(m->group_chat_object, function, userdata); | ||
60 | } | ||
61 | |||
62 | /* Set the callback for group actions. | ||
63 | * | ||
64 | * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * action, uint16_t length, void *userdata) | ||
65 | */ | ||
66 | void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint16_t, void *), | ||
67 | void *userdata) | ||
68 | { | ||
69 | Messenger *m = tox; | ||
70 | g_callback_group_action(m->group_chat_object, function, userdata); | ||
71 | } | ||
72 | |||
73 | /* Set callback function for title changes. | ||
74 | * | ||
75 | * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * title, uint8_t length, void *userdata) | ||
76 | * if peernumber == -1, then author is unknown (e.g. initial joining the group) | ||
77 | */ | ||
78 | void tox_callback_group_title(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint8_t, | ||
79 | void *), void *userdata) | ||
80 | { | ||
81 | Messenger *m = tox; | ||
82 | g_callback_group_title(m->group_chat_object, function, userdata); | ||
83 | } | ||
84 | |||
85 | /* Set callback function for peer name list changes. | ||
86 | * | ||
87 | * It gets called every time the name list changes(new peer/name, deleted peer) | ||
88 | * Function(Tox *tox, int groupnumber, void *userdata) | ||
89 | */ | ||
90 | void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t, void *), void *userdata) | ||
91 | { | ||
92 | Messenger *m = tox; | ||
93 | g_callback_group_namelistchange(m->group_chat_object, function, userdata); | ||
94 | } | ||
95 | |||
96 | /* Creates a new groupchat and puts it in the chats array. | ||
97 | * | ||
98 | * return group number on success. | ||
99 | * return -1 on failure. | ||
100 | */ | ||
101 | int tox_add_groupchat(Tox *tox) | ||
102 | { | ||
103 | Messenger *m = tox; | ||
104 | return add_groupchat(m->group_chat_object, GROUPCHAT_TYPE_TEXT); | ||
105 | } | ||
106 | |||
107 | /* Delete a groupchat from the chats array. | ||
108 | * | ||
109 | * return 0 on success. | ||
110 | * return -1 if failure. | ||
111 | */ | ||
112 | int tox_del_groupchat(Tox *tox, int groupnumber) | ||
113 | { | ||
114 | Messenger *m = tox; | ||
115 | return del_groupchat(m->group_chat_object, groupnumber); | ||
116 | } | ||
117 | |||
118 | /* Copy the name of peernumber who is in groupnumber to name. | ||
119 | * name must be at least MAX_NICK_BYTES long. | ||
120 | * | ||
121 | * return length of name if success | ||
122 | * return -1 if failure | ||
123 | */ | ||
124 | int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name) | ||
125 | { | ||
126 | const Messenger *m = tox; | ||
127 | return group_peername(m->group_chat_object, groupnumber, peernumber, name); | ||
128 | } | ||
129 | |||
130 | /* Copy the public key of peernumber who is in groupnumber to public_key. | ||
131 | * public_key must be crypto_box_PUBLICKEYBYTES long. | ||
132 | * | ||
133 | * returns 0 on success | ||
134 | * returns -1 on failure | ||
135 | */ | ||
136 | int tox_group_peer_pubkey(const Tox *tox, int groupnumber, int peernumber, uint8_t *public_key) | ||
137 | { | ||
138 | const Messenger *m = tox; | ||
139 | return group_peer_pubkey(m->group_chat_object, groupnumber, peernumber, public_key); | ||
140 | } | ||
141 | |||
142 | /* invite friendnumber to groupnumber | ||
143 | * return 0 on success | ||
144 | * return -1 on failure | ||
145 | */ | ||
146 | int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) | ||
147 | { | ||
148 | Messenger *m = tox; | ||
149 | return invite_friend(m->group_chat_object, friendnumber, groupnumber); | ||
150 | } | ||
151 | |||
152 | /* Join a group (you need to have been invited first.) using data of length obtained | ||
153 | * in the group invite callback. | ||
154 | * | ||
155 | * returns group number on success | ||
156 | * returns -1 on failure. | ||
157 | */ | ||
158 | int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length) | ||
159 | { | ||
160 | Messenger *m = tox; | ||
161 | return join_groupchat(m->group_chat_object, friendnumber, GROUPCHAT_TYPE_TEXT, data, length); | ||
162 | } | ||
163 | |||
164 | /* send a group message | ||
165 | * return 0 on success | ||
166 | * return -1 on failure | ||
167 | */ | ||
168 | int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint16_t length) | ||
169 | { | ||
170 | Messenger *m = tox; | ||
171 | return group_message_send(m->group_chat_object, groupnumber, message, length); | ||
172 | } | ||
173 | |||
174 | /* send a group action | ||
175 | * return 0 on success | ||
176 | * return -1 on failure | ||
177 | */ | ||
178 | int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length) | ||
179 | { | ||
180 | Messenger *m = tox; | ||
181 | return group_action_send(m->group_chat_object, groupnumber, action, length); | ||
182 | } | ||
183 | |||
184 | /* set the group's title, limited to MAX_NAME_LENGTH | ||
185 | * return 0 on success | ||
186 | * return -1 on failure | ||
187 | */ | ||
188 | int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t length) | ||
189 | { | ||
190 | Messenger *m = tox; | ||
191 | return group_title_send(m->group_chat_object, groupnumber, title, length); | ||
192 | } | ||
193 | |||
194 | /* Get group title from groupnumber and put it in title. | ||
195 | * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes. | ||
196 | * | ||
197 | * return length of copied title if success. | ||
198 | * return -1 if failure. | ||
199 | */ | ||
200 | int tox_group_get_title(Tox *tox, int groupnumber, uint8_t *title, uint32_t max_length) | ||
201 | { | ||
202 | Messenger *m = tox; | ||
203 | return group_title_get(m->group_chat_object, groupnumber, title, max_length); | ||
204 | } | ||
205 | |||
206 | /* Check if the current peernumber corresponds to ours. | ||
207 | * | ||
208 | * return 1 if the peernumber corresponds to ours. | ||
209 | * return 0 on failure. | ||
210 | */ | ||
211 | unsigned int tox_group_peernumber_is_ours(const Tox *tox, int groupnumber, int peernumber) | ||
212 | { | ||
213 | const Messenger *m = tox; | ||
214 | return group_peernumber_is_ours(m->group_chat_object, groupnumber, peernumber); | ||
215 | } | ||
216 | |||
217 | /* Return the number of peers in the group chat on success. | ||
218 | * return -1 on failure | ||
219 | */ | ||
220 | int tox_group_number_peers(const Tox *tox, int groupnumber) | ||
221 | { | ||
222 | const Messenger *m = tox; | ||
223 | return group_number_peers(m->group_chat_object, groupnumber); | ||
224 | } | ||
225 | |||
226 | /* List all the peers in the group chat. | ||
227 | * | ||
228 | * Copies the names of the peers to the name[length][MAX_NICK_BYTES] array. | ||
229 | * | ||
230 | * Copies the lengths of the names to lengths[length] | ||
231 | * | ||
232 | * returns the number of peers on success. | ||
233 | * | ||
234 | * return -1 on failure. | ||
235 | */ | ||
236 | int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[], | ||
237 | uint16_t length) | ||
238 | { | ||
239 | const Messenger *m = tox; | ||
240 | return group_names(m->group_chat_object, groupnumber, names, lengths, length); | ||
241 | } | ||
242 | |||
243 | /* Return the number of chats in the instance m. | ||
244 | * You should use this to determine how much memory to allocate | ||
245 | * for copy_chatlist. */ | ||
246 | uint32_t tox_count_chatlist(const Tox *tox) | ||
247 | { | ||
248 | const Messenger *m = tox; | ||
249 | return count_chatlist(m->group_chat_object); | ||
250 | } | ||
251 | |||
252 | /* Copy a list of valid chat IDs into the array out_list. | ||
253 | * If out_list is NULL, returns 0. | ||
254 | * Otherwise, returns the number of elements copied. | ||
255 | * If the array was too small, the contents | ||
256 | * of out_list will be truncated to list_size. */ | ||
257 | uint32_t tox_get_chatlist(const Tox *tox, int32_t *out_list, uint32_t list_size) | ||
258 | { | ||
259 | const Messenger *m = tox; | ||
260 | return copy_chatlist(m->group_chat_object, out_list, list_size); | ||
261 | } | ||
262 | |||
263 | /* return the type of groupchat (TOX_GROUPCHAT_TYPE_) that groupnumber is. | ||
264 | * | ||
265 | * return -1 on failure. | ||
266 | * return type on success. | ||
267 | */ | ||
268 | int tox_group_get_type(const Tox *tox, int groupnumber) | ||
269 | { | ||
270 | const Messenger *m = tox; | ||
271 | return group_get_type(m->group_chat_object, groupnumber); | ||
272 | } | ||