String username = iq.getTo().toBareJID().split("@")[0];
if (username != null) {
CallLog callLog = new CallLog(username);
Element pe = iq.getChildElement().element("callLog");
if (pe != null) {
Element numA = pe.element("numA");
Element numB = pe.element("numB");
Element duration = pe.element("duration");
Element type = pe.element("type");
callLog.setNumA((numA != null) ? numA.getTextTrim() : "");
callLog.setNumB((numB != null) ? numB.getTextTrim() : "");
callLog.setDateTime(new Date().getTime());
callLog.setDuration((duration != null) ? Integer.parseInt(duration.getText()) : 0);
if (type != null && "loss".equals(type.getTextTrim())) {
// Backwards compatibility change
type.setText("missed");
}
callLog.setType((type != null) ? CallLog.Type.valueOf(type.getTextTrim()) : CallLog.Type.dialed);
try {
CallLogDAO.insert(callLog);
} catch (SQLException e) {
Log.error(e.getMessage(), e);