Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

smpp

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smpp - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

README.md

299

lib/defs.js

@@ -1,2 +0,3 @@

var iconv = require('iconv-lite');
var iconv = require('iconv-lite'),
Buffer = require('safer-buffer').Buffer;

@@ -51,3 +52,3 @@ var types = {

if (typeof value == 'string') {
value = new Buffer(value, 'ascii');
value = Buffer.from(value, 'ascii');
}

@@ -71,3 +72,3 @@ value.copy(buffer, offset);

if (typeof value == 'string') {
value = new Buffer(value, 'ascii');
value = Buffer.from(value, 'ascii');
}

@@ -90,3 +91,3 @@ value.copy(buffer, offset);

if (typeof value == 'string') {
value = new Buffer(value, 'ascii');
value = Buffer.from(value, 'ascii');
}

@@ -98,3 +99,3 @@ value.copy(buffer, offset);

},
default: new Buffer(0)
default: Buffer.alloc(0)
},

@@ -203,3 +204,3 @@ dest_address_array: {

if (typeof value == 'string') {
value = new Buffer(value, 'ascii');
value = Buffer.from(value, 'ascii');
}

@@ -219,3 +220,3 @@ value.copy(buffer, offset);

if (typeof value == 'string') {
value = new Buffer(value, 'ascii');
value = Buffer.from(value, 'ascii');
}

@@ -231,46 +232,156 @@ value.copy(buffer, offset);

var gsmCoder = {
// GSM 03.38
GSM: {
chars: '@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1BÆæßÉ !"#¤%&\'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà',
extChars: '\f^{}\\[~]|€',
escChars: '\nΛ()/<=>¡e',
charRegex: /^[@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1BÆæßÉ !"#¤%&\'()*+,\-./0-9:;<=>?¡A-ZÄÖÑܧ¿a-zäöñüà\f^{}\\[~\]|€]*$/,
charListEnc: {},
extCharListEnc: {},
charListDec: {},
extCharListDec: {}
},
// GSM 03.38 Turkish Shift Table
GSM_TR: {
chars: '@£$¥€éùıòÇ\nĞğ\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1BŞşßÉ !"#¤%&\'()*+,-./0123456789:;<=>?İABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧçabcdefghijklmnopqrstuvwxyzäöñüà',
extCharsEnc: '\f^{}\\[~]|',
escCharsEnc: '\nΛ()/<=>İ',
extCharsDec: '\f{}^\\[~]|ĞİŞç€ğış',
escCharsDec: '\n()Λ/<=>İGIScegis',
charRegex: /^[@£$¥€éùıòÇ\nĞğ\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1BŞşßÉ !"#¤%&\'()*+,-./0-9:;<=>?İA-ZÄÖÑܧça-zäöñüà\f^{}\\[~\]|ĞİŞç€ğış]*$/,
charListEnc: {},
extCharListEnc: {},
charListDec: {},
extCharListDec: {}
},
// GSM 03.38 Spanish Shift Table
GSM_ES: {
chars: '@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1BÆæßÉ !"#¤%&\'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà',
extChars: 'ç\f^{}\\[~]|ÁÍÓÚá€íóú',
escChars: 'Ç\nΛ()/<=>¡AIOUaeiou',
charRegex: /^[@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1BÆæßÉ !"#¤%&\'()*+,-./0-9:;<=>?¡A-ZÄÖÑܧ¿a-zäöñüàç\f^{}\\[~\]|ÁÍÓÚá€íóú]*$/,
charListEnc: {},
extCharListEnc: {},
charListDec: {},
extCharListDec: {}
},
// GSM 03.38 Portuguese Shift Table
GSM_PT: {
chars: '@£$¥êéúíóç\nÔô\rÁáΔ_ªÇÀ∞^\\€Ó|\x1BÂâÊÉ !"#º%&\'()*+,-./0123456789:;<=>?ÍABCDEFGHIJKLMNOPQRSTUVWXYZÃÕÚܧ~abcdefghijklmnopqrstuvwxyzãõ`üà',
extCharsEnc: '\fΦΓ^ΩΠΨΣΘ{}\\[~]|',
escCharsEnc: '\nªÇÀ∞^\\€Ó()/<=>Í',
extCharsDec: 'êç\fÔôÁáΦΓ^ΩΠΨΣΘÊ{}\\[~]|ÀÍÓÚÃÕ€íóúãõâ',
escCharsDec: 'éç\nÔôÁáªÇÀ∞^\\€ÓÉ()/<=>ÍAIOUÃÕaeiouãõà',
charRegex: /^[@£$¥êéúíóç\nÔô\rÁáΔ_ªÇÀ∞^\\€Ó|\x1BÂâÊÉ !"#º%&\'()*+,-./0-9:;<=>?ÍA-ZÃÕÚܧ~a-zãõ`üàêç\fÔôÁáΦΓ^ΩΠΨΣΘÊ{}\\[~\]|ÀÍÓÚÃÕ€íóúãõâ]*$/,
charListEnc: {},
extCharListEnc: {},
charListDec: {},
extCharListDec: {}
}
};
gsmCoder.getCoder = function(encoding) {
var coder = this.GSM;
switch (encoding) {
case 0x01:
coder = this.GSM_TR;
break;
case 0x02:
coder = this.GSM_ES;
break;
case 0x03:
coder = this.GSM_PT;
break;
}
if (Object.keys(coder.charListEnc).length === 0) {
for (var i = 0; i < coder.chars.length; i++) {
coder.charListEnc[coder.chars[i]] = i;
coder.charListDec[i] = coder.chars[i];
}
var extCharsEnc = coder.extCharsEnc || coder.extChars;
var escCharsEnc = coder.escCharsEnc || coder.escChars;
for (var i = 0; i < extCharsEnc.length; i++) {
coder.extCharListEnc[extCharsEnc[i]] = escCharsEnc[i];
}
var extCharsDec = coder.extCharsDec || coder.extChars;
var escCharsDec = coder.escCharsDec || coder.escChars;
for (var i = 0; i < escCharsDec.length; i++) {
coder.extCharListDec[escCharsDec[i]] = extCharsDec[i];
}
}
return coder;
};
gsmCoder.encode = function(string, encoding) {
var coder = this.getCoder(encoding);
var extCharsEnc = coder.extCharsEnc || coder.extChars;
var extCharRegex = new RegExp('[' + extCharsEnc.replace(']', '\\]') + ']', 'g');
string = string.replace(extCharRegex, function(match) {
return '\x1B' + coder.extCharListEnc[match];
});
var result = [];
for (var i = 0; i < string.length; i++) {
result.push(string[i] in coder.charListEnc ? coder.charListEnc[string[i]] : '\x20');
}
return Buffer.from(result);
};
gsmCoder.decode = function (string, encoding) {
var coder = this.getCoder(encoding);
var escCharsDec = coder.escCharsDec || coder.escChars;
var escCharRegex = new RegExp('\x1B([' + escCharsDec + '])', 'g');
var result = '';
for (var i = 0; i < string.length; i++) {
result += coder.charListDec[string[i]] || ' ';
}
return result.replace(escCharRegex, function(match, p1) {
return coder.extCharListDec[p1];
});
};
gsmCoder.detect = function (string) {
if (gsmCoder.GSM_ES.charRegex.test(string)) {
return 0x02;
}
if (gsmCoder.GSM_PT.charRegex.test(string)) {
return 0x03;
}
if (gsmCoder.GSM_TR.charRegex.test(string)) {
return 0x01;
}
if (gsmCoder.GSM.charRegex.test(string)) {
return 0x00;
}
return undefined;
};
var encodings = {};
encodings.ASCII = { // GSM 03.38
chars: '@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1BÆæßÉ !"#¤%&\'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà',
charCodes: {},
extChars: {},
regex: /^[@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1BÆæßÉ !"#¤%&\'()*+,\-./0-9:;<=>?¡A-ZÄÖÑܧ¿a-zäöñüà\f^{}\\[~\]|€]*$/,
init: function() {
for (var i = 0; i < this.chars.length; i++) {
this.charCodes[this.chars[i]] = i;
}
var from = '\f^{}\\[~]|€', to = '\nΛ()/<=>¡e';
for (var i = 0; i < from.length; i++) {
this.extChars[from[i]] = to[i];
this.extChars[to[i]] = from[i];
}
},
match: function(value) {
return this.regex.test(value);
return gsmCoder.GSM.charRegex.test(value);
},
encode: function(value) {
var result = [];
value = value.replace(/[\f^{}\\[~\]|€]/g, function(match) {
return '\x1B' + this.extChars[match];
}.bind(this));
for (var i = 0; i < value.length; i++) {
result.push(value[i] in this.charCodes ? this.charCodes[value[i]] : 0x20);
}
return new Buffer(result);
return gsmCoder.encode(value, 0x00);
},
decode: function(value) {
var result = '';
for (var i = 0; i < value.length; i++) {
result += this.chars[value[i]] || ' ';
}
result = result.replace(/\x1B([\nΛ()\/<=>¡e])/g, function(match, p1) {
return this.extChars[p1];
}.bind(this));
return result;
return gsmCoder.decode(value, 0x00);
}
};
encodings.ASCII.init();
encodings.LATIN1 = {

@@ -316,2 +427,28 @@ match: function(value) {

var udhCoder = {};
/**
* @param buffer:Buffer
*
* @return Array
*/
udhCoder.getUdh = function(buffer) {
var bufferLength = buffer.length;
if (bufferLength <= 1) {
return [];
}
var udhList = [];
var cursor = 1;
do {
var udhLength = buffer[cursor + 1] + 2;
udhList.push(buffer.slice(cursor, cursor + udhLength));
cursor += udhLength;
} while (cursor < bufferLength);
return udhList;
};
var filters = {};

@@ -329,3 +466,3 @@

return value;
}
}
if (value instanceof Date) {

@@ -380,9 +517,32 @@ var result = value.getUTCFullYear().toString().substr(-2);

}
var message = typeof value == 'string' ? value : value.message;
if (typeof message == 'string') {
var encoding = encodings.detect(message);
if (message && this.data_coding === null) {
this.data_coding = consts.ENCODING[encoding];
var message = typeof value === 'string' ? value : value.message;
if (typeof message === 'string' && message) {
var encoded = false;
if (value.udh) {
var udhList = udhCoder.getUdh(value.udh);
for (var i = 0; i < udhList.length; i++) {
var udh = udhList[i];
if (udh[0] === 0x24 || udh[0] === 0x25) {
this.data_coding = consts.ENCODING.ASCII;
message = gsmCoder.encode(message, udh[2]);
encoded = true;
break;
}
}
}
message = encodings[encoding].encode(message);
if (!encoded) {
var encoding = encodings.default;
if (this.data_coding === null) {
encoding = encodings.detect(message);
this.data_coding = consts.ENCODING[encoding];
} else if (this.data_coding !== consts.ENCODING.SMSC_DEFAULT) {
for (var key in consts.ENCODING) {
if (consts.ENCODING[key] === this.data_coding) {
encoding = key;
break;
}
}
}
message = encodings[encoding].encode(message);
}
}

@@ -397,3 +557,3 @@ if (!value.udh || !value.udh.length) {

},
decode: function(value) {
decode: function(value, skipUdh) {
if (!Buffer.isBuffer(value) || !('data_coding' in this)) {

@@ -413,6 +573,6 @@ return value;

}
var udhi = this.esm_class & consts.ESM_CLASS.UDH_INDICATOR;
var udhi = this.esm_class & (consts.ESM_CLASS.UDH_INDICATOR || consts.ESM_CLASS.KANNEL_UDH_INDICATOR);
var result = {};
if (value.length && udhi) {
result.udh = value.slice(0, value[0] + 1);
if (!skipUdh && value.length && udhi) {
result.udh = udhCoder.getUdh(value.slice(0, value[0] + 1));
result.message = value.slice(value[0] + 1);

@@ -422,3 +582,16 @@ } else {

}
if (encodings[encoding]) {
if (result.udh && (encoding === consts.ENCODING.SMSC_DEFAULT || consts.ENCODING.ASCII)) {
var decoded = false;
for (var i = 0; i < result.udh.length; i++) {
var udh = result.udh[i];
if (udh[0] === 0x24 || udh[0] === 0x25) {
result.message = gsmCoder.decode(result.message, udh[2]);
decoded = true;
break;
}
}
if (!decoded && encodings[encoding]) {
result.message = encodings[encoding].decode(result.message);
}
} else if (encodings[encoding]) {
result.message = encodings[encoding].decode(result.message);

@@ -435,3 +608,3 @@ }

}
var result = new Buffer(value.data.length + 1);
var result = Buffer.alloc(value.data.length + 1);
result.writeUInt8(value.format, 0);

@@ -464,5 +637,5 @@ value.data.copy(result, 1);

if (typeof value.data == 'string') {
value.data = new Buffer(value.data, 'ascii');
value.data = Buffer.from(value.data, 'ascii');
}
var result = new Buffer(value.data.length + 1);
var result = Buffer.alloc(value.data.length + 1);
result.writeUInt8(value.format, 0);

@@ -492,3 +665,3 @@ value.data.copy(result, 1);

}
var result = new Buffer(3);
var result = Buffer.alloc(3);
result.writeUInt8(value.network, 0);

@@ -514,3 +687,3 @@ result.writeUInt16BE(value.content_type, 1);

}
var result = new Buffer(3);
var result = Buffer.alloc(3);
result.writeUInt8(value.unit, 0);

@@ -536,3 +709,3 @@ result.writeUInt16BE(value.interval, 1);

}
var result = new Buffer(value.number.length + 3);
var result = Buffer.alloc(value.number.length + 3);
result.writeUInt8(value.digit_mode || 0, 0);

@@ -562,6 +735,6 @@ result.writeUInt8(value.ton || 0, 1);

}
var result = new Buffer(value.display.length + 1);
var result = Buffer.alloc(value.display.length + 1);
result.writeUInt8(value.encoding, 0);
if (typeof value.display == 'string') {
value.display = new Buffer(value.display, 'ascii');
value.display = Buffer.from(value.display, 'ascii');
}

@@ -1194,2 +1367,3 @@ value.display.copy(result, 1);

UDH_INDICATOR: 0x40,
KANNEL_UDH_INDICATOR: 0x43,
SET_REPLY_PATH: 0x80

@@ -1232,3 +1406,7 @@ },

ENCODING: {
SMSC_DEFAULT: 0x00,
ASCII: 0x01,
GSM_TR: 0x01,
GSM_ES: 0x01,
GSM_PT: 0x01,
IA5: 0x01,

@@ -1347,2 +1525,3 @@ LATIN1: 0x03,

exports.filters = filters;
exports.gsmCoder = gsmCoder;
exports.consts = consts;

@@ -1349,0 +1528,0 @@ exports.commands = commands;

var defs = require('./defs'),
commands = defs.commands,
commandsById = defs.commandsById,
tlvs = defs.tlvs,
tlvsById = defs.tlvsById;
commands = defs.commands,
commandsById = defs.commandsById,
tlvs = defs.tlvs,
tlvsById = defs.tlvsById,
Buffer = require('safer-buffer').Buffer;

@@ -138,6 +139,11 @@ var pduHeadParams = [

this[key].forEach(function(value, i) {
this[key][i] = tlvs[key].filter[func].call(this, value);
this[key][i] = tlvs[key].filter[func].call(this, value, true);
}.bind(this));
} else {
this[key] = tlvs[key].filter[func].call(this, this[key]);
if (key === 'message_payload') {
skipUdh = this.short_message && this.short_message.message && this.short_message.message.length;
this[key] = tlvs[key].filter[func].call(this, this[key], skipUdh);
} else {
this[key] = tlvs[key].filter[func].call(this, this[key], true);
}
}

@@ -149,3 +155,3 @@ }

PDU.prototype._initBuffer = function() {
var buffer = new Buffer(this.command_length);
var buffer = Buffer.alloc(this.command_length);
pduHeadParams.forEach(function(key, i) {

@@ -152,0 +158,0 @@ buffer.writeUInt32BE(this[key], i * 4);

@@ -122,2 +122,9 @@ var net = require('net'),

Session.prototype.destroy = function(callback) {
if (callback) {
this.socket.once('close', callback);
}
this.socket.destroy();
};
var createShortcut = function(command) {

@@ -168,5 +175,11 @@ return function(options, responseCallback, sendCallback) {

util.inherits(Server, tls.Server);
util.inherits(Server, net.Server);
Server.prototype.listen = function() {
function SecureServer(options, listener) {
Server.call(this, options, listener);
}
util.inherits(SecureServer, tls.Server);
SecureServer.prototype.listen = Server.prototype.listen = function() {
var args = [this.tls ? 3550 : 2775];

@@ -178,6 +191,19 @@ if (typeof arguments[0] == 'function') {

}
return tls.Server.prototype.listen.apply(this, args);
var transport = this.tls ? tls : net;
return transport.Server.prototype.listen.apply(this, args);
};
exports.createServer = function(options, listener) {
if (typeof options == 'function') {
listener = options;
options = {};
} else {
options = options || {};
}
if (options.key && options.cert) {
return new SecureServer(options, listener);
}
return new Server(options, listener);

@@ -235,2 +261,3 @@ };

exports.Server = Server;
exports.SecureServer = SecureServer;
exports.PDU = PDU;

@@ -237,0 +264,0 @@ for (var key in defs) {

{
"name": "smpp",
"version": "0.3.1",
"version": "0.4.0",
"description": "SMPP client and server implementation in node.js",

@@ -29,4 +29,5 @@ "author": "Ali Farhadi <a.farhadi@gmail.com>",

"dependencies": {
"iconv-lite": "0.x"
"iconv-lite": "0.x",
"safer-buffer": ">= 2.1.2 < 3"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc