| 1 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | no if $] >= 5.017011, warnings => 'experimental::smartmatch'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||
| 5 | package Net::IMP::Filter; | ||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Net::IMP; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Net::IMP::Debug; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Hash::Util 'lock_ref_keys'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||
| 12 | ############################################################################ | ||||||||||||||||||||||||||||||||||||||||
| 13 | # these need to be redefined in subclass | ||||||||||||||||||||||||||||||||||||||||
| 14 | ############################################################################ | ||||||||||||||||||||||||||||||||||||||||
| 15 | # analyzed data output | ||||||||||||||||||||||||||||||||||||||||
| 16 | sub out { | ||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | my ($self,$dir,$data) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
out: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||
| 21 | sub deny { | ||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my ($self,$msg,$dir,@extmsg) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
deny: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | while (@extmsg) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my ($k,$v) = splice(@extmsg,0,2); | |||||||||||||||||||||||||||||||||||||||
| 25 | 0 | $msg .= " $k:$v"; | |||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $DEBUG && debug("deny $msg"); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||
| 31 | sub fatal { | ||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my ($self,$msg) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
fatal: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $DEBUG && debug("fatal $msg"); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||
| 37 | sub log { | ||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | my ($self,$level,$msg,$dir,$offset,$len,@extmsg) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | while (@extmsg) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my ($k,$v) = splice(@extmsg,0,2); | |||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $msg .= " $k:$v"; | |||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | $DEBUG && debug("log [$level] $msg"); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||
| 47 | sub acctfld { | ||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my ($self,$key,$value) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
acctfld: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $DEBUG && debug("acctfld $key=$value"); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||
| 53 | ############################################################################ | ||||||||||||||||||||||||||||||||||||||||
| 54 | # Implementation | ||||||||||||||||||||||||||||||||||||||||
| 55 | ############################################################################ | ||||||||||||||||||||||||||||||||||||||||
| 56 | sub new { | ||||||||||||||||||||||||||||||||||||||||
| 57 | 10 | ▶ | my ($class,$imp,%args) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 58 | 10 | ▶ | my $self = lock_ref_keys( bless { | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||
| 59 | %args, | ||||||||||||||||||||||||||||||||||||||||
| 60 | imp => $imp, # analyzer object | ||||||||||||||||||||||||||||||||||||||||
| 61 | buf => [ | ||||||||||||||||||||||||||||||||||||||||
| 62 | # list of buffered data [ offset,buf,type ] per dir | ||||||||||||||||||||||||||||||||||||||||
| 63 | # buffers for same streaming type will be concatenated | ||||||||||||||||||||||||||||||||||||||||
| 64 | [ [0,'',0] ], | ||||||||||||||||||||||||||||||||||||||||
| 65 | [ [0,'',0] ], | ||||||||||||||||||||||||||||||||||||||||
| 66 | ], | ||||||||||||||||||||||||||||||||||||||||
| 67 | pass => [0,0], # may pass up to this offset | ||||||||||||||||||||||||||||||||||||||||
| 68 | prepass => [0,0], # may prepass up to this offset | ||||||||||||||||||||||||||||||||||||||||
| 69 | skipped => [0,0], # flag if last data got not send to analyzer | ||||||||||||||||||||||||||||||||||||||||
| 70 | # because of pass into future | ||||||||||||||||||||||||||||||||||||||||
| 71 | eof => [0,0], # flag if eof received | ||||||||||||||||||||||||||||||||||||||||
| 72 | dead => 0, # set if deny|fatal received | ||||||||||||||||||||||||||||||||||||||||
| 73 | },(ref $class || $class) ); | ||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||
| 75 | 10 | ▶ | if ($imp) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 76 | 10 | weaken( my $weak = $self ); | |||||||||||||||||||||||||||||||||||||||
| 77 | 10 | $imp->set_callback(\&_imp_cb,$weak); | |||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||
| 79 | 10 | return $self; | |||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||
| 82 | # data into analyzer | ||||||||||||||||||||||||||||||||||||||||
| 83 | sub in { | ||||||||||||||||||||||||||||||||||||||||
| 84 | 25 | ▶ | my ($self,$dir,$data,$type) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
in: called CC=27 SCAR=55.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 85 | 25 | ▶ | $self->{dead} and return; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||
| 87 | 25 | ▶ | $type ||= IMP_DATA_STREAM; | ||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$type ||= "imp.data.stream"
MC/DC100%1/1
$type ||= "imp.data.stream"
$type
Truth table100%2/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||
| 88 | 25 | ▶ | $DEBUG && debug("in($dir,$type) %d bytes",length($data)); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||
| 90 | 25 | ▶ | $self->{eof}[$dir] = 1 if $data eq ''; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 91 | 25 | ▶ | return $self->out($dir,$data,$type) if ! $self->{imp}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||
| 93 | 25 | my $buf = $self->{buf}[$dir]; | |||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||
| 95 | # (pre)pass as much as possible | ||||||||||||||||||||||||||||||||||||||||
| 96 | 25 | for my $w (qw(pass prepass)) { | |||||||||||||||||||||||||||||||||||||||
| 97 | 50 | ▶ | my $maxoff = $self->{$w}[$dir] or next; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | @$buf == 1 and ! $buf->[0][2] or die "buf should be empty"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$buf == 1 and not $buf->[0][2]
MC/DC0%0/2
@$buf == 1 and not $buf->[0][2]
@$buf == 1
not $buf->[0][2]
Truth table0%0/3
A and not(B)
A= @$buf == 1B= not $buf->[0][2]
| |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( $maxoff == IMP_MAXOFFSET | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$maxoff == -1 or $maxoff > $buf->[-1][0] + length($data)
MC/DC0%0/2
$maxoff == -1 or $maxoff > $buf->[-1][0] + length($data)
$maxoff == -1
$maxoff > $buf->[-1][0] + length($data)
Truth table0%0/3
A or B
A= $maxoff == -1B= $maxoff > $buf->[-1][0] + length($data)
| |||||||||||||||||||||||||||||||||||||||||
| 100 | or $maxoff > $buf->[-1][0] + length($data) ) { | ||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $DEBUG && debug("can $w everything"); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $lastoff = $self->{skipped}[$dir] && $buf->[0][0]; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'skipped'}[$dir] && $buf->[0][0]
MC/DC0%0/2
$self->{'skipped'}[$dir] && $buf->[0][0]
$self->{'skipped'}[$dir]
$buf->[0][0]
Truth table0%0/3
A && B
A= $self->{'skipped'}[$dir]B= $buf->[0][0]
| |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $buf->[0][0] += length($data); | |||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $self->out($dir,$data,$type); | |||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($w eq 'prepass') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $self->{imp}->data($dir,$data,$lastoff,$type); | |||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $self->{skipped}[$dir] = 0; | |||||||||||||||||||||||||||||||||||||||
| 108 | ▶ | } elsif ( $data eq '' and $maxoff != IMP_MAXOFFSET ) { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$data eq "" and $maxoff != -1
MC/DC0%0/2
$data eq "" and $maxoff != -1
$data eq ""
$maxoff != -1
Truth table0%0/3
A and B
A= $data eq ""B= $maxoff != -1
| |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $self->{imp}->data($dir,$data,$lastoff,$type); | |||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $self->{skipped}[$dir] = 0; | |||||||||||||||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $self->{skipped}[$dir] = 1; | |||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $canfw = $maxoff - $buf->[-1][0]; | |||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if ( $type > 0 and $canfw != length($data)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type > 0 and $canfw != length $data
MC/DC0%0/2
$type > 0 and $canfw != length $data
$type > 0
$canfw != length $data
Truth table0%0/3
A and B
A= $type > 0B= $canfw != length $data
| |||||||||||||||||||||||||||||||||||||||||
| 119 | # packet types need to be handled as a single piece | ||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | debug("partial $w for $type ignored"); | |||||||||||||||||||||||||||||||||||||||
| 121 | 0 | next; | |||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $DEBUG && debug("can $w %d bytes of %d", $canfw, length($data)); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $fwd = substr($data,0,$canfw,''); | |||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my $lastoff = $self->{skipped}[$dir] && $buf->[0][0]; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'skipped'}[$dir] && $buf->[0][0]
MC/DC0%0/2
$self->{'skipped'}[$dir] && $buf->[0][0]
$self->{'skipped'}[$dir]
$buf->[0][0]
Truth table0%0/3
A && B
A= $self->{'skipped'}[$dir]B= $buf->[0][0]
| |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $buf->[0][0] += length($fwd); | |||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $self->{$w}[$dir] = 0; # no more (pre)pass | |||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $self->out($dir,$fwd,$type); | |||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ($w eq 'prepass') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $self->{imp}->data($dir,$fwd,$lastoff,$type); | |||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->{skipped}[$dir] = 0; | |||||||||||||||||||||||||||||||||||||||
| 133 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $self->{skipped}[$dir] = 1; | |||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||
| 138 | # data left which need to be forwarded to analyzer | ||||||||||||||||||||||||||||||||||||||||
| 139 | 25 | ▶ | if ( ! $buf->[-1][2] ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 140 | # replace empty (untyped) buffer with new data | ||||||||||||||||||||||||||||||||||||||||
| 141 | 12 | $buf->[-1][1] = $data; | |||||||||||||||||||||||||||||||||||||||
| 142 | 12 | $buf->[-1][2] = $type; | |||||||||||||||||||||||||||||||||||||||
| 143 | ▶ | } elsif ( $type < 0 and $buf->[-1][2] == $type ) { | |||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$type < 0 and $buf->[-1][2] == $type
MC/DC50%1/2
$type < 0 and $buf->[-1][2] == $type
$type < 0
$buf->[-1][2] == $type
Truth table66%2/3
A and B
A= $type < 0B= $buf->[-1][2] == $type
| |||||||||||||||||||||||||||||||||||||||||
| 144 | # streaming data of same type can be added to current buffer | ||||||||||||||||||||||||||||||||||||||||
| 145 | 12 | $buf->[-1][1] .= $data; | |||||||||||||||||||||||||||||||||||||||
| 146 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 147 | # need new buffer | ||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | push @$buf,[ | |||||||||||||||||||||||||||||||||||||||
| 149 | $buf->[-1][0] + length($buf->[-1][1]), # base = end of last | ||||||||||||||||||||||||||||||||||||||||
| 150 | $data, | ||||||||||||||||||||||||||||||||||||||||
| 151 | $type | ||||||||||||||||||||||||||||||||||||||||
| 152 | ]; | ||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||
| 155 | 25 | ▶ | $DEBUG && debug("buffer and analyze %d bytes of data", length($data)); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 156 | 25 | ▶ | my $lastoff = $self->{skipped}[$dir] && $buf->[0][0]; | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'skipped'}[$dir] && $buf->[0][0]
MC/DC0%0/2
$self->{'skipped'}[$dir] && $buf->[0][0]
$self->{'skipped'}[$dir]
$buf->[0][0]
Truth table33%1/3
A && B
A= $self->{'skipped'}[$dir]B= $buf->[0][0]
| |||||||||||||||||||||||||||||||||||||||||
| 157 | 25 | $self->{imp}->data($dir,$data,$lastoff,$type); | |||||||||||||||||||||||||||||||||||||||
| 158 | 25 | $self->{skipped}[$dir] = 0; | |||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||
| 161 | # callback from analyzer | ||||||||||||||||||||||||||||||||||||||||
| 162 | sub _imp_cb { | ||||||||||||||||||||||||||||||||||||||||
| 163 | 68 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_imp_cb: called CC=45 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||
| 164 | 68 | ▶ | $self->{dead} and return; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||
| 166 | 68 | my @fwd; | |||||||||||||||||||||||||||||||||||||||
| 167 | 68 | for my $rv (@_) { | |||||||||||||||||||||||||||||||||||||||
| 168 | 71 | my $rtype = shift(@$rv); | |||||||||||||||||||||||||||||||||||||||
| 169 | 71 | ▶ | $DEBUG && debug("$rtype ".join(" ",map { "'$_'" } @$rv)); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||
| 171 | 71 | ▶ | if ( $rtype == IMP_DENY ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my ($dir,$msg,@extmsg) = @$rv; | |||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $self->deny($msg,$dir,@extmsg); | |||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $self->{dead} = 1; | |||||||||||||||||||||||||||||||||||||||
| 175 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 176 | } elsif ( $rtype == IMP_FATAL ) { | ||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $reason = shift; | |||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $self->fatal($reason); | |||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $self->{dead} = 1; | |||||||||||||||||||||||||||||||||||||||
| 180 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||
| 182 | } elsif ( $rtype == IMP_LOG ) { | ||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my ($dir,$offset,$len,$level,$msg,@extmsg) = @$rv; | |||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $self->log($level,$msg,$dir,$offset,$len,@extmsg); | |||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||
| 186 | } elsif ( $rtype == IMP_ACCTFIELD ) { | ||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my ($key,$value) = @$rv; | |||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $self->acctfld($key,$value); | |||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||
| 190 | } elsif ( $rtype ~~ [ IMP_PASS, IMP_PREPASS ] ) { | ||||||||||||||||||||||||||||||||||||||||
| 191 | 40 | my ($dir,$offset) = @$rv; | |||||||||||||||||||||||||||||||||||||||
| 192 | 40 | ▶ | $DEBUG && debug("got %s %d|%d", $rtype,$dir,$offset); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||
| 194 | 40 | ▶ | if ( $self->{pass}[$dir] == IMP_MAXOFFSET ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | next; # cannot get better than previous pass | |||||||||||||||||||||||||||||||||||||||
| 196 | } elsif ( $rtype == IMP_PASS ) { | ||||||||||||||||||||||||||||||||||||||||
| 197 | 40 | ▶ | if ( $offset == IMP_MAXOFFSET ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 198 | 9 | $self->{pass}[$dir] = $offset; | |||||||||||||||||||||||||||||||||||||||
| 199 | 9 | $self->{prepass}[$dir] = 0; | |||||||||||||||||||||||||||||||||||||||
| 200 | } elsif ( $offset > $self->{pass}[$dir] ) { | ||||||||||||||||||||||||||||||||||||||||
| 201 | 31 | $self->{pass}[$dir] = $offset; | |||||||||||||||||||||||||||||||||||||||
| 202 | $self->{prepass}[$dir] = 0 | ||||||||||||||||||||||||||||||||||||||||
| 203 | 31 | ▶ | if $offset >= $self->{prepass}[$dir]; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 204 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | next; # not better than previous pass | |||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||
| 208 | # IMP_PREPASS | ||||||||||||||||||||||||||||||||||||||||
| 209 | ▶ | } elsif ( $offset == IMP_MAXOFFSET or ( | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$offset == -1 or $offset > $self->{"pass"}[$dir] and $offset > $self->{"prepass"}[$dir]
$offset > $self->{"pass"}[$dir] and $offset > $self->{"prepass"}[$dir]
MC/DC0%0/3
$offset == -1 or $offset > $self->{"pass"}[$dir] and $offset > $self->{"prepass"}[$dir]
$offset == -1
$offset > $self->{"pass"}[$dir]
$offset > $self->{"prepass"}[$dir]
Truth table0%0/4
A or B and C
A= $offset == -1B= $offset > $self->{"pass"}[$dir]C= $offset > $self->{"prepass"}[$dir]
| |||||||||||||||||||||||||||||||||||||||||
| 210 | $offset > $self->{pass}[$dir] and | ||||||||||||||||||||||||||||||||||||||||
| 211 | $offset > $self->{prepass}[$dir] )) { | ||||||||||||||||||||||||||||||||||||||||
| 212 | # update for prepass | ||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $self->{prepass}[$dir] = $offset | |||||||||||||||||||||||||||||||||||||||
| 214 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 215 | # next; # no better than previous prepass | ||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||
| 218 | 40 | my $buf = $self->{buf}[$dir]; | |||||||||||||||||||||||||||||||||||||||
| 219 | 40 | my $end; | |||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||
| 221 | 40 | ▶ | while ($buf->[0][2]) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 222 | 32 | my $buf0 = shift(@$buf); | |||||||||||||||||||||||||||||||||||||||
| 223 | 32 | $end = $buf0->[0] + length($buf0->[1]); | |||||||||||||||||||||||||||||||||||||||
| 224 | 32 | ▶ | if ( $offset == IMP_MAXOFFSET | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$offset == -1 or $offset >= $end
MC/DC50%1/2
$offset == -1 or $offset >= $end
$offset == -1
$offset >= $end
Truth table66%2/3
A or B
A= $offset == -1B= $offset >= $end
| |||||||||||||||||||||||||||||||||||||||||
| 225 | or $offset >= $end ) { | ||||||||||||||||||||||||||||||||||||||||
| 226 | 10 | ▶ | $DEBUG && debug("pass complete buf"); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 227 | 10 | push @fwd, [ $dir, $buf0->[1] ]; | |||||||||||||||||||||||||||||||||||||||
| 228 | # keep dummy in buf | ||||||||||||||||||||||||||||||||||||||||
| 229 | 10 | ▶ | if ( ! @$buf ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 230 | 9 | unshift @$buf,[ $buf0->[0] + length($buf0->[1]),'',0 ]; | |||||||||||||||||||||||||||||||||||||||
| 231 | 9 | ▶ | push @fwd,[$dir,''] if $self->{eof}[$dir]; # fwd eof | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 232 | 9 | last; | |||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||
| 234 | } elsif ( $offset < $buf0->[0] ) { | ||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $DEBUG && debug("duplicate $rtype $offset ($buf0->[0])"); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | unshift @$buf,$buf0; | |||||||||||||||||||||||||||||||||||||||
| 237 | 0 | last; | |||||||||||||||||||||||||||||||||||||||
| 238 | } elsif ( $offset == $buf0->[0] ) { | ||||||||||||||||||||||||||||||||||||||||
| 239 | # at border, e.g. forward 0 bytes | ||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | unshift @$buf,$buf0; | |||||||||||||||||||||||||||||||||||||||
| 241 | 1 | last; | |||||||||||||||||||||||||||||||||||||||
| 242 | } elsif ( $buf0->[2] < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
| 243 | # streaming type, can pass part of buf | ||||||||||||||||||||||||||||||||||||||||
| 244 | 21 | ▶ | $DEBUG && debug("pass part of buf"); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 245 | 21 | push @fwd, [ | |||||||||||||||||||||||||||||||||||||||
| 246 | $dir, | ||||||||||||||||||||||||||||||||||||||||
| 247 | substr($buf0->[1],0,$offset - $end,'') | ||||||||||||||||||||||||||||||||||||||||
| 248 | ]; | ||||||||||||||||||||||||||||||||||||||||
| 249 | # put back with adjusted offset | ||||||||||||||||||||||||||||||||||||||||
| 250 | 21 | $buf0->[0] = $offset; | |||||||||||||||||||||||||||||||||||||||
| 251 | 21 | unshift @$buf, $buf0; | |||||||||||||||||||||||||||||||||||||||
| 252 | 21 | last; | |||||||||||||||||||||||||||||||||||||||
| 253 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | $DEBUG && debug( | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 255 | "ignore partial $rtype for $buf0->[2] (offset=$offset,pos=$buf0->[0])"); | ||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | unshift @$buf, $buf0; # put back | |||||||||||||||||||||||||||||||||||||||
| 257 | 0 | last; | |||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||
| 261 | 40 | ▶ | if ( $offset != IMP_MAXOFFSET and $offset <= $end ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$offset != -1 and $offset <= $end
MC/DC50%1/2
$offset != -1 and $offset <= $end
$offset != -1
$offset <= $end
Truth table66%2/3
A and B
A= $offset != -1B= $offset <= $end
| |||||||||||||||||||||||||||||||||||||||||
| 262 | # limit reached, reset (pre)pass | ||||||||||||||||||||||||||||||||||||||||
| 263 | 31 | ▶ | $self->{ $rtype == IMP_PASS ? 'pass':'prepass' }[$dir] = 0; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||
| 266 | } elsif ( $rtype == IMP_REPLACE ) { | ||||||||||||||||||||||||||||||||||||||||
| 267 | 31 | my ($dir,$offset,$newdata) = @$rv; | |||||||||||||||||||||||||||||||||||||||
| 268 | 31 | ▶ | $DEBUG && debug("got %s %d|%d", $rtype,$dir,$offset); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||
| 270 | 31 | ▶ | if ( $self->{pass}[$dir] or $self->{prepass}[$dir] ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"pass"}[$dir] or $self->{"prepass"}[$dir]
MC/DC0%0/2
$self->{"pass"}[$dir] or $self->{"prepass"}[$dir]
$self->{"pass"}[$dir]
$self->{"prepass"}[$dir]
Truth table33%1/3
A or B
A= $self->{"pass"}[$dir]B= $self->{"prepass"}[$dir]
| |||||||||||||||||||||||||||||||||||||||||
| 271 | # we are allowed to (pre)pass in future, so we cannot replace | ||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | die "cannot replace already passed data"; | |||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||
| 275 | 31 | my $buf = $self->{buf}[$dir]; | |||||||||||||||||||||||||||||||||||||||
| 276 | 31 | my $buf0 = $buf->[0]; | |||||||||||||||||||||||||||||||||||||||
| 277 | 31 | my $eob = $buf0->[0] + length($buf0->[1]); | |||||||||||||||||||||||||||||||||||||||
| 278 | 31 | ▶ | if ( $eob < $offset ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | die "replacement cannot span different types or packets"; | |||||||||||||||||||||||||||||||||||||||
| 280 | } elsif ( $eob == $offset ) { | ||||||||||||||||||||||||||||||||||||||||
| 281 | # full replace | ||||||||||||||||||||||||||||||||||||||||
| 282 | 3 | ▶ | $DEBUG && debug("full replace"); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 283 | 3 | push @fwd,[ $dir,$newdata ]; | |||||||||||||||||||||||||||||||||||||||
| 284 | 3 | shift(@$buf); | |||||||||||||||||||||||||||||||||||||||
| 285 | 3 | ▶ | push @$buf, [ $eob,'',0 ] if ! @$buf; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 286 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 287 | 28 | ▶ | die "no partial replacement for packet types allowed" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 288 | if $buf0->[2]>0; | ||||||||||||||||||||||||||||||||||||||||
| 289 | 28 | ▶ | $DEBUG && debug("partial replace"); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 290 | 28 | push @fwd,[ $dir,$newdata ]; | |||||||||||||||||||||||||||||||||||||||
| 291 | 28 | substr( $buf0->[1],0,$offset - $buf0->[0],''); | |||||||||||||||||||||||||||||||||||||||
| 292 | 28 | $buf0->[0] = $offset; | |||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||
| 295 | } elsif ( $rtype ~~ [ IMP_PAUSE, IMP_CONTINUE ] ) { | ||||||||||||||||||||||||||||||||||||||||
| 296 | # ignore | ||||||||||||||||||||||||||||||||||||||||
| 297 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | die "cannot handle Net::IMP rtype $rtype"; | |||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||
| 301 | 68 | $self->out(@$_) for (@fwd); | |||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||
| 305 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||
| 306 | __END__ | ||||||||||||||||||||||||||||||||||||||||