diff options
-rw-r--r-- | testing/nTox.c | 2 | ||||
-rw-r--r-- | toxcore/Messenger.c | 174 | ||||
-rw-r--r-- | toxcore/Messenger.h | 163 | ||||
-rw-r--r-- | toxcore/tox.c | 115 | ||||
-rw-r--r-- | toxcore/tox.h | 197 |
5 files changed, 334 insertions, 317 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index 8f7dc7ea..343db236 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -1243,7 +1243,7 @@ int main(int argc, char *argv[]) | |||
1243 | 1243 | ||
1244 | new_lines("[i] change username with /n"); | 1244 | new_lines("[i] change username with /n"); |
1245 | uint8_t name[TOX_MAX_NAME_LENGTH + 1]; | 1245 | uint8_t name[TOX_MAX_NAME_LENGTH + 1]; |
1246 | uint16_t namelen = tox_get_self_name(m, name, sizeof(name)); | 1246 | uint16_t namelen = tox_get_self_name(m, name); |
1247 | name[namelen] = 0; | 1247 | name[namelen] = 0; |
1248 | 1248 | ||
1249 | if (namelen > 0) { | 1249 | if (namelen > 0) { |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 69bc845a..9f75f89f 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -34,16 +34,16 @@ | |||
34 | #define MIN(a,b) (((a)<(b))?(a):(b)) | 34 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
35 | 35 | ||
36 | 36 | ||
37 | static void set_friend_status(Messenger *m, int friendnumber, uint8_t status); | 37 | static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status); |
38 | static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length); | 38 | static int write_cryptpacket_id(Messenger *m, int32_t friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length); |
39 | 39 | ||
40 | // friend_not_valid determines if the friendnumber passed is valid in the Messenger object | 40 | // friend_not_valid determines if the friendnumber passed is valid in the Messenger object |
41 | static uint8_t friend_not_valid(Messenger *m, int friendnumber) | 41 | static uint8_t friend_not_valid(Messenger *m, int32_t friendnumber) |
42 | { | 42 | { |
43 | return (unsigned int)friendnumber >= m->numfriends; | 43 | return (unsigned int)friendnumber >= m->numfriends; |
44 | } | 44 | } |
45 | 45 | ||
46 | static int add_online_friend(Messenger *m, int friendnumber) | 46 | static int add_online_friend(Messenger *m, int32_t friendnumber) |
47 | { | 47 | { |
48 | if (friend_not_valid(m, friendnumber)) | 48 | if (friend_not_valid(m, friendnumber)) |
49 | return -1; | 49 | return -1; |
@@ -74,7 +74,7 @@ static int add_online_friend(Messenger *m, int friendnumber) | |||
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
77 | static int remove_online_friend(Messenger *m, int friendnumber) | 77 | static int remove_online_friend(Messenger *m, int32_t friendnumber) |
78 | { | 78 | { |
79 | uint32_t i; | 79 | uint32_t i; |
80 | Online_Friend *temp; | 80 | Online_Friend *temp; |
@@ -132,7 +132,7 @@ int realloc_friendlist(Messenger *m, uint32_t num) | |||
132 | /* return the friend id associated to that public key. | 132 | /* return the friend id associated to that public key. |
133 | * return -1 if no such friend. | 133 | * return -1 if no such friend. |
134 | */ | 134 | */ |
135 | int getfriend_id(Messenger *m, uint8_t *client_id) | 135 | int32_t getfriend_id(Messenger *m, uint8_t *client_id) |
136 | { | 136 | { |
137 | uint32_t i; | 137 | uint32_t i; |
138 | 138 | ||
@@ -151,13 +151,13 @@ int getfriend_id(Messenger *m, uint8_t *client_id) | |||
151 | * return 0 if success. | 151 | * return 0 if success. |
152 | * return -1 if failure. | 152 | * return -1 if failure. |
153 | */ | 153 | */ |
154 | int getclient_id(Messenger *m, int friend_id, uint8_t *client_id) | 154 | int getclient_id(Messenger *m, int32_t friendnumber, uint8_t *client_id) |
155 | { | 155 | { |
156 | if (friend_not_valid(m, friend_id)) | 156 | if (friend_not_valid(m, friendnumber)) |
157 | return -1; | 157 | return -1; |
158 | 158 | ||
159 | if (m->friendlist[friend_id].status > 0) { | 159 | if (m->friendlist[friendnumber].status > 0) { |
160 | memcpy(client_id, m->friendlist[friend_id].client_id, CLIENT_ID_SIZE); | 160 | memcpy(client_id, m->friendlist[friendnumber].client_id, CLIENT_ID_SIZE); |
161 | return 0; | 161 | return 0; |
162 | } | 162 | } |
163 | 163 | ||
@@ -210,7 +210,7 @@ void getaddress(Messenger *m, uint8_t *address) | |||
210 | * (the nospam for that friend was set to the new one). | 210 | * (the nospam for that friend was set to the new one). |
211 | * return FAERR_NOMEM if increasing the friend list size fails. | 211 | * return FAERR_NOMEM if increasing the friend list size fails. |
212 | */ | 212 | */ |
213 | int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length) | 213 | int32_t m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length) |
214 | { | 214 | { |
215 | if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES | 215 | if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES |
216 | - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES | 216 | - crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES |
@@ -231,7 +231,7 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length) | |||
231 | if (id_equal(client_id, m->net_crypto->self_public_key)) | 231 | if (id_equal(client_id, m->net_crypto->self_public_key)) |
232 | return FAERR_OWNKEY; | 232 | return FAERR_OWNKEY; |
233 | 233 | ||
234 | int friend_id = getfriend_id(m, client_id); | 234 | int32_t friend_id = getfriend_id(m, client_id); |
235 | 235 | ||
236 | if (friend_id != -1) { | 236 | if (friend_id != -1) { |
237 | uint32_t nospam; | 237 | uint32_t nospam; |
@@ -250,7 +250,7 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length) | |||
250 | 250 | ||
251 | memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); | 251 | memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); |
252 | 252 | ||
253 | int onion_friendnum = onion_addfriend(m->onion_c, client_id); | 253 | int32_t onion_friendnum = onion_addfriend(m->onion_c, client_id); |
254 | 254 | ||
255 | if (onion_friendnum == -1) | 255 | if (onion_friendnum == -1) |
256 | return FAERR_UNKNOWN; | 256 | return FAERR_UNKNOWN; |
@@ -285,7 +285,7 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length) | |||
285 | return FAERR_UNKNOWN; | 285 | return FAERR_UNKNOWN; |
286 | } | 286 | } |
287 | 287 | ||
288 | int m_addfriend_norequest(Messenger *m, uint8_t *client_id) | 288 | int32_t m_addfriend_norequest(Messenger *m, uint8_t *client_id) |
289 | { | 289 | { |
290 | if (getfriend_id(m, client_id) != -1) | 290 | if (getfriend_id(m, client_id) != -1) |
291 | return -1; | 291 | return -1; |
@@ -299,7 +299,7 @@ int m_addfriend_norequest(Messenger *m, uint8_t *client_id) | |||
299 | 299 | ||
300 | memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); | 300 | memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend)); |
301 | 301 | ||
302 | int onion_friendnum = onion_addfriend(m->onion_c, client_id); | 302 | int32_t onion_friendnum = onion_addfriend(m->onion_c, client_id); |
303 | 303 | ||
304 | if (onion_friendnum == -1) | 304 | if (onion_friendnum == -1) |
305 | return FAERR_UNKNOWN; | 305 | return FAERR_UNKNOWN; |
@@ -335,7 +335,7 @@ int m_addfriend_norequest(Messenger *m, uint8_t *client_id) | |||
335 | * return 0 if success. | 335 | * return 0 if success. |
336 | * return -1 if failure. | 336 | * return -1 if failure. |
337 | */ | 337 | */ |
338 | int m_delfriend(Messenger *m, int friendnumber) | 338 | int m_delfriend(Messenger *m, int32_t friendnumber) |
339 | { | 339 | { |
340 | if (friend_not_valid(m, friendnumber)) | 340 | if (friend_not_valid(m, friendnumber)) |
341 | return -1; | 341 | return -1; |
@@ -362,7 +362,7 @@ int m_delfriend(Messenger *m, int friendnumber) | |||
362 | return 0; | 362 | return 0; |
363 | } | 363 | } |
364 | 364 | ||
365 | int m_get_friend_connectionstatus(Messenger *m, int friendnumber) | 365 | int m_get_friend_connectionstatus(Messenger *m, int32_t friendnumber) |
366 | { | 366 | { |
367 | if (friend_not_valid(m, friendnumber)) | 367 | if (friend_not_valid(m, friendnumber)) |
368 | return -1; | 368 | return -1; |
@@ -370,7 +370,7 @@ int m_get_friend_connectionstatus(Messenger *m, int friendnumber) | |||
370 | return m->friendlist[friendnumber].status == FRIEND_ONLINE; | 370 | return m->friendlist[friendnumber].status == FRIEND_ONLINE; |
371 | } | 371 | } |
372 | 372 | ||
373 | int m_friend_exists(Messenger *m, int friendnumber) | 373 | int m_friend_exists(Messenger *m, int32_t friendnumber) |
374 | { | 374 | { |
375 | if (friend_not_valid(m, friendnumber)) | 375 | if (friend_not_valid(m, friendnumber)) |
376 | return 0; | 376 | return 0; |
@@ -383,7 +383,7 @@ int m_friend_exists(Messenger *m, int friendnumber) | |||
383 | * return the message id if packet was successfully put into the send queue. | 383 | * return the message id if packet was successfully put into the send queue. |
384 | * return 0 if it was not. | 384 | * return 0 if it was not. |
385 | */ | 385 | */ |
386 | uint32_t m_sendmessage(Messenger *m, int friendnumber, uint8_t *message, uint32_t length) | 386 | uint32_t m_sendmessage(Messenger *m, int32_t friendnumber, uint8_t *message, uint32_t length) |
387 | { | 387 | { |
388 | if (friend_not_valid(m, friendnumber)) | 388 | if (friend_not_valid(m, friendnumber)) |
389 | return 0; | 389 | return 0; |
@@ -400,7 +400,7 @@ uint32_t m_sendmessage(Messenger *m, int friendnumber, uint8_t *message, uint32_ | |||
400 | return 0; | 400 | return 0; |
401 | } | 401 | } |
402 | 402 | ||
403 | uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length) | 403 | uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length) |
404 | { | 404 | { |
405 | if (length >= (MAX_DATA_SIZE - sizeof(theid))) | 405 | if (length >= (MAX_DATA_SIZE - sizeof(theid))) |
406 | return 0; | 406 | return 0; |
@@ -417,7 +417,7 @@ uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, ui | |||
417 | * return the message id if packet was successfully put into the send queue. | 417 | * return the message id if packet was successfully put into the send queue. |
418 | * return 0 if it was not. | 418 | * return 0 if it was not. |
419 | */ | 419 | */ |
420 | uint32_t m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length) | 420 | uint32_t m_sendaction(Messenger *m, int32_t friendnumber, uint8_t *action, uint32_t length) |
421 | { | 421 | { |
422 | if (friend_not_valid(m, friendnumber)) | 422 | if (friend_not_valid(m, friendnumber)) |
423 | return 0; | 423 | return 0; |
@@ -434,7 +434,7 @@ uint32_t m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t | |||
434 | return 0; | 434 | return 0; |
435 | } | 435 | } |
436 | 436 | ||
437 | uint32_t m_sendaction_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length) | 437 | uint32_t m_sendaction_withid(Messenger *m, int32_t friendnumber, uint32_t theid, uint8_t *action, uint32_t length) |
438 | { | 438 | { |
439 | if (length >= (MAX_DATA_SIZE - sizeof(theid))) | 439 | if (length >= (MAX_DATA_SIZE - sizeof(theid))) |
440 | return 0; | 440 | return 0; |
@@ -449,7 +449,7 @@ uint32_t m_sendaction_withid(Messenger *m, int friendnumber, uint32_t theid, uin | |||
449 | /* Send a name packet to friendnumber. | 449 | /* Send a name packet to friendnumber. |
450 | * length is the length with the NULL terminator. | 450 | * length is the length with the NULL terminator. |
451 | */ | 451 | */ |
452 | static int m_sendname(Messenger *m, int friendnumber, uint8_t *name, uint16_t length) | 452 | static int m_sendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_t length) |
453 | { | 453 | { |
454 | if (length > MAX_NAME_LENGTH || length == 0) | 454 | if (length > MAX_NAME_LENGTH || length == 0) |
455 | return 0; | 455 | return 0; |
@@ -462,7 +462,7 @@ static int m_sendname(Messenger *m, int friendnumber, uint8_t *name, uint16_t le | |||
462 | * return 0 if success. | 462 | * return 0 if success. |
463 | * return -1 if failure. | 463 | * return -1 if failure. |
464 | */ | 464 | */ |
465 | int setfriendname(Messenger *m, int friendnumber, uint8_t *name, uint16_t length) | 465 | int setfriendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_t length) |
466 | { | 466 | { |
467 | if (friend_not_valid(m, friendnumber)) | 467 | if (friend_not_valid(m, friendnumber)) |
468 | return -1; | 468 | return -1; |
@@ -507,18 +507,15 @@ int setname(Messenger *m, uint8_t *name, uint16_t length) | |||
507 | * | 507 | * |
508 | * return the length of the name. | 508 | * return the length of the name. |
509 | */ | 509 | */ |
510 | uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen) | 510 | uint16_t getself_name(Messenger *m, uint8_t *name) |
511 | { | 511 | { |
512 | uint16_t len; | 512 | if (name == NULL) { |
513 | |||
514 | if (name == NULL || nlen == 0) { | ||
515 | return 0; | 513 | return 0; |
516 | } | 514 | } |
517 | 515 | ||
518 | len = MIN(nlen, m->name_length); | 516 | memcpy(name, m->name, m->name_length); |
519 | memcpy(name, m->name, len); | ||
520 | 517 | ||
521 | return len; | 518 | return m->name_length; |
522 | } | 519 | } |
523 | 520 | ||
524 | /* Get name of friendnumber and put it in name. | 521 | /* Get name of friendnumber and put it in name. |
@@ -527,7 +524,7 @@ uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen) | |||
527 | * return length of name if success. | 524 | * return length of name if success. |
528 | * return -1 if failure. | 525 | * return -1 if failure. |
529 | */ | 526 | */ |
530 | int getname(Messenger *m, int friendnumber, uint8_t *name) | 527 | int getname(Messenger *m, int32_t friendnumber, uint8_t *name) |
531 | { | 528 | { |
532 | if (friend_not_valid(m, friendnumber)) | 529 | if (friend_not_valid(m, friendnumber)) |
533 | return -1; | 530 | return -1; |
@@ -570,7 +567,7 @@ int m_set_userstatus(Messenger *m, USERSTATUS status) | |||
570 | /* return the size of friendnumber's user status. | 567 | /* return the size of friendnumber's user status. |
571 | * Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH. | 568 | * Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH. |
572 | */ | 569 | */ |
573 | int m_get_statusmessage_size(Messenger *m, int friendnumber) | 570 | int m_get_statusmessage_size(Messenger *m, int32_t friendnumber) |
574 | { | 571 | { |
575 | if (friend_not_valid(m, friendnumber)) | 572 | if (friend_not_valid(m, friendnumber)) |
576 | return -1; | 573 | return -1; |
@@ -581,7 +578,7 @@ int m_get_statusmessage_size(Messenger *m, int friendnumber) | |||
581 | /* Copy the user status of friendnumber into buf, truncating if needed to maxlen | 578 | /* Copy the user status of friendnumber into buf, truncating if needed to maxlen |
582 | * bytes, use m_get_statusmessage_size to find out how much you need to allocate. | 579 | * bytes, use m_get_statusmessage_size to find out how much you need to allocate. |
583 | */ | 580 | */ |
584 | int m_copy_statusmessage(Messenger *m, int friendnumber, uint8_t *buf, uint32_t maxlen) | 581 | int m_copy_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen) |
585 | { | 582 | { |
586 | if (friend_not_valid(m, friendnumber)) | 583 | if (friend_not_valid(m, friendnumber)) |
587 | return -1; | 584 | return -1; |
@@ -598,7 +595,7 @@ int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen) | |||
598 | return MIN(maxlen, m->statusmessage_length); | 595 | return MIN(maxlen, m->statusmessage_length); |
599 | } | 596 | } |
600 | 597 | ||
601 | USERSTATUS m_get_userstatus(Messenger *m, int friendnumber) | 598 | USERSTATUS m_get_userstatus(Messenger *m, int32_t friendnumber) |
602 | { | 599 | { |
603 | if (friend_not_valid(m, friendnumber)) | 600 | if (friend_not_valid(m, friendnumber)) |
604 | return USERSTATUS_INVALID; | 601 | return USERSTATUS_INVALID; |
@@ -617,7 +614,7 @@ USERSTATUS m_get_self_userstatus(Messenger *m) | |||
617 | return m->userstatus; | 614 | return m->userstatus; |
618 | } | 615 | } |
619 | 616 | ||
620 | int m_set_usertyping(Messenger *m, int friendnumber, uint8_t is_typing) | 617 | int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing) |
621 | { | 618 | { |
622 | if (is_typing != 0 && is_typing != 1) { | 619 | if (is_typing != 0 && is_typing != 1) { |
623 | return -1; | 620 | return -1; |
@@ -632,7 +629,7 @@ int m_set_usertyping(Messenger *m, int friendnumber, uint8_t is_typing) | |||
632 | return 0; | 629 | return 0; |
633 | } | 630 | } |
634 | 631 | ||
635 | int m_get_istyping(Messenger *m, int friendnumber) | 632 | int m_get_istyping(Messenger *m, int32_t friendnumber) |
636 | { | 633 | { |
637 | if (friend_not_valid(m, friendnumber)) | 634 | if (friend_not_valid(m, friendnumber)) |
638 | return -1; | 635 | return -1; |
@@ -640,24 +637,24 @@ int m_get_istyping(Messenger *m, int friendnumber) | |||
640 | return m->friendlist[friendnumber].is_typing; | 637 | return m->friendlist[friendnumber].is_typing; |
641 | } | 638 | } |
642 | 639 | ||
643 | static int send_statusmessage(Messenger *m, int friendnumber, uint8_t *status, uint16_t length) | 640 | static int send_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *status, uint16_t length) |
644 | { | 641 | { |
645 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length); | 642 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length); |
646 | } | 643 | } |
647 | 644 | ||
648 | static int send_userstatus(Messenger *m, int friendnumber, USERSTATUS status) | 645 | static int send_userstatus(Messenger *m, int32_t friendnumber, USERSTATUS status) |
649 | { | 646 | { |
650 | uint8_t stat = status; | 647 | uint8_t stat = status; |
651 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &stat, sizeof(stat)); | 648 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &stat, sizeof(stat)); |
652 | } | 649 | } |
653 | 650 | ||
654 | static int send_user_istyping(Messenger *m, int friendnumber, uint8_t is_typing) | 651 | static int send_user_istyping(Messenger *m, int32_t friendnumber, uint8_t is_typing) |
655 | { | 652 | { |
656 | uint8_t typing = is_typing; | 653 | uint8_t typing = is_typing; |
657 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing)); | 654 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing)); |
658 | } | 655 | } |
659 | 656 | ||
660 | static int send_ping(Messenger *m, int friendnumber) | 657 | static int send_ping(Messenger *m, int32_t friendnumber) |
661 | { | 658 | { |
662 | int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_PING, 0, 0); | 659 | int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_PING, 0, 0); |
663 | 660 | ||
@@ -667,7 +664,7 @@ static int send_ping(Messenger *m, int friendnumber) | |||
667 | return ret; | 664 | return ret; |
668 | } | 665 | } |
669 | 666 | ||
670 | static int set_friend_statusmessage(Messenger *m, int friendnumber, uint8_t *status, uint16_t length) | 667 | static int set_friend_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *status, uint16_t length) |
671 | { | 668 | { |
672 | if (friend_not_valid(m, friendnumber)) | 669 | if (friend_not_valid(m, friendnumber)) |
673 | return -1; | 670 | return -1; |
@@ -680,18 +677,18 @@ static int set_friend_statusmessage(Messenger *m, int friendnumber, uint8_t *sta | |||
680 | return 0; | 677 | return 0; |
681 | } | 678 | } |
682 | 679 | ||
683 | static void set_friend_userstatus(Messenger *m, int friendnumber, USERSTATUS status) | 680 | static void set_friend_userstatus(Messenger *m, int32_t friendnumber, USERSTATUS status) |
684 | { | 681 | { |
685 | m->friendlist[friendnumber].userstatus = status; | 682 | m->friendlist[friendnumber].userstatus = status; |
686 | } | 683 | } |
687 | 684 | ||
688 | static void set_friend_typing(Messenger *m, int friendnumber, uint8_t is_typing) | 685 | static void set_friend_typing(Messenger *m, int32_t friendnumber, uint8_t is_typing) |
689 | { | 686 | { |
690 | m->friendlist[friendnumber].is_typing = is_typing; | 687 | m->friendlist[friendnumber].is_typing = is_typing; |
691 | } | 688 | } |
692 | 689 | ||
693 | /* Sets whether we send read receipts for friendnumber. */ | 690 | /* Sets whether we send read receipts for friendnumber. */ |
694 | void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno) | 691 | void m_set_sends_receipts(Messenger *m, int32_t friendnumber, int yesno) |
695 | { | 692 | { |
696 | if (yesno != 0 && yesno != 1) | 693 | if (yesno != 0 && yesno != 1) |
697 | return; | 694 | return; |
@@ -710,66 +707,67 @@ void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t | |||
710 | } | 707 | } |
711 | 708 | ||
712 | /* Set the function that will be executed when a message from a friend is received. */ | 709 | /* Set the function that will be executed when a message from a friend is received. */ |
713 | void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | 710 | void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *), |
714 | void *userdata) | 711 | void *userdata) |
715 | { | 712 | { |
716 | m->friend_message = function; | 713 | m->friend_message = function; |
717 | m->friend_message_userdata = userdata; | 714 | m->friend_message_userdata = userdata; |
718 | } | 715 | } |
719 | 716 | ||
720 | void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), void *userdata) | 717 | void m_callback_action(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *), |
718 | void *userdata) | ||
721 | { | 719 | { |
722 | m->friend_action = function; | 720 | m->friend_action = function; |
723 | m->friend_action_userdata = userdata; | 721 | m->friend_action_userdata = userdata; |
724 | } | 722 | } |
725 | 723 | ||
726 | void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | 724 | void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *), |
727 | void *userdata) | 725 | void *userdata) |
728 | { | 726 | { |
729 | m->friend_namechange = function; | 727 | m->friend_namechange = function; |
730 | m->friend_namechange_userdata = userdata; | 728 | m->friend_namechange_userdata = userdata; |
731 | } | 729 | } |
732 | 730 | ||
733 | void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | 731 | void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *), |
734 | void *userdata) | 732 | void *userdata) |
735 | { | 733 | { |
736 | m->friend_statusmessagechange = function; | 734 | m->friend_statusmessagechange = function; |
737 | m->friend_statuschange_userdata = userdata; | 735 | m->friend_statuschange_userdata = userdata; |
738 | } | 736 | } |
739 | 737 | ||
740 | void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS, void *), void *userdata) | 738 | void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int32_t, USERSTATUS, void *), void *userdata) |
741 | { | 739 | { |
742 | m->friend_userstatuschange = function; | 740 | m->friend_userstatuschange = function; |
743 | m->friend_userstatuschange_userdata = userdata; | 741 | m->friend_userstatuschange_userdata = userdata; |
744 | } | 742 | } |
745 | 743 | ||
746 | void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int, int, void *), void *userdata) | 744 | void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int32_t, int, void *), void *userdata) |
747 | { | 745 | { |
748 | m->friend_typingchange = function; | 746 | m->friend_typingchange = function; |
749 | m->friend_typingchange_userdata = userdata; | 747 | m->friend_typingchange_userdata = userdata; |
750 | } | 748 | } |
751 | 749 | ||
752 | void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t, void *), void *userdata) | 750 | void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int32_t, uint32_t, void *), void *userdata) |
753 | { | 751 | { |
754 | m->read_receipt = function; | 752 | m->read_receipt = function; |
755 | m->read_receipt_userdata = userdata; | 753 | m->read_receipt_userdata = userdata; |
756 | } | 754 | } |
757 | 755 | ||
758 | void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void *), void *userdata) | 756 | void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *), void *userdata) |
759 | { | 757 | { |
760 | m->friend_connectionstatuschange = function; | 758 | m->friend_connectionstatuschange = function; |
761 | m->friend_connectionstatuschange_userdata = userdata; | 759 | m->friend_connectionstatuschange_userdata = userdata; |
762 | } | 760 | } |
763 | 761 | ||
764 | void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void *), | 762 | void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *), |
765 | void *userdata) | 763 | void *userdata) |
766 | { | 764 | { |
767 | m->friend_connectionstatuschange_internal = function; | 765 | m->friend_connectionstatuschange_internal = function; |
768 | m->friend_connectionstatuschange_internal_userdata = userdata; | 766 | m->friend_connectionstatuschange_internal_userdata = userdata; |
769 | } | 767 | } |
770 | 768 | ||
771 | static void break_files(Messenger *m, int friendnumber); | 769 | static void break_files(Messenger *m, int32_t friendnumber); |
772 | static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_t status) | 770 | static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, uint8_t status) |
773 | { | 771 | { |
774 | if (status == NOFRIEND) | 772 | if (status == NOFRIEND) |
775 | return; | 773 | return; |
@@ -796,13 +794,13 @@ static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_ | |||
796 | } | 794 | } |
797 | } | 795 | } |
798 | 796 | ||
799 | void set_friend_status(Messenger *m, int friendnumber, uint8_t status) | 797 | void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status) |
800 | { | 798 | { |
801 | check_friend_connectionstatus(m, friendnumber, status); | 799 | check_friend_connectionstatus(m, friendnumber, status); |
802 | m->friendlist[friendnumber].status = status; | 800 | m->friendlist[friendnumber].status = status; |
803 | } | 801 | } |
804 | 802 | ||
805 | int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length) | 803 | int write_cryptpacket_id(Messenger *m, int32_t friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length) |
806 | { | 804 | { |
807 | if (friend_not_valid(m, friendnumber)) | 805 | if (friend_not_valid(m, friendnumber)) |
808 | return 0; | 806 | return 0; |
@@ -842,7 +840,7 @@ static uint8_t groupnumber_not_valid(Messenger *m, int groupnumber) | |||
842 | /* returns valid ip port of connected friend on success | 840 | /* returns valid ip port of connected friend on success |
843 | * returns zeroed out IP_Port on failure | 841 | * returns zeroed out IP_Port on failure |
844 | */ | 842 | */ |
845 | IP_Port get_friend_ipport(Messenger *m, int friendnumber) | 843 | IP_Port get_friend_ipport(Messenger *m, int32_t friendnumber) |
846 | { | 844 | { |
847 | IP_Port zero; | 845 | IP_Port zero; |
848 | memset(&zero, 0, sizeof(zero)); | 846 | memset(&zero, 0, sizeof(zero)); |
@@ -876,9 +874,9 @@ static int group_num(Messenger *m, uint8_t *group_public_key) | |||
876 | 874 | ||
877 | /* Set the callback for group invites. | 875 | /* Set the callback for group invites. |
878 | * | 876 | * |
879 | * Function(Messenger *m, int friendnumber, uint8_t *group_public_key, void *userdata) | 877 | * Function(Messenger *m, int32_t friendnumber, uint8_t *group_public_key, void *userdata) |
880 | */ | 878 | */ |
881 | void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, void *), void *userdata) | 879 | void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, void *), void *userdata) |
882 | { | 880 | { |
883 | m->group_invite = function; | 881 | m->group_invite = function; |
884 | m->group_invite_userdata = userdata; | 882 | m->group_invite_userdata = userdata; |
@@ -1081,7 +1079,7 @@ int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *nam | |||
1081 | 1079 | ||
1082 | /* Store the fact that we invited a specific friend. | 1080 | /* Store the fact that we invited a specific friend. |
1083 | */ | 1081 | */ |
1084 | static void group_store_friendinvite(Messenger *m, int friendnumber, int groupnumber) | 1082 | static void group_store_friendinvite(Messenger *m, int32_t friendnumber, int groupnumber) |
1085 | { | 1083 | { |
1086 | /* Add 1 to the groupchat number because 0 (default value in invited_groups) is a valid groupchat number */ | 1084 | /* Add 1 to the groupchat number because 0 (default value in invited_groups) is a valid groupchat number */ |
1087 | m->friendlist[friendnumber].invited_groups[m->friendlist[friendnumber].invited_groups_num % MAX_INVITED_GROUPS] = | 1085 | m->friendlist[friendnumber].invited_groups[m->friendlist[friendnumber].invited_groups_num % MAX_INVITED_GROUPS] = |
@@ -1092,7 +1090,7 @@ static void group_store_friendinvite(Messenger *m, int friendnumber, int groupnu | |||
1092 | /* return 1 if that friend was invited to the group | 1090 | /* return 1 if that friend was invited to the group |
1093 | * return 0 if the friend was not or error. | 1091 | * return 0 if the friend was not or error. |
1094 | */ | 1092 | */ |
1095 | static uint8_t group_invited(Messenger *m, int friendnumber, int groupnumber) | 1093 | static uint8_t group_invited(Messenger *m, int32_t friendnumber, int groupnumber) |
1096 | { | 1094 | { |
1097 | 1095 | ||
1098 | uint32_t i; | 1096 | uint32_t i; |
@@ -1114,7 +1112,7 @@ static uint8_t group_invited(Messenger *m, int friendnumber, int groupnumber) | |||
1114 | * return 0 on success | 1112 | * return 0 on success |
1115 | * return -1 on failure | 1113 | * return -1 on failure |
1116 | */ | 1114 | */ |
1117 | int invite_friend(Messenger *m, int friendnumber, int groupnumber) | 1115 | int invite_friend(Messenger *m, int32_t friendnumber, int groupnumber) |
1118 | { | 1116 | { |
1119 | if (friend_not_valid(m, friendnumber) || (unsigned int)groupnumber >= m->numchats) | 1117 | if (friend_not_valid(m, friendnumber) || (unsigned int)groupnumber >= m->numchats) |
1120 | return -1; | 1118 | return -1; |
@@ -1140,7 +1138,7 @@ int invite_friend(Messenger *m, int friendnumber, int groupnumber) | |||
1140 | * returns group number on success | 1138 | * returns group number on success |
1141 | * returns -1 on failure. | 1139 | * returns -1 on failure. |
1142 | */ | 1140 | */ |
1143 | int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_key) | 1141 | int join_groupchat(Messenger *m, int32_t friendnumber, uint8_t *friend_group_public_key) |
1144 | { | 1142 | { |
1145 | if (friend_not_valid(m, friendnumber)) | 1143 | if (friend_not_valid(m, friendnumber)) |
1146 | return -1; | 1144 | return -1; |
@@ -1257,9 +1255,10 @@ static void do_allgroupchats(Messenger *m) | |||
1257 | 1255 | ||
1258 | /* Set the callback for file send requests. | 1256 | /* Set the callback for file send requests. |
1259 | * | 1257 | * |
1260 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) | 1258 | * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) |
1261 | */ | 1259 | */ |
1262 | void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint64_t, uint8_t *, uint16_t, | 1260 | void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint64_t, uint8_t *, |
1261 | uint16_t, | ||
1263 | void *), void *userdata) | 1262 | void *), void *userdata) |
1264 | { | 1263 | { |
1265 | m->file_sendrequest = function; | 1264 | m->file_sendrequest = function; |
@@ -1268,10 +1267,10 @@ void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int, | |||
1268 | 1267 | ||
1269 | /* Set the callback for file control requests. | 1268 | /* Set the callback for file control requests. |
1270 | * | 1269 | * |
1271 | * Function(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata) | 1270 | * 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) |
1272 | * | 1271 | * |
1273 | */ | 1272 | */ |
1274 | void callback_file_control(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint8_t, uint8_t, uint8_t *, | 1273 | void callback_file_control(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *, |
1275 | uint16_t, | 1274 | uint16_t, |
1276 | void *), void *userdata) | 1275 | void *), void *userdata) |
1277 | { | 1276 | { |
@@ -1281,10 +1280,11 @@ void callback_file_control(Messenger *m, void (*function)(Messenger *m, int, uin | |||
1281 | 1280 | ||
1282 | /* Set the callback for file data. | 1281 | /* Set the callback for file data. |
1283 | * | 1282 | * |
1284 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) | 1283 | * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) |
1285 | * | 1284 | * |
1286 | */ | 1285 | */ |
1287 | void callback_file_data(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint8_t *, uint16_t length, void *), | 1286 | void callback_file_data(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint8_t *, uint16_t length, |
1287 | void *), | ||
1288 | void *userdata) | 1288 | void *userdata) |
1289 | { | 1289 | { |
1290 | m->file_filedata = function; | 1290 | m->file_filedata = function; |
@@ -1298,7 +1298,7 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, int, uint8_ | |||
1298 | * return 1 on success | 1298 | * return 1 on success |
1299 | * return 0 on failure | 1299 | * return 0 on failure |
1300 | */ | 1300 | */ |
1301 | int file_sendrequest(Messenger *m, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, | 1301 | int file_sendrequest(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, |
1302 | uint16_t filename_length) | 1302 | uint16_t filename_length) |
1303 | { | 1303 | { |
1304 | if (friend_not_valid(m, friendnumber)) | 1304 | if (friend_not_valid(m, friendnumber)) |
@@ -1321,7 +1321,7 @@ int file_sendrequest(Messenger *m, int friendnumber, uint8_t filenumber, uint64_ | |||
1321 | * return file number on success | 1321 | * return file number on success |
1322 | * return -1 on failure | 1322 | * return -1 on failure |
1323 | */ | 1323 | */ |
1324 | int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length) | 1324 | int new_filesender(Messenger *m, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length) |
1325 | { | 1325 | { |
1326 | if (friend_not_valid(m, friendnumber)) | 1326 | if (friend_not_valid(m, friendnumber)) |
1327 | return -1; | 1327 | return -1; |
@@ -1351,7 +1351,7 @@ int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *f | |||
1351 | * return 0 on success | 1351 | * return 0 on success |
1352 | * return -1 on failure | 1352 | * return -1 on failure |
1353 | */ | 1353 | */ |
1354 | int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, | 1354 | int file_control(Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, |
1355 | uint8_t *data, uint16_t length) | 1355 | uint8_t *data, uint16_t length) |
1356 | { | 1356 | { |
1357 | if (length > MAX_DATA_SIZE - 3) | 1357 | if (length > MAX_DATA_SIZE - 3) |
@@ -1439,7 +1439,7 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f | |||
1439 | * return 0 on success | 1439 | * return 0 on success |
1440 | * return -1 on failure | 1440 | * return -1 on failure |
1441 | */ | 1441 | */ |
1442 | int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) | 1442 | int file_data(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) |
1443 | { | 1443 | { |
1444 | if (length > MAX_DATA_SIZE - 1) | 1444 | if (length > MAX_DATA_SIZE - 1) |
1445 | return -1; | 1445 | return -1; |
@@ -1474,7 +1474,7 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, | |||
1474 | * return number of bytes remaining to be sent/received on success | 1474 | * return number of bytes remaining to be sent/received on success |
1475 | * return 0 on failure | 1475 | * return 0 on failure |
1476 | */ | 1476 | */ |
1477 | uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive) | 1477 | uint64_t file_dataremaining(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive) |
1478 | { | 1478 | { |
1479 | if (friend_not_valid(m, friendnumber)) | 1479 | if (friend_not_valid(m, friendnumber)) |
1480 | return 0; | 1480 | return 0; |
@@ -1497,7 +1497,7 @@ uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, | |||
1497 | /* Run this when the friend disconnects. | 1497 | /* Run this when the friend disconnects. |
1498 | * Sets all current file transfers to broken. | 1498 | * Sets all current file transfers to broken. |
1499 | */ | 1499 | */ |
1500 | static void break_files(Messenger *m, int friendnumber) | 1500 | static void break_files(Messenger *m, int32_t friendnumber) |
1501 | { | 1501 | { |
1502 | uint32_t i; | 1502 | uint32_t i; |
1503 | 1503 | ||
@@ -1510,7 +1510,7 @@ static void break_files(Messenger *m, int friendnumber) | |||
1510 | } | 1510 | } |
1511 | } | 1511 | } |
1512 | 1512 | ||
1513 | static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t receive_send, uint8_t filenumber, | 1513 | static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, |
1514 | uint8_t message_id, uint8_t *data, | 1514 | uint8_t message_id, uint8_t *data, |
1515 | uint16_t length) | 1515 | uint16_t length) |
1516 | { | 1516 | { |
@@ -1600,7 +1600,7 @@ static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t receive_se | |||
1600 | * | 1600 | * |
1601 | * Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata) | 1601 | * Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata) |
1602 | */ | 1602 | */ |
1603 | void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | 1603 | void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *), |
1604 | void *userdata) | 1604 | void *userdata) |
1605 | { | 1605 | { |
1606 | m->msi_packet = function; | 1606 | m->msi_packet = function; |
@@ -1612,12 +1612,12 @@ void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uin | |||
1612 | * return 1 on success | 1612 | * return 1 on success |
1613 | * return 0 on failure | 1613 | * return 0 on failure |
1614 | */ | 1614 | */ |
1615 | int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length) | 1615 | int m_msi_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length) |
1616 | { | 1616 | { |
1617 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length); | 1617 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length); |
1618 | } | 1618 | } |
1619 | 1619 | ||
1620 | static int friendnum_from_ip_port(Messenger *m, IP_Port ip_port) | 1620 | static int32_t friendnum_from_ip_port(Messenger *m, IP_Port ip_port) |
1621 | { | 1621 | { |
1622 | uint32_t i; | 1622 | uint32_t i; |
1623 | 1623 | ||
@@ -1632,7 +1632,7 @@ static int friendnum_from_ip_port(Messenger *m, IP_Port ip_port) | |||
1632 | static int handle_custom_user_packet(void *object, IP_Port source, uint8_t *packet, uint32_t length) | 1632 | static int handle_custom_user_packet(void *object, IP_Port source, uint8_t *packet, uint32_t length) |
1633 | { | 1633 | { |
1634 | Messenger *m = object; | 1634 | Messenger *m = object; |
1635 | int friend_num = friendnum_from_ip_port(m, source); | 1635 | int32_t friend_num = friendnum_from_ip_port(m, source); |
1636 | 1636 | ||
1637 | if (friend_num == -1) | 1637 | if (friend_num == -1) |
1638 | return 1; | 1638 | return 1; |
@@ -1645,7 +1645,7 @@ static int handle_custom_user_packet(void *object, IP_Port source, uint8_t *pack | |||
1645 | } | 1645 | } |
1646 | 1646 | ||
1647 | 1647 | ||
1648 | int custom_user_packet_registerhandler(Messenger *m, int friendnumber, uint8_t byte, packet_handler_callback cb, | 1648 | int custom_user_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, packet_handler_callback cb, |
1649 | void *object) | 1649 | void *object) |
1650 | { | 1650 | { |
1651 | if (friend_not_valid(m, friendnumber)) | 1651 | if (friend_not_valid(m, friendnumber)) |
@@ -1660,7 +1660,7 @@ int custom_user_packet_registerhandler(Messenger *m, int friendnumber, uint8_t b | |||
1660 | return 0; | 1660 | return 0; |
1661 | } | 1661 | } |
1662 | 1662 | ||
1663 | int send_custom_user_packet(Messenger *m, int friendnumber, uint8_t *data, uint32_t length) | 1663 | int send_custom_user_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint32_t length) |
1664 | { | 1664 | { |
1665 | IP_Port ip_port = get_friend_ipport(m, friendnumber); | 1665 | IP_Port ip_port = get_friend_ipport(m, friendnumber); |
1666 | 1666 | ||
@@ -2573,7 +2573,7 @@ uint32_t get_num_online_friends(Messenger *m) | |||
2573 | * Otherwise, returns the number of elements copied. | 2573 | * Otherwise, returns the number of elements copied. |
2574 | * If the array was too small, the contents | 2574 | * If the array was too small, the contents |
2575 | * of out_list will be truncated to list_size. */ | 2575 | * of out_list will be truncated to list_size. */ |
2576 | uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size) | 2576 | uint32_t copy_friendlist(Messenger *m, int32_t *out_list, uint32_t list_size) |
2577 | { | 2577 | { |
2578 | if (!out_list) | 2578 | if (!out_list) |
2579 | return 0; | 2579 | return 0; |
@@ -2605,7 +2605,7 @@ uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size) | |||
2605 | * retun 0 if success. | 2605 | * retun 0 if success. |
2606 | * return -1 if failure. | 2606 | * return -1 if failure. |
2607 | */ | 2607 | */ |
2608 | int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length) | 2608 | int get_friendlist(Messenger *m, int32_t **out_list, uint32_t *out_list_length) |
2609 | { | 2609 | { |
2610 | uint32_t i; | 2610 | uint32_t i; |
2611 | 2611 | ||
@@ -2616,7 +2616,7 @@ int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length) | |||
2616 | return 0; | 2616 | return 0; |
2617 | } | 2617 | } |
2618 | 2618 | ||
2619 | *out_list = malloc(m->numfriends * sizeof(int)); | 2619 | *out_list = malloc(m->numfriends * sizeof(int32_t)); |
2620 | 2620 | ||
2621 | if (*out_list == NULL) { | 2621 | if (*out_list == NULL) { |
2622 | return -1; | 2622 | return -1; |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index e6851800..8474bbe7 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -198,28 +198,28 @@ typedef struct Messenger { | |||
198 | 198 | ||
199 | uint64_t last_LANdiscovery; | 199 | uint64_t last_LANdiscovery; |
200 | 200 | ||
201 | void (*friend_message)(struct Messenger *m, int, uint8_t *, uint16_t, void *); | 201 | void (*friend_message)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *); |
202 | void *friend_message_userdata; | 202 | void *friend_message_userdata; |
203 | void (*friend_action)(struct Messenger *m, int, uint8_t *, uint16_t, void *); | 203 | void (*friend_action)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *); |
204 | void *friend_action_userdata; | 204 | void *friend_action_userdata; |
205 | void (*friend_namechange)(struct Messenger *m, int, uint8_t *, uint16_t, void *); | 205 | void (*friend_namechange)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *); |
206 | void *friend_namechange_userdata; | 206 | void *friend_namechange_userdata; |
207 | void (*friend_statusmessagechange)(struct Messenger *m, int, 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, int, USERSTATUS, void *); | 209 | void (*friend_userstatuschange)(struct Messenger *m, int32_t, USERSTATUS, void *); |
210 | void *friend_userstatuschange_userdata; | 210 | void *friend_userstatuschange_userdata; |
211 | void (*friend_typingchange)(struct Messenger *m, int, int, void *); | 211 | void (*friend_typingchange)(struct Messenger *m, int32_t, int, void *); |
212 | void *friend_typingchange_userdata; | 212 | void *friend_typingchange_userdata; |
213 | void (*read_receipt)(struct Messenger *m, int, uint32_t, void *); | 213 | void (*read_receipt)(struct Messenger *m, int32_t, uint32_t, void *); |
214 | void *read_receipt_userdata; | 214 | void *read_receipt_userdata; |
215 | void (*friend_statuschange)(struct Messenger *m, int, uint8_t, void *); | 215 | void (*friend_statuschange)(struct Messenger *m, int32_t, uint8_t, void *); |
216 | void *friend_statuschange_userdata; | 216 | void *friend_statuschange_userdata; |
217 | void (*friend_connectionstatuschange)(struct Messenger *m, int, uint8_t, void *); | 217 | void (*friend_connectionstatuschange)(struct Messenger *m, int32_t, uint8_t, void *); |
218 | void *friend_connectionstatuschange_userdata; | 218 | void *friend_connectionstatuschange_userdata; |
219 | void (*friend_connectionstatuschange_internal)(struct Messenger *m, int, uint8_t, void *); | 219 | void (*friend_connectionstatuschange_internal)(struct Messenger *m, int32_t, uint8_t, void *); |
220 | void *friend_connectionstatuschange_internal_userdata; | 220 | void *friend_connectionstatuschange_internal_userdata; |
221 | 221 | ||
222 | void (*group_invite)(struct Messenger *m, int, uint8_t *, void *); | 222 | void (*group_invite)(struct Messenger *m, int32_t, uint8_t *, void *); |
223 | void *group_invite_userdata; | 223 | void *group_invite_userdata; |
224 | void (*group_message)(struct Messenger *m, int, int, uint8_t *, uint16_t, void *); | 224 | void (*group_message)(struct Messenger *m, int, int, uint8_t *, uint16_t, void *); |
225 | void *group_message_userdata; | 225 | void *group_message_userdata; |
@@ -228,14 +228,14 @@ typedef struct Messenger { | |||
228 | void (*group_namelistchange)(struct Messenger *m, int, int, uint8_t, void *); | 228 | void (*group_namelistchange)(struct Messenger *m, int, int, uint8_t, void *); |
229 | void *group_namelistchange_userdata; | 229 | void *group_namelistchange_userdata; |
230 | 230 | ||
231 | void (*file_sendrequest)(struct Messenger *m, int, uint8_t, uint64_t, uint8_t *, uint16_t, void *); | 231 | void (*file_sendrequest)(struct Messenger *m, int32_t, uint8_t, uint64_t, uint8_t *, uint16_t, void *); |
232 | void *file_sendrequest_userdata; | 232 | void *file_sendrequest_userdata; |
233 | void (*file_filecontrol)(struct Messenger *m, int, uint8_t, uint8_t, uint8_t, uint8_t *, uint16_t, void *); | 233 | void (*file_filecontrol)(struct Messenger *m, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *, uint16_t, void *); |
234 | void *file_filecontrol_userdata; | 234 | void *file_filecontrol_userdata; |
235 | void (*file_filedata)(struct Messenger *m, int, uint8_t, uint8_t *, uint16_t length, void *); | 235 | void (*file_filedata)(struct Messenger *m, int32_t, uint8_t, uint8_t *, uint16_t length, void *); |
236 | void *file_filedata_userdata; | 236 | void *file_filedata_userdata; |
237 | 237 | ||
238 | void (*msi_packet)(struct Messenger *m, int, uint8_t *, uint16_t, void *); | 238 | void (*msi_packet)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *); |
239 | void *msi_packet_userdata; | 239 | void *msi_packet_userdata; |
240 | 240 | ||
241 | } Messenger; | 241 | } Messenger; |
@@ -262,19 +262,19 @@ void getaddress(Messenger *m, uint8_t *address); | |||
262 | * (the nospam for that friend was set to the new one). | 262 | * (the nospam for that friend was set to the new one). |
263 | * return -8 if increasing the friend list size fails. | 263 | * return -8 if increasing the friend list size fails. |
264 | */ | 264 | */ |
265 | int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length); | 265 | int32_t m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length); |
266 | 266 | ||
267 | 267 | ||
268 | /* Add a friend without sending a friendrequest. | 268 | /* Add a friend without sending a friendrequest. |
269 | * return the friend number if success. | 269 | * return the friend number if success. |
270 | * return -1 if failure. | 270 | * return -1 if failure. |
271 | */ | 271 | */ |
272 | int m_addfriend_norequest(Messenger *m, uint8_t *client_id); | 272 | int32_t m_addfriend_norequest(Messenger *m, uint8_t *client_id); |
273 | 273 | ||
274 | /* return the friend id associated to that client id. | 274 | /* return the friend number associated to that client id. |
275 | * return -1 if no such friend. | 275 | * return -1 if no such friend. |
276 | */ | 276 | */ |
277 | int getfriend_id(Messenger *m, uint8_t *client_id); | 277 | int32_t getfriend_id(Messenger *m, uint8_t *client_id); |
278 | 278 | ||
279 | /* Copies the public key associated to that friend id into client_id buffer. | 279 | /* Copies the public key associated to that friend id into client_id buffer. |
280 | * Make sure that client_id is of size CLIENT_ID_SIZE. | 280 | * Make sure that client_id is of size CLIENT_ID_SIZE. |
@@ -282,10 +282,14 @@ int getfriend_id(Messenger *m, uint8_t *client_id); | |||
282 | * return 0 if success | 282 | * return 0 if success |
283 | * return -1 if failure | 283 | * return -1 if failure |
284 | */ | 284 | */ |
285 | int getclient_id(Messenger *m, int friend_id, uint8_t *client_id); | 285 | int getclient_id(Messenger *m, int32_t friendnumber, uint8_t *client_id); |
286 | 286 | ||
287 | /* Remove a friend. */ | 287 | /* Remove a friend. |
288 | int m_delfriend(Messenger *m, int friendnumber); | 288 | * |
289 | * return 0 if success | ||
290 | * return -1 if failure | ||
291 | */ | ||
292 | int m_delfriend(Messenger *m, int32_t friendnumber); | ||
289 | 293 | ||
290 | /* Checks friend's connecting status. | 294 | /* Checks friend's connecting status. |
291 | * | 295 | * |
@@ -293,14 +297,14 @@ int m_delfriend(Messenger *m, int friendnumber); | |||
293 | * return 0 if friend is not connected to us (Offline). | 297 | * return 0 if friend is not connected to us (Offline). |
294 | * return -1 on failure. | 298 | * return -1 on failure. |
295 | */ | 299 | */ |
296 | int m_get_friend_connectionstatus(Messenger *m, int friendnumber); | 300 | int m_get_friend_connectionstatus(Messenger *m, int32_t friendnumber); |
297 | 301 | ||
298 | /* Checks if there exists a friend with given friendnumber. | 302 | /* Checks if there exists a friend with given friendnumber. |
299 | * | 303 | * |
300 | * return 1 if friend exists. | 304 | * return 1 if friend exists. |
301 | * return 0 if friend doesn't exist. | 305 | * return 0 if friend doesn't exist. |
302 | */ | 306 | */ |
303 | int m_friend_exists(Messenger *m, int friendnumber); | 307 | int m_friend_exists(Messenger *m, int32_t friendnumber); |
304 | 308 | ||
305 | /* Send a text chat message to an online friend. | 309 | /* Send a text chat message to an online friend. |
306 | * | 310 | * |
@@ -312,8 +316,8 @@ int m_friend_exists(Messenger *m, int friendnumber); | |||
312 | * m_sendmessage_withid will send a message with the id of your choosing, | 316 | * m_sendmessage_withid will send a message with the id of your choosing, |
313 | * however we can generate an id for you by calling plain m_sendmessage. | 317 | * however we can generate an id for you by calling plain m_sendmessage. |
314 | */ | 318 | */ |
315 | uint32_t m_sendmessage(Messenger *m, int friendnumber, uint8_t *message, uint32_t length); | 319 | uint32_t m_sendmessage(Messenger *m, int32_t friendnumber, uint8_t *message, uint32_t length); |
316 | uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length); | 320 | uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length); |
317 | 321 | ||
318 | /* Send an action to an online friend. | 322 | /* Send an action to an online friend. |
319 | * | 323 | * |
@@ -325,8 +329,8 @@ uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, ui | |||
325 | * m_sendaction_withid will send an action message with the id of your choosing, | 329 | * m_sendaction_withid will send an action message with the id of your choosing, |
326 | * however we can generate an id for you by calling plain m_sendaction. | 330 | * however we can generate an id for you by calling plain m_sendaction. |
327 | */ | 331 | */ |
328 | uint32_t m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length); | 332 | uint32_t m_sendaction(Messenger *m, int32_t friendnumber, uint8_t *action, uint32_t length); |
329 | uint32_t m_sendaction_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length); | 333 | uint32_t m_sendaction_withid(Messenger *m, int32_t friendnumber, uint32_t theid, uint8_t *action, uint32_t length); |
330 | 334 | ||
331 | /* Set the name and name_length of a friend. | 335 | /* Set the name and name_length of a friend. |
332 | * name must be a string of maximum MAX_NAME_LENGTH length. | 336 | * name must be a string of maximum MAX_NAME_LENGTH length. |
@@ -336,7 +340,7 @@ uint32_t m_sendaction_withid(Messenger *m, int friendnumber, uint32_t theid, uin | |||
336 | * return 0 if success. | 340 | * return 0 if success. |
337 | * return -1 if failure. | 341 | * return -1 if failure. |
338 | */ | 342 | */ |
339 | int setfriendname(Messenger *m, int friendnumber, uint8_t *name, uint16_t length); | 343 | int setfriendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_t length); |
340 | 344 | ||
341 | /* Set our nickname. | 345 | /* Set our nickname. |
342 | * name must be a string of maximum MAX_NAME_LENGTH length. | 346 | * name must be a string of maximum MAX_NAME_LENGTH length. |
@@ -351,13 +355,12 @@ int setname(Messenger *m, uint8_t *name, uint16_t length); | |||
351 | /* | 355 | /* |
352 | * Get your nickname. | 356 | * Get your nickname. |
353 | * m - The messanger context to use. | 357 | * m - The messanger context to use. |
354 | * name - Pointer to a string for the name. | 358 | * name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes. |
355 | * nlen - The length of the string buffer. | ||
356 | * | 359 | * |
357 | * return length of the name. | 360 | * return length of the name. |
358 | * return 0 on error. | 361 | * return 0 on error. |
359 | */ | 362 | */ |
360 | uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen); | 363 | uint16_t getself_name(Messenger *m, uint8_t *name); |
361 | 364 | ||
362 | /* Get name of friendnumber and put it in name. | 365 | /* Get name of friendnumber and put it in name. |
363 | * name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. | 366 | * name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. |
@@ -365,12 +368,12 @@ uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen); | |||
365 | * return length of name if success. | 368 | * return length of name if success. |
366 | * return -1 if failure. | 369 | * return -1 if failure. |
367 | */ | 370 | */ |
368 | int getname(Messenger *m, int friendnumber, uint8_t *name); | 371 | int getname(Messenger *m, int32_t friendnumber, uint8_t *name); |
369 | 372 | ||
370 | /* returns valid ip port of connected friend on success | 373 | /* returns valid ip port of connected friend on success |
371 | * returns zeroed out IP_Port on failure | 374 | * returns zeroed out IP_Port on failure |
372 | */ | 375 | */ |
373 | IP_Port get_friend_ipport(Messenger *m, int friendnumber); | 376 | IP_Port get_friend_ipport(Messenger *m, int32_t friendnumber); |
374 | 377 | ||
375 | /* Set our user status. | 378 | /* Set our user status. |
376 | * You are responsible for freeing status after. | 379 | * You are responsible for freeing status after. |
@@ -384,7 +387,7 @@ int m_set_userstatus(Messenger *m, USERSTATUS status); | |||
384 | /* return the length of friendnumber's status message, including null. | 387 | /* return the length of friendnumber's status message, including null. |
385 | * Pass it into malloc. | 388 | * Pass it into malloc. |
386 | */ | 389 | */ |
387 | int m_get_statusmessage_size(Messenger *m, int friendnumber); | 390 | int m_get_statusmessage_size(Messenger *m, int32_t friendnumber); |
388 | 391 | ||
389 | /* Copy friendnumber's status message into buf, truncating if size is over maxlen. | 392 | /* Copy friendnumber's status message into buf, truncating if size is over maxlen. |
390 | * Get the size you need to allocate from m_get_statusmessage_size. | 393 | * Get the size you need to allocate from m_get_statusmessage_size. |
@@ -393,7 +396,7 @@ int m_get_statusmessage_size(Messenger *m, int friendnumber); | |||
393 | * returns the length of the copied data on success | 396 | * returns the length of the copied data on success |
394 | * retruns -1 on failure. | 397 | * retruns -1 on failure. |
395 | */ | 398 | */ |
396 | int m_copy_statusmessage(Messenger *m, int friendnumber, uint8_t *buf, uint32_t maxlen); | 399 | int m_copy_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen); |
397 | int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen); | 400 | int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen); |
398 | 401 | ||
399 | /* return one of USERSTATUS values. | 402 | /* return one of USERSTATUS values. |
@@ -401,7 +404,7 @@ int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen); | |||
401 | * As above, the self variant will return our own USERSTATUS. | 404 | * As above, the self variant will return our own USERSTATUS. |
402 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. | 405 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. |
403 | */ | 406 | */ |
404 | USERSTATUS m_get_userstatus(Messenger *m, int friendnumber); | 407 | USERSTATUS m_get_userstatus(Messenger *m, int32_t friendnumber); |
405 | USERSTATUS m_get_self_userstatus(Messenger *m); | 408 | USERSTATUS m_get_self_userstatus(Messenger *m); |
406 | 409 | ||
407 | /* Set our typing status for a friend. | 410 | /* Set our typing status for a friend. |
@@ -410,19 +413,19 @@ USERSTATUS m_get_self_userstatus(Messenger *m); | |||
410 | * returns 0 on success. | 413 | * returns 0 on success. |
411 | * returns -1 on failure. | 414 | * returns -1 on failure. |
412 | */ | 415 | */ |
413 | int m_set_usertyping(Messenger *m, int friendnumber, uint8_t is_typing); | 416 | int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing); |
414 | 417 | ||
415 | /* Get the typing status of a friend. | 418 | /* Get the typing status of a friend. |
416 | * | 419 | * |
417 | * returns 0 if friend is not typing. | 420 | * returns 0 if friend is not typing. |
418 | * returns 1 if friend is typing. | 421 | * returns 1 if friend is typing. |
419 | */ | 422 | */ |
420 | int m_get_istyping(Messenger *m, int friendnumber); | 423 | int m_get_istyping(Messenger *m, int32_t friendnumber); |
421 | 424 | ||
422 | /* Sets whether we send read receipts for friendnumber. | 425 | /* Sets whether we send read receipts for friendnumber. |
423 | * This function is not lazy, and it will fail if yesno is not (0 or 1). | 426 | * This function is not lazy, and it will fail if yesno is not (0 or 1). |
424 | */ | 427 | */ |
425 | void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno); | 428 | void m_set_sends_receipts(Messenger *m, int32_t friendnumber, int yesno); |
426 | 429 | ||
427 | /* Set the function that will be executed when a friend request is received. | 430 | /* Set the function that will be executed when a friend request is received. |
428 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) | 431 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) |
@@ -430,43 +433,44 @@ void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno); | |||
430 | void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata); | 433 | void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata); |
431 | 434 | ||
432 | /* Set the function that will be executed when a message from a friend is received. | 435 | /* Set the function that will be executed when a message from a friend is received. |
433 | * Function format is: function(int friendnumber, uint8_t * message, uint32_t length) | 436 | * Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length) |
434 | */ | 437 | */ |
435 | void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | 438 | void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *), |
436 | void *userdata); | 439 | void *userdata); |
437 | 440 | ||
438 | /* Set the function that will be executed when an action from a friend is received. | 441 | /* Set the function that will be executed when an action from a friend is received. |
439 | * Function format is: function(int friendnumber, uint8_t * action, uint32_t length) | 442 | * Function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length) |
440 | */ | 443 | */ |
441 | void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), void *userdata); | 444 | void m_callback_action(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *), |
445 | void *userdata); | ||
442 | 446 | ||
443 | /* Set the callback for name changes. | 447 | /* Set the callback for name changes. |
444 | * Function(int friendnumber, uint8_t *newname, uint16_t length) | 448 | * Function(int32_t friendnumber, uint8_t *newname, uint16_t length) |
445 | * You are not responsible for freeing newname. | 449 | * You are not responsible for freeing newname. |
446 | */ | 450 | */ |
447 | void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | 451 | void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *), |
448 | void *userdata); | 452 | void *userdata); |
449 | 453 | ||
450 | /* Set the callback for status message changes. | 454 | /* Set the callback for status message changes. |
451 | * Function(int friendnumber, uint8_t *newstatus, uint16_t length) | 455 | * Function(int32_t friendnumber, uint8_t *newstatus, uint16_t length) |
452 | * | 456 | * |
453 | * You are not responsible for freeing newstatus | 457 | * You are not responsible for freeing newstatus |
454 | */ | 458 | */ |
455 | void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | 459 | void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *), |
456 | void *userdata); | 460 | void *userdata); |
457 | 461 | ||
458 | /* Set the callback for status type changes. | 462 | /* Set the callback for status type changes. |
459 | * Function(int friendnumber, USERSTATUS kind) | 463 | * Function(int32_t friendnumber, USERSTATUS kind) |
460 | */ | 464 | */ |
461 | void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS, void *), void *userdata); | 465 | void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int32_t, USERSTATUS, void *), void *userdata); |
462 | 466 | ||
463 | /* Set the callback for typing changes. | 467 | /* Set the callback for typing changes. |
464 | * Function(int friendnumber, int is_typing) | 468 | * Function(int32_t friendnumber, int is_typing) |
465 | */ | 469 | */ |
466 | void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int, int, void *), void *userdata); | 470 | void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int32_t, int, void *), void *userdata); |
467 | 471 | ||
468 | /* Set the callback for read receipts. | 472 | /* Set the callback for read receipts. |
469 | * Function(int friendnumber, uint32_t receipt) | 473 | * Function(int32_t friendnumber, uint32_t receipt) |
470 | * | 474 | * |
471 | * If you are keeping a record of returns from m_sendmessage, | 475 | * If you are keeping a record of returns from m_sendmessage, |
472 | * receipt might be one of those values, meaning the message | 476 | * receipt might be one of those values, meaning the message |
@@ -474,10 +478,10 @@ void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int, in | |||
474 | * Since core doesn't track ids for you, receipt may not correspond to any message. | 478 | * Since core doesn't track ids for you, receipt may not correspond to any message. |
475 | * In that case, you should discard it. | 479 | * In that case, you should discard it. |
476 | */ | 480 | */ |
477 | void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t, void *), void *userdata); | 481 | void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int32_t, uint32_t, void *), void *userdata); |
478 | 482 | ||
479 | /* Set the callback for connection status changes. | 483 | /* Set the callback for connection status changes. |
480 | * function(int friendnumber, uint8_t status) | 484 | * function(int32_t friendnumber, uint8_t status) |
481 | * | 485 | * |
482 | * Status: | 486 | * Status: |
483 | * 0 -- friend went offline after being previously online. | 487 | * 0 -- friend went offline after being previously online. |
@@ -487,18 +491,19 @@ void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, u | |||
487 | * being previously online" part. | 491 | * being previously online" part. |
488 | * It's assumed that when adding friends, their connection status is offline. | 492 | * It's assumed that when adding friends, their connection status is offline. |
489 | */ | 493 | */ |
490 | void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void *), void *userdata); | 494 | void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *), |
495 | void *userdata); | ||
491 | /* Same as previous but for internal A/V core usage only */ | 496 | /* Same as previous but for internal A/V core usage only */ |
492 | void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void *), | 497 | void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *), |
493 | void *userdata); | 498 | void *userdata); |
494 | 499 | ||
495 | /**********GROUP CHATS************/ | 500 | /**********GROUP CHATS************/ |
496 | 501 | ||
497 | /* Set the callback for group invites. | 502 | /* Set the callback for group invites. |
498 | * | 503 | * |
499 | * Function(Messenger *m, int friendnumber, uint8_t *group_public_key, void *userdata) | 504 | * Function(Messenger *m, int32_t friendnumber, uint8_t *group_public_key, void *userdata) |
500 | */ | 505 | */ |
501 | void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, void *), void *userdata); | 506 | void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, void *), void *userdata); |
502 | 507 | ||
503 | /* Set the callback for group messages. | 508 | /* Set the callback for group messages. |
504 | * | 509 | * |
@@ -548,14 +553,14 @@ int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *nam | |||
548 | * return 0 on success | 553 | * return 0 on success |
549 | * return -1 on failure | 554 | * return -1 on failure |
550 | */ | 555 | */ |
551 | int invite_friend(Messenger *m, int friendnumber, int groupnumber); | 556 | int invite_friend(Messenger *m, int32_t friendnumber, int groupnumber); |
552 | 557 | ||
553 | /* Join a group (you need to have been invited first.) | 558 | /* Join a group (you need to have been invited first.) |
554 | * | 559 | * |
555 | * returns group number on success | 560 | * returns group number on success |
556 | * returns -1 on failure. | 561 | * returns -1 on failure. |
557 | */ | 562 | */ |
558 | int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_key); | 563 | int join_groupchat(Messenger *m, int32_t friendnumber, uint8_t *friend_group_public_key); |
559 | 564 | ||
560 | /* send a group message | 565 | /* send a group message |
561 | * return 0 on success | 566 | * return 0 on success |
@@ -589,25 +594,27 @@ int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], | |||
589 | 594 | ||
590 | /* Set the callback for file send requests. | 595 | /* Set the callback for file send requests. |
591 | * | 596 | * |
592 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) | 597 | * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) |
593 | */ | 598 | */ |
594 | void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint64_t, uint8_t *, uint16_t, | 599 | void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint64_t, uint8_t *, |
600 | uint16_t, | ||
595 | void *), void *userdata); | 601 | void *), void *userdata); |
596 | 602 | ||
597 | /* Set the callback for file control requests. | 603 | /* Set the callback for file control requests. |
598 | * | 604 | * |
599 | * Function(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata) | 605 | * 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) |
600 | * | 606 | * |
601 | */ | 607 | */ |
602 | void callback_file_control(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint8_t, uint8_t, uint8_t *, | 608 | void callback_file_control(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *, |
603 | uint16_t, void *), void *userdata); | 609 | uint16_t, void *), void *userdata); |
604 | 610 | ||
605 | /* Set the callback for file data. | 611 | /* Set the callback for file data. |
606 | * | 612 | * |
607 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) | 613 | * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) |
608 | * | 614 | * |
609 | */ | 615 | */ |
610 | void callback_file_data(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint8_t *, uint16_t length, void *), | 616 | void callback_file_data(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint8_t *, uint16_t length, |
617 | void *), | ||
611 | void *userdata); | 618 | void *userdata); |
612 | 619 | ||
613 | /* Send a file send request. | 620 | /* Send a file send request. |
@@ -615,7 +622,7 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, int, uint8_ | |||
615 | * return 1 on success | 622 | * return 1 on success |
616 | * return 0 on failure | 623 | * return 0 on failure |
617 | */ | 624 | */ |
618 | int file_sendrequest(Messenger *m, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, | 625 | int file_sendrequest(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, |
619 | uint16_t filename_length); | 626 | uint16_t filename_length); |
620 | 627 | ||
621 | /* Send a file send request. | 628 | /* Send a file send request. |
@@ -623,7 +630,7 @@ int file_sendrequest(Messenger *m, int friendnumber, uint8_t filenumber, uint64_ | |||
623 | * return file number on success | 630 | * return file number on success |
624 | * return -1 on failure | 631 | * return -1 on failure |
625 | */ | 632 | */ |
626 | int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length); | 633 | int new_filesender(Messenger *m, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length); |
627 | 634 | ||
628 | /* Send a file control request. | 635 | /* Send a file control request. |
629 | * send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file. | 636 | * send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file. |
@@ -631,7 +638,7 @@ int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *f | |||
631 | * return 1 on success | 638 | * return 1 on success |
632 | * return 0 on failure | 639 | * return 0 on failure |
633 | */ | 640 | */ |
634 | int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, | 641 | int file_control(Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, |
635 | uint8_t *data, uint16_t length); | 642 | uint8_t *data, uint16_t length); |
636 | 643 | ||
637 | /* Send file data. | 644 | /* Send file data. |
@@ -639,7 +646,7 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f | |||
639 | * return 1 on success | 646 | * return 1 on success |
640 | * return 0 on failure | 647 | * return 0 on failure |
641 | */ | 648 | */ |
642 | int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length); | 649 | int file_data(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length); |
643 | 650 | ||
644 | /* Give the number of bytes left to be sent/received. | 651 | /* Give the number of bytes left to be sent/received. |
645 | * | 652 | * |
@@ -648,15 +655,15 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, | |||
648 | * return number of bytes remaining to be sent/received on success | 655 | * return number of bytes remaining to be sent/received on success |
649 | * return 0 on failure | 656 | * return 0 on failure |
650 | */ | 657 | */ |
651 | uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive); | 658 | uint64_t file_dataremaining(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive); |
652 | 659 | ||
653 | /*************** A/V related ******************/ | 660 | /*************** A/V related ******************/ |
654 | 661 | ||
655 | /* Set the callback for msi packets. | 662 | /* Set the callback for msi packets. |
656 | * | 663 | * |
657 | * Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata) | 664 | * Function(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata) |
658 | */ | 665 | */ |
659 | void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), | 666 | void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *), |
660 | void *userdata); | 667 | void *userdata); |
661 | 668 | ||
662 | /* Send an msi packet. | 669 | /* Send an msi packet. |
@@ -664,7 +671,7 @@ void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uin | |||
664 | * return 1 on success | 671 | * return 1 on success |
665 | * return 0 on failure | 672 | * return 0 on failure |
666 | */ | 673 | */ |
667 | int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length); | 674 | int m_msi_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length); |
668 | 675 | ||
669 | /**********************************************/ | 676 | /**********************************************/ |
670 | 677 | ||
@@ -673,7 +680,7 @@ int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length) | |||
673 | * return -1 on failure. | 680 | * return -1 on failure. |
674 | * return 0 on success. | 681 | * return 0 on success. |
675 | */ | 682 | */ |
676 | int custom_user_packet_registerhandler(Messenger *m, int friendnumber, uint8_t byte, packet_handler_callback cb, | 683 | int custom_user_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, packet_handler_callback cb, |
677 | void *object); | 684 | void *object); |
678 | 685 | ||
679 | /* High level function to send custom user packets. | 686 | /* High level function to send custom user packets. |
@@ -681,7 +688,7 @@ int custom_user_packet_registerhandler(Messenger *m, int friendnumber, uint8_t b | |||
681 | * return -1 on failure. | 688 | * return -1 on failure. |
682 | * return number of bytes sent on success. | 689 | * return number of bytes sent on success. |
683 | */ | 690 | */ |
684 | int send_custom_user_packet(Messenger *m, int friendnumber, uint8_t *data, uint32_t length); | 691 | int send_custom_user_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint32_t length); |
685 | 692 | ||
686 | /**********************************************/ | 693 | /**********************************************/ |
687 | /* Run this at startup. | 694 | /* Run this at startup. |
@@ -747,7 +754,7 @@ uint32_t get_num_online_friends(Messenger *m); | |||
747 | * Otherwise, returns the number of elements copied. | 754 | * Otherwise, returns the number of elements copied. |
748 | * If the array was too small, the contents | 755 | * If the array was too small, the contents |
749 | * of out_list will be truncated to list_size. */ | 756 | * of out_list will be truncated to list_size. */ |
750 | uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size); | 757 | uint32_t copy_friendlist(Messenger *m, int32_t *out_list, uint32_t list_size); |
751 | 758 | ||
752 | /* Allocate and return a list of valid friend id's. List must be freed by the | 759 | /* Allocate and return a list of valid friend id's. List must be freed by the |
753 | * caller. | 760 | * caller. |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 0115e827..ae824697 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,7 +204,7 @@ 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); |
@@ -225,13 +224,13 @@ int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length) | |||
225 | int tox_set_user_status(Tox *tox, TOX_USERSTATUS status) | 224 | int tox_set_user_status(Tox *tox, TOX_USERSTATUS status) |
226 | { | 225 | { |
227 | Messenger *m = tox; | 226 | Messenger *m = tox; |
228 | return m_set_userstatus(m, (USERSTATUS)status); | 227 | return m_set_userstatus(m, status); |
229 | } | 228 | } |
230 | 229 | ||
231 | /* return the length of friendnumber's status message, including null. | 230 | /* return the length of friendnumber's status message, including null. |
232 | * Pass it into malloc. | 231 | * Pass it into malloc. |
233 | */ | 232 | */ |
234 | int tox_get_status_message_size(Tox *tox, int friendnumber) | 233 | int tox_get_status_message_size(Tox *tox, int32_t friendnumber) |
235 | { | 234 | { |
236 | Messenger *m = tox; | 235 | Messenger *m = tox; |
237 | return m_get_statusmessage_size(m, friendnumber); | 236 | return m_get_statusmessage_size(m, friendnumber); |
@@ -241,7 +240,7 @@ int tox_get_status_message_size(Tox *tox, int friendnumber) | |||
241 | * Get the size you need to allocate from m_get_statusmessage_size. | 240 | * Get the size you need to allocate from m_get_statusmessage_size. |
242 | * The self variant will copy our own status message. | 241 | * The self variant will copy our own status message. |
243 | */ | 242 | */ |
244 | int tox_get_status_message(Tox *tox, int friendnumber, uint8_t *buf, uint32_t maxlen) | 243 | int tox_get_status_message(Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen) |
245 | { | 244 | { |
246 | Messenger *m = tox; | 245 | Messenger *m = tox; |
247 | return m_copy_statusmessage(m, friendnumber, buf, maxlen); | 246 | return m_copy_statusmessage(m, friendnumber, buf, maxlen); |
@@ -258,7 +257,7 @@ 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. | 257 | * As above, the self variant will return our own USERSTATUS. |
259 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. | 258 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. |
260 | */ | 259 | */ |
261 | TOX_USERSTATUS tox_get_user_status(Tox *tox, int friendnumber) | 260 | TOX_USERSTATUS tox_get_user_status(Tox *tox, int32_t friendnumber) |
262 | { | 261 | { |
263 | Messenger *m = tox; | 262 | Messenger *m = tox; |
264 | return (TOX_USERSTATUS)m_get_userstatus(m, friendnumber); | 263 | return (TOX_USERSTATUS)m_get_userstatus(m, friendnumber); |
@@ -276,7 +275,7 @@ TOX_USERSTATUS tox_get_self_user_status(Tox *tox) | |||
276 | * returns 0 on success. | 275 | * returns 0 on success. |
277 | * returns -1 on failure. | 276 | * returns -1 on failure. |
278 | */ | 277 | */ |
279 | int tox_set_user_is_typing(Tox *tox, int friendnumber, uint8_t is_typing) | 278 | int tox_set_user_is_typing(Tox *tox, int32_t friendnumber, uint8_t is_typing) |
280 | { | 279 | { |
281 | Messenger *m = tox; | 280 | Messenger *m = tox; |
282 | return m_set_usertyping(m, friendnumber, is_typing); | 281 | return m_set_usertyping(m, friendnumber, is_typing); |
@@ -287,7 +286,7 @@ int tox_set_user_is_typing(Tox *tox, int friendnumber, uint8_t is_typing) | |||
287 | * returns 0 if friend is not typing. | 286 | * returns 0 if friend is not typing. |
288 | * returns 1 if friend is typing. | 287 | * returns 1 if friend is typing. |
289 | */ | 288 | */ |
290 | int tox_get_is_typing(Tox *tox, int friendnumber) | 289 | int tox_get_is_typing(Tox *tox, int32_t friendnumber) |
291 | { | 290 | { |
292 | Messenger *m = tox; | 291 | Messenger *m = tox; |
293 | return m_get_istyping(m, friendnumber); | 292 | return m_get_istyping(m, friendnumber); |
@@ -297,7 +296,7 @@ int tox_get_is_typing(Tox *tox, int friendnumber) | |||
297 | /* Sets whether we send read receipts for friendnumber. | 296 | /* Sets whether we send read receipts for friendnumber. |
298 | * This function is not lazy, and it will fail if yesno is not (0 or 1). | 297 | * This function is not lazy, and it will fail if yesno is not (0 or 1). |
299 | */ | 298 | */ |
300 | void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno) | 299 | void tox_set_sends_receipts(Tox *tox, int32_t friendnumber, int yesno) |
301 | { | 300 | { |
302 | Messenger *m = tox; | 301 | Messenger *m = tox; |
303 | m_set_sends_receipts(m, friendnumber, yesno); | 302 | m_set_sends_receipts(m, friendnumber, yesno); |
@@ -324,7 +323,7 @@ uint32_t tox_get_num_online_friends(Tox *tox) | |||
324 | * Otherwise, returns the number of elements copied. | 323 | * Otherwise, returns the number of elements copied. |
325 | * If the array was too small, the contents | 324 | * If the array was too small, the contents |
326 | * of out_list will be truncated to list_size. */ | 325 | * of out_list will be truncated to list_size. */ |
327 | uint32_t tox_get_friendlist(Tox *tox, int *out_list, uint32_t list_size) | 326 | uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size) |
328 | { | 327 | { |
329 | Messenger *m = tox; | 328 | Messenger *m = tox; |
330 | return copy_friendlist(m, out_list, list_size); | 329 | return copy_friendlist(m, out_list, list_size); |
@@ -341,9 +340,9 @@ void tox_callback_friend_request(Tox *tox, void (*function)(uint8_t *, uint8_t * | |||
341 | 340 | ||
342 | 341 | ||
343 | /* Set the function that will be executed when a message from a friend is received. | 342 | /* Set the function that will be executed when a message from a friend is received. |
344 | * Function format is: function(int friendnumber, uint8_t * message, uint32_t length) | 343 | * Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length) |
345 | */ | 344 | */ |
346 | void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 345 | void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), |
347 | void *userdata) | 346 | void *userdata) |
348 | { | 347 | { |
349 | Messenger *m = tox; | 348 | Messenger *m = tox; |
@@ -351,9 +350,9 @@ void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int, | |||
351 | } | 350 | } |
352 | 351 | ||
353 | /* Set the function that will be executed when an action from a friend is received. | 352 | /* Set the function that will be executed when an action from a friend is received. |
354 | * function format is: function(int friendnumber, uint8_t * action, uint32_t length) | 353 | * function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length) |
355 | */ | 354 | */ |
356 | void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 355 | void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), |
357 | void *userdata) | 356 | void *userdata) |
358 | { | 357 | { |
359 | Messenger *m = tox; | 358 | Messenger *m = tox; |
@@ -361,10 +360,10 @@ void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int, | |||
361 | } | 360 | } |
362 | 361 | ||
363 | /* Set the callback for name changes. | 362 | /* Set the callback for name changes. |
364 | * function(int friendnumber, uint8_t *newname, uint16_t length) | 363 | * function(int32_t friendnumber, uint8_t *newname, uint16_t length) |
365 | * You are not responsible for freeing newname. | 364 | * You are not responsible for freeing newname. |
366 | */ | 365 | */ |
367 | void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 366 | void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), |
368 | void *userdata) | 367 | void *userdata) |
369 | { | 368 | { |
370 | Messenger *m = tox; | 369 | Messenger *m = tox; |
@@ -372,10 +371,10 @@ void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int, ui | |||
372 | } | 371 | } |
373 | 372 | ||
374 | /* Set the callback for status message changes. | 373 | /* Set the callback for status message changes. |
375 | * function(int friendnumber, uint8_t *newstatus, uint16_t length) | 374 | * function(int32_t friendnumber, uint8_t *newstatus, uint16_t length) |
376 | * You are not responsible for freeing newstatus. | 375 | * You are not responsible for freeing newstatus. |
377 | */ | 376 | */ |
378 | void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 377 | void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), |
379 | void *userdata) | 378 | void *userdata) |
380 | { | 379 | { |
381 | Messenger *m = tox; | 380 | Messenger *m = tox; |
@@ -383,25 +382,26 @@ void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int, | |||
383 | } | 382 | } |
384 | 383 | ||
385 | /* Set the callback for status type changes. | 384 | /* Set the callback for status type changes. |
386 | * function(int friendnumber, USERSTATUS kind) | 385 | * function(int32_t friendnumber, USERSTATUS kind) |
387 | */ | 386 | */ |
388 | void tox_callback_user_status(Tox *tox, void (*function)(Messenger *tox, int, TOX_USERSTATUS, void *), void *userdata) | 387 | void tox_callback_user_status(Tox *tox, void (*function)(Messenger *tox, int32_t, TOX_USERSTATUS, void *), |
388 | void *userdata) | ||
389 | { | 389 | { |
390 | Messenger *m = tox; | 390 | Messenger *m = tox; |
391 | m_callback_userstatus(m, function, userdata); | 391 | m_callback_userstatus(m, function, userdata); |
392 | } | 392 | } |
393 | 393 | ||
394 | /* Set the callback for typing changes. | 394 | /* Set the callback for typing changes. |
395 | * function (int friendnumber, int is_typing) | 395 | * function (int32_t friendnumber, int is_typing) |
396 | */ | 396 | */ |
397 | void tox_callback_typing_change(Tox *tox, void (*function)(Messenger *tox, int, int, void *), void *userdata) | 397 | void tox_callback_typing_change(Tox *tox, void (*function)(Messenger *tox, int32_t, int, void *), void *userdata) |
398 | { | 398 | { |
399 | Messenger *m = tox; | 399 | Messenger *m = tox; |
400 | m_callback_typingchange(m, function, userdata); | 400 | m_callback_typingchange(m, function, userdata); |
401 | } | 401 | } |
402 | 402 | ||
403 | /* Set the callback for read receipts. | 403 | /* Set the callback for read receipts. |
404 | * function(int friendnumber, uint32_t receipt) | 404 | * function(int32_t friendnumber, uint32_t receipt) |
405 | * | 405 | * |
406 | * If you are keeping a record of returns from m_sendmessage; | 406 | * If you are keeping a record of returns from m_sendmessage; |
407 | * receipt might be one of those values, meaning the message | 407 | * receipt might be one of those values, meaning the message |
@@ -409,14 +409,14 @@ void tox_callback_typing_change(Tox *tox, void (*function)(Messenger *tox, int, | |||
409 | * Since core doesn't track ids for you, receipt may not correspond to any message. | 409 | * Since core doesn't track ids for you, receipt may not correspond to any message. |
410 | * in that case, you should discard it. | 410 | * in that case, you should discard it. |
411 | */ | 411 | */ |
412 | void tox_callback_read_receipt(Tox *tox, void (*function)(Messenger *tox, int, uint32_t, void *), void *userdata) | 412 | void tox_callback_read_receipt(Tox *tox, void (*function)(Messenger *tox, int32_t, uint32_t, void *), void *userdata) |
413 | { | 413 | { |
414 | Messenger *m = tox; | 414 | Messenger *m = tox; |
415 | m_callback_read_receipt(m, function, userdata); | 415 | m_callback_read_receipt(m, function, userdata); |
416 | } | 416 | } |
417 | 417 | ||
418 | /* Set the callback for connection status changes. | 418 | /* Set the callback for connection status changes. |
419 | * function(int friendnumber, uint8_t status) | 419 | * function(int32_t friendnumber, uint8_t status) |
420 | * | 420 | * |
421 | * Status: | 421 | * Status: |
422 | * 0 -- friend went offline after being previously online | 422 | * 0 -- friend went offline after being previously online |
@@ -426,7 +426,8 @@ void tox_callback_read_receipt(Tox *tox, void (*function)(Messenger *tox, int, u | |||
426 | * being previously online" part. It's assumed that when adding friends, | 426 | * being previously online" part. It's assumed that when adding friends, |
427 | * their connection status is offline. | 427 | * their connection status is offline. |
428 | */ | 428 | */ |
429 | void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, void *), void *userdata) | 429 | void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, void *), |
430 | void *userdata) | ||
430 | { | 431 | { |
431 | Messenger *m = tox; | 432 | Messenger *m = tox; |
432 | m_callback_connectionstatus(m, function, userdata); | 433 | m_callback_connectionstatus(m, function, userdata); |
@@ -436,9 +437,9 @@ void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, i | |||
436 | 437 | ||
437 | /* Set the callback for group invites. | 438 | /* Set the callback for group invites. |
438 | * | 439 | * |
439 | * Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata) | 440 | * Function(Tox *tox, int32_t friendnumber, uint8_t *group_public_key, void *userdata) |
440 | */ | 441 | */ |
441 | void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, void *), void *userdata) | 442 | void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, void *), void *userdata) |
442 | { | 443 | { |
443 | Messenger *m = tox; | 444 | Messenger *m = tox; |
444 | m_callback_group_invite(m, function, userdata); | 445 | m_callback_group_invite(m, function, userdata); |
@@ -513,7 +514,7 @@ int tox_group_peername(Tox *tox, int groupnumber, int peernumber, uint8_t *name) | |||
513 | * return 0 on success | 514 | * return 0 on success |
514 | * return -1 on failure | 515 | * return -1 on failure |
515 | */ | 516 | */ |
516 | int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber) | 517 | int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) |
517 | { | 518 | { |
518 | Messenger *m = tox; | 519 | Messenger *m = tox; |
519 | return invite_friend(m, friendnumber, groupnumber); | 520 | return invite_friend(m, friendnumber, groupnumber); |
@@ -523,7 +524,7 @@ int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber) | |||
523 | * returns group number on success | 524 | * returns group number on success |
524 | * returns -1 on failure. | 525 | * returns -1 on failure. |
525 | */ | 526 | */ |
526 | int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key) | 527 | int tox_join_groupchat(Tox *tox, int32_t friendnumber, uint8_t *friend_group_public_key) |
527 | { | 528 | { |
528 | Messenger *m = tox; | 529 | Messenger *m = tox; |
529 | return join_groupchat(m, friendnumber, friend_group_public_key); | 530 | return join_groupchat(m, friendnumber, friend_group_public_key); |
@@ -598,9 +599,9 @@ uint32_t tox_get_chatlist(Tox *tox, int *out_list, uint32_t list_size) | |||
598 | 599 | ||
599 | /* Set the callback for file send requests. | 600 | /* Set the callback for file send requests. |
600 | * | 601 | * |
601 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) | 602 | * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) |
602 | */ | 603 | */ |
603 | void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint64_t, uint8_t *, | 604 | void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint64_t, uint8_t *, |
604 | uint16_t, | 605 | uint16_t, |
605 | void *), void *userdata) | 606 | void *), void *userdata) |
606 | { | 607 | { |
@@ -609,10 +610,10 @@ void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, i | |||
609 | } | 610 | } |
610 | /* Set the callback for file control requests. | 611 | /* Set the callback for file control requests. |
611 | * | 612 | * |
612 | * Function(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata) | 613 | * 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) |
613 | * | 614 | * |
614 | */ | 615 | */ |
615 | void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint8_t, uint8_t, uint8_t *, | 616 | void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *, |
616 | uint16_t, void *), void *userdata) | 617 | uint16_t, void *), void *userdata) |
617 | { | 618 | { |
618 | Messenger *m = tox; | 619 | Messenger *m = tox; |
@@ -620,10 +621,10 @@ void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int, u | |||
620 | } | 621 | } |
621 | /* Set the callback for file data. | 622 | /* Set the callback for file data. |
622 | * | 623 | * |
623 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) | 624 | * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) |
624 | * | 625 | * |
625 | */ | 626 | */ |
626 | void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint8_t *, uint16_t length, | 627 | void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint8_t *, uint16_t length, |
627 | void *), | 628 | void *), |
628 | void *userdata) | 629 | void *userdata) |
629 | 630 | ||
@@ -636,7 +637,7 @@ void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int, uint | |||
636 | * return file number on success | 637 | * return file number on success |
637 | * return -1 on failure | 638 | * return -1 on failure |
638 | */ | 639 | */ |
639 | int tox_new_file_sender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length) | 640 | int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length) |
640 | { | 641 | { |
641 | Messenger *m = tox; | 642 | Messenger *m = tox; |
642 | return new_filesender(m, friendnumber, filesize, filename, filename_length); | 643 | return new_filesender(m, friendnumber, filesize, filename, filename_length); |
@@ -647,7 +648,7 @@ int tox_new_file_sender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t * | |||
647 | * return 0 on success | 648 | * return 0 on success |
648 | * return -1 on failure | 649 | * return -1 on failure |
649 | */ | 650 | */ |
650 | int tox_file_send_control(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, | 651 | int tox_file_send_control(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, |
651 | uint8_t *data, uint16_t length) | 652 | uint8_t *data, uint16_t length) |
652 | { | 653 | { |
653 | Messenger *m = tox; | 654 | Messenger *m = tox; |
@@ -658,7 +659,7 @@ int tox_file_send_control(Tox *tox, int friendnumber, uint8_t send_receive, uint | |||
658 | * return 0 on success | 659 | * return 0 on success |
659 | * return -1 on failure | 660 | * return -1 on failure |
660 | */ | 661 | */ |
661 | int tox_file_send_data(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) | 662 | int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) |
662 | { | 663 | { |
663 | Messenger *m = tox; | 664 | Messenger *m = tox; |
664 | return file_data(m, friendnumber, filenumber, data, length); | 665 | return file_data(m, friendnumber, filenumber, data, length); |
@@ -669,7 +670,7 @@ int tox_file_send_data(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t * | |||
669 | * return size on success | 670 | * return size on success |
670 | * return -1 on failure (currently will never return -1) | 671 | * return -1 on failure (currently will never return -1) |
671 | */ | 672 | */ |
672 | int tox_file_data_size(Tox *tox, int friendnumber) | 673 | int tox_file_data_size(Tox *tox, int32_t friendnumber) |
673 | { | 674 | { |
674 | return MAX_DATA_SIZE - crypto_box_MACBYTES - 3; | 675 | return MAX_DATA_SIZE - crypto_box_MACBYTES - 3; |
675 | } | 676 | } |
@@ -681,7 +682,7 @@ int tox_file_data_size(Tox *tox, int friendnumber) | |||
681 | * return number of bytes remaining to be sent/received on success | 682 | * return number of bytes remaining to be sent/received on success |
682 | * return 0 on failure | 683 | * return 0 on failure |
683 | */ | 684 | */ |
684 | uint64_t tox_file_data_remaining(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive) | 685 | uint64_t tox_file_data_remaining(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive) |
685 | { | 686 | { |
686 | Messenger *m = tox; | 687 | Messenger *m = tox; |
687 | return file_dataremaining(m, friendnumber, filenumber, send_receive); | 688 | return file_dataremaining(m, friendnumber, filenumber, send_receive); |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 1db5c46e..348ef6e5 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -36,8 +36,6 @@ | |||
36 | #include <windows.h> | 36 | #include <windows.h> |
37 | #include <ws2tcpip.h> | 37 | #include <ws2tcpip.h> |
38 | 38 | ||
39 | /* sa_family_t is the sockaddr_in / sockaddr_in6 family field */ | ||
40 | typedef short sa_family_t; | ||
41 | 39 | ||
42 | #ifndef true | 40 | #ifndef true |
43 | #define true 1 | 41 | #define true 1 |
@@ -58,7 +56,7 @@ extern "C" { | |||
58 | #endif | 56 | #endif |
59 | 57 | ||
60 | #define TOX_MAX_NAME_LENGTH 128 | 58 | #define TOX_MAX_NAME_LENGTH 128 |
61 | #define TOX_MAX_STATUSMESSAGE_LENGTH 128 | 59 | #define TOX_MAX_STATUSMESSAGE_LENGTH 1007 |
62 | #define TOX_CLIENT_ID_SIZE 32 | 60 | #define TOX_CLIENT_ID_SIZE 32 |
63 | 61 | ||
64 | #define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) | 62 | #define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) |
@@ -67,37 +65,8 @@ extern "C" { | |||
67 | #define TOX_PORTRANGE_TO 33545 | 65 | #define TOX_PORTRANGE_TO 33545 |
68 | #define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM | 66 | #define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM |
69 | 67 | ||
70 | typedef union { | ||
71 | uint8_t c[4]; | ||
72 | uint16_t s[2]; | ||
73 | uint32_t i; | ||
74 | } tox_IP4; | ||
75 | |||
76 | typedef union { | ||
77 | uint8_t uint8[16]; | ||
78 | uint16_t uint16[8]; | ||
79 | uint32_t uint32[4]; | ||
80 | struct in6_addr in6_addr; | ||
81 | } tox_IP6; | ||
82 | |||
83 | typedef struct { | ||
84 | sa_family_t family; | ||
85 | union { | ||
86 | tox_IP4 ip4; | ||
87 | tox_IP6 ip6; | ||
88 | }; | ||
89 | } tox_IP; | ||
90 | |||
91 | /* will replace IP_Port as soon as the complete infrastructure is in place | ||
92 | * removed the unused union and padding also */ | ||
93 | typedef struct { | ||
94 | tox_IP ip; | ||
95 | uint16_t port; | ||
96 | } tox_IP_Port; | ||
97 | |||
98 | #define TOX_ENABLE_IPV6_DEFAULT 1 | 68 | #define TOX_ENABLE_IPV6_DEFAULT 1 |
99 | 69 | ||
100 | |||
101 | /* Errors for m_addfriend | 70 | /* Errors for m_addfriend |
102 | * FAERR - Friend Add Error | 71 | * FAERR - Friend Add Error |
103 | */ | 72 | */ |
@@ -132,6 +101,8 @@ typedef struct Tox Tox; | |||
132 | * | 101 | * |
133 | * The length when passing those strings to the core includes that NULL character. | 102 | * The length when passing those strings to the core includes that NULL character. |
134 | * | 103 | * |
104 | * The length of all strings returned by the core include the NULL character. | ||
105 | * | ||
135 | * If you send non NULL terminated strings Tox will force NULL terminates them when it receives them. | 106 | * If you send non NULL terminated strings Tox will force NULL terminates them when it receives them. |
136 | */ | 107 | */ |
137 | 108 | ||
@@ -156,28 +127,32 @@ void tox_get_address(Tox *tox, uint8_t *address); | |||
156 | * (the nospam for that friend was set to the new one). | 127 | * (the nospam for that friend was set to the new one). |
157 | * return TOX_FAERR_NOMEM if increasing the friend list size fails. | 128 | * return TOX_FAERR_NOMEM if increasing the friend list size fails. |
158 | */ | 129 | */ |
159 | int tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length); | 130 | int32_t tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length); |
160 | 131 | ||
161 | 132 | ||
162 | /* Add a friend without sending a friendrequest. | 133 | /* Add a friend without sending a friendrequest. |
163 | * return the friend number if success. | 134 | * return the friend number if success. |
164 | * return -1 if failure. | 135 | * return -1 if failure. |
165 | */ | 136 | */ |
166 | int tox_add_friend_norequest(Tox *tox, uint8_t *client_id); | 137 | int32_t tox_add_friend_norequest(Tox *tox, uint8_t *client_id); |
167 | 138 | ||
168 | /* return the friend id associated to that client id. | 139 | /* return the friend number associated to that client id. |
169 | return -1 if no such friend */ | 140 | return -1 if no such friend */ |
170 | int tox_get_friend_id(Tox *tox, uint8_t *client_id); | 141 | int32_t tox_get_friend_number(Tox *tox, uint8_t *client_id); |
171 | 142 | ||
172 | /* Copies the public key associated to that friend id into client_id buffer. | 143 | /* Copies the public key associated to that friend id into client_id buffer. |
173 | * Make sure that client_id is of size CLIENT_ID_SIZE. | 144 | * Make sure that client_id is of size CLIENT_ID_SIZE. |
174 | * return 0 if success. | 145 | * return 0 if success. |
175 | * return -1 if failure. | 146 | * return -1 if failure. |
176 | */ | 147 | */ |
177 | int tox_get_client_id(Tox *tox, int friend_id, uint8_t *client_id); | 148 | int tox_get_client_id(Tox *tox, int32_t friendnumber, uint8_t *client_id); |
178 | 149 | ||
179 | /* Remove a friend. */ | 150 | /* Remove a friend. |
180 | int tox_del_friend(Tox *tox, int friendnumber); | 151 | * |
152 | * return 0 if success. | ||
153 | * return -1 if failure. | ||
154 | */ | ||
155 | int tox_del_friend(Tox *tox, int32_t friendnumber); | ||
181 | 156 | ||
182 | /* Checks friend's connecting status. | 157 | /* Checks friend's connecting status. |
183 | * | 158 | * |
@@ -185,14 +160,14 @@ int tox_del_friend(Tox *tox, int friendnumber); | |||
185 | * return 0 if friend is not connected to us (Offline). | 160 | * return 0 if friend is not connected to us (Offline). |
186 | * return -1 on failure. | 161 | * return -1 on failure. |
187 | */ | 162 | */ |
188 | int tox_get_friend_connection_status(Tox *tox, int friendnumber); | 163 | int tox_get_friend_connection_status(Tox *tox, int32_t friendnumber); |
189 | 164 | ||
190 | /* Checks if there exists a friend with given friendnumber. | 165 | /* Checks if there exists a friend with given friendnumber. |
191 | * | 166 | * |
192 | * return 1 if friend exists. | 167 | * return 1 if friend exists. |
193 | * return 0 if friend doesn't exist. | 168 | * return 0 if friend doesn't exist. |
194 | */ | 169 | */ |
195 | int tox_friend_exists(Tox *tox, int friendnumber); | 170 | int tox_friend_exists(Tox *tox, int32_t friendnumber); |
196 | 171 | ||
197 | /* Send a text chat message to an online friend. | 172 | /* Send a text chat message to an online friend. |
198 | * | 173 | * |
@@ -204,8 +179,8 @@ int tox_friend_exists(Tox *tox, int friendnumber); | |||
204 | * m_sendmessage_withid will send a message with the id of your choosing, | 179 | * m_sendmessage_withid will send a message with the id of your choosing, |
205 | * however we can generate an id for you by calling plain m_sendmessage. | 180 | * however we can generate an id for you by calling plain m_sendmessage. |
206 | */ | 181 | */ |
207 | uint32_t tox_send_message(Tox *tox, int friendnumber, uint8_t *message, uint32_t length); | 182 | uint32_t tox_send_message(Tox *tox, int32_t friendnumber, uint8_t *message, uint32_t length); |
208 | uint32_t tox_send_message_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length); | 183 | uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length); |
209 | 184 | ||
210 | /* Send an action to an online friend. | 185 | /* Send an action to an online friend. |
211 | * | 186 | * |
@@ -217,8 +192,8 @@ uint32_t tox_send_message_withid(Tox *tox, int friendnumber, uint32_t theid, uin | |||
217 | * m_sendaction_withid will send an action message with the id of your choosing, | 192 | * m_sendaction_withid will send an action message with the id of your choosing, |
218 | * however we can generate an id for you by calling plain m_sendaction. | 193 | * however we can generate an id for you by calling plain m_sendaction. |
219 | */ | 194 | */ |
220 | uint32_t tox_send_action(Tox *tox, int friendnumber, uint8_t *action, uint32_t length); | 195 | uint32_t tox_send_action(Tox *tox, int32_t friendnumber, uint8_t *action, uint32_t length); |
221 | uint32_t tox_send_action_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length); | 196 | uint32_t tox_send_action_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *action, uint32_t length); |
222 | 197 | ||
223 | /* Set our nickname. | 198 | /* Set our nickname. |
224 | * name must be a string of maximum MAX_NAME_LENGTH length. | 199 | * name must be a string of maximum MAX_NAME_LENGTH length. |
@@ -233,35 +208,36 @@ int tox_set_name(Tox *tox, uint8_t *name, uint16_t length); | |||
233 | /* | 208 | /* |
234 | * Get your nickname. | 209 | * Get your nickname. |
235 | * m - The messanger context to use. | 210 | * m - The messanger context to use. |
236 | * name - Pointer to a string for the name. | 211 | * name - needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. |
237 | * nlen - The length of the string buffer. | ||
238 | * | 212 | * |
239 | * return length of name. | 213 | * return length of name. |
240 | * return 0 on error. | 214 | * return 0 on error. |
241 | */ | 215 | */ |
242 | uint16_t tox_get_self_name(Tox *tox, uint8_t *name, uint16_t nlen); | 216 | uint16_t tox_get_self_name(Tox *tox, uint8_t *name); |
243 | 217 | ||
244 | /* Get name of friendnumber and put it in name. | 218 | /* Get name of friendnumber and put it in name. |
245 | * name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. | 219 | * name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. |
246 | * | 220 | * |
247 | * return length of name (with the NULL terminator) if success. | 221 | * return length of name if success. |
248 | * return -1 if failure. | 222 | * return -1 if failure. |
249 | */ | 223 | */ |
250 | int tox_get_name(Tox *tox, int friendnumber, uint8_t *name); | 224 | int tox_get_name(Tox *tox, int32_t friendnumber, uint8_t *name); |
251 | 225 | ||
252 | /* Set our user status. | 226 | /* Set our user status. |
253 | * You are responsible for freeing status after. | 227 | * You are responsible for freeing status after. |
254 | * | 228 | * |
229 | * userstatus must be one of TOX_USERSTATUS values. | ||
230 | * | ||
255 | * returns 0 on success. | 231 | * returns 0 on success. |
256 | * returns -1 on failure. | 232 | * returns -1 on failure. |
257 | */ | 233 | */ |
258 | int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length); | 234 | int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length); |
259 | int tox_set_user_status(Tox *tox, TOX_USERSTATUS status); | 235 | int tox_set_user_status(Tox *tox, TOX_USERSTATUS userstatus); |
260 | 236 | ||
261 | /* return the length of friendnumber's status message, including null. | 237 | /* return the length of friendnumber's status message. |
262 | * Pass it into malloc | 238 | * Pass it into malloc |
263 | */ | 239 | */ |
264 | int tox_get_status_message_size(Tox *tox, int friendnumber); | 240 | int tox_get_status_message_size(Tox *tox, int32_t friendnumber); |
265 | 241 | ||
266 | /* Copy friendnumber's status message into buf, truncating if size is over maxlen. | 242 | /* Copy friendnumber's status message into buf, truncating if size is over maxlen. |
267 | * Get the size you need to allocate from m_get_statusmessage_size. | 243 | * Get the size you need to allocate from m_get_statusmessage_size. |
@@ -270,15 +246,15 @@ int tox_get_status_message_size(Tox *tox, int friendnumber); | |||
270 | * returns the length of the copied data on success | 246 | * returns the length of the copied data on success |
271 | * retruns -1 on failure. | 247 | * retruns -1 on failure. |
272 | */ | 248 | */ |
273 | int tox_get_status_message(Tox *tox, int friendnumber, uint8_t *buf, uint32_t maxlen); | 249 | int tox_get_status_message(Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen); |
274 | int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen); | 250 | int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen); |
275 | 251 | ||
276 | /* return one of USERSTATUS values. | 252 | /* return one of TOX_USERSTATUS values. |
277 | * Values unknown to your application should be represented as USERSTATUS_NONE. | 253 | * Values unknown to your application should be represented as TOX_USERSTATUS_NONE. |
278 | * As above, the self variant will return our own USERSTATUS. | 254 | * As above, the self variant will return our own TOX_USERSTATUS. |
279 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. | 255 | * If friendnumber is invalid, this shall return TOX_USERSTATUS_INVALID. |
280 | */ | 256 | */ |
281 | TOX_USERSTATUS tox_get_user_status(Tox *tox, int friendnumber); | 257 | TOX_USERSTATUS tox_get_user_status(Tox *tox, int32_t friendnumber); |
282 | TOX_USERSTATUS tox_get_self_user_status(Tox *tox); | 258 | TOX_USERSTATUS tox_get_self_user_status(Tox *tox); |
283 | 259 | ||
284 | /* Set our typing status for a friend. | 260 | /* Set our typing status for a friend. |
@@ -287,19 +263,19 @@ TOX_USERSTATUS tox_get_self_user_status(Tox *tox); | |||
287 | * returns 0 on success. | 263 | * returns 0 on success. |
288 | * returns -1 on failure. | 264 | * returns -1 on failure. |
289 | */ | 265 | */ |
290 | int tox_set_user_is_typing(Tox *tox, int friendnumber, uint8_t is_typing); | 266 | int tox_set_user_is_typing(Tox *tox, int32_t friendnumber, uint8_t is_typing); |
291 | 267 | ||
292 | /* Get the typing status of a friend. | 268 | /* Get the typing status of a friend. |
293 | * | 269 | * |
294 | * returns 0 if friend is not typing. | 270 | * returns 0 if friend is not typing. |
295 | * returns 1 if friend is typing. | 271 | * returns 1 if friend is typing. |
296 | */ | 272 | */ |
297 | int tox_get_is_typing(Tox *tox, int friendnumber); | 273 | int tox_get_is_typing(Tox *tox, int32_t friendnumber); |
298 | 274 | ||
299 | /* Sets whether we send read receipts for friendnumber. | 275 | /* Sets whether we send read receipts for friendnumber. |
300 | * This function is not lazy, and it will fail if yesno is not (0 or 1). | 276 | * This function is not lazy, and it will fail if yesno is not (0 or 1). |
301 | */ | 277 | */ |
302 | void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno); | 278 | void tox_set_sends_receipts(Tox *tox, int32_t friendnumber, int yesno); |
303 | 279 | ||
304 | /* Return the number of friends in the instance m. | 280 | /* Return the number of friends in the instance m. |
305 | * You should use this to determine how much memory to allocate | 281 | * You should use this to determine how much memory to allocate |
@@ -314,7 +290,7 @@ uint32_t tox_get_num_online_friends(Tox *tox); | |||
314 | * Otherwise, returns the number of elements copied. | 290 | * Otherwise, returns the number of elements copied. |
315 | * If the array was too small, the contents | 291 | * If the array was too small, the contents |
316 | * of out_list will be truncated to list_size. */ | 292 | * of out_list will be truncated to list_size. */ |
317 | uint32_t tox_get_friendlist(Tox *tox, int *out_list, uint32_t list_size); | 293 | uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size); |
318 | 294 | ||
319 | /* Set the function that will be executed when a friend request is received. | 295 | /* Set the function that will be executed when a friend request is received. |
320 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) | 296 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) |
@@ -328,36 +304,37 @@ void tox_callback_friend_message(Tox *tox, void (*function)(Tox *tox, int, uint8 | |||
328 | void *userdata); | 304 | void *userdata); |
329 | 305 | ||
330 | /* Set the function that will be executed when an action from a friend is received. | 306 | /* Set the function that will be executed when an action from a friend is received. |
331 | * Function format is: function(int friendnumber, uint8_t * action, uint32_t length) | 307 | * Function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length) |
332 | */ | 308 | */ |
333 | void tox_callback_friend_action(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *), void *userdata); | 309 | void tox_callback_friend_action(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *), |
310 | void *userdata); | ||
334 | 311 | ||
335 | /* Set the callback for name changes. | 312 | /* Set the callback for name changes. |
336 | * function(int friendnumber, uint8_t *newname, uint16_t length) | 313 | * function(int32_t friendnumber, uint8_t *newname, uint16_t length) |
337 | * You are not responsible for freeing newname | 314 | * You are not responsible for freeing newname |
338 | */ | 315 | */ |
339 | void tox_callback_name_change(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *), | 316 | void tox_callback_name_change(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *), |
340 | void *userdata); | 317 | void *userdata); |
341 | 318 | ||
342 | /* Set the callback for status message changes. | 319 | /* Set the callback for status message changes. |
343 | * function(int friendnumber, uint8_t *newstatus, uint16_t length) | 320 | * function(int32_t friendnumber, uint8_t *newstatus, uint16_t length) |
344 | * You are not responsible for freeing newstatus. | 321 | * You are not responsible for freeing newstatus. |
345 | */ | 322 | */ |
346 | void tox_callback_status_message(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *), | 323 | void tox_callback_status_message(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *), |
347 | void *userdata); | 324 | void *userdata); |
348 | 325 | ||
349 | /* Set the callback for status type changes. | 326 | /* Set the callback for status type changes. |
350 | * function(int friendnumber, USERSTATUS kind) | 327 | * function(int32_t friendnumber, USERSTATUS kind) |
351 | */ | 328 | */ |
352 | void tox_callback_user_status(Tox *tox, void (*function)(Tox *tox, int, TOX_USERSTATUS, void *), void *userdata); | 329 | void tox_callback_user_status(Tox *tox, void (*function)(Tox *tox, int32_t, TOX_USERSTATUS, void *), void *userdata); |
353 | 330 | ||
354 | /* Set the callback for typing changes. | 331 | /* Set the callback for typing changes. |
355 | * function (int friendnumber, int is_typing) | 332 | * function (int32_t friendnumber, int is_typing) |
356 | */ | 333 | */ |
357 | void tox_callback_typing_change(Tox *tox, void (*function)(Tox *tox, int, int, void *), void *userdata); | 334 | void tox_callback_typing_change(Tox *tox, void (*function)(Tox *tox, int32_t, int, void *), void *userdata); |
358 | 335 | ||
359 | /* Set the callback for read receipts. | 336 | /* Set the callback for read receipts. |
360 | * function(int friendnumber, uint32_t receipt) | 337 | * function(int32_t friendnumber, uint32_t receipt) |
361 | * | 338 | * |
362 | * If you are keeping a record of returns from m_sendmessage; | 339 | * If you are keeping a record of returns from m_sendmessage; |
363 | * receipt might be one of those values, meaning the message | 340 | * receipt might be one of those values, meaning the message |
@@ -365,10 +342,10 @@ void tox_callback_typing_change(Tox *tox, void (*function)(Tox *tox, int, int, v | |||
365 | * Since core doesn't track ids for you, receipt may not correspond to any message. | 342 | * Since core doesn't track ids for you, receipt may not correspond to any message. |
366 | * In that case, you should discard it. | 343 | * In that case, you should discard it. |
367 | */ | 344 | */ |
368 | void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int, uint32_t, void *), void *userdata); | 345 | void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int32_t, uint32_t, void *), void *userdata); |
369 | 346 | ||
370 | /* Set the callback for connection status changes. | 347 | /* Set the callback for connection status changes. |
371 | * function(int friendnumber, uint8_t status) | 348 | * function(int32_t friendnumber, uint8_t status) |
372 | * | 349 | * |
373 | * Status: | 350 | * Status: |
374 | * 0 -- friend went offline after being previously online | 351 | * 0 -- friend went offline after being previously online |
@@ -378,7 +355,7 @@ void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int, uint32_ | |||
378 | * being previously online" part. it's assumed that when adding friends, | 355 | * being previously online" part. it's assumed that when adding friends, |
379 | * their connection status is offline. | 356 | * their connection status is offline. |
380 | */ | 357 | */ |
381 | void tox_callback_connection_status(Tox *tox, void (*function)(Tox *tox, int, uint8_t, void *), void *userdata); | 358 | void tox_callback_connection_status(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata); |
382 | 359 | ||
383 | /**********GROUP CHAT FUNCTIONS: WARNING WILL BREAK A LOT************/ | 360 | /**********GROUP CHAT FUNCTIONS: WARNING WILL BREAK A LOT************/ |
384 | 361 | ||
@@ -386,7 +363,7 @@ void tox_callback_connection_status(Tox *tox, void (*function)(Tox *tox, int, ui | |||
386 | * | 363 | * |
387 | * Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata) | 364 | * Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata) |
388 | */ | 365 | */ |
389 | void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, void *), void *userdata); | 366 | void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, void *), void *userdata); |
390 | 367 | ||
391 | /* Set the callback for group messages. | 368 | /* Set the callback for group messages. |
392 | * | 369 | * |
@@ -442,14 +419,14 @@ int tox_group_peername(Tox *tox, int groupnumber, int peernumber, uint8_t *name) | |||
442 | * return 0 on success | 419 | * return 0 on success |
443 | * return -1 on failure | 420 | * return -1 on failure |
444 | */ | 421 | */ |
445 | int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber); | 422 | int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber); |
446 | 423 | ||
447 | /* Join a group (you need to have been invited first.) | 424 | /* Join a group (you need to have been invited first.) |
448 | * | 425 | * |
449 | * returns group number on success | 426 | * returns group number on success |
450 | * returns -1 on failure. | 427 | * returns -1 on failure. |
451 | */ | 428 | */ |
452 | int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key); | 429 | int tox_join_groupchat(Tox *tox, int32_t friendnumber, uint8_t *friend_group_public_key); |
453 | 430 | ||
454 | /* send a group message | 431 | /* send a group message |
455 | * return 0 on success | 432 | * return 0 on success |
@@ -528,9 +505,9 @@ enum { | |||
528 | }; | 505 | }; |
529 | /* Set the callback for file send requests. | 506 | /* Set the callback for file send requests. |
530 | * | 507 | * |
531 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) | 508 | * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) |
532 | */ | 509 | */ |
533 | void tox_callback_file_send_request(Tox *tox, void (*function)(Tox *m, int, uint8_t, uint64_t, uint8_t *, uint16_t, | 510 | void tox_callback_file_send_request(Tox *tox, void (*function)(Tox *m, int32_t, uint8_t, uint64_t, uint8_t *, uint16_t, |
534 | void *), void *userdata); | 511 | void *), void *userdata); |
535 | 512 | ||
536 | /* Set the callback for file control requests. | 513 | /* Set the callback for file control requests. |
@@ -538,18 +515,18 @@ void tox_callback_file_send_request(Tox *tox, void (*function)(Tox *m, int, uint | |||
538 | * receive_send is 1 if the message is for a slot on which we are currently sending a file and 0 if the message | 515 | * receive_send is 1 if the message is for a slot on which we are currently sending a file and 0 if the message |
539 | * is for a slot on which we are receiving the file | 516 | * is for a slot on which we are receiving the file |
540 | * | 517 | * |
541 | * Function(Tox *tox, int friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata) | 518 | * Function(Tox *tox, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata) |
542 | * | 519 | * |
543 | */ | 520 | */ |
544 | void tox_callback_file_control(Tox *tox, void (*function)(Tox *m, int, uint8_t, uint8_t, uint8_t, uint8_t *, | 521 | void tox_callback_file_control(Tox *tox, void (*function)(Tox *m, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *, |
545 | uint16_t, void *), void *userdata); | 522 | uint16_t, void *), void *userdata); |
546 | 523 | ||
547 | /* Set the callback for file data. | 524 | /* Set the callback for file data. |
548 | * | 525 | * |
549 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) | 526 | * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) |
550 | * | 527 | * |
551 | */ | 528 | */ |
552 | void tox_callback_file_data(Tox *tox, void (*function)(Tox *m, int, uint8_t, uint8_t *, uint16_t length, void *), | 529 | void tox_callback_file_data(Tox *tox, void (*function)(Tox *m, int32_t, uint8_t, uint8_t *, uint16_t length, void *), |
553 | void *userdata); | 530 | void *userdata); |
554 | 531 | ||
555 | 532 | ||
@@ -558,7 +535,7 @@ void tox_callback_file_data(Tox *tox, void (*function)(Tox *m, int, uint8_t, uin | |||
558 | * return file number on success | 535 | * return file number on success |
559 | * return -1 on failure | 536 | * return -1 on failure |
560 | */ | 537 | */ |
561 | int tox_new_file_sender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length); | 538 | int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length); |
562 | 539 | ||
563 | /* Send a file control request. | 540 | /* Send a file control request. |
564 | * | 541 | * |
@@ -568,7 +545,7 @@ int tox_new_file_sender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t * | |||
568 | * return 0 on success | 545 | * return 0 on success |
569 | * return -1 on failure | 546 | * return -1 on failure |
570 | */ | 547 | */ |
571 | int tox_file_send_control(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, | 548 | int tox_file_send_control(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, |
572 | uint8_t *data, uint16_t length); | 549 | uint8_t *data, uint16_t length); |
573 | 550 | ||
574 | /* Send file data. | 551 | /* Send file data. |
@@ -576,14 +553,14 @@ int tox_file_send_control(Tox *tox, int friendnumber, uint8_t send_receive, uint | |||
576 | * return 0 on success | 553 | * return 0 on success |
577 | * return -1 on failure | 554 | * return -1 on failure |
578 | */ | 555 | */ |
579 | int tox_file_send_data(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length); | 556 | int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length); |
580 | 557 | ||
581 | /* Returns the recommended/maximum size of the filedata you send with tox_file_send_data() | 558 | /* Returns the recommended/maximum size of the filedata you send with tox_file_send_data() |
582 | * | 559 | * |
583 | * return size on success | 560 | * return size on success |
584 | * return -1 on failure (currently will never return -1) | 561 | * return -1 on failure (currently will never return -1) |
585 | */ | 562 | */ |
586 | int tox_file_data_size(Tox *tox, int friendnumber); | 563 | int tox_file_data_size(Tox *tox, int32_t friendnumber); |
587 | 564 | ||
588 | /* Give the number of bytes left to be sent/received. | 565 | /* Give the number of bytes left to be sent/received. |
589 | * | 566 | * |
@@ -592,19 +569,51 @@ int tox_file_data_size(Tox *tox, int friendnumber); | |||
592 | * return number of bytes remaining to be sent/received on success | 569 | * return number of bytes remaining to be sent/received on success |
593 | * return 0 on failure | 570 | * return 0 on failure |
594 | */ | 571 | */ |
595 | uint64_t tox_file_data_remaining(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive); | 572 | uint64_t tox_file_data_remaining(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive); |
596 | 573 | ||
597 | /***************END OF FILE SENDING FUNCTIONS******************/ | 574 | /***************END OF FILE SENDING FUNCTIONS******************/ |
598 | 575 | ||
576 | /* WARNING: DEPRECATED, DO NOT USE. */ | ||
577 | typedef union { | ||
578 | uint8_t c[4]; | ||
579 | uint16_t s[2]; | ||
580 | uint32_t i; | ||
581 | } tox_IP4; | ||
599 | 582 | ||
600 | /* | 583 | typedef union { |
601 | * Use these two functions to bootstrap the client. | 584 | uint8_t uint8[16]; |
602 | */ | 585 | uint16_t uint16[8]; |
586 | uint32_t uint32[4]; | ||
587 | struct in6_addr in6_addr; | ||
588 | } tox_IP6; | ||
589 | |||
590 | typedef struct { | ||
591 | uint8_t family; | ||
592 | /* Not used for anything right now. */ | ||
593 | uint8_t padding[3]; | ||
594 | union { | ||
595 | tox_IP4 ip4; | ||
596 | tox_IP6 ip6; | ||
597 | }; | ||
598 | } tox_IP; | ||
599 | |||
600 | /* will replace IP_Port as soon as the complete infrastructure is in place | ||
601 | * removed the unused union and padding also */ | ||
602 | typedef struct { | ||
603 | tox_IP ip; | ||
604 | uint16_t port; | ||
605 | } tox_IP_Port; | ||
606 | /* WARNING: DEPRECATED, DO NOT USE. */ | ||
603 | /* Sends a "get nodes" request to the given node with ip, port and public_key | 607 | /* Sends a "get nodes" request to the given node with ip, port and public_key |
604 | * to setup connections | 608 | * to setup connections |
605 | */ | 609 | */ |
606 | void tox_bootstrap_from_ip(Tox *tox, tox_IP_Port ip_port, uint8_t *public_key); | 610 | void tox_bootstrap_from_ip(Tox *tox, tox_IP_Port ip_port, uint8_t *public_key); |
607 | 611 | ||
612 | |||
613 | /* | ||
614 | * Use this function to bootstrap the client. | ||
615 | */ | ||
616 | |||
608 | /* Resolves address into an IP address. If successful, sends a "get nodes" | 617 | /* Resolves address into an IP address. If successful, sends a "get nodes" |
609 | * request to the given node with ip, port (in network byte order, HINT: use htons()) | 618 | * request to the given node with ip, port (in network byte order, HINT: use htons()) |
610 | * and public_key to setup connections | 619 | * and public_key to setup connections |