Use Jid (and subclasses) from jxmpp-jid

Fixes SMACK-634
filetransferTypos
Florian Schmaus 8 years ago
parent 0ee2d9ed1e
commit 5bb4727c57
  1. 7
      smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java
  2. 3
      smack-core/build.gradle
  3. 17
      smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
  4. 9
      smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java
  5. 7
      smack-core/src/main/java/org/jivesoftware/smack/SmackException.java
  6. 6
      smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
  7. 9
      smack-core/src/main/java/org/jivesoftware/smack/debugger/AbstractDebugger.java
  8. 3
      smack-core/src/main/java/org/jivesoftware/smack/debugger/SmackDebugger.java
  9. 42
      smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java
  10. 26
      smack-core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java
  11. 12
      smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java
  12. 10
      smack-core/src/main/java/org/jivesoftware/smack/packet/Bind.java
  13. 7
      smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java
  14. 52
      smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java
  15. 5
      smack-core/src/main/java/org/jivesoftware/smack/provider/BindIQProvider.java
  16. 13
      smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java
  17. 13
      smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
  18. 24
      smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java
  19. 32
      smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java
  20. 31
      smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java
  21. 19
      smack-core/src/test/java/org/jivesoftware/smack/filters/FromMatchesFilterTest.java
  22. 30
      smack-core/src/test/java/org/jivesoftware/smack/packet/IQResponseTest.java
  23. 6
      smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java
  24. 3
      smack-core/src/test/java/org/jivesoftware/smack/sasl/core/SCRAMSHA1MechanismTest.java
  25. 2
      smack-core/src/test/java/org/jivesoftware/smack/test/util/WaitForPacketListener.java
  26. 15
      smack-debug-slf4j/src/main/java/org/jivesoftware/smackx/debugger/slf4j/SLF4JSmackDebugger.java
  27. 13
      smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebugger.java
  28. 13
      smack-debug/src/main/java/org/jivesoftware/smackx/debugger/LiteDebugger.java
  29. 3
      smack-experimental/src/main/java/org/jivesoftware/smackx/hoxt/HOXTManager.java
  30. 4
      smack-experimental/src/test/java/org/jivesoftware/smackx/carbons/CarbonTest.java
  31. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientInfo.java
  32. 55
      smack-extensions/src/main/java/org/jivesoftware/smackx/address/MultipleRecipientManager.java
  33. 9
      smack-extensions/src/main/java/org/jivesoftware/smackx/address/packet/MultipleAddresses.java
  34. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/address/provider/MultipleAddressesProvider.java
  35. 8
      smack-extensions/src/main/java/org/jivesoftware/smackx/amp/AMPManager.java
  36. 2
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/BytestreamListener.java
  37. 21
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/BytestreamManager.java
  38. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/BytestreamRequest.java
  39. 2
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamListener.java
  40. 19
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java
  41. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequest.java
  42. 7
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java
  43. 2
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamListener.java
  44. 41
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java
  45. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamRequest.java
  46. 6
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java
  47. 2
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java
  48. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Utils.java
  49. 31
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java
  50. 10
      smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/provider/BytestreamsProvider.java
  51. 18
      smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java
  52. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommand.java
  53. 13
      smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java
  54. 9
      smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommand.java
  55. 7
      smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java
  56. 7
      smack-extensions/src/main/java/org/jivesoftware/smackx/commands/packet/AdHocCommandData.java
  57. 32
      smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java
  58. 7
      smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverItems.java
  59. 6
      smack-extensions/src/main/java/org/jivesoftware/smackx/disco/provider/DiscoverItemsProvider.java
  60. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java
  61. 8
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java
  62. 13
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java
  63. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java
  64. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java
  65. 7
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IBBTransferNegotiator.java
  66. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java
  67. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java
  68. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java
  69. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java
  70. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java
  71. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java
  72. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java
  73. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java
  74. 10
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Affiliate.java
  75. 34
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultParticipantStatusListener.java
  76. 6
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultUserStatusListener.java
  77. 11
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/HostedRoom.java
  78. 150
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java
  79. 55
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java
  80. 25
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Occupant.java
  81. 34
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/ParticipantStatusListener.java
  82. 15
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java
  83. 4
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/SubjectUpdatedListener.java
  84. 6
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/UserStatusListener.java
  85. 26
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java
  86. 11
      smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java
  87. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageHeader.java
  88. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPListener.java
  89. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPManager.java
  90. 23
      smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java
  91. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java
  92. 18
      smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/PrivacyItem.java
  93. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java
  94. 15
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java
  95. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java
  96. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java
  97. 3
      smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java
  98. 7
      smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java
  99. 7
      smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearchManager.java
  100. 5
      smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -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;

@ -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'

@ -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.
* </p>
*/
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<HostAddress> 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());

@ -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();
}

@ -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;
}
}

@ -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

@ -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.

@ -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.

@ -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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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 <code>null</code> 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;
}
}

@ -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));
}
}

@ -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);
}

@ -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);
}

@ -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);
}

@ -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<String, PacketExtension> 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 <tt>null</tt> 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 <tt>null</tt> 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;
}

@ -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 = Bind.newSet(parser.nextText());
break;
case "jid":
bind = Bind.newResult(parser.nextText());
FullJid fullJid = JidCreate.fullFrom(parser.nextText());
bind = Bind.newResult(fullJid);
break;
}
break;

@ -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;
* <li>{@link #getName()} -- returns the common name of the SASL mechanism.</li>
* </ul>
* Subclasses will likely want to implement their own versions of these methods:
* <li>{@link #authenticate(String, String, String, String)} -- Initiate authentication stanza using the
* <li>{@link #authenticate(String, String, DomainBareJid, String)} -- Initiate authentication stanza using the
* deprecated method.</li>
* <li>{@link #authenticate(String, String, CallbackHandler)} -- Initiate authentication stanza
* <li>{@link #authenticate(String, DomainBareJid, CallbackHandler)} -- Initiate authentication stanza
* using the CallbackHandler method.</li>
* <li>{@link #challengeReceived(String, boolean)} -- Handle a challenge from the server.</li>
* </ul>
@ -104,7 +105,7 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
/**
* 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<SASLMechanism> {
/**
* Builds and sends the <tt>auth</tt> 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<SASLMechanism> {
* @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<SASLMechanism> {
* @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;

@ -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) {

@ -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.
*

@ -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());
}

@ -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<TopLevelStreamElement> queue = new LinkedBlockingQueue<TopLevelStreamElement>();
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;
}

@ -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()

@ -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 <a href="http://xmpp.org/rfcs/rfc3920.html#stanzas-semantics-iq"
* >RFC3920: IQ Semantics</a> 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 <a href="http://xmpp.org/rfcs/rfc3920.html#stanzas-semantics-iq"
* >RFC3920: IQ Semantics</a> 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 {