mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Merge branch '4.0'
Also slightly improve OfflineMessageManager.getMessages() Conflicts: build.gradle smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java
This commit is contained in:
commit
92a6d01507
12 changed files with 123 additions and 46 deletions
|
@ -20,6 +20,7 @@ package org.jivesoftware.smack;
|
|||
import org.jivesoftware.smack.packet.Session;
|
||||
import org.jivesoftware.smack.proxy.ProxyInfo;
|
||||
import org.jivesoftware.smack.util.DNSUtil;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.dns.HostAddress;
|
||||
import org.jxmpp.util.XmppStringUtils;
|
||||
|
||||
|
@ -191,6 +192,9 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
}
|
||||
|
||||
protected void init(String serviceName, ProxyInfo proxy) {
|
||||
if (StringUtils.isEmpty(serviceName)) {
|
||||
throw new IllegalArgumentException("serviceName must not be the empty String");
|
||||
}
|
||||
this.serviceName = serviceName;
|
||||
this.proxy = proxy;
|
||||
|
||||
|
@ -645,6 +649,9 @@ public class ConnectionConfiguration implements Cloneable {
|
|||
}
|
||||
|
||||
private void initHostAddresses(String host, int port) {
|
||||
if (StringUtils.isEmpty(host)) {
|
||||
throw new IllegalArgumentException("host must not be the empty String");
|
||||
}
|
||||
hostAddresses = new ArrayList<HostAddress>(1);
|
||||
HostAddress hostAddress;
|
||||
hostAddress = new HostAddress(host, port);
|
||||
|
|
|
@ -48,6 +48,9 @@ public class Java7ZlibInputOutputStream extends XMPPInputOutputStream {
|
|||
private final static boolean supported;
|
||||
private final static int compressionLevel = Deflater.DEFAULT_COMPRESSION;
|
||||
|
||||
private static final int SYNC_FLUSH_INT = 2;
|
||||
private static final int FULL_FLUSH_INT = 3;
|
||||
|
||||
static {
|
||||
Method m = null;
|
||||
try {
|
||||
|
@ -100,25 +103,23 @@ public class Java7ZlibInputOutputStream extends XMPPInputOutputStream {
|
|||
|
||||
@Override
|
||||
public OutputStream getOutputStream(OutputStream outputStream) {
|
||||
final int flushMethodInt;
|
||||
if (flushMethod == FlushMethod.SYNC_FLUSH) {
|
||||
flushMethodInt = SYNC_FLUSH_INT;
|
||||
} else {
|
||||
flushMethodInt = FULL_FLUSH_INT;
|
||||
}
|
||||
return new DeflaterOutputStream(outputStream, new Deflater(compressionLevel)) {
|
||||
public void flush() throws IOException {
|
||||
if (!supported) {
|
||||
super.flush();
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
if (!def.needsInput()) {
|
||||
do {
|
||||
count = def.deflate(buf, 0, buf.length);
|
||||
out.write(buf, 0, count);
|
||||
} while (count > 0);
|
||||
out.flush();
|
||||
}
|
||||
try {
|
||||
do {
|
||||
count = (Integer) method.invoke(def, buf, 0, buf.length, 2);
|
||||
int count;
|
||||
while ((count = (Integer) method.invoke(def, buf, 0, buf.length, flushMethodInt)) != 0) {
|
||||
out.write(buf, 0, count);
|
||||
} while (count > 0);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IOException("Can't flush");
|
||||
} catch (IllegalAccessException e) {
|
||||
|
|
|
@ -20,6 +20,21 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
|
||||
public abstract class XMPPInputOutputStream {
|
||||
|
||||
protected static FlushMethod flushMethod;
|
||||
|
||||
/**
|
||||
* Set the used flushed method when compressing data. The default is full flush which may not
|
||||
* achieve the best compression ratio, but provides better security against certain attacks.
|
||||
* Only use sync flush if you fully understand the implications.
|
||||
*
|
||||
* @see <a href="https://blog.thijsalkema.de/blog/2014/08/07/https-attacks-and-xmpp-2-crime-and-breach/">Attacks against XMPP when using compression</a>
|
||||
* @param flushMethod
|
||||
*/
|
||||
public static void setFlushMethod(FlushMethod flushMethod) {
|
||||
XMPPInputOutputStream.flushMethod = flushMethod;
|
||||
}
|
||||
|
||||
protected String compressionMethod;
|
||||
|
||||
public String getCompressionMethod() {
|
||||
|
@ -31,4 +46,9 @@ public abstract class XMPPInputOutputStream {
|
|||
public abstract InputStream getInputStream(InputStream inputStream) throws Exception;
|
||||
|
||||
public abstract OutputStream getOutputStream(OutputStream outputStream) throws Exception;
|
||||
|
||||
public enum FlushMethod {
|
||||
FULL_FLUSH,
|
||||
SYNC_FLUSH,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -279,13 +279,23 @@ public class StringUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given CharSequence is not null or empty.
|
||||
* Returns true if the given CharSequence is null or empty.
|
||||
*
|
||||
* @param cs
|
||||
* @return true if the given CharSequence is not null or empty
|
||||
* @return true if the given CharSequence is null or empty
|
||||
*/
|
||||
public static boolean isNullOrEmpty(CharSequence cs) {
|
||||
return cs == null || cs.length() == 0;
|
||||
return cs == null || isEmpty(cs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given CharSequence is empty
|
||||
*
|
||||
* @param cs
|
||||
* @return true if the given CharSequence is empty
|
||||
*/
|
||||
public static boolean isEmpty(CharSequence cs) {
|
||||
return cs.length() == 0;
|
||||
}
|
||||
|
||||
public static String collectionToString(Collection<String> collection) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue