From cafd510a0efc9df985999ceded57efa1d411de2e Mon Sep 17 00:00:00 2001 From: Nick Hudson Date: Fri, 7 Feb 2014 10:29:11 +0000 Subject: Move hardcoded XMPP SRV information from Connector into CoreClient The Connector class had "_xmpp-client._tcp." hard-coded in it, which meant that it was not suitable for non XMPP clients. This change means that Connector could now be used by clients who are interested in arbitrary SRV records; the CoreClient class is updated accordingly. Test-information: Built and tested using MLC. Also tested with a client that is interested in IMAP SRV records Change-Id: Ia23c148fd8afdd7b3271c47b1c96d086d57a44bd diff --git a/src/com/isode/stroke/client/CoreClient.java b/src/com/isode/stroke/client/CoreClient.java index 524a05a..646f8fe 100644 --- a/src/com/isode/stroke/client/CoreClient.java +++ b/src/com/isode/stroke/client/CoreClient.java @@ -187,7 +187,8 @@ public class CoreClient { /* FIXME: Port Proxies */ String host = (o.manualHostname == null || o.manualHostname.isEmpty()) ? jid_.getDomain() : o.manualHostname; int port = o.manualPort; - connector_ = Connector.create(host, port, o.manualHostname == null || o.manualHostname.isEmpty(), networkFactories.getDomainNameResolver(), networkFactories.getConnectionFactory(), networkFactories.getTimerFactory()); + String serviceLookupPrefix = (o.manualHostname == null || o.manualHostname.isEmpty() ? "_xmpp-client._tcp." : null); + connector_ = Connector.create(host, port, serviceLookupPrefix, networkFactories.getDomainNameResolver(), networkFactories.getConnectionFactory(), networkFactories.getTimerFactory()); connectorConnectFinishedConnection_ = connector_.onConnectFinished.connect(new Slot2() { public void call(Connection p1, com.isode.stroke.base.Error p2) { handleConnectorFinished(p1, p2); diff --git a/src/com/isode/stroke/network/Connector.java b/src/com/isode/stroke/network/Connector.java index 983882b..80caf0e 100644 --- a/src/com/isode/stroke/network/Connector.java +++ b/src/com/isode/stroke/network/Connector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2012, Isode Limited, London, England. + * Copyright (c) 2010-2014, Isode Limited, London, England. * All rights reserved. */ /* @@ -20,8 +20,8 @@ import java.util.Collection; public class Connector { - public static Connector create(String hostname, int port, boolean doServiceLookups, DomainNameResolver resolver, ConnectionFactory connectionFactory, TimerFactory timerFactory) { - return new Connector(hostname, port, doServiceLookups, resolver, connectionFactory, timerFactory); + public static Connector create(String hostname, int port, String serviceLookupPrefix, DomainNameResolver resolver, ConnectionFactory connectionFactory, TimerFactory timerFactory) { + return new Connector(hostname, port, serviceLookupPrefix, resolver, connectionFactory, timerFactory); } public void setTimeoutMilliseconds(int milliseconds) { @@ -35,8 +35,8 @@ public class Connector { queriedAllServices = false; serviceQueryResults = new ArrayList(); - if (doServiceLookups) { - serviceQuery = resolver.createServiceQuery("_xmpp-client._tcp." + hostname); + if (serviceLookupPrefix != null) { + serviceQuery = resolver.createServiceQuery(serviceLookupPrefix + hostname); serviceQuery.onResult.connect(new Slot1>() { public void call(Collection p1) { handleServiceQueryResult(p1); @@ -64,13 +64,13 @@ public class Connector { public final Signal2 onConnectFinished = new Signal2(); - private Connector(String hostname,int port, boolean doServiceLookups, DomainNameResolver resolver, ConnectionFactory connectionFactory, TimerFactory timerFactory) { + private Connector(String hostname,int port, String serviceLookupPrefix, DomainNameResolver resolver, ConnectionFactory connectionFactory, TimerFactory timerFactory) { this.hostname = hostname; this.resolver = resolver; this.connectionFactory = connectionFactory; this.timerFactory = timerFactory; this.port = port; - this.doServiceLookups = doServiceLookups; + this.serviceLookupPrefix = serviceLookupPrefix; } private void handleServiceQueryResult(Collection result) { @@ -231,6 +231,6 @@ public class Connector { private Connection currentConnection; private SignalConnection currentConnectionConnectFinishedConnection; private final int port; - private final boolean doServiceLookups; + private final String serviceLookupPrefix; private boolean foundSomeDNS = false; } -- cgit v0.10.2-6-g49f6