line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package SRS::EPP::Packets; |
3
|
|
|
|
|
|
|
{ |
4
|
|
|
|
|
|
|
$SRS::EPP::Packets::VERSION = '0.22'; |
5
|
|
|
|
|
|
|
} |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# encapsulate the packetization part of RFC3734 |
8
|
2
|
|
|
2
|
|
5012
|
use Moose; |
|
2
|
|
|
|
|
589744
|
|
|
2
|
|
|
|
|
20
|
|
9
|
2
|
|
|
2
|
|
16119
|
use MooseX::Params::Validate; |
|
2
|
|
|
|
|
16243
|
|
|
2
|
|
|
|
|
20
|
|
10
|
2
|
|
|
2
|
|
1071
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
237
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'MooseX::Log::Log4perl::Easy'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has input_state => |
15
|
|
|
|
|
|
|
is => "rw", |
16
|
|
|
|
|
|
|
default => "expect_length", |
17
|
|
|
|
|
|
|
; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has input_buffer => |
20
|
|
|
|
|
|
|
is => "ro", |
21
|
|
|
|
|
|
|
default => sub { [] }, |
22
|
|
|
|
|
|
|
; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
2
|
|
1319
|
use bytes; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
15
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub input_buffer_size { |
27
|
140
|
|
|
140
|
0
|
169
|
my $self = shift; |
28
|
|
|
|
|
|
|
|
29
|
140
|
|
|
|
|
194
|
my $size = 0; |
30
|
140
|
|
|
|
|
144
|
for ( @{ $self->input_buffer } ) { |
|
140
|
|
|
|
|
5047
|
|
31
|
249
|
|
|
|
|
427
|
$size += length $_; |
32
|
|
|
|
|
|
|
} |
33
|
140
|
|
|
|
|
531
|
$size; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub input_buffer_read { |
37
|
59
|
|
|
59
|
0
|
71
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
59
|
|
|
|
|
292
|
my ( $size ) = pos_validated_list( |
40
|
|
|
|
|
|
|
\@_, |
41
|
|
|
|
|
|
|
{ isa => 'Int' }, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
59
|
50
|
|
|
|
9925
|
croak '$size must be > 0' unless $size > 0; |
45
|
|
|
|
|
|
|
|
46
|
59
|
|
|
|
|
2379
|
my $buffer = $self->input_buffer; |
47
|
59
|
|
|
|
|
90
|
my @rv; |
48
|
59
|
|
66
|
|
|
301
|
while ( $size and @$buffer ) { |
49
|
89
|
|
|
|
|
152
|
my $chunk = shift @$buffer; |
50
|
89
|
100
|
|
|
|
170
|
if ( length $chunk > $size ) { |
51
|
50
|
|
|
|
|
114
|
push @rv, substr $chunk, 0, $size; |
52
|
50
|
|
|
|
|
103
|
unshift @$buffer, substr $chunk, $size; |
53
|
50
|
|
|
|
|
72
|
last; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
39
|
|
|
|
|
58
|
push @rv, $chunk; |
57
|
39
|
|
|
|
|
155
|
$size -= length $chunk; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
59
|
|
|
|
|
598
|
join "", @rv; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has 'input_expect' => |
64
|
|
|
|
|
|
|
is => "rw", |
65
|
|
|
|
|
|
|
isa => "Int", |
66
|
|
|
|
|
|
|
default => 4, |
67
|
|
|
|
|
|
|
; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
has 'session' => |
70
|
|
|
|
|
|
|
handles => [qw(input_packet read_input input_ready yield empty_read)], |
71
|
|
|
|
|
|
|
; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub input_event { |
74
|
40
|
|
|
40
|
0
|
4218
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
40
|
|
|
|
|
209
|
my ( $data ) = pos_validated_list( |
77
|
|
|
|
|
|
|
\@_, |
78
|
|
|
|
|
|
|
{ isa => 'Str', optional => 1 }, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
40
|
100
|
|
|
|
5009
|
$self->log_trace( |
82
|
|
|
|
|
|
|
"input event: " |
83
|
|
|
|
|
|
|
.(defined($data)?length($data)." byte(s)":"will read") |
84
|
|
|
|
|
|
|
); |
85
|
40
|
100
|
100
|
|
|
2720
|
if ( defined $data and $data ne "") { |
86
|
17
|
|
|
|
|
24
|
push @{ $self->input_buffer }, $data; |
|
17
|
|
|
|
|
768
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
40
|
|
|
|
|
96
|
my $ready = $self->input_buffer_size; |
91
|
40
|
|
|
|
|
1538
|
my $expected = $self->input_expect; |
92
|
|
|
|
|
|
|
|
93
|
40
|
100
|
|
|
|
168
|
if ( !defined $data ) { |
94
|
22
|
|
|
|
|
73
|
$data = $self->read_input($expected - $ready); |
95
|
22
|
50
|
|
|
|
3648
|
if ( defined $data ) { |
96
|
22
|
|
|
|
|
94
|
$self->log_trace( |
97
|
|
|
|
|
|
|
"input_event read ".length($data)." byte(s)" |
98
|
|
|
|
|
|
|
); |
99
|
22
|
50
|
|
|
|
1180
|
if ( length($data) == 0 ) { |
100
|
0
|
|
|
|
|
0
|
$self->empty_read; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else { |
103
|
22
|
|
|
|
|
24
|
push @{ $self->input_buffer }, $data; |
|
22
|
|
|
|
|
760
|
|
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
40
|
|
|
|
|
49
|
my $got_chunk; |
109
|
|
|
|
|
|
|
|
110
|
40
|
|
|
|
|
81
|
while ( $self->input_buffer_size >= $expected ) { |
111
|
60
|
100
|
|
|
|
197
|
my $data = $expected |
112
|
|
|
|
|
|
|
? $self->input_buffer_read($expected) |
113
|
|
|
|
|
|
|
: ""; |
114
|
60
|
100
|
|
|
|
2282
|
if ( $self->input_state eq "expect_length" ) { |
115
|
30
|
|
|
|
|
1100
|
$self->input_state("expect_data"); |
116
|
30
|
|
|
|
|
1175
|
$self->input_expect(unpack("N", $data)-4); |
117
|
30
|
|
|
|
|
1113
|
$self->log_trace( |
118
|
|
|
|
|
|
|
"expecting ".$self->input_expect." byte(s)" |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
30
|
|
|
|
|
89
|
$self->log_trace( |
123
|
|
|
|
|
|
|
"got complete packet, calling input_packet" |
124
|
|
|
|
|
|
|
); |
125
|
30
|
|
|
|
|
2531
|
$self->input_state("expect_length"); |
126
|
30
|
|
|
|
|
104
|
$self->input_packet($data); |
127
|
30
|
|
|
|
|
6189
|
$self->input_expect(4); |
128
|
30
|
|
|
|
|
95
|
$self->log_trace( |
129
|
|
|
|
|
|
|
"now expecting length packet" |
130
|
|
|
|
|
|
|
); |
131
|
|
|
|
|
|
|
} |
132
|
60
|
|
|
|
|
4932
|
$expected = $self->input_expect; |
133
|
60
|
|
|
|
|
169
|
$got_chunk = 1; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
40
|
50
|
|
|
|
123
|
if ( $self->input_ready ) { |
137
|
0
|
|
|
|
|
0
|
$self->log_trace( |
138
|
|
|
|
|
|
|
"done input_event, but more input ready - yielding input_event" |
139
|
|
|
|
|
|
|
); |
140
|
0
|
|
|
|
|
0
|
$self->yield("input_event"); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
40
|
|
|
|
|
5359
|
return $got_chunk; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |