Update of /cvsroot/openantivirus/java/src/org/openantivirus/engine
In directory sc8-pr-cvs1:/tmp/cvs-serv13887/engine
Modified Files:
ScanEngine.java
Added Files:
ScanAbortedException.java ScanListener.java
Log Message:
Let VirusHammer use the new engine
--- NEW FILE: ScanAbortedException.java ---
/*
* $Id: ScanAbortedException.java,v 1.1 2003/12/14 20:24:58 kurti Exp $
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is OAV.
*
* The Initial Developer of the Original Code is Kurt Huwig <[email protected]>.
* Portions created by the Initial Developer are Copyright (C) 2001-2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
package org.openantivirus.engine;
/**
* Thrown, when the scanning should be aborted
*
* Pattern-Roles:
* @author Kurt Huwig <[email protected]>
* @version $Revision: 1.1 $
*/
public class ScanAbortedException extends Exception {
public ScanAbortedException(String reason) {
super(reason);
}
}
--- NEW FILE: ScanListener.java ---
/*
* $Id: ScanListener.java,v 1.1 2003/12/14 20:24:58 kurti Exp $
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is OAV.
*
* The Initial Developer of the Original Code is Kurt Huwig <[email protected]>.
* Portions created by the Initial Developer are Copyright (C) 2001-2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
package org.openantivirus.engine;
import java.util.*;
import org.openantivirus.engine.censor.*;
import org.openantivirus.engine.vfs.*;
/**
* Listener for events occuring during scanning
*
* Pattern-Roles:
* @author Kurt Huwig <[email protected]>
* @version $Revision: 1.1 $
*/
public interface ScanListener extends EventListener {
/** called when the scan is about to start */
void startingScan();
/**
* called for each files to be scanned
* @param vfsEntry VfsEntry to be scanned
*/
void scanning(VfsEntry vfsEntry) throws ScanAbortedException;
/** called, when a malware has been found */
void malwareFound(MalwareFoundException malwareFoundException);
/** called when an Excption other than MalwareFoundException was thrown */
void exceptionThrown(Exception exception);
/** called when the scan has finished */
void finishedScan();
}
Index: ScanEngine.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/engine/ScanEngine.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ScanEngine.java 14 Dec 2003 11:08:26 -0000 1.1
+++ ScanEngine.java 14 Dec 2003 20:24:58 -0000 1.2
@@ -22,11 +22,13 @@
*
* Contributor(s):
*
- * ***** END LICENSE BLOCK ***** */
+ * ***** END LICENSE BLOCK *****
+ */
package org.openantivirus.engine;
import java.io.*;
+import java.util.*;
import org.openantivirus.engine.censor.*;
import org.openantivirus.engine.censor.trie.*;
@@ -49,6 +51,7 @@
private final Censor[] censors;
+ private final List scanListeners = new LinkedList();
private final ScanConfiguration scanConfiguration;
public ScanEngine() throws IOException, CredoException {
@@ -96,12 +99,19 @@
*/
public void scan(File file, ScanConfiguration conf)
throws MalwareFoundException, IOException {
- scan(new FileVfsEntry(file), conf);
+ notifyStartingScan();
+ try {
+ scan(new FileVfsEntry(file), conf);
+ } catch (ScanAbortedException sae) {
+ // ok, we stop here
+ }
+ notifyFinishedScan();
}
protected void scan(VfsEntry entry, ScanConfiguration conf)
- throws MalwareFoundException {
+ throws MalwareFoundException, ScanAbortedException {
try {
+ notifyScanning(entry);
if (scanContainer(entry, conf)) {
return;
}
@@ -182,12 +192,42 @@
return containerFound;
}
+ public void addScanListener(ScanListener listener) {
+ scanListeners.add(listener);
+ }
+
+ public void removeScanListener(ScanListener listener) {
+ scanListeners.remove(listener);
+ }
+
+ protected void notifyStartingScan() {
+ for (Iterator it = scanListeners.iterator(); it.hasNext();) {
+ ((ScanListener) it.next()).startingScan();
+ }
+ }
+
+ protected void notifyScanning(VfsEntry entry) throws ScanAbortedException {
+ for (Iterator it = scanListeners.iterator(); it.hasNext();) {
+ ((ScanListener) it.next()).scanning(entry);
+ }
+ }
+
protected void notifyException(Exception exception) {
- exception.printStackTrace();
+ for (Iterator it = scanListeners.iterator(); it.hasNext();) {
+ ((ScanListener) it.next()).exceptionThrown(exception);
+ }
}
protected void notifyMalwareFound(MalwareFoundException mfe) {
- System.out.println("FOUND: " + mfe.getName());
- System.out.println(" in '" + mfe.getEntry().getName() + "'");
+ for (Iterator it = scanListeners.iterator(); it.hasNext();) {
+ ((ScanListener) it.next()).malwareFound(mfe);
+ }
}
+
+ protected void notifyFinishedScan() {
+ for (Iterator it = scanListeners.iterator(); it.hasNext();) {
+ ((ScanListener) it.next()).finishedScan();
+ }
+ }
+
}
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.