Merge upstream

This commit is contained in:
vanitasvitae 2017-08-16 15:46:32 +02:00
commit aeab6504a7
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
35 changed files with 262 additions and 357 deletions

View File

@ -963,52 +963,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
replyTimeout = timeout;
}
/**
* Set the default value used to determine if new connection will reply to unknown IQ requests. The pre-configured
* default is 'true'.
*
* @param replyToUnkownIqDefault
* @see #setReplyToUnknownIq(boolean)
* @deprecated Use {@link SmackConfiguration#setUnknownIqRequestReplyMode(org.jivesoftware.smack.SmackConfiguration.UnknownIqRequestReplyMode)} instead.
*/
@Deprecated
// TODO Remove in Smack 4.3
public static void setReplyToUnknownIqDefault(boolean replyToUnkownIqDefault) {
SmackConfiguration.UnknownIqRequestReplyMode mode;
if (replyToUnkownIqDefault) {
mode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable;
} else {
mode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply;
}
SmackConfiguration.setUnknownIqRequestReplyMode(mode);
}
private SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode = SmackConfiguration.getUnknownIqRequestReplyMode();
public void setUnknownIqRequestReplyMode(UnknownIqRequestReplyMode unknownIqRequestReplyMode) {
this.unknownIqRequestReplyMode = Objects.requireNonNull(unknownIqRequestReplyMode, "Mode must not be null");
}
/**
* Set if Smack will automatically send
* {@link org.jivesoftware.smack.packet.XMPPError.Condition#feature_not_implemented} when a request IQ without a
* registered {@link IQRequestHandler} is received.
*
* @param replyToUnknownIq
* @deprecated use {@link #setUnknownIqRequestReplyMode(UnknownIqRequestReplyMode)} instead.
*/
@Deprecated
// TODO Remove in Smack 4.3
public void setReplyToUnknownIq(boolean replyToUnknownIq) {
SmackConfiguration.UnknownIqRequestReplyMode mode;
if (replyToUnknownIq) {
mode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable;
} else {
mode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply;
}
unknownIqRequestReplyMode = mode;
}
protected void parseAndProcessStanza(XmlPullParser parser) throws Exception {
ParserUtils.assertAtStartTag(parser);
int parserDepth = parser.getDepth();
@ -1476,12 +1436,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
streamFeatures.put(key, feature);
}
@SuppressWarnings("deprecation")
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
StanzaListener callback) throws NotConnectedException, InterruptedException {
sendStanzaWithResponseCallback(stanza, replyFilter, callback, null);
}
@SuppressWarnings("deprecation")
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
StanzaListener callback, ExceptionCallback exceptionCallback)
@ -1571,7 +1533,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return future;
}
@SuppressWarnings("FutureReturnValueIgnored")
@SuppressWarnings({ "FutureReturnValueIgnored", "deprecation" })
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, final StanzaFilter replyFilter,
final StanzaListener callback, final ExceptionCallback exceptionCallback,
@ -1624,18 +1586,21 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
sendStanza(stanza);
}
@SuppressWarnings("deprecation")
@Override
public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback)
throws NotConnectedException, InterruptedException {
sendIqWithResponseCallback(iqRequest, callback, null);
}
@SuppressWarnings("deprecation")
@Override
public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback,
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException {
sendIqWithResponseCallback(iqRequest, callback, exceptionCallback, getReplyTimeout());
}
@SuppressWarnings("deprecation")
@Override
public void sendIqWithResponseCallback(IQ iqRequest, final StanzaListener callback,
final ExceptionCallback exceptionCallback, long timeout)

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,6 +16,12 @@
*/
package org.jivesoftware.smack;
/**
* This interface has been deprecated. Please use org.jivesoftware.smack.util.ExceptionCallback instead.
*
* @deprecated use {@link org.jivesoftware.smack.util.ExceptionCallback} instead.
*/
@Deprecated
public interface ExceptionCallback {
public void processException(Exception exception);

View File

@ -345,8 +345,7 @@ public final class SmackConfiguration {
replyServiceUnavailable,
}
// TODO Change to replyFeatureNotImplemented in Smack 4.3
private static UnknownIqRequestReplyMode unknownIqRequestReplyMode = UnknownIqRequestReplyMode.replyServiceUnavailable;
private static UnknownIqRequestReplyMode unknownIqRequestReplyMode = UnknownIqRequestReplyMode.replyFeatureNotImplemented;
public static UnknownIqRequestReplyMode getUnknownIqRequestReplyMode() {
return unknownIqRequestReplyMode;

View File

@ -106,14 +106,9 @@ public abstract class SmackFuture<V, E extends Exception> implements Future<V>,
return getOrThrowExecutionException();
}
public synchronized final V getOrThrow() throws E {
public synchronized final V getOrThrow() throws E, InterruptedException {
while (result == null && exception == null && !cancelled) {
try {
wait();
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
wait();
}
if (exception != null) {

View File

@ -428,7 +428,6 @@ public interface XMPPConnection {
*/
public boolean hasFeature(String element, String namespace);
/**
* Send an IQ request asynchronously. The connection's default reply timeout will be used.
*
@ -447,7 +446,8 @@ public interface XMPPConnection {
public SmackFuture<IQ, Exception> sendIqRequestAsync(IQ request, long timeout);
/**
* Send a stanza asynchronously, waiting for exactly one response stanza using the given reply filter. The connection's default reply timeout will be used.
* Send a stanza asynchronously, waiting for exactly one response stanza using the given reply filter. The
* connection's default reply timeout will be used.
*
* @param stanza the stanza to send.
* @param replyFilter the filter used for the response stanza.
@ -477,9 +477,11 @@ public interface XMPPConnection {
* @param replyFilter the filter used to determine response stanza (required)
* @param callback the callback invoked if there is a response (required)
* @throws NotConnectedException
* @throws InterruptedException
* @throws InterruptedException
* @deprecated use {@link #sendAsync(Stanza, StanzaFilter)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
StanzaListener callback) throws NotConnectedException, InterruptedException;
@ -497,10 +499,12 @@ public interface XMPPConnection {
* @param exceptionCallback the callback invoked if there is an exception (optional)
* @throws NotConnectedException
* @throws InterruptedException
* @deprecated use {@link #sendAsync(Stanza, StanzaFilter)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API. And do not forget to mark smack.ExceptionCallback deprecated too.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter, StanzaListener callback,
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
@SuppressWarnings("deprecation") ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
/**
* Send a stanza and wait asynchronously for a response by using <code>replyFilter</code>.
@ -517,10 +521,12 @@ public interface XMPPConnection {
* @param timeout the timeout in milliseconds to wait for a response
* @throws NotConnectedException
* @throws InterruptedException
* @deprecated use {@link #sendAsync(Stanza, StanzaFilter, long)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
final StanzaListener callback, final ExceptionCallback exceptionCallback,
final StanzaListener callback, @SuppressWarnings("deprecation") final ExceptionCallback exceptionCallback,
long timeout) throws NotConnectedException, InterruptedException;
/**
@ -532,8 +538,10 @@ public interface XMPPConnection {
* @param callback the callback invoked if there is result response (required)
* @throws NotConnectedException
* @throws InterruptedException
* @deprecated use {@link #sendIqRequestAsync(IQ)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback) throws NotConnectedException, InterruptedException;
/**
@ -549,10 +557,12 @@ public interface XMPPConnection {
* @param exceptionCallback the callback invoked if there is an Exception optional
* @throws NotConnectedException
* @throws InterruptedException
* @deprecated use {@link #sendIqRequestAsync(IQ)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback,
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
@SuppressWarnings("deprecation") ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
/**
* Send a IQ stanza and invoke <code>callback</code> if there is a result of
@ -568,10 +578,12 @@ public interface XMPPConnection {
* @param timeout the timeout in milliseconds to wait for a response
* @throws NotConnectedException
* @throws InterruptedException
* @deprecated use {@link #sendIqRequestAsync(IQ, long)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendIqWithResponseCallback(IQ iqRequest, final StanzaListener callback,
final ExceptionCallback exceptionCallback, long timeout)
@SuppressWarnings("deprecation") final ExceptionCallback exceptionCallback, long timeout)
throws NotConnectedException, InterruptedException;
/**

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2015 Florian Schmaus
* Copyright 2003-2007 Jive Software, 2015-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
*/
package org.jivesoftware.smack.packet;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@ -102,50 +101,6 @@ public class XMPPError extends AbstractError {
private final Type type;
private final Stanza stanza;
// TODO: Deprecated constructors
// deprecate in 4.3
/**
* Create a new XMPPError.
*
* @param condition
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public XMPPError(Condition condition) {
this(condition, null, null, null, null, null, null);
}
/**
* Create a new XMPPError.
*
* @param condition
* @param applicationSpecificCondition
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public XMPPError(Condition condition, ExtensionElement applicationSpecificCondition) {
this(condition, null, null, null, null, Arrays.asList(applicationSpecificCondition), null);
}
/**
* Creates a new error with the specified type, condition and message.
* This constructor is used when the condition is not recognized automatically by XMPPError
* i.e. there is not a defined instance of ErrorCondition or it does not apply the default
* specification.
*
* @param type the error type.
* @param condition the error condition.
* @param descriptiveTexts
* @param extensions list of stanza(/packet) extensions
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public XMPPError(Condition condition, String conditionText, String errorGenerator, Type type, Map<String, String> descriptiveTexts,
List<ExtensionElement> extensions) {
this(condition, conditionText, errorGenerator, type, descriptiveTexts, extensions, null);
}
/**
* Creates a new error with the specified type, condition and message.
* This constructor is used when the condition is not recognized automatically by XMPPError

View File

@ -303,7 +303,7 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
protected abstract SASLMechanism newInstance();
protected static byte[] toBytes(String string) {
return StringUtils.toBytes(string);
return StringUtils.toUtf8Bytes(string);
}
/**

View File

@ -42,7 +42,7 @@ public class MD5 {
}
public static byte[] bytes(String string) {
return bytes(StringUtils.toBytes(string));
return bytes(StringUtils.toUtf8Bytes(string));
}
public static String hex(byte[] bytes) {
@ -50,7 +50,7 @@ public class MD5 {
}
public static String hex(String string) {
return hex(StringUtils.toBytes(string));
return hex(StringUtils.toUtf8Bytes(string));
}
}

View File

@ -43,7 +43,7 @@ public class SHA1 {
}
public static byte[] bytes(String string) {
return bytes(StringUtils.toBytes(string));
return bytes(StringUtils.toUtf8Bytes(string));
}
public static String hex(byte[] bytes) {
@ -51,7 +51,7 @@ public class SHA1 {
}
public static String hex(String string) {
return hex(StringUtils.toBytes(string));
return hex(StringUtils.toUtf8Bytes(string));
}
}

View File

@ -41,19 +41,6 @@ public class StringUtils {
public static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
/**
* Escape <code>input</code> for XML.
*
* @param input the input to escape.
* @return the XML escaped variant of <code>input</code>.
* @deprecated use {@link #escapeForXml(CharSequence)} instead.
*/
// Remove in 4.3.
@Deprecated
public static CharSequence escapeForXML(CharSequence input) {
return escapeForXml(input);
}
/**
* Escape <code>input</code> for XML.
*
@ -257,7 +244,7 @@ public class StringUtils {
return new String(hexChars);
}
public static byte[] toBytes(String string) {
public static byte[] toUtf8Bytes(String string) {
try {
return string.getBytes(StringUtils.UTF8);
}

View File

@ -1,6 +1,6 @@
/**
*
* Copyright © 2016 Florian Schmaus
* Copyright © 2016-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,7 +22,6 @@ import org.jivesoftware.smack.packet.Presence.Mode;
import org.junit.Test;
import org.jxmpp.jid.JidTestUtil;
import org.jxmpp.stringprep.XmppStringprepException;
public class ToStringTest {
@ -43,7 +42,7 @@ public class ToStringTest {
}
@Test
public void iqTest() throws XmppStringprepException {
public void iqTest() {
Bind bindIq = Bind.newResult(JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE);
bindIq.setStanzaId("bind-id");
String string = bindIq.toString();

View File

@ -34,7 +34,7 @@ import org.jxmpp.stringprep.XmppStringprepException;
public class DigestMd5SaslTest extends AbstractSaslTest {
protected static final String challenge = "realm=\"xmpp.org\",nonce=\"jgGgnz+cQcmyVaAs2n88kQ==\",qop=\"auth\",charset=utf-8,algorithm=md5-sess";
protected static final byte[] challengeBytes = StringUtils.toBytes(challenge);
protected static final byte[] challengeBytes = StringUtils.toUtf8Bytes(challenge);
public DigestMd5SaslTest(SASLMechanism saslMechanism) {
super(saslMechanism);

View File

@ -23,11 +23,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.AbstractConnectionListener;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.ExceptionCallback;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.SmackFuture;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPConnectionRegistry;
@ -42,6 +42,8 @@ import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.ExceptionCallback;
import org.jivesoftware.smack.util.SuccessCallback;
import org.jivesoftware.smackx.carbons.packet.Carbon;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
@ -245,10 +247,9 @@ public final class CarbonManager extends Manager {
* </p>
*
* @param exceptionCallback the optional exception callback.
* @throws InterruptedException if the thread got interrupted while this action is performed.
* @since 4.2
*/
public void enableCarbonsAsync(ExceptionCallback exceptionCallback) throws InterruptedException {
public void enableCarbonsAsync(ExceptionCallback<Exception> exceptionCallback) {
sendUseCarbons(true, exceptionCallback);
}
@ -262,29 +263,24 @@ public final class CarbonManager extends Manager {
* </p>
*
* @param exceptionCallback the optional exception callback.
* @throws InterruptedException if the thread got interrupted while this action is performed.
* @since 4.2
*/
public void disableCarbonsAsync(ExceptionCallback exceptionCallback) throws InterruptedException {
public void disableCarbonsAsync(ExceptionCallback<Exception> exceptionCallback) {
sendUseCarbons(false, exceptionCallback);
}
private void sendUseCarbons(final boolean use, ExceptionCallback exceptionCallback) throws InterruptedException {
private void sendUseCarbons(final boolean use, ExceptionCallback<Exception> exceptionCallback) {
IQ setIQ = carbonsEnabledIQ(use);
try {
connection().sendIqWithResponseCallback(setIQ, new StanzaListener() {
@Override
public void processStanza(Stanza packet) {
enabled_state = use;
}
}, exceptionCallback);
}
catch (NotConnectedException e) {
if (exceptionCallback != null) {
exceptionCallback.processException(e);
SmackFuture<IQ, Exception> future = connection().sendIqRequestAsync(setIQ);
future.onSuccess(new SuccessCallback<IQ>() {
@Override
public void onSuccess(IQ result) {
enabled_state = use;
}
}
}).onError(exceptionCallback);
}
/**

View File

@ -16,6 +16,8 @@
*/
package org.jivesoftware.smackx.hashes;
import static org.jivesoftware.smack.util.StringUtils.encodeHex;
import static org.jivesoftware.smack.util.StringUtils.toUtf8Bytes;
import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.BLAKE2B160;
import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.BLAKE2B256;
import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.BLAKE2B384;
@ -31,8 +33,6 @@ import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.SHA_256;
import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.SHA_384;
import static org.jivesoftware.smackx.hashes.HashManager.ALGORITHM.SHA_512;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
@ -44,7 +44,6 @@ import java.util.WeakHashMap;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.hashes.element.HashElement;
@ -52,7 +51,10 @@ import org.jivesoftware.smackx.hashes.element.HashElement;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
/**
* Manager that can be used to determine support for hash functions.
* Manager that can be used to determine support for hash functions. By default the Manager announces support for
* XEP-0300, as well as for the recommended set of hash algorithms. Those contain SHA256, SHA384, SHA512, SHA3-256,
* SHA3-384, SHA3-512, BLAKE2B256, BLAKE2B384 and BLAKE2B512. Those algorithms got recommended here:
* <a href="https://xmpp.org/extensions/xep-0300.html#recommendations">https://xmpp.org/extensions/xep-0300.html#recommendations</a>.
*/
public final class HashManager extends Manager {
@ -88,9 +90,7 @@ public final class HashManager extends Manager {
/**
* Constructor of the HashManager.
* By default the Manager announces support for XEP-0300, as well as for the RECOMMENDED set of hash algorithms.
* Those contain SHA256, SHA384, SHA512, SHA3-256, SHA3-384, SHA3-512, BLAKE2B256, BLAKE2B384 and BLAKE2B512.
* Those algorithms got recommended here: https://xmpp.org/extensions/xep-0300.html#recommendations
*
* @param connection connection
*/
private HashManager(XMPPConnection connection) {
@ -122,9 +122,9 @@ public final class HashManager extends Manager {
/**
* Get an instance of the HashManager for the given connection.
* @param connection
* @return
* @return the manager for the given connection.
*/
public HashManager getInstanceFor(XMPPConnection connection) {
public static synchronized HashManager getInstanceFor(XMPPConnection connection) {
HashManager hashManager = INSTANCES.get(connection);
if (hashManager == null) {
hashManager = new HashManager(connection);
@ -142,26 +142,36 @@ public final class HashManager extends Manager {
return PREFIX_NS_ALGO + algorithm.toString();
}
public enum ALGORITHM { // RECOMMENDATION:
MD5 ("md5"), // MUST NOT use this
SHA_1 ("sha-1"), // SHOULD NOT use this
SHA_224 ("sha-224"),
SHA_256 ("sha-256"), // MUST use this
SHA_384 ("sha-384"),
SHA_512 ("sha-512"), // SHOULD use this
SHA3_224 ("sha3-224"),
SHA3_256 ("sha3-256"), // MUST use this
SHA3_384 ("sha3-384"),
SHA3_512 ("sha3-512"), // SHOULD use this
BLAKE2B160("id-blake2b160"),
BLAKE2B256("id-blake2b256"), // MUST use this
BLAKE2B384("id-blake2b384"),
BLAKE2B512("id-blake2b512"); // SHOULD use this
enum AlgorithmRecommendation {
unknown,
must_not,
should_not,
should,
must,
}
public enum ALGORITHM {
MD5 ("md5", AlgorithmRecommendation.must_not),
SHA_1 ("sha-1", AlgorithmRecommendation.should_not),
SHA_224 ("sha-224", AlgorithmRecommendation.unknown),
SHA_256 ("sha-256", AlgorithmRecommendation.must),
SHA_384 ("sha-384", AlgorithmRecommendation.unknown),
SHA_512 ("sha-512", AlgorithmRecommendation.should),
SHA3_224 ("sha3-224", AlgorithmRecommendation.unknown),
SHA3_256 ("sha3-256", AlgorithmRecommendation.must),
SHA3_384 ("sha3-384", AlgorithmRecommendation.unknown),
SHA3_512 ("sha3-512", AlgorithmRecommendation.should),
BLAKE2B160("id-blake2b160", AlgorithmRecommendation.unknown),
BLAKE2B256("id-blake2b256", AlgorithmRecommendation.must),
BLAKE2B384("id-blake2b384", AlgorithmRecommendation.unknown),
BLAKE2B512("id-blake2b512", AlgorithmRecommendation.should);
private final String name;
private final AlgorithmRecommendation recommendation;
ALGORITHM(String name) {
ALGORITHM(String name, AlgorithmRecommendation recommendation) {
this.name = name;
this.recommendation = recommendation;
}
/**
@ -173,10 +183,16 @@ public final class HashManager extends Manager {
return this.name;
}
public AlgorithmRecommendation getRecommendation() {
return recommendation;
}
/**
* Compensational method for static 'valueOf' function.
*
* @param s
* @return
* @return the algorithm for the given string.
* @throws IllegalArgumentException if no algorithm for the given string is known.
*/
public static ALGORITHM valueOfName(String s) {
for (ALGORITHM a : ALGORITHM.values()) {
@ -190,16 +206,17 @@ public final class HashManager extends Manager {
/**
* Calculate the hash sum of data using algorithm.
* @param algorithm
* @param data
* @return
*
* @param algorithm the algorithm to use.
* @param data the data to calculate the hash for.
* @return the hash value produced by the given algorithm for the given data.
*/
public static byte[] hash(ALGORITHM algorithm, byte[] data) {
return getMessageDigest(algorithm).digest(data);
}
public static byte[] hash(ALGORITHM algorithm, String data) {
return hash(algorithm, utf8(data));
return hash(algorithm, toUtf8Bytes(data));
}
public static MessageDigest getMessageDigest(ALGORITHM algorithm) {
@ -249,7 +266,7 @@ public final class HashManager extends Manager {
md = MessageDigest.getInstance("BLAKE2b-512", PROVIDER);
break;
default:
throw new AssertionError("Invalid enum value.");
throw new AssertionError("Invalid enum value: " + algorithm);
}
return md;
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
@ -262,15 +279,15 @@ public final class HashManager extends Manager {
}
public static byte[] md5(String data) {
return md5(utf8(data));
return md5(toUtf8Bytes(data));
}
public static String md5HexString(byte[] data) {
return hex(md5(data));
return encodeHex(md5(data));
}
public static String md5HexString(String data) {
return hex(md5(data));
return encodeHex(md5(data));
}
public static byte[] sha_1(byte[] data) {
@ -278,15 +295,15 @@ public final class HashManager extends Manager {
}
public static byte[] sha_1(String data) {
return sha_1(utf8(data));
return sha_1(toUtf8Bytes(data));
}
public static String sha_1HexString(byte[] data) {
return hex(sha_1(data));
return encodeHex(sha_1(data));
}
public static String sha_1HexString(String data) {
return hex(sha_1(data));
return encodeHex(sha_1(data));
}
public static byte[] sha_224(byte[] data) {
@ -294,15 +311,15 @@ public final class HashManager extends Manager {
}
public static byte[] sha_224(String data) {
return sha_224(utf8(data));
return sha_224(toUtf8Bytes(data));
}
public static String sha_224HexString(byte[] data) {
return hex(sha_224(data));
return encodeHex(sha_224(data));
}
public static String sha_224HexString(String data) {
return hex(sha_224(data));
return encodeHex(sha_224(data));
}
public static byte[] sha_256(byte[] data) {
@ -310,15 +327,15 @@ public final class HashManager extends Manager {
}
public static byte[] sha_256(String data) {
return sha_256(utf8(data));
return sha_256(toUtf8Bytes(data));
}
public static String sha_256HexString(byte[] data) {
return hex(sha_256(data));
return encodeHex(sha_256(data));
}
public static String sha_256HexString(String data) {
return hex(sha_256(data));
return encodeHex(sha_256(data));
}
public static byte[] sha_384(byte[] data) {
@ -326,15 +343,15 @@ public final class HashManager extends Manager {
}
public static byte[] sha_384(String data) {
return sha_384(utf8(data));
return sha_384(toUtf8Bytes(data));
}
public static String sha_384HexString(byte[] data) {
return hex(sha_384(data));
return encodeHex(sha_384(data));
}
public static String sha_384HexString(String data) {
return hex(sha_384(data));
return encodeHex(sha_384(data));
}
public static byte[] sha_512(byte[] data) {
@ -342,15 +359,15 @@ public final class HashManager extends Manager {
}
public static byte[] sha_512(String data) {
return sha_512(utf8(data));
return sha_512(toUtf8Bytes(data));
}
public static String sha_512HexString(byte[] data) {
return hex(sha_512(data));
return encodeHex(sha_512(data));
}
public static String sha_512HexString(String data) {
return hex(sha_512(data));
return encodeHex(sha_512(data));
}
public static byte[] sha3_224(byte[] data) {
@ -358,15 +375,15 @@ public final class HashManager extends Manager {
}
public static byte[] sha3_224(String data) {
return sha3_224(utf8(data));
return sha3_224(toUtf8Bytes(data));
}
public static String sha3_224HexString(byte[] data) {
return hex(sha3_224(data));
return encodeHex(sha3_224(data));
}
public static String sha3_224HexString(String data) {
return hex(sha3_224(data));
return encodeHex(sha3_224(data));
}
public static byte[] sha3_256(byte[] data) {
@ -374,15 +391,15 @@ public final class HashManager extends Manager {
}
public static byte[] sha3_256(String data) {
return sha3_256(utf8(data));
return sha3_256(toUtf8Bytes(data));
}
public static String sha3_256HexString(byte[] data) {
return hex(sha3_256(data));
return encodeHex(sha3_256(data));
}
public static String sha3_256HexString(String data) {
return hex(sha3_256(data));
return encodeHex(sha3_256(data));
}
public static byte[] sha3_384(byte[] data) {
@ -390,15 +407,15 @@ public final class HashManager extends Manager {
}
public static byte[] sha3_384(String data) {
return sha3_384(utf8(data));
return sha3_384(toUtf8Bytes(data));
}
public static String sha3_384HexString(byte[] data) {
return hex(sha3_384(data));
return encodeHex(sha3_384(data));
}
public static String sha3_384HexString(String data) {
return hex(sha3_384(data));
return encodeHex(sha3_384(data));
}
public static byte[] sha3_512(byte[] data) {
@ -406,15 +423,15 @@ public final class HashManager extends Manager {
}
public static byte[] sha3_512(String data) {
return sha3_512(utf8(data));
return sha3_512(toUtf8Bytes(data));
}
public static String sha3_512HexString(byte[] data) {
return hex(sha3_512(data));
return encodeHex(sha3_512(data));
}
public static String sha3_512HexString(String data) {
return hex(sha3_512(data));
return encodeHex(sha3_512(data));
}
public static byte[] blake2b160(byte[] data) {
@ -422,15 +439,15 @@ public final class HashManager extends Manager {
}
public static byte[] blake2b160(String data) {
return blake2b160(utf8(data));
return blake2b160(toUtf8Bytes(data));
}
public static String blake2b160HexString(byte[] data) {
return hex(blake2b160(data));
return encodeHex(blake2b160(data));
}
public static String blake2b160HexString(String data) {
return hex(blake2b160(data));
return encodeHex(blake2b160(data));
}
public static byte[] blake2b256(byte[] data) {
@ -438,15 +455,15 @@ public final class HashManager extends Manager {
}
public static byte[] blake2b256(String data) {
return blake2b256(utf8(data));
return blake2b256(toUtf8Bytes(data));
}
public static String blake2b256HexString(byte[] data) {
return hex(blake2b256(data));
return encodeHex(blake2b256(data));
}
public static String blake2b256HexString(String data) {
return hex(blake2b256(data));
return encodeHex(blake2b256(data));
}
public static byte[] blake2b384(byte[] data) {
@ -454,15 +471,15 @@ public final class HashManager extends Manager {
}
public static byte[] blake2b384(String data) {
return blake2b384(utf8(data));
return blake2b384(toUtf8Bytes(data));
}
public String blake2b384HexString(byte[] data) {
return hex(blake2b384(data));
public static String blake2b384HexString(byte[] data) {
return encodeHex(blake2b384(data));
}
public String blake2b384HexString(String data) {
return hex(blake2b384(data));
public static String blake2b384HexString(String data) {
return encodeHex(blake2b384(data));
}
public static byte[] blake2b512(byte[] data) {
@ -470,32 +487,15 @@ public final class HashManager extends Manager {
}
public static byte[] blake2b512(String data) {
return blake2b512(utf8(data));
return blake2b512(toUtf8Bytes(data));
}
public String blake2b512HexString(byte[] data) {
return hex(blake2b512(data));
public static String blake2b512HexString(byte[] data) {
return encodeHex(blake2b512(data));
}
public String blake2b512HexString(String data) {
return hex(blake2b512(data));
}
/**
* Encode a byte array in HEX.
* @param hash
* @return
*/
public static String hex(byte[] hash) {
return new BigInteger(1, hash).toString(16);
}
public static byte[] utf8(String data) {
try {
return data.getBytes(StringUtils.UTF8);
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
public static String blake2b512HexString(String data) {
return encodeHex(blake2b512(data));
}
}

View File

@ -62,7 +62,8 @@ public class HashElement implements ExtensionElement {
/**
* Return the hash algorithm used in this HashElement.
* @return algorithm
*
* @return algorithm the algorithm.
*/
public HashManager.ALGORITHM getAlgorithm() {
return algorithm;
@ -70,7 +71,8 @@ public class HashElement implements ExtensionElement {
/**
* Return the checksum as a byte array.
* @return
*
* @return the hash.
*/
public byte[] getHash() {
return hash;
@ -78,7 +80,8 @@ public class HashElement implements ExtensionElement {
/**
* Return the checksum as a base16 (hex) string.
* @return
*
* @return the hash.
*/
public String getHashB64() {
return hashB64;

View File

@ -25,7 +25,7 @@ public class UploadService {
enum Version {
v0_2,
v0_3,
};
}
private final DomainBareJid address;
private final Version version;

View File

@ -607,23 +607,6 @@ public final class MamManager extends Manager {
return serviceDiscoveryManager.supportsFeature(myBareJid, MamElements.NAMESPACE);
}
/**
* Returns true if Message Archive Management is supported by the server.
*
* @return true if Message Archive Management is supported by the server.
* @throws NotConnectedException
* @throws XMPPErrorException
* @throws NoResponseException
* @throws InterruptedException
* @depreacted use {@link #isSupported()} instead.
*/
@Deprecated
// TODO Remove in Smack 4.3
public boolean isSupportedByServer()
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).serverSupportsFeature(MamElements.NAMESPACE);
}
private static DataForm getNewMamForm() {
FormField field = new FormField(FormField.FORM_TYPE);
field.setType(FormField.Type.hidden);

View File

@ -146,6 +146,7 @@ public class MultiUserChatLight {
* for the newly created chat.
* @return new Chat for sending private messages to a given room occupant.
*/
@SuppressWarnings("deprecation")
@Deprecated
// Do not re-use Chat API, which was designed for XMPP-IM 1:1 chats and not MUClight private chats.
public org.jivesoftware.smack.chat.Chat createPrivateChat(EntityJid occupant, ChatMessageListener listener) {

View File

@ -68,7 +68,7 @@ public class MUCLightBlockingIQProvider extends IQProvider<MUCLightBlockingIQ> {
return mucLightBlockingIQ;
}
private HashMap<Jid, Boolean> parseBlocking(XmlPullParser parser, HashMap<Jid, Boolean> map)
private static HashMap<Jid, Boolean> parseBlocking(XmlPullParser parser, HashMap<Jid, Boolean> map)
throws XmppStringprepException, XmlPullParserException, IOException {
if (map == null) {
map = new HashMap<>();

View File

@ -93,7 +93,7 @@ public class MUCLightInfoIQProvider extends IQProvider<MUCLightInfoIQ> {
return new MUCLightInfoIQ(version, new MUCLightRoomConfiguration(roomName, subject, customConfigs), occupants);
}
private HashMap<Jid, MUCLightAffiliation> iterateOccupants(XmlPullParser parser) throws Exception {
private static HashMap<Jid, MUCLightAffiliation> iterateOccupants(XmlPullParser parser) throws Exception {
HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>();
int depth = parser.getDepth();

View File

@ -39,7 +39,7 @@ public class HashElementTest extends SmackTestSuite {
@Test
public void stanzaTest() throws Exception {
String message = "Hello World!";
HashElement element = HashManager.calculateHashElement(SHA_256, HashManager.utf8(message));
HashElement element = HashManager.calculateHashElement(SHA_256, StringUtils.toUtf8Bytes(message));
String expected = "<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=</hash>";
assertEquals(expected, element.toXML().toString());

View File

@ -19,6 +19,7 @@ package org.jivesoftware.smackx.hashes;
import static junit.framework.TestCase.assertEquals;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.util.StringUtils;
import org.junit.Test;
@ -47,7 +48,7 @@ public class HashTest extends SmackTestSuite {
private byte[] array() {
if (testArray == null) {
testArray = HashManager.utf8(testString);
testArray = StringUtils.toUtf8Bytes(testString);
}
return testArray;
}
@ -56,103 +57,103 @@ public class HashTest extends SmackTestSuite {
@Test
public void hashTest() {
assertEquals(md5sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.MD5, array())));
assertEquals(sha1sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA_1, array())));
assertEquals(sha224sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA_224, array())));
assertEquals(sha256sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA_256, array())));
assertEquals(sha384sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA_384, array())));
assertEquals(sha512sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA_512, array())));
assertEquals(sha3_224sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA3_224, array())));
assertEquals(sha3_256sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA3_256, array())));
assertEquals(sha3_384sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA3_384, array())));
assertEquals(sha3_512sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.SHA3_512, array())));
assertEquals(b2_160sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B160, array())));
assertEquals(b2_256sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B256, array())));
assertEquals(b2_384sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B384, array())));
assertEquals(b2_512sum, HashManager.hex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B512, array())));
assertEquals(md5sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.MD5, array())));
assertEquals(sha1sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA_1, array())));
assertEquals(sha224sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA_224, array())));
assertEquals(sha256sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA_256, array())));
assertEquals(sha384sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA_384, array())));
assertEquals(sha512sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA_512, array())));
assertEquals(sha3_224sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA3_224, array())));
assertEquals(sha3_256sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA3_256, array())));
assertEquals(sha3_384sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA3_384, array())));
assertEquals(sha3_512sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.SHA3_512, array())));
assertEquals(b2_160sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B160, array())));
assertEquals(b2_256sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B256, array())));
assertEquals(b2_384sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B384, array())));
assertEquals(b2_512sum, StringUtils.encodeHex(HashManager.hash(HashManager.ALGORITHM.BLAKE2B512, array())));
}
@Test
public void md5Test() {
String actual = HashManager.hex(HashManager.md5(array()));
String actual = StringUtils.encodeHex(HashManager.md5(array()));
assertEquals(md5sum, actual);
}
@Test
public void sha1Test() {
String actual = HashManager.hex(HashManager.sha_1(array()));
String actual = StringUtils.encodeHex(HashManager.sha_1(array()));
assertEquals(sha1sum, actual);
}
@Test
public void sha224Test() {
String actual = HashManager.hex(HashManager.sha_224(array()));
String actual = StringUtils.encodeHex(HashManager.sha_224(array()));
assertEquals(sha224sum, actual);
}
@Test
public void sha256Test() {
String actual = HashManager.hex(HashManager.sha_256(array()));
String actual = StringUtils.encodeHex(HashManager.sha_256(array()));
assertEquals(sha256sum, actual);
}
@Test
public void sha384Test() {
String actual = HashManager.hex(HashManager.sha_384(array()));
String actual = StringUtils.encodeHex(HashManager.sha_384(array()));
assertEquals(sha384sum, actual);
}
@Test
public void sha512Test() {
String actual = HashManager.hex(HashManager.sha_512(array()));
String actual = StringUtils.encodeHex(HashManager.sha_512(array()));
assertEquals(sha512sum, actual);
}
@Test
public void sha3_224Test() {
String actual = HashManager.hex(HashManager.sha3_224(array()));
String actual = StringUtils.encodeHex(HashManager.sha3_224(array()));
assertEquals(sha3_224sum, actual);
}
@Test
public void sha3_256Test() {
String actual = HashManager.hex(HashManager.sha3_256(array()));
String actual = StringUtils.encodeHex(HashManager.sha3_256(array()));
assertEquals(sha3_256sum, actual);
}
@Test
public void sha3_384Test() {
String actual = HashManager.hex(HashManager.sha3_384(array()));
String actual = StringUtils.encodeHex(HashManager.sha3_384(array()));
assertEquals(sha3_384sum, actual);
}
@Test
public void sha3_512Test() {
String actual = HashManager.hex(HashManager.sha3_512(array()));
String actual = StringUtils.encodeHex(HashManager.sha3_512(array()));
assertEquals(sha3_512sum, actual);
}
@Test
public void blake2b160Test() {
String actual = HashManager.hex(HashManager.blake2b160(array()));
String actual = StringUtils.encodeHex(HashManager.blake2b160(array()));
assertEquals(b2_160sum, actual);
}
@Test
public void blake2b256Test() {
String actual = HashManager.hex(HashManager.blake2b256(array()));
String actual = StringUtils.encodeHex(HashManager.blake2b256(array()));
assertEquals(b2_256sum, actual);
}
@Test
public void blake2b384Test() {
String actual = HashManager.hex(HashManager.blake2b384(array()));
String actual = StringUtils.encodeHex(HashManager.blake2b384(array()));
assertEquals(b2_384sum, actual);
}
@Test
public void blake2b512Test() {
String actual = HashManager.hex(HashManager.blake2b512(array()));
String actual = StringUtils.encodeHex(HashManager.blake2b512(array()));
assertEquals(b2_512sum, actual);
}

View File

@ -42,6 +42,7 @@ public final class Chat extends Manager {
public void send(CharSequence message) throws NotConnectedException, InterruptedException {
Message stanza = new Message();
stanza.setBody(message);
stanza.setType(Message.Type.chat);
send(stanza);
}

View File

@ -75,7 +75,7 @@ public interface BytestreamManager {
*
* @param initiatorJID the JID of the user the listener should be removed
*/
public void removeIncomingBytestreamListener(String initiatorJID);
public void removeIncomingBytestreamListener(Jid initiatorJID);
/**
* Establishes a bytestream with the given user and returns the session to send/receive data

View File

@ -282,9 +282,7 @@ public final class InBandBytestreamManager extends Manager implements Bytestream
* @param initiatorJID the JID of the user the listener should be removed
*/
@Override
// TODO: Change argument to Jid in Smack 4.3.
@SuppressWarnings("CollectionIncompatibleType")
public void removeIncomingBytestreamListener(String initiatorJID) {
public void removeIncomingBytestreamListener(Jid initiatorJID) {
this.userListeners.remove(initiatorJID);
}

View File

@ -245,10 +245,8 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
*
* @param initiatorJID the JID of the user the listener should be removed
*/
// TODO: Change parameter to Jid in Smack 4.3.
@Override
@SuppressWarnings("CollectionIncompatibleType")
public void removeIncomingBytestreamListener(String initiatorJID) {
public void removeIncomingBytestreamListener(Jid initiatorJID) {
this.userListeners.remove(initiatorJID);
}

View File

@ -408,9 +408,7 @@ public final class EntityCapsManager extends Manager {
* @param user
* the user (Full JID)
*/
// TODO: Change parameter type to Jid in Smack 4.3.
@SuppressWarnings("CollectionIncompatibleType")
public static void removeUserCapsNode(String user) {
public static void removeUserCapsNode(Jid user) {
// While JID_TO_NODEVER_CHACHE has the generic types <Jid, NodeVerHash>, it is ok to call remove with String
// arguments, since the same Jid and String representations would be equal and have the same hash code.
JID_TO_NODEVER_CACHE.remove(user);

View File

@ -205,15 +205,8 @@ public final class AdHocCommandManager extends Manager {
public void registerCommand(String node, String name, final Class<? extends LocalCommand> clazz) {
registerCommand(node, name, new LocalCommandFactory() {
@Override
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
try {
return clazz.getConstructor().newInstance();
}
catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException e) {
// TODO: Throw those method in Smack 4.3.
throw new IllegalStateException(e);
}
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
return clazz.getConstructor().newInstance();
}
});
}
@ -361,7 +354,15 @@ public final class AdHocCommandManager extends Manager {
try {
// Create a new instance of the command with the
// corresponding sessioid
LocalCommand command = newInstanceOfCmd(commandNode, sessionId);
LocalCommand command;
try {
command = newInstanceOfCmd(commandNode, sessionId);
}
catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
XMPPError.Builder xmppError = XMPPError.getBuilder().setCondition(XMPPError.Condition.internal_server_error).setDescriptiveEnText(e.getMessage());
return respondError(response, xmppError);
}
response.setType(IQ.Type.result);
command.setData(response);
@ -627,26 +628,22 @@ public final class AdHocCommandManager extends Manager {
* @param sessionID the session id of this execution.
* @return the command instance to execute.
* @throws XMPPErrorException if there is problem creating the new instance.
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws InstantiationException
*/
@SuppressWarnings("deprecation")
private LocalCommand newInstanceOfCmd(String commandNode, String sessionID) throws XMPPErrorException
{
private LocalCommand newInstanceOfCmd(String commandNode, String sessionID)
throws XMPPErrorException, InstantiationException, IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException {
AdHocCommandInfo commandInfo = commands.get(commandNode);
LocalCommand command;
try {
command = commandInfo.getCommandInstance();
command.setSessionID(sessionID);
command.setName(commandInfo.getName());
command.setNode(commandInfo.getNode());
}
catch (InstantiationException e) {
throw new XMPPErrorException(XMPPError.getBuilder(
XMPPError.Condition.internal_server_error));
}
catch (IllegalAccessException e) {
throw new XMPPErrorException(XMPPError.getBuilder(
XMPPError.Condition.internal_server_error));
}
LocalCommand command = commandInfo.getCommandInstance();
command.setSessionID(sessionID);
command.setName(commandInfo.getName());
command.setNode(commandInfo.getNode());
return command;
}
@ -680,7 +677,7 @@ public final class AdHocCommandManager extends Manager {
}
public LocalCommand getCommandInstance() throws InstantiationException,
IllegalAccessException
IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException
{
return factory.getInstance();
}

View File

@ -16,6 +16,8 @@
*/
package org.jivesoftware.smackx.commands;
import java.lang.reflect.InvocationTargetException;
/**
* A factory for creating local commands. It's useful in cases where instantiation
* of a command is more complicated than just using the default constructor. For example,
@ -34,7 +36,11 @@ public interface LocalCommandFactory {
* @return a LocalCommand instance.
* @throws InstantiationException if creating an instance failed.
* @throws IllegalAccessException if creating an instance is not allowed.
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
*/
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException;
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException;
}

View File

@ -236,11 +236,10 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
private void establishBytestreamSession(XMPPConnection connection)
throws SmackException.NotConnectedException, InterruptedException {
Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr);
JingleS5BTransportManager transportManager = JingleS5BTransportManager.getInstanceFor(connection);
this.ourSelectedCandidate = connectToCandidates(MAX_TIMEOUT);
if (ourSelectedCandidate == CANDIDATE_FAILURE) {
connection.createStanzaCollectorAndSend(transportManager.createCandidateError(this));
connection.createStanzaCollectorAndSend(JingleS5BTransportManager.createCandidateError(this));
return;
}
@ -248,7 +247,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
throw new AssertionError("MUST NOT BE NULL.");
}
connection.createStanzaCollectorAndSend(transportManager.createCandidateUsed(this, ourSelectedCandidate));
connection.createStanzaCollectorAndSend(JingleS5BTransportManager.createCandidateUsed(this, ourSelectedCandidate));
connectIfReady();
}
@ -281,7 +280,6 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
@SuppressWarnings("ReferenceEquality")
private void connectIfReady() {
final JingleS5BTransportManager jingleS5BTransportManager = JingleS5BTransportManager.getInstanceFor(getParent().getParent().getJingleManager().getConnection());
final JingleSession session = getParent().getParent();
if (ourSelectedCandidate == null || theirSelectedCandidate == null) {
@ -331,7 +329,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
@Override
public void run() {
try {
session.getJingleManager().getConnection().createStanzaCollectorAndSend(jingleS5BTransportManager.createProxyError(JingleS5BTransport.this));
session.getJingleManager().getConnection().createStanzaCollectorAndSend(JingleS5BTransportManager.createProxyError(JingleS5BTransport.this));
} catch (SmackException.NotConnectedException | InterruptedException e1) {
LOGGER.log(Level.SEVERE, "Could not send proxy error: " + e, e);
}
@ -344,7 +342,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
if (isProxy) {
LOGGER.log(Level.INFO, "Send candidate-activate.");
JingleElement candidateActivate = jingleS5BTransportManager.createCandidateActivated((JingleS5BTransport) nominated.getParent(), nominated);
JingleElement candidateActivate = JingleS5BTransportManager.createCandidateActivated((JingleS5BTransport) nominated.getParent(), nominated);
try {
session.getJingleManager().getConnection().createStanzaCollectorAndSend(candidateActivate)

View File

@ -465,7 +465,7 @@ public class MultiUserChat {
* @deprecated use {@link #createOrJoin(MucEnterConfiguration)} instead.
*/
@Deprecated
public MucCreateConfigFormHandle createOrJoin(Resourcepart nickname, String password, DiscussionHistory history, long timeout)
public MucCreateConfigFormHandle createOrJoin(Resourcepart nickname, String password, @SuppressWarnings("deprecation") DiscussionHistory history, long timeout)
throws NoResponseException, XMPPErrorException, InterruptedException, MucAlreadyJoinedException, NotConnectedException, NotAMucServiceException {
MucEnterConfiguration.Builder builder = getEnterConfigurationBuilder(nickname).withPassword(
password).timeoutAfter(timeout);
@ -666,7 +666,7 @@ public class MultiUserChat {
public void join(
Resourcepart nickname,
String password,
DiscussionHistory history,
@SuppressWarnings("deprecation") DiscussionHistory history,
long timeout)
throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException, NotAMucServiceException {
MucEnterConfiguration.Builder builder = getEnterConfigurationBuilder(nickname).withPassword(

View File

@ -33,7 +33,7 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
* to true, otherwise it will be null.
* </ul>
*
* <h3>An Item created to send to a node (via {@link LeafNode#send()} or {@link LeafNode#publish()}</h3>
* <h3>An Item created to send to a node (via {@link LeafNode#publish()} or {@link LeafNode#publish()}</h3>
* <ul>
* <li>The id is optional, since the server will generate one if necessary, but should be used if it is
* meaningful in the context of the node. This value must be unique within the node that it is sent to, since
@ -57,8 +57,8 @@ public class Item extends NodeExtension
* Create an empty <tt>Item</tt> with no id. This is a valid item for nodes which are configured
* so that {@link ConfigureForm#isDeliverPayloads()} is false. In most cases an id will be generated by the server.
* For nodes configured with {@link ConfigureForm#isDeliverPayloads()} and {@link ConfigureForm#isPersistItems()}
* set to false, no <tt>Item</tt> is sent to the node, you have to use {@link LeafNode#send()} or {@link LeafNode#publish()}
* methods in this case.
* set to false, no <tt>Item</tt> is sent to the node, you have to use the {@link LeafNode#publish()}
* method in this case.
*/
public Item()
{

View File

@ -34,7 +34,7 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
* to true, otherwise it will be null.</li>
* </ul>
*
* <h3>An Item created to send to a node (via {@link LeafNode#send()} or {@link LeafNode#publish()}</h3>
* <h3>An Item created to send to a node (via {@link LeafNode#publish()}</h3>
* <ul>
* <li>The id is optional, since the server will generate one if necessary, but should be used if it is
* meaningful in the context of the node. This value must be unique within the node that it is sent to, since

View File

@ -272,8 +272,8 @@ public final class DeliveryReceiptManager extends Manager {
/**
* Enables automatic requests of delivery receipts for outgoing messages of
* {@link Message.Type#normal}, {@link Message.Type#chat} or {@link Message.Type#headline}, and
* with a {@link Message.Body} extension.
* {@link org.jivesoftware.smack.packet.Message.Type#normal}, {@link org.jivesoftware.smack.packet.Message.Type#chat} or {@link org.jivesoftware.smack.packet.Message.Type#headline}, and
* with a {@link org.jivesoftware.smack.packet.Message.Body} extension.
*
* @since 4.1
* @see #dontAutoAddDeliveryReceiptRequests()

View File

@ -35,13 +35,13 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.AbstractConnectionListener;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.ExceptionCallback;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.FeatureNotSupportedException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.SmackException.NotLoggedInException;
import org.jivesoftware.smack.SmackFuture;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPConnectionRegistry;
@ -63,7 +63,9 @@ import org.jivesoftware.smack.roster.packet.RosterPacket.Item;
import org.jivesoftware.smack.roster.packet.RosterVer;
import org.jivesoftware.smack.roster.packet.SubscriptionPreApproval;
import org.jivesoftware.smack.roster.rosterstore.RosterStore;
import org.jivesoftware.smack.util.ExceptionCallback;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.SuccessCallback;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
@ -428,7 +430,11 @@ public final class Roster extends Manager {
packet.setVersion(rosterStore.getRosterVersion());
}
rosterState = RosterState.loading;
connection.sendIqWithResponseCallback(packet, new RosterResultListener(), new ExceptionCallback() {
SmackFuture<IQ, Exception> future = connection.sendIqRequestAsync(packet);
future.onSuccess(new RosterResultListener()).onError(new ExceptionCallback<Exception>() {
@Override
public void processException(Exception exception) {
rosterState = RosterState.uninitialized;
@ -438,11 +444,12 @@ public final class Roster extends Manager {
} else {
logLevel = Level.SEVERE;
}
LOGGER.log(logLevel, "Exception reloading roster" , exception);
LOGGER.log(logLevel, "Exception reloading roster", exception);
for (RosterLoadedListener listener : rosterLoadedListeners) {
listener.onRosterLoadingFailed(exception);
}
}
});
}
@ -1565,10 +1572,10 @@ public final class Roster extends Manager {
/**
* Handles Roster results as described in <a href="https://tools.ietf.org/html/rfc6121#section-2.1.4">RFC 6121 2.1.4</a>.
*/
private class RosterResultListener implements StanzaListener {
private class RosterResultListener implements SuccessCallback<IQ> {
@Override
public void processStanza(Stanza packet) {
public void onSuccess(IQ packet) {
final XMPPConnection connection = connection();
LOGGER.log(Level.FINE, "RosterResultListener received {}", packet);
Collection<Jid> addedEntries = new ArrayList<>();