Class: Smpp::Pdu::DeliverSm

Inherits:
Base
  • Object
show all
Defined in:
lib/smpp/pdu/deliver_sm.rb

Overview

Received for MO message or delivery notification

Constant Summary

Constants inherited from Base

Base::BIND_RECEIVER, Base::BIND_RECEIVER_RESP, Base::BIND_TRANSCEIVER, Base::BIND_TRANSCEIVER_RESP, Base::BIND_TRANSMITTER, Base::BIND_TRANSMITTER_RESP, Base::CANCEL_SM, Base::CANCEL_SM_RESP, Base::DELIVER_SM, Base::DELIVER_SM_RESP, Base::ENQUIRE_LINK, Base::ENQUIRE_LINK_RESP, Base::ESME_RALYBND, Base::ESME_RBINDFAIL, Base::ESME_RCANCELFAIL, Base::ESME_RCNTSUBDL, Base::ESME_RINVBNDSTS, Base::ESME_RINVCMDID, Base::ESME_RINVCMDLEN, Base::ESME_RINVDESTFLAG, Base::ESME_RINVDLNAME, Base::ESME_RINVDSTADR, Base::ESME_RINVDSTNPI, Base::ESME_RINVDSTTON, Base::ESME_RINVESMCLASS, Base::ESME_RINVMSGID, Base::ESME_RINVMSGLEN, Base::ESME_RINVNUMDESTS, Base::ESME_RINVNUMMSGS, Base::ESME_RINVPASWD, Base::ESME_RINVPRTFLG, Base::ESME_RINVREGDLVFLG, Base::ESME_RINVREPFLAG, Base::ESME_RINVSERTYP, Base::ESME_RINVSRCADR, Base::ESME_RINVSRCNPI, Base::ESME_RINVSRCTON, Base::ESME_RINVSUBREP, Base::ESME_RINVSYSID, Base::ESME_RINVSYSTYP, Base::ESME_RMSGQFUL, Base::ESME_ROK, Base::ESME_RREPLACEFAIL, Base::ESME_RSUBMITFAIL, Base::ESME_RSYSERR, Base::ESME_RTHROTTLED, Base::GENERIC_NACK, Base::PROTOCOL_VERSION, Base::QUERY_SM, Base::QUERY_SM_RESP, Base::REPLACE_SM, Base::REPLACE_SM_RESP, Base::SUBMIT_MULTI, Base::SUBMIT_MULTI_RESP, Base::SUBMIT_SM, Base::SUBMIT_SM_RESP, Base::UNBIND, Base::UNBIND_RESP

Instance Attribute Summary collapse

Attributes inherited from Base

#body, #command_id, #command_status, #data, #sequence_number

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

create, #fixed_int, handles_cmd, #logger, #next_sequence_number, next_sequence_number, #to_human

Constructor Details

#initialize(source_addr, destination_addr, short_message, options = {}, seq = nil) ⇒ DeliverSm

Returns a new instance of DeliverSm.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/smpp/pdu/deliver_sm.rb', line 9

def initialize(source_addr, destination_addr, short_message, options={}, seq=nil) 
  
  @udh = options[:udh]      
  @service_type            = options[:service_type]? options[:service_type] :''
  @source_addr_ton         = options[:source_addr_ton]?options[:source_addr_ton]:0 # network specific
  @source_addr_npi         = options[:source_addr_npi]?options[:source_addr_npi]:1 # unknown
  @source_addr             = source_addr
  @dest_addr_ton           = options[:dest_addr_ton]?options[:dest_addr_ton]:1 # international
  @dest_addr_npi           = options[:dest_addr_npi]?options[:dest_addr_npi]:1 # unknown 
  @destination_addr        = destination_addr
  @esm_class               = options[:esm_class]?options[:esm_class]:0 # default smsc mode
  @protocol_id             = options[:protocol_id]?options[:protocol_id]:0
  @priority_flag           = options[:priority_flag]?options[:priority_flag]:1
  @schedule_delivery_time  = options[:schedule_delivery_time]?options[:schedule_delivery_time]:''
  @validity_period         = options[:validity_period]?options[:validity_period]:''
  @registered_delivery     = options[:registered_delivery]?options[:registered_delivery]:1 # we want delivery notifications
  @replace_if_present_flag = options[:replace_if_present_flag]?options[:replace_if_present_flag]:0
  @data_coding             = options[:data_coding]?options[:data_coding]:3 # iso-8859-1
  @sm_default_msg_id       = options[:sm_default_msg_id]?options[:sm_default_msg_id]:0
  @short_message           = short_message
  payload                  = @udh ? @udh + @short_message : @short_message 
  @sm_length               = payload.length

  #fields set for delivery report
  @stat                    = options[:stat]
  @msg_reference           = options[:msg_reference]

  pdu_body = sprintf("%s\0%c%c%s\0%c%c%s\0%c%c%c%s\0%s\0%c%c%c%c%c%s", @service_type, @source_addr_ton, @source_addr_npi, @source_addr,
  @dest_addr_ton, @dest_addr_npi, @destination_addr, @esm_class, @protocol_id, @priority_flag, @schedule_delivery_time, @validity_period,
  @registered_delivery, @replace_if_present_flag, @data_coding, @sm_default_msg_id, @sm_length, payload)

  seq ||= next_sequence_number

  super(DELIVER_SM, 0, seq, pdu_body)
