From 43744eb09fc5dc780261dae77fcaf7709b031278 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Mon, 16 Oct 2006 20:45:43 +0000 Subject: [PATCH] Added new constructor that performs DNS SRV lookups. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@5726 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smack/ConnectionConfiguration.java | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/source/org/jivesoftware/smack/ConnectionConfiguration.java b/source/org/jivesoftware/smack/ConnectionConfiguration.java index a613604e8..cabe21576 100644 --- a/source/org/jivesoftware/smack/ConnectionConfiguration.java +++ b/source/org/jivesoftware/smack/ConnectionConfiguration.java @@ -20,6 +20,8 @@ package org.jivesoftware.smack; +import org.jivesoftware.smack.util.DNSUtil; + import javax.net.SocketFactory; import java.io.File; @@ -64,8 +66,46 @@ public class ConnectionConfiguration implements Cloneable { // Holds the authentication information for future reconnections private String username; private String password; - + + /** + * Creates a new ConnectionConfiguration for a connection that will connect + * to the desired service name. A DNS SRV lookup will be performed to find out the + * actual host address and port to use for the connection. + * + * @param serviceName the name of the service provided by an XMPP server. + */ + public ConnectionConfiguration(String serviceName) { + // Perform DNS lookup to get host and port to use + DNSUtil.HostAddress address = DNSUtil.resolveXMPPDomain(serviceName); + init(address.getHost(), address.getPort(), serviceName); + } + + /** + * Creates a new ConnectionConfiguration for a connection that will connect + * to the desired host, port and service name. It is expected for the XMPP server to + * be running at the specified address and to be using the specified service name. + * Anyway, if the service name is incorrect the correct one will be used instead. + * + * @param host the host where the XMPP server is running. + * @param port the port where the XMPP is listening. + * @param serviceName the name of the service provided by an XMPP server. + */ public ConnectionConfiguration(String host, int port, String serviceName) { + init(host, port, serviceName); + } + + /** + * Creates a new ConnectionConfiguration for a connection that will connect + * to the desired host and port. + * + * @param host the host where the XMPP server is running. + * @param port the port where the XMPP is listening. + */ + public ConnectionConfiguration(String host, int port) { + init(host, port, host); + } + + private void init(String host, int port, String serviceName) { this.host = host; this.port = port; this.serviceName = serviceName; @@ -84,10 +124,6 @@ public class ConnectionConfiguration implements Cloneable { truststorePassword = "changeit"; } - public ConnectionConfiguration(String host, int port) { - this(host, port, host); - } - /** * Returns the server name of the target server. *