1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 12:02:05 +01:00

Do not call XmlPullParser.getName() when the event is unknown

XmlPullParser.getName() only returns a result if the current parser
event is START_ELEMENT or END_ELEMENT. If this is not the case, then
the method may throw (if StAX is used).
This commit is contained in:
Florian Schmaus 2021-07-06 12:33:11 +02:00
parent 4120b42761
commit 5eef31e49c
25 changed files with 74 additions and 90 deletions

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright © 2016-2019 Florian Schmaus * Copyright © 2016-2021 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,9 +39,9 @@ public class IoTSetRequestProvider extends IQProvider<IoTSetRequest> {
List<SetData> data = new ArrayList<>(4); List<SetData> data = new ArrayList<>(4);
outerloop: while (true) { outerloop: while (true) {
final XmlPullParser.Event eventType = parser.next(); final XmlPullParser.Event eventType = parser.next();
final String name = parser.getName();
switch (eventType) { switch (eventType) {
case START_ELEMENT: case START_ELEMENT:
final String name = parser.getName();
switch (name) { switch (name) {
case "bool": { case "bool": {
String valueName = parser.getAttributeValue(null, "name"); String valueName = parser.getAttributeValue(null, "name");

View file

@ -110,9 +110,9 @@ public class IoTFieldsExtensionProvider extends ExtensionElementProvider<IoTFiel
List<IoTDataField> fields = new ArrayList<>(); List<IoTDataField> fields = new ArrayList<>();
outerloop: while (true) { outerloop: while (true) {
final XmlPullParser.Event eventType = parser.next(); final XmlPullParser.Event eventType = parser.next();
final String name = parser.getName();
switch (eventType) { switch (eventType) {
case START_ELEMENT: case START_ELEMENT:
final String name = parser.getName();
IoTDataField field = null; IoTDataField field = null;
final String fieldName = parser.getAttributeValue(null, "name"); final String fieldName = parser.getAttributeValue(null, "name");
final String fieldValue = parser.getAttributeValue(null, "value"); final String fieldValue = parser.getAttributeValue(null, "value");

View file

@ -59,9 +59,9 @@ public class MamPrefsIQProvider extends IQProvider<MamPrefsIQ> {
outerloop: while (true) { outerloop: while (true) {
final XmlPullParser.Event eventType = parser.next(); final XmlPullParser.Event eventType = parser.next();
final String name = parser.getName();
switch (eventType) { switch (eventType) {
case START_ELEMENT: case START_ELEMENT:
final String name = parser.getName();
switch (name) { switch (name) {
case "always": case "always":
alwaysJids = iterateJids(parser); alwaysJids = iterateJids(parser);
@ -92,9 +92,9 @@ public class MamPrefsIQProvider extends IQProvider<MamPrefsIQ> {
outerloop: while (true) { outerloop: while (true) {
final XmlPullParser.Event eventType = parser.next(); final XmlPullParser.Event eventType = parser.next();
final String name = parser.getName();
switch (eventType) { switch (eventType) {
case START_ELEMENT: case START_ELEMENT:
final String name = parser.getName();
switch (name) { switch (name) {
case "jid": case "jid":
parser.next(); parser.next();

View file

@ -47,10 +47,10 @@ public class MamQueryIQProvider extends IQProvider<MamQueryIQ> {
outerloop: while (true) { outerloop: while (true) {
final XmlPullParser.Event eventType = parser.next(); final XmlPullParser.Event eventType = parser.next();
final String name = parser.getName();
switch (eventType) { switch (eventType) {
case START_ELEMENT: case START_ELEMENT:
final String name = parser.getName();
switch (name) { switch (name) {
case DataForm.ELEMENT: case DataForm.ELEMENT:
dataForm = DataFormProvider.INSTANCE.parse(parser); dataForm = DataFormProvider.INSTANCE.parse(parser);

View file

@ -49,9 +49,9 @@ public class MamResultProvider extends ExtensionElementProvider<MamResultExtensi
outerloop: while (true) { outerloop: while (true) {
final XmlPullParser.Event eventType = parser.next(); final XmlPullParser.Event eventType = parser.next();
final String name = parser.getName();
switch (eventType) { switch (eventType) {
case START_ELEMENT: case START_ELEMENT:
final String name = parser.getName();
switch (name) { switch (name) {
case Forwarded.ELEMENT: case Forwarded.ELEMENT:
forwarded = ForwardedProvider.parseForwardedMessage(parser, xmlEnvironment); forwarded = ForwardedProvider.parseForwardedMessage(parser, xmlEnvironment);

View file

@ -50,10 +50,11 @@ public class MarkupElementProvider extends ExtensionElementProvider<MarkupElemen
while (true) { while (true) {
XmlPullParser.Event tag = parser.next(); XmlPullParser.Event tag = parser.next();
String name = parser.getName(); String name;
int start, end; int start, end;
switch (tag) { switch (tag) {
case START_ELEMENT: case START_ELEMENT:
name = parser.getName();
switch (name) { switch (name) {
case BlockQuoteElement.ELEMENT: case BlockQuoteElement.ELEMENT:
start = ParserUtils.getIntegerAttributeOrThrow(parser, MarkupChildElement.ATTR_START, start = ParserUtils.getIntegerAttributeOrThrow(parser, MarkupChildElement.ATTR_START,
@ -108,6 +109,11 @@ public class MarkupElementProvider extends ExtensionElementProvider<MarkupElemen
break; break;
case END_ELEMENT: case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
return markup.build();
}
name = parser.getName();
switch (name) { switch (name) {
case SpanElement.ELEMENT: case SpanElement.ELEMENT:
markup.addSpan(spanStart, spanEnd, spanStyles); markup.addSpan(spanStart, spanEnd, spanStyles);
@ -128,9 +134,6 @@ public class MarkupElementProvider extends ExtensionElementProvider<MarkupElemen
} }
listBuilder.endList(); listBuilder.endList();
break; break;
case MarkupElement.ELEMENT:
return markup.build();
} }
break; break;

View file

@ -55,8 +55,8 @@ public class BytestreamsProvider extends IQProvider<Bytestream> {
String elementName; String elementName;
while (!done) { while (!done) {
eventType = parser.next(); eventType = parser.next();
elementName = parser.getName();
if (eventType == XmlPullParser.Event.START_ELEMENT) { if (eventType == XmlPullParser.Event.START_ELEMENT) {
elementName = parser.getName();
if (elementName.equals(Bytestream.StreamHost.ELEMENT)) { if (elementName.equals(Bytestream.StreamHost.ELEMENT)) {
JID = ParserUtils.getJidAttribute(parser); JID = ParserUtils.getJidAttribute(parser);
host = parser.getAttributeValue("", "host"); host = parser.getAttributeValue("", "host");
@ -70,6 +70,7 @@ public class BytestreamsProvider extends IQProvider<Bytestream> {
} }
} }
else if (eventType == XmlPullParser.Event.END_ELEMENT) { else if (eventType == XmlPullParser.Event.END_ELEMENT) {
elementName = parser.getName();
if (elementName.equals("streamhost")) { if (elementName.equals("streamhost")) {
if (port == null) { if (port == null) {
toReturn.addStreamHost(JID, host); toReturn.addStreamHost(JID, host);

View file

@ -78,9 +78,9 @@ public class AdHocCommandDataProvider extends IQProvider<AdHocCommandData> {
} }
while (!done) { while (!done) {
eventType = parser.next(); eventType = parser.next();
elementName = parser.getName();
namespace = parser.getNamespace(); namespace = parser.getNamespace();
if (eventType == XmlPullParser.Event.START_ELEMENT) { if (eventType == XmlPullParser.Event.START_ELEMENT) {
elementName = parser.getName();
if (parser.getName().equals("actions")) { if (parser.getName().equals("actions")) {
String execute = parser.getAttributeValue("", "execute"); String execute = parser.getAttributeValue("", "execute");
if (execute != null) { if (execute != null) {

View file

@ -31,7 +31,6 @@ import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.xml.XmlPullParser; import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException; import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate; import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate;
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider; import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport; import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport;
@ -62,9 +61,9 @@ public class JingleS5BTransportProvider extends JingleContentTransportProvider<J
JingleS5BTransportCandidate.Builder cb; JingleS5BTransportCandidate.Builder cb;
outerloop: while (true) { outerloop: while (true) {
XmlPullParser.TagEvent tag = parser.nextTag(); XmlPullParser.TagEvent tag = parser.nextTag();
String name = parser.getName();
switch (tag) { switch (tag) {
case START_ELEMENT: { case START_ELEMENT: {
String name = parser.getName();
switch (name) { switch (name) {
case JingleContentTransportCandidate.ELEMENT: case JingleContentTransportCandidate.ELEMENT:
@ -110,8 +109,7 @@ public class JingleS5BTransportProvider extends JingleContentTransportProvider<J
break; break;
case END_ELEMENT: { case END_ELEMENT: {
switch (name) { if (parser.getDepth() == initialDepth) {
case JingleContentTransport.ELEMENT:
break outerloop; break outerloop;
} }
} }

View file

@ -45,11 +45,11 @@ public class MoodProvider extends ExtensionElementProvider<MoodElement> {
outerloop: while (true) { outerloop: while (true) {
XmlPullParser.Event tag = parser.next(); XmlPullParser.Event tag = parser.next();
String name = parser.getName();
String namespace = parser.getNamespace();
switch (tag) { switch (tag) {
case START_ELEMENT: case START_ELEMENT:
String name = parser.getName();
String namespace = parser.getNamespace();
if (MoodElement.ELEM_TEXT.equals(name)) { if (MoodElement.ELEM_TEXT.equals(name)) {
text = parser.nextText(); text = parser.nextText();
continue outerloop; continue outerloop;
@ -74,7 +74,7 @@ public class MoodProvider extends ExtensionElementProvider<MoodElement> {
} }
case END_ELEMENT: case END_ELEMENT:
if (MoodElement.ELEMENT.equals(name)) { if (MoodElement.ELEMENT.equals(parser.getName())) {
MoodElement.MoodSubjectElement subjectElement = (mood == null && concretisation == null) ? MoodElement.MoodSubjectElement subjectElement = (mood == null && concretisation == null) ?
null : new MoodElement.MoodSubjectElement(mood, concretisation); null : new MoodElement.MoodSubjectElement(mood, concretisation);
return new MoodElement(subjectElement, text); return new MoodElement(subjectElement, text);

View file

@ -46,8 +46,6 @@ public class StreamInitiationProvider extends IQProvider<StreamInitiation> {
@Override @Override
public StreamInitiation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException { public StreamInitiation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
boolean done = false;
// si // si
String id = parser.getAttributeValue("", "id"); String id = parser.getAttributeValue("", "id");
String mimeType = parser.getAttributeValue("", "mime-type"); String mimeType = parser.getAttributeValue("", "mime-type");
@ -66,13 +64,11 @@ public class StreamInitiationProvider extends IQProvider<StreamInitiation> {
DataForm form = null; DataForm form = null;
DataFormProvider dataFormProvider = new DataFormProvider(); DataFormProvider dataFormProvider = new DataFormProvider();
String elementName; outerloop: while (true) {
String namespace;
while (!done) {
XmlPullParser.Event eventType = parser.next(); XmlPullParser.Event eventType = parser.next();
elementName = parser.getName();
namespace = parser.getNamespace();
if (eventType == XmlPullParser.Event.START_ELEMENT) { if (eventType == XmlPullParser.Event.START_ELEMENT) {
String elementName = parser.getName();
String namespace = parser.getNamespace();
if (elementName.equals("file")) { if (elementName.equals("file")) {
name = parser.getAttributeValue("", "name"); name = parser.getAttributeValue("", "name");
size = parser.getAttributeValue("", "size"); size = parser.getAttributeValue("", "size");
@ -87,9 +83,10 @@ public class StreamInitiationProvider extends IQProvider<StreamInitiation> {
form = dataFormProvider.parse(parser); form = dataFormProvider.parse(parser);
} }
} else if (eventType == XmlPullParser.Event.END_ELEMENT) { } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (elementName.equals("si")) { if (parser.getDepth() == initialDepth) {
done = true; break outerloop;
} else if (elementName.equals("file")) { }
if (parser.getName().equals("file")) {
long fileSize = 0; long fileSize = 0;
if (size != null && size.trim().length() != 0) { if (size != null && size.trim().length() != 0) {
try { try {

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2003-2007 Jive Software, 2014-2019 Florian Schmaus * Copyright 2003-2007 Jive Software, 2014-2021 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -40,8 +40,8 @@ public class XHTMLExtensionProvider extends ExtensionElementProvider<XHTMLExtens
while (true) { while (true) {
XmlPullParser.Event eventType = parser.getEventType(); XmlPullParser.Event eventType = parser.getEventType();
String name = parser.getName();
if (eventType == XmlPullParser.Event.START_ELEMENT) { if (eventType == XmlPullParser.Event.START_ELEMENT) {
String name = parser.getName();
if (name.equals(Message.BODY)) { if (name.equals(Message.BODY)) {
xhtmlExtension.addBody(PacketParserUtils.parseElement(parser)); xhtmlExtension.addBody(PacketParserUtils.parseElement(parser));
} }

View file

@ -340,7 +340,6 @@ public class RTPBridge extends IQ {
boolean done = false; boolean done = false;
XmlPullParser.Event eventType; XmlPullParser.Event eventType;
String elementName;
if (!parser.getNamespace().equals(RTPBridge.NAMESPACE)) if (!parser.getNamespace().equals(RTPBridge.NAMESPACE))
// TODO: Should be SmackParseException. // TODO: Should be SmackParseException.
@ -356,9 +355,9 @@ public class RTPBridge extends IQ {
// Start processing sub-elements // Start processing sub-elements
while (!done) { while (!done) {
eventType = parser.next(); eventType = parser.next();
elementName = parser.getName();
if (eventType == XmlPullParser.Event.START_ELEMENT) { if (eventType == XmlPullParser.Event.START_ELEMENT) {
String elementName = parser.getName();
if (elementName.equals("candidate")) { if (elementName.equals("candidate")) {
for (int i = 0; i < parser.getAttributeCount(); i++) { for (int i = 0; i < parser.getAttributeCount(); i++) {
if (parser.getAttributeName(i).equals("ip")) if (parser.getAttributeName(i).equals("ip"))

View file

@ -66,14 +66,13 @@ public abstract class JingleContentDescriptionProvider extends ExtensionElementP
public JingleContentDescription parse(XmlPullParser parser, public JingleContentDescription parse(XmlPullParser parser,
int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException,
IOException { IOException {
boolean done = false;
JingleContentDescription desc = getInstance(); JingleContentDescription desc = getInstance();
while (!done) { outerloop: while (true) {
XmlPullParser.Event eventType = parser.next(); XmlPullParser.Event eventType = parser.next();
String name = parser.getName();
if (eventType == XmlPullParser.Event.START_ELEMENT) { if (eventType == XmlPullParser.Event.START_ELEMENT) {
String name = parser.getName();
if (name.equals(JingleContentDescription.JinglePayloadType.NODENAME)) { if (name.equals(JingleContentDescription.JinglePayloadType.NODENAME)) {
desc.addJinglePayloadType(parsePayload(parser)); desc.addJinglePayloadType(parsePayload(parser));
} else { } else {
@ -81,8 +80,8 @@ public abstract class JingleContentDescriptionProvider extends ExtensionElementP
throw new IOException("Unknow element \"" + name + "\" in content."); throw new IOException("Unknow element \"" + name + "\" in content.");
} }
} else if (eventType == XmlPullParser.Event.END_ELEMENT) { } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (name.equals(JingleContentDescription.NODENAME)) { if (parser.getDepth() == initialDepth) {
done = true; break outerloop;
} }
} }
} }

View file

@ -65,14 +65,12 @@ public abstract class JingleDescriptionProvider extends ExtensionElementProvider
*/ */
@Override @Override
public JingleDescription parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { public JingleDescription parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
boolean done = false;
JingleDescription desc = getInstance(); JingleDescription desc = getInstance();
while (!done) { outerloop: while (true) {
XmlPullParser.Event eventType = parser.next(); XmlPullParser.Event eventType = parser.next();
String name = parser.getName();
if (eventType == XmlPullParser.Event.START_ELEMENT) { if (eventType == XmlPullParser.Event.START_ELEMENT) {
String name = parser.getName();
if (name.equals(PayloadType.NODENAME)) { if (name.equals(PayloadType.NODENAME)) {
desc.addPayloadType(parsePayload(parser)); desc.addPayloadType(parsePayload(parser));
} else { } else {
@ -80,8 +78,8 @@ public abstract class JingleDescriptionProvider extends ExtensionElementProvider
throw new IOException("Unknow element \"" + name + "\" in content."); throw new IOException("Unknow element \"" + name + "\" in content.");
} }
} else if (eventType == XmlPullParser.Event.END_ELEMENT) { } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (name.equals(JingleDescription.NODENAME)) { if (parser.getDepth() == initialDepth) {
done = true; break outerloop;
} }
} }
} }

View file

@ -84,10 +84,10 @@ public class JingleProvider extends IQProvider<Jingle> {
// Start processing sub-elements // Start processing sub-elements
while (!done) { while (!done) {
eventType = parser.next(); eventType = parser.next();
elementName = parser.getName();
namespace = parser.getNamespace();
if (eventType == XmlPullParser.Event.START_ELEMENT) { if (eventType == XmlPullParser.Event.START_ELEMENT) {
elementName = parser.getName();
namespace = parser.getNamespace();
// Parse some well know subelements, depending on the namespaces // Parse some well know subelements, depending on the namespaces
// and element names... // and element names...

View file

@ -54,14 +54,13 @@ public abstract class JingleTransportProvider extends ExtensionElementProvider<J
*/ */
@Override @Override
public JingleTransport parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { public JingleTransport parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
boolean done = false;
JingleTransport trans = getInstance(); JingleTransport trans = getInstance();
while (!done) { outerloop: while (true) {
XmlPullParser.Event eventType = parser.next(); XmlPullParser.Event eventType = parser.next();
String name = parser.getName();
if (eventType == XmlPullParser.Event.START_ELEMENT) { if (eventType == XmlPullParser.Event.START_ELEMENT) {
String name = parser.getName();
if (name.equals(JingleTransportCandidate.NODENAME)) { if (name.equals(JingleTransportCandidate.NODENAME)) {
JingleTransportCandidate jtc = parseCandidate(parser); JingleTransportCandidate jtc = parseCandidate(parser);
if (jtc != null) trans.addCandidate(jtc); if (jtc != null) trans.addCandidate(jtc);
@ -72,8 +71,8 @@ public abstract class JingleTransportProvider extends ExtensionElementProvider<J
} }
} }
else if (eventType == XmlPullParser.Event.END_ELEMENT) { else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (name.equals(JingleTransport.NODENAME)) { if (parser.getDepth() == initialDepth) {
done = true; break outerloop;
} }
} }
} }

View file

@ -71,14 +71,13 @@ public class OfferConfirmation extends SimpleIQ {
boolean done = false; boolean done = false;
while (!done) { while (!done) {
parser.next(); parser.next();
String elementName = parser.getName(); if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "user-jid".equals(parser.getName())) {
if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "user-jid".equals(elementName)) {
confirmation.setUserJID(parser.nextText()); confirmation.setUserJID(parser.nextText());
} }
else if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "session-id".equals(elementName)) { else if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "session-id".equals(parser.getName())) {
confirmation.setSessionID(Long.valueOf(parser.nextText())); confirmation.setSessionID(Long.valueOf(parser.nextText()));
} }
else if (parser.getEventType() == XmlPullParser.Event.END_ELEMENT && "offer-confirmation".equals(elementName)) { else if (parser.getEventType() == XmlPullParser.Event.END_ELEMENT && "offer-confirmation".equals(parser.getName())) {
done = true; done = true;
} }
} }

View file

@ -108,14 +108,13 @@ public class QueueUpdate implements ExtensionElement {
int timeRemaining = -1; int timeRemaining = -1;
while (!done) { while (!done) {
parser.next(); parser.next();
String elementName = parser.getName(); if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "position".equals(parser.getName())) {
if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "position".equals(elementName)) {
position = Integer.parseInt(parser.nextText()); position = Integer.parseInt(parser.nextText());
} }
else if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "time".equals(elementName)) { else if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "time".equals(parser.getName())) {
timeRemaining = Integer.parseInt(parser.nextText()); timeRemaining = Integer.parseInt(parser.nextText());
} }
else if (parser.getEventType() == XmlPullParser.Event.END_ELEMENT && "queue-status".equals(elementName)) { else if (parser.getEventType() == XmlPullParser.Event.END_ELEMENT && "queue-status".equals(parser.getName())) {
done = true; done = true;
} }
} }

View file

@ -179,11 +179,10 @@ public class RoomInvitation implements ExtensionElement {
final RoomInvitation invitation = new RoomInvitation(); final RoomInvitation invitation = new RoomInvitation();
invitation.type = Type.valueOf(parser.getAttributeValue("", "type")); invitation.type = Type.valueOf(parser.getAttributeValue("", "type"));
boolean done = false; outerloop: while (true) {
while (!done) {
parser.next(); parser.next();
String elementName = parser.getName();
if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT) { if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT) {
String elementName = parser.getName();
if ("session".equals(elementName)) { if ("session".equals(elementName)) {
invitation.sessionID = parser.getAttributeValue("", "id"); invitation.sessionID = parser.getAttributeValue("", "id");
} }
@ -203,8 +202,8 @@ public class RoomInvitation implements ExtensionElement {
invitation.room = JidCreate.entityBareFrom(roomString); invitation.room = JidCreate.entityBareFrom(roomString);
} }
} }
else if (parser.getEventType() == XmlPullParser.Event.END_ELEMENT && ELEMENT_NAME.equals(elementName)) { else if (parser.getEventType() == XmlPullParser.Event.END_ELEMENT && parser.getDepth() == initialDepth) {
done = true; break outerloop;
} }
} }
return invitation; return invitation;

View file

@ -174,11 +174,10 @@ public class RoomTransfer implements ExtensionElement {
final RoomTransfer invitation = new RoomTransfer(); final RoomTransfer invitation = new RoomTransfer();
invitation.type = RoomTransfer.Type.valueOf(parser.getAttributeValue("", "type")); invitation.type = RoomTransfer.Type.valueOf(parser.getAttributeValue("", "type"));
boolean done = false; outerloop: while (true) {
while (!done) {
parser.next(); parser.next();
String elementName = parser.getName();
if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT) { if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT) {
String elementName = parser.getName();
if ("session".equals(elementName)) { if ("session".equals(elementName)) {
invitation.sessionID = parser.getAttributeValue("", "id"); invitation.sessionID = parser.getAttributeValue("", "id");
} }
@ -195,8 +194,8 @@ public class RoomTransfer implements ExtensionElement {
invitation.room = parser.nextText(); invitation.room = parser.nextText();
} }
} }
else if (parser.getEventType() == XmlPullParser.Event.END_ELEMENT && ELEMENT_NAME.equals(elementName)) { else if (parser.getEventType() == XmlPullParser.Event.END_ELEMENT && parser.getDepth() == initialDepth) {
done = true; break outerloop;
} }
} }
return invitation; return invitation;

View file

@ -16,7 +16,6 @@
*/ */
package org.jivesoftware.smackx.omemo.provider; package org.jivesoftware.smackx.omemo.provider;
import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.BUNDLE;
import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.IDENTITY_KEY; import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.IDENTITY_KEY;
import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.PRE_KEYS; import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.PRE_KEYS;
import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.PRE_KEY_ID; import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.PRE_KEY_ID;
@ -43,7 +42,6 @@ import org.jivesoftware.smackx.omemo.element.OmemoBundleElement_VAxolotl;
public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider<OmemoBundleElement_VAxolotl> { public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider<OmemoBundleElement_VAxolotl> {
@Override @Override
public OmemoBundleElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { public OmemoBundleElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
boolean stop = false;
boolean inPreKeys = false; boolean inPreKeys = false;
int signedPreKeyId = -1; int signedPreKeyId = -1;
@ -52,11 +50,11 @@ public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider<OmemoB
String identityKey = null; String identityKey = null;
HashMap<Integer, String> preKeys = new HashMap<>(); HashMap<Integer, String> preKeys = new HashMap<>();
while (!stop) { outerloop: while (true) {
XmlPullParser.Event tag = parser.next(); XmlPullParser.Event tag = parser.next();
String name = parser.getName();
switch (tag) { switch (tag) {
case START_ELEMENT: case START_ELEMENT:
String name = parser.getName();
final int attributeCount = parser.getAttributeCount(); final int attributeCount = parser.getAttributeCount();
// <signedPreKeyPublic> // <signedPreKeyPublic>
if (name.equals(SIGNED_PRE_KEY_PUB)) { if (name.equals(SIGNED_PRE_KEY_PUB)) {
@ -91,8 +89,8 @@ public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider<OmemoB
} }
break; break;
case END_ELEMENT: case END_ELEMENT:
if (name.equals(BUNDLE)) { if (parser.getDepth() == initialDepth) {
stop = true; break outerloop;
} }
break; break;
default: default:

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2017 Paul Schaub * Copyright 2017 Paul Schaub, 2021 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,7 +18,6 @@ package org.jivesoftware.smackx.omemo.provider;
import static org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement.DEVICE; import static org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement.DEVICE;
import static org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement.ID; import static org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement.ID;
import static org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement.LIST;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
@ -41,12 +40,11 @@ public class OmemoDeviceListVAxolotlProvider extends ExtensionElementProvider<Om
@Override @Override
public OmemoDeviceListElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { public OmemoDeviceListElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
Set<Integer> deviceListIds = new HashSet<>(); Set<Integer> deviceListIds = new HashSet<>();
boolean stop = false; outerloop: while (true) {
while (!stop) {
XmlPullParser.Event tag = parser.next(); XmlPullParser.Event tag = parser.next();
String name = parser.getName();
switch (tag) { switch (tag) {
case START_ELEMENT: case START_ELEMENT:
String name = parser.getName();
if (name.equals(DEVICE)) { if (name.equals(DEVICE)) {
for (int i = 0; i < parser.getAttributeCount(); i++) { for (int i = 0; i < parser.getAttributeCount(); i++) {
if (parser.getAttributeName(i).equals(ID)) { if (parser.getAttributeName(i).equals(ID)) {
@ -57,8 +55,8 @@ public class OmemoDeviceListVAxolotlProvider extends ExtensionElementProvider<Om
} }
break; break;
case END_ELEMENT: case END_ELEMENT:
if (name.equals(LIST)) { if (parser.getDepth() == initialDepth) {
stop = true; break outerloop;
} }
break; break;
default: default:

View file

@ -17,7 +17,6 @@
package org.jivesoftware.smackx.omemo.provider; package org.jivesoftware.smackx.omemo.provider;
import static org.jivesoftware.smackx.omemo.element.OmemoElement.ATTR_PAYLOAD; import static org.jivesoftware.smackx.omemo.element.OmemoElement.ATTR_PAYLOAD;
import static org.jivesoftware.smackx.omemo.element.OmemoElement.NAME_ENCRYPTED;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -42,17 +41,16 @@ public class OmemoVAxolotlProvider extends ExtensionElementProvider<OmemoElement
@Override @Override
public OmemoElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { public OmemoElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
boolean inEncrypted = true;
int sid = -1; int sid = -1;
ArrayList<OmemoKeyElement> keys = new ArrayList<>(); ArrayList<OmemoKeyElement> keys = new ArrayList<>();
byte[] iv = null; byte[] iv = null;
byte[] payload = null; byte[] payload = null;
while (inEncrypted) { outerloop: while (true) {
XmlPullParser.Event tag = parser.next(); XmlPullParser.Event tag = parser.next();
String name = parser.getName();
switch (tag) { switch (tag) {
case START_ELEMENT: case START_ELEMENT:
String name = parser.getName();
switch (name) { switch (name) {
case OmemoHeaderElement.ELEMENT: case OmemoHeaderElement.ELEMENT:
for (int i = 0; i < parser.getAttributeCount(); i++) { for (int i = 0; i < parser.getAttributeCount(); i++) {
@ -82,8 +80,8 @@ public class OmemoVAxolotlProvider extends ExtensionElementProvider<OmemoElement
} }
break; break;
case END_ELEMENT: case END_ELEMENT:
if (name.equals(NAME_ENCRYPTED)) { if (parser.getDepth() == initialDepth) {
inEncrypted = false; break outerloop;
} }
break; break;
default: default:

View file

@ -42,8 +42,8 @@ public class PubkeyElementProvider extends ExtensionElementProvider<PubkeyElemen
Date date = ParserUtils.getDateFromOptionalXep82String(dateString); Date date = ParserUtils.getDateFromOptionalXep82String(dateString);
while (true) { while (true) {
XmlPullParser.Event tag = parser.next(); XmlPullParser.Event tag = parser.next();
String name = parser.getName();
if (tag == XmlPullParser.Event.START_ELEMENT) { if (tag == XmlPullParser.Event.START_ELEMENT) {
String name = parser.getName();
switch (name) { switch (name) {
case PubkeyElement.PubkeyDataElement.ELEMENT: case PubkeyElement.PubkeyDataElement.ELEMENT:
String base64EncodedOpenPgpPubKey = parser.nextText(); String base64EncodedOpenPgpPubKey = parser.nextText();