comparison libpurple/protocols/jabber/presence.c @ 27502:3bb1085235d0

propagate from branch 'im.pidgin.pidgin' (head 90138fae4d2350d166f730736ecea9ee8e20ecdb) to branch 'im.pidgin.cpw.darkrain42.roster' (head 04af1d94534183574e72b50b268b425b4cac2a33)
author Paul Aurich <paul@darkrain42.org>
date Sun, 12 Jul 2009 02:56:06 +0000
parents 6d26258e9f1d e1090ed76286
children ebd9630ffc77
comparison
equal deleted inserted replaced
27501:6d26258e9f1d 27502:3bb1085235d0
766 real_jid, flags, !delayed); 766 real_jid, flags, !delayed);
767 else 767 else
768 purple_conv_chat_user_set_flags(PURPLE_CONV_CHAT(chat->conv), jid->resource, 768 purple_conv_chat_user_set_flags(PURPLE_CONV_CHAT(chat->conv), jid->resource,
769 flags); 769 flags);
770 } else if (g_str_equal(type, "unavailable")) { 770 } else if (g_str_equal(type, "unavailable")) {
771 xmlnode *x;
771 gboolean nick_change = FALSE; 772 gboolean nick_change = FALSE;
772 gboolean kick = FALSE; 773 gboolean kick = FALSE;
773 gboolean is_our_resource = FALSE; /* Is the presence about us? */ 774 gboolean is_our_resource = FALSE; /* Is the presence about us? */
774 775
775 /* If the chat nick is invalid, we haven't yet joined, or we've 776 /* If the chat nick is invalid, we haven't yet joined, or we've
788 } 789 }
789 790
790 is_our_resource = (0 == g_utf8_collate(jid->resource, chat->handle)); 791 is_our_resource = (0 == g_utf8_collate(jid->resource, chat->handle));
791 792
792 jabber_buddy_remove_resource(jb, jid->resource); 793 jabber_buddy_remove_resource(jb, jid->resource);
793 if(chat->muc) { 794
794 xmlnode *x; 795 x = xmlnode_get_child_with_namespace(packet, "x",
795 for(x = xmlnode_get_child(packet, "x"); x; x = xmlnode_get_next_twin(x)) { 796 "http://jabber.org/protocol/muc#user");
796 const char *xmlns, *nick, *code; 797 if (chat->muc && x) {
797 xmlnode *stat, *item; 798 const char *nick;
798 if(!(xmlns = xmlnode_get_namespace(x)) || 799 const char *code = NULL;
799 strcmp(xmlns, "http://jabber.org/protocol/muc#user")) 800 const char *item_jid = NULL;
800 continue; 801 xmlnode *stat;
801 if(!(stat = xmlnode_get_child(x, "status"))) 802 xmlnode *item;
802 continue; 803
803 if(!(code = xmlnode_get_attrib(stat, "code"))) 804 item = xmlnode_get_child(x, "item");
804 continue; 805 if (item)
805 806 item_jid = xmlnode_get_attrib(item, "jid");
806 item = xmlnode_get_child(x, "item"); 807
807 808
809 stat = xmlnode_get_child(x, "status");
810
811 if (stat)
812 code = xmlnode_get_attrib(stat, "code");
813
814 if (code) {
808 if(!strcmp(code, "301")) { 815 if(!strcmp(code, "301")) {
809 /* XXX: we got banned */ 816 /* XXX: we got banned */
810 } else if(!strcmp(code, "303")) { 817 } else if(!strcmp(code, "303") && item &&
811 if (!item) 818 (nick = xmlnode_get_attrib(item, "nick"))) {
812 continue;
813 if(!(nick = xmlnode_get_attrib(item, "nick")))
814 continue;
815 nick_change = TRUE; 819 nick_change = TRUE;
816 if(!strcmp(jid->resource, chat->handle)) { 820 if(!strcmp(jid->resource, chat->handle)) {
817 g_free(chat->handle); 821 g_free(chat->handle);
818 chat->handle = g_strdup(nick); 822 chat->handle = g_strdup(nick);
819 } 823 }
820 purple_conv_chat_rename_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, nick); 824 purple_conv_chat_rename_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, nick);
821 jabber_chat_remove_handle(chat, jid->resource); 825 jabber_chat_remove_handle(chat, jid->resource);
822 break; 826 /* TODO: Enable this when this is in a for-loop...
827 break; */
823 } else if(!strcmp(code, "307")) { 828 } else if(!strcmp(code, "307")) {
824 /* Someone was kicked from the room */ 829 /* Someone was kicked from the room */
825 xmlnode *reason = NULL, *actor = NULL; 830 xmlnode *reason = NULL, *actor = NULL;
826 const char *actor_name = NULL; 831 const char *actor_name = NULL;
827 char *reason_text = NULL; 832 char *reason_text = NULL;
866 } else if(!strcmp(code, "322")) { 871 } else if(!strcmp(code, "322")) {
867 /* XXX: removed because room is now members-only */ 872 /* XXX: removed because room is now members-only */
868 } else if(!strcmp(code, "332")) { 873 } else if(!strcmp(code, "332")) {
869 /* XXX: removed due to system shutdown */ 874 /* XXX: removed due to system shutdown */
870 } 875 }
876 }
877
878 /*
879 * Possibly another connected resource of our JID (see XEP-0045
880 * v1.24 section 7.1.10) being disconnected. Should be
881 * distinguished by the item_jid.
882 * Also possibly works around bits of an Openfire bug. See
883 * #8319.
884 */
885 if (is_our_resource && !purple_strequal(from, item_jid)) {
886 /* TODO: When the above is a loop, this needs to still act
887 * sanely for all cases (this code is a little fragile). */
888 if (!kick && !nick_change)
889 /* Presumably, kicks and nick changes also affect us. */
890 is_our_resource = FALSE;
871 } 891 }
872 } 892 }
873 if(!nick_change) { 893 if(!nick_change) {
874 if (is_our_resource) { 894 if (is_our_resource) {
875 if (kick) 895 if (kick)