summaryrefslogtreecommitdiff
path: root/toxcore/group.h
diff options
context:
space:
mode:
authorJfreegman <jfreegman@gmail.com>2016-09-17 17:32:25 -0400
committerJfreegman <jfreegman@gmail.com>2016-09-17 19:11:28 -0400
commit8e43ca834cc0a5b2f904ce2589154c2f17bd12ce (patch)
treee88701e5dfe6a623c7fe7f60ba2ddb304ffadc07 /toxcore/group.h
parentc0397a0a4614671679d409c428b47549a01fdf7f (diff)
Complete old groupchat conversion to new API
Diffstat (limited to 'toxcore/group.h')
-rw-r--r--toxcore/group.h67
1 files changed, 45 insertions, 22 deletions
diff --git a/toxcore/group.h b/toxcore/group.h
index 6d278dde..fc7629f3 100644
--- a/toxcore/group.h
+++ b/toxcore/group.h
@@ -120,7 +120,7 @@ typedef struct {
120 void *invite_callback_userdata; 120 void *invite_callback_userdata;
121 void (*message_callback)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *); 121 void (*message_callback)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *);
122 void *message_callback_userdata; 122 void *message_callback_userdata;
123 void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *); 123 void (*group_namelistchange)(Messenger *m, int, int, uint8_t, void *);
124 void *group_namelistchange_userdata; 124 void *group_namelistchange_userdata;
125 void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); 125 void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *);
126 void *title_callback_userdata; 126 void *title_callback_userdata;
@@ -144,8 +144,7 @@ void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, ui
144 * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) 144 * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
145 */ 145 */
146void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, 146void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *,
147 size_t, 147 size_t, void *), void *userdata);
148 void *), void *userdata);
149 148
150 149
151/* Set callback function for title changes. 150/* Set callback function for title changes.
@@ -154,8 +153,7 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u
154 * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) 153 * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group)
155 */ 154 */
156void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, 155void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *,
157 size_t, 156 size_t, void *), void *userdata);
158 void *), void *userdata);
159 157
160/* Set callback function for peer name list changes. 158/* Set callback function for peer name list changes.
161 * 159 *
@@ -182,31 +180,41 @@ int add_groupchat(Group_Chats *g_c, uint8_t type);
182/* Delete a groupchat from the chats array. 180/* Delete a groupchat from the chats array.
183 * 181 *
184 * return 0 on success. 182 * return 0 on success.
185 * return -1 if failure. 183 * return -1 if groupnumber is invalid.
186 */ 184 */
187int del_groupchat(Group_Chats *g_c, int groupnumber); 185int del_groupchat(Group_Chats *g_c, int groupnumber);
188 186
189/* Copy the public key of peernumber who is in groupnumber to pk. 187/* Copy the public key of peernumber who is in groupnumber to pk.
190 * pk must be crypto_box_PUBLICKEYBYTES long. 188 * pk must be crypto_box_PUBLICKEYBYTES long.
191 * 189 *
192 * returns 0 on success 190 * return 0 on success
193 * returns -1 on failure 191 * return -1 if groupnumber is invalid.
192 * return -2 if peernumber is invalid.
194 */ 193 */
195int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *pk); 194int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *pk);
196 195
196/*
197 * Return the size of peernumber's name.
198 *
199 * return -1 if groupnumber is invalid.
200 * return -2 if peernumber is invalid.
201 */
197int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber); 202int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber);
198 203
199/* Copy the name of peernumber who is in groupnumber to name. 204/* Copy the name of peernumber who is in groupnumber to name.
200 * name must be at least MAX_NAME_LENGTH long. 205 * name must be at least MAX_NAME_LENGTH long.
201 * 206 *
202 * return length of name if success 207 * return length of name if success
203 * return -1 if failure 208 * return -1 if groupnumber is invalid.
209 * return -2 if peernumber is invalid.
204 */ 210 */
205int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *name); 211int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *name);
206 212
207/* invite friendnumber to groupnumber 213/* invite friendnumber to groupnumber
208 * return 0 on success 214 *
209 * return -1 on failure 215 * return 0 on success.
216 * return -1 if groupnumber is invalid.
217 * return -2 if invite packet failed to send.
210 */ 218 */
211int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber); 219int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber);
212 220
@@ -214,49 +222,64 @@ int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber);
214 * 222 *
215 * expected_type is the groupchat type we expect the chat we are joining is. 223 * expected_type is the groupchat type we expect the chat we are joining is.
216 * 224 *
217 * returns group number on success 225 * return group number on success.
218 * returns -1 on failure. 226 * return -1 if data length is invalid.
227 * return -2 if group is not the expected type.
228 * return -3 if friendnumber is invalid.
229 * return -4 if client is already in this group.
230 * return -5 if group instance failed to initialize.
231 * return -6 if join packet fails to send.
219 */ 232 */
220int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length); 233int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length);
221 234
222/* send a group message 235/* send a group message
223 * return 0 on success 236 * return 0 on success
224 * return -1 on failure 237 * see: send_message_group() for error codes.
225 */ 238 */
226int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *message, uint16_t length); 239int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *message, uint16_t length);
227 240
228/* send a group action 241/* send a group action
229 * return 0 on success 242 * return 0 on success
230 * return -1 on failure 243 * see: send_message_group() for error codes.
231 */ 244 */
232int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length); 245int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length);
233 246
234/* set the group's title, limited to MAX_NAME_LENGTH 247/* set the group's title, limited to MAX_NAME_LENGTH
235 * return 0 on success 248 * return 0 on success
236 * return -1 on failure 249 * return -1 if groupnumber is invalid.
250 * return -2 if title is too long or empty.
251 * return -3 if packet fails to send.
237 */ 252 */
238int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len); 253int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len);
239 254
240 255
256/* return the group's title size.
257 * return -1 of groupnumber is invalid.
258 * return -2 if title is too long or empty.
259 */
241int group_title_get_size(const Group_Chats *g_c, int groupnumber); 260int group_title_get_size(const Group_Chats *g_c, int groupnumber);
242 261
243/* Get group title from groupnumber and put it in title. 262/* Get group title from groupnumber and put it in title.
244 * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes. 263 * Title needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
245 * 264 *
246 * return length of copied title if success. 265 * return length of copied title if success.
247 * return -1 if failure. 266 * return -1 if groupnumber is invalid.
267 * return -2 if title is too long or empty.
248 */ 268 */
249int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title); 269int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title);
250 270
251/* Return the number of peers in the group chat on success. 271/* Return the number of peers in the group chat on success.
252 * return -1 on failure 272 * return -1 if groupnumber is invalid.
253 */ 273 */
254int group_number_peers(const Group_Chats *g_c, int groupnumber); 274int group_number_peers(const Group_Chats *g_c, int groupnumber);
255 275
256/* return 1 if the peernumber corresponds to ours. 276/* return 1 if the peernumber corresponds to ours.
257 * return 0 on failure. 277 * return 0 if the peernumber is not ours.
278 * return -1 if groupnumber is invalid.
279 * return -2 if peernumber is invalid.
280 * return -3 if we are not connected to the group chat.
258 */ 281 */
259unsigned int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernumber); 282int group_peernumber_is_ours(const Group_Chats *g_c, int groupnumber, int peernumber);
260 283
261/* List all the peers in the group chat. 284/* List all the peers in the group chat.
262 * 285 *