mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
Rename 'serviceName' to 'xmppServiceDomain'
Also use 'null' as default value for the resource, to enforce server generated resources. Fixes Smack-665
This commit is contained in:
parent
0c8199650b
commit
f369a009ac
38 changed files with 116 additions and 104 deletions
|
@ -193,7 +193,7 @@ public class MessageTest extends SmackTestCase {
|
|||
public void testHighestPriority() throws Exception {
|
||||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
new ConnectionConfiguration(getHost(), getPort(), getXMPPServiceDomain());
|
||||
XMPPTCPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||
conn3.connect();
|
||||
conn3.login(getUsername(0), getPassword(0), "Home");
|
||||
|
@ -242,7 +242,7 @@ public class MessageTest extends SmackTestCase {
|
|||
public void testHighestShow() throws Exception {
|
||||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
new ConnectionConfiguration(getHost(), getPort(), getXMPPServiceDomain());
|
||||
XMPPTCPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||
conn3.connect();
|
||||
conn3.login(getUsername(0), getPassword(0), "Home");
|
||||
|
@ -291,7 +291,7 @@ public class MessageTest extends SmackTestCase {
|
|||
public void testMostRecentActive() throws Exception {
|
||||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
new ConnectionConfiguration(getHost(), getPort(), getXMPPServiceDomain());
|
||||
XMPPTCPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||
conn3.connect();
|
||||
conn3.login(getUsername(0), getPassword(0), "Home");
|
||||
|
@ -307,7 +307,7 @@ public class MessageTest extends SmackTestCase {
|
|||
getConnection(0).sendStanza(presence);
|
||||
|
||||
connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
new ConnectionConfiguration(getHost(), getPort(), getXMPPServiceDomain());
|
||||
XMPPTCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
conn4.connect();
|
||||
conn4.login(getUsername(0), getPassword(0), "Home2");
|
||||
|
@ -326,7 +326,7 @@ public class MessageTest extends SmackTestCase {
|
|||
PacketCollector coll4 = conn4.createPacketCollector(new MessageTypeFilter(Message.Type.chat));
|
||||
|
||||
// Send a message from this resource to indicate most recent activity
|
||||
conn3.sendStanza(new Message("admin@" + getServiceName()));
|
||||
conn3.sendStanza(new Message("admin@" + getXMPPServiceDomain()));
|
||||
|
||||
// User1 sends a message to the bare JID of User0
|
||||
Chat chat = getConnection(1).getChatManager().createChat(getBareJID(0), null);
|
||||
|
|
|
@ -168,7 +168,7 @@ public class PresenceTest extends SmackTestCase {
|
|||
public void testMultipleResources() throws Exception {
|
||||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
new ConnectionConfiguration(getHost(), getPort(), getXMPPServiceDomain());
|
||||
XMPPTCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
conn4.connect();
|
||||
conn4.login(getUsername(1), getPassword(1), "Home");
|
||||
|
|
|
@ -434,7 +434,7 @@ public class RosterSmackTest extends SmackTestCase {
|
|||
|
||||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
new ConnectionConfiguration(getHost(), getPort(), getXMPPServiceDomain());
|
||||
XMPPTCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
conn4.connect();
|
||||
conn4.login(getUsername(1), getPassword(1), "Home");
|
||||
|
@ -455,7 +455,7 @@ public class RosterSmackTest extends SmackTestCase {
|
|||
assertTrue("Returned a null Presence for an existing user", presence.isAvailable());
|
||||
|
||||
// Check that the right presence is returned for a user+resource
|
||||
presence = roster.getPresenceResource(getUsername(1) + "@" + conn4.getServiceName() + "/Home");
|
||||
presence = roster.getPresenceResource(getUsername(1) + "@" + conn4.getXMPPServiceDomain() + "/Home");
|
||||
assertEquals("Returned the wrong Presence", "Home",
|
||||
StringUtils.parseResource(presence.getFrom()));
|
||||
|
||||
|
@ -466,7 +466,7 @@ public class RosterSmackTest extends SmackTestCase {
|
|||
StringUtils.parseResource(presence.getFrom()));
|
||||
|
||||
// Check the returned presence for a non-existent user+resource
|
||||
presence = roster.getPresenceResource("noname@" + getServiceName() + "/Smack");
|
||||
presence = roster.getPresenceResource("noname@" + getXMPPServiceDomain() + "/Smack");
|
||||
assertFalse("Available presence was returned for a non-existing user", presence.isAvailable());
|
||||
assertEquals("Returned Presence for a non-existing user has the incorrect type",
|
||||
Presence.Type.unavailable, presence.getType());
|
||||
|
@ -501,7 +501,7 @@ public class RosterSmackTest extends SmackTestCase {
|
|||
public void testMultipleResources() throws Exception {
|
||||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
new ConnectionConfiguration(getHost(), getPort(), getXMPPServiceDomain());
|
||||
XMPPTCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
conn4.connect();
|
||||
conn4.login(getUsername(1), getPassword(1), "Home");
|
||||
|
@ -566,7 +566,7 @@ public class RosterSmackTest extends SmackTestCase {
|
|||
|
||||
// Create another connection for the same user of connection 0
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
new ConnectionConfiguration(getHost(), getPort(), getXMPPServiceDomain());
|
||||
XMPPTCPConnection conn2 = new XMPPConnection(connectionConfiguration);
|
||||
conn2.connect();
|
||||
conn2.login(getUsername(0), getPassword(0), "Home");
|
||||
|
|
|
@ -185,7 +185,7 @@ public abstract class SmackTestCase extends TestCase {
|
|||
* @return the bare XMPP address of the user (e.g. johndoe@jabber.org).
|
||||
*/
|
||||
protected String getBareJID(int index) {
|
||||
return getUsername(index) + "@" + getConnection(index).getServiceName();
|
||||
return getUsername(index) + "@" + getConnection(index).getXMPPServiceDomain();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,7 +207,7 @@ public abstract class SmackTestCase extends TestCase {
|
|||
return port;
|
||||
}
|
||||
|
||||
protected String getServiceName() {
|
||||
protected String getXMPPServiceDomain() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ public abstract class SmackTestCase extends TestCase {
|
|||
// cases, but could fail if the user set a hostname in their XMPP server
|
||||
// that will not resolve as a network connection.
|
||||
host = connections[0].getHost();
|
||||
serviceName = connections[0].getServiceName();
|
||||
serviceName = connections[0].getXMPPServiceDomain();
|
||||
|
||||
if (!createOfflineConnections()) {
|
||||
for (int i = 0; i < getMaxConnections(); i++) {
|
||||
|
|
|
@ -111,7 +111,7 @@ public class DNSUtilTest {
|
|||
}
|
||||
|
||||
private void xmppClientDomainTest() {
|
||||
List<HostAddress> hostAddresses = DNSUtil.resolveXMPPDomain(igniterealtimeDomain);
|
||||
List<HostAddress> hostAddresses = DNSUtil.resolveXMPPServiceDomain(igniterealtimeDomain);
|
||||
HostAddress ha = hostAddresses.get(0);
|
||||
assertEquals(ha.getFQDN(), igniterealtimeXMPPServer);
|
||||
assertEquals(ha.getPort(), igniterealtimeClientPort);
|
||||
|
|
|
@ -303,12 +303,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
return config;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public DomainBareJid getServiceName() {
|
||||
if (serviceName != null) {
|
||||
return serviceName;
|
||||
return getXMPPServiceDomain();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DomainBareJid getXMPPServiceDomain() {
|
||||
if (xmppServiceDomain != null) {
|
||||
return xmppServiceDomain;
|
||||
}
|
||||
return config.getServiceName();
|
||||
return config.getXMPPServiceDomain();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -506,7 +512,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
// from the login() arguments and the configurations service name, as, for example, when SASL External is used,
|
||||
// the username is not given to login but taken from the 'external' certificate.
|
||||
user = response.getJid();
|
||||
serviceName = user.asDomainBareJid();
|
||||
xmppServiceDomain = user.asDomainBareJid();
|
||||
|
||||
Session.Feature sessionFeature = getFeature(Session.ELEMENT, Session.NAMESPACE);
|
||||
// Only bind the session if it's announced as stream feature by the server, is not optional and not disabled
|
||||
|
@ -549,7 +555,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
&& !config.allowNullOrEmptyUsername;
|
||||
}
|
||||
|
||||
private DomainBareJid serviceName;
|
||||
private DomainBareJid xmppServiceDomain;
|
||||
|
||||
protected List<HostAddress> hostAddresses;
|
||||
|
||||
|
@ -567,7 +573,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
hostAddress = new HostAddress(config.host, config.port);
|
||||
hostAddresses.add(hostAddress);
|
||||
} else {
|
||||
hostAddresses = DNSUtil.resolveXMPPDomain(config.serviceName.toString(), failedAddresses);
|
||||
hostAddresses = DNSUtil.resolveXMPPServiceDomain(config.getXMPPServiceDomain().toString(), failedAddresses);
|
||||
}
|
||||
// If we reach this, then hostAddresses *must not* be empty, i.e. there is at least one host added, either the
|
||||
// config.host one or the host representing the service name by DNSUtil
|
||||
|
|
|
@ -22,8 +22,6 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.packet.Session;
|
||||
import org.jivesoftware.smack.proxy.ProxyInfo;
|
||||
|
@ -54,14 +52,13 @@ public abstract class ConnectionConfiguration {
|
|||
SmackConfiguration.getVersion();
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ConnectionConfiguration.class.getName());
|
||||
|
||||
/**
|
||||
* Hostname of the XMPP server. Usually servers use the same service name as the name
|
||||
* The XMPP domain of the XMPP Service. Usually servers use the same service name as the name
|
||||
* of the server. However, there are some servers like google where host would be
|
||||
* talk.google.com and the serviceName would be gmail.com.
|
||||
*/
|
||||
protected final DomainBareJid serviceName;
|
||||
protected final DomainBareJid xmppServiceDomain;
|
||||
|
||||
protected final String host;
|
||||
protected final int port;
|
||||
|
||||
|
@ -120,9 +117,9 @@ public abstract class ConnectionConfiguration {
|
|||
// Resource can be null, this means that the server must provide one
|
||||
resource = builder.resource;
|
||||
|
||||
serviceName = builder.serviceName;
|
||||
if (serviceName == null) {
|
||||
throw new IllegalArgumentException("Must provide XMPP service name");
|
||||
xmppServiceDomain = builder.xmppServiceDomain;
|
||||
if (xmppServiceDomain == null) {
|
||||
throw new IllegalArgumentException("Must define the XMPP domain");
|
||||
}
|
||||
host = builder.host;
|
||||
port = builder.port;
|
||||
|
@ -159,9 +156,20 @@ public abstract class ConnectionConfiguration {
|
|||
* Returns the server name of the target server.
|
||||
*
|
||||
* @return the server name of the target server.
|
||||
* @deprecated use {@link #getXMPPServiceDomain()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public DomainBareJid getServiceName() {
|
||||
return serviceName;
|
||||
return xmppServiceDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the XMPP domain used by this configuration.
|
||||
*
|
||||
* @return the XMPP domain.
|
||||
*/
|
||||
public DomainBareJid getXMPPServiceDomain() {
|
||||
return xmppServiceDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -407,19 +415,6 @@ public abstract class ConnectionConfiguration {
|
|||
* @param <C> the resulting connection configuration type parameter.
|
||||
*/
|
||||
public static abstract class Builder<B extends Builder<B, C>, C extends ConnectionConfiguration> {
|
||||
private static final Resourcepart DEFAULT_RESOURCE;
|
||||
|
||||
static {
|
||||
Resourcepart resourcepart = null;
|
||||
try {
|
||||
resourcepart = Resourcepart.from("Smack");
|
||||
}
|
||||
catch (XmppStringprepException e) {
|
||||
LOGGER.log(Level.WARNING, "Could not create default resourcepart", e);
|
||||
}
|
||||
DEFAULT_RESOURCE = resourcepart;
|
||||
}
|
||||
|
||||
private SecurityMode securityMode = SecurityMode.ifpossible;
|
||||
private String keystorePath = System.getProperty("javax.net.ssl.keyStore");
|
||||
private String keystoreType = "jks";
|
||||
|
@ -430,14 +425,14 @@ public abstract class ConnectionConfiguration {
|
|||
private HostnameVerifier hostnameVerifier;
|
||||
private CharSequence username;
|
||||
private String password;
|
||||
private Resourcepart resource = DEFAULT_RESOURCE;
|
||||
private Resourcepart resource;
|
||||
private boolean sendPresence = true;
|
||||
private boolean legacySessionDisabled = false;
|
||||
private ProxyInfo proxy;
|
||||
private CallbackHandler callbackHandler;
|
||||
private boolean debuggerEnabled = SmackConfiguration.DEBUG;
|
||||
private SocketFactory socketFactory;
|
||||
private DomainBareJid serviceName;
|
||||
private DomainBareJid xmppServiceDomain;
|
||||
private String host;
|
||||
private int port = 5222;
|
||||
private boolean allowEmptyOrNullUsername = false;
|
||||
|
@ -471,7 +466,7 @@ public abstract class ConnectionConfiguration {
|
|||
* @return a reference to this builder.
|
||||
*/
|
||||
public B setServiceName(DomainBareJid serviceName) {
|
||||
this.serviceName = serviceName;
|
||||
this.xmppServiceDomain = serviceName;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
|
@ -496,7 +491,7 @@ public abstract class ConnectionConfiguration {
|
|||
* @param resource the non-null CharSequence to use a resource.
|
||||
* @return a reference ot this builder.
|
||||
* @throws XmppStringprepException if the CharSequence is not a valid resourcepart.
|
||||
* @see setResource(Resourcepart)
|
||||
* @see #setResource(Resourcepart)
|
||||
*/
|
||||
public B setResource(CharSequence resource) throws XmppStringprepException {
|
||||
Objects.requireNonNull(resource, "resource must not be null");
|
||||
|
|
|
@ -183,14 +183,14 @@ public class SASLAuthentication {
|
|||
currentMechanism = selectMechanism();
|
||||
final CallbackHandler callbackHandler = configuration.getCallbackHandler();
|
||||
final String host = connection.getHost();
|
||||
final DomainBareJid xmppDomain = connection.getServiceName();
|
||||
final DomainBareJid xmppServiceDomain = connection.getXMPPServiceDomain();
|
||||
|
||||
synchronized (this) {
|
||||
if (callbackHandler != null) {
|
||||
currentMechanism.authenticate(host, xmppDomain, callbackHandler);
|
||||
currentMechanism.authenticate(host, xmppServiceDomain, callbackHandler);
|
||||
}
|
||||
else {
|
||||
currentMechanism.authenticate(username, host, xmppDomain, password);
|
||||
currentMechanism.authenticate(username, host, xmppServiceDomain, password);
|
||||
}
|
||||
// Wait until SASL negotiation finishes
|
||||
wait(connection.getPacketReplyTimeout());
|
||||
|
|
|
@ -78,9 +78,20 @@ public interface XMPPConnection {
|
|||
* authenticating with the server the returned value may be different.
|
||||
*
|
||||
* @return the name of the service provided by the XMPP server.
|
||||
// TODO remove this once the java bugs are fixed, causing a warning
|
||||
// * @deprecated use {@link #getXMPPServiceDomain()} instead.
|
||||
*/
|
||||
// @Deprecated
|
||||
public DomainBareJid getServiceName();
|
||||
|
||||
/**
|
||||
* Returns the XMPP Domain of the service provided by the XMPP server and used for this connection. After
|
||||
* authenticating with the server the returned value may be different.
|
||||
*
|
||||
* @return the XMPP domain of this XMPP session.
|
||||
*/
|
||||
public DomainBareJid getXMPPServiceDomain();
|
||||
|
||||
/**
|
||||
* Returns the host name of the server where the XMPP server is running. This would be the
|
||||
* IP address of the server or a name that may be resolved by a DNS server.
|
||||
|
|
|
@ -149,7 +149,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
|
|||
"User logged (" + connection.getConnectionCounter() + "): "
|
||||
+ (isAnonymous ? "" : localpart)
|
||||
+ "@"
|
||||
+ connection.getServiceName()
|
||||
+ connection.getXMPPServiceDomain()
|
||||
+ ":"
|
||||
+ connection.getPort();
|
||||
title += "/" + user.getResourcepart();
|
||||
|
|
|
@ -91,7 +91,7 @@ public class IQReplyFilter implements StanzaFilter {
|
|||
throw new IllegalArgumentException("Must have a local (user) JID set. Either you didn't configure one or you where not connected at least once");
|
||||
}
|
||||
|
||||
server = conn.getServiceName();
|
||||
server = conn.getXMPPServiceDomain();
|
||||
packetId = iqPacket.getStanzaId();
|
||||
|
||||
StanzaFilter iqFilter = new OrFilter(IQTypeFilter.ERROR, IQTypeFilter.RESULT);
|
||||
|
|
|
@ -109,7 +109,7 @@ public class DNSUtil {
|
|||
* @return List of HostAddress, which encompasses the hostname and port that the
|
||||
* XMPP server can be reached at for the specified domain.
|
||||
*/
|
||||
public static List<HostAddress> resolveXMPPDomain(String domain, List<HostAddress> failedAddresses) {
|
||||
public static List<HostAddress> resolveXMPPServiceDomain(String domain, List<HostAddress> failedAddresses) {
|
||||
domain = idnaTransformer.transform(domain);
|
||||
if (dnsResolver == null) {
|
||||
LOGGER.warning("No DNS Resolver active in Smack, will be unable to perform DNS SRV lookups");
|
||||
|
|
|
@ -69,7 +69,7 @@ public class DummyConnection extends AbstractXMPPConnection {
|
|||
try {
|
||||
return JidCreate.fullFrom(config.getUsername()
|
||||
+ "@"
|
||||
+ config.getServiceName()
|
||||
+ config.getXMPPServiceDomain()
|
||||
+ "/"
|
||||
+ (config.getResource() != null ? config.getResource() : "Test"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue