line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Sms::Token::UD - SMS UD (user data length + user data) token |
2
|
|
|
|
|
|
|
# Copyright (C) 2002-2006 Cosimo Streppone, cosimo@cpan.org |
3
|
|
|
|
|
|
|
# Copyright (C) 2006-2011 Grzegorz Wozniak, wozniakg@gmail.com |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
6
|
|
|
|
|
|
|
# it only under the terms of Perl itself. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
9
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11
|
|
|
|
|
|
|
# Perl licensing terms for details. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# $Id$ |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package Sms::Token::UD; |
16
|
1
|
|
|
1
|
|
6
|
use integer; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
17
|
1
|
|
|
1
|
|
34
|
use strict; |
|
1
|
|
|
|
|
95
|
|
|
1
|
|
|
|
|
38
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
7
|
use Device::Gsm::Charset; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
20
|
1
|
|
|
1
|
|
6
|
use Device::Gsm::Pdu; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
21
|
1
|
|
|
1
|
|
6
|
use Device::Gsm::Sms::Token; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
528
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#my $udh1_length=UDH1_LENGTH; |
24
|
|
|
|
|
|
|
#my $udh2_length=UDH2_LENGTH; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
@Sms::Token::UD::ISA = ('Sms::Token'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# takes (scalar message (string) reference) |
29
|
|
|
|
|
|
|
# returns success/failure of decoding |
30
|
|
|
|
|
|
|
# if all ok, removes user data from message |
31
|
|
|
|
|
|
|
sub decode { |
32
|
6
|
|
|
6
|
|
15
|
my ($self, $rMessage) = @_; |
33
|
6
|
|
|
|
|
11
|
my $ok = 0; |
34
|
6
|
|
|
|
|
8
|
my $padding = 0; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Get length of message |
37
|
6
|
|
|
|
|
16
|
my $ud_len = hex substr($$rMessage, 0, 2); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Finally get text of message |
40
|
6
|
|
|
|
|
24
|
my $dcs = $self->get('_messageTokens')->{'DCS'}->get('_data')->[0]; |
41
|
6
|
|
|
|
|
22
|
my $is_csms = $self->get('_messageTokens')->{'UDH'}->{'_IS_CSMS'}; |
42
|
6
|
50
|
|
|
|
16
|
$is_csms |
43
|
|
|
|
|
|
|
and my $udhl = $self->get('_messageTokens')->{'UDH'}->{'_length'}; |
44
|
6
|
|
|
|
|
9
|
my $text; |
45
|
|
|
|
|
|
|
|
46
|
6
|
50
|
|
|
|
17
|
if ($dcs == 8) { |
47
|
0
|
|
|
|
|
0
|
$text = Device::Gsm::Pdu::decode_text_UCS2($$rMessage); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
6
|
50
|
|
|
|
16
|
if ($is_csms) { |
51
|
0
|
|
|
|
|
0
|
$padding = Sms::Token::UDH::calculate_padding($udhl); |
52
|
0
|
|
|
|
|
0
|
$text = Device::Gsm::Pdu::decode_text7_udh($$rMessage, $padding); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
6
|
|
|
|
|
22
|
$text = Device::Gsm::Pdu::decode_text7($$rMessage); |
56
|
|
|
|
|
|
|
} |
57
|
6
|
|
|
|
|
58
|
$text = Device::Gsm::Charset::gsm0338_to_iso8859($text); |
58
|
|
|
|
|
|
|
} |
59
|
6
|
|
|
|
|
31
|
$self->set('padding' => $padding); |
60
|
6
|
|
|
|
|
18
|
$self->set('length' => $ud_len); |
61
|
6
|
|
|
|
|
20
|
$self->set('text' => $text); |
62
|
6
|
|
|
|
|
24
|
$self->data($text); |
63
|
6
|
|
|
|
|
19
|
$self->state(Sms::Token::DECODED); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Empty message |
66
|
6
|
|
|
|
|
48
|
$$rMessage = ''; |
67
|
|
|
|
|
|
|
|
68
|
6
|
|
|
|
|
24
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
# [token]->encode( [$data] ) |
73
|
|
|
|
|
|
|
# |
74
|
|
|
|
|
|
|
# takes internal token data and encodes it, returning the result or undef value in case of errors |
75
|
|
|
|
|
|
|
# |
76
|
|
|
|
|
|
|
sub encode { |
77
|
0
|
|
|
0
|
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
my $padding = shift; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#my $ud_len = $self->get('length'); |
81
|
0
|
|
|
|
|
|
my $text = $self->get('text'); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return Device::Gsm::Pdu::encode_text7($text); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|