2004-08-08 Mikael Hallendal <micke@imendio.com>
* docs/reference/tmpl/lm-proxy.sgml: Updated docs
* examples/test-tunnel.c: Use the new API for connecting to other host
than the actual server name (host part of jid).
* loudmouth/lm-connection.[ch]:
(lm_connection_set_host), (lm_connection_get_host): Added
- Use lm_connection_get_host internally when connecting.
- Make LM_PROXY_TYPE_NONE reset the proxy settings on a connection.
* loudmouth/lm-proxy.c: (_lm_proxy_connect_cb): Don't connect when
proxy is of type LM_PROXY_TYPE_NONE.
--- a/ChangeLog Sun Aug 08 11:01:32 2004 +0000
+++ b/ChangeLog Sun Aug 08 20:01:54 2004 +0000
@@ -1,3 +1,15 @@
+2004-08-08 Mikael Hallendal <micke@imendio.com>
+
+ * docs/reference/tmpl/lm-proxy.sgml: Updated docs
+ * examples/test-tunnel.c: Use the new API for connecting to other host
+ than the actual server name (host part of jid).
+ * loudmouth/lm-connection.[ch]:
+ (lm_connection_set_host), (lm_connection_get_host): Added
+ - Use lm_connection_get_host internally when connecting.
+ - Make LM_PROXY_TYPE_NONE reset the proxy settings on a connection.
+ * loudmouth/lm-proxy.c: (_lm_proxy_connect_cb): Don't connect when
+ proxy is of type LM_PROXY_TYPE_NONE.
+
2004-08-08 Mikael Hallendal <micke@imendio.com>
* docs/reference/tmpl/lm-proxy.sgml: Added LM_PROXY_TYPE_NONE
--- a/docs/reference/tmpl/lm-proxy.sgml Sun Aug 08 11:01:32 2004 +0000
+++ b/docs/reference/tmpl/lm-proxy.sgml Sun Aug 08 20:01:54 2004 +0000
@@ -35,7 +35,7 @@
The type of the proxy.
</para>
-@LM_PROXY_TYPE_NONE: A direct proxy, for example when using through a simple tunnel.
+@LM_PROXY_TYPE_NONE: Use this to unset the proxy on an #LmConnection.
@LM_PROXY_TYPE_HTTP: An HTTP proxy.
<!-- ##### FUNCTION lm_proxy_new ##### -->
--- a/examples/test-tunnel.c Sun Aug 08 11:01:32 2004 +0000
+++ b/examples/test-tunnel.c Sun Aug 08 20:01:54 2004 +0000
@@ -92,8 +92,6 @@
LmMessageHandler *handler;
gboolean result;
UserInfo *info;
- LmProxy *proxy;
- guint proxy_port;
if (argc < 6) {
g_print ("Usage: %s <server> <username> <password> <proxyserver> <proxyport>\n", argv[0]);
@@ -102,14 +100,9 @@
connection = lm_connection_new (argv[1]);
- proxy = lm_proxy_new (LM_PROXY_TYPE_NONE);
- lm_proxy_set_server (proxy, argv[4]);
+ lm_connection_set_host (connection, argv[4]);
+ lm_connection_set_port (connection, strtol (argv[5], (char **) NULL, 10));
- proxy_port = strtol (argv[5], (char **) NULL, 10);
- lm_proxy_set_port (proxy, proxy_port);
- lm_connection_set_proxy (connection, proxy);
- lm_proxy_unref (proxy);
-
handler = lm_message_handler_new (handle_messages, NULL, NULL);
lm_connection_register_message_handler (connection, handler,
LM_MESSAGE_TYPE_MESSAGE,
--- a/loudmouth/lm-connection.c Sun Aug 08 11:01:32 2004 +0000
+++ b/loudmouth/lm-connection.c Sun Aug 08 20:01:54 2004 +0000
@@ -58,6 +58,7 @@
/* Parameters */
GMainContext *context;
gchar *server;
+ gchar *host;
guint port;
LmSSL *ssl;
@@ -181,6 +182,7 @@
int i;
g_free (connection->server);
+ g_free (connection->host);
/* Unref handlers */
for (i = 0; i < LM_MESSAGE_TYPE_UNKNOWN; ++i) {
@@ -292,7 +294,8 @@
if (connection->ssl) {
if (!_lm_ssl_begin (connection->ssl, connection->fd,
- connection->server, NULL)) {
+ lm_connection_get_host (connection),
+ NULL)) {
shutdown (connection->fd, SHUT_RDWR);
close (connection->fd);
connection_do_close (connection);
@@ -523,7 +526,7 @@
return FALSE;
}
- if (!connection->server) {
+ if (!lm_connection_get_host (connection)) {
g_set_error (error,
LM_ERROR,
LM_ERROR_CONNECTION_OPEN,
@@ -536,7 +539,7 @@
g_source_attach (connection->incoming_source, connection->context);
lm_verbose ("Connecting to: %s:%d\n",
- connection->server, connection->port);
+ lm_connection_get_host (connection), connection->port);
memset (&req, 0, sizeof(req));
@@ -564,9 +567,11 @@
}
} else { /* connect directly */
g_log (LM_LOG_DOMAIN,LM_LOG_LEVEL_NET,
- "Going to connect to %s\n",connection->server);
+ "Going to connect to %s\n",
+ lm_connection_get_host (connection));
- if (getaddrinfo (connection->server, NULL, &req, &ans) != 0) {
+ if (getaddrinfo (lm_connection_get_host (connection),
+ NULL, &req, &ans) != 0) {
g_set_error (error,
LM_ERROR,
LM_ERROR_CONNECTION_OPEN,
@@ -1055,6 +1060,7 @@
connection->context = NULL;
connection->port = LM_CONNECTION_DEFAULT_PORT;
+ connection->host = NULL;
connection->ssl = NULL;
connection->proxy = NULL;
connection->disconnect_cb = NULL;
@@ -1207,7 +1213,7 @@
}
lm_verbose ("Disconnecting from: %s:%d\n",
- connection->server,
+ lm_connection_get_host (connection),
connection->port);
if (!connection_send (connection, "</stream:stream>", -1, error)) {
@@ -1403,7 +1409,8 @@
* lm_connection_get_server:
* @connection: an #LmConnection
*
- * Fetches the server address that @connection is using.
+ * Fetches the server address that @connection is using. The server address
+ * will be used when connecting unless the host address is set.
*
* Return value: the server address
**/
@@ -1420,7 +1427,9 @@
* @connection: an #LmConnection
* @server: Address of the server
*
- * Sets the server address for @connection to @server. Notice that @connection can't be open while doing this.
+ * 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.
**/
void
lm_connection_set_server (LmConnection *connection, const gchar *server)
@@ -1433,11 +1442,57 @@
return;
}
- if (connection->server) {
- g_free (connection->server);
+ g_free (connection->server);
+ connection->server = g_strdup (server);
+}
+
+/**
+ * lm_connection_get_host:
+ * @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.
+ *
+ * Return value: the host address
+ **/
+const gchar *
+lm_connection_get_host (LmConnection *connection)
+{
+ g_return_val_if_fail (connection != NULL, NULL);
+
+ if (connection->host) {
+ return connection->host;
}
- connection->server = g_strdup (server);
+ return connection->server;
+}
+
+/**
+ * lm_connection_set_host:
+ * @connection: an #LmConnection
+ * @host: Address of the server
+ *
+ * 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.
+ **/
+void
+lm_connection_set_host (LmConnection *connection, const gchar *host)
+{
+ g_return_if_fail (connection != NULL);
+
+ if (lm_connection_is_open (connection)) {
+ g_warning ("Can't change server address while connected");
+ return;
+ }
+
+ g_free (connection->host);
+ connection->host = g_strdup (host);
}
/**
@@ -1536,7 +1591,8 @@
* @connection: an #LmConnection
* @proxy: an #LmProxy
*
- * Sets the proxy to use for this connection.
+ * Sets the proxy to use for this connection. To unset pass a proxy of type
+ * #LM_PROXY_TYPE_NONE to this function.
*
**/
void
@@ -1549,12 +1605,15 @@
g_warning ("Can't change server proxy while connected");
return;
}
-
+
if (connection->proxy) {
lm_proxy_unref (connection->proxy);
+ connection->proxy = NULL;
}
- connection->proxy = lm_proxy_ref (proxy);
+ if (lm_proxy_get_type (proxy) != LM_PROXY_TYPE_NONE) {
+ connection->proxy = lm_proxy_ref (proxy);
+ }
}
/**
--- a/loudmouth/lm-connection.h Sun Aug 08 11:01:32 2004 +0000
+++ b/loudmouth/lm-connection.h Sun Aug 08 20:01:54 2004 +0000
@@ -110,6 +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);
guint lm_connection_get_port (LmConnection *connection);
void lm_connection_set_port (LmConnection *connection,
--- a/loudmouth/lm-proxy.c Sun Aug 08 11:01:32 2004 +0000
+++ b/loudmouth/lm-proxy.c Sun Aug 08 20:01:54 2004 +0000
@@ -205,15 +205,11 @@
_lm_connection_failed (connect_data);
return FALSE;
}
- if (proxy->type == LM_PROXY_TYPE_NONE) {
- _lm_connection_succeeded (connect_data);
- }
- else {
- proxy->io_watch = g_io_add_watch (connect_data->io_channel,
- G_IO_IN|G_IO_ERR,
- (GIOFunc) proxy_read_cb,
- connect_data);
- }
+
+ proxy->io_watch = g_io_add_watch (connect_data->io_channel,
+ G_IO_IN|G_IO_ERR,
+ (GIOFunc) proxy_read_cb,
+ connect_data);
} else {
g_assert_not_reached ();
}