Support for returning effective JID, possibly changed by the server.
authorSenko Rasic <senko.rasic@collabora.co.uk>
Mon, 29 Oct 2007 22:34:34 +0100
changeset 297 f65eee8ec802
parent 296 54393019edac
child 298 71aaed5a9c34
Support for returning effective JID, possibly changed by the server.
loudmouth/lm-connection.c
loudmouth/lm-connection.h
--- a/loudmouth/lm-connection.c	Mon Oct 29 20:02:01 2007 +0100
+++ b/loudmouth/lm-connection.c	Mon Oct 29 22:34:34 2007 +0100
@@ -58,6 +58,7 @@
 	GMainContext *context;
 	gchar        *server;
 	gchar        *jid;
+	gchar        *effective_jid;
 	guint         port;
 	gboolean      use_srv;
 
@@ -183,6 +184,7 @@
 
 	g_free (connection->server);
 	g_free (connection->jid);
+	g_free (connection->effective_jid);
 	g_free (connection->stream_id);
 	g_free (connection->resource);
 
@@ -903,6 +905,7 @@
 {
 	LmMessage        *m;
 	LmMessageNode    *session_node;
+	LmMessageNode    *jid_node;
 	int               result;
 	LmMessageSubType  type;
 
@@ -915,6 +918,14 @@
 		return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 	}
 
+	/* use whatever server returns as our effective jid */
+	jid_node = lm_message_node_find_child (message->node, "jid");
+	if (jid_node) {
+		connection->effective_jid = g_strdup
+			(lm_message_node_get_value (jid_node));
+	}
+
+
 	m = lm_message_new_with_sub_type (NULL,
 					  LM_MESSAGE_TYPE_IQ, 
 					  LM_MESSAGE_SUB_TYPE_SET);
@@ -1062,6 +1073,7 @@
 	connection->context           = NULL;
 	connection->port              = LM_CONNECTION_DEFAULT_PORT;
 	connection->jid               = NULL;
+	connection->effective_jid     = NULL;
 	connection->ssl               = NULL;
 	connection->proxy             = NULL;
 	connection->disconnect_cb     = NULL;
@@ -1576,6 +1588,25 @@
 }
 
 /**
+ * lm_connection_get_effective_jid:
+ * @connection: an #LmConnection
+ * 
+ * Returns the jid that server set for us after resource binding.
+ *
+ * Return value: the jid
+ **/
+const gchar *
+lm_connection_get_effective_jid (LmConnection *connection)
+{
+	g_return_val_if_fail (connection != NULL, NULL);
+
+	if (connection->effective_jid)
+		return connection->effective_jid;
+	else
+		return connection->jid;
+}
+
+/**
  * lm_connection_set_jid:
  * @connection: an #LmConnection
  * @jid: JID to be used for @connection
--- a/loudmouth/lm-connection.h	Mon Oct 29 20:02:01 2007 +0100
+++ b/loudmouth/lm-connection.h	Mon Oct 29 22:34:34 2007 +0100
@@ -116,6 +116,7 @@
 void          lm_connection_set_jid           (LmConnection       *connection,
 					       const gchar        *jid);
 const gchar * lm_connection_get_jid           (LmConnection       *connection);
+const gchar * lm_connection_get_effective_jid (LmConnection       *connection);
 
 guint         lm_connection_get_port          (LmConnection       *connection);
 void          lm_connection_set_port          (LmConnection       *connection,