james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r531136 - in /james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf: ./ core/ terms/ util/
Date Sun, 22 Apr 2007 02:17:54 GMT
Author: bago
Date: Sat Apr 21 19:17:53 2007
New Revision: 531136

URL: http://svn.apache.org/viewvc?view=rev&rev=531136
Log:
Another step.
Now, when possible, the spfChecker simply push tasks into the spfSession, and they will be
executed somewhere else (or later).
At the moment the SPF.checkSPF method takes care to execute pending jobs.

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/core/Directive.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.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=531136&r1=531135&r2=531136
==============================================================================
--- 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 Sat Apr 21
19:17:53 2007
@@ -56,6 +56,7 @@
 
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.LinkedList;
 
 /**
  * This class is used to generate a SPF-Test and provided all intressting data.
@@ -99,7 +100,7 @@
         wiringService.put(MacroExpandEnabled.class, this.macroExpand);
         this.parser = new DefaultSPF1Parser(logger.getChildLogger("parser"), new DefaultTermsFactory(logger.getChildLogger("termsfactory"),
wiringService));
         // We add this after the parser creation because services cannot be null
-        wiringService.put(SPFCheckEnabled.class, this.parser);
+        wiringService.put(SPFCheckEnabled.class, this);
     }
     
     
@@ -183,12 +184,37 @@
      * @throws NeutralException exception
      */
     public void checkSPF(SPFSession spfData, SPF1Record spfRecord) throws PermErrorException,
