line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Squid::Purge::UDP; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1347
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base qw(Net::Squid::Purge); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
91
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Socket; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
760
|
|
9
|
1
|
|
|
1
|
|
7
|
use IO::Socket::INET; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Net::Squid::Purge::UDP->mk_accessors(qw(squid_servers)); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.1'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub purge { |
16
|
0
|
|
|
0
|
1
|
|
my ($self, @urls) = @_; |
17
|
0
|
0
|
|
|
|
|
if (! $self->squid_servers) { die 'squid_servers must be set!'; } |
|
0
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
for my $squid_host (@{$self->squid_hosts}) { |
|
0
|
|
|
|
|
|
|
19
|
0
|
|
0
|
|
|
|
my $s = IO::Socket::INET->new( |
20
|
|
|
|
|
|
|
PeerAddr => $squid_host->{'host'}, |
21
|
|
|
|
|
|
|
PeerPort => $squid_host->{'port'} || 3128, |
22
|
|
|
|
|
|
|
Proto => 'udp', |
23
|
|
|
|
|
|
|
Type => SOCK_DGRAM |
24
|
|
|
|
|
|
|
); |
25
|
0
|
0
|
|
|
|
|
if (! $s) { die 'Could not create socket to host ' . $squid_host->{'host'}; } |
|
0
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
for my $url (@urls) { |
27
|
0
|
0
|
|
|
|
|
if (! $s->send($self->_format_purge($url))) { die 'Purge request failed'; } |
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
0
|
|
|
|
|
|
return 1; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _format_purge { |
34
|
0
|
|
|
0
|
|
|
my ($self, $url) = @_; |
35
|
0
|
0
|
|
|
|
|
if (! $url) { die 'url parameter must be passed'; } |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $spec = pack( |
37
|
|
|
|
|
|
|
'na4na*na8n', |
38
|
|
|
|
|
|
|
4, 'NONE', length( $url ), $url, |
39
|
|
|
|
|
|
|
8, 'HTTP/1.0', 0 |
40
|
|
|
|
|
|
|
); |
41
|
0
|
|
|
|
|
|
my $dlen = 8 + 2 + length( $spec ); |
42
|
0
|
|
|
|
|
|
my $len = 4 + $dlen + 2; |
43
|
0
|
|
|
|
|
|
return pack( 'nxxnCxNxxa*n', $len, $dlen, 4, rand(), $spec, 2); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
__END__ |