Class: Smpp::Pdu::SubmitMulti

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

Overview

Sending an MT message to multiple addresses Author: Abhishek Parolkar, (abhishekparolkar.com) TODO: Implement from_wire_data for this pdu class.

Constant Summary collapse

IS_SMEADDR =

type of dest_flag

1
IS_DISTLISTNAME =

type of dest_flag

2

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::ESME_RX_T_APPN, Base::GENERIC_NACK, Base::OPTIONAL_MESSAGE_STATE, Base::OPTIONAL_RECEIPTED_MESSAGE_ID, Base::PROTOCOL_VERSION, Base::QUERY_SM, Base::QUERY_SM_RESP, Base::REPLACE_SM, Base::REPLACE_SM_RESP, Base::SEQUENCE_MAX, Base::SUBMIT_MULTI, Base::SUBMIT_MULTI_RESP, Base::SUBMIT_SM, Base::SUBMIT_SM_RESP, Base::UNBIND, Base::UNBIND_RESP

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Base

create, fixed_int, #fixed_int, from_wire_data, handles_cmd, #logger, next_sequence_number, #next_sequence_number, optional_parameters_to_buffer, #optional_parameters_to_buffer, parse_optional_parameters

Constructor Details

#initialize(source_addr, destination_addr_array, short_message, options = {}) ⇒ SubmitMulti

Note: short_message (the SMS body) must be in iso-8859-1 format



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
# File 'lib/smpp/pdu/submit_multi.rb', line 9

def initialize(source_addr, destination_addr_array, short_message, options={})
  options.merge!(
    :esm_class => 0,    # default smsc mode
    :dcs => 3           # iso-8859-1
  ) { |key, old_val, new_val| old_val } 

  @msg_body = short_message
  
  udh = options[:udh]          
  service_type            = ''
  source_addr_ton         = 0 # network specific
  source_addr_npi         = 1 # unknown
  number_of_dests         = destination_addr_array.length # Max value can be 254
  dest_addr_ton           = 1 # international
  dest_addr_npi           = 1 # unknown
  dest_addresses          = build_destination_addresses(destination_addr_array,dest_addr_ton,dest_addr_npi,IS_SMEADDR) 
  esm_class               = options[:esm_class]
  protocol_id             = 0
  priority_flag           = 0
  schedule_delivery_time  = ''
  validity_period         = ''
  registered_delivery     = 1 # we want delivery notifications
  replace_if_present_flag = 0
  data_coding             = options[:dcs]
  sm_default_msg_id       = 0
  payload                 = udh ? udh + short_message : short_message # this used to be (short_message + "\0")
  sm_length               = payload.length
  
  # craft the string/byte buffer
  pdu_body = sprintf("%s\0%c%c%s\0%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, number_of_dests,dest_addresses, 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)
  super(SUBMIT_MULTI, 0, next_sequence_number, pdu_body)        
end

Instance Method Details

#build_destination_addresses(dest_array, dest_addr_ton, dest_addr_npi, dest_flag = IS_SMEADDR) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/smpp/pdu/submit_multi.rb', line 50

def build_destination_addresses(dest_array,dest_addr_ton,dest_addr_npi, dest_flag = IS_SMEADDR)
  formatted_array = Array.new
  dest_array.each { |dest_elem|
    if dest_flag == IS_SMEADDR
      packet_str = sprintf("%c%c%c%s",IS_SMEADDR,dest_addr_ton,dest_addr_npi,dest_elem)
      formatted_array.push(packet_str)

    elsif dest_flag == IS_DISTLISTNAME
      packet_str = sprintf("%c%s",IS_SMEADDR,dest_elem)
                        formatted_array.push(packet_str)

    end

  }

  formatted_array.join("\0");
end

#to_humanObject

some special formatting is needed for SubmitSm PDUs to show the actual message content



44
45
46
47
48
# File 'lib/smpp/pdu/submit_multi.rb', line 44

def to_human
  # convert header (4 bytes) to array of 4-byte ints
  a = @data.to_s.unpack('N4')       
  sprintf("(%22s) len=%3d cmd=%8s status=%1d seq=%03d (%s)", self.class.to_s[11..-1], a[0], a[1].to_s(16), a[2], a[3], @msg_body[0..30])
end