comparison libpurple/protocols/jabber/disco.c @ 26690:9fb8d8d9783a

Move the handling of chat rooms to jabber_disco_service_items_cb. This saves us from (needlessly) disco#info'ing the conference server once per chat, which adds up when you're testing against jabber.org.
author Paul Aurich <paul@darkrain42.org>
date Wed, 15 Apr 2009 04:38:28 +0000
parents 217a3ad87fc4
children 464dbfad4474
comparison
equal deleted inserted replaced
26689:1009214ba476 26690:9fb8d8d9783a
674 GSList *l; 674 GSList *l;
675 struct _disco_data *disco_data; 675 struct _disco_data *disco_data;
676 struct jabber_disco_list_data *list_data; 676 struct jabber_disco_list_data *list_data;
677 PurpleDiscoList *list; 677 PurpleDiscoList *list;
678 PurpleDiscoService *parent; 678 PurpleDiscoService *parent;
679 PurpleDiscoServiceType parent_type;
679 const char *parent_node; 680 const char *parent_node;
680 gboolean has_items = FALSE;
681 681
682 disco_data = data; 682 disco_data = data;
683 list_data = disco_data->list_data; 683 list_data = disco_data->list_data;
684 list = list_data->list; 684 list = list_data->list;
685 685
699 purple_disco_list_unref(list); 699 purple_disco_list_unref(list);
700 return; 700 return;
701 } 701 }
702 702
703 parent = disco_data->parent; 703 parent = disco_data->parent;
704 parent_type = purple_disco_service_get_type(parent);
704 parent_node = disco_data->node; 705 parent_node = disco_data->node;
705 706
706 for (l = items; l; l = l->next) { 707 for (l = items; l; l = l->next) {
707 JabberDiscoItem *item = l->data; 708 JabberDiscoItem *item = l->data;
708 JabberIq *iq; 709
709 struct _disco_data *req_data; 710 if (parent_type & PURPLE_DISCO_SERVICE_TYPE_CHAT) {
710 char *full_node; 711 /* A chat server's items are chats. I promise. */
711 712 PurpleDiscoService *service;
712 if (parent_node) { 713 struct jabber_disco_service_data *service_data;
713 if (item->node) { 714 JabberID *jid = jabber_id_new(item->jid);
714 full_node = g_strdup_printf("%s/%s", parent_node, item->node); 715
715 } else { 716 if (jid) {
716 continue; 717 service_data = g_new0(struct jabber_disco_service_data, 1);
718 service_data->jid = g_strdup(item->jid);
719
720 service = purple_disco_list_service_new(PURPLE_DISCO_SERVICE_TYPE_CHAT,
721 jid->node, item->name, PURPLE_DISCO_ADD, service_data);
722
723 purple_disco_list_service_add(list, service, parent);
724
725 jabber_id_free(jid);
717 } 726 }
718 } else { 727 } else {
719 full_node = g_strdup(item->node); 728 JabberIq *iq;
729 struct _disco_data *req_data;
730 char *full_node;
731
732 if (parent_node && !item->node)
733 continue;
734
735 if (parent_node)
736 full_node = g_strconcat(parent_node, "/", item->node, NULL);
737 else
738 full_node = g_strdup(item->node);
739
740 req_data = g_new0(struct _disco_data, 1);
741 req_data->list_data = list_data;
742 req_data->parent = parent;
743 req_data->node = full_node;
744
745 ++list_data->fetch_count;
746 purple_disco_list_ref(list);
747
748 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
749 xmlnode_set_attrib(iq->node, "to", item->jid);
750 if (full_node)
751 xmlnode_set_attrib(xmlnode_get_child(iq->node, "query"),
752 "node", full_node);
753 jabber_iq_set_callback(iq, jabber_disco_service_info_cb, req_data);
754
755 jabber_iq_send(iq);
720 } 756 }
721
722 req_data = g_new0(struct _disco_data, 1);
723 req_data->list_data = list_data;
724 req_data->parent = parent;
725 req_data->node = full_node;
726
727 has_items = TRUE;
728
729 ++list_data->fetch_count;
730 purple_disco_list_ref(list);
731
732 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
733 xmlnode_set_attrib(iq->node, "to", item->jid);
734 if (full_node)
735 xmlnode_set_attrib(xmlnode_get_child(iq->node, "query"),
736 "node", full_node);
737 jabber_iq_set_callback(iq, jabber_disco_service_info_cb, req_data);
738
739 jabber_iq_send(iq);
740 } 757 }
741 758
742 g_slist_foreach(items, (GFunc)jabber_disco_item_free, NULL); 759 g_slist_foreach(items, (GFunc)jabber_disco_item_free, NULL);
743 g_slist_free(items); 760 g_slist_free(items);
744 761
818 service_type = PURPLE_DISCO_SERVICE_TYPE_CHAT; 835 service_type = PURPLE_DISCO_SERVICE_TYPE_CHAT;
819 } 836 }
820 } 837 }
821 838
822 if ((anode = xmlnode_get_attrib(query, "node"))) 839 if ((anode = xmlnode_get_attrib(query, "node")))
823 aname = g_strdup_printf("%s%s", from, anode); 840 aname = g_strconcat(from, anode, NULL);
824 else 841 else
825 aname = g_strdup(from); 842 aname = g_strdup(from);
826 843
827 service_data = g_new0(struct jabber_disco_service_data, 1); 844 service_data = g_new0(struct jabber_disco_service_data, 1);
828 service_data->jid = g_strdup(from); 845 service_data->jid = g_strdup(from);