VirusScan/Engine/Daemon/Trend/Trophie.pm

filter: Statementstmt 53.0% 35 / 66 Branchbran 15.0% 3 / 20 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.9% 10 / 11 Podpod 100% 2 / 2 totaltotal 45.4% 50 / 110 CC 14 SCAR 43.7
CC
14
Cov
41%
scan
156.0
_get_socket
2.1
new
2.0
CRAP 78.7
« VirusScan/Engine/Daemon/Sophos/Sophie.pm ↑ Summary VirusScan/Engine/Command/CentralCommand/Vexira.pm »
1 package File::VirusScan::Engine::Daemon::Trend::Trophie;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use File::VirusScan::Engine::Daemon;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 @ISA = qw( File::VirusScan::Engine::Daemon );
9  
10 1 ▶use IO::Socket::UNIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Cwd 'abs_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use File::VirusScan::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub new
16 8 ▶{
Subroutine new: called CC=2 SCAR=6.9
Pod documented
17 8 my ($class, $conf) = @_;
18  
19 8 ▶ if(!$conf->{socket_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conf->{"socket_name"}) 1 7 8
20 1 croak "Must supply a 'socket_name' config value for $class";
21 }
22  
23 7 my $self = { socket_name => $conf->{socket_name}, };
24  
25 7 return bless $self, $class;
26 }
27  
28 sub _get_socket
29 1 ▶{
Subroutine _get_socket: called CC=2 SCAR=7.4
30 1 my ($self) = @_;
31  
32 1 my $sock = IO::Socket::UNIX->new(Peer => $self->{socket_name});
33 1 ▶ if(!defined $sock) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sock) 1 0 1
34 1 croak "Error: Could not connect to sophie daemon at $self->{socket_name}";
35 }
36  
37 0 return $sock;
38 }
39  
40 sub scan
41 0 ▶{
Subroutine scan: not called CC=12 SCAR=50.5
Pod documented
42 0 my ($self, $path) = @_;
43  
44 0 my $abs = abs_path($path);
45 0 ▶ if ($abs && $abs ne $path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($abs and $abs ne $path) 0 0 0
Condition0%0/3
$abs and $abs ne $path
!ll&&!rl&&r
000
MC/DC0%0/2
$abs and $abs ne $path
$abs $abs ne $path
Truth table0%0/3
A and B
A= $absB= $abs ne $path
ABresult
0X0
100
111
46 0 $path = $abs;
47 }
48  
49 0 my $sock = eval { $self->_get_socket };
50 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
51 0 return File::VirusScan::Result->error($@);
52 }
53  
54 0 ▶ if(!$sock->print("$path\n")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sock->print("$path\n")) 0 0 0
55 0 $sock->close;
56 0 return File::VirusScan::Result->error("Could not get trophie to scan $path");
57 }
58  
59 0 ▶ if(!$sock->flush) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sock->flush) 0 0 0
60 0 $sock->close;
61 0 return File::VirusScan::Result->error("Could not get trophie to scan $path");
62 }
63  
64 0 my $scan_response;
65 0 my $rc = $sock->sysread($scan_response, 256);
66 0 $sock->close();
67  
68 0 ▶ if(!$rc) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rc) 0 0 0
69 0 return File::VirusScan::Result->error("Did not get response from trophie while scanning $path");
70 }
71  
72 0 ▶ if($scan_response =~ m/^0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scan_response =~ /^0/) 0 0 0
73 0 return File::VirusScan::Result->clean();
74 }
75  
76 0 ▶ if($scan_response =~ m/^1/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scan_response =~ /^1/) 0 0 0
77 0 my ($virus_name) = $scan_response =~ /^1:(.*)$/;
78 0 ▶ $virus_name ||= 'Unknown-trophie-virus';
Condition0%0/2
$virus_name ||= "Unknown-trophie-virus"
l!l
00
MC/DC0%0/1
$virus_name ||= "Unknown-trophie-virus"
$virus_name
Truth table0%0/2
A
A= $virus_name
Aresult
11
00
79 0 return File::VirusScan::Result->virus($virus_name);
80 }
81  
82 0 ▶ if($scan_response =~ m/^-1:(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scan_response =~ /^-1:(.*)$/) 0 0 0
83 0 my $error_message = $1;
84 0 ▶ $error_message ||= 'unknown error';
Condition0%0/2
$error_message ||= "unknown error"
l!l
00
MC/DC0%0/1
$error_message ||= "unknown error"
$error_message
Truth table0%0/2
A
A= $error_message
Aresult
11
00
85 0 return File::VirusScan::Result->error($error_message);
86 }
87  
88 0 return File::VirusScan::Result->error('Unknown response from trophie');
89 }
90  
91 1 1;
92 __END__
« VirusScan/Engine/Daemon/Sophos/Sophie.pm ↑ Summary VirusScan/Engine/Command/CentralCommand/Vexira.pm »