diff libpurple/protocols/jabber/jabber.c @ 24555:7ec139c84d36

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. committer: John Bailey <rekkanoryo@rekkanoryo.org>
author Jonathan Sailor <jsailor@jesnetplus.com>
date Fri, 28 Nov 2008 02:19:42 +0000
parents 3a3d36791a47
children 8e7e6f60e053
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Fri Nov 28 01:49:58 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Fri Nov 28 02:19:42 2008 +0000
@@ -146,10 +146,27 @@
 	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,11 +181,17 @@
 		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);