diff options
author | sudden6 <sudden6@gmx.at> | 2018-02-19 22:58:03 +0100 |
---|---|---|
committer | sudden6 <sudden6@gmx.at> | 2018-02-20 20:58:54 +0100 |
commit | 03b55cde1a98b02f9019f068340094b5062857d1 (patch) | |
tree | 3fd16d56a9546e458d03a47d9e8e8fa68e0f9c16 /toxcore/group.h | |
parent | c4a734e30462d59d7f9bfe4a865b33936907e0d5 (diff) |
make groupnumber uint32_t
fixes #606
Diffstat (limited to 'toxcore/group.h')
-rw-r--r-- | toxcore/group.h | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/toxcore/group.h b/toxcore/group.h index af37f21e..4324613c 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -103,9 +103,9 @@ typedef struct { | |||
103 | 103 | ||
104 | void *object; | 104 | void *object; |
105 | 105 | ||
106 | void (*peer_on_join)(void *, int, int); | 106 | void (*peer_on_join)(void *, uint32_t, uint32_t); |
107 | void (*peer_on_leave)(void *, int, int, void *); | 107 | void (*peer_on_leave)(void *, uint32_t, uint32_t, void *); |
108 | void (*group_on_delete)(void *, int); | 108 | void (*group_on_delete)(void *, uint32_t); |
109 | } Group_c; | 109 | } Group_c; |
110 | 110 | ||
111 | typedef struct { | 111 | typedef struct { |
@@ -117,17 +117,17 @@ typedef struct { | |||
117 | 117 | ||
118 | void (*invite_callback)(Messenger *m, uint32_t, int, const uint8_t *, size_t, void *); | 118 | void (*invite_callback)(Messenger *m, uint32_t, int, const uint8_t *, size_t, void *); |
119 | void (*message_callback)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *); | 119 | void (*message_callback)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *); |
120 | void (*group_namelistchange)(Messenger *m, int, int, uint8_t, void *); | 120 | void (*group_namelistchange)(Messenger *m, uint32_t, uint32_t, uint8_t, void *); |
121 | void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); | 121 | void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); |
122 | 122 | ||
123 | struct { | 123 | struct { |
124 | int (*function)(void *, int, int, void *, const uint8_t *, uint16_t); | 124 | int (*function)(void *, uint32_t, uint32_t, void *, const uint8_t *, uint16_t); |
125 | } lossy_packethandlers[256]; | 125 | } lossy_packethandlers[256]; |
126 | } Group_Chats; | 126 | } Group_Chats; |
127 | 127 | ||
128 | /* Set the callback for group invites. | 128 | /* Set the callback for group invites. |
129 | * | 129 | * |
130 | * Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) | 130 | * Function(Group_Chats *g_c, uint32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata) |
131 | * | 131 | * |
132 | * data of length is what needs to be passed to join_groupchat(). | 132 | * data of length is what needs to be passed to join_groupchat(). |
133 | */ | 133 | */ |
@@ -136,7 +136,7 @@ void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, ui | |||
136 | 136 | ||
137 | /* Set the callback for group messages. | 137 | /* Set the callback for group messages. |
138 | * | 138 | * |
139 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) | 139 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) |
140 | */ | 140 | */ |
141 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, | 141 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, |
142 | size_t, void *)); | 142 | size_t, void *)); |
@@ -144,7 +144,7 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u | |||
144 | 144 | ||
145 | /* Set callback function for title changes. | 145 | /* Set callback function for title changes. |
146 | * | 146 | * |
147 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) | 147 | * Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) |
148 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) | 148 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) |
149 | */ | 149 | */ |
150 | void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, | 150 | void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, |
@@ -159,7 +159,8 @@ enum { | |||
159 | CHAT_CHANGE_OCCURRED, | 159 | CHAT_CHANGE_OCCURRED, |
160 | CHAT_CHANGE_PEER_NAME, | 160 | CHAT_CHANGE_PEER_NAME, |
161 | }; | 161 | }; |
162 | void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, int, int, uint8_t, void *)); | 162 | void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, uint8_t, |
163 | void *)); | ||
163 | 164 | ||
164 | /* Creates a new groupchat and puts it in the chats array. | 165 | /* Creates a new groupchat and puts it in the chats array. |
165 | * | 166 | * |
@@ -175,7 +176,7 @@ int add_groupchat(Group_Chats *g_c, uint8_t type); | |||
175 | * return 0 on success. | 176 | * return 0 on success. |
176 | * return -1 if groupnumber is invalid. | 177 | * return -1 if groupnumber is invalid. |
177 | */ | 178 | */ |
178 | int del_groupchat(Group_Chats *g_c, int groupnumber); | 179 | int del_groupchat(Group_Chats *g_c, uint32_t groupnumber); |
179 | 180 | ||
180 | /* Copy the public key of peernumber who is in groupnumber to pk. | 181 | /* Copy the public key of peernumber who is in groupnumber to pk. |
181 | * pk must be CRYPTO_PUBLIC_KEY_SIZE long. | 182 | * pk must be CRYPTO_PUBLIC_KEY_SIZE long. |
@@ -184,7 +185,7 @@ int del_groupchat(Group_Chats *g_c, int groupnumber); | |||
184 | * return -1 if groupnumber is invalid. | 185 | * return -1 if groupnumber is invalid. |
185 | * return -2 if peernumber is invalid. | 186 | * return -2 if peernumber is invalid. |
186 | */ | 187 | */ |
187 | int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *pk); | 188 | int group_peer_pubkey(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *pk); |
188 | 189 | ||
189 | /* | 190 | /* |
190 | * Return the size of peernumber's name. | 191 | * Return the size of peernumber's name. |
@@ -192,7 +193,7 @@ int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, u | |||
192 | * return -1 if groupnumber is invalid. | 193 | * return -1 if groupnumber is invalid. |
193 | * return -2 if peernumber is invalid. | 194 | * return -2 if peernumber is invalid. |
194 | */ | 195 | */ |
195 | int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber); | 196 | int group_peername_size(const Group_Chats *g_c, uint32_t groupnumber, int32_t peernumber); |
196 | 197 | ||
197 | /* Copy the name of peernumber who is in groupnumber to name. | 198 | /* Copy the name of peernumber who is in groupnumber to name. |
198 | * name must be at least MAX_NAME_LENGTH long. | 199 | * name must be at least MAX_NAME_LENGTH long. |
@@ -201,7 +202,7 @@ int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber) | |||
201 | * return -1 if groupnumber is invalid. | 202 | * return -1 if groupnumber is invalid. |
202 | * return -2 if peernumber is invalid. | 203 | * return -2 if peernumber is invalid. |
203 | */ | 204 | */ |
204 | int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *name); | 205 | int group_peername(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, uint8_t *name); |
205 | 206 | ||
206 | /* invite friendnumber to groupnumber | 207 | /* invite friendnumber to groupnumber |
207 | * | 208 | * |
@@ -209,7 +210,7 @@ int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint | |||
209 | * return -1 if groupnumber is invalid. | 210 | * return -1 if groupnumber is invalid. |
210 | * return -2 if invite packet failed to send. | 211 | * return -2 if invite packet failed to send. |
211 | */ | 212 | */ |
212 | int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber); | 213 | int invite_friend(Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber); |
213 | 214 | ||
214 | /* Join a group (you need to have been invited first.) | 215 | /* Join a group (you need to have been invited first.) |
215 | * | 216 | * |
@@ -223,19 +224,20 @@ int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber); | |||
223 | * return -5 if group instance failed to initialize. | 224 | * return -5 if group instance failed to initialize. |
224 | * return -6 if join packet fails to send. | 225 | * return -6 if join packet fails to send. |
225 | */ | 226 | */ |
226 | int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length); | 227 | int join_groupchat(Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_type, const uint8_t *data, |
228 | uint16_t length); | ||
227 | 229 | ||
228 | /* send a group message | 230 | /* send a group message |
229 | * return 0 on success | 231 | * return 0 on success |
230 | * see: send_message_group() for error codes. | 232 | * see: send_message_group() for error codes. |
231 | */ | 233 | */ |
232 | int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *message, uint16_t length); | 234 | int group_message_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *message, uint16_t length); |
233 | 235 | ||
234 | /* send a group action | 236 | /* send a group action |
235 | * return 0 on success | 237 | * return 0 on success |
236 | * see: send_message_group() for error codes. | 238 | * see: send_message_group() for error codes. |
237 | */ | 239 | */ |
238 | int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length); | 240 | int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *action, uint16_t length); |
239 | 241 | ||
240 | /* set the group's title, limited to MAX_NAME_LENGTH | 242 | /* set the group's title, limited to MAX_NAME_LENGTH |
241 | * return 0 on success | 243 | * return 0 on success |
@@ -243,14 +245,14 @@ int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *ac | |||
243 | * return -2 if title is too long or empty. | 245 | * return -2 if title is too long or empty. |
244 | * return -3 if packet fails to send. | 246 | * return -3 if packet fails to send. |
245 | */ | 247 | */ |
246 | int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len); | 248 | int group_title_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *title, uint8_t title_len); |
247 | 249 | ||
248 | 250 | ||
249 | /* return the group's title size. | 251 | /* return the group's title size. |
250 | * return -1 of groupnumber is invalid. | 252 | * return -1 of groupnumber is invalid. |
251 | * return -2 if title is too long or empty. | 253 | * return -2 if title is too long or empty. |
252 | */ | 254 | */ |
253 | int group_title_get_size(const Group_Chats *g_c, int groupnumber); | 255 | int group_title_get_size(const Group_Chats *g_c, uint32_t groupnumber); |
254 | 256 | ||
255 | /* Get group title from groupnumber and put it in title. | 257 | /* Get group title from groupnumber and put it in title. |
256 | * Title needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. | 258 | * Title needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. |
@@ -259,12 +261,12 @@ int group_title_get_size(const Group_Chats *g_c, int groupnumber); | |||
259 | * return -1 if groupnumber is invalid. | 261 | * return -1 if groupnumber is invalid. |
260 | * return -2 if title is too long or empty. | 262 | * return -2 if title is too long or empty. |
261 | */ | 263 | */ |
262 | int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title); | 264 | int group_title_get(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *title); |
263 | 265 | ||
264 | /* Return the number of peers in the group chat on success. | 266 | /* Return the number of peers in the group chat on success. |
265 | * return -1 if groupnumber is invalid. | 267 | * return -1 if groupnumber is invalid. |
266 | */ | 268 | */ |
267 | int group_number_peers(const Group_Chats *g_c, int groupnumber); | 269 | int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber); |
268 | 270 | ||
269 | /* return 1 if the peernumber corresponds to ours. | 271 | /* return 1 if the peernumber corresponds to ours. |
270 | * return 0 if the peernumber is not ours. | 272 | * return 0 if the peernumber is not ours. |
@@ -272,7 +274,7 @@ int group_number_peers(const Group_Chats *g_c, int groupnumber); | |||
272 | * return -2 if peernumber is invalid. | 274 | * return -2 if peernumber is invalid. |
273 | * return -3 if we are not connected to the group chat. | 275 | * return -3 if we are not connected to the group chat. |
274 | */ | 276 | */ |
275 | int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernumber); | 277 | int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, int peernumber); |
276 | 278 | ||
277 | /* List all the peers in the group chat. | 279 | /* List all the peers in the group chat. |
278 | * | 280 | * |
@@ -284,16 +286,17 @@ int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernu | |||
284 | * | 286 | * |
285 | * return -1 on failure. | 287 | * return -1 on failure. |
286 | */ | 288 | */ |
287 | int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], | 289 | int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], |
288 | uint16_t length); | 290 | uint16_t length); |
289 | 291 | ||
290 | /* Set handlers for custom lossy packets. | 292 | /* Set handlers for custom lossy packets. |
291 | * | 293 | * |
292 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. | 294 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. |
293 | * | 295 | * |
294 | * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) | 296 | * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object), const uint8_t *packet, uint16_t length) |
295 | */ | 297 | */ |
296 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, int, int, void *, | 298 | void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*function)(void *, uint32_t, uint32_t, |
299 | void *, | ||
297 | const uint8_t *, uint16_t)); | 300 | const uint8_t *, uint16_t)); |
298 | 301 | ||
299 | /* High level function to send custom lossy packets. | 302 | /* High level function to send custom lossy packets. |
@@ -301,7 +304,7 @@ void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, int (*fu | |||
301 | * return -1 on failure. | 304 | * return -1 on failure. |
302 | * return 0 on success. | 305 | * return 0 on success. |
303 | */ | 306 | */ |
304 | int send_group_lossy_packet(const Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length); | 307 | int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length); |
305 | 308 | ||
306 | /* Return the number of chats in the instance m. | 309 | /* Return the number of chats in the instance m. |
307 | * You should use this to determine how much memory to allocate | 310 | * You should use this to determine how much memory to allocate |
@@ -321,7 +324,7 @@ uint32_t copy_chatlist(Group_Chats *g_c, uint32_t *out_list, uint32_t list_size) | |||
321 | * return -1 on failure. | 324 | * return -1 on failure. |
322 | * return type on success. | 325 | * return type on success. |
323 | */ | 326 | */ |
324 | int group_get_type(const Group_Chats *g_c, int groupnumber); | 327 | int group_get_type(const Group_Chats *g_c, uint32_t groupnumber); |
325 | 328 | ||
326 | /* Send current name (set in messenger) to all online groups. | 329 | /* Send current name (set in messenger) to all online groups. |
327 | */ | 330 | */ |
@@ -332,28 +335,28 @@ void send_name_all_groups(Group_Chats *g_c); | |||
332 | * return 0 on success. | 335 | * return 0 on success. |
333 | * return -1 on failure | 336 | * return -1 on failure |
334 | */ | 337 | */ |
335 | int group_set_object(const Group_Chats *g_c, int groupnumber, void *object); | 338 | int group_set_object(const Group_Chats *g_c, uint32_t groupnumber, void *object); |
336 | 339 | ||
337 | /* Set the object that is tied to the group peer. | 340 | /* Set the object that is tied to the group peer. |
338 | * | 341 | * |
339 | * return 0 on success. | 342 | * return 0 on success. |
340 | * return -1 on failure | 343 | * return -1 on failure |
341 | */ | 344 | */ |
342 | int group_peer_set_object(const Group_Chats *g_c, int groupnumber, int peernumber, void *object); | 345 | int group_peer_set_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber, void *object); |
343 | 346 | ||
344 | /* Return the object tide to the group chat previously set by group_set_object. | 347 | /* Return the object tide to the group chat previously set by group_set_object. |
345 | * | 348 | * |
346 | * return NULL on failure. | 349 | * return NULL on failure. |
347 | * return object on success. | 350 | * return object on success. |
348 | */ | 351 | */ |
349 | void *group_get_object(const Group_Chats *g_c, int groupnumber); | 352 | void *group_get_object(const Group_Chats *g_c, uint32_t groupnumber); |
350 | 353 | ||
351 | /* Return the object tide to the group chat peer previously set by group_peer_set_object. | 354 | /* Return the object tide to the group chat peer previously set by group_peer_set_object. |
352 | * | 355 | * |
353 | * return NULL on failure. | 356 | * return NULL on failure. |
354 | * return object on success. | 357 | * return object on success. |
355 | */ | 358 | */ |
356 | void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernumber); | 359 | void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, int peernumber); |
357 | 360 | ||
358 | /* Set a function to be called when a new peer joins a group chat. | 361 | /* Set a function to be called when a new peer joins a group chat. |
359 | * | 362 | * |
@@ -362,25 +365,27 @@ void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernum | |||
362 | * return 0 on success. | 365 | * return 0 on success. |
363 | * return -1 on failure. | 366 | * return -1 on failure. |
364 | */ | 367 | */ |
365 | int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int)); | 368 | int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, |
369 | uint32_t)); | ||
366 | 370 | ||
367 | /* Set a function to be called when a peer leaves a group chat. | 371 | /* Set a function to be called when a peer leaves a group chat. |
368 | * | 372 | * |
369 | * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object)) | 373 | * Function(void *group object (set with group_set_object), uint32_t groupnumber, uint32_t friendgroupnumber, void *group peer object (set with group_peer_set_object)) |
370 | * | 374 | * |
371 | * return 0 on success. | 375 | * return 0 on success. |
372 | * return -1 on failure. | 376 | * return -1 on failure. |
373 | */ | 377 | */ |
374 | int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int, void *)); | 378 | int callback_groupchat_peer_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t, uint32_t, |
379 | void *)); | ||
375 | 380 | ||
376 | /* Set a function to be called when the group chat is deleted. | 381 | /* Set a function to be called when the group chat is deleted. |
377 | * | 382 | * |
378 | * Function(void *group object (set with group_set_object), int groupnumber) | 383 | * Function(void *group object (set with group_set_object), uint32_t groupnumber) |
379 | * | 384 | * |
380 | * return 0 on success. | 385 | * return 0 on success. |
381 | * return -1 on failure. | 386 | * return -1 on failure. |
382 | */ | 387 | */ |
383 | int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int)); | 388 | int callback_groupchat_delete(Group_Chats *g_c, uint32_t groupnumber, void (*function)(void *, uint32_t)); |
384 | 389 | ||
385 | /* Create new groupchat instance. */ | 390 | /* Create new groupchat instance. */ |
386 | Group_Chats *new_groupchats(Messenger *m); | 391 | Group_Chats *new_groupchats(Messenger *m); |