1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

Merge branch '4.2'

This commit is contained in:
Florian Schmaus 2017-11-22 08:37:47 +01:00
commit 81002c4fbd
63 changed files with 391 additions and 266 deletions

View file

@ -46,6 +46,7 @@ import org.jivesoftware.smack.SmackException.AlreadyConnectedException;
import org.jivesoftware.smack.SmackException.AlreadyLoggedInException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.SmackException.NotLoggedInException;
import org.jivesoftware.smack.SmackException.ResourceBindingNotOfferedException;
import org.jivesoftware.smack.SmackException.SecurityRequiredByClientException;
import org.jivesoftware.smack.SmackException.SecurityRequiredException;
@ -1541,7 +1542,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
final StanzaListener packetListener = new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException {
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException, NotLoggedInException {
boolean removed = removeAsyncStanzaListener(this);
if (!removed) {
// We lost a race against the "no response" handling runnable. Avoid calling the callback, as the
@ -1609,7 +1610,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
public void addOneTimeSyncCallback(final StanzaListener callback, final StanzaFilter packetFilter) {
final StanzaListener packetListener = new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException {
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException, NotLoggedInException {
try {
callback.processStanza(packet);
} finally {

View file

@ -18,6 +18,7 @@
package org.jivesoftware.smack;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.SmackException.NotLoggedInException;
import org.jivesoftware.smack.packet.Stanza;
/**
@ -49,7 +50,8 @@ public interface StanzaListener {
* @param packet the stanza(/packet) to process.
* @throws NotConnectedException
* @throws InterruptedException
* @throws NotLoggedInException
*/
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException;
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException, NotLoggedInException;
}

View file

@ -66,7 +66,15 @@ public final class Presence extends Stanza implements TypedCloneable<Presence> {
private Type type = Type.available;
private String status = null;
/**
* The priority of the presence. The magic value {@link Integer#MIN_VALUE} is used to indicate that the original
* presence stanza did not had an explicit priority set. In which case the priority defaults to 0.
*
* @see <a href="https://tools.ietf.org/html/rfc6121#section-4.7.2.3">RFC 6121 § 4.7.2.3.</a>
*/
private int priority = Integer.MIN_VALUE;
private Mode mode = null;
/**
@ -201,6 +209,9 @@ public final class Presence extends Stanza implements TypedCloneable<Presence> {
* @see <a href="https://tools.ietf.org/html/rfc6121#section-4.7.2.3">RFC 6121 § 4.7.2.3. Priority Element</a>
*/
public int getPriority() {
if (priority == Integer.MIN_VALUE) {
return 0;
}
return priority;
}

View file

@ -226,9 +226,13 @@ public class XMPPError extends AbstractError {
}
public static XMPPError.Builder from(Condition condition, String descriptiveText) {
Map<String, String> descriptiveTexts = new HashMap<String, String>();
descriptiveTexts.put("en", descriptiveText);
return getBuilder().setCondition(condition).setDescriptiveTexts(descriptiveTexts);
XMPPError.Builder builder = getBuilder().setCondition(condition);
if (descriptiveText != null) {
Map<String, String> descriptiveTexts = new HashMap<>();
descriptiveTexts.put("en", descriptiveText);
builder.setDescriptiveTexts(descriptiveTexts);
}
return builder;
}
public static Builder getBuilder() {

View file

@ -97,7 +97,6 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
| 1 | 1 |
+----+--------+
*/
//in.read(buf, 0, 2);
fill(in, buf, 2);
boolean check = false;
@ -160,7 +159,6 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
`failure' (STATUS value other than X'00') status, it MUST close the
connection.
*/
//in.read(buf, 0, 2);
fill(in, buf, 2);
if (buf[1] == 0)
{
@ -260,7 +258,6 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
o BND.PORT server bound port in network octet order
*/
//in.read(buf, 0, 4);
fill(in, buf, 4);
if (buf[1] != 0)
@ -279,17 +276,13 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
switch (buf[3] & 0xff)
{
case 1:
//in.read(buf, 0, 6);
fill(in, buf, 6);
break;
case 3:
//in.read(buf, 0, 1);
fill(in, buf, 1);
//in.read(buf, 0, buf[0]+2);
fill(in, buf, (buf[0] & 0xff) + 2);
break;
case 4:
//in.read(buf, 0, 18);
fill(in, buf, 18);
break;
default:

View file

@ -272,7 +272,7 @@ public class StringUtils {
* array index.
*/
private static final char[] numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz" +
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
"ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
/**
* Returns a random String of numbers and letters (lower and upper case)
@ -288,17 +288,7 @@ public class StringUtils {
* @return a random String of numbers and letters of the specified length.
*/
public static String insecureRandomString(int length) {
if (length < 1) {
return null;
}
final Random random = randGen.get();
// Create a char buffer to put random letters and numbers in.
char[] randBuffer = new char[length];
for (int i = 0; i < randBuffer.length; i++) {
randBuffer[i] = numbersAndLetters[random.nextInt(numbersAndLetters.length)];
}
return new String(randBuffer);
return randomString(length, randGen.get());
}
private static final ThreadLocal<SecureRandom> SECURE_RANDOM = new ThreadLocal<SecureRandom>() {
@ -309,12 +299,16 @@ public class StringUtils {
};
public static String randomString(final int length) {
return randomString(length, SECURE_RANDOM.get());
}
private static String randomString(final int length, Random random) {
if (length < 1) {
return null;
}
byte[] randomBytes = new byte[length];
SECURE_RANDOM.get().nextBytes(randomBytes);
random.nextBytes(randomBytes);
char[] randomChars = new char[length];
for (int i = 0; i < length; i++) {
randomChars[i] = getPrintableChar(randomBytes[i]);

View file

@ -172,7 +172,7 @@ public class StanzaCollectorTest
catch (InterruptedException e)
{
}
//We cannot guarantee that this is going to pass due to the possible issue of timing between consumer 1
// We cannot guarantee that this is going to pass due to the possible issue of timing between consumer 1
// and main, but the probability is extremely remote.
assertNull(collector.pollResult());
}