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' into local-bind
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
	package.json
  • Loading branch information
bjyoungblood committed Nov 1, 2011
2 parents 440a663 + 82ad45a commit eec29fc
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 53 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ Shorty is a lightweight, high performance SMPP client and server built on Node.j
(tested on v0.2.8, v0.4.0, and v0.4.x). Shorty is sponsored and maintained by (tested on v0.2.8, v0.4.0, and v0.4.x). Shorty is sponsored and maintained by
[SMS Cloud](http://www.smscloud.com/), a subsidiary of MediaTech Designs, LLC. [SMS Cloud](http://www.smscloud.com/), a subsidiary of MediaTech Designs, LLC.


Requirements
------------
Currently, Shorty requires the node-iconv library in order to support conversion
from UCS-2 to UTF-8. This package is available in npm using `npm install iconv`
or on [Github](https://github.com/bnoordhuis/node-iconv).

Usage Usage
----- -----
Easy method: `npm install shorty` Easy method: `npm install shorty`
Expand Down
2 changes: 1 addition & 1 deletion client-example.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ process.stdin.on('data', function(chunk) {
message += parts[i] + " "; message += parts[i] + " ";
} }


id = shortyClient.sendMessage(parts[0], parts[1], message); id = shortyClient.sendMessage(parts[0], parts[1], message, {source_addr_ton:0x01,dest_addr_ton:0x01});
}); });


