From clamav-devel-bounces@lists.clamav.net  Wed Jan 26 15:47:10 2005
Return-Path: <clamav-devel-bounces@lists.clamav.net>
X-Original-To: list@krisma.oltrelinux.com
Delivered-To: list@krisma.oltrelinux.com
Received: from localhost (krisma [127.0.0.1])
	by mail.oltrelinux.com (Postfix) with ESMTP id 28AE411AE51
	for <list@krisma.oltrelinux.com>; Wed, 26 Jan 2005 15:47:10 +0100 (CET)
Received: from mail.oltrelinux.com ([127.0.0.1])
	by localhost (krisma.oltrelinux.com [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 14372-08 for <list@krisma.oltrelinux.com>;
	Wed, 26 Jan 2005 15:47:06 +0100 (CET)
Received: from aj.catt.com (aj.catt.com [64.18.103.6])
	by mail.oltrelinux.com (Postfix) with ESMTP id 7789911AE52
	for <list@krisma.oltrelinux.com>; Wed, 26 Jan 2005 15:47:05 +0100 (CET)
Received: from aj.catt.com (localhost [127.0.0.1])
	by aj.catt.com (Postfix) with ESMTP id 7862D15DF04;
	Wed, 26 Jan 2005 09:46:59 -0500 (EST)
Received: from cantillo.uniqmail.ch (mail.uniqmail.ch [212.55.198.173])
	by aj.catt.com (Postfix) with ESMTP id 34A0210B4D3
	for <clamav-devel@lists.clamav.net>;
	Wed, 26 Jan 2005 09:46:52 -0500 (EST)
Received: (qmail 15603 invoked from network); 26 Jan 2005 14:46:49 -0000
Received: from zhenge-fw1.cyberlink.ch (HELO uniqmail.ch) (193.246.253.9)
	by cantillo.uniqmail.ch with AES256-SHA encrypted SMTP;
	26 Jan 2005 14:46:49 -0000
Message-ID: <41F7ABE9.5010901@uniqmail.ch>
Date: Wed, 26 Jan 2005 15:40:41 +0100
From: Ramon Amat <amat@uniqmail.ch>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US;
	rv:1.4) Gecko/20030624
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: ClamAV Development <clamav-devel@lists.clamav.net>,
 dev@uniqmail.ch
Subject: Re: [Clamav-devel] Sending SCAN command multiple times on the same
	socket fails.
References: <41F6B723.70706@uniqmail.ch>	<1106692572.5014.1.camel@mac.bandsman.co.uk>	<41F76489.6080805@uniqmail.ch>
	<1106732754.14592.5.camel@syntax>
In-Reply-To: <1106732754.14592.5.camel@syntax>
X-BeenThere: clamav-devel@lists.clamav.net
X-Mailman-Version: 2.1.5
Precedence: list
Reply-To: ClamAV Development <clamav-devel@lists.clamav.net>
List-Id: ClamAV Development <clamav-devel.lists.clamav.net>
List-Unsubscribe: <http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel>,
	<mailto:clamav-devel-request@lists.clamav.net?subject=unsubscribe>
List-Post: <mailto:clamav-devel@lists.clamav.net>
List-Help: <mailto:clamav-devel-request@lists.clamav.net?subject=help>
List-Subscribe: <http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel>,
	<mailto:clamav-devel-request@lists.clamav.net?subject=subscribe>
Content-Type: multipart/mixed; boundary="===============1576471275=="
Mime-version: 1.0
Sender: clamav-devel-bounces@lists.clamav.net
Errors-To: clamav-devel-bounces@lists.clamav.net
X-Spam-Status: No, hits=1.3 tagged_above=0.5 required=5.0 tests=AWL,
	FORGED_RCVD_HELO, HTML_50_60, HTML_MESSAGE, HTML_TITLE_EMPTY
X-Spam-Level: *

This is a multi-part message in MIME format.
--===============1576471275==
Content-Type: multipart/alternative;
	boundary="------------090805000304060906040802"

This is a multi-part message in MIME format.
--------------090805000304060906040802
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Trog wrote:

>On Wed, 2005-01-26 at 10:36 +0100, Ramon Amat wrote:
>
>  
>
>>>>open socket
>>>>   
>>>>
>>>>        
>>>>
>>>SESSION
>>> 
>>>
>>>      
>>>
>>>>SCAN filepath-1
>>>>SCAN filepath-2
>>>>SCAN filepath-3
>>>>close socket (I do that and not clamd!!!)
>>>>        
>>>>
>
>Did you wait for the result to come back (and read it) between these
>commands?
>
When you talk about (read it) between these commands ? As you can see 
below, I just write the SESSION command and that's it.
So far I actually would say that works 30 out of 32 times.

>
>-trog
>

Ok.

I am scanning three files consecutievly. Speed has notably increased 
since I am using the SESSION command and creating just one socket. 
However, sometimes clamd hangs (I cannot reproduce it on my machine 0.8v 
on GNU/LINUX Debian Sarge). It actually will not come back after sWrite 
within the scan(...) method. It does not happen very often but it 
happens. Some idea what could be done to prevent clamd hanging ?



/// Default Constructor
apevs::ClamavVirusDetector::ClamavVirusDetector(const std::string& 
aSocketPath )
   : mSocketPath( aSocketPath )
{
     try {
         mSocket.sCreate();
         mSocket.sConnect(mSocketPath.c_str());
         mSocket.sWrite("SESSION");
     }
     catch ( SocketException &e ) { ...  }
}


/// Default Destructor
apevs::ClamavVirusDetector::~ClamavVirusDetector()
{
    mSocket.sWrite("END");
}

/// Sends a fileName to Clamav and parses response
/// @param aPathName The pathname to the the file to be scanned.
/// @return Returns the name of the virus if the file/pathname is infected.
const std::string apevs::ClamavVirusDetector::scan(
                    const std::string& aPathName )
{
    std::string virusName;
    std::string pathName = "SCAN " + aPathName + "\n";

    // Scan request
    mSocket.sWrite(pathName);
    std::string buf;
    mSocket.sRead( buf );

    // Parse Response
    // "FILE IS INFECTED" !!!
    int i = 0;
    if ( (i = buf.find( "FOUND" )) < buf.length() ) {
        int e = i-1;
        int b = e;
        while ( buf[b-1]!=' ' ) b--;
        virusName = buf.substr(b,e-b);

        WARNING(
            "clamavVirusDetector %s: %s infected by %s",
            mSocketPath.c_str(), aPathName.c_str(), virusName.c_str( ));
        }
    // startsWith("-1"), then "UNKNOWN STATUS" !!!
    else if ( !( buf.find( "OK" ) < buf.length() ) ) {

    WARNING(
            "clamavVirusDetector %s: UNKNOWN STATUS in %s",
            mSocketPath.c_str(), aPathName.c_str());
    }
    return virusName;
}


>_______________________________________________
>http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel
>  
>


--------------090805000304060906040802
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
Trog wrote:<br>
<blockquote type="cite" cite="mid1106732754.14592.5.camel@syntax">
  <pre wrap="">On Wed, 2005-01-26 at 10:36 +0100, Ramon Amat wrote:

  </pre>
  <blockquote type="cite">
    <blockquote type="cite">
      <blockquote type="cite">
        <pre wrap="">open socket
   

        </pre>
      </blockquote>
      <pre wrap="">SESSION
 

      </pre>
      <blockquote type="cite">
        <pre wrap="">SCAN filepath-1
SCAN filepath-2
SCAN filepath-3
close socket (I do that and not clamd!!!)
        </pre>
      </blockquote>
    </blockquote>
  </blockquote>
  <pre wrap=""><!---->
Did you wait for the result to come back (and read it) between these
commands?</pre>
</blockquote>
When you talk about (read it) between these commands ? As you can see
below, I just write the SESSION command and that's it. <br>
So far I actually would say that works 30 out of 32 times. <br>
<blockquote type="cite" cite="mid1106732754.14592.5.camel@syntax">
  <pre wrap="">

-trog</pre>
</blockquote>
<br>
Ok. <br>
<tt><br>
I am scanning three files consecutievly. Speed has notably increased
since I am using the SESSION command and creating just one socket.
However, sometimes clamd hangs (I cannot reproduce it on my machine
0.8v on GNU/LINUX Debian Sarge). It actually will not come back after
sWrite within the scan(...) method. It does not happen very often but
it happens. Some idea what could be done to prevent clamd hanging ?<br>
<br>
<br>
<br>
/// Default Constructor<br>
apevs::ClamavVirusDetector::ClamavVirusDetector(const std::string&amp;
aSocketPath )<br>
&nbsp;&nbsp; : mSocketPath( aSocketPath )<br>
{<br>
&nbsp;&nbsp;&nbsp;&nbsp; try {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mSocket.sCreate();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mSocket.sConnect(mSocketPath.c_str());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mSocket.sWrite("SESSION");<br>
&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp; catch ( SocketException &amp;e ) { ...&nbsp; }<br>
}<br>
<br>
<br>
/// Default Destructor<br>
apevs::ClamavVirusDetector::~ClamavVirusDetector()<br>
{<br>
&nbsp;&nbsp;&nbsp; mSocket.sWrite("END");<br>
}<br>
<br>
/// Sends a fileName to Clamav and parses response<br>
/// @param aPathName The pathname to the the file to be scanned.<br>
/// @return Returns the name of the virus if the file/pathname is
infected.<br>
const std::string apevs::ClamavVirusDetector::scan(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const std::string&amp; aPathName )<br>
{<br>
&nbsp;&nbsp;&nbsp; std::string virusName;<br>
&nbsp;&nbsp;&nbsp; std::string pathName = "SCAN " + aPathName + "\n";<br>
<br>
&nbsp;&nbsp;&nbsp; // Scan request<br>
&nbsp;&nbsp;&nbsp; mSocket.sWrite(pathName);<br>
&nbsp;&nbsp;&nbsp; std::string buf;<br>
&nbsp;&nbsp;&nbsp; mSocket.sRead( buf );<br>
<br>
&nbsp;&nbsp;&nbsp; // Parse Response<br>
&nbsp;&nbsp;&nbsp; // "FILE IS INFECTED" !!!<br>
&nbsp;&nbsp;&nbsp; int i = 0;<br>
&nbsp;&nbsp;&nbsp; if ( (i = buf.find( "FOUND" )) &lt; buf.length() ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int e = i-1;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int b = e;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while ( buf[b-1]!=' ' ) b--;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; virusName = buf.substr(b,e-b);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WARNING(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "clamavVirusDetector %s: %s infected by %s",<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mSocketPath.c_str(), aPathName.c_str(), virusName.c_str( ));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; // startsWith("-1"), then "UNKNOWN STATUS" !!!<br>
&nbsp;&nbsp;&nbsp; else if ( !( buf.find( "OK" ) &lt; buf.length() ) ) {<br>
<br>
&nbsp;&nbsp;&nbsp; WARNING(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "clamavVirusDetector %s: UNKNOWN STATUS in %s",<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mSocketPath.c_str(), aPathName.c_str());<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; return virusName;<br>
}</tt><br>
<br>
<br>
<blockquote type="cite" cite="mid1106732754.14592.5.camel@syntax">
  <pre wrap="">_______________________________________________
<a class="moz-txt-link-freetext" href="http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel">http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel</a>
  </pre>
</blockquote>
<br>
</body>
</html>

--------------090805000304060906040802--


--===============1576471275==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel

--===============1576471275==--

