Skip to content

Commit

Permalink
Whitespace cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
malmckay committed Oct 21, 2013
1 parent 4386cd9 commit 201485d
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 181 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ rvm:
- 1.8.7
- 1.9.3
- 2.0.0

10 changes: 5 additions & 5 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
- Adds a send_concat_mt method to Transceivers (not implemented for Transmitter/Receiver), which does the neccesary encoding and message splitting to send messages > 160 characters by splitting them into multiple parts.

= 2008.10.20

== Patch from Josh Bryan:

Fixes smpp/base.rb so that it can handle partial pdu's and multiple pdu's available on the stream. Previously, base.rb assumed that all data available on the TCP stream constituted the next pdu. Though this often works in low load environments, moderately high traffic environments often see multiple pdu's back to back on the stream before event machine cycles through another turn of the reactor. Also, pdu's can be split over multiple TCP packets. Thus, incomplete or multiple pdu's may be delivered to Base#receive_data, and Base needs to be able buffer and split the pdu's.

= 2008.10.13

== Patch from Taryn East:

I added the receiver and transmitter equivalents of the transmitter class, and also hacked in some code that would support basic setup of an smpp server. Note: we were only using this to set up a test-harness for our own ruby-smpp code, so it's pretty basic and doesn't support all messages - or even do anything useful with an incoming deliver_sm. But it's better than nothing at all ;)

NOTE: Taryn's patch currently lives in a separate branch (taryn-patch), awaiting merge.
Expand All @@ -44,9 +44,9 @@ I have implemented 4.5.1 section of SMPPv3.4: support for sending an MT message
- Made submit_sm more configurable with options
- Added PDU examples for submit_sm
- Added example to use submit_multi and submit_sm

= 2008.04.07

== Initial release (August Z. Flatby)

My first open source project after all these years! Ah.. it feels good.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.0
0.6.0
30 changes: 15 additions & 15 deletions examples/sample_smsc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# encoding: UTF-8


# Sample SMPP SMS Gateway.
# Sample SMPP SMS Gateway.

require 'rubygems'
require File.dirname(__FILE__) + '/../lib/smpp'
Expand All @@ -22,7 +22,7 @@ module KeyboardHandler
def receive_line(data)
puts "Sending MO: #{data}"
from = '1111111111'
to = '1111111112'
to = '1111111112'
$tx.send_mo(from, to, data)


Expand All @@ -32,21 +32,21 @@ def receive_line(data)
# :service_type => 1,
# :source_addr_ton => 5,
# :source_addr_npi => 0 ,
# :dest_addr_ton => 2,
# :dest_addr_npi => 1,
# :dest_addr_ton => 2,
# :dest_addr_npi => 1,
# :esm_class => 3 ,
# :protocol_id => 0,
# :protocol_id => 0,
# :priority_flag => 0,
# :schedule_delivery_time => nil,
# :validity_period => nil,
# :registered_delivery=> 1,
# :replace_if_present_flag => 0,
# :data_coding => 0,
# :sm_default_msg_id => 0
# })
# :sm_default_msg_id => 0
# })

# if you want to send message to multiple destinations , uncomment below code
# $tx.send_multi_mt(123, from, ["919900000001","919900000002","919900000003"], "I am echoing that ruby-smpp is great")
# $tx.send_multi_mt(123, from, ["919900000001","919900000002","919900000003"], "I am echoing that ruby-smpp is great")
prompt
end
end
Expand All @@ -64,22 +64,22 @@ def start(config)

# Run EventMachine in loop so we can reconnect when the SMSC drops our connection.
loop do
EventMachine::run do
EventMachine::run do
$tx = EventMachine::start_server(
config[:host],
config[:port],
config[:host],
config[:port],
Smpp::Server,
config
)
)
end
logger.warn "Event loop stopped. Restarting in 5 seconds.."
sleep 5
end
end

# Start the Gateway
begin
puts "Starting SMS Gateway"
begin
puts "Starting SMS Gateway"

# SMPP properties. These parameters the ones provided sample_gateway.rb and
# will work with it.
Expand All @@ -98,7 +98,7 @@ def start(config)
:destination_address_range => '',
:enquire_link_delay_secs => 10
}
start(config)
start(config)
rescue Exception => ex
puts "Exception in SMS Gateway: #{ex} at #{ex.backtrace[0]}"
end
2 changes: 1 addition & 1 deletion lib/smpp/optional_parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Smpp::OptionalParameter

attr_reader :tag, :value

