when parsing omemo messages ensure we only find one element
This commit is contained in:
parent
a7c47a33fa
commit
e395da18bf
|
@ -135,7 +135,7 @@ public class XmppAxolotlMessage {
|
|||
break;
|
||||
}
|
||||
}
|
||||
Element payloadElement = axolotlMessage.findChild(PAYLOAD); //TODO make sure we only have _one_ paypload
|
||||
final Element payloadElement = axolotlMessage.findChildEnsureSingle(PAYLOAD, AxolotlService.PEP_PREFIX);
|
||||
if (payloadElement != null) {
|
||||
ciphertext = Base64.decode(payloadElement.getContent().trim(), Base64.DEFAULT);
|
||||
}
|
||||
|
|
|
@ -338,7 +338,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||
final URL xP1S3url = xP1S3 == null ? null : P1S3UrlStreamHandler.of(xP1S3);
|
||||
final String oobUrl = oob != null ? oob.findChildContent("url") : null;
|
||||
final String replacementId = replaceElement == null ? null : replaceElement.getAttribute("id");
|
||||
final Element axolotlEncrypted = packet.findChild(XmppAxolotlMessage.CONTAINERTAG, AxolotlService.PEP_PREFIX); //TODO make sure we only have _one_ axolotl element!
|
||||
final Element axolotlEncrypted = packet.findChildEnsureSingle(XmppAxolotlMessage.CONTAINERTAG, AxolotlService.PEP_PREFIX);
|
||||
int status;
|
||||
final Jid counterpart;
|
||||
final Jid to = packet.getTo();
|
||||
|
|
|
@ -80,6 +80,19 @@ public class Element {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Element findChildEnsureSingle(String name, String xmlns) {
|
||||
final List<Element> results = new ArrayList<>();
|
||||
for (Element child : this.children) {
|
||||
if (name.equals(child.getName()) && xmlns.equals(child.getAttribute("xmlns"))) {
|
||||
results.add(child);
|
||||
}
|
||||
}
|
||||
if (results.size() == 1) {
|
||||
return results.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String findChildContent(String name, String xmlns) {
|
||||
Element element = findChild(name,xmlns);
|
||||
return element == null ? null : element.getContent();
|
||||
|
|
Loading…
Reference in a new issue