cpw.darkrain42.xmpp.disco: f5084a8b: jabber_disco_items_do(), which functions...
paul at darkrain42.org
paul at darkrain42.org
Sat Apr 25 16:18:02 EDT 2009
-----------------------------------------------------------------
Revision: f5084a8ba566c7579bfab69658d673e41fbaaf4f
Ancestor: 0b3b2fbcf7c37afe5fe95c06a5f52be4a84e7c9f
Author: paul at darkrain42.org
Date: 2009-03-31T06:58:26
Branch: im.pidgin.cpw.darkrain42.xmpp.disco
URL: http://d.pidgin.im/viewmtn/revision/info/f5084a8ba566c7579bfab69658d673e41fbaaf4f
Modified files:
libpurple/protocols/jabber/disco.c
libpurple/protocols/jabber/disco.h
ChangeLog:
jabber_disco_items_do(), which functions like jabber_disco_info_do.
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/disco.c 43dc72d4718708a7d4d93371bdd0d6916f06d462
+++ libpurple/protocols/jabber/disco.c f5a205f6da2e54139792dce578323c82fe5d3ad0
@@ -42,6 +42,11 @@ struct _jabber_disco_info_cb_data {
JabberDiscoInfoCallback *callback;
};
+struct _jabber_disco_items_cb_data {
+ gpointer data;
+ JabberDiscoItemsCallback *callback;
+};
+
#define SUPPORT_FEATURE(x) { \
feature = xmlnode_new_child(query, "feature"); \
xmlnode_set_attrib(feature, "var", x); \
@@ -553,7 +558,7 @@ void jabber_disco_info_do(JabberStream *
JabberBuddy *jb;
JabberBuddyResource *jbr = NULL;
struct _jabber_disco_info_cb_data *jdicd;
- const char *id;
+ char *id;
JabberIq *iq;
if((jid = jabber_id_new(who))) {
@@ -1021,3 +1026,65 @@ jabber_disco_service_register(PurpleConn
return 0;
}
+static void
+jabber_disco_items_cb(JabberStream *js, xmlnode *packet, gpointer data)
+{
+ struct _jabber_disco_items_cb_data *jdicd;
+ xmlnode *query, *child;
+ const char *from;
+ const char *type;
+ GSList *items = NULL;
+
+ jdicd = data;
+
+ from = xmlnode_get_attrib(packet, "from");
+ type = xmlnode_get_attrib(packet, "type");
+ query = xmlnode_get_child(packet, "query");
+
+ if (!from || !strcmp(type, "error") || !query) {
+ jdicd->callback(js, NULL, jdicd->data);
+ g_free(jdicd);
+ return;
+ }
+
+ for (child = xmlnode_get_child(query, "item"); child;
+ child = xmlnode_get_next_twin(child)) {
+ JabberDiscoItem *item;
+
+ item = g_new0(JabberDiscoItem, 1);
+ item->jid = g_strdup(xmlnode_get_attrib(child, "jid"));
+ item->node = g_strdup(xmlnode_get_attrib(child, "node"));
+ item->name = g_strdup(xmlnode_get_attrib(child, "name"));
+
+ items = g_slist_prepend(items, item);
+ }
+
+ items = g_slist_reverse(items);
+ jdicd->callback(js, items, jdicd->data);
+ g_free(jdicd);
+}
+
+void jabber_disco_items_do(JabberStream *js, const char *who,
+ JabberDiscoItemsCallback *callback, gpointer data)
+{
+ struct _jabber_disco_items_cb_data *jdicd;
+ JabberIq *iq;
+
+ jdicd = g_new0(struct _jabber_disco_items_cb_data, 1);
+ jdicd->data = data;
+ jdicd->callback = callback;
+
+ iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items");
+ xmlnode_set_attrib(iq->node, "to", who);
+
+ jabber_iq_set_callback(iq, jabber_disco_items_cb, jdicd);
+ jabber_iq_send(iq);
+}
+
+void jabber_disco_item_free(JabberDiscoItem *item)
+{
+ g_free((char *)item->jid);
+ g_free((char *)item->node);
+ g_free((char *)item->name);
+ g_free(item);
+}
============================================================
--- libpurple/protocols/jabber/disco.h 06d3b22de8e170e8598344b7bd49e46988bec16c
+++ libpurple/protocols/jabber/disco.h 929aa336df6927f1edb475f719e59ffe5a319811
@@ -24,9 +24,18 @@
#include "jabber.h"
+typedef struct _JabberDiscoItem {
+ const char *jid; /* MUST */
+ const char *node; /* SHOULD */
+ const char *name; /* MAY */
+} JabberDiscoItem;
+
typedef void (JabberDiscoInfoCallback)(JabberStream *js, const char *who,
JabberCapabilities capabilities, gpointer data);
+typedef void (JabberDiscoItemsCallback)(JabberStream *js,
+ GSList *items, gpointer data);
+
void jabber_disco_info_parse(JabberStream *js, xmlnode *packet);
void jabber_disco_items_parse(JabberStream *js, xmlnode *packet);
@@ -40,4 +49,9 @@ int jabber_disco_service_register(Purple
int jabber_disco_service_register(PurpleConnection *gc, PurpleDiscoService *service);
+
+void jabber_disco_items_do(JabberStream *js, const char *jid,
+ JabberDiscoItemsCallback *callback, gpointer data);
+void jabber_disco_item_free(JabberDiscoItem *);
+
#endif /* _PURPLE_JABBER_DISCO_H_ */
More information about the Commits
mailing list