#
# Sophos Anti Virus via Sophie
#
use IO::Socket;
$|=1;


if ($sophie_sockname) {
    do_log(2,"Using Sophie");
    socket(\*sock, AF_UNIX, SOCK_STREAM, 0)
      or die "Can't open socket to Sophie: $!";
    connect(\*sock, pack_sockaddr_un $sophie_sockname)
      or die "Can't connect to Sophie: $!";

    my $chkdir = "$TEMPDIR/parts/\n";
    defined syswrite(\*sock, $chkdir, length($chkdir))
      or die "syswrite to Sophie failed: $!";
    defined sysread(\*sock, $output, 256)
      or die "sysread from Sophie failed: $!";

    chomp($output);
    $output =~ s/[^A-Za-z0-9\._=+-:\/]+//g;
    do_log(2,$output);

    close(\*sock) or die "Sophie socket close failed: $!";

    if ($output =~ m/^1/) {
	if ($output =~ m/^1:.*$/) {
	    @virusname = ($output =~ m/^1:'?(.*)'?$/g);
	}
	@virusname = (undef)  if !@virusname;  # just in case: make list nonnil
	$scanner_errors = 0;  # no errors, a virus was found
	do_virus();
    } elsif ($output == 0) {
	$scanner_errors = 0;  # no errors, no viruses
    } elsif ($output == -1) {
	do_log(0,"Virus scanner failure: Sophie - UNKNOWN STATUS (error code: $output)");
    } else {
	do_log(0,"Virus scanner failure: Sophie - OOOPS (error code: $output)");
    }
}
