From 830daff160930fa185d5b8ffdc64516d1ef03218 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 5 Aug 2018 22:00:31 +0300 Subject: XMPP: fix stream:error parser --- .../com/juick/server/xmpp/router/StreamError.java | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'juick-server/src/main/java/com/juick/server/xmpp/router') diff --git a/juick-server/src/main/java/com/juick/server/xmpp/router/StreamError.java b/juick-server/src/main/java/com/juick/server/xmpp/router/StreamError.java index 7eacfc94..f731f039 100644 --- a/juick-server/src/main/java/com/juick/server/xmpp/router/StreamError.java +++ b/juick-server/src/main/java/com/juick/server/xmpp/router/StreamError.java @@ -12,6 +12,7 @@ import java.io.IOException; public class StreamError { private String condition; + private String text; public StreamError() {} @@ -21,13 +22,21 @@ public class StreamError { public static StreamError parse(XmlPullParser parser) throws IOException, XmlPullParserException { StreamError streamError = new StreamError(); - while (parser.next() == XmlPullParser.START_TAG) { - final String tag = parser.getName(); - final String xmlns = parser.getNamespace(); - if (xmlns.equals(StreamNamespaces.NS_XMPP_STREAMS)) { - streamError.condition = tag; - } else { - XmlUtils.skip(parser); + final int initial = parser.getDepth(); + while (true) { + int eventType = parser.next(); + if (eventType == XmlPullParser.START_TAG && parser.getDepth() == initial + 1) { + final String tag = parser.getName(); + final String xmlns = parser.getNamespace(); + if (tag.equals("text") && xmlns.equals(StreamNamespaces.NS_XMPP_STREAMS)) { + streamError.text = XmlUtils.getTagText(parser); + } else if (xmlns.equals(StreamNamespaces.NS_XMPP_STREAMS)) { + streamError.condition = tag; + } else { + XmlUtils.skip(parser); + } + } else if (eventType == XmlPullParser.END_TAG && parser.getDepth() == initial) { + break; } } return streamError; @@ -41,4 +50,8 @@ public class StreamError { public String toString() { return String.format("<%s xmlns='%s'/>", condition, StreamNamespaces.NS_XMPP_STREAMS); } + + public String getText() { + return text; + } } -- cgit v1.2.3