var to let or const, better lints, code style and more
This commit is contained in:
@@ -1,28 +1,36 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true,
|
||||
"mocha": true
|
||||
"es6": true,
|
||||
"mocha": true,
|
||||
"node": true
|
||||
},
|
||||
"rules": {
|
||||
"strict": [2, "global"],
|
||||
"camelcase": [0],
|
||||
"comma-spacing": [2, {"before": false, "after": true}],
|
||||
"eol-last": [0],
|
||||
"indent": ["error", "tab"],
|
||||
"key-spacing": [0],
|
||||
"no-mixed-requires": [0],
|
||||
"no-multi-spaces": [0],
|
||||
"space-infix-ops": [2],
|
||||
"quotes": [2, "single"],
|
||||
"vars-on-top": [2],
|
||||
"one-var": [2],
|
||||
"no-shadow": [0],
|
||||
"eol-last": [0],
|
||||
"key-spacing": [0],
|
||||
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
|
||||
"space-unary-ops": [1, { "words": true, "nonwords": true }],
|
||||
"no-underscore-dangle": [0],
|
||||
"camelcase": [0],
|
||||
"no-process-exit": [0],
|
||||
"no-use-before-define": [0],
|
||||
"no-shadow": [0],
|
||||
"no-underscore-dangle": [0],
|
||||
"no-unused-expressions": [2],
|
||||
"semi": [2, "always"],
|
||||
"no-unused-vars": [2],
|
||||
"comma-spacing": [2, {"before": false, "after": true}]
|
||||
"no-use-before-define": [0],
|
||||
"no-var": ["error"],
|
||||
"one-var": [2],
|
||||
"quotes": [2, "single"],
|
||||
"semi": [2, "always"],
|
||||
"space-infix-ops": [2],
|
||||
"space-unary-ops": [1, { "words": true, "nonwords": true }],
|
||||
"strict": [2, "global"],
|
||||
"vars-on-top": [2],
|
||||
"space-before-function-paren": ["error", {
|
||||
"anonymous": "always",
|
||||
"named": "never",
|
||||
"asyncArrow": "ignore"
|
||||
}],
|
||||
"keyword-spacing": ["error"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
exports.server = require(__dirname + '/lib/server');
|
||||
exports.client = require(__dirname + '/lib/client');
|
||||
exports.utils = require(__dirname + '/lib/utils');
|
||||
exports.defs = require(__dirname + '/lib/defs');
|
||||
@@ -1,6 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
exports.server = require(__dirname + '/lib/server');
|
||||
exports.client = require(__dirname + '/lib/client');
|
||||
exports.utils = require(__dirname + '/lib/utils');
|
||||
exports.defs = require(__dirname + '/lib/defs');
|
||||
+43
-39
@@ -1,55 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
var log = require('winston'),
|
||||
const topLogPrefix = 'larvitsmpp: lib/client.js: ',
|
||||
session = require(__dirname + '/session'),
|
||||
merge = require('utils-merge'),
|
||||
log = require('winston'),
|
||||
net = require('net'),
|
||||
tls = require('tls'),
|
||||
session = require('./session');
|
||||
tls = require('tls');
|
||||
|
||||
function login() {
|
||||
var that = this,
|
||||
loginPdu;
|
||||
const logPrefix = topLogPrefix + 'login() - ',
|
||||
that = this;
|
||||
|
||||
let loginPdu;
|
||||
|
||||
loginPdu = {
|
||||
'cmdName': 'bind_transceiver',
|
||||
'seqNr': this.ourSeqNr,
|
||||
'seqNr': that.ourSeqNr,
|
||||
'params': {
|
||||
'system_id': this.options.username,
|
||||
'password': this.options.password
|
||||
'system_id': that.options.username,
|
||||
'password': that.options.password
|
||||
}
|
||||
};
|
||||
|
||||
this.send(loginPdu, function(err, retPduObj) {
|
||||
if (err) {
|
||||
that.emit('loginFailed');
|
||||
return;
|
||||
}
|
||||
that.send(loginPdu, function (err, retPduObj) {
|
||||
if (err) return that.emit('loginFailed');
|
||||
|
||||
if (retPduObj.cmdStatus === 'ESME_ROK') {
|
||||
log.info('larvitsmpp: lib/client.js: login() - Successful login system_id: "' + loginPdu.params.system_id + '"');
|
||||
log.info(logPrefix + 'Successful login system_id: "' + loginPdu.params.system_id + '"');
|
||||
that.loggedIn = true;
|
||||
that.emit('loggedIn');
|
||||
} else {
|
||||
log.info('larvitsmpp: lib/client.js: login() - Login failed system_id: "' + loginPdu.params.system_id + '". Status msg: ' + retPduObj.cmdStatus);
|
||||
log.info(logPrefix + 'Login failed system_id: "' + loginPdu.params.system_id + '". Status msg: ' + retPduObj.cmdStatus);
|
||||
that.emit('loginFailed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function resetEnqLinkTimer() {
|
||||
var that = this;
|
||||
const logPrefix = topLogPrefix + 'resetEnqLinkTimer() - ',
|
||||
that = this;
|
||||
|
||||
log.silly('larvitsmpp: lib/client.js: resetEnqLinkTimer() - Resetting the kill timer');
|
||||
if (this.enqLinkTimer) {
|
||||
clearTimeout(this.enqLinkTimer);
|
||||
log.silly(logPrefix + 'Resetting the kill timer');
|
||||
if (that.enqLinkTimer) {
|
||||
clearTimeout(that.enqLinkTimer);
|
||||
}
|
||||
|
||||
this.enqLinkTimer = setTimeout(function() {
|
||||
that.enqLinkTimer = setTimeout(function () {
|
||||
that.send({
|
||||
cmdName: 'enquire_link',
|
||||
seqNr: that.ourSeqNr
|
||||
});
|
||||
}, this.options.enqLinkTiming);
|
||||
}, that.options.enqLinkTiming);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +61,8 @@ function resetEnqLinkTimer() {
|
||||
* @return {object} (returnObj)
|
||||
*/
|
||||
function clientSession(sock, options) {
|
||||
var returnObj = session(sock);
|
||||
const returnObj = session(sock),
|
||||
logPrefix = topLogPrefix + 'clientSession() - ';
|
||||
|
||||
returnObj.options = options;
|
||||
returnObj.login = login;
|
||||
@@ -70,16 +72,16 @@ function clientSession(sock, options) {
|
||||
returnObj.resetEnqLinkTimer();
|
||||
|
||||
// Handle incoming Pdu Objects
|
||||
returnObj.on('incomingPduObj', function(pduObj) {
|
||||
returnObj.on('incomingPduObj', function (pduObj) {
|
||||
// Call the appropriate handleCmd function
|
||||
|
||||
if (typeof returnObj.handleCmd[pduObj.cmdName] === 'function') {
|
||||
log.debug('larvitsmpp: lib/client.js: clientSession() - returnObj.on(incomingPduObj) - Running cmd handling function returnObj.handleCmd.' + pduObj.cmdName + '()');
|
||||
log.debug(logPrefix + 'returnObj.on(incomingPduObj) - Running cmd handling function returnObj.handleCmd.' + pduObj.cmdName + '()');
|
||||
|
||||
returnObj.handleCmd[pduObj.cmdName](pduObj);
|
||||
} else {
|
||||
// No command handling function is registered, return error "invalid command"
|
||||
log.info('larvitsmpp: lib/client.js: clientSession() - returnObj.on(incomingPduObj) - No handling function found for command: "' + pduObj.cmdName + '"');
|
||||
log.info(logPrefix + 'returnObj.on(incomingPduObj) - No handling function found for command: "' + pduObj.cmdName + '"');
|
||||
|
||||
returnObj.sendReturn(pduObj, 'ESME_RINVCMDID');
|
||||
}
|
||||
@@ -92,13 +94,15 @@ function clientSession(sock, options) {
|
||||
* Setup a client.
|
||||
*
|
||||
* @param {object} options - host, port, username, password, tls, enqLinkTiming
|
||||
* @param {function} callback(err, session)
|
||||
* @param {function} cb(err, session)
|
||||
*/
|
||||
function client(options, callback) {
|
||||
var sock;
|
||||
function client(options, cb) {
|
||||
const logPrefix = topLogPrefix + 'client() - ';
|
||||
|
||||
let sock;
|
||||
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
cb = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
@@ -118,20 +122,20 @@ function client(options, callback) {
|
||||
sock = new net.Socket();
|
||||
}
|
||||
|
||||
log.debug('larvitsmpp: lib/client.js: client() - Connecting to ' + options.host + ':' + options.port);
|
||||
sock.connect(options, function() {
|
||||
var session = clientSession(sock, options);
|
||||
log.debug(logPrefix + 'Connecting to ' + options.host + ':' + options.port);
|
||||
sock.connect(options, function () {
|
||||
const session = clientSession(sock, options);
|
||||
|
||||
log.info('larvitsmpp: lib/client.js: client() - Connected to ' + sock.remoteAddress + ':' + sock.remotePort);
|
||||
log.info(logPrefix + 'Connected to ' + sock.remoteAddress + ':' + sock.remotePort);
|
||||
|
||||
session.on('loggedIn', function() {
|
||||
callback(null, session);
|
||||
session.on('loggedIn', function () {
|
||||
cb(null, session);
|
||||
});
|
||||
|
||||
session.on('loginFailed', function() {
|
||||
var err = new Error('Remote host refused login.');
|
||||
log.warn('larvitsmpp: lib/client.js: client() - ' + err.message);
|
||||
callback(err);
|
||||
session.on('loginFailed', function () {
|
||||
const err = new Error('Remote host refused login.');
|
||||
log.warn(logPrefix + err.message);
|
||||
cb(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
+923
-934
File diff suppressed because it is too large
Load Diff
+46
-49
@@ -1,11 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var log = require('winston'),
|
||||
const topLogPrefix = 'larvitsmpp: lib/server.js: ',
|
||||
smppUtils = require(__dirname + '/utils'),
|
||||
session = require(__dirname + '/session'),
|
||||
merge = require('utils-merge'),
|
||||
log = require('winston'),
|
||||
net = require('net'),
|
||||
tls = require('tls'),
|
||||
session = require('./session'),
|
||||
smppUtils = require('./utils');
|
||||
tls = require('tls');
|
||||
|
||||
/**
|
||||
* Try to log a connecting peer in
|
||||
@@ -13,22 +14,20 @@ var log = require('winston'),
|
||||
* @param {object} pduObj
|
||||
*/
|
||||
function login(pduObj) {
|
||||
var that = this;
|
||||
const logPrefix = topLogPrefix + 'login() - ',
|
||||
that = this;
|
||||
|
||||
log.debug('larvitsmpp: lib/server.js: login() - Data received and session is not loggedIn');
|
||||
log.debug(logPrefix + 'Data received and session is not loggedIn');
|
||||
|
||||
// Pause socket so we do not receive any other commands until we have processed the login
|
||||
this.sock.pause();
|
||||
that.sock.pause();
|
||||
|
||||
// Only bind_* is accepted when the client is not logged in
|
||||
if (pduObj.cmdName !== 'bind_transceiver' && pduObj.cmdName !== 'bind_receiver' && pduObj.cmdName !== 'bind_transmitter') {
|
||||
log.debug('larvitsmpp: lib/server.js: login() - Session is not loggedIn and no bind_* command is given. Return error "ESME_RINVBNDSTS');
|
||||
log.debug(logPrefix + 'Session is not loggedIn and no bind_* command is given. Return error "ESME_RINVBNDSTS');
|
||||
|
||||
smppUtils.pduReturn(pduObj, 'ESME_RINVBNDSTS', function(err, retPdu) {
|
||||
if (err) {
|
||||
that.closeSocket();
|
||||
return;
|
||||
}
|
||||
smppUtils.pduReturn(pduObj, 'ESME_RINVBNDSTS', function (err, retPdu) {
|
||||
if (err) return that.closeSocket();
|
||||
|
||||
that.sock.resume();
|
||||
that.sockWrite(retPdu);
|
||||
@@ -38,22 +37,18 @@ function login(pduObj) {
|
||||
}
|
||||
|
||||
// If there is a checkuserpass(), use it to check system_id and password from the PDU
|
||||
if (typeof this.options.checkuserpass === 'function') {
|
||||
this.options.checkuserpass(pduObj.params.system_id, pduObj.params.password, function(err, res, userData) {
|
||||
if (err) {
|
||||
that.closeSocket();
|
||||
return;
|
||||
}
|
||||
if (typeof that.options.checkuserpass === 'function') {
|
||||
return that.options.checkuserpass(pduObj.params.system_id, pduObj.params.password, function (err, res, userData) {
|
||||
if (err) return that.closeSocket();
|
||||
|
||||
if ( ! res) {
|
||||
log.info('larvitsmpp: lib/server.js: serverSession() - login() - Login failed! Connected host: ' + that.sock.remoteAddress + ':' + that.sock.remotePort + ' system_id: "' + pduObj.params.system_id + '"');
|
||||
log.info(logPrefix + 'Login failed! Connected host: ' + that.sock.remoteAddress + ':' + that.sock.remotePort + ' system_id: "' + pduObj.params.system_id + '"');
|
||||
|
||||
that.sock.resume();
|
||||
that.sendReturn(pduObj, 'ESME_RBINDFAIL');
|
||||
return;
|
||||
return that.sendReturn(pduObj, 'ESME_RBINDFAIL');
|
||||
}
|
||||
|
||||
log.verbose('larvitsmpp: lib/server.js: serverSession() - login() - Login successful! Connected host: ' + that.sock.remoteAddress + ':' + that.sock.remotePort + ' system_id: "' + pduObj.params.system_id + '"');
|
||||
log.verbose(logPrefix + 'Login successful! Connected host: ' + that.sock.remoteAddress + ':' + that.sock.remotePort + ' system_id: "' + pduObj.params.system_id + '"');
|
||||
that.loggedIn = true;
|
||||
|
||||
// Set additional user data to the session
|
||||
@@ -65,15 +60,13 @@ function login(pduObj) {
|
||||
that.emit('login');
|
||||
that.sendReturn(pduObj);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If we arrived here it means we are not logged in and that a bind_* event happened and no checkuserpass() method exists. Lets login!
|
||||
this.loggedIn = true;
|
||||
this.sock.resume();
|
||||
this.emit('login');
|
||||
this.sendReturn(pduObj);
|
||||
that.loggedIn = true;
|
||||
that.sock.resume();
|
||||
that.emit('login');
|
||||
that.sendReturn(pduObj);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,15 +74,16 @@ function login(pduObj) {
|
||||
* If this is not ran within options.timeout milliseconds, this session will self terminate
|
||||
*/
|
||||
function resetEnqLinkTimer() {
|
||||
var that = this;
|
||||
const logPrefix = topLogPrefix + 'resetEnqLinkTimer() - ',
|
||||
that = this;
|
||||
|
||||
log.silly('larvitsmpp: lib/server.js: resetEnqLinkTimer() - Resetting the kill timer');
|
||||
log.silly(logPrefix + 'Resetting the kill timer');
|
||||
if (that.enqLinkTimer) {
|
||||
clearTimeout(that.enqLinkTimer);
|
||||
}
|
||||
|
||||
that.enqLinkTimer = setTimeout(function() {
|
||||
log.info('larvitsmpp: lib/server.js: resetEnqLinkTimer() - Closing session from ' + that.sock.remoteAddress + ':' + that.sock.remotePort + ' due to timeout');
|
||||
that.enqLinkTimer = setTimeout(function () {
|
||||
log.info(logPrefix + 'Closing session from ' + that.sock.remoteAddress + ':' + that.sock.remotePort + ' due to timeout');
|
||||
that.closeSocket();
|
||||
}, that.options.timeout);
|
||||
}
|
||||
@@ -102,7 +96,7 @@ function resetEnqLinkTimer() {
|
||||
* @return {object} (returnObj)
|
||||
*/
|
||||
function serverSession(sock, options) {
|
||||
var returnObj = session(sock);
|
||||
const returnObj = session(sock);
|
||||
|
||||
returnObj.options = options;
|
||||
returnObj.login = login;
|
||||
@@ -111,7 +105,8 @@ function serverSession(sock, options) {
|
||||
returnObj.resetEnqLinkTimer();
|
||||
|
||||
// Handle incoming Pdu Objects
|
||||
returnObj.on('incomingPduObj', function(pduObj) {
|
||||
returnObj.on('incomingPduObj', function (pduObj) {
|
||||
const logPrefix = topLogPrefix + 'serverSession() - returnObj.handleIncomingPdu() - ';
|
||||
// Call the appropriate handleCmd function
|
||||
|
||||
// Unbind is always ok
|
||||
@@ -120,18 +115,18 @@ function serverSession(sock, options) {
|
||||
|
||||
// If client is not logged in, always run the login function
|
||||
} else if (returnObj.loggedIn === false) {
|
||||
log.debug('larvitsmpp: lib/server.js: serverSession() - returnObj.handleIncomingPdu() - Not logged in, running login function');
|
||||
log.debug(logPrefix + ' Not logged in, running login function');
|
||||
returnObj.login(pduObj);
|
||||
|
||||
// Client is logged in, try to match a handling function
|
||||
} else if (typeof returnObj.handleCmd[pduObj.cmdName] === 'function') {
|
||||
log.debug('larvitsmpp: lib/server.js: serverSession() - returnObj.on(incomingPduObj) - Running cmd handling function returnObj.handleCmd.' + pduObj.cmdName + '()');
|
||||
log.debug(logPrefix + 'Running cmd handling function returnObj.handleCmd.' + pduObj.cmdName + '()');
|
||||
|
||||
returnObj.handleCmd[pduObj.cmdName](pduObj);
|
||||
|
||||
// No command handling function is registered, return error "invalid command"
|
||||
} else {
|
||||
log.info('larvitsmpp: lib/server.js: serverSession() - returnObj.on(incomingPduObj) - No handling function found for command: "' + pduObj.cmdName + '"');
|
||||
log.info(logPrefix + 'No handling function found for command: "' + pduObj.cmdName + '"');
|
||||
|
||||
returnObj.sendReturn(pduObj, 'ESME_RINVCMDID');
|
||||
}
|
||||
@@ -144,13 +139,15 @@ function serverSession(sock, options) {
|
||||
* Setup a server
|
||||
*
|
||||
* @param {object} options - host, port, checkuserpass() etc (OPTIONAL)
|
||||
* @param {function} callback(err, session)
|
||||
* @param {function} cb(err, session)
|
||||
*/
|
||||
function server(options, callback) {
|
||||
var tlsOrNet;
|
||||
function server(options, cb) {
|
||||
const logPrefix = topLogPrefix + 'server() - ';
|
||||
|
||||
let tlsOrNet;
|
||||
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
cb = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
@@ -169,20 +166,20 @@ function server(options, callback) {
|
||||
|
||||
// Create a server instance, and chain the listen function to it
|
||||
// The function passed to net.createServer() becomes the event handler for the 'connection' event
|
||||
// The sock object the callback function receives UNIQUE for each connection
|
||||
tlsOrNet.createServer(options, function(sock) {
|
||||
var returnObj = serverSession(sock, options);
|
||||
// The sock object the cb function receives UNIQUE for each connection
|
||||
tlsOrNet.createServer(options, function (sock) {
|
||||
const returnObj = serverSession(sock, options);
|
||||
|
||||
// We have a connection - a socket object is assigned to the connection automatically
|
||||
log.verbose('larvitsmpp: lib/server.js: server() - Incoming connection! From: ' + sock.remoteAddress + ':' + sock.remotePort);
|
||||
log.verbose(logPrefix + 'Incoming connection! From: ' + sock.remoteAddress + ':' + sock.remotePort);
|
||||
|
||||
callback(null, returnObj);
|
||||
cb(null, returnObj);
|
||||
}).listen(options.port, options.host);
|
||||
|
||||
if (options.host !== undefined) {
|
||||
log.info('larvitsmpp: lib/server.js: server() - Up and listening at ' + options.host + ':' + options.port);
|
||||
log.info(logPrefix + 'Up and listening at ' + options.host + ':' + options.port);
|
||||
} else {
|
||||
log.info('larvitsmpp: lib/server.js: server() - Up and listening at *:' + options.port);
|
||||
log.info(logPrefix + 'Up and listening at *:' + options.port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+204
-210
@@ -1,33 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
var log = require('winston'),
|
||||
const topLogPrefix = 'larvitsmpp: lib/session.js: ',
|
||||
events = require('events'),
|
||||
moment = require('moment'),
|
||||
utils = require('./utils'),
|
||||
async = require('async'),
|
||||
defs = require('./defs'),
|
||||
async = require('async');
|
||||
log = require('winston');
|
||||
|
||||
/*
|
||||
/**
|
||||
* Send a response to an sms
|
||||
* This must be called from an sms object context
|
||||
*
|
||||
* @param str status - see list at defs.errors - defaults to 'ESME_ROK' - no error (OPTIONAL)
|
||||
* @param func callback(err, [retPdu, ...])
|
||||
* @param {string} status - see list at defs.errors - defaults to 'ESME_ROK' - no error (OPTIONAL)
|
||||
* @param {function} cb - cb(err, [retPdu, ...])
|
||||
*/
|
||||
function smsResp(status, callback) {
|
||||
var sms = this,
|
||||
function smsResp(status, cb) {
|
||||
const logPrefix = topLogPrefix + 'smsResp() - ',
|
||||
tasks = [],
|
||||
params,
|
||||
err,
|
||||
i;
|
||||
sms = this;
|
||||
|
||||
let params;
|
||||
|
||||
if (typeof status === 'function') {
|
||||
callback = status;
|
||||
cb = status;
|
||||
status = true;
|
||||
}
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
callback = function() {};
|
||||
if (typeof cb !== 'function') {
|
||||
cb = function () {};
|
||||
}
|
||||
|
||||
if (sms.smsId === undefined) {
|
||||
@@ -45,15 +46,13 @@ function smsResp(status, callback) {
|
||||
}
|
||||
|
||||
if (sms.pduObjs === undefined) {
|
||||
err = new Error('No pdu objects found to base return PDU upon');
|
||||
log.warn('larvitsmpp: lib/session.js: smsResp() - ' + err.message);
|
||||
callback(err);
|
||||
return;
|
||||
const err = new Error('No pdu objects found to base return PDU upon');
|
||||
log.warn(logPrefix + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// Build async tasks to run the responses in parallel
|
||||
i = 0;
|
||||
while (sms.pduObjs[i] !== undefined) {
|
||||
for (let i = 0; sms.pduObjs[i] !== undefined; i ++) {
|
||||
if (sms.smsId) {
|
||||
if (sms.pduObjs[i].pduObj.params.esm_class === 0x40) {
|
||||
params = {'message_id': sms.smsId + '-' + (i + 1)};
|
||||
@@ -71,11 +70,9 @@ function smsResp(status, callback) {
|
||||
params,
|
||||
false
|
||||
);
|
||||
|
||||
i ++;
|
||||
}
|
||||
|
||||
async.parallel(tasks, callback);
|
||||
async.parallel(tasks, cb);
|
||||
}
|
||||
|
||||
function incOurSeqNr() {
|
||||
@@ -92,9 +89,11 @@ function incOurSeqNr() {
|
||||
* Always use this function to close the socket so we get it on log
|
||||
*/
|
||||
function closeSocket() {
|
||||
log.verbose('larvitsmpp: lib/session.js: closeSocket() - Closing socket for ' + this.sock.remoteAddress + ':' + this.sock.remotePort);
|
||||
const logPrefix = topLogPrefix + 'closeSocket() - ';
|
||||
|
||||
log.verbose(logPrefix + 'Closing socket for ' + this.sock.remoteAddress + ':' + this.sock.remotePort);
|
||||
if (this.enqLinkTimer) {
|
||||
log.debug('larvitsmpp: lib/session.js: closeSocket() - enqLinkTimer found, clearing.');
|
||||
log.debug(logPrefix + 'enqLinkTimer found, clearing.');
|
||||
clearTimeout(this.enqLinkTimer);
|
||||
}
|
||||
this.sock.destroy();
|
||||
@@ -107,14 +106,14 @@ function closeSocket() {
|
||||
* @param {boolean} closeAfterSend - if true will close the socket after sending
|
||||
*/
|
||||
function sockWrite(pdu, closeAfterSend) {
|
||||
var that = this;
|
||||
const logPrefix = topLogPrefix + 'sockWrite() - ',
|
||||
that = this;
|
||||
|
||||
if ( ! Buffer.isBuffer(pdu)) {
|
||||
utils.objToPdu(pdu, function(err, buffer) {
|
||||
utils.objToPdu(pdu, function (err, buffer) {
|
||||
if (err) {
|
||||
log.warn('larvitsmpp: lib/session.js: sockWrite() - Could not convert PDU to buffer');
|
||||
that.closeSocket();
|
||||
return;
|
||||
log.warn(logPrefix + 'Could not convert PDU to buffer');
|
||||
return that.closeSocket();
|
||||
}
|
||||
|
||||
that.sockWrite(buffer);
|
||||
@@ -123,16 +122,16 @@ function sockWrite(pdu, closeAfterSend) {
|
||||
}
|
||||
|
||||
try {
|
||||
log.verbose('larvitsmpp: lib/session.js: sockWrite() - sending PDU. SeqNr: ' + pdu.readUInt32BE(12) + ' cmd: ' + defs.cmdsById[pdu.readUInt32BE(4)].command + ' cmdStatus: ' + defs.errorsById[parseInt(pdu.readUInt32BE(8))] + ' hex: ' + pdu.toString('hex'));
|
||||
} catch (e) {
|
||||
log.error('larvitsmpp: lib/session.js: sockWrite() - PDU buffer is invalid. Buffer hex: "' + pdu.toString('hex') + '"');
|
||||
log.verbose(logPrefix + 'sending PDU. SeqNr: ' + pdu.readUInt32BE(12) + ' cmd: ' + defs.cmdsById[pdu.readUInt32BE(4)].command + ' cmdStatus: ' + defs.errorsById[parseInt(pdu.readUInt32BE(8))] + ' hex: ' + pdu.toString('hex'));
|
||||
} catch (err) {
|
||||
log.error(logPrefix + 'PDU buffer is invalid. Buffer hex: "' + pdu.toString('hex') + '"');
|
||||
return;
|
||||
}
|
||||
|
||||
this.sock.write(pdu);
|
||||
that.sock.write(pdu);
|
||||
|
||||
if (closeAfterSend) {
|
||||
this.closeSocket();
|
||||
that.closeSocket();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,22 +140,19 @@ function sockWrite(pdu, closeAfterSend) {
|
||||
*
|
||||
* @param {buffer|object} pdu
|
||||
* @param {boolean} closeAfterSend - Will close after return is fetched. Defaults to false (OPTIONAL)
|
||||
* @param {function} callback(err, retPdu) (OPTIONAL)
|
||||
* @param {function} cb - cb(err, retPdu) (OPTIONAL)
|
||||
*/
|
||||
function send(pdu, closeAfterSend, callback) {
|
||||
var pduObj = pdu,
|
||||
err = null,
|
||||
function send(pdu, closeAfterSend, cb) {
|
||||
const logPrefix = topLogPrefix + 'send() - ',
|
||||
pduObj = pdu,
|
||||
that = this;
|
||||
|
||||
// Make sure the pdu is an object
|
||||
if (Buffer.isBuffer(pdu)) {
|
||||
utils.pduToObj(pdu, function(err, pduObj) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
utils.pduToObj(pdu, function (err, pduObj) {
|
||||
if (err) return cb(err);
|
||||
|
||||
that.send(pduObj, closeAfterSend, callback);
|
||||
that.send(pduObj, closeAfterSend, cb);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -164,50 +160,49 @@ function send(pdu, closeAfterSend, callback) {
|
||||
// Make sure the sequence number is set and is correct
|
||||
pduObj.seqNr = this.ourSeqNr;
|
||||
|
||||
log.debug('larvitsmpp: lib/session.js: send() - Sending PDU to remote. pduObj: ' + JSON.stringify(pduObj));
|
||||
log.debug(logPrefix + 'Sending PDU to remote. pduObj: ' + JSON.stringify(pduObj));
|
||||
|
||||
// If closeAndSend is omitted, put callback in its place
|
||||
// If closeAndSend is omitted, put cb in its place
|
||||
if (typeof closeAfterSend === 'function') {
|
||||
callback = closeAfterSend;
|
||||
cb = closeAfterSend;
|
||||
closeAfterSend = undefined;
|
||||
}
|
||||
|
||||
// Make sure the callack is a function
|
||||
if (typeof callback !== 'function') {
|
||||
callback = function(){};
|
||||
if (typeof cb !== 'function') {
|
||||
cb = function () {};
|
||||
}
|
||||
|
||||
// Response PDUs are not allowed with the send() command, they should use the sendReturn()
|
||||
if (pduObj.cmdName.substring(pduObj.cmdName - 5) === '_resp') {
|
||||
err = new Error('Given pduObj is a response, use sendReturn() instead. cmdName: ' + pduObj.cmdName);
|
||||
callback(err);
|
||||
return;
|
||||
const err = new Error('Given pduObj is a response, use sendReturn() instead. cmdName: ' + pduObj.cmdName);
|
||||
log.verbose(logPrefix + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// When the return is fetched, call the callback
|
||||
this.on('incomingPduObj' + pduObj.seqNr, function(incPduObj) {
|
||||
|
||||
log.debug('larvitsmpp: lib/session.js: send() - this.on(incomingPduObj) - cmdName: ' + incPduObj.cmdName + ' seqNr: ' + incPduObj.seqNr + ' cmdStatus: ' + incPduObj.cmdStatus);
|
||||
// When the return is fetched, call the cb
|
||||
that.on('incomingPduObj' + pduObj.seqNr, function (incPduObj) {
|
||||
log.debug(logPrefix + 'this.on(incomingPduObj) - cmdName: ' + incPduObj.cmdName + ' seqNr: ' + incPduObj.seqNr + ' cmdStatus: ' + incPduObj.cmdStatus);
|
||||
|
||||
// Make sure this is the actual response to the sent PDU
|
||||
if (incPduObj.isResp() && incPduObj.seqNr === pduObj.seqNr) {
|
||||
callback(null, incPduObj);
|
||||
cb(null, incPduObj);
|
||||
|
||||
if (closeAfterSend) {
|
||||
that.closeSocket();
|
||||
}
|
||||
} else {
|
||||
err = new Error('Event triggered but incoming PDU is not a response or seqNr does not match. isResp: ' + incPduObj.isResp().toString() + ' incSeqNr: ' + incPduObj.seqNr + ' expected seqNr: ' + pduObj.seqNr);
|
||||
log.warn('larvitsmpp: lib/session.js: send() - this.on(incomingPduObj) - ' + err.message);
|
||||
callback(err);
|
||||
const err = new Error('Event triggered but incoming PDU is not a response or seqNr does not match. isResp: ' + incPduObj.isResp().toString() + ' incSeqNr: ' + incPduObj.seqNr + ' expected seqNr: ' + pduObj.seqNr);
|
||||
log.warn(logPrefix + 'this.on(incomingPduObj) - ' + err.message);
|
||||
cb(err);
|
||||
}
|
||||
});
|
||||
|
||||
// Increase our internal sequence number
|
||||
this.incOurSeqNr();
|
||||
that.incOurSeqNr();
|
||||
|
||||
// Write the PDU to socket
|
||||
this.sockWrite(pduObj);
|
||||
that.sockWrite(pduObj);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,58 +212,58 @@ function send(pdu, closeAfterSend, callback) {
|
||||
* @param {string} status - see list at defs.errors - defaults to 'ESME_ROK' - no error (OPTIONAL)
|
||||
* @param {object} [params]
|
||||
* @param {boolean} closeAfterSend - if true will close the socket after sending (OPTIONAL)
|
||||
* @param {function} [callback(err, retPdu)]
|
||||
* @param {function} [cb(err, retPdu)]
|
||||
*/
|
||||
function sendReturn(pdu, status, params, closeAfterSend, callback) {
|
||||
var that = this;
|
||||
function sendReturn(pdu, status, params, closeAfterSend, cb) {
|
||||
const logPrefix = topLogPrefix + 'sendReturn() - ',
|
||||
that = this;
|
||||
|
||||
log.silly('larvitsmpp: lib/session.js: sendReturn() - ran');
|
||||
log.silly(logPrefix + 'ran');
|
||||
|
||||
if (typeof params === 'function') {
|
||||
callback = params;
|
||||
cb = params;
|
||||
params = undefined;
|
||||
closeAfterSend = undefined;
|
||||
}
|
||||
|
||||
if (typeof closeAfterSend === 'function') {
|
||||
callback = closeAfterSend;
|
||||
cb = closeAfterSend;
|
||||
closeAfterSend = undefined;
|
||||
}
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
callback = function() {};
|
||||
if (typeof cb !== 'function') {
|
||||
cb = function () {};
|
||||
}
|
||||
|
||||
|
||||
|
||||
utils.pduReturn(pdu, status, params, function(err, retPdu) {
|
||||
utils.pduReturn(pdu, status, params, function (err, retPdu) {
|
||||
if (err) {
|
||||
log.error('larvitsmpp: lib/session.js: sendReturn() - Could not create return PDU: ' + err.message);
|
||||
log.error(logPrefix + 'Could not create return PDU: ' + err.message);
|
||||
that.closeSocket();
|
||||
|
||||
callback(err);
|
||||
return;
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
log.silly('larvitsmpp: lib/session.js: sendReturn() - Sending return PDU: ' + retPdu.toString('hex'));
|
||||
log.silly(logPrefix + 'Sending return PDU: ' + retPdu.toString('hex'));
|
||||
that.sockWrite(retPdu, closeAfterSend);
|
||||
callback(null, retPdu);
|
||||
cb(null, retPdu);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an SMS
|
||||
*
|
||||
* @param {object} smsOptions
|
||||
* @param {object} smsOptions {
|
||||
* from - alphanum or international format
|
||||
* to - international format
|
||||
* message - string
|
||||
* dlr - boolean defaults to false
|
||||
* flash - boolean defaults to false
|
||||
* @param {function} callback(err, smsIds, retPduObjs)
|
||||
* }
|
||||
* @param {function} cb(err, smsIds, retPduObjs)
|
||||
*/
|
||||
function sendSms(smsOptions, callback) {
|
||||
var pduObj = {};
|
||||
function sendSms(smsOptions, cb) {
|
||||
const logPrefix = topLogPrefix + 'sendSms() - ',
|
||||
pduObj = {};
|
||||
|
||||
pduObj.cmdName = 'submit_sm';
|
||||
pduObj.params = {
|
||||
@@ -280,7 +275,7 @@ function sendSms(smsOptions, callback) {
|
||||
|
||||
// Flash messages overrides default data_coding
|
||||
if (smsOptions.flash) {
|
||||
log.debug('larvitsmpp: lib/session.js: sendSms() - Flash SMS detected, set data_coding to 0x10!');
|
||||
log.debug(logPrefix + 'Flash SMS detected, set data_coding to 0x10!');
|
||||
pduObj.params.data_coding = 0x10;
|
||||
}
|
||||
|
||||
@@ -291,18 +286,18 @@ function sendSms(smsOptions, callback) {
|
||||
|
||||
// Check if we must split this message into multiple
|
||||
if (utils.bitCount(smsOptions.message) > 1120) {
|
||||
log.debug('larvitsmpp: lib/session.js: sendSms() - Message larger than 1120 bits, send it as long message!');
|
||||
log.debug(logPrefix + 'Message larger than 1120 bits, send it as long message!');
|
||||
|
||||
this.sendLongSms(smsOptions, callback);
|
||||
this.sendLongSms(smsOptions, cb);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug('larvitsmpp: lib/session.js: sendSms() - pduObj: ' + JSON.stringify(pduObj));
|
||||
log.debug(logPrefix + 'pduObj: ' + JSON.stringify(pduObj));
|
||||
|
||||
this.send(pduObj, function(err, retPduObj) {
|
||||
if (typeof callback === 'function') {
|
||||
callback(err, [retPduObj.params.message_id], [retPduObj]);
|
||||
this.send(pduObj, function (err, retPduObj) {
|
||||
if (typeof cb === 'function') {
|
||||
cb(err, [retPduObj.params.message_id], [retPduObj]);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -310,22 +305,24 @@ function sendSms(smsOptions, callback) {
|
||||
/**
|
||||
* Send a longer SMS than 1120 bits
|
||||
*
|
||||
* @param {object} smsOptions
|
||||
* @param {object} smsOptions {
|
||||
* from - alphanum or international format
|
||||
* to - international format
|
||||
* message - string
|
||||
* dlr - boolean defaults to false
|
||||
* @param {function} callback(err, smsId, retPduObj)
|
||||
* }
|
||||
* @param {function} cb - cb(err, smsId, retPduObj)
|
||||
*/
|
||||
function sendLongSms(smsOptions, callback) {
|
||||
var that = this,
|
||||
function sendLongSms(smsOptions, cb) {
|
||||
const retPduObjs = [],
|
||||
logPrefix = topLogPrefix + 'sendLongSms() - ',
|
||||
encoding = defs.encodings.detect(smsOptions.message), // Set encoding once for all message parts
|
||||
smsIds = [],
|
||||
retPduObjs = [],
|
||||
msgs = utils.splitMsg(smsOptions.message),
|
||||
encoding = defs.encodings.detect(smsOptions.message); // Set encoding once for all message parts
|
||||
that = this,
|
||||
msgs = utils.splitMsg(smsOptions.message);
|
||||
|
||||
function sendPart(i) {
|
||||
var pduObj = {
|
||||
const pduObj = {
|
||||
'cmdName': 'submit_sm',
|
||||
'params': {
|
||||
'source_addr_ton': 1, // Default to international format
|
||||
@@ -343,17 +340,17 @@ function sendLongSms(smsOptions, callback) {
|
||||
pduObj.params.registered_delivery = 0x01;
|
||||
}
|
||||
|
||||
log.debug('larvitsmpp: lib/session.js: sendLongSms() - pduObj: ' + JSON.stringify(pduObj));
|
||||
log.debug(logPrefix + 'pduObj: ' + JSON.stringify(pduObj));
|
||||
|
||||
that.send(pduObj, function(err, retPduObj) {
|
||||
that.send(pduObj, function (err, retPduObj) {
|
||||
smsIds.push(retPduObj.params.message_id);
|
||||
retPduObjs.push(retPduObj);
|
||||
|
||||
log.silly('larvitsmpp: lib/session.js: sendLongSms() - Got callback from that.send()');
|
||||
log.silly(logPrefix + 'Got cb from that.send()');
|
||||
|
||||
if (typeof callback === 'function' && smsIds.length === msgs.length) {
|
||||
log.silly('larvitsmpp: lib/session.js: sendLongSms() - All callbacks returned, run the parent callback.');
|
||||
callback(err, smsIds, retPduObjs);
|
||||
if (typeof cb === 'function' && smsIds.length === msgs.length) {
|
||||
log.silly(logPrefix + 'All cbs returned, run the parent cb.');
|
||||
cb(err, smsIds, retPduObjs);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -372,17 +369,17 @@ 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 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 + 2],
|
||||
longSmsId = pduObj.params.source_addr + '_' + pduObj.params.destination_addr + '_' + csmsReference;
|
||||
|
||||
if (this.longSmses[longSmsId] === undefined) {
|
||||
this.longSmses[longSmsId] = {
|
||||
const 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],
|
||||
longSmsId = pduObj.params.source_addr + '_' + pduObj.params.destination_addr + '_' + csmsReference,
|
||||
partNr = pduObj.params.short_message[2 + csmsReference.length + 2],
|
||||
that = this;
|
||||
|
||||
if (that.longSmses[longSmsId] === undefined) {
|
||||
that.longSmses[longSmsId] = {
|
||||
'created': new Date(),
|
||||
'partsCount': partsCount,
|
||||
'udhSize': udhHeaderSize, // Saving udh size to remove garbage from message
|
||||
@@ -392,14 +389,14 @@ function longSms(pduObj) {
|
||||
}]
|
||||
};
|
||||
} else {
|
||||
this.longSmses[longSmsId].pduObjs.push({
|
||||
that.longSmses[longSmsId].pduObjs.push({
|
||||
'partNr': partNr, // We save this here to easier sort the array later on
|
||||
'pduObj': pduObj
|
||||
});
|
||||
}
|
||||
|
||||
// Check the long messages tmp storage to see if we should handle them
|
||||
this.checkLongSmses();
|
||||
that.checkLongSmses();
|
||||
}
|
||||
|
||||
// Sort function to sort group parts
|
||||
@@ -418,15 +415,11 @@ function sortLongSmsPdus(a, b) {
|
||||
// Walk through the long sms storage to investigate if we can send complete messages along
|
||||
// or should remove old ones
|
||||
function checkLongSmses() {
|
||||
var that = this,
|
||||
smsGroupId,
|
||||
smsGroup,
|
||||
udhSize, // UDH Size from longSms() function
|
||||
smsObj,
|
||||
i,
|
||||
curPduObj;
|
||||
const logPrefix = topLogPrefix + 'checkLongSmses() - ',
|
||||
smsObj = {},
|
||||
that = this;
|
||||
|
||||
log.silly('larvitsmpp: lib/session.js: checkLongSmses() - Running');
|
||||
log.silly(logPrefix + 'Running');
|
||||
|
||||
// Call when complete SMS is received
|
||||
function smsReceived() {
|
||||
@@ -436,44 +429,41 @@ function checkLongSmses() {
|
||||
delete that.longSmses[smsObj.smsGroupId];
|
||||
}
|
||||
|
||||
for (smsGroupId in this.longSmses) {
|
||||
smsGroup = this.longSmses[smsGroupId];
|
||||
for (const smsGroupId in this.longSmses) {
|
||||
const smsGroup = this.longSmses[smsGroupId],
|
||||
udhSize = smsGroup.udhSize;
|
||||
|
||||
// All parts are accounted for! Emit sms event and clear from tmp storage
|
||||
if (smsGroup.partsCount === smsGroup.pduObjs.length) {
|
||||
log.debug('larvitsmpp: lib/session.js: checkLongSmses() - All parts accounted for in smsGroupId "' + smsGroupId + '", emitting sms event.');
|
||||
log.debug(logPrefix + 'All parts accounted for in smsGroupId "' + smsGroupId + '", emitting sms event.');
|
||||
|
||||
smsObj = {
|
||||
// These are needed for references here and there in functions
|
||||
'session': that,
|
||||
'smsGroupId': smsGroupId,
|
||||
'pduObjs': smsGroup.pduObjs,
|
||||
'from': smsGroup.pduObjs[0].pduObj.params.source_addr,
|
||||
'to': smsGroup.pduObjs[0].pduObj.params.destination_addr,
|
||||
'submitTime': new Date(),
|
||||
'message': '',
|
||||
'dlr': Boolean(smsGroup.pduObjs[0].pduObj.params.registered_delivery),
|
||||
'sendResp': smsResp,
|
||||
'sendDlr': utils.smsDlr
|
||||
};
|
||||
smsObj.session = that;
|
||||
smsObj.smsGroupId = smsGroupId;
|
||||
smsObj.pduObjs = smsGroup.pduObjs;
|
||||
smsObj.from = smsGroup.pduObjs[0].pduObj.params.source_addr;
|
||||
smsObj.to = smsGroup.pduObjs[0].pduObj.params.destination_addr;
|
||||
smsObj.submitTime = new Date();
|
||||
smsObj.message = '';
|
||||
smsObj.dlr = Boolean(smsGroup.pduObjs[0].pduObj.params.registered_delivery);
|
||||
smsObj.sendResp = smsResp;
|
||||
smsObj.sendDlr = utils.smsDlr;
|
||||
|
||||
// Concatenate all the parts messages to one and set references to the session
|
||||
|
||||
// First we need to sort the parts, since they can come in random order
|
||||
smsObj.pduObjs.sort(sortLongSmsPdus);
|
||||
|
||||
i = 0;
|
||||
while (smsObj.pduObjs[i] !== undefined) {
|
||||
curPduObj = smsObj.pduObjs[i].pduObj;
|
||||
for (let i = 0; smsObj.pduObjs[i] !== undefined; i ++) {
|
||||
const curPduObj = smsObj.pduObjs[i].pduObj;
|
||||
|
||||
curPduObj.session = this;
|
||||
|
||||
smsObj.message += utils.decodeMsg(curPduObj.params.short_message, curPduObj.params.data_coding, udhSize + 1);
|
||||
|
||||
i ++;
|
||||
}
|
||||
smsReceived();
|
||||
} else if (moment(new Date()).diff(smsGroup.created, 'hours') > 24) {
|
||||
log.info('larvitsmpp: lib/session.js: checkLongSmses() - smsGroupId "' + smsGroupId + '" is removed from this.longSmses due to being older than 24 hours.');
|
||||
log.info(logPrefix + 'smsGroupId "' + smsGroupId + '" is removed from this.longSmses due to being older than 24 hours.');
|
||||
|
||||
delete this.longSmses[smsGroupId];
|
||||
}
|
||||
@@ -487,18 +477,14 @@ function checkLongSmses() {
|
||||
* @return {object} (returnObj)
|
||||
*/
|
||||
function session(sock) {
|
||||
var returnObj = new events.EventEmitter();
|
||||
const logPrefix = topLogPrefix + 'session() - socket address: ' + sock.remoteAddress + ':' + sock.remotePort + ' - ',
|
||||
returnObj = new events.EventEmitter();
|
||||
|
||||
log.silly('larvitsmpp: lib/session.js: session() - New session started from ' + sock.remoteAddress + ':' + sock.remotePort);
|
||||
log.silly(logPrefix + 'New session started');
|
||||
|
||||
returnObj.loggedIn = false;
|
||||
|
||||
// Sequence number used for commands initiated from us
|
||||
returnObj.ourSeqNr = 1;
|
||||
|
||||
// Make the socket transparent via the returned emitter
|
||||
returnObj.sock = sock;
|
||||
|
||||
returnObj.ourSeqNr = 1; // Sequence number used for commands initiated from us
|
||||
returnObj.sock = sock; // Make the socket transparent via the returned emitter
|
||||
returnObj.incOurSeqNr = incOurSeqNr;
|
||||
returnObj.closeSocket = closeSocket;
|
||||
returnObj.sockWrite = sockWrite;
|
||||
@@ -524,12 +510,13 @@ function session(sock) {
|
||||
returnObj.handleCmd = {};
|
||||
|
||||
// Handle incoming deliver_sm
|
||||
returnObj.handleCmd.deliver_sm = function(pduObj) {
|
||||
var dlrObj;
|
||||
returnObj.handleCmd.deliver_sm = function deliver_sm(pduObj) {
|
||||
const thisLogPrefix = logPrefix + 'deliver_sm() - ',
|
||||
dlrObj = {};
|
||||
|
||||
// TLV message_state must exists
|
||||
if (pduObj.tlvs.message_state === undefined) {
|
||||
log.info('larvitsmpp: lib/session.js: session() - returnObj.handleCmd.deliver_sm() - TLV message_state is missing. SeqNr: ' + pduObj.seqNr);
|
||||
log.info(thisLogPrefix + 'TLV message_state is missing. SeqNr: ' + pduObj.seqNr);
|
||||
returnObj.sendReturn(pduObj, 'ESME_RINVTLVSTREAM');
|
||||
|
||||
return;
|
||||
@@ -537,7 +524,7 @@ function session(sock) {
|
||||
|
||||
// TLV message_state needs to be valid
|
||||
if (defs.constsById.MESSAGE_STATE[pduObj.tlvs.message_state.tagValue] === undefined) {
|
||||
log.info('larvitsmpp: lib/session.js: session() - returnObj.handleCmd.deliver_sm() - Invalid TLV message_state: "' + pduObj.tlvs.message_state.tagValue + '". SeqNr: ' + pduObj.seqNr);
|
||||
log.info(thisLogPrefix + 'Invalid TLV message_state: "' + pduObj.tlvs.message_state.tagValue + '". SeqNr: ' + pduObj.seqNr);
|
||||
returnObj.sendReturn(pduObj, 'ESME_RINVTLVSTREAM');
|
||||
|
||||
return;
|
||||
@@ -545,85 +532,86 @@ function session(sock) {
|
||||
|
||||
// TLV receipted_message_id must exist
|
||||
if (pduObj.tlvs.receipted_message_id === undefined) {
|
||||
log.info('larvitsmpp: lib/session.js: session() - returnObj.handleCmd.deliver_sm() - TLV receipted_message_id is missing. SeqNr: ' + pduObj.seqNr);
|
||||
log.info(thisLogPrefix + 'TLV receipted_message_id is missing. SeqNr: ' + pduObj.seqNr);
|
||||
returnObj.sendReturn(pduObj, 'ESME_RINVTLVSTREAM');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
dlrObj = {
|
||||
'statusMsg': defs.constsById.MESSAGE_STATE[pduObj.tlvs.message_state.tagValue],
|
||||
'statusId': pduObj.tlvs.message_state.tagValue,
|
||||
'smsId': pduObj.tlvs.receipted_message_id.tagValue
|
||||
};
|
||||
dlrObj.statusMsg = defs.constsById.MESSAGE_STATE[pduObj.tlvs.message_state.tagValue];
|
||||
dlrObj.statusId = pduObj.tlvs.message_state.tagValue;
|
||||
dlrObj.smsId = pduObj.tlvs.receipted_message_id.tagValue;
|
||||
|
||||
returnObj.emit('dlr', dlrObj, pduObj);
|
||||
returnObj.sendReturn(pduObj);
|
||||
};
|
||||
|
||||
// Enquire link
|
||||
returnObj.handleCmd.enquire_link = function(pduObj) {
|
||||
log.silly('larvitsmpp: lib/session.js: session() - enquireLink() - Enquiring link');
|
||||
returnObj.handleCmd.enquire_link = function enquire_link(pduObj) {
|
||||
const thisLogPrefix = logPrefix + 'enquire_link() - ';
|
||||
|
||||
log.silly(thisLogPrefix + 'Enquiring link');
|
||||
returnObj.resetEnqLinkTimer();
|
||||
returnObj.sendReturn(pduObj);
|
||||
};
|
||||
|
||||
// Handle incoming submit_sm
|
||||
returnObj.handleCmd.submit_sm = function(pduObj) {
|
||||
var smsObj = {};
|
||||
returnObj.handleCmd.submit_sm = function submit_sm(pduObj) {
|
||||
const thisLogPrefix = logPrefix + 'submit_sm() - ',
|
||||
smsObj = {};
|
||||
|
||||
log.silly('larvitsmpp: lib/session.js: session() - returnObj.handleCmd.submit_sm() - ran');
|
||||
log.silly(thisLogPrefix + 'ran');
|
||||
|
||||
// If esm_class is 0x40 it means this is just a part of a larger message
|
||||
//if (pduObj.params.esm_class === 0x40) {
|
||||
// Fix: esm_class can be combination of bits. We need to extract 0x40 and then compare
|
||||
if ((pduObj.params.esm_class & 0x40) === 0x40) {
|
||||
log.debug('larvitsmpp: lib/session.js: session() - returnObj.handleCmd.submit_sm() - long sms detected, esm_class 0x40.');
|
||||
log.debug(thisLogPrefix + 'long sms detected, esm_class 0x40.');
|
||||
returnObj.longSms(pduObj);
|
||||
return; // Long messages should not get handled here at all, so cancel execution here
|
||||
}
|
||||
|
||||
smsObj = {
|
||||
|
||||
// These are needed for references here and there in functions
|
||||
'session': returnObj,
|
||||
'pduObjs': [{'pduObj': pduObj}],
|
||||
'from': pduObj.params.source_addr,
|
||||
'to': pduObj.params.destination_addr,
|
||||
'submitTime': new Date(),
|
||||
'message': pduObj.params.short_message,
|
||||
'dlr': Boolean(pduObj.params.registered_delivery),
|
||||
'sendResp': smsResp,
|
||||
'sendDlr': utils.smsDlr
|
||||
};
|
||||
smsObj.session = returnObj;
|
||||
smsObj.pduObjs = [{'pduObj': pduObj}];
|
||||
smsObj.from = pduObj.params.source_addr;
|
||||
smsObj.to = pduObj.params.destination_addr;
|
||||
smsObj.submitTime = new Date();
|
||||
smsObj.message = pduObj.params.short_message;
|
||||
smsObj.dlr = Boolean(pduObj.params.registered_delivery);
|
||||
smsObj.sendResp = smsResp;
|
||||
smsObj.sendDlr = utils.smsDlr;
|
||||
|
||||
if (pduObj.params.data_coding === 0x10) {
|
||||
smsObj.flash = true;
|
||||
}
|
||||
|
||||
log.silly('larvitsmpp: lib/session.js: session() - returnObj.handleCmd.submit_sm() - Emitting sms object');
|
||||
log.silly(thisLogPrefix + 'Emitting sms object');
|
||||
|
||||
returnObj.emit('sms', smsObj);
|
||||
};
|
||||
|
||||
// Handle incoming unbind
|
||||
returnObj.handleCmd.unbind = function(pduObj) {
|
||||
returnObj.handleCmd.unbind = function unbind(pduObj) {
|
||||
returnObj.sendReturn(pduObj, 'ESME_ROK', undefined, true);
|
||||
};
|
||||
|
||||
// Dummy, should be extended by serverSession or clientSession
|
||||
returnObj.login = function() {
|
||||
log.info('larvitsmpp: lib/session.js: session() - login() - Dummy login function ran, this might be a mistake');
|
||||
returnObj.login = function login() {
|
||||
const thisLogPrefix = logPrefix + 'login() - ';
|
||||
|
||||
log.info(thisLogPrefix + 'Dummy login function ran, this might be a mistake');
|
||||
returnObj.loggedIn = true;
|
||||
};
|
||||
|
||||
// Dummy method - should be used by serverSession or clientSession
|
||||
returnObj.resetEnqLinkTimer = function() {
|
||||
log.silly('larvitsmpp: lib/session.js: session() - resetEnqLinkTimer() - Resetting the kill timer');
|
||||
returnObj.resetEnqLinkTimer = function resetEnqLinkTimer() {
|
||||
const thisLogPrefix = logPrefix + 'resetEnqLinkTimer() - ';
|
||||
log.silly(thisLogPrefix + 'Resetting the kill timer');
|
||||
};
|
||||
|
||||
// Unbind this session
|
||||
returnObj.unbind = function() {
|
||||
returnObj.unbind = function () {
|
||||
returnObj.send({
|
||||
'cmdName': 'unbind'
|
||||
}, true);
|
||||
@@ -634,9 +622,8 @@ function session(sock) {
|
||||
returnObj.dataQueue = new Buffer(0);
|
||||
|
||||
// Add a 'data' event handler to this instance of socket
|
||||
sock.on('data', function(data) {
|
||||
var cmdLength,
|
||||
pdu;
|
||||
sock.on('data', function (data) {
|
||||
const thisLogPrefix = logPrefix + 'sock.on(data) - ';
|
||||
|
||||
// Pass the data along to the returnObj
|
||||
returnObj.emit('data', data);
|
||||
@@ -644,20 +631,22 @@ function session(sock) {
|
||||
// Reset the enquire link timer
|
||||
returnObj.resetEnqLinkTimer();
|
||||
|
||||
log.debug('larvitsmpp: lib/session.js: session() - sock.on(data) - Incoming data: ' + data.toString('hex'));
|
||||
log.debug(thisLogPrefix + 'Incoming data: ' + data.toString('hex'));
|
||||
|
||||
// Add this data to the dataQueue for processing
|
||||
returnObj.dataQueue = Buffer.concat([returnObj.dataQueue, data]);
|
||||
|
||||
// Process queue
|
||||
while (returnObj.dataQueue.length > 4) {
|
||||
// Get this commands length
|
||||
cmdLength = parseInt(returnObj.dataQueue.readUInt32BE(0));
|
||||
log.silly('larvitsmpp: lib/session.js: session() - sock.on(data) - Processing ' + cmdLength + ' bytes of data');
|
||||
const cmdLength = parseInt(returnObj.dataQueue.readUInt32BE(0)); // Get this commands length
|
||||
|
||||
let pdu;
|
||||
|
||||
log.silly(thisLogPrefix + 'Processing ' + cmdLength + ' bytes of data');
|
||||
|
||||
// If there is at least enough bytes in the dataQueue to fill this PDU, do it!
|
||||
if (cmdLength <= returnObj.dataQueue.length) {
|
||||
log.silly('larvitsmpp: lib/session.js: session() - sock.on(data) - Full PDU found in dataQueue, processing ' + cmdLength + ' bytes of queue total ' + returnObj.dataQueue.length + ' bytes');
|
||||
log.silly(thisLogPrefix + 'Full PDU found in dataQueue, processing ' + cmdLength + ' bytes of queue total ' + returnObj.dataQueue.length + ' bytes');
|
||||
|
||||
// Slice up the dataQueue buffer to this commands length
|
||||
pdu = returnObj.dataQueue.slice(0, cmdLength);
|
||||
@@ -667,34 +656,35 @@ function session(sock) {
|
||||
|
||||
returnObj.emit('incomingPdu', pdu);
|
||||
} else {
|
||||
log.debug('larvitsmpp: lib/session.js: session() - sock.on(data) - Tried to process ' + cmdLength + ' bytes, but only ' + returnObj.dataQueue.length + ' bytes found. Awaiting more data. Current data in queue: ' + returnObj.dataQueue.toString('hex'));
|
||||
log.debug(thisLogPrefix + 'Tried to process ' + cmdLength + ' bytes, but only ' + returnObj.dataQueue.length + ' bytes found. Awaiting more data. Current data in queue: ' + returnObj.dataQueue.toString('hex'));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (returnObj.dataQueue.length === 0) {
|
||||
log.silly('larvitsmpp: lib/session.js: session() - sock.on(data) - All queue handled, breaking while loop.');
|
||||
log.silly(thisLogPrefix + 'All queue handled, breaking while loop.');
|
||||
break;
|
||||
}
|
||||
|
||||
// If the command length is larger than the queue, we need to wait for more data. Stop processing!
|
||||
if (cmdLength > returnObj.dataQueue) {
|
||||
log.debug('larvitsmpp: lib/session.js: session() - sock.on(data) - Incomplete PDU found in dataQueue, waiting for more data to continue. Current cmdLength: ' + cmdLength + ' current queue: ' + returnObj.dataQueue.toString('hex'));
|
||||
|
||||
log.debug(thisLogPrefix + 'Incomplete PDU found in dataQueue, waiting for more data to continue. Current cmdLength: ' + cmdLength + ' current queue: ' + returnObj.dataQueue.toString('hex'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Handle incoming Pdu Buffers
|
||||
returnObj.on('incomingPdu', function(pdu) {
|
||||
utils.pduToObj(pdu, function(err, pduObj) {
|
||||
returnObj.on('incomingPdu', function (pdu) {
|
||||
const thisLogPrefix = logPrefix + 'sock.on(incomingPdu) - ';
|
||||
|
||||
utils.pduToObj(pdu, function (err, pduObj) {
|
||||
if (err) {
|
||||
log.warn('larvitsmpp: lib/session.js: session() - returnObj.on(incomingPdu) - Invalid PDU, closing socket.');
|
||||
log.warn(thisLogPrefix + 'Invalid PDU, closing socket.');
|
||||
|
||||
returnObj.closeSocket();
|
||||
} else {
|
||||
log.verbose('larvitsmpp: lib/session.js: session() - returnObj.on(incomingPdu) - Incoming PDU parsed. Seqnr: ' + pduObj.seqNr + ' cmd: ' + pduObj.cmdName + ' cmdStatus: ' + pduObj.cmdStatus + ' hex: ' + pdu.toString('hex'));
|
||||
log.verbose(thisLogPrefix + 'Incoming PDU parsed. Seqnr: ' + pduObj.seqNr + ' cmd: ' + pduObj.cmdName + ' cmdStatus: ' + pduObj.cmdStatus + ' hex: ' + pdu.toString('hex'));
|
||||
|
||||
if (pduObj.isResp()) {
|
||||
// We do this so we can remove the dynamic event listeners to not have a memory leak
|
||||
@@ -710,19 +700,23 @@ function session(sock) {
|
||||
});
|
||||
|
||||
// Add a 'close' event handler to this instance of socket
|
||||
sock.on('close', function() {
|
||||
sock.on('close', function () {
|
||||
const thisLogPrefix = logPrefix + 'sock.on(close) - ';
|
||||
|
||||
returnObj.emit('close');
|
||||
if (returnObj.enqLinkTimer) {
|
||||
log.debug('larvitsmpp: lib/session.js: session() - sock.on(close) - enqLinkTimer found, clearing.');
|
||||
log.debug(thisLogPrefix + 'enqLinkTimer found, clearing.');
|
||||
clearTimeout(returnObj.enqLinkTimer);
|
||||
}
|
||||
log.debug('larvitsmpp: lib/session.js: session() - sock.on(close) - socket closed');
|
||||
log.debug(thisLogPrefix + 'socket closed');
|
||||
});
|
||||
|
||||
sock.on('error', function() {
|
||||
log.warn('larvitsmpp: lib/session.js: session() - sock.on(error) - Socket error detected!');
|
||||
sock.on('error', function () {
|
||||
const thisLogPrefix = logPrefix + 'sock.on(error) - ';
|
||||
|
||||
log.warn(thisLogPrefix + 'Socket error detected!');
|
||||
if (returnObj.enqLinkTimer) {
|
||||
log.debug('larvitsmpp: lib/session.js: session() - sock.on(error) - enqLinkTimer found, clearing.');
|
||||
log.debug(thisLogPrefix + 'enqLinkTimer found, clearing.');
|
||||
clearTimeout(returnObj.enqLinkTimer);
|
||||
}
|
||||
});
|
||||
|
||||
+192
-241
@@ -1,49 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var log = require('winston'),
|
||||
defs = require('./defs'),
|
||||
bundleMsgId = 0;
|
||||
const topLogPrefix = 'larvitsmpp: lib/utils.js: ',
|
||||
defs = require(__dirname + '/defs.js'),
|
||||
log = require('winston');
|
||||
|
||||
let bundleMsgId = 0;
|
||||
|
||||
/**
|
||||
* Calculate cmdLength from object
|
||||
*
|
||||
* @param {object} obj
|
||||
* @param {function} callback(err, cmdLength)
|
||||
* @param {function} cb - cb(err, cmdLength)
|
||||
*/
|
||||
function calcCmdLength(obj, callback) {
|
||||
var cmdLength = 16, // All commands are at least 16 octets long
|
||||
err,
|
||||
param,
|
||||
paramType,
|
||||
tlvValue,
|
||||
tlvName,
|
||||
tlvDef;
|
||||
function calcCmdLength(obj, cb) {
|
||||
const logPrefix = topLogPrefix + 'calcCmdLength() - ';
|
||||
|
||||
let cmdLength = 16; // All commands are at least 16 octets long
|
||||
|
||||
// Handle params - All command params should always exists, even if they do not contain data.
|
||||
for (param in defs.cmds[obj.cmdName].params) {
|
||||
|
||||
for (const param in defs.cmds[obj.cmdName].params) {
|
||||
// Get the parameter type, int, string, cstring etc.
|
||||
// This is needed so we can calculate length etc
|
||||
paramType = defs.cmds[obj.cmdName].params[param].type;
|
||||
const paramType = defs.cmds[obj.cmdName].params[param].type;
|
||||
|
||||
if (obj.params[param] === undefined) {
|
||||
obj.params[param] = paramType.default;
|
||||
}
|
||||
|
||||
if (isNaN(paramType.size(obj.params[param]))) {
|
||||
err = new Error('Invalid param value "' + obj.params[param] + '" for param "' + param + '" and command "' + obj.cmdName + '". Is it of the right type?');
|
||||
log.error('larvitsmpp: lib/utils.js: calcCmdLength() - ' + err.message);
|
||||
callback(err);
|
||||
return;
|
||||
const err = new Error('Invalid param value "' + obj.params[param] + '" for param "' + param + '" and command "' + obj.cmdName + '". Is it of the right type?');
|
||||
log.error(logPrefix + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
cmdLength += paramType.size(obj.params[param]);
|
||||
}
|
||||
|
||||
// TLV params - optional parameters
|
||||
for (tlvName in obj.tlvs) {
|
||||
tlvValue = obj.tlvs[tlvName].tagValue;
|
||||
tlvDef = defs.tlvsById[obj.tlvs[tlvName].tagId];
|
||||
for (const tlvName in obj.tlvs) {
|
||||
const tlvValue = obj.tlvs[tlvName].tagValue;
|
||||
|
||||
let tlvDef = defs.tlvsById[obj.tlvs[tlvName].tagId];
|
||||
|
||||
if (tlvDef === undefined) {
|
||||
tlvDef = defs.tlvs.default;
|
||||
@@ -51,15 +48,14 @@ function calcCmdLength(obj, callback) {
|
||||
|
||||
try {
|
||||
cmdLength += tlvDef.type.size(tlvValue) + 4;
|
||||
} catch(e) {
|
||||
err = new Error('Could not get size of TLV parameter "' + tlvName + '" with value "' + tlvValue + '"');
|
||||
log.error('larvitsmpp: lib/utils.js: calcCmdLength() - ' + err.message);
|
||||
callback(err);
|
||||
return;
|
||||
} catch (err) {
|
||||
const manErr = new Error('Could not get size of TLV parameter "' + tlvName + '" with value "' + tlvValue + '", err: ' + err.message);
|
||||
log.error(logPrefix + manErr.message);
|
||||
return cb(manErr);
|
||||
}
|
||||
}
|
||||
|
||||
callback(null, cmdLength);
|
||||
cb(null, cmdLength);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,33 +63,24 @@ function calcCmdLength(obj, callback) {
|
||||
*
|
||||
* @param {object} obj - the PDU object to be written to buffer
|
||||
* @param {number} cmdLength - The length of the pdu buffer
|
||||
* @param {function} callback(err, buff)
|
||||
* @param {function} cb - cb(err, buff)
|
||||
*/
|
||||
function writeBuffer(obj, cmdLength, callback) {
|
||||
var offset = 16, // Start the offset on the body
|
||||
buff,
|
||||
param,
|
||||
paramType,
|
||||
paramSize,
|
||||
tlvId,
|
||||
tlvName,
|
||||
tlvValue,
|
||||
tlvDef,
|
||||
tlvSize,
|
||||
err;
|
||||
function writeBuffer(obj, cmdLength, cb) {
|
||||
const logPrefix = topLogPrefix + 'writeBuffer() - ';
|
||||
|
||||
let offset = 16, // Start the offset on the body
|
||||
buff;
|
||||
|
||||
if (isNaN(cmdLength) || cmdLength < 16) {
|
||||
if (isNaN(cmdLength)) {
|
||||
err = new Error('cmdLength is NaN');
|
||||
const err = new Error('cmdLength is NaN');
|
||||
log.error(logPrefix + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
if (cmdLength < 16) {
|
||||
err = new Error('cmdLength is less than 16 (' + cmdLength + ')');
|
||||
}
|
||||
|
||||
log.error('larvitsmpp: lib/utils.js: objToPdu() - writeBuffer() - ' + err.message);
|
||||
callback(err);
|
||||
return;
|
||||
const err = new Error('cmdLength is less than 16 (' + cmdLength + ')');
|
||||
log.error(logPrefix + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
buff = new Buffer(cmdLength);
|
||||
@@ -104,26 +91,25 @@ function writeBuffer(obj, cmdLength, callback) {
|
||||
buff.writeUInt32BE(defs.cmds[obj.cmdName].id, 4); // Command id for the second 4 octets
|
||||
buff.writeUInt32BE(defs.errors[obj.cmdStatus], 8); // Command status for the third 4 octets
|
||||
buff.writeUInt32BE(obj.seqNr, 12); // Sequence number as the fourth 4 octets
|
||||
} catch (e) {
|
||||
err = new Error('Could not write PDU header, catched err: ' + e.message, obj);
|
||||
log.error('larvitsmpp: lib/utils.js: writeBuffer() - ' + err.message);
|
||||
callback(err);
|
||||
return;
|
||||
} catch (err) {
|
||||
const manErr = new Error('Could not write PDU header, catched err: ' + err.message, obj);
|
||||
log.error(logPrefix + manErr.message);
|
||||
return cb(manErr);
|
||||
}
|
||||
|
||||
// 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;
|
||||
for (const param in defs.cmds[obj.cmdName].params) {
|
||||
const paramType = defs.cmds[obj.cmdName].params[param].type,
|
||||
paramSize = paramType.size(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 + '"');
|
||||
log.silly(logPrefix + 'Writing param "' + param + '" with content "' + obj.params[param].toString('hex') + '" and size "' + paramSize + '"');
|
||||
} else {
|
||||
if (param === 'sm_length') {
|
||||
log.silly('larvitsmpp: lib/utils.js: writeBuffer() - sm_length is calculated by short_message: "' + obj.params.short_message.toString('hex') + '"');
|
||||
log.silly(logPrefix + 'sm_length is calculated by short_message: "' + obj.params.short_message.toString('hex') + '"');
|
||||
}
|
||||
|
||||
log.silly('larvitsmpp: lib/utils.js: writeBuffer() - Writing param "' + param + '" with content "' + obj.params[param] + '"');
|
||||
log.silly(logPrefix + 'Writing param "' + param + '" with content "' + obj.params[param] + '"');
|
||||
}
|
||||
|
||||
// Write parameter value to buffer using the types method write()
|
||||
@@ -134,10 +120,12 @@ function writeBuffer(obj, cmdLength, callback) {
|
||||
}
|
||||
|
||||
// Cycle through the tlvs
|
||||
for (tlvName in obj.tlvs) {
|
||||
for (const tlvName in obj.tlvs) {
|
||||
const tlvValue = obj.tlvs[tlvName].tagValue,
|
||||
tlvId = obj.tlvs[tlvName].tagId;
|
||||
tlvValue = obj.tlvs[tlvName].tagValue;
|
||||
tlvDef = defs.tlvsById[tlvId];
|
||||
|
||||
let tlvDef = defs.tlvsById[tlvId],
|
||||
tlvSize;
|
||||
|
||||
if (tlvDef === undefined) {
|
||||
tlvDef = defs.tlvs.default;
|
||||
@@ -145,7 +133,7 @@ function writeBuffer(obj, cmdLength, callback) {
|
||||
|
||||
tlvSize = tlvDef.type.size(tlvValue);
|
||||
|
||||
log.silly('larvitsmpp: lib/utils.js: writeBuffer() - Writing TLV "' + tlvName + '" offset: ' + offset + ' value: "' + tlvValue + '"');
|
||||
log.silly(logPrefix + 'Writing TLV "' + tlvName + '" offset: ' + offset + ' value: "' + tlvValue + '"');
|
||||
|
||||
buff.writeUInt16BE(tlvId, offset);
|
||||
buff.writeUInt16BE(tlvSize, offset + 2);
|
||||
@@ -154,9 +142,9 @@ function writeBuffer(obj, cmdLength, callback) {
|
||||
offset += tlvDef.type.size(tlvValue) + 4;
|
||||
}
|
||||
|
||||
log.silly('larvitsmpp: lib/utils.js: writeBuffer() - Complete PDU: "' + buff.toString('hex') + '"');
|
||||
log.silly(logPrefix + 'Complete PDU: "' + buff.toString('hex') + '"');
|
||||
|
||||
callback(null, buff);
|
||||
cb(null, buff);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,30 +156,30 @@ function writeBuffer(obj, cmdLength, callback) {
|
||||
* @return {string} in utf8 format
|
||||
*/
|
||||
function decodeMsg(buffer, encoding, offset) {
|
||||
var checkEnc;
|
||||
const logPrefix = topLogPrefix + 'decodeMsg() - ';
|
||||
|
||||
if (offset === undefined) {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
for (checkEnc in defs.consts.ENCODING) {
|
||||
for (const checkEnc in defs.consts.ENCODING) {
|
||||
if (parseInt(encoding) === defs.consts.ENCODING[checkEnc] || encoding === checkEnc) {
|
||||
encoding = checkEnc;
|
||||
}
|
||||
}
|
||||
|
||||
if (defs.encodings[encoding] === undefined) {
|
||||
log.info('larvitsmpp: lib/utils.js: decodeMsg() - Invalid encoding "' + encoding + '" given. Falling back to ASCII (0x01).');
|
||||
log.info(logPrefix + 'Invalid encoding "' + encoding + '" given. Falling back to ASCII (0x01).');
|
||||
encoding = 'ASCII';
|
||||
}
|
||||
|
||||
log.debug('larvitsmpp: lib/utils.js: decodeMsg() - Decoding msg. Encoding: "' + encoding + '" offset: "' + offset + '" buffer: "' + buffer.toString('hex') + '"');
|
||||
log.debug(logPrefix + 'Decoding msg. Encoding: "' + encoding + '" offset: "' + offset + '" buffer: "' + buffer.toString('hex') + '"');
|
||||
|
||||
return defs.encodings[encoding].decode(buffer.slice(offset));
|
||||
}
|
||||
|
||||
function encodeMsg(str) {
|
||||
var encoding = defs.encodings.detect(str);
|
||||
const encoding = defs.encodings.detect(str);
|
||||
|
||||
return defs.encodings[encoding].encode(str);
|
||||
}
|
||||
@@ -201,37 +189,31 @@ function encodeMsg(str) {
|
||||
*
|
||||
* @param {buffer} pdu
|
||||
* @param {boolean} stupidNullByte - Define if the short_message should be followed by a stupid NULL byte - will be auto resolved if left undefined
|
||||
* @param {function} callback(err, obj)
|
||||
* @param {function} cb - cb(err, obj)
|
||||
*/
|
||||
function pduToObj(pdu, stupidNullByte, callback) {
|
||||
var retObj = {'params': {}, 'tlvs': {}},
|
||||
err = null,
|
||||
offset,
|
||||
command,
|
||||
param,
|
||||
tlvCmdId,
|
||||
tlvLength,
|
||||
tlvValue,
|
||||
paramSize;
|
||||
function pduToObj(pdu, stupidNullByte, cb) {
|
||||
const logPrefix = topLogPrefix + 'pduToObj() - ',
|
||||
retObj = {'params': {}, 'tlvs': {}};
|
||||
|
||||
let offset = 16, // 0-15 is the header, so the body starts at 16
|
||||
command;
|
||||
|
||||
if (typeof stupidNullByte === 'function') {
|
||||
callback = stupidNullByte;
|
||||
cb = stupidNullByte;
|
||||
stupidNullByte = undefined;
|
||||
}
|
||||
|
||||
// Returns true if this PDU is a response to another PDU
|
||||
retObj.isResp = function() {
|
||||
retObj.isResp = function () {
|
||||
return ! ! (this.cmdId & 0x80000000);
|
||||
};
|
||||
|
||||
log.silly('larvitsmpp: lib/utils.js: pduToObj() - Decoding PDU to Obj. PDU buff in hex: ' + pdu.toString('hex'));
|
||||
log.silly(logPrefix + 'Decoding PDU to Obj. PDU buff in hex: ' + pdu.toString('hex'));
|
||||
|
||||
if (pdu.length < 16) {
|
||||
err = new Error('PDU is to small, minimum size is 16, given size is ' + pdu.length);
|
||||
log.warn('larvitsmpp: lib/utils.js: pduToObj() - ' + err.message);
|
||||
|
||||
callback(err);
|
||||
return;
|
||||
const err = new Error('PDU is to small, minimum size is 16, given size is ' + pdu.length);
|
||||
log.warn(logPrefix + '' + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// Read the PDU Header
|
||||
@@ -242,66 +224,69 @@ function pduToObj(pdu, stupidNullByte, callback) {
|
||||
|
||||
// Lookup the command id in the definitions
|
||||
if (defs.cmdsById[retObj.cmdId] === undefined) {
|
||||
err = new Error('Unknown PDU command id: ' + retObj.cmdId + ' PDU buff in hex: ' + pdu.toString('hex'));
|
||||
const err = new Error('Unknown PDU command id: ' + retObj.cmdId + ' PDU buff in hex: ' + pdu.toString('hex'));
|
||||
log.warn(logPrefix + '' + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
if (isNaN(retObj.seqNr)) {
|
||||
err = new Error('Invalid seqNr, is not an interger: "' + retObj.seqNr + '"');
|
||||
} else if (retObj.seqNr > 2147483646) {
|
||||
err = new Error('Invalid seqNr, maximum size of 2147483646 (0x7fffffff) exceeded.');
|
||||
const err = new Error('Invalid seqNr, is not an interger: "' + retObj.seqNr + '"');
|
||||
log.warn(logPrefix + '' + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// If error is found, do not proceed with execution
|
||||
if (err !== null) {
|
||||
log.warn('larvitsmpp: lib/utils.js: pduToObj() - ' + err.message);
|
||||
callback(err);
|
||||
return;
|
||||
if (retObj.seqNr > 2147483646) {
|
||||
const err = new Error('Invalid seqNr, maximum size of 2147483646 (0x7fffffff) exceeded.');
|
||||
log.warn(logPrefix + '' + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
command = defs.cmdsById[retObj.cmdId];
|
||||
retObj.cmdName = command.command;
|
||||
|
||||
// Get all parameters from the body that should exists with this command
|
||||
offset = 16; // 0-15 is the header, so the body starts at 16
|
||||
for (param in command.params) {
|
||||
for (const param in command.params) {
|
||||
|
||||
// Get the parameter value by using the definition type read() function
|
||||
try {
|
||||
let paramSize;
|
||||
|
||||
retObj.params[param] = command.params[param].type.read(pdu, offset, retObj.params.sm_length);
|
||||
paramSize = command.params[param].type.size(retObj.params[param]);
|
||||
|
||||
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'));
|
||||
log.silly(logPrefix + 'Reading param "' + param + '" at offset ' + offset + ' with calculated size: ' + paramSize + ' content in hex: ' + pdu.slice(offset, offset + paramSize).toString('hex'));
|
||||
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');
|
||||
log.silly(logPrefix + 'stupidNullByte is set, so short_message is followed by a NULL octet, increase paramSize one extra to account for that');
|
||||
paramSize ++;
|
||||
}
|
||||
}
|
||||
|
||||
// Increase the offset by the current params length
|
||||
offset += paramSize;
|
||||
} catch (e) {
|
||||
err = new Error('Failed to read param "' + param + '": ' + e.message);
|
||||
log.error('larvitsmpp: lib/utils.js: pduToObj() - ' + err.message);
|
||||
callback(err);
|
||||
|
||||
return;
|
||||
} catch (err) {
|
||||
const manErr = new Error('Failed to read param "' + param + '", err: ' + err.message);
|
||||
log.error(logPrefix + '' + manErr.message);
|
||||
return cb(err);
|
||||
}
|
||||
}
|
||||
|
||||
// If the length is greater than the current offset, there must be TLVs - resolve them!
|
||||
// The minimal size for a TLV is its head, 4 octets
|
||||
while ((offset + 4) < retObj.cmdLength) {
|
||||
let tlvLength,
|
||||
tlvCmdId,
|
||||
tlvValue;
|
||||
|
||||
try {
|
||||
tlvCmdId = pdu.readInt16BE(offset);
|
||||
tlvLength = pdu.readInt16BE(offset + 2);
|
||||
} catch (e) {
|
||||
err = new Error('Unable to read TLV at offset "' + offset + '", given cmdLength: "' + retObj.cmdLength + '" pdu: ' + pdu.toString('hex'));
|
||||
log.error('larvitsmpp: lib/utils.js: pduToObj() - ' + err.message);
|
||||
callback(err);
|
||||
return;
|
||||
} catch (err) {
|
||||
const manErr = new Error('Unable to read TLV at offset "' + offset + '", given cmdLength: "' + retObj.cmdLength + '" pdu: ' + pdu.toString('hex') + ', err: ' + err.message);
|
||||
log.error(logPrefix + '' + manErr.message);
|
||||
return cb(manErr);
|
||||
}
|
||||
|
||||
if (defs.tlvsById[tlvCmdId] === undefined) {
|
||||
@@ -313,7 +298,7 @@ function pduToObj(pdu, stupidNullByte, callback) {
|
||||
'tagValue': tlvValue
|
||||
};
|
||||
|
||||
log.verbose('larvitsmpp: lib/utils.js: pduToObj() - Unknown TLV found. Hex ID: ' + tlvCmdId.toString(16) + ' length: ' + tlvLength + ' hex value: ' + tlvValue);
|
||||
log.verbose(logPrefix + 'Unknown TLV found. Hex ID: ' + tlvCmdId.toString(16) + ' length: ' + tlvLength + ' hex value: ' + tlvValue);
|
||||
} else {
|
||||
tlvValue = defs.tlvsById[tlvCmdId].type.read(pdu, offset + 4, tlvLength);
|
||||
|
||||
@@ -327,21 +312,20 @@ function pduToObj(pdu, stupidNullByte, callback) {
|
||||
'tagValue': tlvValue
|
||||
};
|
||||
|
||||
log.silly('larvitsmpp: lib/utils.js: pduToObj() - TLV found: "' + defs.tlvsById[tlvCmdId].tag + '" ID: "' + tlvCmdId + '" value: "' + tlvValue + '"');
|
||||
log.silly(logPrefix + 'TLV found: "' + defs.tlvsById[tlvCmdId].tag + '" ID: "' + tlvCmdId + '" value: "' + tlvValue + '"');
|
||||
}
|
||||
|
||||
offset = offset + 4 + tlvLength;
|
||||
}
|
||||
|
||||
if (offset !== retObj.cmdLength && stupidNullByte === undefined) {
|
||||
log.verbose('larvitsmpp: lib/utils.js: pduToObj() - Offset (' + offset + ') !== cmdLength (' + retObj.cmdLength + ') for seqNr: ' + retObj.seqNr + ' - retry with the stupid NULL byte for short_message');
|
||||
log.verbose(logPrefix + 'Offset (' + offset + ') !== cmdLength (' + retObj.cmdLength + ') for seqNr: ' + retObj.seqNr + ' - retry with the stupid NULL byte for short_message');
|
||||
|
||||
pduToObj(pdu, true, callback);
|
||||
return;
|
||||
return pduToObj(pdu, true, cb);
|
||||
}
|
||||
|
||||
if (offset !== retObj.cmdLength) {
|
||||
log.warn('larvitsmpp: lib/utils.js: pduToObj() - Offset (' + offset + ') !== cmdLength (' + retObj.cmdLength + ') for seqNr: ' + retObj.seqNr);
|
||||
log.warn(logPrefix + 'Offset (' + offset + ') !== cmdLength (' + retObj.cmdLength + ') for seqNr: ' + retObj.seqNr);
|
||||
}
|
||||
|
||||
// Decode the short message if it is set and esm_class is 0
|
||||
@@ -351,50 +335,50 @@ function pduToObj(pdu, stupidNullByte, callback) {
|
||||
retObj.params.short_message = decodeMsg(retObj.params.short_message, retObj.params.data_coding);
|
||||
}
|
||||
|
||||
log.debug('larvitsmpp: lib/utils.js: pduToObj() - Complete decoded PDU: ' + JSON.stringify(retObj));
|
||||
log.debug(logPrefix + 'Complete decoded PDU: ' + JSON.stringify(retObj));
|
||||
|
||||
callback(null, retObj);
|
||||
cb(null, retObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an object to a PDU
|
||||
*
|
||||
* @param {object} obj - example {'cmdName': 'bind_transceiver_resp', 'cmdStatus': 'ESME_ROK', 'seqNr': 2} - to add parameters add a key 'params' as object
|
||||
* @param {function} callback(err, pdu)
|
||||
* @param {function} cb - cb(err, pdu)
|
||||
*/
|
||||
function objToPdu(obj, callback) {
|
||||
var err = null,
|
||||
shortMsg,
|
||||
seqNr;
|
||||
function objToPdu(obj, cb) {
|
||||
const logPrefix = topLogPrefix + 'objToPdu() - ',
|
||||
seqNr = parseInt(obj.seqNr);
|
||||
|
||||
// Check so the command is ok
|
||||
if (defs.cmds[obj.cmdName] === undefined) {
|
||||
err = new Error('larvitsmpp: lib/utils.js: objToPdu() - Invalid cmdName: "' + obj.cmdName + '"');
|
||||
const err = new Error('Invalid cmdName: "' + obj.cmdName + '"');
|
||||
log.warn(logPrefix + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// Check so the command status is ok
|
||||
if (obj.cmdStatus === undefined) {
|
||||
// Default to OK
|
||||
obj.cmdStatus = 'ESME_ROK';
|
||||
obj.cmdStatus = 'ESME_ROK'; // Default to OK
|
||||
}
|
||||
|
||||
if (defs.errors[obj.cmdStatus] === undefined) {
|
||||
err = new Error('larvitsmpp: lib/utils.js: objToPdu() - Invalid cmdStatus: "' + obj.cmdStatus + '"');
|
||||
const err = new Error('Invalid cmdStatus: "' + obj.cmdStatus + '"');
|
||||
log.warn(logPrefix + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// Check so seqNr is ok
|
||||
seqNr = parseInt(obj.seqNr);
|
||||
if (isNaN(seqNr)) {
|
||||
err = new Error('larvitsmpp: lib/utils.js: objToPdu() - Invalid seqNr, is not an interger: "' + obj.seqNr + '"');
|
||||
} else if (seqNr > 2147483646) {
|
||||
err = new Error('larvitsmpp: lib/utils.js: objToPdu() - Invalid seqNr, maximum size of 2147483646 (0x7fffffff) exceeded.');
|
||||
const err = new Error('Invalid seqNr, is not an interger: "' + obj.seqNr + '"');
|
||||
log.warn(logPrefix + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// If error is found, do not proceed with execution
|
||||
if (err !== null) {
|
||||
log.warn(err.message);
|
||||
callback(err);
|
||||
return;
|
||||
if (seqNr > 2147483646) {
|
||||
const err = new Error('Invalid seqNr, maximum size of 2147483646 (0x7fffffff) exceeded.');
|
||||
log.warn(logPrefix + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// Params must be an object
|
||||
@@ -404,12 +388,13 @@ function objToPdu(obj, callback) {
|
||||
|
||||
// If param "short_message" exists, encode it and set parameter "data_coding" accordingly
|
||||
if (obj.params.short_message !== undefined && ! Buffer.isBuffer(obj.params.short_message)) {
|
||||
let shortMsg;
|
||||
|
||||
// Detect encoding if is not set already
|
||||
if (obj.params.data_coding === undefined) {
|
||||
obj.params.data_coding = defs.encodings.detect(obj.params.short_message);
|
||||
|
||||
log.silly('larvitsmpp: lib/utils.js: objToPdu() - data_coding "' + obj.params.data_coding + '" detected');
|
||||
log.silly(logPrefix + 'data_coding "' + obj.params.data_coding + '" detected');
|
||||
|
||||
// Now set the hex value
|
||||
obj.params.data_coding = defs.consts.ENCODING[obj.params.data_coding];
|
||||
@@ -418,20 +403,16 @@ 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') + '"');
|
||||
log.silly(logPrefix + 'Encoding message "' + shortMsg + '" to "' + obj.params.short_message.toString('hex') + '"');
|
||||
}
|
||||
|
||||
log.debug('larvitsmpp: lib/utils.js: objToPdu() - Complete object to encode: ' + JSON.stringify(obj));
|
||||
log.debug(logPrefix + 'Complete object to encode: ' + JSON.stringify(obj));
|
||||
|
||||
calcCmdLength(obj, function(err, cmdLength) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
calcCmdLength(obj, function (err, cmdLength) {
|
||||
if (err) return cb(err);
|
||||
|
||||
writeBuffer(obj, cmdLength, callback);
|
||||
writeBuffer(obj, cmdLength, cb);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -442,42 +423,40 @@ function objToPdu(obj, callback) {
|
||||
* @param {string} status - see list at defs.errors - defaults to 'ESME_ROK' - no error (OPTIONAL)
|
||||
* @param {object} [params]
|
||||
* @param {object} [tlvs]
|
||||
* @param {function} [callback(err, pduBuffer)]
|
||||
* @param {function} [cb(err, pduBuffer)]
|
||||
*/
|
||||
function pduReturn(pdu, status, params, tlvs, callback) {
|
||||
var err = null,
|
||||
retPdu = {},
|
||||
param;
|
||||
function pduReturn(pdu, status, params, tlvs, cb) {
|
||||
const logPrefix = topLogPrefix + 'pduReturn() - ',
|
||||
retPdu = {};
|
||||
|
||||
let err = null;
|
||||
|
||||
if (Buffer.isBuffer(pdu)) {
|
||||
log.silly('larvitsmpp: lib/utils.js: pduReturn() - ran with pdu as buffer, run pduToObj() and retry');
|
||||
log.silly(logPrefix + 'Ran with pdu as buffer, run pduToObj() and retry');
|
||||
|
||||
pduToObj(pdu, function(err, pduObj) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
pduToObj(pdu, function (err, pduObj) {
|
||||
if (err) return cb(err);
|
||||
|
||||
pduReturn(pduObj, status, params, tlvs, callback);
|
||||
pduReturn(pduObj, status, params, tlvs, cb);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
log.silly('larvitsmpp: lib/utils.js: pduReturn() - ran');
|
||||
log.silly(logPrefix + 'ran');
|
||||
|
||||
if (typeof tlvs === 'function') {
|
||||
callback = tlvs;
|
||||
cb = tlvs;
|
||||
tlvs = undefined;
|
||||
}
|
||||
|
||||
if (typeof params === 'function') {
|
||||
callback = params;
|
||||
cb = params;
|
||||
params = {};
|
||||
tlvs = undefined;
|
||||
}
|
||||
|
||||
if (typeof status === 'function') {
|
||||
callback = status;
|
||||
cb = status;
|
||||
status = 'ESME_ROK';
|
||||
params = {};
|
||||
tlvs = undefined;
|
||||
@@ -487,38 +466,23 @@ function pduReturn(pdu, status, params, tlvs, callback) {
|
||||
status = 'ESME_ROK';
|
||||
}
|
||||
|
||||
if (callback === undefined) {
|
||||
callback = function() {};
|
||||
if (cb === undefined) {
|
||||
cb = function () {};
|
||||
}
|
||||
|
||||
if (params === undefined) {
|
||||
params = {};
|
||||
}
|
||||
|
||||
if (pdu === undefined) {
|
||||
err = new Error('larvitsmpp: lib/utils.js: pduReturn() - PDU is undefined, cannot create response PDU');
|
||||
}
|
||||
|
||||
if (pdu.cmdName === undefined) {
|
||||
err = new Error('larvitsmpp: lib/utils.js: pduReturn() - pdu.cmdName is undefined, cannot create response PDU');
|
||||
}
|
||||
|
||||
if (pdu.seqNr === undefined) {
|
||||
err = new Error('larvitsmpp: lib/utils.js: pduReturn() - pdu.seqNr is undefined, cannot create response PDU');
|
||||
}
|
||||
|
||||
if (err === null && defs.errors[status] === undefined) {
|
||||
err = new Error('larvitsmpp: lib/utils.js: pduReturn() - Invalid status: "' + status + '"');
|
||||
}
|
||||
|
||||
if (err === null && defs.cmds[pdu.cmdName + '_resp'] === undefined) {
|
||||
err = new Error('larvitsmpp: lib/utils.js: pduReturn() - This command does not have a response listed. Given command: "' + pdu.cmdName + '"');
|
||||
}
|
||||
if (pdu === undefined) err = new Error('PDU is undefined, cannot create response PDU');
|
||||
if (pdu.cmdName === undefined) err = new Error('pdu.cmdName is undefined, cannot create response PDU');
|
||||
if (pdu.seqNr === undefined) err = new Error('pdu.seqNr is undefined, cannot create response PDU');
|
||||
if (err === null && defs.errors[status] === undefined) err = new Error('Invalid status: "' + status + '"');
|
||||
if (err === null && defs.cmds[pdu.cmdName + '_resp'] === undefined) err = new Error('This command does not have a response listed. Given command: "' + pdu.cmdName + '"');
|
||||
|
||||
if (err !== null) {
|
||||
log.warn(err.message);
|
||||
callback(err);
|
||||
return;
|
||||
log.warn(logPrefix + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
retPdu.cmdName = pdu.cmdName + '_resp';
|
||||
@@ -528,7 +492,7 @@ function pduReturn(pdu, status, params, tlvs, callback) {
|
||||
retPdu.tlvs = tlvs;
|
||||
|
||||
// Populate parameters that should exist in the response
|
||||
for (param in defs.cmds[pdu.cmdName + '_resp'].params) {
|
||||
for (const param in defs.cmds[pdu.cmdName + '_resp'].params) {
|
||||
|
||||
// Do not override the manually supplied parameters
|
||||
if (retPdu.params[param] === undefined) {
|
||||
@@ -536,9 +500,7 @@ function pduReturn(pdu, status, params, tlvs, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
objToPdu(retPdu, function(err, retPdu) {
|
||||
callback(err, retPdu);
|
||||
});
|
||||
objToPdu(retPdu, cb);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -548,7 +510,7 @@ function pduReturn(pdu, status, params, tlvs, callback) {
|
||||
* @return {string}
|
||||
*/
|
||||
function smppDate(jsDateObj) {
|
||||
var uglyStr = '';
|
||||
let uglyStr = '';
|
||||
|
||||
uglyStr += jsDateObj.getFullYear().toString().substring(2);
|
||||
|
||||
@@ -606,20 +568,20 @@ function bitCount(msg, encoding) {
|
||||
* @return array of buffers
|
||||
*/
|
||||
function splitMsg(msg, encoding) {
|
||||
var msgPart = '',
|
||||
msgs = [],
|
||||
encoding = encoding || defs.encodings.detect(msg),
|
||||
totBitCount = bitCount(msg, encoding),
|
||||
udh,
|
||||
i,
|
||||
i2,
|
||||
partCharLimit;
|
||||
const resolvedEncoding = encoding || defs.encodings.detect(msg),
|
||||
totBitCount = bitCount(msg, resolvedEncoding),
|
||||
logPrefix = topLogPrefix + 'splitMsg() - ',
|
||||
msgs = [];
|
||||
|
||||
let msgPart = '',
|
||||
partCharLimit,
|
||||
i2;
|
||||
|
||||
// A single message could contain up to 1120 bits
|
||||
// Return directly if the message fits into that
|
||||
if (totBitCount < 1121) {
|
||||
log.silly('larvitsmpp: lib/utils.js: splitMsg() - bitCount below 1121 (' + totBitCount + ') return only one part');
|
||||
return [defs.encodings[encoding].encode(msg)];
|
||||
log.silly(logPrefix + 'bitCount below 1121 (' + totBitCount + ') return only one part');
|
||||
return [defs.encodings[resolvedEncoding].encode(msg)];
|
||||
}
|
||||
|
||||
bundleMsgId ++; // This will identify this message "bundle"
|
||||
@@ -628,17 +590,16 @@ function splitMsg(msg, encoding) {
|
||||
bundleMsgId = 1;
|
||||
}
|
||||
|
||||
log.silly('larvitsmpp: lib/utils.js: splitMsg() - bundleMsgId set to ' + bundleMsgId);
|
||||
log.silly(logPrefix + 'bundleMsgId set to ' + bundleMsgId);
|
||||
|
||||
if (encoding === 'ASCII') {
|
||||
if (resolvedEncoding === 'ASCII') {
|
||||
partCharLimit = 153;
|
||||
} else {
|
||||
partCharLimit = 67;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
i2 = 0;
|
||||
while (msg[i] !== undefined) {
|
||||
for (let i = 0; msg[i] !== undefined; i ++) {
|
||||
msgPart += msg[i];
|
||||
|
||||
i2 ++;
|
||||
@@ -650,7 +611,7 @@ function splitMsg(msg, encoding) {
|
||||
i2 = 0;
|
||||
|
||||
// Add this msgPart minus the last character to the msgs array as an encoded buffer
|
||||
msgs.push(defs.encodings[encoding].encode(msgPart.slice(0, - 1)));
|
||||
msgs.push(defs.encodings[resolvedEncoding].encode(msgPart.slice(0, - 1)));
|
||||
|
||||
// Reset msgPart
|
||||
msgPart = '';
|
||||
@@ -658,19 +619,15 @@ function splitMsg(msg, encoding) {
|
||||
// Put i back one to account for the last character we removed from the msgPart
|
||||
i --;
|
||||
}
|
||||
|
||||
i ++;
|
||||
}
|
||||
|
||||
// Add the last msgPart to the msgs array
|
||||
msgs.push(defs.encodings[encoding].encode(msgPart));
|
||||
msgs.push(defs.encodings[resolvedEncoding].encode(msgPart));
|
||||
|
||||
// Add the UDH (http://en.wikipedia.org/wiki/Concatenated_SMS)
|
||||
i = 0;
|
||||
while (msgs[i] !== undefined) {
|
||||
|
||||
for (let i = 0; msgs[i] !== undefined; i ++) {
|
||||
// Create the UDH buffer
|
||||
udh = new Buffer([
|
||||
const udh = new Buffer([
|
||||
0x05, // Length of User Data Header, in this case 05.
|
||||
0x00, // Information Element Identifier, equal to 00 (Concatenated short messages, 8-bit reference number)
|
||||
0x03, // Length of the header, excluding the first two fields; equal to 03
|
||||
@@ -680,8 +637,6 @@ function splitMsg(msg, encoding) {
|
||||
]);
|
||||
|
||||
msgs[i] = Buffer.concat([udh, msgs[i]]);
|
||||
|
||||
i ++;
|
||||
}
|
||||
|
||||
return msgs;
|
||||
@@ -692,16 +647,17 @@ function splitMsg(msg, encoding) {
|
||||
* This must be called from an sms object context
|
||||
*
|
||||
* @param {string} status - see list at defs.consts.MESSAGE_STATE - defaults to 'DELIVERED'
|
||||
* @param {function} callback(err, retPdu, dlrPduObj)
|
||||
* @param {function} cb - cb(err, retPdu, dlrPduObj)
|
||||
*/
|
||||
function smsDlr(status, callback) {
|
||||
var shortMessage,
|
||||
dlrPduObj,
|
||||
err,
|
||||
function smsDlr(status, cb) {
|
||||
const logPrefix = topLogPrefix + 'smsDlr() - ',
|
||||
dlrPduObj = {},
|
||||
sms = this;
|
||||
|
||||
let shortMessage = 'id:' + sms.smsId + ' sub:001 ';
|
||||
|
||||
if (typeof status === 'function') {
|
||||
callback = status;
|
||||
cb = status;
|
||||
status = undefined;
|
||||
}
|
||||
|
||||
@@ -715,19 +671,16 @@ function smsDlr(status, callback) {
|
||||
status = 5; // UNDELIVERABLE
|
||||
}
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
callback = function() {};
|
||||
if (typeof cb !== 'function') {
|
||||
cb = function () {};
|
||||
}
|
||||
|
||||
if (sms.smsId === undefined) {
|
||||
err = new Error('Trying to send DLR with no smsId.');
|
||||
log.warn('larvitsmpp: lib/utils.js: smsDlr() - ' + err.message);
|
||||
callback(err);
|
||||
return;
|
||||
const err = new Error('Trying to send DLR with no smsId.');
|
||||
log.warn(logPrefix + err.message);
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
shortMessage = 'id:' + sms.smsId + ' sub:001 ';
|
||||
|
||||
if (status === 2) {
|
||||
shortMessage += 'dlvrd:1 ';
|
||||
} else {
|
||||
@@ -743,17 +696,16 @@ function smsDlr(status, callback) {
|
||||
shortMessage += ' stat:UNDELIVERABLE err:1 text:xxx';
|
||||
}
|
||||
|
||||
log.verbose('larvitsmpp: lib/utils.js: smsDlr() - Sending DLR message: "' + shortMessage + '"');
|
||||
log.verbose(logPrefix + 'Sending DLR message: "' + shortMessage + '"');
|
||||
|
||||
dlrPduObj = {
|
||||
'cmdName': 'deliver_sm',
|
||||
'params': {
|
||||
dlrPduObj.cmdName = 'deliver_sm';
|
||||
dlrPduObj.params = {
|
||||
'source_addr': sms.from,
|
||||
'destination_addr': sms.to,
|
||||
'esm_class': 4,
|
||||
'short_message': shortMessage
|
||||
},
|
||||
'tlvs': {
|
||||
};
|
||||
dlrPduObj.tlvs = {
|
||||
'receipted_message_id': {
|
||||
'tagId': 0x001E,
|
||||
'tagName': 'receipted_message_id',
|
||||
@@ -764,11 +716,10 @@ function smsDlr(status, callback) {
|
||||
'tagName': 'message_state',
|
||||
'tagValue': status
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
sms.session.send(dlrPduObj, false, function(err, retPdu) {
|
||||
callback(err, retPdu, dlrPduObj);
|
||||
sms.session.send(dlrPduObj, false, function (err, retPdu) {
|
||||
cb(err, retPdu, dlrPduObj);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Generated
+418
-141
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "larvitsmpp",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"abbrev": {
|
||||
@@ -54,9 +54,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"ansi-escapes": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-1.4.0.tgz",
|
||||
"integrity": "sha1-06ioOzGapneTZisT52HHkRQiMG4=",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-2.0.0.tgz",
|
||||
"integrity": "sha1-W65SvkJIeN2Xg+iRDj/Cki6DyBs=",
|
||||
"dev": true
|
||||
},
|
||||
"ansi-regex": {
|
||||
@@ -108,9 +108,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"async": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz",
|
||||
"integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo="
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-2.4.1.tgz",
|
||||
"integrity": "sha1-YqVrJ5yYoR0JhwlqAcw+6463u9c="
|
||||
},
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
@@ -130,6 +130,12 @@
|
||||
"integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=",
|
||||
"dev": true
|
||||
},
|
||||
"babel-code-frame": {
|
||||
"version": "6.22.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.22.0.tgz",
|
||||
"integrity": "sha1-AnYgvuVnqIwyVhV05/0IAdMxGOQ=",
|
||||
"dev": true
|
||||
},
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
@@ -155,6 +161,12 @@
|
||||
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
|
||||
"dev": true
|
||||
},
|
||||
"browser-stdout": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz",
|
||||
"integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=",
|
||||
"dev": true
|
||||
},
|
||||
"caller-path": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz",
|
||||
@@ -200,9 +212,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"cli-cursor": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-1.0.2.tgz",
|
||||
"integrity": "sha1-ZNo/fValRBLll5S9Ytw1KV6PKYc=",
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz",
|
||||
"integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=",
|
||||
"dev": true
|
||||
},
|
||||
"cli-width": {
|
||||
@@ -343,15 +355,15 @@
|
||||
"dev": true
|
||||
},
|
||||
"diff": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-1.4.0.tgz",
|
||||
"integrity": "sha1-fyjS657nsVqX79ic5j3P2qPMur8=",
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz",
|
||||
"integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=",
|
||||
"dev": true
|
||||
},
|
||||
"doctrine": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz",
|
||||
"integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.0.0.tgz",
|
||||
"integrity": "sha1-xz2NKQnSIpHhoAejlYBNqLZl/mM=",
|
||||
"dev": true
|
||||
},
|
||||
"ecc-jsbn": {
|
||||
@@ -424,9 +436,29 @@
|
||||
"dev": true
|
||||
},
|
||||
"eslint": {
|
||||
"version": "2.13.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-2.13.1.tgz",
|
||||
"integrity": "sha1-5MyPoPAJ+4KaquI4VaKTYL4fbBE=",
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-4.1.0.tgz",
|
||||
"integrity": "sha1-u7VaKCIO4Itp2pVU1FprLr/X2RM=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"esprima": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-3.1.3.tgz",
|
||||
"integrity": "sha1-/cpRzuYTOJXjyI1TXOSdv/YqRjM=",
|
||||
"dev": true
|
||||
},
|
||||
"js-yaml": {
|
||||
"version": "3.8.4",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.8.4.tgz",
|
||||
"integrity": "sha1-UgtFZPhlc7qWZir4Woyvp7S1pvY=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"eslint-scope": {
|
||||
"version": "3.7.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz",
|
||||
"integrity": "sha1-PWPD7f2gLgbgGkUq2IyqzHzctug=",
|
||||
"dev": true
|
||||
},
|
||||
"espree": {
|
||||
@@ -441,6 +473,12 @@
|
||||
"integrity": "sha1-luO3DVd59q1JzQMmc9HDEnZ7pYE=",
|
||||
"dev": true
|
||||
},
|
||||
"esquery": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.0.tgz",
|
||||
"integrity": "sha1-z7qLV9f7qT8XKYqKAGoEzaE9gPo=",
|
||||
"dev": true
|
||||
},
|
||||
"esrecurse": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.0.tgz",
|
||||
@@ -477,6 +515,12 @@
|
||||
"integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=",
|
||||
"dev": true
|
||||
},
|
||||
"external-editor": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.0.4.tgz",
|
||||
"integrity": "sha1-HtkZnanL/i7y96MbL96LDRI2iXI=",
|
||||
"dev": true
|
||||
},
|
||||
"extsprintf": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.0.2.tgz",
|
||||
@@ -495,15 +539,15 @@
|
||||
"dev": true
|
||||
},
|
||||
"figures": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz",
|
||||
"integrity": "sha1-y+Hjr/zxzUS4DK3+0o3Hk6lwHS4=",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz",
|
||||
"integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=",
|
||||
"dev": true
|
||||
},
|
||||
"file-entry-cache": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-1.3.1.tgz",
|
||||
"integrity": "sha1-RMYepgeuS+nBQC9B9EJwy/4zT/g=",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-2.0.0.tgz",
|
||||
"integrity": "sha1-w5KZDD5oR4PYOLjISkXYoEhFg2E=",
|
||||
"dev": true
|
||||
},
|
||||
"flat-cache": {
|
||||
@@ -562,6 +606,26 @@
|
||||
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
|
||||
"dev": true
|
||||
},
|
||||
"glob-all": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/glob-all/-/glob-all-3.1.0.tgz",
|
||||
"integrity": "sha1-iRPd+17hrHgSZWJBsD1SF8ZLAqs=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"minimist": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.1.0.tgz",
|
||||
"integrity": "sha1-md9lelJXTCHJBXSX33QnkLK0wN4=",
|
||||
"dev": true
|
||||
},
|
||||
"yargs": {
|
||||
"version": "1.2.6",
|
||||
"resolved": "https://registry.npmjs.org/yargs/-/yargs-1.2.6.tgz",
|
||||
"integrity": "sha1-nHtKgv1dWVsr8Xq23MQxNUMv40s=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"globals": {
|
||||
"version": "9.18.0",
|
||||
"resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz",
|
||||
@@ -598,6 +662,12 @@
|
||||
"integrity": "sha1-PTDHGLCaPZbyPqTMH0A8TTup/08=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"async": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz",
|
||||
"integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=",
|
||||
"dev": true
|
||||
},
|
||||
"source-map": {
|
||||
"version": "0.4.4",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz",
|
||||
@@ -672,9 +742,15 @@
|
||||
"dev": true
|
||||
},
|
||||
"inquirer": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/inquirer/-/inquirer-0.12.0.tgz",
|
||||
"integrity": "sha1-HvK/1jUE3wvHV4X/+MLEHfEvB34=",
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.1.1.tgz",
|
||||
"integrity": "sha512-H50sHQwgvvaTBd3HpKMVtL/u6LoHDvYym51gd7bGQe/+9HkCE+J0/3N5FJLfd6O6oz44hHewC2Pc2LodzWVafQ==",
|
||||
"dev": true
|
||||
},
|
||||
"interpret": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/interpret/-/interpret-1.0.3.tgz",
|
||||
"integrity": "sha1-y8NcYu7uc/Gat7EKgBURQBr8D5A=",
|
||||
"dev": true
|
||||
},
|
||||
"is-buffer": {
|
||||
@@ -684,9 +760,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"is-fullwidth-code-point": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
|
||||
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
|
||||
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
|
||||
"dev": true
|
||||
},
|
||||
"is-my-json-valid": {
|
||||
@@ -713,6 +789,12 @@
|
||||
"integrity": "sha1-/AbloWg/vaE95mev9xe7wQpI838=",
|
||||
"dev": true
|
||||
},
|
||||
"is-promise": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz",
|
||||
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=",
|
||||
"dev": true
|
||||
},
|
||||
"is-property": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz",
|
||||
@@ -754,6 +836,12 @@
|
||||
"integrity": "sha1-ZcfXPUxNqE1POsMQuRj7C4Azczs=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"async": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz",
|
||||
"integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=",
|
||||
"dev": true
|
||||
},
|
||||
"glob": {
|
||||
"version": "5.0.15",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-5.0.15.tgz",
|
||||
@@ -768,26 +856,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"jade": {
|
||||
"version": "0.26.3",
|
||||
"resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz",
|
||||
"integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"commander": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz",
|
||||
"integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=",
|
||||
"js-tokens": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.1.tgz",
|
||||
"integrity": "sha1-COnxMkhKLEWjCQfp3E1VZ7fxFNc=",
|
||||
"dev": true
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz",
|
||||
"integrity": "sha1-G79asbqCevI1dRQ0kEJkVfSB/h4=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"js-yaml": {
|
||||
"version": "3.6.1",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.6.1.tgz",
|
||||
@@ -801,6 +875,12 @@
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"jschardet": {
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/jschardet/-/jschardet-1.4.2.tgz",
|
||||
"integrity": "sha1-KqEH8UKvQSHRRWWdRPUIMJYeaZo=",
|
||||
"dev": true
|
||||
},
|
||||
"json-schema": {
|
||||
"version": "0.2.3",
|
||||
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz",
|
||||
@@ -819,6 +899,12 @@
|
||||
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=",
|
||||
"dev": true
|
||||
},
|
||||
"json3": {
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz",
|
||||
"integrity": "sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE=",
|
||||
"dev": true
|
||||
},
|
||||
"jsonify": {
|
||||
"version": "0.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz",
|
||||
@@ -873,7 +959,60 @@
|
||||
"lodash": {
|
||||
"version": "4.17.4",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz",
|
||||
"integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=",
|
||||
"integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4="
|
||||
},
|
||||
"lodash._baseassign": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz",
|
||||
"integrity": "sha1-jDigmVAPIVrQnlnxci/QxSv+Ck4=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash._basecopy": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz",
|
||||
"integrity": "sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash._basecreate": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz",
|
||||
"integrity": "sha1-G8ZhYU2qf8MRt9A78WgGoCE8+CE=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash._getnative": {
|
||||
"version": "3.9.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz",
|
||||
"integrity": "sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash._isiterateecall": {
|
||||
"version": "3.0.9",
|
||||
"resolved": "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz",
|
||||
"integrity": "sha1-UgOte6Ql+uhCRg5pbbnPPmqsBXw=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.create": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.create/-/lodash.create-3.1.1.tgz",
|
||||
"integrity": "sha1-1/KEnw29p+BGgruM1yqwIkYd6+c=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.isarguments": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz",
|
||||
"integrity": "sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.isarray": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz",
|
||||
"integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.keys": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz",
|
||||
"integrity": "sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo=",
|
||||
"dev": true
|
||||
},
|
||||
"log-driver": {
|
||||
@@ -888,12 +1027,6 @@
|
||||
"integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=",
|
||||
"dev": true
|
||||
},
|
||||
"lru-cache": {
|
||||
"version": "2.7.3",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz",
|
||||
"integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=",
|
||||
"dev": true
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.27.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz",
|
||||
@@ -906,6 +1039,12 @@
|
||||
"integrity": "sha1-pOv1BkCUVpI3uM9wBGd20J/JKu0=",
|
||||
"dev": true
|
||||
},
|
||||
"mimic-fn": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.1.0.tgz",
|
||||
"integrity": "sha1-5md4PZLonb00KBi1IwudYqZyrRg=",
|
||||
"dev": true
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
@@ -933,55 +1072,149 @@
|
||||
}
|
||||
},
|
||||
"mocha": {
|
||||
"version": "2.5.3",
|
||||
"resolved": "https://registry.npmjs.org/mocha/-/mocha-2.5.3.tgz",
|
||||
"integrity": "sha1-FhvlvetJZ3HrmzV0UFC2IrWu/Fg=",
|
||||
"version": "3.4.2",
|
||||
"resolved": "https://registry.npmjs.org/mocha/-/mocha-3.4.2.tgz",
|
||||
"integrity": "sha1-0O9NMyEm2/GNDWQMmzgt1IvpdZQ=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"commander": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.3.0.tgz",
|
||||
"integrity": "sha1-/UMOiJgy7DU7ms0d4hfBHLPu+HM=",
|
||||
"version": "2.9.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz",
|
||||
"integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=",
|
||||
"dev": true
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz",
|
||||
"integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=",
|
||||
"dev": true
|
||||
},
|
||||
"escape-string-regexp": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz",
|
||||
"integrity": "sha1-Tbwv5nTnGUnK8/smlc5/LcHZqNE=",
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.0.tgz",
|
||||
"integrity": "sha1-vFlryr52F/Edn6FTYe3tVgi4SZs=",
|
||||
"dev": true
|
||||
},
|
||||
"glob": {
|
||||
"version": "3.2.11",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz",
|
||||
"integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=",
|
||||
"dev": true
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz",
|
||||
"integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=",
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz",
|
||||
"integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=",
|
||||
"dev": true
|
||||
},
|
||||
"ms": {
|
||||
"version": "0.7.1",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz",
|
||||
"integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg=",
|
||||
"version": "0.7.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-0.7.2.tgz",
|
||||
"integrity": "sha1-riXPJRKziFodldfwN4aNhDESR2U=",
|
||||
"dev": true
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-1.2.0.tgz",
|
||||
"integrity": "sha1-/x7R5hFp0Gs88tWI4YixjYhH4X4=",
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.1.2.tgz",
|
||||
"integrity": "sha1-cqJiiU2dQIuVbKBf83su2KbiotU=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"mocha-eslint": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/mocha-eslint/-/mocha-eslint-3.0.1.tgz",
|
||||
"integrity": "sha1-rnKrxWHLKJ0ubBQ3iO4YKsoaBNs=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ansi-escapes": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-1.4.0.tgz",
|
||||
"integrity": "sha1-06ioOzGapneTZisT52HHkRQiMG4=",
|
||||
"dev": true
|
||||
},
|
||||
"cli-cursor": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-1.0.2.tgz",
|
||||
"integrity": "sha1-ZNo/fValRBLll5S9Ytw1KV6PKYc=",
|
||||
"dev": true
|
||||
},
|
||||
"eslint": {
|
||||
"version": "3.19.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-3.19.0.tgz",
|
||||
"integrity": "sha1-yPxiAcf0DdCJQbh8CFdnOGpnmsw=",
|
||||
"dev": true
|
||||
},
|
||||
"figures": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz",
|
||||
"integrity": "sha1-y+Hjr/zxzUS4DK3+0o3Hk6lwHS4=",
|
||||
"dev": true
|
||||
},
|
||||
"inquirer": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/inquirer/-/inquirer-0.12.0.tgz",
|
||||
"integrity": "sha1-HvK/1jUE3wvHV4X/+MLEHfEvB34=",
|
||||
"dev": true
|
||||
},
|
||||
"is-fullwidth-code-point": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
|
||||
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
|
||||
"dev": true
|
||||
},
|
||||
"onetime": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
|
||||
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=",
|
||||
"dev": true
|
||||
},
|
||||
"pluralize": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/pluralize/-/pluralize-1.2.1.tgz",
|
||||
"integrity": "sha1-0aIUg/0iu0HlihL6NCGCMUCJfEU=",
|
||||
"dev": true
|
||||
},
|
||||
"progress": {
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz",
|
||||
"integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74=",
|
||||
"dev": true
|
||||
},
|
||||
"restore-cursor": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-1.0.1.tgz",
|
||||
"integrity": "sha1-NGYfRohjJ/7SmRR5FSJS35LapUE=",
|
||||
"dev": true
|
||||
},
|
||||
"run-async": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/run-async/-/run-async-0.1.0.tgz",
|
||||
"integrity": "sha1-yK1KXhEGYeQCp9IbUw4AnyX444k=",
|
||||
"dev": true
|
||||
},
|
||||
"rx-lite": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-3.1.2.tgz",
|
||||
"integrity": "sha1-Gc5QLKVyZl87ZHsQk5+X/RYV8QI=",
|
||||
"dev": true
|
||||
},
|
||||
"string-width": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
|
||||
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
|
||||
"dev": true
|
||||
},
|
||||
"table": {
|
||||
"version": "3.8.3",
|
||||
"resolved": "https://registry.npmjs.org/table/-/table-3.8.3.tgz",
|
||||
"integrity": "sha1-K7xULw/amGGnVdOUf+/Ys/UThV8=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"is-fullwidth-code-point": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
|
||||
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
|
||||
"dev": true
|
||||
},
|
||||
"string-width": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.0.0.tgz",
|
||||
"integrity": "sha1-Y1xUNsxypuDDh87KJ41OLuxSaH4=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"moment": {
|
||||
"version": "2.18.1",
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.18.1.tgz",
|
||||
@@ -994,9 +1227,15 @@
|
||||
"dev": true
|
||||
},
|
||||
"mute-stream": {
|
||||
"version": "0.0.5",
|
||||
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.5.tgz",
|
||||
"integrity": "sha1-j7+rsKmKJT0xhDMfno3rc3L6xsA=",
|
||||
"version": "0.0.7",
|
||||
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz",
|
||||
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=",
|
||||
"dev": true
|
||||
},
|
||||
"natural-compare": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
|
||||
"integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=",
|
||||
"dev": true
|
||||
},
|
||||
"nopt": {
|
||||
@@ -1030,9 +1269,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"onetime": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
|
||||
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=",
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz",
|
||||
"integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=",
|
||||
"dev": true
|
||||
},
|
||||
"optimist": {
|
||||
@@ -1067,6 +1306,12 @@
|
||||
"integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=",
|
||||
"dev": true
|
||||
},
|
||||
"os-tmpdir": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
|
||||
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=",
|
||||
"dev": true
|
||||
},
|
||||
"path-is-absolute": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||
@@ -1098,16 +1343,24 @@
|
||||
"dev": true
|
||||
},
|
||||
"pluralize": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/pluralize/-/pluralize-1.2.1.tgz",
|
||||
"integrity": "sha1-0aIUg/0iu0HlihL6NCGCMUCJfEU=",
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pluralize/-/pluralize-4.0.0.tgz",
|
||||
"integrity": "sha1-WbcIwcAZCi9pLxx2GMRGsFL9F2I=",
|
||||
"dev": true
|
||||
},
|
||||
"portfinder": {
|
||||
"version": "1.0.13",
|
||||
"resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.13.tgz",
|
||||
"integrity": "sha1-uzLs2HwnEErm7kS1o8y/Drsa7ek=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"async": {
|
||||
"version": "1.5.2",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz",
|
||||
"integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"prelude-ls": {
|
||||
"version": "1.1.2",
|
||||
@@ -1122,9 +1375,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"progress": {
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz",
|
||||
"integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74=",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz",
|
||||
"integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8=",
|
||||
"dev": true
|
||||
},
|
||||
"punycode": {
|
||||
@@ -1149,6 +1402,26 @@
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/readline2/-/readline2-1.0.1.tgz",
|
||||
"integrity": "sha1-QQWWCP/BVHV7cV2ZidGZ/783LjU=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"is-fullwidth-code-point": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
|
||||
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
|
||||
"dev": true
|
||||
},
|
||||
"mute-stream": {
|
||||
"version": "0.0.5",
|
||||
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.5.tgz",
|
||||
"integrity": "sha1-j7+rsKmKJT0xhDMfno3rc3L6xsA=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"rechoir": {
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz",
|
||||
"integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=",
|
||||
"dev": true
|
||||
},
|
||||
"repeat-string": {
|
||||
@@ -1157,6 +1430,12 @@
|
||||
"integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=",
|
||||
"dev": true
|
||||
},
|
||||
"replaceall": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/replaceall/-/replaceall-0.1.6.tgz",
|
||||
"integrity": "sha1-gdgax663LX9cSUKt8ml6MiBojY4=",
|
||||
"dev": true
|
||||
},
|
||||
"request": {
|
||||
"version": "2.79.0",
|
||||
"resolved": "https://registry.npmjs.org/request/-/request-2.79.0.tgz",
|
||||
@@ -1182,9 +1461,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"restore-cursor": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-1.0.1.tgz",
|
||||
"integrity": "sha1-NGYfRohjJ/7SmRR5FSJS35LapUE=",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz",
|
||||
"integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=",
|
||||
"dev": true
|
||||
},
|
||||
"right-align": {
|
||||
@@ -1201,15 +1480,21 @@
|
||||
"dev": true
|
||||
},
|
||||
"run-async": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/run-async/-/run-async-0.1.0.tgz",
|
||||
"integrity": "sha1-yK1KXhEGYeQCp9IbUw4AnyX444k=",
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz",
|
||||
"integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=",
|
||||
"dev": true
|
||||
},
|
||||
"rx-lite": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-3.1.2.tgz",
|
||||
"integrity": "sha1-Gc5QLKVyZl87ZHsQk5+X/RYV8QI=",
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz",
|
||||
"integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=",
|
||||
"dev": true
|
||||
},
|
||||
"rx-lite-aggregates": {
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz",
|
||||
"integrity": "sha1-dTuHqJoRyVRnxKwWJsTvxOBcZ74=",
|
||||
"dev": true
|
||||
},
|
||||
"safe-buffer": {
|
||||
@@ -1219,15 +1504,15 @@
|
||||
"dev": true
|
||||
},
|
||||
"shelljs": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.6.1.tgz",
|
||||
"integrity": "sha1-7GIRvtGSBEIIj+D3Cyg3Iy7SyKg=",
|
||||
"version": "0.7.8",
|
||||
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.7.8.tgz",
|
||||
"integrity": "sha1-3svPh0sNHl+3LhSxZKloMEjprLM=",
|
||||
"dev": true
|
||||
},
|
||||
"sigmund": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz",
|
||||
"integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=",
|
||||
"signal-exit": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
|
||||
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
|
||||
"dev": true
|
||||
},
|
||||
"slice-ansi": {
|
||||
@@ -1281,9 +1566,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"string-width": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
|
||||
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.0.0.tgz",
|
||||
"integrity": "sha1-Y1xUNsxypuDDh87KJ41OLuxSaH4=",
|
||||
"dev": true
|
||||
},
|
||||
"stringstream": {
|
||||
@@ -1298,10 +1583,16 @@
|
||||
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
|
||||
"dev": true
|
||||
},
|
||||
"strip-bom": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz",
|
||||
"integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=",
|
||||
"dev": true
|
||||
},
|
||||
"strip-json-comments": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz",
|
||||
"integrity": "sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=",
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",
|
||||
"integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=",
|
||||
"dev": true
|
||||
},
|
||||
"supports-color": {
|
||||
@@ -1311,25 +1602,11 @@
|
||||
"dev": true
|
||||
},
|
||||
"table": {
|
||||
"version": "3.8.3",
|
||||
"resolved": "https://registry.npmjs.org/table/-/table-3.8.3.tgz",
|
||||
"integrity": "sha1-K7xULw/amGGnVdOUf+/Ys/UThV8=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"is-fullwidth-code-point": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
|
||||
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/table/-/table-4.0.1.tgz",
|
||||
"integrity": "sha1-qBFsEz+sLGH0pCCrbN9cTWHw5DU=",
|
||||
"dev": true
|
||||
},
|
||||
"string-width": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.0.0.tgz",
|
||||
"integrity": "sha1-Y1xUNsxypuDDh87KJ41OLuxSaH4=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"text-table": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
|
||||
@@ -1342,10 +1619,10 @@
|
||||
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
|
||||
"dev": true
|
||||
},
|
||||
"to-iso-string": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/to-iso-string/-/to-iso-string-0.0.2.tgz",
|
||||
"integrity": "sha1-TcGeZk38y+Jb2NtQiwDG2hWCVdE=",
|
||||
"tmp": {
|
||||
"version": "0.0.31",
|
||||
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.31.tgz",
|
||||
"integrity": "sha1-jzirlDjhcxXl29izZX6L+yd65Kc=",
|
||||
"dev": true
|
||||
},
|
||||
"tough-cookie": {
|
||||
|
||||
+8
-7
@@ -9,18 +9,19 @@
|
||||
"private": false,
|
||||
"contributors": [],
|
||||
"dependencies": {
|
||||
"async": "^1.5.2",
|
||||
"iconv-lite": "^0.4.13",
|
||||
"moment": "^2.13.0",
|
||||
"async": "^2.4.1",
|
||||
"iconv-lite": "^0.4.18",
|
||||
"moment": "^2.18.1",
|
||||
"utils-merge": "^1.0.0",
|
||||
"winston": "^2.2.0"
|
||||
"winston": "^2.3.1"
|
||||
},
|
||||
"description": "Simplified SMPP implementation",
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.11.9",
|
||||
"eslint": "^2.11.1",
|
||||
"eslint": "^4.1.0",
|
||||
"istanbul": "^0.4.3",
|
||||
"mocha": "^2.5.3",
|
||||
"mocha": "^3.4.2",
|
||||
"mocha-eslint": "^3.0.1",
|
||||
"portfinder": "^1.0.3"
|
||||
},
|
||||
"keywords": [
|
||||
@@ -28,7 +29,7 @@
|
||||
"pdu",
|
||||
"sms"
|
||||
],
|
||||
"main": "larvitsmpp.js",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"url": "https://github.com/larvit/larvitsmpp",
|
||||
"type": "git"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var log = require('winston');
|
||||
const log = require('winston');
|
||||
|
||||
// Remove log output to the console
|
||||
log.remove(log.transports.Console);
|
||||
+48
-66
@@ -1,21 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert'),
|
||||
encodings = require('../lib/defs').encodings;
|
||||
const encodings = require(__dirname + '/../lib/defs.js').encodings,
|
||||
assert = require('assert');
|
||||
|
||||
describe('encodings', function() {
|
||||
describe('ASCII', function() {
|
||||
var ASCII = encodings.ASCII,
|
||||
samples;
|
||||
describe('encodings', function () {
|
||||
describe('ASCII', function () {
|
||||
const samples = {},
|
||||
ASCII = encodings.ASCII;
|
||||
|
||||
samples = {
|
||||
'@£$¥': [0, 1, 2, 3],
|
||||
' 1a=': [0x20, 0x31, 0x61, 0x3D],
|
||||
'~^€': [0x1B, 0x3D, 0x1B, 0x14, 0x1B, 0x65]
|
||||
};
|
||||
samples['@£$¥'] = [0, 1, 2, 3];
|
||||
samples[' 1a='] = [0x20, 0x31, 0x61, 0x3D];
|
||||
samples['~^€'] = [0x1B, 0x3D, 0x1B, 0x14, 0x1B, 0x65];
|
||||
|
||||
describe('#match()', function() {
|
||||
it('should return true for strings that can be encoded using GSM 03.38 ASCII charset', function() {
|
||||
describe('#match()', function () {
|
||||
it('should return true for strings that can be encoded using GSM 03.38 ASCII charset', function () {
|
||||
assert(ASCII.match(''));
|
||||
assert(ASCII.match('@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1BÆæßÉ !"#¤%&\''));
|
||||
assert(ASCII.match('()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZ'));
|
||||
@@ -23,88 +21,76 @@ describe('encodings', function() {
|
||||
assert(ASCII.match('\f^{}\\[~]|€'));
|
||||
});
|
||||
|
||||
it('should return false for strings that can not be encoded using GSM 03.38 ASCII charset', function() {
|
||||
it('should return false for strings that can not be encoded using GSM 03.38 ASCII charset', function () {
|
||||
assert( ! ASCII.match('`'));
|
||||
assert( ! ASCII.match('ÁáçÚUÓO'));
|
||||
assert( ! ASCII.match('تست'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('#encode', function() {
|
||||
it('should properly encode the given string using GSM 03.38 ASCII charset', function() {
|
||||
var str;
|
||||
|
||||
for (str in samples) {
|
||||
describe('#encode', function () {
|
||||
it('should properly encode the given string using GSM 03.38 ASCII charset', function () {
|
||||
for (const str in samples) {
|
||||
assert.deepEqual(ASCII.encode(str), new Buffer(samples[str]));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#decode', function() {
|
||||
it('should properly decode the given buffer using GSM 03.38 ASCII charset', function() {
|
||||
var str;
|
||||
|
||||
for (str in samples) {
|
||||
describe('#decode', function () {
|
||||
it('should properly decode the given buffer using GSM 03.38 ASCII charset', function () {
|
||||
for (const str in samples) {
|
||||
assert.deepEqual(ASCII.decode(samples[str]), str);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('LATIN1', function() {
|
||||
var LATIN1 = encodings.LATIN1,
|
||||
samples;
|
||||
describe('LATIN1', function () {
|
||||
const samples = {},
|
||||
LATIN1 = encodings.LATIN1;
|
||||
|
||||
samples = {
|
||||
'@$`Á': [0x40, 0x24, 0x60, 0xC1],
|
||||
'áçÚ': [0xE1, 0xE7, 0xDA],
|
||||
'UÓO': [0x55, 0xD3, 0x4F]
|
||||
};
|
||||
samples['@$`Á'] = [0x40, 0x24, 0x60, 0xC1];
|
||||
samples['áçÚ'] = [0xE1, 0xE7, 0xDA];
|
||||
samples['UÓO'] = [0x55, 0xD3, 0x4F];
|
||||
|
||||
describe('#match()', function() {
|
||||
it('should return false for strings that can be encoded using LATIN1 charset', function() {
|
||||
describe('#match()', function () {
|
||||
it('should return false for strings that can be encoded using LATIN1 charset', function () {
|
||||
assert( ! LATIN1.match('`ÁáçÚUÓO'));
|
||||
});
|
||||
|
||||
it('should return false for strings that can not be encoded using LATIN1 charset', function() {
|
||||
it('should return false for strings that can not be encoded using LATIN1 charset', function () {
|
||||
assert( ! LATIN1.match('تست'));
|
||||
assert( ! LATIN1.match('۱۲۳۴۵۶۷۸۹۰'));
|
||||
assert( ! LATIN1.match('ʹʺʻʼʽ`'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('#encode', function() {
|
||||
it('should properly encode the given string using LATIN1 charset', function() {
|
||||
var str;
|
||||
|
||||
for (str in samples) {
|
||||
describe('#encode', function () {
|
||||
it('should properly encode the given string using LATIN1 charset', function () {
|
||||
for (const str in samples) {
|
||||
assert.deepEqual(LATIN1.encode(str), new Buffer(samples[str]));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#decode', function() {
|
||||
it('should properly decode the given buffer using LATIN1 charset', function() {
|
||||
var str;
|
||||
|
||||
for (str in samples) {
|
||||
describe('#decode', function () {
|
||||
it('should properly decode the given buffer using LATIN1 charset', function () {
|
||||
for (const str in samples) {
|
||||
assert.deepEqual(LATIN1.decode(new Buffer(samples[str])), str);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('UCS2', function() {
|
||||
var UCS2 = encodings.UCS2,
|
||||
samples;
|
||||
describe('UCS2', function () {
|
||||
const samples = {},
|
||||
UCS2 = encodings.UCS2;
|
||||
|
||||
samples = {
|
||||
' 1a': [0x00, 0x20, 0x00, 0x31, 0x00, 0x61],
|
||||
'۱۲۳': [0x06, 0xF1, 0x06, 0xF2, 0x06, 0xF3]
|
||||
};
|
||||
samples[' 1a'] = [0x00, 0x20, 0x00, 0x31, 0x00, 0x61];
|
||||
samples['۱۲۳'] = [0x06, 0xF1, 0x06, 0xF2, 0x06, 0xF3];
|
||||
|
||||
describe('#match()', function() {
|
||||
it('should always return true', function() {
|
||||
describe('#match()', function () {
|
||||
it('should always return true', function () {
|
||||
assert(UCS2.match(''));
|
||||
assert(UCS2.match('`ÁáçÚUÓO'));
|
||||
assert(UCS2.match('تست'));
|
||||
@@ -113,29 +99,25 @@ describe('encodings', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#encode', function() {
|
||||
it('should properly encode the given string using UCS2 charset', function() {
|
||||
var str;
|
||||
|
||||
for (str in samples) {
|
||||
describe('#encode', function () {
|
||||
it('should properly encode the given string using UCS2 charset', function () {
|
||||
for (const str in samples) {
|
||||
assert.deepEqual(UCS2.encode(str), new Buffer(samples[str]));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#decode', function() {
|
||||
it('should properly decode the given buffer using UCS2 charset', function() {
|
||||
var str;
|
||||
|
||||
for (str in samples) {
|
||||
describe('#decode', function () {
|
||||
it('should properly decode the given buffer using UCS2 charset', function () {
|
||||
for (const str in samples) {
|
||||
assert.deepEqual(UCS2.decode(samples[str]), str);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#detect()', function() {
|
||||
it('should return proper encoding for the given string', function() {
|
||||
describe('#detect()', function () {
|
||||
it('should return proper encoding for the given string', function () {
|
||||
assert.equal(encodings.detect(''), 'ASCII');
|
||||
assert.equal(encodings.detect('ÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà(){}[]'), 'ASCII');
|
||||
assert.equal(encodings.detect('`ÁáçÚUÓO'), 'UCS2');
|
||||
|
||||
+107
-114
@@ -1,242 +1,235 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert'),
|
||||
types = require('../lib/defs').types;
|
||||
const assert = require('assert'),
|
||||
types = require(__dirname + '/../lib/defs.js').types;
|
||||
|
||||
describe('int8', function() {
|
||||
var b = new Buffer([0, 0x65]), expected = 0x65;
|
||||
describe('int8', function () {
|
||||
const expected = 0x65,
|
||||
b = new Buffer([0, 0x65]);
|
||||
|
||||
describe('#read()', function() {
|
||||
it('should read one byte as integer', function() {
|
||||
var result = types.int8.read(b, 1);
|
||||
describe('#read()', function () {
|
||||
it('should read one byte as integer', function () {
|
||||
const result = types.int8.read(b, 1);
|
||||
assert.equal(result, expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#size()', function() {
|
||||
it('should return 1', function() {
|
||||
describe('#size()', function () {
|
||||
it('should return 1', function () {
|
||||
assert.equal(types.int8.size(expected), 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#write()', function() {
|
||||
it('should write one byte to the buffer', function() {
|
||||
describe('#write()', function () {
|
||||
it('should write one byte to the buffer', function () {
|
||||
types.int8.write(expected, b, 0);
|
||||
assert.deepEqual(new Buffer([0x65]), b.slice(0, 1));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('int16', function() {
|
||||
var b = new Buffer([0, 0x05, 0x65]), expected = 0x0565;
|
||||
describe('int16', function () {
|
||||
const expected = 0x0565,
|
||||
b = new Buffer([0, 0x05, 0x65]);
|
||||
|
||||
describe('#read()', function() {
|
||||
it('should read 2 bytes as integer', function() {
|
||||
var result = types.int16.read(b, 1);
|
||||
describe('#read()', function () {
|
||||
it('should read 2 bytes as integer', function () {
|
||||
const result = types.int16.read(b, 1);
|
||||
assert.equal(result, expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#size()', function() {
|
||||
it('should return 2', function() {
|
||||
describe('#size()', function () {
|
||||
it('should return 2', function () {
|
||||
assert.equal(types.int16.size(expected), 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#write()', function() {
|
||||
it('should write 2 bytes to the buffer', function() {
|
||||
describe('#write()', function () {
|
||||
it('should write 2 bytes to the buffer', function () {
|
||||
types.int16.write(expected, b, 0);
|
||||
assert.deepEqual(new Buffer([0x05, 0x65]), b.slice(0, 2));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('int32', function() {
|
||||
var b = new Buffer([0, 0x10, 0x02, 0x40, 0x45]), expected = 0x10024045;
|
||||
describe('int32', function () {
|
||||
const expected = 0x10024045,
|
||||
b = new Buffer([0, 0x10, 0x02, 0x40, 0x45]);
|
||||
|
||||
describe('#read()', function() {
|
||||
it('should read 4 bytes as integer', function() {
|
||||
var result = types.int32.read(b, 1);
|
||||
describe('#read()', function () {
|
||||
it('should read 4 bytes as integer', function () {
|
||||
const result = types.int32.read(b, 1);
|
||||
assert.equal(result, expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#size()', function() {
|
||||
it('should return 4', function() {
|
||||
describe('#size()', function () {
|
||||
it('should return 4', function () {
|
||||
assert.equal(types.int32.size(expected), 4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#write()', function() {
|
||||
it('should write 4 bytes to the buffer', function() {
|
||||
describe('#write()', function () {
|
||||
it('should write 4 bytes to the buffer', function () {
|
||||
types.int32.write(expected, b, 0);
|
||||
assert.deepEqual(new Buffer([0x10, 0x02, 0x40, 0x45]), b.slice(0, 4));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('string', function() {
|
||||
var b = new Buffer(9), expected = 'abcd1234';
|
||||
describe('string', function () {
|
||||
const expected = 'abcd1234',
|
||||
b = new Buffer(9);
|
||||
|
||||
b[0] = 8;
|
||||
b.write(expected, 1);
|
||||
|
||||
describe('#read()', function() {
|
||||
it('should read an Octet String from the buffer', function() {
|
||||
var result = types.string.read(b, 0);
|
||||
describe('#read()', function () {
|
||||
it('should read an Octet String from the buffer', function () {
|
||||
const result = types.string.read(b, 0);
|
||||
assert.equal(result, expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#size()', function() {
|
||||
it('should return the length of an Octet String from its first byte', function() {
|
||||
describe('#size()', function () {
|
||||
it('should return the length of an Octet String from its first byte', function () {
|
||||
assert.equal(9, types.string.size(expected));
|
||||
});
|
||||
});
|
||||
|
||||
describe('#write()', function() {
|
||||
it('should write an Octet String to the buffer', function() {
|
||||
var b2 = new Buffer(9);
|
||||
describe('#write()', function () {
|
||||
it('should write an Octet String to the buffer', function () {
|
||||
const b2 = new Buffer(9);
|
||||
types.string.write(expected, b2, 0);
|
||||
assert.deepEqual(b, b2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('cstring', function() {
|
||||
var b = new Buffer(9), expected = 'abcd1234';
|
||||
describe('cstring', function () {
|
||||
const expected = 'abcd1234',
|
||||
b = new Buffer(9);
|
||||
|
||||
b[8] = 0;
|
||||
b.write(expected, 0);
|
||||
|
||||
describe('#read()', function() {
|
||||
it('should read a C-Octet String (null-terminated string) from the buffer', function() {
|
||||
var result = types.cstring.read(b, 0);
|
||||
describe('#read()', function () {
|
||||
it('should read a C-Octet String (null-terminated string) from the buffer', function () {
|
||||
const result = types.cstring.read(b, 0);
|
||||
assert.equal(result, expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#size()', function() {
|
||||
it('should return the length of a C-Octet String (null-terminated string)', function() {
|
||||
describe('#size()', function () {
|
||||
it('should return the length of a C-Octet String (null-terminated string)', function () {
|
||||
assert.equal(9, types.cstring.size(expected));
|
||||
});
|
||||
});
|
||||
|
||||
describe('#write()', function() {
|
||||
it('should write a C-Octet String (null-terminated string) to the buffer', function() {
|
||||
var b2 = new Buffer(9);
|
||||
describe('#write()', function () {
|
||||
it('should write a C-Octet String (null-terminated string) to the buffer', function () {
|
||||
const b2 = new Buffer(9);
|
||||
types.cstring.write(expected, b2, 0);
|
||||
assert.deepEqual(b, b2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('buffer', function() {
|
||||
var b = new Buffer(8),
|
||||
expected = new Buffer('abcd1234');
|
||||
describe('buffer', function () {
|
||||
const expected = new Buffer('abcd1234'),
|
||||
b = new Buffer(8);
|
||||
|
||||
b.write(expected.toString());
|
||||
|
||||
describe('#read()', function() {
|
||||
it('should read a binary field from the buffer', function() {
|
||||
var result = types.buffer.read(b, 0, b.length);
|
||||
describe('#read()', function () {
|
||||
it('should read a binary field from the buffer', function () {
|
||||
const result = types.buffer.read(b, 0, b.length);
|
||||
assert.deepEqual(result, expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#size()', function() {
|
||||
it('should return the size of a binary field in bytes', function() {
|
||||
describe('#size()', function () {
|
||||
it('should return the size of a binary field in bytes', function () {
|
||||
assert.equal(8, types.buffer.size(expected));
|
||||
});
|
||||
});
|
||||
|
||||
describe('#write()', function() {
|
||||
it('should write a binary field to the buffer', function() {
|
||||
var b2 = new Buffer(8);
|
||||
describe('#write()', function () {
|
||||
it('should write a binary field to the buffer', function () {
|
||||
const b2 = new Buffer(8);
|
||||
types.buffer.write(expected, b2, 0);
|
||||
assert.deepEqual(b, b2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('dest_address_array', function() {
|
||||
var b,
|
||||
expected;
|
||||
describe('dest_address_array', function () {
|
||||
const expected = [],
|
||||
b = new Buffer([0x02, 0x01, 0x01, 0x02, 0x31, 0x32, 0x33, 0x00, 0x02, 0x61, 0x62, 0x63, 0x00]);
|
||||
|
||||
b = new Buffer([
|
||||
0x02, 0x01, 0x01, 0x02, 0x31, 0x32, 0x33, 0x00,
|
||||
0x02, 0x61, 0x62, 0x63, 0x00
|
||||
]);
|
||||
expected.push({
|
||||
'dest_addr_ton': 1,
|
||||
'dest_addr_npi': 2,
|
||||
'destination_addr': '123'
|
||||
});
|
||||
expected.push({'dl_name': 'abc'});
|
||||
|
||||
expected = [
|
||||
{
|
||||
dest_addr_ton: 1,
|
||||
dest_addr_npi: 2,
|
||||
destination_addr: '123'
|
||||
},
|
||||
{ dl_name: 'abc' }
|
||||
];
|
||||
|
||||
describe('#read()', function() {
|
||||
it('should read all dest_address structures from the buffer', function() {
|
||||
var result = types.dest_address_array.read(b, 0);
|
||||
describe('#read()', function () {
|
||||
it('should read all dest_address structures from the buffer', function () {
|
||||
const result = types.dest_address_array.read(b, 0);
|
||||
assert.deepEqual(result, expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#size()', function() {
|
||||
it('should return the size of all dest_address structures in bytes', function() {
|
||||
describe('#size()', function () {
|
||||
it('should return the size of all dest_address structures in bytes', function () {
|
||||
assert.equal(types.dest_address_array.size(expected), 13);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#write()', function() {
|
||||
it('should write an array of dest_address structures to the buffer', function() {
|
||||
var b2 = new Buffer(13);
|
||||
describe('#write()', function () {
|
||||
it('should write an array of dest_address structures to the buffer', function () {
|
||||
const b2 = new Buffer(13);
|
||||
types.dest_address_array.write(expected, b2, 0);
|
||||
assert.deepEqual(b, b2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('unsuccess_sme_array', function() {
|
||||
var b,
|
||||
expected;
|
||||
describe('unsuccess_sme_array', function () {
|
||||
const expected = [],
|
||||
b = new Buffer([0x02, 0x03, 0x04, 0x61, 0x62, 0x63, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x06, 0x31, 0x32, 0x33, 0x00, 0x10, 0x00, 0x00, 0x08]);
|
||||
|
||||
b = new Buffer([
|
||||
0x02, 0x03, 0x04, 0x61, 0x62, 0x63, 0x00, 0x00, 0x00, 0x00, 0x07,
|
||||
0x05, 0x06, 0x31, 0x32, 0x33, 0x00, 0x10, 0x00, 0x00, 0x08
|
||||
]);
|
||||
expected.push({
|
||||
'dest_addr_ton': 3,
|
||||
'dest_addr_npi': 4,
|
||||
'destination_addr': 'abc',
|
||||
'error_status_code': 0x00000007
|
||||
});
|
||||
expected.push({
|
||||
'dest_addr_ton': 5,
|
||||
'dest_addr_npi': 6,
|
||||
'destination_addr': '123',
|
||||
'error_status_code': 0x10000008
|
||||
});
|
||||
|
||||
expected = [
|
||||
{
|
||||
dest_addr_ton: 3,
|
||||
dest_addr_npi: 4,
|
||||
destination_addr: 'abc',
|
||||
error_status_code: 0x00000007
|
||||
},
|
||||
{
|
||||
dest_addr_ton: 5,
|
||||
dest_addr_npi: 6,
|
||||
destination_addr: '123',
|
||||
error_status_code: 0x10000008
|
||||
}
|
||||
];
|
||||
|
||||
describe('#read()', function() {
|
||||
it('should read all unsuccess_sme structures from the buffer', function() {
|
||||
var result = types.unsuccess_sme_array.read(b, 0);
|
||||
describe('#read()', function () {
|
||||
it('should read all unsuccess_sme structures from the buffer', function () {
|
||||
const result = types.unsuccess_sme_array.read(b, 0);
|
||||
assert.deepEqual(result, expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#size()', function() {
|
||||
it('should return the size of all unsuccess_sme structures in bytes', function() {
|
||||
describe('#size()', function () {
|
||||
it('should return the size of all unsuccess_sme structures in bytes', function () {
|
||||
assert.equal(types.unsuccess_sme_array.size(expected), 21);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#write()', function() {
|
||||
it('should write an array of unsuccess_sme structures to the buffer', function() {
|
||||
var b2 = new Buffer(21);
|
||||
describe('#write()', function () {
|
||||
it('should write an array of unsuccess_sme structures to the buffer', function () {
|
||||
const b2 = new Buffer(21);
|
||||
types.unsuccess_sme_array.write(expected, b2, 0);
|
||||
assert.deepEqual(b, b2);
|
||||
});
|
||||
|
||||
+145
-148
@@ -1,111 +1,111 @@
|
||||
'use strict';
|
||||
|
||||
var larvitsmpp = require('../larvitsmpp'),
|
||||
const larvitsmpp = require(__dirname + '/../index.js'),
|
||||
assert = require('assert');
|
||||
|
||||
describe('PDU convertion', function() {
|
||||
describe('PDU convertion', function () {
|
||||
this.slow(20);
|
||||
|
||||
describe('No TLVs', function() {
|
||||
it('should build a PDU buffer for bind_transceiver_resp with error correctly', function(done) {
|
||||
describe('No TLVs', function () {
|
||||
it('should build a PDU buffer for bind_transceiver_resp with error correctly', function (done) {
|
||||
larvitsmpp.utils.objToPdu({
|
||||
'cmdName': 'bind_transceiver_resp',
|
||||
'cmdStatus': 'ESME_RALYBND',
|
||||
'seqNr': 1
|
||||
}, function(err, pdu) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
}, function (err, pdu) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(pdu.readUInt32BE(0) === 17, 'Command length should be 17, but is: "' + pdu.readUInt32BE(0) + '"');
|
||||
assert(pdu.readUInt32BE(4).toString(16) === '80000009', 'Command ID should be 0x80000009');
|
||||
assert(pdu.readUInt32BE(8).toString(16) === '5', 'Command status should be 0x00000005');
|
||||
assert(pdu.readUInt32BE(12).toString(10) === '1', 'Sequence number should be 1');
|
||||
assert.strictEqual(pdu.readUInt32BE(0), 17);
|
||||
assert.strictEqual(pdu.readUInt32BE(4).toString(16), '80000009');
|
||||
assert.strictEqual(pdu.readUInt32BE(8).toString(16), '5');
|
||||
assert.strictEqual(pdu.readUInt32BE(12).toString(10), '1');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to do the above test and put it back to an object', function(done) {
|
||||
it('should be able to do the above test and put it back to an object', function (done) {
|
||||
larvitsmpp.utils.objToPdu({
|
||||
'cmdName': 'bind_transceiver_resp',
|
||||
'cmdStatus': 'ESME_RALYBND',
|
||||
'seqNr': 1
|
||||
}, function(err, pdu) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
}, function (err, pdu) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.utils.pduToObj(pdu, function(err, obj) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduToObj(pdu, function (err, obj) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(obj.cmdId.toString(16) === '80000009', 'Command ID should be 0x80000009');
|
||||
assert(obj.cmdStatus === 'ESME_RALYBND', 'Command status should be "ESME_RALYBND"');
|
||||
assert(obj.seqNr === 1, 'Sequence number should be 1');
|
||||
assert.strictEqual(obj.cmdId.toString(16), '80000009');
|
||||
assert.strictEqual(obj.cmdStatus, 'ESME_RALYBND');
|
||||
assert.strictEqual(obj.seqNr, 1);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should parse a PDU to obj correctly', function(done) {
|
||||
var pdu = new Buffer('0000002F000000020000000000000001534D50503354455354007365637265743038005355424D4954310000010100', 'hex');
|
||||
it('should parse a PDU to obj correctly', function (done) {
|
||||
const pdu = new Buffer('0000002F000000020000000000000001534D50503354455354007365637265743038005355424D4954310000010100', 'hex');
|
||||
|
||||
larvitsmpp.utils.pduToObj(pdu, function(err, obj) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduToObj(pdu, function (err, obj) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(obj.cmdId === 2, 'Command ID should be 2');
|
||||
assert(obj.cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(obj.cmdName === 'bind_transmitter', 'Command name should be "bind_transmitter"');
|
||||
assert(obj.params.system_id === 'SMPP3TEST', 'system_id should be "SMPP3TEST"');
|
||||
assert(obj.params.interface_version === 0, 'Interface version should be 0');
|
||||
assert.strictEqual(obj.cmdId, 2);
|
||||
assert.strictEqual(obj.cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(obj.cmdName, 'bind_transmitter');
|
||||
assert.strictEqual(obj.params.system_id, 'SMPP3TEST');
|
||||
assert.strictEqual(obj.params.interface_version, 0);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a return PDU without error', function(done) {
|
||||
var pdu = new Buffer('0000002f000000020000000000000001534d50503354455354007365637265743038005355424d4954310000010100', 'hex');
|
||||
it('should create a return PDU without error', function (done) {
|
||||
const pdu = new Buffer('0000002f000000020000000000000001534d50503354455354007365637265743038005355424d4954310000010100', 'hex');
|
||||
|
||||
larvitsmpp.utils.pduReturn(pdu, function(err, retPdu) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduReturn(pdu, function (err, retPdu) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.utils.pduToObj(retPdu, function(err, retObj) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduToObj(retPdu, function (err, retObj) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retObj.cmdId === 2147483650, 'Command ID should be 2147483650');
|
||||
assert(retObj.cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retObj.cmdName === 'bind_transmitter_resp', 'Command name should be "bind_transmitter_resp"');
|
||||
assert(retObj.params.system_id === 'SMPP3TEST', 'system_id should be "SMPP3TEST"');
|
||||
assert.strictEqual(retObj.cmdId, 2147483650);
|
||||
assert.strictEqual(retObj.cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retObj.cmdName, 'bind_transmitter_resp');
|
||||
assert.strictEqual(retObj.params.system_id, 'SMPP3TEST');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should read a submit_sm with an ending NULL octet to the short_message', function(done) {
|
||||
var pdu = new Buffer('0000003c0000000400000000000000020001003436373031313333313131000101343637303937373133333700000000000000000100047465737400', 'hex');
|
||||
it('should read a submit_sm with an ending NULL octet to the short_message', function (done) {
|
||||
const pdu = new Buffer('0000003c0000000400000000000000020001003436373031313333313131000101343637303937373133333700000000000000000100047465737400', 'hex');
|
||||
|
||||
larvitsmpp.utils.pduToObj(pdu, function(err, obj) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduToObj(pdu, function (err, obj) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(obj.params.short_message === 'test', 'Param short_message should read "test"');
|
||||
assert(obj.cmdLength === 60, 'Command length should be 60, due to the trailing NULL octet');
|
||||
assert.strictEqual(obj.params.short_message, 'test');
|
||||
assert.strictEqual(obj.cmdLength, 60);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should read a submit_sm without an ending NULL octet to the short_message', function(done) {
|
||||
var pdu = new Buffer('0000003b00000004000000000000000200010034363730313133333131310001013436373039373731333337000000000000000001000474657374', 'hex');
|
||||
it('should read a submit_sm without an ending NULL octet to the short_message', function (done) {
|
||||
const pdu = new Buffer('0000003b00000004000000000000000200010034363730313133333131310001013436373039373731333337000000000000000001000474657374', 'hex');
|
||||
|
||||
larvitsmpp.utils.pduToObj(pdu, function(err, obj) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduToObj(pdu, function (err, obj) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(obj.params.short_message === 'test', 'Param short_message should read "test"');
|
||||
assert(obj.cmdLength === 59, 'Command length should be 59');
|
||||
assert.strictEqual(obj.params.short_message, 'test');
|
||||
assert.strictEqual(obj.cmdLength, 59);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a very simple submit_sm PDU', function(done) {
|
||||
it('should create a very simple submit_sm PDU', function (done) {
|
||||
larvitsmpp.utils.objToPdu({
|
||||
'cmdName': 'submit_sm',
|
||||
'cmdStatus': 'ESME_ROK',
|
||||
@@ -115,16 +115,16 @@ describe('PDU convertion', function() {
|
||||
'destination_addr': '46709771337',
|
||||
'short_message': 'Hello world'
|
||||
}
|
||||
}, function(err, pdu) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
}, function (err, pdu) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(pdu.toString('hex') === '0000004200000004000000000000000c00000034363730313131333331310000003436373039373731333337000000000000000001000b48656c6c6f20776f726c64');
|
||||
assert.strictEqual(pdu.toString('hex'), '0000004200000004000000000000000c00000034363730313131333331310000003436373039373731333337000000000000000001000b48656c6c6f20776f726c64');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a submit_sm PDU with UCS2 encoding', function(done) {
|
||||
it('should create a submit_sm PDU with UCS2 encoding', function (done) {
|
||||
larvitsmpp.utils.objToPdu({
|
||||
'cmdName': 'submit_sm',
|
||||
'cmdStatus': 'ESME_ROK',
|
||||
@@ -134,17 +134,17 @@ describe('PDU convertion', function() {
|
||||
'destination_addr': '46709771337',
|
||||
'short_message': 'Hello«»world'
|
||||
}
|
||||
}, function(err, pdu) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
}, function (err, pdu) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(pdu.toString('hex') === '0000004f00000004000000000000000c00000034363730313131333331310000003436373039373731333337000000000000000008001800480065006c006c006f00ab00bb0077006f0072006c0064');
|
||||
assert.strictEqual(pdu.toString('hex'), '0000004f00000004000000000000000c00000034363730313131333331310000003436373039373731333337000000000000000008001800480065006c006c006f00ab00bb0077006f0072006c0064');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a submit_sm PDU with esm_class 0x40 and a short_message with UDH in it', function(done) {
|
||||
var msg = 'hej världen',
|
||||
it('should create a submit_sm PDU with esm_class 0x40 and a short_message with UDH in it', function (done) {
|
||||
const msg = 'hej världen',
|
||||
msgBuf = Buffer.concat([new Buffer('050003010101', 'hex'), new Buffer(msg)]),
|
||||
encoding = larvitsmpp.defs.encodings.detect(msg);
|
||||
|
||||
@@ -160,23 +160,22 @@ describe('PDU convertion', function() {
|
||||
'data_coding': larvitsmpp.defs.consts.ENCODING[encoding],
|
||||
'short_message': msgBuf
|
||||
}
|
||||
}, function(err, pdu) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
}, function (err, pdu) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.utils.pduToObj(pdu, function(err, retObj) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduToObj(pdu, function (err, retObj) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retObj.params.short_message.toString('hex') === '05000301010168656a2076c3a4726c64656e', 'short_message should be correct');
|
||||
assert.strictEqual(retObj.params.short_message.toString('hex'), '05000301010168656a2076c3a4726c64656e');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should encode and decode integer cstring params correctly', function(done) {
|
||||
var pduObj = {
|
||||
it('should encode and decode integer cstring params correctly', function (done) {
|
||||
const pduObj = {
|
||||
'cmdName': 'submit_sm_resp',
|
||||
'cmdStatus': 'ESME_ROK',
|
||||
'seqNr': 2,
|
||||
@@ -185,13 +184,13 @@ describe('PDU convertion', function() {
|
||||
}
|
||||
};
|
||||
|
||||
larvitsmpp.utils.objToPdu(pduObj, function(err, pduBuf) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.objToPdu(pduObj, function (err, pduBuf) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.utils.pduToObj(pduBuf, function(err, retPduObj) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduToObj(pduBuf, function (err, retPduObj) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retPduObj.params.message_id === '450', 'message_id param should be 450, but as string');
|
||||
assert.strictEqual(retPduObj.params.message_id, '450');
|
||||
|
||||
done();
|
||||
});
|
||||
@@ -199,25 +198,25 @@ describe('PDU convertion', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('TLVs', function() {
|
||||
it('should extract TLVs from a PDU', function(done) {
|
||||
var pdu = new Buffer('000000e9000000050000000002a82e8600010134363730393737313333370000003436373031313133333131000400000000000000007569643a313535303430363231323432313433353835207375623a30303120646c7672643a303031207375626d697420646174653a3135303430363233323420646f6e6520646174653a3135303430363233323420737461743a44454c49565244206572723a3030303020746578743a202062616666042300030300000427000102001e001331353530343036323132343231343335383500141800040000076c145400040000000114160006323430303800', 'hex');
|
||||
describe('TLVs', function () {
|
||||
it('should extract TLVs from a PDU', function (done) {
|
||||
const pdu = new Buffer('000000e9000000050000000002a82e8600010134363730393737313333370000003436373031313133333131000400000000000000007569643a313535303430363231323432313433353835207375623a30303120646c7672643a303031207375626d697420646174653a3135303430363233323420646f6e6520646174653a3135303430363233323420737461743a44454c49565244206572723a3030303020746578743a202062616666042300030300000427000102001e001331353530343036323132343231343335383500141800040000076c145400040000000114160006323430303800', 'hex');
|
||||
|
||||
larvitsmpp.utils.pduToObj(pdu, function(err, obj) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduToObj(pdu, function (err, obj) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(obj.cmdId.toString(16) === '5', 'Command ID should be 0x00000005 (5)');
|
||||
assert(obj.cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(obj.seqNr === 44576390, 'Sequence number should be 44576390');
|
||||
assert(obj.params.destination_addr === '46701113311', 'Param destination_addr should be "46701113311"');
|
||||
assert(obj.tlvs.receipted_message_id.tagValue === '155040621242143585', 'TLV receipted_message_id should be "155040621242143585", but is "' + obj.tlvs.receipted_message_id.tagValue + '"');
|
||||
assert.strictEqual(obj.cmdId.toString(16), '5');
|
||||
assert.strictEqual(obj.cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(obj.seqNr, 44576390);
|
||||
assert.strictEqual(obj.params.destination_addr, '46701113311');
|
||||
assert.strictEqual(obj.tlvs.receipted_message_id.tagValue, '155040621242143585');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should add TLVs to a PDU', function(done) {
|
||||
var pduObj = {
|
||||
it('should add TLVs to a PDU', function (done) {
|
||||
const pduObj = {
|
||||
'cmdName': 'deliver_sm',
|
||||
'seqNr': 393,
|
||||
'cmdStatus': 'ESME_ROK',
|
||||
@@ -241,25 +240,25 @@ describe('PDU convertion', function() {
|
||||
}
|
||||
};
|
||||
|
||||
larvitsmpp.utils.objToPdu(pduObj, function(err, pduBuf) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.objToPdu(pduObj, function (err, pduBuf) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.utils.pduToObj(pduBuf, function(err, pduObj2) {
|
||||
var unknownTlvBuf = new Buffer(pduObj2.tlvs['5142'].tagValue, 'hex');
|
||||
larvitsmpp.utils.pduToObj(pduBuf, function (err, pduObj2) {
|
||||
const unknownTlvBuf = new Buffer(pduObj2.tlvs['5142'].tagValue, 'hex');
|
||||
|
||||
assert( ! err, 'Error should be negative');
|
||||
if (err) throw err;
|
||||
|
||||
assert(pduObj2.tlvs.receipted_message_id !== undefined, 'TLV receipted_message_id should not be undefined');
|
||||
assert(pduObj2.tlvs.receipted_message_id.tagValue === '293f293', 'receipted_message_id should match the given one');
|
||||
assert(unknownTlvBuf.toString('ascii') === 'blajfoo', 'Unknown TLV 5142 should have a valid buffer');
|
||||
assert.notStrictEqual(pduObj2.tlvs.receipted_message_id, undefined);
|
||||
assert.strictEqual(pduObj2.tlvs.receipted_message_id.tagValue, '293f293');
|
||||
assert.strictEqual(unknownTlvBuf.toString('ascii'), 'blajfoo');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should add some other TLVs to a PDU', function(done) {
|
||||
var pduObj = {
|
||||
it('should add some other TLVs to a PDU', function (done) {
|
||||
const pduObj = {
|
||||
'cmdName': 'deliver_sm',
|
||||
'params': {
|
||||
'source_addr': '46701113311',
|
||||
@@ -282,19 +281,19 @@ describe('PDU convertion', function() {
|
||||
'seqNr': 323
|
||||
};
|
||||
|
||||
larvitsmpp.utils.objToPdu(pduObj, function(err, pduBuf) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.objToPdu(pduObj, function (err, pduBuf) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.utils.pduToObj(pduBuf, function(err, retPduObj) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduToObj(pduBuf, function (err, retPduObj) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retPduObj.params.short_message === 'id:450 sub:001 dlvrd:1 submit date:1504031342 done date:1504031342 stat:DELIVRD err:0 text:xxx', 'short_message should be preserved');
|
||||
assert(retPduObj.cmdName === 'deliver_sm', 'Command name should be "deliver_sm"');
|
||||
assert(retPduObj.tlvs.message_state !== undefined, 'TLV message_state should be set');
|
||||
assert(retPduObj.tlvs.message_state.tagValue === 2, 'TLV message_state tagValue should be 2');
|
||||
assert(retPduObj.tlvs.receipted_message_id !== undefined, 'TLV receipted_message_id should be set');
|
||||
assert(retPduObj.tlvs.receipted_message_id.tagValue === '450', 'TLV receipted_message_id tagValue should be "450"');
|
||||
assert(retPduObj.seqNr === 323, 'Sequence number should be 323');
|
||||
assert.strictEqual(retPduObj.params.short_message, 'id:450 sub:001 dlvrd:1 submit date:1504031342 done date:1504031342 stat:DELIVRD err:0 text:xxx');
|
||||
assert.strictEqual(retPduObj.cmdName, 'deliver_sm');
|
||||
assert.notStrictEqual(retPduObj.tlvs.message_state, undefined);
|
||||
assert.strictEqual(retPduObj.tlvs.message_state.tagValue, 2);
|
||||
assert.notStrictEqual(retPduObj.tlvs.receipted_message_id, undefined);
|
||||
assert.strictEqual(retPduObj.tlvs.receipted_message_id.tagValue, '450');
|
||||
assert.strictEqual(retPduObj.seqNr, 323);
|
||||
|
||||
done();
|
||||
});
|
||||
@@ -302,9 +301,9 @@ describe('PDU convertion', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Return PDUs', function() {
|
||||
it('should create a basic and valid return PDU', function(done) {
|
||||
var pduObj = {
|
||||
describe('Return PDUs', function () {
|
||||
it('should create a basic and valid return PDU', function (done) {
|
||||
const pduObj = {
|
||||
'cmdName': 'deliver_sm',
|
||||
'seqNr': 393,
|
||||
'cmdStatus': 'ESME_ROK',
|
||||
@@ -329,23 +328,23 @@ describe('PDU convertion', function() {
|
||||
}
|
||||
};
|
||||
|
||||
larvitsmpp.utils.pduReturn(pduObj, function(err, pduBuffer) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduReturn(pduObj, function (err, pduBuffer) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.utils.pduToObj(pduBuffer, function(err, retPduObj) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduToObj(pduBuffer, function (err, retPduObj) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retPduObj.cmdName === 'deliver_sm_resp', 'Command name should be "deliver_sm_resp"');
|
||||
assert(retPduObj.cmdStatus === 'ESME_ROK', 'Command status should be ESME_ROK');
|
||||
assert(retPduObj.params.message_id === 'od9s2', 'message_id should be correct');
|
||||
assert.strictEqual(retPduObj.cmdName, 'deliver_sm_resp');
|
||||
assert.strictEqual(retPduObj.cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObj.params.message_id, 'od9s2');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a valid return PDU with custom param', function(done) {
|
||||
var pduObj = {
|
||||
it('should create a valid return PDU with custom param', function (done) {
|
||||
const pduObj = {
|
||||
'cmdName': 'deliver_sm',
|
||||
'seqNr': 393,
|
||||
'cmdStatus': 'ESME_ROK',
|
||||
@@ -370,15 +369,15 @@ describe('PDU convertion', function() {
|
||||
}
|
||||
};
|
||||
|
||||
larvitsmpp.utils.pduReturn(pduObj, 'ESME_RINVMSGID', {'message_id': 'mep'}, function(err, pduBuffer) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduReturn(pduObj, 'ESME_RINVMSGID', {'message_id': 'mep'}, function (err, pduBuffer) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.utils.pduToObj(pduBuffer, function(err, retPduObj) {
|
||||
assert( ! err, 'Error should be negative');
|
||||
larvitsmpp.utils.pduToObj(pduBuffer, function (err, retPduObj) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retPduObj.cmdName === 'deliver_sm_resp', 'Command name should be "deliver_sm_resp"');
|
||||
assert(retPduObj.cmdStatus === 'ESME_RINVMSGID', 'Command status should be ESME_RINVMSGID');
|
||||
assert(retPduObj.params.message_id === 'mep', 'message_id should be the overriden one');
|
||||
assert.strictEqual(retPduObj.cmdName, 'deliver_sm_resp');
|
||||
assert.strictEqual(retPduObj.cmdStatus, 'ESME_RINVMSGID');
|
||||
assert.strictEqual(retPduObj.params.message_id, 'mep');
|
||||
|
||||
done();
|
||||
});
|
||||
@@ -386,9 +385,9 @@ describe('PDU convertion', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Message size and split', function() {
|
||||
it('should calculate sizes of msgs', function(done) {
|
||||
var a = 'abcd',
|
||||
describe('Message size and split', function () {
|
||||
it('should calculate sizes of msgs', function (done) {
|
||||
const a = 'abcd',
|
||||
b = 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
|
||||
c = 'Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi',
|
||||
d = 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdHIHIHIHI foobar',
|
||||
@@ -396,34 +395,32 @@ describe('PDU convertion', function() {
|
||||
f = 'abcd€abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd',
|
||||
g = 'Ledds med « df BLAH och därför är alla hjul runda fast bara några hihi bara lite längre';
|
||||
|
||||
assert(larvitsmpp.utils.bitCount(a) === 28, 'ASCII');
|
||||
assert(larvitsmpp.utils.bitCount(b) === 1120, 'ASCII');
|
||||
assert(larvitsmpp.utils.bitCount(b, 'UCS2') === 2560, 'ASCII, expected 2560 but got ' + larvitsmpp.utils.bitCount(b, 'UCS2'));
|
||||
assert(larvitsmpp.utils.bitCount(c) === 1120, 'UCS2');
|
||||
assert(larvitsmpp.utils.bitCount(d) === 1225, 'ASCII');
|
||||
assert(larvitsmpp.utils.bitCount(e) === 4528, 'UCS2');
|
||||
assert(larvitsmpp.utils.bitCount(f) === 1120, 'ASCII with special char');
|
||||
assert(larvitsmpp.utils.bitCount(g) === 1392, 'UCS2');
|
||||
|
||||
assert(larvitsmpp.utils.splitMsg(a).length === 1);
|
||||
assert(larvitsmpp.utils.splitMsg(b).length === 1);
|
||||
assert(larvitsmpp.utils.splitMsg(b, 'UCS2').length === 3, 'Expected length 2, but got ' + larvitsmpp.utils.splitMsg(b, 'UCS2').length);
|
||||
assert(larvitsmpp.utils.splitMsg(c).length === 1);
|
||||
assert(larvitsmpp.utils.splitMsg(d).length === 2);
|
||||
assert(larvitsmpp.utils.splitMsg(e).length === 5);
|
||||
assert(larvitsmpp.utils.splitMsg(f).length === 1);
|
||||
assert(larvitsmpp.utils.splitMsg(g).length === 2);
|
||||
assert.strictEqual(larvitsmpp.utils.bitCount(a), 28);
|
||||
assert.strictEqual(larvitsmpp.utils.bitCount(b), 1120);
|
||||
assert.strictEqual(larvitsmpp.utils.bitCount(b, 'UCS2'), 2560);
|
||||
assert.strictEqual(larvitsmpp.utils.bitCount(c), 1120);
|
||||
assert.strictEqual(larvitsmpp.utils.bitCount(d), 1225);
|
||||
assert.strictEqual(larvitsmpp.utils.bitCount(e), 4528);
|
||||
assert.strictEqual(larvitsmpp.utils.bitCount(f), 1120);
|
||||
assert.strictEqual(larvitsmpp.utils.bitCount(g), 1392);
|
||||
assert.strictEqual(larvitsmpp.utils.splitMsg(a).length, 1);
|
||||
assert.strictEqual(larvitsmpp.utils.splitMsg(b).length, 1);
|
||||
assert.strictEqual(larvitsmpp.utils.splitMsg(b, 'UCS2').length, 3);
|
||||
assert.strictEqual(larvitsmpp.utils.splitMsg(c).length, 1);
|
||||
assert.strictEqual(larvitsmpp.utils.splitMsg(d).length, 2);
|
||||
assert.strictEqual(larvitsmpp.utils.splitMsg(e).length, 5);
|
||||
assert.strictEqual(larvitsmpp.utils.splitMsg(f).length, 1);
|
||||
assert.strictEqual(larvitsmpp.utils.splitMsg(g).length, 2);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return an array with a buffer equalling the input msg', function(done) {
|
||||
var msg = 'hello world',
|
||||
it('should return an array with a buffer equalling the input msg', function (done) {
|
||||
const msg = 'hello world',
|
||||
msgs = larvitsmpp.utils.splitMsg(msg);
|
||||
|
||||
assert(msgs[0].toString() === msg, 'Messages should equal');
|
||||
assert.strictEqual(msgs[0].toString(), msg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
+200
-200
@@ -1,32 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
var larvitsmpp = require('../larvitsmpp'),
|
||||
const larvitsmpp = require(__dirname + '/../index.js'),
|
||||
portfinder = require('portfinder'),
|
||||
assert = require('assert'),
|
||||
net = require('net');
|
||||
|
||||
// Very advanced auth system
|
||||
function checkuserpass(username, password, callback) {
|
||||
function checkuserpass(username, password, cb) {
|
||||
if (username === 'foo' && password === 'bar') {
|
||||
callback(null, true);
|
||||
cb(null, true);
|
||||
} else {
|
||||
callback(null, false);
|
||||
cb(null, false);
|
||||
}
|
||||
}
|
||||
|
||||
describe('Sessions', function() {
|
||||
describe('Sessions', function () {
|
||||
this.slow(200);
|
||||
|
||||
it('should setup a basic server and client and then directly unbinding again', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should setup a basic server and client and then directly unbinding again', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
@@ -34,8 +34,8 @@ describe('Sessions', function() {
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -45,17 +45,17 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should setup a server with auth and client trying to connect with wrong username and password', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should setup a server with auth and client trying to connect with wrong username and password', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort,
|
||||
'checkuserpass': checkuserpass
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
@@ -63,7 +63,7 @@ describe('Sessions', function() {
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err) {
|
||||
}, function (err) {
|
||||
assert(err, 'Error should be set since login should have failed');
|
||||
|
||||
done();
|
||||
@@ -71,17 +71,17 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should setup a server with auth and client trying to connect with correct username and password', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should setup a server with auth and client trying to connect with correct username and password', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort,
|
||||
'checkuserpass': checkuserpass
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
@@ -91,8 +91,8 @@ describe('Sessions', function() {
|
||||
'port': freePort,
|
||||
'username': 'foo',
|
||||
'password': 'bar'
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -102,32 +102,32 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should try sending a simple sms', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should try sending a simple sms', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
serverSession.on('sms', function (sms) {
|
||||
sms.smsId = 2343;
|
||||
|
||||
assert(sms.from === 'foo', 'SMS from should be "foo"');
|
||||
assert(sms.to === '46709771337', 'SMS to should be "46709771337"');
|
||||
assert(sms.message === 'hello world', 'SMS message should be "hello world"');
|
||||
assert(sms.dlr === false, 'DLR should be boolean false');
|
||||
assert(sms.pduObjs[0].pduObj.cmdId === 4, 'SMS pduObj cmdId should be 4');
|
||||
assert.strictEqual(sms.from, 'foo');
|
||||
assert.strictEqual(sms.to, '46709771337');
|
||||
assert.strictEqual(sms.message, 'hello world');
|
||||
assert.strictEqual(sms.dlr, false);
|
||||
assert.strictEqual(sms.pduObjs[0].pduObj.cmdId, 4);
|
||||
|
||||
sms.sendResp(function(err, retPdus) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err, retPdus) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retPdus[0].toString('hex') === '000000158000000400000000000000023233343300', 'The return PDU should be "000000158000000400000000000000023233343300"');
|
||||
assert.strictEqual(retPdus[0].toString('hex'), '000000158000000400000000000000023233343300');
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
@@ -135,21 +135,21 @@ describe('Sessions', function() {
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
clientSession.sendSms({
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'hello world'
|
||||
}, function(err, smsIds, retPduObjs) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, smsIds, retPduObjs) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||
assert(smsIds[0] === '2343', 'Given smsId should be "2343"');
|
||||
assert(retPduObjs instanceof Array, 'retPduObjs should be an Array');
|
||||
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert.strictEqual(smsIds[0], '2343');
|
||||
assert.strictEqual(retPduObjs[0].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[0].cmdName, 'submit_sm_resp');
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -160,34 +160,34 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should try sending a long sms', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should try sending a long sms', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
serverSession.on('sms', function (sms) {
|
||||
sms.smsId = 2343;
|
||||
|
||||
assert(sms.from === 'foo', 'SMS from should be "foo"');
|
||||
assert(sms.to === '46709771337', 'SMS to should be "46709771337"');
|
||||
assert(sms.message === 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.', 'SMS message should be correct');
|
||||
assert(sms.dlr === false, 'DLR should be boolean false');
|
||||
assert(sms.pduObjs[0].pduObj.cmdId === 4, 'SMS pduObj cmdId should be 4');
|
||||
assert.strictEqual(sms.from, 'foo');
|
||||
assert.strictEqual(sms.to, '46709771337');
|
||||
assert.strictEqual(sms.message, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.');
|
||||
assert.strictEqual(sms.dlr, false);
|
||||
assert.strictEqual(sms.pduObjs[0].pduObj.cmdId, 4);
|
||||
|
||||
sms.sendResp(function(err, retPdus) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err, retPdus) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retPdus[0].toString('hex') === '00000017800000040000000000000002323334332d3100', 'Return PDU 0 is wrong');
|
||||
assert(retPdus[1].toString('hex') === '00000017800000040000000000000003323334332d3200', 'Return PDU 1 is wrong');
|
||||
assert(retPdus[2].toString('hex') === '00000017800000040000000000000004323334332d3300', 'Return PDU 2 is wrong');
|
||||
assert.strictEqual(retPdus[0].toString('hex'), '00000017800000040000000000000002323334332d3100');
|
||||
assert.strictEqual(retPdus[1].toString('hex'), '00000017800000040000000000000003323334332d3200');
|
||||
assert.strictEqual(retPdus[2].toString('hex'), '00000017800000040000000000000004323334332d3300');
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
@@ -195,27 +195,27 @@ describe('Sessions', function() {
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
clientSession.sendSms({
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.'
|
||||
}, function(err, smsIds, retPduObjs) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, smsIds, retPduObjs) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||
assert(smsIds[0] === '2343-1', 'First smsId should be "2343-1"');
|
||||
assert(smsIds[1] === '2343-2', 'Second smsId should be "2343-2"');
|
||||
assert(smsIds[2] === '2343-3', 'Third smsId should be "2343-3"');
|
||||
assert(smsIds[3] === undefined, 'Fourth smsId should be undefined');
|
||||
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[1].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[1].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[2].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[2].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert.strictEqual(smsIds[0], '2343-1');
|
||||
assert.strictEqual(smsIds[1], '2343-2');
|
||||
assert.strictEqual(smsIds[2], '2343-3');
|
||||
assert.strictEqual(smsIds[3], undefined);
|
||||
assert.strictEqual(retPduObjs[0].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[0].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[1].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[1].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[2].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[2].cmdName, 'submit_sm_resp');
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -226,34 +226,34 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should try sending a weirder long sms', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should try sending a weirder long sms', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
serverSession.on('sms', function (sms) {
|
||||
sms.smsId = 2344;
|
||||
|
||||
assert(sms.from === 'foo', 'SMS from should be "foo"');
|
||||
assert(sms.to === '46709771337', 'SMS to should be "46709771337"');
|
||||
assert(sms.message === 'K sKM8NYUuoVbORtCn€swWsvTZjbtYM1TceGJJouolLk4cOtlk7j dxWMI56Domdx2W!dHKjGBR5UsynmUnbp1ysRDCktBri WW2pxIWHv0P7H OVRZNw 6 DBzAqpnd7ZPslwNyi»x OuiNH0R!WM2DTo8ItysNDNe1eNnpLvahhRgv»TC y lvgFrmv4OiUTOP', 'SMS message should be correct');
|
||||
assert(sms.dlr === false, 'DLR should be boolean false');
|
||||
assert(sms.pduObjs[0].pduObj.cmdId === 4, 'SMS pduObj cmdId should be 4');
|
||||
assert.strictEqual(sms.from, 'foo');
|
||||
assert.strictEqual(sms.to, '46709771337');
|
||||
assert.strictEqual(sms.message, 'K sKM8NYUuoVbORtCn€swWsvTZjbtYM1TceGJJouolLk4cOtlk7j dxWMI56Domdx2W!dHKjGBR5UsynmUnbp1ysRDCktBri WW2pxIWHv0P7H OVRZNw 6 DBzAqpnd7ZPslwNyi»x OuiNH0R!WM2DTo8ItysNDNe1eNnpLvahhRgv»TC y lvgFrmv4OiUTOP');
|
||||
assert.strictEqual(sms.dlr, false);
|
||||
assert.strictEqual(sms.pduObjs[0].pduObj.cmdId, 4);
|
||||
|
||||
sms.sendResp(function(err, retPdus) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err, retPdus) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(retPdus[0].toString('hex') === '00000017800000040000000000000002323334342d3100', 'Return PDU 0 is wrong');
|
||||
assert(retPdus[1].toString('hex') === '00000017800000040000000000000003323334342d3200', 'Return PDU 1 is wrong');
|
||||
assert(retPdus[2].toString('hex') === '00000017800000040000000000000004323334342d3300', 'Return PDU 2 is wrong');
|
||||
assert.strictEqual(retPdus[0].toString('hex'), '00000017800000040000000000000002323334342d3100');
|
||||
assert.strictEqual(retPdus[1].toString('hex'), '00000017800000040000000000000003323334342d3200');
|
||||
assert.strictEqual(retPdus[2].toString('hex'), '00000017800000040000000000000004323334342d3300');
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
@@ -261,27 +261,27 @@ describe('Sessions', function() {
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
clientSession.sendSms({
|
||||
'from': 'foo',
|
||||
'to': '46709771337',
|
||||
'message': 'K sKM8NYUuoVbORtCn€swWsvTZjbtYM1TceGJJouolLk4cOtlk7j dxWMI56Domdx2W!dHKjGBR5UsynmUnbp1ysRDCktBri WW2pxIWHv0P7H OVRZNw 6 DBzAqpnd7ZPslwNyi»x OuiNH0R!WM2DTo8ItysNDNe1eNnpLvahhRgv»TC y lvgFrmv4OiUTOP'
|
||||
}, function(err, smsIds, retPduObjs) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, smsIds, retPduObjs) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||
assert(smsIds[0] === '2344-1', 'First smsId should be "2344-1"');
|
||||
assert(smsIds[1] === '2344-2', 'Second smsId should be "2344-2"');
|
||||
assert(smsIds[2] === '2344-3', 'Third smsId should be "2344-3"');
|
||||
assert(smsIds[3] === undefined, 'Fourth smsId should be undefined');
|
||||
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[1].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[1].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[2].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[2].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert.strictEqual(smsIds[0], '2344-1');
|
||||
assert.strictEqual(smsIds[1], '2344-2');
|
||||
assert.strictEqual(smsIds[2], '2344-3');
|
||||
assert.strictEqual(smsIds[3], undefined);
|
||||
assert.strictEqual(retPduObjs[0].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[0].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[1].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[1].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[2].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[2].cmdName, 'submit_sm_resp');
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -292,29 +292,29 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should send a long sms and receive dlrs for it', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should send a long sms and receive dlrs for it', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
serverSession.on('sms', function (sms) {
|
||||
sms.smsId = 2343;
|
||||
|
||||
sms.sendResp(function(err) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(sms.dlr === true, 'sms.dlr should be true');
|
||||
assert.strictEqual(sms.dlr, true);
|
||||
|
||||
// Send the DLR(s)
|
||||
sms.sendDlr(true);
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
@@ -322,14 +322,14 @@ describe('Sessions', function() {
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
var sentSmsId;
|
||||
}, function (err, clientSession) {
|
||||
let sentSmsId;
|
||||
|
||||
assert( ! err, 'Error should not be negative');
|
||||
if (err) throw err;
|
||||
|
||||
clientSession.on('dlr', function(dlr) {
|
||||
assert(dlr.statusMsg === 'DELIVERED', 'DLR statusMsg should be "DELIVERED"');
|
||||
assert(dlr.smsId.toString() === sentSmsId.toString(), 'SmsId should be "' + sentSmsId.toString() + '"');
|
||||
clientSession.on('dlr', function (dlr) {
|
||||
assert.strictEqual(dlr.statusMsg, 'DELIVERED');
|
||||
assert.strictEqual(dlr.smsId.toString(), sentSmsId.toString());
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -342,20 +342,20 @@ describe('Sessions', function() {
|
||||
'to': '46709771337',
|
||||
'message': 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.',
|
||||
'dlr': true
|
||||
}, function(err, smsIds, retPduObjs) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, smsIds, retPduObjs) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||
assert(smsIds[0] === '2343-1', 'First smsId should be "2343-1"');
|
||||
assert(smsIds[1] === '2343-2', 'Second smsId should be "2343-2"');
|
||||
assert(smsIds[2] === '2343-3', 'Third smsId should be "2343-3"');
|
||||
assert(smsIds[3] === undefined, 'Fourth smsId should be undefined');
|
||||
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[1].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[1].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert(retPduObjs[2].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||
assert(retPduObjs[2].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||
assert.strictEqual(smsIds[0], '2343-1');
|
||||
assert.strictEqual(smsIds[1], '2343-2');
|
||||
assert.strictEqual(smsIds[2], '2343-3');
|
||||
assert.strictEqual(smsIds[3], undefined);
|
||||
assert.strictEqual(retPduObjs[0].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[0].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[1].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[1].cmdName, 'submit_sm_resp');
|
||||
assert.strictEqual(retPduObjs[2].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObjs[2].cmdName, 'submit_sm_resp');
|
||||
|
||||
// Save the SMS id to match the DLR for
|
||||
sentSmsId = smsIds[0].split('-')[0];
|
||||
@@ -364,29 +364,29 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should verify dlr on readme example', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
it('should verify dlr on readme example', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
if (err) throw err;
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
serverSession.on('sms', function (sms) {
|
||||
sms.smsId = 2343; // Random integer
|
||||
|
||||
sms.sendResp(function(err) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err) {
|
||||
if (err) throw err;
|
||||
|
||||
assert(sms.dlr === true, 'sms.dlr should be true');
|
||||
assert.strictEqual(sms.dlr, true);
|
||||
|
||||
// Send the DLR(s)
|
||||
sms.sendDlr(true);
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
done();
|
||||
@@ -395,18 +395,18 @@ describe('Sessions', function() {
|
||||
|
||||
larvitsmpp.client({
|
||||
'port': freePort
|
||||
}, function(err, clientSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, clientSession) {
|
||||
if (err) throw err;
|
||||
|
||||
clientSession.on('dlr', function(dlr, dlrPduObj) {
|
||||
assert.deepEqual(dlr.statusMsg, 'DELIVERED');
|
||||
assert.deepEqual(dlr.statusId, 2);
|
||||
assert.deepEqual(parseInt(dlr.smsId), 2343);
|
||||
clientSession.on('dlr', function (dlr, dlrPduObj) {
|
||||
assert.strictEqual(dlr.statusMsg, 'DELIVERED');
|
||||
assert.strictEqual(dlr.statusId, 2);
|
||||
assert.strictEqual(parseInt(dlr.smsId), 2343);
|
||||
|
||||
assert.deepEqual(dlrPduObj.params.short_message.substring(0, 36), 'id:2343 sub:001 dlvrd:1 submit date:');
|
||||
assert.deepEqual(dlrPduObj.params.short_message.substring(68), 'stat:DELIVRD err:0 text:xxx');
|
||||
assert.deepEqual(dlrPduObj.cmdStatus, 'ESME_ROK');
|
||||
assert.deepEqual(dlrPduObj.cmdName, 'deliver_sm');
|
||||
assert.strictEqual(dlrPduObj.params.short_message.substring(0, 36), 'id:2343 sub:001 dlvrd:1 submit date:');
|
||||
assert.strictEqual(dlrPduObj.params.short_message.substring(68), 'stat:DELIVRD err:0 text:xxx');
|
||||
assert.strictEqual(dlrPduObj.cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(dlrPduObj.cmdName, 'deliver_sm');
|
||||
|
||||
// Gracefully close connection
|
||||
clientSession.unbind();
|
||||
@@ -417,34 +417,34 @@ describe('Sessions', function() {
|
||||
'to': '46709771337',
|
||||
'message': '«baff»',
|
||||
'dlr': true
|
||||
}, function(err, smsId, retPduObj) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
assert.deepEqual(parseInt(smsId[0]), 2343);
|
||||
assert.deepEqual(smsId[1], undefined);
|
||||
assert.deepEqual(retPduObj[0].cmdStatus, 'ESME_ROK');
|
||||
assert.deepEqual(retPduObj[0].cmdName, 'submit_sm_resp');
|
||||
}, function (err, smsId, retPduObj) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(parseInt(smsId[0]), 2343);
|
||||
assert.strictEqual(smsId[1], undefined);
|
||||
assert.strictEqual(retPduObj[0].cmdStatus, 'ESME_ROK');
|
||||
assert.strictEqual(retPduObj[0].cmdName, 'submit_sm_resp');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should test a session fetched from Kannel on long messages with large UDH', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
var sock = new net.Socket(),
|
||||
sockInLog = []; // Log incomming socket messages
|
||||
it('should test a session fetched from Kannel on long messages with large UDH', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
const sockInLog = [], // Log incomming socket messages
|
||||
sock = new net.Socket();
|
||||
|
||||
assert( ! err, 'Error should not be negative');
|
||||
if (err) throw err;
|
||||
|
||||
sock.connect(freePort, 'localhost', function() {
|
||||
sock.connect(freePort, 'localhost', function () {
|
||||
// bind_transceiver - initial call. Subsequent calls should be made on the sock.on('data') thingie
|
||||
sock.write(new Buffer('0000002100000009000000000000002f666f6f0062617200736d70700034000000', 'hex'));
|
||||
});
|
||||
|
||||
sock.on('data', function(data) {
|
||||
sock.on('data', function (data) {
|
||||
sockInLog.push(data.toString('hex'));
|
||||
|
||||
if (sockInLog.length === 1) {
|
||||
assert.deepEqual(data.toString('hex'), '0000001480000009000000000000002f666f6f00');
|
||||
assert.strictEqual(data.toString('hex'), '0000001480000009000000000000002f666f6f00');
|
||||
|
||||
// Send all 4 parts at the same time
|
||||
sock.write(new Buffer('000000de00000004000000000000003000050074657374000201313233343500430000003136303630373136333031333030302b00000000009f0500030204014c6f72656d20497073756d2069732073696d706c792064756d6d792074657874206f6620746865207072696e74696e6720616e64207479706573657474696e6720696e6475737472792e204c6f72656d20497073756d20686173206265656e2074686520696e6475737472792773207374616e646172642064756d6d79207465787420657665722073696e6365207468652031353030732c200426000101', 'hex'));
|
||||
@@ -452,10 +452,10 @@ describe('Sessions', function() {
|
||||
sock.write(new Buffer('000000de00000004000000000000003200050074657374000201313233343500430000003136303630373136333031333030302b00000000009f0500030204036e746f20656c656374726f6e6963207479706573657474696e672c2072656d61696e696e6720657373656e7469616c6c7920756e6368616e6765642e2049742077617320706f70756c61726973656420696e207468652031393630732077697468207468652072656c65617365206f66204c657472617365742073686565747320636f6e7461696e696e67204c6f72656d20497073756d20700426000101', 'hex'));
|
||||
sock.write(new Buffer('000000b200000004000000000000003300050074657374000201313233343500430000003136303630373136333031333030302b000000000078050003020404617373616765732c20616e64206d6f726520726563656e746c792077697468206465736b746f70207075626c697368696e6720736f667477617265206c696b6520416c64757320506167654d616b657220696e636c7564696e672076657273696f6e73206f66204c6f72656d20497073756d', 'hex'));
|
||||
} else if (sockInLog.length === 2) {
|
||||
assert.deepEqual(data.toString('hex'), '000000158000000400000000000000303233343300');
|
||||
assert.strictEqual(data.toString('hex'), '000000158000000400000000000000303233343300');
|
||||
} else if (sockInLog.length === 3) {
|
||||
// This is actually four different PDUs at the same time, marking the response on all four parts above
|
||||
assert.deepEqual(data.toString('hex'), '000000158000000400000000000000313233343300000000158000000400000000000000323233343300000000158000000400000000000000333233343300');
|
||||
assert.strictEqual(data.toString('hex'), '000000158000000400000000000000313233343300000000158000000400000000000000323233343300000000158000000400000000000000333233343300');
|
||||
done();
|
||||
} else {
|
||||
throw new Error('To much data received');
|
||||
@@ -464,20 +464,20 @@ describe('Sessions', function() {
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
assert.deepEqual(sms.message, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum');
|
||||
serverSession.on('sms', function (sms) {
|
||||
assert.strictEqual(sms.message, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum');
|
||||
|
||||
sms.smsId = 2343;
|
||||
|
||||
sms.sendResp(function(err) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err) {
|
||||
if (err) throw err;
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
@@ -485,23 +485,23 @@ describe('Sessions', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should test a session can recreate SMS with random sequence', function(done) {
|
||||
portfinder.getPort(function(err, freePort) {
|
||||
var sock = new net.Socket(),
|
||||
sockInLog = []; // Log incomming socket messages
|
||||
it('should test a session can recreate SMS with random sequence', function (done) {
|
||||
portfinder.getPort(function (err, freePort) {
|
||||
const sockInLog = [], // Log incomming socket messages
|
||||
sock = new net.Socket();
|
||||
|
||||
assert( ! err, 'Error should not be negative');
|
||||
if (err) throw err;
|
||||
|
||||
sock.connect(freePort, 'localhost', function() {
|
||||
sock.connect(freePort, 'localhost', function () {
|
||||
// bind_transceiver - initial call. Subsequent calls should be made on the sock.on('data') thingie
|
||||
sock.write(new Buffer('0000002100000009000000000000002f666f6f0062617200736d70700034000000', 'hex'));
|
||||
});
|
||||
|
||||
sock.on('data', function(data) {
|
||||
sock.on('data', function (data) {
|
||||
sockInLog.push(data.toString('hex'));
|
||||
|
||||
if (sockInLog.length === 1) {
|
||||
assert.deepEqual(data.toString('hex'), '0000001480000009000000000000002f666f6f00');
|
||||
assert.strictEqual(data.toString('hex'), '0000001480000009000000000000002f666f6f00');
|
||||
|
||||
// Send all 4 parts at the same time but random order
|
||||
// Message Part 2
|
||||
@@ -513,10 +513,10 @@ describe('Sessions', function() {
|
||||
// Message Part 3
|
||||
sock.write(new Buffer('000000de00000004000000000000003200050074657374000201313233343500430000003136303630373136333031333030302b00000000009f0500030204036e746f20656c656374726f6e6963207479706573657474696e672c2072656d61696e696e6720657373656e7469616c6c7920756e6368616e6765642e2049742077617320706f70756c61726973656420696e207468652031393630732077697468207468652072656c65617365206f66204c657472617365742073686565747320636f6e7461696e696e67204c6f72656d20497073756d20700426000101', 'hex'));
|
||||
} else if (sockInLog.length === 2) {
|
||||
assert.deepEqual(data.toString('hex'), '000000158000000400000000000000303233343300');
|
||||
assert.strictEqual(data.toString('hex'), '000000158000000400000000000000303233343300');
|
||||
} else if (sockInLog.length === 3) {
|
||||
// This is actually four different PDUs at the same time, marking the response on all four parts above
|
||||
assert.deepEqual(data.toString('hex'), '000000158000000400000000000000313233343300000000158000000400000000000000323233343300000000158000000400000000000000333233343300');
|
||||
assert.strictEqual(data.toString('hex'), '000000158000000400000000000000313233343300000000158000000400000000000000323233343300000000158000000400000000000000333233343300');
|
||||
done();
|
||||
} else {
|
||||
throw new Error('To much data received');
|
||||
@@ -525,20 +525,20 @@ describe('Sessions', function() {
|
||||
|
||||
larvitsmpp.server({
|
||||
'port': freePort
|
||||
}, function(err, serverSession) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
}, function (err, serverSession) {
|
||||
if (err) throw err;
|
||||
|
||||
serverSession.on('sms', function(sms) {
|
||||
assert.deepEqual(sms.message, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum');
|
||||
serverSession.on('sms', function (sms) {
|
||||
assert.strictEqual(sms.message, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum');
|
||||
|
||||
sms.smsId = 2343;
|
||||
|
||||
sms.sendResp(function(err) {
|
||||
assert( ! err, 'Error should not be negative');
|
||||
sms.sendResp(function (err) {
|
||||
if (err) throw err;
|
||||
});
|
||||
});
|
||||
|
||||
serverSession.on('close', function() {
|
||||
serverSession.on('close', function () {
|
||||
// Manually destroy the server socket
|
||||
serverSession.sock.destroy();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
require(
|
||||
'mocha-eslint')([__dirname + '/..'],
|
||||
{
|
||||
// Increase the timeout of the test if linting takes to long
|
||||
'timeout': 5000, // Defaults to the global mocha `timeout` option
|
||||
|
||||
// Increase the time until a test is marked as slow
|
||||
'slow': 1000, // Defaults to the global mocha `slow` option
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user