Add DNS SRV query for the jabber account server.

cusax-fix
Damian Minkov 20 years ago
parent 7d4fa8a46e
commit 8abf73a5f5

@ -29,6 +29,8 @@ org.osgi.framework.system.packages= org.osgi.framework; \
net.java.stun4j.StunAddress; \
net.java.stun4j.StunException; \
javax.net.ssl; \
javax.naming; \
javax.naming.directory; \
edu.stanford.ejalbert; \
edu.stanford.ejalbert.exception; \
edu.stanford.ejalbert.exceptionhandler;

@ -16,6 +16,8 @@ org.osgi.framework.system.packages= org.osgi.framework; \
javax.xml.transform.stream;\
net.java.stun4j;\
net.java.stun4j.client;\
javax.naming; \
javax.naming.directory; \
javax.net.ssl;

@ -15,6 +15,7 @@
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.service.protocol.jabberconstants.*;
import net.java.sip.communicator.util.*;
import javax.naming.*;
/**
* An implementation of the protocol provider service over the Jabber protocol
@ -222,6 +223,25 @@ private void connectAndLogin(SecurityAuthority authority)
getAccountProperties().get(
ProtocolProviderFactory.SERVER_PORT);
// check to see is there SRV records for this server domain
try
{
String hosts[] =
NetworkUtils.getSRVRecords(
"_xmpp-client._tcp." + serviceName);
if(hosts != null && hosts.length > 0)
{
logger.trace("Will set server address from SRV records "
+ hosts[0]);
serverAddress = hosts[0];
}
}
catch (NamingException ex1)
{
logger.error("Domain not resolved " + ex1.getMessage());
}
connection = new XMPPConnection(
serverAddress,
Integer.parseInt(serverPort),

@ -7,6 +7,8 @@ Import-Package: org.osgi.framework,
javax.net.ssl,
javax.swing,
javax.xml.parsers,
javax.naming,
javax.naming.directory,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.util,
net.java.sip.communicator.service.configuration.event,

@ -8,11 +8,14 @@
import java.net.*;
import java.util.*;
import javax.naming.*;
import javax.naming.directory.*;
/**
* Utility methods and fields to use when working with network addresses.
*
* @author Emil Ivov
* @author Damian Minkov
*/
public class NetworkUtils
{
@ -94,4 +97,45 @@ public static boolean isIPv6Address(String address)
{
return (address != null && address.indexOf(':') != -1);
}
/**
* Returns array of hosts from the SRV record of the specified domain.
* The records are ordered against the SRV record priority
* @param domain String
* @return String[]
*/
public static String[] getSRVRecords(String domain)
throws NamingException
{
InitialDirContext iDirC = new InitialDirContext();
Attributes attributes =
iDirC.getAttributes("dns:/" + domain, new String[]{"SRV"});
Attribute attributeMX = attributes.get("SRV");
String[][] pvhn = new String[attributeMX.size()][2];
for(int i = 0; i < attributeMX.size(); i++)
{
pvhn[i] = ("" + attributeMX.get(i)).split("\\s+");
}
// sort the SRV RRs by RR value (lower is preferred)
Arrays.sort(pvhn, new Comparator()
{
public int compare(Object o1, Object o2)
{
return(Integer.parseInt(((String[])o1)[0]) -
Integer.parseInt(((String[])o2)[0]));
}
});
// put sorted host names in an array, get rid of any trailing '.'
String[] sortedHostNames = new String[pvhn.length];
for(int i = 0; i < pvhn.length; i++)
{
sortedHostNames[i] = pvhn[i][3].endsWith(".") ?
pvhn[i][3].substring(0, pvhn[i][3].length() - 1) : pvhn[i][3];
}
return sortedHostNames;
}
}

@ -9,6 +9,8 @@ Import-Package: org.w3c.dom,
javax.xml.transform,
javax.xml.transform.dom,
javax.xml.transform.stream,
javax.naming,
javax.naming.directory,
net.java.sip.communicator.util.xml,
net.java.sip.communicator.util,
Export-Package: net.java.sip.communicator.util.xml,

Loading…
Cancel
Save