From 5673eca05966e7cffefcff7e07a7671e58726ab4 Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Thu, 19 Jun 2003 14:40:48 +0000 Subject: [PATCH] More forgiving with values from incoming packets. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1967 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/packet/IQ.java | 4 ++++ source/org/jivesoftware/smack/packet/Message.java | 4 ++++ source/org/jivesoftware/smack/packet/Presence.java | 7 ++++++- source/org/jivesoftware/smack/packet/RosterPacket.java | 8 ++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/source/org/jivesoftware/smack/packet/IQ.java b/source/org/jivesoftware/smack/packet/IQ.java index 9c1c7ba57..5f0e431f7 100644 --- a/source/org/jivesoftware/smack/packet/IQ.java +++ b/source/org/jivesoftware/smack/packet/IQ.java @@ -154,6 +154,10 @@ public class IQ extends Packet { * @return the corresponding Type. */ public static Type fromString(String type) { + if (type == null) { + return null; + } + type = type.toLowerCase(); if (GET.toString().equals(type)) { return GET; } diff --git a/source/org/jivesoftware/smack/packet/Message.java b/source/org/jivesoftware/smack/packet/Message.java index dbd426750..7041680b5 100644 --- a/source/org/jivesoftware/smack/packet/Message.java +++ b/source/org/jivesoftware/smack/packet/Message.java @@ -269,6 +269,10 @@ public class Message extends Packet { * @return the Type corresponding to the String. */ public static Type fromString(String type) { + if (type == null) { + return NORMAL; + } + type = type.toLowerCase(); if (CHAT.toString().equals(type)) { return CHAT; } diff --git a/source/org/jivesoftware/smack/packet/Presence.java b/source/org/jivesoftware/smack/packet/Presence.java index 7ac28b8a3..52d7708f1 100644 --- a/source/org/jivesoftware/smack/packet/Presence.java +++ b/source/org/jivesoftware/smack/packet/Presence.java @@ -252,6 +252,10 @@ public class Presence extends Packet { * Returns the type constant associated with the String value. */ public static Type fromString(String value) { + if (value == null) { + return AVAILABLE; + } + value = value.toLowerCase(); if ("unavailable".equals(value)) { return UNAVAILABLE; } @@ -306,7 +310,8 @@ public class Presence extends Packet { if (value == null) { return AVAILABLE; } - else if (value.equals("chat")) { + value = value.toLowerCase(); + if (value.equals("chat")) { return CHAT; } else if (value.equals("away")) { diff --git a/source/org/jivesoftware/smack/packet/RosterPacket.java b/source/org/jivesoftware/smack/packet/RosterPacket.java index cb818e81e..091d033f6 100644 --- a/source/org/jivesoftware/smack/packet/RosterPacket.java +++ b/source/org/jivesoftware/smack/packet/RosterPacket.java @@ -276,6 +276,10 @@ public class RosterPacket extends IQ { public static final ItemStatus UNSUBCRIPTION_PENDING = new ItemStatus("unsubscribe"); public static ItemStatus fromString(String value) { + if (value == null) { + return null; + } + value = value.toLowerCase(); if ("unsubscribe".equals(value)) { return SUBSCRIPTION_PENDING; } @@ -329,6 +333,10 @@ public class RosterPacket extends IQ { public static final ItemType BOTH = new ItemType("both"); public static ItemType fromString(String value) { + if (value == null) { + return null; + } + value = value.toLowerCase(); if ("none".equals(value)) { return NONE; }