Package org.primefaces.virusscan.impl
Class ClamDaemonClient
java.lang.Object
org.primefaces.virusscan.impl.ClamDaemonClient
Simple client for ClamAV's clamd scanner.
Provides straightforward instream scanning.
Support for basic INSTREAM scanning and PING command.
Clamd protocol is explained here:
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final String
static final int
static final int
-
Constructor Summary
ConstructorsConstructorDescriptionClamDaemonClient
(String host, int port) ClamDaemonClient
(String host, int port, int timeout, int bufferSize) -
Method Summary
Modifier and TypeMethodDescriptionint
getHost()
int
getPort()
protected Socket
Get a socket to the current host and port.int
static boolean
isCleanReply
(byte[] reply) Interpret the result from a ClamAV scan, and determine if the result means the data is clean.boolean
ping()
Run PING command to CLAMD to test it is responding.byte[]
scan
(byte[] in) Scans bytes for virus by passing the bytes to clamavbyte[]
scan
(InputStream is) Streams the given data to the server in chunks.
-
Field Details
-
DEFAULT_BUFFER
public static final int DEFAULT_BUFFER- See Also:
-
DEFAULT_HOST
- See Also:
-
DEFAULT_PORT
public static final int DEFAULT_PORT- See Also:
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUT- See Also:
-
-
Constructor Details
-
ClamDaemonClient
- Parameters:
host
- The hostname of the server running clamav-daemonport
- The port that clamav-daemon listens to(By default it might not listen to a port. Check your clamav configuration).timeout
- zero means infinite timeout. Not a good idea, but will be accepted.bufferSize
- The buffer (chunk size).
-
ClamDaemonClient
public ClamDaemonClient() -
ClamDaemonClient
-
-
Method Details
-
getBufferSize
public int getBufferSize() -
getHost
-
getPort
public int getPort() -
getTimeout
public int getTimeout() -
ping
Run PING command to CLAMD to test it is responding.- Returns:
- true if the server responded with proper ping reply.
- Throws:
IOException
- if there is an I/O problem communicating with CLAMD
-
scan
Streams the given data to the server in chunks. The whole data is not kept in memory. This method is preferred if you don't want to keep the data in memory, for instance by scanning a file on disk. Since the parameter InputStream is not reset, you can not use the stream afterwards, as it will be left in a EOF-state. If your goal is to scan some data, and then pass that data further, consider usingscan(byte[] in)
.Opens a socket and reads the reply. Parameter input stream is NOT closed.
- Parameters:
is
- data to scan. Not closed by this method!- Returns:
- server reply
- Throws:
IOException
- if there is an I/O problem
-
scan
Scans bytes for virus by passing the bytes to clamav- Parameters:
in
- data to scan.- Returns:
- server reply
- Throws:
IOException
- if there is an I/O problem
-
getSocket
Get a socket to the current host and port. Partly implemented as a separate method for unit testing purposes.- Returns:
- socket to host and port
- Throws:
IOException
- if an I/O error occurs when creating the socket
-
isCleanReply
public static boolean isCleanReply(byte[] reply) Interpret the result from a ClamAV scan, and determine if the result means the data is clean.- Parameters:
reply
- The reply from the server after scanning- Returns:
- true if no virus was found according to the clamd reply message
-