comparison libpurple/protocols/jabber/presence.c @ 27862:f05c87f3121e

jabber: Read all MUC status codes in a presence. Fixes #6651. This should also fix any XMPP prpl issues in Adium#12279.
author Paul Aurich <paul@darkrain42.org>
date Sun, 09 Aug 2009 19:08:41 +0000
parents 49cb3fc2c01a
children c585572e80dd
comparison
equal deleted inserted replaced
27861:58c8d6fc3aaf 27862:f05c87f3121e
696 if (type == NULL) { 696 if (type == NULL) {
697 xmlnode *x; 697 xmlnode *x;
698 const char *real_jid = NULL; 698 const char *real_jid = NULL;
699 const char *affiliation = NULL; 699 const char *affiliation = NULL;
700 const char *role = NULL; 700 const char *role = NULL;
701 gboolean is_our_resource = FALSE; /* Is the presence about us? */
701 702
702 /* 703 /*
703 * XEP-0045 mandates the presence to include a resource (which is 704 * XEP-0045 mandates the presence to include a resource (which is
704 * treated as the chat nick). Some non-compliant servers allow 705 * treated as the chat nick). Some non-compliant servers allow
705 * joining without a nick. 706 * joining without a nick.
716 "http://jabber.org/protocol/muc#user"); 717 "http://jabber.org/protocol/muc#user");
717 if (x) { 718 if (x) {
718 xmlnode *status_node; 719 xmlnode *status_node;
719 xmlnode *item_node; 720 xmlnode *item_node;
720 721
721 status_node = xmlnode_get_child(x, "status"); 722 for (status_node = xmlnode_get_child(x, "status"); status_node;
722 if (status_node) { 723 status_node = xmlnode_get_next_twin(status_node)) {
723 const char *code = xmlnode_get_attrib(status_node, "code"); 724 const char *code = xmlnode_get_attrib(status_node, "code");
724 if (purple_strequal(code, "201")) { 725 if (!code)
726 continue;
727
728 if (g_str_equal(code, "110")) {
729 is_our_resource = TRUE;
730 } else if (g_str_equal(code, "201")) {
725 if ((chat = jabber_chat_find(js, jid->node, jid->domain))) { 731 if ((chat = jabber_chat_find(js, jid->node, jid->domain))) {
726 chat->config_dialog_type = PURPLE_REQUEST_ACTION; 732 chat->config_dialog_type = PURPLE_REQUEST_ACTION;
727 chat->config_dialog_handle = 733 chat->config_dialog_handle =
728 purple_request_action(js->gc, 734 purple_request_action(js->gc,
729 _("Create New Room"), 735 _("Create New Room"),
735 purple_connection_get_account(js->gc), NULL, chat->conv, 741 purple_connection_get_account(js->gc), NULL, chat->conv,
736 chat, 2, 742 chat, 2,
737 _("_Configure Room"), G_CALLBACK(jabber_chat_request_room_configure), 743 _("_Configure Room"), G_CALLBACK(jabber_chat_request_room_configure),
738 _("_Accept Defaults"), G_CALLBACK(jabber_chat_create_instant_room)); 744 _("_Accept Defaults"), G_CALLBACK(jabber_chat_create_instant_room));
739 } 745 }
740 } else if (purple_strequal(code, "210")) { 746 } else if (g_str_equal(code, "210")) {
741 /* server rewrote room-nick */ 747 /* server rewrote room-nick */
742 if((chat = jabber_chat_find(js, jid->node, jid->domain))) { 748 if((chat = jabber_chat_find(js, jid->node, jid->domain))) {
743 g_free(chat->handle); 749 g_free(chat->handle);
744 chat->handle = g_strdup(jid->resource); 750 chat->handle = g_strdup(jid->resource);
745 } 751 }
812 818
813 x = xmlnode_get_child_with_namespace(packet, "x", 819 x = xmlnode_get_child_with_namespace(packet, "x",
814 "http://jabber.org/protocol/muc#user"); 820 "http://jabber.org/protocol/muc#user");
815 if (chat->muc && x) { 821 if (chat->muc && x) {
816 const char *nick; 822 const char *nick;
817 const char *code = NULL;
818 const char *item_jid = NULL; 823 const char *item_jid = NULL;
819 const char *to; 824 const char *to;
820 xmlnode *stat; 825 xmlnode *stat;
821 xmlnode *item; 826 xmlnode *item;
822 827
823 item = xmlnode_get_child(x, "item"); 828 item = xmlnode_get_child(x, "item");
824 if (item) 829 if (item)
825 item_jid = xmlnode_get_attrib(item, "jid"); 830 item_jid = xmlnode_get_attrib(item, "jid");
826 831
827 stat = xmlnode_get_child(x, "status"); 832 for (stat = xmlnode_get_child(x, "status"); stat;
828 833 stat = xmlnode_get_next_twin(stat)) {
829 if (stat) 834 const char *code = xmlnode_get_attrib(stat, "code");
830 code = xmlnode_get_attrib(stat, "code"); 835
831 836 if (!code)
832 if (code) { 837 continue;
833 if(!strcmp(code, "301")) { 838
839 if (g_str_equal(code, "110")) {
840 is_our_resource = TRUE;
841 } else if(!strcmp(code, "301")) {
834 /* XXX: we got banned */ 842 /* XXX: we got banned */
835 } else if(!strcmp(code, "303") && item && 843 } else if(!strcmp(code, "303") && item &&
836 (nick = xmlnode_get_attrib(item, "nick"))) { 844 (nick = xmlnode_get_attrib(item, "nick"))) {
837 nick_change = TRUE; 845 nick_change = TRUE;
838 if(!strcmp(jid->resource, chat->handle)) { 846 if(!strcmp(jid->resource, chat->handle)) {
839 g_free(chat->handle); 847 g_free(chat->handle);
840 chat->handle = g_strdup(nick); 848 chat->handle = g_strdup(nick);
841 } 849 }
850
851 /* TODO: This should probably be moved out of the loop */
842 purple_conv_chat_rename_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, nick); 852 purple_conv_chat_rename_user(PURPLE_CONV_CHAT(chat->conv), jid->resource, nick);
843 jabber_chat_remove_handle(chat, jid->resource); 853 jabber_chat_remove_handle(chat, jid->resource);
844 /* TODO: Enable this when this is in a for-loop... 854 continue;
845 break; */
846 } else if(!strcmp(code, "307")) { 855 } else if(!strcmp(code, "307")) {
847 /* Someone was kicked from the room */ 856 /* Someone was kicked from the room */
848 xmlnode *reason = NULL, *actor = NULL; 857 xmlnode *reason = NULL, *actor = NULL;
849 const char *actor_name = NULL; 858 const char *actor_name = NULL;
850 char *reason_text = NULL; 859 char *reason_text = NULL;