From db766927f3298eab0f534c65f3ddea7be53a7708 Mon Sep 17 00:00:00 2001 From: lilleman Date: Wed, 3 Jun 2015 16:52:15 +0200 Subject: [PATCH] Fixed msg decoding issue and cleaning up in long messages queue --- lib/session.js | 10 +++++----- lib/utils.js | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/session.js b/lib/session.js index d6de946..c9a4c26 100644 --- a/lib/session.js +++ b/lib/session.js @@ -504,8 +504,10 @@ function session(sock) { return 0; } - // Callback function for emitted sms event + // Call when complete SMS is received function smsReceived() { + returnObj.emit('sms', smsObj); + // This needs to be ran if DLRs are sent for these messages delete returnObj.longSmses[smsGroupId]; } @@ -518,7 +520,6 @@ function session(sock) { log.debug('larvitsmpp: lib/session.js: session() - returnObj.checkLongSmses() - All parts accounted for in smsGroupId "' + smsGroupId + '", emitting sms event.'); smsObj = { - // These are needed for references here and there in functions 'session': returnObj, 'pduObjs': smsGroup.pduObjs, @@ -541,12 +542,11 @@ function session(sock) { curPduObj = smsObj.pduObjs[i].pduObj; curPduObj.session = returnObj; - smsObj.message += utils.decodeMsg(curPduObj.params.short_message, curPduObj.params.data_coding, curPduObj.params.short_message[0]); + smsObj.message += utils.decodeMsg(curPduObj.params.short_message, curPduObj.params.data_coding, curPduObj.params.short_message[0] + 1); i ++; } - - returnObj.emit('sms', smsObj); + smsReceived(); } else if (moment(new Date()).diff(smsGroup.created, 'hours') > 24) { log.info('larvitsmpp: lib/session.js: session() - returnObj.checkLongSmses() - smsGroupId "' + smsGroupId + '" is removed from returnObj.longSmses due to being older than 24 hours.'); diff --git a/lib/utils.js b/lib/utils.js index 25c6255..f0bfa01 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -180,7 +180,9 @@ function decodeMsg(buffer, encoding, offset) { encoding = 'ASCII'; } - return defs.encodings[encoding].decode(buffer.slice(offset, buffer.length)); + log.debug('larvitsmpp: lib/utils.js: decodeMsg() - Decoding msg. Encoding: "' + encoding + '" offset: "' + offset + '" buffer: "' + buffer.toString('hex') + '"'); + + return defs.encodings[encoding].decode(buffer.slice(offset)); } function encodeMsg(str) {