Correctly extract the server from a JID when resource is included.
authorMikael Hallendal <micke@imendio.com>
Sat, 24 Feb 2007 04:07:54 +0100
changeset 235 645f722461e3
parent 234 8e1bb9d60aa5
child 237 7b9c442e7251
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 wou 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 04:06:24 2007 +0100
+++ b/loudmouth/lm-connection.c	Sat Feb 24 04:07:54 2007 +0100
@@ -340,6 +340,7 @@
 	LmMessage    *m;
 	gchar        *server_from_jid;
 	gchar        *ch;
+	gchar        *ch_end;
 
 	connection = connect_data->connection;
 	
@@ -440,9 +441,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);
@@ -459,6 +465,7 @@
 		connection_do_close (connection);
 	}
 		
+	g_free (server_from_jid);
 	lm_message_unref (m);
 }