aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-08 20:57:53 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-08 20:57:53 +0200
commit9b39e693d0ea9e1917d37c8c570529ab9a6c52b7 (patch)
tree9394322cf5ea128e220a76176fd604a0437b9de0 /src
parent8f65e5056be793be79504d45ad77d49be6993aa5 (diff)
trim to original resource if server added something
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index 0cab67922..515f0b3c6 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -1,5 +1,6 @@
package de.pixart.messenger.xmpp;
+import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.SystemClock;
@@ -1035,6 +1036,8 @@ public class XmppConnection implements Runnable {
clearIqCallbacks();
if (account.getJid().isBareJid()) {
account.setResource(this.createNewResource());
+ } else {
+ fixResource(mXmppConnectionService, account);
}
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
final String resource = Config.USE_RANDOM_RESOURCE_ON_EVERY_BIND ? nextRandomId() : account.getResource();
@@ -1315,7 +1318,7 @@ public class XmppConnection implements Runnable {
private void sendStartStream() throws IOException {
final Tag stream = Tag.start("stream:stream");
- stream.setAttribute("to", account.getServer().toString());
+ stream.setAttribute("to", account.getServer());
stream.setAttribute("version", "1.0");
stream.setAttribute("xml:lang", "en");
stream.setAttribute("xmlns", "jabber:client");
@@ -1327,6 +1330,25 @@ public class XmppConnection implements Runnable {
return mXmppConnectionService.getString(R.string.app_name) + '.' + nextRandomId(true);
}
+ private static void fixResource(Context context, Account account) {
+ String resource = account.getResource();
+ int fixedPartLength = context.getString(R.string.app_name).length() + 1; //include the trailing dot
+ int randomPartLength = 4; // 3 bytes
+ if (resource != null && resource.length() > fixedPartLength + randomPartLength) {
+ if (validBase64(resource.substring(fixedPartLength, fixedPartLength + randomPartLength))) {
+ account.setResource(resource.substring(0, fixedPartLength + randomPartLength));
+ }
+ }
+ }
+
+ private static boolean validBase64(String input) {
+ try {
+ return Base64.decode(input, Base64.URL_SAFE).length == 3;
+ } catch (Throwable throwable) {
+ return false;
+ }
+ }
+
private String nextRandomId() {
return nextRandomId(false);
}