Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into local-bind

Conflicts:
	README.md
	package.json
  • Loading branch information...
commit eec29fcb5f1471715d79d6f3b5966092f1725511 2 parents 440a663 + 82ad45a
Ben Youngblood bjyoungblood authored
6 README.md
View
@@ -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
[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
-----
Easy method: `npm install shorty`
2  client-example.js
View
@@ -70,7 +70,7 @@ process.stdin.on('data', function(chunk) {
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() {
8 lib/client.js
View
@@ -179,18 +179,20 @@ exports.client = function(config) {
* use is up to the user, and it's not necessary if it doesn't matter
* whether messages were sent without error
*/
- self.sendMessage = function(sender, recipient, message) {
+ self.sendMessage = function(sender, recipient, message, options) {
var mySms, myPdu, success;
if (self.bind_type === smpp.RECEIVER || self.bind_type === smpp.UNBOUND) {
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
self.sequence_number++;
- mySms.sequence_number = self.sequence_number;
+ mySms = sms.create(sender, recipient, message, self.sequence_number, options);
// create and send the PDU
myPdu = smpp.submit_sm(mySms, {});
118 lib/models/sms.js
View
@@ -19,12 +19,11 @@
* @package models
*/
-var smpp = require('../smpp'),
- pdu = require('./pdu'),
- pack = require('./utils/pack'),
- Iconv = require('iconv').Iconv;
+var smpp = require('../smpp'),
+ pdu = require('./pdu'),
+ pack = require('./utils/pack');
-var sms = function(sender, recipient, message, sequence_number) {
+var sms = function(sender, recipient, message, sequence_number, options) {
var self = this;
self.sender = sender;
self.recipient = recipient;
@@ -34,30 +33,74 @@ var sms = function(sender, recipient, message, sequence_number) {
} else {
self.sequence_number = sequence_number;
}
+
+ if (options === undefined) {
+ self.options = {};
+ } else {
+ self.options = options;
+ }
+
self.confirmation = false;
self.failureTimeout = null;
self.toPdu = function(command) {
- var payload = pack.pack(
- 'a1cca' + (self.sender.length + 1) + 'cca' + (self.recipient.length + 1) + 'ccca1a1cccccU' + (Buffer.byteLength(self.message, 'utf8')),
- "", //service_type
- 0x00, //source_addr_ton
- 0x00, //source_addr_npi
- self.sender, //source_addr
- 0x00, //dest_addr_ton
- 0x00, //dest_addr_npi
- self.recipient, //destination_addr
- 0x00, //esm_class
- 0x00, //protocol_id
- 0x00, //priority_flag
- "", //schedule_delivery_time
- "", //validity_period
- 0x00, //a couple fields,
- 0x00,
- 0x03,
- 0x00,
- Buffer.byteLength(self.message), //message length
- self.message); //message
+ var payload,
+ source_addr_ton = 0x00,
+ source_addr_npi = 0x00,
+ dest_addr_ton = 0x00,
+ dest_addr_npi = 0x00,
+ esm_class = 0x00,
+ protocol_id = 0x00,
+ priority_flag = 0x00;
+
+ if (self.options.source_addr_ton !== undefined) {
+ source_addr_ton = self.options.source_addr_ton;
+ }
+
+ if (self.options.source_addr_npi !== undefined) {
+ source_addr_npi = self.options.source_addr_npi;
+ }
+
+ if (self.options.dest_addr_ton !== undefined) {
+ dest_addr_ton = self.options.dest_addr_ton;
+ }
+
+ 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);
};
@@ -66,11 +109,11 @@ var sms = function(sender, recipient, message, sequence_number) {
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
// over utf8, but it works for the moment
-
+
for (i = 0; i < 6; i++) {
if (myPdu.pdu_body[i] === 0x0) {
break;
@@ -106,35 +149,24 @@ exports.fromPdu = function(myPdu) {
} else {
i += 17;
}
-
+
if (myPdu.pdu_body[i] === 0x0) {
i++;
} else {
i += 17;
}
- i += 2;
- data_coding = myPdu.pdu_body[i];
-
- i += 2;
+ i += 4;
length = myPdu.pdu_body[i];
i++;
-
- 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);
- }
+ message = myPdu.pdu_body.toString('utf8', i, i + length);
sequence_number = myPdu.sequence_number;
return new sms(from, to, message, sequence_number);
};
-exports.create = function(sender, recipient, message, sequence_number) {
- return new sms(sender, recipient, message, sequence_number);
+exports.create = function(sender, recipient, message, sequence_number, options) {
+ return new sms(sender, recipient, message, sequence_number, options);
};
Please sign in to comment.
Something went wrong with that request. Please try again.