summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/Messenger.c17
-rw-r--r--toxcore/Messenger.h10
-rw-r--r--toxcore/tox.c12
-rw-r--r--toxcore/tox.h26
4 files changed, 32 insertions, 33 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index da326b88..81a347be 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -562,7 +562,7 @@ int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length)
562 return 0; 562 return 0;
563} 563}
564 564
565int m_set_userstatus(Messenger *m, USERSTATUS status) 565int m_set_userstatus(Messenger *m, uint8_t status)
566{ 566{
567 if (status >= USERSTATUS_INVALID) { 567 if (status >= USERSTATUS_INVALID) {
568 return -1; 568 return -1;
@@ -616,12 +616,12 @@ int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen)
616 return MIN(maxlen, m->statusmessage_length); 616 return MIN(maxlen, m->statusmessage_length);
617} 617}
618 618
619USERSTATUS m_get_userstatus(Messenger *m, int32_t friendnumber) 619uint8_t m_get_userstatus(Messenger *m, int32_t friendnumber)
620{ 620{
621 if (friend_not_valid(m, friendnumber)) 621 if (friend_not_valid(m, friendnumber))
622 return USERSTATUS_INVALID; 622 return USERSTATUS_INVALID;
623 623
624 USERSTATUS status = m->friendlist[friendnumber].userstatus; 624 uint8_t status = m->friendlist[friendnumber].userstatus;
625 625
626 if (status >= USERSTATUS_INVALID) { 626 if (status >= USERSTATUS_INVALID) {
627 status = USERSTATUS_NONE; 627 status = USERSTATUS_NONE;
@@ -630,7 +630,7 @@ USERSTATUS m_get_userstatus(Messenger *m, int32_t friendnumber)
630 return status; 630 return status;
631} 631}
632 632
633USERSTATUS m_get_self_userstatus(Messenger *m) 633uint8_t m_get_self_userstatus(Messenger *m)
634{ 634{
635 return m->userstatus; 635 return m->userstatus;
636} 636}
@@ -663,10 +663,9 @@ static int send_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *statu
663 return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length); 663 return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length);
664} 664}
665 665
666static int send_userstatus(Messenger *m, int32_t friendnumber, USERSTATUS status) 666static int send_userstatus(Messenger *m, int32_t friendnumber, uint8_t status)
667{ 667{
668 uint8_t stat = status; 668 return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &status, sizeof(status));
669 return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &stat, sizeof(stat));
670} 669}
671 670
672static int send_user_istyping(Messenger *m, int32_t friendnumber, uint8_t is_typing) 671static int send_user_istyping(Messenger *m, int32_t friendnumber, uint8_t is_typing)
@@ -698,7 +697,7 @@ static int set_friend_statusmessage(Messenger *m, int32_t friendnumber, uint8_t
698 return 0; 697 return 0;
699} 698}
700 699
701static void set_friend_userstatus(Messenger *m, int32_t friendnumber, USERSTATUS status) 700static void set_friend_userstatus(Messenger *m, int32_t friendnumber, uint8_t status)
702{ 701{
703 m->friendlist[friendnumber].userstatus = status; 702 m->friendlist[friendnumber].userstatus = status;
704} 703}
@@ -756,7 +755,7 @@ void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int32
756 m->friend_statuschange_userdata = userdata; 755 m->friend_statuschange_userdata = userdata;
757} 756}
758 757
759void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int32_t, USERSTATUS, void *), void *userdata) 758void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *), void *userdata)
760{ 759{
761 m->friend_userstatuschange = function; 760 m->friend_userstatuschange = function;
762 m->friend_userstatuschange_userdata = userdata; 761 m->friend_userstatuschange_userdata = userdata;
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 88e5e19d..213f8586 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -206,7 +206,7 @@ typedef struct Messenger {
206 void *friend_namechange_userdata; 206 void *friend_namechange_userdata;
207 void (*friend_statusmessagechange)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *); 207 void (*friend_statusmessagechange)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *);
208 void *friend_statusmessagechange_userdata; 208 void *friend_statusmessagechange_userdata;
209 void (*friend_userstatuschange)(struct Messenger *m, int32_t, USERSTATUS, void *); 209 void (*friend_userstatuschange)(struct Messenger *m, int32_t, uint8_t, void *);
210 void *friend_userstatuschange_userdata; 210 void *friend_userstatuschange_userdata;
211 void (*friend_typingchange)(struct Messenger *m, int32_t, int, void *); 211 void (*friend_typingchange)(struct Messenger *m, int32_t, int, void *);
212 void *friend_typingchange_userdata; 212 void *friend_typingchange_userdata;
@@ -388,7 +388,7 @@ IP_Port get_friend_ipport(Messenger *m, int32_t friendnumber);
388 * returns -1 on failure. 388 * returns -1 on failure.
389 */ 389 */
390int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length); 390int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length);
391int m_set_userstatus(Messenger *m, USERSTATUS status); 391int m_set_userstatus(Messenger *m, uint8_t status);
392 392
393/* return the length of friendnumber's status message, including null on success. 393/* return the length of friendnumber's status message, including null on success.
394 * return -1 on failure. 394 * return -1 on failure.
@@ -411,8 +411,8 @@ int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen);
411 * As above, the self variant will return our own USERSTATUS. 411 * As above, the self variant will return our own USERSTATUS.
412 * If friendnumber is invalid, this shall return USERSTATUS_INVALID. 412 * If friendnumber is invalid, this shall return USERSTATUS_INVALID.
413 */ 413 */
414USERSTATUS m_get_userstatus(Messenger *m, int32_t friendnumber); 414uint8_t m_get_userstatus(Messenger *m, int32_t friendnumber);
415USERSTATUS m_get_self_userstatus(Messenger *m); 415uint8_t m_get_self_userstatus(Messenger *m);
416 416
417/* Set our typing status for a friend. 417/* Set our typing status for a friend.
418 * You are responsible for turning it on or off. 418 * You are responsible for turning it on or off.
@@ -469,7 +469,7 @@ void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int32
469/* Set the callback for status type changes. 469/* Set the callback for status type changes.
470 * Function(int32_t friendnumber, USERSTATUS kind) 470 * Function(int32_t friendnumber, USERSTATUS kind)
471 */ 471 */
472void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int32_t, USERSTATUS, void *), void *userdata); 472void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *), void *userdata);
473 473
474/* Set the callback for typing changes. 474/* Set the callback for typing changes.
475 * Function(int32_t friendnumber, int is_typing) 475 * Function(int32_t friendnumber, int is_typing)
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 0b430a90..d3e596ba 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -236,7 +236,7 @@ int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length)
236 return m_set_statusmessage(m, status, length); 236 return m_set_statusmessage(m, status, length);
237} 237}
238 238
239int tox_set_user_status(Tox *tox, TOX_USERSTATUS status) 239int tox_set_user_status(Tox *tox, uint8_t status)
240{ 240{
241 Messenger *m = tox; 241 Messenger *m = tox;
242 return m_set_userstatus(m, status); 242 return m_set_userstatus(m, status);
@@ -278,16 +278,16 @@ int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen)
278 * As above, the self variant will return our own USERSTATUS. 278 * As above, the self variant will return our own USERSTATUS.
279 * If friendnumber is invalid, this shall return USERSTATUS_INVALID. 279 * If friendnumber is invalid, this shall return USERSTATUS_INVALID.
280 */ 280 */
281TOX_USERSTATUS tox_get_user_status(Tox *tox, int32_t friendnumber) 281uint8_t tox_get_user_status(Tox *tox, int32_t friendnumber)
282{ 282{
283 Messenger *m = tox; 283 Messenger *m = tox;
284 return (TOX_USERSTATUS)m_get_userstatus(m, friendnumber); 284 return m_get_userstatus(m, friendnumber);
285} 285}
286 286
287TOX_USERSTATUS tox_get_self_user_status(Tox *tox) 287uint8_t tox_get_self_user_status(Tox *tox)
288{ 288{
289 Messenger *m = tox; 289 Messenger *m = tox;
290 return (TOX_USERSTATUS)m_get_self_userstatus(m); 290 return m_get_self_userstatus(m);
291} 291}
292 292
293/* Set our typing status for a friend. 293/* Set our typing status for a friend.
@@ -405,7 +405,7 @@ void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int3
405/* Set the callback for status type changes. 405/* Set the callback for status type changes.
406 * function(int32_t friendnumber, USERSTATUS kind) 406 * function(int32_t friendnumber, USERSTATUS kind)
407 */ 407 */
408void tox_callback_user_status(Tox *tox, void (*function)(Messenger *tox, int32_t, TOX_USERSTATUS, void *), 408void tox_callback_user_status(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, void *),
409 void *userdata) 409 void *userdata)
410{ 410{
411 Messenger *m = tox; 411 Messenger *m = tox;
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 8fb03af3..5b619cd0 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -236,7 +236,7 @@ int tox_get_self_name_size(Tox *tox);
236 * returns -1 on failure. 236 * returns -1 on failure.
237 */ 237 */
238int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length); 238int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length);
239int tox_set_user_status(Tox *tox, TOX_USERSTATUS userstatus); 239int tox_set_user_status(Tox *tox, uint8_t userstatus);
240 240
241/* returns the length of status message on success. 241/* returns the length of status message on success.
242 * returns -1 on failure. 242 * returns -1 on failure.
@@ -259,8 +259,8 @@ int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen);
259 * As above, the self variant will return our own TOX_USERSTATUS. 259 * As above, the self variant will return our own TOX_USERSTATUS.
260 * If friendnumber is invalid, this shall return TOX_USERSTATUS_INVALID. 260 * If friendnumber is invalid, this shall return TOX_USERSTATUS_INVALID.
261 */ 261 */
262TOX_USERSTATUS tox_get_user_status(Tox *tox, int32_t friendnumber); 262uint8_t tox_get_user_status(Tox *tox, int32_t friendnumber);
263TOX_USERSTATUS tox_get_self_user_status(Tox *tox); 263uint8_t tox_get_self_user_status(Tox *tox);
264 264
265/* Set our typing status for a friend. 265/* Set our typing status for a friend.
266 * You are responsible for turning it on or off. 266 * You are responsible for turning it on or off.
@@ -298,48 +298,48 @@ uint32_t tox_get_num_online_friends(Tox *tox);
298uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size); 298uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size);
299 299
300/* Set the function that will be executed when a friend request is received. 300/* Set the function that will be executed when a friend request is received.
301 * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) 301 * Function format is function(Tox *tox, uint8_t * public_key, uint8_t * data, uint16_t length, void *userdata)
302 */ 302 */
303void tox_callback_friend_request(Tox *tox, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata); 303void tox_callback_friend_request(Tox *tox, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata);
304 304
305/* Set the function that will be executed when a message from a friend is received. 305/* Set the function that will be executed when a message from a friend is received.
306 * Function format is: function(int friendnumber, uint8_t * message, uint32_t length) 306 * Function format is: function(Tox *tox, int friendnumber, uint8_t * message, uint32_t length, void *userdata)
307 */ 307 */
308void tox_callback_friend_message(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *), 308void tox_callback_friend_message(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *),
309 void *userdata); 309 void *userdata);
310 310
311/* Set the function that will be executed when an action from a friend is received. 311/* Set the function that will be executed when an action from a friend is received.
312 * Function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length) 312 * Function format is: function(Tox *tox, int32_t friendnumber, uint8_t * action, uint32_t length, void *userdata)
313 */ 313 */
314void tox_callback_friend_action(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *), 314void tox_callback_friend_action(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *),
315 void *userdata); 315 void *userdata);
316 316
317/* Set the callback for name changes. 317/* Set the callback for name changes.
318 * function(int32_t friendnumber, uint8_t *newname, uint16_t length) 318 * function(Tox *tox, int32_t friendnumber, uint8_t *newname, uint16_t length, void *userdata)
319 * You are not responsible for freeing newname 319 * You are not responsible for freeing newname
320 */ 320 */
321void tox_callback_name_change(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *), 321void tox_callback_name_change(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *),
322 void *userdata); 322 void *userdata);
323 323
324/* Set the callback for status message changes. 324/* Set the callback for status message changes.
325 * function(int32_t friendnumber, uint8_t *newstatus, uint16_t length) 325 * function(Tox *tox, int32_t friendnumber, uint8_t *newstatus, uint16_t length, void *userdata)
326 * You are not responsible for freeing newstatus. 326 * You are not responsible for freeing newstatus.
327 */ 327 */
328void tox_callback_status_message(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *), 328void tox_callback_status_message(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *),
329 void *userdata); 329 void *userdata);
330 330
331/* Set the callback for status type changes. 331/* Set the callback for status type changes.
332 * function(int32_t friendnumber, USERSTATUS kind) 332 * function(Tox *tox, int32_t friendnumber, uint8_t TOX_USERSTATUS, void *userdata)
333 */ 333 */
334void tox_callback_user_status(Tox *tox, void (*function)(Tox *tox, int32_t, TOX_USERSTATUS, void *), void *userdata); 334void tox_callback_user_status(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata);
335 335
336/* Set the callback for typing changes. 336/* Set the callback for typing changes.
337 * function (int32_t friendnumber, int is_typing) 337 * function (Tox *tox, int32_t friendnumber, int is_typing, void *userdata)
338 */ 338 */
339void tox_callback_typing_change(Tox *tox, void (*function)(Tox *tox, int32_t, int, void *), void *userdata); 339void tox_callback_typing_change(Tox *tox, void (*function)(Tox *tox, int32_t, int, void *), void *userdata);
340 340
341/* Set the callback for read receipts. 341/* Set the callback for read receipts.
342 * function(int32_t friendnumber, uint32_t receipt) 342 * function(Tox *tox, int32_t friendnumber, uint32_t receipt, void *userdata)
343 * 343 *
344 * If you are keeping a record of returns from m_sendmessage; 344 * If you are keeping a record of returns from m_sendmessage;
345 * receipt might be one of those values, meaning the message 345 * receipt might be one of those values, meaning the message
@@ -350,7 +350,7 @@ void tox_callback_typing_change(Tox *tox, void (*function)(Tox *tox, int32_t, in
350void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int32_t, uint32_t, void *), void *userdata); 350void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int32_t, uint32_t, void *), void *userdata);
351 351
352/* Set the callback for connection status changes. 352/* Set the callback for connection status changes.
353 * function(int32_t friendnumber, uint8_t status) 353 * function(Tox *tox, int32_t friendnumber, uint8_t status, void *userdata)
354 * 354 *
355 * Status: 355 * Status:
356 * 0 -- friend went offline after being previously online 356 * 0 -- friend went offline after being previously online