Correctly extract the server from a JID when resource is included.
authorMikael Hallendal <micke@imendio.com>
Sat, 24 Feb 2007 04:03:49 +0100
changeset 232 71cdf1c0faaf
parent 231 6c6259ccb40b
child 236 b4e5c1cb114e
Correctly extract the server from a JID when resource is included. If a full JID (including resource) was given to lm_connection_set_jid it would include the resource part when trying to connect to the server. Patch from Matthias Quasthoff
loudmouth/lm-connection.c
--- a/loudmouth/lm-connection.c	Sat Feb 24 03:33:00 2007 +0100
+++ b/loudmouth/lm-connection.c	Sat Feb 24 04:03:49 2007 +0100
@@ -734,6 +734,7 @@
 	LmMessage    *m;
 	gchar        *server_from_jid;
 	gchar        *ch;
+	gchar        *ch_end;
 
 	if (!result) {
 		_lm_connection_do_close (connection);
@@ -763,9 +764,14 @@
 	}
 
 	if (connection->jid != NULL && (ch = strchr (connection->jid, '@')) != NULL) {
-		server_from_jid = ch + 1;
+		ch_end = strchr(ch + 1, '/');
+		if (ch_end != NULL) {
+			server_from_jid = g_strndup (ch + 1, ch_end - ch - 1);
+		} else {
+			server_from_jid = g_strdup (ch + 1);
+		}
 	} else {
-		server_from_jid = connection->server;
+		server_from_jid = g_strdup (connection->server);
 	}
 
 	m = lm_message_new (server_from_jid, LM_MESSAGE_TYPE_STREAM);
@@ -783,6 +789,7 @@
 		_lm_connection_do_close (connection);
 	}
 		
+	g_free (server_from_jid);
 	lm_message_unref (m);
 }