From 03e473a36dc489f1c3a58f6f89aa2b9c0ae6b1b6 Mon Sep 17 00:00:00 2001 From: Laszlo Papp Date: Fri, 8 Nov 2013 16:20:47 +0000 Subject: [PATCH 1/4] Sms can be longer than 127 characters --- lib/smpp/pdu/base.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/smpp/pdu/base.rb b/lib/smpp/pdu/base.rb index 73f3281..13c9127 100644 --- a/lib/smpp/pdu/base.rb +++ b/lib/smpp/pdu/base.rb @@ -88,7 +88,11 @@ def initialize(command_id, command_status, seq, body='') @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 + if RUBY_VERSION < 1.9 + @data = fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq) + body + else + @data = (fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq)).force_encoding("BINARY") + body.force_encoding("BINARY") + end end def logger From ca5cc6e62080407e05ca79d3934e97c527fcaa06 Mon Sep 17 00:00:00 2001 From: Laszlo Papp Date: Fri, 8 Nov 2013 17:29:09 +0000 Subject: [PATCH 2/4] Compare string with string. --- lib/smpp/pdu/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/smpp/pdu/base.rb b/lib/smpp/pdu/base.rb index 13c9127..0be1dc6 100644 --- a/lib/smpp/pdu/base.rb +++ b/lib/smpp/pdu/base.rb @@ -88,7 +88,7 @@ def initialize(command_id, command_status, seq, body='') @command_status = command_status @body = body @sequence_number = seq - if RUBY_VERSION < 1.9 + if RUBY_VERSION < "1.9" @data = fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq) + body else @data = (fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq)).force_encoding("BINARY") + body.force_encoding("BINARY") From 23fb4875e6f2d5789d95cbfd50293b067f3c7b9c Mon Sep 17 00:00:00 2001 From: Laszlo Papp Date: Tue, 12 Nov 2013 11:07:28 +0000 Subject: [PATCH 3/4] Using UTF-8 encoding to be able to send messages longer than 255 chars. --- lib/smpp/pdu/base.rb | 2 +- lib/smpp/pdu/submit_sm.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/smpp/pdu/base.rb b/lib/smpp/pdu/base.rb index 0be1dc6..e66e76e 100644 --- a/lib/smpp/pdu/base.rb +++ b/lib/smpp/pdu/base.rb @@ -91,7 +91,7 @@ def initialize(command_id, command_status, seq, body='') if RUBY_VERSION < "1.9" @data = fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq) + body else - @data = (fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq)).force_encoding("BINARY") + body.force_encoding("BINARY") + @data = (fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq)).force_encoding("UTF-8") + body.force_encoding("UTF-8") end end diff --git a/lib/smpp/pdu/submit_sm.rb b/lib/smpp/pdu/submit_sm.rb index edf7fdc..8d7f2b4 100644 --- a/lib/smpp/pdu/submit_sm.rb +++ b/lib/smpp/pdu/submit_sm.rb @@ -1,3 +1,5 @@ +# -*- encoding : utf-8 -*- + # Sending an MT message class Smpp::Pdu::SubmitSm < Smpp::Pdu::Base handles_cmd SUBMIT_SM From 4400f15b8430ee31526b42e5862b9051f31f0977 Mon Sep 17 00:00:00 2001 From: Laszlo Papp Date: Wed, 5 Feb 2014 10:27:37 +0000 Subject: [PATCH 4/4] Added UTF-8 sentinels --- config/environment.rb | 1 + examples/sample_gateway.rb | 1 + examples/sample_smsc.rb | 1 + lib/smpp.rb | 1 + lib/smpp/base.rb | 1 + lib/smpp/encoding/utf8_encoder.rb | 1 + lib/smpp/optional_parameter.rb | 1 + lib/smpp/pdu/base.rb | 1 + lib/smpp/pdu/bind_base.rb | 1 + lib/smpp/pdu/bind_receiver.rb | 1 + lib/smpp/pdu/bind_receiver_response.rb | 1 + lib/smpp/pdu/bind_resp_base.rb | 1 + lib/smpp/pdu/bind_transceiver.rb | 1 + lib/smpp/pdu/bind_transceiver_response.rb | 1 + lib/smpp/pdu/bind_transmitter.rb | 1 + lib/smpp/pdu/bind_transmitter_response.rb | 1 + lib/smpp/pdu/deliver_sm.rb | 1 + lib/smpp/pdu/deliver_sm_response.rb | 1 + lib/smpp/pdu/enquire_link.rb | 1 + lib/smpp/pdu/enquire_link_response.rb | 1 + lib/smpp/pdu/generic_nack.rb | 1 + lib/smpp/pdu/submit_multi.rb | 1 + lib/smpp/pdu/submit_multi_response.rb | 1 + lib/smpp/pdu/submit_sm_response.rb | 1 + lib/smpp/pdu/unbind.rb | 1 + lib/smpp/pdu/unbind_response.rb | 1 + lib/smpp/receiver.rb | 1 + lib/smpp/server.rb | 1 + lib/smpp/transceiver.rb | 1 + lib/smpp/transmitter.rb | 1 + lib/smpp/version.rb | 1 + lib/sms.rb | 3 ++- test/delegate.rb | 1 + test/encoding_test.rb | 1 + test/optional_parameter_test.rb | 1 + test/pdu_parsing_test.rb | 1 + test/receiver_test.rb | 1 + test/responsive_delegate.rb | 1 + test/server.rb | 1 + test/smpp_test.rb | 1 + test/submit_sm_test.rb | 1 + test/transceiver_test.rb | 1 + 42 files changed, 43 insertions(+), 1 deletion(-) diff --git a/config/environment.rb b/config/environment.rb index 3b7b109..6c018f3 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,2 +1,3 @@ +# -*- encoding : utf-8 -*- require "rubygems" require "bundler/setup" diff --git a/examples/sample_gateway.rb b/examples/sample_gateway.rb index 86b3a31..9e48fde 100755 --- a/examples/sample_gateway.rb +++ b/examples/sample_gateway.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- #!/usr/bin/env ruby # Sample SMS gateway that can receive MOs (mobile originated messages) and diff --git a/examples/sample_smsc.rb b/examples/sample_smsc.rb index 5f38568..2342cd3 100755 --- a/examples/sample_smsc.rb +++ b/examples/sample_smsc.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- #!/usr/bin/env ruby # Sample SMPP SMS Gateway. diff --git a/lib/smpp.rb b/lib/smpp.rb index 2ec90bc..4e8f8d2 100644 --- a/lib/smpp.rb +++ b/lib/smpp.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # SMPP v3.4 subset implementation. # SMPP is a short message peer-to-peer protocol typically used to communicate # with SMS Centers (SMSCs) over TCP/IP. diff --git a/lib/smpp/base.rb b/lib/smpp/base.rb index 0d2c904..213fcc7 100644 --- a/lib/smpp/base.rb +++ b/lib/smpp/base.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'timeout' require 'scanf' require 'monitor' diff --git a/lib/smpp/encoding/utf8_encoder.rb b/lib/smpp/encoding/utf8_encoder.rb index 241cb1c..0b01963 100644 --- a/lib/smpp/encoding/utf8_encoder.rb +++ b/lib/smpp/encoding/utf8_encoder.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'iconv' module Smpp diff --git a/lib/smpp/optional_parameter.rb b/lib/smpp/optional_parameter.rb index 1b85417..6f68b30 100644 --- a/lib/smpp/optional_parameter.rb +++ b/lib/smpp/optional_parameter.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::OptionalParameter attr_reader :tag, :value diff --git a/lib/smpp/pdu/base.rb b/lib/smpp/pdu/base.rb index e66e76e..6b88362 100644 --- a/lib/smpp/pdu/base.rb +++ b/lib/smpp/pdu/base.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # PDUs are the protcol base units in SMPP module Smpp::Pdu class Base diff --git a/lib/smpp/pdu/bind_base.rb b/lib/smpp/pdu/bind_base.rb index aac4cfa..fb8a50a 100644 --- a/lib/smpp/pdu/bind_base.rb +++ b/lib/smpp/pdu/bind_base.rb @@ -1,3 +1,4 @@ +# -*- 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, # sub classes just change the @@command_id diff --git a/lib/smpp/pdu/bind_receiver.rb b/lib/smpp/pdu/bind_receiver.rb index a551004..834d26e 100644 --- a/lib/smpp/pdu/bind_receiver.rb +++ b/lib/smpp/pdu/bind_receiver.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::BindReceiver < Smpp::Pdu::BindBase @command_id = BIND_RECEIVER handles_cmd BIND_RECEIVER diff --git a/lib/smpp/pdu/bind_receiver_response.rb b/lib/smpp/pdu/bind_receiver_response.rb index a5ca7dd..c19f87b 100644 --- a/lib/smpp/pdu/bind_receiver_response.rb +++ b/lib/smpp/pdu/bind_receiver_response.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::BindReceiverResponse < Smpp::Pdu::BindRespBase @command_id = BIND_RECEIVER_RESP handles_cmd BIND_RECEIVER_RESP diff --git a/lib/smpp/pdu/bind_resp_base.rb b/lib/smpp/pdu/bind_resp_base.rb index 4395d77..0ca5b17 100644 --- a/lib/smpp/pdu/bind_resp_base.rb +++ b/lib/smpp/pdu/bind_resp_base.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::BindRespBase < Smpp::Pdu::Base class << self; attr_accessor :command_id ; end attr_accessor :system_id diff --git a/lib/smpp/pdu/bind_transceiver.rb b/lib/smpp/pdu/bind_transceiver.rb index cf60a85..26d0923 100644 --- a/lib/smpp/pdu/bind_transceiver.rb +++ b/lib/smpp/pdu/bind_transceiver.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::BindTransceiver < Smpp::Pdu::BindBase @command_id = BIND_TRANSCEIVER handles_cmd BIND_TRANSCEIVER diff --git a/lib/smpp/pdu/bind_transceiver_response.rb b/lib/smpp/pdu/bind_transceiver_response.rb index 711613e..17ba166 100644 --- a/lib/smpp/pdu/bind_transceiver_response.rb +++ b/lib/smpp/pdu/bind_transceiver_response.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::BindTransceiverResponse < Smpp::Pdu::BindRespBase @command_id = BIND_TRANSCEIVER_RESP handles_cmd BIND_TRANSCEIVER_RESP diff --git a/lib/smpp/pdu/bind_transmitter.rb b/lib/smpp/pdu/bind_transmitter.rb index 411d6a9..5128500 100644 --- a/lib/smpp/pdu/bind_transmitter.rb +++ b/lib/smpp/pdu/bind_transmitter.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::BindTransmitter < Smpp::Pdu::BindBase @command_id = BIND_TRANSMITTER handles_cmd BIND_TRANSMITTER diff --git a/lib/smpp/pdu/bind_transmitter_response.rb b/lib/smpp/pdu/bind_transmitter_response.rb index 185dab4..0c0a485 100644 --- a/lib/smpp/pdu/bind_transmitter_response.rb +++ b/lib/smpp/pdu/bind_transmitter_response.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::BindTransmitterResponse < Smpp::Pdu::BindRespBase @command_id = BIND_TRANSMITTER_RESP handles_cmd BIND_TRANSMITTER_RESP diff --git a/lib/smpp/pdu/deliver_sm.rb b/lib/smpp/pdu/deliver_sm.rb index 356a31f..cf65393 100644 --- a/lib/smpp/pdu/deliver_sm.rb +++ b/lib/smpp/pdu/deliver_sm.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Received for MO message or delivery notification class Smpp::Pdu::DeliverSm < Smpp::Pdu::Base diff --git a/lib/smpp/pdu/deliver_sm_response.rb b/lib/smpp/pdu/deliver_sm_response.rb index caa4077..17ecaf7 100644 --- a/lib/smpp/pdu/deliver_sm_response.rb +++ b/lib/smpp/pdu/deliver_sm_response.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::DeliverSmResponse < Smpp::Pdu::Base handles_cmd DELIVER_SM_RESP diff --git a/lib/smpp/pdu/enquire_link.rb b/lib/smpp/pdu/enquire_link.rb index 78b874c..f86a4fb 100644 --- a/lib/smpp/pdu/enquire_link.rb +++ b/lib/smpp/pdu/enquire_link.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::EnquireLink < Smpp::Pdu::Base handles_cmd ENQUIRE_LINK diff --git a/lib/smpp/pdu/enquire_link_response.rb b/lib/smpp/pdu/enquire_link_response.rb index 96e8a46..4e561de 100644 --- a/lib/smpp/pdu/enquire_link_response.rb +++ b/lib/smpp/pdu/enquire_link_response.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::EnquireLinkResponse < Smpp::Pdu::Base handles_cmd ENQUIRE_LINK_RESP diff --git a/lib/smpp/pdu/generic_nack.rb b/lib/smpp/pdu/generic_nack.rb index dd0e278..76fc26e 100644 --- a/lib/smpp/pdu/generic_nack.rb +++ b/lib/smpp/pdu/generic_nack.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # signals invalid message header class Smpp::Pdu::GenericNack < Smpp::Pdu::Base handles_cmd GENERIC_NACK diff --git a/lib/smpp/pdu/submit_multi.rb b/lib/smpp/pdu/submit_multi.rb index 960a378..933529a 100644 --- a/lib/smpp/pdu/submit_multi.rb +++ b/lib/smpp/pdu/submit_multi.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Sending an MT message to multiple addresses # Author: Abhishek Parolkar, (abhishek[at]parolkar.com) #TODO: Implement from_wire_data for this pdu class. diff --git a/lib/smpp/pdu/submit_multi_response.rb b/lib/smpp/pdu/submit_multi_response.rb index d543946..3316a91 100644 --- a/lib/smpp/pdu/submit_multi_response.rb +++ b/lib/smpp/pdu/submit_multi_response.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Recieving response for an MT message sent to multiple addresses # Author: Abhishek Parolkar, (abhishek[at]parolkar.com) class Smpp::Pdu::SubmitMultiResponse < Smpp::Pdu::Base diff --git a/lib/smpp/pdu/submit_sm_response.rb b/lib/smpp/pdu/submit_sm_response.rb index 966d25c..701a052 100644 --- a/lib/smpp/pdu/submit_sm_response.rb +++ b/lib/smpp/pdu/submit_sm_response.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::SubmitSmResponse < Smpp::Pdu::Base handles_cmd SUBMIT_SM_RESP diff --git a/lib/smpp/pdu/unbind.rb b/lib/smpp/pdu/unbind.rb index 2d548c6..685d838 100644 --- a/lib/smpp/pdu/unbind.rb +++ b/lib/smpp/pdu/unbind.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::Unbind < Smpp::Pdu::Base handles_cmd UNBIND diff --git a/lib/smpp/pdu/unbind_response.rb b/lib/smpp/pdu/unbind_response.rb index b0d4053..9be0732 100644 --- a/lib/smpp/pdu/unbind_response.rb +++ b/lib/smpp/pdu/unbind_response.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class Smpp::Pdu::UnbindResponse < Smpp::Pdu::Base handles_cmd UNBIND_RESP diff --git a/lib/smpp/receiver.rb b/lib/smpp/receiver.rb index 87d9e7c..26506eb 100644 --- a/lib/smpp/receiver.rb +++ b/lib/smpp/receiver.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # The SMPP Receiver maintains a unidirectional connection to an SMSC. # Provide a config hash with connection options to get started. # See the sample_gateway.rb for examples of config values. diff --git a/lib/smpp/server.rb b/lib/smpp/server.rb index 6ee8579..1350c55 100644 --- a/lib/smpp/server.rb +++ b/lib/smpp/server.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # -------- # This is experimental stuff submitted by taryn@taryneast.org # -------- diff --git a/lib/smpp/transceiver.rb b/lib/smpp/transceiver.rb index 70516c6..ed771d1 100644 --- a/lib/smpp/transceiver.rb +++ b/lib/smpp/transceiver.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # The SMPP Transceiver maintains a bidirectional connection to an SMSC. # Provide a config hash with connection options to get started. # See the sample_gateway.rb for examples of config values. diff --git a/lib/smpp/transmitter.rb b/lib/smpp/transmitter.rb index 72e5104..0410655 100644 --- a/lib/smpp/transmitter.rb +++ b/lib/smpp/transmitter.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # The SMPP Transmitter maintains a unidirectional connection to an SMSC. # Provide a config hash with connection options to get started. # See the sample_gateway.rb for examples of config values. diff --git a/lib/smpp/version.rb b/lib/smpp/version.rb index d84a70f..d9810b3 100644 --- a/lib/smpp/version.rb +++ b/lib/smpp/version.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module Smpp VERSION = "0.6.0" end diff --git a/lib/sms.rb b/lib/sms.rb index ae3d48d..df853f4 100644 --- a/lib/sms.rb +++ b/lib/sms.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Basic SMS class for sample gateway class Sms @@ -6,4 +7,4 @@ class Sms def initialize(body) self.body = body end -end \ No newline at end of file +end diff --git a/test/delegate.rb b/test/delegate.rb index 060d9c9..42ccf41 100644 --- a/test/delegate.rb +++ b/test/delegate.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # the delagate receives callbacks when interesting things happen on the connection class Delegate diff --git a/test/encoding_test.rb b/test/encoding_test.rb index 8f52247..9387aa6 100644 --- a/test/encoding_test.rb +++ b/test/encoding_test.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'rubygems' require 'test/unit' require 'smpp/encoding/utf8_encoder' diff --git a/test/optional_parameter_test.rb b/test/optional_parameter_test.rb index 59b5932..f5bdd16 100644 --- a/test/optional_parameter_test.rb +++ b/test/optional_parameter_test.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'rubygems' require 'test/unit' require 'smpp' diff --git a/test/pdu_parsing_test.rb b/test/pdu_parsing_test.rb index 82608ed..a7f8993 100644 --- a/test/pdu_parsing_test.rb +++ b/test/pdu_parsing_test.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'rubygems' require 'test/unit' require File.expand_path(File.dirname(__FILE__) + "../../lib/smpp") diff --git a/test/receiver_test.rb b/test/receiver_test.rb index 4625c38..0b75300 100644 --- a/test/receiver_test.rb +++ b/test/receiver_test.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'rubygems' require 'test/unit' require 'smpp' diff --git a/test/responsive_delegate.rb b/test/responsive_delegate.rb index 7a20225..b438ac3 100644 --- a/test/responsive_delegate.rb +++ b/test/responsive_delegate.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- #TODO This should be made prettier with mocha class ResponsiveDelegate attr_reader :seq, :event_counter diff --git a/test/server.rb b/test/server.rb index e281f87..bfa4e98 100644 --- a/test/server.rb +++ b/test/server.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # a server which immediately requests the client to unbind module Server def self.config diff --git a/test/smpp_test.rb b/test/smpp_test.rb index 0d71ecf..368e8cd 100644 --- a/test/smpp_test.rb +++ b/test/smpp_test.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'rubygems' require 'test/unit' require 'smpp' diff --git a/test/submit_sm_test.rb b/test/submit_sm_test.rb index 7611457..f0e32f6 100644 --- a/test/submit_sm_test.rb +++ b/test/submit_sm_test.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'rubygems' require 'test/unit' require 'smpp' diff --git a/test/transceiver_test.rb b/test/transceiver_test.rb index 3f825cb..104bdbf 100644 --- a/test/transceiver_test.rb +++ b/test/transceiver_test.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require "rubygems" require "test/unit" require File.expand_path(File.dirname(__FILE__) + "../../lib/smpp")