From 3e680545dada1e0dd9cd4f39ac053bcb5bfe22d8 Mon Sep 17 00:00:00 2001 From: kuroineko Date: Thu, 21 Jun 2012 00:13:50 +0000 Subject: [PATCH 1/6] encoding conversion fix while reading some PDU`s --- 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 530a4c6..c772d2d 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 - @data = fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq) + body + @data = fixed_int(length) + fixed_int(command_id) + fixed_int(command_status) + fixed_int(seq) + body.force_encoding("ascii-8bit") end def logger From ffbae547fe9d118f34f6710cf4951a9130397b4a Mon Sep 17 00:00:00 2001 From: kuroineko Date: Thu, 21 Jun 2012 00:17:59 +0000 Subject: [PATCH 2/6] Smpp::Tranciever#send_concat_mt doesn`t raises exception anymore if message_id is not an integer --- lib/smpp/transceiver.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/smpp/transceiver.rb b/lib/smpp/transceiver.rb index 70516c6..e5c0e2e 100644 --- a/lib/smpp/transceiver.rb +++ b/lib/smpp/transceiver.rb @@ -44,7 +44,8 @@ def send_concat_mt(message_id, source_addr, destination_addr, message, options = udh << sprintf("%c%c", 0, 3) # This is a concatenated message #TODO Figure out why this needs to be an int here, it's a string elsewhere - udh << sprintf("%c", message_id) # The ID for the entire concatenated message + # so, we can use object_id because it`s always integer + udh << sprintf("%c", message_id.object_id) # The ID for the entire concatenated message udh << sprintf("%c", parts.size) # How many parts this message consists of udh << sprintf("%c", i+1) # This is part i+1 From b78fcace13d829ff6d391cdb68405e5715ca350d Mon Sep 17 00:00:00 2001 From: kuroineko Date: Thu, 21 Jun 2012 00:27:03 +0000 Subject: [PATCH 3/6] message_id in send_contact_mt is now reduced to 1 octet length --- lib/smpp/transceiver.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/smpp/transceiver.rb b/lib/smpp/transceiver.rb index e5c0e2e..3c146fb 100644 --- a/lib/smpp/transceiver.rb +++ b/lib/smpp/transceiver.rb @@ -45,7 +45,7 @@ def send_concat_mt(message_id, source_addr, destination_addr, message, options = #TODO Figure out why this needs to be an int here, it's a string elsewhere # so, we can use object_id because it`s always integer - udh << sprintf("%c", message_id.object_id) # The ID for the entire concatenated message + udh << sprintf("%c", message_id.object_id & 0xFF) # The ID for the entire concatenated message udh << sprintf("%c", parts.size) # How many parts this message consists of udh << sprintf("%c", i+1) # This is part i+1 From 257c8c288a3eeb227e658defe9fce684acacb637 Mon Sep 17 00:00:00 2001 From: kuroineko Date: Thu, 21 Jun 2012 12:59:35 +0400 Subject: [PATCH 4/6] correct message slicing for ucs2 --- lib/smpp/transceiver.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/smpp/transceiver.rb b/lib/smpp/transceiver.rb index 3c146fb..b1167d7 100644 --- a/lib/smpp/transceiver.rb +++ b/lib/smpp/transceiver.rb @@ -31,12 +31,20 @@ def send_mt(message_id, source_addr, destination_addr, short_message, options={} # Send a concatenated message with a body of > 160 characters as multiple messages. def send_concat_mt(message_id, source_addr, destination_addr, message, options = {}) + message = message.dup logger.debug "Sending concatenated MT: #{message}" if @state == :bound # Split the message into parts of 153 characters. (160 - 7 characters for UDH) parts = [] - while message.size > 0 do - parts << message.slice!(0..Smpp::Transceiver.get_message_part_size(options)) + if options[:data_coding] != 8 + while message.size > 0 do + parts << message.slice!(0..Smpp::Transceiver.get_message_part_size(options)) + end + else + bytes = message.bytes.to_a + 0.upto((bytes / 134.0).ceil) do |part| + parts << bytes.slice(part * 134, 134).pack("C*") + end end 0.upto(parts.size-1) do |i| From 3b3181fe65ddd27ce2c54d9f5bf916b8aed9b693 Mon Sep 17 00:00:00 2001 From: kuroineko Date: Thu, 21 Jun 2012 13:05:16 +0400 Subject: [PATCH 5/6] fix --- lib/smpp/transceiver.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/smpp/transceiver.rb b/lib/smpp/transceiver.rb index b1167d7..484f539 100644 --- a/lib/smpp/transceiver.rb +++ b/lib/smpp/transceiver.rb @@ -42,7 +42,7 @@ def send_concat_mt(message_id, source_addr, destination_addr, message, options = end else bytes = message.bytes.to_a - 0.upto((bytes / 134.0).ceil) do |part| + 0.upto((bytes.length / 134.0).ceil) do |part| parts << bytes.slice(part * 134, 134).pack("C*") end end From 846821a393bbd8824c91c40426777722c8ec2023 Mon Sep 17 00:00:00 2001 From: kuroineko Date: Thu, 21 Jun 2012 13:10:37 +0400 Subject: [PATCH 6/6] fix --- lib/smpp/transceiver.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/smpp/transceiver.rb b/lib/smpp/transceiver.rb index 484f539..4b16da6 100644 --- a/lib/smpp/transceiver.rb +++ b/lib/smpp/transceiver.rb @@ -42,7 +42,7 @@ def send_concat_mt(message_id, source_addr, destination_addr, message, options = end else bytes = message.bytes.to_a - 0.upto((bytes.length / 134.0).ceil) do |part| + 0.upto(bytes.length / 134) do |part| parts << bytes.slice(part * 134, 134).pack("C*") end end