Permalink
Browse files

ability to add vendor-specific command statuses and optional params

  • Loading branch information...
1 parent c4d121d commit 3261921d1e27c5c76f6e49205cea36eda4bd0a1e @bjyoungblood bjyoungblood committed Feb 10, 2012
Showing with 70 additions and 18 deletions.
  1. +7 −3 lib/client.js
  2. +7 −1 lib/data-handler.js
  3. +5 −1 lib/pdu-parser.js
  4. +6 −2 lib/pdu-writer.js
  5. +8 −4 lib/server-connection.js
  6. +5 −3 lib/server.js
  7. +32 −4 lib/shorty.js
View
@@ -23,11 +23,11 @@ var net = require('net'),
events = require('events'),
util = require('util'),
writer = require('./pdu-writer'),
- smpp = require('./smpp-definitions'),
data = require('./data-handler')
- common = require('./common');
+ common = require('./common'),
+ smpp = {};
-exports.client = function(config) {
+exports.client = function(config, smppDefs) {
var self = this;
self.config = config;
self.socket = {};
@@ -38,6 +38,10 @@ exports.client = function(config) {
self.start_time = new Date();
self.shouldReconnect = true;
+ smpp = smppDefs;
+ writer.setSmppDefinitions(smpp);
+ data.setSmppDefinitions(smpp);
+
self.reconnectTimer = false;
self.splitPacketBuffer = new Buffer(0);
View
@@ -19,7 +19,13 @@
* @package models
*/
-var parser = require('./pdu-parser');
+var parser = require('./pdu-parser'),
+ smpp;
+
+exports.setSmppDefinitions = function(defs) {
+ smpp = defs;
+ parser.setSmppDefinitions(defs);
+};
exports.fromBuffer = function(pduBuffer, splitBuffer) {
var pdus = [], tempPduBuffer, bufferPosition, length, pdu, splitPacketBuffer;
View
@@ -19,7 +19,11 @@
* @package smpp
*/
-var smpp = require('./smpp-definitions');
+var smpp;
+
+exports.setSmppDefinitions = function(defs) {
+ smpp = defs;
+};
/**
* Thanks to the amazing improvements to buffers in node v0.6, we no longer have
View
@@ -19,8 +19,12 @@
* @package smpp
*/
-var smpp = require('./smpp-definitions'),
- common = require('./common.js');
+var common = require('./common.js'),
+ smpp;
+
+exports.setSmppDefinitions = function(defs) {
+ smpp = defs;
+};
exports.write = function(pdu) {
var format, buffer, fields = [], offset = 0, length = 0;
View
@@ -24,11 +24,15 @@ var net = require('net'),
util = require('util'),
writer = require('./pdu-writer'),
data = require('./data-handler'),
- smpp = require('./smpp-definitions');
+ smpp;
-var serverConnection = function(socket, server, closeConnectionServerCallback, callbacks) {
+var serverConnection = function(socket, server, closeConnectionServerCallback, smppDefs) {
var self = this;
+ smpp = smppDefs;
+ writer.setSmppDefinitions(smpp);
+ data.setSmppDefinitions(smpp);
+
self.socket = socket;
self.sequence_number = 1;
self.bound = false;
@@ -440,8 +444,8 @@ var serverConnection = function(socket, server, closeConnectionServerCallback, c
util.inherits(serverConnection, events.EventEmitter);
-exports.fromSocket = function(socket, server, connectionEndCallback, callbacks) {
- var client = new serverConnection(socket, server, connectionEndCallback, callbacks);
+exports.fromSocket = function(socket, server, connectionEndCallback, smppDefs) {
+ var client = new serverConnection(socket, server, connectionEndCallback, smppDefs);
client.init(client.socketDataHandler);
return client;
};
View
@@ -22,16 +22,18 @@
var net = require('net'),
events = require('events'),
util = require('util'),
- client = require('./server-connection');
+ client = require('./server-connection'),
+ smpp;
-exports.server = function(config) {
+exports.server = function(config, smppDefs) {
var self = this;
self.config = config;
self.server = {};
self.clients = [];
self.started = false;
self.connections = 0;
+ smpp = smppDefs;
self.eventListeners = [];
self.on('newListener', function(event, listener) {
@@ -87,7 +89,7 @@ exports.server = function(config) {
self.connectionListener = function(incomingSocket) {
// add a client and keep track of it
- var myClient = client.fromSocket(incomingSocket, self, self.clientCloseHandler);
+ var myClient = client.fromSocket(incomingSocket, self, self.clientCloseHandler, smpp);
myClient.connection_id = self.connections++;
for (var i = 0; i < self.eventListeners.length; i++) {
View
@@ -21,7 +21,10 @@
var client = require('./client').client,
server = require('./server').server,
- fs = require('fs');
+ fs = require('fs'),
+ smpp = require('./smpp-definitions'),
+ assert = require('assert'),
+ shorty = exports;
exports.loadConfig = function(file) {
var config;
@@ -47,19 +50,44 @@ exports.createClient = function(config) {
config = exports.loadConfig(config);
}
- return new client(config.smpp);
+ return new client(config.smpp, shorty.getSmppDefinitions());
};
exports.createServer = function(config) {
if (typeof config === "string") {
config = exports.loadConfig(config);
}
- return new server(config.smpp);
+ return new server(config.smpp, shorty.getSmppDefinitions());
+};
+
+exports.addVendorCommandStatus = function(definitions) {
+ assert(typeof definitions === "object", "Status codes must be provided as an object");
+
+ for (var cmdStatus in definitions) {
+ assert(definitions[cmdStatus].hasOwnProperty('value'), "Status codes must have a defined value");
+ assert(definitions[cmdStatus].hasOwnProperty('description'), "Status codes must have a description");
+ assert(typeof definitions[cmdStatus].value === "number", "Status code value must be a number");
+
+ smpp.command_status[cmdStatus] = definitions[cmdStatus];
+ smpp.command_status_codes[ definitions[cmdStatus].value ] = cmdStatus;
+ }
+};
+
+exports.addVendorOptionalParams = function(definitions) {
+ assert(typeof definitions === "object", "Optional params must be provided as an object");
+
+ for (var optParam in definitions) {
+ assert(definitions[optParam].hasOwnProperty('tag'), "Optional params must have a tag");
+ assert(definitions[optParam].hasOwnProperty('type'), "Optional params must have a data type");
+
+ smpp.optional_params[optParam] = definitions[optParam];
+ smpp.optional_param_tags[ definitions[optParam].tag ] = optParam;
+ }
};
exports.getSmppDefinitions = function() {
- return require('./smpp-definitions');
+ return smpp;
};
exports.getPduParser = function() {

0 comments on commit 3261921

Please sign in to comment.