def initialize(tag, value)
@tag = tag
@value = value
Expand Down
112 changes: 56 additions & 56 deletions lib/smpp/pdu/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,63 @@ class Base
PROTOCOL_VERSION = 0x34
# Error constants
ESME_ROK = 0x00000000 # OK!
ESME_RINVMSGLEN = 0x00000001 # Message Length is invalid
ESME_RINVCMDLEN = 0x00000002 # Command Length is invalid
ESME_RINVCMDID = 0x00000003 # Invalid Command ID
ESME_RINVBNDSTS = 0x00000004 # Incorrect BIND Status for given com-
ESME_RALYBND = 0x00000005 # ESME Already in Bound State
ESME_RINVPRTFLG = 0x00000006 # Invalid Priority Flag
ESME_RINVREGDLVFLG = 0x00000007 # Invalid Registered Delivery Flag
ESME_RSYSERR = 0x00000008 # System Error
ESME_RINVSRCADR = 0x0000000A # Invalid Source Address
ESME_RINVDSTADR = 0x0000000B # Invalid Dest Addr
ESME_RINVMSGID = 0x0000000C # Message ID is invalid
ESME_RBINDFAIL = 0x0000000D # Bind Failed
ESME_RINVPASWD = 0x0000000E # Invalid Password
ESME_RINVSYSID = 0x0000000F # Invalid System ID
ESME_RCANCELFAIL = 0x00000011 # Cancel SM Failed
ESME_RREPLACEFAIL = 0x00000013 # Replace SM Failed
ESME_RMSGQFUL = 0x00000014 # Message Queue Full
ESME_RINVSERTYP = 0x00000015 # Invalid Service Type
ESME_RINVNUMDESTS = 0x00000033 # Invalid number of destinations
ESME_RINVDLNAME = 0x00000034 # Invalid Distribution List name
ESME_RINVDESTFLAG = 0x00000040 # Destination flag is invalid
ESME_RINVSUBREP = 0x00000042 # Invalid ‘submit with replace’ request
ESME_RINVESMCLASS = 0x00000043 # Invalid esm_class field data
ESME_RCNTSUBDL = 0x00000044 # Cannot Submit to Distribution List
ESME_RSUBMITFAIL = 0x00000045 # submit_sm or submit_multi failed
ESME_RINVSRCTON = 0x00000048 # Invalid Source address TON
ESME_RINVSRCNPI = 0x00000049 # Invalid Source address NPI
ESME_RINVDSTTON = 0x00000050 # Invalid Destination address TON
ESME_RINVDSTNPI = 0x00000051 # Invalid Destination address NPI
ESME_RINVSYSTYP = 0x00000053 # Invalid system_type field
ESME_RINVREPFLAG = 0x00000054 # Invalid replace_if_present flag
ESME_RINVNUMMSGS = 0x00000055 # Invalid number of messages
ESME_RTHROTTLED = 0x00000058 # Throttling error (ESME has exceeded allowed message limits)
ESME_RINVMSGLEN = 0x00000001 # Message Length is invalid
ESME_RINVCMDLEN = 0x00000002 # Command Length is invalid
ESME_RINVCMDID = 0x00000003 # Invalid Command ID
ESME_RINVBNDSTS = 0x00000004 # Incorrect BIND Status for given com-
ESME_RALYBND = 0x00000005 # ESME Already in Bound State
ESME_RINVPRTFLG = 0x00000006 # Invalid Priority Flag
ESME_RINVREGDLVFLG = 0x00000007 # Invalid Registered Delivery Flag
ESME_RSYSERR = 0x00000008 # System Error
ESME_RINVSRCADR = 0x0000000A # Invalid Source Address
ESME_RINVDSTADR = 0x0000000B # Invalid Dest Addr
ESME_RINVMSGID = 0x0000000C # Message ID is invalid
ESME_RBINDFAIL = 0x0000000D # Bind Failed
ESME_RINVPASWD = 0x0000000E # Invalid Password
ESME_RINVSYSID = 0x0000000F # Invalid System ID
ESME_RCANCELFAIL = 0x00000011 # Cancel SM Failed
ESME_RREPLACEFAIL = 0x00000013 # Replace SM Failed
ESME_RMSGQFUL = 0x00000014 # Message Queue Full
ESME_RINVSERTYP = 0x00000015 # Invalid Service Type
ESME_RINVNUMDESTS = 0x00000033 # Invalid number of destinations
ESME_RINVDLNAME = 0x00000034 # Invalid Distribution List name
ESME_RINVDESTFLAG = 0x00000040 # Destination flag is invalid
ESME_RINVSUBREP = 0x00000042 # Invalid ‘submit with replace’ request
ESME_RINVESMCLASS = 0x00000043 # Invalid esm_class field data
ESME_RCNTSUBDL = 0x00000044 # Cannot Submit to Distribution List
ESME_RSUBMITFAIL = 0x00000045 # submit_sm or submit_multi failed
ESME_RINVSRCTON = 0x00000048 # Invalid Source address TON
ESME_RINVSRCNPI = 0x00000049 # Invalid Source address NPI
ESME_RINVDSTTON = 0x00000050 # Invalid Destination address TON
ESME_RINVDSTNPI = 0x00000051 # Invalid Destination address NPI
ESME_RINVSYSTYP = 0x00000053 # Invalid system_type field
ESME_RINVREPFLAG = 0x00000054 # Invalid replace_if_present flag
ESME_RINVNUMMSGS = 0x00000055 # Invalid number of messages
ESME_RTHROTTLED = 0x00000058 # Throttling error (ESME has exceeded allowed message limits)

ESME_RX_T_APPN = 0x00000064 # ESME Receiver Temporary App Error Code

