FastCGI/Protocol/PP.pm

filter: Statementstmt 100% 184 / 184 Branchbran 99.4% 167 / 168 Conditioncond 96.9% 96 / 99 MC/DCmcdc 89.0% 49 / 55 Subroutinesub 100% 34 / 34 Podpod 0.0% 0 / 29 totaltotal 93.1% 530 / 569 CC 121 SCAR 22.1
CC
121
Cov
99%
parse_record_body
27.0
build_stream
9.0
parse_params
9.0
CRAP 9.2
« FastCGI/Protocol.pm ↑ Summary FastCGI/Constant.pm »
1 package Net::FastCGI::Protocol::PP;
2 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 20 ▶use Carp qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use Net::FastCGI::Constant qw[:all];
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 20 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 our $VERSION = '0.14';
10 20 our @EXPORT_OK = qw[ build_begin_request
11 build_begin_request_body
12 build_begin_request_record
13 build_end_request
14 build_end_request_body
15 build_end_request_record
16 build_header
17 build_params
18 build_record
19 build_stream
20 build_unknown_type_body
21 build_unknown_type_record
22 check_params
23 parse_begin_request_body
24 parse_end_request_body
25 parse_header
26 parse_params
27 parse_record
28 parse_record_body
29 parse_unknown_type_body
30 is_known_type
31 is_management_type
32 is_discrete_type
33 is_stream_type
34 get_record_length
35 get_role_name
36 get_type_name
37 get_protocol_status_name ];
38  
39 20 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
40  
41 20 require Exporter;
42 20 *import = \&Exporter::import;
43 }
44  
45 sub TRUE () { !!1 }
46 sub FALSE () { !!0 }
47  
48 sub ERRMSG_OCTETS () { q/FastCGI: Insufficient number of octets to parse %s/ }
49 sub ERRMSG_MALFORMED () { q/FastCGI: Malformed record %s/ }
50 sub ERRMSG_VERSION () { q/FastCGI: Protocol version mismatch (0x%.2X)/ }
51 sub ERRMSG_OCTETS_LE () { q/Invalid Argument: '%s' cannot exceed %u octets in length/ }
52  
53 96 ▶sub throw {
Subroutine throw: called CC=2 SCAR=6.9
Pod undocumented
54 96 ▶ @_ = ( sprintf($_[0], @_[1..$#_]) ) if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 57 39 96
55 96 goto \&Carp::croak;
56 }
57  
58 # FCGI_Header
59  
60 110 ▶sub build_header {
Subroutine build_header: called CC=2 SCAR=6.9
Pod undocumented
61 110 ▶ @_ == 4 || throw(q/Usage: build_header(type, request_id, content_length, padding_length)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or throw("Usage: build_header(type, request_id, content_length, padding_length)") 109 1 110
62 109 return pack(FCGI_Header, FCGI_VERSION_1, @_);
63 }
64  
65 61 ▶sub parse_header {
Subroutine parse_header: called CC=6 SCAR=17.9
Pod undocumented
66 61 ▶ @_ == 1 || throw(q/Usage: parse_header(octets)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: parse_header(octets)") 60 1 61
67 60 ▶ (defined $_[0] && length $_[0] >= 8)
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and length $_[0] >= 8 or throw("FastCGI: Insufficient number of octets to parse %s", "FCGI_Header") 58 2 60
Condition100%3/3
defined $_[0] and length $_[0] >= 8
!ll&&!rl&&r
1158
MC/DC100%2/2
defined $_[0] and length $_[0] >= 8
defined $_[0] length $_[0] >= 8
Truth table100%3/3
A and B
A= defined $_[0]B= length $_[0] >= 8
ABresult
0X0
100
111
68 || throw(ERRMSG_OCTETS, q/FCGI_Header/);
69 58 ▶ (vec($_[0], 0, 8) == FCGI_VERSION_1)
Branch: 1 branch
BranchTrueFalseTotal
vec($_[0], 0, 8) == 1 or throw("FastCGI: Protocol version mismatch (0x%.2X)", unpack("C", $_[0])) 56 2 58
70 || throw(ERRMSG_VERSION, unpack('C', $_[0]));
71 56 ▶ return unpack('xCnnCx', $_[0])
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 54 2 56
72 if wantarray;
73 2 my %header;
74 2 @header{qw(type request_id content_length padding_length)}
75 = unpack('xCnnCx', $_[0]);
76 2 return \%header;
77 }
78  
79 # FCGI_BeginRequestBody
80  
81 17 ▶sub build_begin_request_body {
Subroutine build_begin_request_body: called CC=2 SCAR=6.9
Pod undocumented
82 17 ▶ @_ == 2 || throw(q/Usage: build_begin_request_body(role, flags)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or throw("Usage: build_begin_request_body(role, flags)") 16 1 17
83 16 return pack(FCGI_BeginRequestBody, @_);
84 }
85  
86 11 ▶sub parse_begin_request_body {
Subroutine parse_begin_request_body: called CC=4 SCAR=13.9
Pod undocumented
87 11 ▶ @_ == 1 || throw(q/Usage: parse_begin_request_body(octets)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: parse_begin_request_body(octets)") 10 1 11
88 10 ▶ (defined $_[0] && length $_[0] >= 8)
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and length $_[0] >= 8 or throw("FastCGI: Insufficient number of octets to parse %s", "FCGI_BeginRequestBody") 8 2 10
Condition100%3/3
defined $_[0] and length $_[0] >= 8
!ll&&!rl&&r
118
MC/DC100%2/2
defined $_[0] and length $_[0] >= 8
defined $_[0] length $_[0] >= 8
Truth table100%3/3
A and B
A= defined $_[0]B= length $_[0] >= 8
ABresult
0X0
100
111
89 || throw(ERRMSG_OCTETS, q/FCGI_BeginRequestBody/);
90 8 return unpack(FCGI_BeginRequestBody, $_[0]);
91 }
92  
93 # FCGI_EndRequestBody
94  
95 17 ▶sub build_end_request_body {
Subroutine build_end_request_body: called CC=2 SCAR=6.9
Pod undocumented
96 17 ▶ @_ == 2 || throw(q/Usage: build_end_request_body(app_status, protocol_status)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or throw("Usage: build_end_request_body(app_status, protocol_status)") 16 1 17
97 16 return pack(FCGI_EndRequestBody, @_);
98 }
99  
100 12 ▶sub parse_end_request_body {
Subroutine parse_end_request_body: called CC=4 SCAR=13.9
Pod undocumented
101 12 ▶ @_ == 1 || throw(q/Usage: parse_end_request_body(octets)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: parse_end_request_body(octets)") 11 1 12
102 11 ▶ (defined $_[0] && length $_[0] >= 8)
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and length $_[0] >= 8 or throw("FastCGI: Insufficient number of octets to parse %s", "FCGI_EndRequestBody") 9 2 11
Condition100%3/3
defined $_[0] and length $_[0] >= 8
!ll&&!rl&&r
119
MC/DC100%2/2
defined $_[0] and length $_[0] >= 8
defined $_[0] length $_[0] >= 8
Truth table100%3/3
A and B
A= defined $_[0]B= length $_[0] >= 8
ABresult
0X0
100
111
103 || throw(ERRMSG_OCTETS, q/FCGI_EndRequestBody/);
104 9 return unpack(FCGI_EndRequestBody, $_[0]);
105 }
106  
107 # FCGI_UnknownTypeBody
108  
109 17 ▶sub build_unknown_type_body {
Subroutine build_unknown_type_body: called CC=2 SCAR=6.9
Pod undocumented
110 17 ▶ @_ == 1 || throw(q/Usage: build_unknown_type_body(type)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: build_unknown_type_body(type)") 16 1 17
111 16 return pack(FCGI_UnknownTypeBody, @_);
112 }
113  
114 18 ▶sub parse_unknown_type_body {
Subroutine parse_unknown_type_body: called CC=4 SCAR=13.9
Pod undocumented
115 18 ▶ @_ == 1 || throw(q/Usage: parse_unknown_type_body(octets)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: parse_unknown_type_body(octets)") 17 1 18
116 17 ▶ (defined $_[0] && length $_[0] >= 8)
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and length $_[0] >= 8 or throw("FastCGI: Insufficient number of octets to parse %s", "FCGI_UnknownTypeBody") 15 2 17
Condition100%3/3
defined $_[0] and length $_[0] >= 8
!ll&&!rl&&r
1115
MC/DC100%2/2
defined $_[0] and length $_[0] >= 8
defined $_[0] length $_[0] >= 8
Truth table100%3/3
A and B
A= defined $_[0]B= length $_[0] >= 8
ABresult
0X0
100
111
117 || throw(ERRMSG_OCTETS, q/FCGI_UnknownTypeBody/);
118 15 return unpack(FCGI_UnknownTypeBody, $_[0]);
119 }
120  
121 # FCGI_BeginRequestRecord
122  
123 11 ▶sub build_begin_request_record {
Subroutine build_begin_request_record: called CC=2 SCAR=6.9
Pod undocumented
124 11 ▶ @_ == 3 || throw(q/Usage: build_begin_request_record(request_id, role, flags)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or throw("Usage: build_begin_request_record(request_id, role, flags)") 10 1 11
125 10 my ($request_id, $role, $flags) = @_;
126 10 return build_record(FCGI_BEGIN_REQUEST, $request_id,
127 build_begin_request_body($role, $flags));
128 }
129  
130 # FCGI_EndRequestRecord
131  
132 10 ▶sub build_end_request_record {
Subroutine build_end_request_record: called CC=2 SCAR=6.9
Pod undocumented
133 10 ▶ @_ == 3 || throw(q/Usage: build_end_request_record(request_id, app_status, protocol_status)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or throw("Usage: build_end_request_record(request_id, app_status, protocol_status)") 9 1 10
134 9 my ($request_id, $app_status, $protocol_status) = @_;
135 9 return build_record(FCGI_END_REQUEST, $request_id,
136 build_end_request_body($app_status, $protocol_status));
137 }
138  
139 # FCGI_UnknownTypeRecord
140  
141 3 ▶sub build_unknown_type_record {
Subroutine build_unknown_type_record: called CC=2 SCAR=6.9
Pod undocumented
142 3 ▶ @_ == 1 || throw(q/Usage: build_unknown_type_record(type)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: build_unknown_type_record(type)") 2 1 3
143 2 my ($type) = @_;
144 2 return build_record(FCGI_UNKNOWN_TYPE, FCGI_NULL_REQUEST_ID,
145 build_unknown_type_body($type));
146 }
147  
148 60 ▶sub build_record {
Subroutine build_record: called CC=7 SCAR=19.5
Pod undocumented
149 60 ▶ @_ == 2 || @_ == 3 || throw(q/Usage: build_record(type, request_id [, content])/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or @_ == 3 or throw("Usage: build_record(type, request_id [, content])") 57 3 60
Condition100%3/3
@_ == 2 or @_ == 3
l!l&&r!l&&!r
1563
MC/DC100%2/2
@_ == 2 or @_ == 3
@_ == 2 @_ == 3
Truth table100%3/3
A or B
A= @_ == 2B= @_ == 3
ABresult
1X1
011
000
150 57 my ($type, $request_id) = @_;
151  
152 57 ▶ my $content_length = defined $_[2] ? length $_[2] : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 54 3 57
153 57 my $padding_length = (8 - ($content_length % 8)) % 8;
154  
155 57 ▶ ($content_length <= FCGI_MAX_CONTENT_LEN)
Branch: 1 branch
BranchTrueFalseTotal
$content_length <= 65535 or throw("Invalid Argument: '%s' cannot exceed %u octets in length", "content", 65535) 56 1 57
156 || throw(ERRMSG_OCTETS_LE, q/content/, FCGI_MAX_CONTENT_LEN);
157  
158 56 my $res = build_header($type, $request_id, $content_length, $padding_length);
159  
160 56 ▶ if ($content_length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content_length) 43 13 56
161 43 $res .= $_[2];
162 }
163  
164 56 ▶ if ($padding_length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($padding_length) 8 48 56
165 8 $res .= "\x00" x $padding_length;
166 }
167  
168 56 return $res;
169 }
170  
171 53 ▶sub parse_record {
Subroutine parse_record: called CC=4 SCAR=13.9
Pod undocumented
172 53 ▶ @_ == 1 || throw(q/Usage: parse_record(octets)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: parse_record(octets)") 52 1 53
173 52 my ($type, $request_id, $content_length) = &parse_header;
174  
175 52 ▶ (length $_[0] >= FCGI_HEADER_LEN + $content_length)
Branch: 1 branch
BranchTrueFalseTotal
length $_[0] >= 8 + $content_length or throw("FastCGI: Insufficient number of octets to parse %s", "FCGI_Record") 52 0 52
176 || throw(ERRMSG_OCTETS, q/FCGI_Record/);
177  
178 return wantarray
179 52 ▶ ? ($type, $request_id, substr($_[0], FCGI_HEADER_LEN, $content_length))
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 19 33 52
180 : parse_record_body($type, $request_id,
181 substr($_[0], FCGI_HEADER_LEN, $content_length));
182 }
183  
184 64 ▶sub parse_record_body {
Subroutine parse_record_body: called CC=27 SCAR=33.0
Pod undocumented
185 64 ▶ @_ == 3 || throw(q/Usage: parse_record_body(type, request_id, content)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or throw("Usage: parse_record_body(type, request_id, content)") 62 2 64
186 62 my ($type, $request_id) = @_;
187  
188 62 ▶ my $content_length = defined $_[2] ? length $_[2] : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 60 2 62
189  
190 62 ▶ ($content_length <= FCGI_MAX_CONTENT_LEN)
Branch: 1 branch
BranchTrueFalseTotal
$content_length <= 65535 or throw("Invalid Argument: '%s' cannot exceed %u octets in length", "content", 65535) 49 13 62
191 || throw(ERRMSG_OCTETS_LE, q/content/, FCGI_MAX_CONTENT_LEN);
192  
193 49 my %record = (type => $type, request_id => $request_id);
194 49 ▶ if ($type == FCGI_BEGIN_REQUEST) {
Branch: 6 branches
BranchTrueFalseTotal
if ($type == 1) { } 5 44 49
elsif ($type == 2) { } 3 41 44
elsif ($type == 3) { } 5 36 41
elsif ($type == 4 or $type == 5 or $type == 6 or $type == 7 or $type == 8) { } 22 14 36
elsif ($type == 9 or $type == 10) { } 8 6 14
elsif ($type == 11) { } 4 2 6
195 5 ▶ ($request_id != FCGI_NULL_REQUEST_ID && $content_length == 8)
Branch: 1 branch
BranchTrueFalseTotal
$request_id != 0 and $content_length == 8 or throw("FastCGI: Malformed record %s", "FCGI_BeginRequestRecord") 2 3 5
Condition100%3/3
$request_id != 0 and $content_length == 8
!ll&&!rl&&r
212
MC/DC100%2/2
$request_id != 0 and $content_length == 8
$request_id != 0 $content_length == 8
Truth table100%3/3
A and B
A= $request_id != 0B= $content_length == 8
ABresult
0X0
100
111
196 || throw(ERRMSG_MALFORMED, q/FCGI_BeginRequestRecord/);
197 2 @record{ qw(role flags) } = parse_begin_request_body($_[2]);
198 }
199 elsif ($type == FCGI_ABORT_REQUEST) {
200 3 ▶ ($request_id != FCGI_NULL_REQUEST_ID && $content_length == 0)
Branch: 1 branch
BranchTrueFalseTotal
$request_id != 0 and $content_length == 0 or throw("FastCGI: Malformed record %s", "FCGI_AbortRequestRecord") 1 2 3
Condition100%3/3
$request_id != 0 and $content_length == 0
!ll&&!rl&&r
111
MC/DC100%2/2
$request_id != 0 and $content_length == 0
$request_id != 0 $content_length == 0
Truth table100%3/3
A and B
A= $request_id != 0B= $content_length == 0
ABresult
0X0
100
111
201 || throw(ERRMSG_MALFORMED, q/FCGI_AbortRequestRecord/);
202 }
203 elsif ($type == FCGI_END_REQUEST) {
204 5 ▶ ($request_id != FCGI_NULL_REQUEST_ID && $content_length == 8)
Branch: 1 branch
BranchTrueFalseTotal
$request_id != 0 and $content_length == 8 or throw("FastCGI: Malformed record %s", "FCGI_EndRequestRecord") 2 3 5
Condition100%3/3
$request_id != 0 and $content_length == 8
!ll&&!rl&&r
212
MC/DC100%2/2
$request_id != 0 and $content_length == 8
$request_id != 0 $content_length == 8
Truth table100%3/3
A and B
A= $request_id != 0B= $content_length == 8
ABresult
0X0
100
111
205 || throw(ERRMSG_MALFORMED, q/FCGI_EndRequestRecord/);
206 2 @record{ qw(app_status protocol_status) }
207 = parse_end_request_body($_[2]);
208 }
209 ▶ elsif ( $type == FCGI_PARAMS
Condition100%12/12
$type == 4 or $type == 5 or $type == 6 or $type == 7 or $type == 8
l!l&&r!l&&!r
18414
$type == 4 or $type == 5 or $type == 6 or $type == 7
l!l&&r!l&&!r
14418
$type == 4 or $type == 5 or $type == 6
l!l&&r!l&&!r
10422
$type == 4 or $type == 5
l!l&&r!l&&!r
5526
MC/DC100%5/5
$type == 4 or $type == 5 or $type == 6 or $type == 7 or $type == 8
$type == 4 $type == 5 $type == 6 $type == 7 $type == 8
Truth table100%6/6
A or B or C or D or E
A= $type == 4B= $type == 5C= $type == 6D= $type == 7E= $type == 8
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
210 || $type == FCGI_STDIN
211 || $type == FCGI_STDOUT
212 || $type == FCGI_STDERR
213 || $type == FCGI_DATA) {
214 22 ▶ ($request_id != FCGI_NULL_REQUEST_ID)
Branch: 1 branch
BranchTrueFalseTotal
$request_id != 0 or throw("FastCGI: Malformed record %s", $Net::FastCGI::Protocol::PP::FCGI_RECORD_NAME[$type]) 12 10 22
215 || throw(ERRMSG_MALFORMED, $FCGI_RECORD_NAME[$type]);
216 12 ▶ $record{content} = $content_length ? $_[2] : '';
Branch: 1 branch
BranchTrueFalseTotal
$content_length ? : 5 7 12
217 }
218 ▶ elsif ( $type == FCGI_GET_VALUES
Condition100%3/3
$type == 9 or $type == 10
l!l&&r!l&&!r
446
MC/DC100%2/2
$type == 9 or $type == 10
$type == 9 $type == 10
Truth table100%3/3
A or B
A= $type == 9B= $type == 10
ABresult
1X1
011
000
219 || $type == FCGI_GET_VALUES_RESULT) {
220 8 ▶ ($request_id == FCGI_NULL_REQUEST_ID)
Branch: 1 branch
BranchTrueFalseTotal
$request_id == 0 or throw("FastCGI: Malformed record %s", $Net::FastCGI::Protocol::PP::FCGI_RECORD_NAME[$type]) 4 4 8
221 || throw(ERRMSG_MALFORMED, $FCGI_RECORD_NAME[$type]);
222 4 $record{values} = parse_params($_[2]);
223 }
224 elsif ($type == FCGI_UNKNOWN_TYPE) {
225 4 ▶ ($request_id == FCGI_NULL_REQUEST_ID && $content_length == 8)
Branch: 1 branch
BranchTrueFalseTotal
$request_id == 0 and $content_length == 8 or throw("FastCGI: Malformed record %s", "FCGI_UnknownTypeRecord") 1 3 4
Condition100%3/3
$request_id == 0 and $content_length == 8
!ll&&!rl&&r
211
MC/DC100%2/2
$request_id == 0 and $content_length == 8
$request_id == 0 $content_length == 8
Truth table100%3/3
A and B
A= $request_id == 0B= $content_length == 8
ABresult
0X0
100
111
226 || throw(ERRMSG_MALFORMED, q/FCGI_UnknownTypeRecord/);
227 1 $record{unknown_type} = parse_unknown_type_body($_[2]);
228 }
229 else {
230 # unknown record type, pass content so caller can decide appropriate action
231 2 ▶ $record{content} = $_[2] if $content_length;
Branch: 1 branch
BranchTrueFalseTotal
if $content_length 1 1 2
232 }
233  
234 24 return \%record;
235 }
236  
237 # Reference implementation use 8192 (libfcgi)
238 sub FCGI_SEGMENT_LEN () { 32768 - FCGI_HEADER_LEN }
239  
240 37 ▶sub build_stream {
Subroutine build_stream: called CC=9 SCAR=22.0
Pod undocumented
241 37 ▶ @_ == 3 || @_ == 4 || throw(q/Usage: build_stream(type, request_id, content [, terminate])/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or @_ == 4 or throw("Usage: build_stream(type, request_id, content [, terminate])") 36 1 37
Condition100%3/3
@_ == 3 or @_ == 4
l!l&&r!l&&!r
2341
MC/DC100%2/2
@_ == 3 or @_ == 4
@_ == 3 @_ == 4
Truth table100%3/3
A or B
A= @_ == 3B= @_ == 4
ABresult
1X1
011
000
242 36 my ($type, $request_id, undef, $terminate) = @_;
243  
244 36 ▶ my $len = defined $_[2] ? length $_[2] : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 28 8 36
245 36 my $res = '';
246  
247 36 ▶ if ($len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len) 15 21 36
248 15 ▶ if ($len < FCGI_SEGMENT_LEN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len < 32760) { } 11 4 15
249 11 $res = build_record($type, $request_id, $_[2]);
250 }
251 else {
252 4 my $header = build_header($type, $request_id, FCGI_SEGMENT_LEN, 0);
253 4 my $off = 0;
254 4 ▶ while ($len >= FCGI_SEGMENT_LEN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len >= 32760) 4 4 8
255 4 $res .= $header;
256 4 $res .= substr($_[2], $off, FCGI_SEGMENT_LEN);
257 4 $len -= FCGI_SEGMENT_LEN;
258 4 $off += FCGI_SEGMENT_LEN;
259 }
260 4 ▶ if ($len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len) 2 2 4
261 2 $res .= build_record($type, $request_id, substr($_[2], $off, $len));
262 }
263 }
264 }
265  
266 36 ▶ if ($terminate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($terminate) 31 5 36
267 31 $res .= build_header($type, $request_id, 0, 0);
268 }
269  
270 36 return $res;
271 }
272  
273 31 ▶sub build_params {
Subroutine build_params: called CC=7 SCAR=19.5
Pod undocumented
274 31 ▶ @_ == 1 || throw(q/Usage: build_params(params)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: build_params(params)") 30 1 31
275 30 my ($params) = @_;
276 30 my $res = '';
277 30 ▶ while (my ($key, $val) = each(%$params)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$params) 25 30 55
278 25 for ($key, $val) {
279 50 ▶ my $len = defined $_ ? length : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 49 1 50
280 50 ▶ $res .= $len < 0x80 ? pack('C', $len) : pack('N', $len | 0x8000_0000);
Branch: 1 branch
BranchTrueFalseTotal
$len < 128 ? : 45 5 50
281 }
282 25 $res .= $key;
283 25 ▶ $res .= $val if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 24 1 25
284 }
285 30 return $res;
286 }
287  
288 17 ▶sub parse_params {
Subroutine parse_params: called CC=9 SCAR=22.0
Pod undocumented
289 17 ▶ @_ == 1 || throw(q/Usage: parse_params(octets)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: parse_params(octets)") 16 1 17
290 16 my ($octets) = @_;
291  
292 16 ▶ (defined $octets)
Branch: 1 branch
BranchTrueFalseTotal
defined $octets or return {} 15 1 16
293 || return +{};
294  
295 15 my ($params, $klen, $vlen) = ({}, 0, 0);
296 15 ▶ while (length $octets) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $octets) 20 7 27
297 20 for ($klen, $vlen) {
298 40 ▶ (1 <= length $octets)
Branch: 1 branch
BranchTrueFalseTotal
1 <= length $octets or throw("FastCGI: Insufficient number of octets to parse %s", "FCGI_NameValuePair") 38 2 40
299 || throw(ERRMSG_OCTETS, q/FCGI_NameValuePair/);
300 38 $_ = vec(substr($octets, 0, 1, ''), 0, 8);
301 38 ▶ next if $_ < 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $_ < 128 34 4 38
302 4 ▶ (3 <= length $octets)
Branch: 1 branch
BranchTrueFalseTotal
3 <= length $octets or throw("FastCGI: Insufficient number of octets to parse %s", "FCGI_NameValuePair") 2 2 4
303 || throw(ERRMSG_OCTETS, q/FCGI_NameValuePair/);
304 2 $_ = vec(pack('C', $_ & 0x7F) . substr($octets, 0, 3, ''), 0, 32);
305 }
306 16 ▶ ($klen + $vlen <= length $octets)
Branch: 1 branch
BranchTrueFalseTotal
$klen + $vlen <= length $octets or throw("FastCGI: Insufficient number of octets to parse %s", "FCGI_NameValuePair") 12 4 16
307 || throw(ERRMSG_OCTETS, q/FCGI_NameValuePair/);
308 12 my $key = substr($octets, 0, $klen, '');
309 12 $params->{$key} = substr($octets, 0, $vlen, '');
310 }
311 7 return $params;
312 }
313  
314 29 ▶sub check_params {
Subroutine check_params: called CC=9 SCAR=22.0
Pod undocumented
315 29 ▶ @_ == 1 || throw(q/Usage: check_params(octets)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: check_params(octets)") 28 1 29
316 28 ▶ (defined $_[0])
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] or 27 1 28
317 || return FALSE;
318  
319 27 my ($len, $off, $klen, $vlen) = (length $_[0], 0, 0, 0);
320 27 ▶ while ($off < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($off < $len) 28 16 44
321 28 for ($klen, $vlen) {
322 56 ▶ (($off += 1) <= $len)
Branch: 1 branch
BranchTrueFalseTotal
($off += 1) <= $len or 54 2 56
323 || return FALSE;
324 54 $_ = vec($_[0], $off - 1, 8);
325 54 ▶ next if $_ < 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $_ < 128 47 7 54
326 7 ▶ (($off += 3) <= $len)
Branch: 1 branch
BranchTrueFalseTotal
($off += 3) <= $len or 5 2 7
327 || return FALSE;
328 5 $_ = vec(substr($_[0], $off - 4, 4), 0, 32) & 0x7FFF_FFFF;
329 }
330 24 ▶ (($off += $klen + $vlen) <= $len)
Branch: 1 branch
BranchTrueFalseTotal
($off += $klen + $vlen) <= $len or 17 7 24
331 || return FALSE;
332 }
333 16 return TRUE;
334 }
335  
336 13 ▶sub build_begin_request {
Subroutine build_begin_request: called CC=5 SCAR=16.1
Pod undocumented
337 13 ▶ (@_ >= 4 && @_ <= 6) || throw(q/Usage: build_begin_request(request_id, role, flags, params [, stdin [, data]])/);
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 4 and @_ <= 6 or throw("Usage: build_begin_request(request_id, role, flags, params [, stdin [, data]])") 8 5 13
Condition100%3/3
@_ >= 4 and @_ <= 6
!ll&&!rl&&r
418
MC/DC100%2/2
@_ >= 4 and @_ <= 6
@_ >= 4 @_ <= 6
Truth table100%3/3
A and B
A= @_ >= 4B= @_ <= 6
ABresult
0X0
100
111
338 8 my ($request_id, $role, $flags, $params) = @_;
339  
340 8 my $r = build_begin_request_record($request_id, $role, $flags)
341 . build_stream(FCGI_PARAMS, $request_id, build_params($params), TRUE);
342  
343 8 ▶ if (@_ > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 4) 6 2 8
344 6 $r .= build_stream(FCGI_STDIN, $request_id, $_[4], TRUE);
345 6 ▶ if (@_ > 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 5) 3 3 6
346 3 $r .= build_stream(FCGI_DATA, $request_id, $_[5], TRUE);
347 }
348 }
349 8 return $r;
350 }
351  
352 11 ▶sub build_end_request {
Subroutine build_end_request: called CC=5 SCAR=16.1
Pod undocumented
353 11 ▶ (@_ >= 3 && @_ <= 5) || throw(q/Usage: build_end_request(request_id, app_status, protocol_status [, stdout [, stderr]])/);
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 3 and @_ <= 5 or throw("Usage: build_end_request(request_id, app_status, protocol_status [, stdout [, stderr]])") 7 4 11
Condition100%3/3
@_ >= 3 and @_ <= 5
!ll&&!rl&&r
317
MC/DC100%2/2
@_ >= 3 and @_ <= 5
@_ >= 3 @_ <= 5
Truth table100%3/3
A and B
A= @_ >= 3B= @_ <= 5
ABresult
0X0
100
111
354 7 my ($request_id, $app_status, $protocol_status) = @_;
355  
356 7 my $r;
357 7 ▶ if (@_ > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 3) 6 1 7
358 6 $r .= build_stream(FCGI_STDOUT, $request_id, $_[3], TRUE);
359 6 ▶ if (@_ > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 4) 3 3 6
360 3 $r .= build_stream(FCGI_STDERR, $request_id, $_[4], TRUE);
361 }
362 }
363 7 $r .= build_end_request_record($request_id, $app_status, $protocol_status);
364 7 return $r;
365 }
366  
367 21 ▶sub get_record_length {
Subroutine get_record_length: called CC=4 SCAR=13.9
Pod undocumented
368 21 ▶ @_ == 1 || throw(q/Usage: get_record_length(octets)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: get_record_length(octets)") 19 2 21
369 19 ▶ (defined $_[0] && length $_[0] >= FCGI_HEADER_LEN)
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and length $_[0] >= 8 or return 0 9 10 19
Condition100%3/3
defined $_[0] and length $_[0] >= 8
!ll&&!rl&&r
199
MC/DC100%2/2
defined $_[0] and length $_[0] >= 8
defined $_[0] length $_[0] >= 8
Truth table100%3/3
A and B
A= defined $_[0]B= length $_[0] >= 8
ABresult
0X0
100
111
370 || return 0;
371 9 return FCGI_HEADER_LEN + vec($_[0], 2, 16) # contentLength
372 + vec($_[0], 6, 8); # paddingLength
373 }
374  
375 16 ▶sub is_known_type {
Subroutine is_known_type: called CC=3 SCAR=11.0
Pod undocumented
376 16 ▶ @_ == 1 || throw(q/Usage: is_known_type(type)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: is_known_type(type)") 15 1 16
377 15 my ($type) = @_;
378 15 ▶ return ($type > 0 && $type <= FCGI_MAXTYPE);
Condition100%3/3
$type > 0 && $type <= 11
!ll&&!rl&&r
2112
MC/DC100%2/2
$type > 0 && $type <= 11
$type > 0 $type <= 11
Truth table100%3/3
A && B
A= $type > 0B= $type <= 11
ABresult
0X0
100
111
379 }
380  
381 15 ▶sub is_discrete_type {
Subroutine is_discrete_type: called CC=7 SCAR=19.5
Pod undocumented
382 15 ▶ @_ == 1 || throw(q/Usage: is_discrete_type(type)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: is_discrete_type(type)") 14 1 15
383 14 my ($type) = @_;
384 14 ▶ return ( $type == FCGI_BEGIN_REQUEST
Condition100%15/15
$type == 1 || $type == 2 || $type == 3 || $type == 9 || $type == 10 || $type == 11
l!l&&r!l&&!r
518
$type == 1 or $type == 2 or $type == 3 or $type == 9 or $type == 10
l!l&&r!l&&!r
419
$type == 1 or $type == 2 or $type == 3 or $type == 9
l!l&&r!l&&!r
3110
$type == 1 or $type == 2 or $type == 3
l!l&&r!l&&!r
2111
$type == 1 or $type == 2
l!l&&r!l&&!r
1112
MC/DC100%6/6
$type == 1 || $type == 2 || $type == 3 || $type == 9 || $type == 10 || $type == 11
$type == 1 $type == 2 $type == 3 $type == 9 $type == 10 $type == 11
Truth table100%7/7
A or B or C or D or E || F
A= $type == 1B= $type == 2C= $type == 3D= $type == 9E= $type == 10F= $type == 11
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
385 || $type == FCGI_ABORT_REQUEST
386 || $type == FCGI_END_REQUEST
387 || $type == FCGI_GET_VALUES
388 || $type == FCGI_GET_VALUES_RESULT
389 || $type == FCGI_UNKNOWN_TYPE );
390 }
391  
392 7 ▶sub is_management_type {
Subroutine is_management_type: called CC=4 SCAR=13.9
Pod undocumented
393 7 ▶ @_ == 1 || throw(q/Usage: is_management_type(type)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: is_management_type(type)") 6 1 7
394 6 my ($type) = @_;
395 6 ▶ return ( $type == FCGI_GET_VALUES
Condition100%6/6
$type == 9 || $type == 10 || $type == 11
l!l&&r!l&&!r
213
$type == 9 or $type == 10
l!l&&r!l&&!r
114
MC/DC100%3/3
$type == 9 || $type == 10 || $type == 11
$type == 9 $type == 10 $type == 11
Truth table100%4/4
A or B || C
A= $type == 9B= $type == 10C= $type == 11
ABCresult
1XX1
01X1
0011
0000
396 || $type == FCGI_GET_VALUES_RESULT
397 || $type == FCGI_UNKNOWN_TYPE );
398 }
399  
400 15 ▶sub is_stream_type {
Subroutine is_stream_type: called CC=6 SCAR=17.9
Pod undocumented
401 15 ▶ @_ == 1 || throw(q/Usage: is_stream_type(type)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: is_stream_type(type)") 14 1 15
402 14 my ($type) = @_;
403 14 ▶ return ( $type == FCGI_PARAMS
Condition100%12/12
$type == 4 || $type == 5 || $type == 6 || $type == 7 || $type == 8
l!l&&r!l&&!r
419
$type == 4 or $type == 5 or $type == 6 or $type == 7
l!l&&r!l&&!r
3110
$type == 4 or $type == 5 or $type == 6
l!l&&r!l&&!r
2111
$type == 4 or $type == 5
l!l&&r!l&&!r
1112
MC/DC100%5/5
$type == 4 || $type == 5 || $type == 6 || $type == 7 || $type == 8
$type == 4 $type == 5 $type == 6 $type == 7 $type == 8
Truth table100%6/6
A or B or C or D || E
A= $type == 4B= $type == 5C= $type == 6D= $type == 7E= $type == 8
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
404 || $type == FCGI_STDIN
405 || $type == FCGI_STDOUT
406 || $type == FCGI_STDERR
407 || $type == FCGI_DATA );
408 }
409  
410 89 ▶sub get_type_name {
Subroutine get_type_name: called CC=3 SCAR=11.0
Pod undocumented
411 89 ▶ @_ == 1 || throw(q/Usage: get_type_name(type)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: get_type_name(type)") 88 1 89
412 88 my ($type) = @_;
413 88 ▶ return $FCGI_TYPE_NAME[$type] || sprintf('0x%.2X', $type);
Condition66%2/3
$Net::FastCGI::Protocol::PP::FCGI_TYPE_NAME[$type] || sprintf('0x%.2X', $type)
l!l&&r!l&&!r
8260
MC/DC0%0/2
$Net::FastCGI::Protocol::PP::FCGI_TYPE_NAME[$type] || sprintf('0x%.2X', $type)
$Net::FastCGI::Protocol::PP::FCGI_TYPE_NAME[$type] sprintf('0x%.2X', $type)
Truth table66%2/3
A || B
A= $Net::FastCGI::Protocol::PP::FCGI_TYPE_NAME[$type]B= sprintf('0x%.2X', $type)
ABresult
1X1
011
000
414 }
415  
416 11 ▶sub get_role_name {
Subroutine get_role_name: called CC=3 SCAR=11.0
Pod undocumented
417 11 ▶ @_ == 1 || throw(q/Usage: get_role_name(role)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: get_role_name(role)") 10 1 11
418 10 my ($role) = @_;
419 10 ▶ return $FCGI_ROLE_NAME[$role] || sprintf('0x%.4X', $role);
Condition66%2/3
$Net::FastCGI::Protocol::PP::FCGI_ROLE_NAME[$role] || sprintf('0x%.4X', $role)
l!l&&r!l&&!r
640
MC/DC0%0/2
$Net::FastCGI::Protocol::PP::FCGI_ROLE_NAME[$role] || sprintf('0x%.4X', $role)
$Net::FastCGI::Protocol::PP::FCGI_ROLE_NAME[$role] sprintf('0x%.4X', $role)
Truth table66%2/3
A || B
A= $Net::FastCGI::Protocol::PP::FCGI_ROLE_NAME[$role]B= sprintf('0x%.4X', $role)
ABresult
1X1
011
000
420 }
421  
422 11 ▶sub get_protocol_status_name {
Subroutine get_protocol_status_name: called CC=3 SCAR=11.0
Pod undocumented
423 11 ▶ @_ == 1 || throw(q/Usage: get_protocol_status_name(protocol_status)/);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or throw("Usage: get_protocol_status_name(protocol_status)") 10 1 11
424 10 my ($status) = @_;
425 10 ▶ return $FCGI_PROTOCOL_STATUS_NAME[$status] || sprintf('0x%.2X', $status);
Condition66%2/3
$Net::FastCGI::Protocol::PP::FCGI_PROTOCOL_STATUS_NAME[$status] || sprintf('0x%.2X', $status)
l!l&&r!l&&!r
820
MC/DC0%0/2
$Net::FastCGI::Protocol::PP::FCGI_PROTOCOL_STATUS_NAME[$status] || sprintf('0x%.2X', $status)
$Net::FastCGI::Protocol::PP::FCGI_PROTOCOL_STATUS_NAME[$status] sprintf('0x%.2X', $status)
Truth table66%2/3
A || B
A= $Net::FastCGI::Protocol::PP::FCGI_PROTOCOL_STATUS_NAME[$status]B= sprintf('0x%.2X', $status)
ABresult
1X1
011
000
426 }
427  
428 20 1;
429  
« FastCGI/Protocol.pm ↑ Summary FastCGI/Constant.pm »