aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/utils')
-rw-r--r--src/main/java/eu/siacs/conversations/utils/DNSHelper.java29
-rw-r--r--src/main/java/eu/siacs/conversations/utils/PhoneHelper.java5
-rw-r--r--src/main/java/eu/siacs/conversations/utils/Validator.java14
-rw-r--r--src/main/java/eu/siacs/conversations/utils/Xmlns.java7
-rw-r--r--src/main/java/eu/siacs/conversations/utils/XmppUri.java3
-rw-r--r--src/main/java/eu/siacs/conversations/utils/zlib/ZLibInputStream.java54
-rw-r--r--src/main/java/eu/siacs/conversations/utils/zlib/ZLibOutputStream.java95
7 files changed, 31 insertions, 176 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
index 8c1a8dea..a09b4d0f 100644
--- a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java
@@ -140,15 +140,18 @@ public class DNSHelper {
}
ArrayList<Bundle> values = new ArrayList<>();
for (SRV srv : result) {
- Bundle namePort = new Bundle();
- namePort.putString("name", srv.getName());
- namePort.putInt("port", srv.getPort());
+ boolean added = false;
+ if (ips6.containsKey(srv.getName())) {
+ values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips6));
+ added = true;
+ }
if (ips4.containsKey(srv.getName())) {
- ArrayList<String> ip = ips4.get(srv.getName());
- Collections.shuffle(ip, rnd);
- namePort.putString("ipv4", ip.get(0));
+ values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips4));
+ added = true;
+ }
+ if (!added) {
+ values.add(createNamePortBundle(srv.getName(),srv.getPort(),null));
}
- values.add(namePort);
}
bundle.putParcelableArrayList("values", values);
} catch (SocketTimeoutException e) {
@@ -159,6 +162,18 @@ public class DNSHelper {
return bundle;
}
+ private static Bundle createNamePortBundle(String name, int port, TreeMap<String, ArrayList<String>> ips) {
+ Bundle namePort = new Bundle();
+ namePort.putString("name", name);
+ namePort.putInt("port", port);
+ if (ips!=null) {
+ ArrayList<String> ip = ips.get(name);
+ Collections.shuffle(ip, new Random());
+ namePort.putString("ip", ip.get(0));
+ }
+ return namePort;
+ }
+
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
diff --git a/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java b/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java
index 87973159..9a5cbaaf 100644
--- a/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java
@@ -16,10 +16,7 @@ import android.provider.ContactsContract.Profile;
public class PhoneHelper {
- public static void loadPhoneContacts(Context context,
- final OnPhoneContactsLoadedListener listener) {
- final List<Bundle> phoneContacts = new ArrayList<Bundle>();
-
+ public static void loadPhoneContacts(Context context,final List<Bundle> phoneContacts, final OnPhoneContactsLoadedListener listener) {
final String[] PROJECTION = new String[] { ContactsContract.Data._ID,
ContactsContract.Data.DISPLAY_NAME,
ContactsContract.Data.PHOTO_URI,
diff --git a/src/main/java/eu/siacs/conversations/utils/Validator.java b/src/main/java/eu/siacs/conversations/utils/Validator.java
deleted file mode 100644
index 00130fa2..00000000
--- a/src/main/java/eu/siacs/conversations/utils/Validator.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package eu.siacs.conversations.utils;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class Validator {
- public static final Pattern VALID_JID = Pattern.compile(
- "^[^@/<>'\"\\s]+@[^@/<>'\"\\s]+$", Pattern.CASE_INSENSITIVE);
-
- public static boolean isValidJid(String jid) {
- Matcher matcher = VALID_JID.matcher(jid);
- return matcher.find();
- }
-}
diff --git a/src/main/java/eu/siacs/conversations/utils/Xmlns.java b/src/main/java/eu/siacs/conversations/utils/Xmlns.java
new file mode 100644
index 00000000..67de7c79
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/utils/Xmlns.java
@@ -0,0 +1,7 @@
+package eu.siacs.conversations.utils;
+
+public final class Xmlns {
+ public static final String BLOCKING = "urn:xmpp:blocking";
+ public static final String ROSTER = "jabber:iq:roster";
+ public static final String REGISTER = "jabber:iq:register";
+}
diff --git a/src/main/java/eu/siacs/conversations/utils/XmppUri.java b/src/main/java/eu/siacs/conversations/utils/XmppUri.java
index a9b8d1c0..aacb6362 100644
--- a/src/main/java/eu/siacs/conversations/utils/XmppUri.java
+++ b/src/main/java/eu/siacs/conversations/utils/XmppUri.java
@@ -5,7 +5,6 @@ import android.net.Uri;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
-import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
@@ -54,7 +53,7 @@ public class XmppUri {
final String NEEDLE = "otr-fingerprint=";
int index = query.indexOf(NEEDLE);
if (index >= 0 && query.length() >= (NEEDLE.length() + index + 40)) {
- return CryptoHelper.prettifyFingerprint(query.substring(index + NEEDLE.length(), index + NEEDLE.length() + 40));
+ return query.substring(index + NEEDLE.length(), index + NEEDLE.length() + 40);
} else {
return null;
}
diff --git a/src/main/java/eu/siacs/conversations/utils/zlib/ZLibInputStream.java b/src/main/java/eu/siacs/conversations/utils/zlib/ZLibInputStream.java
deleted file mode 100644
index b777c10c..00000000
--- a/src/main/java/eu/siacs/conversations/utils/zlib/ZLibInputStream.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package eu.siacs.conversations.utils.zlib;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.Inflater;
-import java.util.zip.InflaterInputStream;
-
-/**
- * ZLibInputStream is a zlib and input stream compatible version of an
- * InflaterInputStream. This class solves the incompatibility between
- * {@link InputStream#available()} and {@link InflaterInputStream#available()}.
- */
-public class ZLibInputStream extends InflaterInputStream {
-
- /**
- * Construct a ZLibInputStream, reading data from the underlying stream.
- *
- * @param is
- * The {@code InputStream} to read data from.
- * @throws IOException
- * If an {@code IOException} occurs.
- */
- public ZLibInputStream(InputStream is) throws IOException {
- super(is, new Inflater(), 512);
- }
-
- /**
- * Provide a more InputStream compatible version of available. A return
- * value of 1 means that it is likly to read one byte without blocking, 0
- * means that the system is known to block for more input.
- *
- * @return 0 if no data is available, 1 otherwise
- * @throws IOException
- */
- @Override
- public int available() throws IOException {
- /*
- * This is one of the funny code blocks. InflaterInputStream.available
- * violates the contract of InputStream.available, which breaks kXML2.
- *
- * I'm not sure who's to blame, oracle/sun for a broken api or the
- * google guys for mixing a sun bug with a xml reader that can't handle
- * it....
- *
- * Anyway, this simple if breaks suns distorted reality, but helps to
- * use the api as intended.
- */
- if (inf.needsInput()) {
- return 0;
- }
- return super.available();
- }
-
-}
diff --git a/src/main/java/eu/siacs/conversations/utils/zlib/ZLibOutputStream.java b/src/main/java/eu/siacs/conversations/utils/zlib/ZLibOutputStream.java
deleted file mode 100644
index 8b3f5e68..00000000
--- a/src/main/java/eu/siacs/conversations/utils/zlib/ZLibOutputStream.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package eu.siacs.conversations.utils.zlib;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.security.NoSuchAlgorithmException;
-import java.util.zip.Deflater;
-import java.util.zip.DeflaterOutputStream;
-
-/**
- * <p>
- * Android 2.2 includes Java7 FLUSH_SYNC option, which will be used by this
- * Implementation, preferable via reflection. The @hide was remove in API level
- * 19. This class might thus go away in the future.
- * </p>
- * <p>
- * Please use {@link ZLibOutputStream#SUPPORTED} to check for flush
- * compatibility.
- * </p>
- */
-public class ZLibOutputStream extends DeflaterOutputStream {
-
- /**
- * The reflection based flush method.
- */
-
- private final static Method method;
- /**
- * SUPPORTED is true if a flush compatible method exists.
- */
- public final static boolean SUPPORTED;
-
- /**
- * Static block to initialize {@link #SUPPORTED} and {@link #method}.
- */
- static {
- Method m = null;
- try {
- m = Deflater.class.getMethod("deflate", byte[].class, int.class,
- int.class, int.class);
- } catch (SecurityException e) {
- } catch (NoSuchMethodException e) {
- }
- method = m;
- SUPPORTED = (method != null);
- }
-
- /**
- * Create a new ZLib compatible output stream wrapping the given low level
- * stream. ZLib compatiblity means we will send a zlib header.
- *
- * @param os
- * OutputStream The underlying stream.
- * @throws IOException
- * In case of a lowlevel transfer problem.
- * @throws NoSuchAlgorithmException
- * In case of a {@link Deflater} error.
- */
- public ZLibOutputStream(OutputStream os) throws IOException,
- NoSuchAlgorithmException {
- super(os, new Deflater(Deflater.BEST_COMPRESSION));
- }
-
- /**
- * Flush the given stream, preferring Java7 FLUSH_SYNC if available.
- *
- * @throws IOException
- * In case of a lowlevel exception.
- */
- @Override
- public void flush() throws IOException {
- if (!SUPPORTED) {
- super.flush();
- return;
- }
- try {
- int count = 0;
- do {
- count = (Integer) method.invoke(def, buf, 0, buf.length, 3);
- if (count > 0) {
- out.write(buf, 0, count);
- }
- } while (count > 0);
- } catch (IllegalArgumentException e) {
- throw new IOException("Can't flush");
- } catch (IllegalAccessException e) {
- throw new IOException("Can't flush");
- } catch (InvocationTargetException e) {
- throw new IOException("Can't flush");
- }
- super.flush();
- }
-
-}