HTTP2/Frame/Settings.pm

filter: Statementstmt 67.8% 38 / 56 Branchbran 54.5% 12 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 2 totaltotal 60.0% 57 / 95 CC 14 SCAR 23.9
CC
14
Cov
63%
decode
19.4
__ANON__
6.0
__ANON__
6.0
CRAP 10.9
« HTTP2/Frame.pm ↑ Summary HTTP2/Upgrade.pm »
1 package Protocol::HTTP2::Frame::Settings;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use Protocol::HTTP2::Constants qw(const_name :flags :errors :limits :settings);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Protocol::HTTP2::Trace qw(tracer);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 my %s_check = (
8 &SETTINGS_MAX_FRAME_SIZE => {
9 0 ▶ validator => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
10 0 ▶ $_[0] <= MAX_PAYLOAD_SIZE && $_[0] >= DEFAULT_MAX_FRAME_SIZE;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] <= 16777215 and $_[0] >= 16384 0 0 0
11 },
12 error => PROTOCOL_ERROR
13 },
14 &SETTINGS_ENABLE_PUSH => {
15 0 ▶ validator => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
16 0 ▶ $_[0] == 0 || $_[0] == 1;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 0 or $_[0] == 1 0 0 0
17 },
18 error => PROTOCOL_ERROR
19 },
20 &SETTINGS_INITIAL_WINDOW_SIZE => {
21 0 ▶ validator => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 $_[0] <= MAX_FCW_SIZE;
23 },
24 13 error => FLOW_CONTROL_ERROR
25 },
26 );
27  
28 my %s_action = (
29 0 ▶ &SETTINGS_INITIAL_WINDOW_SIZE => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 my ( $con, $size ) = @_;
31 0 $con->fcw_initial_change($size);
32 }
33 13 );
34  
35 70 ▶sub decode {
Subroutine decode: called CC=11 SCAR=29.7
Pod undocumented
36 70 my ( $con, $buf_ref, $buf_offset, $length ) = @_;
37 70 my $frame_ref = $con->decode_context->{frame};
38  
39 70 ▶ if ( $frame_ref->{stream} != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frame_ref->{"stream"} != 0) 0 70 70
40 0 $con->error(PROTOCOL_ERROR);
41 0 return undef;
42 }
43  
44 # just ack for our previous settings
45 70 ▶ if ( $frame_ref->{flags} & ACK ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($frame_ref->{'flags'} & 1) { } 34 36 70
elsif ($length == 0) { } 17 19 36
46 34 ▶ if ( $length != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length != 0) 0 34 34
47 0 tracer->error(
48 "ACK settings frame have non-zero ($length) payload\n");
49 0 $con->error(FRAME_SIZE_ERROR);
50 0 return undef;
51 }
52 34 return 0
53  
54 # received empty settings (default), accept it
55 }
56 elsif ( $length == 0 ) {
57 17 $con->accept_settings();
58 17 return 0;
59 }
60  
61 19 ▶ if ( $length % 6 != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length % 6 != 0) 0 19 19
62 0 tracer->error("Settings frame payload is broken (length $length)\n");
63 0 $con->error(FRAME_SIZE_ERROR);
64 0 return undef;
65 }
66  
67 19 my @settings = unpack( '(nN)*', substr( $$buf_ref, $buf_offset, $length ) );
68 19 ▶ while ( my ( $key, $value ) = splice @settings, 0, 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@settings, 0, 2)) 20 19 39
69 20 ▶ if ( !defined $con->enc_setting($key) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $con->enc_setting($key)) { } 0 20 20
elsif (exists $s_check{$key} and not $s_check{$key}{'validator'}->($value)) { } 0 40 40
70 0 tracer->debug("\tUnknown setting $key\n");
71  
72 # ignore unknown setting
73 0 next;
74 }
75 ▶ elsif ( exists $s_check{$key}
Condition33%1/3
exists $s_check{$key} and not $s_check{$key}{"validator"}->($value)
!ll&&!rl&&r
2000
MC/DC0%0/2
exists $s_check{$key} and not $s_check{$key}{"validator"}->($value)
exists $s_check{$key} not $s_check{$key}{"validator"}->($value)
Truth table33%1/3
A and not(B)
A= exists $s_check{$key}B= not $s_check{$key}{"validator"}->($value)
ABresult
0X0
100
111
76 && !$s_check{$key}{validator}->($value) )
77 {
78 0 tracer->debug( "\tInvalid value of setting "
79 . const_name( "settings", $key ) . ": "
80 . $value );
81 0 $con->error( $s_check{$key}{error} );
82 0 return undef;
83 }
84  
85 # Settings change may run some action
86 20 ▶ $s_action{$key}->( $con, $value ) if exists $s_action{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $s_action{$key} 0 20 20
87  
88 20 tracer->debug(
89 "\tSettings " . const_name( "settings", $key ) . " = $value\n" );
90 20 $con->enc_setting( $key, $value );
91 }
92  
93 19 $con->accept_settings();
94 19 return $length;
95 }
96  
97 76 ▶sub encode {
Subroutine encode: called CC=2 SCAR=6.9
Pod undocumented
98 76 my ( $con, $flags_ref, $stream, $data ) = @_;
99 76 my $payload = '';
100 76 for my $key ( sort keys %$data ) {
101 21 tracer->debug( "\tSettings "
102 . const_name( "settings", $key )
103 . " = $data->{$key}\n" );
104 21 $payload .= pack( 'nN', $key, $data->{$key} );
105 }
106 76 return $payload;
107 }
108  
109 13 1;
« HTTP2/Frame.pm ↑ Summary HTTP2/Upgrade.pm »