changeset 13384:a580ffe73314

[gaim-migrate @ 15757] jabber updates, including the first half of JEP-0115 support, and maybe the fix for jabber plaintext messages not having their line-endings preserved committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 03 Mar 2006 03:38:36 +0000
parents 07286677b8b8
children 1a965241c8b9
files src/protocols/jabber/disco.c src/protocols/jabber/jabber.c src/protocols/jabber/jabber.h src/protocols/jabber/message.c src/protocols/jabber/presence.c
diffstat 5 files changed, 65 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/jabber/disco.c	Fri Mar 03 03:00:33 2006 +0000
+++ b/src/protocols/jabber/disco.c	Fri Mar 03 03:38:36 2006 +0000
@@ -25,6 +25,7 @@
 #include "buddy.h"
 #include "iq.h"
 #include "disco.h"
+#include "jabber.h"
 
 
 struct _jabber_disco_info_cb_data {
@@ -46,7 +47,17 @@
 
 	if(!strcmp(type, "get")) {
 		xmlnode *query, *identity, *feature;
-		JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
+		JabberIq *iq;
+
+		xmlnode *in_query;
+		const char *node = NULL;
+
+		if((in_query = xmlnode_get_child(packet, "query"))) {
+			node = xmlnode_get_attrib(in_query, "node");
+		}
+
+
+		iq = jabber_iq_new_query(js, JABBER_IQ_RESULT,
 				"http://jabber.org/protocol/disco#info");
 
 		jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id"));
@@ -54,28 +65,46 @@
 		xmlnode_set_attrib(iq->node, "to", from);
 		query = xmlnode_get_child(iq->node, "query");
 
-		identity = xmlnode_new_child(query, "identity");
-		xmlnode_set_attrib(identity, "category", "client");
-		xmlnode_set_attrib(identity, "type", "pc"); /* XXX: bot, console,
-													 * handheld, pc, phone,
-													 * web */
+		if(node)
+			xmlnode_set_attrib(query, "node", node);
+
+		if(!node || !strcmp(node, CAPS0115_NODE "#" VERSION)) {
+
+			identity = xmlnode_new_child(query, "identity");
+			xmlnode_set_attrib(identity, "category", "client");
+			xmlnode_set_attrib(identity, "type", "pc"); /* XXX: bot, console,
+														 * handheld, pc, phone,
+														 * web */
 
-		SUPPORT_FEATURE("jabber:iq:last")
-		SUPPORT_FEATURE("jabber:iq:oob")
-		SUPPORT_FEATURE("jabber:iq:time")
-		SUPPORT_FEATURE("jabber:iq:version")
-		SUPPORT_FEATURE("jabber:x:conference")
-		SUPPORT_FEATURE("http://jabber.org/protocol/bytestreams")
-		SUPPORT_FEATURE("http://jabber.org/protocol/disco#info")
-		SUPPORT_FEATURE("http://jabber.org/protocol/disco#items")
+			SUPPORT_FEATURE("jabber:iq:last")
+			SUPPORT_FEATURE("jabber:iq:oob")
+			SUPPORT_FEATURE("jabber:iq:time")
+			SUPPORT_FEATURE("jabber:iq:version")
+			SUPPORT_FEATURE("jabber:x:conference")
+			SUPPORT_FEATURE("http://jabber.org/protocol/bytestreams")
+			SUPPORT_FEATURE("http://jabber.org/protocol/disco#info")
+			SUPPORT_FEATURE("http://jabber.org/protocol/disco#items")
 #if 0
-		SUPPORT_FEATURE("http://jabber.org/protocol/ibb")
+				SUPPORT_FEATURE("http://jabber.org/protocol/ibb")
 #endif
-		SUPPORT_FEATURE("http://jabber.org/protocol/muc")
-		SUPPORT_FEATURE("http://jabber.org/protocol/muc#user")
-		SUPPORT_FEATURE("http://jabber.org/protocol/si")
-		SUPPORT_FEATURE("http://jabber.org/protocol/si/profile/file-transfer")
-		SUPPORT_FEATURE("http://jabber.org/protocol/xhtml-im")
+			SUPPORT_FEATURE("http://jabber.org/protocol/muc")
+			SUPPORT_FEATURE("http://jabber.org/protocol/muc#user")
+			SUPPORT_FEATURE("http://jabber.org/protocol/si")
+			SUPPORT_FEATURE("http://jabber.org/protocol/si/profile/file-transfer")
+			SUPPORT_FEATURE("http://jabber.org/protocol/xhtml-im")
+		} else {
+			xmlnode *error, *inf;
+
+			/* XXX: gross hack, implement jabber_iq_set_type or something */
+			xmlnode_set_attrib(iq->node, "type", "error");
+			iq->type = JABBER_IQ_ERROR;
+
+			error = xmlnode_new_child(query, "error");
+			xmlnode_set_attrib(error, "code", "404");
+			xmlnode_set_attrib(error, "type", "cancel");
+			inf = xmlnode_new_child(error, "item-not-found");
+			xmlnode_set_attrib(inf, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas");
+		}
 
 		jabber_iq_send(iq);
 	} else if(!strcmp(type, "result")) {
--- a/src/protocols/jabber/jabber.c	Fri Mar 03 03:00:33 2006 +0000
+++ b/src/protocols/jabber/jabber.c	Fri Mar 03 03:38:36 2006 +0000
@@ -912,18 +912,14 @@
 	 * if we were forcibly disconnected because it will crash. -- evands
 	 */
 	if (!gc->disconnect_timeout)
-		jabber_send_raw(js, "</stream:stream>", -1);
-#else
+#endif
 	jabber_send_raw(js, "</stream:stream>", -1);
-#endif
 
 	if(js->gsc) {
 #ifdef HAVE_OPENSSL
 		if (!gc->disconnect_timeout)
+#endif
 			gaim_ssl_close(js->gsc);
-#else
-		gaim_ssl_close(js->gsc);		
-#endif
 	} else if (js->fd > 0) {
 		if(js->gc->inpa)
 			gaim_input_remove(js->gc->inpa);
--- a/src/protocols/jabber/jabber.h	Fri Mar 03 03:00:33 2006 +0000
+++ b/src/protocols/jabber/jabber.h	Fri Mar 03 03:38:36 2006 +0000
@@ -35,6 +35,8 @@
 #include <sasl/sasl.h>
 #endif
 
+#define CAPS0115_NODE "http://gaim.sf.net/caps"
+
 typedef enum {
 	JABBER_CAP_NONE           = 0,
 	JABBER_CAP_XHTML          = 1 << 0,
--- a/src/protocols/jabber/message.c	Fri Mar 03 03:00:33 2006 +0000
+++ b/src/protocols/jabber/message.c	Fri Mar 03 03:38:36 2006 +0000
@@ -283,8 +283,11 @@
 			if(!jm->thread_id)
 				jm->thread_id = xmlnode_get_data(child);
 		} else if(!strcmp(child->name, "body")) {
-			if(!jm->body)
-				jm->body = xmlnode_to_str(child, NULL);
+			if(!jm->body) {
+				char *msg = xmlnode_to_str(child, NULL);
+				jm->body = gaim_strdup_withhtml(msg);
+				g_free(msg);
+			}
 		} else if(!strcmp(child->name, "html")) {
 			if(!jm->xhtml && xmlnode_get_child(child, "body"))
 				jm->xhtml = xmlnode_to_str(child, NULL);
--- a/src/protocols/jabber/presence.c	Fri Mar 03 03:00:33 2006 +0000
+++ b/src/protocols/jabber/presence.c	Fri Mar 03 03:38:36 2006 +0000
@@ -136,13 +136,11 @@
 
 xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority)
 {
-	xmlnode *show, *status, *presence, *pri;
+	xmlnode *show, *status, *presence, *pri, *c;
 	const char *show_string = NULL;
 
-
 	presence = xmlnode_new("presence");
 
-
 	if(state == JABBER_BUDDY_STATE_UNAVAILABLE)
 		xmlnode_set_attrib(presence, "type", "unavailable");
 	else if(state != JABBER_BUDDY_STATE_ONLINE &&
@@ -167,6 +165,12 @@
 		g_free(pstr);
 	}
 
+	/* JEP-0115 */
+	c = xmlnode_new_child(presence, "c");
+	xmlnode_set_attrib(c, "xmlns",  "http://jabber.org/protocol/caps");
+	xmlnode_set_attrib(c, "node", CAPS0115_NODE);
+	xmlnode_set_attrib(c, "ver", VERSION);
+
 	return presence;
 }