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


if ($sophie_sockname) {
    do_log(2,"Using Sophie");
    socket(\*sock, AF_UNIX, SOCK_STREAM, 0) || do_exit($REGERR, __LINE__);
    connect(\*sock, pack_sockaddr_un $sophie_sockname) || do_exit($REGERR, __LINE__);

    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/[^\w\d\-._:\/]+//g;
    do_log(2,$output);

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

    $scanner_errors = 0;

    if ($output =~ m/^1/) {
	if ($output =~ m/^1:.*$/) {
	    @virusname = ($output =~ m/^1:'?(.*)'?$/g);
	}
	do_virus();
    } elsif ($output == -1) {
	$scanner_errors &= 1;
	do_log(0,"Virus scanner failure: Sophie - UNKNOWN STATUS (error code: $output)");
    } elsif ( ($output != 1) && ($output != 0) && ($output != -1) ) {
	$scanner_errors &= 1;
	do_log(0,"Virus scanner failure: Sophie - OOOPS (error code: $output)");
    }
}
