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$ * $Revision$
* $Date$ * $Date$
* *
...@@ -29,7 +29,7 @@ public class DNSUtil { ...@@ -29,7 +29,7 @@ public class DNSUtil {
static { static {
try { try {
Hashtable env = new Hashtable(); Hashtable<String,String> env = new Hashtable<String,String>();
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
context = new InitialDirContext(env); context = new InitialDirContext(env);
} }
...@@ -46,21 +46,21 @@ public class DNSUtil { ...@@ -46,21 +46,21 @@ public class DNSUtil {
* of "_jabber._tcp.example.com" is attempted since servers that implement an * 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 * 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 * 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 * host resolved by a DNS lookup at the specified domain on the specified default port.<p>
* of 5269.<p>
* *
* As an example, a lookup for "example.com" may return "im.example.com:5269". * As an example, a lookup for "example.com" may return "im.example.com:5269".
* *
* @param domain the domain. * @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 * @return a HostAddress, which encompasses the hostname and port that the XMPP
* server can be reached at for the specified domain. * 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) { if (context == null) {
return new HostAddress(domain, 5269); return new HostAddress(domain, defaultPort);
} }
String host = domain; String host = domain;
int port = 5269; int port = defaultPort;
try { try {
Attributes dnsLookup = context.getAttributes("_xmpp-server._tcp." + domain); Attributes dnsLookup = context.getAttributes("_xmpp-server._tcp." + domain);
String srvRecord = (String)dnsLookup.get("SRV").get(); String srvRecord = (String)dnsLookup.get("SRV").get();
......
...@@ -120,15 +120,17 @@ class ServerDialback { ...@@ -120,15 +120,17 @@ class ServerDialback {
*/ */
public OutgoingServerSession createOutgoingSession(String domain, String hostname, int port) { public OutgoingServerSession createOutgoingSession(String domain, String hostname, int port) {
String realHostname = null; String realHostname = null;
int realPort = port;
try { try {
// Establish a TCP connection to the Receiving Server // Establish a TCP connection to the Receiving Server
Log.debug("OS - Trying to connect to " + hostname + ":" + port); Log.debug("OS - Trying to connect to " + hostname + ":" + port);
// Get the real hostname to connect to using DNS lookup of the specified hostname // 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(); realHostname = address.getHost();
realPort = address.getPort();
// Connect to the remote server // Connect to the remote server
Socket socket = new Socket(); Socket socket = new Socket();
socket.connect(new InetSocketAddress(realHostname, port), socket.connect(new InetSocketAddress(realHostname, realPort),
RemoteServerManager.getSocketTimeout()); RemoteServerManager.getSocketTimeout());
Log.debug("OS - Connection to " + hostname + ":" + port + " successful"); Log.debug("OS - Connection to " + hostname + ":" + port + " successful");
connection = connection =
...@@ -184,9 +186,7 @@ class ServerDialback { ...@@ -184,9 +186,7 @@ class ServerDialback {
} }
catch (UnknownHostException e) { catch (UnknownHostException e) {
Log.debug("Error connecting to the remote server: " + hostname + "(DNS lookup: " + Log.debug("Error connecting to the remote server: " + hostname + "(DNS lookup: " +
realHostname + realHostname + ":" + realPort + ")", e);
")",
e);
// Close the connection // Close the connection
if (connection != null) { if (connection != null) {
connection.close(); connection.close();
...@@ -445,7 +445,8 @@ class ServerDialback { ...@@ -445,7 +445,8 @@ class ServerDialback {
else { else {
String key = doc.getTextTrim(); String key = doc.getTextTrim();
DNSUtil.HostAddress address = DNSUtil.resolveXMPPServerDomain(hostname); DNSUtil.HostAddress address = DNSUtil.resolveXMPPServerDomain(hostname,
RemoteServerManager.getPortForServer(hostname));
try { try {
boolean valid = verifyKey(key, streamID.toString(), recipient, hostname, 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