line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#=============================================================================== |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# FILE: Message.pm |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION: Common mobile message class |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# NOTES: --- |
8
|
|
|
|
|
|
|
# AUTHOR: Michael Bochkaryov (Rattler), <misha@rattler.kiev.ua> |
9
|
|
|
|
|
|
|
# COMPANY: Net.Style |
10
|
|
|
|
|
|
|
# CREATED: 21.08.2009 14:24:18 EEST |
11
|
|
|
|
|
|
|
#=============================================================================== |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
NetSDS::Message - common mobile message (SMS, MMS, IM) |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use NetSDS::Message; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
... |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$msg = NetSDS::Message->new( |
24
|
|
|
|
|
|
|
src_addr => '1234@mtsgw', |
25
|
|
|
|
|
|
|
dst_addr => '380441234567@mtsgw', |
26
|
|
|
|
|
|
|
body => $content, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
C<NetSDS::Message> is a superclass for other modules implementing API |
33
|
|
|
|
|
|
|
to exact structure of some messaging data (i.e. CPA2, SMS, MMS, etc). |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This module implemented to avoid duplication of code providing common |
36
|
|
|
|
|
|
|
functionality for all message types like managing addresses, headers, |
37
|
|
|
|
|
|
|
preparing reply message and so on. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
package NetSDS::Message; |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
2
|
|
34640
|
use 5.8.0; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
93
|
|
44
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
76
|
|
45
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
60
|
|
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
2
|
|
906
|
use NetSDS::Util::Misc; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use base qw(NetSDS::Class::Abstract); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
use version; our $VERSION = '0.021'; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#=============================================================================== |
54
|
|
|
|
|
|
|
# |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 CLASS API |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=over |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item B<new([...])> - class constructor |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $object = NetSDS::SomeClass->new(%options); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
67
|
|
|
|
|
|
|
sub new { |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my ( $class, %params ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $this = $class->SUPER::new( |
72
|
|
|
|
|
|
|
message_id => undef, # internal message id |
73
|
|
|
|
|
|
|
src_addr => undef, # source address (addr@system) |
74
|
|
|
|
|
|
|
dst_addr => undef, # destination address (addr@system) |
75
|
|
|
|
|
|
|
subject => undef, # subject if exists |
76
|
|
|
|
|
|
|
media => undef, # messaging media ('sms', 'mms', 'ussd', etc) |
77
|
|
|
|
|
|
|
headers => {}, # optional headers |
78
|
|
|
|
|
|
|
body => {}, # message body (depends on media) |
79
|
|
|
|
|
|
|
external_id => undef, # message id on external system (SMSC, SDP, customer, etc) |
80
|
|
|
|
|
|
|
format => undef, # message format ('cpa2', 'mtssmtp', 'smpp') |
81
|
|
|
|
|
|
|
%params |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Generate message id if absent |
85
|
|
|
|
|
|
|
if ( !$this->{message_id} ) { |
86
|
|
|
|
|
|
|
$this->{message_id} = $this->_make_id(); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
return $this; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} ## end sub new |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#*********************************************************************** |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item B<message_id([$value])> - set/get message id |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$msg_id = $msg->message_id(); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
102
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors('message_id'); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#*********************************************************************** |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item B<src_addr()> - set/get source address |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$msg->src_addr('380121234567@operatorgw'); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors('src_addr'); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
#*********************************************************************** |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item B<src_addr_native()> - get native form of source address |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Set address |
121
|
|
|
|
|
|
|
$msg->src_addr('380121234567@operatorgw'); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Get native form of address |
124
|
|
|
|
|
|
|
$phone = $msg->src_addr_native(); # return '380121234567' |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub src_addr_native { |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my ($this) = @_; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
if ( $this->src_addr =~ /(.*)@.*/ ) { |
135
|
|
|
|
|
|
|
return $1; |
136
|
|
|
|
|
|
|
} else { |
137
|
|
|
|
|
|
|
return $this->src_addr(); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
#*********************************************************************** |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item B<dst_addr()> - set/get destination address |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$dst_addr = $msg->dst_addr(); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
150
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors('dst_addr'); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
#*********************************************************************** |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item B<dst_addr_native()> - get native form of destination address |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
if ($mo_msg->dst_addr_native() eq '1234') { |
157
|
|
|
|
|
|
|
print "Received SMS to 1234"; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub dst_addr_native { |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my ($this) = @_; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
if ( $this->dst_addr =~ /(.*)@.*/ ) { |
169
|
|
|
|
|
|
|
return $1; |
170
|
|
|
|
|
|
|
} else { |
171
|
|
|
|
|
|
|
return $this->dst_addr(); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
#*********************************************************************** |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item B<subject()> - set/get message subject |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
$msg->subject('Hello there'); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors('subject'); |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
#*********************************************************************** |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item B<media()> - set/get message media |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Paramters: new media if set or none if get |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Supported media types: 'sms', 'mms', 'ussd'. In fact media types processing |
194
|
|
|
|
|
|
|
is not responsibility of this module and implemented in other modules. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors('media'); |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
#*********************************************************************** |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item B<header($name[, $value])> - set/get header |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Paramters: header name, new header value |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Returns: header value |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Message headers implemented as hash reference and contains supplementary |
211
|
|
|
|
|
|
|
information about message. All header name characters are lowercased |
212
|
|
|
|
|
|
|
and all '-' replaced with '_'. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# Set header |
215
|
|
|
|
|
|
|
$msg->header('X-Beer', 'Guinness'); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# Get this header |
218
|
|
|
|
|
|
|
$beer = $msg->header('x_beer'); |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=cut |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub header { |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
my ( $this, $name, $value ) = @_; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
# Normalize name first |
229
|
|
|
|
|
|
|
# All |
230
|
|
|
|
|
|
|
$name =~ s/-/_/g; |
231
|
|
|
|
|
|
|
$name = lc($name); |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
if (defined $value) { |
234
|
|
|
|
|
|
|
$this->{headers}->{$name} = $value; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
return $this->{headers}->{$name}; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
#*********************************************************************** |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item B<format()> - get/set message format |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Paramters: new format name |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Returns: format name |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Message format provides is related to transport layer code and describe |
249
|
|
|
|
|
|
|
data structure of message body. |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Supported formats: |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
B<sms> - generic SMS data for ETSI GSM 03.40 compliant implementations. |
254
|
|
|
|
|
|
|
See L<NetSDS::Message::SMS> for details. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
B<cpa2> - CPA2 compatible structure. |
257
|
|
|
|
|
|
|
See L<NetSDS::Message::CPA2> for details. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=cut |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors('format'); |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
#*********************************************************************** |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item B<reply()> - make reply message |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
This message allows to make reply to current one. |
270
|
|
|
|
|
|
|
Source and destination message are exchanged, media left the same. |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=cut |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub reply { |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
my ( $this, %params ) = @_; |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
# Prepare message with exchanged src_addr and dst_addr |
281
|
|
|
|
|
|
|
my $reply = $this->new( |
282
|
|
|
|
|
|
|
src_addr => $this->dst_addr, |
283
|
|
|
|
|
|
|
dst_addr => $this->src_addr, |
284
|
|
|
|
|
|
|
media => $this->media, |
285
|
|
|
|
|
|
|
format => $this->format, |
286
|
|
|
|
|
|
|
%params, |
287
|
|
|
|
|
|
|
); |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
$reply->_make_id(); |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
return $reply; |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
#*********************************************************************** |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=back |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head1 INTERNAL METHODS |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=over |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=item B<_make_id($system_name)> - generate message id |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
This method implements automatic generation of message id using |
306
|
|
|
|
|
|
|
make_uuid() routine. System name is set to 'netsds.generic' if |
307
|
|
|
|
|
|
|
not given in arguments. |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=cut |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
sub _make_id { |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
my ( $this, $system_name ) = @_; |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
# Generate default system name |
318
|
|
|
|
|
|
|
if ( !$system_name ) { |
319
|
|
|
|
|
|
|
$system_name = 'netsds.generic'; |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
return make_uuid() . '@' . $system_name; |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
1; |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
__END__ |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=back |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=head1 EXAMPLES |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
See C<samples> directory for examples. |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=head1 BUGS |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
Unknown yet |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=head1 SEE ALSO |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
None |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
=head1 TODO |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
None |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=head1 AUTHOR |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
Michael Bochkaryov <misha@rattler.kiev.ua> |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=head1 LICENSE |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
Copyright (C) 2008 Michael Bochkaryov |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
356
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
357
|
|
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or |
358
|
|
|
|
|
|
|
(at your option) any later version. |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
361
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
362
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
363
|
|
|
|
|
|
|
GNU General Public License for more details. |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
366
|
|
|
|
|
|
|
along with this program; if not, write to the Free Software |
367
|
|
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
=cut |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
|