From 2df20c5e3b77a59d8a499e8ba9c2755f87fcbf77 Mon Sep 17 00:00:00 2001 From: Ben Youngblood Date: Wed, 5 Dec 2012 15:29:31 -0700 Subject: [PATCH] certain response PDUs omit the PDU body if there is a non-zero command_status --- lib/pdu-parser.js | 7 ++++++- lib/smpp-definitions.js | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/pdu-parser.js b/lib/pdu-parser.js index b550d52..593446e 100644 --- a/lib/pdu-parser.js +++ b/lib/pdu-parser.js @@ -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 diff --git a/lib/smpp-definitions.js b/lib/smpp-definitions.js index 306deb2..f4b02af 100644 --- a/lib/smpp-definitions.js +++ b/lib/smpp-definitions.js @@ -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,6 +179,7 @@ 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 } ] @@ -185,6 +187,7 @@ exports.command_formats = { 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,6 +201,7 @@ 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 } ] @@ -205,6 +209,7 @@ exports.command_formats = { 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,6 +223,7 @@ 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 } ] @@ -225,6 +231,7 @@ exports.command_formats = { 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,6 +283,7 @@ 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: "" }, ] @@ -279,6 +291,7 @@ exports.command_formats = { 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,6 +316,7 @@ 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: "" }, ] @@ -310,6 +324,7 @@ exports.command_formats = { 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,6 +341,7 @@ 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: "" } ] @@ -333,6 +349,7 @@ exports.command_formats = { 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 },