Permalink
Browse files

certain response PDUs omit the PDU body if there is a non-zero comman…

…d_status
  • Loading branch information...
1 parent 04f058a commit 2df20c5e3b77a59d8a499e8ba9c2755f87fcbf77 @bjyoungblood bjyoungblood committed Dec 5, 2012
Showing with 31 additions and 1 deletion.
  1. +6 −1 lib/pdu-parser.js
  2. +25 −0 lib/smpp-definitions.js
View
@@ -61,6 +61,11 @@ exports.parse = function(buffer) {
format = smpp.command_formats[smpp.command_ids[result.command_id]];
+ // for certain PDUs, the PDU body is omitted if there is a non-zero (error) status
+ if (result.command_status != 0 && format.empty_body_if_error == true) {
+ return result;
+ }
+
// Read each mandatory field from the command format definition
for (var i = 0; i < format.body.length; i++) {
var start, end;
@@ -80,7 +85,7 @@ exports.parse = function(buffer) {
* - for fixed-length strings, the string can either be
* empty (just a null terminator) or the the length
* defined in the "length" field
- *
+ *
* string: similar to c-string, but not null-terminated; this is only
* really present in the short_message field, which is a special
* case anyway, due to the fact that its length is defined by
View
@@ -165,6 +165,7 @@ exports.command_status_codes = {
exports.command_formats = {
bind_transmitter : {
command_id : 0x00000002,
+ empty_body_if_error: false,
body : [
{ name: "system_id", type: "c-string", min: 1, max: 16 },
{ name: "password", type: "c-string", min: 1, max: 9 },
@@ -178,13 +179,15 @@ exports.command_formats = {
bind_transmitter_resp : {
command_id : 0x80000002,
+ empty_body_if_error: true,
body: [
{ name: "system_id", type: "c-string", min: 1, max: 16 }
]
},
bind_receiver : {
command_id : 0x00000001,
+ empty_body_if_error: false,
body : [
{ name: "system_id", type: "c-string", min: 1, max: 16 },
{ name: "password", type: "c-string", min: 1, max: 9 },
@@ -198,13 +201,15 @@ exports.command_formats = {
bind_receiver_resp : {
command_id : 0x80000001,
+ empty_body_if_error: true,
body: [
{ name: "system_id", type: "c-string", min: 1, max: 16 }
]
},
bind_transceiver : {
command_id : 0x00000009,
+ empty_body_if_error: false,
body : [
{ name: "system_id", type: "c-string", min: 1, max: 16 },
{ name: "password", type: "c-string", min: 1, max: 9 },
@@ -218,13 +223,15 @@ exports.command_formats = {
bind_transceiver_resp : {
command_id : 0x80000009,
+ empty_body_if_error: true,
body: [
{ name: "system_id", type: "c-string", min: 1, max: 16 }
]
},
outbind : {
command_id : 0x0000000B,
+ empty_body_if_error: false,
body : [
{ name: "system_id", type: "c-string", min: 1, max: 16 },
{ name: "password", type: "c-string", min: 1, max: 9 },
@@ -233,21 +240,25 @@ exports.command_formats = {
unbind : {
command_id : 0x00000006,
+ empty_body_if_error: false,
body : []
},
unbind_resp : {
command_id : 0x80000006,
+ empty_body_if_error: false,
body : []
},
generic_nack : {
command_id : 0x80000000,
+ empty_body_if_error: false,
body : []
},
submit_sm : {
command_id : 0x00000004,
+ empty_body_if_error: false,
body : [
{ name: "service_type", type: "c-string", min: 1, max: 6, default: "" },
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
@@ -272,13 +283,15 @@ exports.command_formats = {
submit_sm_resp : {
command_id : 0x80000004,
+ empty_body_if_error: true,
body : [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
]
},
deliver_sm : {
command_id : 0x00000005,
+ empty_body_if_error: false,
body : [
{ name: "service_type", type: "c-string", min: 1, max: 6, default: "" },
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
@@ -303,13 +316,15 @@ exports.command_formats = {
deliver_sm_resp : {
command_id : 0x80000005,
+ empty_body_if_error: false,
body : [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
]
},
data_sm : {
command_id : 0x00000103,
+ empty_body_if_error: false,
body : [
{ name: "service_type", type: "c-string", min: 1, max: 6, default: "" },
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
@@ -326,13 +341,15 @@ exports.command_formats = {
data_sm_resp : {
command_id : 0x80000103,
+ empty_body_if_error: false,
body : [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" }
]
},
query_sm : {
command_id : 0x00000003,
+ empty_body_if_error: false,
body : [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
@@ -343,6 +360,7 @@ exports.command_formats = {
query_sm_resp : {
command_id : 0x80000003,
+ empty_body_if_error: false,
body: [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
{ name: "final_date", type: "c-string", length: 17, default: "" },
@@ -353,6 +371,7 @@ exports.command_formats = {
cancel_sm : {
command_id : 0x00000008,
+ empty_body_if_error: false,
body: [
{ name: "service_type", type: "c-string", min: 1, max: 6, default: "" },
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
@@ -367,11 +386,13 @@ exports.command_formats = {
cancel_sm_resp : {
command_id : 0x80000008,
+ empty_body_if_error: false,
body : []
},
replace_sm : {
command_id : 0x00000007,
+ empty_body_if_error: false,
body : [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
@@ -388,21 +409,25 @@ exports.command_formats = {
replace_sm_resp : {
command_id : 0x80000007,
+ empty_body_if_error: false,
body : []
},
enquire_link : {
command_id : 0x00000015,
+ empty_body_if_error: false,
body : []
},
enquire_link_resp : {
command_id : 0x80000015,
+ empty_body_if_error: false,
body : []
},
alert_notification : {
command_id : 0x00000102,
+ empty_body_if_error: false,
body : [
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
{ name: "source_addr_npi", type: "int", bytes: 1, default: 0 },

0 comments on commit 2df20c5

Please sign in to comment.