line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenID::Lite::Util::XRI; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1155
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
68
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
96
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my @XRI_AUTHORITIES = qw[! = @ + $ (]; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1096
|
use List::MoreUtils qw(any); |
|
2
|
|
|
|
|
1354
|
|
|
2
|
|
|
|
|
162
|
|
9
|
2
|
|
|
2
|
|
861
|
use URI::Escape; |
|
2
|
|
|
|
|
1409
|
|
|
2
|
|
|
|
|
1517
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub identifier_scheme { |
12
|
7
|
|
|
7
|
0
|
26
|
my ( $class, $identifier ) = @_; |
13
|
7
|
50
|
33
|
|
|
44
|
if ( $identifier |
14
|
|
|
|
|
|
|
&& length($identifier) > 0 ) |
15
|
|
|
|
|
|
|
{ |
16
|
7
|
|
|
|
|
14
|
my $first = substr( $identifier, 0, 1 ); |
17
|
|
|
|
|
|
|
return q{xri} |
18
|
|
|
|
|
|
|
if ( $identifier =~ /^xri:\/\// |
19
|
7
|
100
|
100
|
26
|
|
64
|
|| any { $first eq $_ } @XRI_AUTHORITIES ); |
|
26
|
|
|
|
|
60
|
|
20
|
|
|
|
|
|
|
} |
21
|
3
|
|
|
|
|
16
|
return q{uri}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub to_iri_normal { |
25
|
1
|
|
|
1
|
0
|
3
|
my ( $class, $xri ) = @_; |
26
|
1
|
50
|
|
|
|
7
|
$xri = sprintf( q{xri://%s}, $xri ) if $xri !~ /^xri\:\/\//; |
27
|
1
|
|
|
|
|
4
|
return $class->escape_for_iri($xri); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub escape_for_iri { |
31
|
5
|
|
|
5
|
0
|
9
|
my ( $class, $xri ) = @_; |
32
|
5
|
|
|
|
|
11
|
$xri =~ s/%/%25/g; |
33
|
5
|
|
|
|
|
20
|
$xri =~ s/(\(.*?\))/$class->_escape_for_iri_match($1)/eg; |
|
3
|
|
|
|
|
8
|
|
34
|
5
|
|
|
|
|
21
|
return $xri; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _escape_for_iri_match { |
38
|
3
|
|
|
3
|
|
7
|
my ( $class, $matched ) = @_; |
39
|
3
|
|
|
|
|
8
|
$matched =~ s/([\/\?\#])/URI::Escape::uri_escape_utf8($1)/eg; |
|
3
|
|
|
|
|
42
|
|
40
|
3
|
|
|
|
|
74
|
return $matched; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub to_url_normal { |
44
|
0
|
|
|
0
|
0
|
|
my ( $class, $xri ) = @_; |
45
|
0
|
|
|
|
|
|
return $class->iri_to_url( $class->to_iri_normal($xri) ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub iri_to_url { |
49
|
0
|
|
|
0
|
0
|
|
my ( $class, $iri ) = @_; |
50
|
0
|
|
|
|
|
|
return $iri; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub make_xri { |
54
|
0
|
|
|
0
|
0
|
|
my ( $class, $xri ) = @_; |
55
|
0
|
0
|
|
|
|
|
if ( $xri =~ /^xri:\/\// ) { |
56
|
0
|
|
|
|
|
|
$xri = sprintf q{xri://%s}, $xri; |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
return $xri; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub root_authority { |
62
|
0
|
|
|
0
|
0
|
|
my ( $class, $xri ) = @_; |
63
|
0
|
0
|
|
|
|
|
$xri = substr($xri, 6) if (index($xri, q{xri://}) == 0); |
64
|
0
|
|
|
|
|
|
my $authority = ( split( /\//, $xri, 2 ) )[0]; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $root; |
67
|
0
|
0
|
|
|
|
|
if ( $authority =~ /^(\([^\)]*\))/ ) { |
|
|
0
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$root = $1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
elsif ( $authority =~ /^([\!\=\@\+\$\(])/ ) { |
71
|
0
|
|
|
|
|
|
$root = $1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { |
74
|
0
|
|
|
|
|
|
$root = ( split /[!*]/, $authority )[0]; |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
return $class->make_xri($root); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub provider_is_authoritative { |
80
|
0
|
|
|
0
|
0
|
|
my ( $class, $provider_id, $canonical_id ) = @_; |
81
|
0
|
0
|
0
|
|
|
|
return unless ($provider_id && $canonical_id); |
82
|
0
|
|
|
|
|
|
my $lastbang = rindex($canonical_id, '!'); |
83
|
0
|
0
|
|
|
|
|
return 0 if $lastbang < 0; |
84
|
0
|
|
|
|
|
|
my $parent = substr($canonical_id, 0, $lastbang); |
85
|
0
|
|
|
|
|
|
return ( $parent eq $provider_id ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|