mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 03:32:15 -05:00
refactor getServerIdentity() to parse disco result directly
This commit is contained in:
parent
c03e3b5965
commit
1876b444fa
@ -178,8 +178,6 @@ public class XmppConnection implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Identity mServerIdentity = Identity.UNKNOWN;
|
|
||||||
|
|
||||||
public final OnIqPacketReceived registrationResponseListener = new OnIqPacketReceived() {
|
public final OnIqPacketReceived registrationResponseListener = new OnIqPacketReceived() {
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(Account account, IqPacket packet) {
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
||||||
@ -253,17 +251,6 @@ public class XmppConnection implements Runnable {
|
|||||||
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": connecting");
|
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": connecting");
|
||||||
features.encryptionEnabled = false;
|
features.encryptionEnabled = false;
|
||||||
this.attempt++;
|
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 {
|
try {
|
||||||
Socket localSocket;
|
Socket localSocket;
|
||||||
shouldAuthenticate = needsBinding = !account.isOptionSet(Account.OPTION_REGISTER);
|
shouldAuthenticate = needsBinding = !account.isOptionSet(Account.OPTION_REGISTER);
|
||||||
@ -747,7 +734,7 @@ public class XmppConnection implements Runnable {
|
|||||||
final Pair<IqPacket, OnIqPacketReceived> packetCallbackDuple = packetCallbacks.get(packet.getId());
|
final Pair<IqPacket, OnIqPacketReceived> packetCallbackDuple = packetCallbacks.get(packet.getId());
|
||||||
// Packets to the server should have responses from the server
|
// Packets to the server should have responses from the server
|
||||||
if (packetCallbackDuple.first.toServer(account)) {
|
if (packetCallbackDuple.first.toServer(account)) {
|
||||||
if (packet.fromServer(account) || mServerIdentity == Identity.FACEBOOK) {
|
if (packet.fromServer(account)) {
|
||||||
callback = packetCallbackDuple.second;
|
callback = packetCallbackDuple.second;
|
||||||
packetCallbacks.remove(packet.getId());
|
packetCallbacks.remove(packet.getId());
|
||||||
} else {
|
} else {
|
||||||
@ -1099,7 +1086,7 @@ public class XmppConnection implements Runnable {
|
|||||||
this.disco.clear();
|
this.disco.clear();
|
||||||
}
|
}
|
||||||
mPendingServiceDiscoveries.set(0);
|
mPendingServiceDiscoveries.set(0);
|
||||||
mWaitForDisco.set(mServerIdentity != Identity.NIMBUZZ && smVersion != 0);
|
mWaitForDisco.set(smVersion != 0 && !account.getJid().getDomainpart().equalsIgnoreCase("nimbuzz.com"));
|
||||||
lastDiscoStarted = SystemClock.elapsedRealtime();
|
lastDiscoStarted = SystemClock.elapsedRealtime();
|
||||||
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": starting service discovery");
|
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": starting service discovery");
|
||||||
mXmppConnectionService.scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode());
|
mXmppConnectionService.scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode());
|
||||||
@ -1138,24 +1125,6 @@ public class XmppConnection implements Runnable {
|
|||||||
boolean advancedStreamFeaturesLoaded;
|
boolean advancedStreamFeaturesLoaded;
|
||||||
synchronized (XmppConnection.this.disco) {
|
synchronized (XmppConnection.this.disco) {
|
||||||
ServiceDiscoveryResult result = new ServiceDiscoveryResult(packet);
|
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())) {
|
if (jid.equals(account.getServer())) {
|
||||||
mXmppConnectionService.databaseBackend.insertDiscoveryResult(result);
|
mXmppConnectionService.databaseBackend.insertDiscoveryResult(result);
|
||||||
}
|
}
|
||||||
@ -1540,7 +1509,25 @@ public class XmppConnection implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Identity getServerIdentity() {
|
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 {
|
private class UnauthorizedException extends IOException {
|
||||||
|
Loading…
Reference in New Issue
Block a user