diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/xmpp')
-rw-r--r-- | src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 62 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java | 10 |
2 files changed, 30 insertions, 42 deletions
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 7cd4707d..08dbdc18 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -13,8 +13,6 @@ import android.util.Log; import android.util.Pair; import android.util.SparseArray; -import org.json.JSONException; -import org.json.JSONObject; import org.xmlpull.v1.XmlPullParserException; import java.io.ByteArrayInputStream; @@ -26,8 +24,8 @@ import java.net.IDN; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; -import java.net.UnknownHostException; import java.net.URL; +import java.net.UnknownHostException; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.Principal; @@ -61,6 +59,7 @@ import eu.siacs.conversations.crypto.sasl.External; import eu.siacs.conversations.crypto.sasl.Plain; import eu.siacs.conversations.crypto.sasl.SaslMechanism; import eu.siacs.conversations.crypto.sasl.ScramSha1; +import eu.siacs.conversations.crypto.sasl.ScramSha256; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.ServiceDiscoveryResult; @@ -178,8 +177,6 @@ public class XmppConnection implements Runnable { } } - private Identity mServerIdentity = Identity.UNKNOWN; - public final OnIqPacketReceived registrationResponseListener = new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { @@ -253,17 +250,6 @@ public class XmppConnection implements Runnable { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": connecting"); features.encryptionEnabled = false; this.attempt++; - switch (account.getJid().getDomainpart()) { - case "chat.facebook.com": - mServerIdentity = Identity.FACEBOOK; - break; - case "nimbuzz.com": - mServerIdentity = Identity.NIMBUZZ; - break; - default: - mServerIdentity = Identity.UNKNOWN; - break; - } try { Socket localSocket; shouldAuthenticate = needsBinding = !account.isOptionSet(Account.OPTION_REGISTER); @@ -747,7 +733,7 @@ public class XmppConnection implements Runnable { final Pair<IqPacket, OnIqPacketReceived> packetCallbackDuple = packetCallbacks.get(packet.getId()); // Packets to the server should have responses from the server if (packetCallbackDuple.first.toServer(account)) { - if (packet.fromServer(account) || mServerIdentity == Identity.FACEBOOK) { + if (packet.fromServer(account)) { callback = packetCallbackDuple.second; packetCallbacks.remove(packet.getId()); } else { @@ -868,6 +854,8 @@ public class XmppConnection implements Runnable { auth.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl"); if (mechanisms.contains("EXTERNAL") && account.getPrivateKeyAlias() != null) { saslMechanism = new External(tagWriter, account, mXmppConnectionService.getRNG()); + } else if (mechanisms.contains("SCRAM-SHA-256")) { + saslMechanism = new ScramSha256(tagWriter, account, mXmppConnectionService.getRNG()); } else if (mechanisms.contains("SCRAM-SHA-1")) { saslMechanism = new ScramSha1(tagWriter, account, mXmppConnectionService.getRNG()); } else if (mechanisms.contains("PLAIN")) { @@ -1099,7 +1087,7 @@ public class XmppConnection implements Runnable { this.disco.clear(); } mPendingServiceDiscoveries.set(0); - mWaitForDisco.set(mServerIdentity != Identity.NIMBUZZ && smVersion != 0); + mWaitForDisco.set(smVersion != 0 && !account.getJid().getDomainpart().equalsIgnoreCase("nimbuzz.com")); lastDiscoStarted = SystemClock.elapsedRealtime(); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": starting service discovery"); mXmppConnectionService.scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode()); @@ -1138,24 +1126,6 @@ public class XmppConnection implements Runnable { boolean advancedStreamFeaturesLoaded; synchronized (XmppConnection.this.disco) { ServiceDiscoveryResult result = new ServiceDiscoveryResult(packet); - for (final ServiceDiscoveryResult.Identity id : result.getIdentities()) { - if (mServerIdentity == Identity.UNKNOWN && id.getType().equals("im") && - id.getCategory().equals("server") && id.getName() != null && - jid.equals(account.getServer())) { - switch (id.getName()) { - case "Prosody": - mServerIdentity = Identity.PROSODY; - break; - case "ejabberd": - mServerIdentity = Identity.EJABBERD; - break; - case "Slack-XMPP": - mServerIdentity = Identity.SLACK; - break; - } - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server name: " + id.getName()); - } - } if (jid.equals(account.getServer())) { mXmppConnectionService.databaseBackend.insertDiscoveryResult(result); } @@ -1540,7 +1510,25 @@ public class XmppConnection implements Runnable { } public Identity getServerIdentity() { - return mServerIdentity; + synchronized (this.disco) { + ServiceDiscoveryResult result = disco.get(account.getJid().toDomainJid()); + if (result == null) { + return Identity.UNKNOWN; + } + for (final ServiceDiscoveryResult.Identity id : result.getIdentities()) { + if (id.getType().equals("im") && id.getCategory().equals("server") && id.getName() != null) { + switch (id.getName()) { + case "Prosody": + return Identity.PROSODY; + case "ejabberd": + return Identity.EJABBERD; + case "Slack-XMPP": + return Identity.SLACK; + } + } + } + } + return Identity.UNKNOWN; } private class UnauthorizedException extends IOException { diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 5461b9c6..0c0c054d 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -388,7 +388,7 @@ public class JingleConnection implements Transferable { long size = Long.parseLong(fileSize.getContent()); message.setBody(Long.toString(size)); conversation.add(message); - mXmppConnectionService.updateConversationUi(); + mJingleConnectionManager.updateConversationUi(true); if (mJingleConnectionManager.hasStoragePermission() && size < this.mJingleConnectionManager.getAutoAcceptFileSize() && mXmppConnectionService.isDataSaverDisabled()) { @@ -510,7 +510,7 @@ public class JingleConnection implements Transferable { private void sendAccept() { mJingleStatus = JINGLE_STATUS_ACCEPTED; this.mStatus = Transferable.STATUS_DOWNLOADING; - mXmppConnectionService.updateConversationUi(); + this.mJingleConnectionManager.updateConversationUi(true); this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() { @Override public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) { @@ -842,7 +842,7 @@ public class JingleConnection implements Transferable { if (this.file!=null) { file.delete(); } - this.mXmppConnectionService.updateConversationUi(); + this.mJingleConnectionManager.updateConversationUi(true); } else { this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_FAILED); @@ -868,7 +868,7 @@ public class JingleConnection implements Transferable { if (this.file!=null) { file.delete(); } - this.mXmppConnectionService.updateConversationUi(); + this.mJingleConnectionManager.updateConversationUi(true); } else { this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_FAILED, @@ -1016,7 +1016,7 @@ public class JingleConnection implements Transferable { public void updateProgress(int i) { this.mProgress = i; - mXmppConnectionService.updateConversationUi(); + mJingleConnectionManager.updateConversationUi(false); } public String getTransportId() { |