check if socket was null before doing ssl connect

This commit is contained in:
iNPUTmice 2014-11-08 20:52:02 +01:00
parent ea657ece0d
commit 047aaf5d4f
2 changed files with 42 additions and 47 deletions

View File

@ -7,7 +7,6 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.NotificationService;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;

View File

@ -65,44 +65,33 @@ import eu.siacs.conversations.xmpp.stanzas.streammgmt.ResumePacket;
public class XmppConnection implements Runnable { 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; protected Account account;
private WakeLock wakeLock; private WakeLock wakeLock;
private SecureRandom mRandom; private SecureRandom mRandom;
private Socket socket; private Socket socket;
private XmlReader tagReader; private XmlReader tagReader;
private TagWriter tagWriter; private TagWriter tagWriter;
private Features features = new Features(this); private Features features = new Features(this);
private boolean shouldBind = true; private boolean shouldBind = true;
private boolean shouldAuthenticate = true; private boolean shouldAuthenticate = true;
private Element streamFeatures; private Element streamFeatures;
private HashMap<String, List<String>> disco = new HashMap<String, List<String>>(); private HashMap<String, List<String>> disco = new HashMap<String, List<String>>();
private String streamId = null; private String streamId = null;
private int smVersion = 3; private int smVersion = 3;
private SparseArray<String> messageReceipts = new SparseArray<String>(); private SparseArray<String> messageReceipts = new SparseArray<String>();
private boolean usingCompression = false; private boolean usingCompression = false;
private boolean usingEncryption = false; private boolean usingEncryption = false;
private int stanzasReceived = 0; private int stanzasReceived = 0;
private int stanzasSent = 0; private int stanzasSent = 0;
private long lastPaketReceived = 0; private long lastPaketReceived = 0;
private long lastPingSent = 0; private long lastPingSent = 0;
private long lastConnect = 0; private long lastConnect = 0;
private long lastSessionStarted = 0; private long lastSessionStarted = 0;
private int attempt = 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<String, PacketReceived> packetCallbacks = new Hashtable<String, PacketReceived>(); private Hashtable<String, PacketReceived> packetCallbacks = new Hashtable<String, PacketReceived>();
private OnPresencePacketReceived presenceListener = null; private OnPresencePacketReceived presenceListener = null;
private OnJinglePacketReceived jingleListener = null; private OnJinglePacketReceived jingleListener = null;
@ -112,7 +101,6 @@ public class XmppConnection implements Runnable {
private OnBindListener bindListener = null; private OnBindListener bindListener = null;
private OnMessageAcknowledged acknowledgedListener = null; private OnMessageAcknowledged acknowledgedListener = null;
private MemorizingTrustManager mMemorizingTrustManager; private MemorizingTrustManager mMemorizingTrustManager;
private final Context applicationContext;
public XmppConnection(Account account, XmppConnectionService service) { public XmppConnection(Account account, XmppConnectionService service) {
this.mRandom = service.getRNG(); this.mRandom = service.getRNG();
@ -569,6 +557,10 @@ public class XmppConnection implements Runnable {
HostnameVerifier verifier = this.mMemorizingTrustManager HostnameVerifier verifier = this.mMemorizingTrustManager
.wrapHostnameVerifier(new StrictHostnameVerifier()); .wrapHostnameVerifier(new StrictHostnameVerifier());
if (socket == null) {
throw new IOException("socket was null");
}
SSLSocket sslSocket = (SSLSocket) factory.createSocket(socket, SSLSocket sslSocket = (SSLSocket) factory.createSocket(socket,
socket.getInetAddress().getHostAddress(), socket.getPort(), socket.getInetAddress().getHostAddress(), socket.getPort(),
true); true);
@ -1055,6 +1047,36 @@ public class XmppConnection implements Runnable {
return this.features; 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 { public class Features {
XmppConnection connection; XmppConnection connection;
@ -1091,6 +1113,10 @@ public class XmppConnection implements Runnable {
"http://jabber.org/protocol/pubsub#publish"); "http://jabber.org/protocol/pubsub#publish");
} }
public boolean mam() {
return hasDiscoFeature(account.getServer(), "urn:xmpp:mam:0");
}
public boolean rosterVersioning() { public boolean rosterVersioning() {
if (connection.streamFeatures == null) { if (connection.streamFeatures == null) {
return false; return false;
@ -1108,34 +1134,4 @@ public class XmppConnection implements Runnable {
return connection.usingCompression; 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);
}
} }