Modifications to Qasims pull request to fix support for UDH header sizes above 1

This commit is contained in:
2016-06-07 12:48:50 +02:00
parent 14f6fa4e5c
commit fc629ddfdb
2 changed files with 22 additions and 33 deletions
+15 -19
View File
@@ -272,27 +272,23 @@ 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.
var hsize = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(0, 2));
//If hsize is >5 then CSMS Reference consist of two parts
if(hsize == 5) {
var reference = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(6, 8)),
totalParts = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(8, 10)),
partNr = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(10, 12));
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 {
var 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)),
totalParts = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(10, 12)),
partNr = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(12, 14));
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));
}
var udhHeader = {
'size': hsize,
'reference': reference,
'totalParts': totalParts,
'partNr': partNr
}
retObj.params['udhHeader'] = udhHeader;
}
// 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) {
@@ -368,7 +364,7 @@ function pduToObj(pdu, stupidNullByte, callback) {
// Decode the short message if it is set and esm_class is 0
// The esm_class 0x40 (64 int) means the short_message have a UDH
// Thats why we return the short_message as a buffer
if (retObj.params.short_message !== undefined && retObj.params.esm_class !== 0x40) {
if (retObj.params.short_message !== undefined && (retObj.params.esm_class & 0x40) !== 0x40) {
retObj.params.short_message = decodeMsg(retObj.params.short_message, retObj.params.data_coding);
}