aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/parser/MessageParser.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-02 20:39:16 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-02 20:39:16 +0200
commit41d726ef73a20e7e7ee1ff81c5f8326aa0e6c7d8 (patch)
treefc1b190df4275cc753bc869c7f137c0486ba2c91 /src/main/java/de/pixart/messenger/parser/MessageParser.java
parent419504eaecd538561307d2b10ef08bdc3a47b137 (diff)
return InvalidJid object instead of null if Jid can not be parsed
Diffstat (limited to 'src/main/java/de/pixart/messenger/parser/MessageParser.java')
-rw-r--r--src/main/java/de/pixart/messenger/parser/MessageParser.java25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java
index 1f3166015..5e307531f 100644
--- a/src/main/java/de/pixart/messenger/parser/MessageParser.java
+++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java
@@ -40,6 +40,7 @@ import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.utils.CryptoHelper;
import de.pixart.messenger.utils.Namespace;
import de.pixart.messenger.xml.Element;
+import de.pixart.messenger.xmpp.InvalidJid;
import de.pixart.messenger.xmpp.OnMessagePacketReceived;
import de.pixart.messenger.xmpp.chatstate.ChatState;
import de.pixart.messenger.xmpp.pep.Avatar;
@@ -73,7 +74,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
for (Element child : packet.getChildren()) {
if (child.getName().equals("stanza-id")
&& Namespace.STANZA_IDS.equals(child.getNamespace())
- && by.equals(child.getAttributeAsJid("by"))) {
+ && by.equals(InvalidJid.getNullForInvalid(child.getAttributeAsJid("by")))) {
return child.getAttribute("id");
}
}
@@ -82,7 +83,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
private static Jid getTrueCounterpart(Element mucUserElement, Jid fallback) {
final Element item = mucUserElement == null ? null : mucUserElement.findChild("item");
- Jid result = item == null ? null : item.getAttributeAsJid("jid");
+ Jid result = item == null ? null : InvalidJid.getNullForInvalid(item.getAttributeAsJid("jid"));
return result != null ? result : fallback;
}
@@ -232,17 +233,25 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (x != null) {
Element invite = x.findChild("invite");
if (invite != null) {
- Element pw = x.findChild("password");
- Jid from = invite.getAttributeAsJid("from");
+ String password = x.findChildContent("password");
+ Jid from = InvalidJid.getNullForInvalid(invite.getAttributeAsJid("from"));
Contact contact = from == null ? null : account.getRoster().getContact(from);
- return new Invite(message.getAttributeAsJid("from"), pw != null ? pw.getContent() : null, contact);
+ Jid room = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from"));
+ if (room == null) {
+ return null;
+ }
+ return new Invite(room, password, contact);
}
} else {
x = message.findChild("x", "jabber:x:conference");
if (x != null) {
- Jid from = message.getAttributeAsJid("from");
+ Jid from = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from"));
Contact contact = from == null ? null : account.getRoster().getContact(from);
- return new Invite(x.getAttributeAsJid("jid"), x.getAttribute("password"), contact);
+ Jid room = InvalidJid.getNullForInvalid(x.getAttributeAsJid("jid"));
+ if (room == null) {
+ return null;
+ }
+ return new Invite(room, x.getAttribute("password"), contact);
}
}
return null;
@@ -810,7 +819,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
Element displayed = packet.findChild("displayed", "urn:xmpp:chat-markers:0");
if (displayed != null) {
final String id = displayed.getAttribute("id");
- final Jid sender = displayed.getAttributeAsJid("sender");
+ final Jid sender = InvalidJid.getNullForInvalid(displayed.getAttributeAsJid("sender"));
if (packet.fromAccount(account) && !selfAddressed) {
dismissNotification(account, counterpart, query);
} else if (isTypeGroupChat) {