Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/byoungblood/shorty
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDotPro committed Dec 22, 2010
2 parents 14e2da0 + d8d8d42 commit d921362
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
6 changes: 4 additions & 2 deletions lib/client.js
Expand Up @@ -100,9 +100,11 @@ exports.client = function(config) {
// submit_sm_resp
self.sm_submit_resp(myPdu);
break;
case smpp.commands.bind_receiver_resp:
case smpp.commands.bind_transmitter_resp:
case smpp.commands.bind_transceiver_resp:
// bind_transceiver_resp
if (DEBUG) { console.log('bind_transceiver successful'); }
if (DEBUG) { console.log('bind successful'); }
self.bound = true;
self.sequence_number++;
if (typeof self.callbacks['bind_success'] == 'function') {
Expand Down Expand Up @@ -164,7 +166,7 @@ exports.client = function(config) {
// at the moment we only support transceiver mode, but receiver and transmitter
// modes are certainly a possibility, even if they're a little redundant
self.bind = function() {
var myPdu = smpp.bind_transceiver(self.config, self.sequence_number);
var myPdu = smpp.bind(self.config, self.sequence_number);
self.sendPdu(myPdu);
};

Expand Down
28 changes: 21 additions & 7 deletions lib/models/serverClient.js
Expand Up @@ -45,7 +45,7 @@ var serverClient = function(socket, server, closeConnectionServerCallback, callb

/*
* Implemented callbacks:
* - bind_request(system_id, password, system_type): use this to check the
* - bind_request(system_id, password, system_type, bind_type): use this to check the
* credentials of an incoming connection; return true to allow bind
* - bind_success(): called on a successful bind
* - incoming(sms): called when an incoming sms is received; return a
Expand All @@ -68,7 +68,7 @@ var serverClient = function(socket, server, closeConnectionServerCallback, callb
self.addr_npi = "";
self.addr_range = "";
// we only support transceiver right now, but the other options are receiver and transmitter
self.bind_type = "transceiver";
self.bind_type;

self.sms_delivered = {};

Expand Down Expand Up @@ -128,10 +128,12 @@ var serverClient = function(socket, server, closeConnectionServerCallback, callb
}

switch (myPdu.command_id) {
case smpp.commands.bind_receiver:
case smpp.commands.bind_transceiver:
case smpp.commands.bind_transmitter:
// bind_transceiver
if (DEBUG) { console.log('transceiver attempting bind'); }
self.bind_transceiver_resp(myPdu);
self.bind_resp(myPdu);
break;

case smpp.commands.enquire_link_resp:
Expand Down Expand Up @@ -224,7 +226,7 @@ var serverClient = function(socket, server, closeConnectionServerCallback, callb
}
};

self.bind_transceiver_resp = function(myPdu) {
self.bind_resp = function(myPdu) {
/*
* Parse the PDU body
*/
Expand Down Expand Up @@ -258,11 +260,23 @@ var serverClient = function(socket, server, closeConnectionServerCallback, callb
self.addr_range += payload.toString('ascii', i, i+1);
}

switch (myPdu.command_id) {
case smpp.commands.bind_receiver:
self.bind_type = 'receiver';
break;
case smpp.commands.bind_transceiver:
self.bind_type = 'transceiver';
break;
case smpp.commands.bind_transmitter:
self.bind_type = 'transmitter';
break;
}

/*
* Ask the callback (if there is one) if the credentials are okay
*/
if (typeof self.callbacks['bind_request'] == 'function') {
var bindAllowed = self.callbacks['bind_request'](self.system_id, self.password, self.system_type);
var bindAllowed = self.callbacks['bind_request'](self.system_id, self.password, self.system_type, self.bind_type);
} else {
var bindAllowed = true;
}
Expand All @@ -271,7 +285,7 @@ var serverClient = function(socket, server, closeConnectionServerCallback, callb
* Create a new PDU with our response
*/
if (bindAllowed) {
var newPdu = smpp.bind_transceiver_resp(self.sequence_number, self.config.system_id);
var newPdu = smpp.bind_resp(myPdu.command_id, self.sequence_number, self.config.system_id);
self.bound = true;
self.socket.setTimeout(self.config.timeout * 1000);
self.socket.on('timeout', self.enquire_link);
Expand All @@ -280,7 +294,7 @@ var serverClient = function(socket, server, closeConnectionServerCallback, callb
// were incorrect (if they were). the Shorty developers think that this is a bad security practice
// so we offer another option
if (self.config.strict == 1) {
var newPdu = smpp.bind_transceiver_resp(self.sequence_number, self.config.system_id, true);
var newPdu = smpp.bind_resp(myPdu.command_id, self.sequence_number, self.config.system_id, true);
} else {

// outside of strict mode, Shorty will reject this connection, meaning that all incoming data
Expand Down
25 changes: 21 additions & 4 deletions lib/smpp.js
Expand Up @@ -86,7 +86,7 @@ exports.submit_sm_resp = function(myPdu, message_id) {
return pdu.createPdu(exports.commands.submit_sm_resp, myPdu.sequence_number, payload);
};

exports.bind_transceiver_resp = function(sequence_number, system_id, error_status) {
exports.bind_resp = function(bind_type, sequence_number, system_id, error_status) {
// IMPORTANT: note the parentheses around (system_id.length + 1)
// This is absolutely essential and will totally screw up your PDU
// if you omit them.
Expand All @@ -106,7 +106,8 @@ exports.bind_transceiver_resp = function(sequence_number, system_id, error_statu
var cmd_status = 0x0;
}

return pdu.createPdu(exports.commands.bind_transceiver_resp, sequence_number, payload, cmd_status);
var command_id = 0x80000000 | bind_type;
return pdu.createPdu(command_id, sequence_number, payload, cmd_status);
};

exports.enquire_link = function(sequence_number) {
Expand Down Expand Up @@ -138,7 +139,7 @@ exports.deliver_sm = function(mySms, optional_params) {
* Since most of the parameters required for this method are in
* the config file, just pass in the config object (or a subset)
*/
exports.bind_transceiver = function(config, sequence_number) {
exports.bind = function(config, sequence_number) {
var payload = pdu.pack(
'a' + (config.system_id.length + 1) +
'a' + (config.password.length + 1) +
Expand All @@ -148,7 +149,23 @@ exports.bind_transceiver = function(config, sequence_number) {
config.version, config.addr_ton, config.addr_npi,
config.addr_range);

return pdu.createPdu(smpp.commands.bind_transceiver, sequence_number, payload);
var command;
switch (config.mode) {
case 'transceiver':
command = smpp.commands.bind_transceiver;
break;
case 'receiver':
command = smpp.commands.bind_receiver;
break;
case 'transmitter':
command = smpp.commands.bind_transmitter;
break;
default:
throw('invalid client mode specified in config');
break;
}

return pdu.createPdu(command, sequence_number, payload);
};

/*
Expand Down
4 changes: 2 additions & 2 deletions server-example.js
Expand Up @@ -26,8 +26,8 @@ var shorty = require('./lib/shorty'),
shortyServer = shorty.createServer('config.json');

// all clientOn event handlers must be set up before calling shortyServer.start()
shortyServer.clientOn('bind_request', function(username, password, system_type) {
console.log('bind_request callback fired');
shortyServer.clientOn('bind_request', function(username, password, system_type, bind_type) {
console.log('bind_request ('+bind_type+') callback fired');
return true;
});

Expand Down

0 comments on commit d921362

Please sign in to comment.