some fixes related to variable UDH header and Multipart SMS's

reference: https://github.com/larvit/larvitsmpp/issues/1
This commit is contained in:
Qasim Ayyaz Khan
2016-06-02 15:18:58 -04:00
parent 5da55e0f52
commit 7d0da6202c
+30 -8
View File
@@ -363,22 +363,39 @@ function sendLongSms(smsOptions, callback) {
// Store long smses in the temporary storage
function longSms(pduObj) {
var smsGroupId = pduObj.params.short_message[3],
smsParts = pduObj.params.short_message[4],
longSmsId = pduObj.params.source_addr + '_' + pduObj.params.destination_addr + '_' + smsGroupId;
// Fix: UDH values are stored in HEX and decoding them make it garbage. First OCTET contains
// the size of UDH data header. If UDH data header size is 0x05 then field 4 i.e. CSMS
// reference number is of one octet otherwise it consists of 2 octets. Other fields can
// be found from below reference.
// reference: https://en.wikipedia.org/wiki/Concatenated_SMS
var encodedMessage = utils.encodeMsg(pduObj.params.short_message),
udhSize = encodedMessage[0];
var smsGroupId, smsParts, partNr;
if(udhSize === 0x05) {
smsGroupId = encodedMessage[3],
smsParts = encodedMessage[4],
partNr = encodedMessage[5];
} else {
smsGroupId = (encodedMessage[3] * 256) + encodedMessage[4],
smsParts = encodedMessage[5],
partNr = encodedMessage[6];
}
var longSmsId = pduObj.params.source_addr + '_' + pduObj.params.destination_addr + '_' + smsGroupId;
if (this.longSmses[longSmsId] === undefined) {
this.longSmses[longSmsId] = {
'created': new Date(),
'partsCount': parseInt(smsParts),
'udhSize': udhSize, // Saving udh size to remove garbage from message
'pduObjs': [{
'partNr': pduObj.params.short_message[5], // We save this here to easier sort the array later on
'partNr': partNr, // We save this here to easier sort the array later on
'pduObj': pduObj
}]
};
} else {
this.longSmses[longSmsId].pduObjs.push({
'partNr': pduObj.params.short_message[5], // We save this here to easier sort the array later on
'partNr': partNr, // We save this here to easier sort the array later on
'pduObj': pduObj
});
}
@@ -406,6 +423,7 @@ function checkLongSmses() {
var that = this,
smsGroupId,
smsGroup,
udhSize, // UDH Size from longSms() function
smsObj,
i,
curPduObj;
@@ -422,7 +440,7 @@ function checkLongSmses() {
for (smsGroupId in this.longSmses) {
smsGroup = this.longSmses[smsGroupId];
udhSize = smsGroup.udhSize;
// All parts are accounted for! Emit sms event and clear from tmp storage
if (smsGroup.partsCount === smsGroup.pduObjs.length) {
log.debug('larvitsmpp: lib/session.js: checkLongSmses() - All parts accounted for in smsGroupId "' + smsGroupId + '", emitting sms event.');
@@ -451,7 +469,9 @@ function checkLongSmses() {
curPduObj = smsObj.pduObjs[i].pduObj;
curPduObj.session = this;
smsObj.message += utils.decodeMsg(curPduObj.params.short_message, curPduObj.params.data_coding, curPduObj.params.short_message[0] + 1);
// Fix: message in pduObj is already decoded we dont need to do it again. Also removing garbade from original message.
//smsObj.message += utils.decodeMsg(curPduObj.params.short_message, curPduObj.params.data_coding, curPduObj.params.short_message[0] + 1);
smsObj.message += curPduObj.params.short_message.substring(udhSize + 1);
i ++;
}
@@ -557,7 +577,9 @@ function session(sock) {
var smsObj = {};
// If esm_class is 0x40 it means this is just a part of a larger message
if (pduObj.params.esm_class === 0x40) {
//if (pduObj.params.esm_class === 0x40) {
// Fix: esm_class can be combination of bits. We need to extract 0x40 and then compare
if ((pduObj.params.esm_class & 0x40) === 0x40) {
log.debug('larvitsmpp: lib/session.js: session() - returnObj.handleCmd.submit_sm() - long sms detected, esm_class 0x40.');
returnObj.longSms(pduObj);
return; // Long messages should not get handled here at all, so cancel execution here