Permalink
Browse files

More optional paramters work

Renamed Smpp::Pdu::Base.optinal_parameters to parse_optional_parameters
Added optional_parameters accessors to SubmitSmResponse
Added convience method for submit_sm_response.optional_parameter(tag)
  • Loading branch information...
1 parent 9c9c701 commit fb0a6694f753e1e227a5ca236d2414f27fa28a8e @raykrueger committed Apr 16, 2011
View
@@ -168,7 +168,7 @@ def Base.handles_cmd(command_id)
@@cmd_map[command_id] = self
end
- def Base.optional_parameters(remaining_bytes)
+ def Base.parse_optional_parameters(remaining_bytes)
optionals = {}
while not remaining_bytes.empty?
optional = {}
@@ -87,7 +87,7 @@ def self.from_wire_data(seq, status, body)
short_message = remaining_bytes.slice!(0...options[:sm_length])
#everything left in remaining_bytes is 3.4 optional parameters
- options[:optional_parameters] = optional_parameters(remaining_bytes)
+ options[:optional_parameters] = parse_optional_parameters(remaining_bytes)
#parse the 'standard' optional parameters for delivery receipts
options[:optional_parameters].each do |tag, tlv|
@@ -81,7 +81,7 @@ def self.from_wire_data(seq, status, body)
short_message = remaining_bytes.slice!(0...options[:sm_length])
#everything left in remaining_bytes is 3.4 optional parameters
- options[:optional_parameters] = optional_parameters(remaining_bytes)
+ options[:optional_parameters] = parse_optional_parameters(remaining_bytes)
Smpp::Base.logger.debug "SubmitSM with source_addr=#{source_addr}, destination_addr=#{destination_addr}"
@@ -2,20 +2,30 @@ class Smpp::Pdu::SubmitSmResponse < Smpp::Pdu::Base
handles_cmd SUBMIT_SM_RESP
attr_accessor :message_id
+ attr_accessor :optional_parameters
- def initialize(seq, status, message_id)
+ def initialize(seq, status, message_id, optional_parameters=nil)
seq ||= next_sequence_number
body = message_id.to_s + "\000"
super(SUBMIT_SM_RESP, status, seq, body)
@message_id = message_id
+ @optional_parameters = optional_parameters
+ end
+
+ def optional_parameter(tag)
+ if optional_parameters
+ if param = optional_parameters[tag]
+ param.value
+ end
+ end
end
def self.from_wire_data(seq, status, body)
message_id, remaining_bytes = body.unpack("Z*a*")
+ optionals = nil
if remaining_bytes && !remaining_bytes.empty?
- op = optional_parameters(remaining_bytes)
- Smpp::Base.logger.warn "Unparsed SUBMIT_SM_RESP optional parameters: #{op}"
+ optionals = parse_optional_parameters(remaining_bytes)
end
- pdu = new(seq, status, message_id)
+ new(seq, status, message_id, optionals)
end
end
View
@@ -98,6 +98,8 @@ def test_submit_sm_response_with_optional_params
pdu = create_pdu(data)
assert_equal Smpp::Pdu::SubmitSmResponse, pdu.class
assert_equal "", pdu.message_id
+ assert pdu.optional_parameters
+ assert_equal "Source address denied.", pdu.optional_parameter(0x2167)
end
protected

0 comments on commit fb0a669

Please sign in to comment.