mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
SMACK-452 Correctly parse stream error packets
Modified PacketParserUtils.parseStreamError() to take into account that there may be an optional text element and an optional application specific element. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_3_2@13767 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
b253203cfb
commit
bd709dc323
3 changed files with 126 additions and 7 deletions
|
@ -82,13 +82,21 @@ package org.jivesoftware.smack.packet;
|
|||
*/
|
||||
public class StreamError {
|
||||
|
||||
public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-streams";
|
||||
|
||||
private String code;
|
||||
private String text;
|
||||
|
||||
public StreamError(String code) {
|
||||
super();
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public StreamError(String code, String text) {
|
||||
this(code);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error code.
|
||||
*
|
||||
|
@ -98,9 +106,19 @@ public class StreamError {
|
|||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error text, which may be null.
|
||||
*
|
||||
* @return the error text.
|
||||
*/
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder txt = new StringBuilder();
|
||||
txt.append("stream:error (").append(code).append(")");
|
||||
if (text != null) txt.append(" text: ").append(text);
|
||||
return txt.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -695,21 +695,33 @@ public class PacketParserUtils {
|
|||
*/
|
||||
public static StreamError parseStreamError(XmlPullParser parser) throws IOException,
|
||||
XmlPullParserException {
|
||||
StreamError streamError = null;
|
||||
final int depth = parser.getDepth();
|
||||
boolean done = false;
|
||||
String code = null;
|
||||
String text = null;
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
streamError = new StreamError(parser.getName());
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals("error")) {
|
||||
done = true;
|
||||
String namespace = parser.getNamespace();
|
||||
if (StreamError.NAMESPACE.equals(namespace)) {
|
||||
String name = parser.getName();
|
||||
if (name.equals("text") && !parser.isEmptyElementTag()) {
|
||||
parser.next();
|
||||
text = parser.getText();
|
||||
}
|
||||
else {
|
||||
// If it's not a text element, that is qualified by the StreamError.NAMESPACE,
|
||||
// then it has to be the stream error code
|
||||
code = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG && depth == parser.getDepth()) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
return streamError;
|
||||
return new StreamError(code, text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue