| 1 | package Linux::Event::WebSocket::_Frame; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use utf8 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Linux::Event::WebSocket::_Random; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Linux::Event::WebSocket::_UTF8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | my %OPCODE = ( | |||||||||||||||||||||||||||||||||||||||||
| 13 | continuation => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 14 | text => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 15 | binary => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | close => 8, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ping => 9, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | pong => 10, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 10 | my %TYPE = reverse %OPCODE; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 10 | my %CLOSE_CODE = ( | |||||||||||||||||||||||||||||||||||||||||
| 23 | SUCCESS => 1000, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ENDPOINT_UNAVAILABLE => 1001, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | PROTOCOL_ERROR => 1002, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | INVALID_DATA_TYPE => 1003, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | INVALID_PAYLOAD => 1007, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | POLICY_VIOLATION => 1008, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | MESSAGE_TOO_BIG => 1009, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | UNSUPPORTED_EXTENSIONS => 1010, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | INTERNAL_ERROR => 1011, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | SERVER_ERROR => 1011, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | SERVICE_RESTART => 1012, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | TRY_AGAIN_LATER => 1013, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | BAD_GATEWAY => 1014, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 297 | ▶ | sub type ($class, $opcode) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 297 | return $TYPE{$opcode}; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub opcode ($class, $type) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opcode: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return $OPCODE{$type}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 172 | ▶ | sub mask ($class, $payload, $key) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mask: called CC=5 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 172 | ▶ | croak 'mask(): key must contain exactly four bytes' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $key or ref $key or length $key != 4
not defined $key or ref $key
MC/DC0%0/3
not defined $key or ref $key or length $key != 4
not defined $key
ref $key
length $key != 4
Truth table25%1/4
not(A) or B or C
A= not defined $keyB= ref $keyC= length $key != 4
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | if !defined($key) || ref($key) || length($key) != 4; | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 172 | ▶ | return '' if !length $payload; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 172 | my $mask = $key x (int(length($payload) / 4) + 1); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 172 | substr($mask, length($payload)) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 172 | return $payload ^. $mask; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub _mask_data ($payload, $key) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mask_data: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return '' if !length $payload; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $mask = $key x (int(length($payload) / 4) + 1); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | substr($mask, length($payload)) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return $payload ^. $mask; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub encode_data ($class, $opcode, $bytes, $masked) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_data: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $length = length $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $mask_bit = $masked ? 0x80 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $header; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ($length < 126) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $header = pack('CC', 0x80 | $opcode, $mask_bit | $length); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } elsif ($length < 65_536) { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $header = pack('CCn', 0x80 | $opcode, $mask_bit | 126, $length); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $high = int($length / 4_294_967_296); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $low = $length % 4_294_967_296; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $header = pack( | |||||||||||||||||||||||||||||||||||||||||
| 75 | 'CCNN', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0x80 | $opcode, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | $mask_bit | 127, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | $high, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | $low, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | return $header . $bytes if !$masked; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $mask = Linux::Event::WebSocket::_Random->mask_key; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | return $header . $mask . _mask_data($bytes, $mask); | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 42 | ▶ | sub encode ($class, $type, $payload, %option) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=23 SCAR=35.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | croak "encode(): unknown frame type '$type'" | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 42 | ▶ | if !defined($type) || ref($type) || !exists $OPCODE{$type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $type or ref $type or not exists $OPCODE{$type}
not defined $type or ref $type
MC/DC0%0/3
not defined $type or ref $type or not exists $OPCODE{$type}
not defined $type
ref $type
not exists $OPCODE{$type}
Truth table25%1/4
not(A) or B or not(C)
A= not defined $typeB= ref $typeC= not exists $OPCODE{$type}
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 42 | ▶ | croak 'encode(): payload must be a defined scalar' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $payload or ref $payload
MC/DC0%0/2
not defined $payload or ref $payload
not defined $payload
ref $payload
Truth table33%1/3
not(A) or B
A= not defined $payloadB= ref $payload
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | if !defined($payload) || ref($payload); | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 42 | my $bytes = "$payload"; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 42 | ▶ | croak 'encode(): payload must contain bytes' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | if !utf8::downgrade($bytes, 1); | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 42 | ▶ | my $fin = exists($option{fin}) ? delete($option{fin}) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 42 | ▶ | my $masked = delete($option{masked}) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 42 | my $mask_key = delete $option{mask_key}; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 42 | ▶ | croak 'encode(): mask_key requires masked output' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $mask_key and not $masked
MC/DC0%0/2
defined $mask_key and not $masked
defined $mask_key
not $masked
Truth table66%2/3
A and not(B)
A= defined $mask_keyB= not $masked
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | if defined($mask_key) && !$masked; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 42 | ▶ | croak 'encode(): unknown option(s): ' . join(', ', sort keys %option) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | if %option; | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 42 | my $opcode = $OPCODE{$type}; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 42 | my $control = $opcode >= 8; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 42 | ▶ | croak 'encode(): control frames must be final' if $control && !$fin; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$control and not $fin
MC/DC0%0/2
$control and not $fin
$control
not $fin
Truth table66%2/3
A and not(B)
A= $controlB= not $fin
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 42 | ▶ | croak 'encode(): control frame payload exceeds 125 bytes' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$control and length $bytes > 125
MC/DC0%0/2
$control and length $bytes > 125
$control
length $bytes > 125
Truth table66%2/3
A and B
A= $controlB= length $bytes > 125
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | if $control && length($bytes) > 125; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 42 | my $length = length $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 42 | my ($length_code, $extended); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 42 | ▶ | if ($length < 126) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 41 | $length_code = $length; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 41 | $extended = ''; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } elsif ($length < 65_536) { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | $length_code = 126; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | $extended = pack('n', $length); | |||||||||||||||||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $length_code = 127; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $high = int($length / 4_294_967_296); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $low = $length % 4_294_967_296; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $extended = pack('NN', $high, $low); | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 42 | ▶ | my $first = $opcode | ($fin ? 0x80 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 42 | ▶ | my $second = $length_code | ($masked ? 0x80 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 42 | my $mask = ''; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 42 | ▶ | if ($masked) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 36 | ▶ | $mask = defined($mask_key) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | ? "$mask_key" | ||||||||||||||||||||||||||||||||||||||||||
| 134 | : Linux::Event::WebSocket::_Random->bytes(4); | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 36 | ▶ | croak 'encode(): mask_key must contain exactly four bytes' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | if length($mask) != 4; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 36 | $bytes = $class->mask($bytes, $mask); | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 42 | return chr($first) . chr($second) . $extended . $mask . $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 34 | ▶ | sub valid_close_code ($class, $code) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
valid_close_code: called CC=3 SCAR=16.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 34 | ▶ | return 1 if grep { $_ == $code } values %CLOSE_CODE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | return $code >= 3000 && $code < 5000; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$code >= 3000 && $code < 5000
MC/DC0%0/2
$code >= 3000 && $code < 5000
$code >= 3000
$code < 5000
Truth table0%0/3
A && B
A= $code >= 3000B= $code < 5000
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 8 | ▶ | sub close_code ($class, $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close_code: called CC=6 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 8 | ▶ | croak 'close code is required' if !defined($value) || ref($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $value or ref $value
MC/DC0%0/2
not defined $value or ref $value
not defined $value
ref $value
Truth table33%1/3
not(A) or B
A= not defined $valueB= ref $value
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 8 | ▶ | return $CLOSE_CODE{$value} if exists $CLOSE_CODE{$value}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 8 | ▶ | croak "invalid WebSocket close code '$value'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
"$value" =~ /\A[0-9]+\z/u and $class->valid_close_code(0 + $value)
MC/DC0%0/2
"$value" =~ /\A[0-9]+\z/u and $class->valid_close_code(0 + $value)
"$value" =~ /\A[0-9]+\z/u
$class->valid_close_code(0 + $value)
Truth table33%1/3
A and B
A= "$value" =~ /\A[0-9]+\z/uB= $class->valid_close_code(0 + $value)
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | if "$value" !~ /\A[0-9]+\z/ || !$class->valid_close_code(0 + $value); | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 8 | return 0 + $value; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | ▶ | sub close_payload ($class, $code, $reason = '') { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close_payload: called CC=10 SCAR=26.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | ▶ | croak 'close reason must be a defined scalar' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $reason or ref $reason
MC/DC0%0/2
not defined $reason or ref $reason
not defined $reason
ref $reason
Truth table33%1/3
not(A) or B
A= not defined $reasonB= ref $reason
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | if !defined($reason) || ref($reason); | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | ▶ | croak 'close reason requires a close code' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $code and length $reason
MC/DC0%0/2
not defined $code and length $reason
not defined $code
length $reason
Truth table33%1/3
not(A) and B
A= not defined $codeB= length $reason
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | if !defined($code) && length($reason); | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | ▶ | return '' if !defined $code; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | my $number = $class->close_code($code); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | my $bytes = "$reason"; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | ▶ | croak 'close reason must contain UTF-8 bytes' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | if !utf8::downgrade($bytes, 1); | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | ▶ | croak 'close reason exceeds 123 bytes' if length($bytes) > 123; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | ▶ | eval { Linux::Event::WebSocket::_UTF8->validate_bytes($bytes); 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | or croak 'close reason contains invalid UTF-8'; | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | return pack('n', $number) . $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 26 | ▶ | sub parse_close_payload ($class, $payload) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_close_payload: called CC=5 SCAR=16.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 26 | my $length = length $payload; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 26 | ▶ | die "WebSocket close frame has a one-byte payload\n" if $length == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 26 | ▶ | return (undef, '') if !$length; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 26 | my ($code, $reason) = unpack('na*', $payload); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 26 | ▶ | die "WebSocket close frame contains invalid status code $code\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | if !$class->valid_close_code($code); | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 26 | ▶ | eval { Linux::Event::WebSocket::_UTF8->validate_bytes($reason); 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | or die "WebSocket close frame contains invalid UTF-8 reason\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 26 | return ($code, $reason); | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||