NoneException, TempErrorException, NeutralException {
+        LinkedList reversedCheckers = new LinkedList();
         Iterator i = spfRecord.iterator();
         while (i.hasNext()) {
-            SPFChecker m = (SPFChecker) i.next();
+            reversedCheckers.addFirst(i.next());
+        }
+
+        // try to remember the starting checker to better handle recursion.
+        SPFChecker startChecker = spfData.popChecker();
+        if (startChecker != null) {
+            spfData.pushChecker(startChecker);
+        }
 
-            m.checkSPF(spfData);
+        for (int k = 0; k < reversedCheckers.size(); k++) {
+            System.out.println("Pushing checker: "+reversedCheckers.get(k));
+            spfData.pushChecker((SPFChecker) reversedCheckers.get(k));
+        }
+        
+        // To make it asynchronous we should start the executor and 
+        // return here.. instead we run the executor locally by now.
 
+        SPFChecker checker;
+        while ((checker = spfData.popChecker()) != null) {
+            // only execute checkers we added (better recursivity)
+            if (startChecker != null && startChecker == checker) {
+                System.out.println("NOT Executing checker: "+checker);
+                spfData.pushChecker(startChecker);
+                break;
+            } else {
+                System.out.println("Executing checker.: "+checker);
+                checker.checkSPF(spfData);
+            }
         }
     }
 

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Directive.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Directive.java?view=diff&rev=531136&r1=531135&r2=531136
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Directive.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Directive.java
Sat Apr 21 19:17:53 2007
@@ -74,22 +74,39 @@
         // if already have a current result we don't run this
         if (spfData.getCurrentResult() == null) {
 
+            Boolean previous = (Boolean) spfData.getAttribute(ATTRIBUTE_MECHANISM_RESULT);
             spfData.setAttribute(ATTRIBUTE_MECHANISM_RESULT, null);
 
-            mechanism.checkSPF(spfData);
-            
-            Boolean res = (Boolean) spfData.getAttribute(ATTRIBUTE_MECHANISM_RESULT);
-            if (res != null ? res.booleanValue() : true) {
-                if (qualifier.equals("")) {
-                    spfData.setCurrentResult(SPF1Constants.PASS);
-                } else {
-                    spfData.setCurrentResult(qualifier);
+            spfData.pushChecker(new SPFChecker() {
+
+                private Boolean previous;
+
+                public void checkSPF(SPFSession spfData)
+                        throws PermErrorException, TempErrorException,
+                        NeutralException, NoneException {
+                    Boolean res = (Boolean) spfData.getAttribute(ATTRIBUTE_MECHANISM_RESULT);
+                    if (res != null ? res.booleanValue() : true) {
+                        if (qualifier.equals("")) {
+                            spfData.setCurrentResult(SPF1Constants.PASS);
+                        } else {
+                            spfData.setCurrentResult(qualifier);
+                        }
+                        
+                        log.info("Processed directive matched: " + Directive.this + " returned
" + spfData.getCurrentResult());
+                    } else {
+                        log.debug("Processed directive NOT matched: " + this);
+                    }
+                    spfData.setAttribute(ATTRIBUTE_MECHANISM_RESULT, previous);
+                }
+
+                public SPFChecker setPrevious(Boolean previous) {
+                    this.previous = previous;
+                    return this;
                 }
                 
-                log.info("Processed directive matched: " + this + " returned " + spfData.getCurrentResult());
-            } else {
-                log.debug("Processed directive NOT matched: " + this);
-            }
+            }.setPrevious(previous));
+            
+            spfData.pushChecker(mechanism);
 
         }
     }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java?view=diff&rev=531136&r1=531135&r2=531136
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
Sat Apr 21 19:17:53 2007
@@ -26,6 +26,7 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Stack;
 
 /**
  * 
@@ -70,6 +71,8 @@
     private boolean ignoreExplanation = false;
     
     private Map attributes = new HashMap();
+    
+    private Stack checkers = new Stack();
 
     /**
      * Build the SPF1Data from the given parameters
@@ -352,5 +355,22 @@
     public void setAttribute(String key, Object value) {
         this.attributes.put(key, value);
     }
+
+    /**
+     * @param mechanism
+     */
+    public void pushChecker(SPFChecker checker) {
+        checkers.push(checker);
+    }
     
+    /**
+     * @return the last checker
+     */
+    public SPFChecker popChecker() {
+        if (checkers.isEmpty()) {
+            return null;
+        } else {
+            return (SPFChecker) checkers.pop();
+        }
+    }
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java?view=diff&rev=531136&r1=531135&r2=531136
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
Sat Apr 21 19:17:53 2007
@@ -27,6 +27,7 @@
 import org.apache.james.jspf.core.Directive;
 import org.apache.james.jspf.core.IPAddr;
 import org.apache.james.jspf.core.SPFChecker;
+import org.apache.james.jspf.core.SPFCheckerDNSResponseListener;
 import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.exceptions.NeutralException;
 import org.apache.james.jspf.exceptions.NoneException;
@@ -45,7 +46,7 @@
  * This class represent the a mechanism
  * 
  */
-public class AMechanism extends GenericMechanism implements DNSServiceEnabled {
+public class AMechanism extends GenericMechanism implements DNSServiceEnabled, SPFCheckerDNSResponseListener
{
 
     private static final String ATTRIBUTE_AMECHANISM_IPV4CHECK = "AMechanism.ipv4check";
 
@@ -84,7 +85,7 @@
 
                         List aRecords = getARecords(dnsService,host);
                         if (aRecords == null) {
-                            onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host,
DNSService.A)), spfData);
+                            DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.A),
spfData, AMechanism.this);
                         } else {
                             onDNSResponse(new DNSResponse(aRecords), spfData);
                         }
@@ -93,7 +94,7 @@
                         
                         List aaaaRecords = getAAAARecords(dnsService, host);
                         if (aaaaRecords == null) {
-                            onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host,
DNSService.AAAA)), spfData);
+                            DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.AAAA),
spfData, AMechanism.this);
                         } else {
                             onDNSResponse(new DNSResponse(aaaaRecords), spfData);
                         }
@@ -250,8 +251,11 @@
     }
 
 
-    private void onDNSResponse(DNSResponse response, SPFSession spfSession)
-        throws PermErrorException, TempErrorException, NoneException {
+    /**
+     * @see org.apache.james.jspf.core.SPFCheckerDNSResponseListener#onDNSResponse(org.apache.james.jspf.core.DNSResponse,
org.apache.james.jspf.core.SPFSession)
+     */
+    public void onDNSResponse(DNSResponse response, SPFSession spfSession)
+        throws PermErrorException, TempErrorException, NoneException, NeutralException {
         List listAData = null;
         try {
             listAData = response.getResponse();

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java?view=diff&rev=531136&r1=531135&r2=531136
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
Sat Apr 21 19:17:53 2007
@@ -25,6 +25,7 @@
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.Directive;
 import org.apache.james.jspf.core.SPFChecker;
+import org.apache.james.jspf.core.SPFCheckerDNSResponseListener;
 import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.exceptions.NeutralException;
 import org.apache.james.jspf.exceptions.NoneException;
@@ -40,7 +41,7 @@
 /**
  * This class represent the exists mechanism
  */
-public class ExistsMechanism extends GenericMechanism implements DNSServiceEnabled {
+public class ExistsMechanism extends GenericMechanism implements DNSServiceEnabled, SPFCheckerDNSResponseListener
{
 
     /**
      * ABNF: exists = "exists" ":" domain-spec
@@ -63,7 +64,7 @@
             public void checkSPF(SPFSession spfData) throws PermErrorException,
                     TempErrorException, NeutralException, NoneException {
                 String host = expandHost(spfData);
-                onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host,DNSService.A)),
spfData);
+                DNSResolver.lookup(dnsService, new DNSRequest(host,DNSService.A), spfData,
ExistsMechanism.this);
             }
             
         };
@@ -73,9 +74,9 @@
     }
 
     /**
-     * @see org.apache.james.jspf.core.Mechanism#onDNSResponse(org.apache.james.jspf.core.DNSResponse,
org.apache.james.jspf.core.SPFSession)
+     * @see org.apache.james.jspf.core.SPFCheckerDNSResponseListener#onDNSResponse(org.apache.james.jspf.core.DNSResponse,
org.apache.james.jspf.core.SPFSession)
      */
-    private void onDNSResponse(DNSResponse response, SPFSession spfSession) throws PermErrorException,
TempErrorException {
+    public void onDNSResponse(DNSResponse response, SPFSession spfSession) throws PermErrorException,
TempErrorException {
         List aRecords;
         
         try {

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java?view=diff&rev=531136&r1=531135&r2=531136
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
Sat Apr 21 19:17:53 2007
@@ -25,6 +25,7 @@
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.SPF1Constants;
 import org.apache.james.jspf.core.SPFChecker;
+import org.apache.james.jspf.core.SPFCheckerDNSResponseListener;
 import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.exceptions.NeutralException;
 import org.apache.james.jspf.exceptions.NoneException;
@@ -42,7 +43,7 @@
  * This class represent the exp modifier
  * 
  */
-public class ExpModifier extends GenericModifier implements DNSServiceEnabled, MacroExpandEnabled
{
+public class ExpModifier extends GenericModifier implements DNSServiceEnabled, MacroExpandEnabled,
SPFCheckerDNSResponseListener {
 
     private static final String ATTRIBUTE_EXPAND_EXPLANATION = "ExpModifier.ExpandExplanation";
 
@@ -94,7 +95,7 @@
                     NoneException, TempErrorException, NeutralException {
                 String host = macroExpand.expand(getHost(), spfData, MacroExpand.DOMAIN);
 
-                onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.TXT)),
spfData);
+                DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.TXT), spfData,
ExpModifier.this);
             }
             
         });
@@ -115,6 +116,10 @@
      * @throws TempErrorException
      *             if the lookup result was "TRY_AGAIN"
      */
+    
+    /**
+     * @see org.apache.james.jspf.core.SPFCheckerDNSResponseListener#onDNSResponse(org.apache.james.jspf.core.DNSResponse,
org.apache.james.jspf.core.SPFSession)
+     */
     public void onDNSResponse(DNSResponse lookup, SPFSession spfData) throws PermErrorException,
TempErrorException, NeutralException, NoneException {
         try {
             List records = lookup.getResponse();
@@ -147,9 +152,13 @@
                             public void checkSPF(SPFSession spfData)
                                     throws PermErrorException, NoneException,
                                     TempErrorException, NeutralException {
-                                String exp = (String) spfData.getAttribute(ATTRIBUTE_EXPAND_EXPLANATION);
-                                String expandedExplanation = macroExpand.expand(exp, spfData,
MacroExpand.EXPLANATION);
-                                spfData.setExplanation(expandedExplanation);
+                                try {
+                                    String exp = (String) spfData.getAttribute(ATTRIBUTE_EXPAND_EXPLANATION);
+                                    String expandedExplanation = macroExpand.expand(exp,
spfData, MacroExpand.EXPLANATION);
+                                    spfData.setExplanation(expandedExplanation);
+                                } catch (PermErrorException e) {
+                                    // ignore syntax error on explanation expansion
+                                }
                             }
                             
                         });

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java?view=diff&rev=531136&r1=531135&r2=531136
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
Sat Apr 21 19:17:53 2007
@@ -67,7 +67,7 @@
     /**
      * @see org.apache.james.jspf.core.SPFChecker#checkSPF(org.apache.james.jspf.core.SPFSession)
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException, TempErrorException,
NoneException {
+    public void checkSPF(SPFSession spfData) throws PermErrorException, TempErrorException,
NoneException, NeutralException {
         // update currentDepth
         spfData.increaseCurrentDepth();      
         
@@ -96,7 +96,10 @@
                     spfData.setCurrentResult(null);
                     
                     try {
+                         System.out.println("===> INCLUDE");
                          spfChecker.checkSPF(spfData);
+                         System.out.println("===> INCLUDE DONE");
+                         
                     } catch (NeutralException e) {
                         throw new PermErrorException("included checkSPF returned NeutralException");
                     } catch (NoneException e) {
@@ -126,12 +129,12 @@
             
         };
         
-        try {
+        // TODO check if this is ok. I removed the catch and all tests still pass.
+//        try {
             DNSResolver.hostExpand(dnsService, macroExpand, getHost(), spfData, MacroExpand.DOMAIN,
checker);
-        } catch (NeutralException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
+//        } catch (NeutralException e) {
+//            // catch neutral exception.
+//        }
     }
 
     /**

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java?view=diff&rev=531136&r1=531135&r2=531136
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
Sat Apr 21 19:17:53 2007
@@ -26,6 +26,7 @@
 import org.apache.james.jspf.core.Directive;
 import org.apache.james.jspf.core.IPAddr;
 import org.apache.james.jspf.core.SPFChecker;
+import org.apache.james.jspf.core.SPFCheckerDNSResponseListener;
 import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.exceptions.NeutralException;
 import org.apache.james.jspf.exceptions.NoneException;
@@ -42,7 +43,7 @@
  * This class represent the mx mechanism
  * 
  */
-public class MXMechanism extends AMechanism {
+public class MXMechanism extends AMechanism implements SPFCheckerDNSResponseListener {
 
     private static final String ATTRIBUTE_MX_RECORDS = "MXMechanism.mxRecords";
     private static final String ATTRIBUTE_CHECK_RECORDS = "MXMechanism.checkRecords";
@@ -70,7 +71,7 @@
                 // Get the right host.
                 String host = expandHost(spfData);
                 
-                onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.MX)),
spfData);
+                DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.MX), spfData,
MXMechanism.this);
             }
             
         };
