HashMap<String, Object> rawPacket = MSIMParser.parse(buffer.toString());
if (rawPacket.containsKey("bm")) {
PacketType type = PacketType.eval((String) rawPacket.get("bm"));
if (type.equals(PacketType.INSTANT_MESSAGE)) {
InstantMessage message = new InstantMessage();
message.setFrom((String) rawPacket.get("f"));
message.setBody((String) rawPacket.get("msg"));
invokeMessageListener(message);
}
else if (type.equals(PacketType.STATUS_MESSAGE)) {
String statusPcs[] = rawPacket.get("msg").toString().split("\\|");
int statusType = Integer.valueOf(statusPcs[2]);
String statusMsg = statusPcs[4];
StatusMessage message = new StatusMessage();
message.setFrom((String) rawPacket.get("f"));
message.setStatusMessage(statusMsg);
message.setStatusCode(statusType);
invokeMessageListener(message);
}
else if (type.equals(PacketType.ACTION_MESSAGE)) {
ActionMessage message = new ActionMessage();
message.setFrom((String) rawPacket.get("f"));
message.setAction((String) rawPacket.get("msg"));
invokeMessageListener(message);
}
else {
Log.debug("Unsupported buddy message type: " + type);
}
}
else if (rawPacket.containsKey("ka")) {
// Keepalive status packet.
Log.debug("Received keepalive packet.");
}
else if (rawPacket.containsKey("persistr")) {
// Persistent roster packet.
contactManager.parseContactListPacket(rawPacket);
}
else if (rawPacket.containsKey("error")) {
// Error message
ErrorMessage message = new ErrorMessage();
message.setErrorMessage((String) rawPacket.get("errmsg"));
message.setIsFatal(rawPacket.containsKey("fatal"));
invokeMessageListener(message);
}
else {
Log.debug("Unsupported packet type: " + rawPacket);
}