cpw.darkrain42.xmpp.iq-handlers: 17897c9d: Fix the implementation of XEP-0202 (Enti...

paul at darkrain42.org paul at darkrain42.org
Tue Feb 3 13:20:41 EST 2009


-----------------------------------------------------------------
Revision: 17897c9d8d1dc956210208cda10460775bc971f5
Ancestor: d949c12854ee58512ea6a3b7e12d22624dc6bd73
Author: paul at darkrain42.org
Date: 2009-02-03T18:14:15
Branch: im.pidgin.cpw.darkrain42.xmpp.iq-handlers
URL: http://d.pidgin.im/viewmtn/revision/info/17897c9d8d1dc956210208cda10460775bc971f5

Modified files:
        libpurple/protocols/jabber/iq.c

ChangeLog: 

Fix the implementation of XEP-0202 (Entity Time) (thanks again to Marcus)

The element for XEP-0202 is <time/>, not <query/>. Fixed the time format,
which was incorrect (%Y%m%d when it should be %Y-%m-%d a.k.a. %F).

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/iq.c	892e75bb540117ab772721a6ed8c8e9dc1a5490b
+++ libpurple/protocols/jabber/iq.c	b144679bc5e17b831c8dfd4808061bc240abbb85
@@ -174,7 +174,7 @@ static void jabber_iq_time_parse(JabberS
 {
 	const char *type, *from, *id, *xmlns;
 	JabberIq *iq;
-	xmlnode *query;
+	xmlnode *child;
 	time_t now_t;
 	struct tm *now;
 
@@ -185,37 +185,41 @@ static void jabber_iq_time_parse(JabberS
 	from = xmlnode_get_attrib(packet, "from");
 	id = xmlnode_get_attrib(packet, "id");
 
-	/* we're gonna throw this away in a moment, but we need it
-	 * to get the xmlns, so we can figure out if this is
-	 * jabber:iq:time or urn:xmpp:time */
-	query = xmlnode_get_child(packet, "query");
-	xmlns = xmlnode_get_namespace(query);
+	if ((child = xmlnode_get_child(packet, "query"))) {
+		xmlns = "jabber:iq:time";
+	} else if ((child = xmlnode_get_child(packet, "time"))) {
+		xmlns = "urn:xmpp:time";
+	} else {
+		purple_debug_warning("jabber", "Malformed IQ time packet\n");
+		return;
+	}
 
 	if(type && !strcmp(type, "get")) {
 		xmlnode *utc;
-		const char *date;
+		const char *date, *tz, *display;
 
-		iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, xmlns);
+		iq = jabber_iq_new(js, JABBER_IQ_RESULT);
 		jabber_iq_set_id(iq, id);
 		xmlnode_set_attrib(iq->node, "to", from);
 
-		query = xmlnode_get_child(iq->node, "query");
+		child = xmlnode_new_child(iq->node, child->name);
+		utc = xmlnode_new_child(child, "utc");
 
-		date = purple_utf8_strftime("%Y%m%dT%T", now);
-		utc = xmlnode_new_child(query, "utc");
-		xmlnode_insert_data(utc, date, -1);
-
 		if(!strcmp("urn:xmpp:time", xmlns)) {
-			xmlnode_insert_data(utc, "Z", 1); /* of COURSE the thing that is the same is different */
+			tz = purple_get_tzoff_str(now, TRUE);
+			xmlnode_insert_data(xmlnode_new_child(child, "tzo"), tz, -1);
 
-			date = purple_get_tzoff_str(now, TRUE);
-			xmlnode_insert_data(xmlnode_new_child(query, "tzo"), date, -1);
+			date = purple_utf8_strftime("%FT%TZ", now);
+			xmlnode_insert_data(utc, date, -1);
 		} else { /* jabber:iq:time */
-			date = purple_utf8_strftime("%Z", now);
-			xmlnode_insert_data(xmlnode_new_child(query, "tz"), date, -1);
+			tz = purple_utf8_strftime("%Z", now);
+			xmlnode_insert_data(xmlnode_new_child(child, "tz"), tz, -1);
 
-			date = purple_utf8_strftime("%d %b %Y %T", now);
-			xmlnode_insert_data(xmlnode_new_child(query, "display"), date, -1);
+			date = purple_utf8_strftime("%Y%m%dT%T", now);
+			xmlnode_insert_data(utc, date, -1);
+
+			display = purple_utf8_strftime("%d %b %Y %T", now);
+			xmlnode_insert_data(xmlnode_new_child(child, "display"), display, -1);
 		}
 
 		jabber_iq_send(iq);


More information about the Commits mailing list