diff --git a/lib/session.js b/lib/session.js index d77d885..1d04743 100644 --- a/lib/session.js +++ b/lib/session.js @@ -372,21 +372,29 @@ function longSms(pduObj) { // 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 longSmsId = pduObj.params.source_addr + '_' + pduObj.params.destination_addr + '_' + pduObj.params.udhHeader.reference; + var udhHeaderSize = pduObj.params.short_message[0], // First octet is the size of UDH Header + headerSize = pduObj.params.short_message[2], // Header size other than first 2 octets + csmsReference = pduObj.params.short_message.slice(3, 3 + headerSize - 2), // CSMS Reference starts from + // 4th octet and length is + // header size -2 octets + partsCount = pduObj.params.short_message[2 + csmsReference.length + 1], + partNr = pduObj.params.short_message[2 + csmsReference.length + 1]; + + var longSmsId = pduObj.params.source_addr + '_' + pduObj.params.destination_addr + '_' + csmsReference; if (this.longSmses[longSmsId] === undefined) { this.longSmses[longSmsId] = { 'created': new Date(), - 'partsCount': pduObj.params.udhHeader.totalParts, - 'udhSize': pduObj.params.udhHeader.size, // Saving udh size to remove garbage from message + 'partsCount': partsCount, + 'udhSize': udhHeaderSize, // Saving udh size to remove garbage from message 'pduObjs': [{ - 'partNr': pduObj.params.udhHeader.partNr, // 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.udhHeader.partNr, // 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 }); } diff --git a/lib/utils.js b/lib/utils.js index 48e24e8..b9e9b45 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -272,23 +272,6 @@ function pduToObj(pdu, stupidNullByte, callback) { log.silly('larvitsmpp: lib/utils.js: pduToObj() - Reading param "' + param + '" at offset ' + offset + ' with calculated size: ' + paramSize + ' content in hex: ' + pdu.slice(offset, offset + paramSize).toString('hex')); if (param === 'short_message') { - if ((retObj.params.esm_class & 0x40) === 0x40) { - // This is a part of long sms. We should save UDH header information in params. - retObj.params.udhHeader = {}; - retObj.params.udhHeader.size = parseInt('0x' + pdu.slice(offset, offset + paramSize).toString('hex').slice(0, 2)); - - // If hsize is >5 then CSMS Reference consist of two parts - if (retObj.params.udhHeader.size === 5) { - retObj.params.udhHeader.reference = parseInt('0x' + pdu.slice(offset, offset + paramSize).toString('hex').slice(6, 8)); - retObj.params.udhHeader.totalParts = parseInt('0x' + pdu.slice(offset, offset + paramSize).toString('hex').slice(8, 10)); - retObj.params.udhHeader.partNr = parseInt('0x' + pdu.slice(offset, offset + paramSize).toString('hex').slice(10, 12)); - } else { - retObj.params.udhHeader.reference = (parseInt('0x' + pdu.slice(offset, offset + paramSize).toString('hex').slice(6, 8)) * 256) + parseInt('0x' + pdu.slice(offset, offset + paramSize).toString('hex').slice(8, 10)), - retObj.params.udhHeader.totalParts = parseInt('0x' + pdu.slice(offset, offset + paramSize).toString('hex').slice(10, 12)), - retObj.params.udhHeader.partNr = parseInt('0x' + pdu.slice(offset, offset + paramSize).toString('hex').slice(12, 14)); - } - } - // Check if we have a trailing NULL octet after the short_message. Some idiot thought that would be a good idea // in some implementations, so we need to account for that. if (stupidNullByte === true) {