line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Saftpresse::Input::RELP::Frame; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use Moose; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.6'; # VERSION |
6
|
|
|
|
|
|
|
# ABSTRACT: class for parsing and generating RELP frames |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'txnr' => ( is => 'rw', isa => 'Int', required => 1 ); |
9
|
|
|
|
|
|
|
has 'command' => ( is => 'rw', isa => 'Str', required => 1 ); |
10
|
|
|
|
|
|
|
has 'data' => ( is => 'rw', isa => 'Str', default => '', |
11
|
|
|
|
|
|
|
traits => [ 'String' ], |
12
|
|
|
|
|
|
|
handles => { |
13
|
|
|
|
|
|
|
data_len => 'length', |
14
|
|
|
|
|
|
|
}, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub as_string { |
18
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
19
|
0
|
0
|
|
|
|
|
return join(' ', $self->txnr, $self->command, $self->data_len, |
20
|
|
|
|
|
|
|
$self->data_len ? $self->data : () )."\n"; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new_next_frame { |
24
|
0
|
|
|
0
|
0
|
|
my ( $class, $prev ) = ( shift, shift ); |
25
|
0
|
|
|
|
|
|
my $obj = $class->new( |
26
|
|
|
|
|
|
|
'txnr' => $prev->txnr, |
27
|
|
|
|
|
|
|
@_ |
28
|
|
|
|
|
|
|
); |
29
|
0
|
|
|
|
|
|
return $obj; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new_from_fh { |
33
|
0
|
|
|
0
|
0
|
|
my ( $class, $fh ) = ( shift, shift ); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
local $/ = ' '; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $txnr = $fh->getline; |
38
|
0
|
0
|
|
|
|
|
if( ! defined $txnr ) { |
39
|
0
|
|
|
|
|
|
return; # no more data? |
40
|
|
|
|
|
|
|
} |
41
|
0
|
0
|
|
|
|
|
if( $txnr !~ /^\d+ $/) { |
42
|
0
|
|
|
|
|
|
die('invalid txnr in RELP frame: '.$txnr); |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
chomp( $txnr ); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $command = $fh->getline; |
47
|
0
|
0
|
0
|
|
|
|
if( ! defined $command || $command !~ /^[a-zA-Z]+ $/) { |
48
|
0
|
|
|
|
|
|
die('invalid command in RELP frame: '.$command); |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
|
chomp( $command ); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $digit; |
53
|
|
|
|
|
|
|
my $data; |
54
|
0
|
0
|
|
|
|
|
if( ! $fh->read( $digit, 1 ) ) { |
55
|
0
|
|
|
|
|
|
die('error reading data_len'); |
56
|
|
|
|
|
|
|
} |
57
|
0
|
0
|
|
|
|
|
if( $digit !~ /\d/ ) { |
58
|
0
|
|
|
|
|
|
die('data_len in RELP is not numeric!'); |
59
|
|
|
|
|
|
|
} |
60
|
0
|
0
|
|
|
|
|
if( $digit eq '0' ) { |
61
|
0
|
|
|
|
|
|
$data = ''; |
62
|
|
|
|
|
|
|
} else { |
63
|
0
|
|
|
|
|
|
my $left_data_len = $fh->getline; |
64
|
0
|
0
|
|
|
|
|
if( ! defined $left_data_len ) { |
65
|
0
|
|
|
|
|
|
die('error reading more digits of data_len'); |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
chomp( $left_data_len ); |
68
|
0
|
|
|
|
|
|
my $data_len = int( $digit . $left_data_len ); |
69
|
0
|
0
|
0
|
|
|
|
if( ! $data_len || $data_len > 131072 ) { # 128k |
70
|
0
|
|
|
|
|
|
die('invalid data_len in RELP frame'); |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
$fh->read( $data, $data_len ); |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
my $trailer; |
75
|
0
|
|
|
|
|
|
$fh->read( $trailer, 1 ); |
76
|
0
|
0
|
0
|
|
|
|
if( ! defined $trailer || $trailer ne "\n" ) { |
77
|
0
|
|
|
|
|
|
die('no trailer (LF) present. possible framing error.'); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $obj = $class->new( |
81
|
|
|
|
|
|
|
'txnr' => $txnr, |
82
|
|
|
|
|
|
|
'command' => $command, |
83
|
|
|
|
|
|
|
'data' => $data, |
84
|
|
|
|
|
|
|
@_ |
85
|
|
|
|
|
|
|
); |
86
|
0
|
|
|
|
|
|
return $obj; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=encoding UTF-8 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Log::Saftpresse::Input::RELP::Frame - class for parsing and generating RELP frames |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 VERSION |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
version 1.6 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This is free software, licensed under: |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |