line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perinci::AccessUtil; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2014-10-23'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.04'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
497
|
use 5.010001; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
7
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
8
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
429
|
use MIME::Base64; |
|
1
|
|
|
|
|
595
|
|
|
1
|
|
|
|
|
471
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(insert_riap_stuffs_to_res |
15
|
|
|
|
|
|
|
strip_riap_stuffs_from_res |
16
|
|
|
|
|
|
|
decode_args_in_riap_req); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub insert_riap_stuffs_to_res { |
19
|
10
|
|
|
10
|
1
|
927
|
my ($res, $def_ver, $nmeta) = @_; |
20
|
|
|
|
|
|
|
|
21
|
10
|
|
100
|
|
|
65
|
$res->[3]{'riap.v'} //= $def_ver // 1.1; |
|
|
|
66
|
|
|
|
|
22
|
10
|
100
|
|
|
|
23
|
if ($res->[3]{'riap.v'} >= 1.2) { |
23
|
|
|
|
|
|
|
# do we need to base64-encode? |
24
|
|
|
|
|
|
|
{ |
25
|
8
|
100
|
|
|
|
6
|
last if $res->[3]{'riap.result_encoding'}; |
|
8
|
|
|
|
|
17
|
|
26
|
7
|
100
|
|
|
|
11
|
if ($nmeta) { |
27
|
2
|
100
|
66
|
|
|
11
|
last unless $nmeta->{result}{schema} && |
28
|
|
|
|
|
|
|
$nmeta->{result}{schema}[0] eq 'buf'; |
29
|
|
|
|
|
|
|
} |
30
|
6
|
100
|
100
|
|
|
36
|
last unless defined($res->[2]) && !ref($res->[2]) && |
|
|
|
100
|
|
|
|
|
31
|
|
|
|
|
|
|
$res->[2] =~ /[^\x20-\x7f]/; |
32
|
2
|
|
|
|
|
13
|
$res->[2] = encode_base64($res->[2]); |
33
|
2
|
|
|
|
|
4
|
$res->[3]{'riap.result_encoding'} = 'base64'; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
10
|
|
|
|
|
55
|
$res; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub strip_riap_stuffs_from_res { |
40
|
6
|
|
|
6
|
1
|
2342
|
my $res = shift; |
41
|
|
|
|
|
|
|
|
42
|
6
|
|
50
|
|
|
19
|
my $ver = $res->[3]{'riap.v'} // 1.1; |
43
|
6
|
100
|
100
|
|
|
34
|
return [501, "Riap version returned by server ($ver) is not supported, ". |
44
|
|
|
|
|
|
|
"only recognize v1.1 and v1.2"] |
45
|
|
|
|
|
|
|
unless $ver == 1.1 || $ver == 1.2; |
46
|
|
|
|
|
|
|
|
47
|
5
|
100
|
|
|
|
10
|
if ($ver >= 1.2) { |
48
|
|
|
|
|
|
|
# check and strip riap.* |
49
|
3
|
|
|
|
|
5
|
for my $k (keys %{$res->[3]}) { |
|
3
|
|
|
|
|
10
|
|
50
|
5
|
50
|
|
|
|
13
|
next unless $k =~ /\Ariap\./; |
51
|
5
|
|
|
|
|
7
|
my $val = $res->[3]{$k}; |
52
|
5
|
100
|
|
|
|
13
|
if ($k eq 'riap.v') { |
|
|
100
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} elsif ($k eq 'riap.result_encoding') { |
54
|
2
|
100
|
|
|
|
10
|
return [501, "Unknown result_encoding returned by server ". |
55
|
|
|
|
|
|
|
"($val), only base64 is supported"] |
56
|
|
|
|
|
|
|
unless $val eq 'base64'; |
57
|
1
|
|
50
|
|
|
7
|
$res->[2] = decode_base64($res->[2]//''); |
58
|
|
|
|
|
|
|
} else { |
59
|
1
|
|
|
|
|
7
|
return [501, "Unknown Riap attribute in result metadata ". |
60
|
|
|
|
|
|
|
"returned by server ($k)"]; |
61
|
|
|
|
|
|
|
} |
62
|
3
|
|
|
|
|
7
|
delete $res->[3]{$k}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
3
|
|
|
|
|
13
|
$res; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub decode_args_in_riap_req { |
70
|
2
|
|
|
2
|
1
|
2523
|
my $req = shift; |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
100
|
|
|
11
|
my $v = $req->{v} // 1.1; |
73
|
2
|
100
|
|
|
|
26
|
if ($v >= 1.2) { |
74
|
1
|
50
|
|
|
|
3
|
if ($req->{args}) { |
75
|
1
|
|
|
|
|
2
|
my $args = $req->{args}; |
76
|
1
|
|
|
|
|
4
|
for (keys %$args) { |
77
|
2
|
100
|
|
|
|
7
|
next unless /\A(.+):base64\z/; |
78
|
1
|
|
|
|
|
6
|
$args->{$1} = decode_base64($args->{$_}); |
79
|
1
|
|
|
|
|
3
|
delete $args->{$_}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
2
|
|
|
|
|
12
|
$req; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
# ABSTRACT: Utility module for Riap client/server |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |