Subject: | send_sms_multipart did not works correct |
If i use the send_sms_multipart method, i get an endless loop in the
while loop to split the message in chunks.
I have write a new loop (as documented in attached patch) and some code
optimizations.
Subject: | Net_UCP_multisend.patch |
--- Net-UCP-0.40/lib/Net/UCP.pm 2009-05-29 15:28:33.000000000 +0200
+++ Net-UCP-0.41/lib/Net/UCP.pm 2010-04-06 16:50:44.000000000 +0200
@@ -50,6 +50,7 @@
# login to SMSC
sub login {
my $self = shift();
+
my %args = (
SMSC_ID => '',
SMSC_PW => '',
@@ -208,9 +209,7 @@
sub send_sms_multipart {
my $self = shift;
-
- my %argsLong =(
- RECIPIENT => '',
+ my %argsLong =(RECIPIENT => '',
MESSAGE_TEXT => '',
SENDER_TEXT => '',
UDH => undef,
@@ -219,45 +218,20 @@
TIMEOUT => undef,
@_);
- my $chunkBlock = 134;
my $messageId = random_int(1,255);
-
my $multiHash;
-
- my $txtTmp = $argsLong{MESSAGE_TEXT};
my $countPart = 0;
- my $chunk;
- while (length($txtTmp) != 0) {
-
- if (length($txtTmp) > 134) {
- $txtTmp =~ s/((.){134})//;
- $chunk = $1;
- } else {
- $chunk = $txtTmp;
- $txtTmp = '';
- }
-
+ foreach my $chunk ($argsLong{MESSAGE_TEXT}=~m/(.{1,134})/sg){
$multiHash->{++$countPart} = $chunk;
-
}
-
- my $textChunk = '';
- my $k = '';
- my $udhChunk = '';
- my $ret;
-
- while (($k, $textChunk) = each %{$multiHash}) {
- $udhChunk = "0106050003"
- . sprintf("%02X", $messageId)
- . sprintf("%02X", $countPart)
- . sprintf("%02X", $k);
-
- $ret = $self->send_sms(
+ while (my ($k, $textChunk) = each %{$multiHash}) {
+ my $udh=sprintf('%s%02X%02X%02X',"0106050003",$messageId,$countPart,$k);
+ my $ret = $self->send_sms(
RECIPIENT => $argsLong{RECIPIENT},
MESSAGE_TEXT => $textChunk,
SENDER_TEXT => $argsLong{SENDER_TEXT},
- UDH => $udhChunk,
+ UDH => $udh
);
return $ret if (!$ret || !defined($ret)); #it could be better