Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/disco.c @ 26340:b5fe3f47487b
jabber_disco_items_do(), which functions like jabber_disco_info_do.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Tue, 31 Mar 2009 06:58:26 +0000 |
parents | ce23e32a0ada |
children | 9d0bad6f4b0d |
comparison
equal
deleted
inserted
replaced
26339:ce23e32a0ada | 26340:b5fe3f47487b |
---|---|
38 #include "libpurple/disco.h" | 38 #include "libpurple/disco.h" |
39 | 39 |
40 struct _jabber_disco_info_cb_data { | 40 struct _jabber_disco_info_cb_data { |
41 gpointer data; | 41 gpointer data; |
42 JabberDiscoInfoCallback *callback; | 42 JabberDiscoInfoCallback *callback; |
43 }; | |
44 | |
45 struct _jabber_disco_items_cb_data { | |
46 gpointer data; | |
47 JabberDiscoItemsCallback *callback; | |
43 }; | 48 }; |
44 | 49 |
45 #define SUPPORT_FEATURE(x) { \ | 50 #define SUPPORT_FEATURE(x) { \ |
46 feature = xmlnode_new_child(query, "feature"); \ | 51 feature = xmlnode_new_child(query, "feature"); \ |
47 xmlnode_set_attrib(feature, "var", x); \ | 52 xmlnode_set_attrib(feature, "var", x); \ |
551 { | 556 { |
552 JabberID *jid; | 557 JabberID *jid; |
553 JabberBuddy *jb; | 558 JabberBuddy *jb; |
554 JabberBuddyResource *jbr = NULL; | 559 JabberBuddyResource *jbr = NULL; |
555 struct _jabber_disco_info_cb_data *jdicd; | 560 struct _jabber_disco_info_cb_data *jdicd; |
556 const char *id; | 561 char *id; |
557 JabberIq *iq; | 562 JabberIq *iq; |
558 | 563 |
559 if((jid = jabber_id_new(who))) { | 564 if((jid = jabber_id_new(who))) { |
560 if(jid->resource && (jb = jabber_buddy_find(js, who, TRUE))) | 565 if(jid->resource && (jb = jabber_buddy_find(js, who, TRUE))) |
561 jbr = jabber_buddy_find_resource(jb, jid->resource); | 566 jbr = jabber_buddy_find_resource(jb, jid->resource); |
1019 jabber_register_gateway(js, purple_disco_service_get_name(service)); | 1024 jabber_register_gateway(js, purple_disco_service_get_name(service)); |
1020 | 1025 |
1021 return 0; | 1026 return 0; |
1022 } | 1027 } |
1023 | 1028 |
1029 static void | |
1030 jabber_disco_items_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
1031 { | |
1032 struct _jabber_disco_items_cb_data *jdicd; | |
1033 xmlnode *query, *child; | |
1034 const char *from; | |
1035 const char *type; | |
1036 GSList *items = NULL; | |
1037 | |
1038 jdicd = data; | |
1039 | |
1040 from = xmlnode_get_attrib(packet, "from"); | |
1041 type = xmlnode_get_attrib(packet, "type"); | |
1042 query = xmlnode_get_child(packet, "query"); | |
1043 | |
1044 if (!from || !strcmp(type, "error") || !query) { | |
1045 jdicd->callback(js, NULL, jdicd->data); | |
1046 g_free(jdicd); | |
1047 return; | |
1048 } | |
1049 | |
1050 for (child = xmlnode_get_child(query, "item"); child; | |
1051 child = xmlnode_get_next_twin(child)) { | |
1052 JabberDiscoItem *item; | |
1053 | |
1054 item = g_new0(JabberDiscoItem, 1); | |
1055 item->jid = g_strdup(xmlnode_get_attrib(child, "jid")); | |
1056 item->node = g_strdup(xmlnode_get_attrib(child, "node")); | |
1057 item->name = g_strdup(xmlnode_get_attrib(child, "name")); | |
1058 | |
1059 items = g_slist_prepend(items, item); | |
1060 } | |
1061 | |
1062 items = g_slist_reverse(items); | |
1063 jdicd->callback(js, items, jdicd->data); | |
1064 g_free(jdicd); | |
1065 } | |
1066 | |
1067 void jabber_disco_items_do(JabberStream *js, const char *who, | |
1068 JabberDiscoItemsCallback *callback, gpointer data) | |
1069 { | |
1070 struct _jabber_disco_items_cb_data *jdicd; | |
1071 JabberIq *iq; | |
1072 | |
1073 jdicd = g_new0(struct _jabber_disco_items_cb_data, 1); | |
1074 jdicd->data = data; | |
1075 jdicd->callback = callback; | |
1076 | |
1077 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items"); | |
1078 xmlnode_set_attrib(iq->node, "to", who); | |
1079 | |
1080 jabber_iq_set_callback(iq, jabber_disco_items_cb, jdicd); | |
1081 jabber_iq_send(iq); | |
1082 } | |
1083 | |
1084 void jabber_disco_item_free(JabberDiscoItem *item) | |
1085 { | |
1086 g_free((char *)item->jid); | |
1087 g_free((char *)item->node); | |
1088 g_free((char *)item->name); | |
1089 g_free(item); | |
1090 } |