var sighandle = function() { var sighandle = function() {
Expand Down
8 changes: 5 additions & 3 deletions lib/client.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -179,18 +179,20 @@ exports.client = function(config) {
* use is up to the user, and it's not necessary if it doesn't matter * use is up to the user, and it's not necessary if it doesn't matter
* whether messages were sent without error * whether messages were sent without error
*/ */
self.sendMessage = function(sender, recipient, message) { self.sendMessage = function(sender, recipient, message, options) {
var mySms, myPdu, success; var mySms, myPdu, success;


if (self.bind_type === smpp.RECEIVER || self.bind_type === smpp.UNBOUND) { if (self.bind_type === smpp.RECEIVER || self.bind_type === smpp.UNBOUND) {
return false; return false;
} }


mySms = sms.create(sender, recipient, message); if (options === undefined) {
options = {};
}


// for all requests that we initiate, we need to increment the sequence number // for all requests that we initiate, we need to increment the sequence number
self.sequence_number++; self.sequence_number++;
mySms.sequence_number = self.sequence_number; mySms = sms.create(sender, recipient, message, self.sequence_number, options);


// create and send the PDU // create and send the PDU
myPdu = smpp.submit_sm(mySms, {}); myPdu = smpp.submit_sm(mySms, {});
Expand Down
118 changes: 75 additions & 43 deletions lib/models/sms.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
* @package models * @package models
*/ */


var smpp = require('../smpp'), var smpp = require('../smpp'),
pdu = require('./pdu'), pdu = require('./pdu'),
pack = require('./utils/pack'), pack = require('./utils/pack');
Iconv = require('iconv').Iconv;


var sms = function(sender, recipient, message, sequence_number) { var sms = function(sender, recipient, message, sequence_number, options) {
var self = this; var self = this;
self.sender = sender; self.sender = sender;
self.recipient = recipient; self.recipient = recipient;
Expand All @@ -34,30 +33,74 @@ var sms = function(sender, recipient, message, sequence_number) {
} else { } else {
self.sequence_number = sequence_number; self.sequence_number = sequence_number;
} }

if (options === undefined) {
self.options = {};
} else {
self.options = options;
}

self.confirmation = false; self.confirmation = false;
self.failureTimeout = null; self.failureTimeout = null;


self.toPdu = function(command) { self.toPdu = function(command) {
var payload = pack.pack( var payload,
'a1cca' + (self.sender.length + 1) + 'cca' + (self.recipient.length + 1) + 'ccca1a1cccccU' + (Buffer.byteLength(self.message, 'utf8')), source_addr_ton = 0x00,
"", //service_type source_addr_npi = 0x00,
0x00, //source_addr_ton dest_addr_ton = 0x00,
0x00, //source_addr_npi dest_addr_npi = 0x00,
self.sender, //source_addr esm_class = 0x00,
0x00, //dest_addr_ton protocol_id = 0x00,
0x00, //dest_addr_npi priority_flag = 0x00;
self.recipient, //destination_addr
0x00, //esm_class if (self.options.source_addr_ton !== undefined) {
0x00, //protocol_id source_addr_ton = self.options.source_addr_ton;
0x00, //priority_flag }
"", //schedule_delivery_time
"", //validity_period if (self.options.source_addr_npi !== undefined) {
0x00, //a couple fields, source_addr_npi = self.options.source_addr_npi;
0x00, }
0x03,
0x00, if (self.options.dest_addr_ton !== undefined) {
Buffer.byteLength(self.message), //message length dest_addr_ton = self.options.dest_addr_ton;
self.message); //message }

if (self.options.dest_addr_npi !== undefined) {
dest_addr_npi = self.options.dest_addr_npi;
}

if (self.options.esm_class !== undefined) {
esm_class = self.options.esm_class;
}

if (self.options.protocol_id !== undefined) {
protocol_id = self.options.protocol_id;
}

if (self.options.priority_flag !== undefined) {
priority_flag = self.options.priority_flag;
}

payload = pack.pack(
'a1cca' + (self.sender.length + 1) + 'cca' + (self.recipient.length + 1) + 'ccca1a1cccccU' + (Buffer.byteLength(self.message, 'utf8')),
"", //service_type
source_addr_ton, //source_addr_ton
source_addr_npi, //source_addr_npi
self.sender, //source_addr
dest_addr_ton, //dest_addr_ton
dest_addr_npi, //dest_addr_npi
self.recipient, //destination_addr
esm_class, //esm_class
protocol_id, //protocol_id
priority_flag, //priority_flag
"", //schedule_delivery_time
"", //validity_period
0x00, //a couple fields,
0x00,
0x03,
0x00,
Buffer.byteLength(self.message), //message length
self.message); //message


return pdu.createPdu(command, self.sequence_number, payload); return pdu.createPdu(command, self.sequence_number, payload);
}; };
Expand All @@ -66,11 +109,11 @@ var sms = function(sender, recipient, message, sequence_number) {


exports.fromPdu = function(myPdu) { exports.fromPdu = function(myPdu) {


var i, from, to, length, ucs2Message, message, sequence_number, start, end, data_coding, iconv; var i, from, to, length, message, sequence_number, start, end;


// not really sure whether we'll run into encoding issues by using ascii encoding // not really sure whether we'll run into encoding issues by using ascii encoding
// over utf8, but it works for the moment // over utf8, but it works for the moment

for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
if (myPdu.pdu_body[i] === 0x0) { if (myPdu.pdu_body[i] === 0x0) {
break; break;
Expand Down Expand Up @@ -106,35 +149,24 @@ exports.fromPdu = function(myPdu) {
} else { } else {
i += 17; i += 17;
} }

if (myPdu.pdu_body[i] === 0x0) { if (myPdu.pdu_body[i] === 0x0) {
i++; i++;
} else { } else {
i += 17; i += 17;
} }


i += 2; i += 4;
data_coding = myPdu.pdu_body[i];

i += 2;
length = myPdu.pdu_body[i]; length = myPdu.pdu_body[i];


i++; i++;

message = myPdu.pdu_body.toString('utf8', i, i + length);
if (data_coding == 0x08) {
ucs2Message = new Buffer(length);
myPdu.pdu_body.copy(ucs2Message, 0, i, i + length);
iconv = new Iconv('UCS-2', 'UTF-8//TRANSLIT//IGNORE');
message = iconv.convert(ucs2Message).toString('utf8');
} else {
message = myPdu.pdu_body.toString('utf8', i, i + length);
}


sequence_number = myPdu.sequence_number; sequence_number = myPdu.sequence_number;


return new sms(from, to, message, sequence_number); return new sms(from, to, message, sequence_number);
}; };


exports.create = function(sender, recipient, message, sequence_number) { exports.create = function(sender, recipient, message, sequence_number, options) {
return new sms(sender, recipient, message, sequence_number); return new sms(sender, recipient, message, sequence_number, options);
}; };

0 comments on commit eec29fc

Please sign in to comment.