From 0228adb98c28ae77f77a70b6e50c900ee1b3b159 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 16 Jun 2015 20:11:54 +0200 Subject: [PATCH] Moved smsDlr function to utils --- lib/session.js | 85 ++------------------------------------------------ lib/utils.js | 84 ++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- 3 files changed, 86 insertions(+), 85 deletions(-) diff --git a/lib/session.js b/lib/session.js index 134c0c1..dbc644e 100644 --- a/lib/session.js +++ b/lib/session.js @@ -78,87 +78,6 @@ function smsResp(status, callback) { async.parallel(tasks, callback); } -/** - * Send a dlr to an sms - * This must be called from an sms object context - * - * @param str status - see list at defs.consts.MESSAGE_STATE - defaults to 'DELIVERED' - * @param func callback(err, retPdu) - */ -function smsDlr(status, callback) { - var shortMessage, - dlrPduObj, - err, - sms = this; - - if (typeof status === 'function') { - callback = status; - status = undefined; - } - - if (status === undefined || status === true || status === 2 || status === 'true') { - status = 2; - } else if (defs.consts.MESSAGE_STATE[status] !== undefined) { - status = defs.consts.MESSAGE_STATE[status]; - } else if (defs.constsById.MESSAGE_STATE[status]) { - status = parseInt(status); - } else { - status = 5; // UNDELIVERABLE - } - - if (typeof callback !== 'function') { - callback = function() {}; - } - - if (sms.smsId === undefined) { - err = new Error('Trying to send DLR with no smsId.'); - log.warn('larvitsmpp: lib/session.js: smsDlr() - ' + err.message); - callback(err); - return; - } - - shortMessage = 'id:' + sms.smsId + ' sub:001 '; - - if (status === 2) { - shortMessage += 'dlvrd:1 '; - } else { - shortMessage += 'dlvrd:0 '; - } - - shortMessage += 'submit date:' + utils.smppDate(sms.submitTime); - shortMessage += ' done date:' + utils.smppDate(new Date()); - - if (status === 2) { - shortMessage += ' stat:DELIVRD err:0 text:xxx'; - } else { - shortMessage += ' stat:UNDELIVERABLE err:1 text:xxx'; - } - - dlrPduObj = { - 'cmdName': 'deliver_sm', - 'params': { - 'source_addr': sms.from, - 'destination_addr': sms.to, - 'esm_class': 4, - 'short_message': shortMessage - }, - 'tlvs': { - 'receipted_message_id': { - 'tagId': 0x001E, - 'tagName': 'receipted_message_id', - 'tagValue': sms.smsId - }, - 'message_state': { - 'tagId': 0x0427, - 'tagName': 'message_state', - 'tagValue': status - } - } - }; - - sms.session.send(dlrPduObj, false, callback); -} - function incOurSeqNr() { this.ourSeqNr = this.ourSeqNr + 1; @@ -519,7 +438,7 @@ function checkLongSmses() { 'message': '', 'dlr': Boolean(smsGroup.pduObjs[0].pduObj.params.registered_delivery), 'sendResp': smsResp, - 'sendDlr': smsDlr + 'sendDlr': utils.smsDlr }; // Concatenate all the parts messages to one and set references to the session @@ -654,7 +573,7 @@ function session(sock) { 'message': pduObj.params.short_message, 'dlr': Boolean(pduObj.params.registered_delivery), 'sendResp': smsResp, - 'sendDlr': smsDlr + 'sendDlr': utils.smsDlr }; if (pduObj.params.data_coding === 0x10) { diff --git a/lib/utils.js b/lib/utils.js index 583eeb0..c46f1ea 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -687,6 +687,87 @@ function splitMsg(msg) { return msgs; } +/** + * Send a dlr to an sms + * This must be called from an sms object context + * + * @param str status - see list at defs.consts.MESSAGE_STATE - defaults to 'DELIVERED' + * @param func callback(err, retPdu) + */ +function smsDlr(status, callback) { + var shortMessage, + dlrPduObj, + err, + sms = this; + + if (typeof status === 'function') { + callback = status; + status = undefined; + } + + if (status === undefined || status === true || status === 2 || status === 'true') { + status = 2; + } else if (defs.consts.MESSAGE_STATE[status] !== undefined) { + status = defs.consts.MESSAGE_STATE[status]; + } else if (defs.constsById.MESSAGE_STATE[status]) { + status = parseInt(status); + } else { + status = 5; // UNDELIVERABLE + } + + if (typeof callback !== 'function') { + callback = function() {}; + } + + if (sms.smsId === undefined) { + err = new Error('Trying to send DLR with no smsId.'); + log.warn('larvitsmpp: lib/session.js: smsDlr() - ' + err.message); + callback(err); + return; + } + + shortMessage = 'id:' + sms.smsId + ' sub:001 '; + + if (status === 2) { + shortMessage += 'dlvrd:1 '; + } else { + shortMessage += 'dlvrd:0 '; + } + + shortMessage += 'submit date:' + smppDate(sms.submitTime); + shortMessage += ' done date:' + smppDate(new Date()); + + if (status === 2) { + shortMessage += ' stat:DELIVRD err:0 text:xxx'; + } else { + shortMessage += ' stat:UNDELIVERABLE err:1 text:xxx'; + } + + dlrPduObj = { + 'cmdName': 'deliver_sm', + 'params': { + 'source_addr': sms.from, + 'destination_addr': sms.to, + 'esm_class': 4, + 'short_message': shortMessage + }, + 'tlvs': { + 'receipted_message_id': { + 'tagId': 0x001E, + 'tagName': 'receipted_message_id', + 'tagValue': sms.smsId + }, + 'message_state': { + 'tagId': 0x0427, + 'tagName': 'message_state', + 'tagValue': status + } + } + }; + + sms.session.send(dlrPduObj, false, callback); +} + // Expose some functions exports.decodeMsg = decodeMsg; exports.encodeMsg = encodeMsg; @@ -695,4 +776,5 @@ exports.objToPdu = objToPdu; exports.pduReturn = pduReturn; exports.smppDate = smppDate; exports.bitCount = bitCount; -exports.splitMsg = splitMsg; \ No newline at end of file +exports.splitMsg = splitMsg; +exports.smsDlr = smsDlr; \ No newline at end of file diff --git a/package.json b/package.json index 9021d02..aa5953e 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "url": "https://github.com/larvit/larvitsmpp", "type": "git" }, - "version": "0.1.4", + "version": "0.1.5", "readmeFilename": "README.md", "readme": "larvitsmpp", "bugs": {