diff options
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r-- | toxcore/tox.c | 172 |
1 files changed, 100 insertions, 72 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c index ce4bd996..a928f3f9 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -60,7 +60,7 @@ void tox_get_address(Tox *tox, uint8_t *address) | |||
60 | * (the nospam for that friend was set to the new one). | 60 | * (the nospam for that friend was set to the new one). |
61 | * return FAERR_NOMEM if increasing the friend list size fails. | 61 | * return FAERR_NOMEM if increasing the friend list size fails. |
62 | */ | 62 | */ |
63 | int tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length) | 63 | int32_t tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length) |
64 | { | 64 | { |
65 | Messenger *m = tox; | 65 | Messenger *m = tox; |
66 | return m_addfriend(m, address, data, length); | 66 | return m_addfriend(m, address, data, length); |
@@ -71,16 +71,16 @@ int tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length) | |||
71 | * return the friend number if success. | 71 | * return the friend number if success. |
72 | * return -1 if failure. | 72 | * return -1 if failure. |
73 | */ | 73 | */ |
74 | int tox_add_friend_norequest(Tox *tox, uint8_t *client_id) | 74 | int32_t tox_add_friend_norequest(Tox *tox, uint8_t *client_id) |
75 | { | 75 | { |
76 | Messenger *m = tox; | 76 | Messenger *m = tox; |
77 | return m_addfriend_norequest(m, client_id); | 77 | return m_addfriend_norequest(m, client_id); |
78 | } | 78 | } |
79 | 79 | ||
80 | /* return the friend id associated to that client id. | 80 | /* return the friend number associated to that client id. |
81 | * return -1 if no such friend. | 81 | * return -1 if no such friend. |
82 | */ | 82 | */ |
83 | int tox_get_friend_id(Tox *tox, uint8_t *client_id) | 83 | int32_t tox_get_friend_number(Tox *tox, uint8_t *client_id) |
84 | { | 84 | { |
85 | Messenger *m = tox; | 85 | Messenger *m = tox; |
86 | return getfriend_id(m, client_id); | 86 | return getfriend_id(m, client_id); |
@@ -92,14 +92,14 @@ int tox_get_friend_id(Tox *tox, uint8_t *client_id) | |||
92 | * return 0 if success. | 92 | * return 0 if success. |
93 | * return -1 if failure. | 93 | * return -1 if failure. |
94 | */ | 94 | */ |
95 | int tox_get_client_id(Tox *tox, int friend_id, uint8_t *client_id) | 95 | int tox_get_client_id(Tox *tox, int32_t friendnumber, uint8_t *client_id) |
96 | { | 96 | { |
97 | Messenger *m = tox; | 97 | Messenger *m = tox; |
98 | return getclient_id(m, friend_id, client_id); | 98 | return getclient_id(m, friendnumber, client_id); |
99 | } | 99 | } |
100 | 100 | ||
101 | /* Remove a friend. */ | 101 | /* Remove a friend. */ |
102 | int tox_del_friend(Tox *tox, int friendnumber) | 102 | int tox_del_friend(Tox *tox, int32_t friendnumber) |
103 | { | 103 | { |
104 | Messenger *m = tox; | 104 | Messenger *m = tox; |
105 | return m_delfriend(m, friendnumber); | 105 | return m_delfriend(m, friendnumber); |
@@ -111,7 +111,7 @@ int tox_del_friend(Tox *tox, int friendnumber) | |||
111 | * return 0 if friend is not connected to us (Offline). | 111 | * return 0 if friend is not connected to us (Offline). |
112 | * return -1 on failure. | 112 | * return -1 on failure. |
113 | */ | 113 | */ |
114 | int tox_get_friend_connection_status(Tox *tox, int friendnumber) | 114 | int tox_get_friend_connection_status(Tox *tox, int32_t friendnumber) |
115 | { | 115 | { |
116 | Messenger *m = tox; | 116 | Messenger *m = tox; |
117 | return m_get_friend_connectionstatus(m, friendnumber); | 117 | return m_get_friend_connectionstatus(m, friendnumber); |
@@ -122,7 +122,7 @@ int tox_get_friend_connection_status(Tox *tox, int friendnumber) | |||
122 | * return 1 if friend exists. | 122 | * return 1 if friend exists. |
123 | * return 0 if friend doesn't exist. | 123 | * return 0 if friend doesn't exist. |
124 | */ | 124 | */ |
125 | int tox_friend_exists(Tox *tox, int friendnumber) | 125 | int tox_friend_exists(Tox *tox, int32_t friendnumber) |
126 | { | 126 | { |
127 | Messenger *m = tox; | 127 | Messenger *m = tox; |
128 | return m_friend_exists(m, friendnumber); | 128 | return m_friend_exists(m, friendnumber); |
@@ -137,13 +137,13 @@ int tox_friend_exists(Tox *tox, int friendnumber) | |||
137 | * m_sendmessage_withid will send a message with the id of your choosing, | 137 | * m_sendmessage_withid will send a message with the id of your choosing, |
138 | * however we can generate an id for you by calling plain m_sendmessage. | 138 | * however we can generate an id for you by calling plain m_sendmessage. |
139 | */ | 139 | */ |
140 | uint32_t tox_send_message(Tox *tox, int friendnumber, uint8_t *message, uint32_t length) | 140 | uint32_t tox_send_message(Tox *tox, int32_t friendnumber, uint8_t *message, uint32_t length) |
141 | { | 141 | { |
142 | Messenger *m = tox; | 142 | Messenger *m = tox; |
143 | return m_sendmessage(m, friendnumber, message, length); | 143 | return m_sendmessage(m, friendnumber, message, length); |
144 | } | 144 | } |
145 | 145 | ||
146 | uint32_t tox_send_message_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length) | 146 | uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length) |
147 | { | 147 | { |
148 | Messenger *m = tox; | 148 | Messenger *m = tox; |
149 | return m_sendmessage_withid(m, friendnumber, theid, message, length); | 149 | return m_sendmessage_withid(m, friendnumber, theid, message, length); |
@@ -159,13 +159,13 @@ uint32_t tox_send_message_withid(Tox *tox, int friendnumber, uint32_t theid, uin | |||
159 | * m_sendaction_withid will send an action message with the id of your choosing, | 159 | * m_sendaction_withid will send an action message with the id of your choosing, |
160 | * however we can generate an id for you by calling plain m_sendaction. | 160 | * however we can generate an id for you by calling plain m_sendaction. |
161 | */ | 161 | */ |
162 | uint32_t tox_send_action(Tox *tox, int friendnumber, uint8_t *action, uint32_t length) | 162 | uint32_t tox_send_action(Tox *tox, int32_t friendnumber, uint8_t *action, uint32_t length) |
163 | { | 163 | { |
164 | Messenger *m = tox; | 164 | Messenger *m = tox; |
165 | return m_sendaction(m, friendnumber, action, length); | 165 | return m_sendaction(m, friendnumber, action, length); |
166 | } | 166 | } |
167 | 167 | ||
168 | uint32_t tox_send_action_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length) | 168 | uint32_t tox_send_action_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *action, uint32_t length) |
169 | { | 169 | { |
170 | Messenger *m = tox; | 170 | Messenger *m = tox; |
171 | return m_sendaction_withid(m, friendnumber, theid, action, length); | 171 | return m_sendaction_withid(m, friendnumber, theid, action, length); |
@@ -187,16 +187,15 @@ int tox_set_name(Tox *tox, uint8_t *name, uint16_t length) | |||
187 | 187 | ||
188 | /* Get your nickname. | 188 | /* Get your nickname. |
189 | * m - The messanger context to use. | 189 | * m - The messanger context to use. |
190 | * name - Pointer to a string for the name. | 190 | * name - Pointer to a string for the name. (must be at least MAX_NAME_LENGTH) |
191 | * nlen - The length of the string buffer. | ||
192 | * | 191 | * |
193 | * return length of the name. | 192 | * return length of the name. |
194 | * return 0 on error. | 193 | * return 0 on error. |
195 | */ | 194 | */ |
196 | uint16_t tox_get_self_name(Tox *tox, uint8_t *name, uint16_t nlen) | 195 | uint16_t tox_get_self_name(Tox *tox, uint8_t *name) |
197 | { | 196 | { |
198 | Messenger *m = tox; | 197 | Messenger *m = tox; |
199 | return getself_name(m, name, nlen); | 198 | return getself_name(m, name); |
200 | } | 199 | } |
201 | 200 | ||
202 | /* Get name of friendnumber and put it in name. | 201 | /* Get name of friendnumber and put it in name. |
@@ -205,12 +204,27 @@ uint16_t tox_get_self_name(Tox *tox, uint8_t *name, uint16_t nlen) | |||
205 | * return length of name (with the NULL terminator) if success. | 204 | * return length of name (with the NULL terminator) if success. |
206 | * return -1 if failure. | 205 | * return -1 if failure. |
207 | */ | 206 | */ |
208 | int tox_get_name(Tox *tox, int friendnumber, uint8_t *name) | 207 | int tox_get_name(Tox *tox, int32_t friendnumber, uint8_t *name) |
209 | { | 208 | { |
210 | Messenger *m = tox; | 209 | Messenger *m = tox; |
211 | return getname(m, friendnumber, name); | 210 | return getname(m, friendnumber, name); |
212 | } | 211 | } |
213 | 212 | ||
213 | /* returns the length of name on success. | ||
214 | * returns -1 on failure. | ||
215 | */ | ||
216 | int tox_get_name_size(Tox *tox, int32_t friendnumber) | ||
217 | { | ||
218 | Messenger *m = tox; | ||
219 | return m_get_name_size(m, friendnumber); | ||
220 | } | ||
221 | |||
222 | int tox_get_self_name_size(Tox *tox) | ||
223 | { | ||
224 | Messenger *m = tox; | ||
225 | return m_get_self_name_size(m); | ||
226 | } | ||
227 | |||
214 | /* Set our user status; | 228 | /* Set our user status; |
215 | * you are responsible for freeing status after. | 229 | * you are responsible for freeing status after. |
216 | * | 230 | * |
@@ -222,26 +236,32 @@ int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length) | |||
222 | return m_set_statusmessage(m, status, length); | 236 | return m_set_statusmessage(m, status, length); |
223 | } | 237 | } |
224 | 238 | ||
225 | int tox_set_user_status(Tox *tox, TOX_USERSTATUS status) | 239 | int tox_set_user_status(Tox *tox, uint8_t status) |
226 | { | 240 | { |
227 | Messenger *m = tox; | 241 | Messenger *m = tox; |
228 | return m_set_userstatus(m, (USERSTATUS)status); | 242 | return m_set_userstatus(m, status); |
229 | } | 243 | } |
230 | 244 | ||
231 | /* return the length of friendnumber's status message, including null. | 245 | /* returns the length of status message on success. |
232 | * Pass it into malloc. | 246 | * returns -1 on failure. |
233 | */ | 247 | */ |
234 | int tox_get_status_message_size(Tox *tox, int friendnumber) | 248 | int tox_get_status_message_size(Tox *tox, int32_t friendnumber) |
235 | { | 249 | { |
236 | Messenger *m = tox; | 250 | Messenger *m = tox; |
237 | return m_get_statusmessage_size(m, friendnumber); | 251 | return m_get_statusmessage_size(m, friendnumber); |
238 | } | 252 | } |
239 | 253 | ||
254 | int tox_get_self_status_message_size(Tox *tox) | ||
255 | { | ||
256 | Messenger *m = tox; | ||
257 | return m_get_self_statusmessage_size(m); | ||
258 | } | ||
259 | |||
240 | /* Copy friendnumber's status message into buf, truncating if size is over maxlen. | 260 | /* Copy friendnumber's status message into buf, truncating if size is over maxlen. |
241 | * Get the size you need to allocate from m_get_statusmessage_size. | 261 | * Get the size you need to allocate from m_get_statusmessage_size. |
242 | * The self variant will copy our own status message. | 262 | * The self variant will copy our own status message. |
243 | */ | 263 | */ |
244 | int tox_get_status_message(Tox *tox, int friendnumber, uint8_t *buf, uint32_t maxlen) | 264 | int tox_get_status_message(Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen) |
245 | { | 265 | { |
246 | Messenger *m = tox; | 266 | Messenger *m = tox; |
247 | return m_copy_statusmessage(m, friendnumber, buf, maxlen); | 267 | return m_copy_statusmessage(m, friendnumber, buf, maxlen); |
@@ -258,22 +278,22 @@ int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen) | |||
258 | * As above, the self variant will return our own USERSTATUS. | 278 | * As above, the self variant will return our own USERSTATUS. |
259 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. | 279 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. |
260 | */ | 280 | */ |
261 | TOX_USERSTATUS tox_get_user_status(Tox *tox, int friendnumber) | 281 | uint8_t tox_get_user_status(Tox *tox, int32_t friendnumber) |
262 | { | 282 | { |
263 | Messenger *m = tox; | 283 | Messenger *m = tox; |
264 | return (TOX_USERSTATUS)m_get_userstatus(m, friendnumber); | 284 | return m_get_userstatus(m, friendnumber); |
265 | } | 285 | } |
266 | 286 | ||
267 | TOX_USERSTATUS tox_get_self_user_status(Tox *tox) | 287 | uint8_t tox_get_self_user_status(Tox *tox) |
268 | { | 288 | { |
269 | Messenger *m = tox; | 289 | Messenger *m = tox; |
270 | return (TOX_USERSTATUS)m_get_self_userstatus(m); | 290 | return m_get_self_userstatus(m); |
271 | } | 291 | } |
272 | 292 | ||
273 | /* returns timestamp of last time friendnumber was seen online, or 0 if never seen. | 293 | /* returns timestamp of last time friendnumber was seen online, or 0 if never seen. |
274 | * returns -1 on error. | 294 | * returns -1 on error. |
275 | */ | 295 | */ |
276 | uint64_t tox_get_last_online(Tox *tox, int friendnumber) | 296 | uint64_t tox_get_last_online(Tox *tox, int32_t friendnumber) |
277 | { | 297 | { |
278 | Messenger *m = tox; | 298 | Messenger *m = tox; |
279 | return m_get_last_online(m, friendnumber); | 299 | return m_get_last_online(m, friendnumber); |
@@ -285,7 +305,7 @@ uint64_t tox_get_last_online(Tox *tox, int friendnumber) | |||
285 | * returns 0 on success. | 305 | * returns 0 on success. |
286 | * returns -1 on failure. | 306 | * returns -1 on failure. |
287 | */ | 307 | */ |
288 | int tox_set_user_is_typing(Tox *tox, int friendnumber, uint8_t is_typing) | 308 | int tox_set_user_is_typing(Tox *tox, int32_t friendnumber, uint8_t is_typing) |
289 | { | 309 | { |
290 | Messenger *m = tox; | 310 | Messenger *m = tox; |
291 | return m_set_usertyping(m, friendnumber, is_typing); | 311 | return m_set_usertyping(m, friendnumber, is_typing); |
@@ -296,7 +316,7 @@ int tox_set_user_is_typing(Tox *tox, int friendnumber, uint8_t is_typing) | |||
296 | * returns 0 if friend is not typing. | 316 | * returns 0 if friend is not typing. |
297 | * returns 1 if friend is typing. | 317 | * returns 1 if friend is typing. |
298 | */ | 318 | */ |
299 | int tox_get_is_typing(Tox *tox, int friendnumber) | 319 | int tox_get_is_typing(Tox *tox, int32_t friendnumber) |
300 | { | 320 | { |
301 | Messenger *m = tox; | 321 | Messenger *m = tox; |
302 | return m_get_istyping(m, friendnumber); | 322 | return m_get_istyping(m, friendnumber); |
@@ -305,7 +325,7 @@ int tox_get_is_typing(Tox *tox, int friendnumber) | |||
305 | /* Sets whether we send read receipts for friendnumber. | 325 | /* Sets whether we send read receipts for friendnumber. |
306 | * This function is not lazy, and it will fail if yesno is not (0 or 1). | 326 | * This function is not lazy, and it will fail if yesno is not (0 or 1). |
307 | */ | 327 | */ |
308 | void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno) | 328 | void tox_set_sends_receipts(Tox *tox, int32_t friendnumber, int yesno) |
309 | { | 329 | { |
310 | Messenger *m = tox; | 330 | Messenger *m = tox; |
311 | m_set_sends_receipts(m, friendnumber, yesno); | 331 | m_set_sends_receipts(m, friendnumber, yesno); |
@@ -332,7 +352,7 @@ uint32_t tox_get_num_online_friends(Tox *tox) | |||
332 | * Otherwise, returns the number of elements copied. | 352 | * Otherwise, returns the number of elements copied. |
333 | * If the array was too small, the contents | 353 | * If the array was too small, the contents |
334 | * of out_list will be truncated to list_size. */ | 354 | * of out_list will be truncated to list_size. */ |
335 | uint32_t tox_get_friendlist(Tox *tox, int *out_list, uint32_t list_size) | 355 | uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size) |
336 | { | 356 | { |
337 | Messenger *m = tox; | 357 | Messenger *m = tox; |
338 | return copy_friendlist(m, out_list, list_size); | 358 | return copy_friendlist(m, out_list, list_size); |
@@ -341,7 +361,8 @@ uint32_t tox_get_friendlist(Tox *tox, int *out_list, uint32_t list_size) | |||
341 | /* Set the function that will be executed when a friend request is received. | 361 | /* Set the function that will be executed when a friend request is received. |
342 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) | 362 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) |
343 | */ | 363 | */ |
344 | void tox_callback_friend_request(Tox *tox, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata) | 364 | void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, uint8_t *, uint8_t *, uint16_t, void *), |
365 | void *userdata) | ||
345 | { | 366 | { |
346 | Messenger *m = tox; | 367 | Messenger *m = tox; |
347 | m_callback_friendrequest(m, function, userdata); | 368 | m_callback_friendrequest(m, function, userdata); |
@@ -349,9 +370,9 @@ void tox_callback_friend_request(Tox *tox, void (*function)(uint8_t *, uint8_t * | |||
349 | 370 | ||
350 | 371 | ||
351 | /* Set the function that will be executed when a message from a friend is received. | 372 | /* Set the function that will be executed when a message from a friend is received. |
352 | * Function format is: function(int friendnumber, uint8_t * message, uint32_t length) | 373 | * Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length) |
353 | */ | 374 | */ |
354 | void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 375 | void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), |
355 | void *userdata) | 376 | void *userdata) |
356 | { | 377 | { |
357 | Messenger *m = tox; | 378 | Messenger *m = tox; |
@@ -359,9 +380,9 @@ void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int, | |||
359 | } | 380 | } |
360 | 381 | ||
361 | /* Set the function that will be executed when an action from a friend is received. | 382 | /* Set the function that will be executed when an action from a friend is received. |
362 | * function format is: function(int friendnumber, uint8_t * action, uint32_t length) | 383 | * function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length) |
363 | */ | 384 | */ |
364 | void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 385 | void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), |
365 | void *userdata) | 386 | void *userdata) |
366 | { | 387 | { |
367 | Messenger *m = tox; | 388 | Messenger *m = tox; |
@@ -369,10 +390,10 @@ void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int, | |||
369 | } | 390 | } |
370 | 391 | ||
371 | /* Set the callback for name changes. | 392 | /* Set the callback for name changes. |
372 | * function(int friendnumber, uint8_t *newname, uint16_t length) | 393 | * function(int32_t friendnumber, uint8_t *newname, uint16_t length) |
373 | * You are not responsible for freeing newname. | 394 | * You are not responsible for freeing newname. |
374 | */ | 395 | */ |
375 | void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 396 | void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), |
376 | void *userdata) | 397 | void *userdata) |
377 | { | 398 | { |
378 | Messenger *m = tox; | 399 | Messenger *m = tox; |
@@ -380,10 +401,10 @@ void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int, ui | |||
380 | } | 401 | } |
381 | 402 | ||
382 | /* Set the callback for status message changes. | 403 | /* Set the callback for status message changes. |
383 | * function(int friendnumber, uint8_t *newstatus, uint16_t length) | 404 | * function(int32_t friendnumber, uint8_t *newstatus, uint16_t length) |
384 | * You are not responsible for freeing newstatus. | 405 | * You are not responsible for freeing newstatus. |
385 | */ | 406 | */ |
386 | void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 407 | void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), |
387 | void *userdata) | 408 | void *userdata) |
388 | { | 409 | { |
389 | Messenger *m = tox; | 410 | Messenger *m = tox; |
@@ -391,25 +412,26 @@ void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int, | |||
391 | } | 412 | } |
392 | 413 | ||
393 | /* Set the callback for status type changes. | 414 | /* Set the callback for status type changes. |
394 | * function(int friendnumber, USERSTATUS kind) | 415 | * function(int32_t friendnumber, USERSTATUS kind) |
395 | */ | 416 | */ |
396 | void tox_callback_user_status(Tox *tox, void (*function)(Messenger *tox, int, TOX_USERSTATUS, void *), void *userdata) | 417 | void tox_callback_user_status(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, void *), |
418 | void *userdata) | ||
397 | { | 419 | { |
398 | Messenger *m = tox; | 420 | Messenger *m = tox; |
399 | m_callback_userstatus(m, function, userdata); | 421 | m_callback_userstatus(m, function, userdata); |
400 | } | 422 | } |
401 | 423 | ||
402 | /* Set the callback for typing changes. | 424 | /* Set the callback for typing changes. |
403 | * function (int friendnumber, int is_typing) | 425 | * function (int32_t friendnumber, int is_typing) |
404 | */ | 426 | */ |
405 | void tox_callback_typing_change(Tox *tox, void (*function)(Messenger *tox, int, int, void *), void *userdata) | 427 | void tox_callback_typing_change(Tox *tox, void (*function)(Messenger *tox, int32_t, int, void *), void *userdata) |
406 | { | 428 | { |
407 | Messenger *m = tox; | 429 | Messenger *m = tox; |
408 | m_callback_typingchange(m, function, userdata); | 430 | m_callback_typingchange(m, function, userdata); |
409 | } | 431 | } |
410 | 432 | ||
411 | /* Set the callback for read receipts. | 433 | /* Set the callback for read receipts. |
412 | * function(int friendnumber, uint32_t receipt) | 434 | * function(int32_t friendnumber, uint32_t receipt) |
413 | * | 435 | * |
414 | * If you are keeping a record of returns from m_sendmessage; | 436 | * If you are keeping a record of returns from m_sendmessage; |
415 | * receipt might be one of those values, meaning the message | 437 | * receipt might be one of those values, meaning the message |
@@ -417,14 +439,14 @@ void tox_callback_typing_change(Tox *tox, void (*function)(Messenger *tox, int, | |||
417 | * Since core doesn't track ids for you, receipt may not correspond to any message. | 439 | * Since core doesn't track ids for you, receipt may not correspond to any message. |
418 | * in that case, you should discard it. | 440 | * in that case, you should discard it. |
419 | */ | 441 | */ |
420 | void tox_callback_read_receipt(Tox *tox, void (*function)(Messenger *tox, int, uint32_t, void *), void *userdata) | 442 | void tox_callback_read_receipt(Tox *tox, void (*function)(Messenger *tox, int32_t, uint32_t, void *), void *userdata) |
421 | { | 443 | { |
422 | Messenger *m = tox; | 444 | Messenger *m = tox; |
423 | m_callback_read_receipt(m, function, userdata); | 445 | m_callback_read_receipt(m, function, userdata); |
424 | } | 446 | } |
425 | 447 | ||
426 | /* Set the callback for connection status changes. | 448 | /* Set the callback for connection status changes. |
427 | * function(int friendnumber, uint8_t status) | 449 | * function(int32_t friendnumber, uint8_t status) |
428 | * | 450 | * |
429 | * Status: | 451 | * Status: |
430 | * 0 -- friend went offline after being previously online | 452 | * 0 -- friend went offline after being previously online |
@@ -434,7 +456,8 @@ void tox_callback_read_receipt(Tox *tox, void (*function)(Messenger *tox, int, u | |||
434 | * being previously online" part. It's assumed that when adding friends, | 456 | * being previously online" part. It's assumed that when adding friends, |
435 | * their connection status is offline. | 457 | * their connection status is offline. |
436 | */ | 458 | */ |
437 | void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, void *), void *userdata) | 459 | void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, void *), |
460 | void *userdata) | ||
438 | { | 461 | { |
439 | Messenger *m = tox; | 462 | Messenger *m = tox; |
440 | m_callback_connectionstatus(m, function, userdata); | 463 | m_callback_connectionstatus(m, function, userdata); |
@@ -444,9 +467,9 @@ void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, i | |||
444 | 467 | ||
445 | /* Set the callback for group invites. | 468 | /* Set the callback for group invites. |
446 | * | 469 | * |
447 | * Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata) | 470 | * Function(Tox *tox, int32_t friendnumber, uint8_t *group_public_key, void *userdata) |
448 | */ | 471 | */ |
449 | void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, void *), void *userdata) | 472 | void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, void *), void *userdata) |
450 | { | 473 | { |
451 | Messenger *m = tox; | 474 | Messenger *m = tox; |
452 | m_callback_group_invite(m, function, userdata); | 475 | m_callback_group_invite(m, function, userdata); |
@@ -521,7 +544,7 @@ int tox_group_peername(Tox *tox, int groupnumber, int peernumber, uint8_t *name) | |||
521 | * return 0 on success | 544 | * return 0 on success |
522 | * return -1 on failure | 545 | * return -1 on failure |
523 | */ | 546 | */ |
524 | int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber) | 547 | int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) |
525 | { | 548 | { |
526 | Messenger *m = tox; | 549 | Messenger *m = tox; |
527 | return invite_friend(m, friendnumber, groupnumber); | 550 | return invite_friend(m, friendnumber, groupnumber); |
@@ -531,7 +554,7 @@ int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber) | |||
531 | * returns group number on success | 554 | * returns group number on success |
532 | * returns -1 on failure. | 555 | * returns -1 on failure. |
533 | */ | 556 | */ |
534 | int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key) | 557 | int tox_join_groupchat(Tox *tox, int32_t friendnumber, uint8_t *friend_group_public_key) |
535 | { | 558 | { |
536 | Messenger *m = tox; | 559 | Messenger *m = tox; |
537 | return join_groupchat(m, friendnumber, friend_group_public_key); | 560 | return join_groupchat(m, friendnumber, friend_group_public_key); |
@@ -606,9 +629,9 @@ uint32_t tox_get_chatlist(Tox *tox, int *out_list, uint32_t list_size) | |||
606 | 629 | ||
607 | /* Set the callback for file send requests. | 630 | /* Set the callback for file send requests. |
608 | * | 631 | * |
609 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) | 632 | * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) |
610 | */ | 633 | */ |
611 | void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint64_t, uint8_t *, | 634 | void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint64_t, uint8_t *, |
612 | uint16_t, | 635 | uint16_t, |
613 | void *), void *userdata) | 636 | void *), void *userdata) |
614 | { | 637 | { |
@@ -617,10 +640,10 @@ void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, i | |||
617 | } | 640 | } |
618 | /* Set the callback for file control requests. | 641 | /* Set the callback for file control requests. |
619 | * | 642 | * |
620 | * Function(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata) | 643 | * Function(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata) |
621 | * | 644 | * |
622 | */ | 645 | */ |
623 | void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint8_t, uint8_t, uint8_t *, | 646 | void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *, |
624 | uint16_t, void *), void *userdata) | 647 | uint16_t, void *), void *userdata) |
625 | { | 648 | { |
626 | Messenger *m = tox; | 649 | Messenger *m = tox; |
@@ -628,10 +651,10 @@ void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int, u | |||
628 | } | 651 | } |
629 | /* Set the callback for file data. | 652 | /* Set the callback for file data. |
630 | * | 653 | * |
631 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) | 654 | * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) |
632 | * | 655 | * |
633 | */ | 656 | */ |
634 | void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint8_t *, uint16_t length, | 657 | void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint8_t *, uint16_t length, |
635 | void *), | 658 | void *), |
636 | void *userdata) | 659 | void *userdata) |
637 | 660 | ||
@@ -644,7 +667,7 @@ void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int, uint | |||
644 | * return file number on success | 667 | * return file number on success |
645 | * return -1 on failure | 668 | * return -1 on failure |
646 | */ | 669 | */ |
647 | int tox_new_file_sender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length) | 670 | int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length) |
648 | { | 671 | { |
649 | Messenger *m = tox; | 672 | Messenger *m = tox; |
650 | return new_filesender(m, friendnumber, filesize, filename, filename_length); | 673 | return new_filesender(m, friendnumber, filesize, filename, filename_length); |
@@ -655,7 +678,7 @@ int tox_new_file_sender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t * | |||
655 | * return 0 on success | 678 | * return 0 on success |
656 | * return -1 on failure | 679 | * return -1 on failure |
657 | */ | 680 | */ |
658 | int tox_file_send_control(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, | 681 | int tox_file_send_control(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, |
659 | uint8_t *data, uint16_t length) | 682 | uint8_t *data, uint16_t length) |
660 | { | 683 | { |
661 | Messenger *m = tox; | 684 | Messenger *m = tox; |
@@ -666,7 +689,7 @@ int tox_file_send_control(Tox *tox, int friendnumber, uint8_t send_receive, uint | |||
666 | * return 0 on success | 689 | * return 0 on success |
667 | * return -1 on failure | 690 | * return -1 on failure |
668 | */ | 691 | */ |
669 | int tox_file_send_data(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) | 692 | int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) |
670 | { | 693 | { |
671 | Messenger *m = tox; | 694 | Messenger *m = tox; |
672 | return file_data(m, friendnumber, filenumber, data, length); | 695 | return file_data(m, friendnumber, filenumber, data, length); |
@@ -677,7 +700,7 @@ int tox_file_send_data(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t * | |||
677 | * return size on success | 700 | * return size on success |
678 | * return -1 on failure (currently will never return -1) | 701 | * return -1 on failure (currently will never return -1) |
679 | */ | 702 | */ |
680 | int tox_file_data_size(Tox *tox, int friendnumber) | 703 | int tox_file_data_size(Tox *tox, int32_t friendnumber) |
681 | { | 704 | { |
682 | return MAX_DATA_SIZE - crypto_box_MACBYTES - 3; | 705 | return MAX_DATA_SIZE - crypto_box_MACBYTES - 3; |
683 | } | 706 | } |
@@ -689,7 +712,7 @@ int tox_file_data_size(Tox *tox, int friendnumber) | |||
689 | * return number of bytes remaining to be sent/received on success | 712 | * return number of bytes remaining to be sent/received on success |
690 | * return 0 on failure | 713 | * return 0 on failure |
691 | */ | 714 | */ |
692 | uint64_t tox_file_data_remaining(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive) | 715 | uint64_t tox_file_data_remaining(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive) |
693 | { | 716 | { |
694 | Messenger *m = tox; | 717 | Messenger *m = tox; |
695 | return file_dataremaining(m, friendnumber, filenumber, send_receive); | 718 | return file_dataremaining(m, friendnumber, filenumber, send_receive); |
@@ -753,22 +776,27 @@ void tox_do(Tox *tox) | |||
753 | /* | 776 | /* |
754 | * functions to avoid excessive polling | 777 | * functions to avoid excessive polling |
755 | */ | 778 | */ |
756 | int tox_wait_prepare(Tox *tox, uint8_t *data, uint16_t *lenptr) | 779 | |
780 | size_t tox_wait_data_size() | ||
757 | { | 781 | { |
758 | Messenger *m = tox; | 782 | return wait_data_size(); |
759 | return wait_prepare_messenger(m, data, lenptr); | ||
760 | } | 783 | } |
761 | 784 | ||
762 | int tox_wait_execute(Tox *tox, uint8_t *data, uint16_t len, uint16_t milliseconds) | 785 | int tox_wait_prepare(Tox *tox, uint8_t *data) |
763 | { | 786 | { |
764 | Messenger *m = tox; | 787 | Messenger *m = tox; |
765 | return wait_execute_messenger(m, data, len, milliseconds); | 788 | return wait_prepare_messenger(m, data); |
789 | } | ||
790 | |||
791 | int tox_wait_execute(uint8_t *data, long seconds, long microseconds) | ||
792 | { | ||
793 | return wait_execute_messenger(data, seconds, microseconds); | ||
766 | } | 794 | } |
767 | 795 | ||
768 | void tox_wait_cleanup(Tox *tox, uint8_t *data, uint16_t len) | 796 | int tox_wait_cleanup(Tox *tox, uint8_t *data) |
769 | { | 797 | { |
770 | Messenger *m = tox; | 798 | Messenger *m = tox; |
771 | wait_cleanup_messenger(m, data, len); | 799 | return wait_cleanup_messenger(m, data); |
772 | } | 800 | } |
773 | 801 | ||
774 | /* SAVING AND LOADING FUNCTIONS: */ | 802 | /* SAVING AND LOADING FUNCTIONS: */ |