cpw.darkrain42.xmpp.disco: 1f8b779c: Split the jabber_disco_info_do IQ callba...
paul at darkrain42.org
paul at darkrain42.org
Sat Apr 25 16:16:23 EDT 2009
-----------------------------------------------------------------
Revision: 1f8b779c8bb884431c03c752a57a9a0a1a9a3195
Ancestor: 8fd65bcf7fdc714eb9482f169a3b736e98359f64
Author: paul at darkrain42.org
Date: 2009-04-13T04:34:17
Branch: im.pidgin.cpw.darkrain42.xmpp.disco
URL: http://d.pidgin.im/viewmtn/revision/info/1f8b779c8bb884431c03c752a57a9a0a1a9a3195
Modified files:
libpurple/protocols/jabber/disco.c
libpurple/protocols/jabber/jabber.c
libpurple/protocols/jabber/jabber.h
ChangeLog:
Split the jabber_disco_info_do IQ callback from the IQ handler and use the IQ callback semantics.
How often do we get to remove something from the JabberStream?
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/disco.c 80a0c8afbec055a1793e0e092b63b6ac11fccee8
+++ libpurple/protocols/jabber/disco.c 8cef5fe2aa517e044c9987fe0a23791c8ce6124a
@@ -218,13 +218,42 @@ void jabber_disco_info_parse(JabberStrea
}
jabber_iq_send(iq);
- } else if(type == JABBER_IQ_RESULT) {
+ } else if (type == JABBER_IQ_SET) {
+ /* wtf? seriously. wtf? */
+ JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR);
+ xmlnode *error, *bad_request;
+
+ /* Free the <query/> */
+ xmlnode_free(xmlnode_get_child(iq->node, "query"));
+ /* Add an error */
+ error = xmlnode_new_child(iq->node, "error");
+ xmlnode_set_attrib(error, "type", "modify");
+ bad_request = xmlnode_new_child(error, "bad-request");
+ xmlnode_set_namespace(bad_request, "urn:ietf:params:xml:ns:xmpp-stanzas");
+
+ jabber_iq_set_id(iq, id);
+ xmlnode_set_attrib(iq->node, "to", from);
+
+ jabber_iq_send(iq);
+ }
+}
+
+static void jabber_disco_info_cb(JabberStream *js, const char *from,
+ JabberIqType type, const char *id,
+ xmlnode *packet, gpointer data)
+{
+ struct _jabber_disco_info_cb_data *jdicd = data;
+ xmlnode *query;
+
+ query = xmlnode_get_child_with_namespace(packet, "query",
+ "http://jabber.org/protocol/disco#info");
+
+ if (type == JABBER_IQ_RESULT && query) {
xmlnode *child;
JabberID *jid;
JabberBuddy *jb;
JabberBuddyResource *jbr = NULL;
JabberCapabilities capabilities = JABBER_CAP_NONE;
- struct _jabber_disco_info_cb_data *jdicd;
if((jid = jabber_id_new(from))) {
if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE)))
@@ -235,7 +264,7 @@ void jabber_disco_info_parse(JabberStrea
if(jbr)
capabilities = jbr->capabilities;
- for(child = in_query->child; child; child = child->next) {
+ for(child = query->child; child; child = child->next) {
if(child->type != XMLNODE_TYPE_TAG)
continue;
@@ -304,20 +333,13 @@ void jabber_disco_info_parse(JabberStrea
if(jbr)
jbr->capabilities = capabilities;
- if((jdicd = g_hash_table_lookup(js->disco_callbacks, id))) {
- jdicd->callback(js, from, capabilities, jdicd->data);
- g_hash_table_remove(js->disco_callbacks, id);
- }
- } else if(type == JABBER_IQ_ERROR) {
+ jdicd->callback(js, from, capabilities, jdicd->data);
+ } else { /* type == JABBER_IQ_ERROR or query == NULL */
JabberID *jid;
JabberBuddy *jb;
JabberBuddyResource *jbr = NULL;
JabberCapabilities capabilities = JABBER_CAP_NONE;
- struct _jabber_disco_info_cb_data *jdicd;
- if(!(jdicd = g_hash_table_lookup(js->disco_callbacks, id)))
- return;
-
if((jid = jabber_id_new(from))) {
if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE)))
jbr = jabber_buddy_find_resource(jb, jid->resource);
@@ -328,7 +350,6 @@ void jabber_disco_info_parse(JabberStrea
capabilities = jbr->capabilities;
jdicd->callback(js, from, capabilities, jdicd->data);
- g_hash_table_remove(js->disco_callbacks, id);
}
}
@@ -556,7 +577,6 @@ void jabber_disco_info_do(JabberStream *
JabberBuddy *jb;
JabberBuddyResource *jbr = NULL;
struct _jabber_disco_info_cb_data *jdicd;
- char *id;
JabberIq *iq;
if((jid = jabber_id_new(who))) {
@@ -577,10 +597,7 @@ void jabber_disco_info_do(JabberStream *
iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
xmlnode_set_attrib(iq->node, "to", who);
- id = jabber_get_next_id(js);
- jabber_iq_set_id(iq, id);
- g_hash_table_insert(js->disco_callbacks, id, jdicd);
-
+ jabber_iq_set_callback(iq, jabber_disco_info_cb, jdicd);
jabber_iq_send(iq);
}
============================================================
--- libpurple/protocols/jabber/jabber.c a3cf207f47441ac391f6ed6b4469590ef3a5e81b
+++ libpurple/protocols/jabber/jabber.c 5939bd164d6afda1e0dc4f6fe63af62d4adb6a85
@@ -709,8 +709,6 @@ jabber_login(PurpleAccount *account)
js->fd = -1;
js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, g_free);
- js->disco_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
- g_free, g_free);
js->buddies = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, (GDestroyNotify)jabber_buddy_free);
js->chats = g_hash_table_new_full(g_str_hash, g_str_equal,
@@ -1201,8 +1199,6 @@ void jabber_register_account(PurpleAccou
js->registration = TRUE;
js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, g_free);
- js->disco_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
- g_free, g_free);
js->user = jabber_id_new(purple_account_get_username(account));
js->next_id = g_random_int();
js->old_length = 0;
@@ -1357,8 +1353,6 @@ void jabber_close(PurpleConnection *gc)
if(js->iq_callbacks)
g_hash_table_destroy(js->iq_callbacks);
- if(js->disco_callbacks)
- g_hash_table_destroy(js->disco_callbacks);
if(js->buddies)
g_hash_table_destroy(js->buddies);
if(js->chats)
============================================================
--- libpurple/protocols/jabber/jabber.h b2c4378deab9cde8c72d723d6258baede8f614d2
+++ libpurple/protocols/jabber/jabber.h 2a7b5e5981dda430a5bca7f61196c7009ee18935
@@ -152,7 +152,6 @@ struct _JabberStream
GList *user_directories;
GHashTable *iq_callbacks;
- GHashTable *disco_callbacks;
int next_id;
GList *bs_proxies;
More information about the Commits
mailing list