diff options
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r-- | toxcore/tox.c | 71 |
1 files changed, 49 insertions, 22 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c index e8ec593b..19e1c0a4 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | #include "Messenger.h" | 28 | #include "Messenger.h" |
29 | #include "group.h" | ||
29 | #include "logger.h" | 30 | #include "logger.h" |
30 | 31 | ||
31 | #define __TOX_DEFINED__ | 32 | #define __TOX_DEFINED__ |
@@ -544,13 +545,15 @@ int tox_send_lossless_packet(const Tox *tox, int32_t friendnumber, const uint8_t | |||
544 | 545 | ||
545 | /* Set the callback for group invites. | 546 | /* Set the callback for group invites. |
546 | * | 547 | * |
547 | * Function(Tox *tox, int32_t friendnumber, uint8_t *group_public_key, void *userdata) | 548 | * Function(Tox *tox, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata) |
549 | * | ||
550 | * data of length is what needs to be passed to join_groupchat(). | ||
548 | */ | 551 | */ |
549 | void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, void *), | 552 | void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *), |
550 | void *userdata) | 553 | void *userdata) |
551 | { | 554 | { |
552 | Messenger *m = tox; | 555 | Messenger *m = tox; |
553 | m_callback_group_invite(m, function, userdata); | 556 | g_callback_group_invite(m->group_chat_object, function, userdata); |
554 | } | 557 | } |
555 | 558 | ||
556 | /* Set the callback for group messages. | 559 | /* Set the callback for group messages. |
@@ -561,7 +564,7 @@ void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int, | |||
561 | void *userdata) | 564 | void *userdata) |
562 | { | 565 | { |
563 | Messenger *m = tox; | 566 | Messenger *m = tox; |
564 | m_callback_group_message(m, function, userdata); | 567 | g_callback_group_message(m->group_chat_object, function, userdata); |
565 | } | 568 | } |
566 | 569 | ||
567 | /* Set the callback for group actions. | 570 | /* Set the callback for group actions. |
@@ -572,7 +575,7 @@ void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, i | |||
572 | void *userdata) | 575 | void *userdata) |
573 | { | 576 | { |
574 | Messenger *m = tox; | 577 | Messenger *m = tox; |
575 | m_callback_group_action(m, function, userdata); | 578 | //m_callback_group_action(m, function, userdata); |
576 | } | 579 | } |
577 | 580 | ||
578 | /* Set callback function for peer name list changes. | 581 | /* Set callback function for peer name list changes. |
@@ -583,7 +586,7 @@ void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, i | |||
583 | void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t, void *), void *userdata) | 586 | void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t, void *), void *userdata) |
584 | { | 587 | { |
585 | Messenger *m = tox; | 588 | Messenger *m = tox; |
586 | m_callback_group_namelistchange(m, function, userdata); | 589 | //m_callback_group_namelistchange(m, function, userdata); |
587 | } | 590 | } |
588 | 591 | ||
589 | /* Creates a new groupchat and puts it in the chats array. | 592 | /* Creates a new groupchat and puts it in the chats array. |
@@ -594,8 +597,9 @@ void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int | |||
594 | int tox_add_groupchat(Tox *tox) | 597 | int tox_add_groupchat(Tox *tox) |
595 | { | 598 | { |
596 | Messenger *m = tox; | 599 | Messenger *m = tox; |
597 | return add_groupchat(m); | 600 | return add_groupchat(m->group_chat_object); |
598 | } | 601 | } |
602 | |||
599 | /* Delete a groupchat from the chats array. | 603 | /* Delete a groupchat from the chats array. |
600 | * | 604 | * |
601 | * return 0 on success. | 605 | * return 0 on success. |
@@ -604,7 +608,7 @@ int tox_add_groupchat(Tox *tox) | |||
604 | int tox_del_groupchat(Tox *tox, int groupnumber) | 608 | int tox_del_groupchat(Tox *tox, int groupnumber) |
605 | { | 609 | { |
606 | Messenger *m = tox; | 610 | Messenger *m = tox; |
607 | return del_groupchat(m, groupnumber); | 611 | return del_groupchat(m->group_chat_object, groupnumber); |
608 | } | 612 | } |
609 | 613 | ||
610 | /* Copy the name of peernumber who is in groupnumber to name. | 614 | /* Copy the name of peernumber who is in groupnumber to name. |
@@ -616,8 +620,10 @@ int tox_del_groupchat(Tox *tox, int groupnumber) | |||
616 | int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name) | 620 | int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name) |
617 | { | 621 | { |
618 | const Messenger *m = tox; | 622 | const Messenger *m = tox; |
619 | return m_group_peername(m, groupnumber, peernumber, name); | 623 | //return m_group_peername(m, groupnumber, peernumber, name); |
624 | return -1; | ||
620 | } | 625 | } |
626 | |||
621 | /* invite friendnumber to groupnumber | 627 | /* invite friendnumber to groupnumber |
622 | * return 0 on success | 628 | * return 0 on success |
623 | * return -1 on failure | 629 | * return -1 on failure |
@@ -625,37 +631,40 @@ int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t | |||
625 | int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) | 631 | int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) |
626 | { | 632 | { |
627 | Messenger *m = tox; | 633 | Messenger *m = tox; |
628 | return invite_friend(m, friendnumber, groupnumber); | 634 | return invite_friend(m->group_chat_object, friendnumber, groupnumber); |
629 | } | 635 | } |
630 | /* Join a group (you need to have been invited first.) | 636 | |
637 | /* Join a group (you need to have been invited first.) using data of length obtained | ||
638 | * in the group invite callback. | ||
631 | * | 639 | * |
632 | * returns group number on success | 640 | * returns group number on success |
633 | * returns -1 on failure. | 641 | * returns -1 on failure. |
634 | */ | 642 | */ |
635 | int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *friend_group_public_key) | 643 | int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length) |
636 | { | 644 | { |
637 | Messenger *m = tox; | 645 | Messenger *m = tox; |
638 | return join_groupchat(m, friendnumber, friend_group_public_key); | 646 | return join_groupchat(m->group_chat_object, friendnumber, data, length); |
639 | } | 647 | } |
640 | 648 | ||
641 | /* send a group message | 649 | /* send a group message |
642 | * return 0 on success | 650 | * return 0 on success |
643 | * return -1 on failure | 651 | * return -1 on failure |
644 | */ | 652 | */ |
645 | int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint32_t length) | 653 | int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint16_t length) |
646 | { | 654 | { |
647 | Messenger *m = tox; | 655 | Messenger *m = tox; |
648 | return group_message_send(m, groupnumber, message, length); | 656 | return group_message_send(m->group_chat_object, groupnumber, message, length); |
649 | } | 657 | } |
650 | 658 | ||
651 | /* send a group action | 659 | /* send a group action |
652 | * return 0 on success | 660 | * return 0 on success |
653 | * return -1 on failure | 661 | * return -1 on failure |
654 | */ | 662 | */ |
655 | int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint32_t length) | 663 | int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length) |
656 | { | 664 | { |
657 | Messenger *m = tox; | 665 | Messenger *m = tox; |
658 | return group_action_send(m, groupnumber, action, length); | 666 | //return group_action_send(m, groupnumber, action, length); |
667 | return -1; | ||
659 | } | 668 | } |
660 | 669 | ||
661 | /* Return the number of peers in the group chat on success. | 670 | /* Return the number of peers in the group chat on success. |
@@ -664,7 +673,8 @@ int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint | |||
664 | int tox_group_number_peers(const Tox *tox, int groupnumber) | 673 | int tox_group_number_peers(const Tox *tox, int groupnumber) |
665 | { | 674 | { |
666 | const Messenger *m = tox; | 675 | const Messenger *m = tox; |
667 | return group_number_peers(m, groupnumber); | 676 | //return group_number_peers(m, groupnumber); |
677 | return -1; | ||
668 | } | 678 | } |
669 | 679 | ||
670 | /* List all the peers in the group chat. | 680 | /* List all the peers in the group chat. |
@@ -681,7 +691,8 @@ int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX | |||
681 | uint16_t length) | 691 | uint16_t length) |
682 | { | 692 | { |
683 | const Messenger *m = tox; | 693 | const Messenger *m = tox; |
684 | return group_names(m, groupnumber, names, lengths, length); | 694 | //return group_names(m, groupnumber, names, lengths, length); |
695 | return -1; | ||
685 | } | 696 | } |
686 | 697 | ||
687 | /* Return the number of chats in the instance m. | 698 | /* Return the number of chats in the instance m. |
@@ -690,7 +701,8 @@ int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX | |||
690 | uint32_t tox_count_chatlist(const Tox *tox) | 701 | uint32_t tox_count_chatlist(const Tox *tox) |
691 | { | 702 | { |
692 | const Messenger *m = tox; | 703 | const Messenger *m = tox; |
693 | return count_chatlist(m); | 704 | //return count_chatlist(m); |
705 | return 0; | ||
694 | } | 706 | } |
695 | 707 | ||
696 | /* Copy a list of valid chat IDs into the array out_list. | 708 | /* Copy a list of valid chat IDs into the array out_list. |
@@ -701,7 +713,8 @@ uint32_t tox_count_chatlist(const Tox *tox) | |||
701 | uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size) | 713 | uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size) |
702 | { | 714 | { |
703 | const Messenger *m = tox; | 715 | const Messenger *m = tox; |
704 | return copy_chatlist(m, out_list, list_size); | 716 | //return copy_chatlist(m, out_list, list_size); |
717 | return 0; | ||
705 | } | 718 | } |
706 | 719 | ||
707 | 720 | ||
@@ -820,6 +833,12 @@ int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t lengt | |||
820 | return m_set_avatar(m, format, data, length); | 833 | return m_set_avatar(m, format, data, length); |
821 | } | 834 | } |
822 | 835 | ||
836 | int tox_unset_avatar(Tox *tox) | ||
837 | { | ||
838 | Messenger *m = tox; | ||
839 | return m_unset_avatar(m); | ||
840 | } | ||
841 | |||
823 | int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash) | 842 | int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash) |
824 | { | 843 | { |
825 | const Messenger *m = tox; | 844 | const Messenger *m = tox; |
@@ -947,7 +966,14 @@ Tox *tox_new(Tox_Options *options) | |||
947 | } | 966 | } |
948 | } | 967 | } |
949 | 968 | ||
950 | return new_messenger(&m_options); | 969 | Messenger *m = new_messenger(&m_options); |
970 | |||
971 | if (!new_groupchats(m)) { | ||
972 | kill_messenger(m); | ||
973 | return NULL; | ||
974 | } | ||
975 | |||
976 | return m; | ||
951 | } | 977 | } |
952 | 978 | ||
953 | /* Run this before closing shop. | 979 | /* Run this before closing shop. |
@@ -956,6 +982,7 @@ Tox *tox_new(Tox_Options *options) | |||
956 | void tox_kill(Tox *tox) | 982 | void tox_kill(Tox *tox) |
957 | { | 983 | { |
958 | Messenger *m = tox; | 984 | Messenger *m = tox; |
985 | kill_groupchats(m->group_chat_object); | ||
959 | kill_messenger(m); | 986 | kill_messenger(m); |
960 | } | 987 | } |
961 | 988 | ||