From 249763e89dcf3394a8c3b55d036a2d7ebce3bdd9 Mon Sep 17 00:00:00 2001 From: Andreas Romeyke <andreas.romeyke@slub-dresden.de> Date: Tue, 11 Mar 2014 15:51:17 +0000 Subject: [PATCH] - added support to getAgent() --- .../plugin/SLUBVirusCheckClamAVPlugin.java | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/java/org/slub/rosetta/dps/repository/plugin/SLUBVirusCheckClamAVPlugin.java b/java/org/slub/rosetta/dps/repository/plugin/SLUBVirusCheckClamAVPlugin.java index 1a2252a..8dfc9de 100644 --- a/java/org/slub/rosetta/dps/repository/plugin/SLUBVirusCheckClamAVPlugin.java +++ b/java/org/slub/rosetta/dps/repository/plugin/SLUBVirusCheckClamAVPlugin.java @@ -40,6 +40,7 @@ public class SLUBVirusCheckClamAVPlugin implements VirusCheckPlugin { //private static final ExLogger log = ExLogger.getExLogger(SLUBVirusCheckClamAVPlugin.class); private static final int DEFAULT_CHUNK_SIZE = 2048; private static final byte[] INSTREAM = "zINSTREAM\0".getBytes(); + private static final byte[] VERSION = "zVERSION\0".getBytes(); private static final String RESPONSEOK = "stream: OK"; private static final String FOUND_SUFFIX = "FOUND"; private static final String STREAM_PREFIX = "stream: "; @@ -144,7 +145,45 @@ public class SLUBVirusCheckClamAVPlugin implements VirusCheckPlugin { } public String getAgent () { - return "clamd"; + try { + // create a socket + Socket socket = new Socket (); + //socket.connect( new InetSocketAddress(getHost())); + socket.connect( new InetSocketAddress(getHost(), getPort())); + try { + socket.setSoTimeout( getTimeOut() ); + } catch (SocketException e) { + System.out.println( "Could not set socket timeout to " + getTimeOut() + "ms " + e); + //log.error( "Could not set socket timeout to " + getTimeOut() + "ms", e); + } + DataOutputStream dos = null; + response = ""; + try { + dos = new DataOutputStream(socket.getOutputStream()); + dos.write(VERSION); + int read; + byte[] buffer = new byte[DEFAULT_CHUNK_SIZE]; + dos.flush(); + read = socket.getInputStream().read(buffer); + if (read > 0) response = new String(buffer, 0, read); + } finally { + if (dos != null) try { dos.close(); } catch (IOException e) { + // log.debug("exception closing DOS", e); + System.out.println( "exception closing DOS "+ e ); + } + try { socket.close(); } catch (IOException e) { + // log.debug("exception closing socket", e); + System.out.println( "exception closing socket "+ e); + } + } + return response; + } catch (IOException e) { + //log.error("exception creation socket, clamd not available at host=" + host + "port=" + port, e); + System.out.println ("exception creation socket, clamd not available at host=" + host + "port=" + port + " " + e); + setStatus(Status.FAILED); + setSignature("ERROR: clamd not available"); + return "ERROR: clamd not available"; + } } public boolean isVirusFree() { @@ -155,6 +194,7 @@ public class SLUBVirusCheckClamAVPlugin implements VirusCheckPlugin { // stand alone check public static void main(String [] args) { SLUBVirusCheckClamAVPlugin plugin = new SLUBVirusCheckClamAVPlugin( "127.0.0.1", 3310, 60); + System.out.println("Agent: "+ plugin.getAgent() ); for (String file:args) { plugin.scan( file ); System.out.println("RESULT: " + plugin.isVirusFree() + " SIGNATURE: " + plugin.getOutput()); -- GitLab