noel 2003/06/06 16:52:49
Modified: src/java/org/apache/james/transport/matchers Tag:
branch_2_1_fcs RemoteAddrInNetwork.java
RemoteAddrNotInNetwork.java
Added: src/java/org/apache/james/transport/matchers Tag:
branch_2_1_fcs AbstractNetworkMatcher.java
Log:
New AbstractNetworkMatcher class using NetMatcher. RemoteAddr[Not]InNetwork are now
subclasses.
Revision Changes Path
No revision
No revision
1.3.4.3 +6 -57
jakarta-james/src/java/org/apache/james/transport/matchers/RemoteAddrInNetwork.java
Index: RemoteAddrInNetwork.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/transport/matchers/RemoteAddrInNetwork.java,v
retrieving revision 1.3.4.2
retrieving revision 1.3.4.3
diff -u -r1.3.4.2 -r1.3.4.3
--- RemoteAddrInNetwork.java 8 Mar 2003 21:54:09 -0000 1.3.4.2
+++ RemoteAddrInNetwork.java 6 Jun 2003 23:52:49 -0000 1.3.4.3
@@ -58,72 +58,21 @@
package org.apache.james.transport.matchers;
-import org.apache.mailet.GenericMatcher;
import org.apache.mailet.Mail;
import javax.mail.MessagingException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.Collection;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-import java.util.Vector;
/**
* Checks the IP address of the sending server against a comma-
- * delimited list of IP addresses or domain names.
- * <P>Networks should be indicated with a wildcard *, e.g. 192.168.*
- * <br>Note: The wildcard can go at any level, the matcher will match if the
- * sending host's IP address (as a String based on the octet representation)
- * starts with the String indicated in the configuration file, excluding the
- * wildcard.
- * <p>Multiple addresses can be indicated, e.g: '127.0.0.1,192.168.*,domain.tld'
+ * delimited list of IP addresses, domain names or sub-nets.
+ *
+ * <p>See AbstractNetworkMatcher for details on how to specify
+ * entries.</p>
*
- * @author Serge Knystautas <[EMAIL PROTECTED]>
*/
-public class RemoteAddrInNetwork extends GenericMatcher {
- private Collection networks = null;
-
- public void init() throws MessagingException {
- StringTokenizer st = new StringTokenizer(getCondition(), ", ", false);
- networks = new Vector();
- while (st.hasMoreTokens()) {
- String addr = st.nextToken();
- if (addr.equals("127.0.0.1")) {
- //Add address of local machine as a match
- try {
- InetAddress localaddr = InetAddress.getLocalHost();
- networks.add(localaddr.getHostAddress());
- } catch (UnknownHostException uhe) {
- }
- }
-
- try {
- if (addr.endsWith("*")) {
- addr = addr.substring(0, addr.length() - 1);
- }
- else {
- addr = InetAddress.getByName(addr).getHostAddress();
- }
- networks.add(addr);
- } catch (UnknownHostException uhe) {
- log("Cannot match against invalid domain: " + uhe.getMessage());
- }
- }
- }
-
+public class RemoteAddrInNetwork extends AbstractNetworkMatcher {
public Collection match(Mail mail) {
- String host = mail.getRemoteAddr();
- //Check to see whether it's in any of the networks... needs to be smarter to
- // support subnets better
- for (Iterator i = networks.iterator(); i.hasNext(); ) {
- String networkAddr = i.next().toString();
- if (host.startsWith(networkAddr)) {
- //This is in this network... that's all we need for a match
- return mail.getRecipients();
- }
- }
- //Could not match this to any network
- return null;
+ return matchNetwork(mail.getRemoteAddr()) ? mail.getRecipients() : null;
}
}
1.4.4.3 +6 -57
jakarta-james/src/java/org/apache/james/transport/matchers/RemoteAddrNotInNetwork.java
Index: RemoteAddrNotInNetwork.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/transport/matchers/RemoteAddrNotInNetwork.java,v
retrieving revision 1.4.4.2
retrieving revision 1.4.4.3
diff -u -r1.4.4.2 -r1.4.4.3
--- RemoteAddrNotInNetwork.java 8 Mar 2003 21:54:09 -0000 1.4.4.2
+++ RemoteAddrNotInNetwork.java 6 Jun 2003 23:52:49 -0000 1.4.4.3
@@ -58,72 +58,21 @@
package org.apache.james.transport.matchers;
-import org.apache.mailet.GenericMatcher;
import org.apache.mailet.Mail;
import javax.mail.MessagingException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.Collection;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-import java.util.Vector;
/**
* Checks the IP address of the sending server against a comma-
- * delimited list of IP addresses or domain names.
- * <P>Networks should be indicated with a wildcard *, e.g. 192.168.*
- * <br>Note: The wildcard can go at any level, the matcher will match if the
- * sending host's IP address (as a String based on the octet representation)
- * starts with the String indicated in the configuration file, excluding the
- * wildcard.
- * <p>Multiple addresses can be indicated, e.g: '127.0.0.1,192.168.*,domain.tld'
+ * delimited list of IP addresses, domain names or sub-nets.
+ *
+ * <p>See AbstractNetworkMatcher for details on how to specify
+ * entries.</p>
*
- * @author Serge Knystautas <[EMAIL PROTECTED]>
*/
-public class RemoteAddrNotInNetwork extends GenericMatcher {
- private Collection networks = null;
-
- public void init() throws MessagingException {
- StringTokenizer st = new StringTokenizer(getCondition(), ", ", false);
- networks = new Vector();
- while (st.hasMoreTokens()) {
- String addr = st.nextToken();
- if (addr.equals("127.0.0.1")) {
- //Add address of local machine as a match
- try {
- InetAddress localaddr = InetAddress.getLocalHost();
- networks.add(localaddr.getHostAddress());
- } catch (UnknownHostException uhe) {
- }
- }
-
- try {
- if (addr.endsWith("*")) {
- addr = addr.substring(0, addr.length() - 1);
- }
- else {
- addr = InetAddress.getByName(addr).getHostAddress();
- }
- networks.add(addr);
- } catch (UnknownHostException uhe) {
- log("Cannot match against invalid domain: " + uhe.getMessage());
- }
- }
- }
-
+public class RemoteAddrNotInNetwork extends AbstractNetworkMatcher {
public Collection match(Mail mail) {
- String host = mail.getRemoteAddr();
- //Check to see whether it's in any of the networks... needs to be smarter to
- // support subnets better
- for (Iterator i = networks.iterator(); i.hasNext(); ) {
- String invalidNetwork = i.next().toString();
- if (host.startsWith(invalidNetwork)) {
- //This is in this network... that's all we need for a failed match
- return null;
- }
- }
- //Could not match this to any network
- return mail.getRecipients();
+ return matchNetwork(mail.getRemoteAddr()) ? null : mail.getRecipients();
}
}
No revision
No revision
1.1.2.1 +0 -0
jakarta-james/src/java/org/apache/james/transport/matchers/AbstractNetworkMatcher.java
Index: AbstractNetworkMatcher.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/transport/matchers/AbstractNetworkMatcher.java,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -r1.1 -r1.1.2.1
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]