diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java index bddd37851..39ec4b976 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java @@ -43,6 +43,7 @@ import org.jivesoftware.smack.packet.Presence.Type; import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure; import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Success; import org.jivesoftware.smack.util.PacketParserUtils; +import org.jxmpp.jid.DomainBareJid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserFactory; import org.igniterealtime.jbosh.AbstractBody; @@ -116,7 +117,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { * @param xmppDomain the XMPP service name * (e.g. domain.lt for the user alice@domain.lt) */ - public XMPPBOSHConnection(String username, String password, boolean https, String host, int port, String filePath, String xmppDomain) { + public XMPPBOSHConnection(String username, String password, boolean https, String host, int port, String filePath, DomainBareJid xmppDomain) { this(BOSHConfiguration.builder().setUseHttps(https).setHost(host) .setPort(port).setFile(filePath).setServiceName(xmppDomain) .setUsernameAndPassword(username, password).build()); @@ -145,7 +146,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { // Initialize BOSH client BOSHClientConfig.Builder cfgBuilder = BOSHClientConfig.Builder - .create(config.getURI(), config.getServiceName()); + .create(config.getURI(), config.getServiceName().toString()); if (config.isProxyEnabled()) { cfgBuilder.setProxy(config.getProxyAddress(), config.getProxyPort()); } @@ -537,7 +538,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { XMPPBOSHConnection.XMPP_BOSH_NS).setAttribute( BodyQName.createWithPrefix(XMPPBOSHConnection.XMPP_BOSH_NS, "restart", "xmpp"), "true").setAttribute( - BodyQName.create(XMPPBOSHConnection.BOSH_URI, "to"), getServiceName()).build()); + BodyQName.create(XMPPBOSHConnection.BOSH_URI, "to"), getServiceName().toString()).build()); Success success = new Success(parser.nextText()); getSASLAuthentication().authenticated(success); break; diff --git a/smack-core/build.gradle b/smack-core/build.gradle index c350291bb..9b2f6c973 100644 --- a/smack-core/build.gradle +++ b/smack-core/build.gradle @@ -9,7 +9,8 @@ Smack core components.""" dependencies { compile 'xpp3:xpp3:1.1.4c' compile "org.jxmpp:jxmpp-core:$jxmppVersion" - // compile "org.igniterealtime.jxmpp:jxmpp-jid:$jxmppVersion" + compile "org.jxmpp:jxmpp-jid:$jxmppVersion" + testCompile "org.jxmpp:jxmpp-jid:$jxmppVersion:tests" testCompile 'junit:junit:4.11' testCompile 'xmlunit:xmlunit:1.5' testCompile 'org.powermock:powermock-module-junit4:1.5.5' diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 5bdb0fa60..7ab1e558f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -81,6 +81,9 @@ import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smack.util.SmackExecutorThreadFactory; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.dns.HostAddress; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.Jid; import org.jxmpp.util.XmppStringUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -164,7 +167,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { * certificate. *

*/ - protected String user; + protected FullJid user; protected boolean connected = false; @@ -342,7 +345,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } @Override - public String getServiceName() { + public DomainBareJid getServiceName() { if (serviceName != null) { return serviceName; } @@ -510,7 +513,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } @Override - public final String getUser() { + public final FullJid getUser() { return user; } @@ -550,7 +553,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 = XmppStringUtils.parseDomain(user); + serviceName = 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 @@ -590,7 +593,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { && !config.allowNullOrEmptyUsername; } - private String serviceName; + private DomainBareJid serviceName; protected List hostAddresses; @@ -608,7 +611,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { hostAddress = new HostAddress(config.host, config.port); hostAddresses.add(hostAddress); } else { - hostAddresses = DNSUtil.resolveXMPPDomain(config.serviceName, failedAddresses); + hostAddresses = DNSUtil.resolveXMPPDomain(config.serviceName.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 @@ -645,7 +648,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { throwNotConnectedExceptionIfAppropriate(); switch (fromMode) { case OMITTED: - packet.setFrom(null); + packet.setFrom((Jid) null); break; case USER: packet.setFrom(getUser()); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java index 125c691ed..e40d7c3f1 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java @@ -19,6 +19,7 @@ package org.jivesoftware.smack; import org.jivesoftware.smack.packet.Session; import org.jivesoftware.smack.proxy.ProxyInfo; +import org.jxmpp.jid.DomainBareJid; import javax.net.SocketFactory; import javax.net.ssl.HostnameVerifier; @@ -43,7 +44,7 @@ public abstract class ConnectionConfiguration { * 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 String serviceName; + protected final DomainBareJid serviceName; protected final String host; protected final int port; @@ -136,7 +137,7 @@ public abstract class ConnectionConfiguration { * * @return the server name of the target server. */ - public String getServiceName() { + public DomainBareJid getServiceName() { return serviceName; } @@ -382,7 +383,7 @@ public abstract class ConnectionConfiguration { private CallbackHandler callbackHandler; private boolean debuggerEnabled = SmackConfiguration.DEBUG; private SocketFactory socketFactory; - private String serviceName; + private DomainBareJid serviceName; private String host; private int port = 5222; private boolean allowEmptyOrNullUsername = false; @@ -413,7 +414,7 @@ public abstract class ConnectionConfiguration { * @param serviceName the service name * @return a reference to this builder. */ - public B setServiceName(String serviceName) { + public B setServiceName(DomainBareJid serviceName) { this.serviceName = serviceName; return getThis(); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java index 807f68ef1..d0c747800 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackException.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; import org.jivesoftware.smack.util.dns.HostAddress; +import org.jxmpp.jid.Jid; /** * Smack uses SmackExceptions for errors that are not defined by any XMPP specification. @@ -225,13 +226,13 @@ public class SmackException extends Exception { private static final long serialVersionUID = 4713404802621452016L; private final String feature; - private final String jid; + private final Jid jid; public FeatureNotSupportedException(String feature) { this(feature, null); } - public FeatureNotSupportedException(String feature, String jid) { + public FeatureNotSupportedException(String feature, Jid jid) { super(feature + " not supported" + (jid == null ? "" : " by '" + jid + "'")); this.jid = jid; this.feature = feature; @@ -252,7 +253,7 @@ public class SmackException extends Exception { * * @return the JID which does not support the feature, or null */ - public String getJid() { + public Jid getJid() { return jid; } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java index 89877edd8..4cc9de333 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java @@ -26,6 +26,8 @@ import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PlainStreamElement; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; /** * The XMPPConnection interface provides an interface for connections to an XMPP server and @@ -78,7 +80,7 @@ public interface XMPPConnection { * * @return the name of the service provided by the XMPP server. */ - public String getServiceName(); + public DomainBareJid getServiceName(); /** * Returns the host name of the server where the XMPP server is running. This would be the @@ -103,7 +105,7 @@ public interface XMPPConnection { * * @return the full XMPP address of the user logged in. */ - public String getUser(); + public FullJid getUser(); /** * Returns the stream ID for this connection, which is the value set by the server diff --git a/smack-core/src/main/java/org/jivesoftware/smack/debugger/AbstractDebugger.java b/smack-core/src/main/java/org/jivesoftware/smack/debugger/AbstractDebugger.java index 199167f02..758738fc8 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/debugger/AbstractDebugger.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/debugger/AbstractDebugger.java @@ -24,7 +24,7 @@ import org.jivesoftware.smack.util.ObservableReader; import org.jivesoftware.smack.util.ObservableWriter; import org.jivesoftware.smack.util.ReaderListener; import org.jivesoftware.smack.util.WriterListener; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.FullJid; import java.io.Reader; import java.io.Writer; @@ -141,8 +141,9 @@ public abstract class AbstractDebugger implements SmackDebugger { return writer; } - public void userHasLogged(String user) { - String localpart = XmppStringUtils.parseLocalpart(user); + @Override + public void userHasLogged(FullJid user) { + String localpart = user.getLocalpart().toString(); boolean isAnonymous = "".equals(localpart); String title = "User logged (" + connection.getConnectionCounter() + "): " @@ -151,7 +152,7 @@ public abstract class AbstractDebugger implements SmackDebugger { + connection.getServiceName() + ":" + connection.getPort(); - title += "/" + XmppStringUtils.parseResource(user); + title += "/" + user.getResourcepart(); log(title); // Add the connection listener to the connection so that the debugger can be notified // whenever the connection is closed. diff --git a/smack-core/src/main/java/org/jivesoftware/smack/debugger/SmackDebugger.java b/smack-core/src/main/java/org/jivesoftware/smack/debugger/SmackDebugger.java index 6bef09459..b4f85d857 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/debugger/SmackDebugger.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/debugger/SmackDebugger.java @@ -21,6 +21,7 @@ import java.io.Reader; import java.io.Writer; import org.jivesoftware.smack.PacketListener; +import org.jxmpp.jid.FullJid; /** * Interface that allows for implementing classes to debug XML traffic. That is a GUI window that @@ -40,7 +41,7 @@ public interface SmackDebugger { * * @param user the user@host/resource that has just logged in */ - public abstract void userHasLogged(String user); + public abstract void userHasLogged(FullJid user); /** * Returns the special Reader that wraps the main Reader and logs data to the GUI. diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java index ee570aa78..78af6cdca 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java @@ -17,10 +17,8 @@ package org.jivesoftware.smack.filter; -import java.util.Locale; - import org.jivesoftware.smack.packet.Stanza; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.Jid; /** * Filter for packets where the "from" field exactly matches a specified JID. If the specified @@ -32,12 +30,12 @@ import org.jxmpp.util.XmppStringUtils; */ public class FromMatchesFilter implements PacketFilter { - private final String address; + private final Jid address; /** * Flag that indicates if the checking will be done against bare JID addresses or full JIDs. */ - private final boolean matchBareJID; + private final boolean ignoreResourcepart; /** * Creates a filter matching on the "from" field. The from address must be the same as the @@ -46,11 +44,16 @@ public class FromMatchesFilter implements PacketFilter { * * @param address The address to filter for. If null is given, the packet must not * have a from address. - * @param matchBare + * @param ignoreResourcepart */ - public FromMatchesFilter(String address, boolean matchBare) { - this.address = (address == null) ? null : address.toLowerCase(Locale.US); - matchBareJID = matchBare; + public FromMatchesFilter(Jid address, boolean ignoreResourcepart) { + if (address != null && ignoreResourcepart) { + this.address = address.withoutResource(); + } + else { + this.address = address; + } + this.ignoreResourcepart = ignoreResourcepart; } /** @@ -61,8 +64,8 @@ public class FromMatchesFilter implements PacketFilter { * @param address The address to filter for. If null is given, the packet must not * have a from address. */ - public static FromMatchesFilter create(String address) { - return new FromMatchesFilter(address, "".equals(XmppStringUtils.parseResource(address))) ; + public static FromMatchesFilter create(Jid address) { + return new FromMatchesFilter(address, address.hasNoResource()) ; } /** @@ -72,8 +75,8 @@ public class FromMatchesFilter implements PacketFilter { * @param address The address to filter for. If null is given, the packet must not * have a from address. */ - public static FromMatchesFilter createBare(String address) { - address = (address == null) ? null : XmppStringUtils.parseBareJid(address); + public static FromMatchesFilter createBare(Jid address) { + address = (address == null) ? null : address; return new FromMatchesFilter(address, true); } @@ -85,25 +88,24 @@ public class FromMatchesFilter implements PacketFilter { * @param address The address to filter for. If null is given, the packet must not * have a from address. */ - public static FromMatchesFilter createFull(String address) { + public static FromMatchesFilter createFull(Jid address) { return new FromMatchesFilter(address, false); } public boolean accept(Stanza packet) { - String from = packet.getFrom(); + Jid from = packet.getFrom(); if (from == null) { return address == null; } - // Simplest form of NAMEPREP/STRINGPREP - from = from.toLowerCase(Locale.US); - if (matchBareJID) { - from = XmppStringUtils.parseBareJid(from); + + if (ignoreResourcepart) { + from = from.withoutResource(); } return from.equals(address); } public String toString() { - String matchMode = matchBareJID ? "bare" : "full"; + String matchMode = ignoreResourcepart ? "ignoreResourcepart" : "full"; return "FromMatchesFilter (" +matchMode + "): " + address; } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java index fc0673548..499029563 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java @@ -16,14 +16,15 @@ */ package org.jivesoftware.smack.filter; -import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Stanza; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.Jid; /** * Filters for packets which are a valid reply to an IQ request. @@ -53,9 +54,9 @@ public class IQReplyFilter implements PacketFilter { private final PacketFilter iqAndIdFilter; private final OrFilter fromFilter; - private final String to; - private final String local; - private final String server; + private final Jid to; + private final FullJid local; + private final DomainBareJid server; private final String packetId; /** @@ -84,18 +85,13 @@ public class IQReplyFilter implements PacketFilter { if (!iqPacket.isRequestIQ()) { throw new IllegalArgumentException("IQ must be a request IQ, i.e. of type 'get' or 'set'."); } - if (iqPacket.getTo() != null) { - to = iqPacket.getTo().toLowerCase(Locale.US); - } else { - to = null; - } - final String localJid = conn.getUser(); - if (localJid == null) { + to = iqPacket.getTo(); + local = conn.getUser(); + if (local == null) { throw new IllegalArgumentException("Must have a local (user) JID set. Either you didn't configure one or you where not connected at least once"); } - local = localJid.toLowerCase(Locale.US); - server = conn.getServiceName().toLowerCase(Locale.US); + server = conn.getServiceName(); packetId = iqPacket.getStanzaId(); PacketFilter iqFilter = new OrFilter(IQTypeFilter.ERROR, IQTypeFilter.RESULT); @@ -107,7 +103,7 @@ public class IQReplyFilter implements PacketFilter { fromFilter.addFilter(FromMatchesFilter.createBare(local)); fromFilter.addFilter(FromMatchesFilter.createFull(server)); } - else if (to.equals(XmppStringUtils.parseBareJid(local))) { + else if (to.equals(local.asBareJid())) { fromFilter.addFilter(FromMatchesFilter.createFull(null)); } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java index cfb0d3ed4..e0fd2f900 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java @@ -16,25 +16,23 @@ */ package org.jivesoftware.smack.filter; -import java.util.Locale; - import org.jivesoftware.smack.packet.Stanza; +import org.jxmpp.jid.Jid; public class ToFilter implements PacketFilter { - private final String to; + private final Jid to; - public ToFilter(String to) { - this.to = to.toLowerCase(Locale.US); + public ToFilter(Jid to) { + this.to = to; } @Override public boolean accept(Stanza packet) { - String packetTo = packet.getTo(); + Jid packetTo = packet.getTo(); if (packetTo == null) { return false; } - packetTo = packetTo.toLowerCase(Locale.US); return packetTo.equals(to); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Bind.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Bind.java index df59cc5f6..5001bcc1f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Bind.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Bind.java @@ -17,6 +17,8 @@ package org.jivesoftware.smack.packet; +import org.jxmpp.jid.FullJid; + /** * IQ packet used by Smack to bind a resource and to obtain the jid assigned by the server. * There are two ways to bind a resource. One is simply sending an empty Bind packet where the @@ -34,9 +36,9 @@ public class Bind extends IQ { public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-bind"; private final String resource; - private final String jid; + private final FullJid jid; - public Bind(String resource, String jid) { + public Bind(String resource, FullJid jid) { super(ELEMENT, NAMESPACE); this.resource = resource; this.jid = jid; @@ -46,7 +48,7 @@ public class Bind extends IQ { return resource; } - public String getJid() { + public FullJid getJid() { return jid; } @@ -56,7 +58,7 @@ public class Bind extends IQ { return bind; } - public static Bind newResult(String jid) { + public static Bind newResult(FullJid jid) { return new Bind(null, jid); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java index 22b25a810..2cd9e9209 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java @@ -25,6 +25,7 @@ import java.util.Locale; import java.util.Set; import org.jivesoftware.smack.util.XmlStringBuilder; +import org.jxmpp.jid.Jid; /** * Represents XMPP message packets. A message can be one of several types: @@ -72,7 +73,7 @@ public final class Message extends Stanza { * * @param to the recipient of the message. */ - public Message(String to) { + public Message(Jid to) { setTo(to); } @@ -82,7 +83,7 @@ public final class Message extends Stanza { * @param to the user to send the message to. * @param type the message type. */ - public Message(String to, Type type) { + public Message(Jid to, Type type) { this(to); setType(type); } @@ -93,7 +94,7 @@ public final class Message extends Stanza { * @param to the user to send the message to. * @param body the body of the message. */ - public Message(String to, String body) { + public Message(Jid to, String body) { this(to); setBody(body); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java index 205ce160b..09f91452b 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java @@ -23,6 +23,9 @@ import org.jivesoftware.smack.packet.id.StanzaIdUtil; import org.jivesoftware.smack.util.MultiMap; import org.jivesoftware.smack.util.PacketUtil; import org.jivesoftware.smack.util.XmlStringBuilder; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; import org.jxmpp.util.XmppStringUtils; import java.util.Collection; @@ -56,8 +59,8 @@ public abstract class Stanza implements TopLevelStreamElement { private final MultiMap packetExtensions = new MultiMap<>(); private String id = null; - private String to = null; - private String from = null; + private Jid to; + private Jid from; private XMPPError error = null; /** @@ -154,7 +157,7 @@ public abstract class Stanza implements TopLevelStreamElement { * @return who the packet is being sent to, or null if the * value has not been set. */ - public String getTo() { + public Jid getTo() { return to; } @@ -163,8 +166,28 @@ public abstract class Stanza implements TopLevelStreamElement { * the "to" attribute optional, so it does not always need to be set. * * @param to who the packet is being sent to. + * @throws IllegalArgumentException if to is not a valid JID String. + * @deprecated use {@link #setTo(Jid)} instead. */ + @Deprecated public void setTo(String to) { + Jid jid; + try { + jid = JidCreate.from(to); + } + catch (XmppStringprepException e) { + throw new IllegalArgumentException(e); + } + setTo(jid); + } + + /** + * Sets who the packet is being sent "to". The XMPP protocol often makes + * the "to" attribute optional, so it does not always need to be set. + * + * @param to who the packet is being sent to. + */ + public void setTo(Jid to) { this.to = to; } @@ -176,7 +199,7 @@ public abstract class Stanza implements TopLevelStreamElement { * @return who the packet is being sent from, or null if the * value has not been set. */ - public String getFrom() { + public Jid getFrom() { return from; } @@ -186,8 +209,29 @@ public abstract class Stanza implements TopLevelStreamElement { * be set. * * @param from who the packet is being sent to. + * @throws IllegalArgumentException if from is not a valid JID String. + * @deprecated use {@link #setFrom(Jid)} instead. */ + @Deprecated public void setFrom(String from) { + Jid jid; + try { + jid = JidCreate.from(from); + } + catch (XmppStringprepException e) { + throw new IllegalArgumentException(e); + } + setFrom(jid); + } + + /** + * Sets who the packet is being sent "from". The XMPP protocol often + * makes the "from" attribute optional, so it does not always need to + * be set. + * + * @param from who the packet is being sent to. + */ + public void setFrom(Jid from) { this.from = from; } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/BindIQProvider.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/BindIQProvider.java index ea78378dc..031d130be 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/provider/BindIQProvider.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/BindIQProvider.java @@ -20,6 +20,8 @@ import java.io.IOException; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.packet.Bind; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.impl.JidCreate; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -40,7 +42,8 @@ public class BindIQProvider extends IQProvider { bind = Bind.newSet(parser.nextText()); break; case "jid": - bind = Bind.newResult(parser.nextText()); + FullJid fullJid = JidCreate.fullFrom(parser.nextText()); + bind = Bind.newResult(fullJid); break; } break; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java b/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java index bde8b6310..b476186fa 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java @@ -24,6 +24,7 @@ import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Response; import org.jivesoftware.smack.util.StringTransformer; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.stringencoder.Base64; +import org.jxmpp.jid.DomainBareJid; import javax.security.auth.callback.CallbackHandler; @@ -33,9 +34,9 @@ import javax.security.auth.callback.CallbackHandler; *
  • {@link #getName()} -- returns the common name of the SASL mechanism.
  • * * Subclasses will likely want to implement their own versions of these methods: - *
  • {@link #authenticate(String, String, String, String)} -- Initiate authentication stanza using the + *
  • {@link #authenticate(String, String, DomainBareJid, String)} -- Initiate authentication stanza using the * deprecated method.
  • - *
  • {@link #authenticate(String, String, CallbackHandler)} -- Initiate authentication stanza + *
  • {@link #authenticate(String, DomainBareJid, CallbackHandler)} -- Initiate authentication stanza * using the CallbackHandler method.
  • *
  • {@link #challengeReceived(String, boolean)} -- Handle a challenge from the server.
  • * @@ -104,7 +105,7 @@ public abstract class SASLMechanism implements Comparable { /** * The name of the XMPP service */ - protected String serviceName; + protected DomainBareJid serviceName; /** * The users password @@ -115,7 +116,7 @@ public abstract class SASLMechanism implements Comparable { /** * Builds and sends the auth stanza to the server. Note that this method of * authentication is not recommended, since it is very inflexible. Use - * {@link #authenticate(String, String, CallbackHandler)} whenever possible. + * {@link #authenticate(String, DomainBareJid, CallbackHandler)} whenever possible. * * Explanation of auth stanza: * @@ -160,7 +161,7 @@ public abstract class SASLMechanism implements Comparable { * @throws NotConnectedException * @throws InterruptedException */ - public final void authenticate(String username, String host, String serviceName, String password) + public final void authenticate(String username, String host, DomainBareJid serviceName, String password) throws SmackException, NotConnectedException, InterruptedException { this.authenticationId = username; this.host = host; @@ -184,7 +185,7 @@ public abstract class SASLMechanism implements Comparable { * @throws NotConnectedException * @throws InterruptedException */ - public void authenticate(String host,String serviceName, CallbackHandler cbh) + public void authenticate(String host, DomainBareJid serviceName, CallbackHandler cbh) throws SmackException, NotConnectedException, InterruptedException { this.host = host; this.serviceName = serviceName; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java index 54f994609..3652a974a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java @@ -47,6 +47,7 @@ import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.ProviderManager; import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; @@ -222,8 +223,8 @@ public class PacketParserUtils { final int initialDepth = parser.getDepth(); Message message = new Message(); message.setStanzaId(parser.getAttributeValue("", "id")); - message.setTo(parser.getAttributeValue("", "to")); - message.setFrom(parser.getAttributeValue("", "from")); + message.setTo(ParserUtils.getJidAttribute(parser, "to")); + message.setFrom(ParserUtils.getJidAttribute(parser, "from")); String typeString = parser.getAttributeValue("", "type"); if (typeString != null) { message.setType(Message.Type.fromString(typeString)); @@ -527,8 +528,8 @@ public class PacketParserUtils { type = Presence.Type.fromString(typeString); } Presence presence = new Presence(type); - presence.setTo(parser.getAttributeValue("", "to")); - presence.setFrom(parser.getAttributeValue("", "from")); + presence.setTo(ParserUtils.getJidAttribute(parser, "to")); + presence.setFrom(ParserUtils.getJidAttribute(parser, "from")); presence.setStanzaId(parser.getAttributeValue("", "id")); String language = getLanguageAttribute(parser); @@ -606,8 +607,8 @@ public class PacketParserUtils { XMPPError error = null; final String id = parser.getAttributeValue("", "id"); - final String to = parser.getAttributeValue("", "to"); - final String from = parser.getAttributeValue("", "from"); + final Jid to = ParserUtils.getJidAttribute(parser, "to"); + final Jid from = ParserUtils.getJidAttribute(parser, "from"); final IQ.Type type = IQ.Type.fromString(parser.getAttributeValue("", "type")); outerloop: while (true) { diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java index acd2829f3..9091b4688 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java @@ -19,6 +19,10 @@ package org.jivesoftware.smack.util; import java.io.IOException; import java.util.Locale; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.jid.parts.Resourcepart; +import org.jxmpp.stringprep.XmppStringprepException; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -39,6 +43,26 @@ public class ParserUtils { } } + public static Jid getJidAttribute(XmlPullParser parser) throws XmppStringprepException { + return getJidAttribute(parser, "jid"); + } + + public static Jid getJidAttribute(XmlPullParser parser, String name) throws XmppStringprepException { + final String jidString = parser.getAttributeValue("", name); + if (jidString == null) { + return null; + } + return JidCreate.from(jidString); + } + + public static Resourcepart getResourcepartAttribute(XmlPullParser parser, String name) throws XmppStringprepException { + final String resourcepartString = parser.getAttributeValue("", name); + if (resourcepartString == null) { + return null; + } + return Resourcepart.from(resourcepartString); + } + /** * Get the boolean value of an argument. * diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java b/smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java index 0f7ebe138..9de90788c 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java @@ -63,6 +63,16 @@ public class XmlStringBuilder implements Appendable, CharSequence { return this; } + /** + * + * @param name + * @param content + * @return the XmlStringBuilder + */ + public XmlStringBuilder element(String name, CharSequence content) { + return element(name, content.toString()); + } + public XmlStringBuilder element(String name, Enum content) { assert content != null; element(name, content.name()); @@ -81,6 +91,13 @@ public class XmlStringBuilder implements Appendable, CharSequence { return this; } + public XmlStringBuilder optElement(String name, CharSequence content) { + if (content != null) { + element(name, content.toString()); + } + return this; + } + public XmlStringBuilder optElement(Element element) { if (element != null) { append(element.toXML()); @@ -168,6 +185,10 @@ public class XmlStringBuilder implements Appendable, CharSequence { return this; } + public XmlStringBuilder attribute(String name, CharSequence value) { + return attribute(name, value.toString()); + } + public XmlStringBuilder attribute(String name, Enum value) { assert value != null; attribute(name, value.name()); @@ -186,6 +207,13 @@ public class XmlStringBuilder implements Appendable, CharSequence { return this; } + public XmlStringBuilder optAttribute(String name, CharSequence value) { + if (value != null) { + attribute(name, value.toString()); + } + return this; + } + public XmlStringBuilder optAttribute(String name, Enum value) { if (value != null) { attribute(name, value.toString()); @@ -244,6 +272,10 @@ public class XmlStringBuilder implements Appendable, CharSequence { return this; } + public XmlStringBuilder escape(CharSequence text) { + return escape(text.toString()); + } + public XmlStringBuilder prelude(PacketExtension pe) { return prelude(pe.getElementName(), pe.getNamespace()); } diff --git a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java index bd103c17a..68e9438b9 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java @@ -27,6 +27,10 @@ import java.util.concurrent.TimeUnit; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.PlainStreamElement; import org.jivesoftware.smack.packet.TopLevelStreamElement; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.JidTestUtil; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; /** * A dummy implementation of {@link XMPPConnection}, intended to be used during @@ -51,7 +55,7 @@ public class DummyConnection extends AbstractXMPPConnection { private final BlockingQueue queue = new LinkedBlockingQueue(); public static ConnectionConfiguration.Builder getDummyConfigurationBuilder() { - return DummyConnectionConfiguration.builder().setServiceName("example.org").setUsernameAndPassword("dummy", + return DummyConnectionConfiguration.builder().setServiceName(JidTestUtil.EXAMPLE_ORG).setUsernameAndPassword("dummy", "dummypass"); } @@ -59,17 +63,26 @@ public class DummyConnection extends AbstractXMPPConnection { this(getDummyConfigurationBuilder().build()); } + private FullJid getUserJid() { + try { + return JidCreate.fullFrom(config.getUsername() + + "@" + + config.getServiceName() + + "/" + + (config.getResource() != null ? config.getResource() : "Test")); + } + catch (XmppStringprepException e) { + throw new IllegalStateException(e); + } + } + public DummyConnection(ConnectionConfiguration configuration) { super(configuration); for (ConnectionCreationListener listener : XMPPConnectionRegistry.getConnectionCreationListeners()) { listener.connectionCreated(this); } - user = config.getUsername() - + "@" - + config.getServiceName() - + "/" - + (config.getResource() != null ? config.getResource() : "Test"); + user = getUserJid(); } @Override @@ -104,11 +117,7 @@ public class DummyConnection extends AbstractXMPPConnection { @Override protected void loginNonAnonymously(String username, String password, String resource) throws XMPPException { - user = username - + "@" - + config.getServiceName() - + "/" - + (resource != null ? resource : "Test"); + user = getUserJid(); authenticated = true; } diff --git a/smack-core/src/test/java/org/jivesoftware/smack/filters/FromMatchesFilterTest.java b/smack-core/src/test/java/org/jivesoftware/smack/filters/FromMatchesFilterTest.java index bc4077b89..d9bb8938e 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/filters/FromMatchesFilterTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/filters/FromMatchesFilterTest.java @@ -22,6 +22,9 @@ import static org.junit.Assert.assertFalse; import org.jivesoftware.smack.filter.FromMatchesFilter; import org.jivesoftware.smack.packet.Stanza; import org.junit.Test; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.JidTestUtil; /** * @@ -29,16 +32,16 @@ import org.junit.Test; * */ public class FromMatchesFilterTest { - private static final String BASE_JID1 = "ss@muc.myserver.com"; - private static final String FULL_JID1_R1 = BASE_JID1 + "/resource"; - private static final String FULL_JID1_R2 = BASE_JID1 + "/resource2"; - private static final String BASE_JID2 = "sss@muc.myserver.com"; - private static final String FULL_JID2 = BASE_JID2 + "/resource"; + private static final Jid BASE_JID1 = JidTestUtil.BARE_JID_1; + private static final FullJid FULL_JID1_R1 = JidTestUtil.FULL_JID_1_RESOURCE_1; + private static final FullJid FULL_JID1_R2 = JidTestUtil.FULL_JID_1_RESOURCE_2; + private static final Jid BASE_JID2 = JidTestUtil.BARE_JID_2; + private static final Jid FULL_JID2 = JidTestUtil.FULL_JID_2_RESOURCE_1; - private static final String BASE_JID3 = "ss@muc.myserver.comm.net"; + private static final Jid BASE_JID3 = JidTestUtil.DUMMY_AT_EXAMPLE_ORG; - private static final String SERVICE_JID1 = "muc.myserver.com"; - private static final String SERVICE_JID2 = "pubsub.myserver.com"; + private static final Jid SERVICE_JID1 = JidTestUtil.MUC_EXAMPLE_ORG; + private static final Jid SERVICE_JID2 = JidTestUtil.PUBSUB_EXAMPLE_ORG; @Test public void autoCompareMatchingFullJid() diff --git a/smack-core/src/test/java/org/jivesoftware/smack/packet/IQResponseTest.java b/smack-core/src/test/java/org/jivesoftware/smack/packet/IQResponseTest.java index 10bfa0205..26d3827f4 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/packet/IQResponseTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/packet/IQResponseTest.java @@ -22,6 +22,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import org.junit.Test; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; /** * Tests that verifies the correct behavior of creating result and error IQ packets. @@ -36,12 +38,13 @@ public class IQResponseTest { /** * Test creating a simple and empty IQ response. + * @throws XmppStringprepException */ @Test - public void testGeneratingSimpleResponse() { + public void testGeneratingSimpleResponse() throws XmppStringprepException { final IQ request = new TestIQ(ELEMENT, NAMESPACE); - request.setFrom("sender@test/Smack"); - request.setTo("receiver@test/Smack"); + request.setFrom(JidCreate.from("sender@test/Smack")); + request.setTo(JidCreate.from("receiver@test/Smack")); final IQ result = IQ.createResultIQ(request); @@ -55,15 +58,16 @@ public class IQResponseTest { /** * Test creating a error response based on an IQ request. + * @throws XmppStringprepException */ @Test - public void testGeneratingValidErrorResponse() { + public void testGeneratingValidErrorResponse() throws XmppStringprepException { final XMPPError error = new XMPPError(XMPPError.Condition.bad_request); final IQ request = new TestIQ(ELEMENT, NAMESPACE); request.setType(IQ.Type.set); - request.setFrom("sender@test/Smack"); - request.setTo("receiver@test/Smack"); + request.setFrom(JidCreate.from("sender@test/Smack")); + request.setTo(JidCreate.from("receiver@test/Smack")); final IQ result = IQ.createErrorResponse(request, error); @@ -79,14 +83,15 @@ public class IQResponseTest { /** * According to RFC3920: IQ Semantics we shouldn't respond to an IQ of type result. + * @throws XmppStringprepException */ @Test - public void testGeneratingResponseBasedOnResult() { + public void testGeneratingResponseBasedOnResult() throws XmppStringprepException { final IQ request = new TestIQ(ELEMENT, NAMESPACE); request.setType(IQ.Type.result); - request.setFrom("sender@test/Smack"); - request.setTo("receiver@test/Smack"); + request.setFrom(JidCreate.from("sender@test/Smack")); + request.setTo(JidCreate.from("receiver@test/Smack")); try { IQ.createResultIQ(request); @@ -101,15 +106,16 @@ public class IQResponseTest { /** * According to RFC3920: IQ Semantics we shouldn't respond to an IQ of type error. + * @throws XmppStringprepException */ @Test - public void testGeneratingErrorBasedOnError() { + public void testGeneratingErrorBasedOnError() throws XmppStringprepException { final XMPPError error = new XMPPError(XMPPError.Condition.bad_request); final IQ request = new TestIQ(ELEMENT, NAMESPACE); request.setType(IQ.Type.error); - request.setFrom("sender@test/Smack"); - request.setTo("receiver@test/Smack"); + request.setFrom(JidCreate.from("sender@test/Smack")); + request.setTo(JidCreate.from("receiver@test/Smack")); request.setError(error); try { diff --git a/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java b/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java index be61be0b4..19e3936c7 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java @@ -25,6 +25,8 @@ import java.util.Map; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.util.StringUtils; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; public class DigestMd5SaslTest extends AbstractSaslTest { @@ -35,8 +37,8 @@ public class DigestMd5SaslTest extends AbstractSaslTest { super(saslMechanism); } - protected void runTest() throws NotConnectedException, SmackException, InterruptedException { - saslMechanism.authenticate("florian", "irrelevant", "xmpp.org", "secret"); + protected void runTest() throws NotConnectedException, SmackException, InterruptedException, XmppStringprepException { + saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret"); byte[] response = saslMechanism.evaluateChallenge(challengeBytes); String responseString = new String(response); diff --git a/smack-core/src/test/java/org/jivesoftware/smack/sasl/core/SCRAMSHA1MechanismTest.java b/smack-core/src/test/java/org/jivesoftware/smack/sasl/core/SCRAMSHA1MechanismTest.java index fe8c808a9..46e359895 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/sasl/core/SCRAMSHA1MechanismTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/sasl/core/SCRAMSHA1MechanismTest.java @@ -27,6 +27,7 @@ import org.jivesoftware.smack.test.util.SmackTestSuite; import org.jivesoftware.smack.util.stringencoder.Base64; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.JidTestUtil; public class SCRAMSHA1MechanismTest { @@ -53,7 +54,7 @@ public class SCRAMSHA1MechanismTest { } }; - mech.authenticate(USERNAME, "unusedFoo", "unusedBar", PASSWORD); + mech.authenticate(USERNAME, "unusedFoo", JidTestUtil.DOMAIN_BARE_JID_1, PASSWORD); AuthMechanism authMechanism = con.getSentPacket(); assertEquals(SCRAMSHA1Mechanism.NAME, authMechanism.getMechanism()); assertEquals(CLIENT_FIRST_MESSAGE, saslLayerString(authMechanism.getAuthenticationText())); diff --git a/smack-core/src/test/java/org/jivesoftware/smack/test/util/WaitForPacketListener.java b/smack-core/src/test/java/org/jivesoftware/smack/test/util/WaitForPacketListener.java index 2e2c02425..05118b168 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/test/util/WaitForPacketListener.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/test/util/WaitForPacketListener.java @@ -43,7 +43,7 @@ public class WaitForPacketListener implements PacketListener { public void waitUntilInvocationOrTimeout() { try { - boolean res = latch.await(30, TimeUnit.SECONDS); + boolean res = latch.await(300, TimeUnit.SECONDS); if (!res) { throw new IllegalStateException("Latch timed out before it reached zero"); } diff --git a/smack-debug-slf4j/src/main/java/org/jivesoftware/smackx/debugger/slf4j/SLF4JSmackDebugger.java b/smack-debug-slf4j/src/main/java/org/jivesoftware/smackx/debugger/slf4j/SLF4JSmackDebugger.java index c9dd213d8..ee628c3e8 100644 --- a/smack-debug-slf4j/src/main/java/org/jivesoftware/smackx/debugger/slf4j/SLF4JSmackDebugger.java +++ b/smack-debug-slf4j/src/main/java/org/jivesoftware/smackx/debugger/slf4j/SLF4JSmackDebugger.java @@ -23,7 +23,7 @@ import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.debugger.SmackDebugger; import org.jivesoftware.smack.util.ObservableReader; import org.jivesoftware.smack.util.ObservableWriter; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.FullJid; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -93,18 +93,9 @@ public class SLF4JSmackDebugger implements SmackDebugger { } @Override - public void userHasLogged(String user) { + public void userHasLogged(FullJid user) { if (logger.isDebugEnabled()) { - String userTitle = getUserTitle(user); - logger.debug("({}) User logged in {}", connection.hashCode(), userTitle); - } - } - - private String getUserTitle(String user) { - if (("@" + connection.getServiceName()).equals(XmppStringUtils.parseBareJid(user))) { - return "@" + connection.getServiceName(); - } else { - return user; + logger.debug("({}) User logged in {}", connection.hashCode(), user.toString()); } } diff --git a/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebugger.java b/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebugger.java index 06fa6cbe7..1449c2a34 100644 --- a/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebugger.java +++ b/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebugger.java @@ -32,6 +32,8 @@ import org.jivesoftware.smack.util.ObservableWriter; import org.jivesoftware.smack.util.ReaderListener; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.WriterListener; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.Jid; import javax.swing.AbstractAction; import javax.swing.BorderFactory; @@ -735,12 +737,13 @@ public class EnhancedDebugger implements SmackDebugger { return writer; } - public void userHasLogged(final String user) { + @Override + public void userHasLogged(final FullJid user) { final EnhancedDebugger debugger = this; SwingUtilities.invokeLater(new Runnable() { public void run() { - userField.setText(user); - EnhancedDebuggerWindow.userHasLogged(debugger, user); + userField.setText(user.toString()); + EnhancedDebuggerWindow.userHasLogged(debugger, user.toString()); // Add the connection listener to the connection so that the debugger can be notified // whenever the connection is closed. connection.addConnectionListener(connListener); @@ -795,7 +798,7 @@ public class EnhancedDebugger implements SmackDebugger { SwingUtilities.invokeLater(new Runnable() { public void run() { String messageType; - String from = packet.getFrom(); + Jid from = packet.getFrom(); String type = ""; Icon packetTypeIcon; receivedPackets++; @@ -856,7 +859,7 @@ public class EnhancedDebugger implements SmackDebugger { SwingUtilities.invokeLater(new Runnable() { public void run() { String messageType; - String to = packet.getTo(); + Jid to = packet.getTo(); String type = ""; Icon packetTypeIcon; sentPackets++; diff --git a/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/LiteDebugger.java b/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/LiteDebugger.java index 259ca7900..f9892f14e 100644 --- a/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/LiteDebugger.java +++ b/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/LiteDebugger.java @@ -48,7 +48,7 @@ import org.jivesoftware.smack.util.ObservableReader; import org.jivesoftware.smack.util.ObservableWriter; import org.jivesoftware.smack.util.ReaderListener; import org.jivesoftware.smack.util.WriterListener; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.FullJid; /** * The LiteDebugger is a very simple debugger that allows to debug sent, received and @@ -324,16 +324,11 @@ public class LiteDebugger implements SmackDebugger { return writer; } - public void userHasLogged(String user) { - boolean isAnonymous = "".equals(XmppStringUtils.parseLocalpart(user)); + @Override + public void userHasLogged(FullJid user) { String title = "Smack Debug Window -- " - + (isAnonymous ? "" : XmppStringUtils.parseBareJid(user)) - + "@" - + connection.getServiceName() - + ":" - + connection.getPort(); - title += "/" + XmppStringUtils.parseResource(user); + + user; frame.setTitle(title); } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/HOXTManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/HOXTManager.java index b57f6c5f9..a99132630 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/HOXTManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/HOXTManager.java @@ -24,6 +24,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp; +import org.jxmpp.jid.Jid; /** * Manager for HTTP ove XMPP transport (XEP-0332) extension. @@ -58,7 +59,7 @@ public class HOXTManager { * @throws NotConnectedException * @throws InterruptedException */ - public static boolean isSupported(String jid, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public static boolean isSupported(Jid jid, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(jid, NAMESPACE); } } diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/carbons/CarbonTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/carbons/CarbonTest.java index 7f9b97f05..c0f9e3e07 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/carbons/CarbonTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/carbons/CarbonTest.java @@ -17,6 +17,8 @@ package org.jivesoftware.smackx.carbons; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence; import java.util.Properties; @@ -62,7 +64,7 @@ public class CarbonTest extends ExperimentalInitializerTest { assertEquals(null, fwd.getDelayInformation()); // check message - assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom()); + assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedPacket().getFrom())); // check end of tag assertEquals(XmlPullParser.END_TAG, parser.getEventType()); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientInfo.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientInfo.java index 0b64bf2d0..41caa4595 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientInfo.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientInfo.java @@ -18,6 +18,7 @@ package org.jivesoftware.smackx.address; import org.jivesoftware.smackx.address.packet.MultipleAddresses; +import org.jxmpp.jid.Jid; import java.util.List; @@ -64,7 +65,8 @@ public class MultipleRecipientInfo { * @return the JID of a MUC room to which responses should be sent or null if * no specific address was provided. */ - public String getReplyRoom() { + // TODO should return BareJid + public Jid getReplyRoom() { List replyRoom = extension.getAddressesOfType(MultipleAddresses.Type.replyroom); return replyRoom.isEmpty() ? null : ((MultipleAddresses.Address) replyRoom.get(0)).getJid(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientManager.java index a33402c8d..f8cf79c89 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientManager.java @@ -28,7 +28,10 @@ import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smackx.address.packet.MultipleAddresses; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.Jid; import java.util.ArrayList; import java.util.Collection; @@ -66,7 +69,7 @@ public class MultipleRecipientManager { * @throws NotConnectedException * @throws InterruptedException */ - public static void send(XMPPConnection connection, Stanza packet, Collection to, Collection cc, Collection bcc) throws NoResponseException, XMPPErrorException, FeatureNotSupportedException, NotConnectedException, InterruptedException + public static void send(XMPPConnection connection, Stanza packet, Collection to, Collection cc, Collection bcc) throws NoResponseException, XMPPErrorException, FeatureNotSupportedException, NotConnectedException, InterruptedException { send(connection, packet, to, cc, bcc, null, null, false); } @@ -96,18 +99,18 @@ public class MultipleRecipientManager { * @throws NotConnectedException * @throws InterruptedException */ - public static void send(XMPPConnection connection, Stanza packet, Collection to, Collection cc, Collection bcc, - String replyTo, String replyRoom, boolean noReply) throws NoResponseException, XMPPErrorException, FeatureNotSupportedException, NotConnectedException, InterruptedException { + public static void send(XMPPConnection connection, Stanza packet, Collection to, Collection cc, Collection bcc, + Jid replyTo, Jid replyRoom, boolean noReply) throws NoResponseException, XMPPErrorException, FeatureNotSupportedException, NotConnectedException, InterruptedException { // Check if *only* 'to' is set and contains just *one* entry, in this case extended stanzas addressing is not // required at all and we can send it just as normal stanza without needing to add the extension element if (to != null && to.size() == 1 && (cc == null || cc.isEmpty()) && (bcc == null || bcc.isEmpty()) && !noReply && StringUtils.isNullOrEmpty(replyTo) && StringUtils.isNullOrEmpty(replyRoom)) { - String toJid = to.iterator().next(); + Jid toJid = to.iterator().next(); packet.setTo(toJid); connection.sendPacket(packet); return; } - String serviceAddress = getMultipleRecipienServiceAddress(connection); + DomainBareJid serviceAddress = getMultipleRecipienServiceAddress(connection); if (serviceAddress != null) { // Send packet to target users using multiple recipient service provided by the server sendThroughService(connection, packet, to, cc, bcc, replyTo, replyRoom, noReply, @@ -115,8 +118,8 @@ public class MultipleRecipientManager { } else { // Server does not support XEP-33 so try to send the packet to each recipient - if (noReply || (replyTo != null && replyTo.trim().length() > 0) || - (replyRoom != null && replyRoom.trim().length() > 0)) { + if (noReply || replyTo != null || + replyRoom != null) { // Some specified XEP-33 features were requested so throw an exception alerting // the user that this features are not available throw new FeatureNotSupportedException("Extended Stanza Addressing"); @@ -162,8 +165,8 @@ public class MultipleRecipientManager { } else { // Send reply to multiple recipients - List to = new ArrayList(info.getTOAddresses().size()); - List cc = new ArrayList(info.getCCAddresses().size()); + List to = new ArrayList<>(info.getTOAddresses().size()); + List cc = new ArrayList<>(info.getCCAddresses().size()); for (MultipleAddresses.Address jid : info.getTOAddresses()) { to.add(jid.getJid()); } @@ -175,9 +178,9 @@ public class MultipleRecipientManager { to.add(original.getFrom()); } // Remove the sender from the TO/CC list (try with bare JID too) - String from = connection.getUser(); + FullJid from = connection.getUser(); if (!to.remove(from) && !cc.remove(from)) { - String bareJID = XmppStringUtils.parseBareJid(from); + BareJid bareJID = from.asBareJid(); to.remove(bareJID); cc.remove(bareJID); } @@ -202,44 +205,44 @@ public class MultipleRecipientManager { } private static void sendToIndividualRecipients(XMPPConnection connection, Stanza packet, - Collection to, Collection cc, Collection bcc) throws NotConnectedException, InterruptedException { + Collection to, Collection cc, Collection bcc) throws NotConnectedException, InterruptedException { if (to != null) { - for (String jid : to) { + for (Jid jid : to) { packet.setTo(jid); connection.sendPacket(new PacketCopy(packet.toXML())); } } if (cc != null) { - for (String jid : cc) { + for (Jid jid : cc) { packet.setTo(jid); connection.sendPacket(new PacketCopy(packet.toXML())); } } if (bcc != null) { - for (String jid : bcc) { + for (Jid jid : bcc) { packet.setTo(jid); connection.sendPacket(new PacketCopy(packet.toXML())); } } } - private static void sendThroughService(XMPPConnection connection, Stanza packet, Collection to, - Collection cc, Collection bcc, String replyTo, String replyRoom, boolean noReply, - String serviceAddress) throws NotConnectedException, InterruptedException { + private static void sendThroughService(XMPPConnection connection, Stanza packet, Collection to, + Collection cc, Collection bcc, Jid replyTo, Jid replyRoom, boolean noReply, + DomainBareJid serviceAddress) throws NotConnectedException, InterruptedException { // Create multiple recipient extension MultipleAddresses multipleAddresses = new MultipleAddresses(); if (to != null) { - for (String jid : to) { + for (Jid jid : to) { multipleAddresses.addAddress(MultipleAddresses.Type.to, jid, null, null, false, null); } } if (cc != null) { - for (String jid : cc) { + for (Jid jid : cc) { multipleAddresses.addAddress(MultipleAddresses.Type.to, jid, null, null, false, null); } } if (bcc != null) { - for (String jid : bcc) { + for (Jid jid : bcc) { multipleAddresses.addAddress(MultipleAddresses.Type.bcc, jid, null, null, false, null); } } @@ -247,11 +250,11 @@ public class MultipleRecipientManager { multipleAddresses.setNoReply(); } else { - if (replyTo != null && replyTo.trim().length() > 0) { + if (replyTo != null) { multipleAddresses .addAddress(MultipleAddresses.Type.replyto, replyTo, null, null, false, null); } - if (replyRoom != null && replyRoom.trim().length() > 0) { + if (replyRoom != null) { multipleAddresses.addAddress(MultipleAddresses.Type.replyroom, replyRoom, null, null, false, null); } @@ -278,9 +281,9 @@ public class MultipleRecipientManager { * @throws NotConnectedException * @throws InterruptedException */ - private static String getMultipleRecipienServiceAddress(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + private static DomainBareJid getMultipleRecipienServiceAddress(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); - List services = sdm.findServices(MultipleAddresses.NAMESPACE, true, true); + List services = sdm.findServices(MultipleAddresses.NAMESPACE, true, true); if (services.size() > 0) { return services.get(0); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/packet/MultipleAddresses.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/packet/MultipleAddresses.java index 18b1d4265..644036e2b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/packet/MultipleAddresses.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/packet/MultipleAddresses.java @@ -20,6 +20,7 @@ package org.jivesoftware.smackx.address.packet; import org.jivesoftware.smack.packet.NamedElement; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.util.XmlStringBuilder; +import org.jxmpp.jid.Jid; import java.util.ArrayList; import java.util.List; @@ -64,7 +65,7 @@ public class MultipleAddresses implements PacketExtension { * @param delivered true when the packet was already delivered to this address. * @param uri used to specify an external system address, such as a sip:, sips:, or im: URI. */ - public void addAddress(Type type, String jid, String node, String desc, boolean delivered, + public void addAddress(Type type, Jid jid, String node, String desc, boolean delivered, String uri) { // Create a new address with the specificed configuration Address address = new Address(type); @@ -132,7 +133,7 @@ public class MultipleAddresses implements PacketExtension { public static final String ELEMENT = "address"; private final Type type; - private String jid; + private Jid jid; private String node; private String description; private boolean delivered; @@ -146,11 +147,11 @@ public class MultipleAddresses implements PacketExtension { return type; } - public String getJid() { + public Jid getJid() { return jid; } - private void setJid(String jid) { + private void setJid(Jid jid) { this.jid = jid; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/provider/MultipleAddressesProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/provider/MultipleAddressesProvider.java index 77e3d6313..cda939f4e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/address/provider/MultipleAddressesProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/address/provider/MultipleAddressesProvider.java @@ -20,8 +20,10 @@ package org.jivesoftware.smackx.address.provider; import java.io.IOException; import org.jivesoftware.smack.provider.PacketExtensionProvider; +import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smackx.address.packet.MultipleAddresses; import org.jivesoftware.smackx.address.packet.MultipleAddresses.Type; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -46,7 +48,7 @@ public class MultipleAddressesProvider extends PacketExtensionProviderAdvanced Message * Processing. To set the stanza that should be used invoke {@link #setStanza(StanzaType)}. *

    - * To establish an In-Band Bytestream invoke the {@link #establishSession(String)} method. This will + * To establish an In-Band Bytestream invoke the {@link #establishSession(Jid)} method. This will * negotiate an in-band bytestream with the given target JID and return a session. *

    * If a session ID for the In-Band Bytestream was already negotiated (e.g. while negotiating a file - * transfer) invoke {@link #establishSession(String, String)}. + * transfer) invoke {@link #establishSession(Jid, String)}. *

    * To handle incoming In-Band Bytestream requests add an {@link InBandBytestreamListener} to the * manager. There are two ways to add this listener. If you want to be informed about incoming * In-Band Bytestreams from a specific user add the listener by invoking - * {@link #addIncomingBytestreamListener(BytestreamListener, String)}. If the listener should + * {@link #addIncomingBytestreamListener(BytestreamListener, Jid)}. If the listener should * respond to all In-Band Bytestream requests invoke * {@link #addIncomingBytestreamListener(BytestreamListener)}. *

    @@ -147,7 +148,7 @@ public class InBandBytestreamManager implements BytestreamManager { * assigns a user to a listener that is informed if an In-Band Bytestream request for this user * is received */ - private final Map userListeners = new ConcurrentHashMap(); + private final Map userListeners = new ConcurrentHashMap<>(); /* * list of listeners that respond to all In-Band Bytestream requests if there are no user @@ -267,7 +268,7 @@ public class InBandBytestreamManager implements BytestreamManager { * @param listener the listener to register * @param initiatorJID the JID of the user that wants to establish an In-Band Bytestream */ - public void addIncomingBytestreamListener(BytestreamListener listener, String initiatorJID) { + public void addIncomingBytestreamListener(BytestreamListener listener, Jid initiatorJID) { this.userListeners.put(initiatorJID, listener); } @@ -392,7 +393,7 @@ public class InBandBytestreamManager implements BytestreamManager { * the data to be sent. *

    * To establish an In-Band Bytestream after negotiation the kind of data to be sent (e.g. file - * transfer) use {@link #establishSession(String, String)}. + * transfer) use {@link #establishSession(Jid, String)}. * * @param targetJID the JID of the user an In-Band Bytestream should be established * @return the session to send/receive data to/from the user @@ -401,7 +402,7 @@ public class InBandBytestreamManager implements BytestreamManager { * @throws SmackException if there was no response from the server. * @throws InterruptedException */ - public InBandBytestreamSession establishSession(String targetJID) throws XMPPException, SmackException, InterruptedException { + public InBandBytestreamSession establishSession(Jid targetJID) throws XMPPException, SmackException, InterruptedException { String sessionID = getNextSessionID(); return establishSession(targetJID, sessionID); } @@ -419,7 +420,7 @@ public class InBandBytestreamManager implements BytestreamManager { * @throws NotConnectedException * @throws InterruptedException */ - public InBandBytestreamSession establishSession(String targetJID, String sessionID) + public InBandBytestreamSession establishSession(Jid targetJID, String sessionID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Open byteStreamRequest = new Open(sessionID, this.defaultBlockSize, this.stanza); byteStreamRequest.setTo(targetJID); @@ -504,7 +505,7 @@ public class InBandBytestreamManager implements BytestreamManager { * @param initiator the initiator's JID * @return the listener */ - protected BytestreamListener getUserListener(String initiator) { + protected BytestreamListener getUserListener(Jid initiator) { return this.userListeners.get(initiator); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequest.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequest.java index 5fa289096..b3a66b875 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequest.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequest.java @@ -21,6 +21,7 @@ import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.bytestreams.BytestreamRequest; import org.jivesoftware.smackx.bytestreams.ibb.packet.Open; +import org.jxmpp.jid.Jid; /** * InBandBytestreamRequest class handles incoming In-Band Bytestream requests. @@ -49,7 +50,7 @@ public class InBandBytestreamRequest implements BytestreamRequest { * * @return the sender of the In-Band Bytestream open request */ - public String getFrom() { + public Jid getFrom() { return this.byteStreamRequest.getFrom(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java index b6e569c08..155d52dfa 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java @@ -40,6 +40,7 @@ import org.jivesoftware.smackx.bytestreams.ibb.packet.Close; import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; import org.jivesoftware.smackx.bytestreams.ibb.packet.Open; +import org.jxmpp.jid.Jid; /** * InBandBytestreamSession class represents an In-Band Bytestream session. @@ -73,7 +74,7 @@ public class InBandBytestreamSession implements BytestreamSession { private IBBOutputStream outputStream; /* JID of the remote peer */ - private String remoteJID; + private Jid remoteJID; /* flag to close both streams if one of them is closed */ private boolean closeBothStreamsEnabled = false; @@ -89,7 +90,7 @@ public class InBandBytestreamSession implements BytestreamSession { * @param remoteJID JID of the remote peer */ protected InBandBytestreamSession(XMPPConnection connection, Open byteStreamRequest, - String remoteJID) { + Jid remoteJID) { this.connection = connection; this.byteStreamRequest = byteStreamRequest; this.remoteJID = remoteJID; @@ -556,7 +557,7 @@ public class InBandBytestreamSession implements BytestreamSession { public boolean accept(Stanza packet) { // sender equals remote peer - if (!packet.getFrom().equalsIgnoreCase(remoteJID)) { + if (!packet.getFrom().equals(remoteJID)) { return false; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamListener.java index 6ff919ee8..bbb576041 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamListener.java @@ -25,7 +25,7 @@ import org.jivesoftware.smackx.bytestreams.BytestreamRequest; *

    * There are two ways to add this listener. See * {@link Socks5BytestreamManager#addIncomingBytestreamListener(BytestreamListener)} and - * {@link Socks5BytestreamManager#addIncomingBytestreamListener(BytestreamListener, String)} for + * {@link Socks5BytestreamManager#addIncomingBytestreamListener(BytestreamListener, org.jxmpp.jid.Jid)} for * further details. * * @author Henning Staib diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java index fcece1406..bf3902543 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java @@ -21,10 +21,12 @@ import java.net.Socket; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeoutException; @@ -51,6 +53,7 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverItems; import org.jivesoftware.smackx.disco.packet.DiscoverItems.Item; import org.jivesoftware.smackx.filetransfer.FileTransferManager; +import org.jxmpp.jid.Jid; /** * The Socks5BytestreamManager class handles establishing SOCKS5 Bytestreams as specified in the - * To establish a SOCKS5 Bytestream invoke the {@link #establishSession(String)} method. This will + * To establish a SOCKS5 Bytestream invoke the {@link #establishSession(Jid)} method. This will * negotiate a SOCKS5 Bytestream with the given target JID and return a socket. *

    * If a session ID for the SOCKS5 Bytestream was already negotiated (e.g. while negotiating a file - * transfer) invoke {@link #establishSession(String, String)}. + * transfer) invoke {@link #establishSession(Jid, String)}. *

    * To handle incoming SOCKS5 Bytestream requests add an {@link Socks5BytestreamListener} to the * manager. There are two ways to add this listener. If you want to be informed about incoming * SOCKS5 Bytestreams from a specific user add the listener by invoking - * {@link #addIncomingBytestreamListener(BytestreamListener, String)}. If the listener should + * {@link #addIncomingBytestreamListener(BytestreamListener, Jid)}. If the listener should * respond to all SOCKS5 Bytestream requests invoke * {@link #addIncomingBytestreamListener(BytestreamListener)}. *

    @@ -135,7 +138,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { * assigns a user to a listener that is informed if a bytestream request for this user is * received */ - private final Map userListeners = new ConcurrentHashMap(); + private final Map userListeners = new ConcurrentHashMap<>(); /* * list of listeners that respond to all bytestream requests if there are not user specific @@ -153,10 +156,10 @@ public final class Socks5BytestreamManager implements BytestreamManager { private int proxyConnectionTimeout = 10000; /* blacklist of errornous SOCKS5 proxies */ - private final List proxyBlacklist = Collections.synchronizedList(new LinkedList()); + private final Set proxyBlacklist = Collections.synchronizedSet(new HashSet()); /* remember the last proxy that worked to prioritize it */ - private String lastWorkingProxy = null; + private Jid lastWorkingProxy; /* flag to enable/disable prioritization of last working proxy */ private boolean proxyPrioritizationEnabled = true; @@ -246,7 +249,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { * @param listener the listener to register * @param initiatorJID the JID of the user that wants to establish a SOCKS5 Bytestream */ - public void addIncomingBytestreamListener(BytestreamListener listener, String initiatorJID) { + public void addIncomingBytestreamListener(BytestreamListener listener, Jid initiatorJID) { this.userListeners.put(initiatorJID, listener); } @@ -392,7 +395,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { * the data to be sent. *

    * To establish a SOCKS5 Bytestream after negotiation the kind of data to be sent (e.g. file - * transfer) use {@link #establishSession(String, String)}. + * transfer) use {@link #establishSession(Jid, String)}. * * @param targetJID the JID of the user a SOCKS5 Bytestream should be established * @return the Socket to send/receive data to/from the user @@ -402,7 +405,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { * @throws InterruptedException if the current thread was interrupted while waiting * @throws SmackException if there was no response from the server. */ - public Socks5BytestreamSession establishSession(String targetJID) throws XMPPException, + public Socks5BytestreamSession establishSession(Jid targetJID) throws XMPPException, IOException, InterruptedException, SmackException { String sessionID = getNextSessionID(); return establishSession(targetJID, sessionID); @@ -421,7 +424,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { * @throws SmackException if the target does not support SOCKS5. * @throws XMPPException */ - public Socks5BytestreamSession establishSession(String targetJID, String sessionID) + public Socks5BytestreamSession establishSession(Jid targetJID, String sessionID) throws IOException, InterruptedException, NoResponseException, SmackException, XMPPException{ XMPPErrorException discoveryException = null; @@ -430,7 +433,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { throw new FeatureNotSupportedException("SOCKS5 Bytestream", targetJID); } - List proxies = new ArrayList(); + List proxies = new ArrayList<>(); // determine SOCKS5 proxies from XMPP-server try { proxies.addAll(determineProxies()); @@ -529,7 +532,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { * @throws NotConnectedException * @throws InterruptedException */ - private boolean supportsSocks5(String targetJID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + private boolean supportsSocks5(Jid targetJID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(targetJID, Bytestream.NAMESPACE); } @@ -543,10 +546,10 @@ public final class Socks5BytestreamManager implements BytestreamManager { * @throws NotConnectedException * @throws InterruptedException */ - private List determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + private List determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection); - List proxies = new ArrayList(); + List proxies = new ArrayList<>(); // get all items from XMPP server DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(this.connection.getServiceName()); @@ -591,7 +594,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { * @param proxies a list of SOCKS5 proxy JIDs * @return a list of stream hosts containing the IP address an the port */ - private List determineStreamHostInfos(List proxies) { + private List determineStreamHostInfos(List proxies) { List streamHosts = new ArrayList(); // add local proxy on first position if exists @@ -601,7 +604,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { } // query SOCKS5 proxies for network settings - for (String proxy : proxies) { + for (Jid proxy : proxies) { Bytestream streamHostRequest = createStreamHostRequest(proxy); try { Bytestream response = (Bytestream) connection.createPacketCollectorAndSend( @@ -623,7 +626,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { * @param proxy the proxy to query * @return IQ packet to query a SOCKS5 proxy its network settings */ - private Bytestream createStreamHostRequest(String proxy) { + private Bytestream createStreamHostRequest(Jid proxy) { Bytestream request = new Bytestream(); request.setType(IQ.Type.get); request.setTo(proxy); @@ -678,7 +681,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { * @param streamHosts a list of SOCKS5 proxies the target should connect to * @return a SOCKS5 Bytestream initialization request packet */ - private Bytestream createBytestreamInitiation(String sessionID, String targetJID, + private Bytestream createBytestreamInitiation(String sessionID, Jid targetJID, List streamHosts) { Bytestream initiation = new Bytestream(sessionID); @@ -758,7 +761,7 @@ public final class Socks5BytestreamManager implements BytestreamManager { * @param initiator the initiator's JID * @return the listener */ - protected BytestreamListener getUserListener(String initiator) { + protected BytestreamListener getUserListener(Jid initiator) { return this.userListeners.get(initiator); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamRequest.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamRequest.java index 71050178a..fe810e2b1 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamRequest.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamRequest.java @@ -30,6 +30,7 @@ import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smackx.bytestreams.BytestreamRequest; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost; +import org.jxmpp.jid.Jid; import org.jxmpp.util.cache.Cache; import org.jxmpp.util.cache.ExpirationCache; @@ -169,7 +170,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest { * * @return the sender of the SOCKS5 Bytestream initialization request. */ - public String getFrom() { + public Jid getFrom() { return this.bytestreamRequest.getFrom(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java index 6849c4f03..a6f33a91d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java @@ -29,6 +29,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost; +import org.jxmpp.jid.Jid; /** * Implementation of a SOCKS5 client used on the initiators side. This is needed because connecting @@ -47,7 +48,8 @@ class Socks5ClientForInitiator extends Socks5Client { private String sessionID; /* the target JID used to activate SOCKS5 stream */ - private String target; + // TODO fullJid? + private final Jid target; /** * Creates a new SOCKS5 client for the initiators side. @@ -59,7 +61,7 @@ class Socks5ClientForInitiator extends Socks5Client { * @param target the target JID of the SOCKS5 Bytestream */ public Socks5ClientForInitiator(StreamHost streamHost, String digest, XMPPConnection connection, - String sessionID, String target) { + String sessionID, Jid target) { super(streamHost, digest); this.connection = connection; this.sessionID = sessionID; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java index 152922300..70e4bbe21 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java @@ -54,7 +54,7 @@ import org.jivesoftware.smack.SmackException; *

    * The local SOCKS5 proxy server refuses all connections except the ones that are explicitly allowed * in the process of establishing a SOCKS5 Bytestream ( - * {@link Socks5BytestreamManager#establishSession(String)}). + * {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid)}). *

    * This Implementation has the following limitations: *

      diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Utils.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Utils.java index f06ec1938..f5b048631 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Utils.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Utils.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.util.SHA1; +import org.jxmpp.jid.Jid; /** * A collection of utility methods for SOcKS5 messages. @@ -38,7 +39,7 @@ class Socks5Utils { * @param targetJID JID of the target of a SOCKS5 Bytestream * @return SHA-1 digest of the given parameters */ - public static String createDigest(String sessionID, String initiatorJID, String targetJID) { + public static String createDigest(String sessionID, Jid initiatorJID, Jid targetJID) { StringBuilder b = new StringBuilder(); b.append(sessionID).append(initiatorJID).append(targetJID); return SHA1.hex(b.toString()); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java index 8f76afc71..eae4c928e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java @@ -23,6 +23,7 @@ import java.util.List; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.NamedElement; import org.jivesoftware.smack.util.XmlStringBuilder; +import org.jxmpp.jid.Jid; /** * A packet representing part of a SOCKS5 Bytestream negotiation. @@ -113,7 +114,7 @@ public class Bytestream extends IQ { * @param address The internet address of the stream host. * @return The added stream host. */ - public StreamHost addStreamHost(final String JID, final String address) { + public StreamHost addStreamHost(final Jid JID, final String address) { return addStreamHost(JID, address, 0); } @@ -125,7 +126,7 @@ public class Bytestream extends IQ { * @param port The port on which the remote host is seeking connections. * @return The added stream host. */ - public StreamHost addStreamHost(final String JID, final String address, final int port) { + public StreamHost addStreamHost(final Jid JID, final String address, final int port) { StreamHost host = new StreamHost(JID, address, port); addStreamHost(host); @@ -156,7 +157,7 @@ public class Bytestream extends IQ { * @param JID The JID of the desired stream host. * @return Returns the stream host related to the given JID, or null if there is none. */ - public StreamHost getStreamHost(final String JID) { + public StreamHost getStreamHost(final Jid JID) { if (JID == null) { return null; } @@ -184,7 +185,7 @@ public class Bytestream extends IQ { * * @param JID The JID of the used host. */ - public void setUsedHost(final String JID) { + public void setUsedHost(final Jid JID) { this.usedHost = new StreamHostUsed(JID); } @@ -215,7 +216,7 @@ public class Bytestream extends IQ { * * @param targetID The JID of the target of the file transfer. */ - public void setToActivate(final String targetID) { + public void setToActivate(final Jid targetID) { this.toActivate = new Activate(targetID); } @@ -265,13 +266,13 @@ public class Bytestream extends IQ { public static String ELEMENTNAME = "streamhost"; - private final String JID; + private final Jid JID; private final String addy; private final int port; - public StreamHost(String jid, String address) { + public StreamHost(Jid jid, String address) { this(jid, address, 0); } @@ -281,7 +282,7 @@ public class Bytestream extends IQ { * @param JID The JID of the stream host. * @param address The internet address of the stream host. */ - public StreamHost(final String JID, final String address, int port) { + public StreamHost(final Jid JID, final String address, int port) { this.JID = JID; this.addy = address; this.port = port; @@ -292,7 +293,7 @@ public class Bytestream extends IQ { * * @return Returns the JID of the stream host. */ - public String getJID() { + public Jid getJID() { return JID; } @@ -343,14 +344,14 @@ public class Bytestream extends IQ { public static String ELEMENTNAME = "streamhost-used"; - private final String JID; + private final Jid JID; /** * Default constructor. * * @param JID The JID of the selected stream host. */ - public StreamHostUsed(final String JID) { + public StreamHostUsed(final Jid JID) { this.JID = JID; } @@ -359,7 +360,7 @@ public class Bytestream extends IQ { * * @return Returns the JID of the selected stream host. */ - public String getJID() { + public Jid getJID() { return JID; } @@ -385,14 +386,14 @@ public class Bytestream extends IQ { public static String ELEMENTNAME = "activate"; - private final String target; + private final Jid target; /** * Default constructor specifying the target of the stream. * * @param target The target of the stream. */ - public Activate(final String target) { + public Activate(final Jid target) { this.target = target; } @@ -401,7 +402,7 @@ public class Bytestream extends IQ { * * @return Returns the target of the activation. */ - public String getTarget() { + public Jid getTarget() { return target; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/provider/BytestreamsProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/provider/BytestreamsProvider.java index 18feb3228..a4312d269 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/provider/BytestreamsProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/provider/BytestreamsProvider.java @@ -19,7 +19,9 @@ package org.jivesoftware.smackx.bytestreams.socks5.provider; import java.io.IOException; import org.jivesoftware.smack.provider.IQProvider; +import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -41,7 +43,7 @@ public class BytestreamsProvider extends IQProvider { String mode = parser.getAttributeValue("", "mode"); // streamhost - String JID = null; + Jid JID = null; String host = null; String port = null; @@ -52,15 +54,15 @@ public class BytestreamsProvider extends IQProvider { elementName = parser.getName(); if (eventType == XmlPullParser.START_TAG) { if (elementName.equals(Bytestream.StreamHost.ELEMENTNAME)) { - JID = parser.getAttributeValue("", "jid"); + JID = ParserUtils.getJidAttribute(parser); host = parser.getAttributeValue("", "host"); port = parser.getAttributeValue("", "port"); } else if (elementName.equals(Bytestream.StreamHostUsed.ELEMENTNAME)) { - toReturn.setUsedHost(parser.getAttributeValue("", "jid")); + toReturn.setUsedHost(ParserUtils.getJidAttribute(parser)); } else if (elementName.equals(Bytestream.Activate.ELEMENTNAME)) { - toReturn.setToActivate(parser.getAttributeValue("", "jid")); + toReturn.setToActivate(ParserUtils.getJidAttribute(parser)); } } else if (eventType == XmlPullParser.END_TAG) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java index 9b41096dc..55aa489b6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java @@ -45,6 +45,8 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo.Feature; import org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity; import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.packet.DataForm; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.Jid; import org.jxmpp.util.cache.LruCache; import java.util.Comparator; @@ -107,7 +109,7 @@ public class EntityCapsManager extends Manager { * link-local connection the key is formed as user@host (no resource) In * case of a server or component the key is formed as domain */ - private static final LruCache JID_TO_NODEVER_CACHE = new LruCache(10000); + private static final LruCache JID_TO_NODEVER_CACHE = new LruCache<>(10000); static { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { @@ -166,7 +168,7 @@ public class EntityCapsManager extends Manager { } } - public static NodeVerHash getNodeVerHashByJid(String jid) { + public static NodeVerHash getNodeVerHashByJid(Jid jid) { return JID_TO_NODEVER_CACHE.get(jid); } @@ -179,7 +181,7 @@ public class EntityCapsManager extends Manager { * user name (Full JID) * @return the discovered info */ - public static DiscoverInfo getDiscoverInfoByUser(String user) { + public static DiscoverInfo getDiscoverInfoByUser(Jid user) { NodeVerHash nvh = JID_TO_NODEVER_CACHE.get(user); if (nvh == null) return null; @@ -242,7 +244,7 @@ public class EntityCapsManager extends Manager { CAPS_CACHE.clear(); } - private static void addCapsExtensionInfo(String from, CapsExtension capsExtension) { + private static void addCapsExtensionInfo(Jid from, CapsExtension capsExtension) { String capsExtensionHash = capsExtension.getHash(); String hashInUppercase = capsExtensionHash.toUpperCase(Locale.US); // SUPPORTED_HASHES uses the format of MessageDigest, which is uppercase, e.g. "SHA-1" instead of "sha-1" @@ -300,7 +302,7 @@ public class EntityCapsManager extends Manager { if (capsExtension == null) { return; } - String from = connection.getServiceName(); + DomainBareJid from = connection.getServiceName(); addCapsExtensionInfo(from, capsExtension); } }); @@ -320,7 +322,7 @@ public class EntityCapsManager extends Manager { return; CapsExtension capsExtension = CapsExtension.from(packet); - String from = packet.getFrom(); + Jid from = packet.getFrom(); addCapsExtensionInfo(from, capsExtension); } @@ -331,7 +333,7 @@ public class EntityCapsManager extends Manager { public void processPacket(Stanza packet) { // always remove the JID from the map, even if entityCaps are // disabled - String from = packet.getFrom(); + Jid from = packet.getFrom(); JID_TO_NODEVER_CACHE.remove(from); } }, PRESENCES_WITHOUT_CAPS); @@ -436,7 +438,7 @@ public class EntityCapsManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public boolean areEntityCapsSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public boolean areEntityCapsSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return sdm.supportsFeature(jid, NAMESPACE); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommand.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommand.java index 0b894d7ed..feaba1328 100755 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommand.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommand.java @@ -22,6 +22,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smackx.commands.packet.AdHocCommandData; import org.jivesoftware.smackx.xdata.Form; +import org.jxmpp.jid.Jid; import java.util.List; @@ -146,7 +147,7 @@ public abstract class AdHocCommand { * * @return the owner JID. */ - public abstract String getOwnerJID(); + public abstract Jid getOwnerJID(); /** * Returns the notes that the command has at the current stage. diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java index b550a3670..c209c7634 100755 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java @@ -48,6 +48,7 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverItems; import org.jivesoftware.smackx.xdata.Form; +import org.jxmpp.jid.Jid; /** * An AdHocCommandManager is responsible for keeping the list of available @@ -254,7 +255,7 @@ public class AdHocCommandManager extends Manager { * @throws SmackException if there was no response from the server. * @throws InterruptedException */ - public DiscoverItems discoverCommands(String jid) throws XMPPException, SmackException, InterruptedException { + public DiscoverItems discoverCommands(Jid jid) throws XMPPException, SmackException, InterruptedException { return serviceDiscoveryManager.discoverItems(jid, NAMESPACE); } @@ -266,7 +267,7 @@ public class AdHocCommandManager extends Manager { * @throws SmackException if there was no response from the server. * @throws InterruptedException */ - public void publishCommands(String jid) throws XMPPException, SmackException, InterruptedException { + public void publishCommands(Jid jid) throws XMPPException, SmackException, InterruptedException { // Collects the commands to publish as items DiscoverItems discoverItems = new DiscoverItems(); Collection xCommandsList = getRegisteredCommands(); @@ -291,7 +292,7 @@ public class AdHocCommandManager extends Manager { * @param node the identifier of the command * @return a local instance equivalent to the remote command. */ - public RemoteCommand getRemoteCommand(String jid, String node) { + public RemoteCommand getRemoteCommand(Jid jid, String node) { return new RemoteCommand(connection(), node, jid); } @@ -652,10 +653,10 @@ public class AdHocCommandManager extends Manager { private String node; private String name; - private String ownerJID; + private final Jid ownerJID; private LocalCommandFactory factory; - public AdHocCommandInfo(String node, String name, String ownerJID, + public AdHocCommandInfo(String node, String name, Jid ownerJID, LocalCommandFactory factory) { this.node = node; @@ -678,7 +679,7 @@ public class AdHocCommandManager extends Manager { return node; } - public String getOwnerJID() { + public Jid getOwnerJID() { return ownerJID; } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommand.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommand.java index 457a0edb8..7d0e86d5e 100755 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommand.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommand.java @@ -18,6 +18,7 @@ package org.jivesoftware.smackx.commands; import org.jivesoftware.smackx.commands.packet.AdHocCommandData; +import org.jxmpp.jid.Jid; /** * Represents a command that can be executed locally from a remote location. This @@ -52,7 +53,7 @@ public abstract class LocalCommand extends AdHocCommand { /** * The full JID of the host of the command. */ - private String ownerJID; + private Jid ownerJID; /** * The number of the current stage. @@ -91,12 +92,12 @@ public abstract class LocalCommand extends AdHocCommand { * * @param ownerJID the JID of the owner. */ - public void setOwnerJID(String ownerJID) { + public void setOwnerJID(Jid ownerJID) { this.ownerJID = ownerJID; } @Override - public String getOwnerJID() { + public Jid getOwnerJID() { return ownerJID; } @@ -128,7 +129,7 @@ public abstract class LocalCommand extends AdHocCommand { * @param jid the JID to check permissions on. * @return true if the user has permission to execute this action. */ - public abstract boolean hasPermission(String jid); + public abstract boolean hasPermission(Jid jid); /** * Returns the currently executing stage number. The first stage number is diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java index ff62d5f6c..e438a1a15 100755 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java @@ -23,6 +23,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.commands.packet.AdHocCommandData; import org.jivesoftware.smackx.xdata.Form; +import org.jxmpp.jid.Jid; /** * Represents a command that is in a remote location. Invoking one of the @@ -48,7 +49,7 @@ public class RemoteCommand extends AdHocCommand { /** * The full JID of the command host */ - private String jid; + private Jid jid; /** * The session ID of this execution. @@ -64,7 +65,7 @@ public class RemoteCommand extends AdHocCommand { * @param node the identifier of the command. * @param jid the JID of the host. */ - protected RemoteCommand(XMPPConnection connection, String node, String jid) { + protected RemoteCommand(XMPPConnection connection, String node, Jid jid) { super(); this.connection = connection; this.jid = jid; @@ -150,7 +151,7 @@ public class RemoteCommand extends AdHocCommand { } @Override - public String getOwnerJID() { + public Jid getOwnerJID() { return jid; } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/packet/AdHocCommandData.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/packet/AdHocCommandData.java index fc58c8088..9265aa092 100755 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/packet/AdHocCommandData.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/packet/AdHocCommandData.java @@ -24,6 +24,7 @@ import org.jivesoftware.smackx.commands.AdHocCommand.Action; import org.jivesoftware.smackx.commands.AdHocCommand.SpecificErrorCondition; import org.jivesoftware.smackx.commands.AdHocCommandNote; import org.jivesoftware.smackx.xdata.packet.DataForm; +import org.jxmpp.jid.Jid; import java.util.ArrayList; import java.util.List; @@ -39,7 +40,7 @@ public class AdHocCommandData extends IQ { public static final String NAMESPACE = "http://jabber.org/protocol/commands"; /* JID of the command host */ - private String id; + private Jid id; /* Command name */ private String name; @@ -114,11 +115,11 @@ public class AdHocCommandData extends IQ { * * @return the JID of the command host. */ - public String getId() { + public Jid getId() { return id; } - public void setId(String id) { + public void setId(Jid id) { this.id = id; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java index 0f0eee27d..24740af9a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java @@ -34,6 +34,8 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverItems; import org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity; import org.jivesoftware.smackx.xdata.packet.DataForm; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.Jid; import org.jxmpp.util.cache.Cache; import org.jxmpp.util.cache.ExpirationCache; @@ -477,7 +479,7 @@ public class ServiceDiscoveryManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public DiscoverInfo discoverInfo(String entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public DiscoverInfo discoverInfo(Jid entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { if (entityID == null) return discoverInfo(null, null); @@ -523,7 +525,7 @@ public class ServiceDiscoveryManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public DiscoverInfo discoverInfo(String entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public DiscoverInfo discoverInfo(Jid entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { // Discover the entity's info DiscoverInfo disco = new DiscoverInfo(); disco.setType(IQ.Type.get); @@ -545,7 +547,7 @@ public class ServiceDiscoveryManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public DiscoverItems discoverItems(String entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public DiscoverItems discoverItems(Jid entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return discoverItems(entityID, null); } @@ -562,7 +564,7 @@ public class ServiceDiscoveryManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public DiscoverItems discoverItems(String entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public DiscoverItems discoverItems(Jid entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { // Discover the entity's items DiscoverItems disco = new DiscoverItems(); disco.setType(IQ.Type.get); @@ -586,7 +588,7 @@ public class ServiceDiscoveryManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public boolean canPublishItems(String entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public boolean canPublishItems(Jid entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { DiscoverInfo info = discoverInfo(entityID); return canPublishItems(info); } @@ -617,7 +619,7 @@ public class ServiceDiscoveryManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public void publishItems(String entityID, DiscoverItems discoverItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public void publishItems(Jid entityID, DiscoverItems discoverItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { publishItems(entityID, null, discoverItems); } @@ -635,7 +637,7 @@ public class ServiceDiscoveryManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public void publishItems(String entityID, String node, DiscoverItems discoverItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + public void publishItems(Jid entityID, String node, DiscoverItems discoverItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { discoverItems.setType(IQ.Type.set); discoverItems.setTo(entityID); @@ -671,7 +673,7 @@ public class ServiceDiscoveryManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public boolean supportsFeature(String jid, String feature) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public boolean supportsFeature(Jid jid, String feature) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { DiscoverInfo result = discoverInfo(jid); return result.containsFeature(feature); } @@ -680,7 +682,7 @@ public class ServiceDiscoveryManager extends Manager { * Create a cache to hold the 25 most recently lookup services for a given feature for a period * of 24 hours. */ - private Cache> services = new ExpirationCache>(25, + private Cache> services = new ExpirationCache<>(25, 24 * 60 * 60 * 1000); /** @@ -695,17 +697,17 @@ public class ServiceDiscoveryManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public List findServices(String feature, boolean stopOnFirst, boolean useCache) + public List findServices(String feature, boolean stopOnFirst, boolean useCache) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - List serviceAddresses = null; - String serviceName = connection().getServiceName(); + List serviceAddresses = null; + DomainBareJid serviceName = connection().getServiceName(); if (useCache) { - serviceAddresses = (List) services.get(feature); + serviceAddresses = services.get(feature); if (serviceAddresses != null) { return serviceAddresses; } } - serviceAddresses = new LinkedList(); + serviceAddresses = new LinkedList<>(); // Send the disco packet to the server itself DiscoverInfo info; try { @@ -748,7 +750,7 @@ public class ServiceDiscoveryManager extends Manager { continue; } if (info.containsFeature(feature)) { - serviceAddresses.add(item.getEntityID()); + serviceAddresses.add(item.getEntityID().asDomainBareJid()); if (stopOnFirst) { break; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverItems.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverItems.java index 50636e616..a61aefddf 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverItems.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverItems.java @@ -18,6 +18,7 @@ package org.jivesoftware.smackx.disco.packet; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.util.XmlStringBuilder; +import org.jxmpp.jid.Jid; import java.util.Collection; import java.util.Collections; @@ -134,7 +135,7 @@ public class DiscoverItems extends IQ { */ public static final String REMOVE_ACTION = "remove"; - private String entityID; + private final Jid entityID; private String name; private String node; private String action; @@ -144,7 +145,7 @@ public class DiscoverItems extends IQ { * * @param entityID the id of the entity that contains the item */ - public Item(String entityID) { + public Item(Jid entityID) { this.entityID = entityID; } @@ -153,7 +154,7 @@ public class DiscoverItems extends IQ { * * @return the entity's ID. */ - public String getEntityID() { + public Jid getEntityID() { return entityID; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/provider/DiscoverItemsProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/provider/DiscoverItemsProvider.java index cfec90a04..18ddf97a8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/provider/DiscoverItemsProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/provider/DiscoverItemsProvider.java @@ -20,7 +20,9 @@ package org.jivesoftware.smackx.disco.provider; import java.io.IOException; import org.jivesoftware.smack.provider.IQProvider; +import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smackx.disco.packet.DiscoverItems; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -37,7 +39,7 @@ public class DiscoverItemsProvider extends IQProvider { DiscoverItems discoverItems = new DiscoverItems(); boolean done = false; DiscoverItems.Item item; - String jid = ""; + Jid jid = null; String name = ""; String action = ""; String node = ""; @@ -47,7 +49,7 @@ public class DiscoverItemsProvider extends IQProvider { if (eventType == XmlPullParser.START_TAG && "item".equals(parser.getName())) { // Initialize the variables from the parsed XML - jid = parser.getAttributeValue("", "jid"); + jid = ParserUtils.getJidAttribute(parser); name = parser.getAttributeValue("", "name"); node = parser.getAttributeValue("", "node"); action = parser.getAttributeValue("", "action"); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java index 312d48414..adae5be86 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java @@ -39,6 +39,7 @@ import org.jivesoftware.smack.filter.OrFilter; import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smackx.si.packet.StreamInitiation; +import org.jxmpp.jid.Jid; /** @@ -61,7 +62,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator { this.connection = connection; } - public PacketFilter getInitiationPacketFilter(String from, String streamID) { + public PacketFilter getInitiationPacketFilter(Jid from, String streamID) { if (primaryFilter == null || secondaryFilter == null) { primaryFilter = primaryNegotiator.getInitiationPacketFilter(from, streamID); secondaryFilter = secondaryNegotiator.getInitiationPacketFilter(from, streamID); @@ -143,7 +144,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator { return primaryFilter.accept(streamInitiation) ? primaryNegotiator : secondaryNegotiator; } - public OutputStream createOutgoingStream(String streamID, String initiator, String target) + public OutputStream createOutgoingStream(String streamID, Jid initiator, Jid target) throws SmackException, XMPPException, InterruptedException { OutputStream stream; try { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java index 586c934cd..77eb55e6e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.jxmpp.jid.Jid; + /** * Contains the generic file information and progress related to a particular * file transfer. @@ -35,7 +37,7 @@ public abstract class FileTransfer { private long fileSize; - private String peer; + private Jid peer; private Status status = Status.initial; @@ -56,7 +58,7 @@ public abstract class FileTransfer { */ private static final int BUFFER_SIZE = 8192; - protected FileTransfer(String peer, String streamID, + protected FileTransfer(Jid peer, String streamID, FileTransferNegotiator negotiator) { this.peer = peer; this.streamID = streamID; @@ -106,7 +108,7 @@ public abstract class FileTransfer { * * @return Returns the JID of the peer for this file transfer. */ - public String getPeer() { + public Jid getPeer() { return peer; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java index 05931cb31..223ee9cd6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java @@ -24,7 +24,7 @@ import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smackx.si.packet.StreamInitiation; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.FullJid; import java.util.List; import java.util.Map; @@ -33,7 +33,7 @@ import java.util.concurrent.CopyOnWriteArrayList; /** * The file transfer manager class handles the sending and recieving of files. - * To send a file invoke the {@link #createOutgoingFileTransfer(String)} method. + * To send a file invoke the {@link #createOutgoingFileTransfer(FullJid)} method. *

      * And to recieve a file add a file transfer listener to the manager. The * listener will notify you when there is a new file transfer request. To create @@ -117,15 +117,12 @@ public class FileTransferManager extends Manager { * @return The send file object on which the negotiated transfer can be run. * @exception IllegalArgumentException if userID is null or not a full JID */ - public OutgoingFileTransfer createOutgoingFileTransfer(String userID) { - if (userID == null) { - throw new IllegalArgumentException("userID was null"); - } + public OutgoingFileTransfer createOutgoingFileTransfer(FullJid userID) { // We need to create outgoing file transfers with a full JID since this method will later // use XEP-0095 to negotiate the stream. This is done with IQ stanzas that need to be addressed to a full JID // in order to reach an client entity. - else if (!XmppStringUtils.isFullJID(userID)) { - throw new IllegalArgumentException("The provided user id was not a full JID (i.e. with resource part)"); + if (userID == null) { + throw new IllegalArgumentException("userID was null"); } return new OutgoingFileTransfer(connection().getUser(), userID, diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java index f678c051d..726ad6f15 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java @@ -42,6 +42,7 @@ import org.jivesoftware.smackx.filetransfer.FileTransferException.NoStreamMethod import org.jivesoftware.smackx.si.packet.StreamInitiation; import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.packet.DataForm; +import org.jxmpp.jid.Jid; /** * Manages the negotiation of file transfers according to XEP-0096. If a file is @@ -302,7 +303,7 @@ public class FileTransferNegotiator extends Manager { * @throws NoAcceptableTransferMechanisms * @throws InterruptedException */ - public StreamNegotiator negotiateOutgoingTransfer(final String userID, + public StreamNegotiator negotiateOutgoingTransfer(final Jid userID, final String streamID, final String fileName, final long size, final String desc, int responseTimeout) throws XMPPErrorException, NotConnectedException, NoResponseException, NoAcceptableTransferMechanisms, InterruptedException { StreamInitiation si = new StreamInitiation(); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java index 75f672264..ea5e2447d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java @@ -18,6 +18,7 @@ package org.jivesoftware.smackx.filetransfer; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smackx.si.packet.StreamInitiation; +import org.jxmpp.jid.Jid; /** * A request to send a file recieved from another user. @@ -88,7 +89,7 @@ public class FileTransferRequest { * @return Returns the fully-qualified jabber ID of the user that requested * this file transfer. */ - public String getRequestor() { + public Jid getRequestor() { return streamInitiation.getFrom(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IBBTransferNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IBBTransferNegotiator.java index 2cee14b03..ee8465911 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IBBTransferNegotiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IBBTransferNegotiator.java @@ -35,6 +35,7 @@ import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamSession; import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; import org.jivesoftware.smackx.bytestreams.ibb.packet.Open; import org.jivesoftware.smackx.si.packet.StreamInitiation; +import org.jxmpp.jid.Jid; /** * The In-Band Bytestream file transfer method, or IBB for short, transfers the @@ -62,8 +63,8 @@ public class IBBTransferNegotiator extends StreamNegotiator { this.manager = InBandBytestreamManager.getByteStreamManager(connection); } - public OutputStream createOutgoingStream(String streamID, String initiator, - String target) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public OutputStream createOutgoingStream(String streamID, Jid initiator, + Jid target) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { InBandBytestreamSession session = this.manager.establishSession(target, streamID); session.setCloseBothStreamsEnabled(true); return session.getOutputStream(); @@ -81,7 +82,7 @@ public class IBBTransferNegotiator extends StreamNegotiator { return negotiateIncomingStream(streamInitiation); } - public PacketFilter getInitiationPacketFilter(String from, String streamID) { + public PacketFilter getInitiationPacketFilter(Jid from, String streamID) { /* * this method is always called prior to #negotiateIncomingStream() so * the In-Band Bytestream initiation listener must ignore the next diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java index ed7207fe1..b00542526 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java @@ -30,6 +30,7 @@ import org.jivesoftware.smack.SmackException.IllegalStateChangeException; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.XMPPError; +import org.jxmpp.jid.Jid; /** * Handles the sending of a file to another user. File transfer's in jabber have @@ -70,11 +71,11 @@ public class OutgoingFileTransfer extends FileTransfer { private OutputStream outputStream; - private String initiator; + private Jid initiator; private Thread transferThread; - protected OutgoingFileTransfer(String initiator, String target, + protected OutgoingFileTransfer(Jid initiator, Jid target, String streamID, FileTransferNegotiator transferNegotiator) { super(target, streamID, transferNegotiator); this.initiator = initiator; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java index 4dc0cb39e..1ebf2d614 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java @@ -37,6 +37,7 @@ import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamRequest; import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream; import org.jivesoftware.smackx.si.packet.StreamInitiation; +import org.jxmpp.jid.Jid; /** * Negotiates a SOCKS5 Bytestream to be used for file transfers. The implementation is based on the @@ -57,7 +58,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator { } @Override - public OutputStream createOutgoingStream(String streamID, String initiator, String target) throws NoResponseException, SmackException, XMPPException + public OutputStream createOutgoingStream(String streamID, Jid initiator, Jid target) throws NoResponseException, SmackException, XMPPException { try { return this.manager.establishSession(target, streamID).getOutputStream(); @@ -84,7 +85,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator { } @Override - public PacketFilter getInitiationPacketFilter(final String from, String streamID) { + public PacketFilter getInitiationPacketFilter(final Jid from, String streamID) { /* * this method is always called prior to #negotiateIncomingStream() so the SOCKS5 * InitiationListener must ignore the next SOCKS5 Bytestream request with the given session diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java index 50d649857..fd16368e9 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java @@ -29,6 +29,7 @@ import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smackx.si.packet.StreamInitiation; import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.packet.DataForm; +import org.jxmpp.jid.Jid; import java.io.InputStream; import java.io.OutputStream; @@ -94,7 +95,7 @@ public abstract class StreamNegotiator { * @return The PacketFilter that will return the packet relatable to the stream * initiation. */ - public abstract PacketFilter getInitiationPacketFilter(String from, String streamID); + public abstract PacketFilter getInitiationPacketFilter(Jid from, String streamID); abstract InputStream negotiateIncomingStream(Stanza streamInitiation) throws XMPPErrorException, @@ -137,7 +138,7 @@ public abstract class StreamNegotiator { * @throws InterruptedException */ public abstract OutputStream createOutgoingStream(String streamID, - String initiator, String target) throws XMPPErrorException, NoResponseException, SmackException, XMPPException, InterruptedException; + Jid initiator, Jid target) throws XMPPErrorException, NoResponseException, SmackException, XMPPException, InterruptedException; /** * Returns the XMPP namespace reserved for this particular type of file diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java index 6e8b03fae..a3a1d1b2c 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java @@ -40,6 +40,7 @@ import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError.Condition; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.iqlast.packet.LastActivity; +import org.jxmpp.jid.Jid; /** * A last activity manager for handling information about the last activity @@ -233,7 +234,7 @@ public class LastActivityManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public LastActivity getLastActivity(String jid) throws NoResponseException, XMPPErrorException, + public LastActivity getLastActivity(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { LastActivity activity = new LastActivity(jid); return (LastActivity) connection().createPacketCollectorAndSend(activity).nextResultOrThrow(); @@ -249,7 +250,7 @@ public class LastActivityManager extends Manager { * @throws NoResponseException * @throws InterruptedException */ - public boolean isLastActivitySupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public boolean isLastActivitySupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, LastActivity.NAMESPACE); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java index b4cd6fcd6..43e9de00e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java @@ -22,6 +22,7 @@ import java.io.IOException; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.provider.IQProvider; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -47,7 +48,7 @@ public class LastActivity extends IQ { setType(IQ.Type.get); } - public LastActivity(String to) { + public LastActivity(Jid to) { this(); setTo(to); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java index f3296c867..d673f9753 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java @@ -34,7 +34,6 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.filter.PacketIDFilter; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.iqregister.packet.Registration; -import org.jxmpp.util.XmppStringUtils; /** * Allows creation and management of accounts on an XMPP server. @@ -253,7 +252,7 @@ public class AccountManager extends Manager { */ public void changePassword(String newPassword) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Map map = new HashMap(); - map.put("username",XmppStringUtils.parseLocalpart(connection().getUser())); + map.put("username", connection().getUser().getLocalpart().toString()); map.put("password",newPassword); Registration reg = new Registration(map); reg.setType(IQ.Type.set); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java index 2681d9b2d..8f081e679 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java @@ -35,6 +35,7 @@ import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError.Condition; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.iqversion.packet.Version; +import org.jxmpp.jid.Jid; /** * A Version Manager that automatically responds to version IQs with a predetermined reply. @@ -123,7 +124,7 @@ public class VersionManager extends Manager { ourVersion = null; } - public boolean isSupported(String jid) throws NoResponseException, XMPPErrorException, + public boolean isSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Version.NAMESPACE); @@ -139,7 +140,7 @@ public class VersionManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public Version getVersion(String jid) throws NoResponseException, XMPPErrorException, + public Version getVersion(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { if (!isSupported(jid)) { return null; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java index 58e592849..6a72a919f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java @@ -21,6 +21,7 @@ package org.jivesoftware.smackx.iqversion.packet; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.util.StringUtils; +import org.jxmpp.jid.Jid; /** * A Version IQ packet, which is used by XMPP clients to discover version information @@ -68,7 +69,7 @@ public class Version extends IQ { * * @param to the jid where to request version from */ - public Version(String to) { + public Version(Jid to) { this(); setTo(to); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Affiliate.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Affiliate.java index 8177a75c0..1a41c59e5 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Affiliate.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Affiliate.java @@ -18,6 +18,8 @@ package org.jivesoftware.smackx.muc; import org.jivesoftware.smackx.muc.packet.MUCItem; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.parts.Resourcepart; /** * Represents an affiliation of a user to a given room. The affiliate's information will always have @@ -28,12 +30,12 @@ import org.jivesoftware.smackx.muc.packet.MUCItem; */ public class Affiliate { // Fields that must have a value - private final String jid; + private final Jid jid; private final MUCAffiliation affiliation; // Fields that may have a value private final MUCRole role; - private final String nick; + private final Resourcepart nick; Affiliate(MUCItem item) { this.jid = item.getJid(); @@ -47,7 +49,7 @@ public class Affiliate { * * @return the bare JID of the affiliated user. */ - public String getJid() { + public Jid getJid() { return jid; } @@ -79,7 +81,7 @@ public class Affiliate { * @return the current nickname of the affiliated user in the room or null if the user is not in * the room. */ - public String getNick() { + public Resourcepart getNick() { return nick; } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultParticipantStatusListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultParticipantStatusListener.java index 258ad6d14..4578accc7 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultParticipantStatusListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultParticipantStatusListener.java @@ -17,6 +17,10 @@ package org.jivesoftware.smackx.muc; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.parts.Resourcepart; + /** * Default implementation of the ParticipantStatusListener interface.

      * @@ -28,49 +32,49 @@ package org.jivesoftware.smackx.muc; */ public class DefaultParticipantStatusListener implements ParticipantStatusListener { - public void joined(String participant) { + public void joined(FullJid participant) { } - public void left(String participant) { + public void left(FullJid participant) { } - public void kicked(String participant, String actor, String reason) { + public void kicked(FullJid participant, Jid actor, String reason) { } - public void voiceGranted(String participant) { + public void voiceGranted(FullJid participant) { } - public void voiceRevoked(String participant) { + public void voiceRevoked(FullJid participant) { } - public void banned(String participant, String actor, String reason) { + public void banned(FullJid participant, Jid actor, String reason) { } - public void membershipGranted(String participant) { + public void membershipGranted(FullJid participant) { } - public void membershipRevoked(String participant) { + public void membershipRevoked(FullJid participant) { } - public void moderatorGranted(String participant) { + public void moderatorGranted(FullJid participant) { } - public void moderatorRevoked(String participant) { + public void moderatorRevoked(FullJid participant) { } - public void ownershipGranted(String participant) { + public void ownershipGranted(FullJid participant) { } - public void ownershipRevoked(String participant) { + public void ownershipRevoked(FullJid participant) { } - public void adminGranted(String participant) { + public void adminGranted(FullJid participant) { } - public void adminRevoked(String participant) { + public void adminRevoked(FullJid participant) { } - public void nicknameChanged(String participant, String newNickname) { + public void nicknameChanged(FullJid participant, Resourcepart newNickname) { } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultUserStatusListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultUserStatusListener.java index f83b88419..9d9757465 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultUserStatusListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultUserStatusListener.java @@ -17,6 +17,8 @@ package org.jivesoftware.smackx.muc; +import org.jxmpp.jid.Jid; + /** * Default implementation of the UserStatusListener interface.

      * @@ -28,7 +30,7 @@ package org.jivesoftware.smackx.muc; */ public class DefaultUserStatusListener implements UserStatusListener { - public void kicked(String actor, String reason) { + public void kicked(Jid actor, String reason) { } public void voiceGranted() { @@ -37,7 +39,7 @@ public class DefaultUserStatusListener implements UserStatusListener { public void voiceRevoked() { } - public void banned(String actor, String reason) { + public void banned(Jid actor, String reason) { } public void membershipGranted() { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/HostedRoom.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/HostedRoom.java index 0c15b352d..5d4defa1e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/HostedRoom.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/HostedRoom.java @@ -17,21 +17,22 @@ package org.jivesoftware.smackx.muc; import org.jivesoftware.smackx.disco.packet.DiscoverItems; +import org.jxmpp.jid.Jid; /** * Hosted rooms by a chat service may be discovered if they are configured to appear in the room * directory . The information that may be discovered is the XMPP address of the room and the room * name. The address of the room may be used for obtaining more detailed information - * {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getRoomInfo(String)} + * {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getRoomInfo(org.jxmpp.jid.BareJid)} * or could be used for joining the room - * {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getMultiUserChat(String)} - * and {@link org.jivesoftware.smackx.muc.MultiUserChat#join(String)}. + * {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getMultiUserChat(org.jxmpp.jid.BareJid)} + * and {@link org.jivesoftware.smackx.muc.MultiUserChat#join(org.jxmpp.jid.parts.Resourcepart)}. * * @author Gaston Dombiak */ public class HostedRoom { - private final String jid; + private final Jid jid; private final String name; @@ -46,7 +47,7 @@ public class HostedRoom { * * @return the XMPP address of the hosted room by the chat service. */ - public String getJid() { + public Jid getJid() { return jid; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java index 87d26566f..3a02dcb96 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -19,9 +19,7 @@ package org.jivesoftware.smackx.muc; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -69,9 +67,15 @@ import org.jivesoftware.smackx.muc.packet.MUCUser.Status; import org.jivesoftware.smackx.xdata.Form; import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.packet.DataForm; +import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.JidWithLocalpart; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.jid.parts.Resourcepart; /** - * A MultiUserChat room (XEP-45), created with {@link MultiUserChatManager#getMultiUserChat(String)}. + * A MultiUserChat room (XEP-45), created with {@link MultiUserChatManager#getMultiUserChat(BareJid)}. *

      * A MultiUserChat is a conversation that takes place among many users in a virtual * room. A room could have many occupants with different affiliation and roles. @@ -91,9 +95,9 @@ public class MultiUserChat { private static final Logger LOGGER = Logger.getLogger(MultiUserChat.class.getName()); private final XMPPConnection connection; - private final String room; + private final BareJid room; private final MultiUserChatManager multiUserChatManager; - private final Map occupantsMap = new ConcurrentHashMap(); + private final Map occupantsMap = new ConcurrentHashMap<>(); private final Set invitationRejectionListeners = new CopyOnWriteArraySet(); private final Set subjectUpdatedListeners = new CopyOnWriteArraySet(); @@ -122,13 +126,13 @@ public class MultiUserChat { private final PacketListener declinesListener; private String subject; - private String nickname = null; + private Resourcepart nickname; private boolean joined = false; private PacketCollector messageCollector; - MultiUserChat(XMPPConnection connection, String room, MultiUserChatManager multiUserChatManager) { + MultiUserChat(XMPPConnection connection, BareJid room, MultiUserChatManager multiUserChatManager) { this.connection = connection; - this.room = room.toLowerCase(Locale.US); + this.room = room; this.multiUserChatManager = multiUserChatManager; fromRoomFilter = FromMatchesFilter.create(room); @@ -148,11 +152,16 @@ public class MultiUserChat { subjectListener = new PacketListener() { public void processPacket(Stanza packet) { Message msg = (Message) packet; + FullJid from = msg.getFrom().asFullJidIfPossible(); + if (from == null) { + LOGGER.warning("Message subject not changed by a full JID: " + msg.getFrom()); + return; + } // Update the room subject subject = msg.getSubject(); // Fire event for subject updated listeners for (SubjectUpdatedListener listener : subjectUpdatedListeners) { - listener.subjectUpdated(subject, msg.getFrom()); + listener.subjectUpdated(subject, from); } } }; @@ -161,7 +170,11 @@ public class MultiUserChat { presenceListener = new PacketListener() { public void processPacket(Stanza packet) { Presence presence = (Presence) packet; - String from = presence.getFrom(); + final FullJid from = presence.getFrom().asFullJidIfPossible(); + if (from == null) { + LOGGER.warning("Presence not from a full JID: " + presence.getFrom()); + return; + } String myRoomJID = MultiUserChat.this.room + "/" + nickname; boolean isUserStatusModification = presence.getFrom().equals(myRoomJID); switch (presence.getType()) { @@ -254,7 +267,7 @@ public class MultiUserChat { * * @return the multi user chat room name. */ - public String getRoom() { + public BareJid getRoom() { return room; } @@ -272,14 +285,15 @@ public class MultiUserChat { * @throws InterruptedException * @see XEP-45 7.2 Entering a Room */ - private Presence enter(String nickname, String password, DiscussionHistory history, + private Presence enter(Resourcepart nickname, String password, DiscussionHistory history, long timeout) throws NotConnectedException, NoResponseException, XMPPErrorException, InterruptedException { StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank."); // We enter a room by sending a presence packet where the "to" // field is in the form "roomName@service/nickname" Presence joinPresence = new Presence(Presence.Type.available); - joinPresence.setTo(room + "/" + nickname); + final FullJid jid = JidCreate.fullFrom(room, nickname); + joinPresence.setTo(jid); // Indicate the the client supports MUC MUCInitialPresence mucInitialPresence = new MUCInitialPresence(); @@ -292,8 +306,7 @@ public class MultiUserChat { joinPresence.addExtension(mucInitialPresence); // Wait for a presence packet back from the server. - PacketFilter responseFilter = new AndFilter(FromMatchesFilter.createFull(room + "/" - + nickname), new PacketTypeFilter(Presence.class)); + PacketFilter responseFilter = new AndFilter(FromMatchesFilter.createFull(jid), new PacketTypeFilter(Presence.class)); // Setup the messageListeners and presenceListeners *before* the join presence is send. connection.addSyncPacketListener(messageListener, fromRoomGroupchatFilter); @@ -348,7 +361,7 @@ public class MultiUserChat { * server, e.g. because the room already existed. * @throws InterruptedException */ - public synchronized void create(String nickname) throws NoResponseException, XMPPErrorException, SmackException, InterruptedException { + public synchronized void create(Resourcepart nickname) throws NoResponseException, XMPPErrorException, SmackException, InterruptedException { if (joined) { throw new IllegalStateException("Creation failed - User already joined the room."); } @@ -363,7 +376,7 @@ public class MultiUserChat { } /** - * Same as {@link #createOrJoin(String, String, DiscussionHistory, long)}, but without a password, specifying a + * Same as {@link #createOrJoin(Resourcepart, String, DiscussionHistory, long)}, but without a password, specifying a * discussion history and using the connections default reply timeout. * * @param nickname @@ -372,15 +385,15 @@ public class MultiUserChat { * @throws XMPPErrorException * @throws SmackException * @throws InterruptedException - * @see #createOrJoin(String, String, DiscussionHistory, long) + * @see #createOrJoin(Resourcepart, String, DiscussionHistory, long) */ - public synchronized boolean createOrJoin(String nickname) throws NoResponseException, XMPPErrorException, + public synchronized boolean createOrJoin(Resourcepart nickname) throws NoResponseException, XMPPErrorException, SmackException, InterruptedException { return createOrJoin(nickname, null, null, connection.getPacketReplyTimeout()); } /** - * Like {@link #create(String)}, but will return true if the room creation was acknowledged by + * Like {@link #create(Resourcepart)}, but will return true if the room creation was acknowledged by * the service (with an 201 status code). It's up to the caller to decide, based on the return * value, if he needs to continue sending the room configuration. If false is returned, the room * already existed and the user is able to join right away, without sending a form. @@ -395,7 +408,7 @@ public class MultiUserChat { * @throws NoResponseException if there was no response from the server. * @throws InterruptedException */ - public synchronized boolean createOrJoin(String nickname, String password, DiscussionHistory history, long timeout) + public synchronized boolean createOrJoin(Resourcepart nickname, String password, DiscussionHistory history, long timeout) throws NoResponseException, XMPPErrorException, SmackException, InterruptedException { if (joined) { throw new IllegalStateException("Creation failed - User already joined the room."); @@ -431,7 +444,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void join(String nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public void join(Resourcepart nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { join(nickname, null, null, connection.getPacketReplyTimeout()); } @@ -456,7 +469,7 @@ public class MultiUserChat { * @throws SmackException if there was no response from the server. * @throws InterruptedException */ - public void join(String nickname, String password) throws XMPPErrorException, SmackException, InterruptedException { + public void join(Resourcepart nickname, String password) throws XMPPErrorException, SmackException, InterruptedException { join(nickname, password, null, connection.getPacketReplyTimeout()); } @@ -489,7 +502,7 @@ public class MultiUserChat { * @throws InterruptedException */ public synchronized void join( - String nickname, + Resourcepart nickname, String password, DiscussionHistory history, long timeout) @@ -504,7 +517,7 @@ public class MultiUserChat { /** * Returns true if currently in the multi user chat (after calling the {@link - * #join(String)} method). + * #join(Resourcepart)} method). * * @return true if currently in the multi user chat room. */ @@ -525,7 +538,7 @@ public class MultiUserChat { // We leave a room by sending a presence packet where the "to" // field is in the form "roomName@service/nickname" Presence leavePresence = new Presence(Presence.Type.unavailable); - leavePresence.setTo(room + "/" + nickname); + leavePresence.setTo(JidCreate.fullFrom(room, nickname)); connection.sendPacket(leavePresence); // Reset occupant information. occupantsMap.clear(); @@ -841,7 +854,7 @@ public class MultiUserChat { * * @return the nickname currently being used. */ - public String getNickname() { + public Resourcepart getNickname() { return nickname; } @@ -858,23 +871,24 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void changeNickname(String nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public void changeNickname(Resourcepart nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank."); // Check that we already have joined the room before attempting to change the // nickname. if (!joined) { throw new IllegalStateException("Must be logged into the room to change nickname."); } + final FullJid jid = JidCreate.fullFrom(room, nickname); // We change the nickname by sending a presence packet where the "to" // field is in the form "roomName@service/nickname" // We don't have to signal the MUC support again Presence joinPresence = new Presence(Presence.Type.available); - joinPresence.setTo(room + "/" + nickname); + joinPresence.setTo(jid); // Wait for a presence packet back from the server. PacketFilter responseFilter = new AndFilter( - FromMatchesFilter.createFull(room + "/" + nickname), + FromMatchesFilter.createFull(jid), new PacketTypeFilter(Presence.class)); PacketCollector response = connection.createPacketCollectorAndSend(responseFilter, joinPresence); // Wait up to a certain number of seconds for a reply. If there is a negative reply, an @@ -907,7 +921,7 @@ public class MultiUserChat { Presence joinPresence = new Presence(Presence.Type.available); joinPresence.setStatus(status); joinPresence.setMode(mode); - joinPresence.setTo(room + "/" + nickname); + joinPresence.setTo(JidCreate.fullFrom(room, nickname)); // Send join packet. connection.sendPacket(joinPresence); @@ -934,7 +948,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void kickParticipant(String nickname, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void kickParticipant(Resourcepart nickname, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeRole(nickname, MUCRole.none, reason); } @@ -976,7 +990,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void grantVoice(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void grantVoice(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeRole(nicknames, MUCRole.participant); } @@ -994,7 +1008,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void grantVoice(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void grantVoice(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeRole(nickname, MUCRole.participant, null); } @@ -1012,7 +1026,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void revokeVoice(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void revokeVoice(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeRole(nicknames, MUCRole.visitor); } @@ -1030,7 +1044,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void revokeVoice(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void revokeVoice(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeRole(nickname, MUCRole.visitor, null); } @@ -1049,7 +1063,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void banUsers(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void banUsers(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jids, MUCAffiliation.outcast); } @@ -1069,7 +1083,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void banUser(String jid, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void banUser(Jid jid, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jid, MUCAffiliation.outcast, reason); } @@ -1084,7 +1098,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void grantMembership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void grantMembership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jids, MUCAffiliation.member); } @@ -1099,7 +1113,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void grantMembership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void grantMembership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jid, MUCAffiliation.member, null); } @@ -1115,7 +1129,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void revokeMembership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void revokeMembership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jids, MUCAffiliation.none); } @@ -1131,7 +1145,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void revokeMembership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void revokeMembership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jid, MUCAffiliation.none, null); } @@ -1146,7 +1160,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void grantModerator(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void grantModerator(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeRole(nicknames, MUCRole.moderator); } @@ -1161,7 +1175,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void grantModerator(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void grantModerator(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeRole(nickname, MUCRole.moderator, null); } @@ -1177,7 +1191,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void revokeModerator(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void revokeModerator(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeRole(nicknames, MUCRole.participant); } @@ -1193,7 +1207,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void revokeModerator(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void revokeModerator(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeRole(nickname, MUCRole.participant, null); } @@ -1209,7 +1223,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void grantOwnership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void grantOwnership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jids, MUCAffiliation.owner); } @@ -1225,7 +1239,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void grantOwnership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void grantOwnership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jid, MUCAffiliation.owner, null); } @@ -1240,7 +1254,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void revokeOwnership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void revokeOwnership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jids, MUCAffiliation.admin); } @@ -1255,7 +1269,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void revokeOwnership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void revokeOwnership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jid, MUCAffiliation.admin, null); } @@ -1270,7 +1284,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void grantAdmin(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void grantAdmin(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jids, MUCAffiliation.admin); } @@ -1286,7 +1300,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void grantAdmin(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void grantAdmin(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jid, MUCAffiliation.admin); } @@ -1301,7 +1315,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void revokeAdmin(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void revokeAdmin(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jids, MUCAffiliation.admin); } @@ -1317,7 +1331,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - public void revokeAdmin(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { + public void revokeAdmin(JidWithLocalpart jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jid, MUCAffiliation.member); } @@ -1331,7 +1345,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - private void changeAffiliationByAdmin(String jid, MUCAffiliation affiliation) + private void changeAffiliationByAdmin(Jid jid, MUCAffiliation affiliation) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { changeAffiliationByAdmin(jid, affiliation, null); @@ -1348,7 +1362,7 @@ public class MultiUserChat { * @throws NotConnectedException * @throws InterruptedException */ - private void changeAffiliationByAdmin(String jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + private void changeAffiliationByAdmin(Jid jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCAdmin iq = new MUCAdmin(); iq.setTo(room); @@ -1360,12 +1374,12 @@ public class MultiUserChat { connection.createPacketCollectorAndSend(iq).nextResultOrThrow(); } - private void changeAffiliationByAdmin(Collection jids, MUCAffiliation affiliation) + private void changeAffiliationByAdmin(Collection jids, MUCAffiliation affiliation) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCAdmin iq = new MUCAdmin(); iq.setTo(room); iq.setType(IQ.Type.set); - for (String jid : jids) { + for (Jid jid : jids) { // Set the new affiliation. MUCItem item = new MUCItem(affiliation, jid); iq.addItem(item); @@ -1374,7 +1388,7 @@ public class MultiUserChat { connection.createPacketCollectorAndSend(iq).nextResultOrThrow(); } - private void changeRole(String nickname, MUCRole role, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + private void changeRole(Resourcepart nickname, MUCRole role, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCAdmin iq = new MUCAdmin(); iq.setTo(room); iq.setType(IQ.Type.set); @@ -1385,11 +1399,11 @@ public class MultiUserChat { connection.createPacketCollectorAndSend(iq).nextResultOrThrow(); } - private void changeRole(Collection nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + private void changeRole(Collection nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { MUCAdmin iq = new MUCAdmin(); iq.setTo(room); iq.setType(IQ.Type.set); - for (String nickname : nicknames) { + for (Resourcepart nickname : nicknames) { // Set the new role. MUCItem item = new MUCItem(role, nickname); iq.addItem(item); @@ -1413,7 +1427,7 @@ public class MultiUserChat { } /** - * Returns an Iterator (of Strings) for the list of fully qualified occupants + * Returns an List for the list of fully qualified occupants * in the group chat. For example, "conference@chat.jivesoftware.com/SomeUser". * Typically, a client would only display the nickname of the occupant. To * get the nickname from the fully qualified name, use the @@ -1423,8 +1437,8 @@ public class MultiUserChat { * * @return a List of the occupants in the group chat. */ - public List getOccupants() { - return Collections.unmodifiableList(new ArrayList(occupantsMap.keySet())); + public List getOccupants() { + return new ArrayList<>(occupantsMap.keySet()); } /** @@ -1642,7 +1656,7 @@ public class MultiUserChat { * created chat. * @return new Chat for sending private messages to a given room occupant. */ - public Chat createPrivateChat(String occupant, ChatMessageListener listener) { + public Chat createPrivateChat(FullJid occupant, ChatMessageListener listener) { return ChatManager.getInstanceFor(connection).createChat(occupant, listener); } @@ -1884,7 +1898,7 @@ public class MultiUserChat { MUCRole oldRole, MUCRole newRole, boolean isUserModification, - String from) { + FullJid from) { // Voice was granted to a visitor if (("visitor".equals(oldRole) || "none".equals(oldRole)) && "participant".equals(newRole)) { @@ -2010,7 +2024,7 @@ public class MultiUserChat { MUCAffiliation oldAffiliation, MUCAffiliation newAffiliation, boolean isUserModification, - String from) { + FullJid from) { // First check for revoked affiliation and then for granted affiliations. The idea is to // first fire the "revoke" events and then fire the "grant" events. @@ -2107,7 +2121,7 @@ public class MultiUserChat { Set statusCodes, boolean isUserModification, MUCUser mucUser, - String from) { + FullJid from) { // Check if an occupant was kicked from the room if (statusCodes.contains(Status.KICKED_307)) { // Check if this occupant was kicked diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java index f55ba50b8..5724dbb01 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Set; import java.util.WeakHashMap; import java.util.concurrent.CopyOnWriteArraySet; +import java.util.logging.Logger; import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.Manager; @@ -49,10 +50,16 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverItems; import org.jivesoftware.smackx.muc.packet.MUCInitialPresence; import org.jivesoftware.smackx.muc.packet.MUCUser; +import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.JidWithLocalpart; public class MultiUserChatManager extends Manager { private final static String DISCO_NODE = MUCInitialPresence.NAMESPACE + "#rooms"; + private static final Logger LOGGER = Logger.getLogger(MultiUserChatManager.class.getName()); + static { XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { public void connectionCreated(final XMPPConnection connection) { @@ -71,9 +78,9 @@ public class MultiUserChatManager extends Manager { XMPPConnection connection = weakRefConnection.get(); if (connection == null) return Collections.emptyList(); - Set joinedRooms = MultiUserChatManager.getInstanceFor(connection).getJoinedRooms(); + Set joinedRooms = MultiUserChatManager.getInstanceFor(connection).getJoinedRooms(); List answer = new ArrayList(); - for (String room : joinedRooms) { + for (BareJid room : joinedRooms) { answer.add(new DiscoverItems.Item(room)); } return answer; @@ -104,14 +111,14 @@ public class MultiUserChatManager extends Manager { new NotFilter(MessageTypeFilter.ERROR)); private final Set invitationsListeners = new CopyOnWriteArraySet(); - private final Set joinedRooms = new HashSet(); + private final Set joinedRooms = new HashSet<>(); /** * A Map of MUC JIDs to {@link MultiUserChat} instances. We use weak references for the values in order to allow * those instances to get garbage collected. Note that MultiUserChat instances can not get garbage collected while * the user is joined, because then the MUC will have PacketListeners added to the XMPPConnection. */ - private final Map> multiUserChats = new HashMap>(); + private final Map> multiUserChats = new HashMap<>(); private MultiUserChatManager(XMPPConnection connection) { super(connection); @@ -124,8 +131,13 @@ public class MultiUserChatManager extends Manager { final MUCUser mucUser = MUCUser.from(message); // Check if the MUCUser extension includes an invitation if (mucUser.getInvite() != null) { + BareJid mucJid = message.getFrom().asBareJidIfPossible(); + if (mucJid == null) { + LOGGER.warning("Invite to non bare JID: '" + message.toXML() + "'"); + return; + } // Fire event for invitation listeners - final MultiUserChat muc = getMultiUserChat(packet.getFrom()); + final MultiUserChat muc = getMultiUserChat(mucJid); for (final InvitationListener listener : invitationsListeners) { listener.invitationReceived(connection(), muc, mucUser.getInvite().getFrom(), mucUser.getInvite().getReason(), mucUser.getPassword(), message); @@ -138,7 +150,7 @@ public class MultiUserChatManager extends Manager { /** * Creates a multi user chat. Note: no information is sent to or received from the server until you attempt to - * {@link MultiUserChat#join(String) join} the chat room. On some server implementations, the room will not be + * {@link MultiUserChat#join(org.jxmpp.jid.parts.Resourcepart) join} the chat room. On some server implementations, the room will not be * created until the first person joins it. *

      * Most XMPP servers use a sub-domain for the chat service (eg chat.example.com for the XMPP server example.com). @@ -148,7 +160,7 @@ public class MultiUserChatManager extends Manager { * @param jid the name of the room in the form "roomName@service", where "service" is the hostname at which the * multi-user chat service is running. Make sure to provide a valid JID. */ - public synchronized MultiUserChat getMultiUserChat(String jid) { + public synchronized MultiUserChat getMultiUserChat(BareJid jid) { WeakReference weakRefMultiUserChat = multiUserChats.get(jid); if (weakRefMultiUserChat == null) { return createNewMucAndAddToMap(jid); @@ -160,7 +172,7 @@ public class MultiUserChatManager extends Manager { return multiUserChat; } - private MultiUserChat createNewMucAndAddToMap(String jid) { + private MultiUserChat createNewMucAndAddToMap(BareJid jid) { MultiUserChat multiUserChat = new MultiUserChat(connection(), jid, this); multiUserChats.put(jid, new WeakReference(multiUserChat)); return multiUserChat; @@ -176,7 +188,7 @@ public class MultiUserChatManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public boolean isServiceEnabled(String user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public boolean isServiceEnabled(Jid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(user, MUCInitialPresence.NAMESPACE); } @@ -186,7 +198,7 @@ public class MultiUserChatManager extends Manager { * * @return a List of the rooms where the user has joined using a given connection. */ - public Set getJoinedRooms() { + public Set getJoinedRooms() { return Collections.unmodifiableSet(joinedRooms); } @@ -201,15 +213,20 @@ public class MultiUserChatManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public List getJoinedRooms(String user) throws NoResponseException, XMPPErrorException, + public List getJoinedRooms(JidWithLocalpart user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { // Send the disco packet to the user DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(user, DISCO_NODE); List items = result.getItems(); - List answer = new ArrayList(items.size()); + List answer = new ArrayList<>(items.size()); // Collect the entityID for each returned item for (DiscoverItems.Item item : items) { - answer.add(item.getEntityID()); + BareJid muc = item.getEntityID().asBareJidIfPossible(); + if (muc == null) { + LOGGER.warning("Not a bare JID: " + item.getEntityID()); + continue; + } + answer.add(muc); } return answer; } @@ -225,7 +242,7 @@ public class MultiUserChatManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public RoomInfo getRoomInfo(String room) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public RoomInfo getRoomInfo(BareJid room) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection()).discoverInfo(room); return new RoomInfo(info); } @@ -239,7 +256,7 @@ public class MultiUserChatManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public List getServiceNames() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public List getServiceNames() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); return sdm.findServices(MUCInitialPresence.NAMESPACE, false, false); } @@ -256,7 +273,7 @@ public class MultiUserChatManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public List getHostedRooms(String serviceName) throws NoResponseException, XMPPErrorException, + public List getHostedRooms(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection()); DiscoverItems discoverItems = discoManager.discoverItems(serviceName); @@ -278,7 +295,7 @@ public class MultiUserChatManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public void decline(String room, String inviter, String reason) throws NotConnectedException, InterruptedException { + public void decline(BareJid room, String inviter, String reason) throws NotConnectedException, InterruptedException { Message message = new Message(room); // Create the MUCUser packet that will include the rejection @@ -311,11 +328,11 @@ public class MultiUserChatManager extends Manager { invitationsListeners.remove(listener); } - void addJoinedRoom(String room) { + void addJoinedRoom(BareJid room) { joinedRooms.add(room); } - void removeJoinedRoom(String room) { + void removeJoinedRoom(BareJid room) { joinedRooms.remove(room); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Occupant.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Occupant.java index caa629d3d..0e6f93301 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Occupant.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Occupant.java @@ -17,10 +17,14 @@ package org.jivesoftware.smackx.muc; +import java.util.logging.Logger; + import org.jivesoftware.smackx.muc.packet.MUCItem; import org.jivesoftware.smackx.muc.packet.MUCUser; import org.jivesoftware.smack.packet.Presence; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.parts.Resourcepart; /** * Represents the information about an occupant in a given room. The information will always have @@ -29,12 +33,15 @@ import org.jxmpp.util.XmppStringUtils; * @author Gaston Dombiak */ public class Occupant { + + private static final Logger LOGGER = Logger.getLogger(Occupant.class.getName()); + // Fields that must have a value private final MUCAffiliation affiliation; private final MUCRole role; // Fields that may have a value - private final String jid; - private final String nick; + private final Jid jid; + private final Resourcepart nick; Occupant(MUCItem item) { this.jid = item.getJid(); @@ -51,7 +58,13 @@ public class Occupant { this.affiliation = item.getAffiliation(); this.role = item.getRole(); // Get the nickname from the FROM attribute of the presence - this.nick = XmppStringUtils.parseResource(presence.getFrom()); + FullJid from = presence.getFrom().asFullJidIfPossible(); + if (from == null) { + LOGGER.warning("Occupant presence without resource: " + presence.getFrom()); + this.nick = null; + } else { + this.nick = from.getResourcepart(); + } } /** @@ -62,7 +75,7 @@ public class Occupant { * * @return the full JID of the occupant. */ - public String getJid() { + public Jid getJid() { return jid; } @@ -93,7 +106,7 @@ public class Occupant { * @return the current nickname of the occupant in the room or null if this information was * obtained from a presence. */ - public String getNick() { + public Resourcepart getNick() { return nick; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/ParticipantStatusListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/ParticipantStatusListener.java index 83c13ce24..2464540d8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/ParticipantStatusListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/ParticipantStatusListener.java @@ -17,6 +17,10 @@ package org.jivesoftware.smackx.muc; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.parts.Resourcepart; + /** * A listener that is fired anytime a participant's status in a room is changed, such as the * user being kicked, banned, or granted admin permissions. @@ -33,7 +37,7 @@ public interface ParticipantStatusListener { * @param participant the participant that has just joined the room * (e.g. room@conference.jabber.org/nick). */ - public abstract void joined(String participant); + public abstract void joined(FullJid participant); /** * Called when a room occupant has left the room on its own. This means that the occupant was @@ -42,7 +46,7 @@ public interface ParticipantStatusListener { * @param participant the participant that has left the room on its own. * (e.g. room@conference.jabber.org/nick). */ - public abstract void left(String participant); + public abstract void left(FullJid participant); /** * Called when a room participant has been kicked from the room. This means that the kicked @@ -53,7 +57,7 @@ public interface ParticipantStatusListener { * @param actor the moderator that kicked the occupant from the room (e.g. user@host.org). * @param reason the reason provided by the actor to kick the occupant from the room. */ - public abstract void kicked(String participant, String actor, String reason); + public abstract void kicked(FullJid participant, Jid actor, String reason); /** * Called when a moderator grants voice to a visitor. This means that the visitor @@ -62,7 +66,7 @@ public interface ParticipantStatusListener { * @param participant the participant that was granted voice in the room * (e.g. room@conference.jabber.org/nick). */ - public abstract void voiceGranted(String participant); + public abstract void voiceGranted(FullJid participant); /** * Called when a moderator revokes voice from a participant. This means that the participant @@ -72,7 +76,7 @@ public interface ParticipantStatusListener { * @param participant the participant that was revoked voice from the room * (e.g. room@conference.jabber.org/nick). */ - public abstract void voiceRevoked(String participant); + public abstract void voiceRevoked(FullJid participant); /** * Called when an administrator or owner banned a participant from the room. This means that @@ -83,7 +87,7 @@ public interface ParticipantStatusListener { * @param actor the administrator that banned the occupant (e.g. user@host.org). * @param reason the reason provided by the administrator to ban the occupant. */ - public abstract void banned(String participant, String actor, String reason); + public abstract void banned(FullJid participant, Jid actor, String reason); /** * Called when an administrator grants a user membership to the room. This means that the user @@ -92,7 +96,7 @@ public interface ParticipantStatusListener { * @param participant the participant that was granted membership in the room * (e.g. room@conference.jabber.org/nick). */ - public abstract void membershipGranted(String participant); + public abstract void membershipGranted(FullJid participant); /** * Called when an administrator revokes a user membership to the room. This means that the @@ -101,7 +105,7 @@ public interface ParticipantStatusListener { * @param participant the participant that was revoked membership from the room * (e.g. room@conference.jabber.org/nick). */ - public abstract void membershipRevoked(String participant); + public abstract void membershipRevoked(FullJid participant); /** * Called when an administrator grants moderator privileges to a user. This means that the user @@ -111,7 +115,7 @@ public interface ParticipantStatusListener { * @param participant the participant that was granted moderator privileges in the room * (e.g. room@conference.jabber.org/nick). */ - public abstract void moderatorGranted(String participant); + public abstract void moderatorGranted(FullJid participant); /** * Called when an administrator revokes moderator privileges from a user. This means that the @@ -121,7 +125,7 @@ public interface ParticipantStatusListener { * @param participant the participant that was revoked moderator privileges in the room * (e.g. room@conference.jabber.org/nick). */ - public abstract void moderatorRevoked(String participant); + public abstract void moderatorRevoked(FullJid participant); /** * Called when an owner grants a user ownership on the room. This means that the user @@ -131,7 +135,7 @@ public interface ParticipantStatusListener { * @param participant the participant that was granted ownership on the room * (e.g. room@conference.jabber.org/nick). */ - public abstract void ownershipGranted(String participant); + public abstract void ownershipGranted(FullJid participant); /** * Called when an owner revokes a user ownership on the room. This means that the user @@ -141,7 +145,7 @@ public interface ParticipantStatusListener { * @param participant the participant that was revoked ownership on the room * (e.g. room@conference.jabber.org/nick). */ - public abstract void ownershipRevoked(String participant); + public abstract void ownershipRevoked(FullJid participant); /** * Called when an owner grants administrator privileges to a user. This means that the user @@ -151,7 +155,7 @@ public interface ParticipantStatusListener { * @param participant the participant that was granted administrator privileges * (e.g. room@conference.jabber.org/nick). */ - public abstract void adminGranted(String participant); + public abstract void adminGranted(FullJid participant); /** * Called when an owner revokes administrator privileges from a user. This means that the user @@ -161,7 +165,7 @@ public interface ParticipantStatusListener { * @param participant the participant that was revoked administrator privileges * (e.g. room@conference.jabber.org/nick). */ - public abstract void adminRevoked(String participant); + public abstract void adminRevoked(FullJid participant); /** * Called when a participant changed his/her nickname in the room. The new participant's @@ -171,6 +175,6 @@ public interface ParticipantStatusListener { * (e.g. room@conference.jabber.org/nick). * @param newNickname the new nickname that the participant decided to use. */ - public abstract void nicknameChanged(String participant, String newNickname); + public abstract void nicknameChanged(FullJid participant, Resourcepart newNickname); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java index 28c8ec872..4c38321d8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java @@ -26,6 +26,8 @@ import java.util.logging.Logger; import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.xdata.Form; import org.jivesoftware.smackx.xdata.FormField; +import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.Jid; /** * Represents the room information that was discovered using Service Discovery. It's possible to @@ -39,9 +41,9 @@ public class RoomInfo { private static final Logger LOGGER = Logger.getLogger(RoomInfo.class.getName()); /** - * JID of the room. The node of the JID is commonly used as the ID of the room or name. + * JID of the room. The localpart of the JID is commonly used as the ID of the room or name. */ - private final String room; + private final BareJid room; /** * Description of the room. */ @@ -128,7 +130,12 @@ public class RoomInfo { private final Form form; RoomInfo(DiscoverInfo info) { - this.room = info.getFrom(); + final Jid from = info.getFrom(); + if (from != null) { + this.room = info.getFrom().asBareJidIfPossible(); + } else { + this.room = null; + } // Get the information based on the discovered features this.membersOnly = info.containsFeature("muc_membersonly"); this.moderated = info.containsFeature("muc_moderated"); @@ -233,7 +240,7 @@ public class RoomInfo { * * @return the JID of the room whose information was discovered. */ - public String getRoom() { + public BareJid getRoom() { return room; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/SubjectUpdatedListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/SubjectUpdatedListener.java index ac254a033..8c55a5695 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/SubjectUpdatedListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/SubjectUpdatedListener.java @@ -17,6 +17,8 @@ package org.jivesoftware.smackx.muc; +import org.jxmpp.jid.FullJid; + /** * A listener that is fired anytime a MUC room changes its subject. * @@ -30,6 +32,6 @@ public interface SubjectUpdatedListener { * @param subject the new room's subject. * @param from the user that changed the room's subject (e.g. room@conference.jabber.org/nick). */ - public abstract void subjectUpdated(String subject, String from); + public abstract void subjectUpdated(String subject, FullJid from); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/UserStatusListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/UserStatusListener.java index 872bc10a9..4fe0329e8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/UserStatusListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/UserStatusListener.java @@ -17,6 +17,8 @@ package org.jivesoftware.smackx.muc; +import org.jxmpp.jid.Jid; + /** * A listener that is fired anytime your participant's status in a room is changed, such as the * user being kicked, banned, or granted admin permissions. @@ -32,7 +34,7 @@ public interface UserStatusListener { * @param actor the moderator that kicked your user from the room (e.g. user@host.org). * @param reason the reason provided by the actor to kick you from the room. */ - public abstract void kicked(String actor, String reason); + public abstract void kicked(Jid actor, String reason); /** * Called when a moderator grants voice to your user. This means that you were a visitor in @@ -57,7 +59,7 @@ public interface UserStatusListener { * @param actor the administrator that banned your user (e.g. user@host.org). * @param reason the reason provided by the administrator to banned you. */ - public abstract void banned(String actor, String reason); + public abstract void banned(Jid actor, String reason); /** * Called when an administrator grants your user membership to the room. This means that you diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java index 7f1630390..9fb2216ac 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java @@ -21,6 +21,8 @@ import org.jivesoftware.smack.packet.NamedElement; import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smackx.muc.MUCAffiliation; import org.jivesoftware.smackx.muc.MUCRole; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.parts.Resourcepart; /** * Item child that holds information about roles, affiliation, jids and nicks. @@ -32,10 +34,10 @@ public class MUCItem implements NamedElement { private final MUCAffiliation affiliation; private final MUCRole role; - private final String actor; + private final Jid actor; private final String reason; - private final String jid; - private final String nick; + private final Jid jid; + private final Resourcepart nick; public MUCItem(MUCAffiliation affiliation) { this(affiliation, null, null, null, null, null); @@ -45,19 +47,19 @@ public class MUCItem implements NamedElement { this(null, role, null, null, null, null); } - public MUCItem(MUCRole role, String nick) { + public MUCItem(MUCRole role, Resourcepart nick) { this(null, role, null, null, null, nick); } - public MUCItem(MUCAffiliation affiliation, String jid, String reason) { + public MUCItem(MUCAffiliation affiliation, Jid jid, String reason) { this(affiliation, null, null, reason, jid, null); } - public MUCItem(MUCAffiliation affiliation, String jid) { + public MUCItem(MUCAffiliation affiliation, Jid jid) { this(affiliation, null, null, null, jid, null); } - public MUCItem(MUCRole role, String nick, String reason) { + public MUCItem(MUCRole role, Resourcepart nick, String reason) { this(null, role, null, reason, null, nick); } @@ -71,8 +73,8 @@ public class MUCItem implements NamedElement { * @param jid * @param nick */ - public MUCItem(MUCAffiliation affiliation, MUCRole role, String actor, - String reason, String jid, String nick) { + public MUCItem(MUCAffiliation affiliation, MUCRole role, Jid actor, + String reason, Jid jid, Resourcepart nick) { this.affiliation = affiliation; this.role = role; this.actor = actor; @@ -86,7 +88,7 @@ public class MUCItem implements NamedElement { * * @return the JID of an occupant in the room that was kicked or banned. */ - public String getActor() { + public Jid getActor() { return actor; } @@ -118,7 +120,7 @@ public class MUCItem implements NamedElement { * * @return the room JID by which an occupant is identified within the room. */ - public String getJid() { + public Jid getJid() { return jid; } @@ -128,7 +130,7 @@ public class MUCItem implements NamedElement { * * @return the new nickname of an occupant that is changing his/her nickname. */ - public String getNick() { + public Resourcepart getNick() { return nick; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java index c3f3f85fa..a143d7418 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java @@ -18,10 +18,13 @@ package org.jivesoftware.smackx.muc.provider; import java.io.IOException; +import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smackx.muc.MUCAffiliation; import org.jivesoftware.smackx.muc.MUCRole; import org.jivesoftware.smackx.muc.packet.Destroy; import org.jivesoftware.smackx.muc.packet.MUCItem; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.parts.Resourcepart; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -29,10 +32,10 @@ public class MUCParserUtils { public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException { int initialDepth = parser.getDepth(); MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation")); - String nick = parser.getAttributeValue("", "nick"); + Resourcepart nick = ParserUtils.getResourcepartAttribute(parser, "nick"); MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role")); - String jid = parser.getAttributeValue("", "jid"); - String actor = null; + Jid jid = ParserUtils.getJidAttribute(parser); + Jid actor = null; String reason = null; outerloop: while (true) { int eventType = parser.next(); @@ -41,7 +44,7 @@ public class MUCParserUtils { String name = parser.getName(); switch (name) { case "actor": - actor = parser.getAttributeValue("", "jid"); + actor = ParserUtils.getJidAttribute(parser); break; case "reason": reason = parser.nextText(); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageHeader.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageHeader.java index a43ecf1f4..e604e376d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageHeader.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageHeader.java @@ -18,6 +18,7 @@ package org.jivesoftware.smackx.offline; import org.jivesoftware.smackx.disco.packet.DiscoverItems; +import org.jxmpp.jid.Jid; /** * The OfflineMessageHeader holds header information of an offline message. The header @@ -32,7 +33,7 @@ public class OfflineMessageHeader { /** * Bare JID of the user that was offline when the message was sent. */ - private String user; + private Jid user; /** * Full JID of the user that sent the message. */ @@ -56,7 +57,7 @@ public class OfflineMessageHeader { * * @return the bare JID of the user that was offline when the message was sent. */ - public String getUser() { + public Jid getUser() { return user; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPListener.java index 794321edc..b53811847 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPListener.java @@ -18,6 +18,7 @@ package org.jivesoftware.smackx.pep; import org.jivesoftware.smackx.pep.packet.PEPEvent; +import org.jxmpp.jid.Jid; /** @@ -34,6 +35,6 @@ public interface PEPListener { * @param from the user that sent the entries. * @param event the event contained in the message. */ - public void eventReceived(String from, PEPEvent event); + public void eventReceived(Jid from, PEPEvent event); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPManager.java index 0be4e1b51..c6b1b9d71 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPManager.java @@ -31,6 +31,7 @@ import org.jivesoftware.smack.packet.IQ.Type; import org.jivesoftware.smackx.pep.packet.PEPEvent; import org.jivesoftware.smackx.pep.packet.PEPItem; import org.jivesoftware.smackx.pep.packet.PEPPubSub; +import org.jxmpp.jid.Jid; /** * @@ -122,7 +123,7 @@ public class PEPManager { /** * Fires roster exchange listeners. */ - private void firePEPListeners(String from, PEPEvent event) { + private void firePEPListeners(Jid from, PEPEvent event) { PEPListener[] listeners = null; synchronized (pepListeners) { listeners = new PEPListener[pepListeners.size()]; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java index a8c572827..608ab4775 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java @@ -45,6 +45,7 @@ import org.jivesoftware.smack.packet.IQ.Type; import org.jivesoftware.smack.util.SmackExecutorThreadFactory; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.ping.packet.Ping; +import org.jxmpp.jid.Jid; /** * Implements the XMPP Ping as defined by XEP-0199. The XMPP Ping protocol allows one entity to @@ -147,7 +148,7 @@ public class PingManager extends Manager { * to this, is a server ping, which will always return true if the server is reachable, * event if there is an error on the ping itself (i.e. ping not supported). *

      - * Use {@link #isPingSupported(String)} to determine if XMPP Ping is supported + * Use {@link #isPingSupported(Jid)} to determine if XMPP Ping is supported * by the entity. * * @param jid The id of the entity the ping is being sent to @@ -157,7 +158,7 @@ public class PingManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public boolean ping(String jid, long pingTimeout) throws NotConnectedException, NoResponseException, InterruptedException { + public boolean ping(Jid jid, long pingTimeout) throws NotConnectedException, NoResponseException, InterruptedException { final XMPPConnection connection = connection(); // Packet collector for IQs needs an connection that was at least authenticated once, // otherwise the client JID will be null causing an NPE @@ -175,7 +176,7 @@ public class PingManager extends Manager { } /** - * Same as calling {@link #ping(String, long)} with the defaultpacket reply + * Same as calling {@link #ping(Jid, long)} with the defaultpacket reply * timeout. * * @param jid The id of the entity the ping is being sent to @@ -184,7 +185,7 @@ public class PingManager extends Manager { * @throws NoResponseException if there was no response from the jid. * @throws InterruptedException */ - public boolean ping(String jid) throws NotConnectedException, NoResponseException, InterruptedException { + public boolean ping(Jid jid) throws NotConnectedException, NoResponseException, InterruptedException { return ping(jid, connection().getPacketReplyTimeout()); } @@ -198,7 +199,7 @@ public class PingManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public boolean isPingSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public boolean isPingSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Ping.NAMESPACE); } @@ -206,8 +207,8 @@ public class PingManager extends Manager { * Pings the server. This method will return true if the server is reachable. It * is the equivalent of calling ping with the XMPP domain. *

      - * Unlike the {@link #ping(String)} case, this method will return true even if - * {@link #isPingSupported(String)} is false. + * Unlike the {@link #ping(Jid)} case, this method will return true even if + * {@link #isPingSupported(Jid)} is false. * * @return true if a reply was received from the server, false otherwise. * @throws NotConnectedException @@ -221,8 +222,8 @@ public class PingManager extends Manager { * Pings the server. This method will return true if the server is reachable. It * is the equivalent of calling ping with the XMPP domain. *

      - * Unlike the {@link #ping(String)} case, this method will return true even if - * {@link #isPingSupported(String)} is false. + * Unlike the {@link #ping(Jid)} case, this method will return true even if + * {@link #isPingSupported(Jid)} is false. * * @param notifyListeners Notify the PingFailedListener in case of error if true * @return true if the user's server could be pinged. @@ -237,8 +238,8 @@ public class PingManager extends Manager { * Pings the server. This method will return true if the server is reachable. It * is the equivalent of calling ping with the XMPP domain. *

      - * Unlike the {@link #ping(String)} case, this method will return true even if - * {@link #isPingSupported(String)} is false. + * Unlike the {@link #ping(Jid)} case, this method will return true even if + * {@link #isPingSupported(Jid)} is false. * * @param notifyListeners Notify the PingFailedListener in case of error if true * @param pingTimeout The time to wait for a reply in milliseconds diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java index e36137f70..7025bbc85 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java @@ -1,6 +1,6 @@ /** * - * Copyright 2012 Florian Schmaus + * Copyright 2012-2015 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.jivesoftware.smackx.ping.packet; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.SimpleIQ; +import org.jxmpp.jid.Jid; public class Ping extends SimpleIQ { @@ -28,7 +29,7 @@ public class Ping extends SimpleIQ { super(ELEMENT, NAMESPACE); } - public Ping(String to) { + public Ping(Jid to) { this(); setTo(to); setType(IQ.Type.get); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/PrivacyItem.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/PrivacyItem.java index 02d138f93..93a38dee8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/PrivacyItem.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/PrivacyItem.java @@ -106,6 +106,24 @@ public class PrivacyItem { this.order = order; } + /** + * Creates a new privacy item. + * + * If the type is "jid", then the 'value' attribute MUST contain a valid Jabber ID. + * If the type is "group", then the 'value' attribute SHOULD contain the name of a group + * in the user's roster. + * If the type is "subscription", then the 'value' attribute MUST be one of "both", "to", + * "from", or "none". + * + * @param type the type. + * @param value the value of the privacy item + * @param allow true if this is an allow item + * @param order the order of this privacy item + */ + public PrivacyItem(Type type, CharSequence value, boolean allow, long order) { + this(type, value != null ? value.toString() : null, allow, order); + } + /** * Returns the action associated with the item, it MUST be filled and will allow or deny * the communication. diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java index 239fb84f6..ee393efd7 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java @@ -43,12 +43,13 @@ import org.jivesoftware.smackx.pubsub.util.NodeUtils; import org.jivesoftware.smackx.shim.packet.Header; import org.jivesoftware.smackx.shim.packet.HeadersExtension; import org.jivesoftware.smackx.xdata.Form; +import org.jxmpp.jid.Jid; abstract public class Node { protected XMPPConnection con; protected String id; - protected String to; + protected Jid to; protected ConcurrentHashMap, PacketListener> itemEventToListenerMap = new ConcurrentHashMap, PacketListener>(); protected ConcurrentHashMap itemDeleteToListenerMap = new ConcurrentHashMap(); @@ -73,7 +74,7 @@ abstract public class Node * * For example, OpenFire requires the server to be prefixed by pubsub */ - void setTo(String toAddress) + void setTo(Jid toAddress) { to = toAddress; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java index 9ba220a69..0f5064c2c 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java @@ -38,6 +38,10 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace; import org.jivesoftware.smackx.pubsub.util.NodeUtils; import org.jivesoftware.smackx.xdata.Form; import org.jivesoftware.smackx.xdata.FormField; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; /** * This is the starting point for access to the pubsub service. It @@ -51,7 +55,7 @@ import org.jivesoftware.smackx.xdata.FormField; final public class PubSubManager { private XMPPConnection con; - private String to; + private DomainBareJid to; private Map nodeMap = new ConcurrentHashMap(); /** @@ -59,11 +63,12 @@ final public class PubSubManager * name to pubsub * * @param connection The XMPP connection + * @throws XmppStringprepException */ - public PubSubManager(XMPPConnection connection) + public PubSubManager(XMPPConnection connection) throws XmppStringprepException { con = connection; - to = "pubsub." + connection.getServiceName(); + to = JidCreate.domainBareFrom("pubsub." + connection.getServiceName()); } /** @@ -73,7 +78,7 @@ final public class PubSubManager * @param connection The XMPP connection * @param toAddress The pubsub specific to address (required for some servers) */ - public PubSubManager(XMPPConnection connection, String toAddress) + public PubSubManager(XMPPConnection connection, DomainBareJid toAddress) { con = connection; to = toAddress; @@ -314,7 +319,7 @@ final public class PubSubManager return sendPubsubPacket(con, to, type, Collections.singletonList(ext), ns); } - static PubSub sendPubsubPacket(XMPPConnection con, String to, Type type, List extList, PubSubNamespace ns) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + static PubSub sendPubsubPacket(XMPPConnection con, Jid to, Type type, List extList, PubSubNamespace ns) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub pubSub = new PubSub(to, type, ns); for (PacketExtension pe : extList) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java index ed979cc82..0636abc95 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java @@ -19,6 +19,7 @@ package org.jivesoftware.smackx.pubsub.packet; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smackx.pubsub.PubSubElementType; +import org.jxmpp.jid.Jid; /** * The standard PubSub extension of an {@link IQ} packet. This is the topmost @@ -40,7 +41,7 @@ public class PubSub extends IQ super(ELEMENT, ns.getXmlns()); } - public PubSub(String to, Type type, PubSubNamespace ns) { + public PubSub(Jid to, Type type, PubSubNamespace ns) { super(ELEMENT, (ns == null ? PubSubNamespace.BASIC : ns).getXmlns()); setTo(to); setType(type); @@ -86,7 +87,7 @@ public class PubSub extends IQ return xml; } - public static PubSub createPubsubPacket(String to, Type type, PacketExtension extension, PubSubNamespace ns) { + public static PubSub createPubsubPacket(Jid to, Type type, PacketExtension extension, PubSubNamespace ns) { PubSub pubSub = new PubSub(to, type, ns); pubSub.addExtension(extension); return pubSub; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java index bed43508c..9f51ae2a6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java @@ -38,6 +38,7 @@ import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.roster.Roster; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; +import org.jxmpp.jid.Jid; /** * Manager for XEP-0184: Message Delivery Receipts. This class implements @@ -142,7 +143,7 @@ public class DeliveryReceiptManager extends Manager { connection.addAsyncPacketListener(new PacketListener() { @Override public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException { - final String from = packet.getFrom(); + final Jid from = packet.getFrom(); final XMPPConnection connection = connection(); switch (autoReceiptMode) { case disabled: @@ -190,7 +191,7 @@ public class DeliveryReceiptManager extends Manager { * @throws XMPPException * @throws InterruptedException */ - public boolean isSupported(String jid) throws SmackException, XMPPException, InterruptedException { + public boolean isSupported(Jid jid) throws SmackException, XMPPException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, DeliveryReceipt.NAMESPACE); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java index 774820ea7..5f6c849cb 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java @@ -17,6 +17,7 @@ package org.jivesoftware.smackx.receipts; import org.jivesoftware.smack.packet.Stanza; +import org.jxmpp.jid.Jid; /** * Interface for received receipt notifications. @@ -36,5 +37,5 @@ public interface ReceiptReceivedListener { * @param receiptId the message ID of the packet which has been received and this receipt is for * @param receipt the receipt */ - void onReceiptReceived(String fromJid, String toJid, String receiptId, Stanza receipt); + void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java index f0aa55664..936c10590 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java @@ -30,6 +30,7 @@ import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smackx.xdata.Form; import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.packet.DataForm; +import org.jxmpp.jid.DomainBareJid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -66,7 +67,7 @@ public class UserSearch extends SimpleIQ { * @throws NotConnectedException * @throws InterruptedException */ - public Form getSearchForm(XMPPConnection con, String searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public Form getSearchForm(XMPPConnection con, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { UserSearch search = new UserSearch(); search.setType(IQ.Type.get); search.setTo(searchService); @@ -87,7 +88,7 @@ public class UserSearch extends SimpleIQ { * @throws NotConnectedException * @throws InterruptedException */ - public ReportedData sendSearchForm(XMPPConnection con, Form searchForm, String searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public ReportedData sendSearchForm(XMPPConnection con, Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { UserSearch search = new UserSearch(); search.setType(IQ.Type.set); search.setTo(searchService); @@ -109,7 +110,7 @@ public class UserSearch extends SimpleIQ { * @throws NotConnectedException * @throws InterruptedException */ - public ReportedData sendSimpleSearchForm(XMPPConnection con, Form searchForm, String searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public ReportedData sendSimpleSearchForm(XMPPConnection con, Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { SimpleUserSearch search = new SimpleUserSearch(); search.setForm(searchForm); search.setType(IQ.Type.set); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearchManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearchManager.java index 3d2944fb8..b9b2bff8d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearchManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearchManager.java @@ -22,6 +22,7 @@ import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.xdata.Form; +import org.jxmpp.jid.DomainBareJid; import java.util.List; @@ -68,7 +69,7 @@ public class UserSearchManager { * @throws NotConnectedException * @throws InterruptedException */ - public Form getSearchForm(String searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public Form getSearchForm(DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return userSearch.getSearchForm(con, searchService); } @@ -84,7 +85,7 @@ public class UserSearchManager { * @throws NotConnectedException * @throws InterruptedException */ - public ReportedData getSearchResults(Form searchForm, String searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public ReportedData getSearchResults(Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return userSearch.sendSearchForm(con, searchForm, searchService); } @@ -98,7 +99,7 @@ public class UserSearchManager { * @throws NotConnectedException * @throws InterruptedException */ - public List getSearchServices() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public List getSearchServices() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con); return discoManager.findServices(UserSearch.NAMESPACE, false, false); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java index 03ee6e078..ad96e2742 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java @@ -34,6 +34,7 @@ import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError.Condition; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.time.packet.Time; +import org.jxmpp.jid.Jid; public class EntityTimeManager extends Manager { @@ -99,11 +100,11 @@ public class EntityTimeManager extends Manager { enabled = false; } - public boolean isTimeSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public boolean isTimeSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Time.NAMESPACE); } - public Time getTime(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public Time getTime(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { if (!isTimeSupported(jid)) return null; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java index 23f99e33e..34c5ecbd6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java @@ -29,6 +29,8 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.vcardtemp.packet.VCard; +import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.Jid; public class VCardManager extends Manager { public static final String NAMESPACE = VCard.NAMESPACE; @@ -71,10 +73,10 @@ public class VCardManager extends Manager { * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException - * @deprecated use {@link #isSupported(String)} instead. + * @deprecated use {@link #isSupported(Jid)} instead. */ @Deprecated - public static boolean isSupported(String jid, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public static boolean isSupported(Jid jid, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return VCardManager.getInstanceFor(connection).isSupported(jid); } @@ -117,7 +119,7 @@ public class VCardManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public VCard loadVCard(String bareJid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public VCard loadVCard(BareJid bareJid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { VCard vcardRequest = new VCard(); vcardRequest.setTo(bareJid); VCard result = connection().createPacketCollectorAndSend(vcardRequest).nextResultOrThrow(); @@ -134,7 +136,7 @@ public class VCardManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public boolean isSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public boolean isSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, NAMESPACE); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java index 08db8e932..1bc712450 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java @@ -40,6 +40,7 @@ import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.stringencoder.Base64; import org.jivesoftware.smackx.vcardtemp.VCardManager; +import org.jxmpp.jid.BareJid; /** * A VCard class for use with the @@ -551,10 +552,10 @@ public class VCard extends IQ { * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException * @throws InterruptedException - * @deprecated use {@link VCardManager#loadVCard(String)} instead. + * @deprecated use {@link VCardManager#loadVCard(BareJid)} instead. */ @Deprecated - public void load(XMPPConnection connection, String user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public void load(XMPPConnection connection, BareJid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { VCard result = VCardManager.getInstanceFor(connection).loadVCard(user); copyFieldsFrom(result); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/XDataManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/XDataManager.java index 194b12a2d..ebd948d99 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/XDataManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/XDataManager.java @@ -28,6 +28,7 @@ import org.jivesoftware.smack.XMPPConnectionRegistry; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.xdata.packet.DataForm; +import org.jxmpp.jid.Jid; public class XDataManager extends Manager { @@ -80,7 +81,7 @@ public class XDataManager extends Manager { * @see XEP-0004: Data Forms § 6. Service Discovery * @since 4.1 */ - public boolean isSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public boolean isSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, NAMESPACE); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java index f0ac83b0c..10c96c936 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java @@ -26,6 +26,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension; +import org.jxmpp.jid.Jid; import java.util.List; @@ -130,7 +131,7 @@ public class XHTMLManager { * @throws NotConnectedException * @throws InterruptedException */ - public static boolean isServiceEnabled(XMPPConnection connection, String userID) + public static boolean isServiceEnabled(XMPPConnection connection, Jid userID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(userID, XHTMLExtension.NAMESPACE); } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/CloseListenerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/CloseListenerTest.java index 0430124bf..22c2d5a00 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/CloseListenerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/CloseListenerTest.java @@ -25,6 +25,8 @@ import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smackx.bytestreams.ibb.packet.Close; import org.junit.Test; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.JidTestUtil; import org.mockito.ArgumentCaptor; import org.powermock.reflect.Whitebox; @@ -35,8 +37,8 @@ import org.powermock.reflect.Whitebox; */ public class CloseListenerTest { - String initiatorJID = "initiator@xmpp-server/Smack"; - String targetJID = "target@xmpp-server/Smack"; + static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1; /** * If a close request to an unknown session is received it should be replied diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/DataListenerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/DataListenerTest.java index 29da9edd2..79f8fa6a7 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/DataListenerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/DataListenerTest.java @@ -26,6 +26,8 @@ import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension; import org.junit.Test; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.JidTestUtil; import org.mockito.ArgumentCaptor; import org.powermock.reflect.Whitebox; @@ -36,8 +38,8 @@ import org.powermock.reflect.Whitebox; */ public class DataListenerTest { - String initiatorJID = "initiator@xmpp-server/Smack"; - String targetJID = "target@xmpp-server/Smack"; + static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1; /** * If a data packet of an unknown session is received it should be replied diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java index 92dadc2d8..0618cdde1 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java @@ -20,6 +20,7 @@ import org.jivesoftware.smack.packet.EmptyResultIQ; import org.jivesoftware.smack.packet.ErrorIQ; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.XMPPError; +import org.jxmpp.jid.Jid; /** * Utility methods to create packets. @@ -36,7 +37,7 @@ public class IBBPacketUtils { * @param xmppError the XMPP error * @return an error IQ */ - public static IQ createErrorIQ(String from, String to, XMPPError xmppError) { + public static IQ createErrorIQ(Jid from, Jid to, XMPPError xmppError) { IQ errorIQ = new ErrorIQ(xmppError); errorIQ.setType(IQ.Type.error); errorIQ.setFrom(from); @@ -51,7 +52,7 @@ public class IBBPacketUtils { * @param to the recipients JID * @return a result IQ */ - public static IQ createResultIQ(String from, String to) { + public static IQ createResultIQ(Jid from, Jid to) { IQ result = new EmptyResultIQ(); result.setType(IQ.Type.result); result.setFrom(from); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java index 902e82b19..f37cd3304 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java @@ -35,6 +35,9 @@ import org.jivesoftware.util.Protocol; import org.jivesoftware.util.Verification; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.JidTestUtil; /** * Test for InBandBytestreamManager. @@ -44,9 +47,9 @@ import org.junit.Test; public class InBandBytestreamManagerTest { // settings - String initiatorJID = "initiator@xmpp-server/Smack"; - String targetJID = "target@xmpp-server/Smack"; - String xmppServer = "xmpp-server"; + static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1; + static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1; String sessionID = "session_id"; // protocol verifier @@ -99,7 +102,7 @@ public class InBandBytestreamManagerTest { } /** - * Invoking {@link InBandBytestreamManager#establishSession(String)} should + * Invoking {@link InBandBytestreamManager#establishSession(org.jxmpp.jid.Jid)} should * throw an exception if the given target does not support in-band * bytestream. * @throws SmackException diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java index b04ed0cf3..dae6c52cd 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java @@ -28,6 +28,8 @@ import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smackx.bytestreams.ibb.packet.Open; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.JidTestUtil; import org.mockito.ArgumentCaptor; /** @@ -37,8 +39,8 @@ import org.mockito.ArgumentCaptor; */ public class InBandBytestreamRequestTest { - String initiatorJID = "initiator@xmpp-server/Smack"; - String targetJID = "target@xmpp-server/Smack"; + static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1; String sessionID = "session_id"; XMPPConnection connection; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java index 347a5087a..5179fece0 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java @@ -40,6 +40,9 @@ import org.jivesoftware.util.Protocol; import org.jivesoftware.util.Verification; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.JidTestUtil; import org.powermock.reflect.Whitebox; /** @@ -52,9 +55,9 @@ import org.powermock.reflect.Whitebox; public class InBandBytestreamSessionMessageTest { // settings - String initiatorJID = "initiator@xmpp-server/Smack"; - String targetJID = "target@xmpp-server/Smack"; - String xmppServer = "xmpp-server"; + static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1; + static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1; String sessionID = "session_id"; int blockSize = 10; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java index 2b066b3f4..f1aa83966 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java @@ -40,6 +40,9 @@ import org.jivesoftware.util.Protocol; import org.jivesoftware.util.Verification; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.JidTestUtil; import org.powermock.reflect.Whitebox; /** @@ -53,9 +56,9 @@ import org.powermock.reflect.Whitebox; public class InBandBytestreamSessionTest { // settings - String initiatorJID = "initiator@xmpp-server/Smack"; - String targetJID = "target@xmpp-server/Smack"; - String xmppServer = "xmpp-server"; + static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1; + static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1; String sessionID = "session_id"; int blockSize = 10; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InitiationListenerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InitiationListenerTest.java index 5f57d089b..f6290689e 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InitiationListenerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InitiationListenerTest.java @@ -28,6 +28,9 @@ import org.jivesoftware.smackx.bytestreams.BytestreamRequest; import org.jivesoftware.smackx.bytestreams.ibb.packet.Open; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.JidTestUtil; +import org.jxmpp.jid.impl.JidCreate; import org.mockito.ArgumentCaptor; import org.powermock.reflect.Whitebox; @@ -38,8 +41,8 @@ import org.powermock.reflect.Whitebox; */ public class InitiationListenerTest { - String initiatorJID = "initiator@xmpp-server/Smack"; - String targetJID = "target@xmpp-server/Smack"; + static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1; String sessionID = "session_id"; XMPPConnection connection; @@ -190,7 +193,7 @@ public class InitiationListenerTest { // add listener for request of user "other_initiator" InBandBytestreamListener listener = mock(InBandBytestreamListener.class); - byteStreamManager.addIncomingBytestreamListener(listener, "other_" + initiatorJID); + byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID)); // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); @@ -261,8 +264,8 @@ public class InitiationListenerTest { // add listener for request of user "other_initiator" InBandBytestreamListener userRequestsListener = mock(InBandBytestreamListener.class); - byteStreamManager.addIncomingBytestreamListener(userRequestsListener, "other_" - + initiatorJID); + byteStreamManager.addIncomingBytestreamListener(userRequestsListener, JidCreate.from("other_" + + initiatorJID)); // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/CloseTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/CloseTest.java index 2e02b216c..0103d250f 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/CloseTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/CloseTest.java @@ -17,13 +17,13 @@ package org.jivesoftware.smackx.bytestreams.ibb.packet; import static org.junit.Assert.assertEquals; - import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; import java.util.Properties; import org.jivesoftware.smack.packet.IQ; import org.junit.Test; +import org.jxmpp.jid.impl.JidCreate; import com.jamesmurty.utils.XMLBuilder; @@ -74,8 +74,8 @@ public class CloseTest { .asString(outputProperties); Close close = new Close("i781hf64"); - close.setFrom("romeo@montague.lit/orchard"); - close.setTo("juliet@capulet.lit/balcony"); + close.setFrom(JidCreate.from("romeo@montague.lit/orchard")); + close.setTo(JidCreate.from("juliet@capulet.lit/balcony")); close.setStanzaId("us71g45j"); assertXMLEqual(control, close.toXML().toString()); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataTest.java index 96b7d9452..c8c2a9371 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataTest.java @@ -25,6 +25,7 @@ import java.util.Properties; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.util.stringencoder.Base64; import org.junit.Test; +import org.jxmpp.jid.impl.JidCreate; import com.jamesmurty.utils.XMLBuilder; @@ -70,8 +71,8 @@ public class DataTest { DataPacketExtension dpe = new DataPacketExtension("i781hf64", 0, encodedData); Data data = new Data(dpe); - data.setFrom("romeo@montague.lit/orchard"); - data.setTo("juliet@capulet.lit/balcony"); + data.setFrom(JidCreate.from("romeo@montague.lit/orchard")); + data.setTo(JidCreate.from("juliet@capulet.lit/balcony")); data.setStanzaId("kr91n475"); assertXMLEqual(control, data.toXML().toString()); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/OpenTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/OpenTest.java index 469d7a732..459e1fd2a 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/OpenTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/OpenTest.java @@ -24,6 +24,7 @@ import java.util.Properties; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType; import org.junit.Test; +import org.jxmpp.jid.impl.JidCreate; import com.jamesmurty.utils.XMLBuilder; @@ -95,8 +96,8 @@ public class OpenTest { .asString(outputProperties); Open open = new Open("i781hf64", 4096, StanzaType.IQ); - open.setFrom("romeo@montague.lit/orchard"); - open.setTo("juliet@capulet.lit/balcony"); + open.setFrom(JidCreate.from("romeo@montague.lit/orchard")); + open.setTo(JidCreate.from("juliet@capulet.lit/balcony")); open.setStanzaId("jn3h8g65"); assertXMLEqual(control, open.toXML().toString()); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/InitiationListenerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/InitiationListenerTest.java index 9475fe287..f6172f6b2 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/InitiationListenerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/InitiationListenerTest.java @@ -29,6 +29,10 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.JidTestUtil; +import org.jxmpp.jid.impl.JidCreate; import org.mockito.ArgumentCaptor; import org.powermock.reflect.Whitebox; @@ -39,10 +43,10 @@ import org.powermock.reflect.Whitebox; */ public class InitiationListenerTest { - String initiatorJID = "initiator@xmpp-server/Smack"; - String targetJID = "target@xmpp-server/Smack"; - String xmppServer = "xmpp-server"; - String proxyJID = "proxy.xmpp-server"; + static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1; + static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1; + static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG; String proxyAddress = "127.0.0.1"; String sessionID = "session_id"; @@ -169,7 +173,7 @@ public class InitiationListenerTest { // add listener for request of user "other_initiator" Socks5BytestreamListener listener = mock(Socks5BytestreamListener.class); - byteStreamManager.addIncomingBytestreamListener(listener, "other_" + initiatorJID); + byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID)); // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); @@ -240,8 +244,8 @@ public class InitiationListenerTest { // add listener for request of user "other_initiator" Socks5BytestreamListener userRequestsListener = mock(Socks5BytestreamListener.class); - byteStreamManager.addIncomingBytestreamListener(userRequestsListener, "other_" - + initiatorJID); + byteStreamManager.addIncomingBytestreamListener(userRequestsListener, JidCreate.from("other_" + + initiatorJID)); // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java index dc32b8587..ecad7c6b6 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java @@ -50,6 +50,11 @@ import org.jivesoftware.util.Verification; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.JidTestUtil; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; /** * Test for Socks5BytestreamManager. @@ -59,10 +64,10 @@ import org.junit.Test; public class Socks5ByteStreamManagerTest { // settings - String initiatorJID = "initiator@xmpp-server/Smack"; - String targetJID = "target@xmpp-server/Smack"; - String xmppServer = "xmpp-server"; - String proxyJID = "proxy.xmpp-server"; + static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1; + static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1; + static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG; String proxyAddress = "127.0.0.1"; String sessionID = "session_id"; @@ -137,7 +142,7 @@ public class Socks5ByteStreamManagerTest { } /** - * Invoking {@link Socks5BytestreamManager#establishSession(String)} should throw an exception + * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid)} should throw an exception * if the given target does not support SOCKS5 Bytestream. * @throws XMPPException */ @@ -165,7 +170,7 @@ public class Socks5ByteStreamManagerTest { } /** - * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if XMPP + * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if XMPP * server doesn't return any proxies. */ @Test @@ -216,7 +221,7 @@ public class Socks5ByteStreamManagerTest { } /** - * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if no + * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no * proxy is a SOCKS5 proxy. */ @Test @@ -254,7 +259,7 @@ public class Socks5ByteStreamManagerTest { // build discover info for proxy containing information about NOT being a Socks5 // proxy DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID); - Identity identity = new Identity("noproxy", proxyJID, "bytestreams"); + Identity identity = new Identity("noproxy", proxyJID.toString(), "bytestreams"); proxyInfo.addIdentity(identity); // return the proxy identity if proxy is queried @@ -279,7 +284,7 @@ public class Socks5ByteStreamManagerTest { } /** - * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if no + * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no * SOCKS5 proxy can be found. If it turns out that a proxy is not a SOCKS5 proxy it should not * be queried again. */ @@ -318,7 +323,7 @@ public class Socks5ByteStreamManagerTest { // build discover info for proxy containing information about NOT being a Socks5 // proxy DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID); - Identity identity = new Identity("noproxy", proxyJID, "bytestreams"); + Identity identity = new Identity("noproxy", proxyJID.toString(), "bytestreams"); proxyInfo.addIdentity(identity); // return the proxy identity if proxy is queried @@ -370,7 +375,7 @@ public class Socks5ByteStreamManagerTest { } /** - * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if the + * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the * target does not accept a SOCKS5 Bytestream. See XEP-0065 Section 5.2 A2 */ @@ -408,7 +413,7 @@ public class Socks5ByteStreamManagerTest { // build discover info for proxy containing information about being a SOCKS5 proxy DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID); - Identity identity = new Identity("proxy", proxyJID, "bytestreams"); + Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams"); proxyInfo.addIdentity(identity); // return the socks5 bytestream proxy identity if proxy is queried @@ -454,11 +459,12 @@ public class Socks5ByteStreamManagerTest { } /** - * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if the + * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the * proxy used by target is invalid. + * @throws XmppStringprepException */ @Test - public void shouldFailIfTargetUsesInvalidSocks5Proxy() { + public void shouldFailIfTargetUsesInvalidSocks5Proxy() throws XmppStringprepException { // disable clients local SOCKS5 proxy Socks5Proxy.setLocalSocks5ProxyEnabled(false); @@ -491,7 +497,7 @@ public class Socks5ByteStreamManagerTest { // build discover info for proxy containing information about being a SOCKS5 proxy DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID); - Identity identity = new Identity("proxy", proxyJID, "bytestreams"); + Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams"); proxyInfo.addIdentity(identity); // return the socks5 bytestream proxy identity if proxy is queried @@ -512,7 +518,7 @@ public class Socks5ByteStreamManagerTest { Bytestream streamHostUsedPacket = Socks5PacketUtils.createBytestreamResponse(targetJID, initiatorJID); streamHostUsedPacket.setSessionID(sessionID); - streamHostUsedPacket.setUsedHost("invalid.proxy"); + streamHostUsedPacket.setUsedHost(JidCreate.from("invalid.proxy")); // return used stream host info as response to the bytestream initiation protocol.addResponse(streamHostUsedPacket, Verification.correspondingSenderReceiver, @@ -536,7 +542,7 @@ public class Socks5ByteStreamManagerTest { } /** - * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if + * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if * initiator can not connect to the SOCKS5 proxy used by target. */ @Test @@ -573,7 +579,7 @@ public class Socks5ByteStreamManagerTest { // build discover info for proxy containing information about being a SOCKS5 proxy DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID); - Identity identity = new Identity("proxy", proxyJID, "bytestreams"); + Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams"); proxyInfo.addIdentity(identity); // return the socks5 bytestream proxy identity if proxy is queried @@ -628,7 +634,7 @@ public class Socks5ByteStreamManagerTest { } /** - * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should successfully + * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should successfully * negotiate and return a SOCKS5 Bytestream connection. * * @throws Exception should not happen @@ -667,7 +673,7 @@ public class Socks5ByteStreamManagerTest { // build discover info for proxy containing information about being a SOCKS5 proxy DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID); - Identity identity = new Identity("proxy", proxyJID, "bytestreams"); + Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams"); proxyInfo.addIdentity(identity); // return the socks5 bytestream proxy identity if proxy is queried @@ -838,7 +844,7 @@ public class Socks5ByteStreamManagerTest { } /** - * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} the first time + * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} the first time * should successfully negotiate a SOCKS5 Bytestream via the second SOCKS5 proxy and should * prioritize this proxy for a second SOCKS5 Bytestream negotiation. * @@ -921,7 +927,7 @@ public class Socks5ByteStreamManagerTest { } /** - * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} the first time + * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} the first time * should successfully negotiate a SOCKS5 Bytestream via the second SOCKS5 proxy. The second * negotiation should run in the same manner if prioritization is disabled. * @@ -995,7 +1001,7 @@ public class Socks5ByteStreamManagerTest { } - private void createResponses(Verification streamHostUsedVerification) { + private void createResponses(Verification streamHostUsedVerification) throws XmppStringprepException { // build discover info that supports the SOCKS5 feature DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID); discoverInfo.addFeature(Bytestream.NAMESPACE); @@ -1007,7 +1013,7 @@ public class Socks5ByteStreamManagerTest { // build discover items containing a proxy item DiscoverItems discoverItems = Socks5PacketUtils.createDiscoverItems(xmppServer, initiatorJID); - discoverItems.addItem(new Item("proxy2.xmpp-server")); + discoverItems.addItem(new Item(JidCreate.from("proxy2.xmpp-server"))); discoverItems.addItem(new Item(proxyJID)); // return the proxy item if XMPP server is queried @@ -1018,7 +1024,7 @@ public class Socks5ByteStreamManagerTest { * build discover info for proxy "proxy2.xmpp-server" containing information about being a * SOCKS5 proxy */ - DiscoverInfo proxyInfo1 = Socks5PacketUtils.createDiscoverInfo("proxy2.xmpp-server", + DiscoverInfo proxyInfo1 = Socks5PacketUtils.createDiscoverInfo(JidCreate.from("proxy2.xmpp-server"), initiatorJID); Identity identity1 = new Identity("proxy", "proxy2.xmpp-server", "bytestreams"); proxyInfo1.addIdentity(identity1); @@ -1029,7 +1035,7 @@ public class Socks5ByteStreamManagerTest { // build discover info for proxy containing information about being a SOCKS5 proxy DiscoverInfo proxyInfo2 = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID); - Identity identity2 = new Identity("proxy", proxyJID, "bytestreams"); + Identity identity2 = new Identity("proxy", proxyJID.toString(), "bytestreams"); proxyInfo2.addIdentity(identity2); // return the SOCKS5 bytestream proxy identity if proxy is queried @@ -1041,8 +1047,8 @@ public class Socks5ByteStreamManagerTest { * port of the proxy */ Bytestream streamHostInfo1 = Socks5PacketUtils.createBytestreamResponse( - "proxy2.xmpp-server", initiatorJID); - streamHostInfo1.addStreamHost("proxy2.xmpp-server", proxyAddress, 7778); + JidCreate.from("proxy2.xmpp-server"), initiatorJID); + streamHostInfo1.addStreamHost(JidCreate.from("proxy2.xmpp-server"), proxyAddress, 7778); // return stream host info if it is queried protocol.addResponse(streamHostInfo1, Verification.correspondingSenderReceiver, diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java index 266f229f3..16dcb57fd 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java @@ -40,6 +40,10 @@ import org.jivesoftware.util.Protocol; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.JidTestUtil; +import org.jxmpp.jid.impl.JidCreate; /** * Tests for the Socks5BytestreamRequest class. @@ -49,10 +53,10 @@ import org.junit.Test; public class Socks5ByteStreamRequestTest { // settings - String initiatorJID = "initiator@xmpp-server/Smack"; - String targetJID = "target@xmpp-server/Smack"; - String xmppServer = "xmpp-server"; - String proxyJID = "proxy.xmpp-server"; + static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1; + static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1; + static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG; String proxyAddress = "127.0.0.1"; String sessionID = "session_id"; @@ -174,7 +178,7 @@ public class Socks5ByteStreamRequestTest { // build SOCKS5 Bytestream initialization request Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation( initiatorJID, targetJID, sessionID); - bytestreamInitialization.addStreamHost("invalid." + proxyJID, "127.0.0.2", 7778); + bytestreamInitialization.addStreamHost(JidCreate.from("invalid." + proxyJID), "127.0.0.2", 7778); // get SOCKS5 Bytestream manager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); @@ -266,7 +270,7 @@ public class Socks5ByteStreamRequestTest { // build SOCKS5 Bytestream initialization request Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation( initiatorJID, targetJID, sessionID); - bytestreamInitialization.addStreamHost("invalid." + proxyJID, "127.0.0.2", 7778); + bytestreamInitialization.addStreamHost(JidCreate.from("invalid." + proxyJID), "127.0.0.2", 7778); // get SOCKS5 Bytestream manager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java index 1a19e6d18..79ec5976b 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java @@ -42,6 +42,9 @@ import org.jivesoftware.util.Verification; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.JidTestUtil; /** * Test for Socks5ClientForInitiator class. @@ -51,10 +54,10 @@ import org.junit.Test; public class Socks5ClientForInitiatorTest { // settings - String initiatorJID = "initiator@xmpp-server/Smack"; - String targetJID = "target@xmpp-server/Smack"; - String xmppServer = "xmpp-server"; - String proxyJID = "proxy.xmpp-server"; + static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1; + static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1; + static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG; String proxyAddress = "127.0.0.1"; int proxyPort = 7890; String sessionID = "session_id"; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java index 34800a10c..8e74614be 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java @@ -32,6 +32,8 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.JidTestUtil; /** * Test for Socks5Client class. @@ -43,7 +45,7 @@ public class Socks5ClientTest { // settings private String serverAddress = "127.0.0.1"; private int serverPort = 7890; - private String proxyJID = "proxy.xmpp-server"; + private DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG; private String digest = "digest"; private ServerSocket serverSocket; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java index fac8cab5d..b16c6cf20 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java @@ -21,6 +21,7 @@ import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream; import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverItems; +import org.jxmpp.jid.Jid; /** * A collection of utility methods to create XMPP packets. @@ -38,7 +39,7 @@ public class Socks5PacketUtils { * @param sessionID the session ID * @return SOCKS5 Bytestream initialization request packet */ - public static Bytestream createBytestreamInitiation(String from, String to, String sessionID) { + public static Bytestream createBytestreamInitiation(Jid from, Jid to, String sessionID) { Bytestream bytestream = new Bytestream(); bytestream.setFrom(from); bytestream.setTo(to); @@ -55,7 +56,7 @@ public class Socks5PacketUtils { * @param to the initiator * @return response to a SOCKS5 Bytestream initialization request */ - public static Bytestream createBytestreamResponse(String from, String to) { + public static Bytestream createBytestreamResponse(Jid from, Jid to) { Bytestream streamHostInfo = new Bytestream(); streamHostInfo.setFrom(from); streamHostInfo.setTo(to); @@ -70,7 +71,7 @@ public class Socks5PacketUtils { * @param to the XMPP client * @return response to an item discovery request */ - public static DiscoverItems createDiscoverItems(String from, String to) { + public static DiscoverItems createDiscoverItems(Jid from, Jid to) { DiscoverItems discoverItems = new DiscoverItems(); discoverItems.setFrom(from); discoverItems.setTo(to); @@ -85,7 +86,7 @@ public class Socks5PacketUtils { * @param to the initiator * @return response to an info discovery request */ - public static DiscoverInfo createDiscoverInfo(String from, String to) { + public static DiscoverInfo createDiscoverInfo(Jid from, Jid to) { DiscoverInfo discoverInfo = new DiscoverInfo(); discoverInfo.setFrom(from); discoverInfo.setTo(to); @@ -100,7 +101,7 @@ public class Socks5PacketUtils { * @param to JID of the client who wants to activate the SOCKS5 Bytestream * @return response IQ for a activation request to the proxy */ - public static IQ createActivationConfirmation(String from, String to) { + public static IQ createActivationConfirmation(Jid from, Jid to) { IQ response = new EmptyResultIQ(); response.setFrom(from); response.setTo(to); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/caps/EntityCapsManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/caps/EntityCapsManagerTest.java index 0ce256dc1..b60956da6 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/caps/EntityCapsManagerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/caps/EntityCapsManagerTest.java @@ -38,6 +38,8 @@ import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.packet.DataForm; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; public class EntityCapsManagerTest extends InitExtensions { @@ -50,9 +52,10 @@ public class EntityCapsManagerTest extends InitExtensions { /** * XEP- * 0115 Complex Generation Example + * @throws XmppStringprepException */ @Test - public void testComplexGenerationExample() { + public void testComplexGenerationExample() throws XmppStringprepException { DiscoverInfo di = createComplexSamplePacket(); CapsVersionAndHash versionAndHash = EntityCapsManager.generateVerificationString(di, StringUtils.SHA1); @@ -66,13 +69,13 @@ public class EntityCapsManagerTest extends InitExtensions { } @Test - public void testVerificationDuplicateFeatures() { + public void testVerificationDuplicateFeatures() throws XmppStringprepException { DiscoverInfo di = createMalformedDiscoverInfo(); assertTrue(di.containsDuplicateFeatures()); } @Test - public void testVerificationDuplicateIdentities() { + public void testVerificationDuplicateIdentities() throws XmppStringprepException { DiscoverInfo di = createMalformedDiscoverInfo(); assertTrue(di.containsDuplicateIdentities()); } @@ -97,11 +100,11 @@ public class EntityCapsManagerTest extends InitExtensions { assertEquals(di.toXML().toString(), restored_di.toXML().toString()); } - private static DiscoverInfo createComplexSamplePacket() { + private static DiscoverInfo createComplexSamplePacket() throws XmppStringprepException { DiscoverInfo di = new DiscoverInfo(); - di.setFrom("benvolio@capulet.lit/230193"); + di.setFrom(JidCreate.from("benvolio@capulet.lit/230193")); di.setStanzaId("disco1"); - di.setTo("juliet@capulet.lit/chamber"); + di.setTo(JidCreate.from("juliet@capulet.lit/chamber")); di.setType(IQ.Type.result); Collection identities = new LinkedList(); @@ -148,11 +151,11 @@ public class EntityCapsManagerTest extends InitExtensions { return di; } - private static DiscoverInfo createMalformedDiscoverInfo() { + private static DiscoverInfo createMalformedDiscoverInfo() throws XmppStringprepException { DiscoverInfo di = new DiscoverInfo(); - di.setFrom("benvolio@capulet.lit/230193"); + di.setFrom(JidCreate.from("benvolio@capulet.lit/230193")); di.setStanzaId("disco1"); - di.setTo(")juliet@capulet.lit/chamber"); + di.setTo(JidCreate.from(")juliet@capulet.lit/chamber")); di.setType(IQ.Type.result); Collection identities = new LinkedList(); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java index e7d9f46c0..d8a49487f 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java @@ -25,6 +25,7 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.JidTestUtil; public class FileTransferNegotiatorTest { private DummyConnection connection; @@ -50,7 +51,7 @@ public class FileTransferNegotiatorTest { public void verifyForm() throws Exception { FileTransferNegotiator fileNeg = FileTransferNegotiator.getInstanceFor(connection); try { - fileNeg.negotiateOutgoingTransfer("me", "streamid", "file", 1024, null, 10); + fileNeg.negotiateOutgoingTransfer(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, "streamid", "file", 1024, null, 10); } catch (NoResponseException e) { // Ignore } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java index 30ea25fa3..70e05054d 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java @@ -16,8 +16,10 @@ */ package org.jivesoftware.smackx.forward; +import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import java.util.Properties; @@ -56,7 +58,7 @@ public class ForwardedTest { assertEquals(null, fwd.getDelayInformation()); // check message - assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom()); + assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedPacket().getFrom())); // check end of tag assertEquals(XmlPullParser.END_TAG, parser.getEventType()); @@ -84,7 +86,7 @@ public class ForwardedTest { assertNotNull(delay); // check message - assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom()); + assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedPacket().getFrom())); // check end of tag assertEquals(XmlPullParser.END_TAG, parser.getEventType()); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java index d8bb596e4..2855994ee 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java @@ -16,7 +16,9 @@ */ package org.jivesoftware.smackx.iqversion; +import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import org.jivesoftware.smack.DummyConnection; @@ -52,7 +54,7 @@ public class VersionTest { Version reply = (Version) replyPacket; //getFrom check is pending for SMACK-547 //assertEquals("juliet@capulet.lit/balcony", reply.getFrom()); - assertEquals("capulet.lit", reply.getTo()); + assertThat("capulet.lit", equalsCharSequence(reply.getTo())); assertEquals("s2c1", reply.getStanzaId()); assertEquals(IQ.Type.result, reply.getType()); assertEquals("Test", reply.getName()); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java index 3ebab7b09..887d3fa85 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java @@ -16,10 +16,13 @@ */ package org.jivesoftware.smackx.ping; +import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.jxmpp.jid.JidTestUtil.DUMMY_AT_EXAMPLE_ORG; import java.io.IOException; @@ -66,7 +69,7 @@ public class PingTest extends InitExtensions { assertTrue(pongPacket instanceof IQ); IQ pong = (IQ) pongPacket; - assertEquals("capulet.lit", pong.getTo()); + assertThat("capulet.lit", equalsCharSequence(pong.getTo())); assertEquals("s2c1", pong.getStanzaId()); assertEquals(IQ.Type.result, pong.getType()); } @@ -76,7 +79,7 @@ public class PingTest extends InitExtensions { DummyConnection dummyCon = getAuthentiactedDummyConnection(); PingManager pinger = PingManager.getInstanceFor(dummyCon); try { - pinger.ping("test@myserver.com"); + pinger.ping(DUMMY_AT_EXAMPLE_ORG); } catch (SmackException e) { // Ignore the fact the server won't answer for this unit test. @@ -92,7 +95,7 @@ public class PingTest extends InitExtensions { PingManager pinger = PingManager.getInstanceFor(threadedCon); - boolean pingSuccess = pinger.ping("test@myserver.com"); + boolean pingSuccess = pinger.ping(DUMMY_AT_EXAMPLE_ORG); assertTrue(pingSuccess); @@ -111,7 +114,7 @@ public class PingTest extends InitExtensions { PingManager pinger = PingManager.getInstanceFor(dummyCon); try { - pinger.ping("test@myserver.com"); + pinger.ping(DUMMY_AT_EXAMPLE_ORG); } catch (NoResponseException e) { return; @@ -140,7 +143,7 @@ public class PingTest extends InitExtensions { PingManager pinger = PingManager.getInstanceFor(threadedCon); - boolean pingSuccess = pinger.ping("test@myserver.com"); + boolean pingSuccess = pinger.ping(DUMMY_AT_EXAMPLE_ORG); assertFalse(pingSuccess); } @@ -207,7 +210,7 @@ public class PingTest extends InitExtensions { con.addIQReply(discoReply); PingManager pinger = PingManager.getInstanceFor(con); - boolean pingSupported = pinger.isPingSupported("test@myserver.com"); + boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG); assertTrue(pingSupported); } @@ -229,7 +232,7 @@ public class PingTest extends InitExtensions { con.addIQReply(discoReply); PingManager pinger = PingManager.getInstanceFor(con); - boolean pingSupported = pinger.isPingSupported("test@myserver.com"); + boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG); assertFalse(pingSupported); } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java index 48b382c8a..0bf1158fa 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java @@ -33,6 +33,7 @@ import org.jivesoftware.smackx.pubsub.packet.PubSub; import org.jivesoftware.smackx.xdata.packet.DataForm; import org.junit.Assert; import org.junit.Test; +import org.jxmpp.stringprep.XmppStringprepException; /** * @@ -77,7 +78,7 @@ public class ConfigureFormTest } @Test (expected=SmackException.class) - public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException + public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException, XmppStringprepException { ThreadedDummyConnection con = new ThreadedDummyConnection(); PubSubManager mgr = new PubSubManager(con); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java index 7f30b9d5d..7a6ef7a06 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java @@ -19,7 +19,9 @@ package org.jivesoftware.smackx.receipts; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence; import java.util.Properties; @@ -31,6 +33,8 @@ import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smackx.InitExtensions; import org.jivesoftware.smackx.receipts.DeliveryReceiptManager.AutoReceiptMode; import org.junit.Test; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.impl.JidCreate; import org.xmlpull.v1.XmlPullParser; import com.jamesmurty.utils.XMLBuilder; @@ -62,7 +66,7 @@ public class DeliveryReceiptTest extends InitExtensions { assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(p)); - Message m = new Message("romeo@montague.com", Message.Type.normal); + Message m = new Message(JidCreate.from("romeo@montague.com"), Message.Type.normal); assertFalse(DeliveryReceiptManager.hasDeliveryReceiptRequest(m)); DeliveryReceiptRequest.addTo(m); assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(m)); @@ -77,8 +81,8 @@ public class DeliveryReceiptTest extends InitExtensions { TestReceiptReceivedListener rrl = new TestReceiptReceivedListener(); drm.addReceiptReceivedListener(rrl); - Message m = new Message("romeo@montague.com", Message.Type.normal); - m.setFrom("julia@capulet.com"); + Message m = new Message(JidCreate.from("romeo@montague.com"), Message.Type.normal); + m.setFrom(JidCreate.from("julia@capulet.com")); m.setStanzaId("reply-id"); m.addExtension(new DeliveryReceipt("original-test-id")); c.processPacket(m); @@ -88,9 +92,9 @@ public class DeliveryReceiptTest extends InitExtensions { private static class TestReceiptReceivedListener extends WaitForPacketListener implements ReceiptReceivedListener { @Override - public void onReceiptReceived(String fromJid, String toJid, String receiptId, Stanza receipt) { - assertEquals("julia@capulet.com", fromJid); - assertEquals("romeo@montague.com", toJid); + public void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt) { + assertThat("julia@capulet.com", equalsCharSequence(fromJid)); + assertThat("romeo@montague.com", equalsCharSequence(toJid)); assertEquals("original-test-id", receiptId); reportInvoked(); } @@ -106,8 +110,8 @@ public class DeliveryReceiptTest extends InitExtensions { assertEquals(AutoReceiptMode.always, drm.getAutoReceiptMode()); // test auto-receipts - Message m = new Message("julia@capulet.com", Message.Type.normal); - m.setFrom("romeo@montague.com"); + Message m = new Message(JidCreate.from("julia@capulet.com"), Message.Type.normal); + m.setFrom(JidCreate.from("romeo@montague.com")); m.setStanzaId("test-receipt-request"); DeliveryReceiptRequest.addTo(m); @@ -116,7 +120,7 @@ public class DeliveryReceiptTest extends InitExtensions { Stanza reply = c.getSentPacket(); DeliveryReceipt r = DeliveryReceipt.from(reply); - assertEquals("romeo@montague.com", reply.getTo()); + assertThat("romeo@montague.com", equalsCharSequence(reply.getTo())); assertEquals("test-receipt-request", r.getId()); } } diff --git a/smack-extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java b/smack-extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java index e6a6e4869..a43ed7c8b 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java +++ b/smack-extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java @@ -32,6 +32,8 @@ import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.FullJid; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -67,7 +69,7 @@ public class ConnectionUtils { * @throws InterruptedException */ public static XMPPConnection createMockedConnection(final Protocol protocol, - String initiatorJID, String xmppServer) throws SmackException, XMPPErrorException, InterruptedException { + FullJid initiatorJID, DomainBareJid xmppServer) throws SmackException, XMPPErrorException, InterruptedException { // mock XMPP connection XMPPConnection connection = mock(XMPPConnection.class); diff --git a/smack-im/src/main/java/org/jivesoftware/smack/chat/Chat.java b/smack-im/src/main/java/org/jivesoftware/smack/chat/Chat.java index 64a9b875c..db80a2dc4 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/chat/Chat.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/chat/Chat.java @@ -21,6 +21,7 @@ import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.util.StringUtils; +import org.jxmpp.jid.JidWithLocalpart; import java.util.Set; import java.util.Collections; @@ -40,7 +41,7 @@ public class Chat { private ChatManager chatManager; private String threadID; - private String participant; + private JidWithLocalpart participant; private final Set listeners = new CopyOnWriteArraySet(); /** @@ -50,7 +51,7 @@ public class Chat { * @param participant the user to chat with. * @param threadID the thread ID to use. */ - Chat(ChatManager chatManager, String participant, String threadID) { + Chat(ChatManager chatManager, JidWithLocalpart participant, String threadID) { if (StringUtils.isEmpty(threadID)) { throw new IllegalArgumentException("Thread ID must not be null"); } @@ -75,7 +76,7 @@ public class Chat { * * @return the name of the user the chat is occuring with. */ - public String getParticipant() { + public JidWithLocalpart getParticipant() { return participant; } diff --git a/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java index 0685f5669..6e2daead8 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java @@ -24,6 +24,7 @@ import java.util.UUID; import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArraySet; +import java.util.logging.Logger; import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.MessageListener; @@ -41,7 +42,9 @@ import org.jivesoftware.smack.filter.ThreadFilter; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message.Type; import org.jivesoftware.smack.packet.Stanza; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.JidWithLocalpart; /** * The chat manager keeps track of references to all current chats. It will not hold any references @@ -51,6 +54,9 @@ import org.jxmpp.util.XmppStringUtils; * @author Alexander Wenckus */ public class ChatManager extends Manager{ + + private static final Logger LOGGER = Logger.getLogger(ChatManager.class.getName()); + private static final Map INSTANCES = new WeakHashMap(); /** @@ -124,12 +130,12 @@ public class ChatManager extends Manager{ /** * Maps jids to chats */ - private Map jidChats = new ConcurrentHashMap<>(); + private Map jidChats = new ConcurrentHashMap<>(); /** * Maps base jids to chats */ - private Map baseJidChats = new ConcurrentHashMap<>(); + private Map baseJidChats = new ConcurrentHashMap<>(); private Set chatManagerListeners = new CopyOnWriteArraySet(); @@ -209,7 +215,7 @@ public class ChatManager extends Manager{ * @param userJID the user this chat is with. * @return the created chat. */ - public Chat createChat(String userJID) { + public Chat createChat(JidWithLocalpart userJID) { return createChat(userJID, null); } @@ -220,7 +226,7 @@ public class ChatManager extends Manager{ * @param listener the optional listener which will listen for new messages from this chat. * @return the created chat. */ - public Chat createChat(String userJID, ChatMessageListener listener) { + public Chat createChat(JidWithLocalpart userJID, ChatMessageListener listener) { return createChat(userJID, null, listener); } @@ -232,7 +238,7 @@ public class ChatManager extends Manager{ * @param listener the optional listener to add to the chat * @return the created chat. */ - public Chat createChat(String userJID, String thread, ChatMessageListener listener) { + public Chat createChat(JidWithLocalpart userJID, String thread, ChatMessageListener listener) { if (thread == null) { thread = nextID(); } @@ -245,11 +251,11 @@ public class ChatManager extends Manager{ return chat; } - private Chat createChat(String userJID, String threadID, boolean createdLocally) { + private Chat createChat(JidWithLocalpart userJID, String threadID, boolean createdLocally) { Chat chat = new Chat(this, userJID, threadID); threadChats.put(threadID, chat); jidChats.put(userJID, chat); - baseJidChats.put(XmppStringUtils.parseBareJid(userJID), chat); + baseJidChats.put(userJID.asBareJid(), chat); for(ChatManagerListener listener : chatManagerListeners) { listener.chatCreated(chat, createdLocally); @@ -260,9 +266,9 @@ public class ChatManager extends Manager{ void closeChat(Chat chat) { threadChats.remove(chat.getThreadID()); - String userJID = chat.getParticipant(); + JidWithLocalpart userJID = chat.getParticipant(); jidChats.remove(userJID); - baseJidChats.remove(XmppStringUtils.parseBareJid(userJID)); + baseJidChats.remove(userJID.withoutResource()); } /** @@ -273,10 +279,16 @@ public class ChatManager extends Manager{ * @return a Chat or null if none can be created */ private Chat createChat(Message message) { - String userJID = message.getFrom(); + Jid from = message.getFrom(); // According to RFC6120 8.1.2.1 4. messages without a 'from' attribute are valid, but they // are of no use in this case for ChatManager + if (from == null) { + return null; + } + + JidWithLocalpart userJID = from.asJidWithLocalpartIfPossible(); if (userJID == null) { + LOGGER.warning("Message from JID without localpart: '" +message.toXML() + "'"); return null; } String threadID = message.getThread(); @@ -296,7 +308,7 @@ public class ChatManager extends Manager{ * @param userJID jid in the from field of message. * @return Matching chat, or null if no match found. */ - private Chat getUserChat(String userJID) { + private Chat getUserChat(Jid userJID) { if (matchMode == MatchMode.NONE) { return null; } @@ -308,7 +320,7 @@ public class ChatManager extends Manager{ Chat match = jidChats.get(userJID); if (match == null && (matchMode == MatchMode.BARE_JID)) { - match = baseJidChats.get(XmppStringUtils.parseBareJid(userJID)); + match = baseJidChats.get(userJID.asBareJidIfPossible()); } return match; } diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java index 56e3ea400..13e767f05 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -60,7 +59,11 @@ import org.jivesoftware.smack.roster.packet.RosterVer; import org.jivesoftware.smack.roster.packet.RosterPacket.Item; import org.jivesoftware.smack.roster.rosterstore.RosterStore; import org.jivesoftware.smack.util.Objects; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.JidWithResource; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.jid.parts.Resourcepart; /** * Represents a user's roster, which is the collection of users a person receives @@ -96,7 +99,7 @@ public class Roster extends Manager { *

      * This method will never return null, instead if the user has not yet logged into * the server or is logged in anonymously all modifying methods of the returned roster object - * like {@link Roster#createEntry(String, String, String[])}, + * like {@link Roster#createEntry(Jid, String, String[])}, * {@link Roster#removeEntry(RosterEntry)} , etc. except adding or removing * {@link RosterListener}s will throw an IllegalStateException. * @@ -128,11 +131,16 @@ public class Roster extends Manager { /** * Concurrent hash map from JID to its roster entry. */ - private final Map entries = new ConcurrentHashMap(); + private final Map entries = new ConcurrentHashMap<>(); private final Set unfiledEntries = new CopyOnWriteArraySet<>(); private final Set rosterListeners = new LinkedHashSet<>(); - private final Map> presenceMap = new ConcurrentHashMap>(); + + /** + * A map of JIDs to another Map of Resourceparts to Presences. The 'inner' map may contain + * {@link Resourcepart#EMPTY} if there are no other Presences available. + */ + private final Map> presenceMap = new ConcurrentHashMap<>(); /** * Mutually exclude roster listener invocation and changing the {@link entries} map. Also used @@ -421,7 +429,7 @@ public class Roster extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public void createEntry(String user, String name, String[] groups) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public void createEntry(Jid user, String name, String[] groups) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { final XMPPConnection connection = connection(); if (!connection.isAuthenticated()) { throw new NotLoggedInException(); @@ -568,11 +576,11 @@ public class Roster extends Manager { * in any valid format (e.g. "domain/resource", "user@domain" or "user@domain/resource"). * @return the roster entry or null if it does not exist. */ - public RosterEntry getEntry(String user) { + public RosterEntry getEntry(Jid user) { if (user == null) { return null; } - String key = getMapKey(user); + Jid key = getMapKey(user); return entries.get(key); } @@ -584,7 +592,7 @@ public class Roster extends Manager { * "user@domain" or "user@domain/resource"). * @return true if the XMPP address is an entry in the roster. */ - public boolean contains(String user) { + public boolean contains(Jid user) { return getEntry(user) != null; } @@ -645,9 +653,9 @@ public class Roster extends Manager { * @return the user's current presence, or unavailable presence if the user is offline * or if no presence information is available.. */ - public Presence getPresence(String user) { - String key = getMapKey(XmppStringUtils.parseBareJid(user)); - Map userPresences = presenceMap.get(key); + public Presence getPresence(Jid user) { + Jid key = getMapKey(user); + Map userPresences = presenceMap.get(key); if (userPresences == null) { Presence presence = new Presence(Presence.Type.unavailable); presence.setFrom(user); @@ -660,7 +668,7 @@ public class Roster extends Manager { // This is used in case no available presence is found Presence unavailable = null; - for (String resource : userPresences.keySet()) { + for (Resourcepart resource : userPresences.keySet()) { Presence p = userPresences.get(resource); if (!p.isAvailable()) { unavailable = p; @@ -712,10 +720,10 @@ public class Roster extends Manager { * @return the user's current presence, or unavailable presence if the user is offline * or if no presence information is available. */ - public Presence getPresenceResource(String userWithResource) { - String key = getMapKey(userWithResource); - String resource = XmppStringUtils.parseResource(userWithResource); - Map userPresences = presenceMap.get(key); + public Presence getPresenceResource(JidWithResource userWithResource) { + Jid key = getMapKey(userWithResource); + Resourcepart resource = userWithResource.getResourcepart(); + Map userPresences = presenceMap.get(key); if (userPresences == null) { Presence presence = new Presence(Presence.Type.unavailable); presence.setFrom(userWithResource); @@ -742,8 +750,8 @@ public class Roster extends Manager { * @return a List of Presence objects for all the user's current presences, or an unavailable presence if no * presence information is available. */ - public List getAllPresences(String bareJid) { - Map userPresences = presenceMap.get(getMapKey(bareJid)); + public List getAllPresences(Jid bareJid) { + Map userPresences = presenceMap.get(getMapKey(bareJid)); List res; if (userPresences == null) { // Create an unavailable presence if none was found @@ -763,7 +771,7 @@ public class Roster extends Manager { * @param bareJid the bare JID from which the presences should be retrieved. * @return available presences for the bare JID. */ - public List getAvailablePresences(String bareJid) { + public List getAvailablePresences(Jid bareJid) { List allPresences = getAllPresences(bareJid); List res = new ArrayList<>(allPresences.size()); for (Presence presence : allPresences) { @@ -785,10 +793,10 @@ public class Roster extends Manager { * or an unavailable presence if the user is offline or if no presence information * is available. */ - public List getPresences(String user) { + public List getPresences(Jid user) { List res; - String key = getMapKey(user); - Map userPresences = presenceMap.get(key); + Jid key = getMapKey(user); + Map userPresences = presenceMap.get(key); if (userPresences == null) { Presence presence = new Presence(Presence.Type.unavailable); presence.setFrom(user); @@ -835,7 +843,7 @@ public class Roster extends Manager { * @return true if the given JID is allowed to see the users presence. * @since 4.1 */ - public boolean isSubscribedToMyPresence(String jid) { + public boolean isSubscribedToMyPresence(Jid jid) { if (connection().getServiceName().equals(jid)) { return true; } @@ -892,15 +900,19 @@ public class Roster extends Manager { * jdoe@example.com/Work. * @return the key to use in the presenceMap and entries Map for the fully qualified XMPP ID. */ - private String getMapKey(String user) { + private Jid getMapKey(Jid user) { if (user == null) { return null; } if (entries.containsKey(user)) { return user; } - String key = XmppStringUtils.parseBareJid(user); - return key.toLowerCase(Locale.US); + BareJid bareJid = user.asBareJidIfPossible(); + if (bareJid != null) { + return bareJid; + } + // jid validate, log this case? + return user; } /** @@ -911,12 +923,17 @@ public class Roster extends Manager { */ private void setOfflinePresencesAndResetLoaded() { Presence packetUnavailable; - outerloop: for (String user : presenceMap.keySet()) { - Map resources = presenceMap.get(user); + outerloop: for (Jid user : presenceMap.keySet()) { + Map resources = presenceMap.get(user); if (resources != null) { - for (String resource : resources.keySet()) { + for (Resourcepart resource : resources.keySet()) { packetUnavailable = new Presence(Presence.Type.unavailable); - packetUnavailable.setFrom(user + "/" + resource); + BareJid bareUserJid = user.asBareJidIfPossible(); + if (bareUserJid == null) { + LOGGER.warning("Can not transform user JID to bare JID: '" + user + "'"); + continue; + } + packetUnavailable.setFrom(JidCreate.fullFrom(bareUserJid, resource)); try { presencePacketListener.processPacket(packetUnavailable); } @@ -943,8 +960,8 @@ public class Roster extends Manager { * @param updatedEntries the collection of address of the updated contacts. * @param deletedEntries the collection of address of the deleted contacts. */ - private void fireRosterChangedEvent(final Collection addedEntries, final Collection updatedEntries, - final Collection deletedEntries) { + private void fireRosterChangedEvent(final Collection addedEntries, final Collection updatedEntries, + final Collection deletedEntries) { synchronized (rosterListenersAndEntriesLock) { for (RosterListener listener : rosterListeners) { if (!addedEntries.isEmpty()) { @@ -973,8 +990,8 @@ public class Roster extends Manager { } } - private void addUpdateEntry(Collection addedEntries, Collection updatedEntries, - Collection unchangedEntries, RosterPacket.Item item, RosterEntry entry) { + private void addUpdateEntry(Collection addedEntries, Collection updatedEntries, + Collection unchangedEntries, RosterPacket.Item item, RosterEntry entry) { RosterEntry oldEntry; synchronized (rosterListenersAndEntriesLock) { oldEntry = entries.put(item.getUser(), entry); @@ -1032,11 +1049,11 @@ public class Roster extends Manager { } } - private void deleteEntry(Collection deletedEntries, RosterEntry entry) { - String user = entry.getUser(); + private void deleteEntry(Collection deletedEntries, RosterEntry entry) { + Jid user = entry.getUser(); entries.remove(user); unfiledEntries.remove(entry); - presenceMap.remove(XmppStringUtils.parseBareJid(user)); + presenceMap.remove(user); deletedEntries.add(user); for (Entry e: groups.entrySet()) { @@ -1131,8 +1148,8 @@ public class Roster extends Manager { * @param key the presence map key * @return the user presences */ - private Map getUserPresences(String key) { - Map userPresences = presenceMap.get(key); + private Map getUserPresences(Jid key) { + Map userPresences = presenceMap.get(key); if (userPresences == null) { userPresences = new ConcurrentHashMap<>(); presenceMap.put(key, userPresences); @@ -1144,9 +1161,13 @@ public class Roster extends Manager { public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException { final XMPPConnection connection = connection(); Presence presence = (Presence) packet; - String from = presence.getFrom(); - String key = getMapKey(from); - Map userPresences; + Jid from = presence.getFrom(); + Resourcepart fromResource = from.getResourceOrNull(); + if (fromResource == null) { + fromResource = Resourcepart.EMPTY; + } + Jid key = getMapKey(from); + Map userPresences; Presence response = null; // If an "available" presence, add it to the presence map. Each presence @@ -1158,9 +1179,9 @@ public class Roster extends Manager { userPresences = getUserPresences(key); // See if an offline presence was being stored in the map. If so, remove // it since we now have an online presence. - userPresences.remove(""); + userPresences.remove(Resourcepart.EMPTY); // Add the new presence, using the resources as a key. - userPresences.put(XmppStringUtils.parseResource(from), presence); + userPresences.put(fromResource, presence); // If the user is in the roster, fire an event. if (entries.containsKey(key)) { fireRosterPresenceEvent(presence); @@ -1170,17 +1191,17 @@ public class Roster extends Manager { case unavailable: // If no resource, this is likely an offline presence as part of // a roster presence flood. In that case, we store it. - if ("".equals(XmppStringUtils.parseResource(from))) { + if (from.hasNoResource()) { // Get the user presence map userPresences = getUserPresences(key); - userPresences.put("", presence); + userPresences.put(Resourcepart.EMPTY, presence); } // Otherwise, this is a normal offline presence. else if (presenceMap.get(key) != null) { userPresences = presenceMap.get(key); // Store the offline presence, as it may include extra information // such as the user being on vacation. - userPresences.put(XmppStringUtils.parseResource(from), presence); + userPresences.put(fromResource, presence); } // If the user is in the roster, fire an event. if (entries.containsKey(key)) { @@ -1221,7 +1242,7 @@ public class Roster extends Manager { // Error presence packets from a bare JID mean we invalidate all existing // presence info for the user. case error: - if (!"".equals(XmppStringUtils.parseResource(from))) { + if (!from.isBareJid()) { break; } userPresences = getUserPresences(key); @@ -1229,7 +1250,7 @@ public class Roster extends Manager { userPresences.clear(); // Set the new presence using the empty resource as a key. - userPresences.put("", presence); + userPresences.put(Resourcepart.EMPTY, presence); // If the user is in the roster, fire an event. if (entries.containsKey(key)) { fireRosterPresenceEvent(presence); @@ -1250,10 +1271,10 @@ public class Roster extends Manager { public void processPacket(Stanza packet) { final XMPPConnection connection = connection(); LOGGER.fine("RosterResultListener received stanza"); - Collection addedEntries = new ArrayList(); - Collection updatedEntries = new ArrayList(); - Collection deletedEntries = new ArrayList(); - Collection unchangedEntries = new ArrayList(); + Collection addedEntries = new ArrayList<>(); + Collection updatedEntries = new ArrayList<>(); + Collection deletedEntries = new ArrayList<>(); + Collection unchangedEntries = new ArrayList<>(); if (packet instanceof RosterPacket) { // Non-empty roster result. This stanza contains all the roster elements. @@ -1274,14 +1295,14 @@ public class Roster extends Manager { } // Delete all entries which where not added or updated - Set toDelete = new HashSet(); + Set toDelete = new HashSet<>(); for (RosterEntry entry : entries.values()) { toDelete.add(entry.getUser()); } toDelete.removeAll(addedEntries); toDelete.removeAll(updatedEntries); toDelete.removeAll(unchangedEntries); - for (String user : toDelete) { + for (Jid user : toDelete) { deleteEntry(deletedEntries, entries.get(user)); } @@ -1329,8 +1350,8 @@ public class Roster extends Manager { // Roster push (RFC 6121, 2.1.6) // A roster push with a non-empty from not matching our address MUST be ignored - String jid = XmppStringUtils.parseBareJid(connection.getUser()); - String from = rosterPacket.getFrom(); + BareJid jid = connection.getUser().asBareJid(); + Jid from = rosterPacket.getFrom(); if (from != null && !from.equals(jid)) { LOGGER.warning("Ignoring roster push with a non matching 'from' ourJid='" + jid + "' from='" + from + "'"); @@ -1344,10 +1365,10 @@ public class Roster extends Manager { return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.bad_request)); } - Collection addedEntries = new ArrayList(); - Collection updatedEntries = new ArrayList(); - Collection deletedEntries = new ArrayList(); - Collection unchangedEntries = new ArrayList(); + Collection addedEntries = new ArrayList<>(); + Collection updatedEntries = new ArrayList<>(); + Collection deletedEntries = new ArrayList<>(); + Collection unchangedEntries = new ArrayList<>(); // We assured above that the size of items is exaclty 1, therefore we are able to // safely retrieve this single item here. diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java index f87ad50fa..22fafc822 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java @@ -28,6 +28,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.roster.packet.RosterPacket; +import org.jxmpp.jid.Jid; /** @@ -41,7 +42,7 @@ public class RosterEntry { /** * The JID of the entity/user. */ - private final String user; + private final Jid user; private String name; private RosterPacket.ItemType type; @@ -58,7 +59,7 @@ public class RosterEntry { * @param status the subscription status (related to subscriptions pending to be approbed). * @param connection a connection to the XMPP server. */ - RosterEntry(String user, String name, RosterPacket.ItemType type, + RosterEntry(Jid user, String name, RosterPacket.ItemType type, RosterPacket.ItemStatus status, Roster roster, XMPPConnection connection) { this.user = user; this.name = name; @@ -73,7 +74,7 @@ public class RosterEntry { * * @return the user associated with this entry. */ - public String getUser() { + public Jid getUser() { return user; } diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterListener.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterListener.java index 2a00de66a..e3216d7ae 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterListener.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterListener.java @@ -18,6 +18,7 @@ package org.jivesoftware.smack.roster; import org.jivesoftware.smack.packet.Presence; +import org.jxmpp.jid.Jid; import java.util.Collection; @@ -35,21 +36,21 @@ public interface RosterListener { * * @param addresses the XMPP addresses of the contacts that have been added to the roster. */ - public void entriesAdded(Collection addresses); + public void entriesAdded(Collection addresses); /** * Called when a roster entries are updated. * * @param addresses the XMPP addresses of the contacts whose entries have been updated. */ - public void entriesUpdated(Collection addresses); + public void entriesUpdated(Collection addresses); /** * Called when a roster entries are removed. * * @param addresses the XMPP addresses of the contacts that have been removed from the roster. */ - public void entriesDeleted(Collection addresses); + public void entriesDeleted(Collection addresses); /** * Called when the presence of a roster entry is changed. Care should be taken @@ -74,7 +75,7 @@ public interface RosterListener { * presence packets will not cause this method to be called. * * @param presence the presence that changed. - * @see Roster#getPresence(String) + * @see Roster#getPresence(Jid) */ public void presenceChanged(Presence presence); } diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterPacket.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterPacket.java index 9997cbbed..74e5afa25 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterPacket.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterPacket.java @@ -20,11 +20,11 @@ package org.jivesoftware.smack.roster.packet; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.util.XmlStringBuilder; +import org.jxmpp.jid.Jid; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; @@ -107,7 +107,7 @@ public class RosterPacket extends IQ { public static final String GROUP = "group"; - private String user; + private final Jid user; private String name; private ItemType itemType; private ItemStatus itemStatus; @@ -119,8 +119,8 @@ public class RosterPacket extends IQ { * @param user the user. * @param name the user's name. */ - public Item(String user, String name) { - this.user = user.toLowerCase(Locale.US); + public Item(Jid user, String name) { + this.user = user; this.name = name; itemType = null; itemStatus = null; @@ -132,7 +132,7 @@ public class RosterPacket extends IQ { * * @return the user. */ - public String getUser() { + public Jid getUser() { return user; } diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterPacketProvider.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterPacketProvider.java index eaddfb504..941817e34 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterPacketProvider.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterPacketProvider.java @@ -21,6 +21,8 @@ import java.io.IOException; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.roster.packet.RosterPacket; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.impl.JidCreate; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -44,8 +46,9 @@ public class RosterPacketProvider extends IQProvider { String startTag = parser.getName(); switch (startTag) { case "item": - String jid = parser.getAttributeValue("", "jid"); + String jidString = parser.getAttributeValue("", "jid"); String name = parser.getAttributeValue("", "name"); + Jid jid = JidCreate.from(jidString); // Create packet. item = new RosterPacket.Item(jid, name); // Set status. diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java index 5bdde3ea9..279e47b60 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java @@ -31,6 +31,8 @@ import org.jivesoftware.smack.roster.packet.RosterPacket.Item; import org.jivesoftware.smack.util.FileUtils; import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.util.stringencoder.Base32; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.impl.JidCreate; import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -131,7 +133,7 @@ public class DirectoryRosterStore implements RosterStore { } @Override - public Item getEntry(String bareJid) { + public Item getEntry(Jid bareJid) { return readEntry(getBareJidFile(bareJid)); } @@ -158,7 +160,7 @@ public class DirectoryRosterStore implements RosterStore { } @Override - public boolean removeEntry(String bareJid, String version) { + public boolean removeEntry(Jid bareJid, String version) { return getBareJidFile(bareJid).delete() && setRosterVersion(version); } @@ -182,7 +184,7 @@ public class DirectoryRosterStore implements RosterStore { } String parserName; - String user = null; + Jid user = null; String name = null; String type = null; String status = null; @@ -199,11 +201,12 @@ public class DirectoryRosterStore implements RosterStore { parserName = parser.getName(); if (eventType == XmlPullParser.START_TAG) { if (parserName.equals("item")) { - user = name = type = status = null; + user = null; + name = type = status = null; } else if (parserName.equals("user")) { parser.next(); - user = parser.getText(); + user = JidCreate.from(parser.getText()); } else if (parserName.equals("name")) { parser.next(); @@ -297,8 +300,8 @@ public class DirectoryRosterStore implements RosterStore { } - private File getBareJidFile(String bareJid) { - String encodedJid = Base32.encode(bareJid); + private File getBareJidFile(Jid bareJid) { + String encodedJid = Base32.encode(bareJid.toString()); return new File(fileDir, ENTRY_PREFIX + encodedJid); } diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/RosterStore.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/RosterStore.java index b732da296..f99a7d0e3 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/RosterStore.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/RosterStore.java @@ -19,6 +19,7 @@ package org.jivesoftware.smack.roster.rosterstore; import java.util.Collection; import org.jivesoftware.smack.roster.packet.RosterPacket; +import org.jxmpp.jid.Jid; /** * This is an interface for persistent roster store needed to implement @@ -37,7 +38,7 @@ public interface RosterStore { * @param bareJid The bare JID of the RosterEntry * @return The {@link org.jivesoftware.smack.roster.RosterEntry} which belongs to that user */ - public RosterPacket.Item getEntry(String bareJid); + public RosterPacket.Item getEntry(Jid bareJid); /** * This method returns the version number as specified by the "ver" attribute * of the local store. For a fresh store, this MUST be the empty string. @@ -64,6 +65,6 @@ public interface RosterStore { * @param version the new roster version * @return True if successful */ - public boolean removeEntry(String bareJid, String version); + public boolean removeEntry(Jid bareJid, String version); } diff --git a/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java b/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java index 10e139f17..48a5748fb 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java @@ -32,6 +32,8 @@ import org.jivesoftware.smack.test.util.WaitForPacketListener; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.JidTestUtil; public class ChatConnectionTest { @@ -219,7 +221,7 @@ public class ChatConnectionTest { */ @Test public void chatFoundWhenNoThreadFullJid() { - Chat outgoing = cm.createChat("you@testserver", null); + Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null); Stanza incomingChat = createChatPacket(null, true); processServerMessage(incomingChat); @@ -235,7 +237,7 @@ public class ChatConnectionTest { */ @Test public void chatFoundWhenNoThreadBaseJid() { - Chat outgoing = cm.createChat("you@testserver", null); + Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null); Stanza incomingChat = createChatPacket(null, false); processServerMessage(incomingChat); @@ -251,7 +253,7 @@ public class ChatConnectionTest { */ @Test public void chatFoundWithSameThreadFullJid() { - Chat outgoing = cm.createChat("you@testserver", null); + Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null); Stanza incomingChat = createChatPacket(outgoing.getThreadID(), true); processServerMessage(incomingChat); @@ -267,7 +269,7 @@ public class ChatConnectionTest { */ @Test public void chatFoundWithSameThreadBaseJid() { - Chat outgoing = cm.createChat("you@testserver", null); + Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null); Stanza incomingChat = createChatPacket(outgoing.getThreadID(), false); processServerMessage(incomingChat); @@ -283,7 +285,7 @@ public class ChatConnectionTest { */ @Test public void chatNotFoundWithDiffThreadBaseJid() { - Chat outgoing = cm.createChat("you@testserver", null); + Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null); Stanza incomingChat = createChatPacket(outgoing.getThreadID() + "ff", false); processServerMessage(incomingChat); @@ -299,7 +301,7 @@ public class ChatConnectionTest { */ @Test public void chatNotFoundWithDiffThreadFullJid() { - Chat outgoing = cm.createChat("you@testserver", null); + Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null); Stanza incomingChat = createChatPacket(outgoing.getThreadID() + "ff", true); processServerMessage(incomingChat); @@ -321,9 +323,15 @@ public class ChatConnectionTest { } private Message createChatPacket(final String threadId, final boolean isFullJid) { - Message chatMsg = new Message("me@testserver", Message.Type.chat); + Message chatMsg = new Message(JidTestUtil.BARE_JID_1, Message.Type.chat); chatMsg.setBody("the body message - " + System.currentTimeMillis()); - chatMsg.setFrom("you@testserver" + (isFullJid ? "/resource" : "")); + Jid jid; + if (isFullJid) { + jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; + } else { + jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG; + } + chatMsg.setFrom(jid); chatMsg.setThread(threadId); return chatMsg; } diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java index 005c3c837..930c6b919 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java @@ -45,11 +45,6 @@ public class RosterOfflineTest { assertNotNull(roster); } - @Test(expected = SmackException.class) - public void shouldThrowExceptionOnCreateEntry() throws Exception { - roster.createEntry("test", "test", null); - } - @Test(expected = SmackException.class) public void shouldThrowExceptionOnReload() throws Exception { roster.reload(); diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java index cc37c7afe..05f1523ad 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java @@ -50,6 +50,9 @@ import org.jivesoftware.smack.util.PacketParserUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; import org.xmlpull.v1.XmlPullParser; /** @@ -104,18 +107,18 @@ public class RosterTest extends InitSmackIm { // Verify roster assertTrue("Roster can't be loaded!", roster.waitUntilLoaded()); - verifyRomeosEntry(roster.getEntry("romeo@example.net")); - verifyMercutiosEntry(roster.getEntry("mercutio@example.com")); - verifyBenvoliosEntry(roster.getEntry("benvolio@example.net")); + verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net"))); + verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); + verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); assertSame("Wrong number of roster entries.", 3, roster.getEntries().size()); // Verify roster listener assertTrue("The roster listener wasn't invoked for Romeo.", - rosterListener.getAddedAddresses().contains("romeo@example.net")); + rosterListener.addedAddressesContains("romeo@example.net")); assertTrue("The roster listener wasn't invoked for Mercutio.", - rosterListener.getAddedAddresses().contains("mercutio@example.com")); + rosterListener.addedAddressesContains("mercutio@example.com")); assertTrue("The roster listener wasn't invoked for Benvolio.", - rosterListener.getAddedAddresses().contains("benvolio@example.net")); + rosterListener.addedAddressesContains("benvolio@example.net")); assertSame("RosterListeners implies that a item was deleted!", 0, rosterListener.getDeletedAddresses().size()); @@ -132,7 +135,7 @@ public class RosterTest extends InitSmackIm { @Test public void testAddRosterItem() throws Throwable { // Constants for the new contact - final String contactJID = "nurse@example.com"; + final Jid contactJID = JidCreate.from("nurse@example.com"); final String contactName = "Nurse"; final String[] contactGroup = {"Servants"}; @@ -189,9 +192,9 @@ public class RosterTest extends InitSmackIm { addedEntry.getGroups().iterator().next().getName()); // Verify the unchanged roster items - verifyRomeosEntry(roster.getEntry("romeo@example.net")); - verifyMercutiosEntry(roster.getEntry("mercutio@example.com")); - verifyBenvoliosEntry(roster.getEntry("benvolio@example.net")); + verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net"))); + verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); + verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); assertSame("Wrong number of roster entries.", 4, roster.getEntries().size()); } @@ -203,7 +206,7 @@ public class RosterTest extends InitSmackIm { @Test public void testUpdateRosterItem() throws Throwable { // Constants for the updated contact - final String contactJID = "romeo@example.net"; + final Jid contactJID = JidCreate.from("romeo@example.net"); final String contactName = "Romeo"; final String[] contactGroups = {"Friends", "Lovers"}; @@ -263,8 +266,8 @@ public class RosterTest extends InitSmackIm { addedEntry.getGroups().size()); // Verify the unchanged roster items - verifyMercutiosEntry(roster.getEntry("mercutio@example.com")); - verifyBenvoliosEntry(roster.getEntry("benvolio@example.net")); + verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); + verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); assertSame("Wrong number of roster entries (" + roster.getEntries() + ").", 3, roster.getEntries().size()); @@ -278,7 +281,7 @@ public class RosterTest extends InitSmackIm { @Test public void testDeleteRosterItem() throws Throwable { // The contact which should be deleted - final String contactJID = "romeo@example.net"; + final Jid contactJID = JidCreate.from("romeo@example.net"); // Setup assertNotNull("Can't get the roster from the provided connection!", roster); @@ -310,8 +313,8 @@ public class RosterTest extends InitSmackIm { assertNull("The contact wasn't deleted from the roster!", deletedEntry); assertTrue("The roster listener wasn't invoked for the deleted contact!", rosterListener.getDeletedAddresses().contains(contactJID)); - verifyMercutiosEntry(roster.getEntry("mercutio@example.com")); - verifyBenvoliosEntry(roster.getEntry("benvolio@example.net")); + verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); + verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); assertSame("Wrong number of roster entries (" + roster.getEntries() + ").", 2, roster.getEntries().size()); @@ -324,7 +327,7 @@ public class RosterTest extends InitSmackIm { */ @Test public void testSimpleRosterPush() throws Throwable { - final String contactJID = "nurse@example.com"; + final Jid contactJID = JidCreate.from("nurse@example.com"); assertNotNull("Can't get the roster from the provided connection!", roster); final StringBuilder sb = new StringBuilder(); sb.append("RFC 6121, Section 2.1.6 */ @Test - public void testIgnoreInvalidFrom() { + public void testIgnoreInvalidFrom() throws XmppStringprepException { + final Jid spammerJid = JidCreate.from("spam@example.com"); RosterPacket packet = new RosterPacket(); packet.setType(Type.set); packet.setTo(connection.getUser()); - packet.setFrom("mallory@example.com"); - packet.addRosterItem(new Item("spam@example.com", "Cool products!")); + packet.setFrom(JidCreate.from("mallory@example.com")); + packet.addRosterItem(new Item(spammerJid, "Cool products!")); final String requestId = packet.getStanzaId(); // Simulate receiving the roster push @@ -383,7 +388,7 @@ public class RosterTest extends InitSmackIm { assertEquals(requestId, errorIQ.getStanzaId()); assertEquals(Condition.service_unavailable, errorIQ.getError().getCondition()); - assertNull("Contact was added to roster", Roster.getInstanceFor(connection).getEntry("spam@example.com")); + assertNull("Contact was added to roster", Roster.getInstanceFor(connection).getEntry(spammerJid)); } /** @@ -395,7 +400,7 @@ public class RosterTest extends InitSmackIm { @Test(timeout=5000) public void testAddEmptyGroupEntry() throws Throwable { // Constants for the new contact - final String contactJID = "nurse@example.com"; + final Jid contactJID = JidCreate.from("nurse@example.com"); final String contactName = "Nurse"; final String[] contactGroup = {""}; @@ -447,9 +452,9 @@ public class RosterTest extends InitSmackIm { addedEntry.getGroups().size()); // Verify the unchanged roster items - verifyRomeosEntry(roster.getEntry("romeo@example.net")); - verifyMercutiosEntry(roster.getEntry("mercutio@example.com")); - verifyBenvoliosEntry(roster.getEntry("benvolio@example.net")); + verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net"))); + verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); + verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); assertSame("Wrong number of roster entries.", 4, roster.getEntries().size()); } @@ -461,7 +466,7 @@ public class RosterTest extends InitSmackIm { */ @Test public void testEmptyGroupRosterPush() throws Throwable { - final String contactJID = "nurse@example.com"; + final Jid contactJID = JidCreate.from("nurse@example.com"); assertNotNull("Can't get the roster from the provided connection!", roster); final StringBuilder sb = new StringBuilder(); sb.append(" addressesAdded = new CopyOnWriteArrayList<>(); - private final List addressesDeleted = new CopyOnWriteArrayList<>(); - private final List addressesUpdated = new CopyOnWriteArrayList<>(); + private final List addressesAdded = new CopyOnWriteArrayList<>(); + private final List addressesDeleted = new CopyOnWriteArrayList<>(); + private final List addressesUpdated = new CopyOnWriteArrayList<>(); - public synchronized void entriesAdded(Collection addresses) { + public synchronized void entriesAdded(Collection addresses) { addressesAdded.addAll(addresses); if (SmackConfiguration.DEBUG) { - for (String address : addresses) { + for (Jid address : addresses) { System.out.println("Roster entry for " + address + " added."); } } reportInvoked(); } - public synchronized void entriesDeleted(Collection addresses) { + public synchronized void entriesDeleted(Collection addresses) { addressesDeleted.addAll(addresses); if (SmackConfiguration.DEBUG) { - for (String address : addresses) { + for (Jid address : addresses) { System.out.println("Roster entry for " + address + " deleted."); } } reportInvoked(); } - public synchronized void entriesUpdated(Collection addresses) { + public synchronized void entriesUpdated(Collection addresses) { addressesUpdated.addAll(addresses); if (SmackConfiguration.DEBUG) { - for (String address : addresses) { + for (Jid address : addresses) { System.out.println("Roster entry for " + address + " updated."); } } @@ -750,7 +756,7 @@ public class RosterTest extends InitSmackIm { * * @return the collection of addresses which were added. */ - public Collection getAddedAddresses() { + public Collection getAddedAddresses() { return Collections.unmodifiableCollection(addressesAdded); } @@ -759,7 +765,7 @@ public class RosterTest extends InitSmackIm { * * @return the collection of addresses which were deleted. */ - public Collection getDeletedAddresses() { + public Collection getDeletedAddresses() { return Collections.unmodifiableCollection(addressesDeleted); } @@ -768,10 +774,43 @@ public class RosterTest extends InitSmackIm { * * @return the collection of addresses which were updated. */ - public Collection getUpdatedAddresses() { + public Collection getUpdatedAddresses() { return Collections.unmodifiableCollection(addressesUpdated); } + public boolean addedAddressesContains(String jidString) { + Jid jid; + try { + jid = JidCreate.from(jidString); + } + catch (XmppStringprepException e) { + throw new IllegalArgumentException(e); + } + return addressesAdded.contains(jid); + } + + public boolean deletedAddressesContains(String jidString) { + Jid jid; + try { + jid = JidCreate.from(jidString); + } + catch (XmppStringprepException e) { + throw new IllegalArgumentException(e); + } + return addressesDeleted.contains(jid); + } + + public boolean updatedAddressesContains(String jidString) { + Jid jid; + try { + jid = JidCreate.from(jidString); + } + catch (XmppStringprepException e) { + throw new IllegalArgumentException(e); + } + return addressesUpdated.contains(jid); + } + /** * Reset the lists of added, deleted or updated items. */ diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java index b88447dc8..5ccf8c999 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java @@ -44,6 +44,8 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; /** * Tests that verify the correct behavior of the {@link Roster} implementation @@ -130,9 +132,10 @@ public class RosterVersioningTest { * Tests that a non-empty roster result empties the store. * @throws SmackException * @throws XMPPException + * @throws XmppStringprepException */ @Test(timeout = 5000) - public void testOtherVersionStored() throws InterruptedException, XMPPException, SmackException { + public void testOtherVersionStored() throws InterruptedException, XMPPException, SmackException, XmppStringprepException { Item vaglafItem = vaglafItem(); // We expect that the roster request is the only packet sent. This is not part of the specification, @@ -181,7 +184,7 @@ public class RosterVersioningTest { // Simulate a roster push adding vaglaf { RosterPacket rosterPush = new RosterPacket(); - rosterPush.setTo("rostertest@example.com/home"); + rosterPush.setTo(JidCreate.from("rostertest@example.com/home")); rosterPush.setType(Type.set); rosterPush.setVersion("v97"); @@ -193,7 +196,7 @@ public class RosterVersioningTest { assertEquals("Expect store version after push", "v97", store.getRosterVersion()); - Item storedItem = store.getEntry("vaglaf@example.com"); + Item storedItem = store.getEntry(JidCreate.from("vaglaf@example.com")); assertNotNull("Expect vaglaf to be added", storedItem); assertEquals("Expect vaglaf to be equal to pushed item", pushedItem, storedItem); @@ -207,24 +210,24 @@ public class RosterVersioningTest { // Simulate a roster push removing vaglaf { RosterPacket rosterPush = new RosterPacket(); - rosterPush.setTo("rostertest@example.com/home"); + rosterPush.setTo(JidCreate.from("rostertest@example.com/home")); rosterPush.setType(Type.set); rosterPush.setVersion("v98"); - Item item = new Item("vaglaf@example.com", "vaglaf the only"); + Item item = new Item(JidCreate.from("vaglaf@example.com"), "vaglaf the only"); item.setItemType(ItemType.remove); rosterPush.addRosterItem(item); rosterListener.reset(); connection.processPacket(rosterPush); rosterListener.waitAndReset(); - assertNull("Store doses not contain vaglaf", store.getEntry("vaglaf@example.com")); + assertNull("Store doses not contain vaglaf", store.getEntry(JidCreate.from("vaglaf@example.com"))); assertEquals("Expect store version after push", "v98", store.getRosterVersion()); } } - private Item vaglafItem() { - Item item = new Item("vaglaf@example.com", "vaglaf the only"); + private Item vaglafItem() throws XmppStringprepException { + Item item = new Item(JidCreate.from("vaglaf@example.com"), "vaglaf the only"); item.setItemType(ItemType.both); item.addGroupName("all"); item.addGroupName("friends"); @@ -233,14 +236,14 @@ public class RosterVersioningTest { } private void populateStore(RosterStore store) throws IOException { - store.addEntry(new RosterPacket.Item("geoff@example.com", "geoff hurley"), ""); + store.addEntry(new RosterPacket.Item(JidCreate.from("geoff@example.com"), "geoff hurley"), ""); - RosterPacket.Item item = new RosterPacket.Item("joe@example.com", "joe stevens"); + RosterPacket.Item item = new RosterPacket.Item(JidCreate.from("joe@example.com"), "joe stevens"); item.addGroupName("friends"); item.addGroupName("partners"); store.addEntry(item, ""); - item = new RosterPacket.Item("higgins@example.com", "higgins mcmann"); + item = new RosterPacket.Item(JidCreate.from("higgins@example.com"), "higgins mcmann"); item.addGroupName("all"); item.addGroupName("friends"); store.addEntry(item, "v96"); diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStoreTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStoreTest.java index 96c7e17a9..d4ffd22c7 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStoreTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStoreTest.java @@ -34,6 +34,9 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.JidTestUtil; +import org.jxmpp.jid.impl.JidCreate; /** * Tests the implementation of {@link DirectoryRosterStore}. @@ -86,7 +89,7 @@ public class DirectoryRosterStoreTest { assertEquals("Initial roster version", "", store.getRosterVersion()); - String userName = "user@example.com"; + Jid userName = JidTestUtil.DUMMY_AT_EXAMPLE_ORG; final RosterPacket.Item item1 = new Item(userName, null); final String version1 = "1"; @@ -130,13 +133,13 @@ public class DirectoryRosterStoreTest { List entries = store.getEntries(); assertEquals("Number of entries", 1, entries.size()); - final RosterPacket.Item item3 = new Item("foobar@example.com", "Foo Bar"); + final RosterPacket.Item item3 = new Item(JidTestUtil.BARE_JID_1, "Foo Bar"); item3.addGroupName("The Foo Fighters"); item3.addGroupName("Bar Friends"); item3.setItemStatus(ItemStatus.unsubscribe); item3.setItemType(ItemType.both); - final RosterPacket.Item item4 = new Item("baz@example.com", "Baba Baz"); + final RosterPacket.Item item4 = new Item(JidTestUtil.BARE_JID_2, "Baba Baz"); item4.addGroupName("The Foo Fighters"); item4.addGroupName("Bar Friends"); item4.setItemStatus(ItemStatus.subscribe); @@ -149,7 +152,7 @@ public class DirectoryRosterStoreTest { String version3 = "3"; store.resetEntries(items34, version3); - storedItem = store.getEntry("foobar@example.com"); + storedItem = store.getEntry(JidTestUtil.BARE_JID_1); assertNotNull("Added entry not found", storedItem); assertEquals("User of added entry", item3.getUser(), storedItem.getUser()); @@ -162,7 +165,7 @@ public class DirectoryRosterStoreTest { item3.getItemStatus(), storedItem.getItemStatus()); - storedItem = store.getEntry("baz@example.com"); + storedItem = store.getEntry(JidTestUtil.BARE_JID_2); assertNotNull("Added entry not found", storedItem); assertEquals("User of added entry", item4.getUser(), storedItem.getUser()); @@ -178,7 +181,7 @@ public class DirectoryRosterStoreTest { assertEquals("Number of entries", 2, entries.size()); String version4 = "4"; - store.removeEntry("baz@example.com", version4); + store.removeEntry(JidTestUtil.BARE_JID_2, version4); assertEquals("Removing entry sets version correctly", version4, store.getRosterVersion()); assertNull("Removed entry is gone", store.getEntry(userName)); @@ -195,7 +198,7 @@ public class DirectoryRosterStoreTest { File storeDir = tmpFolder.newFolder(); DirectoryRosterStore store = DirectoryRosterStore.init(storeDir); - String user = "../_#;\"'\\&@example.com"; + Jid user = JidCreate.from(".._#;'&@example.com"); String name = "\n../_#\0\t;\"'&@\\"; String group1 = "\t;\"'&@\\\n../_#\0"; String group2 = "#\0\t;\"'&@\\\n../_"; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java index d3cb72c44..60a98887b 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java @@ -46,7 +46,8 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate; import org.jivesoftware.smackx.jingleold.nat.TransportResolver; import org.jivesoftware.smackx.jingleold.packet.Jingle; import org.jivesoftware.smackx.jingleold.provider.JingleProvider; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.Jid; /** * Jingle is a session establishment protocol defined in (XEP-0166). @@ -216,18 +217,18 @@ public class JingleManager implements JingleSessionListener { Roster.getInstanceFor(connection).addRosterListener(new RosterListener() { - public void entriesAdded(Collection addresses) { + public void entriesAdded(Collection addresses) { } - public void entriesUpdated(Collection addresses) { + public void entriesUpdated(Collection addresses) { } - public void entriesDeleted(Collection addresses) { + public void entriesDeleted(Collection addresses) { } public void presenceChanged(Presence presence) { if (!presence.isAvailable()) { - String xmppAddress = presence.getFrom(); + Jid xmppAddress = presence.getFrom(); JingleSession aux = null; for (JingleSession jingleSession : jingleSessions) { if (jingleSession.getInitiator().equals(xmppAddress) || jingleSession.getResponder().equals(xmppAddress)) { @@ -314,7 +315,7 @@ public class JingleManager implements JingleSessionListener { * @throws XMPPException * @throws InterruptedException */ - public static boolean isServiceEnabled(XMPPConnection connection, String userID) throws XMPPException, SmackException, InterruptedException { + public static boolean isServiceEnabled(XMPPConnection connection, Jid userID) throws XMPPException, SmackException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(userID, Jingle.NAMESPACE); } @@ -518,12 +519,7 @@ public class JingleManager implements JingleSessionListener { * user. * @return The session on which the negotiation can be run. */ - public JingleSession createOutgoingJingleSession(String responder) throws XMPPException { - - if (XmppStringUtils.isFullJID(responder)) { - throw new IllegalArgumentException("The provided user id was not fully qualified"); - } - + public JingleSession createOutgoingJingleSession(FullJid responder) throws XMPPException { JingleSession session = new JingleSession(connection, (JingleSessionRequest) null, connection.getUser(), responder, jingleMediaManagers); triggerSessionCreated(session); diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java index d08dbb0b2..8e99d0fc3 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java @@ -49,6 +49,7 @@ import org.jivesoftware.smackx.jingleold.nat.TransportNegotiator; import org.jivesoftware.smackx.jingleold.nat.TransportResolver; import org.jivesoftware.smackx.jingleold.packet.Jingle; import org.jivesoftware.smackx.jingleold.packet.JingleError; +import org.jxmpp.jid.Jid; /** * An abstract Jingle session.

      This class contains some basic properties of @@ -69,9 +70,9 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList // non-static - private String initiator; // Who started the communication + private Jid initiator; // Who started the communication - private String responder; // The other endpoint + private Jid responder; // The other endpoint private String sid; // A unique id that identifies this session @@ -107,7 +108,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList * @param jingleMediaManagers * the jingleMediaManager */ - public JingleSession(XMPPConnection conn, String initiator, String responder, String sessionid, + public JingleSession(XMPPConnection conn, Jid initiator, Jid responder, String sessionid, List jingleMediaManagers) { super(); @@ -141,7 +142,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList * @param jingleMediaManagers * the jingleMediaManager */ - public JingleSession(XMPPConnection conn, JingleSessionRequest request, String initiator, String responder, + public JingleSession(XMPPConnection conn, JingleSessionRequest request, Jid initiator, Jid responder, List jingleMediaManagers) { this(conn, initiator, responder, generateSessionId(), jingleMediaManagers); //sessionRequest = request; // unused @@ -152,7 +153,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList * * @return the initiator */ - public String getInitiator() { + public Jid getInitiator() { return initiator; } @@ -166,7 +167,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList * @param initiator * the initiator to set */ - public void setInitiator(String initiator) { + public void setInitiator(Jid initiator) { this.initiator = initiator; } @@ -193,7 +194,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList * * @return the responder */ - public String getResponder() { + public Jid getResponder() { return responder; } @@ -203,7 +204,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList * @param responder * the receptor to set */ - public void setResponder(String responder) { + public void setResponder(Jid responder) { this.responder = responder; } @@ -450,8 +451,8 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList jout.setSid(getSid()); } - String me = getConnection().getUser(); - String other = getResponder().equals(me) ? getInitiator() : getResponder(); + Jid me = getConnection().getUser(); + Jid other = getResponder().equals(me) ? getInitiator() : getResponder(); if (jout.getTo() == null) { if (iq != null) { @@ -686,13 +687,13 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList if (packet instanceof IQ) { IQ iq = (IQ) packet; - String me = getConnection().getUser(); + Jid me = getConnection().getUser(); if (!iq.getTo().equals(me)) { return false; } - String other = getResponder().equals(me) ? getInitiator() : getResponder(); + Jid other = getResponder().equals(me) ? getInitiator() : getResponder(); if (iq.getFrom() == null || !iq.getFrom().equals(other == null ? "" : other)) { return false; @@ -706,7 +707,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList LOGGER.fine("Ignored Jingle(SID) " + sid + "|" + getSid() + " :" + iq.toXML()); return false; } - String ini = jin.getInitiator(); + Jid ini = jin.getInitiator(); if (!ini.equals(getInitiator())) { LOGGER.fine("Ignored Jingle(INI): " + iq.toXML()); return false; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionRequest.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionRequest.java index 5c51cc68b..d5f983534 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionRequest.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionRequest.java @@ -22,6 +22,7 @@ import java.util.logging.Logger; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smackx.jingleold.packet.Jingle; +import org.jxmpp.jid.Jid; /** * A Jingle session request. @@ -61,7 +62,7 @@ public class JingleSessionRequest { * @return Returns the fully-qualified jabber ID of the user that requested * this session. */ - public String getFrom() { + public Jid getFrom() { return jingle.getFrom(); } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportCandidate.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportCandidate.java index 43244ac7e..a47712eb8 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportCandidate.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportCandidate.java @@ -32,6 +32,7 @@ import java.util.logging.Logger; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smackx.jingleold.JingleSession; import org.jivesoftware.smackx.jingleold.nat.TransportResolverListener.Checker; +import org.jxmpp.jid.Jid; /** * Transport candidate. @@ -608,8 +609,8 @@ public abstract class TransportCandidate { public class CandidateEcho implements Runnable { DatagramSocket socket = null; - String localUser = null; - String remoteUser = null; + Jid localUser; + Jid remoteUser; String id = null; byte[] send = null; byte[] receive = null; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/Jingle.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/Jingle.java index 4669d977b..7e47ff069 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/Jingle.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/Jingle.java @@ -19,6 +19,7 @@ package org.jivesoftware.smackx.jingleold.packet; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.jingleold.JingleActionEnum; +import org.jxmpp.jid.Jid; import java.util.ArrayList; import java.util.Collections; @@ -51,9 +52,9 @@ public class Jingle extends IQ { private JingleActionEnum action; // The action associated to the Jingle - private String initiator; // The initiator as a "user@host/resource" + private Jid initiator; // The initiator as a "user@host/resource" - private String responder; // The responder + private Jid responder; // The responder // Sub-elements of a Jingle object. @@ -281,7 +282,7 @@ public class Jingle extends IQ { * * @return the initiator */ - public String getInitiator() { + public Jid getInitiator() { return initiator; } @@ -292,7 +293,7 @@ public class Jingle extends IQ { * * @param initiator the initiator to set */ - public void setInitiator(final String initiator) { + public void setInitiator(final Jid initiator) { this.initiator = initiator; } @@ -303,7 +304,7 @@ public class Jingle extends IQ { * * @return the responder */ - public String getResponder() { + public Jid getResponder() { return responder; } @@ -314,7 +315,7 @@ public class Jingle extends IQ { * * @param resp the responder to set */ - public void setResponder(final String resp) { + public void setResponder(final Jid resp) { responder = resp; } @@ -325,7 +326,7 @@ public class Jingle extends IQ { * @param initiator The initiator * @return A hash key */ - public static int getSessionHash(final String sid, final String initiator) { + public static int getSessionHash(final String sid, final Jid initiator) { final int PRIME = 31; int result = 1; result = PRIME * result + (initiator == null ? 0 : initiator.hashCode()); diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleProvider.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleProvider.java index 1a9a41e19..4aa971769 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleProvider.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleProvider.java @@ -22,12 +22,14 @@ import java.io.IOException; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider; +import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smackx.jingleold.JingleActionEnum; import org.jivesoftware.smackx.jingleold.packet.Jingle; import org.jivesoftware.smackx.jingleold.packet.JingleContent; import org.jivesoftware.smackx.jingleold.packet.JingleContentInfo; import org.jivesoftware.smackx.jingleold.packet.JingleDescription; import org.jivesoftware.smackx.jingleold.packet.JingleTransport; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -51,8 +53,8 @@ public class JingleProvider extends IQProvider { Jingle jingle = new Jingle(); String sid = ""; JingleActionEnum action; - String initiator = ""; - String responder = ""; + Jid initiator = null; + Jid responder = null; boolean done = false; JingleContent currentContent = null; @@ -70,8 +72,8 @@ public class JingleProvider extends IQProvider { // Get some attributes for the element sid = parser.getAttributeValue("", "sid"); action = JingleActionEnum.getAction(parser.getAttributeValue("", "action")); - initiator = parser.getAttributeValue("", "initiator"); - responder = parser.getAttributeValue("", "responder"); + initiator = ParserUtils.getJidAttribute(parser, "initiator"); + responder = ParserUtils.getJidAttribute(parser, "responder"); jingle.setSid(sid); jingle.setAction(action); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/WorkgroupInvitation.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/WorkgroupInvitation.java index fa0cb841c..f38b39661 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/WorkgroupInvitation.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/WorkgroupInvitation.java @@ -20,6 +20,8 @@ package org.jivesoftware.smackx.workgroup; import java.util.List; import java.util.Map; +import org.jxmpp.jid.Jid; + /** * An immutable class wrapping up the basic information which comprises a group chat invitation. * @@ -27,14 +29,14 @@ import java.util.Map; */ public class WorkgroupInvitation { - protected String uniqueID; + protected Jid uniqueID; protected String sessionID; - protected String groupChatName; - protected String issuingWorkgroupName; + protected Jid groupChatName; + protected Jid issuingWorkgroupName; protected String messageBody; - protected String invitationSender; + protected Jid invitationSender; protected Map> metaData; /** @@ -48,8 +50,8 @@ public class WorkgroupInvitation { * @param msgBody the body of the message which contained the invitation * @param from the user jid who issued the invitation, if known, null otherwise */ - public WorkgroupInvitation (String jid, String group, String workgroup, - String sessID, String msgBody, String from) { + public WorkgroupInvitation (Jid jid, Jid group, Jid workgroup, + String sessID, String msgBody, Jid from) { this(jid, group, workgroup, sessID, msgBody, from, null); } @@ -63,8 +65,8 @@ public class WorkgroupInvitation { * @param from the user jid who issued the invitation, if known, null otherwise * @param metaData the metadata sent with the invitation */ - public WorkgroupInvitation (String jid, String group, String workgroup, String sessID, String msgBody, - String from, Map> metaData) { + public WorkgroupInvitation (Jid jid, Jid group, Jid workgroup, String sessID, String msgBody, + Jid from, Map> metaData) { super(); this.uniqueID = jid; @@ -80,7 +82,7 @@ public class WorkgroupInvitation { * @return the jid string with which the issuing AgentSession or Workgroup instance * was created. */ - public String getUniqueID () { + public Jid getUniqueID () { return this.uniqueID; } @@ -96,14 +98,14 @@ public class WorkgroupInvitation { /** * @return the jid of the room to which the person is invited. */ - public String getGroupChatName () { + public Jid getGroupChatName () { return this.groupChatName; } /** * @return the name of the workgroup from which the invitation was issued. */ - public String getWorkgroupName () { + public Jid getWorkgroupName () { return this.issuingWorkgroupName; } @@ -117,7 +119,7 @@ public class WorkgroupInvitation { /** * @return the user who issued the invitation, or null if it wasn't known. */ - public String getInvitationSender () { + public Jid getInvitationSender () { return this.invitationSender; } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Agent.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Agent.java index 347f7554c..5370bc14e 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Agent.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Agent.java @@ -24,6 +24,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.IQ; +import org.jxmpp.jid.Jid; import java.util.Collection; @@ -34,9 +35,9 @@ import java.util.Collection; */ public class Agent { private XMPPConnection connection; - private String workgroupJID; + private Jid workgroupJID; - public static Collection getWorkgroups(String serviceJID, String agentJID, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public static Collection getWorkgroups(Jid serviceJID, Jid agentJID, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { AgentWorkgroups request = new AgentWorkgroups(agentJID); request.setTo(serviceJID); AgentWorkgroups response = (AgentWorkgroups) connection.createPacketCollectorAndSend(request).nextResultOrThrow(); @@ -46,7 +47,7 @@ public class Agent { /** * Constructs an Agent. */ - Agent(XMPPConnection connection, String workgroupJID) { + Agent(XMPPConnection connection, Jid workgroupJID) { this.connection = connection; this.workgroupJID = workgroupJID; } @@ -56,7 +57,7 @@ public class Agent { * * @return - the agents JID. */ - public String getUser() { + public Jid getUser() { return connection.getUser(); } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentRoster.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentRoster.java index a306faf3e..7f24ef1de 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentRoster.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentRoster.java @@ -26,6 +26,9 @@ import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.PacketTypeFilter; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Presence; +import org.jxmpp.jid.FullJid; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.parts.Resourcepart; import org.jxmpp.util.XmppStringUtils; import java.util.ArrayList; @@ -34,7 +37,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.logging.Logger; @@ -52,10 +54,10 @@ public class AgentRoster { private static final int EVENT_PRESENCE_CHANGED = 2; private XMPPConnection connection; - private String workgroupJID; + private Jid workgroupJID; private List entries; private List listeners; - private Map> presenceMap; + private final Map> presenceMap = new HashMap<>(); // The roster is marked as initialized when at least a single roster packet // has been recieved and processed. boolean rosterInitialized = false; @@ -67,12 +69,11 @@ public class AgentRoster { * @throws NotConnectedException * @throws InterruptedException */ - AgentRoster(XMPPConnection connection, String workgroupJID) throws NotConnectedException, InterruptedException { + AgentRoster(XMPPConnection connection, Jid workgroupJID) throws NotConnectedException, InterruptedException { this.connection = connection; this.workgroupJID = workgroupJID; entries = new ArrayList(); listeners = new ArrayList(); - presenceMap = new HashMap>(); // Listen for any roster packets. PacketFilter rosterFilter = new PacketTypeFilter(AgentStatusRequest.class); connection.addAsyncPacketListener(new AgentStatusListener(), rosterFilter); @@ -118,7 +119,7 @@ public class AgentRoster { if (entries.contains(jid)) { // Fire the agent added event listener.agentAdded(jid); - Map userPresences = presenceMap.get(jid); + Map userPresences = presenceMap.get(jid); if (userPresences != null) { Iterator presences = userPresences.values().iterator(); while (presences.hasNext()) { @@ -176,14 +177,14 @@ public class AgentRoster { * or "user@domain/resource"). * @return true if the XMPP address is an agent in the workgroup. */ - public boolean contains(String jid) { + public boolean contains(Jid jid) { if (jid == null) { return false; } synchronized (entries) { for (Iterator i = entries.iterator(); i.hasNext();) { String entry = i.next(); - if (entry.toLowerCase(Locale.US).equals(jid.toLowerCase())) { + if (entry.equals(jid)) { return true; } } @@ -200,9 +201,9 @@ public class AgentRoster { * @return the agent's current presence, or null if the agent is unavailable * or if no presence information is available.. */ - public Presence getPresence(String user) { - String key = getPresenceMapKey(user); - Map userPresences = presenceMap.get(key); + public Presence getPresence(Jid user) { + Jid key = getPresenceMapKey(user); + Map userPresences = presenceMap.get(key); if (userPresences == null) { Presence presence = new Presence(Presence.Type.unavailable); presence.setFrom(user); @@ -211,7 +212,7 @@ public class AgentRoster { else { // Find the resource with the highest priority // Might be changed to use the resource with the highest availability instead. - Iterator it = userPresences.keySet().iterator(); + Iterator it = userPresences.keySet().iterator(); Presence p; Presence presence = null; @@ -248,10 +249,10 @@ public class AgentRoster { * @param user the fully qualified xmpp ID, e.g. jdoe@example.com/Work. * @return the key to use in the presenceMap for the fully qualified xmpp ID. */ - private String getPresenceMapKey(String user) { - String key = user; + private Jid getPresenceMapKey(Jid user) { + Jid key = user; if (!contains(user)) { - key = XmppStringUtils.parseBareJid(user).toLowerCase(Locale.US); + key = user.asBareJidIfPossible(); } return key; } @@ -286,13 +287,13 @@ public class AgentRoster { private class PresencePacketListener implements PacketListener { public void processPacket(Stanza packet) { Presence presence = (Presence)packet; - String from = presence.getFrom(); + FullJid from = presence.getFrom().asFullJidIfPossible(); if (from == null) { // TODO Check if we need to ignore these presences or this is a server bug? - LOGGER.warning("Presence with no FROM: " + presence.toXML()); + LOGGER.warning("Presence with non full JID from: " + presence.toXML()); return; } - String key = getPresenceMapKey(from); + Jid key = getPresenceMapKey(from); // If an "available" packet, add it to the presence map. Each presence map will hold // for a particular user a map with the presence packets saved for each resource. @@ -308,10 +309,10 @@ public class AgentRoster { else if (!workgroupJID.equals(agentStatus.getWorkgroupJID())) { return; } - Map userPresences; + Map userPresences; // Get the user presence map if (presenceMap.get(key) == null) { - userPresences = new HashMap(); + userPresences = new HashMap<>(); presenceMap.put(key, userPresences); } else { @@ -319,13 +320,13 @@ public class AgentRoster { } // Add the new presence, using the resources as a key. synchronized (userPresences) { - userPresences.put(XmppStringUtils.parseResource(from), presence); + userPresences.put(from.getResourcepart(), presence); } // Fire an event. synchronized (entries) { for (Iterator i = entries.iterator(); i.hasNext();) { String entry = i.next(); - if (entry.toLowerCase(Locale.US).equals(XmppStringUtils.parseBareJid(key).toLowerCase())) { + if (entry.equals(key.asBareJidIfPossible())) { fireEvent(EVENT_PRESENCE_CHANGED, packet); } } @@ -334,9 +335,9 @@ public class AgentRoster { // If an "unavailable" packet, remove any entries in the presence map. else if (presence.getType() == Presence.Type.unavailable) { if (presenceMap.get(key) != null) { - Map userPresences = presenceMap.get(key); + Map userPresences = presenceMap.get(key); synchronized (userPresences) { - userPresences.remove(XmppStringUtils.parseResource(from)); + userPresences.remove(from.getResourcepart()); } if (userPresences.isEmpty()) { presenceMap.remove(key); @@ -346,7 +347,7 @@ public class AgentRoster { synchronized (entries) { for (Iterator i = entries.iterator(); i.hasNext();) { String entry = (String)i.next(); - if (entry.toLowerCase(Locale.US).equals(XmppStringUtils.parseBareJid(key).toLowerCase())) { + if (entry.equals(key.asBareJidIfPossible())) { fireEvent(EVENT_PRESENCE_CHANGED, packet); } } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java index 14dc11728..4a21a86d5 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java @@ -73,7 +73,8 @@ import org.jivesoftware.smackx.workgroup.packet.Transcripts; import org.jivesoftware.smackx.workgroup.settings.GenericSettings; import org.jivesoftware.smackx.workgroup.settings.SearchSettings; import org.jivesoftware.smackx.xdata.Form; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.parts.Resourcepart; /** * This class embodies the agent's active presence within a given workgroup. The application @@ -91,14 +92,14 @@ public class AgentSession { private XMPPConnection connection; - private String workgroupJID; + private Jid workgroupJID; private boolean online = false; private Presence.Mode presenceMode; private int maxChats; private final Map> metaData; - private Map queues; + private final Map queues = new HashMap<>(); private final List offerListeners; private final List invitationListeners; @@ -119,7 +120,7 @@ public class AgentSession { * authentication. * @param workgroupJID the fully qualified JID of the workgroup. */ - public AgentSession(String workgroupJID, XMPPConnection connection) { + public AgentSession(Jid workgroupJID, XMPPConnection connection) { // Login must have been done before passing in connection. if (!connection.isAuthenticated()) { throw new IllegalStateException("Must login to server before creating workgroup."); @@ -134,8 +135,6 @@ public class AgentSession { this.metaData = new HashMap>(); - this.queues = new HashMap(); - offerListeners = new ArrayList(); invitationListeners = new ArrayList(); queueUsersListeners = new ArrayList(); @@ -486,7 +485,7 @@ public class AgentSession { * @throws SmackException * @throws InterruptedException */ - public Transcripts getTranscripts(String userID) throws XMPPException, SmackException, InterruptedException { + public Transcripts getTranscripts(Jid userID) throws XMPPException, SmackException, InterruptedException { return transcriptManager.getTranscripts(workgroupJID, userID); } @@ -514,7 +513,7 @@ public class AgentSession { * @throws InterruptedException */ public Form getTranscriptSearchForm() throws XMPPException, SmackException, InterruptedException { - return transcriptSearchManager.getSearchForm(XmppStringUtils.parseDomain(workgroupJID)); + return transcriptSearchManager.getSearchForm(workgroupJID.asDomainBareJid()); } /** @@ -529,7 +528,7 @@ public class AgentSession { * @throws InterruptedException */ public ReportedData searchTranscripts(Form completedForm) throws XMPPException, SmackException, InterruptedException { - return transcriptSearchManager.submitSearch(XmppStringUtils.parseDomain(workgroupJID), + return transcriptSearchManager.submitSearch(workgroupJID.asDomainBareJid(), completedForm); } @@ -557,7 +556,7 @@ public class AgentSession { /** * @return the fully-qualified name of the workgroup for which this session exists */ - public String getWorkgroupJID() { + public Jid getWorkgroupJID() { return workgroupJID; } @@ -579,7 +578,7 @@ public class AgentSession { } public Iterator getQueues() { - return Collections.unmodifiableMap((new HashMap(queues))).values().iterator(); + return Collections.unmodifiableMap((new HashMap<>(queues))).values().iterator(); } public void addQueueUsersListener(QueueUsersListener listener) { @@ -668,8 +667,8 @@ public class AgentSession { } } - private void fireInvitationEvent(String groupChatJID, String sessionID, String body, - String from, Map> metaData) { + private void fireInvitationEvent(Jid groupChatJID, String sessionID, String body, + Jid from, Map> metaData) { WorkgroupInvitation invitation = new WorkgroupInvitation(connection.getUser(), groupChatJID, workgroupJID, sessionID, body, from, metaData); @@ -717,7 +716,7 @@ public class AgentSession { // check for different packet extensions to see what type of presence // packet it is. - String queueName = XmppStringUtils.parseResource(presence.getFrom()); + Resourcepart queueName = presence.getFrom().getResourceOrNull(); WorkgroupQueue queue = queues.get(queueName); // If there isn't already an entry for the queue, create a new one. if (queue == null) { diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Offer.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Offer.java index 363d92691..f31d4fb8b 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Offer.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/Offer.java @@ -21,6 +21,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Stanza; +import org.jxmpp.jid.Jid; import java.util.Date; import java.util.List; @@ -40,9 +41,9 @@ public class Offer { private AgentSession session; private String sessionID; - private String userJID; - private String userID; - private String workgroupName; + private Jid userJID; + private Jid userID; + private Jid workgroupName; private Date expiresDate; private Map> metaData; private OfferContent content; @@ -63,8 +64,8 @@ public class Offer { * @param content content of the offer. The content explains the reason for the offer * (e.g. user request, transfer) */ - Offer(XMPPConnection conn, AgentSession agentSession, String userID, - String userJID, String workgroupName, Date expiresDate, + Offer(XMPPConnection conn, AgentSession agentSession, Jid userID, + Jid userJID, Jid workgroupName, Date expiresDate, String sessionID, Map> metaData, OfferContent content) { this.connection = conn; @@ -110,7 +111,7 @@ public class Offer { * * @return the userID of the user from which the offer originates. */ - public String getUserID() { + public Jid getUserID() { return userID; } @@ -119,7 +120,7 @@ public class Offer { * * @return the user's JID. */ - public String getUserJID() { + public Jid getUserJID() { return userJID; } @@ -128,7 +129,7 @@ public class Offer { * * @return the name of the workgroup. */ - public String getWorkgroupName() { + public Jid getWorkgroupName() { return this.workgroupName; } @@ -195,7 +196,7 @@ public class Offer { */ private class RejectPacket extends IQ { - RejectPacket(String workgroup) { + RejectPacket(Jid workgroup) { super("offer-reject", "http://jabber.org/protocol/workgroup"); this.setTo(workgroup); this.setType(IQ.Type.set); @@ -214,7 +215,7 @@ public class Offer { */ private class AcceptPacket extends IQ { - AcceptPacket(String workgroup) { + AcceptPacket(Jid workgroup) { super("offer-accept", "http://jabber.org/protocol/workgroup"); this.setTo(workgroup); this.setType(IQ.Type.set); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/OfferConfirmation.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/OfferConfirmation.java index e526ca71e..d8743fd1d 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/OfferConfirmation.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/OfferConfirmation.java @@ -24,6 +24,7 @@ import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.SimpleIQ; import org.jivesoftware.smack.provider.IQProvider; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -53,7 +54,7 @@ public class OfferConfirmation extends SimpleIQ { } - public void notifyService(XMPPConnection con, String workgroup, String createdRoomName) throws NotConnectedException, InterruptedException { + public void notifyService(XMPPConnection con, Jid workgroup, String createdRoomName) throws NotConnectedException, InterruptedException { NotifyServicePacket packet = new NotifyServicePacket(workgroup, createdRoomName); con.sendPacket(packet); } @@ -100,7 +101,7 @@ public class OfferConfirmation extends SimpleIQ { private class NotifyServicePacket extends IQ { String roomName; - NotifyServicePacket(String workgroup, String roomName) { + NotifyServicePacket(Jid workgroup, String roomName) { super("offer-confirmation", "http://jabber.org/protocol/workgroup"); this.setTo(workgroup); this.setType(IQ.Type.result); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/RevokedOffer.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/RevokedOffer.java index b10a01f8a..2c9e7ce79 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/RevokedOffer.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/RevokedOffer.java @@ -19,6 +19,8 @@ package org.jivesoftware.smackx.workgroup.agent; import java.util.Date; +import org.jxmpp.jid.Jid; + /** * An immutable simple class to embody the information concerning a revoked offer, this is namely * the reason, the workgroup, the userJID, and the timestamp which the message was received.
      @@ -27,9 +29,9 @@ import java.util.Date; */ public class RevokedOffer { - private String userJID; - private String userID; - private String workgroupName; + private Jid userJID; + private Jid userID; + private Jid workgroupName; private String sessionID; private String reason; private Date timestamp; @@ -43,7 +45,7 @@ public class RevokedOffer { * @param reason the server issued message as to why this revocation was issued. * @param timestamp the timestamp at which the revocation was issued */ - RevokedOffer(String userJID, String userID, String workgroupName, String sessionID, + RevokedOffer(Jid userJID, Jid userID, Jid workgroupName, String sessionID, String reason, Date timestamp) { super(); @@ -55,21 +57,21 @@ public class RevokedOffer { this.timestamp = timestamp; } - public String getUserJID() { + public Jid getUserJID() { return userJID; } /** * @return the jid of the user for which this revocation was issued */ - public String getUserID() { + public Jid getUserID() { return this.userID; } /** * @return the fully qualified name of the workgroup */ - public String getWorkgroupName() { + public Jid getWorkgroupName() { return this.workgroupName; } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptManager.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptManager.java index f05d6c07c..44f47a40a 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptManager.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptManager.java @@ -23,11 +23,12 @@ import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException.XMPPErrorException; +import org.jxmpp.jid.Jid; /** * A TranscriptManager helps to retrieve the full conversation transcript of a given session - * {@link #getTranscript(String, String)} or to retrieve a list with the summary of all the - * conversations that a user had {@link #getTranscripts(String, String)}. + * {@link #getTranscript(Jid, String)} or to retrieve a list with the summary of all the + * conversations that a user had {@link #getTranscripts(Jid, Jid)}. * * @author Gaston Dombiak */ @@ -49,7 +50,7 @@ public class TranscriptManager { * @throws NotConnectedException * @throws InterruptedException */ - public Transcript getTranscript(String workgroupJID, String sessionID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public Transcript getTranscript(Jid workgroupJID, String sessionID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Transcript request = new Transcript(sessionID); request.setTo(workgroupJID); Transcript response = (Transcript) connection.createPacketCollectorAndSend(request).nextResultOrThrow(); @@ -68,7 +69,7 @@ public class TranscriptManager { * @throws NotConnectedException * @throws InterruptedException */ - public Transcripts getTranscripts(String workgroupJID, String userID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public Transcripts getTranscripts(Jid workgroupJID, Jid userID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Transcripts request = new Transcripts(userID); request.setTo(workgroupJID); Transcripts response = (Transcripts) connection.createPacketCollectorAndSend(request).nextResultOrThrow(); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptSearchManager.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptSearchManager.java index 2dfd15ee8..99415303f 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptSearchManager.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/TranscriptSearchManager.java @@ -25,11 +25,12 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.IQ; +import org.jxmpp.jid.DomainBareJid; /** * A TranscriptSearchManager helps to retrieve the form to use for searching transcripts - * {@link #getSearchForm(String)} or to submit a search form and return the results of - * the search {@link #submitSearch(String, Form)}. + * {@link #getSearchForm(DomainBareJid)} or to submit a search form and return the results of + * the search {@link #submitSearch(DomainBareJid, Form)}. * * @author Gaston Dombiak */ @@ -52,7 +53,7 @@ public class TranscriptSearchManager { * @throws NotConnectedException * @throws InterruptedException */ - public Form getSearchForm(String serviceJID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public Form getSearchForm(DomainBareJid serviceJID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { TranscriptSearch search = new TranscriptSearch(); search.setType(IQ.Type.get); search.setTo(serviceJID); @@ -75,7 +76,7 @@ public class TranscriptSearchManager { * @throws NotConnectedException * @throws InterruptedException */ - public ReportedData submitSearch(String serviceJID, Form completedForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public ReportedData submitSearch(DomainBareJid serviceJID, Form completedForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { TranscriptSearch search = new TranscriptSearch(); search.setType(IQ.Type.get); search.setTo(serviceJID); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/WorkgroupQueue.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/WorkgroupQueue.java index e4314f8ff..a22aa14c5 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/WorkgroupQueue.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/WorkgroupQueue.java @@ -25,6 +25,7 @@ import java.util.Locale; import java.util.Set; import org.jivesoftware.smackx.workgroup.QueueUser; +import org.jxmpp.jid.parts.Resourcepart; /** * A queue in a workgroup, which is a pool of agents that are routed a specific type of @@ -32,7 +33,7 @@ import org.jivesoftware.smackx.workgroup.QueueUser; */ public class WorkgroupQueue { - private String name; + private Resourcepart name; private Status status = Status.CLOSED; private int averageWaitTime = -1; @@ -47,7 +48,7 @@ public class WorkgroupQueue { * * @param name the name of the queue. */ - WorkgroupQueue(String name) { + WorkgroupQueue(Resourcepart name) { this.name = name; } @@ -56,7 +57,7 @@ public class WorkgroupQueue { * * @return the name of the queue. */ - public String getName() { + public Resourcepart getName() { return name; } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/AgentWorkgroups.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/AgentWorkgroups.java index 1b6b6029e..434b9200b 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/AgentWorkgroups.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/AgentWorkgroups.java @@ -19,6 +19,8 @@ package org.jivesoftware.smackx.workgroup.packet; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.provider.IQProvider; +import org.jivesoftware.smack.util.ParserUtils; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -37,7 +39,7 @@ import java.util.List; */ public class AgentWorkgroups extends IQ { - private String agentJID; + private Jid agentJID; private List workgroups; private AgentWorkgroups() { @@ -50,7 +52,7 @@ public class AgentWorkgroups extends IQ { * * @param agentJID the id of the agent to get his workgroups. */ - public AgentWorkgroups(String agentJID) { + public AgentWorkgroups(Jid agentJID) { this(); this.agentJID = agentJID; this.workgroups = new ArrayList(); @@ -63,13 +65,13 @@ public class AgentWorkgroups extends IQ { * @param agentJID the id of the agent that can work in the list of workgroups. * @param workgroups the list of workgroup JIDs where the agent can work. */ - public AgentWorkgroups(String agentJID, List workgroups) { + public AgentWorkgroups(Jid agentJID, List workgroups) { this(); this.agentJID = agentJID; this.workgroups = workgroups; } - public String getAgentJID() { + public Jid getAgentJID() { return agentJID; } @@ -103,7 +105,7 @@ public class AgentWorkgroups extends IQ { @Override public AgentWorkgroups parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { - String agentJID = parser.getAttributeValue("", "jid"); + final Jid agentJID = ParserUtils.getJidAttribute(parser); List workgroups = new ArrayList(); boolean done = false; diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/DepartQueuePacket.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/DepartQueuePacket.java index 40885d648..92bc0da47 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/DepartQueuePacket.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/DepartQueuePacket.java @@ -18,6 +18,7 @@ package org.jivesoftware.smackx.workgroup.packet; import org.jivesoftware.smack.packet.IQ; +import org.jxmpp.jid.Jid; /** * A IQ packet used to depart a workgroup queue. There are two cases for issuing a depart @@ -32,7 +33,7 @@ import org.jivesoftware.smack.packet.IQ; */ public class DepartQueuePacket extends IQ { - private String user; + private Jid user; private DepartQueuePacket() { super("depart-queue", "http://jabber.org/protocol/workgroup"); @@ -43,7 +44,7 @@ public class DepartQueuePacket extends IQ { * * @param workgroup the workgroup to depart. */ - public DepartQueuePacket(String workgroup) { + public DepartQueuePacket(Jid workgroup) { this(workgroup, null); } @@ -54,7 +55,7 @@ public class DepartQueuePacket extends IQ { * @param workgroup the workgroup to depart. * @param user the user to make depart from the queue. */ - public DepartQueuePacket(String workgroup, String user) { + public DepartQueuePacket(Jid workgroup, Jid user) { this(); this.user = user; diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java index f3c166fca..2429f2aea 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java @@ -27,6 +27,8 @@ import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smack.util.ParserUtils; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -59,9 +61,9 @@ public class OfferRequestProvider extends IQProvider { // throw exception } - String userJID = parser.getAttributeValue("", "jid"); + Jid userJID = ParserUtils.getJidAttribute(parser); // Default userID to the JID. - String userID = userJID; + Jid userID = userJID; while (!done) { eventType = parser.next(); @@ -79,7 +81,7 @@ public class OfferRequestProvider extends IQProvider { sessionID = parser.getAttributeValue("", "id"); } else if (UserID.ELEMENT_NAME.equals(elemName)) { - userID = parser.getAttributeValue("", "id"); + userID = ParserUtils.getJidAttribute(parser, "id"); } else if ("user-request".equals(elemName)) { content = UserRequest.getInstance(); @@ -113,13 +115,13 @@ public class OfferRequestProvider extends IQProvider { public static class OfferRequestPacket extends IQ { private int timeout; - private String userID; - private String userJID; + private Jid userID; + private Jid userJID; private Map> metaData; private String sessionID; private OfferContent content; - public OfferRequestPacket(String userJID, String userID, int timeout, Map> metaData, + public OfferRequestPacket(Jid userJID, Jid userID, int timeout, Map> metaData, String sessionID, OfferContent content) { super("offer", "http://jabber.org/protocol/workgroup"); @@ -137,7 +139,7 @@ public class OfferRequestProvider extends IQProvider { * * @return the user ID. */ - public String getUserID() { + public Jid getUserID() { return userID; } @@ -146,7 +148,7 @@ public class OfferRequestProvider extends IQProvider { * * @return the user JID. */ - public String getUserJID() { + public Jid getUserJID() { return userJID; } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider.java index d384347fb..297eee74a 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider.java @@ -21,6 +21,8 @@ import java.io.IOException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.provider.IQProvider; +import org.jivesoftware.smack.util.ParserUtils; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -34,9 +36,9 @@ public class OfferRevokeProvider extends IQProvider { @Override public OfferRevokePacket parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { // The parser will be positioned on the opening IQ tag, so get the JID attribute. - String userJID = parser.getAttributeValue("", "jid"); + Jid userJID = ParserUtils.getJidAttribute(parser); // Default the userID to the JID. - String userID = userJID; + Jid userID = userJID; String reason = null; String sessionID = null; boolean done = false; @@ -53,7 +55,7 @@ public class OfferRevokeProvider extends IQProvider { } else if ((eventType == XmlPullParser.START_TAG) && parser.getName().equals(UserID.ELEMENT_NAME)) { - userID = parser.getAttributeValue("", "id"); + userID = ParserUtils.getJidAttribute(parser, "id"); } else if ((eventType == XmlPullParser.END_TAG) && parser.getName().equals( "offer-revoke")) @@ -67,12 +69,12 @@ public class OfferRevokeProvider extends IQProvider { public class OfferRevokePacket extends IQ { - private String userJID; - private String userID; + private Jid userJID; + private Jid userID; private String sessionID; private String reason; - public OfferRevokePacket (String userJID, String userID, String cause, String sessionID) { + public OfferRevokePacket (Jid userJID, Jid userID, String cause, String sessionID) { super("offer-revoke", "http://jabber.org/protocol/workgroup"); this.userJID = userJID; this.userID = userID; @@ -80,11 +82,11 @@ public class OfferRevokeProvider extends IQProvider { this.sessionID = sessionID; } - public String getUserJID() { + public Jid getUserJID() { return userJID; } - public String getUserID() { + public Jid getUserID() { return this.userID; } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/Transcripts.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/Transcripts.java index 3cd6f74e2..867b8db06 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/Transcripts.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/Transcripts.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.TimeZone; import org.jivesoftware.smack.packet.IQ; +import org.jxmpp.jid.Jid; /** * Represents a list of conversation transcripts that a user had in all his history. Each @@ -40,7 +41,7 @@ public class Transcripts extends IQ { UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0")); } - private String userID; + private Jid userID; private List summaries; @@ -49,7 +50,7 @@ public class Transcripts extends IQ { * * @param userID the id of the user to get his conversations transcripts. */ - public Transcripts(String userID) { + public Transcripts(Jid userID) { this(userID, new ArrayList()); } @@ -60,7 +61,7 @@ public class Transcripts extends IQ { * anonymous users. * @param summaries the list of TranscriptSummaries. */ - public Transcripts(String userID, List summaries) { + public Transcripts(Jid userID, List summaries) { super("transcripts", "http://jabber.org/protocol/workgroup"); this.userID = userID; this.summaries = summaries; @@ -74,7 +75,7 @@ public class Transcripts extends IQ { * * @return the id of the user that was involved in the conversations. */ - public String getUserID() { + public Jid getUserID() { return userID; } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java index db4e0533c..cd748e391 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java @@ -18,6 +18,8 @@ package org.jivesoftware.smackx.workgroup.packet; import org.jivesoftware.smack.provider.IQProvider; +import org.jivesoftware.smack.util.ParserUtils; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -43,7 +45,7 @@ public class TranscriptsProvider extends IQProvider { @Override public Transcripts parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { - String userID = parser.getAttributeValue("", "userID"); + Jid userID = ParserUtils.getJidAttribute(parser, "userID"); List summaries = new ArrayList(); boolean done = false; diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/UserID.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/UserID.java index 145a0519d..64b517662 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/UserID.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/packet/UserID.java @@ -21,6 +21,8 @@ import java.io.IOException; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.provider.PacketExtensionProvider; +import org.jivesoftware.smack.util.ParserUtils; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -36,13 +38,13 @@ public class UserID implements PacketExtension { */ public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; - private String userID; + private Jid userID; - public UserID(String userID) { + public UserID(Jid userID) { this.userID = userID; } - public String getUserID() { + public Jid getUserID() { return this.userID; } @@ -69,7 +71,7 @@ public class UserID implements PacketExtension { @Override public UserID parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { - String userID = parser.getAttributeValue("", "id"); + Jid userID = ParserUtils.getJidAttribute(parser, "id"); // Advance to end of extension. parser.next(); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java index 5b7ae8b93..fedd40b0c 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java @@ -58,7 +58,8 @@ import org.jivesoftware.smackx.workgroup.settings.WorkgroupProperties; import org.jivesoftware.smackx.xdata.Form; import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.packet.DataForm; -import org.jxmpp.util.XmppStringUtils; +import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.Jid; /** * Provides workgroup services for users. Users can join the workgroup queue, depart the @@ -73,7 +74,7 @@ import org.jxmpp.util.XmppStringUtils; */ public class Workgroup { - private String workgroupJID; + private Jid workgroupJID; private XMPPConnection connection; private boolean inQueue; private CopyOnWriteArraySet invitationListeners; @@ -92,7 +93,7 @@ public class Workgroup { * @param connection an XMPP connection which must have already undergone a * successful login. */ - public Workgroup(String workgroupJID, XMPPConnection connection) { + public Workgroup(Jid workgroupJID, XMPPConnection connection) { // Login must have been done before passing in connection. if (!connection.isAuthenticated()) { throw new IllegalStateException("Must login to server before creating workgroup."); @@ -154,7 +155,7 @@ public class Workgroup { * * @return the name of the workgroup. */ - public String getWorkgroupJID() { + public Jid getWorkgroupJID() { return workgroupJID; } @@ -242,7 +243,7 @@ public class Workgroup { * possible. For example, when the user is logged in anonymously using a web client. * In that case the user ID might be a randomly generated value put into a persistent * cookie or a username obtained via the session. A userID can be explicitly - * passed in by using the {@link #joinQueue(Form, String)} method. When specified, + * passed in by using the {@link #joinQueue(Form, Jid)} method. When specified, * that userID will be used instead of the user's JID to track conversations. The * server will ignore a manually specified userID if the user's connection to the server * is not anonymous. @@ -280,7 +281,7 @@ public class Workgroup { * possible. For example, when the user is logged in anonymously using a web client. * In that case the user ID might be a randomly generated value put into a persistent * cookie or a username obtained via the session. A userID can be explicitly - * passed in by using the {@link #joinQueue(Form, String)} method. When specified, + * passed in by using the {@link #joinQueue(Form, Jid)} method. When specified, * that userID will be used instead of the user's JID to track conversations. The * server will ignore a manually specified userID if the user's connection to the server * is not anonymous. @@ -332,7 +333,7 @@ public class Workgroup { * @throws NotConnectedException * @throws InterruptedException */ - public void joinQueue(Form answerForm, String userID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + public void joinQueue(Form answerForm, Jid userID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { // If already in the queue ignore the join request. if (inQueue) { throw new IllegalStateException("Already in queue " + workgroupJID); @@ -380,7 +381,7 @@ public class Workgroup { * @throws SmackException * @throws InterruptedException */ - public void joinQueue(Map metadata, String userID) throws XMPPException, SmackException, InterruptedException { + public void joinQueue(Map metadata, Jid userID) throws XMPPException, SmackException, InterruptedException { // If already in the queue ignore the join request. if (inQueue) { throw new IllegalStateException("Already in queue " + workgroupJID); @@ -553,10 +554,10 @@ public class Workgroup { */ private class JoinQueuePacket extends IQ { - private String userID = null; + private Jid userID; private DataForm form; - public JoinQueuePacket(String workgroup, Form answerForm, String userID) { + public JoinQueuePacket(Jid workgroup, Form answerForm, Jid userID) { super("join-queue", "http://jabber.org/protocol/workgroup"); this.userID = userID; @@ -660,7 +661,7 @@ public class Workgroup { ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); try { - String workgroupService = XmppStringUtils.parseDomain(workgroupJID); + DomainBareJid workgroupService = workgroupJID.asDomainBareJid(); DiscoverInfo infoResult = discoManager.discoverInfo(workgroupService); return infoResult.containsFeature("jive:email:provider"); } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/DefaultMessageEventRequestListener.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/DefaultMessageEventRequestListener.java index 965d54619..7bd7c96ac 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/DefaultMessageEventRequestListener.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/DefaultMessageEventRequestListener.java @@ -18,6 +18,7 @@ package org.jivesoftware.smackx.xevent; import org.jivesoftware.smack.SmackException.NotConnectedException; +import org.jxmpp.jid.Jid; /** * @@ -30,24 +31,24 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; */ public class DefaultMessageEventRequestListener implements MessageEventRequestListener { - public void deliveredNotificationRequested(String from, String packetID, + public void deliveredNotificationRequested(Jid from, String packetID, MessageEventManager messageEventManager) throws NotConnectedException, InterruptedException { // Send to the message's sender that the message has been delivered messageEventManager.sendDeliveredNotification(from, packetID); } - public void displayedNotificationRequested(String from, String packetID, + public void displayedNotificationRequested(Jid from, String packetID, MessageEventManager messageEventManager) { } - public void composingNotificationRequested(String from, String packetID, + public void composingNotificationRequested(Jid from, String packetID, MessageEventManager messageEventManager) { } - public void offlineNotificationRequested(String from, String packetID, + public void offlineNotificationRequested(Jid from, String packetID, MessageEventManager messageEventManager) { } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java index 1856120cf..2b0e59cc3 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java @@ -37,6 +37,7 @@ import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smackx.xevent.packet.MessageEvent; +import org.jxmpp.jid.Jid; /** * @@ -166,7 +167,7 @@ public class MessageEventManager extends Manager { * Fires message event request listeners. */ private void fireMessageEventRequestListeners( - String from, + Jid from, String packetID, String methodName) { try { @@ -186,7 +187,7 @@ public class MessageEventManager extends Manager { * Fires message event notification listeners. */ private void fireMessageEventNotificationListeners( - String from, + Jid from, String packetID, String methodName) { try { @@ -210,7 +211,7 @@ public class MessageEventManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public void sendDeliveredNotification(String to, String packetID) throws NotConnectedException, InterruptedException { + public void sendDeliveredNotification(Jid to, String packetID) throws NotConnectedException, InterruptedException { // Create the message to send Message msg = new Message(to); // Create a MessageEvent Package and add it to the message @@ -230,7 +231,7 @@ public class MessageEventManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public void sendDisplayedNotification(String to, String packetID) throws NotConnectedException, InterruptedException { + public void sendDisplayedNotification(Jid to, String packetID) throws NotConnectedException, InterruptedException { // Create the message to send Message msg = new Message(to); // Create a MessageEvent Package and add it to the message @@ -250,7 +251,7 @@ public class MessageEventManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public void sendComposingNotification(String to, String packetID) throws NotConnectedException, InterruptedException { + public void sendComposingNotification(Jid to, String packetID) throws NotConnectedException, InterruptedException { // Create the message to send Message msg = new Message(to); // Create a MessageEvent Package and add it to the message @@ -270,7 +271,7 @@ public class MessageEventManager extends Manager { * @throws NotConnectedException * @throws InterruptedException */ - public void sendCancelledNotification(String to, String packetID) throws NotConnectedException, InterruptedException { + public void sendCancelledNotification(Jid to, String packetID) throws NotConnectedException, InterruptedException { // Create the message to send Message msg = new Message(to); // Create a MessageEvent Package and add it to the message diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventRequestListener.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventRequestListener.java index 71583a428..54a0c2ad9 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventRequestListener.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xevent/MessageEventRequestListener.java @@ -18,6 +18,7 @@ package org.jivesoftware.smackx.xevent; import org.jivesoftware.smack.SmackException.NotConnectedException; +import org.jxmpp.jid.Jid; /** * @@ -50,7 +51,7 @@ public interface MessageEventRequestListener { * @throws NotConnectedException * @throws InterruptedException */ - public void deliveredNotificationRequested(String from, String packetID, + public void deliveredNotificationRequested(Jid from, String packetID, MessageEventManager messageEventManager) throws NotConnectedException, InterruptedException; /** @@ -60,7 +61,7 @@ public interface MessageEventRequestListener { * @param packetID the id of the message that was sent. * @param messageEventManager the messageEventManager that fired the listener. */ - public void displayedNotificationRequested(String from, String packetID, + public void displayedNotificationRequested(Jid from, String packetID, MessageEventManager messageEventManager); /** @@ -71,7 +72,7 @@ public interface MessageEventRequestListener { * @param packetID the id of the message that was sent. * @param messageEventManager the messageEventManager that fired the listener. */ - public void composingNotificationRequested(String from, String packetID, + public void composingNotificationRequested(Jid from, String packetID, MessageEventManager messageEventManager); /** @@ -81,7 +82,7 @@ public interface MessageEventRequestListener { * @param packetID the id of the message that was sent. * @param messageEventManager the messageEventManager that fired the listener. */ - public void offlineNotificationRequested(String from, String packetID, + public void offlineNotificationRequested(Jid from, String packetID, MessageEventManager messageEventManager); } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RemoteRosterEntry.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RemoteRosterEntry.java index 6261360ec..e3910508d 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RemoteRosterEntry.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RemoteRosterEntry.java @@ -23,6 +23,8 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import org.jxmpp.jid.Jid; + /** * Represents a roster item, which consists of a JID and , their name and * the groups the roster item belongs to. This roster item does not belong @@ -34,7 +36,7 @@ import java.util.List; */ public class RemoteRosterEntry { - private String user; + private Jid user; private String name; private final List groupNames = new ArrayList(); @@ -46,7 +48,7 @@ public class RemoteRosterEntry { * @param groups the list of group names the entry will belong to, or null if the * the roster entry won't belong to a group. */ - public RemoteRosterEntry(String user, String name, String [] groups) { + public RemoteRosterEntry(Jid user, String name, String [] groups) { this.user = user; this.name = name; if (groups != null) { @@ -59,7 +61,7 @@ public class RemoteRosterEntry { * * @return the user. */ - public String getUser() { + public Jid getUser() { return user; } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeListener.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeListener.java index e53878ca3..bfbeefabb 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeListener.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeListener.java @@ -19,6 +19,8 @@ package org.jivesoftware.smackx.xroster; import java.util.Iterator; +import org.jxmpp.jid.Jid; + /** * * A listener that is fired anytime a roster exchange is received. @@ -34,6 +36,6 @@ public interface RosterExchangeListener { * @param remoteRosterEntries the entries sent by the user. The entries are instances of * RemoteRosterEntry. */ - public void entriesReceived(String from, Iterator remoteRosterEntries); + public void entriesReceived(Jid from, Iterator remoteRosterEntries); } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java index 3054026a7..d84dd2ed4 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java @@ -35,6 +35,7 @@ import org.jivesoftware.smack.roster.Roster; import org.jivesoftware.smack.roster.RosterEntry; import org.jivesoftware.smack.roster.RosterGroup; import org.jivesoftware.smackx.xroster.packet.RosterExchange; +import org.jxmpp.jid.Jid; /** * @@ -117,7 +118,7 @@ public class RosterExchangeManager { * @throws NotConnectedException * @throws InterruptedException */ - public void send(Roster roster, String targetUserID) throws NotConnectedException, InterruptedException { + public void send(Roster roster, Jid targetUserID) throws NotConnectedException, InterruptedException { // Create a new message to send the roster Message msg = new Message(targetUserID); // Create a RosterExchange Package and add it to the message @@ -137,7 +138,7 @@ public class RosterExchangeManager { * @throws NotConnectedException * @throws InterruptedException */ - public void send(RosterEntry rosterEntry, String targetUserID) throws NotConnectedException, InterruptedException { + public void send(RosterEntry rosterEntry, Jid targetUserID) throws NotConnectedException, InterruptedException { // Create a new message to send the roster Message msg = new Message(targetUserID); // Create a RosterExchange Package and add it to the message @@ -159,7 +160,7 @@ public class RosterExchangeManager { * @throws NotConnectedException * @throws InterruptedException */ - public void send(RosterGroup rosterGroup, String targetUserID) throws NotConnectedException, InterruptedException { + public void send(RosterGroup rosterGroup, Jid targetUserID) throws NotConnectedException, InterruptedException { // Create a new message to send the roster Message msg = new Message(targetUserID); // Create a RosterExchange Package and add it to the message @@ -177,7 +178,7 @@ public class RosterExchangeManager { /** * Fires roster exchange listeners. */ - private void fireRosterExchangeListeners(String from, Iterator remoteRosterEntries) { + private void fireRosterExchangeListeners(Jid from, Iterator remoteRosterEntries) { RosterExchangeListener[] listeners = null; synchronized (rosterExchangeListeners) { listeners = new RosterExchangeListener[rosterExchangeListeners.size()]; diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/provider/RosterExchangeProvider.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/provider/RosterExchangeProvider.java index 45fd9274e..c1c60c868 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/provider/RosterExchangeProvider.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/provider/RosterExchangeProvider.java @@ -21,8 +21,10 @@ import java.io.IOException; import java.util.ArrayList; import org.jivesoftware.smack.provider.PacketExtensionProvider; +import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smackx.xroster.RemoteRosterEntry; import org.jivesoftware.smackx.xroster.packet.RosterExchange; +import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -49,7 +51,7 @@ public class RosterExchangeProvider extends PacketExtensionProvider groupsName = new ArrayList(); while (!done) { @@ -59,7 +61,7 @@ public class RosterExchangeProvider extends PacketExtensionProvider(); // Initialize the variables from the parsed XML - jid = parser.getAttributeValue("", "jid"); + jid = ParserUtils.getJidAttribute(parser); name = parser.getAttributeValue("", "name"); } if (parser.getName().equals("group")) { diff --git a/smack-sasl-javax/src/main/java/org/jivesoftware/smack/sasl/javax/SASLJavaXMechanism.java b/smack-sasl-javax/src/main/java/org/jivesoftware/smack/sasl/javax/SASLJavaXMechanism.java index c319433b4..8a2848a3f 100644 --- a/smack-sasl-javax/src/main/java/org/jivesoftware/smack/sasl/javax/SASLJavaXMechanism.java +++ b/smack-sasl-javax/src/main/java/org/jivesoftware/smack/sasl/javax/SASLJavaXMechanism.java @@ -54,7 +54,7 @@ public abstract class SASLJavaXMechanism extends SASLMechanism { String[] mechanisms = { getName() }; Map props = getSaslProps(); try { - sc = Sasl.createSaslClient(mechanisms, null, "xmpp", getServerName(), props, + sc = Sasl.createSaslClient(mechanisms, null, "xmpp", getServerName().toString(), props, new CallbackHandler() { @Override public void handle(Callback[] callbacks) throws IOException, @@ -146,6 +146,6 @@ public abstract class SASLJavaXMechanism extends SASLMechanism { } protected String getServerName() { - return serviceName; + return serviceName.toString(); } } diff --git a/smack-sasl-javax/src/test/java/org/jivesoftware/smack/sasl/javax/SASLDigestMD5Test.java b/smack-sasl-javax/src/test/java/org/jivesoftware/smack/sasl/javax/SASLDigestMD5Test.java index 489c6ff3a..125aa3699 100644 --- a/smack-sasl-javax/src/test/java/org/jivesoftware/smack/sasl/javax/SASLDigestMD5Test.java +++ b/smack-sasl-javax/src/test/java/org/jivesoftware/smack/sasl/javax/SASLDigestMD5Test.java @@ -20,6 +20,7 @@ import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.sasl.DigestMd5SaslTest; import org.junit.Test; +import org.jxmpp.stringprep.XmppStringprepException; public class SASLDigestMD5Test extends DigestMd5SaslTest { @@ -28,7 +29,7 @@ public class SASLDigestMD5Test extends DigestMd5SaslTest { } @Test - public void testDigestMD5() throws NotConnectedException, SmackException, InterruptedException { + public void testDigestMD5() throws NotConnectedException, SmackException, InterruptedException, XmppStringprepException { runTest(); } } diff --git a/smack-sasl-provided/src/test/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Test.java b/smack-sasl-provided/src/test/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Test.java index 425473945..75f1c8d03 100644 --- a/smack-sasl-provided/src/test/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Test.java +++ b/smack-sasl-provided/src/test/java/org/jivesoftware/smack/sasl/provided/SASLDigestMD5Test.java @@ -20,6 +20,7 @@ import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.sasl.DigestMd5SaslTest; import org.junit.Test; +import org.jxmpp.stringprep.XmppStringprepException; public class SASLDigestMD5Test extends DigestMd5SaslTest { public SASLDigestMD5Test() { @@ -27,7 +28,7 @@ public class SASLDigestMD5Test extends DigestMd5SaslTest { } @Test - public void testDigestMD5() throws NotConnectedException, SmackException, InterruptedException { + public void testDigestMD5() throws NotConnectedException, SmackException, InterruptedException, XmppStringprepException { runTest(); } } diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 0b6b8881a..7add86c4b 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -74,6 +74,8 @@ import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.TLSUtils; import org.jivesoftware.smack.util.dns.HostAddress; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; import org.jxmpp.util.XmppStringUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -290,8 +292,9 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { * * @param jid the bare JID used by the client. * @param password the password or authentication token. + * @throws XmppStringprepException */ - public XMPPTCPConnection(CharSequence jid, String password) { + public XMPPTCPConnection(CharSequence jid, String password) throws XmppStringprepException { this(XmppStringUtils.parseLocalpart(jid.toString()), password, XmppStringUtils.parseDomain(jid.toString())); } @@ -305,10 +308,11 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { * @param username * @param password * @param serviceName + * @throws XmppStringprepException */ - public XMPPTCPConnection(CharSequence username, String password, String serviceName) { + public XMPPTCPConnection(CharSequence username, String password, String serviceName) throws XmppStringprepException { this(XMPPTCPConnectionConfiguration.builder().setUsernameAndPassword(username, password).setServiceName( - serviceName).build()); + JidCreate.domainBareFrom(serviceName)).build()); } @Override @@ -728,7 +732,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { final HostnameVerifier verifier = getConfiguration().getHostnameVerifier(); if (verifier == null) { throw new IllegalStateException("No HostnameVerifier set. Use connectionConfiguration.setHostnameVerifier() to configure."); - } else if (!verifier.verify(getServiceName(), sslSocket.getSession())) { + } else if (!verifier.verify(getServiceName().toString(), sslSocket.getSession())) { throw new CertificateException("Hostname verification of certificate failed. Certificate does not authenticate " + getServiceName()); } diff --git a/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/PacketWriterTest.java b/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/PacketWriterTest.java index 338c713e2..565100f27 100644 --- a/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/PacketWriterTest.java +++ b/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/PacketWriterTest.java @@ -25,6 +25,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.tcp.XMPPTCPConnection.PacketWriter; import org.junit.Test; +import org.jxmpp.stringprep.XmppStringprepException; import static org.junit.Assert.fail; @@ -41,10 +42,11 @@ public class PacketWriterTest { * @throws InterruptedException * @throws BrokenBarrierException * @throws NotConnectedException + * @throws XmppStringprepException */ @SuppressWarnings("javadoc") @Test - public void shouldBlockAndUnblockTest() throws InterruptedException, BrokenBarrierException, NotConnectedException { + public void shouldBlockAndUnblockTest() throws InterruptedException, BrokenBarrierException, NotConnectedException, XmppStringprepException { XMPPTCPConnection connection = new XMPPTCPConnection("user", "pass", "example.org"); final PacketWriter pw = connection.new PacketWriter(); connection.packetWriter = pw; diff --git a/version.gradle b/version.gradle index f4938188c..f8d21bc2f 100644 --- a/version.gradle +++ b/version.gradle @@ -2,7 +2,7 @@ allprojects { ext { shortVersion = '4.2.0-alpha1' isSnapshot = true - jxmppVersion = '0.4.2-beta1' + jxmppVersion = '0.5.0-alpha1' smackMinAndroidSdk = 8 } }