2004-08-09 Mikael Hallendal <micke@imendio.com>
authorhallski <hallski>
Sun, 08 Aug 2004 23:07:23 +0000
changeset 89 e756a937e540
parent 88 d35d28e50d84
child 90 3f4b38614416
2004-08-09 Mikael Hallendal <micke@imendio.com> * examples/test-tunnel.c: Updated. * loudmouth/lm-connection.[ch]: (lm_connection_get_jid), (lm_connection_set_jid): - Replaced the _host functions with these. These makes much more sense.
ChangeLog
examples/test-tunnel.c
loudmouth/lm-connection.c
loudmouth/lm-connection.h
--- a/ChangeLog	Sun Aug 08 20:04:15 2004 +0000
+++ b/ChangeLog	Sun Aug 08 23:07:23 2004 +0000
@@ -1,3 +1,10 @@
+2004-08-09  Mikael Hallendal  <micke@imendio.com>
+
+	* examples/test-tunnel.c: Updated.
+	* loudmouth/lm-connection.[ch]:
+	(lm_connection_get_jid), (lm_connection_set_jid): 
+	- Replaced the _host functions with these. These makes much more sense.
+
 2004-08-08  Mikael Hallendal  <micke@imendio.com>
 
 	* configure.in: Bumped version to 0.17
--- a/examples/test-tunnel.c	Sun Aug 08 20:04:15 2004 +0000
+++ b/examples/test-tunnel.c	Sun Aug 08 23:07:23 2004 +0000
@@ -92,15 +92,19 @@
         LmMessageHandler *handler;
         gboolean          result;
         UserInfo         *info;
+	gchar            *jid;
                                                                                 
         if (argc < 6) {
-                g_print ("Usage: %s <server> <username> <password> <proxyserver> <proxyport>\n", argv[0]);
+                g_print ("Usage: %s <server> <username> <password> <connectserver> <connectport>\n", argv[0]);
                 return 1;
         }
                                                                                 
-        connection = lm_connection_new (argv[1]);
+        connection = lm_connection_new (argv[4]);
 
-	lm_connection_set_host (connection, argv[4]);
+	jid = g_strdup_printf ("%s@%s", argv[2], argv[1]);
+	lm_connection_set_jid (connection, jid);
+	g_free (jid);
+
 	lm_connection_set_port (connection, strtol (argv[5], (char **) NULL, 10));
 
         handler = lm_message_handler_new (handle_messages, NULL, NULL);
--- a/loudmouth/lm-connection.c	Sun Aug 08 20:04:15 2004 +0000
+++ b/loudmouth/lm-connection.c	Sun Aug 08 23:07:23 2004 +0000
@@ -58,7 +58,7 @@
 	/* Parameters */
 	GMainContext *context;
 	gchar        *server;
-	gchar        *host;
+	gchar        *jid;
 	guint         port;
 
 	LmSSL        *ssl;
@@ -182,7 +182,7 @@
 	int i;
 
 	g_free (connection->server);
-	g_free (connection->host);
+	g_free (connection->jid);
 
 	/* Unref handlers */
 	for (i = 0; i < LM_MESSAGE_TYPE_UNKNOWN; ++i) {
@@ -266,9 +266,13 @@
 gboolean
 _lm_connection_succeeded (LmConnectData *connect_data)
 {
-	LmConnection *connection = connect_data->connection;
+	LmConnection *connection;
 	LmMessage    *m;
 	GIOFlags      flags;
+	gchar        *server_from_jid;
+	gchar        *ch;
+
+	connection = connect_data->connection;
 
 	/* Need some way to report error/success */
 	if (connection->cancel_open) {
@@ -293,8 +297,8 @@
 	g_io_channel_set_flags (connection->io_channel, flags, NULL);
 
 	if (connection->ssl) {
-		if (!_lm_ssl_begin (connection->ssl, connection->fd, 
-				    lm_connection_get_host (connection),
+		if (!_lm_ssl_begin (connection->ssl, connection->fd,
+				    connection->server,
 				    NULL)) {
 			shutdown (connection->fd, SHUT_RDWR);
 			close (connection->fd);
@@ -339,7 +343,13 @@
 		return FALSE;
 	}
 
-	m = lm_message_new (connection->server, LM_MESSAGE_TYPE_STREAM);
+	if (connection->jid != NULL && (ch = strchr (connection->jid, '@')) != NULL) {
+		server_from_jid = ch + 1;
+	} else {
+		server_from_jid = connection->server;
+	}
+
+	m = lm_message_new (server_from_jid, LM_MESSAGE_TYPE_STREAM);
 	lm_message_node_set_attributes (m->node,
 					"xmlns:stream", 
 					"http://etherx.jabber.org/streams",
@@ -526,7 +536,7 @@
 		return FALSE;
 	}
 
-	if (!lm_connection_get_host (connection)) {
+	if (!connection->server) {
 		g_set_error (error,
 			     LM_ERROR,
 			     LM_ERROR_CONNECTION_OPEN,
@@ -539,7 +549,7 @@
 	g_source_attach (connection->incoming_source, connection->context);
 	
 	lm_verbose ("Connecting to: %s:%d\n", 
-		    lm_connection_get_host (connection), connection->port);
+		    connection->server, connection->port);
 
 	memset (&req, 0, sizeof(req));
 
@@ -568,9 +578,9 @@
 	} else { /* connect directly */
 		g_log (LM_LOG_DOMAIN,LM_LOG_LEVEL_NET,
 		       "Going to connect to %s\n", 
-		       lm_connection_get_host (connection));
+		       connection->server);
 
-		if (getaddrinfo (lm_connection_get_host (connection),
+		if (getaddrinfo (connection->server,
 				 NULL, &req, &ans) != 0) {
 			g_set_error (error,
 				     LM_ERROR,                 
@@ -1060,7 +1070,7 @@
 
 	connection->context           = NULL;
 	connection->port              = LM_CONNECTION_DEFAULT_PORT;
-	connection->host              = NULL;
+	connection->jid               = NULL;
 	connection->ssl               = NULL;
 	connection->proxy             = NULL;
 	connection->disconnect_cb     = NULL;
@@ -1213,8 +1223,7 @@
 	}
 	
 	lm_verbose ("Disconnecting from: %s:%d\n", 
-		    lm_connection_get_host (connection),
-		    connection->port);
+		    connection->server, connection->port);
 	
 	if (!connection_send (connection, "</stream:stream>", -1, error)) {
 		return FALSE;
@@ -1409,8 +1418,7 @@
  * lm_connection_get_server:
  * @connection: an #LmConnection
  * 
- * Fetches the server address that @connection is using. The server address 
- * will be used when connecting unless the host address is set. 
+ * Fetches the server address that @connection is using. 
  * 
  * Return value: the server address
  **/
@@ -1428,8 +1436,7 @@
  * @server: Address of the server
  * 
  * Sets the server address for @connection to @server. Notice that @connection
- * can't be open while doing this. The server address will be used when
- * connecting unless the host address is set.
+ * can't be open while doing this. 
  **/
 void
 lm_connection_set_server (LmConnection *connection, const gchar *server)
@@ -1447,52 +1454,40 @@
 }
 
 /**
- * lm_connection_get_host:
+ * lm_connection_get_jid:
  * @connection: an #LmConnection
  * 
- * Fetches the host address that @connection is using. If set the host address
- * will be used instead of the server address when connecting. For example a 
- * server might be named mycompany.com but the real host address needs to be
- * jabber.mycompany.com.
- *
- * If the host address is not set this function will return the server address.
+ * Fetches the jid set for @connection is using. 
  * 
- * Return value: the host address
+ * Return value: the jid
  **/
 const gchar *
-lm_connection_get_host (LmConnection *connection)
+lm_connection_get_jid (LmConnection *connection)
 {
 	g_return_val_if_fail (connection != NULL, NULL);
 
-	if (connection->host) {
-		return connection->host;
-	}
-	
-	return connection->server;
+	return connection->jid;
 }
 
 /**
- * lm_connection_set_host:
+ * lm_connection_set_jid:
  * @connection: an #LmConnection
- * @host: Address of the server
+ * @jid: JID to be used for @connection
  * 
- * Sets the host address for @connection to @host. If this is set it will be 
- * used instead of the @server address when connecting. This is useful if the
- * user wants to connect to a server through a tunnel. Notice that @connection
- * can't be open while doing this.
+ * Sets the JID to be used for @connection.
  **/
 void 
-lm_connection_set_host (LmConnection *connection, const gchar *host)
+lm_connection_set_jid (LmConnection *connection, const gchar *jid)
 {
 	g_return_if_fail (connection != NULL);
 
 	if (lm_connection_is_open (connection)) {
-		g_warning ("Can't change server address while connected");
+		g_warning ("Can't change JID while connected");
 		return;
 	}
 
-	g_free (connection->host);
-	connection->host = g_strdup (host);
+	g_free (connection->jid);
+	connection->jid = g_strdup (jid);
 }
 
 /**
--- a/loudmouth/lm-connection.h	Sun Aug 08 20:04:15 2004 +0000
+++ b/loudmouth/lm-connection.h	Sun Aug 08 23:07:23 2004 +0000
@@ -110,9 +110,9 @@
 const gchar * lm_connection_get_server        (LmConnection       *connection);
 void          lm_connection_set_server        (LmConnection       *connection,
 					       const gchar        *server);
-void          lm_connection_set_host          (LmConnection       *connection,
-					       const gchar        *host);
-const gchar * lm_connection_get_host          (LmConnection       *connection);
+void          lm_connection_set_jid           (LmConnection       *connection,
+					       const gchar        *jid);
+const gchar * lm_connection_get_jid           (LmConnection       *connection);
 
 guint         lm_connection_get_port          (LmConnection       *connection);
 void          lm_connection_set_port          (LmConnection       *connection,