end

Instance Attribute Details

#data_codingObject (readonly)

Returns the value of attribute data_coding.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def data_coding
  @data_coding
end

#dest_addr_npiObject (readonly)

Returns the value of attribute dest_addr_npi.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def dest_addr_npi
  @dest_addr_npi
end

#dest_addr_tonObject (readonly)

Returns the value of attribute dest_addr_ton.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def dest_addr_ton
  @dest_addr_ton
end

#destination_addrObject (readonly)

Returns the value of attribute destination_addr.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def destination_addr
  @destination_addr
end

#esm_classObject (readonly)

Returns the value of attribute esm_class.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def esm_class
  @esm_class
end

#msg_referenceObject (readonly)

Returns the value of attribute msg_reference.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def msg_reference
  @msg_reference
end

#priority_flagObject (readonly)

Returns the value of attribute priority_flag.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def priority_flag
  @priority_flag
end

#protocol_idObject (readonly)

Returns the value of attribute protocol_id.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def protocol_id
  @protocol_id
end

#registered_deliveryObject (readonly)

Returns the value of attribute registered_delivery.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def registered_delivery
  @registered_delivery
end

#replace_if_present_flagObject (readonly)

Returns the value of attribute replace_if_present_flag.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def replace_if_present_flag
  @replace_if_present_flag
end

#schedule_delivery_timeObject (readonly)

Returns the value of attribute schedule_delivery_time.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def schedule_delivery_time
  @schedule_delivery_time
end

#service_typeObject (readonly)

Returns the value of attribute service_type.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def service_type
  @service_type
end

#short_messageObject (readonly)

Returns the value of attribute short_message.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def short_message
  @short_message
end

#sm_default_msg_idObject (readonly)

Returns the value of attribute sm_default_msg_id.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def sm_default_msg_id
  @sm_default_msg_id
end

#sm_lengthObject (readonly)

Returns the value of attribute sm_length.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def sm_length
  @sm_length
end

#source_addrObject (readonly)

Returns the value of attribute source_addr.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def source_addr
  @source_addr
end

#source_addr_npiObject (readonly)

Returns the value of attribute source_addr_npi.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def source_addr_npi
  @source_addr_npi
end

#source_addr_tonObject (readonly)

Returns the value of attribute source_addr_ton.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def source_addr_ton
  @source_addr_ton
end

#statObject (readonly)

Returns the value of attribute stat.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def stat
  @stat
end

#udhObject (readonly)

Returns the value of attribute udh.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def udh
  @udh
end

#validity_periodObject (readonly)

Returns the value of attribute validity_period.



4
5
6
# File 'lib/smpp/pdu/deliver_sm.rb', line 4

def validity_period
  @validity_period
end

Class Method Details

.from_wire_data(seq, status, body) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/smpp/pdu/deliver_sm.rb', line 45

def self.from_wire_data(seq, status, body)
  options = {}
  # brutally unpack it
  options[:service_type], 
  options[:source_addr_ton], 
  options[:source_addr_npi], 
  source_addr, 
  options[:dest_addr_ton], 
  options[:dest_addr_npi], 
  destination_addr, 
  options[:esm_class], 
  options[:protocol_id],
  options[:priority_flag], 
  options[:schedule_delivery_time], 
  options[:validity_period], 
  options[:registered_delivery], 
  options[:replace_if_present_flag], 
  options[:data_coding], 
  options[:sm_default_msg_id],
  options[:sm_length], 
  short_message = body.unpack('Z*CCZ*CCZ*CCCZ*Z*CCCCCa*')
  Smpp::Base.logger.debug "DeliverSM with source_addr=#{source_addr}, destination_addr=#{destination_addr}"

  #Note: if the SM is a delivery receipt (esm_class=4) then the short_message _may_ be in this format:  
  # "id:Smsc2013 sub:1 dlvrd:1 submit date:0610171515 done date:0610171515 stat:0 err:0 text:blah"
  # or this format:
  # "4790000000SMSAlert^id:1054BC63 sub:0 dlvrd:1 submit date:0610231217 done date:0610231217 stat:DELIVRD err: text:"
  # (according to the SMPP spec, the format is vendor specific)
  # For example, Tele2 (Norway):
  # "<msisdn><shortcode>?id:10ea34755d3d4f7a20900cdb3349e549 sub:001 dlvrd:001 submit date:0611011228 done date:0611011230 stat:DELIVRD err:000 Text:abc'!10ea34755d3d4f7a20900cdb3349e549"
  if options[:esm_class] == 4
    options[:msg_reference] = short_message.scanf('id:%s').to_s
    # @stat must be parsed according to the SMSC vendor's specifications (see comment above)
    options[:stat] = 0
  end
  
  new(source_addr, destination_addr, short_message, options, seq) 
end