pidgin: 2cc8e434: Some improvements to XMPP resource handl...

rekkanoryo at pidgin.im rekkanoryo at pidgin.im
Thu Nov 27 21:50:27 EST 2008


-----------------------------------------------------------------
Revision: 2cc8e4346c2748d5b7e177197f54e0146fca809d
Ancestor: 562440c4278856c6e9180b018e1dedae4b7476bc
Author: jsailor at jesnetplus.com
Date: 2008-11-28T02:19:42
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/2cc8e4346c2748d5b7e177197f54e0146fca809d

Modified files:
        COPYRIGHT ChangeLog libpurple/protocols/jabber/jabber.c

ChangeLog: 

Some improvements to XMPP resource handling:
	* Blank resources cause us to expect the server to assign one to us.
	* Using "__HOSTNAME__" as the resource will cause us to replace this
	  string with the actual hostname of the machine we're running on.

Fixes #5565.

-------------- next part --------------
============================================================
--- COPYRIGHT	3d5c7fd18d659379535ddd39dbb1851e9bcf10ed
+++ COPYRIGHT	a41c71a2f3659276bd8534a1b1bee1a4d2a91a94
@@ -349,6 +349,7 @@ Thanumalayan S.
 Michael Ruprecht
 Sam S.
 Thanumalayan S.
+Jonathan Sailor
 Elliott Sales de Andrade
 Tomasz Sa?aci?ski <tsalacinski at gmail.com>
 Pradyumna Sampath
============================================================
--- ChangeLog	a647db6dd3daa238c123d1e0816c78847f1bb64a
+++ ChangeLog	1069ced41a623d0a14f4bd2ae3fc6ebb8f67f0f1
@@ -17,6 +17,10 @@ version 2.5.3 (??/??/????):
 	* Fix a crash in SIMPLE when a malformed message is received.
 	* Fix the namespace URL we look for in PEP reply stanzas to match the URL
 	  used in the 'get' requests (Paul Aurich)
+	* XMPP resources can default to the local machine's hostname by using
+	  __HOSTNAME__ as the resource string (Jonathan Sailor)
+	* XMPP resources can now be left blank, causing the server to generate a
+	  resource for us (Jonathan Sailor)
 
 	Pidgin:
 	* On GTK+ 2.14 and higher, we're using the gtk-tooltip-delay setting
============================================================
--- libpurple/protocols/jabber/jabber.c	79ac7e16fcb72a3679f6e40263ee810e4412bc9c
+++ libpurple/protocols/jabber/jabber.c	c9c76b05193ce707a8c5b3e2041671dc08b7642a
@@ -146,10 +146,27 @@ static void jabber_bind_result_cb(Jabber
 	jabber_session_init(js);
 }
 
+static char *jabber_prep_resource(char *input) {
+	char hostname[256]; /* current hostname */
+
+	/* Empty resource == don't send any */
+	if (strlen(input) == 0)
+		return NULL;
+
+	/* Replace __HOSTNAME__ with hostname */
+	if (gethostname(hostname, sizeof(hostname))) {
+		purple_debug_warning("jabber", "gethostname() failed -- is your hostname set?");
+		strcpy(hostname, "localhost");
+	}
+
+	return purple_strreplace(input, "__HOSTNAME__", hostname);
+}
+
 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet)
 {
 	if(xmlnode_get_child(packet, "starttls")) {
 		if(jabber_process_starttls(js, packet))
+	
 			return;
 	} else if(purple_account_get_bool(js->gc->account, "require_tls", FALSE) && !js->gsc) {
 		purple_connection_error_reason (js->gc,
@@ -164,12 +181,18 @@ static void jabber_stream_features_parse
 		jabber_auth_start(js, packet);
 	} else if(xmlnode_get_child(packet, "bind")) {
 		xmlnode *bind, *resource;
+		char *requested_resource;
 		JabberIq *iq = jabber_iq_new(js, JABBER_IQ_SET);
 		bind = xmlnode_new_child(iq->node, "bind");
 		xmlnode_set_namespace(bind, "urn:ietf:params:xml:ns:xmpp-bind");
-		resource = xmlnode_new_child(bind, "resource");
-		xmlnode_insert_data(resource, js->user->resource, -1);
+		requested_resource = jabber_prep_resource(js->user->resource);
 
+		if (requested_resource != NULL) {
+			resource = xmlnode_new_child(bind, "resource");
+			xmlnode_insert_data(resource, requested_resource, -1);
+			free(requested_resource);
+		}
+
 		jabber_iq_set_callback(iq, jabber_bind_result_cb, NULL);
 
 		jabber_iq_send(iq);


More information about the Commits mailing list