synchronize around the disco object
This commit is contained in:
parent
0bd4105b1d
commit
adca670196
|
@ -812,7 +812,7 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendBindRequest() {
|
private void sendBindRequest() {
|
||||||
while(!mXmppConnectionService.areMessagesInitialized()) {
|
while(!mXmppConnectionService.areMessagesInitialized() && socket != null && !socket.isClosed()) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
} catch (final InterruptedException ignored) {
|
} catch (final InterruptedException ignored) {
|
||||||
|
@ -907,7 +907,9 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
features.carbonsEnabled = false;
|
features.carbonsEnabled = false;
|
||||||
features.blockListRequested = false;
|
features.blockListRequested = false;
|
||||||
disco.clear();
|
synchronized (this.disco) {
|
||||||
|
this.disco.clear();
|
||||||
|
}
|
||||||
sendServiceDiscoveryInfo(account.getServer());
|
sendServiceDiscoveryInfo(account.getServer());
|
||||||
sendServiceDiscoveryInfo(account.getJid().toBareJid());
|
sendServiceDiscoveryInfo(account.getJid().toBareJid());
|
||||||
sendServiceDiscoveryItems(account.getServer());
|
sendServiceDiscoveryItems(account.getServer());
|
||||||
|
@ -920,19 +922,16 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendServiceDiscoveryInfo(final Jid jid) {
|
private void sendServiceDiscoveryInfo(final Jid jid) {
|
||||||
if (disco.containsKey(jid)) {
|
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
|
||||||
if (account.getServer().equals(jid)) {
|
iq.setTo(jid);
|
||||||
enableAdvancedStreamFeatures();
|
iq.query("http://jabber.org/protocol/disco#info");
|
||||||
}
|
this.sendIqPacket(iq, new OnIqPacketReceived() {
|
||||||
} else {
|
|
||||||
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
|
|
||||||
iq.setTo(jid);
|
|
||||||
iq.query("http://jabber.org/protocol/disco#info");
|
|
||||||
this.sendIqPacket(iq, new OnIqPacketReceived() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(final Account account, final IqPacket packet) {
|
public void onIqPacketReceived(final Account account, final IqPacket packet) {
|
||||||
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
||||||
|
boolean advancedStreamFeaturesLoaded = false;
|
||||||
|
synchronized (XmppConnection.this.disco) {
|
||||||
final List<Element> elements = packet.query().getChildren();
|
final List<Element> elements = packet.query().getChildren();
|
||||||
final Info info = new Info();
|
final Info info = new Info();
|
||||||
for (final Element element : elements) {
|
for (final Element element : elements) {
|
||||||
|
@ -947,17 +946,17 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
disco.put(jid, info);
|
disco.put(jid, info);
|
||||||
if ((jid.equals(account.getServer()) || jid.equals(account.getJid().toBareJid()))
|
advancedStreamFeaturesLoaded = disco.containsKey(account.getServer())
|
||||||
&& disco.containsKey(account.getServer())
|
&& disco.containsKey(account.getJid().toBareJid());
|
||||||
&& disco.containsKey(account.getJid().toBareJid())) {
|
|
||||||
enableAdvancedStreamFeatures();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not query disco info for "+jid.toString());
|
|
||||||
}
|
}
|
||||||
|
if (advancedStreamFeaturesLoaded && (jid.equals(account.getServer()) || jid.equals(account.getJid().toBareJid()))) {
|
||||||
|
enableAdvancedStreamFeatures();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not query disco info for " + jid.toString());
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableAdvancedStreamFeatures() {
|
private void enableAdvancedStreamFeatures() {
|
||||||
|
@ -1184,13 +1183,15 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Jid> findDiscoItemsByFeature(final String feature) {
|
public List<Jid> findDiscoItemsByFeature(final String feature) {
|
||||||
final List<Jid> items = new ArrayList<>();
|
synchronized (this.disco) {
|
||||||
for (final Entry<Jid, Info> cursor : disco.entrySet()) {
|
final List<Jid> items = new ArrayList<>();
|
||||||
if (cursor.getValue().features.contains(feature)) {
|
for (final Entry<Jid, Info> cursor : this.disco.entrySet()) {
|
||||||
items.add(cursor.getKey());
|
if (cursor.getValue().features.contains(feature)) {
|
||||||
|
items.add(cursor.getKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
return items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jid findDiscoItemByFeature(final String feature) {
|
public Jid findDiscoItemByFeature(final String feature) {
|
||||||
|
@ -1211,12 +1212,14 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMucServer() {
|
public String getMucServer() {
|
||||||
for (final Entry<Jid, Info> cursor : disco.entrySet()) {
|
synchronized (this.disco) {
|
||||||
final Info value = cursor.getValue();
|
for (final Entry<Jid, Info> cursor : disco.entrySet()) {
|
||||||
if (value.features.contains("http://jabber.org/protocol/muc")
|
final Info value = cursor.getValue();
|
||||||
&& !value.features.contains("jabber:iq:gateway")
|
if (value.features.contains("http://jabber.org/protocol/muc")
|
||||||
&& !value.identities.contains(new Pair<>("conference","irc"))) {
|
&& !value.features.contains("jabber:iq:gateway")
|
||||||
return cursor.getKey().toString();
|
&& !value.identities.contains(new Pair<>("conference", "irc"))) {
|
||||||
|
return cursor.getKey().toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -1302,8 +1305,10 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasDiscoFeature(final Jid server, final String feature) {
|
private boolean hasDiscoFeature(final Jid server, final String feature) {
|
||||||
return connection.disco.containsKey(server) &&
|
synchronized (XmppConnection.this.disco) {
|
||||||
connection.disco.get(server).features.contains(feature);
|
return connection.disco.containsKey(server) &&
|
||||||
|
connection.disco.get(server).features.contains(feature);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean carbons() {
|
public boolean carbons() {
|
||||||
|
@ -1328,13 +1333,15 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean pep() {
|
public boolean pep() {
|
||||||
final Pair<String,String> needle = new Pair<>("pubsub","pep");
|
synchronized (XmppConnection.this.disco) {
|
||||||
Info info = disco.get(account.getServer());
|
final Pair<String, String> needle = new Pair<>("pubsub", "pep");
|
||||||
if (info != null && info.identities.contains(needle)) {
|
Info info = disco.get(account.getServer());
|
||||||
return true;
|
if (info != null && info.identities.contains(needle)) {
|
||||||
} else {
|
return true;
|
||||||
info = disco.get(account.getJid().toBareJid());
|
} else {
|
||||||
return info != null && info.identities.contains(needle);
|
info = disco.get(account.getJid().toBareJid());
|
||||||
|
return info != null && info.identities.contains(needle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1347,7 +1354,9 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean advancedStreamFeaturesLoaded() {
|
public boolean advancedStreamFeaturesLoaded() {
|
||||||
return disco.containsKey(account.getServer());
|
synchronized (XmppConnection.this.disco) {
|
||||||
|
return disco.containsKey(account.getServer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean rosterVersioning() {
|
public boolean rosterVersioning() {
|
||||||
|
|
Loading…
Reference in a new issue