Author: bago
Date: Mon Apr 30 09:36:41 2007
New Revision: 533792

URL: http://svn.apache.org/viewvc?view=rev&rev=533792
Log:
Removed log of the result before returning the SPFResult. In case of 
asynchronous processing the getResult from the log statement will make the 
thread to wait for the result to be completed (join the resolver thread), 
invalidating the asynchronous behaviour.
Moved the InitialChecks before the retriever, and added some check to the 
checker (to avoid relying on specific dnsservice implementation behaviours).

Modified:
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java
    
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/InitialChecksPolicy.java

Modified: 
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java
URL: 
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java?view=diff&rev=533792&r1=533791&r2=533792
==============================================================================
--- 
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java 
(original)
+++ 
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java 
Mon Apr 30 09:36:41 2007
@@ -323,8 +323,9 @@
         
         executor.execute(spfData, ret);
 
-        log.info("[ipAddress=" + ipAddress + "] [mailFrom=" + mailFrom
-                + "] [helo=" + hostName + "] => " + ret.getResult());
+        // if we call ret.getResult it waits the result ;-)
+//        log.info("[ipAddress=" + ipAddress + "] [mailFrom=" + mailFrom
+//                + "] [helo=" + hostName + "] => " + ret.getResult());
 
         return ret;
 
@@ -356,14 +357,14 @@
         if (override != null) {
             policies.add(new SPFPolicyChecker(override));
         }
-        
+
+        policies.add(new InitialChecksPolicy());
+
         if (mustEquals) {
             policies.add(new SPFStrictCheckerRetriever());
         } else {
             policies.add(new SPFRetriever());
         }
-
-        policies.add(new SPFPolicyChecker(new InitialChecksPolicy()));
 
         if (useBestGuess) {
             policies.add(new SPFPolicyPostFilterChecker(new 
BestGuessPolicy()));

Modified: 
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/InitialChecksPolicy.java
URL: 
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/InitialChecksPolicy.java?view=diff&rev=533792&r1=533791&r2=533792
==============================================================================
--- 
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/InitialChecksPolicy.java
 (original)
+++ 
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/InitialChecksPolicy.java
 Mon Apr 30 09:36:41 2007
@@ -19,30 +19,50 @@
 
 package org.apache.james.jspf.policies;
 
+import org.apache.james.jspf.SPF;
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.SPF1Record;
+import org.apache.james.jspf.core.SPFChecker;
+import org.apache.james.jspf.core.SPFSession;
 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.xbill.DNS.Name;
+import org.xbill.DNS.TextParseException;
 
 /**
  * Run the checks on the validity of the domain
  * This is an override filter to be executed as the first 
  * so it should be added as the last filter.
  */
-public final class InitialChecksPolicy implements Policy {
+public final class InitialChecksPolicy implements SPFChecker {
     
-    /**
-     * @see 
org.apache.james.jspf.policies.Policy#getSPFRecord(java.lang.String)
-     */
-    public SPF1Record getSPFRecord(String currentDomain) throws 
PermErrorException, TempErrorException, NoneException, NeutralException {
-        // Initial checks (spec 4.3)
-        if (currentDomain != null) {
-            String[] labels = currentDomain.split("\\.");
-            for (int i = 0; i < labels.length; i++) {
-                if (labels[i] != null && labels[i].length() > 63) {
-                    throw new NoneException("Domain "+currentDomain+" is 
malformed (label longer than 63 characters)");
+    public DNSLookupContinuation checkSPF(SPFSession spfData)
+            throws PermErrorException, TempErrorException, NeutralException,
+            NoneException {
+        SPF1Record res = (SPF1Record) 
spfData.getAttribute(SPF.ATTRIBUTE_SPF1_RECORD);
+        if (res == null) {
+
+            // Initial checks (spec 4.3)
+            String currentDomain = spfData.getCurrentDomain();
+            if (currentDomain != null) {
+                String[] labels = currentDomain.split("\\.");
+                for (int i = 0; i < labels.length; i++) {
+                    if (labels[i] != null && labels[i].length() > 63) {
+                        throw new NoneException("Domain "+currentDomain+" is 
malformed (label longer than 63 characters)");
+                    }
                 }
+            }
+            
+            if (spfData.getSenderDomain().indexOf('.') < 0) {
+                throw new NoneException("Sender domain 
"+spfData.getSenderDomain()+" is not an FQDN.");
+            }
+            
+            try {
+                Name.fromString(spfData.getSenderDomain());
+            } catch (TextParseException e) {
+                throw new NoneException("Invalid sender domain: 
"+e.getMessage());
             }
         }
         return null;



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to