mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02: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
|
@ -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;
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.vcardtemp.packet.VCard;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
public class VCardManager extends Manager {
|
||||
public static final String NAMESPACE = VCard.NAMESPACE;
|
||||
|
@ -71,10 +73,10 @@ public class VCardManager extends Manager {
|
|||
* @throws NoResponseException
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
* @deprecated use {@link #isSupported(String)} instead.
|
||||
* @deprecated use {@link #isSupported(Jid)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isSupported(String jid, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public static boolean isSupported(Jid jid, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return VCardManager.getInstanceFor(connection).isSupported(jid);
|
||||
}
|
||||
|
||||
|
@ -117,7 +119,7 @@ public class VCardManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public VCard loadVCard(String bareJid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public VCard loadVCard(BareJid bareJid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
VCard vcardRequest = new VCard();
|
||||
vcardRequest.setTo(bareJid);
|
||||
VCard result = connection().createPacketCollectorAndSend(vcardRequest).nextResultOrThrow();
|
||||
|
@ -134,7 +136,7 @@ public class VCardManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public boolean isSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public boolean isSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.jivesoftware.smack.packet.IQ;
|
|||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
import org.jivesoftware.smackx.vcardtemp.VCardManager;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
|
||||
/**
|
||||
* A VCard class for use with the
|
||||
|
@ -551,10 +552,10 @@ public class VCard extends IQ {
|
|||
* @throws NoResponseException if there was no response from the server.
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
* @deprecated use {@link VCardManager#loadVCard(String)} instead.
|
||||
* @deprecated use {@link VCardManager#loadVCard(BareJid)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public void load(XMPPConnection connection, String user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public void load(XMPPConnection connection, BareJid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
VCard result = VCardManager.getInstanceFor(connection).loadVCard(user);
|
||||
copyFieldsFrom(result);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.jivesoftware.smack.XMPPConnectionRegistry;
|
|||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
public class XDataManager extends Manager {
|
||||
|
||||
|
@ -80,7 +81,7 @@ public class XDataManager extends Manager {
|
|||
* @see <a href="http://xmpp.org/extensions/xep-0004.html#disco">XEP-0004: Data Forms § 6. Service Discovery</a>
|
||||
* @since 4.1
|
||||
*/
|
||||
public boolean isSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public boolean isSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, NAMESPACE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
|||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -130,7 +131,7 @@ public class XHTMLManager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public static boolean isServiceEnabled(XMPPConnection connection, String userID)
|
||||
public static boolean isServiceEnabled(XMPPConnection connection, Jid userID)
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(userID, XHTMLExtension.NAMESPACE);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ import org.jivesoftware.smack.packet.IQ;
|
|||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
|
@ -35,8 +37,8 @@ import org.powermock.reflect.Whitebox;
|
|||
*/
|
||||
public class CloseListenerTest {
|
||||
|
||||
String initiatorJID = "initiator@xmpp-server/Smack";
|
||||
String targetJID = "target@xmpp-server/Smack";
|
||||
static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
|
||||
/**
|
||||
* If a close request to an unknown session is received it should be replied
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.jivesoftware.smack.packet.XMPPError;
|
|||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
|
@ -36,8 +38,8 @@ import org.powermock.reflect.Whitebox;
|
|||
*/
|
||||
public class DataListenerTest {
|
||||
|
||||
String initiatorJID = "initiator@xmpp-server/Smack";
|
||||
String targetJID = "target@xmpp-server/Smack";
|
||||
static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
|
||||
/**
|
||||
* If a data packet of an unknown session is received it should be replied
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.jivesoftware.smack.packet.EmptyResultIQ;
|
|||
import org.jivesoftware.smack.packet.ErrorIQ;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* Utility methods to create packets.
|
||||
|
@ -36,7 +37,7 @@ public class IBBPacketUtils {
|
|||
* @param xmppError the XMPP error
|
||||
* @return an error IQ
|
||||
*/
|
||||
public static IQ createErrorIQ(String from, String to, XMPPError xmppError) {
|
||||
public static IQ createErrorIQ(Jid from, Jid to, XMPPError xmppError) {
|
||||
IQ errorIQ = new ErrorIQ(xmppError);
|
||||
errorIQ.setType(IQ.Type.error);
|
||||
errorIQ.setFrom(from);
|
||||
|
@ -51,7 +52,7 @@ public class IBBPacketUtils {
|
|||
* @param to the recipients JID
|
||||
* @return a result IQ
|
||||
*/
|
||||
public static IQ createResultIQ(String from, String to) {
|
||||
public static IQ createResultIQ(Jid from, Jid to) {
|
||||
IQ result = new EmptyResultIQ();
|
||||
result.setType(IQ.Type.result);
|
||||
result.setFrom(from);
|
||||
|
|
|
@ -35,6 +35,9 @@ import org.jivesoftware.util.Protocol;
|
|||
import org.jivesoftware.util.Verification;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.DomainBareJid;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
|
||||
/**
|
||||
* Test for InBandBytestreamManager.
|
||||
|
@ -44,9 +47,9 @@ import org.junit.Test;
|
|||
public class InBandBytestreamManagerTest {
|
||||
|
||||
// settings
|
||||
String initiatorJID = "initiator@xmpp-server/Smack";
|
||||
String targetJID = "target@xmpp-server/Smack";
|
||||
String xmppServer = "xmpp-server";
|
||||
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
|
||||
String sessionID = "session_id";
|
||||
|
||||
// protocol verifier
|
||||
|
@ -99,7 +102,7 @@ public class InBandBytestreamManagerTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoking {@link InBandBytestreamManager#establishSession(String)} should
|
||||
* Invoking {@link InBandBytestreamManager#establishSession(org.jxmpp.jid.Jid)} should
|
||||
* throw an exception if the given target does not support in-band
|
||||
* bytestream.
|
||||
* @throws SmackException
|
||||
|
|
|
@ -28,6 +28,8 @@ import org.jivesoftware.smack.packet.XMPPError;
|
|||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
/**
|
||||
|
@ -37,8 +39,8 @@ import org.mockito.ArgumentCaptor;
|
|||
*/
|
||||
public class InBandBytestreamRequestTest {
|
||||
|
||||
String initiatorJID = "initiator@xmpp-server/Smack";
|
||||
String targetJID = "target@xmpp-server/Smack";
|
||||
static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
String sessionID = "session_id";
|
||||
|
||||
XMPPConnection connection;
|
||||
|
|
|
@ -40,6 +40,9 @@ import org.jivesoftware.util.Protocol;
|
|||
import org.jivesoftware.util.Verification;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.DomainBareJid;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
/**
|
||||
|
@ -52,9 +55,9 @@ import org.powermock.reflect.Whitebox;
|
|||
public class InBandBytestreamSessionMessageTest {
|
||||
|
||||
// settings
|
||||
String initiatorJID = "initiator@xmpp-server/Smack";
|
||||
String targetJID = "target@xmpp-server/Smack";
|
||||
String xmppServer = "xmpp-server";
|
||||
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
|
||||
String sessionID = "session_id";
|
||||
|
||||
int blockSize = 10;
|
||||
|
|
|
@ -40,6 +40,9 @@ import org.jivesoftware.util.Protocol;
|
|||
import org.jivesoftware.util.Verification;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.DomainBareJid;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
/**
|
||||
|
@ -53,9 +56,9 @@ import org.powermock.reflect.Whitebox;
|
|||
public class InBandBytestreamSessionTest {
|
||||
|
||||
// settings
|
||||
String initiatorJID = "initiator@xmpp-server/Smack";
|
||||
String targetJID = "target@xmpp-server/Smack";
|
||||
String xmppServer = "xmpp-server";
|
||||
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
|
||||
String sessionID = "session_id";
|
||||
|
||||
int blockSize = 10;
|
||||
|
|
|
@ -28,6 +28,9 @@ import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
|
|||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
|
@ -38,8 +41,8 @@ import org.powermock.reflect.Whitebox;
|
|||
*/
|
||||
public class InitiationListenerTest {
|
||||
|
||||
String initiatorJID = "initiator@xmpp-server/Smack";
|
||||
String targetJID = "target@xmpp-server/Smack";
|
||||
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
String sessionID = "session_id";
|
||||
|
||||
XMPPConnection connection;
|
||||
|
@ -190,7 +193,7 @@ public class InitiationListenerTest {
|
|||
|
||||
// add listener for request of user "other_initiator"
|
||||
InBandBytestreamListener listener = mock(InBandBytestreamListener.class);
|
||||
byteStreamManager.addIncomingBytestreamListener(listener, "other_" + initiatorJID);
|
||||
byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID));
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
@ -261,8 +264,8 @@ public class InitiationListenerTest {
|
|||
|
||||
// add listener for request of user "other_initiator"
|
||||
InBandBytestreamListener userRequestsListener = mock(InBandBytestreamListener.class);
|
||||
byteStreamManager.addIncomingBytestreamListener(userRequestsListener, "other_"
|
||||
+ initiatorJID);
|
||||
byteStreamManager.addIncomingBytestreamListener(userRequestsListener, JidCreate.from("other_"
|
||||
+ initiatorJID));
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
|
@ -74,8 +74,8 @@ public class CloseTest {
|
|||
.asString(outputProperties);
|
||||
|
||||
Close close = new Close("i781hf64");
|
||||
close.setFrom("romeo@montague.lit/orchard");
|
||||
close.setTo("juliet@capulet.lit/balcony");
|
||||
close.setFrom(JidCreate.from("romeo@montague.lit/orchard"));
|
||||
close.setTo(JidCreate.from("juliet@capulet.lit/balcony"));
|
||||
close.setStanzaId("us71g45j");
|
||||
|
||||
assertXMLEqual(control, close.toXML().toString());
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Properties;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
|
@ -70,8 +71,8 @@ public class DataTest {
|
|||
|
||||
DataPacketExtension dpe = new DataPacketExtension("i781hf64", 0, encodedData);
|
||||
Data data = new Data(dpe);
|
||||
data.setFrom("romeo@montague.lit/orchard");
|
||||
data.setTo("juliet@capulet.lit/balcony");
|
||||
data.setFrom(JidCreate.from("romeo@montague.lit/orchard"));
|
||||
data.setTo(JidCreate.from("juliet@capulet.lit/balcony"));
|
||||
data.setStanzaId("kr91n475");
|
||||
|
||||
assertXMLEqual(control, data.toXML().toString());
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Properties;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
|
@ -95,8 +96,8 @@ public class OpenTest {
|
|||
.asString(outputProperties);
|
||||
|
||||
Open open = new Open("i781hf64", 4096, StanzaType.IQ);
|
||||
open.setFrom("romeo@montague.lit/orchard");
|
||||
open.setTo("juliet@capulet.lit/balcony");
|
||||
open.setFrom(JidCreate.from("romeo@montague.lit/orchard"));
|
||||
open.setTo(JidCreate.from("juliet@capulet.lit/balcony"));
|
||||
open.setStanzaId("jn3h8g65");
|
||||
|
||||
assertXMLEqual(control, open.toXML().toString());
|
||||
|
|
|
@ -29,6 +29,10 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
|||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.DomainBareJid;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
|
@ -39,10 +43,10 @@ import org.powermock.reflect.Whitebox;
|
|||
*/
|
||||
public class InitiationListenerTest {
|
||||
|
||||
String initiatorJID = "initiator@xmpp-server/Smack";
|
||||
String targetJID = "target@xmpp-server/Smack";
|
||||
String xmppServer = "xmpp-server";
|
||||
String proxyJID = "proxy.xmpp-server";
|
||||
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
|
||||
static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
|
||||
String proxyAddress = "127.0.0.1";
|
||||
String sessionID = "session_id";
|
||||
|
||||
|
@ -169,7 +173,7 @@ public class InitiationListenerTest {
|
|||
|
||||
// add listener for request of user "other_initiator"
|
||||
Socks5BytestreamListener listener = mock(Socks5BytestreamListener.class);
|
||||
byteStreamManager.addIncomingBytestreamListener(listener, "other_" + initiatorJID);
|
||||
byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID));
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
@ -240,8 +244,8 @@ public class InitiationListenerTest {
|
|||
|
||||
// add listener for request of user "other_initiator"
|
||||
Socks5BytestreamListener userRequestsListener = mock(Socks5BytestreamListener.class);
|
||||
byteStreamManager.addIncomingBytestreamListener(userRequestsListener, "other_"
|
||||
+ initiatorJID);
|
||||
byteStreamManager.addIncomingBytestreamListener(userRequestsListener, JidCreate.from("other_"
|
||||
+ initiatorJID));
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
|
|
@ -50,6 +50,11 @@ import org.jivesoftware.util.Verification;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.DomainBareJid;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
/**
|
||||
* Test for Socks5BytestreamManager.
|
||||
|
@ -59,10 +64,10 @@ import org.junit.Test;
|
|||
public class Socks5ByteStreamManagerTest {
|
||||
|
||||
// settings
|
||||
String initiatorJID = "initiator@xmpp-server/Smack";
|
||||
String targetJID = "target@xmpp-server/Smack";
|
||||
String xmppServer = "xmpp-server";
|
||||
String proxyJID = "proxy.xmpp-server";
|
||||
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
|
||||
static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
|
||||
String proxyAddress = "127.0.0.1";
|
||||
String sessionID = "session_id";
|
||||
|
||||
|
@ -137,7 +142,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(String)} should throw an exception
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid)} should throw an exception
|
||||
* if the given target does not support SOCKS5 Bytestream.
|
||||
* @throws XMPPException
|
||||
*/
|
||||
|
@ -165,7 +170,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if XMPP
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if XMPP
|
||||
* server doesn't return any proxies.
|
||||
*/
|
||||
@Test
|
||||
|
@ -216,7 +221,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if no
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
|
||||
* proxy is a SOCKS5 proxy.
|
||||
*/
|
||||
@Test
|
||||
|
@ -254,7 +259,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
// build discover info for proxy containing information about NOT being a Socks5
|
||||
// proxy
|
||||
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
|
||||
Identity identity = new Identity("noproxy", proxyJID, "bytestreams");
|
||||
Identity identity = new Identity("noproxy", proxyJID.toString(), "bytestreams");
|
||||
proxyInfo.addIdentity(identity);
|
||||
|
||||
// return the proxy identity if proxy is queried
|
||||
|
@ -279,7 +284,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if no
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
|
||||
* SOCKS5 proxy can be found. If it turns out that a proxy is not a SOCKS5 proxy it should not
|
||||
* be queried again.
|
||||
*/
|
||||
|
@ -318,7 +323,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
// build discover info for proxy containing information about NOT being a Socks5
|
||||
// proxy
|
||||
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
|
||||
Identity identity = new Identity("noproxy", proxyJID, "bytestreams");
|
||||
Identity identity = new Identity("noproxy", proxyJID.toString(), "bytestreams");
|
||||
proxyInfo.addIdentity(identity);
|
||||
|
||||
// return the proxy identity if proxy is queried
|
||||
|
@ -370,7 +375,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if the
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
|
||||
* target does not accept a SOCKS5 Bytestream. See <a
|
||||
* href="http://xmpp.org/extensions/xep-0065.html#usecase-alternate">XEP-0065 Section 5.2 A2</a>
|
||||
*/
|
||||
|
@ -408,7 +413,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
|
||||
// build discover info for proxy containing information about being a SOCKS5 proxy
|
||||
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
|
||||
Identity identity = new Identity("proxy", proxyJID, "bytestreams");
|
||||
Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
|
||||
proxyInfo.addIdentity(identity);
|
||||
|
||||
// return the socks5 bytestream proxy identity if proxy is queried
|
||||
|
@ -454,11 +459,12 @@ public class Socks5ByteStreamManagerTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if the
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
|
||||
* proxy used by target is invalid.
|
||||
* @throws XmppStringprepException
|
||||
*/
|
||||
@Test
|
||||
public void shouldFailIfTargetUsesInvalidSocks5Proxy() {
|
||||
public void shouldFailIfTargetUsesInvalidSocks5Proxy() throws XmppStringprepException {
|
||||
|
||||
// disable clients local SOCKS5 proxy
|
||||
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
|
||||
|
@ -491,7 +497,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
|
||||
// build discover info for proxy containing information about being a SOCKS5 proxy
|
||||
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
|
||||
Identity identity = new Identity("proxy", proxyJID, "bytestreams");
|
||||
Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
|
||||
proxyInfo.addIdentity(identity);
|
||||
|
||||
// return the socks5 bytestream proxy identity if proxy is queried
|
||||
|
@ -512,7 +518,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
Bytestream streamHostUsedPacket = Socks5PacketUtils.createBytestreamResponse(targetJID,
|
||||
initiatorJID);
|
||||
streamHostUsedPacket.setSessionID(sessionID);
|
||||
streamHostUsedPacket.setUsedHost("invalid.proxy");
|
||||
streamHostUsedPacket.setUsedHost(JidCreate.from("invalid.proxy"));
|
||||
|
||||
// return used stream host info as response to the bytestream initiation
|
||||
protocol.addResponse(streamHostUsedPacket, Verification.correspondingSenderReceiver,
|
||||
|
@ -536,7 +542,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if
|
||||
* initiator can not connect to the SOCKS5 proxy used by target.
|
||||
*/
|
||||
@Test
|
||||
|
@ -573,7 +579,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
|
||||
// build discover info for proxy containing information about being a SOCKS5 proxy
|
||||
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
|
||||
Identity identity = new Identity("proxy", proxyJID, "bytestreams");
|
||||
Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
|
||||
proxyInfo.addIdentity(identity);
|
||||
|
||||
// return the socks5 bytestream proxy identity if proxy is queried
|
||||
|
@ -628,7 +634,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should successfully
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should successfully
|
||||
* negotiate and return a SOCKS5 Bytestream connection.
|
||||
*
|
||||
* @throws Exception should not happen
|
||||
|
@ -667,7 +673,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
|
||||
// build discover info for proxy containing information about being a SOCKS5 proxy
|
||||
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
|
||||
Identity identity = new Identity("proxy", proxyJID, "bytestreams");
|
||||
Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
|
||||
proxyInfo.addIdentity(identity);
|
||||
|
||||
// return the socks5 bytestream proxy identity if proxy is queried
|
||||
|
@ -838,7 +844,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} the first time
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} the first time
|
||||
* should successfully negotiate a SOCKS5 Bytestream via the second SOCKS5 proxy and should
|
||||
* prioritize this proxy for a second SOCKS5 Bytestream negotiation.
|
||||
*
|
||||
|
@ -921,7 +927,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} the first time
|
||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} the first time
|
||||
* should successfully negotiate a SOCKS5 Bytestream via the second SOCKS5 proxy. The second
|
||||
* negotiation should run in the same manner if prioritization is disabled.
|
||||
*
|
||||
|
@ -995,7 +1001,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
|
||||
}
|
||||
|
||||
private void createResponses(Verification<Bytestream, Bytestream> streamHostUsedVerification) {
|
||||
private void createResponses(Verification<Bytestream, Bytestream> streamHostUsedVerification) throws XmppStringprepException {
|
||||
// build discover info that supports the SOCKS5 feature
|
||||
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
|
||||
discoverInfo.addFeature(Bytestream.NAMESPACE);
|
||||
|
@ -1007,7 +1013,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
// build discover items containing a proxy item
|
||||
DiscoverItems discoverItems = Socks5PacketUtils.createDiscoverItems(xmppServer,
|
||||
initiatorJID);
|
||||
discoverItems.addItem(new Item("proxy2.xmpp-server"));
|
||||
discoverItems.addItem(new Item(JidCreate.from("proxy2.xmpp-server")));
|
||||
discoverItems.addItem(new Item(proxyJID));
|
||||
|
||||
// return the proxy item if XMPP server is queried
|
||||
|
@ -1018,7 +1024,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
* build discover info for proxy "proxy2.xmpp-server" containing information about being a
|
||||
* SOCKS5 proxy
|
||||
*/
|
||||
DiscoverInfo proxyInfo1 = Socks5PacketUtils.createDiscoverInfo("proxy2.xmpp-server",
|
||||
DiscoverInfo proxyInfo1 = Socks5PacketUtils.createDiscoverInfo(JidCreate.from("proxy2.xmpp-server"),
|
||||
initiatorJID);
|
||||
Identity identity1 = new Identity("proxy", "proxy2.xmpp-server", "bytestreams");
|
||||
proxyInfo1.addIdentity(identity1);
|
||||
|
@ -1029,7 +1035,7 @@ public class Socks5ByteStreamManagerTest {
|
|||
|
||||
// build discover info for proxy containing information about being a SOCKS5 proxy
|
||||
DiscoverInfo proxyInfo2 = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
|
||||
Identity identity2 = new Identity("proxy", proxyJID, "bytestreams");
|
||||
Identity identity2 = new Identity("proxy", proxyJID.toString(), "bytestreams");
|
||||
proxyInfo2.addIdentity(identity2);
|
||||
|
||||
// return the SOCKS5 bytestream proxy identity if proxy is queried
|
||||
|
@ -1041,8 +1047,8 @@ public class Socks5ByteStreamManagerTest {
|
|||
* port of the proxy
|
||||
*/
|
||||
Bytestream streamHostInfo1 = Socks5PacketUtils.createBytestreamResponse(
|
||||
"proxy2.xmpp-server", initiatorJID);
|
||||
streamHostInfo1.addStreamHost("proxy2.xmpp-server", proxyAddress, 7778);
|
||||
JidCreate.from("proxy2.xmpp-server"), initiatorJID);
|
||||
streamHostInfo1.addStreamHost(JidCreate.from("proxy2.xmpp-server"), proxyAddress, 7778);
|
||||
|
||||
// return stream host info if it is queried
|
||||
protocol.addResponse(streamHostInfo1, Verification.correspondingSenderReceiver,
|
||||
|
|
|
@ -40,6 +40,10 @@ import org.jivesoftware.util.Protocol;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.DomainBareJid;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
/**
|
||||
* Tests for the Socks5BytestreamRequest class.
|
||||
|
@ -49,10 +53,10 @@ import org.junit.Test;
|
|||
public class Socks5ByteStreamRequestTest {
|
||||
|
||||
// settings
|
||||
String initiatorJID = "initiator@xmpp-server/Smack";
|
||||
String targetJID = "target@xmpp-server/Smack";
|
||||
String xmppServer = "xmpp-server";
|
||||
String proxyJID = "proxy.xmpp-server";
|
||||
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
|
||||
static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
|
||||
String proxyAddress = "127.0.0.1";
|
||||
String sessionID = "session_id";
|
||||
|
||||
|
@ -174,7 +178,7 @@ public class Socks5ByteStreamRequestTest {
|
|||
// build SOCKS5 Bytestream initialization request
|
||||
Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(
|
||||
initiatorJID, targetJID, sessionID);
|
||||
bytestreamInitialization.addStreamHost("invalid." + proxyJID, "127.0.0.2", 7778);
|
||||
bytestreamInitialization.addStreamHost(JidCreate.from("invalid." + proxyJID), "127.0.0.2", 7778);
|
||||
|
||||
// get SOCKS5 Bytestream manager for connection
|
||||
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
|
||||
|
@ -266,7 +270,7 @@ public class Socks5ByteStreamRequestTest {
|
|||
// build SOCKS5 Bytestream initialization request
|
||||
Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(
|
||||
initiatorJID, targetJID, sessionID);
|
||||
bytestreamInitialization.addStreamHost("invalid." + proxyJID, "127.0.0.2", 7778);
|
||||
bytestreamInitialization.addStreamHost(JidCreate.from("invalid." + proxyJID), "127.0.0.2", 7778);
|
||||
|
||||
// get SOCKS5 Bytestream manager for connection
|
||||
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
|
||||
|
|
|
@ -42,6 +42,9 @@ import org.jivesoftware.util.Verification;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.DomainBareJid;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
|
||||
/**
|
||||
* Test for Socks5ClientForInitiator class.
|
||||
|
@ -51,10 +54,10 @@ import org.junit.Test;
|
|||
public class Socks5ClientForInitiatorTest {
|
||||
|
||||
// settings
|
||||
String initiatorJID = "initiator@xmpp-server/Smack";
|
||||
String targetJID = "target@xmpp-server/Smack";
|
||||
String xmppServer = "xmpp-server";
|
||||
String proxyJID = "proxy.xmpp-server";
|
||||
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
|
||||
static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
|
||||
String proxyAddress = "127.0.0.1";
|
||||
int proxyPort = 7890;
|
||||
String sessionID = "session_id";
|
||||
|
|
|
@ -32,6 +32,8 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.DomainBareJid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
|
||||
/**
|
||||
* Test for Socks5Client class.
|
||||
|
@ -43,7 +45,7 @@ public class Socks5ClientTest {
|
|||
// settings
|
||||
private String serverAddress = "127.0.0.1";
|
||||
private int serverPort = 7890;
|
||||
private String proxyJID = "proxy.xmpp-server";
|
||||
private DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
|
||||
private String digest = "digest";
|
||||
private ServerSocket serverSocket;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.jivesoftware.smack.packet.IQ;
|
|||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* A collection of utility methods to create XMPP packets.
|
||||
|
@ -38,7 +39,7 @@ public class Socks5PacketUtils {
|
|||
* @param sessionID the session ID
|
||||
* @return SOCKS5 Bytestream initialization request packet
|
||||
*/
|
||||
public static Bytestream createBytestreamInitiation(String from, String to, String sessionID) {
|
||||
public static Bytestream createBytestreamInitiation(Jid from, Jid to, String sessionID) {
|
||||
Bytestream bytestream = new Bytestream();
|
||||
bytestream.setFrom(from);
|
||||
bytestream.setTo(to);
|
||||
|
@ -55,7 +56,7 @@ public class Socks5PacketUtils {
|
|||
* @param to the initiator
|
||||
* @return response to a SOCKS5 Bytestream initialization request
|
||||
*/
|
||||
public static Bytestream createBytestreamResponse(String from, String to) {
|
||||
public static Bytestream createBytestreamResponse(Jid from, Jid to) {
|
||||
Bytestream streamHostInfo = new Bytestream();
|
||||
streamHostInfo.setFrom(from);
|
||||
streamHostInfo.setTo(to);
|
||||
|
@ -70,7 +71,7 @@ public class Socks5PacketUtils {
|
|||
* @param to the XMPP client
|
||||
* @return response to an item discovery request
|
||||
*/
|
||||
public static DiscoverItems createDiscoverItems(String from, String to) {
|
||||
public static DiscoverItems createDiscoverItems(Jid from, Jid to) {
|
||||
DiscoverItems discoverItems = new DiscoverItems();
|
||||
discoverItems.setFrom(from);
|
||||
discoverItems.setTo(to);
|
||||
|
@ -85,7 +86,7 @@ public class Socks5PacketUtils {
|
|||
* @param to the initiator
|
||||
* @return response to an info discovery request
|
||||
*/
|
||||
public static DiscoverInfo createDiscoverInfo(String from, String to) {
|
||||
public static DiscoverInfo createDiscoverInfo(Jid from, Jid to) {
|
||||
DiscoverInfo discoverInfo = new DiscoverInfo();
|
||||
discoverInfo.setFrom(from);
|
||||
discoverInfo.setTo(to);
|
||||
|
@ -100,7 +101,7 @@ public class Socks5PacketUtils {
|
|||
* @param to JID of the client who wants to activate the SOCKS5 Bytestream
|
||||
* @return response IQ for a activation request to the proxy
|
||||
*/
|
||||
public static IQ createActivationConfirmation(String from, String to) {
|
||||
public static IQ createActivationConfirmation(Jid from, Jid to) {
|
||||
IQ response = new EmptyResultIQ();
|
||||
response.setFrom(from);
|
||||
response.setTo(to);
|
||||
|
|
|
@ -38,6 +38,8 @@ import org.jivesoftware.smackx.xdata.FormField;
|
|||
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
|
||||
public class EntityCapsManagerTest extends InitExtensions {
|
||||
|
@ -50,9 +52,10 @@ public class EntityCapsManagerTest extends InitExtensions {
|
|||
/**
|
||||
* <a href="http://xmpp.org/extensions/xep-0115.html#ver-gen-complex">XEP-
|
||||
* 0115 Complex Generation Example</a>
|
||||
* @throws XmppStringprepException
|
||||
*/
|
||||
@Test
|
||||
public void testComplexGenerationExample() {
|
||||
public void testComplexGenerationExample() throws XmppStringprepException {
|
||||
DiscoverInfo di = createComplexSamplePacket();
|
||||
|
||||
CapsVersionAndHash versionAndHash = EntityCapsManager.generateVerificationString(di, StringUtils.SHA1);
|
||||
|
@ -66,13 +69,13 @@ public class EntityCapsManagerTest extends InitExtensions {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testVerificationDuplicateFeatures() {
|
||||
public void testVerificationDuplicateFeatures() throws XmppStringprepException {
|
||||
DiscoverInfo di = createMalformedDiscoverInfo();
|
||||
assertTrue(di.containsDuplicateFeatures());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerificationDuplicateIdentities() {
|
||||
public void testVerificationDuplicateIdentities() throws XmppStringprepException {
|
||||
DiscoverInfo di = createMalformedDiscoverInfo();
|
||||
assertTrue(di.containsDuplicateIdentities());
|
||||
}
|
||||
|
@ -97,11 +100,11 @@ public class EntityCapsManagerTest extends InitExtensions {
|
|||
assertEquals(di.toXML().toString(), restored_di.toXML().toString());
|
||||
}
|
||||
|
||||
private static DiscoverInfo createComplexSamplePacket() {
|
||||
private static DiscoverInfo createComplexSamplePacket() throws XmppStringprepException {
|
||||
DiscoverInfo di = new DiscoverInfo();
|
||||
di.setFrom("benvolio@capulet.lit/230193");
|
||||
di.setFrom(JidCreate.from("benvolio@capulet.lit/230193"));
|
||||
di.setStanzaId("disco1");
|
||||
di.setTo("juliet@capulet.lit/chamber");
|
||||
di.setTo(JidCreate.from("juliet@capulet.lit/chamber"));
|
||||
di.setType(IQ.Type.result);
|
||||
|
||||
Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
|
||||
|
@ -148,11 +151,11 @@ public class EntityCapsManagerTest extends InitExtensions {
|
|||
return di;
|
||||
}
|
||||
|
||||
private static DiscoverInfo createMalformedDiscoverInfo() {
|
||||
private static DiscoverInfo createMalformedDiscoverInfo() throws XmppStringprepException {
|
||||
DiscoverInfo di = new DiscoverInfo();
|
||||
di.setFrom("benvolio@capulet.lit/230193");
|
||||
di.setFrom(JidCreate.from("benvolio@capulet.lit/230193"));
|
||||
di.setStanzaId("disco1");
|
||||
di.setTo(")juliet@capulet.lit/chamber");
|
||||
di.setTo(JidCreate.from(")juliet@capulet.lit/chamber"));
|
||||
di.setType(IQ.Type.result);
|
||||
|
||||
Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
|
||||
public class FileTransferNegotiatorTest {
|
||||
private DummyConnection connection;
|
||||
|
@ -50,7 +51,7 @@ public class FileTransferNegotiatorTest {
|
|||
public void verifyForm() throws Exception {
|
||||
FileTransferNegotiator fileNeg = FileTransferNegotiator.getInstanceFor(connection);
|
||||
try {
|
||||
fileNeg.negotiateOutgoingTransfer("me", "streamid", "file", 1024, null, 10);
|
||||
fileNeg.negotiateOutgoingTransfer(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, "streamid", "file", 1024, null, 10);
|
||||
} catch (NoResponseException e) {
|
||||
// Ignore
|
||||
}
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.forward;
|
||||
|
||||
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -56,7 +58,7 @@ public class ForwardedTest {
|
|||
assertEquals(null, fwd.getDelayInformation());
|
||||
|
||||
// check message
|
||||
assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom());
|
||||
assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedPacket().getFrom()));
|
||||
|
||||
// check end of tag
|
||||
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
|
||||
|
@ -84,7 +86,7 @@ public class ForwardedTest {
|
|||
assertNotNull(delay);
|
||||
|
||||
// check message
|
||||
assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom());
|
||||
assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedPacket().getFrom()));
|
||||
|
||||
// check end of tag
|
||||
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.iqversion;
|
||||
|
||||
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.jivesoftware.smack.DummyConnection;
|
||||
|
@ -52,7 +54,7 @@ public class VersionTest {
|
|||
Version reply = (Version) replyPacket;
|
||||
//getFrom check is pending for SMACK-547
|
||||
//assertEquals("juliet@capulet.lit/balcony", reply.getFrom());
|
||||
assertEquals("capulet.lit", reply.getTo());
|
||||
assertThat("capulet.lit", equalsCharSequence(reply.getTo()));
|
||||
assertEquals("s2c1", reply.getStanzaId());
|
||||
assertEquals(IQ.Type.result, reply.getType());
|
||||
assertEquals("Test", reply.getName());
|
||||
|
|
|
@ -16,10 +16,13 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.ping;
|
||||
|
||||
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.jxmpp.jid.JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -66,7 +69,7 @@ public class PingTest extends InitExtensions {
|
|||
assertTrue(pongPacket instanceof IQ);
|
||||
|
||||
IQ pong = (IQ) pongPacket;
|
||||
assertEquals("capulet.lit", pong.getTo());
|
||||
assertThat("capulet.lit", equalsCharSequence(pong.getTo()));
|
||||
assertEquals("s2c1", pong.getStanzaId());
|
||||
assertEquals(IQ.Type.result, pong.getType());
|
||||
}
|
||||
|
@ -76,7 +79,7 @@ public class PingTest extends InitExtensions {
|
|||
DummyConnection dummyCon = getAuthentiactedDummyConnection();
|
||||
PingManager pinger = PingManager.getInstanceFor(dummyCon);
|
||||
try {
|
||||
pinger.ping("test@myserver.com");
|
||||
pinger.ping(DUMMY_AT_EXAMPLE_ORG);
|
||||
}
|
||||
catch (SmackException e) {
|
||||
// Ignore the fact the server won't answer for this unit test.
|
||||
|
@ -92,7 +95,7 @@ public class PingTest extends InitExtensions {
|
|||
|
||||
PingManager pinger = PingManager.getInstanceFor(threadedCon);
|
||||
|
||||
boolean pingSuccess = pinger.ping("test@myserver.com");
|
||||
boolean pingSuccess = pinger.ping(DUMMY_AT_EXAMPLE_ORG);
|
||||
|
||||
assertTrue(pingSuccess);
|
||||
|
||||
|
@ -111,7 +114,7 @@ public class PingTest extends InitExtensions {
|
|||
PingManager pinger = PingManager.getInstanceFor(dummyCon);
|
||||
|
||||
try {
|
||||
pinger.ping("test@myserver.com");
|
||||
pinger.ping(DUMMY_AT_EXAMPLE_ORG);
|
||||
}
|
||||
catch (NoResponseException e) {
|
||||
return;
|
||||
|
@ -140,7 +143,7 @@ public class PingTest extends InitExtensions {
|
|||
|
||||
PingManager pinger = PingManager.getInstanceFor(threadedCon);
|
||||
|
||||
boolean pingSuccess = pinger.ping("test@myserver.com");
|
||||
boolean pingSuccess = pinger.ping(DUMMY_AT_EXAMPLE_ORG);
|
||||
|
||||
assertFalse(pingSuccess);
|
||||
}
|
||||
|
@ -207,7 +210,7 @@ public class PingTest extends InitExtensions {
|
|||
con.addIQReply(discoReply);
|
||||
|
||||
PingManager pinger = PingManager.getInstanceFor(con);
|
||||
boolean pingSupported = pinger.isPingSupported("test@myserver.com");
|
||||
boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG);
|
||||
|
||||
assertTrue(pingSupported);
|
||||
}
|
||||
|
@ -229,7 +232,7 @@ public class PingTest extends InitExtensions {
|
|||
con.addIQReply(discoReply);
|
||||
|
||||
PingManager pinger = PingManager.getInstanceFor(con);
|
||||
boolean pingSupported = pinger.isPingSupported("test@myserver.com");
|
||||
boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG);
|
||||
|
||||
assertFalse(pingSupported);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
|||
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -77,7 +78,7 @@ public class ConfigureFormTest
|
|||
}
|
||||
|
||||
@Test (expected=SmackException.class)
|
||||
public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException
|
||||
public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException, XmppStringprepException
|
||||
{
|
||||
ThreadedDummyConnection con = new ThreadedDummyConnection();
|
||||
PubSubManager mgr = new PubSubManager(con);
|
||||
|
|
|
@ -19,7 +19,9 @@ package org.jivesoftware.smackx.receipts;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -31,6 +33,8 @@ import org.jivesoftware.smack.util.PacketParserUtils;
|
|||
import org.jivesoftware.smackx.InitExtensions;
|
||||
import org.jivesoftware.smackx.receipts.DeliveryReceiptManager.AutoReceiptMode;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
@ -62,7 +66,7 @@ public class DeliveryReceiptTest extends InitExtensions {
|
|||
|
||||
assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(p));
|
||||
|
||||
Message m = new Message("romeo@montague.com", Message.Type.normal);
|
||||
Message m = new Message(JidCreate.from("romeo@montague.com"), Message.Type.normal);
|
||||
assertFalse(DeliveryReceiptManager.hasDeliveryReceiptRequest(m));
|
||||
DeliveryReceiptRequest.addTo(m);
|
||||
assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(m));
|
||||
|
@ -77,8 +81,8 @@ public class DeliveryReceiptTest extends InitExtensions {
|
|||
TestReceiptReceivedListener rrl = new TestReceiptReceivedListener();
|
||||
drm.addReceiptReceivedListener(rrl);
|
||||
|
||||
Message m = new Message("romeo@montague.com", Message.Type.normal);
|
||||
m.setFrom("julia@capulet.com");
|
||||
Message m = new Message(JidCreate.from("romeo@montague.com"), Message.Type.normal);
|
||||
m.setFrom(JidCreate.from("julia@capulet.com"));
|
||||
m.setStanzaId("reply-id");
|
||||
m.addExtension(new DeliveryReceipt("original-test-id"));
|
||||
c.processPacket(m);
|
||||
|
@ -88,9 +92,9 @@ public class DeliveryReceiptTest extends InitExtensions {
|
|||
|
||||
private static class TestReceiptReceivedListener extends WaitForPacketListener implements ReceiptReceivedListener {
|
||||
@Override
|
||||
public void onReceiptReceived(String fromJid, String toJid, String receiptId, Stanza receipt) {
|
||||
assertEquals("julia@capulet.com", fromJid);
|
||||
assertEquals("romeo@montague.com", toJid);
|
||||
public void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt) {
|
||||
assertThat("julia@capulet.com", equalsCharSequence(fromJid));
|
||||
assertThat("romeo@montague.com", equalsCharSequence(toJid));
|
||||
assertEquals("original-test-id", receiptId);
|
||||
reportInvoked();
|
||||
}
|
||||
|
@ -106,8 +110,8 @@ public class DeliveryReceiptTest extends InitExtensions {
|
|||
assertEquals(AutoReceiptMode.always, drm.getAutoReceiptMode());
|
||||
|
||||
// test auto-receipts
|
||||
Message m = new Message("julia@capulet.com", Message.Type.normal);
|
||||
m.setFrom("romeo@montague.com");
|
||||
Message m = new Message(JidCreate.from("julia@capulet.com"), Message.Type.normal);
|
||||
m.setFrom(JidCreate.from("romeo@montague.com"));
|
||||
m.setStanzaId("test-receipt-request");
|
||||
DeliveryReceiptRequest.addTo(m);
|
||||
|
||||
|
@ -116,7 +120,7 @@ public class DeliveryReceiptTest extends InitExtensions {
|
|||
|
||||
Stanza reply = c.getSentPacket();
|
||||
DeliveryReceipt r = DeliveryReceipt.from(reply);
|
||||
assertEquals("romeo@montague.com", reply.getTo());
|
||||
assertThat("romeo@montague.com", equalsCharSequence(reply.getTo()));
|
||||
assertEquals("test-receipt-request", r.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ import org.jivesoftware.smack.packet.IQ;
|
|||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jxmpp.jid.DomainBareJid;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
|
@ -67,7 +69,7 @@ public class ConnectionUtils {
|
|||
* @throws InterruptedException
|
||||
*/
|
||||
public static XMPPConnection createMockedConnection(final Protocol protocol,
|
||||
String initiatorJID, String xmppServer) throws SmackException, XMPPErrorException, InterruptedException {
|
||||
FullJid initiatorJID, DomainBareJid xmppServer) throws SmackException, XMPPErrorException, InterruptedException {
|
||||
|
||||
// mock XMPP connection
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue