Added support for sending long messages via splitted short_message parameter
This commit is contained in:
+19
-16
@@ -73,6 +73,7 @@ function writeBuffer(obj, cmdLength, callback) {
|
||||
buff,
|
||||
param,
|
||||
paramType,
|
||||
paramSize,
|
||||
tlvId,
|
||||
tlvName,
|
||||
tlvValue,
|
||||
@@ -112,14 +113,19 @@ function writeBuffer(obj, cmdLength, callback) {
|
||||
// Cycle through the defs list to make sure the params are in the right order
|
||||
for (param in defs.cmds[obj.cmdName].params) {
|
||||
paramType = defs.cmds[obj.cmdName].params[param].type;
|
||||
paramSize = paramType.size(obj.params[param]);
|
||||
|
||||
// Write parameter value to buffer using the types method write()
|
||||
paramType.write(obj.params[param], buff, offset);
|
||||
|
||||
log.silly('larvitsmpp: lib/utils.js: writeBuffer() - Writing param "' + param + '" with content "' + obj.params[param] + '"');
|
||||
if (Buffer.isBuffer(obj.params[param])) {
|
||||
log.silly('larvitsmpp: lib/utils.js: writeBuffer() - Writing param "' + param + '" with content "' + obj.params[param].toString('hex') + '" and size "' + paramSize + '"');
|
||||
} else {
|
||||
log.silly('larvitsmpp: lib/utils.js: writeBuffer() - Writing param "' + param + '" with content "' + obj.params[param] + '"');
|
||||
}
|
||||
|
||||
// Increase the offset for the next param
|
||||
offset += paramType.size(obj.params[param]);
|
||||
offset += paramSize;
|
||||
}
|
||||
|
||||
// Cycle through the tlvs
|
||||
@@ -143,6 +149,8 @@ function writeBuffer(obj, cmdLength, callback) {
|
||||
offset += tlvDef.type.size(tlvValue) + 4;
|
||||
}
|
||||
|
||||
log.silly('larvitsmpp: lib/utils.js: writeBuffer() - Complete PDU: "' + buff.toString('hex') + '"');
|
||||
|
||||
callback(null, buff);
|
||||
}
|
||||
|
||||
@@ -255,7 +263,6 @@ function pduToObj(pdu, stupidNullByte, callback) {
|
||||
if (param === 'short_message') {
|
||||
// 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) {
|
||||
log.silly('larvitsmpp: lib/utils.js: pduToObj() - stupidNullByte is set, so short_message is followed by a NULL octet, increase paramSize one extra to account for that');
|
||||
paramSize ++;
|
||||
@@ -326,8 +333,10 @@ function pduToObj(pdu, stupidNullByte, callback) {
|
||||
log.warn('larvitsmpp: lib/utils.js: pduToObj() - Offset (' + offset + ') !== cmdLength (' + retObj.cmdLength + ') for seqNr: ' + retObj.seqNr);
|
||||
}
|
||||
|
||||
// Decode the short message if it is set
|
||||
if (retObj.params.short_message !== undefined) {
|
||||
// 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) {
|
||||
retObj.params.short_message = decodeMsg(retObj.params.short_message, retObj.params.data_coding);
|
||||
}
|
||||
|
||||
@@ -395,6 +404,7 @@ function objToPdu(obj, callback) {
|
||||
// Acutally encode the string
|
||||
shortMsg = obj.params.short_message;
|
||||
obj.params.short_message = encodeMsg(obj.params.short_message);
|
||||
|
||||
obj.params.sm_length = obj.params.short_message.length;
|
||||
log.silly('larvitsmpp: lib/utils.js: objToPdu() - encoding message "' + shortMsg + '" to "' + obj.params.short_message.toString('hex') + '"');
|
||||
}
|
||||
@@ -571,20 +581,13 @@ function bitCount(msg, encoding) {
|
||||
* @return array of buffers
|
||||
*/
|
||||
function splitMsg(msg) {
|
||||
var msgPart = '',
|
||||
msgs = [],
|
||||
msgId = Math.floor(Math.random() * (255 - 0)), // This will identify this message "bundle"
|
||||
encoding,
|
||||
var msgPart = '',
|
||||
msgs = [],
|
||||
msgId = Math.floor(Math.random() * (255 - 0)), // This will identify this message "bundle"
|
||||
encoding = defs.encodings.detect(msg),
|
||||
udh,
|
||||
i;
|
||||
|
||||
// Build a buffer from the correct encoding
|
||||
if (defs.encodings.ASCII.match(msg)) {
|
||||
encoding = 'ASCII';
|
||||
} else {
|
||||
encoding = 'UCS2';
|
||||
}
|
||||
|
||||
// A single message could contain up to 1120 bits
|
||||
// Return directly if the message fits into that
|
||||
if (bitCount(msg) < 1121) {
|
||||
|
||||
Reference in New Issue
Block a user