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

Commit

Permalink
certain response PDUs omit the PDU body if there is a non-zero comman…
Browse files Browse the repository at this point in the history
…d_status
  • Loading branch information
bjyoungblood committed Dec 5, 2012
1 parent 04f058a commit 2df20c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/pdu-parser.js
Expand Up @@ -61,6 +61,11 @@ exports.parse = function(buffer) {


format = smpp.command_formats[smpp.command_ids[result.command_id]]; 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 // Read each mandatory field from the command format definition
for (var i = 0; i < format.body.length; i++) { for (var i = 0; i < format.body.length; i++) {
var start, end; var start, end;
Expand All @@ -80,7 +85,7 @@ exports.parse = function(buffer) {
* - for fixed-length strings, the string can either be * - for fixed-length strings, the string can either be
* empty (just a null terminator) or the the length * empty (just a null terminator) or the the length
* defined in the "length" field * defined in the "length" field
* *
* string: similar to c-string, but not null-terminated; this is only * string: similar to c-string, but not null-terminated; this is only
* really present in the short_message field, which is a special * really present in the short_message field, which is a special
* case anyway, due to the fact that its length is defined by * case anyway, due to the fact that its length is defined by
Expand Down
25 changes: 25 additions & 0 deletions lib/smpp-definitions.js
Expand Up @@ -165,6 +165,7 @@ exports.command_status_codes = {
exports.command_formats = { exports.command_formats = {
bind_transmitter : { bind_transmitter : {
command_id : 0x00000002, command_id : 0x00000002,
empty_body_if_error: false,
body : [ body : [
{ name: "system_id", type: "c-string", min: 1, max: 16 }, { name: "system_id", type: "c-string", min: 1, max: 16 },
{ name: "password", type: "c-string", min: 1, max: 9 }, { name: "password", type: "c-string", min: 1, max: 9 },
Expand All @@ -178,13 +179,15 @@ exports.command_formats = {


bind_transmitter_resp : { bind_transmitter_resp : {
command_id : 0x80000002, command_id : 0x80000002,
empty_body_if_error: true,
body: [ body: [
{ name: "system_id", type: "c-string", min: 1, max: 16 } { name: "system_id", type: "c-string", min: 1, max: 16 }
] ]
}, },


bind_receiver : { bind_receiver : {
command_id : 0x00000001, command_id : 0x00000001,
empty_body_if_error: false,
body : [ body : [
{ name: "system_id", type: "c-string", min: 1, max: 16 }, { name: "system_id", type: "c-string", min: 1, max: 16 },
{ name: "password", type: "c-string", min: 1, max: 9 }, { name: "password", type: "c-string", min: 1, max: 9 },
Expand All @@ -198,13 +201,15 @@ exports.command_formats = {


bind_receiver_resp : { bind_receiver_resp : {
command_id : 0x80000001, command_id : 0x80000001,
empty_body_if_error: true,
body: [ body: [
{ name: "system_id", type: "c-string", min: 1, max: 16 } { name: "system_id", type: "c-string", min: 1, max: 16 }
] ]
}, },


bind_transceiver : { bind_transceiver : {
command_id : 0x00000009, command_id : 0x00000009,
empty_body_if_error: false,
body : [ body : [
{ name: "system_id", type: "c-string", min: 1, max: 16 }, { name: "system_id", type: "c-string", min: 1, max: 16 },
{ name: "password", type: "c-string", min: 1, max: 9 }, { name: "password", type: "c-string", min: 1, max: 9 },
Expand All @@ -218,13 +223,15 @@ exports.command_formats = {


bind_transceiver_resp : { bind_transceiver_resp : {
command_id : 0x80000009, command_id : 0x80000009,
empty_body_if_error: true,
body: [ body: [
{ name: "system_id", type: "c-string", min: 1, max: 16 } { name: "system_id", type: "c-string", min: 1, max: 16 }
] ]
}, },


outbind : { outbind : {
command_id : 0x0000000B, command_id : 0x0000000B,
empty_body_if_error: false,
body : [ body : [
{ name: "system_id", type: "c-string", min: 1, max: 16 }, { name: "system_id", type: "c-string", min: 1, max: 16 },
{ name: "password", type: "c-string", min: 1, max: 9 }, { name: "password", type: "c-string", min: 1, max: 9 },
Expand All @@ -233,21 +240,25 @@ exports.command_formats = {


unbind : { unbind : {
command_id : 0x00000006, command_id : 0x00000006,
empty_body_if_error: false,
body : [] body : []
}, },


unbind_resp : { unbind_resp : {
command_id : 0x80000006, command_id : 0x80000006,
empty_body_if_error: false,
body : [] body : []
}, },


generic_nack : { generic_nack : {
command_id : 0x80000000, command_id : 0x80000000,
empty_body_if_error: false,
body : [] body : []
}, },


submit_sm : { submit_sm : {
command_id : 0x00000004, command_id : 0x00000004,
empty_body_if_error: false,
body : [ body : [
{ name: "service_type", type: "c-string", min: 1, max: 6, default: "" }, { name: "service_type", type: "c-string", min: 1, max: 6, default: "" },
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 }, { name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
Expand All @@ -272,13 +283,15 @@ exports.command_formats = {


submit_sm_resp : { submit_sm_resp : {
command_id : 0x80000004, command_id : 0x80000004,
empty_body_if_error: true,
body : [ body : [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" }, { name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
] ]
}, },


deliver_sm : { deliver_sm : {
command_id : 0x00000005, command_id : 0x00000005,
empty_body_if_error: false,
body : [ body : [
{ name: "service_type", type: "c-string", min: 1, max: 6, default: "" }, { name: "service_type", type: "c-string", min: 1, max: 6, default: "" },
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 }, { name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
Expand All @@ -303,13 +316,15 @@ exports.command_formats = {


deliver_sm_resp : { deliver_sm_resp : {
command_id : 0x80000005, command_id : 0x80000005,
empty_body_if_error: false,
body : [ body : [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" }, { name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
] ]
}, },


data_sm : { data_sm : {
command_id : 0x00000103, command_id : 0x00000103,
empty_body_if_error: false,
body : [ body : [
{ name: "service_type", type: "c-string", min: 1, max: 6, default: "" }, { name: "service_type", type: "c-string", min: 1, max: 6, default: "" },
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 }, { name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
Expand All @@ -326,13 +341,15 @@ exports.command_formats = {


data_sm_resp : { data_sm_resp : {
command_id : 0x80000103, command_id : 0x80000103,
empty_body_if_error: false,
body : [ body : [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" } { name: "message_id", type: "c-string", min: 1, max: 65, default: "" }
] ]
}, },


query_sm : { query_sm : {
command_id : 0x00000003, command_id : 0x00000003,
empty_body_if_error: false,
body : [ body : [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" }, { name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 }, { name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
Expand All @@ -343,6 +360,7 @@ exports.command_formats = {


query_sm_resp : { query_sm_resp : {
command_id : 0x80000003, command_id : 0x80000003,
empty_body_if_error: false,
body: [ body: [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" }, { name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
{ name: "final_date", type: "c-string", length: 17, default: "" }, { name: "final_date", type: "c-string", length: 17, default: "" },
Expand All @@ -353,6 +371,7 @@ exports.command_formats = {


cancel_sm : { cancel_sm : {
command_id : 0x00000008, command_id : 0x00000008,
empty_body_if_error: false,
body: [ body: [
{ name: "service_type", type: "c-string", min: 1, max: 6, default: "" }, { name: "service_type", type: "c-string", min: 1, max: 6, default: "" },
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" }, { name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
Expand All @@ -367,11 +386,13 @@ exports.command_formats = {


cancel_sm_resp : { cancel_sm_resp : {
command_id : 0x80000008, command_id : 0x80000008,
empty_body_if_error: false,
body : [] body : []
}, },


replace_sm : { replace_sm : {
command_id : 0x00000007, command_id : 0x00000007,
empty_body_if_error: false,
body : [ body : [
{ name: "message_id", type: "c-string", min: 1, max: 65, default: "" }, { name: "message_id", type: "c-string", min: 1, max: 65, default: "" },
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 }, { name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
Expand All @@ -388,21 +409,25 @@ exports.command_formats = {


replace_sm_resp : { replace_sm_resp : {
command_id : 0x80000007, command_id : 0x80000007,
empty_body_if_error: false,
body : [] body : []
}, },


enquire_link : { enquire_link : {
command_id : 0x00000015, command_id : 0x00000015,
empty_body_if_error: false,
body : [] body : []
}, },


enquire_link_resp : { enquire_link_resp : {
command_id : 0x80000015, command_id : 0x80000015,
empty_body_if_error: false,
body : [] body : []
}, },


alert_notification : { alert_notification : {
command_id : 0x00000102, command_id : 0x00000102,
empty_body_if_error: false,
body : [ body : [
{ name: "source_addr_ton", type: "int", bytes: 1, default: 1 }, { name: "source_addr_ton", type: "int", bytes: 1, default: 1 },
{ name: "source_addr_npi", type: "int", bytes: 1, default: 0 }, { name: "source_addr_npi", type: "int", bytes: 1, default: 0 },
Expand Down

0 comments on commit 2df20c5

Please sign in to comment.