# PDU types
GENERIC_NACK = 0X80000000
BIND_RECEIVER = 0X00000001
BIND_RECEIVER_RESP = 0X80000001
BIND_TRANSMITTER = 0X00000002
BIND_TRANSMITTER_RESP = 0X80000002
GENERIC_NACK = 0X80000000
BIND_RECEIVER = 0X00000001
BIND_RECEIVER_RESP = 0X80000001
BIND_TRANSMITTER = 0X00000002
BIND_TRANSMITTER_RESP = 0X80000002
BIND_TRANSCEIVER = 0X00000009
BIND_TRANSCEIVER_RESP = 0X80000009
QUERY_SM = 0X00000003
QUERY_SM_RESP = 0X80000003
SUBMIT_SM = 0X00000004
SUBMIT_SM_RESP = 0X80000004
DELIVER_SM = 0X00000005
DELIVER_SM_RESP = 0X80000005
UNBIND = 0X00000006
UNBIND_RESP = 0X80000006
REPLACE_SM = 0X00000007
REPLACE_SM_RESP = 0X80000007
CANCEL_SM = 0X00000008
CANCEL_SM_RESP = 0X80000008
ENQUIRE_LINK = 0X00000015
QUERY_SM = 0X00000003
QUERY_SM_RESP = 0X80000003
SUBMIT_SM = 0X00000004
SUBMIT_SM_RESP = 0X80000004
DELIVER_SM = 0X00000005
DELIVER_SM_RESP = 0X80000005
UNBIND = 0X00000006
UNBIND_RESP = 0X80000006
REPLACE_SM = 0X00000007
REPLACE_SM_RESP = 0X80000007
CANCEL_SM = 0X00000008
CANCEL_SM_RESP = 0X80000008
ENQUIRE_LINK = 0X00000015
ENQUIRE_LINK_RESP = 0X80000015
SUBMIT_MULTI = 0X00000021
SUBMIT_MULTI_RESP = 0X80000021
Expand All @@ -72,7 +72,7 @@ class Base

SEQUENCE_MAX = 0x7FFFFFFF

# PDU sequence number.
# PDU sequence number.
@@seq = [Time.now.to_i]

# Add monitor to sequence counter for thread safety
Expand All @@ -83,14 +83,14 @@ class Base

attr_reader :command_id, :command_status, :sequence_number, :body, :data

def initialize(command_id, command_status, seq, body='')
def initialize(command_id, command_status, seq, body='')
length = 16 + body.length
@command_id = command_id
@command_status = command_status
@body = body
@sequence_number = seq
@data = fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq) + body
end
@data = fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq) + body
end

def logger
Smpp::Base.logger
Expand Down Expand Up @@ -176,7 +176,7 @@ def Base.parse_optional_parameters(remaining_bytes)
optional_parameter, remaining_bytes = Smpp::OptionalParameter.from_wire_data(remaining_bytes)
optionals[optional_parameter.tag] = optional_parameter
end

return optionals
end

Expand Down
4 changes: 2 additions & 2 deletions lib/smpp/pdu/bind_base.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# encoding: UTF-8
# this class serves as the base for all the bind* commands.
# since the command format remains the same for all bind commands,
# since the command format remains the same for all bind commands,
# sub classes just change the @@command_id
class Smpp::Pdu::BindBase < Smpp::Pdu::Base
class << self; attr_accessor :command_id ; end

attr_reader :system_id, :password, :system_type, :addr_ton, :addr_npi, :address_range
attr_reader :system_id, :password, :system_type, :addr_ton, :addr_npi, :address_range

def initialize(system_id, password, system_type, addr_ton, addr_npi, address_range, seq = nil)
@system_id, @password, @system_type, @addr_ton, @addr_npi, @address_range =
Expand Down
4 changes: 2 additions & 2 deletions lib/smpp/pdu/generic_nack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def initialize(seq, error_code, original_sequence_code = nil)
end

def self.from_wire_data(seq, status, body)
new(seq,status,body)
new(seq,status,body)
end
end
end
22 changes: 11 additions & 11 deletions lib/smpp/pdu/submit_multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
#TODO: Implement from_wire_data for this pdu class.
class Smpp::Pdu::SubmitMulti < Smpp::Pdu::Base
IS_SMEADDR = 1 # type of dest_flag
IS_DISTLISTNAME = 2 #type of dest_flag
IS_DISTLISTNAME = 2 #type of dest_flag

# Note: short_message (the SMS body) must be in iso-8859-1 format
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 }
) { |key, old_val, new_val| old_val }

@msg_body = short_message
udh = options[:udh]

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)
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
Expand All @@ -35,17 +35,17 @@ def initialize(source_addr, destination_addr_array, short_message, options={})
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)
super(SUBMIT_MULTI, 0, next_sequence_number, pdu_body)
end

# some special formatting is needed for SubmitSm PDUs to show the actual message content
def to_human
# convert header (4 bytes) to array of 4-byte ints
a = @data.to_s.unpack('N4')
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

Expand All @@ -66,5 +66,5 @@ def build_destination_addresses(dest_array,dest_addr_ton,dest_addr_npi, dest_fla

formatted_array.join("\0");
end

end
Loading

0 comments on commit 201485d

Please sign in to comment.