comparison libpurple/protocols/jabber/presence.c @ 27444:c4196cd47602

Add support for XEP-0045 code 307 (a.k.a. kicks).
author Paul Aurich <paul@darkrain42.org>
date Sun, 05 Jul 2009 23:55:56 +0000
parents da8d20538145
children eff7db4db632
comparison
equal deleted inserted replaced
27443:1a563a740c7f 27444:c4196cd47602
688 } 688 }
689 689
690 690
691 if(type && !strcmp(type, "unavailable")) { 691 if(type && !strcmp(type, "unavailable")) {
692 gboolean nick_change = FALSE; 692 gboolean nick_change = FALSE;
693 gboolean kick = FALSE;
694 gboolean is_our_resource = FALSE; /* Is the presence about us? */
693 695
694 /* If the chat nick is invalid, we haven't yet joined, or we've 696 /* If the chat nick is invalid, we haven't yet joined, or we've
695 * already left (it was probably us leaving after we closed the 697 * already left (it was probably us leaving after we closed the
696 * chat), we don't care. 698 * chat), we don't care.
697 */ 699 */
704 g_free(avatar_hash); 706 g_free(avatar_hash);
705 g_free(nickname); 707 g_free(nickname);
706 return; 708 return;
707 } 709 }
708 710
711 is_our_resource = (0 == g_utf8_collate(jid->resource, chat->handle));
712
709 jabber_buddy_remove_resource(jb, jid->resource); 713 jabber_buddy_remove_resource(jb, jid->resource);
710 if(chat->muc) { 714 if(chat->muc) {
711 xmlnode *x; 715 xmlnode *x;
712 for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { 716 for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) {
713 const char *xmlns, *nick, *code; 717 const char *xmlns, *nick, *code;
717 continue; 721 continue;
718 if(!(stat = xmlnode_get_child(x, "status"))) 722 if(!(stat = xmlnode_get_child(x, "status")))
719 continue; 723 continue;
720 if(!(code = xmlnode_get_attrib(stat, "code"))) 724 if(!(code = xmlnode_get_attrib(stat, "code")))
721 continue; 725 continue;
726
727 item = xmlnode_get_child(x, "item");
728
722 if(!strcmp(code, "301")) { 729 if(!strcmp(code, "301")) {
723 /* XXX: we got banned */ 730 /* XXX: we got banned */
724 } else if(!strcmp(code, "303")) { 731 } else if(!strcmp(code, "303")) {
725 if(!(item = xmlnode_get_child(x, "item"))) 732 if (!item)
726 continue; 733 continue;
727 if(!(nick = xmlnode_get_attrib(item, "nick"))) 734 if(!(nick = xmlnode_get_attrib(item, "nick")))
728 continue; 735 continue;
729 nick_change = TRUE; 736 nick_change = TRUE;
730 if(!strcmp(jid->resource, chat->handle)) { 737 if(!strcmp(jid->resource, chat->handle)) {
733 } 740 }
734 purple_conv_chat_rename_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, nick); 741 purple_conv_chat_rename_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, nick);
735 jabber_chat_remove_handle(chat, jid->resource); 742 jabber_chat_remove_handle(chat, jid->resource);
736 break; 743 break;
737 } else if(!strcmp(code, "307")) { 744 } else if(!strcmp(code, "307")) {
738 /* XXX: we got kicked */ 745 /* Someone was kicked from the room */
746 xmlnode *reason = NULL, *actor = NULL;
747 const char *actor_name = NULL;
748 char *reason_text = NULL;
749 char *tmp;
750
751 kick = TRUE;
752
753 if (item) {
754 reason = xmlnode_get_child(item, "reason");
755 actor = xmlnode_get_child(item, "actor");
756
757 if (reason != NULL)
758 reason_text = xmlnode_get_data(reason);
759 if (actor != NULL)
760 actor_name = xmlnode_get_attrib(actor, "jid");
761 }
762
763 if (reason_text == NULL)
764 reason_text = g_strdup(_("No reason"));
765
766 if (is_our_resource) {
767 if (actor_name != NULL)
768 tmp = g_strdup_printf(_("You have been kicked by %s: (%s)"),
769 actor_name, reason_text);
770 else
771 tmp = g_strdup_printf(_("You have been kicked: (%s)"),
772 reason_text);
773 } else {
774 if (actor_name != NULL)
775 tmp = g_strdup_printf(_("Kicked by %s (%s)"),
776 actor_name, reason_text);
777 else
778 tmp = g_strdup_printf(_("Kicked (%s)"),
779 reason_text);
780 }
781
782 g_free(reason_text);
783 g_free(status);
784 status = tmp;
739 } else if(!strcmp(code, "321")) { 785 } else if(!strcmp(code, "321")) {
740 /* XXX: removed due to an affiliation change */ 786 /* XXX: removed due to an affiliation change */
741 } else if(!strcmp(code, "322")) { 787 } else if(!strcmp(code, "322")) {
742 /* XXX: removed because room is now members-only */ 788 /* XXX: removed because room is now members-only */
743 } else if(!strcmp(code, "332")) { 789 } else if(!strcmp(code, "332")) {
744 /* XXX: removed due to system shutdown */ 790 /* XXX: removed due to system shutdown */
745 } 791 }
746 } 792 }
747 } 793 }
748 if(!nick_change) { 794 if(!nick_change) {
749 if(!g_utf8_collate(jid->resource, chat->handle)) { 795 if (is_our_resource) {
796 if (kick)
797 purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), jid->resource,
798 status, PURPLE_MESSAGE_SYSTEM, time(NULL));
799
750 serv_got_chat_left(js->gc, chat->id); 800 serv_got_chat_left(js->gc, chat->id);
751 jabber_chat_destroy(chat); 801 jabber_chat_destroy(chat);
752 } else { 802 } else {
753 purple_conv_chat_remove_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, 803 purple_conv_chat_remove_user(PURPLE_CONV_CHAT(chat->conv), jid->resource,
754 status); 804 status);