| 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | package SRS::EPP::Packets; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # encapsulate the packetization part of RFC3734 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use MooseX::Method::Signatures; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | with 'MooseX::Log::Log4perl::Easy'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | has input_state => | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | default => "expect_length", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | has input_buffer => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | is => "ro", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | method input_buffer_size() { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 140 | my $size = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 140 | for ( @{ $self->input_buffer } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 249 | $size += length $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 140 | $size; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | method input_buffer_read( Int $size where { $_ > 0 } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=4 SCAR=18.2
Subroutine
input_buffer_read: called CC=4 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my $buffer = $self->input_buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | while ( $size and @$buffer ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
$size and @$buffer
$size and @$buffer
MC/DC0%0/2
$size and @$buffer
$size
@$buffer
MC/DC50%1/2
$size and @$buffer
$size
@$buffer
Truth table0%0/3
A and B
A= $sizeB= @$buffer
Truth table66%2/3
A and B
A= $sizeB= @$buffer
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $chunk = shift @$buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ( length $chunk > $size ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | push @rv, substr $chunk, 0, $size; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | unshift @$buffer, substr $chunk, $size; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | push @rv, $chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $size -= length $chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | join "", @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | has 'input_expect' => | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | isa => "Int", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | default => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | has 'session' => | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | handles => [qw(input_packet read_input input_ready yield empty_read)], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | method input_event( Str $data? ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=10 SCAR=32.6
Subroutine
input_event: called CC=10 SCAR=32.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | $self->log_trace( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | "input event: " | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | .(defined($data)?length($data)." byte(s)":"will read") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( defined $data and $data ne "") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
defined $data and $data ne ""
defined $data and $data ne ""
MC/DC0%0/2
defined $data and $data ne ""
defined $data
$data ne ""
MC/DC100%2/2
defined $data and $data ne ""
defined $data
$data ne ""
Truth table0%0/3
A and B
A= defined $dataB= $data ne ""
Truth table100%3/3
A and B
A= defined $dataB= $data ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | push @{ $self->input_buffer }, $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $ready = $self->input_buffer_size; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $expected = $self->input_expect; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( !defined $data ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $data = $self->read_input($expected - $ready); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $self->log_trace( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | "input_event read ".length($data)." byte(s)" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ( length($data) == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $self->empty_read; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | push @{ $self->input_buffer }, $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $got_chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | while ( $self->input_buffer_size >= $expected ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my $data = $expected | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ? $self->input_buffer_read($expected) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | : ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( $self->input_state eq "expect_length" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $self->input_state("expect_data"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->input_expect(unpack("N", $data)-4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $self->log_trace( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | "expecting ".$self->input_expect." byte(s)" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $self->log_trace( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | "got complete packet, calling input_packet" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->input_state("expect_length"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $self->input_packet($data); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $self->input_expect(4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $self->log_trace( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | "now expecting length packet" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $expected = $self->input_expect; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $got_chunk = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ( $self->input_ready ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $self->log_trace( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | "done input_event, but more input ready - yielding input_event" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $self->yield("input_event"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | return $got_chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||