Author: bago
Date: Wed Oct 4 07:56:47 2006
New Revision: 452905
URL: http://svn.apache.org/viewvc?view=rev&rev=452905
Log:
Moved enabling interfaces to the "wiring" package.
Removed services from SPF1Data.
Introduced a WiringService (in the wiring package).
A component (Factory) creating childs to be serviced can use
WiringService.wire(Object).
Packages changes, names changes and few more refactoring have to be done.
Added:
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/DNSServiceEnabled.java
(with props)
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/LogEnabled.java
- copied, changed from r452266,
james/jspf/trunk/src/main/java/org/apache/james/jspf/core/LogEnabled.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/SPFCheckEnabled.java
(with props)
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringService.java
(with props)
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringServiceTable.java
(with props)
Removed:
james/jspf/trunk/src/main/java/org/apache/james/jspf/core/LogEnabled.java
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/core/DNSService.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/core/Directive.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/DefaultSPF1Parser.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/DefaultTermsFactory.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/GenericMechanism.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
james/jspf/trunk/src/test/java/org/apache/james/jspf/SPF1ParserTest.java
james/jspf/trunk/src/test/java/org/apache/james/jspf/core/SPF1DataTest.java
Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java Wed Oct 4
07:56:47 2006
@@ -37,15 +37,18 @@
import org.apache.james.jspf.localpolicy.TrustedForwarderPolicy;
import org.apache.james.jspf.macro.MacroExpand;
import org.apache.james.jspf.parser.DefaultSPF1Parser;
+import org.apache.james.jspf.parser.DefaultTermsFactory;
+import org.apache.james.jspf.wiring.DNSServiceEnabled;
+import org.apache.james.jspf.wiring.LogEnabled;
+import org.apache.james.jspf.wiring.SPFCheckEnabled;
+import org.apache.james.jspf.wiring.WiringServiceTable;
import java.util.Iterator;
import java.util.List;
/**
* This class is used to generate a SPF-Test and provided all intressting data.
- *
*/
-
public class SPF implements SPFChecker {
private DNSService dnsProbe;
@@ -85,7 +88,15 @@
* @param logger the logger to use
*/
public SPF(DNSService dnsProbe, Logger logger) {
- this(dnsProbe, new DefaultSPF1Parser(logger), logger);
+ super();
+ this.dnsProbe = dnsProbe;
+ this.log = logger;
+ WiringServiceTable wiringService = new WiringServiceTable();
+ wiringService.put(LogEnabled.class, this.log);
+ wiringService.put(DNSServiceEnabled.class, this.dnsProbe);
+ this.parser = new DefaultSPF1Parser(logger, new
DefaultTermsFactory(this.log, wiringService));
+ // We add this after the parser creation because services cannot be
null
+ wiringService.put(SPFCheckEnabled.class, this.parser);
}
@@ -122,7 +133,8 @@
try {
// Setup the data
- spfData = new SPF1Data(mailFrom, hostName, ipAddress, dnsProbe,
this);
+ spfData = new SPF1Data(mailFrom, hostName, ipAddress);
+ spfData.enableDNSService(dnsProbe);
SPFInternalResult res = checkSPF(spfData);
resultChar = res.getResultChar();
result = SPF1Utils.resultToName(resultChar);
@@ -173,7 +185,7 @@
}
// Get the raw dns txt entry which contains a spf entry
- String spfDnsEntry =
getSpfRecord(spfData.getDnsProbe(),spfData.getCurrentDomain(),
+ String spfDnsEntry = getSpfRecord(dnsProbe,spfData.getCurrentDomain(),
SPF1Constants.SPF_VERSION);
// No SPF-Record found
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/core/DNSService.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/core/DNSService.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/core/DNSService.java
(original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/core/DNSService.java
Wed Oct 4 07:56:47 2006
@@ -30,7 +30,7 @@
/**
* The exception thrown on timeout.
*/
- public class TimeoutException extends Exception {
+ public static class TimeoutException extends Exception {
}
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/core/Directive.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/core/Directive.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/core/Directive.java
(original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/core/Directive.java
Wed Oct 4 07:56:47 2006
@@ -25,7 +25,7 @@
import org.apache.james.jspf.exceptions.TempErrorException;
/**
- *
+ * A Directive is a mechanism with a resulting qualifier.
*/
public class Directive {
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java
(original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java Wed
Oct 4 07:56:47 2006
@@ -25,6 +25,7 @@
import org.apache.james.jspf.exceptions.NoneException;
import org.apache.james.jspf.exceptions.PermErrorException;
import org.apache.james.jspf.macro.MacroData;
+import org.apache.james.jspf.wiring.DNSServiceEnabled;
import java.util.Iterator;
import java.util.List;
@@ -36,11 +37,7 @@
*
*/
-public class SPF1Data implements MacroData {
-
- private DNSService dnsProbe;
-
- private SPFChecker spfProbe;
+public class SPF1Data implements MacroData, DNSServiceEnabled {
private String ipAddress = ""; // also used for (i)<sending-host>
@@ -77,6 +74,8 @@
private boolean ignoreExplanation = false;
+ private DNSService dnsProbe;
+
/**
* Build the SPF1Data from the given parameters
*
@@ -93,14 +92,11 @@
* @throws NoneException
* Get thrown if no valid emailaddress get passed
*/
- public SPF1Data(String mailFrom, String heloDomain, String clientIP,
- DNSService dnsProbe, SPFChecker spfProbe) throws
PermErrorException, NoneException {
+ public SPF1Data(String mailFrom, String heloDomain, String clientIP)
throws PermErrorException, NoneException {
super();
this.mailFrom = mailFrom.trim();
this.hostName = heloDomain.trim();
this.ipAddress = IPAddr.getProperIpAddress(clientIP.trim());
- this.dnsProbe = dnsProbe;
- this.spfProbe = spfProbe;
try {
// get the in Address
@@ -330,15 +326,6 @@
}
/**
- * Get the used DNSService
- *
- * @return dnsProbe The DNSService
- */
- public DNSService getDnsProbe() {
- return dnsProbe;
- }
-
- /**
* Set the explanation which will returned when a fail match
*
* @param explanation
@@ -414,12 +401,10 @@
}
/**
- * Return the SPF checker to be used in recursive lookups
- *
- * @return the spf checker
+ * @see
org.apache.james.jspf.wiring.DNSServiceEnabled#enableDNSService(org.apache.james.jspf.core.DNSService)
*/
- public SPFChecker getSpfProbe() {
- return spfProbe;
+ public void enableDNSService(DNSService service) {
+ this.dnsProbe = service;
}
-
+
}
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/DefaultSPF1Parser.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/DefaultSPF1Parser.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/DefaultSPF1Parser.java
(original)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/DefaultSPF1Parser.java
Wed Oct 4 07:56:47 2006
@@ -116,9 +116,10 @@
*
* @param loggerThe logger to use
*/
- public DefaultSPF1Parser(Logger logger) {
- log = logger;
- termsFactory = new DefaultTermsFactory(logger);
+ public DefaultSPF1Parser(Logger logger, TermsFactory termsFactory) {
+ this.log = logger;
+ this.termsFactory = termsFactory;
+
/**
* ABNF: mechanism = ( all / include / A / MX / PTR / IP4 / IP6 /
exists )
*/
@@ -337,6 +338,7 @@
try {
return termsFactory.createTerm(c, subres);
} catch (InstantiationException e) {
+ e.printStackTrace();
// TODO is it ok to use a Runtime for this? Or should we
use a PermError here?
throw new IllegalStateException("Unexpected error creating
term: " + e.getMessage());
}
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/DefaultTermsFactory.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/DefaultTermsFactory.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/DefaultTermsFactory.java
(original)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/parser/DefaultTermsFactory.java
Wed Oct 4 07:56:47 2006
@@ -21,9 +21,11 @@
import org.apache.james.jspf.core.Configurable;
import org.apache.james.jspf.core.Configuration;
-import org.apache.james.jspf.core.LogEnabled;
import org.apache.james.jspf.core.Logger;
import org.apache.james.jspf.exceptions.PermErrorException;
+import org.apache.james.jspf.wiring.LogEnabled;
+import org.apache.james.jspf.wiring.WiringService;
+import org.apache.james.jspf.wiring.WiringServiceTable;
import java.io.IOException;
import java.io.InputStream;
@@ -44,9 +46,26 @@
private Collection modifiersCollection;
private Logger log;
+
+ private WiringService wiringService;
public DefaultTermsFactory(Logger log) {
this.log = log;
+ this.wiringService = new WiringServiceTable();
+ ((WiringServiceTable) this.wiringService).put(LogEnabled.class, log);
+ init();
+ }
+
+ public DefaultTermsFactory(Logger log, WiringService wiringService) {
+ this.log = log;
+ this.wiringService = wiringService;
+ init();
+ }
+
+ /**
+ * Initialize the factory and the services
+ */
+ private void init() {
try {
InputStream is = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(termFile);
@@ -114,9 +133,14 @@
public Object createTerm(TermDefinition termDef, Configuration subres)
throws PermErrorException, InstantiationException {
try {
Object term = termDef.getTermDef().newInstance();
- if (term instanceof LogEnabled) {
- ((LogEnabled) term).enableLogging(log);
+
+ try {
+ wiringService.wire(term);
+ } catch (WiringService.WiringServiceException e) {
+ throw new InstantiationException(
+ "Unexpected error adding dependencies to term: " +
e.getMessage());
}
+
if (term instanceof Configurable) {
if (subres == null || subres.groupCount() == 0) {
((Configurable) term).config(null);
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java
(original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java
Wed Oct 4 07:56:47 2006
@@ -28,6 +28,7 @@
import org.apache.james.jspf.exceptions.TempErrorException;
import org.apache.james.jspf.util.Inet6Util;
import org.apache.james.jspf.util.SPFTermsRegexps;
+import org.apache.james.jspf.wiring.DNSServiceEnabled;
import java.util.ArrayList;
import java.util.List;
@@ -36,7 +37,7 @@
* This class represent the a mechanism
*
*/
-public class AMechanism extends GenericMechanism {
+public class AMechanism extends GenericMechanism implements DNSServiceEnabled {
/**
* ABNF: A = "a" [ ":" domain-spec ] [ dual-cidr-length ]
@@ -49,6 +50,8 @@
private int ip6cidr;
+ protected DNSService dnsService;
+
/**
*
* @see
org.apache.james.jspf.core.GenericMechanism#run(org.apache.james.jspf.core.SPF1Data)
@@ -68,7 +71,7 @@
IPAddr checkAddress = IPAddr.getAddress(spfData.getIpAddress(),
getIp4cidr());
- List aRecords = getARecords(spfData.getDnsProbe(),host);
+ List aRecords = getARecords(dnsService,host);
// no a records just return null
if (aRecords == null) {
@@ -82,7 +85,7 @@
IPAddr checkAddress = IPAddr.getAddress(spfData.getIpAddress(),
getIp6cidr());
- List aaaaRecords = getAAAARecords(spfData.getDnsProbe(), host);
+ List aaaaRecords = getAAAARecords(dnsService, host);
// no aaaa records just return false
if (aaaaRecords == null) {
@@ -245,6 +248,13 @@
}
}
return listAData;
+ }
+
+ /**
+ * @see
org.apache.james.jspf.wiring.DNSServiceEnabled#enableDNSService(org.apache.james.jspf.core.DNSService)
+ */
+ public void enableDNSService(DNSService service) {
+ this.dnsService = service;
}
}
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
(original)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
Wed Oct 4 07:56:47 2006
@@ -26,6 +26,7 @@
import org.apache.james.jspf.exceptions.TempErrorException;
import org.apache.james.jspf.macro.MacroExpand;
import org.apache.james.jspf.util.SPFTermsRegexps;
+import org.apache.james.jspf.wiring.DNSServiceEnabled;
import java.util.List;
@@ -33,13 +34,15 @@
* This class represent the exists mechanism
*
*/
-public class ExistsMechanism extends GenericMechanism {
+public class ExistsMechanism extends GenericMechanism implements
DNSServiceEnabled {
/**
* ABNF: exists = "exists" ":" domain-spec
*/
public static final String REGEX = "[eE][xX][iI][sS][tT][sS]" + "\\:"
+ SPFTermsRegexps.DOMAIN_SPEC_REGEX;
+
+ private DNSService dnsService;
/**
*
@@ -58,7 +61,7 @@
host = new MacroExpand(spfData, log).expandDomain(host);
try {
- aRecords = spfData.getDnsProbe().getRecords(host,DNSService.A);
+ aRecords = dnsService.getRecords(host,DNSService.A);
} catch (DNSService.TimeoutException e) {
return false;
}
@@ -77,5 +80,13 @@
public String toString() {
return "exists:"+getDomain();
}
+
+ /**
+ * @see
org.apache.james.jspf.wiring.DNSServiceEnabled#enableDNSService(org.apache.james.jspf.core.DNSService)
+ */
+ public void enableDNSService(DNSService service) {
+ this.dnsService = service;
+ }
+
}
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExpModifier.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
(original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
Wed Oct 4 07:56:47 2006
@@ -21,7 +21,6 @@
package org.apache.james.jspf.terms;
import org.apache.james.jspf.core.DNSService;
-import org.apache.james.jspf.core.LogEnabled;
import org.apache.james.jspf.core.Logger;
import org.apache.james.jspf.core.SPF1Constants;
import org.apache.james.jspf.core.SPF1Data;
@@ -29,6 +28,8 @@
import org.apache.james.jspf.exceptions.TempErrorException;
import org.apache.james.jspf.macro.MacroExpand;
import org.apache.james.jspf.util.SPFTermsRegexps;
+import org.apache.james.jspf.wiring.DNSServiceEnabled;
+import org.apache.james.jspf.wiring.LogEnabled;
import java.util.List;
@@ -36,7 +37,7 @@
* This class represent the exp modifier
*
*/
-public class ExpModifier extends GenericModifier implements LogEnabled {
+public class ExpModifier extends GenericModifier implements LogEnabled,
DNSServiceEnabled {
/**
* ABNF: explanation = "exp" "=" domain-spec
@@ -46,6 +47,8 @@
private Logger log;
+ private DNSService dnsService;
+
/**
* Generate the explanation and set it in SPF1Data so it can be accessed
* easy later if needed
@@ -70,7 +73,7 @@
try {
host = new MacroExpand(spfData, log).expandDomain(host);
try {
- exp = getTxtCatType(spfData.getDnsProbe(), host);
+ exp = getTxtCatType(dnsService, host);
} catch (TempErrorException e) {
// Nothing todo here.. just return null
return null;
@@ -95,7 +98,7 @@
}
/**
- * @see
org.apache.james.jspf.core.LogEnabled#enableLogging(org.apache.james.jspf.core.Logger)
+ * @see
org.apache.james.jspf.wiring.LogEnabled#enableLogging(org.apache.james.jspf.core.Logger)
*/
public void enableLogging(Logger logger) {
this.log = logger;
@@ -139,6 +142,13 @@
*/
public String toString() {
return "exp="+getHost();
+ }
+
+ /**
+ * @see
org.apache.james.jspf.wiring.DNSServiceEnabled#enableDNSService(org.apache.james.jspf.core.DNSService)
+ */
+ public void enableDNSService(DNSService service) {
+ this.dnsService = service;
}
}
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/GenericMechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/GenericMechanism.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/GenericMechanism.java
(original)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/GenericMechanism.java
Wed Oct 4 07:56:47 2006
@@ -22,12 +22,12 @@
import org.apache.james.jspf.core.Configurable;
import org.apache.james.jspf.core.Configuration;
-import org.apache.james.jspf.core.LogEnabled;
import org.apache.james.jspf.core.Logger;
import org.apache.james.jspf.core.Mechanism;
import org.apache.james.jspf.core.SPF1Data;
import org.apache.james.jspf.exceptions.PermErrorException;
import org.apache.james.jspf.macro.MacroExpand;
+import org.apache.james.jspf.wiring.LogEnabled;
/**
* This abstract class represent a gerneric mechanism
@@ -92,7 +92,7 @@
}
/**
- * @see
org.apache.james.jspf.core.LogEnabled#enableLogging(org.apache.james.jspf.core.Logger)
+ * @see
org.apache.james.jspf.wiring.LogEnabled#enableLogging(org.apache.james.jspf.core.Logger)
*/
public void enableLogging(Logger logger) {
this.log = logger;
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
(original)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
Wed Oct 4 07:56:47 2006
@@ -22,23 +22,25 @@
import org.apache.james.jspf.core.Configurable;
import org.apache.james.jspf.core.Configuration;
-import org.apache.james.jspf.core.LogEnabled;
import org.apache.james.jspf.core.Logger;
import org.apache.james.jspf.core.Mechanism;
import org.apache.james.jspf.core.SPF1Constants;
import org.apache.james.jspf.core.SPF1Data;
+import org.apache.james.jspf.core.SPFChecker;
import org.apache.james.jspf.exceptions.NeutralException;
import org.apache.james.jspf.exceptions.NoneException;
import org.apache.james.jspf.exceptions.PermErrorException;
import org.apache.james.jspf.exceptions.TempErrorException;
import org.apache.james.jspf.macro.MacroExpand;
import org.apache.james.jspf.util.SPFTermsRegexps;
+import org.apache.james.jspf.wiring.LogEnabled;
+import org.apache.james.jspf.wiring.SPFCheckEnabled;
/**
* This class represent the incude mechanism
*
*/
-public class IncludeMechanism implements Mechanism, Configurable, LogEnabled {
+public class IncludeMechanism implements Mechanism, Configurable, LogEnabled,
SPFCheckEnabled {
/**
* ABNF: include = "include" ":" domain-spec
@@ -50,6 +52,8 @@
protected Logger log;
+ private SPFChecker spfChecker;
+
/**
* Set the host which should be used for include
*
@@ -84,7 +88,7 @@
String res = null;
try {
- res = spfData.getSpfProbe().checkSPF(spfData).getResultChar();
+ res = spfChecker.checkSPF(spfData).getResultChar();
} catch (NoneException e) {
throw new PermErrorException("included checkSPF returned
NoneException");
@@ -129,7 +133,7 @@
}
/**
- * @see
org.apache.james.jspf.core.LogEnabled#enableLogging(org.apache.james.jspf.core.Logger)
+ * @see
org.apache.james.jspf.wiring.LogEnabled#enableLogging(org.apache.james.jspf.core.Logger)
*/
public void enableLogging(Logger logger) {
this.log = logger;
@@ -140,5 +144,12 @@
*/
public String toString() {
return "include:"+getHost();
+ }
+
+ /**
+ * @see
org.apache.james.jspf.wiring.SPFCheckEnabled#enableSPFChecking(org.apache.james.jspf.core.SPFChecker)
+ */
+ public void enableSPFChecking(SPFChecker checker) {
+ this.spfChecker = checker;
}
}
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/MXMechanism.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
(original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
Wed Oct 4 07:56:47 2006
@@ -62,7 +62,7 @@
// get the ipAddress
checkAddress = IPAddr.getAddress(spfData.getIpAddress(), getIp4cidr());
- List mxRecords = getMXRecords(spfData.getDnsProbe(), host);
+ List mxRecords = getMXRecords(dnsService, host);
// no mx record found
if (mxRecords == null) return false;
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
(original)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
Wed Oct 4 07:56:47 2006
@@ -26,6 +26,7 @@
import org.apache.james.jspf.exceptions.PermErrorException;
import org.apache.james.jspf.exceptions.TempErrorException;
import org.apache.james.jspf.util.SPFTermsRegexps;
+import org.apache.james.jspf.wiring.DNSServiceEnabled;
import java.util.ArrayList;
import java.util.List;
@@ -34,13 +35,15 @@
* This class represent the ptr mechanism
*
*/
-public class PTRMechanism extends GenericMechanism {
+public class PTRMechanism extends GenericMechanism implements
DNSServiceEnabled {
/**
* ABNF: PTR = "ptr" [ ":" domain-spec ]
*/
public static final String REGEX = "[pP][tT][rR]" + "(?:\\:"
+ SPFTermsRegexps.DOMAIN_SPEC_REGEX + ")?";
+
+ private DNSService dnsService;
/**
* @see
org.apache.james.jspf.core.Mechanism#run(org.apache.james.jspf.core.SPF1Data)
@@ -59,16 +62,16 @@
try {
// Get PTR Records for the ipAddress which is provided by SPF1Data
IPAddr ip = IPAddr.getAddress(spfData.getIpAddress());
- List domainList =
spfData.getDnsProbe().getRecords(ip.getReverseIP(), DNSService.PTR);
+ List domainList = dnsService.getRecords(ip.getReverseIP(),
DNSService.PTR);
// No PTR records found
if (domainList == null) return false;
// check if the maximum lookup count is reached
- if (spfData.getDnsProbe().getRecordLimit() > 0 &&
domainList.size() > spfData.getDnsProbe().getRecordLimit()) {
+ if (dnsService.getRecordLimit() > 0 && domainList.size() >
dnsService.getRecordLimit()) {
// Truncate the PTR list to getRecordLimit.
// See #ptr-limit rfc4408 test
- domainList = domainList.subList(0,
spfData.getDnsProbe().getRecordLimit()-1);
+ domainList = domainList.subList(0,
dnsService.getRecordLimit()-1);
// throw new PermErrorException("Maximum PTR lookup count
reached");
}
@@ -78,11 +81,11 @@
// check if the connecting ip is ip6. If so lookup AAAA record
if (IPAddr.isIPV6(spfData.getIpAddress())) {
// Get aaaa record for this
- aList = spfData.getDnsProbe().getRecords(
+ aList = dnsService.getRecords(
(String) domainList.get(i), DNSService.AAAA);
} else {
// Get a record for this
- aList = spfData.getDnsProbe().getRecords(
+ aList = dnsService.getRecords(
(String) domainList.get(i), DNSService.A);
}
if (aList != null) {
@@ -110,5 +113,13 @@
}
}
+
+ /**
+ * @see
org.apache.james.jspf.wiring.DNSServiceEnabled#enableDNSService(org.apache.james.jspf.core.DNSService)
+ */
+ public void enableDNSService(DNSService service) {
+ this.dnsService = service;
+ }
+
}
Modified:
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
(original)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
Wed Oct 4 07:56:47 2006
@@ -20,21 +20,23 @@
package org.apache.james.jspf.terms;
-import org.apache.james.jspf.core.LogEnabled;
import org.apache.james.jspf.core.Logger;
import org.apache.james.jspf.core.SPF1Data;
+import org.apache.james.jspf.core.SPFChecker;
import org.apache.james.jspf.exceptions.NeutralException;
import org.apache.james.jspf.exceptions.NoneException;
import org.apache.james.jspf.exceptions.PermErrorException;
import org.apache.james.jspf.exceptions.TempErrorException;
import org.apache.james.jspf.macro.MacroExpand;
import org.apache.james.jspf.util.SPFTermsRegexps;
+import org.apache.james.jspf.wiring.LogEnabled;
+import org.apache.james.jspf.wiring.SPFCheckEnabled;
/**
* This class represent the redirect modifier
*
*/
-public class RedirectModifier extends GenericModifier implements LogEnabled {
+public class RedirectModifier extends GenericModifier implements LogEnabled,
SPFCheckEnabled {
/**
* ABNF: redirect = "redirect" "=" domain-spec
@@ -44,6 +46,8 @@
private Logger log;
+ private SPFChecker spfChecker;
+
/**
* Set the host which should be used for redirection and set it in SPF1Data
* so it can be accessed easy later if needed
@@ -73,7 +77,7 @@
String res = null;
try {
- res = spfData.getSpfProbe().checkSPF(spfData).getResultChar();
+ res = spfChecker.checkSPF(spfData).getResultChar();
} catch (NoneException e) {
// no spf record assigned to the redirect domain
throw new PermErrorException(
@@ -103,7 +107,7 @@
/**
- * @see
org.apache.james.jspf.core.LogEnabled#enableLogging(org.apache.james.jspf.core.Logger)
+ * @see
org.apache.james.jspf.wiring.LogEnabled#enableLogging(org.apache.james.jspf.core.Logger)
*/
public void enableLogging(Logger logger) {
this.log = logger;
@@ -115,4 +119,12 @@
public String toString() {
return "redirect="+getHost();
}
+
+ /**
+ * @see
org.apache.james.jspf.wiring.SPFCheckEnabled#enableSPFChecking(org.apache.james.jspf.core.SPFChecker)
+ */
+ public void enableSPFChecking(SPFChecker checker) {
+ this.spfChecker = checker;
+ }
+
}
Added:
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/DNSServiceEnabled.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/DNSServiceEnabled.java?view=auto&rev=452905
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/DNSServiceEnabled.java
(added)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/DNSServiceEnabled.java
Wed Oct 4 07:56:47 2006
@@ -0,0 +1,36 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jspf.wiring;
+
+import org.apache.james.jspf.core.DNSService;
+
+/**
+ * Components that need to log can implement this interface so that
+ * the container will provide the DNSService
+ */
+public interface DNSServiceEnabled {
+ /**
+ * Provide component with a DNSService.
+ *
+ * @param service
+ * the dns service. Must not be <code>null</code>.
+ */
+ void enableDNSService(DNSService service);
+}
\ No newline at end of file
Propchange:
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/DNSServiceEnabled.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/LogEnabled.java
(from r452266,
james/jspf/trunk/src/main/java/org/apache/james/jspf/core/LogEnabled.java)
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/LogEnabled.java?view=diff&rev=452905&p1=james/jspf/trunk/src/main/java/org/apache/james/jspf/core/LogEnabled.java&r1=452266&p2=james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/LogEnabled.java&r2=452905
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/core/LogEnabled.java
(original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/LogEnabled.java
Wed Oct 4 07:56:47 2006
@@ -17,7 +17,9 @@
* under the License. *
****************************************************************/
-package org.apache.james.jspf.core;
+package org.apache.james.jspf.wiring;
+
+import org.apache.james.jspf.core.Logger;
/**
* Components that need to log can implement this interface to be provided
Added:
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/SPFCheckEnabled.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/SPFCheckEnabled.java?view=auto&rev=452905
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/SPFCheckEnabled.java
(added)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/SPFCheckEnabled.java
Wed Oct 4 07:56:47 2006
@@ -0,0 +1,36 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jspf.wiring;
+
+import org.apache.james.jspf.core.SPFChecker;
+
+/**
+ * Components that need to log can implement this interface so that
+ * the container will provide the SPFChecker
+ */
+public interface SPFCheckEnabled {
+ /**
+ * Provide component with an SPF Checker.
+ *
+ * @param checker
+ * the checker. Must not be <code>null</code>.
+ */
+ void enableSPFChecking(SPFChecker checker);
+}
\ No newline at end of file
Propchange:
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/SPFCheckEnabled.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringService.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringService.java?view=auto&rev=452905
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringService.java
(added)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringService.java
Wed Oct 4 07:56:47 2006
@@ -0,0 +1,44 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+
+package org.apache.james.jspf.wiring;
+
+/**
+ * This is a service used to wire a component with its dependencies.
+ */
+public interface WiringService {
+
+ public static class WiringServiceException extends Exception {
+
+ public WiringServiceException(String string) {
+ super(string);
+ }
+
+ }
+
+ /**
+ * Called to wire a component
+ *
+ * @param component the component to be wired
+ * @throws WiringServiceException if an error occours
+ */
+ void wire(Object component) throws WiringServiceException;
+
+}
Propchange:
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringService.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringServiceTable.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringServiceTable.java?view=auto&rev=452905
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringServiceTable.java
(added)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringServiceTable.java
Wed Oct 4 07:56:47 2006
@@ -0,0 +1,52 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jspf.wiring;
+
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+public class WiringServiceTable extends Hashtable implements WiringService {
+
+ public void wire(Object component) throws WiringServiceException {
+ Iterator i = keySet().iterator();
+ while (i.hasNext()) {
+ Class enablingClass = (Class) i.next();
+ if (enablingClass.isInstance(component)) {
+ Method[] m = enablingClass.getDeclaredMethods();
+ if (m!=null && m.length == 1 && m[0] != null) {
+ try {
+ m[0].invoke(component, new Object[]
{get(enablingClass)});
+ } catch (IllegalArgumentException e) {
+ throw new WiringServiceException("Illegal argument
invoking enabled service: "+enablingClass.toString());
+ } catch (InvocationTargetException e) {
+ throw new WiringServiceException("Unable to invoke
enabled service: "+enablingClass.toString());
+ } catch (IllegalAccessException e) {
+ throw new WiringServiceException("Unable to invoke
enabled service: "+enablingClass.toString());
+ }
+ }
+ }
+ }
+
+ }
+
+}
Propchange:
james/jspf/trunk/src/main/java/org/apache/james/jspf/wiring/WiringServiceTable.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
--- james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
(original)
+++ james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
Wed Oct 4 07:56:47 2006
@@ -20,8 +20,14 @@
package org.apache.james.jspf;
import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.Logger;
import org.apache.james.jspf.core.SPFRecordParser;
import org.apache.james.jspf.parser.DefaultSPF1Parser;
+import org.apache.james.jspf.parser.DefaultTermsFactory;
+import org.apache.james.jspf.wiring.DNSServiceEnabled;
+import org.apache.james.jspf.wiring.LogEnabled;
+import org.apache.james.jspf.wiring.SPFCheckEnabled;
+import org.apache.james.jspf.wiring.WiringService;
import org.jvyaml.Constructor;
import org.jvyaml.DefaultYAMLFactory;
import org.jvyaml.YAMLFactory;
@@ -42,8 +48,9 @@
SPFYamlTestSuite data;
String test;
- protected SPF spf;
+ protected static SPF spf;
protected static SPFRecordParser parser;
+ private static DNSService dns;
protected AbstractYamlTest(SPFYamlTestSuite def, String test) {
super(def.getComment()+" #"+test);
@@ -117,10 +124,36 @@
System.out.println("testing "+next+":
"+currentTest.get("description"));
if (parser == null) {
- parser = new DefaultSPF1Parser(new ConsoleLogger());
- System.err.println("--------------------------------------------");
+ Logger log = new ConsoleLogger();
+ /* PREVIOUS SLOW WAY
+ enabledServices = new WiringServiceTable();
+ enabledServices.put(LogEnabled.class, log);
+ */
+ parser = new DefaultSPF1Parser(log, new DefaultTermsFactory(log,
new WiringService() {
+
+ public void wire(Object component) throws
WiringServiceException {
+ if (component instanceof LogEnabled) {
+ ((LogEnabled) component).enableLogging(new
ConsoleLogger());
+ }
+ if (component instanceof DNSServiceEnabled) {
+ ((DNSServiceEnabled) component).enableDNSService(dns);
+ }
+ if (component instanceof SPFCheckEnabled) {
+ ((SPFCheckEnabled) component).enableSPFChecking(spf);
+ }
+ }
+
+ }));
}
- spf = new SPF(new LoggingDNSService(getDNSService()), parser, new
ConsoleLogger());
+ dns = new LoggingDNSService(getDNSService());
+ spf = new SPF(dns, parser, new ConsoleLogger());
+ /* PREVIOUS SLOW WAY
+ // we add this after the creation because it is a loop reference
+ enabledServices.remove(DNSServiceEnabled.class);
+ enabledServices.put(DNSServiceEnabled.class, getDNSService());
+ enabledServices.remove(SPFCheckEnabled.class);
+ enabledServices.put(SPFCheckEnabled.class, spf);
+ */
String ip = null;
String sender = null;
Modified:
james/jspf/trunk/src/test/java/org/apache/james/jspf/SPF1ParserTest.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/test/java/org/apache/james/jspf/SPF1ParserTest.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
--- james/jspf/trunk/src/test/java/org/apache/james/jspf/SPF1ParserTest.java
(original)
+++ james/jspf/trunk/src/test/java/org/apache/james/jspf/SPF1ParserTest.java
Wed Oct 4 07:56:47 2006
@@ -32,6 +32,7 @@
import org.apache.james.jspf.exceptions.NoneException;
import org.apache.james.jspf.exceptions.PermErrorException;
import org.apache.james.jspf.parser.DefaultSPF1Parser;
+import org.apache.james.jspf.parser.DefaultTermsFactory;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -51,7 +52,7 @@
}
}
assertNotNull(data);
- parser = new DefaultSPF1Parser(new ConsoleLogger());
+ parser = new DefaultSPF1Parser(new ConsoleLogger(), new
DefaultTermsFactory(new ConsoleLogger()));
}
public static Test suite() throws IOException {
@@ -177,7 +178,7 @@
super();
List tests = loadTests();
Iterator i = tests.iterator();
- SPFRecordParser parser = new DefaultSPF1Parser(new
ConsoleLogger());
+ SPFRecordParser parser = new DefaultSPF1Parser(new
ConsoleLogger(), new DefaultTermsFactory(new ConsoleLogger()));
while (i.hasNext()) {
addTest(new SPF1ParserTest((SPF1RecordTestDef) i.next(),
parser));
}
Modified:
james/jspf/trunk/src/test/java/org/apache/james/jspf/core/SPF1DataTest.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/test/java/org/apache/james/jspf/core/SPF1DataTest.java?view=diff&rev=452905&r1=452904&r2=452905
==============================================================================
--- james/jspf/trunk/src/test/java/org/apache/james/jspf/core/SPF1DataTest.java
(original)
+++ james/jspf/trunk/src/test/java/org/apache/james/jspf/core/SPF1DataTest.java
Wed Oct 4 07:56:47 2006
@@ -30,7 +30,7 @@
* Test method for
'org.apache.james.jspf.core.SPF1Data.getMacroIpAddress()'
*/
public void testGetMacroIpAddress() throws PermErrorException,
NoneException {
- SPF1Data d = new SPF1Data("[EMAIL
PROTECTED]","helodomain.com","2001:DB8::CB01", null, null);
+ SPF1Data d = new SPF1Data("[EMAIL
PROTECTED]","helodomain.com","2001:DB8::CB01");
assertEquals("2.0.0.1.0.D.B.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.C.B.0.1",d.getMacroIpAddress());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]