conversations-classic/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java

1092 lines
38 KiB
Java
Raw Normal View History

2014-02-28 17:46:01 +00:00
package eu.siacs.conversations.xmpp;
2014-11-03 09:03:45 +00:00
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.util.Log;
import android.util.Pair;
2014-11-03 09:03:45 +00:00
import android.util.SparseArray;
import org.apache.http.conn.ssl.StrictHostnameVerifier;
2014-11-15 14:42:40 +00:00
import org.json.JSONException;
import org.json.JSONObject;
2014-11-03 09:03:45 +00:00
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.net.ConnectException;
2014-11-08 04:08:31 +00:00
import java.net.IDN;
import java.net.InetAddress;
2014-10-27 20:48:25 +00:00
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
2014-03-06 19:03:35 +00:00
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
2014-03-15 03:59:18 +00:00
import java.util.ArrayList;
2014-10-18 19:56:59 +00:00
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
2014-10-19 19:53:03 +00:00
import java.util.LinkedList;
2014-02-09 13:10:52 +00:00
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
2014-07-22 15:27:44 +00:00
import javax.net.ssl.HostnameVerifier;
2014-03-06 19:03:35 +00:00
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
2014-03-06 19:03:35 +00:00
import javax.net.ssl.X509TrustManager;
2014-08-31 14:28:21 +00:00
import eu.siacs.conversations.Config;
2014-11-12 15:15:38 +00:00
import eu.siacs.conversations.crypto.sasl.DigestMd5;
import eu.siacs.conversations.crypto.sasl.Plain;
import eu.siacs.conversations.crypto.sasl.SaslMechanism;
import eu.siacs.conversations.crypto.sasl.ScramSha1;
2014-02-28 17:46:01 +00:00
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.generator.IqGenerator;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper;
2014-02-28 17:46:01 +00:00
import eu.siacs.conversations.utils.DNSHelper;
import eu.siacs.conversations.utils.Xmlns;
2014-02-28 17:46:01 +00:00
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xml.Tag;
import eu.siacs.conversations.xml.TagWriter;
import eu.siacs.conversations.xml.XmlReader;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.jingle.OnJinglePacketReceived;
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
2014-03-10 18:22:13 +00:00
import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
2014-08-26 15:43:44 +00:00
import eu.siacs.conversations.xmpp.stanzas.csi.ActivePacket;
import eu.siacs.conversations.xmpp.stanzas.csi.InactivePacket;
2014-03-10 18:22:13 +00:00
import eu.siacs.conversations.xmpp.stanzas.streammgmt.AckPacket;
import eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket;
import eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket;
import eu.siacs.conversations.xmpp.stanzas.streammgmt.ResumePacket;
public class XmppConnection implements Runnable {
private static final int PACKET_IQ = 0;
private static final int PACKET_MESSAGE = 1;
private static final int PACKET_PRESENCE = 2;
private final Context applicationContext;
protected Account account;
private final WakeLock wakeLock;
private Socket socket;
private XmlReader tagReader;
private TagWriter tagWriter;
private final Features features = new Features(this);
private boolean shouldBind = true;
private boolean shouldAuthenticate = true;
private Element streamFeatures;
private final HashMap<String, List<String>> disco = new HashMap<>();
2014-03-10 18:22:13 +00:00
private String streamId = null;
2014-04-05 10:08:35 +00:00
private int smVersion = 3;
private final SparseArray<String> messageReceipts = new SparseArray<>();
2014-03-10 18:22:13 +00:00
private int stanzasReceived = 0;
private int stanzasSent = 0;
private long lastPacketReceived = 0;
private long lastPingSent = 0;
private long lastConnect = 0;
private long lastSessionStarted = 0;
2014-05-18 09:25:04 +00:00
private int attempt = 0;
private final Map<String, Pair<IqPacket, OnIqPacketReceived>> packetCallbacks = new Hashtable<>();
2014-02-01 14:07:20 +00:00
private OnPresencePacketReceived presenceListener = null;
private OnJinglePacketReceived jingleListener = null;
2014-02-01 14:07:20 +00:00
private OnIqPacketReceived unregisteredIqListener = null;
private OnMessagePacketReceived messageListener = null;
private OnStatusChanged statusListener = null;
private OnBindListener bindListener = null;
private final ArrayList<OnAdvancedStreamFeaturesLoaded> advancedStreamFeaturesLoadedListeners = new ArrayList<>();
2014-08-26 14:52:42 +00:00
private OnMessageAcknowledged acknowledgedListener = null;
private XmppConnectionService mXmppConnectionService = null;
private SaslMechanism saslMechanism;
2014-11-12 15:15:38 +00:00
public XmppConnection(final Account account, final XmppConnectionService service) {
this.account = account;
2014-08-31 14:28:21 +00:00
this.wakeLock = service.getPowerManager().newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, account.getJid().toBareJid().toString());
tagWriter = new TagWriter();
mXmppConnectionService = service;
applicationContext = service.getApplicationContext();
}
2014-03-06 14:11:56 +00:00
2014-11-15 16:09:02 +00:00
protected void changeStatus(final Account.State nextStatus) {
2014-03-11 15:27:33 +00:00
if (account.getStatus() != nextStatus) {
2014-11-15 16:09:02 +00:00
if ((nextStatus == Account.State.OFFLINE)
&& (account.getStatus() != Account.State.CONNECTING)
&& (account.getStatus() != Account.State.ONLINE)
&& (account.getStatus() != Account.State.DISABLED)) {
2014-03-13 16:29:22 +00:00
return;
}
2014-11-15 16:09:02 +00:00
if (nextStatus == Account.State.ONLINE) {
2014-05-18 09:25:04 +00:00
this.attempt = 0;
}
2014-03-11 15:27:33 +00:00
account.setStatus(nextStatus);
if (statusListener != null) {
statusListener.onStatusChanged(account);
}
2014-03-06 02:57:29 +00:00
}
}
protected void connect() {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": connecting");
features.encryptionEnabled = false;
lastConnect = SystemClock.elapsedRealtime();
lastPingSent = SystemClock.elapsedRealtime();
2014-05-18 09:25:04 +00:00
this.attempt++;
try {
shouldAuthenticate = shouldBind = !account.isOptionSet(Account.OPTION_REGISTER);
tagReader = new XmlReader(wakeLock);
tagWriter = new TagWriter();
packetCallbacks.clear();
2014-11-15 16:09:02 +00:00
this.changeStatus(Account.State.CONNECTING);
final Bundle result = DNSHelper.getSRVRecord(account.getServer());
final ArrayList<Parcelable> values = result.getParcelableArrayList("values");
2014-10-27 20:48:25 +00:00
if ("timeout".equals(result.getString("error"))) {
throw new IOException("timeout in dns");
2014-10-27 20:48:25 +00:00
} else if (values != null) {
2014-11-03 09:03:45 +00:00
int i = 0;
boolean socketError = true;
while (socketError && values.size() > i) {
final Bundle namePort = (Bundle) values.get(i);
2014-11-03 09:03:45 +00:00
try {
String srvRecordServer;
try {
srvRecordServer=IDN.toASCII(namePort.getString("name"));
} catch (final IllegalArgumentException e) {
// TODO: Handle me?`
srvRecordServer = "";
}
final int srvRecordPort = namePort.getInt("port");
final String srvIpServer = namePort.getString("ip");
final InetSocketAddress addr;
2014-11-03 09:03:45 +00:00
if (srvIpServer != null) {
addr = new InetSocketAddress(srvIpServer, srvRecordPort);
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString()
2014-11-03 09:03:45 +00:00
+ ": using values from dns " + srvRecordServer
+ "[" + srvIpServer + "]:" + srvRecordPort);
} else {
addr = new InetSocketAddress(srvRecordServer, srvRecordPort);
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString()
2014-11-03 09:03:45 +00:00
+ ": using values from dns "
+ srvRecordServer + ":" + srvRecordPort);
2014-10-16 21:31:48 +00:00
}
2014-11-03 09:03:45 +00:00
socket = new Socket();
socket.connect(addr, 20000);
socketError = false;
} catch (final UnknownHostException e) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage());
2014-11-03 09:03:45 +00:00
i++;
} catch (final IOException e) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage());
2014-11-03 09:03:45 +00:00
i++;
2014-10-16 21:31:48 +00:00
}
2014-11-03 09:03:45 +00:00
}
if (socketError) {
throw new UnknownHostException();
2014-11-03 09:03:45 +00:00
}
2014-10-27 20:48:25 +00:00
} else if (result.containsKey("error")
&& "nosrv".equals(result.getString("error", null))) {
socket = new Socket(account.getServer().getDomainpart(), 5222);
2014-10-04 12:33:14 +00:00
} else {
throw new IOException("timeout in dns");
}
final OutputStream out = socket.getOutputStream();
tagWriter.setOutputStream(out);
final InputStream in = socket.getInputStream();
tagReader.setInputStream(in);
tagWriter.beginDocument();
sendStartStream();
Tag nextTag;
while ((nextTag = tagReader.readTag()) != null) {
if (nextTag.isStart("stream")) {
processStream(nextTag);
break;
} else {
throw new IOException("unknown tag on connect");
}
}
if (socket.isConnected()) {
socket.close();
}
} catch (final UnknownHostException | ConnectException e) {
this.changeStatus(Account.State.SERVER_NOT_FOUND);
} catch (final IOException | XmlPullParserException | NoSuchAlgorithmException e) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": " + e.getMessage());
2014-11-15 16:09:02 +00:00
this.changeStatus(Account.State.OFFLINE);
this.attempt--; //don't count attempt when reconnecting instantly anyway
} finally {
2014-04-03 16:16:14 +00:00
if (wakeLock.isHeld()) {
2014-08-31 14:28:21 +00:00
try {
wakeLock.release();
} catch (final RuntimeException ignored) {
2014-08-31 14:28:21 +00:00
}
}
}
}
@Override
public void run() {
connect();
}
private void processStream(final Tag currentTag) throws XmlPullParserException,
IOException, NoSuchAlgorithmException {
Tag nextTag = tagReader.readTag();
while ((nextTag != null) && (!nextTag.isEnd("stream"))) {
if (nextTag.isStart("error")) {
processStreamError(nextTag);
} else if (nextTag.isStart("features")) {
processStreamFeatures(nextTag);
} else if (nextTag.isStart("proceed")) {
switchOverToTls(nextTag);
} else if (nextTag.isStart("success")) {
final String challenge = tagReader.readElement(nextTag).getContent();
try {
saslMechanism.getResponse(challenge);
} catch (final SaslMechanism.AuthenticationException e) {
disconnect(true);
Log.e(Config.LOGTAG, String.valueOf(e));
}
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": logged in");
2014-11-15 14:42:40 +00:00
account.setKey(Account.PINNED_MECHANISM_KEY,
String.valueOf(saslMechanism.getPriority()));
tagReader.reset();
sendStartStream();
processStream(tagReader.readTag());
break;
} else if (nextTag.isStart("failure")) {
tagReader.readElement(nextTag);
2014-11-15 16:09:02 +00:00
changeStatus(Account.State.UNAUTHORIZED);
} else if (nextTag.isStart("challenge")) {
final String challenge = tagReader.readElement(nextTag).getContent();
final Element response = new Element("response");
response.setAttribute("xmlns",
"urn:ietf:params:xml:ns:xmpp-sasl");
try {
response.setContent(saslMechanism.getResponse(challenge));
} catch (final SaslMechanism.AuthenticationException e) {
// TODO: Send auth abort tag.
Log.e(Config.LOGTAG, e.toString());
}
tagWriter.writeElement(response);
} else if (nextTag.isStart("enabled")) {
final Element enabled = tagReader.readElement(nextTag);
if ("true".equals(enabled.getAttribute("resume"))) {
this.streamId = enabled.getAttribute("id");
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString()
+ ": stream managment(" + smVersion
+ ") enabled (resumable)");
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString()
+ ": stream managment(" + smVersion + ") enabled");
}
this.lastSessionStarted = SystemClock.elapsedRealtime();
this.stanzasReceived = 0;
final RequestPacket r = new RequestPacket(smVersion);
tagWriter.writeStanzaAsync(r);
} else if (nextTag.isStart("resumed")) {
lastPacketReceived = SystemClock.elapsedRealtime();
final Element resumed = tagReader.readElement(nextTag);
final String h = resumed.getAttribute("h");
try {
final int serverCount = Integer.parseInt(h);
if (serverCount != stanzasSent) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString()
+ ": session resumed with lost packages");
stanzasSent = serverCount;
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString()
+ ": session resumed");
}
if (acknowledgedListener != null) {
for (int i = 0; i < messageReceipts.size(); ++i) {
if (serverCount >= messageReceipts.keyAt(i)) {
acknowledgedListener.onMessageAcknowledged(
account, messageReceipts.valueAt(i));
}
}
}
messageReceipts.clear();
} catch (final NumberFormatException ignored) {
}
2014-11-15 16:24:06 +00:00
sendServiceDiscoveryInfo(account.getServer());
sendServiceDiscoveryItems(account.getServer());
sendInitialPing();
} else if (nextTag.isStart("r")) {
tagReader.readElement(nextTag);
final AckPacket ack = new AckPacket(this.stanzasReceived, smVersion);
tagWriter.writeStanzaAsync(ack);
} else if (nextTag.isStart("a")) {
final Element ack = tagReader.readElement(nextTag);
lastPacketReceived = SystemClock.elapsedRealtime();
final int serverSequence = Integer.parseInt(ack.getAttribute("h"));
final String msgId = this.messageReceipts.get(serverSequence);
if (msgId != null) {
if (this.acknowledgedListener != null) {
this.acknowledgedListener.onMessageAcknowledged(
account, msgId);
}
this.messageReceipts.remove(serverSequence);
}
} else if (nextTag.isStart("failed")) {
tagReader.readElement(nextTag);
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": resumption failed");
streamId = null;
2014-11-15 16:09:02 +00:00
if (account.getStatus() != Account.State.ONLINE) {
sendBindRequest();
}
} else if (nextTag.isStart("iq")) {
processIq(nextTag);
} else if (nextTag.isStart("message")) {
processMessage(nextTag);
} else if (nextTag.isStart("presence")) {
processPresence(nextTag);
}
nextTag = tagReader.readTag();
}
2014-11-15 16:09:02 +00:00
if (account.getStatus() == Account.State.ONLINE) {
account. setStatus(Account.State.OFFLINE);
if (statusListener != null) {
statusListener.onStatusChanged(account);
}
}
}
private void sendInitialPing() {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": sending intial ping");
2014-12-30 13:16:25 +00:00
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setFrom(account.getJid());
iq.addChild("ping", "urn:xmpp:ping");
this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString()
+ ": online with resource " + account.getResource());
2014-11-15 16:09:02 +00:00
changeStatus(Account.State.ONLINE);
}
});
}
2014-02-09 13:10:52 +00:00
private Element processPacket(final Tag currentTag, final int packetType)
throws XmlPullParserException, IOException {
Element element;
switch (packetType) {
2014-11-03 09:03:45 +00:00
case PACKET_IQ:
element = new IqPacket();
break;
case PACKET_MESSAGE:
element = new MessagePacket();
break;
case PACKET_PRESENCE:
element = new PresencePacket();
break;
default:
return null;
}
element.setAttributes(currentTag.getAttributes());
Tag nextTag = tagReader.readTag();
2014-08-31 14:28:21 +00:00
if (nextTag == null) {
2014-05-23 08:15:58 +00:00
throw new IOException("interrupted mid tag");
}
2014-02-09 13:10:52 +00:00
while (!nextTag.isEnd(element.getName())) {
if (!nextTag.isNo()) {
final Element child = tagReader.readElement(nextTag);
final String type = currentTag.getAttribute("type");
if (packetType == PACKET_IQ
&& "jingle".equals(child.getName())
&& ("set".equalsIgnoreCase(type) || "get"
.equalsIgnoreCase(type))) {
element = new JinglePacket();
element.setAttributes(currentTag.getAttributes());
}
element.addChild(child);
}
nextTag = tagReader.readTag();
2014-08-31 14:28:21 +00:00
if (nextTag == null) {
2014-05-23 08:15:58 +00:00
throw new IOException("interrupted mid tag");
}
}
2014-03-10 18:22:13 +00:00
++stanzasReceived;
lastPacketReceived = SystemClock.elapsedRealtime();
return element;
}
private void processIq(final Tag currentTag) throws XmlPullParserException, IOException {
final IqPacket packet = (IqPacket) processPacket(currentTag, PACKET_IQ);
2014-05-21 20:22:36 +00:00
if (packet.getId() == null) {
return; // an iq packet without id is definitely invalid
}
2014-05-21 20:22:36 +00:00
if (packet instanceof JinglePacket) {
if (this.jingleListener != null) {
this.jingleListener.onJinglePacketReceived(account,(JinglePacket) packet);
}
} else {
if (packetCallbacks.containsKey(packet.getId())) {
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)) {
packetCallbackDuple.second.onIqPacketReceived(account, packet);
packetCallbacks.remove(packet.getId());
} else {
Log.e(Config.LOGTAG,account.getJid().toBareJid().toString()+": ignoring spoofed iq packet");
}
} else {
if (packet.getFrom().equals(packetCallbackDuple.first.getTo())) {
packetCallbackDuple.second.onIqPacketReceived(account, packet);
packetCallbacks.remove(packet.getId());
} else {
Log.e(Config.LOGTAG,account.getJid().toBareJid().toString()+": ignoring spoofed iq packet");
}
}
} else if (packet.getType() == IqPacket.TYPE.GET|| packet.getType() == IqPacket.TYPE.SET) {
this.unregisteredIqListener.onIqPacketReceived(account, packet);
}
}
}
2014-02-09 13:10:52 +00:00
private void processMessage(final Tag currentTag) throws XmlPullParserException, IOException {
final MessagePacket packet = (MessagePacket) processPacket(currentTag,PACKET_MESSAGE);
this.messageListener.onMessagePacketReceived(account, packet);
}
2014-02-09 13:10:52 +00:00
private void processPresence(final Tag currentTag) throws XmlPullParserException, IOException {
PresencePacket packet = (PresencePacket) processPacket(currentTag, PACKET_PRESENCE);
this.presenceListener.onPresencePacketReceived(account, packet);
}
2014-03-10 18:22:13 +00:00
private void sendStartTLS() throws IOException {
final Tag startTLS = Tag.empty("starttls");
startTLS.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-tls");
tagWriter.writeTag(startTLS);
}
2014-10-19 19:53:03 +00:00
private SharedPreferences getPreferences() {
return PreferenceManager.getDefaultSharedPreferences(applicationContext);
2014-10-19 19:53:03 +00:00
}
private boolean enableLegacySSL() {
return getPreferences().getBoolean("enable_legacy_ssl", false);
2014-10-19 19:53:03 +00:00
}
2014-12-30 00:17:11 +00:00
private void switchOverToTls(final Tag currentTag) throws XmlPullParserException, IOException {
2014-12-30 13:16:25 +00:00
tagReader.readTag();
try {
2014-12-30 00:17:11 +00:00
final SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null,new X509TrustManager[]{this.mXmppConnectionService.getMemorizingTrustManager()},mXmppConnectionService.getRNG());
final SSLSocketFactory factory = sc.getSocketFactory();
final HostnameVerifier verifier = this.mXmppConnectionService.getMemorizingTrustManager().wrapHostnameVerifier(new StrictHostnameVerifier());
2014-12-30 13:16:25 +00:00
final InetAddress address = socket == null ? null : socket.getInetAddress();
2014-12-30 00:17:11 +00:00
if (factory == null || address == null || verifier == null) {
throw new IOException("could not setup ssl");
}
2014-11-03 09:03:45 +00:00
2014-12-30 13:16:25 +00:00
final SSLSocket sslSocket = (SSLSocket) factory.createSocket(socket,address.getHostAddress(), socket.getPort(),true);
2014-12-30 00:17:11 +00:00
if (sslSocket == null) {
throw new IOException("could not initialize ssl socket");
}
2014-12-30 00:17:11 +00:00
final String[] supportProtocols;
2015-01-17 18:40:15 +00:00
final Collection<String> supportedProtocols = new LinkedList<>(
Arrays.asList(sslSocket.getSupportedProtocols()));
supportedProtocols.remove("SSLv3");
supportProtocols = supportedProtocols.toArray(new String[supportedProtocols.size()]);
2014-12-30 00:17:11 +00:00
sslSocket.setEnabledProtocols(supportProtocols);
final String[] cipherSuites = CryptoHelper.getOrderedCipherSuites(
2015-01-17 18:40:15 +00:00
sslSocket.getSupportedCipherSuites());
Log.d(Config.LOGTAG, "Using ciphers: " + Arrays.toString(cipherSuites));
2015-01-17 18:40:15 +00:00
if (cipherSuites.length > 0) {
sslSocket.setEnabledCipherSuites(cipherSuites);
}
2014-12-30 13:16:25 +00:00
if (!verifier.verify(account.getServer().getDomainpart(),sslSocket.getSession())) {
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": TLS certificate verification failed");
disconnect(true);
changeStatus(Account.State.SECURITY_ERROR);
2014-12-30 00:17:11 +00:00
}
tagReader.setInputStream(sslSocket.getInputStream());
tagWriter.setOutputStream(sslSocket.getOutputStream());
sendStartStream();
Log.d(Config.LOGTAG, account.getJid().toBareJid()+ ": TLS connection established");
features.encryptionEnabled = true;
2014-12-30 00:17:11 +00:00
processStream(tagReader.readTag());
sslSocket.close();
2014-12-30 13:16:25 +00:00
} catch (final NoSuchAlgorithmException | KeyManagementException e1) {
2014-12-30 00:17:11 +00:00
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": TLS certificate verification failed");
disconnect(true);
changeStatus(Account.State.SECURITY_ERROR);
2014-12-30 13:16:25 +00:00
}
}
private void processStreamFeatures(final Tag currentTag)
throws XmlPullParserException, IOException {
this.streamFeatures = tagReader.readElement(currentTag);
if (this.streamFeatures.hasChild("starttls") && !features.encryptionEnabled) {
sendStartTLS();
2014-05-21 20:22:36 +00:00
} else if (this.streamFeatures.hasChild("register")
&& account.isOptionSet(Account.OPTION_REGISTER)
&& features.encryptionEnabled) {
2014-05-21 20:22:36 +00:00
sendRegistryRequest();
} else if (!this.streamFeatures.hasChild("register")
2014-10-19 21:14:17 +00:00
&& account.isOptionSet(Account.OPTION_REGISTER)) {
2014-11-15 16:09:02 +00:00
changeStatus(Account.State.REGISTRATION_NOT_SUPPORTED);
disconnect(true);
2014-02-09 13:10:52 +00:00
} else if (this.streamFeatures.hasChild("mechanisms")
&& shouldAuthenticate && features.encryptionEnabled) {
2014-11-12 15:15:38 +00:00
final List<String> mechanisms = extractMechanisms(streamFeatures
2014-05-21 20:22:36 +00:00
.findChild("mechanisms"));
final Element auth = new Element("auth");
auth.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl");
2014-11-15 14:42:40 +00:00
if (mechanisms.contains("SCRAM-SHA-1")) {
saslMechanism = new ScramSha1(tagWriter, account, mXmppConnectionService.getRNG());
2014-11-15 14:42:40 +00:00
} else if (mechanisms.contains("PLAIN")) {
saslMechanism = new Plain(tagWriter, account);
} else if (mechanisms.contains("DIGEST-MD5")) {
saslMechanism = new DigestMd5(tagWriter, account, mXmppConnectionService.getRNG());
}
2014-11-15 14:42:40 +00:00
final JSONObject keys = account.getKeys();
try {
if (keys.has(Account.PINNED_MECHANISM_KEY) &&
keys.getInt(Account.PINNED_MECHANISM_KEY) > saslMechanism.getPriority() ) {
Log.e(Config.LOGTAG, "Auth failed. Authentication mechanism " + saslMechanism.getMechanism() +
" has lower priority (" + String.valueOf(saslMechanism.getPriority()) +
") than pinned priority (" + keys.getInt(Account.PINNED_MECHANISM_KEY) +
"). Possible downgrade attack?");
disconnect(true);
changeStatus(Account.State.SECURITY_ERROR);
}
2014-11-15 14:42:40 +00:00
} catch (final JSONException e) {
Log.d(Config.LOGTAG, "Parse error while checking pinned auth mechanism");
}
Log.d(Config.LOGTAG,account.getJid().toString()+": Authenticating with " + saslMechanism.getMechanism());
2014-11-15 14:42:40 +00:00
auth.setAttribute("mechanism", saslMechanism.getMechanism());
if (!saslMechanism.getClientFirstMessage().isEmpty()) {
auth.setContent(saslMechanism.getClientFirstMessage());
}
tagWriter.writeElement(auth);
} else if (this.streamFeatures.hasChild("sm", "urn:xmpp:sm:"
+ smVersion)
2014-05-21 20:22:36 +00:00
&& streamId != null) {
final ResumePacket resume = new ResumePacket(this.streamId,
2014-05-21 20:22:36 +00:00
stanzasReceived, smVersion);
2014-03-10 18:22:13 +00:00
this.tagWriter.writeStanzaAsync(resume);
} else if (this.streamFeatures.hasChild("bind") && shouldBind) {
sendBindRequest();
2014-10-19 21:14:17 +00:00
} else {
disconnect(true);
changeStatus(Account.State.INCOMPATIBLE_SERVER);
2014-03-10 18:22:13 +00:00
}
}
2014-02-09 13:10:52 +00:00
private List<String> extractMechanisms(final Element stream) {
final ArrayList<String> mechanisms = new ArrayList<>(stream
2014-05-21 20:22:36 +00:00
.getChildren().size());
for (final Element child : stream.getChildren()) {
mechanisms.add(child.getContent());
}
return mechanisms;
}
private void sendRegistryRequest() {
2014-12-30 13:16:25 +00:00
final IqPacket register = new IqPacket(IqPacket.TYPE.GET);
register.query("jabber:iq:register");
register.setTo(account.getServer());
sendIqPacket(register, new OnIqPacketReceived() {
2014-05-21 20:22:36 +00:00
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
final Element instructions = packet.query().findChild("instructions");
2014-05-21 20:22:36 +00:00
if (packet.query().hasChild("username")
&& (packet.query().hasChild("password"))) {
2014-12-30 13:16:25 +00:00
final IqPacket register = new IqPacket(IqPacket.TYPE.SET);
final Element username = new Element("username")
.setContent(account.getUsername());
final Element password = new Element("password")
.setContent(account.getPassword());
2014-03-20 14:49:53 +00:00
register.query("jabber:iq:register").addChild(username);
register.query().addChild(password);
sendIqPacket(register, new OnIqPacketReceived() {
2014-05-21 20:22:36 +00:00
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
2014-12-30 13:16:25 +00:00
if (packet.getType() == IqPacket.TYPE.RESULT) {
2014-05-21 20:22:36 +00:00
account.setOption(Account.OPTION_REGISTER,
false);
2014-11-15 16:09:02 +00:00
changeStatus(Account.State.REGISTRATION_SUCCESSFUL);
2014-05-21 20:22:36 +00:00
} else if (packet.hasChild("error")
&& (packet.findChild("error")
.hasChild("conflict"))) {
2014-11-15 16:09:02 +00:00
changeStatus(Account.State.REGISTRATION_CONFLICT);
} else {
2014-11-15 16:09:02 +00:00
changeStatus(Account.State.REGISTRATION_FAILED);
2014-08-31 14:28:21 +00:00
Log.d(Config.LOGTAG, packet.toString());
}
disconnect(true);
}
});
} else {
2014-11-15 16:09:02 +00:00
changeStatus(Account.State.REGISTRATION_FAILED);
disconnect(true);
Log.d(Config.LOGTAG, account.getJid().toBareJid()
2014-05-21 20:22:36 +00:00
+ ": could not register. instructions are"
+ instructions.getContent());
}
}
});
}
private void sendBindRequest() {
2014-12-30 13:16:25 +00:00
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
2014-05-21 20:22:36 +00:00
iq.addChild("bind", "urn:ietf:params:xml:ns:xmpp-bind")
.addChild("resource").setContent(account.getResource());
this.sendUnmodifiedIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
final Element bind = packet.findChild("bind");
2014-08-31 14:28:21 +00:00
if (bind != null) {
final Element jid = bind.findChild("jid");
2014-09-22 14:04:37 +00:00
if (jid != null && jid.getContent() != null) {
try {
account.setResource(Jid.fromString(jid.getContent()).getResourcepart());
} catch (final InvalidJidException e) {
// TODO: Handle the case where an external JID is technically invalid?
}
if (streamFeatures.hasChild("sm", "urn:xmpp:sm:3")) {
2014-07-26 13:44:32 +00:00
smVersion = 3;
final EnablePacket enable = new EnablePacket(smVersion);
2014-07-26 13:44:32 +00:00
tagWriter.writeStanzaAsync(enable);
2014-08-26 14:52:42 +00:00
stanzasSent = 0;
2014-08-27 17:25:58 +00:00
messageReceipts.clear();
} else if (streamFeatures.hasChild("sm", "urn:xmpp:sm:2")) {
2014-07-26 13:44:32 +00:00
smVersion = 2;
final EnablePacket enable = new EnablePacket(smVersion);
2014-07-26 13:44:32 +00:00
tagWriter.writeStanzaAsync(enable);
2014-08-26 14:52:42 +00:00
stanzasSent = 0;
2014-08-27 17:25:58 +00:00
messageReceipts.clear();
2014-07-26 13:44:32 +00:00
}
features.carbonsEnabled = false;
features.blockListRequested = false;
2014-11-15 16:24:06 +00:00
disco.clear();
2014-07-26 13:44:32 +00:00
sendServiceDiscoveryInfo(account.getServer());
sendServiceDiscoveryItems(account.getServer());
if (bindListener != null) {
bindListener.onBind(account);
}
sendInitialPing();
2014-07-26 13:44:32 +00:00
} else {
disconnect(true);
}
} else {
disconnect(true);
}
2014-02-09 13:10:52 +00:00
}
});
if (this.streamFeatures.hasChild("session")) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending deprecated session");
final IqPacket startSession = new IqPacket(IqPacket.TYPE.SET);
startSession.addChild("session","urn:ietf:params:xml:ns:xmpp-session");
this.sendUnmodifiedIqPacket(startSession, null);
}
2014-02-09 13:10:52 +00:00
}
private void sendServiceDiscoveryInfo(final Jid server) {
2014-11-15 16:24:06 +00:00
if (disco.containsKey(server.toDomainJid().toString())) {
if (account.getServer().equals(server.toDomainJid())) {
enableAdvancedStreamFeatures();
}
} else {
2014-12-30 13:16:25 +00:00
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
2014-11-15 16:24:06 +00:00
iq.setTo(server.toDomainJid());
iq.query("http://jabber.org/protocol/disco#info");
this.sendIqPacket(iq, new OnIqPacketReceived() {
2014-02-09 13:10:52 +00:00
2014-11-15 16:24:06 +00:00
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
2014-11-15 16:24:06 +00:00
final List<Element> elements = packet.query().getChildren();
final List<String> features = new ArrayList<>();
for (final Element element : elements) {
if (element.getName().equals("identity")) {
if ("irc".equals(element.getAttribute("type"))) {
//add fake feature to not confuse irc and real muc
features.add("siacs:no:muc");
}
} else if (element.getName().equals("feature")) {
2014-11-15 16:24:06 +00:00
features.add(element.getAttribute("var"));
}
}
2014-11-15 16:24:06 +00:00
disco.put(server.toDomainJid().toString(), features);
2014-11-15 16:24:06 +00:00
if (account.getServer().equals(server.toDomainJid())) {
enableAdvancedStreamFeatures();
for (final OnAdvancedStreamFeaturesLoaded listener : advancedStreamFeaturesLoadedListeners) {
listener.onAdvancedStreamFeaturesAvailable(account);
2014-12-05 00:54:16 +00:00
}
2014-11-15 16:24:06 +00:00
}
2014-02-09 13:10:52 +00:00
}
2014-11-15 16:24:06 +00:00
});
}
2014-02-09 13:10:52 +00:00
}
2014-05-21 20:22:36 +00:00
private void enableAdvancedStreamFeatures() {
if (getFeatures().carbons() && !features.carbonsEnabled) {
sendEnableCarbons();
}
if (getFeatures().blocking() && !features.blockListRequested) {
Log.d(Config.LOGTAG, "Requesting block list");
this.sendIqPacket(getIqGenerator().generateGetBlockList(), mXmppConnectionService.getIqParser());
}
}
2014-05-21 20:22:36 +00:00
private void sendServiceDiscoveryItems(final Jid server) {
2014-12-30 13:16:25 +00:00
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setTo(server.toDomainJid());
2014-03-15 03:59:18 +00:00
iq.query("http://jabber.org/protocol/disco#items");
this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
final List<Element> elements = packet.query().getChildren();
for (final Element element : elements) {
if (element.getName().equals("item")) {
final Jid jid = element.getAttributeAsJid("jid");
if (jid != null && !jid.equals(account.getServer())) {
sendServiceDiscoveryInfo(jid);
}
}
}
2014-03-15 03:59:18 +00:00
}
});
}
2014-03-06 14:11:56 +00:00
2014-02-09 13:10:52 +00:00
private void sendEnableCarbons() {
2014-12-30 13:16:25 +00:00
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
2014-05-21 20:22:36 +00:00
iq.addChild("enable", "urn:xmpp:carbons:2");
2014-02-09 13:10:52 +00:00
this.sendIqPacket(iq, new OnIqPacketReceived() {
2014-03-06 14:11:56 +00:00
2014-02-09 13:10:52 +00:00
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
2014-02-09 13:10:52 +00:00
if (!packet.hasChild("error")) {
Log.d(Config.LOGTAG, account.getJid().toBareJid()
2014-03-06 14:11:56 +00:00
+ ": successfully enabled carbons");
features.carbonsEnabled = true;
2014-02-09 13:10:52 +00:00
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid()
2014-03-06 14:11:56 +00:00
+ ": error enableing carbons " + packet.toString());
2014-02-09 13:10:52 +00:00
}
}
});
}
private void processStreamError(final Tag currentTag)
throws XmlPullParserException, IOException {
final Element streamError = tagReader.readElement(currentTag);
if (streamError != null && streamError.hasChild("conflict")) {
final String resource = account.getResource().split("\\.")[0];
account.setResource(resource + "." + nextRandomId());
Log.d(Config.LOGTAG,
account.getJid().toBareJid() + ": switching resource due to conflict ("
+ account.getResource() + ")");
2014-09-03 12:57:40 +00:00
}
}
2014-03-10 18:22:13 +00:00
private void sendStartStream() throws IOException {
final Tag stream = Tag.start("stream:stream");
stream.setAttribute("from", account.getJid().toBareJid().toString());
stream.setAttribute("to", account.getServer().toString());
stream.setAttribute("version", "1.0");
stream.setAttribute("xml:lang", "en");
stream.setAttribute("xmlns", "jabber:client");
stream.setAttribute("xmlns:stream", "http://etherx.jabber.org/streams");
tagWriter.writeTag(stream);
}
private String nextRandomId() {
return new BigInteger(50, mXmppConnectionService.getRNG()).toString(32);
}
2014-02-09 13:10:52 +00:00
public void sendIqPacket(final IqPacket packet, final OnIqPacketReceived callback) {
packet.setFrom(account.getJid());
this.sendUnmodifiedIqPacket(packet,callback);
}
2014-05-21 20:22:36 +00:00
private synchronized void sendUnmodifiedIqPacket(final IqPacket packet, final OnIqPacketReceived callback) {
2014-05-21 20:22:36 +00:00
if (packet.getId() == null) {
final String id = nextRandomId();
packet.setAttribute("id", id);
}
if (callback != null) {
if (packet.getId() == null) {
packet.setId(nextRandomId());
}
packetCallbacks.put(packet.getId(), new Pair<>(packet, callback));
}
this.sendPacket(packet);
}
2014-02-09 13:10:52 +00:00
public void sendMessagePacket(final MessagePacket packet) {
this.sendPacket(packet);
2014-03-03 04:01:02 +00:00
}
2014-03-06 14:11:56 +00:00
public void sendPresencePacket(final PresencePacket packet) {
this.sendPacket(packet);
2014-03-03 04:01:02 +00:00
}
2014-08-31 14:28:21 +00:00
private synchronized void sendPacket(final AbstractStanza packet) {
final String name = packet.getName();
if (name.equals("iq") || name.equals("message") || name.equals("presence")) {
2014-08-26 14:52:42 +00:00
++stanzasSent;
}
2014-03-10 18:22:13 +00:00
tagWriter.writeStanzaAsync(packet);
if (packet instanceof MessagePacket && packet.getId() != null && this.streamId != null) {
Log.d(Config.LOGTAG, "request delivery report for stanza " + stanzasSent);
2014-08-26 14:52:42 +00:00
this.messageReceipts.put(stanzasSent, packet.getId());
tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
2014-03-03 04:01:02 +00:00
}
2014-02-01 14:07:20 +00:00
}
2014-05-21 20:22:36 +00:00
2014-03-11 14:44:22 +00:00
public void sendPing() {
if (streamFeatures.hasChild("sm")) {
2014-04-05 10:08:35 +00:00
tagWriter.writeStanzaAsync(new RequestPacket(smVersion));
2014-03-11 14:44:22 +00:00
} else {
2014-12-30 13:16:25 +00:00
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setFrom(account.getJid());
2014-05-21 20:22:36 +00:00
iq.addChild("ping", "urn:xmpp:ping");
2014-03-11 14:44:22 +00:00
this.sendIqPacket(iq, null);
}
this.lastPingSent = SystemClock.elapsedRealtime();
2014-03-11 14:44:22 +00:00
}
2014-02-09 13:10:52 +00:00
public void setOnMessagePacketReceivedListener(
final OnMessagePacketReceived listener) {
2014-02-01 14:07:20 +00:00
this.messageListener = listener;
}
2014-02-09 13:10:52 +00:00
public void setOnUnregisteredIqPacketReceivedListener(
final OnIqPacketReceived listener) {
2014-02-01 14:07:20 +00:00
this.unregisteredIqListener = listener;
}
2014-02-09 13:10:52 +00:00
public void setOnPresencePacketReceivedListener(
final OnPresencePacketReceived listener) {
2014-02-01 14:07:20 +00:00
this.presenceListener = listener;
}
2014-05-21 20:22:36 +00:00
public void setOnJinglePacketReceivedListener(
final OnJinglePacketReceived listener) {
this.jingleListener = listener;
}
2014-02-09 13:10:52 +00:00
public void setOnStatusChangedListener(final OnStatusChanged listener) {
this.statusListener = listener;
}
2014-05-21 20:22:36 +00:00
public void setOnBindListener(final OnBindListener listener) {
this.bindListener = listener;
}
2014-08-31 14:28:21 +00:00
public void setOnMessageAcknowledgeListener(final OnMessageAcknowledged listener) {
2014-08-26 14:52:42 +00:00
this.acknowledgedListener = listener;
}
public void addOnAdvancedStreamFeaturesAvailableListener(final OnAdvancedStreamFeaturesLoaded listener) {
if (!this.advancedStreamFeaturesLoadedListeners.contains(listener)) {
this.advancedStreamFeaturesLoadedListeners.add(listener);
}
2014-12-05 00:54:16 +00:00
}
public void disconnect(final boolean force) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": disconnecting");
2014-03-10 18:22:13 +00:00
try {
2014-05-21 20:22:36 +00:00
if (force) {
2014-03-10 18:22:13 +00:00
socket.close();
return;
2014-04-03 13:08:53 +00:00
}
2014-05-21 20:22:36 +00:00
new Thread(new Runnable() {
@Override
public void run() {
if (tagWriter.isActive()) {
tagWriter.finish();
try {
while (!tagWriter.finished()) {
2014-08-31 14:28:21 +00:00
Log.d(Config.LOGTAG, "not yet finished");
2014-05-21 20:22:36 +00:00
Thread.sleep(100);
}
tagWriter.writeTag(Tag.end("stream:stream"));
2014-10-08 10:21:58 +00:00
socket.close();
} catch (final IOException e) {
2014-08-31 14:28:21 +00:00
Log.d(Config.LOGTAG,
"io exception during disconnect");
} catch (final InterruptedException e) {
2014-08-31 14:28:21 +00:00
Log.d(Config.LOGTAG, "interrupted");
2014-05-21 20:22:36 +00:00
}
}
}
2014-05-28 08:37:49 +00:00
}).start();
} catch (final IOException e) {
2014-08-31 14:28:21 +00:00
Log.d(Config.LOGTAG, "io exception during disconnect");
2014-03-10 18:22:13 +00:00
}
}
2014-05-21 20:22:36 +00:00
public List<String> findDiscoItemsByFeature(final String feature) {
final List<String> items = new ArrayList<>();
for (final Entry<String, List<String>> cursor : disco.entrySet()) {
2014-07-11 17:48:02 +00:00
if (cursor.getValue().contains(feature)) {
items.add(cursor.getKey());
2014-05-21 20:22:36 +00:00
}
}
return items;
}
2014-08-31 14:28:21 +00:00
public String findDiscoItemByFeature(final String feature) {
final List<String> items = findDiscoItemsByFeature(feature);
2014-08-31 14:28:21 +00:00
if (items.size() >= 1) {
return items.get(0);
}
return null;
2014-03-13 16:29:22 +00:00
}
2014-03-10 18:22:13 +00:00
public void r() {
2014-04-05 10:08:35 +00:00
this.tagWriter.writeStanzaAsync(new RequestPacket(smVersion));
2014-03-10 18:22:13 +00:00
}
2014-08-31 14:28:21 +00:00
2014-03-15 03:59:18 +00:00
public String getMucServer() {
for (final Entry<String, List<String>> cursor : disco.entrySet()) {
final List<String> value = cursor.getValue();
if (value.contains("http://jabber.org/protocol/muc") && !value.contains("jabber:iq:gateway") && !value.contains("siacs:no:muc")) {
return cursor.getKey();
}
}
return null;
2014-03-15 03:59:18 +00:00
}
2014-05-21 20:22:36 +00:00
2014-05-18 09:25:04 +00:00
public int getTimeToNextAttempt() {
final int interval = (int) (25 * Math.pow(1.5, attempt));
final int secondsSinceLast = (int) ((SystemClock.elapsedRealtime() - this.lastConnect) / 1000);
2014-05-18 09:25:04 +00:00
return interval - secondsSinceLast;
}
2014-05-21 20:22:36 +00:00
2014-05-18 09:25:04 +00:00
public int getAttempt() {
return this.attempt;
}
2014-08-31 14:28:21 +00:00
public Features getFeatures() {
return this.features;
}
2014-08-31 14:28:21 +00:00
public long getLastSessionEstablished() {
final long diff;
if (this.lastSessionStarted == 0) {
diff = SystemClock.elapsedRealtime() - this.lastConnect;
} else {
diff = SystemClock.elapsedRealtime() - this.lastSessionStarted;
}
return System.currentTimeMillis() - diff;
}
public long getLastConnect() {
return this.lastConnect;
}
public long getLastPingSent() {
return this.lastPingSent;
}
public long getLastPacketReceived() {
return this.lastPacketReceived;
}
public void sendActive() {
this.sendPacket(new ActivePacket());
}
public void sendInactive() {
this.sendPacket(new InactivePacket());
}
public class Features {
XmppConnection connection;
private boolean carbonsEnabled = false;
private boolean encryptionEnabled = false;
private boolean blockListRequested = false;
2014-08-31 14:28:21 +00:00
public Features(final XmppConnection connection) {
this.connection = connection;
}
2014-08-31 14:28:21 +00:00
private boolean hasDiscoFeature(final Jid server, final String feature) {
return connection.disco.containsKey(server.toDomainJid().toString()) &&
connection.disco.get(server.toDomainJid().toString()).contains(feature);
}
2014-08-31 14:28:21 +00:00
public boolean carbons() {
return hasDiscoFeature(account.getServer(), "urn:xmpp:carbons:2");
}
2014-08-31 14:28:21 +00:00
public boolean blocking() {
return hasDiscoFeature(account.getServer(), Xmlns.BLOCKING);
}
public boolean register() {
return hasDiscoFeature(account.getServer(), Xmlns.REGISTER);
}
public boolean sm() {
return streamId != null;
}
2014-08-31 14:28:21 +00:00
2014-08-26 15:43:44 +00:00
public boolean csi() {
return connection.streamFeatures != null && connection.streamFeatures.hasChild("csi", "urn:xmpp:csi:0");
2014-08-26 15:43:44 +00:00
}
2014-08-31 14:28:21 +00:00
public boolean pubsub() {
2014-08-31 14:28:21 +00:00
return hasDiscoFeature(account.getServer(),
"http://jabber.org/protocol/pubsub#publish");
}
2014-08-31 14:28:21 +00:00
public boolean mam() {
return hasDiscoFeature(account.getServer(), "urn:xmpp:mam:0");
}
public boolean advancedStreamFeaturesLoaded() {
return disco.containsKey(account.getServer().toString());
}
public boolean rosterVersioning() {
return connection.streamFeatures != null && connection.streamFeatures.hasChild("ver");
}
2014-08-31 14:28:21 +00:00
public void setBlockListRequested(boolean value) {
this.blockListRequested = value;
}
}
private IqGenerator getIqGenerator() {
return mXmppConnectionService.getIqGenerator();
}
}