| 1 | package OpenSMTPd::Filter; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use utf8; # so literals and identifiers can be in UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use v5.16; # or later to get "unicode_strings" feature and "charnames" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; # quote strings, declare variables | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; # on by default | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use warnings qw(FATAL utf8); # fatalize encoding glitches | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use open qw(:std :encoding(UTF-8)); # undeclared streams in UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # This happens automatically, but to make pledge(2) happy | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # it has to happen earlier than it would otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Time::HiRes qw< time >; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # ABSTRACT: Easier filters for OpenSMTPd in perl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | our $VERSION = 'v0.0.2'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | my @report_fields = qw< version timestamp subsystem event session suffix >; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | my %report_events = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 'smtp-in' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 'link-connect' => [qw< rdns fcrdns src dest >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 'link-greeting' => [qw< hostname >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 'link-identify' => [qw< method identity >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 'link-tls' => [qw< tls-string >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 'link-disconnect' => [qw< >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 'link-auth' => [qw< username result >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 'tx-reset' => [qw< message-id >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 'tx-begin' => [qw< message-id >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 'tx-mail' => [qw< message-id result address >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 'tx-rcpt' => [qw< message-id result address>], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 'tx-envelope' => [qw< message-id envelope-id >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'tx-data' => [qw< message-id result >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 'tx-commit' => [qw< message-id message-size >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'tx-rollback' => [qw< message-id >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'protocol-client' => [qw< command >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 'protocol-server' => [qw< response >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 'filter-report' => [qw< filter-kind name message >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 'filter-response' => [qw< phase response param>], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'timeout' => [qw< >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | my @filter_fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | = qw< version timestamp subsystem phase session opaque-token suffix >; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | my %filter_events = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'smtp-in' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 'connect' => [qw< rdns fcrdns src dest >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 'helo' => [qw< identity >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 'ehlo' => [qw< identity >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 'starttls' => [qw< tls-string >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 'auth' => [qw< auth >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 'mail-from' => [qw< address >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 'rcpt-to' => [qw< address >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 'data' => [qw< >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 'data-line' => [qw< line >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 'commit' => [qw< >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | 'data-lines' => sub {'data-line'}, # special case | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | my @filter_result_fields = qw< session opaque-token >; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | my %filter_result_decisions = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | #'dataline' => [qw< line >], # special case | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 'proceed' => [qw< >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 'junk' => [qw< >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 'reject' => [qw< error >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 'disconnect' => [qw< error >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 'rewrite' => [qw< parameter >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 'report' => [qw< parameter >], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 19 | ▶ | my ( $class, %params ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 19 | ▶ | $params{on} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{"on"} ||= {}
MC/DC100%1/1
$params{"on"} ||= {}
$params{"on"}
Truth table100%2/2
A
A= $params{"on"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 19 | ▶ | $params{input} ||= \*STDIN; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{"input"} ||= \*STDIN
MC/DC100%1/1
$params{"input"} ||= \*STDIN
$params{"input"}
Truth table100%2/2
A
A= $params{"input"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 19 | ▶ | $params{output} ||= \*STDOUT; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{"output"} ||= \*STDOUT
MC/DC100%1/1
$params{"output"} ||= \*STDOUT
$params{"output"}
Truth table100%2/2
A
A= $params{"output"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 19 | STDERR->autoflush; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 19 | $params{output}->autoflush; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # We expect to read and write bytes from the remote | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 19 | $_->binmode(':raw') for @params{qw< input output >}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 19 | my $check_supported_events; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | $check_supported_events = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 49 | ▶ | my ( $c, $e, $ms ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 49 | ▶ | my $m = shift @{$ms} || return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift @{$ms;} || (return)
MC/DC100%1/1
shift @{$ms;} || (return)
shift @{$ms;}
Truth table100%2/2
A
A= shift @{$ms;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 36 | my @s = sort keys %{$c}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 36 | ▶ | if ( my @u = grep { !$e->{$_} } @s ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | ▶ | my $s = @u == 1 ? '' : 's'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | croak("Unsupported $m$s @u"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 33 | $check_supported_events->( $c->{$_}, $e->{$_}, $ms ) for @s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 19 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | $check_supported_events->( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | $params{on}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 19 | { report => \%report_events, filter => \%filter_events }, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | [ "event type", "event subsystem", "event" ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # Only save data-lines if we're using the helper to process them | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | $params{_save_data_lines} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | = $params{on} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | && $params{on}{filter} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | && $params{on}{filter}{'smtp-in'} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 16 | ▶ | && $params{on}{filter}{'smtp-in'}{'data-lines'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition77%7/9
$params{'on'} && $params{'on'}{'filter'} && $params{'on'}{'filter'}{'smtp-in'} && $params{'on'}{'filter'}{'smtp-in'}{'data-lines'}
$params{"on"} and $params{"on"}{"filter"} and $params{"on"}{"filter"}{"smtp-in"}
$params{"on"} and $params{"on"}{"filter"}
MC/DC50%2/4
$params{'on'} && $params{'on'}{'filter'} && $params{'on'}{'filter'}{'smtp-in'} && $params{'on'}{'filter'}{'smtp-in'}{'data-lines'}
$params{"on"}
$params{"on"}{"filter"}
$params{"on"}{"filter"}{"smtp-in"}
$params{'on'}{'filter'}{'smtp-in'}{'data-lines'}
Truth table60%3/5
A and B and C && D
A= $params{"on"}B= $params{"on"}{"filter"}C= $params{"on"}{"filter"}{"smtp-in"}D= $params{'on'}{'filter'}{'smtp-in'}{'data-lines'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 16 | my $self = bless \%params, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 16 | return $self->_init; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | sub _init { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 17 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=8 SCAR=21.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 17 | my $fh = $self->{input}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 17 | ▶ | my $blocking = $fh->blocking // die "Unable to get blocking on input: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fh->blocking // die("Unable to get blocking on input: $!")
MC/DC0%0/1
$fh->blocking // die("Unable to get blocking on input: $!")
$fh->blocking
Truth table50%1/2
A
A= $fh->blocking
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 17 | ▶ | $fh->blocking(0) // die "Unable to set input to non-blocking: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fh->blocking(0) // die("Unable to set input to non-blocking: $!")
MC/DC0%0/1
$fh->blocking(0) // die("Unable to set input to non-blocking: $!")
$fh->blocking(0)
Truth table50%1/2
A
A= $fh->blocking(0)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 17 | my $timeout = 0.25; # no idea how long we should actually wait | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 17 | my $now = time; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 17 | my %config; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 17 | ▶ | while ( not $self->{_ready} and ( time - $now ) < $timeout ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->{"_ready"} and &OpenSMTPd::Filter::time() - $now < $timeout
MC/DC100%2/2
not $self->{"_ready"} and &OpenSMTPd::Filter::time() - $now < $timeout
not $self->{"_ready"}
&OpenSMTPd::Filter::time() - $now < $timeout
Truth table100%3/3
not(A) and B
A= not $self->{"_ready"}B= &OpenSMTPd::Filter::time() - $now < $timeout
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 462210 | ▶ | my $line = $fh->getline // next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$fh->getline // (next)
MC/DC100%1/1
$fh->getline // (next)
$fh->getline
Truth table100%2/2
A
A= $fh->getline
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | ▶ | STDERR->print("< $line") if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 8 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 8 | $self->_dispatch($line); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 8 | $now = time; # continue waiting, we got a line | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 17 | ▶ | $fh->blocking($blocking) // die "Unable to reset blocking on input: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fh->blocking($blocking) // die("Unable to reset blocking on input: $!")
MC/DC0%0/1
$fh->blocking($blocking) // die("Unable to reset blocking on input: $!")
$fh->blocking($blocking)
Truth table50%1/2
A
A= $fh->blocking($blocking)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 17 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | sub ready { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ready: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 5 | ▶ | croak("Input stream is not ready") unless $self->{_ready}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 76 | my @reports = map {"report|smtp-in|$_"} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | sort keys %{ $report_events{'smtp-in'} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | my @filters; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 4 | for my $subsystem ( sort keys %{ $self->{on}->{filter} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | for ( sort keys %{ $self->{on}->{filter}->{$subsystem} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | my $v = $filter_events{$subsystem}{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | my $phase = ref $v eq 'CODE' ? $v->($_) : $_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | push @filters, "filter|$subsystem|$phase"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 4 | for ( @reports, @filters, 'ready' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 81 | ▶ | STDERR->say("> register|$_") if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 81 | $self->{output}->say("register|$_"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 4 | $self->{input}->blocking(1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 4 | ▶ | while ( defined( my $line = $self->{input}->getline ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 98 | ▶ | STDERR->print("< $line") if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 98 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 98 | $self->_dispatch($line); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # The char "|" may only appear in the last field of a payload, in which | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # case it should be considered a regular char and not a separator. Other | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # fields have strict formatting excluding the possibility of having a "|". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | sub _dispatch { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 143 | ▶ | my ( $self, $line ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dispatch: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 143 | ▶ | $line //= 'undef'; # no unitialized warnings | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$line //= "undef"
MC/DC100%1/1
$line //= "undef"
$line
Truth table100%2/2
A
A= $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 143 | my ( $type, $extra ) = split /\|/, $line, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 143 | ▶ | $type //= 'unsupported'; # no uninitialized warnings | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$type //= "unsupported"
MC/DC100%1/1
$type //= "unsupported"
$type
Truth table100%2/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 143 | my $method = $self->can("_handle_$type"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 143 | ▶ | return $self->$method($extra) if $method; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | croak("Unsupported: $line"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # general configuration information in the form of key-value lines | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | sub _handle_config { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 10 | ▶ | my ( $self, $config ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_config: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 10 | ▶ | return $self->{_ready} = $config | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | if $config eq 'ready'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 5 | my ( $key, $value ) = split /\|/, $config, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 5 | $self->{_config}->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 5 | return $key, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # Each report event is generated by smtpd(8) as a single line | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # The format consists of a protocol prefix containing the stream, the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # protocol version, the timestamp, the subsystem, the event and the unique | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # session identifier separated by "|": | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # It is followed by a suffix containing the event-specific parameters, also | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # separated by "|" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | sub _handle_report { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 109 | ▶ | my ( $self, $report ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_report: called CC=13 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 109 | my %report; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 109 | @report{@report_fields} = split /\|/, $report, @report_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 109 | ▶ | my $event = $report{event} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$report{"event"} // ""
MC/DC100%1/1
$report{"event"} // ""
$report{"event"}
Truth table100%2/2
A
A= $report{"event"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 109 | my $suffix = delete $report{suffix}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 109 | my %params; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 109 | my @fields = $self->_report_fields_for( @report{qw< subsystem event >} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 106 | ▶ | @params{@fields} = split /\|/, $suffix, @fields | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | if @fields; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 106 | ▶ | my $session = $self->{_sessions}->{ $report{session} } ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_sessions"}{$report{"session"}} ||= {}
MC/DC100%1/1
$self->{"_sessions"}{$report{"session"}} ||= {}
$self->{"_sessions"}{$report{"session"}}
Truth table100%2/2
A
A= $self->{"_sessions"}{$report{"session"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 106 | $session->{state}->{$_} = $report{$_} for keys %report; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 106 | push @{ $session->{events} }, { %report, %params, request => 'report' }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # If the session disconncted we can't do anything more with it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | delete $self->{_sessions}->{ $report{session} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 106 | ▶ | if $event eq 'link-disconnect'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 106 | ▶ | if ( $event =~ /^tx-(.*)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 23 | my $phase = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 3 | push @{ $session->{messages} }, $session->{state}->{message} = {} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 23 | ▶ | if $phase eq 'begin'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 23 | my $message = $session->{messages}->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 23 | ▶ | if ( $phase eq 'mail' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 3 | $message->{'mail-from'} = $params{address}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 3 | $message->{result} = $params{result}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | elsif ( $phase eq 'rcpt') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | push @{ $message->{'rcpt-to'} }, $params{address}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 4 | $message->{result} = $params{result}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 16 | $message->{$_} = $params{$_} for keys %params; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 83 | $session->{state}->{$_} = $params{$_} for keys %params; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 106 | my $cb = $self->_cb_for( report => @report{qw< subsystem event >} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 106 | ▶ | $cb->( $event, $session ) if $cb; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 106 | return $session->{events}->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | sub _handle_filter { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 37 | ▶ | my ( $self, $filter ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_filter: called CC=16 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 37 | my %filter; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 37 | @filter{@filter_fields} = split /\|/, $filter, @filter_fields; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 37 | my $suffix = delete $filter{suffix}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # For use in error messages | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 37 | my $subsystem = $filter{subsystem}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 37 | my $phase = $filter{phase}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 37 | my $session_id = $filter{session}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 37 | ▶ | $_ = defined $_ ? "'$_'" : "undef" for $subsystem, $phase, $session_id; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 37 | my %params; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 37 | my @fields = $self->_filter_fields_for( @filter{qw< subsystem phase >} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 32 | ▶ | @params{@fields} = split /\|/, $suffix, @fields | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $suffix and @fields
MC/DC100%2/2
defined $suffix and @fields
defined $suffix
@fields
Truth table100%3/3
A and B
A= defined $suffixB= @fields
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | if defined $suffix and @fields; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 32 | ▶ | my $session = $self->{_sessions}->{ $filter{session} || '' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$filter{'session'} || ''
MC/DC100%1/1
$filter{'session'} || ''
$filter{'session'}
Truth table100%2/2
A
A= $filter{'session'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | or croak("Unknown session $session_id in filter $subsystem|$phase"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 30 | push @{ $session->{events} }, { %filter, %params, request => 'filter' }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | return $self->_handle_filter_data_line( $params{line}, \%filter, $session ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | if $filter{subsystem} eq 'smtp-in' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 30 | ▶ | and $filter{phase} eq 'data-line'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$filter{"subsystem"} eq "smtp-in" and $filter{"phase"} eq "data-line"
MC/DC50%1/2
$filter{"subsystem"} eq "smtp-in" and $filter{"phase"} eq "data-line"
$filter{"subsystem"} eq "smtp-in"
$filter{"phase"} eq "data-line"
Truth table66%2/3
A and B
A= $filter{"subsystem"} eq "smtp-in"B= $filter{"phase"} eq "data-line"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 7 | my @ret; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 7 | ▶ | if ( my $cb = $self->_cb_for( filter => @filter{qw< subsystem phase >} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 6 | @ret = $cb->( $filter{phase}, $session ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | carp("No handler for filter $subsystem|$phase, proceeding"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | @ret = 'proceed'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 7 | my $decisions = $filter_result_decisions{ $ret[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 7 | ▶ | unless ($decisions) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | carp "Unknown return from filter $subsystem|$phase: @ret"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | $ret[0] = 'reject'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | $decisions = $filter_result_decisions{ $ret[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # Pass something as the reason for the rejection | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 7 | ▶ | push @ret, "550 Nope" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
@ret == 1 and ($decisions->[0] || "") eq "error"
$decisions->[0] || ''
MC/DC100%2/2
@ret == 1 and ($decisions->[0] || "") eq "error"
@ret == 1
$decisions->[0]
Truth table100%3/3
A and B
A= @ret == 1B= $decisions->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | if @ret == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | and ( $decisions->[0] || '' ) eq 'error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | carp( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | sprintf "Incorrect params from filter %s|%s, expected %s got %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | $subsystem, $phase, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 3 | join( ' ', map {"'$_'"} 'decision', @$decisions ), | |||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 3 | join( ' ', map {"'$_'"} @ret), | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 7 | ▶ | ) unless @ret == 1 + @{$decisions}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | my $response = join '|', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 'filter-result', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 7 | @filter{qw< session opaque-token >}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | @ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 7 | ▶ | STDERR->say("> $response") if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 7 | $self->{output}->say($response); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 7 | return {%filter}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | sub _handle_filter_data_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 23 | ▶ | my ( $self, $line, $filter, $session ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_filter_data_line: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 23 | ▶ | $line //= ''; # avoid uninit warnings | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$line //= ""
MC/DC100%1/1
$line //= ""
$line
Truth table100%2/2
A
A= $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 23 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 23 | ▶ | if ( my $cb | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 23 | = $self->_cb_for( filter => @{$filter}{qw< subsystem phase >} ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 13 | @lines = $cb->( $filter->{phase}, $session, $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 23 | my $message = $session->{messages}->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 23 | ▶ | push @{ $message->{'data-line'} }, $line if $self->{_save_data_lines}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 23 | ▶ | if ( $line eq '.' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | my $cb | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 3 | = $self->_cb_for( filter => $filter->{subsystem}, 'data-lines' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 3 | ▶ | push @lines, $cb->( 'data-lines', $session, $message->{'data-line'} ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | if $cb; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # make sure we end the message; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 3 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 23 | ▶ | for ( map { $_ ? split /\n/ : $_ } @lines ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 28 | ▶ | last if $message->{'sent-dot'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | my $response = join '|', 'filter-dataline', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 25 | @{$filter}{qw< session opaque-token >}, $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 25 | ▶ | STDERR->say("> $response") if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 25 | $self->{output}->say($response); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 25 | ▶ | $message->{'sent-dot'} = 1 if $_ eq '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 23 | return $filter; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 109 | ▶ | sub _report_fields_for { shift->_fields_for( report => \%report_events, @_ ) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_report_fields_for: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 37 | ▶ | sub _filter_fields_for { shift->_fields_for( filter => \%filter_events, @_ ) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filter_fields_for: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | sub _fields_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 146 | ▶ | my ( $self, $type, $map, $subsystem, $item ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fields_for: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 146 | ▶ | if ( $subsystem and $item and my $items = $map->{$subsystem} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$subsystem and $item and my $items = $map->{$subsystem}
$subsystem and $item
MC/DC100%3/3
$subsystem and $item and my $items = $map->{$subsystem}
$subsystem
$item
my $items = $map->{$subsystem}
Truth table100%4/4
A and B and C
A= $subsystemB= $itemC= my $items = $map->{$subsystem}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 140 | ▶ | return @{ $items->{$item} } if $items->{$item}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 8 | ▶ | $_ = defined $_ ? "'$_'" : "undef" for $subsystem, $item; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 8 | croak("Unsupported $type $subsystem|$item"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | sub _cb_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 139 | ▶ | my ( $self, @lookup ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cb_for: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 139 | my $cb = $self->{on}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 139 | ▶ | $cb = $cb->{$_} || {} for @lookup; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cb->{$_} || {}
MC/DC100%1/1
$cb->{$_} || {}
$cb->{$_}
Truth table100%2/2
A
A= $cb->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 139 | ▶ | return $cb if ref $cb eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 114 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||