mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-25 03:57:58 +01:00
Throw more exceptions when parsing Presences
when parsing core elements of Presences.
This commit is contained in:
parent
009057e2e2
commit
b083449cc3
1 changed files with 6 additions and 23 deletions
|
@ -259,13 +259,8 @@ public class PacketParserUtils {
|
||||||
Presence.Type type = Presence.Type.available;
|
Presence.Type type = Presence.Type.available;
|
||||||
String typeString = parser.getAttributeValue("", "type");
|
String typeString = parser.getAttributeValue("", "type");
|
||||||
if (typeString != null && !typeString.equals("")) {
|
if (typeString != null && !typeString.equals("")) {
|
||||||
try {
|
|
||||||
type = Presence.Type.fromString(typeString);
|
type = Presence.Type.fromString(typeString);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException iae) {
|
|
||||||
LOGGER.warning("Found invalid presence type " + typeString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Presence presence = new Presence(type);
|
Presence presence = new Presence(type);
|
||||||
presence.setTo(parser.getAttributeValue("", "to"));
|
presence.setTo(parser.getAttributeValue("", "to"));
|
||||||
presence.setFrom(parser.getAttributeValue("", "from"));
|
presence.setFrom(parser.getAttributeValue("", "from"));
|
||||||
|
@ -289,32 +284,20 @@ public class PacketParserUtils {
|
||||||
presence.setStatus(parser.nextText());
|
presence.setStatus(parser.nextText());
|
||||||
}
|
}
|
||||||
else if (elementName.equals("priority")) {
|
else if (elementName.equals("priority")) {
|
||||||
try {
|
|
||||||
int priority = Integer.parseInt(parser.nextText());
|
int priority = Integer.parseInt(parser.nextText());
|
||||||
presence.setPriority(priority);
|
presence.setPriority(priority);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException nfe) {
|
|
||||||
// Ignore.
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException iae) {
|
|
||||||
// Presence priority is out of range so assume priority to be zero
|
|
||||||
presence.setPriority(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (elementName.equals("show")) {
|
else if (elementName.equals("show")) {
|
||||||
String modeText = parser.nextText();
|
String modeText = parser.nextText();
|
||||||
try {
|
|
||||||
presence.setMode(Presence.Mode.fromString(modeText));
|
presence.setMode(Presence.Mode.fromString(modeText));
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException iae) {
|
|
||||||
LOGGER.warning("Found invalid presence mode " + modeText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (elementName.equals("error")) {
|
else if (elementName.equals("error")) {
|
||||||
presence.setError(parseError(parser));
|
presence.setError(parseError(parser));
|
||||||
}
|
}
|
||||||
// Otherwise, it must be a packet extension.
|
// Otherwise, it must be a packet extension.
|
||||||
else {
|
else {
|
||||||
|
// Be extra robust: Skip PacketExtensions that cause Exceptions, instead of
|
||||||
|
// failing completely here. See SMACK-390 for more information.
|
||||||
try {
|
try {
|
||||||
presence.addExtension(PacketParserUtils.parsePacketExtension(elementName, namespace, parser));
|
presence.addExtension(PacketParserUtils.parsePacketExtension(elementName, namespace, parser));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue