| 1 |
tdb |
1.8 |
//---PACKAGE DECLARATION--- |
| 2 |
|
|
package uk.ac.ukc.iscream.filter; |
| 3 |
|
|
|
| 4 |
|
|
//---IMPORTS--- |
| 5 |
pjm2 |
1.1 |
import java.io.*; |
| 6 |
|
|
import java.net.*; |
| 7 |
|
|
import java.util.*; |
| 8 |
pjm2 |
1.6 |
import uk.ac.ukc.iscream.core.*; |
| 9 |
tdb |
1.2 |
import uk.ac.ukc.iscream.filter.*; |
| 10 |
ajm |
1.11 |
import uk.ac.ukc.iscream.util.*; |
| 11 |
pjm2 |
1.1 |
|
| 12 |
tdb |
1.8 |
/** |
| 13 |
|
|
* Handle an incoming UDP packet as a separate thread. |
| 14 |
|
|
* |
| 15 |
ajm |
1.12 |
* @author $Author: ajm4 $ |
| 16 |
tdb |
1.13 |
* @version $Id: FilterThread.java,v 1.12 2000/11/30 03:16:17 ajm4 Exp $ |
| 17 |
tdb |
1.8 |
*/ |
| 18 |
tdb |
1.2 |
public class FilterThread extends Thread{ |
| 19 |
pjm2 |
1.1 |
|
| 20 |
tdb |
1.8 |
//---FINAL ATTRIBUTES--- |
| 21 |
|
|
|
| 22 |
|
|
/** |
| 23 |
|
|
* The current CVS revision of this class |
| 24 |
|
|
*/ |
| 25 |
tdb |
1.13 |
public final String REVISION = "$Revision: 1.12 $"; |
| 26 |
tdb |
1.8 |
|
| 27 |
|
|
//---STATIC METHODS--- |
| 28 |
|
|
|
| 29 |
|
|
//---CONSTRUCTORS--- |
| 30 |
|
|
|
| 31 |
pjm2 |
1.3 |
// Class constructor. Obtains the byte[] from a DatagramPacket. |
| 32 |
tdb |
1.10 |
public FilterThread(DatagramPacket packet, Filter parent){ |
| 33 |
|
|
_parent = parent; |
| 34 |
|
|
_rawPacket = packet.getData(); |
| 35 |
|
|
_logger.write(this.toString(), Logger.DEBUG, "created"); |
| 36 |
ajm |
1.9 |
|
| 37 |
pjm2 |
1.1 |
} |
| 38 |
|
|
|
| 39 |
pjm2 |
1.3 |
// Class constructor for passing XML Strings. |
| 40 |
tdb |
1.10 |
public FilterThread(String xml, Filter parent){ |
| 41 |
|
|
_parent = parent; |
| 42 |
|
|
_rawPacket = xml.getBytes(); |
| 43 |
|
|
_logger.write(this.toString(), Logger.DEBUG, "created"); |
| 44 |
pjm2 |
1.1 |
} |
| 45 |
tdb |
1.8 |
|
| 46 |
|
|
//---PUBLIC METHODS--- |
| 47 |
|
|
|
| 48 |
pjm2 |
1.1 |
public void run(){ |
| 49 |
|
|
|
| 50 |
|
|
// Get a string without any null characters in it. |
| 51 |
tdb |
1.10 |
// -- maybe String.trim() would be better here ? |
| 52 |
|
|
String xml = new String(_rawPacket); |
| 53 |
pjm2 |
1.3 |
if (xml.indexOf(0) != -1) { |
| 54 |
tdb |
1.2 |
xml = xml.substring(0, xml.indexOf(0)); |
| 55 |
|
|
} |
| 56 |
|
|
else { |
| 57 |
|
|
xml = xml.substring(0, xml.length()); |
| 58 |
|
|
} |
| 59 |
ajm |
1.9 |
|
| 60 |
pjm2 |
1.3 |
// Use my XMLPacketMaker to make an XMLPacket object. |
| 61 |
tdb |
1.10 |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
| 62 |
pjm2 |
1.1 |
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
| 63 |
tdb |
1.13 |
|
| 64 |
|
|
if(packet != null && PluginFilterManager.getInstance().runFilters(packet)) { |
| 65 |
|
|
// packet is not null |
| 66 |
|
|
// packet was not dropped by a plugin |
| 67 |
|
|
// ... best pass it on ! |
| 68 |
|
|
_parent.receiveXML(xml); |
| 69 |
|
|
} |
| 70 |
|
|
else { |
| 71 |
|
|
// either we had a null, or a plugin dropped it |
| 72 |
|
|
_logger.write(this.toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system."); |
| 73 |
pjm2 |
1.1 |
} |
| 74 |
pjm2 |
1.6 |
|
| 75 |
pjm2 |
1.1 |
} |
| 76 |
tdb |
1.8 |
|
| 77 |
|
|
/** |
| 78 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
| 79 |
|
|
* method to provide clean logging (every class should have this). |
| 80 |
|
|
* |
| 81 |
|
|
* @return the name of this class and its CVS revision |
| 82 |
|
|
*/ |
| 83 |
|
|
public String toString() { |
| 84 |
ajm |
1.9 |
return this.getClass().getName() + "{" + _name + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
| 85 |
tdb |
1.8 |
} |
| 86 |
|
|
|
| 87 |
|
|
//---PRIVATE METHODS--- |
| 88 |
|
|
|
| 89 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
| 90 |
|
|
|
| 91 |
|
|
//---ATTRIBUTES--- |
| 92 |
|
|
|
| 93 |
tdb |
1.10 |
Filter _parent; |
| 94 |
|
|
byte[] _rawPacket; |
| 95 |
|
|
Logger _logger = ReferenceManager.getInstance().getLogger(); |
| 96 |
|
|
String _name = ReferenceManager.getInstance().getName(); |
| 97 |
tdb |
1.8 |
|
| 98 |
|
|
//---STATIC ATTRIBUTES--- |
| 99 |
|
|
|
| 100 |
pjm2 |
1.1 |
} |