Commit acf2e382 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Modified DNSUtil to accept default port. JM-383

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@2867 b35dd754-fafc-0310-a699-88a17e54d16e
parent 3c92837f
/**
* $RCSfile$
* $RCSfile: DNSUtil.java,v $
* $Revision$
* $Date$
*
......@@ -29,7 +29,7 @@ public class DNSUtil {
static {
try {
Hashtable env = new Hashtable();
Hashtable<String,String> env = new Hashtable<String,String>();
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
context = new InitialDirContext(env);
}
......@@ -46,21 +46,21 @@ public class DNSUtil {
* of "_jabber._tcp.example.com" is attempted since servers that implement an
* older version of the protocol may be listed using that notation. If that
* lookup fails as well, it's assumed that the XMPP server lives at the
* host resolved by a DNS lookup at the specified domain on the default port
* of 5269.<p>
* host resolved by a DNS lookup at the specified domain on the specified default port.<p>
*
* As an example, a lookup for "example.com" may return "im.example.com:5269".
*
* @param domain the domain.
* @param defaultPort default port to return if the DNS look up fails.
* @return a HostAddress, which encompasses the hostname and port that the XMPP
* server can be reached at for the specified domain.
*/
public static HostAddress resolveXMPPServerDomain(String domain) {
public static HostAddress resolveXMPPServerDomain(String domain, int defaultPort) {
if (context == null) {
return new HostAddress(domain, 5269);
return new HostAddress(domain, defaultPort);
}
String host = domain;
int port = 5269;
int port = defaultPort;
try {
Attributes dnsLookup = context.getAttributes("_xmpp-server._tcp." + domain);
String srvRecord = (String)dnsLookup.get("SRV").get();
......
......@@ -120,15 +120,17 @@ class ServerDialback {
*/
public OutgoingServerSession createOutgoingSession(String domain, String hostname, int port) {
String realHostname = null;
int realPort = port;
try {
// Establish a TCP connection to the Receiving Server
Log.debug("OS - Trying to connect to " + hostname + ":" + port);
// Get the real hostname to connect to using DNS lookup of the specified hostname
DNSUtil.HostAddress address = DNSUtil.resolveXMPPServerDomain(hostname);
DNSUtil.HostAddress address = DNSUtil.resolveXMPPServerDomain(hostname, port);
realHostname = address.getHost();
realPort = address.getPort();
// Connect to the remote server
Socket socket = new Socket();
socket.connect(new InetSocketAddress(realHostname, port),
socket.connect(new InetSocketAddress(realHostname, realPort),
RemoteServerManager.getSocketTimeout());
Log.debug("OS - Connection to " + hostname + ":" + port + " successful");
connection =
......@@ -184,9 +186,7 @@ class ServerDialback {
}
catch (UnknownHostException e) {
Log.debug("Error connecting to the remote server: " + hostname + "(DNS lookup: " +
realHostname +
")",
e);
realHostname + ":" + realPort + ")", e);
// Close the connection
if (connection != null) {
connection.close();
......@@ -445,7 +445,8 @@ class ServerDialback {
else {
String key = doc.getTextTrim();
DNSUtil.HostAddress address = DNSUtil.resolveXMPPServerDomain(hostname);
DNSUtil.HostAddress address = DNSUtil.resolveXMPPServerDomain(hostname,
RemoteServerManager.getPortForServer(hostname));
try {
boolean valid = verifyKey(key, streamID.toString(), recipient, hostname,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment