mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-21 22:02:06 +01:00
Use Jid (and subclasses) from jxmpp-jid
Fixes SMACK-634
This commit is contained in:
parent
0ee2d9ed1e
commit
5bb4727c57
180 changed files with 1510 additions and 1032 deletions
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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 "<Anonymous>@" + connection.getServiceName();
|
||||
} else {
|
||||
return user;
|
||||
logger.debug("({}) User logged in {}", connection.hashCode(), user.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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 <tt>null</tt> if
|
||||
* no specific address was provided.
|
||||
*/
|
||||
public String getReplyRoom() {
|
||||
// TODO should return BareJid
|
||||
public Jid getReplyRoom() {
|
||||
List<MultipleAddresses.Address> replyRoom = extension.getAddressesOfType(MultipleAddresses.Type.replyroom);
|
||||
return replyRoom.isEmpty() ? null : ((MultipleAddresses.Address) replyRoom.get(0)).getJid();
|
||||
}
|
||||
|
|
|
@ -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<String> to, Collection<String> cc, Collection<String> bcc) throws NoResponseException, XMPPErrorException, FeatureNotSupportedException, NotConnectedException, InterruptedException
|
||||
public static void send(XMPPConnection connection, Stanza packet, Collection<? extends Jid> to, Collection<? extends Jid> cc, Collection<? extends Jid> 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<String> to, Collection<String> cc, Collection<String> bcc,
|
||||
String replyTo, String replyRoom, boolean noReply) throws NoResponseException, XMPPErrorException, FeatureNotSupportedException, NotConnectedException, InterruptedException {
|
||||
public static void send(XMPPConnection connection, Stanza packet, Collection<? extends Jid> to, Collection<? extends Jid> cc, Collection<? extends Jid> 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<String> to = new ArrayList<String>(info.getTOAddresses().size());
|
||||
List<String> cc = new ArrayList<String>(info.getCCAddresses().size());
|
||||
List<Jid> to = new ArrayList<>(info.getTOAddresses().size());
|
||||
List<Jid> 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<String> to, Collection<String> cc, Collection<String> bcc) throws NotConnectedException, InterruptedException {
|
||||
Collection<? extends Jid> to, Collection<? extends Jid> cc, Collection<? extends Jid> 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<String> to,
|
||||
Collection<String> cc, Collection<String> bcc, String replyTo, String replyRoom, boolean noReply,
|
||||
String serviceAddress) throws NotConnectedException, InterruptedException {
|
||||
private static void sendThroughService(XMPPConnection connection, Stanza packet, Collection<? extends Jid> to,
|
||||
Collection<? extends Jid> cc, Collection<? extends Jid> 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<String> services = sdm.findServices(MultipleAddresses.NAMESPACE, true, true);
|
||||
List<DomainBareJid> services = sdm.findServices(MultipleAddresses.NAMESPACE, true, true);
|
||||
if (services.size() > 0) {
|
||||
return services.get(0);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 PacketExtensionProvider<MultipleA
|
|||
case MultipleAddresses.Address.ELEMENT:
|
||||
String typeString = parser.getAttributeValue("", "type");
|
||||
Type type = Type.valueOf(typeString);
|
||||
String jid = parser.getAttributeValue("", "jid");
|
||||
Jid jid = ParserUtils.getJidAttribute(parser, "jid");
|
||||
String node = parser.getAttributeValue("", "node");
|
||||
String desc = parser.getAttributeValue("", "desc");
|
||||
boolean delivered = "true".equals(parser.getAttributeValue("", "delivered"));
|
||||
|
|
|
@ -90,7 +90,7 @@ public class AMPManager {
|
|||
*/
|
||||
public static boolean isActionSupported(XMPPConnection connection, AMPExtension.Action action) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
String featureName = AMPExtension.NAMESPACE + "?action=" + action.toString();
|
||||
return isFeatureSupportedByServer(connection, featureName, AMPExtension.NAMESPACE);
|
||||
return isFeatureSupportedByServer(connection, featureName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,10 +108,10 @@ public class AMPManager {
|
|||
*/
|
||||
public static boolean isConditionSupported(XMPPConnection connection, String conditionName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
String featureName = AMPExtension.NAMESPACE + "?condition=" + conditionName;
|
||||
return isFeatureSupportedByServer(connection, featureName, AMPExtension.NAMESPACE);
|
||||
return isFeatureSupportedByServer(connection, featureName);
|
||||
}
|
||||
|
||||
private static boolean isFeatureSupportedByServer(XMPPConnection connection, String featureName, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(node, featureName);
|
||||
private static boolean isFeatureSupportedByServer(XMPPConnection connection, String featureName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return ServiceDiscoveryManager.getInstanceFor(connection).serverSupportsFeature(featureName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
|||
* <p>
|
||||
* There are two ways to add this listener. See
|
||||
* {@link BytestreamManager#addIncomingBytestreamListener(BytestreamListener)} and
|
||||
* {@link BytestreamManager#addIncomingBytestreamListener(BytestreamListener, String)} for further
|
||||
* {@link BytestreamManager#addIncomingBytestreamListener(BytestreamListener, org.jxmpp.jid.Jid)} for further
|
||||
* details.
|
||||
* <p>
|
||||
* {@link Socks5BytestreamListener} or {@link InBandBytestreamListener} provide a more specific
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.jivesoftware.smack.SmackException;
|
|||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* BytestreamManager provides a generic interface for bytestream managers.
|
||||
|
@ -58,14 +59,14 @@ public interface BytestreamManager {
|
|||
* <p>
|
||||
* Use this method if you are awaiting an incoming bytestream request from a specific user.
|
||||
* <p>
|
||||
* See {@link Socks5BytestreamManager#addIncomingBytestreamListener(BytestreamListener, String)}
|
||||
* and {@link InBandBytestreamManager#addIncomingBytestreamListener(BytestreamListener, String)}
|
||||
* See {@link Socks5BytestreamManager#addIncomingBytestreamListener(BytestreamListener, Jid)}
|
||||
* and {@link InBandBytestreamManager#addIncomingBytestreamListener(BytestreamListener, Jid)}
|
||||
* for further details.
|
||||
*
|
||||
* @param listener the listener to register
|
||||
* @param initiatorJID the JID of the user that wants to establish a bytestream
|
||||
*/
|
||||
public void addIncomingBytestreamListener(BytestreamListener listener, String initiatorJID);
|
||||
public void addIncomingBytestreamListener(BytestreamListener listener, Jid initiatorJID);
|
||||
|
||||
/**
|
||||
* Removes the listener for the given user.
|
||||
|
@ -82,10 +83,10 @@ public interface BytestreamManager {
|
|||
* since this method doesn't provide a way to tell the user something about the data to be sent.
|
||||
* <p>
|
||||
* To establish a bytestream after negotiation the kind of data to be sent (e.g. file transfer)
|
||||
* use {@link #establishSession(String, String)}.
|
||||
* use {@link #establishSession(Jid, String)}.
|
||||
* <p>
|
||||
* See {@link Socks5BytestreamManager#establishSession(String)} and
|
||||
* {@link InBandBytestreamManager#establishSession(String)} for further details.
|
||||
* See {@link Socks5BytestreamManager#establishSession(Jid)} and
|
||||
* {@link InBandBytestreamManager#establishSession(Jid)} for further details.
|
||||
*
|
||||
* @param targetJID the JID of the user a bytestream should be established
|
||||
* @return the session to send/receive data to/from the user
|
||||
|
@ -94,15 +95,15 @@ public interface BytestreamManager {
|
|||
* @throws InterruptedException if the thread was interrupted while waiting in a blocking
|
||||
* operation
|
||||
*/
|
||||
public BytestreamSession establishSession(String targetJID) throws XMPPException, IOException,
|
||||
public BytestreamSession establishSession(Jid targetJID) throws XMPPException, IOException,
|
||||
InterruptedException, SmackException;
|
||||
|
||||
/**
|
||||
* Establishes a bytestream with the given user and returns the session to send/receive data
|
||||
* to/from the user.
|
||||
* <p>
|
||||
* See {@link Socks5BytestreamManager#establishSession(String)} and
|
||||
* {@link InBandBytestreamManager#establishSession(String)} for further details.
|
||||
* See {@link Socks5BytestreamManager#establishSession(Jid)} and
|
||||
* {@link InBandBytestreamManager#establishSession(Jid)} for further details.
|
||||
*
|
||||
* @param targetJID the JID of the user a bytestream should be established
|
||||
* @param sessionID the session ID for the bytestream request
|
||||
|
@ -112,7 +113,7 @@ public interface BytestreamManager {
|
|||
* @throws InterruptedException if the thread was interrupted while waiting in a blocking
|
||||
* operation
|
||||
*/
|
||||
public BytestreamSession establishSession(String targetJID, String sessionID)
|
||||
public BytestreamSession establishSession(Jid targetJID, String sessionID)
|
||||
throws XMPPException, IOException, InterruptedException, SmackException;
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamRequest;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamRequest;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* BytestreamRequest provides an interface to handle incoming bytestream requests.
|
||||
|
@ -38,7 +39,7 @@ public interface BytestreamRequest {
|
|||
*
|
||||
* @return the sender of the bytestream open request
|
||||
*/
|
||||
public String getFrom();
|
||||
public Jid getFrom();
|
||||
|
||||
/**
|
||||
* Returns the session ID of the bytestream open request.
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
|
|||
* <p>
|
||||
* There are two ways to add this listener. See
|
||||
* {@link InBandBytestreamManager#addIncomingBytestreamListener(BytestreamListener)} and
|
||||
* {@link InBandBytestreamManager#addIncomingBytestreamListener(BytestreamListener, String)} for
|
||||
* {@link InBandBytestreamManager#addIncomingBytestreamListener(BytestreamListener, org.jxmpp.jid.Jid)} for
|
||||
* further details.
|
||||
*
|
||||
* @author Henning Staib
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
|||
import org.jivesoftware.smackx.bytestreams.BytestreamManager;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
|
||||
import org.jivesoftware.smackx.filetransfer.FileTransferManager;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* The InBandBytestreamManager class handles establishing In-Band Bytestreams as specified in the <a
|
||||
|
@ -55,16 +56,16 @@ import org.jivesoftware.smackx.filetransfer.FileTransferManager;
|
|||
* flow-control method like <a href="http://xmpp.org/extensions/xep-0079.html">Advanced Message
|
||||
* Processing</a>. To set the stanza that should be used invoke {@link #setStanza(StanzaType)}.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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)}.
|
||||
* <p>
|
||||
* 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)}.
|
||||
* <p>
|
||||
|
@ -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<String, BytestreamListener> userListeners = new ConcurrentHashMap<String, BytestreamListener>();
|
||||
private final Map<Jid, BytestreamListener> 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.
|
||||
* <p>
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
|
|||
* <p>
|
||||
* 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
|
||||
|
|
|
@ -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 <a
|
||||
|
@ -63,16 +66,16 @@ import org.jivesoftware.smackx.filetransfer.FileTransferManager;
|
|||
* The stream host is a specialized SOCKS5 proxy setup on a server, or, the initiator can act as the
|
||||
* stream host.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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)}.
|
||||
* <p>
|
||||
* 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)}.
|
||||
* <p>
|
||||
|
@ -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<String, BytestreamListener> userListeners = new ConcurrentHashMap<String, BytestreamListener>();
|
||||
private final Map<Jid, BytestreamListener> 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<String> proxyBlacklist = Collections.synchronizedList(new LinkedList<String>());
|
||||
private final Set<Jid> proxyBlacklist = Collections.synchronizedSet(new HashSet<Jid>());
|
||||
|
||||
/* 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.
|
||||
* <p>
|
||||
* 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<String> proxies = new ArrayList<String>();
|
||||
List<Jid> 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<String> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
private List<Jid> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection);
|
||||
|
||||
List<String> proxies = new ArrayList<String>();
|
||||
List<Jid> 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<StreamHost> determineStreamHostInfos(List<String> proxies) {
|
||||
private List<StreamHost> determineStreamHostInfos(List<Jid> proxies) {
|
||||
List<StreamHost> streamHosts = new ArrayList<StreamHost>();
|
||||
|
||||
// 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<StreamHost> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -54,7 +54,7 @@ import org.jivesoftware.smack.SmackException;
|
|||
* <p>
|
||||
* 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)}).
|
||||
* <p>
|
||||
* This Implementation has the following limitations:
|
||||
* <ul>
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Bytestream> {
|
|||
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<Bytestream> {
|
|||
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) {
|
||||
|
|
|
@ -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<String, NodeVerHash> JID_TO_NODEVER_CACHE = new LruCache<String, NodeVerHash>(10000);
|
||||
private static final LruCache<Jid, NodeVerHash> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<AdHocCommandInfo> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String, List<String>> services = new ExpirationCache<String, List<String>>(25,
|
||||
private Cache<String, List<DomainBareJid>> services = new ExpirationCache<>(25,
|
||||
24 * 60 * 60 * 1000);
|
||||
|
||||
/**
|
||||
|
@ -695,17 +697,17 @@ public class ServiceDiscoveryManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public List<String> findServices(String feature, boolean stopOnFirst, boolean useCache)
|
||||
public List<DomainBareJid> findServices(String feature, boolean stopOnFirst, boolean useCache)
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
List<String> serviceAddresses = null;
|
||||
String serviceName = connection().getServiceName();
|
||||
List<DomainBareJid> serviceAddresses = null;
|
||||
DomainBareJid serviceName = connection().getServiceName();
|
||||
if (useCache) {
|
||||
serviceAddresses = (List<String>) services.get(feature);
|
||||
serviceAddresses = services.get(feature);
|
||||
if (serviceAddresses != null) {
|
||||
return serviceAddresses;
|
||||
}
|
||||
}
|
||||
serviceAddresses = new LinkedList<String>();
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 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<DiscoverItems> {
|
|||
|
||||
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");
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
* <p>
|
||||
* 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,
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <b><i>PacketFilter</b></i> 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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<String, String> map = new HashMap<String, String>();
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.<p>
|
||||
*
|
||||
|
@ -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) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* Default implementation of the UserStatusListener interface.<p>
|
||||
*
|
||||
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)}.
|
||||
* <p>
|
||||
* 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<String, Presence> occupantsMap = new ConcurrentHashMap<String, Presence>();
|
||||
private final Map<FullJid, Presence> occupantsMap = new ConcurrentHashMap<>();
|
||||
|
||||
private final Set<InvitationRejectionListener> invitationRejectionListeners = new CopyOnWriteArraySet<InvitationRejectionListener>();
|
||||
private final Set<SubjectUpdatedListener> subjectUpdatedListeners = new CopyOnWriteArraySet<SubjectUpdatedListener>();
|
||||
|
@ -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 <a href="http://xmpp.org/extensions/xep-0045.html#enter">XEP-45 7.2 Entering a Room</a>
|
||||
*/
|
||||
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<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantVoice(Collection<Resourcepart> 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<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeVoice(Collection<Resourcepart> 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<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void banUsers(Collection<? extends Jid> 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<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantMembership(Collection<? extends Jid> 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<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeMembership(Collection<? extends Jid> 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<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantModerator(Collection<Resourcepart> 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<String> nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeModerator(Collection<Resourcepart> 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<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantOwnership(Collection<? extends Jid> 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<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeOwnership(Collection<? extends Jid> 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<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void grantAdmin(Collection<? extends Jid> 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<String> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
|
||||
public void revokeAdmin(Collection<? extends Jid> 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<String> jids, MUCAffiliation affiliation)
|
||||
private void changeAffiliationByAdmin(Collection<? extends Jid> 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<String> nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
private void changeRole(Collection<Resourcepart> 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<String> getOccupants() {
|
||||
return Collections.unmodifiableList(new ArrayList<String>(occupantsMap.keySet()));
|
||||
public List<FullJid> 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<Status> 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
|
||||
|
|
|
@ -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<String> joinedRooms = MultiUserChatManager.getInstanceFor(connection).getJoinedRooms();
|
||||
Set<BareJid> joinedRooms = MultiUserChatManager.getInstanceFor(connection).getJoinedRooms();
|
||||
List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>();
|
||||
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<InvitationListener> invitationsListeners = new CopyOnWriteArraySet<InvitationListener>();
|
||||
private final Set<String> joinedRooms = new HashSet<String>();
|
||||
private final Set<BareJid> 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<String, WeakReference<MultiUserChat>> multiUserChats = new HashMap<String, WeakReference<MultiUserChat>>();
|
||||
private final Map<BareJid, WeakReference<MultiUserChat>> 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.
|
||||
* <p>
|
||||
* 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<MultiUserChat> 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>(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<String> getJoinedRooms() {
|
||||
public Set<BareJid> getJoinedRooms() {
|
||||
return Collections.unmodifiableSet(joinedRooms);
|
||||
}
|
||||
|
||||
|
@ -201,15 +213,20 @@ public class MultiUserChatManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public List<String> getJoinedRooms(String user) throws NoResponseException, XMPPErrorException,
|
||||
public List<BareJid> 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<DiscoverItems.Item> items = result.getItems();
|
||||
List<String> answer = new ArrayList<String>(items.size());
|
||||
List<BareJid> 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<String> getServiceNames() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public List<DomainBareJid> 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<HostedRoom> getHostedRooms(String serviceName) throws NoResponseException, XMPPErrorException,
|
||||
public List<HostedRoom> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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()];
|
||||
|
|
|
@ -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).
|
||||
* <p>
|
||||
* 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 <code>ping</code> with the XMPP domain.
|
||||
* <p>
|
||||
* 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 <code>ping</code> with the XMPP domain.
|
||||
* <p>
|
||||
* 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 <code>ping</code> with the XMPP domain.
|
||||
* <p>
|
||||
* 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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<ItemEventListener<Item>, PacketListener> itemEventToListenerMap = new ConcurrentHashMap<ItemEventListener<Item>, PacketListener>();
|
||||
protected ConcurrentHashMap<ItemDeleteListener, PacketListener> itemDeleteToListenerMap = new ConcurrentHashMap<ItemDeleteListener, PacketListener>();
|
||||
|
@ -73,7 +74,7 @@ abstract public class Node
|
|||
*
|
||||
* For example, OpenFire requires the server to be prefixed by <b>pubsub</b>
|
||||
*/
|
||||
void setTo(String toAddress)
|
||||
void setTo(Jid toAddress)
|
||||
{
|
||||
to = toAddress;
|
||||
}
|
||||
|
|
|
@ -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<String, Node> nodeMap = new ConcurrentHashMap<String, Node>();
|
||||
|
||||
/**
|
||||
|
@ -59,11 +63,12 @@ final public class PubSubManager
|
|||
* name to <i>pubsub</i>
|
||||
*
|
||||
* @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<PacketExtension> extList, PubSubNamespace ns) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
|
||||
static PubSub sendPubsubPacket(XMPPConnection con, Jid to, Type type, List<PacketExtension> extList, PubSubNamespace ns) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
|
||||
{
|
||||
PubSub pubSub = new PubSub(to, type, ns);
|
||||
for (PacketExtension pe : extList) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<String> getSearchServices() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public List<DomainBareJid> getSearchServices() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
|
||||
return discoManager.findServices(UserSearch.NAMESPACE, false, false);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue