From 047aaf5d4f25ff8a909c6fb4fb87d5b53002cef4 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 8 Nov 2014 20:52:02 +0100 Subject: check if socket was null before doing ssl connect --- .../siacs/conversations/parser/MessageParser.java | 1 - .../siacs/conversations/xmpp/XmppConnection.java | 88 +++++++++++----------- 2 files changed, 42 insertions(+), 47 deletions(-) (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 472a2e46..7fab1b1b 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -7,7 +7,6 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; -import eu.siacs.conversations.services.NotificationService; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.xml.Element; diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index b907ea97..0ef15a79 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -65,44 +65,33 @@ 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 WakeLock wakeLock; - private SecureRandom mRandom; - private Socket socket; private XmlReader tagReader; private TagWriter tagWriter; - private Features features = new Features(this); - private boolean shouldBind = true; private boolean shouldAuthenticate = true; private Element streamFeatures; private HashMap> disco = new HashMap>(); - private String streamId = null; private int smVersion = 3; private SparseArray messageReceipts = new SparseArray(); - private boolean usingCompression = false; private boolean usingEncryption = false; - private int stanzasReceived = 0; private int stanzasSent = 0; - private long lastPaketReceived = 0; private long lastPingSent = 0; private long lastConnect = 0; private long lastSessionStarted = 0; - private int attempt = 0; - - private static final int PACKET_IQ = 0; - private static final int PACKET_MESSAGE = 1; - private static final int PACKET_PRESENCE = 2; - private Hashtable packetCallbacks = new Hashtable(); private OnPresencePacketReceived presenceListener = null; private OnJinglePacketReceived jingleListener = null; @@ -112,7 +101,6 @@ public class XmppConnection implements Runnable { private OnBindListener bindListener = null; private OnMessageAcknowledged acknowledgedListener = null; private MemorizingTrustManager mMemorizingTrustManager; - private final Context applicationContext; public XmppConnection(Account account, XmppConnectionService service) { this.mRandom = service.getRNG(); @@ -569,6 +557,10 @@ public class XmppConnection implements Runnable { HostnameVerifier verifier = this.mMemorizingTrustManager .wrapHostnameVerifier(new StrictHostnameVerifier()); + + if (socket == null) { + throw new IOException("socket was null"); + } SSLSocket sslSocket = (SSLSocket) factory.createSocket(socket, socket.getInetAddress().getHostAddress(), socket.getPort(), true); @@ -1055,6 +1047,36 @@ public class XmppConnection implements Runnable { return this.features; } + public long getLastSessionEstablished() { + 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.lastPaketReceived; + } + + public void sendActive() { + this.sendPacket(new ActivePacket(), null); + } + + public void sendInactive() { + this.sendPacket(new InactivePacket(), null); + } + public class Features { XmppConnection connection; @@ -1091,6 +1113,10 @@ public class XmppConnection implements Runnable { "http://jabber.org/protocol/pubsub#publish"); } + public boolean mam() { + return hasDiscoFeature(account.getServer(), "urn:xmpp:mam:0"); + } + public boolean rosterVersioning() { if (connection.streamFeatures == null) { return false; @@ -1108,34 +1134,4 @@ public class XmppConnection implements Runnable { return connection.usingCompression; } } - - public long getLastSessionEstablished() { - 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.lastPaketReceived; - } - - public void sendActive() { - this.sendPacket(new ActivePacket(), null); - } - - public void sendInactive() { - this.sendPacket(new InactivePacket(), null); - } } -- cgit v1.2.3