| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package SMS::Handler::Ping; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.005_62; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1635
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
64
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use SMS::Handler; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
57
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use vars qw(@ISA); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
66
|
|
|
10
|
1
|
|
|
1
|
|
1689
|
use Net::SMPP 1.04; |
|
|
1
|
|
|
|
|
65624
|
|
|
|
1
|
|
|
|
|
14
|
|
|
11
|
1
|
|
|
1
|
|
2030
|
use Params::Validate qw(:all); |
|
|
1
|
|
|
|
|
18585
|
|
|
|
1
|
|
|
|
|
1221
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# $Id: Ping.pm,v 1.7 2003/01/14 20:32:34 lem Exp $ |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
(our $VERSION = q$Revision: 1.7 $) =~ s/Revision //; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $Debug = 0; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=pod |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
SMS::Handler::Ping - Simple test for SMS::Handler |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use SMS::Handler::Ping; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $h = SMS::Handler::Ping->new(-message => "It's alive", |
|
30
|
|
|
|
|
|
|
-queue => $queue_obj, |
|
31
|
|
|
|
|
|
|
-addr => '9.9.5551212', |
|
32
|
|
|
|
|
|
|
-dest => '9.9.5551313', |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$h->handle({ ... }); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This module implements a simple responder class. It will respond to |
|
40
|
|
|
|
|
|
|
any message directed to the specified phone number, with the specified |
|
41
|
|
|
|
|
|
|
message. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
The following methods are provided: |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=over 4 |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item C<-Enew()> |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Creates a new C object. It accepts parameters as a |
|
50
|
|
|
|
|
|
|
number of key / value pairs. The following parameters are supported. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=over 2 |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item C $message> |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
The text of the message that must be returned. If it is left |
|
57
|
|
|
|
|
|
|
unspecified, the word B<"Pong"> will be used. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Note that if the SMS text matches this, no answer will be produced to |
|
60
|
|
|
|
|
|
|
avoid loops. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item C $queue_obj> |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
An object obeying the interface defined in L, where the |
|
65
|
|
|
|
|
|
|
response message generated by this module will be stored. |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item C $my_addr> |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
The address assigned to this service, in B format. The |
|
70
|
|
|
|
|
|
|
destination address of the SMS, must match this argument. If this |
|
71
|
|
|
|
|
|
|
address is left unspecified, the SMS will be accepted no matter what |
|
72
|
|
|
|
|
|
|
destination address is used. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item C $dest_addr> |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
If this argument is supplied, any answers will be sent to this |
|
77
|
|
|
|
|
|
|
address. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=back |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub new |
|
84
|
|
|
|
|
|
|
{ |
|
85
|
0
|
|
|
0
|
1
|
|
my $name = shift; |
|
86
|
0
|
|
0
|
|
|
|
my $class = ref($name) || $name; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my %self = validate_with |
|
89
|
|
|
|
|
|
|
( |
|
90
|
|
|
|
|
|
|
params => \@_, |
|
91
|
|
|
|
|
|
|
ignore_case => 1, |
|
92
|
|
|
|
|
|
|
strip_leading => '-', |
|
93
|
|
|
|
|
|
|
spec => |
|
94
|
|
|
|
|
|
|
{ |
|
95
|
|
|
|
|
|
|
message => |
|
96
|
|
|
|
|
|
|
{ |
|
97
|
|
|
|
|
|
|
type => SCALAR, |
|
98
|
|
|
|
|
|
|
default => 'Pong', |
|
99
|
|
|
|
|
|
|
}, |
|
100
|
|
|
|
|
|
|
queue => |
|
101
|
|
|
|
|
|
|
{ |
|
102
|
|
|
|
|
|
|
type => OBJECT, |
|
103
|
|
|
|
|
|
|
can => [ qw(store) ], |
|
104
|
|
|
|
|
|
|
}, |
|
105
|
|
|
|
|
|
|
addr => |
|
106
|
|
|
|
|
|
|
{ |
|
107
|
|
|
|
|
|
|
type => SCALAR, |
|
108
|
|
|
|
|
|
|
default => undef, |
|
109
|
|
|
|
|
|
|
callbacks => |
|
110
|
|
|
|
|
|
|
{ |
|
111
|
0
|
|
|
0
|
|
|
'address format' => sub { $_[0] =~ /^\d+\.\d+\.\d+$/; } |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
}, |
|
114
|
|
|
|
|
|
|
dest => |
|
115
|
|
|
|
|
|
|
{ |
|
116
|
|
|
|
|
|
|
type => SCALAR, |
|
117
|
|
|
|
|
|
|
default => undef, |
|
118
|
|
|
|
|
|
|
callbacks => |
|
119
|
|
|
|
|
|
|
{ |
|
120
|
0
|
|
|
0
|
|
|
'address format' => sub { $_[0] =~ /^\d+\.\d+\.\d+$/; } |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
0
|
|
|
|
|
|
}); |
|
124
|
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
if ($self{addr}) |
|
126
|
|
|
|
|
|
|
{ |
|
127
|
0
|
|
|
|
|
|
($self{ton}, $self{npi}, $self{number}) = split(/\./, $self{addr}, 3); |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
if ($self{dest}) |
|
131
|
|
|
|
|
|
|
{ |
|
132
|
0
|
|
|
|
|
|
($self{dton}, $self{dnpi}, $self{dnumber}) = |
|
133
|
|
|
|
|
|
|
split(/\./, $self{dest}, 3); |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
return bless \%self, $class; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=pod |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item C<-Ehandle()> |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Process the given SMS. The source and destination addresses are |
|
144
|
|
|
|
|
|
|
reversed. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub handle |
|
149
|
|
|
|
|
|
|
{ |
|
150
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
151
|
0
|
|
|
|
|
|
my $hsms = shift; |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
if ($self->{number}) |
|
154
|
|
|
|
|
|
|
{ |
|
155
|
0
|
0
|
|
|
|
|
unless ($hsms->{dest_addr_ton} == $self->{ton}) |
|
156
|
|
|
|
|
|
|
{ |
|
157
|
0
|
0
|
|
|
|
|
warn "Ping: Destination address did not match TON\n" if $Debug; |
|
158
|
0
|
|
|
|
|
|
return SMS_CONTINUE; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
0
|
0
|
|
|
|
|
unless ($hsms->{dest_addr_npi} == $self->{npi}) |
|
161
|
|
|
|
|
|
|
{ |
|
162
|
0
|
0
|
|
|
|
|
warn "Ping: Destination address did not match NPI\n" if $Debug; |
|
163
|
0
|
|
|
|
|
|
return SMS_CONTINUE; |
|
164
|
|
|
|
|
|
|
} |
|
165
|
0
|
0
|
|
|
|
|
unless ($hsms->{destination_addr} == $self->{number}) |
|
166
|
|
|
|
|
|
|
{ |
|
167
|
0
|
0
|
|
|
|
|
warn "Ping: Destination address did not match NUMBER\n" if $Debug; |
|
168
|
0
|
|
|
|
|
|
return SMS_CONTINUE; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
0
|
|
|
|
|
if ($hsms->{short_message} ne $self->{message}) |
|
173
|
|
|
|
|
|
|
{ |
|
174
|
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
my $pdu = new Net::SMPP::PDU; |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
$pdu->source_addr_ton($hsms->{dest_addr_ton}); |
|
178
|
0
|
|
|
|
|
|
$pdu->source_addr_npi($hsms->{dest_addr_npi}); |
|
179
|
0
|
|
|
|
|
|
$pdu->source_addr($hsms->{destination_addr}); |
|
180
|
0
|
|
0
|
|
|
|
$pdu->dest_addr_ton($self->{dton} || $hsms->{source_addr_ton}); |
|
181
|
0
|
|
0
|
|
|
|
$pdu->dest_addr_npi($self->{dnpi} || $hsms->{source_addr_npi}); |
|
182
|
0
|
|
0
|
|
|
|
$pdu->destination_addr($self->{dnumber} || $hsms->{source_addr}); |
|
183
|
0
|
|
|
|
|
|
$pdu->short_message($self->{message}); |
|
184
|
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
my ($fh, $qid) = $self->{queue}->store; |
|
186
|
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
$pdu->nstore_fd($fh); |
|
188
|
|
|
|
|
|
|
|
|
189
|
0
|
0
|
|
|
|
|
if ($fh->close) |
|
190
|
|
|
|
|
|
|
{ |
|
191
|
0
|
0
|
|
|
|
|
warn "Ping: Unlocking and commiting response message\n" if $Debug; |
|
192
|
0
|
|
|
|
|
|
$self->{queue}->unlock($qid); |
|
193
|
0
|
|
|
|
|
|
return SMS_STOP | SMS_DEQUEUE; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
|
|
196
|
0
|
0
|
|
|
|
|
warn "Ping: close() failed (unlocking response): $!\n" if $Debug; |
|
197
|
0
|
|
|
|
|
|
$self->{queue}->unlock($qid); |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
else |
|
200
|
|
|
|
|
|
|
{ |
|
201
|
0
|
0
|
|
|
|
|
warn "Ping: destroy source message\n" if $Debug; |
|
202
|
0
|
|
|
|
|
|
return SMS_STOP | SMS_DEQUEUE; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
0
|
0
|
|
|
|
|
warn "Ping: SMS_CONTINUE\n" if $Debug; |
|
206
|
0
|
|
|
|
|
|
return SMS_CONTINUE; |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
1; |
|
210
|
|
|
|
|
|
|
__END__ |