mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
SMACK-225 Fixed DNS SRV handling, as per RFC 2782. Added support for multiple DNS SRV resolvers namely javax and org.xbill.dns (aka dnsjava).
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_3_0@13561 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
21be8c55ee
commit
2eb13f48d2
12 changed files with 756 additions and 210 deletions
|
@ -22,11 +22,15 @@ package org.jivesoftware.smack;
|
|||
|
||||
import org.jivesoftware.smack.proxy.ProxyInfo;
|
||||
import org.jivesoftware.smack.util.DNSUtil;
|
||||
import org.jivesoftware.smack.util.dns.HostAddress;
|
||||
|
||||
import javax.net.SocketFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Configuration to use while establishing the connection to the server. It is possible to
|
||||
|
@ -48,6 +52,7 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
|
||||
private String host;
|
||||
private int port;
|
||||
protected List<HostAddress> hostAddresses;
|
||||
|
||||
private String truststorePath;
|
||||
private String truststoreType;
|
||||
|
@ -98,12 +103,11 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
*/
|
||||
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,
|
||||
ProxyInfo.forDefaultProxy());
|
||||
hostAddresses = DNSUtil.resolveXMPPDomain(serviceName);
|
||||
init(serviceName, ProxyInfo.forDefaultProxy());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Creates a new ConnectionConfiguration for the specified service name
|
||||
* with specified proxy.
|
||||
* A DNS SRV lookup will be performed to find out the actual host address
|
||||
|
@ -114,8 +118,8 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
*/
|
||||
public ConnectionConfiguration(String serviceName,ProxyInfo proxy) {
|
||||
// Perform DNS lookup to get host and port to use
|
||||
DNSUtil.HostAddress address = DNSUtil.resolveXMPPDomain(serviceName);
|
||||
init(address.getHost(), address.getPort(), serviceName, proxy);
|
||||
hostAddresses = DNSUtil.resolveXMPPDomain(serviceName);
|
||||
init(serviceName, proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,7 +137,8 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
* @param serviceName the name of the service provided by an XMPP server.
|
||||
*/
|
||||
public ConnectionConfiguration(String host, int port, String serviceName) {
|
||||
init(host, port, serviceName, ProxyInfo.forDefaultProxy());
|
||||
initHostAddresses(host, port);
|
||||
init(serviceName, ProxyInfo.forDefaultProxy());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -152,7 +157,8 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
* @param proxy the proxy through which XMPP is to be connected
|
||||
*/
|
||||
public ConnectionConfiguration(String host, int port, String serviceName, ProxyInfo proxy) {
|
||||
init(host, port, serviceName, proxy);
|
||||
initHostAddresses(host, port);
|
||||
init(serviceName, proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,7 +169,8 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
* @param port the port where the XMPP is listening.
|
||||
*/
|
||||
public ConnectionConfiguration(String host, int port) {
|
||||
init(host, port, host, ProxyInfo.forDefaultProxy());
|
||||
initHostAddresses(host, port);
|
||||
init(host, ProxyInfo.forDefaultProxy());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,12 +182,11 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
* @param proxy the proxy through which XMPP is to be connected
|
||||
*/
|
||||
public ConnectionConfiguration(String host, int port, ProxyInfo proxy) {
|
||||
init(host, port, host, proxy);
|
||||
initHostAddresses(host, port);
|
||||
init(host, proxy);
|
||||
}
|
||||
|
||||
private void init(String host, int port, String serviceName, ProxyInfo proxy) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
protected void init(String serviceName, ProxyInfo proxy) {
|
||||
this.serviceName = serviceName;
|
||||
this.proxy = proxy;
|
||||
|
||||
|
@ -243,6 +249,11 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
return port;
|
||||
}
|
||||
|
||||
public void setUsedHostAddress(HostAddress hostAddress) {
|
||||
this.host = hostAddress.getFQDN();
|
||||
this.port = hostAddress.getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TLS security mode used when making the connection. By default,
|
||||
* the mode is {@link SecurityMode#enabled}.
|
||||
|
@ -674,6 +685,10 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
return this.socketFactory;
|
||||
}
|
||||
|
||||
public List<HostAddress> getHostAddresses() {
|
||||
return Collections.unmodifiableList(hostAddresses);
|
||||
}
|
||||
|
||||
/**
|
||||
* An enumeration for TLS security modes that are available when making a connection
|
||||
* to the XMPP server.
|
||||
|
@ -742,4 +757,15 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
this.password = password;
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
private void initHostAddresses(String host, int port) {
|
||||
hostAddresses = new ArrayList<HostAddress>(1);
|
||||
HostAddress hostAddress;
|
||||
try {
|
||||
hostAddress = new HostAddress(host, port);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
hostAddresses.add(hostAddress);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue