james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r531177 - in /james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf: ./ core/ macro/ policies/ policies/local/ terms/ util/
Date Sun, 22 Apr 2007 13:39:20 GMT
Author: bago
Date: Sun Apr 22 06:39:18 2007
New Revision: 531177

URL: http://svn.apache.org/viewvc?view=rev&rev=531177
Log:
DNS Lookups are no more a responsibility of SPFChecker / SPFCheckerDNSResponseListener but they simply have to return a DNSLookupContinuation object including informations about the lookup they need and where to start the processing when the response is available.
if an SPFChecker/SPFCheckerDNSResponseListener returns null then it means it completed the processing.

Added:
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSLookupContinuation.java
Removed:
    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
    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/SPFChecker.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerDNSResponseListener.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/NeutralIfNotMatchPolicy.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.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/AllMechanism.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/GenericModifier.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.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/terms/UnknownModifier.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=531177&r1=531176&r2=531177
==============================================================================
--- 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 Sun Apr 22 06:39:18 2007
@@ -20,6 +20,8 @@
 
 package org.apache.james.jspf;
 
+import org.apache.james.jspf.core.DNSLookupContinuation;
+import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.Logger;
 import org.apache.james.jspf.core.SPF1Constants;
@@ -28,6 +30,7 @@
 import org.apache.james.jspf.core.SPF1Record;
 import org.apache.james.jspf.core.SPFChecker;
 import org.apache.james.jspf.core.SPFRecordParser;
+import org.apache.james.jspf.core.DNSService.TimeoutException;
 import org.apache.james.jspf.exceptions.NeutralException;
 import org.apache.james.jspf.exceptions.NoneException;
 import org.apache.james.jspf.exceptions.PermErrorException;
@@ -139,7 +142,48 @@
         try {
             // Setup the data
             spfData = new SPFSession(mailFrom, hostName, ipAddress);
-            checkSPF(spfData);
+            
+            
+            spfData.pushChecker(this);
+            SPFChecker checker;
+            while ((checker = spfData.popChecker()) != null) {
+                // only execute checkers we added (better recursivity)
+                log.debug("Executing checker: "+checker);
+                try {
+                    DNSLookupContinuation cont = checker.checkSPF(spfData);
+                    // if the checker returns a continuation we return it
+                    while (cont != null) {
+                        DNSResponse response;
+                        try {
+                            response = new DNSResponse(dnsProbe.getRecords(
+                                    cont.getRequest().getHostname(), cont.getRequest().getRecordType()));
+                        } catch (TimeoutException e) {
+                            response = new DNSResponse(e);
+                        }
+                        cont = cont.getListener().onDNSResponse(response, spfData);
+                    }
+                } catch (Exception e) {
+                    SPFCheckerExceptionCatcher catcher = spfData.getExceptionCatcher();
+                    if (catcher != null) {
+                        catcher.onException(e, spfData);
+                    } else {
+                        log.debug("Checker execution resulted in unmanaged exception: "+checker+" => "+e);
+                        if (e instanceof PermErrorException) {
+                            throw (PermErrorException) e;
+                        } else if (e instanceof TempErrorException) {
+                            throw (TempErrorException) e;
+                        } else if (e instanceof NeutralException) {
+                            throw (NeutralException) e;
+                        } else if (e instanceof NoneException) {
+                            throw (NoneException) e;
+                        } else {
+                            throw new IllegalStateException(e);
+                        }
+                    }
+                }
+            }
+            
+            
             String resultChar = spfData.getCurrentResult() != null ? spfData.getCurrentResult() : "";
             result = SPF1Utils.resultToName(resultChar);
             explanation = spfData.getExplanation();
@@ -167,24 +211,11 @@
     /**
      * @see org.apache.james.jspf.SPFChecker#checkSPF(org.apache.james.jspf.core.SPFSession)
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException,
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
             NoneException, TempErrorException, NeutralException {
 
         SPF1Record spfRecord = getPolicy().getSPFRecord(spfData.getCurrentDomain());
-        checkSPF(spfData, spfRecord);
-    }
-
-    /**
-     * Check a given spfData with the given spfRecord
-     * 
-     * @param spfData spf data
-     * @param spfRecord record
-     * @throws PermErrorException exception
-     * @throws NoneException exception
-     * @throws TempErrorException exception
-     * @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()) {
@@ -194,36 +225,9 @@
         for (int k = 0; k < reversedCheckers.size(); 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)
-            log.debug("Executing checker: "+checker);
-            try {
-                checker.checkSPF(spfData);
-            } catch (Exception e) {
-                SPFCheckerExceptionCatcher catcher = spfData.getExceptionCatcher();
-                if (catcher != null) {
-                    catcher.onException(e, spfData);
-                } else {
-                    log.debug("Checker execution resulted in unmanaged exception: "+checker+" => "+e);
-                    if (e instanceof PermErrorException) {
-                        throw (PermErrorException) e;
-                    } else if (e instanceof TempErrorException) {
-                        throw (TempErrorException) e;
-                    } else if (e instanceof NeutralException) {
-                        throw (NeutralException) e;
-                    } else if (e instanceof NoneException) {
-                        throw (NeutralException) e;
-                    } else {
-                        throw new IllegalStateException(e);
-                    }
-                }
-            }
-        }
+        // done
+        return null;
     }
 
     /**
@@ -263,7 +267,7 @@
 
         policyFilters.add(new NeutralIfNotMatchPolicy());
 
-        policyFilters.add(new DefaultExplanationPolicy(log, defaultExplanation, macroExpand, dnsProbe));
+        policyFilters.add(new DefaultExplanationPolicy(log, defaultExplanation, macroExpand));
         
         policies.add(new InitialChecksPolicy());
         

Added: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSLookupContinuation.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSLookupContinuation.java?view=auto&rev=531177
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSLookupContinuation.java (added)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSLookupContinuation.java Sun Apr 22 06:39:18 2007
@@ -0,0 +1,41 @@
+/****************************************************************
+ * 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.core;
+
+public class DNSLookupContinuation {
+    
+    private DNSRequest request;
+    private SPFCheckerDNSResponseListener listener;
+
+    public DNSLookupContinuation(DNSRequest request, SPFCheckerDNSResponseListener listener) {
+        this.request = request;
+        this.listener = listener;
+    }
+
+    public DNSRequest getRequest() {
+        return request;
+    }
+
+    public SPFCheckerDNSResponseListener getListener() {
+        return listener;
+    }
+
+    
+}

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=531177&r1=531176&r2=531177
==============================================================================
--- 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 Sun Apr 22 06:39:18 2007
@@ -32,7 +32,7 @@
 
     private final class MechanismResultChecker implements SPFChecker {
 
-        public void checkSPF(SPFSession spfData)
+        public DNSLookupContinuation checkSPF(SPFSession spfData)
                 throws PermErrorException, TempErrorException,
                 NeutralException, NoneException {
             Boolean res = (Boolean) spfData.getAttribute(ATTRIBUTE_MECHANISM_RESULT);
@@ -47,6 +47,7 @@
             } else {
                 log.debug("Processed directive NOT matched: " + this);
             }
+            return null;
         }
         
     }
@@ -93,7 +94,7 @@
      * @throws NoneException get thrown if a NoneException should returned;
      * @throws NeutralException 
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException,
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
             TempErrorException, NoneException, NeutralException {
         // if already have a current result we don't run this
         if (spfData.getCurrentResult() == null) {
@@ -105,6 +106,7 @@
             spfData.pushChecker(mechanism);
 
         }
+        return null;
     }
 
     /**

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFChecker.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFChecker.java?view=diff&rev=531177&r1=531176&r2=531177
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFChecker.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFChecker.java Sun Apr 22 06:39:18 2007
@@ -44,7 +44,7 @@
      *             Get thrown if the result should be neutral
      * @throws NoneException 
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException,
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
             TempErrorException, NeutralException, NoneException;
 
 //    /**

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerDNSResponseListener.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerDNSResponseListener.java?view=diff&rev=531177&r1=531176&r2=531177
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerDNSResponseListener.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerDNSResponseListener.java Sun Apr 22 06:39:18 2007
@@ -42,6 +42,6 @@
      * @throws NeutralException  
      *             Get thrown if the result should be neutral
      */
-    public void onDNSResponse(DNSResponse response, SPFSession session) throws PermErrorException, NoneException, TempErrorException, NeutralException;
+    public DNSLookupContinuation onDNSResponse(DNSResponse response, SPFSession session) throws PermErrorException, NoneException, TempErrorException, NeutralException;
 
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java?view=diff&rev=531177&r1=531176&r2=531177
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java Sun Apr 22 06:39:18 2007
@@ -27,15 +27,25 @@
  */
 
 import org.apache.james.jspf.SPF1Utils;
+import org.apache.james.jspf.core.DNSLookupContinuation;
+import org.apache.james.jspf.core.DNSRequest;
+import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.IPAddr;
 import org.apache.james.jspf.core.Logger;
+import org.apache.james.jspf.core.SPFCheckerDNSResponseListener;
 import org.apache.james.jspf.core.SPFSession;
+import org.apache.james.jspf.core.DNSService.TimeoutException;
+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.util.SPFTermsRegexps;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -80,6 +90,85 @@
         macroLettersPattern = Pattern.compile(SPFTermsRegexps.MACRO_LETTER_PATTERN);
         log = logger;
         this.dnsProbe = dnsProbe;
+    }
+    
+
+    private static final class AResponseListener implements
+            SPFCheckerDNSResponseListener {
+        public DNSLookupContinuation onDNSResponse(DNSResponse response, SPFSession session)
+                throws PermErrorException, NoneException, TempErrorException,
+                NeutralException {
+            // just return the default "unknown" if we cannot find anything
+            // later
+            session.setClientDomain("unknown");
+            try {
+                List records = response.getResponse();
+                if (records != null && records.size() > 0) {
+                    Iterator i = records.iterator();
+                    while (i.hasNext()) {
+                        String next = (String) i.next();
+                        if (IPAddr.getAddress(session.getIpAddress())
+                                .toString().equals(
+                                        IPAddr.getAddress(next).toString())) {
+                            session
+                                    .setClientDomain((String) session
+                                            .getAttribute(ATTRIBUTE_MACRO_EXPAND_CHECKED_RECORD));
+                            break;
+                        }
+                    }
+                }
+            } catch (TimeoutException e) {
+                // just return the default "unknown".
+            } catch (PermErrorException e) {
+                // just return the default "unknown".
+            }
+            return null;
+        }
+    }
+
+    private static final class PTRResponseListener implements
+            SPFCheckerDNSResponseListener {
+
+        public DNSLookupContinuation onDNSResponse(DNSResponse response, SPFSession session)
+                throws PermErrorException, NoneException, TempErrorException,
+                NeutralException {
+
+            try {
+                boolean ip6 = IPAddr.isIPV6(session.getIpAddress());
+                List records = response.getResponse();
+
+                if (records != null && records.size() > 0) {
+                    String record = (String) records.get(0);
+                    session.setAttribute(ATTRIBUTE_MACRO_EXPAND_CHECKED_RECORD,
+                            record);
+
+                    return new DNSLookupContinuation(new DNSRequest(record,
+                            ip6 ? DNSService.AAAA : DNSService.A), 
+                            new AResponseListener());
+
+                }
+            } catch (TimeoutException e) {
+                // just return the default "unknown".
+                session.setClientDomain("unknown");
+            }
+            return null;
+
+        }
+    }
+
+    private static final String ATTRIBUTE_MACRO_EXPAND_CHECKED_RECORD = "MacroExpand.checkedRecord";
+
+    public DNSLookupContinuation checkExpand(String input, SPFSession session, boolean isExplanation) throws PermErrorException {
+        if (input != null) {
+            String host = this.expand(input, session, isExplanation);
+            if (host == null) {
+
+                return new DNSLookupContinuation(new DNSRequest(IPAddr
+                        .getAddress(session.getIpAddress()).getReverseIP(),
+                        DNSService.PTR), new PTRResponseListener());
+            }
+        }
+        return null;
     }
     
     public String expand(String input, MacroData macroData, boolean isExplanation) throws PermErrorException {

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/NeutralIfNotMatchPolicy.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/NeutralIfNotMatchPolicy.java?view=diff&rev=531177&r1=531176&r2=531177
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/NeutralIfNotMatchPolicy.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/NeutralIfNotMatchPolicy.java Sun Apr 22 06:39:18 2007
@@ -19,6 +19,7 @@
 
 package org.apache.james.jspf.policies;
 
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.SPF1Constants;
 import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.core.SPF1Record;
@@ -34,11 +35,12 @@
 public class NeutralIfNotMatchPolicy implements PolicyPostFilter {
     
     private final class NeutralIfNotMatchModifier implements SPFChecker {
-        public void checkSPF(SPFSession spfData) throws PermErrorException, TempErrorException, NeutralException {
+        public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException, TempErrorException, NeutralException {
             // If no match was found set the result to neutral
             if (spfData.getCurrentResult() == null) {
                 spfData.setCurrentResult(SPF1Constants.NEUTRAL);
             }
+            return null;
         }
 
         public String toString() {

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java?view=diff&rev=531177&r1=531176&r2=531177
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java Sun Apr 22 06:39:18 2007
@@ -20,19 +20,18 @@
 package org.apache.james.jspf.policies.local;
 
 import org.apache.james.jspf.SPF1Utils;
-import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.Logger;
 import org.apache.james.jspf.core.SPF1Constants;
-import org.apache.james.jspf.core.SPFSession;
 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.apache.james.jspf.macro.MacroExpand;
 import org.apache.james.jspf.policies.PolicyPostFilter;
-import org.apache.james.jspf.util.DNSResolver;
 
 /**
  * Policy to add a default explanation
@@ -48,7 +47,7 @@
         }
         
         private final class ExplanationChecker implements SPFChecker {
-            public void checkSPF(SPFSession spfData)
+            public DNSLookupContinuation checkSPF(SPFSession spfData)
                     throws PermErrorException,
                     NoneException, TempErrorException,
                     NeutralException {
@@ -61,10 +60,11 @@
                     // Should never happen !
                     log.debug("Invalid defaulfExplanation: " + attExplanation);
                 }
+                return null;
             }
         }
 
-        public void checkSPF(SPFSession spfData) throws PermErrorException, NoneException, TempErrorException, NeutralException {
+        public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException, NoneException, TempErrorException, NeutralException {
             
             if (SPF1Constants.FAIL.equals(spfData.getCurrentResult())) {  
                 if (spfData.getExplanation()==null || spfData.getExplanation().equals("")) {
@@ -76,9 +76,11 @@
                     }
                     spfData.setAttribute(ATTRIBUTE_DEFAULT_EXPLANATION_POLICY_EXPLANATION, explanation);
                     spfData.pushChecker(explanationCheckr);
-                    DNSResolver.hostExpand(dnsService, macroExpand, explanation, spfData, MacroExpand.EXPLANATION);
+                    return macroExpand.checkExpand(explanation, spfData, MacroExpand.EXPLANATION);
                 }
             }
+            
+            return null;
         }
 
         public String toString() {
@@ -103,17 +105,14 @@
     
     private MacroExpand macroExpand;
     
-    private DNSService dnsService;
-
     /**
      * @param macroExpand 
      * @param spf
      */
-    public DefaultExplanationPolicy(Logger log, String explanation, MacroExpand macroExpand, DNSService dnsService) {
+    public DefaultExplanationPolicy(Logger log, String explanation, MacroExpand macroExpand) {
         this.log = log;
         this.defExplanation = explanation;
         this.macroExpand = macroExpand;
-        this.dnsService = dnsService;
     }
 
     /**

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=531177&r1=531176&r2=531177
==============================================================================
--- 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 Sun Apr 22 06:39:18 2007
@@ -21,6 +21,7 @@
 package org.apache.james.jspf.terms;
 
 import org.apache.james.jspf.core.Configuration;
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.DNSRequest;
 import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
@@ -34,10 +35,8 @@
 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.DNSResolver;
 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;
@@ -46,7 +45,7 @@
  * This class represent the a mechanism
  * 
  */
-public class AMechanism extends GenericMechanism implements DNSServiceEnabled, SPFCheckerDNSResponseListener {
+public class AMechanism extends GenericMechanism implements SPFCheckerDNSResponseListener {
 
     private static final String ATTRIBUTE_AMECHANISM_IPV4CHECK = "AMechanism.ipv4check";
 
@@ -61,12 +60,10 @@
 
     private int ip6cidr;
 
-    protected DNSService dnsService;
-    
     private SPFChecker expandedChecker = new ExpandedChecker();
 
     private final class ExpandedChecker implements SPFChecker {
-        public void checkSPF(SPFSession spfData) throws PermErrorException,
+        public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
                 TempErrorException, NeutralException, NoneException {
             // Get the right host.
             String host = expandHost(spfData);
@@ -77,20 +74,20 @@
                 spfData.setAttribute(ATTRIBUTE_AMECHANISM_IPV4CHECK, Boolean.valueOf(validIPV4Address));
                 if (validIPV4Address) {
 
-                    List aRecords = getARecords(dnsService,host);
+                    List aRecords = getARecords(host);
                     if (aRecords == null) {
-                        DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.A), spfData, AMechanism.this);
+                        return new DNSLookupContinuation(new DNSRequest(host, DNSService.A), AMechanism.this);
                     } else {
-                        onDNSResponse(new DNSResponse(aRecords), spfData);
+                        return onDNSResponse(new DNSResponse(aRecords), spfData);
                     }
          
                 } else {
                     
-                    List aaaaRecords = getAAAARecords(dnsService, host);
+                    List aaaaRecords = getAAAARecords(host);
                     if (aaaaRecords == null) {
-                        DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.AAAA), spfData, AMechanism.this);
+                        return new DNSLookupContinuation(new DNSRequest(host, DNSService.AAAA), AMechanism.this);
                     } else {
-                        onDNSResponse(new DNSResponse(aaaaRecords), spfData);
+                        return onDNSResponse(new DNSResponse(aaaaRecords), spfData);
                     }
 
                 }
@@ -108,13 +105,13 @@
     /**
      * @see org.apache.james.jspf.core.SPFChecker#checkSPF(org.apache.james.jspf.core.SPFSession)
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException, TempErrorException, NeutralException, NoneException {
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException, TempErrorException, NeutralException, NoneException {
         // update currentDepth
         spfData.increaseCurrentDepth();
 
         spfData.pushChecker(expandedChecker);
         
-        DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData, MacroExpand.DOMAIN);
+        return macroExpand.checkExpand(getDomain(), spfData, MacroExpand.DOMAIN);
     }
 
     /**
@@ -212,8 +209,7 @@
     /**
      * Retrieve a list of AAAA records
      */
-    public List getAAAARecords(DNSService dns, String strServer)
-            throws PermErrorException, TempErrorException {
+    public List getAAAARecords(String strServer) {
         List listAAAAData = null;
         if (IPAddr.isIPV6(strServer)) {
             // Address is already an IP address, so add it to list
@@ -227,16 +223,11 @@
     /**
      * Get a list of IPAddr's for a server
      * 
-     * @params dns the DNSService to query
      * @param strServer
      *            The hostname or ipAddress whe should get the A-Records for
      * @return The ipAddresses
-     * @throws PermErrorException
-     *             if an PermError should be returned
-     * @throws TempErrorException
-     *             if the lookup result was "TRY_AGAIN"
      */
-    public List getARecords(DNSService dns, String strServer) throws PermErrorException, TempErrorException {
+    public List getARecords(String strServer) {
         List listAData = null;
         if (IPAddr.isIPAddr(strServer)) {
             listAData = new ArrayList();
@@ -246,17 +237,9 @@
     }
 
     /**
-     * @see org.apache.james.jspf.wiring.DNSServiceEnabled#enableDNSService(org.apache.james.jspf.core.DNSService)
-     */
-    public void enableDNSService(DNSService service) {
-        this.dnsService = service;
-    }
-
-
-    /**
      * @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)
+    public DNSLookupContinuation onDNSResponse(DNSResponse response, SPFSession spfSession)
         throws PermErrorException, TempErrorException, NoneException, NeutralException {
         List listAData = null;
         try {
@@ -267,7 +250,7 @@
         // no a records just return null
         if (listAData == null) {
             spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
-            return;
+            return null;
         }
 
         Boolean ipv4check = (Boolean) spfSession.getAttribute(ATTRIBUTE_AMECHANISM_IPV4CHECK);
@@ -278,7 +261,7 @@
 
             if (checkAddressList(checkAddress, listAData, getIp4cidr())) {
                 spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.TRUE);
-                return;
+                return null;
             }
 
         } else {
@@ -288,13 +271,13 @@
             
             if (checkAddressList(checkAddress, listAData, getIp6cidr())) {
                 spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.TRUE);
-                return;
+                return null;
             }
 
         }
         
         spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
-        return;
+        return null;
     }
 
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AllMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AllMechanism.java?view=diff&rev=531177&r1=531176&r2=531177
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AllMechanism.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AllMechanism.java Sun Apr 22 06:39:18 2007
@@ -22,6 +22,7 @@
 
 import org.apache.james.jspf.core.Configurable;
 import org.apache.james.jspf.core.Configuration;
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.Mechanism;
 import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.exceptions.PermErrorException;
@@ -37,8 +38,8 @@
     /**
      * @see org.apache.james.jspf.core.SPFChecker#checkSPF(org.apache.james.jspf.core.SPFSession)
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException {
-        return;
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException {
+        return null;
     }
 
     /**

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=531177&r1=531176&r2=531177
==============================================================================
--- 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 Sun Apr 22 06:39:18 2007
@@ -20,6 +20,7 @@
 
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.DNSRequest;
 import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
@@ -32,22 +33,20 @@
 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.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
-import org.apache.james.jspf.wiring.DNSServiceEnabled;
 
 import java.util.List;
 
 /**
  * This class represent the exists mechanism
  */
-public class ExistsMechanism extends GenericMechanism implements DNSServiceEnabled, SPFCheckerDNSResponseListener {
+public class ExistsMechanism extends GenericMechanism implements SPFCheckerDNSResponseListener {
 
     private final class ExpandedChecker implements SPFChecker {
-        public void checkSPF(SPFSession spfData) throws PermErrorException,
+        public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
                 TempErrorException, NeutralException, NoneException {
             String host = expandHost(spfData);
-            DNSResolver.lookup(dnsService, new DNSRequest(host,DNSService.A), spfData, ExistsMechanism.this);
+            return new DNSLookupContinuation(new DNSRequest(host,DNSService.A), ExistsMechanism.this);
         }
     }
 
@@ -57,43 +56,41 @@
     public static final String REGEX = "[eE][xX][iI][sS][tT][sS]" + "\\:"
             + SPFTermsRegexps.DOMAIN_SPEC_REGEX;
 
-    private DNSService dnsService;
-
     private SPFChecker expandedChecker = new ExpandedChecker();
 
     /**
      * @see org.apache.james.jspf.core.SPFChecker#checkSPF(org.apache.james.jspf.core.SPFSession)
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException,
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
             TempErrorException, NeutralException, NoneException {
         // update currentDepth
         spfData.increaseCurrentDepth();
 
         spfData.pushChecker(expandedChecker);
-        DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData, MacroExpand.DOMAIN);
-        
+        return macroExpand.checkExpand(getDomain(), spfData, MacroExpand.DOMAIN);
     }
 
     /**
      * @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 {
+    public DNSLookupContinuation onDNSResponse(DNSResponse response, SPFSession spfSession) throws PermErrorException, TempErrorException {
         List aRecords;
         
         try {
             aRecords = response.getResponse();
         } catch (DNSService.TimeoutException e) {
             spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
-            return;
+            return null;
         }
         
         if (aRecords != null && aRecords.size() > 0) {
             spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.TRUE);
-            return;
+            return null;
         }
         
         // No match found
         spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
+        return null;
     }
 
     /**
@@ -101,13 +98,6 @@
      */
     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/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=531177&r1=531176&r2=531177
==============================================================================
--- 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 Sun Apr 22 06:39:18 2007
@@ -20,6 +20,7 @@
 
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.DNSRequest;
 import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
@@ -32,9 +33,7 @@
 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.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
-import org.apache.james.jspf.wiring.DNSServiceEnabled;
 import org.apache.james.jspf.wiring.MacroExpandEnabled;
 
 import java.util.List;
@@ -43,10 +42,10 @@
  * This class represent the exp modifier
  * 
  */
-public class ExpModifier extends GenericModifier implements DNSServiceEnabled, MacroExpandEnabled, SPFCheckerDNSResponseListener {
+public class ExpModifier extends GenericModifier implements MacroExpandEnabled, SPFCheckerDNSResponseListener {
 
     private final class ExpandedExplanationChecker implements SPFChecker {
-        public void checkSPF(SPFSession spfData)
+        public DNSLookupContinuation checkSPF(SPFSession spfData)
                 throws PermErrorException, NoneException,
                 TempErrorException, NeutralException {
             try {
@@ -56,16 +55,17 @@
             } catch (PermErrorException e) {
                 // ignore syntax error on explanation expansion
             }
+            return null;
         }
     }
 
 
     private final class ExpandedChecker implements SPFChecker {
-        public void checkSPF(SPFSession spfData) throws PermErrorException,
+        public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
                 NoneException, TempErrorException, NeutralException {
             String host = macroExpand.expand(getHost(), spfData, MacroExpand.DOMAIN);
 
-            DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.TXT), spfData, ExpModifier.this);
+            return new DNSLookupContinuation(new DNSRequest(host, DNSService.TXT), ExpModifier.this);
         }
     }
 
@@ -82,8 +82,6 @@
     public static final String REGEX = "[eE][xX][pP]" + "\\="
             + SPFTermsRegexps.DOMAIN_SPEC_REGEX+"?";
 
-    private DNSService dnsService;
-    
     private MacroExpand macroExpand;
 
     private ExpandedChecker expandedChecker = new ExpandedChecker();
@@ -101,25 +99,25 @@
      * @throws NoneException 
      * @throws NeutralException 
      */
-    protected void checkSPFLogged(SPFSession spfData) throws PermErrorException, TempErrorException, NeutralException, NoneException {
+    protected DNSLookupContinuation checkSPFLogged(SPFSession spfData) throws PermErrorException, TempErrorException, NeutralException, NoneException {
         String host = getHost();
         
         // RFC4408 Errata: http://www.openspf.org/RFC_4408/Errata#empty-exp
         if (host == null) {
-            return;
+            return null;
         }
 
         // If we should ignore the explanation we don't have to run this class
         if (spfData.ignoreExplanation() == true)
-            return;
+            return null;
         
         // If the currentResult is not fail we have no need to run all these
         // methods!
         if (spfData.getCurrentResult()== null || !spfData.getCurrentResult().equals(SPF1Constants.FAIL))
-            return;
+            return null;
 
         spfData.pushChecker(expandedChecker);
-        DNSResolver.hostExpand(dnsService, macroExpand, host, spfData, MacroExpand.DOMAIN);
+        return macroExpand.checkExpand(host, spfData, MacroExpand.DOMAIN);
     }
 
     /**
@@ -141,12 +139,12 @@
     /**
      * @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 {
+    public DNSLookupContinuation onDNSResponse(DNSResponse lookup, SPFSession spfData) throws PermErrorException, TempErrorException, NeutralException, NoneException {
         try {
             List records = lookup.getResponse();
         
             if (records == null) {
-                return;
+                return null;
             }
     
             // See SPF-Spec 6.2
@@ -169,7 +167,7 @@
                     
                     try {
                         spfData.pushChecker(expandedExplanationChecker);
-                        DNSResolver.hostExpand(dnsService, macroExpand, exp, spfData, MacroExpand.EXPLANATION);
+                        return macroExpand.checkExpand(exp, spfData, MacroExpand.EXPLANATION);
                     } catch (PermErrorException e) {
                         // ignore syntax error on explanation expansion
                     }
@@ -180,8 +178,8 @@
 
         } catch (DNSService.TimeoutException e) {
             // Nothing todo here.. just return null
-            return;
         }
+        return null;
     }
     
     /**
@@ -190,14 +188,6 @@
     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;
-    }
-
 
     /**
      * @see org.apache.james.jspf.wiring.MacroExpandEnabled#enableMacroExpand(org.apache.james.jspf.macro.MacroExpand)

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/GenericModifier.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/GenericModifier.java?view=diff&rev=531177&r1=531176&r2=531177
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/GenericModifier.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/GenericModifier.java Sun Apr 22 06:39:18 2007
@@ -22,6 +22,7 @@
 
 import org.apache.james.jspf.core.Configurable;
 import org.apache.james.jspf.core.Configuration;
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.Logger;
 import org.apache.james.jspf.core.Modifier;
 import org.apache.james.jspf.core.SPFSession;
@@ -47,15 +48,16 @@
      * @see org.apache.james.jspf.core.Modifier#run(SPFSession)
      * 
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException,
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
             TempErrorException, NeutralException, NoneException {
         log.debug("Processing modifier: " + this);
-        checkSPFLogged(spfData);
+        DNSLookupContinuation res = checkSPFLogged(spfData);
         log.debug("Processed modifier: " + this + " resulted in "
-                + spfData.getCurrentResult());
+                + res == null ? spfData.getCurrentResult() : " dns continuation...");
+        return res;
     }
     
-    protected abstract void checkSPFLogged(SPFSession spfData) throws PermErrorException,
+    protected abstract DNSLookupContinuation checkSPFLogged(SPFSession spfData) throws PermErrorException,
         TempErrorException, NeutralException, NoneException;
 
 

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java?view=diff&rev=531177&r1=531176&r2=531177
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java Sun Apr 22 06:39:18 2007
@@ -21,6 +21,7 @@
 package org.apache.james.jspf.terms;
 
 import org.apache.james.jspf.core.Configuration;
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.Directive;
 import org.apache.james.jspf.core.IPAddr;
 import org.apache.james.jspf.core.SPFSession;
@@ -45,13 +46,15 @@
      * 
      * @see org.apache.james.jspf.core.GenericMechanism#run(org.apache.james.jspf.core.SPFSession)
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException {
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException {
         IPAddr originalIP;
 
         originalIP = IPAddr.getAddress(spfData.getIpAddress(), getIp()
                 .getMaskLength());
 
         spfData.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.valueOf(getIp().getMaskedIPAddress().equals(originalIP.getMaskedIPAddress())));
+        
+        return null;
     }
 
     /**

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=531177&r1=531176&r2=531177
==============================================================================
--- 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 Sun Apr 22 06:39:18 2007
@@ -22,8 +22,8 @@
 
 import org.apache.james.jspf.core.Configurable;
 import org.apache.james.jspf.core.Configuration;
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.DNSResponse;
-import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.Directive;
 import org.apache.james.jspf.core.Logger;
 import org.apache.james.jspf.core.Mechanism;
@@ -36,9 +36,7 @@
 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.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
-import org.apache.james.jspf.wiring.DNSServiceEnabled;
 import org.apache.james.jspf.wiring.LogEnabled;
 import org.apache.james.jspf.wiring.MacroExpandEnabled;
 import org.apache.james.jspf.wiring.SPFCheckEnabled;
@@ -47,7 +45,7 @@
  * This class represent the incude mechanism
  * 
  */
-public class IncludeMechanism implements Mechanism, Configurable, LogEnabled, SPFCheckEnabled, MacroExpandEnabled, DNSServiceEnabled {
+public class IncludeMechanism implements Mechanism, Configurable, LogEnabled, SPFCheckEnabled, MacroExpandEnabled {
 
     private final class ExceptionCatcher implements SPFCheckerExceptionCatcher {
         private SPFChecker spfChecker;
@@ -90,7 +88,7 @@
     }
 
     private final class ExpandedChecker implements SPFChecker {
-        public void checkSPF(SPFSession spfData) throws PermErrorException,
+        public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
                 TempErrorException {
 
             // throws a PermErrorException that we can pass through
@@ -104,6 +102,8 @@
             spfData.setCurrentResult(null);
             
             spfData.pushChecker(spfChecker);
+            
+            return null;
         }
     }
 
@@ -112,7 +112,7 @@
 
         private String previousDomain;
 
-        public void checkSPF(SPFSession spfData) throws PermErrorException,
+        public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
                 TempErrorException, NeutralException, NoneException {
             
             spfData.setIgnoreExplanation(false);
@@ -121,6 +121,7 @@
 
             spfData.popExceptionCatcher();
             
+            return null;
         }
 
         public SPFChecker init(SPFSession spfSession) {
@@ -138,7 +139,7 @@
     private final class CleanupAndResultChecker implements SPFChecker {
         private SPFChecker finallyChecker;
 
-        public void checkSPF(SPFSession spfData) throws PermErrorException,
+        public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
                 TempErrorException, NeutralException, NoneException {
             
             String currentResult = spfData.getCurrentResult();
@@ -157,7 +158,7 @@
                 throw new TempErrorException("included checkSPF returned an Illegal result");
             }
 
-
+            return null;
         }
 
         public SPFChecker init(SPFChecker finallyChecker) {
@@ -180,12 +181,10 @@
 
     private MacroExpand macroExpand;
 
-    private DNSService dnsService;
-
     /**
      * @see org.apache.james.jspf.core.SPFChecker#checkSPF(org.apache.james.jspf.core.SPFSession)
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException, TempErrorException, NoneException, NeutralException {
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException, TempErrorException, NoneException, NeutralException {
         // update currentDepth
         spfData.increaseCurrentDepth();
         
@@ -196,8 +195,7 @@
         spfData.pushExceptionCatcher(new ExceptionCatcher().setExceptionHandlerChecker(cleanupAndResultHandler, finallyChecker));
         
         spfData.pushChecker(new ExpandedChecker());
-        DNSResolver.hostExpand(dnsService, macroExpand, getHost(), spfData, MacroExpand.DOMAIN);
-
+        return macroExpand.checkExpand(getHost(), spfData, MacroExpand.DOMAIN);
     }
 
     /**
@@ -252,12 +250,5 @@
             throws PermErrorException, TempErrorException, NoneException {
         // not called yet.
         return false;
-    }
-
-    /**
-     * @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/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=531177&r1=531176&r2=531177
==============================================================================
--- 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 Sun Apr 22 06:39:18 2007
@@ -20,6 +20,7 @@
 
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.DNSRequest;
 import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
@@ -33,7 +34,6 @@
 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.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
 
 import java.util.ArrayList;
@@ -46,13 +46,13 @@
 public class MXMechanism extends AMechanism implements SPFCheckerDNSResponseListener {
 
     private final class ExpandedChecker implements SPFChecker {
-        public void checkSPF(SPFSession spfData) throws PermErrorException,
+        public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
                 TempErrorException, NeutralException, NoneException {
 
             // Get the right host.
             String host = expandHost(spfData);
             
-            DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.MX), spfData, MXMechanism.this);
+            return new DNSLookupContinuation(new DNSRequest(host, DNSService.MX), MXMechanism.this);
         }
     }
 
@@ -70,34 +70,34 @@
     /**
      * @see org.apache.james.jspf.terms.AMechanism#checkSPF(org.apache.james.jspf.core.SPFSession)
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException,
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
             TempErrorException, NeutralException, NoneException{
 
         // update currentDepth
         spfData.increaseCurrentDepth();
 
         spfData.pushChecker(expandedChecker);
-        DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData, MacroExpand.DOMAIN);
+        return macroExpand.checkExpand(getDomain(), spfData, MacroExpand.DOMAIN);
     }
 
     /**
      * @see org.apache.james.jspf.terms.AMechanism#onDNSResponse(org.apache.james.jspf.core.DNSResponse, org.apache.james.jspf.core.SPFSession)
      */
-    public void onDNSResponse(DNSResponse response, SPFSession spfSession)
+    public DNSLookupContinuation onDNSResponse(DNSResponse response, SPFSession spfSession)
         throws PermErrorException, TempErrorException, NoneException, NeutralException {
         try {
             
             List records = (List) spfSession.getAttribute(ATTRIBUTE_CHECK_RECORDS);
             List mxR = (List) spfSession.getAttribute(ATTRIBUTE_MX_RECORDS);
-            
+
             if (records == null) {
             
                 records = response.getResponse();
-                
+
                 if (records == null) {
                     // no mx record found
                     spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
-                    return;
+                    return null;
                 }
                 
                 spfSession.setAttribute(ATTRIBUTE_CHECK_RECORDS, records);
@@ -105,7 +105,7 @@
             } else {
                 
                 List res = response.getResponse();
-                
+
                 if (res != null) {
                     if (mxR == null) {
                         mxR = new ArrayList();
@@ -122,18 +122,17 @@
             String mx;
             while (records.size() > 0 && (mx = (String) records.remove(0)) != null && mx.length() > 0) {
                 log.debug("Add MX-Record " + mx + " to list");
-    
-                DNSResolver.lookup(dnsService, new DNSRequest(mx, isIPv6 ? DNSService.AAAA : DNSService.A), spfSession, MXMechanism.this);
-                return;
+
+                return new DNSLookupContinuation(new DNSRequest(mx, isIPv6 ? DNSService.AAAA : DNSService.A), MXMechanism.this);
                 
             }
                 
             // no mx record found
             if (mxR == null || mxR.size() == 0) {
                 spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
-                return;
+                return null;
             }
-            
+
             // get the ipAddress
             IPAddr checkAddress;
             checkAddress = IPAddr.getAddress(spfSession.getIpAddress(), isIPv6 ? getIp6cidr() : getIp4cidr());
@@ -142,7 +141,7 @@
             spfSession.setAttribute(ATTRIBUTE_CHECK_RECORDS, null);
             spfSession.setAttribute(ATTRIBUTE_MX_RECORDS, null);
             spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.valueOf(checkAddressList(checkAddress, mxR, getIp4cidr())));
-            return;
+            return null;
             
         } catch (DNSService.TimeoutException e) {
             spfSession.setAttribute(ATTRIBUTE_CHECK_RECORDS, null);

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=531177&r1=531176&r2=531177
==============================================================================
--- 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 Sun Apr 22 06:39:18 2007
@@ -20,6 +20,7 @@
 
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.DNSRequest;
 import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
@@ -33,7 +34,6 @@
 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.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
 import org.apache.james.jspf.wiring.DNSServiceEnabled;
 
@@ -46,7 +46,19 @@
 public class PTRMechanism extends GenericMechanism implements DNSServiceEnabled, SPFCheckerDNSResponseListener {
 
     private final class ExpandedChecker implements SPFChecker {
-        public void checkSPF(SPFSession spfData) throws PermErrorException,
+        private CleanupChecker cleanupChecker = new CleanupChecker();
+
+        private final class CleanupChecker implements SPFChecker {
+            public DNSLookupContinuation checkSPF(SPFSession spfData)
+                    throws PermErrorException, TempErrorException,
+                    NeutralException, NoneException {
+                spfData.setAttribute(ATTRIBUTE_DOMAIN_LIST, null);
+                spfData.setAttribute(ATTRIBUTE_CURRENT_DOMAIN, null);
+                return null;
+            }
+        }
+
+        public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
                 TempErrorException, NeutralException, NoneException {
 
             // Get PTR Records for the ipAddress which is provided by SPF1Data
@@ -56,8 +68,10 @@
             String host = expandHost(spfData);
             
             spfData.setAttribute(ATTRIBUTE_EXPANDED_HOST, host);
+            
+            spfData.pushChecker(cleanupChecker);
 
-            DNSResolver.lookup(dnsService, new DNSRequest(ip.getReverseIP(), DNSService.PTR), spfData, PTRMechanism.this);
+            return new DNSLookupContinuation(new DNSRequest(ip.getReverseIP(), DNSService.PTR), PTRMechanism.this);
         }
     }
 
@@ -80,13 +94,13 @@
     /**
      * @see org.apache.james.jspf.core.SPFChecker#checkSPF(org.apache.james.jspf.core.SPFSession)
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException,
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
             TempErrorException, NeutralException, NoneException {
         // update currentDepth
         spfData.increaseCurrentDepth();
 
         spfData.pushChecker(expandedChecker);
-        DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData, MacroExpand.DOMAIN);
+        return macroExpand.checkExpand(getDomain(), spfData, MacroExpand.DOMAIN);
     }
 
     /**
@@ -99,7 +113,7 @@
     /**
      * @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)
+    public DNSLookupContinuation onDNSResponse(DNSResponse response, SPFSession spfSession)
             throws PermErrorException, TempErrorException, NoneException, NeutralException {
         
         List domainList = (List) spfSession.getAttribute(ATTRIBUTE_DOMAIN_LIST);
@@ -111,7 +125,7 @@
                 // No PTR records found
                 if (domainList == null) {
                     spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
-                    return;
+                    return null;
                 }
         
                 // check if the maximum lookup count is reached
@@ -139,7 +153,7 @@
                             if (compareDomain.equals(host)
                                     || compareDomain.endsWith("." + host)) {
                                 spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.TRUE);
-                                return;
+                                return null;
                             }
                             
                         }
@@ -152,33 +166,25 @@
         }
         
 
-        try {
-
-            if (domainList.size() > 0) {
-                String currentDomain = (String) domainList.remove(0);
-        
-                DNSRequest dnsRequest;
-                // check if the connecting ip is ip6. If so lookup AAAA record
-                if (IPAddr.isIPV6(spfSession.getIpAddress())) {
-                    // Get aaaa record for this
-                    dnsRequest = new DNSRequest(currentDomain, DNSService.AAAA);
-                } else {
-                    // Get a record for this
-                    dnsRequest = new DNSRequest(currentDomain, DNSService.A);
-                }
-                
-                spfSession.setAttribute(ATTRIBUTE_CURRENT_DOMAIN, currentDomain);
-                
-                DNSResolver.lookup(dnsService, dnsRequest, spfSession, PTRMechanism.this);
-                return;
+        if (domainList.size() > 0) {
+            String currentDomain = (String) domainList.remove(0);
+    
+            DNSRequest dnsRequest;
+            // check if the connecting ip is ip6. If so lookup AAAA record
+            if (IPAddr.isIPV6(spfSession.getIpAddress())) {
+                // Get aaaa record for this
+                dnsRequest = new DNSRequest(currentDomain, DNSService.AAAA);
             } else {
-                spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
-                return;
+                // Get a record for this
+                dnsRequest = new DNSRequest(currentDomain, DNSService.A);
             }
-
-        } finally {
-            spfSession.setAttribute(ATTRIBUTE_DOMAIN_LIST, null);
-            spfSession.setAttribute(ATTRIBUTE_CURRENT_DOMAIN, null);
+            
+            spfSession.setAttribute(ATTRIBUTE_CURRENT_DOMAIN, currentDomain);
+            
+            return new DNSLookupContinuation(dnsRequest, PTRMechanism.this);
+        } else {
+            spfSession.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
+            return null;
         }
 
     }

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=531177&r1=531176&r2=531177
==============================================================================
--- 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 Sun Apr 22 06:39:18 2007
@@ -19,18 +19,16 @@
 
 package org.apache.james.jspf.terms;
 
-import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.DNSLookupContinuation;
+import org.apache.james.jspf.core.SPFChecker;
 import org.apache.james.jspf.core.SPFCheckerExceptionCatcher;
 import org.apache.james.jspf.core.SPFSession;
-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.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
-import org.apache.james.jspf.wiring.DNSServiceEnabled;
 import org.apache.james.jspf.wiring.MacroExpandEnabled;
 import org.apache.james.jspf.wiring.SPFCheckEnabled;
 
@@ -39,7 +37,7 @@
  * 
  */
 public class RedirectModifier extends GenericModifier implements
-        SPFCheckEnabled, MacroExpandEnabled, DNSServiceEnabled {
+        SPFCheckEnabled, MacroExpandEnabled {
 
     private final class ExceptionCatcher implements SPFCheckerExceptionCatcher {
         private SPFChecker spfChecker;
@@ -86,7 +84,7 @@
     }
 
     private final class ExpandedChecker implements SPFChecker {
-        public void checkSPF(SPFSession spfData)
+        public DNSLookupContinuation checkSPF(SPFSession spfData)
                 throws PermErrorException, NoneException,
                 TempErrorException, NeutralException {
             String host = getHost();
@@ -99,11 +97,12 @@
             spfData.setCurrentDomain(host);
 
             spfData.pushChecker(spfChecker);
+            return null;
         }
     }
 
     private final class CleanupChecker implements SPFChecker {
-        public void checkSPF(SPFSession spfData)
+        public DNSLookupContinuation checkSPF(SPFSession spfData)
                 throws PermErrorException, TempErrorException,
                 NeutralException, NoneException {
             // After the redirect we should not use the
@@ -111,6 +110,7 @@
             spfData.setIgnoreExplanation(true);
             
             spfData.popExceptionCatcher();
+            return null;
         }
     }
 
@@ -124,8 +124,6 @@
 
     private MacroExpand macroExpand;
 
-    private DNSService dnsService;
-
     private SPFChecker cleanupChecker = new CleanupChecker();
 
     private SPFChecker expandedChecker = new ExpandedChecker();
@@ -146,7 +144,7 @@
      * @throws NoneException
      * @throws NeutralException
      */
-    protected void checkSPFLogged(SPFSession spfData)
+    protected DNSLookupContinuation checkSPFLogged(SPFSession spfData)
             throws PermErrorException, TempErrorException, NeutralException,
             NoneException {
         // the redirect modifier is used only when we had no previous matches
@@ -160,9 +158,9 @@
             spfData.pushExceptionCatcher(exceptionCatcher);
 
             spfData.pushChecker(expandedChecker);
-            DNSResolver.hostExpand(dnsService, macroExpand, getHost(), spfData,
-                    MacroExpand.DOMAIN);
+            return macroExpand.checkExpand(getHost(), spfData, MacroExpand.DOMAIN);
         }
+        return null;
     }
 
     /**
@@ -184,10 +182,6 @@
      */
     public void enableMacroExpand(MacroExpand macroExpand) {
         this.macroExpand = macroExpand;
-    }
-
-    public void enableDNSService(DNSService service) {
-        this.dnsService = service;
     }
 
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/UnknownModifier.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/UnknownModifier.java?view=diff&rev=531177&r1=531176&r2=531177
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/UnknownModifier.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/UnknownModifier.java Sun Apr 22 06:39:18 2007
@@ -22,6 +22,7 @@
 
 import org.apache.james.jspf.core.Configurable;
 import org.apache.james.jspf.core.Configuration;
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.Modifier;
 import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.exceptions.PermErrorException;
@@ -44,8 +45,8 @@
     /**
      * @see org.apache.james.jspf.core.Modifier#run(org.apache.james.jspf.core.SPFSession)
      */
-    public void checkSPF(SPFSession spfData) throws PermErrorException {
-        return;
+    public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException {
+        return null;
     }
 
     /**



---------------------------------------------------------------------
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