# HG changeset patch # User Mikael Berthe # Date 1134667754 -3600 # Node ID cf722bff65792efc59fdbe001175ecf800e11d01 # Parent 0b4ed231ebc28416ee4110f7c367b000649bdaee Improve IQ management diff -r 0b4ed231ebc2 -r cf722bff6579 mcabber/src/jab_iq.c --- a/mcabber/src/jab_iq.c Thu Dec 15 15:40:21 2005 +0100 +++ b/mcabber/src/jab_iq.c Thu Dec 15 18:29:14 2005 +0100 @@ -164,7 +164,9 @@ if (!strcmp(ns, NS_ROSTER)) { handle_iq_roster(x); - // Post-login stuff FIXME shouldn't be there + // Post-login stuff + // Usually we request the roster only at connection time + // so we should be there only once. (That's ugly, however) jb_setstatus(available, NULL, NULL); } } @@ -175,12 +177,16 @@ xmlnode x, y, z; id = xmlnode_get_attrib(xmldata, "id"); - if (!id) return; + if (!id) { + scr_LogPrint(LPRINT_LOG, "IQ get stanza with no ID, ignored."); + return; + } // Nothing implemented yet. - x = xmlnode_new_tag("iq"); - xmlnode_put_attrib(x, "to", from); - xmlnode_put_attrib(x, "id", id); + x = xmlnode_dup(xmldata); + xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from")); + xmlnode_hide_attrib(x, "from"); + xmlnode_put_attrib(x, "type", TMSG_ERROR); y = xmlnode_insert_tag(x, TMSG_ERROR); xmlnode_put_attrib(y, "code", "501"); @@ -194,22 +200,42 @@ static void handle_iq_set(jconn conn, char *from, xmlnode xmldata) { - char *id; + char *id, *ns; xmlnode x, y, z; + guint iq_error = FALSE; id = xmlnode_get_attrib(xmldata, "id"); + if (!id) + scr_LogPrint(LPRINT_LOG, "IQ set stanza with no ID..."); + + x = xmlnode_get_tag(xmldata, "query"); + ns = xmlnode_get_attrib(x, "xmlns"); + if (ns && !strcmp(ns, NS_ROSTER)) { + handle_iq_roster(x); + } else { + iq_error = TRUE; + } + if (!id) return; - /* Not implemented yet: send an error stanza */ - x = xmlnode_new_tag("iq"); - xmlnode_put_attrib(x, "to", from); - xmlnode_put_attrib(x, "id", id); - xmlnode_put_attrib(x, "type", TMSG_ERROR); - y = xmlnode_insert_tag(x, TMSG_ERROR); - xmlnode_put_attrib(y, "code", "501"); - xmlnode_put_attrib(y, "type", "cancel"); - z = xmlnode_insert_tag(y, "feature-not-implemented"); - xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS); + if (!iq_error) { + x = xmlnode_new_tag("iq"); + xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from")); + xmlnode_put_attrib(x, "type", "result"); + xmlnode_put_attrib(x, "id", id); + } else { + /* Not implemented yet: send an error stanza */ + x = xmlnode_dup(xmldata); + xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from")); + xmlnode_hide_attrib(x, "from"); + xmlnode_put_attrib(x, "type", "result"); + xmlnode_put_attrib(x, "type", TMSG_ERROR); + y = xmlnode_insert_tag(x, TMSG_ERROR); + xmlnode_put_attrib(y, "code", "501"); + xmlnode_put_attrib(y, "type", "cancel"); + z = xmlnode_insert_tag(y, "feature-not-implemented"); + xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS); + } jab_send(conn, x); xmlnode_free(x); diff -r 0b4ed231ebc2 -r cf722bff6579 mcabber/src/roster.c --- a/mcabber/src/roster.c Thu Dec 15 15:40:21 2005 +0100 +++ b/mcabber/src/roster.c Thu Dec 15 18:29:14 2005 +0100 @@ -277,7 +277,19 @@ // #1 Check this user doesn't already exist slist = roster_find(jid, jidsearch, 0); - if (slist) return slist; + if (slist) { + char *oldgroupname; + // That's an update + roster_usr = slist->data; + roster_usr->subscription = esub; + if (name) + buddy_setname(slist->data, (char*)name); + // Let's check if the group name has changed + oldgroupname = ((roster*)((GSList*)roster_usr->list)->data)->name; + if (group && strcmp(oldgroupname, group)) + buddy_setgroup(slist->data, (char*)group); + return slist; + } // #2 add group if necessary slist = roster_add_group(group); if (!slist) return NULL;