| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTTP::ProxyPAC; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
361778
|
use strict; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
163
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.31'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
15
|
use Carp; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
250
|
|
|
7
|
3
|
|
|
3
|
|
18
|
use Scalar::Util qw(blessed); |
|
|
3
|
|
|
|
|
10
|
|
|
|
3
|
|
|
|
|
252
|
|
|
8
|
3
|
|
|
3
|
|
2729
|
use URI; |
|
|
3
|
|
|
|
|
18413
|
|
|
|
3
|
|
|
|
|
141
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my ($useJE, $usePerlLib); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
|
13
|
|
|
|
|
|
|
# prevent error message when running standalone |
|
14
|
3
|
50
|
|
3
|
|
2571
|
if (-e 'blib/HTTP/ProxyPAC/Functions.pm') {use lib 'blib'} |
|
|
3
|
50
|
|
3
|
|
1928
|
|
|
|
3
|
|
|
|
|
15
|
|
|
|
3
|
|
|
|
|
12
|
|
|
|
3
|
|
|
|
|
369
|
|
|
15
|
3
|
|
|
3
|
|
326
|
elsif (-e 'lib/HTTP/ProxyPAC/Functions.pm') {use lib 'lib'} |
|
|
3
|
|
|
|
|
4
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
3
|
|
|
|
|
2713
|
require HTTP::ProxyPAC::Functions; |
|
18
|
3
|
|
|
|
|
1261
|
require HTTP::ProxyPAC::Result; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
our $UserAgent; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
|
23
|
10
|
|
|
10
|
1
|
716471
|
my $class = shift; |
|
24
|
10
|
|
|
|
|
29
|
my $stuff = shift; |
|
25
|
|
|
|
|
|
|
|
|
26
|
10
|
|
|
|
|
85
|
my %options = @_; |
|
27
|
|
|
|
|
|
|
|
|
28
|
10
|
50
|
33
|
|
|
275
|
if ($options{interp} && $options{interp} =~ /javascript|js/i) { |
|
|
|
50
|
33
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
eval "use JavaScript"; |
|
30
|
0
|
0
|
|
|
|
0
|
if ($@) { |
|
31
|
0
|
0
|
|
|
|
0
|
if (-e "t/00_compile.t") {return} |
|
|
0
|
|
|
|
|
0
|
|
|
32
|
0
|
|
|
|
|
0
|
die $@; |
|
33
|
|
|
|
|
|
|
} } elsif ($options{interp} && $options{interp} =~ /je/i) { |
|
34
|
10
|
|
|
|
|
111
|
require JE; |
|
35
|
10
|
|
|
|
|
28
|
$useJE = 1; |
|
36
|
|
|
|
|
|
|
} else { |
|
37
|
0
|
|
|
|
|
0
|
eval "use JavaScript"; |
|
38
|
0
|
0
|
|
|
|
0
|
if ($@) { |
|
39
|
0
|
|
|
|
|
0
|
my $atJS = $@; |
|
40
|
0
|
|
|
|
|
0
|
eval "use JE"; |
|
41
|
0
|
0
|
|
|
|
0
|
if ($@) { |
|
|
0
|
|
|
|
|
0
|
|
|
42
|
0
|
|
|
|
|
0
|
die "neither the JavaScript module nor the JS module seems to be available\n" |
|
43
|
|
|
|
|
|
|
. "use JavaScript reports: $atJS\nuse JE reports: $@"; |
|
44
|
|
|
|
|
|
|
} else {$useJE = 1} |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
10
|
|
66
|
|
|
86
|
$usePerlLib = $options{lib} && $options{lib} =~ /perl/i; |
|
48
|
|
|
|
|
|
|
|
|
49
|
10
|
100
|
66
|
|
|
255
|
if (blessed($stuff) && $stuff->isa('URI')) { |
|
|
|
50
|
33
|
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
11
|
return $class->init( $class->load_uri($stuff) ); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
elsif (blessed($stuff) && $stuff->isa('IO::Handle')) { |
|
53
|
0
|
|
|
|
|
0
|
return $class->init( $class->load_fh($stuff) ); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
elsif (ref($stuff) && ref($stuff) eq 'GLOB') { |
|
56
|
2
|
|
|
|
|
11
|
return $class->init( $class->load_fh($stuff) ); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
elsif (ref($stuff) && ref($stuff) eq 'SCALAR') { |
|
59
|
2
|
|
|
|
|
11
|
return $class->init( $$stuff ); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
elsif (!ref($stuff)) { |
|
62
|
4
|
|
|
|
|
20
|
return $class->init( $class->load_file($stuff) ); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
else { |
|
65
|
0
|
|
|
|
|
0
|
Carp::croak("Unknown reference type to HTTP::ProxyPAC->new: ", ref($stuff)); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub load_uri { |
|
70
|
2
|
|
|
2
|
0
|
5
|
my($class, $uri) = @_; |
|
71
|
|
|
|
|
|
|
|
|
72
|
2
|
|
66
|
|
|
12
|
$UserAgent ||= do { |
|
73
|
1
|
|
|
|
|
7
|
require LWP::UserAgent; |
|
74
|
1
|
|
|
|
|
14
|
LWP::UserAgent->new(agent => __PACKAGE__ . "/" . $VERSION); |
|
75
|
|
|
|
|
|
|
}; |
|
76
|
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
308
|
my $res = $UserAgent->get($uri); |
|
78
|
|
|
|
|
|
|
|
|
79
|
2
|
50
|
|
|
|
597125
|
if ($res->content_type ne "application/x-ns-proxy-autoconfig") { |
|
80
|
0
|
|
|
|
|
0
|
Carp::croak("Content-Type should be application/x-ns-proxy-autoconfig, is ", |
|
81
|
|
|
|
|
|
|
$res->content_type); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
2
|
|
|
|
|
72
|
return $res->content; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub load_fh { |
|
87
|
6
|
|
|
6
|
0
|
16
|
my($class, $fh) = @_; |
|
88
|
6
|
|
|
|
|
185
|
read($fh, my($body), -s $fh); |
|
89
|
6
|
|
|
|
|
28
|
$body; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub load_file { |
|
93
|
4
|
|
|
4
|
0
|
10
|
my($class, $file) = @_; |
|
94
|
|
|
|
|
|
|
|
|
95
|
4
|
50
|
|
|
|
292
|
open my $fh, $file or Carp::croak("$file: $!"); |
|
96
|
4
|
|
|
|
|
33
|
my $body = $class->load_fh($fh); |
|
97
|
4
|
|
|
|
|
45
|
close $fh; |
|
98
|
|
|
|
|
|
|
|
|
99
|
4
|
|
|
|
|
32
|
$body; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub init { |
|
104
|
10
|
|
|
10
|
0
|
80
|
my ($class, $code) = @_; |
|
105
|
10
|
|
|
|
|
24
|
my ($func, $runtime, $context); |
|
106
|
|
|
|
|
|
|
|
|
107
|
10
|
50
|
|
|
|
29
|
if ($useJE) { |
|
108
|
10
|
|
|
|
|
76
|
$runtime = new JE::; |
|
109
|
|
|
|
|
|
|
} else { |
|
110
|
0
|
|
|
|
|
0
|
$runtime = JavaScript::Runtime->new; |
|
111
|
0
|
|
|
|
|
0
|
$context = $runtime->create_context(); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
10
|
100
|
|
|
|
48255
|
for $func ($usePerlLib ? @HTTP::ProxyPAC::Functions::PACFunctions |
|
114
|
|
|
|
|
|
|
: @HTTP::ProxyPAC::Functions::baseFunctions) { |
|
115
|
3
|
|
|
3
|
|
17
|
no strict 'refs'; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
1110
|
|
|
116
|
70
|
50
|
|
|
|
23494
|
if ($useJE) { |
|
117
|
70
|
|
|
27
|
|
504
|
$runtime->new_function($func => sub { &{"HTTP::ProxyPAC::Functions::$func"}(@_) }); |
|
|
27
|
|
|
|
|
64365
|
|
|
|
27
|
|
|
|
|
244
|
|
|
118
|
|
|
|
|
|
|
} else { |
|
119
|
|
|
|
|
|
|
$context->bind_function(name => $func, |
|
120
|
0
|
|
|
0
|
|
0
|
func => sub { &{"HTTP::ProxyPAC::Functions::$func"}(@_) }); |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
121
|
|
|
|
|
|
|
} } |
|
122
|
|
|
|
|
|
|
# if we are using the JS library functions from Mozilla, include them before the .pac file |
|
123
|
10
|
100
|
|
|
|
2838
|
if (!$usePerlLib) {$code = HTTP::ProxyPAC::Functions::nsProxyAutoConfig . $code} |
|
|
5
|
|
|
|
|
22
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
10
|
50
|
|
|
|
43
|
if ($useJE) { |
|
126
|
10
|
|
|
|
|
53
|
$runtime->eval($code); |
|
127
|
10
|
|
|
|
|
708351
|
bless { context => $runtime }, $class; |
|
128
|
|
|
|
|
|
|
} else { |
|
129
|
0
|
|
|
|
|
0
|
$context->eval($code); |
|
130
|
0
|
|
|
|
|
0
|
bless { context => $context }, $class; |
|
131
|
|
|
|
|
|
|
} } |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub find_proxy { |
|
134
|
24
|
|
|
24
|
1
|
10650
|
my($self, $url) = @_; |
|
135
|
|
|
|
|
|
|
|
|
136
|
24
|
50
|
|
|
|
108
|
Carp::croak("Usage: find_proxy(url)") unless defined $url; |
|
137
|
|
|
|
|
|
|
|
|
138
|
24
|
|
|
|
|
165
|
$url = URI->new($url); |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# there is a PAC file for the interpreter to interpret |
|
141
|
24
|
|
|
|
|
18539
|
my $res = $self->{context}->eval(sprintf("FindProxyForURL('%s', '%s')", |
|
142
|
|
|
|
|
|
|
$url->as_string, $url->host)); |
|
143
|
|
|
|
|
|
|
|
|
144
|
24
|
|
|
|
|
202176
|
my @res = HTTP::ProxyPAC::Result->parse($res, $url); |
|
145
|
24
|
100
|
|
|
|
221
|
return wantarray ? @res : $res[0]; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
|
149
|
|
|
|
|
|
|
__END__ |