try
{
Logger.getInstance().logDebug("READ PDU: " + pduString, null, getGatewayId());
// this will throw an exception for PDUs
// it can't classify
Pdu pdu = parser.parsePdu(pduString);
// NOTE: maybe a message validity vs the current
// date should be put here.
// if the message is invalid, the message should
// be ignored and but logged
if (pdu instanceof SmsDeliveryPdu)
{
Logger.getInstance().logDebug(pdu.toString(), null, getGatewayId());
InboundMessage msg;
String memLocation = getATHandler().getStorageLocations().substring((ml * 2), (ml * 2) + 2);
if (pdu.isBinary())
{
msg = new InboundBinaryMessage((SmsDeliveryPdu) pdu, memIndex, memLocation);
if (Service.getInstance().getKeyManager().getKey(msg.getOriginator()) != null) msg = new InboundEncryptedMessage((SmsDeliveryPdu) pdu, memIndex, memLocation);
}
else
{
msg = new InboundMessage((SmsDeliveryPdu) pdu, memIndex, memLocation);
}
msg.setGatewayId(getGatewayId());
Logger.getInstance().logDebug("IN-DTLS: MI:" + msg.getMemIndex() + " REF:" + msg.getMpRefNo() + " MAX:" + msg.getMpMaxNo() + " SEQ:" + msg.getMpSeqNo(), null, getGatewayId());
if (msg.getMpRefNo() == 0)
{
// single message
msgList.add(msg);
incInboundMessageCount();
}
else
{
// multi-part message
int k, l;
List<InboundMessage> tmpList;
InboundMessage listMsg;
boolean found, duplicate;
found = false;
for (k = 0; k < this.mpMsgList.size(); k++)
{
// List of List<InboundMessage>
tmpList = this.mpMsgList.get(k);
listMsg = tmpList.get(0);
// check if current message list is for this message
if (listMsg.getMpRefNo() == msg.getMpRefNo())
{
duplicate = false;
// check if the message is already in the message list
for (l = 0; l < tmpList.size(); l++)
{
listMsg = tmpList.get(l);
if (listMsg.getMpSeqNo() == msg.getMpSeqNo())
{
duplicate = true;
break;
}
}
if (!duplicate) tmpList.add(msg);
found = true;
break;
}
}
if (!found)
{
// no existing list present for this message
// add one
tmpList = new ArrayList<InboundMessage>();
tmpList.add(msg);
this.mpMsgList.add(tmpList);
}
}
}
else if (pdu instanceof SmsStatusReportPdu)
{
StatusReportMessage msg;
msg = new StatusReportMessage((SmsStatusReportPdu) pdu, memIndex, getATHandler().getStorageLocations().substring((ml * 2), (ml * 2) + 2));
msg.setGatewayId(getGatewayId());
msgList.add(msg);
incInboundMessageCount();
}
else
{
// this theoretically will never happen, but it occasionally does with phones
// like some Sony Ericssons (e.g. Z610i, SENT messages are included in this list)
// instead of throwing a RuntimeException, just ignore any messages that are not of type
// SmsDeliveryPdu
// SmsStatusReportPdu
if (this.displayIllegalReceivedMessages)
{
Logger.getInstance().logError("Wrong type of PDU detected: " + pdu.getClass().getName(), null, getGatewayId());
Logger.getInstance().logError("ERROR PDU: " + pduString, null, getGatewayId());
}
}
}
catch (Exception e)