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