line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Sms::Token::UD - SMS UD (user data length + user data) token |
2
|
|
|
|
|
|
|
# Copyright (C) 2002-2015 Cosimo Streppone, cosimo@cpan.org |
3
|
|
|
|
|
|
|
# Copyright (C) 2006-2015 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
|
|
|
|
|
|
|
package Sms::Token::UD; |
14
|
2
|
|
|
2
|
|
6
|
use integer; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
15
|
2
|
|
|
2
|
|
39
|
use strict; |
|
2
|
|
|
|
|
37
|
|
|
2
|
|
|
|
|
31
|
|
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
7
|
use Device::Gsm::Charset; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
25
|
|
18
|
2
|
|
|
2
|
|
6
|
use Device::Gsm::Pdu; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
59
|
|
19
|
2
|
|
|
2
|
|
7
|
use Device::Gsm::Sms::Token; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
429
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#my $udh1_length=UDH1_LENGTH; |
22
|
|
|
|
|
|
|
#my $udh2_length=UDH2_LENGTH; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
@Sms::Token::UD::ISA = ('Sms::Token'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# takes (scalar message (string) reference) |
27
|
|
|
|
|
|
|
# returns success/failure of decoding |
28
|
|
|
|
|
|
|
# if all ok, removes user data from message |
29
|
|
|
|
|
|
|
sub decode { |
30
|
14
|
|
|
14
|
|
12
|
my ($self, $rMessage) = @_; |
31
|
14
|
|
|
|
|
13
|
my $ok = 0; |
32
|
14
|
|
|
|
|
13
|
my $padding = 0; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Get length of message |
35
|
14
|
|
|
|
|
18
|
my $ud_len = hex substr($$rMessage, 0, 2); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Finally get text of message |
38
|
14
|
|
|
|
|
26
|
my $dcs = $self->get('_messageTokens')->{'DCS'}->get('_data')->[0]; |
39
|
14
|
|
|
|
|
23
|
my $is_csms = $self->get('_messageTokens')->{'UDH'}->{'_IS_CSMS'}; |
40
|
|
|
|
|
|
|
$is_csms |
41
|
14
|
50
|
|
|
|
20
|
and my $udhl = $self->get('_messageTokens')->{'UDH'}->{'_length'}; |
42
|
14
|
|
|
|
|
15
|
my $text; |
43
|
|
|
|
|
|
|
|
44
|
14
|
50
|
|
|
|
16
|
if ($dcs == 8) { |
45
|
0
|
|
|
|
|
0
|
$text = Device::Gsm::Pdu::decode_text_UCS2($$rMessage); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
14
|
50
|
|
|
|
16
|
if ($is_csms) { |
49
|
0
|
|
|
|
|
0
|
$padding = Sms::Token::UDH::calculate_padding($udhl); |
50
|
0
|
|
|
|
|
0
|
$text = Device::Gsm::Pdu::decode_text7_udh($$rMessage, $padding); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
14
|
|
|
|
|
23
|
$text = Device::Gsm::Pdu::decode_text7($$rMessage); |
54
|
|
|
|
|
|
|
} |
55
|
14
|
|
|
|
|
74
|
$text = Device::Gsm::Charset::gsm0338_to_iso8859($text); |
56
|
|
|
|
|
|
|
} |
57
|
14
|
|
|
|
|
38
|
$self->set('padding' => $padding); |
58
|
14
|
|
|
|
|
21
|
$self->set('length' => $ud_len); |
59
|
14
|
|
|
|
|
20
|
$self->set('text' => $text); |
60
|
14
|
|
|
|
|
27
|
$self->data($text); |
61
|
14
|
|
|
|
|
26
|
$self->state(Sms::Token::DECODED); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Empty message |
64
|
14
|
|
|
|
|
13
|
$$rMessage = ''; |
65
|
|
|
|
|
|
|
|
66
|
14
|
|
|
|
|
31
|
return 1; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# |
70
|
|
|
|
|
|
|
# [token]->encode( [$data] ) |
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
# takes internal token data and encodes it, returning the result or undef value in case of errors |
73
|
|
|
|
|
|
|
# |
74
|
|
|
|
|
|
|
sub encode { |
75
|
0
|
|
|
0
|
|
|
my $self = shift; |
76
|
0
|
|
|
|
|
|
my $padding = shift; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#my $ud_len = $self->get('length'); |
79
|
0
|
|
|
|
|
|
my $text = $self->get('text'); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return Device::Gsm::Pdu::encode_text7($text); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|