aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/parser
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
parent419504eaecd538561307d2b10ef08bdc3a47b137 (diff)
return InvalidJid object instead of null if Jid can not be parsed
Diffstat (limited to 'src/main/java/de/pixart/messenger/parser')
-rw-r--r--src/main/java/de/pixart/messenger/parser/AbstractParser.java7
-rw-r--r--src/main/java/de/pixart/messenger/parser/IqParser.java7
-rw-r--r--src/main/java/de/pixart/messenger/parser/MessageParser.java25
-rw-r--r--src/main/java/de/pixart/messenger/parser/PresenceParser.java3
4 files changed, 28 insertions, 14 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/AbstractParser.java b/src/main/java/de/pixart/messenger/parser/AbstractParser.java
index 50204cb7b..e0a26c18d 100644
--- a/src/main/java/de/pixart/messenger/parser/AbstractParser.java
+++ b/src/main/java/de/pixart/messenger/parser/AbstractParser.java
@@ -10,6 +10,7 @@ import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.entities.MucOptions;
import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.xml.Element;
+import de.pixart.messenger.xmpp.InvalidJid;
import de.pixart.messenger.xmpp.stanzas.AbstractStanza;
import rocks.xmpp.addr.Jid;
@@ -36,7 +37,7 @@ public abstract class AbstractParser {
}
for (Element child : element.getChildren()) {
if ("delay".equals(child.getName()) && "urn:xmpp:delay".equals(child.getNamespace())) {
- final Jid f = to == null ? null : child.getAttributeAsJid("from");
+ final Jid f = to == null ? null : InvalidJid.getNullForInvalid(child.getAttributeAsJid("from"));
if (f != null && (to.asBareJid().equals(f) || to.getDomain().equals(f.toString()))) {
continue;
}
@@ -114,7 +115,9 @@ public abstract class AbstractParser {
}
Jid realJid = item.getAttributeAsJid("jid");
MucOptions.User user = new MucOptions.User(conference.getMucOptions(), fullJid);
- user.setRealJid(realJid);
+ if (InvalidJid.isValid(realJid)) {
+ user.setRealJid(realJid);
+ }
user.setAffiliation(affiliation);
user.setRole(role);
return user;
diff --git a/src/main/java/de/pixart/messenger/parser/IqParser.java b/src/main/java/de/pixart/messenger/parser/IqParser.java
index 8f8cf9ae4..04ce4afaa 100644
--- a/src/main/java/de/pixart/messenger/parser/IqParser.java
+++ b/src/main/java/de/pixart/messenger/parser/IqParser.java
@@ -29,6 +29,7 @@ import de.pixart.messenger.entities.Contact;
import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.utils.Namespace;
import de.pixart.messenger.xml.Element;
+import de.pixart.messenger.xmpp.InvalidJid;
import de.pixart.messenger.xmpp.OnIqPacketReceived;
import de.pixart.messenger.xmpp.OnUpdateBlocklist;
import de.pixart.messenger.xmpp.stanzas.IqPacket;
@@ -47,7 +48,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
}
for (final Element item : query.getChildren()) {
if (item.getName().equals("item")) {
- final Jid jid = item.getAttributeAsJid("jid");
+ final Jid jid = InvalidJid.getNullForInvalid(item.getAttributeAsJid("jid"));
if (jid == null) {
continue;
}
@@ -310,7 +311,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
// Create a collection of Jids from the packet
for (final Element item : items) {
if (item.getName().equals("item")) {
- final Jid jid = item.getAttributeAsJid("jid");
+ final Jid jid = InvalidJid.getNullForInvalid(item.getAttributeAsJid("jid"));
if (jid != null) {
jids.add(jid);
}
@@ -344,7 +345,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
final Collection<Jid> jids = new ArrayList<>(items.size());
for (final Element item : items) {
if (item.getName().equals("item")) {
- final Jid jid = item.getAttributeAsJid("jid");
+ final Jid jid = InvalidJid.getNullForInvalid(item.getAttributeAsJid("jid"));
if (jid != null) {
jids.add(jid);
}
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) {
diff --git a/src/main/java/de/pixart/messenger/parser/PresenceParser.java b/src/main/java/de/pixart/messenger/parser/PresenceParser.java
index 8ce9dfbf7..15fb36372 100644
--- a/src/main/java/de/pixart/messenger/parser/PresenceParser.java
+++ b/src/main/java/de/pixart/messenger/parser/PresenceParser.java
@@ -19,6 +19,7 @@ import de.pixart.messenger.generator.PresenceGenerator;
import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.utils.Namespace;
import de.pixart.messenger.xml.Element;
+import de.pixart.messenger.xmpp.InvalidJid;
import de.pixart.messenger.xmpp.OnPresencePacketReceived;
import de.pixart.messenger.xmpp.pep.Avatar;
import de.pixart.messenger.xmpp.stanzas.PresencePacket;
@@ -66,7 +67,7 @@ public class PresenceParser extends AbstractParser implements
if (item != null && !from.isBareJid()) {
mucOptions.setError(MucOptions.Error.NONE);
MucOptions.User user = parseItem(conversation, item, from);
- if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE) || (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && jid.equals(item.getAttributeAsJid("jid")))) {
+ if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE) || (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && jid.equals(InvalidJid.getNullForInvalid(item.getAttributeAsJid("jid"))))) {
if (mucOptions.setOnline()) {
mXmppConnectionService.getAvatarService().clear(mucOptions);
}