@@ -79,10 +80,10 @@
     }
 
     /**
-     * @see org.apache.james.jspf.core.Mechanism#onDNSResponse(org.apache.james.jspf.core.SPFSession)
+     * @see org.apache.james.jspf.terms.AMechanism#onDNSResponse(org.apache.james.jspf.core.DNSResponse,
org.apache.james.jspf.core.SPFSession)
      */
-    private void onDNSResponse(DNSResponse response, SPFSession spfSession)
-        throws PermErrorException, TempErrorException {
+    public void onDNSResponse(DNSResponse response, SPFSession spfSession)
+        throws PermErrorException, TempErrorException, NoneException, NeutralException {
         try {
             
             List records = (List) spfSession.getAttribute(ATTRIBUTE_CHECK_RECORDS);
@@ -122,7 +123,7 @@
             while (records.size() > 0 && (mx = (String) records.remove(0)) !=
null && mx.length() > 0) {
                 log.debug("Add MX-Record " + mx + " to list");
     
-                this.onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(mx, isIPv6
? DNSService.AAAA : DNSService.A)), spfSession);
+                DNSResolver.lookup(dnsService, new DNSRequest(mx, isIPv6 ? DNSService.AAAA
: DNSService.A), spfSession, MXMechanism.this);
                 return;
                 
             }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java?view=diff&rev=531136&r1=531135&r2=531136
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
Sat Apr 21 19:17:53 2007
@@ -26,6 +26,7 @@
 import org.apache.james.jspf.core.Directive;
 import org.apache.james.jspf.core.IPAddr;
 import org.apache.james.jspf.core.SPFChecker;
+import org.apache.james.jspf.core.SPFCheckerDNSResponseListener;
 import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.exceptions.NeutralException;
 import org.apache.james.jspf.exceptions.NoneException;
@@ -42,7 +43,7 @@
  * This class represent the ptr mechanism
  * 
  */
-public class PTRMechanism extends GenericMechanism implements DNSServiceEnabled {
+public class PTRMechanism extends GenericMechanism implements DNSServiceEnabled, SPFCheckerDNSResponseListener
{
 
     private static final String ATTRIBUTE_CURRENT_DOMAIN = "PTRMechanism.currentDomain";
 
@@ -80,8 +81,7 @@
                 
                 spfData.setAttribute(ATTRIBUTE_EXPANDED_HOST, host);
 
-                DNSResponse response = DNSResolver.lookup(dnsService, new DNSRequest(ip.getReverseIP(),
DNSService.PTR));
-                onDNSResponse(response, spfData);
+                DNSResolver.lookup(dnsService, new DNSRequest(ip.getReverseIP(), DNSService.PTR),
spfData, PTRMechanism.this);
             }
             
         };
@@ -97,10 +97,10 @@
     }
 
     /**
-     * @see org.apache.james.jspf.core.Mechanism#onDNSResponse(org.apache.james.jspf.core.DNSResponse,
org.apache.james.jspf.core.SPFSession)
+     * @see org.apache.james.jspf.core.SPFCheckerDNSResponseListener#onDNSResponse(org.apache.james.jspf.core.DNSResponse,
org.apache.james.jspf.core.SPFSession)
      */
-    private void onDNSResponse(DNSResponse response, SPFSession spfSession)
-            throws PermErrorException, TempErrorException {
+    public void onDNSResponse(DNSResponse response, SPFSession spfSession)
+            throws PermErrorException, TempErrorException, NoneException, NeutralException
{
         
         List domainList = (List) spfSession.getAttribute(ATTRIBUTE_DOMAIN_LIST);
         try {
@@ -169,7 +169,7 @@
                 
                 spfSession.setAttribute(ATTRIBUTE_CURRENT_DOMAIN, currentDomain);
                 
-                onDNSResponse(DNSResolver.lookup(dnsService, dnsRequest), spfSession);
+                DNSResolver.lookup(dnsService, dnsRequest, spfSession, PTRMechanism.this);
                 return;
             } else {
                 spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java?view=diff&rev=531136&r1=531135&r2=531136
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
Sat Apr 21 19:17:53 2007
@@ -92,7 +92,9 @@
 
                             // TODO change this to work asynchronously
                             try {
+                                System.out.println("Redirect...");
                                 spfChecker.checkSPF(spfData);
+                                System.out.println("Redirect... DONE");
                             } catch (NoneException e) {
                                 // no spf record assigned to the redirect domain
                                 throw new PermErrorException(

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java?view=diff&rev=531136&r1=531135&r2=531136
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
Sat Apr 21 19:17:53 2007
@@ -42,20 +42,28 @@
 
     /**
      * This is used temporarily to synchronously obtain a DNSResponse for a DNSRequest
+     * @throws NeutralException 
+     * @throws TempErrorException 
+     * @throws NoneException 
+     * @throws PermErrorException 
      */
-    public static DNSResponse lookup(DNSService service, DNSRequest request) {
+    public static void lookup(DNSService service, DNSRequest request, SPFSession session,
SPFCheckerDNSResponseListener listener) throws PermErrorException, NoneException, TempErrorException,
NeutralException {
+        DNSResponse response;
         try {
-            return new DNSResponse(service.getRecords(request.getHostname(), request.getRecordType()));
+            response = new DNSResponse(service.getRecords(request.getHostname(), request.getRecordType()));
         } catch (TimeoutException e) {
-            return new DNSResponse(e);
+            response = new DNSResponse(e);
         }
+        listener.onDNSResponse(response, session);
     }
     
     public static void hostExpand(DNSService dnsService, MacroExpand macroExpand, String
input, final SPFSession spfSession, boolean isExplanation, final SPFChecker next) throws PermErrorException,
TempErrorException, NeutralException, NoneException {
+        spfSession.pushChecker(next);
         if (input != null) {
             String host = macroExpand.expand(input, spfSession, isExplanation);
             if (host == null) {
-                new SPFCheckerDNSResponseListener() {
+                
+                DNSResolver.lookup(dnsService, new DNSRequest(IPAddr.getAddress(spfSession.getIpAddress()).getReverseIP(),
DNSService.PTR), spfSession,new SPFCheckerDNSResponseListener() {
     
                     private DNSService dnsService;
     
@@ -71,8 +79,7 @@
                                 String record = (String) records.get(0);
                                 spfSession.setAttribute(ATTRIBUTE_MACRO_EXPAND_CHECKED_RECORD,
record);
                                 
-                                DNSResponse resp = DNSResolver.lookup(dnsService, new DNSRequest(record,
ip6 ? DNSService.AAAA : DNSService.A));
-                                new SPFCheckerDNSResponseListener() {
+                                DNSResolver.lookup(dnsService, new DNSRequest(record, ip6
? DNSService.AAAA : DNSService.A), spfSession, new SPFCheckerDNSResponseListener() {
                                     
                                     public void onDNSResponse(DNSResponse response,
                                             SPFSession session) throws PermErrorException,
@@ -97,20 +104,16 @@
                                             // just return the default "unknown".
                                         }
                                         
-                                        next.checkSPF(spfSession);
-    
                                     }
-                                }.onDNSResponse(resp, session);
+                                });
                                 
                             }
                         } catch (TimeoutException e) {
                             // just return the default "unknown".
                             spfSession.setClientDomain("unknown");
-                            next.checkSPF(spfSession);
                         } catch (PermErrorException e) {
                             // just return the default "unknown".
                             spfSession.setClientDomain("unknown");
-                            next.checkSPF(spfSession);
                         }
                         
                     }
@@ -121,12 +124,8 @@
                         return this;
                     }
                     
-                }.setDNSService(dnsService).onDNSResponse(DNSResolver.lookup(dnsService,
new DNSRequest(IPAddr.getAddress(spfSession.getIpAddress()).getReverseIP(), DNSService.PTR)),
spfSession);
-            } else {
-                next.checkSPF(spfSession);
+                }.setDNSService(dnsService));
             }
-        } else {
-            next.checkSPF(spfSession);
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message