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