From 77ba68d61f11235f7cbe426a1c26a7f79be90aa1 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 13 Nov 2014 14:27:10 +0100 Subject: more npe checks in muc packet parser --- .../siacs/conversations/entities/MucOptions.java | 67 +++++++++++----------- 1 file changed, 35 insertions(+), 32 deletions(-) (limited to 'src/main/java/eu/siacs/conversations') diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index d7407cd5..01190374 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -151,39 +151,42 @@ public class MucOptions { String type = packet.getAttribute("type"); if (type == null) { User user = new User(); - Element item = packet.findChild("x", - "http://jabber.org/protocol/muc#user") - .findChild("item"); - user.setName(name); - user.setAffiliation(item.getAttribute("affiliation")); - user.setRole(item.getAttribute("role")); - user.setJid(item.getAttribute("jid")); - user.setName(name); - if (name.equals(this.joinnick)) { - this.isOnline = true; - this.error = ERROR_NO_ERROR; - self = user; - if (aboutToRename) { - if (renameListener != null) { - renameListener.onRename(true); - } - aboutToRename = false; - } - } else { - addUser(user); - } - if (pgp != null) { - Element x = packet.findChild("x", "jabber:x:signed"); - if (x != null) { - Element status = packet.findChild("status"); - String msg; - if (status != null) { - msg = status.getContent(); + Element x = packet.findChild("x","http://jabber.org/protocol/muc#user"); + if (x != null) { + Element item = x.findChild("item"); + if (item != null) { + user.setName(name); + user.setAffiliation(item.getAttribute("affiliation")); + user.setRole(item.getAttribute("role")); + user.setJid(item.getAttribute("jid")); + user.setName(name); + if (name.equals(this.joinnick)) { + this.isOnline = true; + this.error = ERROR_NO_ERROR; + self = user; + if (aboutToRename) { + if (renameListener != null) { + renameListener.onRename(true); + } + aboutToRename = false; + } } else { - msg = ""; + addUser(user); + } + if (pgp != null) { + Element signed = packet.findChild("x", "jabber:x:signed"); + if (signed != null) { + Element status = packet.findChild("status"); + String msg; + if (status != null) { + msg = status.getContent(); + } else { + msg = ""; + } + user.setPgpKeyId(pgp.fetchKeyId(account, msg, + signed.getContent())); + } } - user.setPgpKeyId(pgp.fetchKeyId(account, msg, - x.getContent())); } } } else if (type.equals("unavailable") && name.equals(this.joinnick)) { @@ -366,4 +369,4 @@ public class MucOptions { public Conversation getConversation() { return this.conversation; } -} \ No newline at end of file +} -- cgit v1.2.3 From 17c2ed411d747f3206e0e4ea4cd7c4e8331f7d11 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 13 Nov 2014 14:44:19 +0100 Subject: made presences synchronized --- .../eu/siacs/conversations/entities/Presences.java | 40 +++++++++++++++------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src/main/java/eu/siacs/conversations') diff --git a/src/main/java/eu/siacs/conversations/entities/Presences.java b/src/main/java/eu/siacs/conversations/entities/Presences.java index b5899847..bccf3117 100644 --- a/src/main/java/eu/siacs/conversations/entities/Presences.java +++ b/src/main/java/eu/siacs/conversations/entities/Presences.java @@ -22,24 +22,32 @@ public class Presences { } public void updatePresence(String resource, int status) { - this.presences.put(resource, status); + synchronized (this.presences) { + this.presences.put(resource, status); + } } public void removePresence(String resource) { - this.presences.remove(resource); + synchronized (this.presences) { + this.presences.remove(resource); + } } public void clearPresences() { - this.presences.clear(); + synchronized (this.presences) { + this.presences.clear(); + } } public int getMostAvailableStatus() { int status = OFFLINE; - Iterator> it = presences.entrySet().iterator(); - while (it.hasNext()) { - Entry entry = it.next(); - if (entry.getValue() < status) - status = entry.getValue(); + synchronized (this.presences) { + Iterator> it = presences.entrySet().iterator(); + while (it.hasNext()) { + Entry entry = it.next(); + if (entry.getValue() < status) + status = entry.getValue(); + } } return status; } @@ -61,16 +69,22 @@ public class Presences { } public int size() { - return presences.size(); + synchronized (this.presences) { + return presences.size(); + } } public String[] asStringArray() { - final String[] presencesArray = new String[presences.size()]; - presences.keySet().toArray(presencesArray); - return presencesArray; + synchronized (this.presences) { + final String[] presencesArray = new String[presences.size()]; + presences.keySet().toArray(presencesArray); + return presencesArray; + } } public boolean has(String presence) { - return presences.containsKey(presence); + synchronized (this.presences) { + return presences.containsKey(presence); + } } } -- cgit v1.2.3 From ac4eabbd2257217eebddfc33840a618e78a97cad Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sun, 16 Nov 2014 00:34:16 +0100 Subject: close cursor for database --- .../conversations/persistance/DatabaseBackend.java | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/main/java/eu/siacs/conversations') diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index ef045546..e5ea8f90 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -143,7 +143,9 @@ public class DatabaseBackend extends SQLiteOpenHelper { + Conversation.TABLENAME + " where " + Conversation.STATUS + "=" + Conversation.STATUS_AVAILABLE, null); cursor.moveToFirst(); - return cursor.getInt(0); + int count = cursor.getInt(0); + cursor.close(); + return count; } public CopyOnWriteArrayList getConversations(int status) { @@ -156,6 +158,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { while (cursor.moveToNext()) { list.add(Conversation.fromCursor(cursor)); } + cursor.close(); return list; } @@ -189,6 +192,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { list.add(message); } while (cursor.moveToPrevious()); } + cursor.close(); return list; } @@ -201,7 +205,9 @@ public class DatabaseBackend extends SQLiteOpenHelper { if (cursor.getCount() == 0) return null; cursor.moveToFirst(); - return Conversation.fromCursor(cursor); + Conversation conversation = Conversation.fromCursor(cursor); + cursor.close(); + return conversation; } public void updateConversation(Conversation conversation) { @@ -313,7 +319,9 @@ public class DatabaseBackend extends SQLiteOpenHelper { return null; } cursor.moveToFirst(); - return Conversation.fromCursor(cursor); + Conversation conversation = Conversation.fromCursor(cursor); + cursor.close(); + return conversation; } public Message findMessageByUuid(String messageUuid) { @@ -325,7 +333,9 @@ public class DatabaseBackend extends SQLiteOpenHelper { return null; } cursor.moveToFirst(); - return Message.fromCursor(cursor); + Message message = Message.fromCursor(cursor); + cursor.close(); + return message; } public Account findAccountByUuid(String accountUuid) { @@ -337,7 +347,9 @@ public class DatabaseBackend extends SQLiteOpenHelper { return null; } cursor.moveToFirst(); - return Account.fromCursor(cursor); + Account account = Account.fromCursor(cursor); + cursor.close(); + return account; } public List getImageMessages(Conversation conversation) { @@ -355,6 +367,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { list.add(message); } while (cursor.moveToPrevious()); } + cursor.close(); return list; } } -- cgit v1.2.3