line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::WWWAuthenticate; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Parse the WWW-Authenticate HTTP header |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
23468
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
21
|
|
6
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use base 'Exporter'; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
51
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
11
|
1
|
|
|
1
|
|
454
|
use HTTP::Headers::Util qw(_split_header_words); |
|
1
|
|
|
|
|
586
|
|
|
1
|
|
|
|
|
294
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.02; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw(parse_wwwa); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub parse_wwwa { |
18
|
32
|
|
|
32
|
1
|
16735
|
my ($string) = @_; |
19
|
|
|
|
|
|
|
|
20
|
32
|
|
|
|
|
48
|
my @parts = split_header_words( $string); |
21
|
|
|
|
|
|
|
|
22
|
32
|
|
|
|
|
34
|
my $challenge = $parts[0]->[0]; |
23
|
32
|
|
|
|
|
21
|
my %challenges; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
PART: |
26
|
32
|
|
|
|
|
25
|
for my $part ( @parts ) { |
27
|
58
|
|
|
|
|
40
|
my ($maybe_challenge, $challenge_check) = @{$part}; |
|
58
|
|
|
|
|
77
|
|
28
|
|
|
|
|
|
|
|
29
|
58
|
100
|
|
|
|
93
|
if ( !defined $challenge_check ) { |
30
|
41
|
|
|
|
|
45
|
$challenge = ucfirst lc $maybe_challenge; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
58
|
|
|
|
|
56
|
my ($key, $value) = ($part->[-2], $part->[-1]); |
34
|
58
|
100
|
|
|
|
64
|
if ( !defined $value ) { |
35
|
5
|
50
|
|
|
|
9
|
if ( !exists $challenges{$challenge} ) { |
36
|
5
|
|
|
|
|
7
|
$challenges{$challenge} = {}; |
37
|
|
|
|
|
|
|
} |
38
|
5
|
|
|
|
|
8
|
next PART; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
53
|
|
|
|
|
42
|
my $lc_key = lc $key; |
42
|
53
|
100
|
100
|
|
|
159
|
if ( $challenge eq 'Basic' && |
|
|
|
66
|
|
|
|
|
43
|
|
|
|
|
|
|
$lc_key eq 'realm' && |
44
|
|
|
|
|
|
|
exists $challenges{$challenge}->{$lc_key} |
45
|
|
|
|
|
|
|
) { |
46
|
1
|
|
|
|
|
9
|
croak 'only one realm is allowed'; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
52
|
|
|
|
|
98
|
$challenges{$challenge}->{lc $key} = $value; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
31
|
100
|
100
|
|
|
88
|
if ( exists $challenges{Basic} && !exists $challenges{Basic}->{realm} ) { |
53
|
1
|
|
|
|
|
18
|
croak 'realm parameter is missing'; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
30
|
|
|
|
|
101
|
return %challenges; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub split_header_words { |
60
|
32
|
|
|
32
|
1
|
44
|
my @res = &_split_header_words; |
61
|
32
|
|
|
|
|
1088
|
for my $arr (@res) { |
62
|
58
|
|
|
|
|
104
|
for (my $i = @$arr - 2; $i >= 0; $i -= 2) { |
63
|
94
|
|
|
|
|
151
|
$arr->[$i] = $arr->[$i]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
32
|
|
|
|
|
46
|
return @res; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |