You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2006/09/25 16:05:14 UTC

svn commit: r449683 - in /james/jspf/trunk/src: main/java/org/apache/james/jspf/ main/java/org/apache/james/jspf/core/ main/java/org/apache/james/jspf/terms/ test/java/org/apache/james/jspf/ test/resources/org/apache/james/jspf/

Author: bago
Date: Mon Sep 25 07:05:13 2006
New Revision: 449683

URL: http://svn.apache.org/viewvc?view=rev&rev=449683
Log:
A lot of changes for JSPF-29 :
Fixed mailzone-tests.yml and tests.yml to use "inverse-ip.in-addr.arpa" instead of "ip" for PTR records
Updated rfc4408 test to the last available online: changed the first test to have 64 chars in the label instead of 54.
Added a toString() to all the mechanism/modifiers so that they give useful informations when printed out.
Introduced a DNSService.TimeoutException to be used instead of the TempErrorException in dns calls (added catch and rethrow TempError in the caller)
Removed the record specific calls from the DNSService interface in favor of the generic getRecord.
Moved the SPF specific logic from DNSService to the caller terms/code.

Removed:
    james/jspf/trunk/src/test/resources/org/apache/james/jspf/test_mailzone.txt
Modified:
    james/jspf/trunk/src/main/java/org/apache/james/jspf/DNSServiceXBillImpl.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/core/DNSService.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AllMechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IP6Mechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
    james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
    james/jspf/trunk/src/test/java/org/apache/james/jspf/LoggingDNSService.java
    james/jspf/trunk/src/test/resources/org/apache/james/jspf/mailzone-tests.yml
    james/jspf/trunk/src/test/resources/org/apache/james/jspf/rfc4408-tests.yml
    james/jspf/trunk/src/test/resources/org/apache/james/jspf/tests.yml

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/DNSServiceXBillImpl.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/DNSServiceXBillImpl.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/DNSServiceXBillImpl.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/DNSServiceXBillImpl.java Mon Sep 25 07:05:13 2006
@@ -22,15 +22,11 @@
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 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.exceptions.NoneException;
-import org.apache.james.jspf.exceptions.PermErrorException;
-import org.apache.james.jspf.exceptions.TempErrorException;
 import org.xbill.DNS.AAAARecord;
 import org.xbill.DNS.ARecord;
 import org.xbill.DNS.Lookup;
@@ -66,161 +62,6 @@
     }
 
     /**
-     * @see org.apache.james.jspf.core.DNSService#getSpfRecord(java.lang.String,
-     *      java.lang.String)
-     */
-    public String getSpfRecord(String hostname, String spfVersion)
-            throws PermErrorException, TempErrorException {
-
-        String returnValue = null;
-        // do DNS lookup for TXT
-        List txtR = getRecords(hostname, TXT);
-
-        // process returned records
-        if (txtR != null && !txtR.isEmpty()) {
-
-            Iterator all = txtR.iterator();
-
-            while (all.hasNext()) {
-                String compare = all.next().toString().trim();
-
-                // remove '"'
-                compare = compare.toLowerCase().substring(1,
-                        compare.length() - 1);
-
-                if (compare.startsWith(spfVersion + " ")) {
-                    if (returnValue == null) {
-                        returnValue = compare;
-                    } else {
-                        throw new PermErrorException(
-                                "More than 1 SPF record found for host: " + hostname);
-                    }
-                }
-            }
-        }
-        return returnValue;
-    }
-
-    /**
-     * @see org.apache.james.jspf.core.DNSService#getARecords(java.lang.String,
-     *      int)
-     */
-    public List getARecords(String strServer) throws PermErrorException, TempErrorException {
-
-        ArrayList listTxtData = new ArrayList();
-
-        if (IPAddr.isIPAddr(strServer)) {
-            IPAddr ipTest = IPAddr.getAddress(strServer);
-            // Address is already an IP address, so add it to list
-            listTxtData.add(ipTest);
-        } else {
-
-            List records = getRecords(strServer, A);
-            
-            // check if the maximum lookup count is reached
-            if (recordLimit > 0 && records.size() > recordLimit) throw new PermErrorException("Maximum A lookup count reached");
-            
-            for (int i = 0; i < records.size(); i++) {
-                String a = (String) records.get(i);
-                
-                IPAddr ip = IPAddr.getAddress(a);
-
-                log.debug("Add ipAddress " + ip + " to list");
-                listTxtData.add(ip);
-            }
-        }
-        return listTxtData;
-    }
-
-    /**
-     * @see org.apache.james.jspf.core.DNSService#getAAAARecords(java.lang.String,
-     *      int)
-     */
-    public List getAAAARecords(String strServer)
-            throws PermErrorException, TempErrorException {
-
-        ArrayList listTxtData = new ArrayList();
-
-        if (IPAddr.isIPAddr(strServer)) {
-            IPAddr ipTest = IPAddr.getAddress(strServer);
-            // Address is already an IP address, so add it to list
-            listTxtData.add(ipTest);
-        } else {
-            List records = getRecords(strServer, AAAA);
-
-            for (int i = 0; i < records.size(); i++) {
-                String a = (String) records.get(i);
-
-                IPAddr ip = IPAddr.getAddress(a);
-
-                log.debug("Add ipAddress " + ip + " to list");
-                listTxtData.add(ip);
-            }
-        }
-        return listTxtData;
-    }
-
-    /**
-     * @see org.apache.james.jspf.core.DNSService#getTxtCatType(java.lang.String)
-     */
-    public String getTxtCatType(String strServer) throws TempErrorException {
-
-        StringBuffer txtData = new StringBuffer();
-        List records = getRecords(strServer, TXT);
-
-        log.debug("Convert " + records.size() + " TXT-Records to one String");
-
-        for (int i = 0; i < records.size(); i++) {
-            txtData.append(records.get(i));
-        }
-        return txtData.toString();
-    }
-
-    /**
-     * @see org.apache.james.jspf.core.DNSService#getPTRRecords(java.lang.String)
-     */
-    public List getPTRRecords(String ipAddress) throws PermErrorException, TempErrorException {
-        // do DNS lookup for TXT
-        IPAddr ip = IPAddr.getAddress(ipAddress);
-
-        List records = getRecords(ip.getReverseIP() + ".in-addr.arpa", PTR);
-
-        // check if the maximum lookup count is reached
-        if (recordLimit > 0 && records.size() > recordLimit) throw new PermErrorException("Maximum PTR lookup count reached");
-  
-        return records;
-    }
-
-    /**
-     * @see org.apache.james.jspf.core.DNSService#getMXRecords(java.lang.String,
-     *      int)
-     */
-    public List getMXRecords(String domainName)
-            throws PermErrorException, TempErrorException {
-
-        List mxR = null;
-        List records = getRecords(domainName, MX);
-
-        // check if the maximum lookup count is reached
-        if (recordLimit > 0 && records.size() > recordLimit) throw new PermErrorException("Maximum MX lookup count reached");
-  
-        for (int i = 0; i < records.size(); i++) {
-            String mx = (String) records.get(i);
-            log.debug("Add MX-Record " + mx + " to list");
-
-            List res = getARecords(mx);
-            if (res != null) {
-                if (mxR == null) {
-                    mxR = new ArrayList();
-                }
-                mxR.addAll(res);
-            }
-        }
-        
-        return mxR;
-    }
-
-    /**
      * @see org.apache.james.jspf.core.DNSService#setTimeOut(int)
      */
     public synchronized void setTimeOut(int timeOut) {
@@ -266,19 +107,11 @@
         this.recordLimit = recordLimit;
     }
     
-    
-
     /**
-     * Retrieve dns records for the given host
-     * 
-     * @param hostname host to be queried
-     * @param recordType the record type: MX, A, AAAA, PTR, TXT, SPF 
-     * @return an array of Strings representing the records
-     * @throws NoneException when no record is found or a textparse exception happen
-     * @throws TempErrorException on timeout.
+     * @see org.apache.james.jspf.core.DNSService#getRecords(java.lang.String, int)
      */
-    private List getRecords(String hostname, int recordType)
-            throws TempErrorException {
+    public List getRecords(String hostname, int recordType)
+            throws TimeoutException {
         String recordTypeDescription;
         int dnsJavaType;
         switch (recordType) {
@@ -303,8 +136,7 @@
             int queryResult = query.getResult();
 
             if (queryResult == Lookup.TRY_AGAIN) {
-                throw new TempErrorException("DNS Server returns RCODE: "
-                        + queryResult);
+                throw new TimeoutException();
             }
             
             if (rr.length > 0) {

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java Mon Sep 25 07:05:13 2006
@@ -35,6 +35,7 @@
 import org.apache.james.jspf.parser.SPF1Parser;
 
 import java.util.Iterator;
+import java.util.List;
 
 /**
  * This class is used to generate a SPF-Test and provided all intressting data.
@@ -163,7 +164,7 @@
         }
 
         // Get the raw dns txt entry which contains a spf entry
-        String spfDnsEntry = dnsProbe.getSpfRecord(spfData.getCurrentDomain(),
+        String spfDnsEntry = getSpfRecord(dnsProbe,spfData.getCurrentDomain(),
                 SPF1Constants.SPF_VERSION);
 
         if (spfDnsEntry == null) {
@@ -300,4 +301,68 @@
     public synchronized void setDefaultExplanation(String defaultExplanation) {
         this.defaultExplanation = defaultExplanation;      
     }
+    
+    
+
+
+    /**
+     * Get the SPF-Record for a server given it's version
+     * 
+     * TODO: support SPF Records too. This will be done if dnsjava support it!
+     * 
+     * @param dns
+     *            The dns service to query
+     * @param hostname
+     *            The hostname for which we want to retrieve the SPF-Record
+     * @param spfVersion
+     *            The SPF-Version which should used.
+     * @return The SPF-Record if one is found.
+     * @throws PermErrorException
+     *             if more then one SPF-Record was found.
+     * @throws TempErrorException
+     *             if the lookup result was "TRY_AGAIN"
+     */
+    public String getSpfRecord(DNSService dns, String hostname, String spfVersion)
+            throws PermErrorException, TempErrorException {
+
+        String returnValue = null;
+        try {
+            List spfR = dns.getRecords(hostname, DNSService.SPF);
+            if (spfR == null || spfR.isEmpty()) {
+                // do DNS lookup for TXT
+                spfR = dns.getRecords(hostname, DNSService.TXT);
+            }
+    
+            // process returned records
+            if (spfR != null && !spfR.isEmpty()) {
+    
+                Iterator all = spfR.iterator();
+    
+                while (all.hasNext()) {
+                    String compare = all.next().toString().trim();
+    
+                    // TODO is this correct? we remove the first and last char if the
+                    // result has an initial " 
+                    // remove '"'
+                    if (compare.charAt(0)=='"') {
+                        compare = compare.toLowerCase().substring(1,
+                                compare.length() - 1);
+                    }
+    
+                    if (compare.startsWith(spfVersion + " ") || compare.equals(spfVersion)) {
+                        if (returnValue == null) {
+                            returnValue = compare;
+                        } else {
+                            throw new PermErrorException(
+                                    "More than 1 SPF record found for host: " + hostname);
+                        }
+                    }
+                }
+            }
+            return returnValue;
+        } catch (DNSService.TimeoutException e) {
+            throw new TempErrorException("Timeout querying dns");
+        }
+    }
+
 }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/core/DNSService.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/core/DNSService.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/core/DNSService.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/core/DNSService.java Mon Sep 25 07:05:13 2006
@@ -17,12 +17,8 @@
  * under the License.                                           *
  ****************************************************************/
 
-
 package org.apache.james.jspf.core;
 
-import org.apache.james.jspf.exceptions.PermErrorException;
-import org.apache.james.jspf.exceptions.TempErrorException;
-
 import java.util.List;
 
 /**
@@ -31,6 +27,13 @@
  */
 public interface DNSService {
     
+    /**
+     * The exception thrown on timeout.
+     */
+    public class TimeoutException extends Exception {
+        
+    }
+    
     /** The record types for the lookups */
     public int A = 1;
     public int AAAA = 2;
@@ -40,91 +43,15 @@
     public int SPF = 6;
 
     /**
-     * Get the SPF-Record for a server given it's version
-     * 
-     * TODO: support SPF Records too. This will be done if dnsjava support it!
-     * 
-     * @param hostname
-     *            The hostname for which we want to retrieve the SPF-Record
-     * @param spfVersion
-     *            The SPF-Version which should used.
-     * @return The SPF-Record if one is found.
-     * @throws PermErrorException
-     *             if more then one SPF-Record was found.
-     * @throws TempErrorException
-     *             if the lookup result was "TRY_AGAIN"
-     */
-    public String getSpfRecord(String hostname, String spfVersion)
-            throws PermErrorException, TempErrorException;
-
-    /**
-     * Get a list of IPAddr's for a server
-     * 
-     * @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(String strServer) throws PermErrorException, TempErrorException;
-
-    /**
-     * Get a list of IPAddr's for a server
-     * 
-     * @param strServer
-     *            The hostname or ipAddress whe should get the AAAA-Records for
-     * @return The ipAddresses
-     * @throws PermErrorException
-     *             if an PermError should be returned
-     * @throws TempErrorException
-     *             if the lookup result was "TRY_AGAIN"
-     */
-    public List getAAAARecords(String strServer)
-            throws PermErrorException, TempErrorException;
-
-    /**
-     * Get TXT records as a string
-     * 
-     * @param strServer
-     *            The hostname for which we want to retrieve the TXT-Record
-     * @return String which reflect the TXT-Record
-     * @throws PermErrorException
-     *             if the hostname is not resolvable
-     * @throws TempErrorException
-     *             if the lookup result was "TRY_AGAIN"
-     */
-    public String getTxtCatType(String strServer) throws PermErrorException, TempErrorException;
-
-    /**
-     * Get reverse DNS records
-     * 
-     * @param ipAddress
-     *            The ipAddress for which we want to get the PTR-Record
-     * @return the PTR-Records
-     * @throws PermErrorException
-     *             if an PermError should be returned
-     * @throws TempErrorException
-     *             if the lookup result was "TRY_AGAIN"
-     */
-
-    public List getPTRRecords(String ipAddress) throws PermErrorException,
-            TempErrorException;
-
-    /**
-     * Get a list of masked IPAddr MX-Records
+     * Retrieve dns records for the given host
      * 
-     * @param domainName
-     *            The domainName or ipaddress we want to get the ips for
-     * @return IPAddresses of the MX-Records
-     * @throws PermErrorException
-     *             if an PermError should be returned
-     * @throws TempErrorException
-     *             if the lookup result was "TRY_AGAIN"
+     * @param hostname host to be queried
+     * @param recordType the record type: MX, A, AAAA, PTR, TXT, SPF 
+     * @return an array of Strings representing the records
+     * @throws NoneException when no record is found or a textparse exception happen
+     * @throws TempErrorException on timeout.
      */
-    public List getMXRecords(String domainName)
-            throws PermErrorException, TempErrorException;
+    public List getRecords(String hostname, int recordType) throws TimeoutException;
 
     /**
      * Try to get all domain names for the running host

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/core/SPF1Data.java Mon Sep 25 07:05:13 2006
@@ -184,11 +184,10 @@
      */
     public String getClientDomain() {
         if (clientDomain == null) {
-            List domains;
             try {
-                domains = dnsProbe.getPTRRecords(ipAddress);
-                if (domains != null && domains.size() > 0) {
-                    clientDomain = (String) domains.get(0);
+                List records = dnsProbe.getRecords(IPAddr.getAddress(ipAddress).getReverseIP() + ".in-addr.arpa", DNSService.PTR);
+                if (records != null && records.size() > 0) {
+                    clientDomain = (String) records.get(0);
                 } else {
                     clientDomain = ipAddress;
                 }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AMechanism.java Mon Sep 25 07:05:13 2006
@@ -20,6 +20,7 @@
 
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.IPAddr;
 import org.apache.james.jspf.core.SPF1Data;
 import org.apache.james.jspf.exceptions.PermErrorException;
@@ -28,6 +29,7 @@
 import org.apache.james.jspf.util.Inet6Util;
 import org.apache.james.jspf.util.ConfigurationMatch;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -66,7 +68,7 @@
                 IPAddr checkAddress = IPAddr.getAddress(spfData.getIpAddress(),
                         getIp4cidr());
 
-                List aRecords =spfData.getDnsProbe().getARecords(host);
+                List aRecords = getARecords(spfData.getDnsProbe(),host);
      
                 // no a records just return null
                 if (aRecords == null) {
@@ -80,7 +82,7 @@
                 IPAddr checkAddress = IPAddr.getAddress(spfData.getIpAddress(),
                         getIp6cidr());
 
-                List aaaaRecords =spfData.getDnsProbe().getAAAARecords(host);
+                List aaaaRecords = getAAAARecords(spfData.getDnsProbe(), host);
                 
                 // no aaaa records just return false
                 if (aaaaRecords == null) {
@@ -93,6 +95,7 @@
 
             }
         } catch (Exception e) {
+            e.printStackTrace();
             throw new PermErrorException("No valid ipAddress: "
                     + spfData.getIpAddress());
         }
@@ -136,15 +139,15 @@
     public boolean checkAddressList(IPAddr checkAddress, List addressList, int cidr) throws PermErrorException {
 
         for (int i = 0; i < addressList.size(); i++) {
-            IPAddr ip = (IPAddr) addressList.get(i);
+            String ip = (String) addressList.get(i);
 
             // Check for empty record
             if (ip != null) {
                 // set the mask in the address.
                 // TODO should we use cidr from the parameters or the input checkAddress cidr?
-                ip.setMask(checkAddress.getMaskLength());
+                IPAddr ipAddr = IPAddr.getAddress(ip, checkAddress.getMaskLength());
                 if (checkAddress.getMaskedIPAddress().equals(
-                        ip.getMaskedIPAddress())) {
+                        ipAddr.getMaskedIPAddress())) {
                     return true;
                 }
             }
@@ -164,6 +167,83 @@
      */
     protected synchronized int getIp6cidr() {
         return ip6cidr;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return toString("a");
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    protected String toString(String mechKey) {
+        StringBuffer res = new StringBuffer();
+        res.append(mechKey);
+        if (getDomain() != null) {
+            res.append(":"+getDomain());
+        }
+        if (getIp4cidr() != 32) {
+            res.append("/"+getIp4cidr());
+        }
+        if (getIp6cidr() != 128) {
+            res.append("//"+getIp4cidr());
+        }
+        return res.toString();
+    }
+    
+    
+    /**
+     * Retrieve a list of AAAA records
+     */
+    public List getAAAARecords(DNSService dns, String strServer)
+            throws PermErrorException, TempErrorException {
+        List listAAAAData;
+        if (IPAddr.isIPAddr(strServer)) {
+            IPAddr ipTest = IPAddr.getAddress(strServer);
+            // Address is already an IP address, so add it to list
+            listAAAAData = new ArrayList();
+            listAAAAData.add(ipTest);
+        } else {
+            try {
+                listAAAAData = dns.getRecords(strServer, DNSService.AAAA);
+            } catch (DNSService.TimeoutException e) {
+                throw new TempErrorException("Timeout querying dns server");
+            }
+        }
+        return listAAAAData;
+    }
+
+
+    /**
+     * 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 {
+        List listAData;
+        if (IPAddr.isIPAddr(strServer)) {
+            IPAddr ipTest = IPAddr.getAddress(strServer);
+            // Address is already an IP address, so add it to list
+            listAData = new ArrayList();
+            listAData.add(ipTest);
+        } else {
+            try {
+                listAData = dns.getRecords(strServer, DNSService.A);
+            } catch (DNSService.TimeoutException e) {
+                throw new TempErrorException("Timeout querying dns server");
+            }
+        }
+        return listAData;
     }
 
 }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AllMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AllMechanism.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AllMechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/AllMechanism.java Mon Sep 25 07:05:13 2006
@@ -48,5 +48,12 @@
         // no checks needed
         // the regex only passes with no parameters
     }
+    
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return "all";
+    }
 
 }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java Mon Sep 25 07:05:13 2006
@@ -20,6 +20,7 @@
 
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.SPF1Data;
 import org.apache.james.jspf.exceptions.PermErrorException;
 import org.apache.james.jspf.exceptions.TempErrorException;
@@ -59,7 +60,7 @@
         }
 
         try {
-            aRecords = spfData.getDnsProbe().getARecords(host);
+            aRecords = spfData.getDnsProbe().getRecords(host,DNSService.A);
         } catch (Exception e) {
             e.printStackTrace();
             return false;

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExpModifier.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExpModifier.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/ExpModifier.java Mon Sep 25 07:05:13 2006
@@ -20,6 +20,7 @@
 
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.LogEnabled;
 import org.apache.james.jspf.core.Logger;
 import org.apache.james.jspf.core.SPF1Constants;
@@ -29,6 +30,8 @@
 import org.apache.james.jspf.macro.MacroExpand;
 import org.apache.james.jspf.parser.SPF1Parser;
 
+import java.util.List;
+
 /**
  * This class represent the exp modifier
  * 
@@ -67,7 +70,7 @@
         try {
             host = new MacroExpand(spfData, log).expandDomain(host);
             try {
-                exp = spfData.getDnsProbe().getTxtCatType(host);
+                exp = getTxtCatType(spfData.getDnsProbe(), host);
             } catch (TempErrorException e) {
                 // Nothing todo here.. just return null
                 return null;
@@ -96,6 +99,46 @@
      */
     public void enableLogging(Logger logger) {
         this.log = logger;
+    }
+
+
+    /**
+     * Get TXT records as a string
+     * 
+     * @param dns The DNSService to query
+     * @param strServer
+     *            The hostname for which we want to retrieve the TXT-Record
+     * @return String which reflect the TXT-Record
+     * @throws PermErrorException
+     *             if the hostname is not resolvable
+     * @throws TempErrorException
+     *             if the lookup result was "TRY_AGAIN"
+     */
+    public String getTxtCatType(DNSService dns, String strServer) throws TempErrorException {
+        try {
+            List records = dns.getRecords(strServer, DNSService.TXT);
+        
+            if (records == null) {
+                return null;
+            }
+    
+            log.debug("Concatenating " + records.size() + " TXT-Records to one String");
+    
+            StringBuffer txtData = new StringBuffer();
+            for (int i = 0; i < records.size(); i++) {
+                txtData.append(records.get(i));
+            }
+            return txtData.toString();
+        } catch (DNSService.TimeoutException e) {
+            throw new TempErrorException("Timeout querying dns server");
+        }
+    }
+    
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+       return "exp="+getHost();
     }
 
 }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java Mon Sep 25 07:05:13 2006
@@ -104,4 +104,14 @@
         return ip;
     }
 
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        if (getIp().getMaskLength() == getMaxCidr()) {
+            return "ip4:"+getIp().getIPAddress();
+        } else {
+            return "ip4:"+getIp().getIPAddress()+"/"+getIp().getMaskLength();
+        }
+    }
 }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IP6Mechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IP6Mechanism.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IP6Mechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IP6Mechanism.java Mon Sep 25 07:05:13 2006
@@ -47,4 +47,17 @@
     protected int getMaxCidr() {
         return 128;
     }
+    
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        if (getIp().getMaskLength() == getMaxCidr()) {
+            return "ip6:"+getIp().getIPAddress();
+        } else {
+            return "ip6:"+getIp().getIPAddress()+"/"+getIp().getMaskLength();
+        }
+    }
+
 }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java Mon Sep 25 07:05:13 2006
@@ -128,4 +128,10 @@
         this.log = logger;
     }
 
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return "include:"+getHost();
+    }
 }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/MXMechanism.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/MXMechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/MXMechanism.java Mon Sep 25 07:05:13 2006
@@ -20,6 +20,7 @@
 
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.IPAddr;
 import org.apache.james.jspf.core.SPF1Data;
 import org.apache.james.jspf.exceptions.NoneException;
@@ -27,6 +28,7 @@
 import org.apache.james.jspf.exceptions.TempErrorException;
 import org.apache.james.jspf.parser.SPF1Parser;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -60,7 +62,7 @@
         // get the ipAddress
         checkAddress = IPAddr.getAddress(spfData.getIpAddress(), getIp4cidr());
         
-        List mxRecords = spfData.getDnsProbe().getMXRecords(host);
+        List mxRecords = getMXRecords(spfData.getDnsProbe(), host);
 
         // no mx record found
         if (mxRecords == null) return false;
@@ -71,6 +73,55 @@
 
         // No match found
         return false;
+    }
+
+
+    /**
+     * @see org.apache.james.jspf.core.DNSService#getMXRecords(java.lang.String,
+     *      int)
+     */
+    public List getMXRecords(DNSService dnsProbe, String domainName)
+            throws PermErrorException, TempErrorException {
+        try {
+            List mxR = null;
+            List records = dnsProbe.getRecords(domainName, DNSService.MX);
+    
+            if (records == null) {
+                return null;
+            }
+            
+            // check if the maximum lookup count is reached
+            if (dnsProbe.getRecordLimit() > 0 && records.size() > dnsProbe.getRecordLimit()) {
+                throw new PermErrorException("Maximum MX lookup count reached");
+            }
+      
+            for (int i = 0; i < records.size(); i++) {
+                String mx = (String) records.get(i);
+                
+                if (mx != null && mx.length() > 0) {
+                    log.debug("Add MX-Record " + mx + " to list");
+        
+                    List res = dnsProbe.getRecords(mx, DNSService.A);
+                    if (res != null) {
+                        if (mxR == null) {
+                            mxR = new ArrayList();
+                        }
+                        mxR.addAll(res);
+                    }
+                }
+            }
+            
+            return mxR != null && mxR.size() > 0 ? mxR : null;
+        } catch (DNSService.TimeoutException e) {
+            throw new TempErrorException("Timeout querying the dns server");
+        }
+    }
+    
+    /**
+     * @see org.apache.james.jspf.terms.AMechanism#toString()
+     */
+    public String toString() {
+        return super.toString("mx");
     }
 
 }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java Mon Sep 25 07:05:13 2006
@@ -20,6 +20,7 @@
 
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.IPAddr;
 import org.apache.james.jspf.core.SPF1Data;
 import org.apache.james.jspf.exceptions.PermErrorException;
@@ -47,7 +48,6 @@
     public boolean run(SPF1Data spfData) throws PermErrorException,
             TempErrorException {
         String compareDomain;
-        IPAddr compareIP;
         ArrayList validatedHosts = new ArrayList();
 
         // update currentDepth
@@ -56,44 +56,55 @@
         // Get the right host.
         String host = expandHost(spfData);
 
+        try {
+            // Get PTR Records for the ipAddress which is provided by SPF1Data
+            IPAddr ip = IPAddr.getAddress(spfData.getIpAddress());
+            List domainList = spfData.getDnsProbe().getRecords(ip.getReverseIP() + ".in-addr.arpa", DNSService.PTR);
     
-        // Get PTR Records for the ipAddress which is provided by SPF1Data
-        List domainList = spfData.getDnsProbe().getPTRRecords(
-                spfData.getIpAddress());
-        
-        // No PTR records found
-        if (domainList == null) return false;
-       
-        for (int i = 0; i < domainList.size(); i++) {
-
-            // Get a record for this
-            List aList = spfData.getDnsProbe().getARecords(
-                    (String) domainList.get(i));
-            
-            // TODO check this: this is a direct result of the NoneException
-            // removal, and I'm not sure this is correct: maybe we should continue
-            if (aList == null) {
-                return false;
+            // No PTR records found
+            if (domainList == null) return false;
+    
+            // check if the maximum lookup count is reached
+            if (spfData.getDnsProbe().getRecordLimit() > 0 && domainList.size() > spfData.getDnsProbe().getRecordLimit()) {
+                // Truncate the PTR list to getRecordLimit.
+                // See #ptr-limit rfc4408 test
+                domainList = domainList.subList(0, spfData.getDnsProbe().getRecordLimit()-1);
+                // throw new PermErrorException("Maximum PTR lookup count reached");
             }
-            
-            for (int j = 0; j < aList.size(); j++) {
-                compareIP = (IPAddr) aList.get(j);
-                if (compareIP.toString().equals(spfData.getIpAddress())) {
-                    validatedHosts.add(domainList.get(i));
+    
+           
+            for (int i = 0; i < domainList.size(); i++) {
+    
+                // Get a record for this
+                List aList = spfData.getDnsProbe().getRecords(
+                        (String) domainList.get(i), DNSService.A);
+                
+                // TODO check this: this is a direct result of the NoneException
+                // removal, and I'm not sure this is correct: maybe we should continue
+                if (aList == null) {
+                    return false;
+                }
+                
+                for (int j = 0; j < aList.size(); j++) {
+                    if (aList.get(j).equals(spfData.getIpAddress())) {
+                        validatedHosts.add(domainList.get(i));
+                    }
                 }
             }
-        }
-
-        // Check if we match one of this ptr!
-        for (int j = 0; j < validatedHosts.size(); j++) {
-            compareDomain = (String) validatedHosts.get(j);
-            if (compareDomain.equals(host)
-                    || compareDomain.endsWith("." + host)) {
-                return true;
+    
+            // Check if we match one of this ptr!
+            for (int j = 0; j < validatedHosts.size(); j++) {
+                compareDomain = (String) validatedHosts.get(j);
+                if (compareDomain.equals(host)
+                        || compareDomain.endsWith("." + host)) {
+                    return true;
+                }
             }
+            
+            return false;
+        } catch (DNSService.TimeoutException e) {
+            throw new TempErrorException("Timeout querying the dns server");
         }
-        
-        return false;
 
     }
 

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java Mon Sep 25 07:05:13 2006
@@ -116,4 +116,10 @@
         this.log = logger;
     }
 
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return "redirect="+getHost();
+    }
 }

Modified: james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java (original)
+++ james/jspf/trunk/src/test/java/org/apache/james/jspf/AbstractYamlTest.java Mon Sep 25 07:05:13 2006
@@ -20,9 +20,6 @@
 package org.apache.james.jspf;
 
 import org.apache.james.jspf.core.DNSService;
-import org.apache.james.jspf.core.IPAddr;
-import org.apache.james.jspf.exceptions.PermErrorException;
-import org.apache.james.jspf.exceptions.TempErrorException;
 import org.jvyaml.Constructor;
 import org.jvyaml.DefaultYAMLFactory;
 import org.jvyaml.YAMLFactory;
@@ -115,7 +112,7 @@
         
         System.out.println("testing "+next+": "+currentTest.get("description"));
     
-        SPF spf = new SPF(getDNSService(), new ConsoleLogger());
+        SPF spf = new SPF(new LoggingDNSService(getDNSService()), new ConsoleLogger());
         
         String ip = null;
         String sender = null;
@@ -183,217 +180,92 @@
             this.recordLimit = 10;
         }
 
-        public List getAAAARecords(String strServer) throws PermErrorException, TempErrorException {
-            ArrayList res = new ArrayList();
-            if (zonedata.get(strServer) != null) {
-                List l = (List) zonedata.get(strServer);
-                Iterator i = l.iterator();
-
-                while (i.hasNext()) {
-                    HashMap hm = (HashMap) i.next();
-                    if (hm.get("AAAA") != null) {
-                        String a = (String) hm.get("AAAA");
-                        res.add(IPAddr.getAddress(a));
-                    }
-                }
-            }
-            if (res.size() > 0 ) return res;
-            
-            return null;
-        }
-
-        public List getARecords(String strServer) throws PermErrorException, TempErrorException {
-            ArrayList res = new ArrayList();
-       
-            if (zonedata.get(strServer) != null) {
-                List l = (List) zonedata.get(strServer);
-                Iterator i = l.iterator();
-                while (i.hasNext()) {
-                    HashMap hm = (HashMap) i.next();
-                    if (hm.get("A") != null) {
-                        String a = (String) hm.get("A");
-                        res.add(IPAddr.getAddress(a));
-                        
-                    }
-                }
-            }
-            if (res.size() > 0 ) return res;
-            
-            return null;
-        }
-
         public List getLocalDomainNames() {
             List l = new ArrayList();
             l.add("localdomain.foo.bar");
             return l; 
         }
 
-        public List getMXRecords(String domainName) throws PermErrorException, TempErrorException {
-            if (zonedata.get(domainName) != null) {
-                List l = (List) zonedata.get(domainName);
-                Iterator i = l.iterator();
-                ArrayList res = new ArrayList();
-                while (i.hasNext()) {
-                    HashMap hm = (HashMap) i.next();
-                    if (hm.get("MX") != null) {
-                        List mxList = (List) hm.get("MX");
-                         
-                        Iterator mxs = mxList.iterator();
-                
-                        while (mxs.hasNext()) {
-                            // skip the MX priority
-                            mxs.next();
-                            String mx = (String) mxs.next();
-                           
-                            // resolv the record
-                            List records = getARecords(mx);
-                            
-                            // TODO: this is a direct result of the NoneException removal
-                            // we should check wether is correct to return null or we simply
-                            // should skip this record.
-                            if (records == null) {
-                                return null;
-                            }
-                            
-                            for (int i2 = 0; i2 < records.size();i2++ ) {
-                                res.add(records.get(i2));
-                            }
-                        }
-                    }
-                }
-                // check if the maximum lookup count is reached
-                if (recordLimit > 0 && res.size() > recordLimit) throw new PermErrorException("Maximum MX lookup count reached");
-
-                return res.size() > 0 ? res : null;
+        public void setTimeOut(int timeOut) {
+            try {
+                throw new UnsupportedOperationException("setTimeOut()");
+            } catch (UnsupportedOperationException e) {
+                e.printStackTrace();
+                throw e;
             }
-            return null;
         }
 
-        public List getPTRRecords(String ipAddress) throws PermErrorException, TempErrorException {
-            ArrayList res = new ArrayList();
-            
-            if (zonedata.get(ipAddress) != null) {
-                List l = (List) zonedata.get(ipAddress);
-                Iterator i = l.iterator();
-                while (i.hasNext()) {
-                    HashMap hm = (HashMap) i.next();
-                    if (hm.get("PTR") != null) {
-                        String a = (String) hm.get("PTR");
-                        res.add(a);
-                        
-                    }
-                }
-            }
-            if (res.size() > 0 ) return res;
-            
-            return null;
+        public int getRecordLimit() {
+            return recordLimit;
         }
 
-        public String getSpfRecord(String hostname, String spfVersion) throws PermErrorException, TempErrorException {
+        public void setRecordLimit(int recordLimit) {
+            this.recordLimit = recordLimit;
+        }
+
+        public List getRecords(String hostname, int recordType) throws TimeoutException {
+            String type = getRecordTypeDescription(recordType);
+
+            List res;
+            
+            // remove trailing dot before running the search.
             if (hostname.endsWith(".")) hostname = hostname.substring(0, hostname.length()-1);
+            
             if (zonedata.get(hostname) != null) {
                 List l = (List) zonedata.get(hostname);
                 Iterator i = l.iterator();
-                String res = null;
-                boolean SPFexists = false;
+                res = new ArrayList();
                 while (i.hasNext()) {
                     Object o = i.next();
                     if (o instanceof HashMap) {
                         HashMap hm = (HashMap) o;
-                        if (hm.get("SPF") != null) {
-                            SPFexists = true;
-                            String spfrecord = (String) hm.get("SPF");
-                            if (spfrecord.startsWith(spfVersion+" ") || spfrecord.equals(spfVersion)) {
-                                if (res != null) {
-                                    throw new PermErrorException("Multiple SPF records!");
-                                } else {
-                                    res = spfrecord;
+                        if (hm.get(type) != null) {
+                            if (recordType == DNSService.MX) {
+                                List mxList = (List) hm.get(type);
+    
+                                // For MX records we overwrite the result ignoring the priority.
+                                Iterator mxs = mxList.iterator();
+                                while (mxs.hasNext()) {
+                                    // skip the MX priority
+                                    mxs.next();
+                                    String cname = (String) mxs.next();
+                                    res.add(cname);
                                 }
                             } else {
-                                System.err.println("#####1 unmatched: "+spfrecord);
+                                res.add((String) hm.get(type));
                             }
                         }
+                    } else if ("TIMEOUT".equals(o)) {
+                        throw new TimeoutException();
                     } else {
-                        System.err.println("[[[[[[[[[[[[[[[[[[[[1 "+o.getClass().toString()+" ! "+o);
-                    }
-                }
-                if (!SPFexists) {
-                    i = l.iterator();
-                    while (i.hasNext()) {
-                        Object o = i.next();
-                        if (o instanceof HashMap) {
-                            HashMap hm = (HashMap) o;
-                            if (hm.get("TXT") != null) {
-                                String spfrecord = (String) hm.get("TXT");
-                                if (spfrecord.startsWith(spfVersion+" ") || spfrecord.equals(spfVersion)) {
-                                    if (res != null) {
-                                        throw new PermErrorException("Multiple TXT records!");
-                                    } else {
-                                        res = spfrecord;
-                                    }
-                                } else {
-                                    System.err.println("#####2 unmatched: "+spfrecord);
-                                }
-                            }
-                        } else if (o.toString().equals("TIMEOUT")) {
-                            throw new TempErrorException("Timeout");
-                        } else {
-                            System.err.println("[[[[[[[[[[[[[[[[[[[[2 "+o.getClass().toString()+" ! "+o);
-                        }
-                    }
-                }
-                if (res != null) return res;
-            }
-            int p = hostname.indexOf(".");
-            if (p > 0) {
-                hostname = hostname.substring(p+1);
-                if (zonedata.get(hostname) != null) {
-                    if (((List) zonedata.get(hostname)).iterator().next().equals("TIMEOUT")) {
-                        throw new TempErrorException("TIMEOUT");
+                        throw new IllegalStateException("getRecord found an unexpected data");
                     }
                 }
+                return res.size() > 0 ? res : null;
             }
             return null;
         }
 
-        public String getTxtCatType(String strServer) throws PermErrorException, TempErrorException {
-            String res = null;
-            if (strServer.endsWith(".")) strServer = strServer.substring(0, strServer.length()-1);
-            if (zonedata.get(strServer) != null) {
-                List l = (List) zonedata.get(strServer);
-                Iterator i = l.iterator();
-
-                while (i.hasNext()) {
-                    HashMap hm = (HashMap) i.next();
-                    if (hm.get("TXT") != null) {
-                        String spfrecord = (String) hm.get("TXT");
-                        if (res != null) res+=" "; else res = "";
-                        res += spfrecord;
-                    }
-                }
-
-            }
-            return res;
-        }
-
-        public void setTimeOut(int timeOut) {
-            try {
-                throw new UnsupportedOperationException("setTimeOut()");
-            } catch (UnsupportedOperationException e) {
-                e.printStackTrace();
-                throw e;
-            }
-        }
-
-        public int getRecordLimit() {
-            return recordLimit;
-        }
+    }
 
-        public void setRecordLimit(int recordLimit) {
-            this.recordLimit = recordLimit;
+    
+    /**
+     * Return a string representation of a DNSService record type.
+     * 
+     * @param recordType the DNSService.CONSTANT type to convert
+     * @return a string representation of the given record type
+     */
+    public static String getRecordTypeDescription(int recordType) {
+        switch (recordType) {
+            case DNSService.A: return "A";
+            case DNSService.AAAA: return "AAAA";
+            case DNSService.MX: return "MX";
+            case DNSService.PTR: return "PTR";
+            case DNSService.TXT: return "TXT";
+            case DNSService.SPF: return "SPF";
+            default: return null;
         }
     }
-
 
     protected static class SPFYamlTestSuite {
         public String comment;

Modified: james/jspf/trunk/src/test/java/org/apache/james/jspf/LoggingDNSService.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/test/java/org/apache/james/jspf/LoggingDNSService.java?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/test/java/org/apache/james/jspf/LoggingDNSService.java (original)
+++ james/jspf/trunk/src/test/java/org/apache/james/jspf/LoggingDNSService.java Mon Sep 25 07:05:13 2006
@@ -17,19 +17,23 @@
  * under the License.                                           *
  ****************************************************************/
 
-
 package org.apache.james.jspf;
 
 import org.apache.james.jspf.core.DNSService;
-import org.apache.james.jspf.core.IPAddr;
-import org.apache.james.jspf.exceptions.PermErrorException;
-import org.apache.james.jspf.exceptions.TempErrorException;
 
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 public class LoggingDNSService implements DNSService {
+
+    private DNSService dnsService;
+
+    public LoggingDNSService(DNSService service) {
+        this.dnsService = service;
+    }
+
+    public LoggingDNSService() {
+        this.dnsService = new DNSServiceXBillImpl(new ConsoleLogger());
+    }
     
     public int getRecordLimit() {
         return dnsService.getRecordLimit();
@@ -39,27 +43,6 @@
         dnsService.setRecordLimit(recordLimit);
     }
 
-    private DNSService dnsService = new DNSServiceXBillImpl(new ConsoleLogger());
-
-    public String getSpfRecord(String hostname, String spfVersion)
-            throws PermErrorException, TempErrorException {
-        try {
-            String res = dnsService.getSpfRecord(hostname, spfVersion);
-
-            System.out.println("getSpfRecord(" + hostname + "," + spfVersion
-                    + ") = " + res);
-            return res;
-        } catch (TempErrorException e) {
-            System.out.println("getSpfRecord(" + hostname + "," + spfVersion
-                    + ") = TempErrorException[" + e.getMessage() + "]");
-            throw e;
-        } catch (PermErrorException e) {
-            System.out.println("getSpfRecord(" + hostname + "," + spfVersion
-                    + ") = PermErrorException[" + e.getMessage() + "]");
-            throw e;
-        }
-    }
-
     public List getLocalDomainNames() {
         List res = dnsService.getLocalDomainNames();
         System.out.print("getLocalDomainNames() = ");
@@ -79,151 +62,31 @@
 
     }
 
-    public List getAAAARecords(String strServer)
-            throws PermErrorException, TempErrorException {
-
-        try {
-            List res = dnsService.getAAAARecords(strServer);
-            System.out.print("getAAAARecords(" + strServer + ") = ");
-            if (res != null) {
-                for (int i = 0; i < res.size(); i++) {
-                    System.out.print(res.get(i));
-                    if (i == res.size() - 1) {
-                        System.out.println("");
-                    } else {
-                        System.out.print(",");
-                    }
-                }
-            } else {
-                System.out.println("getAAAARecords-ret: null");
-            }
-            return res;
-
-        } catch (TempErrorException e) {
-            System.out.println("getAAAARecords(" + strServer + ") = TermErrorException[" + e.getMessage() + "]");
-            throw e;
-        } catch (PermErrorException e) {
-            System.out.println("getAAAARecords(" + strServer + ") = PermErrorException[" + e.getMessage() + "]");
-            throw e;
-        }
-    }
-
-    public List getARecords(String strServer) throws PermErrorException, TempErrorException {
-        try {
-            List res = dnsService.getARecords(strServer);
-            System.out.print("getARecords(" + strServer + ") = ");
-            if (res != null) {
-                for (int i = 0; i < res.size(); i++) {
-                    System.out.print(res.get(i));
-                    if (i == res.size() - 1) {
-                        System.out.println("");
-                    } else {
-                        System.out.print(",");
-                    }
-                }
-            } else {
-                System.out.println("getARecords-ret: null");
-            }
-            return res;
-
-        } catch (TempErrorException e) {
-            System.out.println("getARecords(" + strServer + ") = TermErrorException[" + e.getMessage() + "]");
-            throw e;
-        } catch (PermErrorException e) {
-            System.out.println("getARecords(" + strServer + ") = PermErrorException[" + e.getMessage() + "]");
-            throw e;
-        }
-
-    }
-
-    public String getTxtCatType(String strServer) throws PermErrorException, TempErrorException {
-        try {
-            String res = dnsService.getTxtCatType(strServer);
-            System.out.println("getTxtCatType(" + strServer + ") = " + res);
-            return res;
-        } catch (TempErrorException e) {
-            System.out.println("getTxtCatType(" + strServer
-                    + ") = TempErrorException[" + e.getMessage() + "]");
-            throw e;
-        } catch (PermErrorException e) {
-            System.out.println("getTxtCatType(" + strServer
-                    + ") = PermErrorException[" + e.getMessage() + "]");
-            throw e;
-        }
-
+    public void setTimeOut(int timeOut) {
+        // MOCK
     }
 
-    public List getPTRRecords(String ipAddress) throws PermErrorException, TempErrorException {
+    public List getRecords(String hostname, int recordType) throws TimeoutException {
         try {
-            List res = dnsService.getPTRRecords(ipAddress);
-            System.out.print("getPTRRecords(" + ipAddress + ") = ");
-            if (res != null) {
-                for (int i = 0; i < res.size(); i++) {
-                    System.out.print(res.get(i));
-                    if (i == res.size() - 1) {
+            List result = dnsService.getRecords(hostname, recordType);
+            System.out.print("getRecords(" + hostname + "," + recordType + ") = ");
+            if (result != null) {
+                for (int i = 0; i < result.size(); i++) {
+                    System.out.print(result.get(i));
+                    if (i == result.size() - 1) {
                         System.out.println("");
                     } else {
                         System.out.print(",");
                     }
                 }
             } else {
-                System.out.println("null");
+                System.out.println("getRecords-ret: null");
             }
-            return res;
-        } catch (TempErrorException e) {
-            System.out.println("getPTRRecords(" + ipAddress
+            return result;
+        } catch (TimeoutException e) {
+            System.out.println("getRecords(" + hostname
                     + ") = TempErrorException[" + e.getMessage() + "]");
             throw e;
-        } catch (PermErrorException e) {
-            System.out.println("getPTRRecords(" + ipAddress
-                    + ") = PermErrorException[" + e.getMessage() + "]");
-            throw e;
-        }
-
-    }
-
-    public List getAddressList(String list, int mask) throws PermErrorException {
-        if (list == null || "".equals(list)) {
-            return new ArrayList();
-        }
-        String[] s = list.split(",");
-        IPAddr[] ips = new IPAddr[s.length];
-        for (int i = 0; i < s.length; i++) {
-            ips[i] = IPAddr.getAddress(s[i], mask);
-        }
-        return new ArrayList(Arrays.asList(ips));
-    }
-
-    public List getMXRecords(String domainName)
-            throws PermErrorException, TempErrorException {
-        try {
-            List res = dnsService.getMXRecords(domainName);
-            System.out
-                    .print("getMXRecords(" + domainName + ") = ");
-            if (res != null) {
-                for (int i = 0; i < res.size(); i++) {
-                    System.out.print(res.get(i));
-                    if (i == res.size() - 1) {
-                        System.out.println("");
-                    } else {
-                        System.out.print(",");
-                    }
-                }
-            } else {
-                System.out.println("null");
-            }
-            return res;
-        } catch (TempErrorException e) {
-            System.out.println("getMXRecords(" + domainName + ") = TempErrorException[" + e.getMessage() + "]");
-            throw e;
-        } catch (PermErrorException e) {
-            System.out.println("getMXRecords(" + domainName + ") = ErrorException[" + e.getMessage() + "]");
-            throw e;
         }
-
-    }
-
-    public void setTimeOut(int timeOut) {
-        // MOCK
     }
 }

Modified: james/jspf/trunk/src/test/resources/org/apache/james/jspf/mailzone-tests.yml
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/test/resources/org/apache/james/jspf/mailzone-tests.yml?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/test/resources/org/apache/james/jspf/mailzone-tests.yml (original)
+++ james/jspf/trunk/src/test/resources/org/apache/james/jspf/mailzone-tests.yml Mon Sep 25 07:05:13 2006
@@ -1030,17 +1030,17 @@
     - MX:  [0, 192.0.2.11.addr]
   www1.cnn.com:
     - A:  64.236.24.4
-  208.210.124.1:
+  1.124.210.208.in-addr.arpa:
     - PTR:  pobox-gw.icgroup.com
-  208.210.124.130:
+  130.124.210.208.in-addr.arpa:
     - PTR:  30.spf1-test.mailzone.com
-  208.210.124.131:
+  131.124.210.208.in-addr.arpa:
     - PTR:  31.spf1-test.mailzone.com
-  208.210.124.180:
+  180.124.210.208.in-addr.arpa:
     - PTR:  80.spf1-test.mailzone.com
-  208.210.124.192:
+  192.124.210.208.in-addr.arpa:
     - PTR:  spf1-test.mailzone.com
-  64.236.24.4:
+  4.24.236.64.in-addr.arpa:
     - PTR:  www1.cnn.com
   fallback-relay.spf1-test.mailzone.com:
     - MX:  [0, 192.0.2.40.addr]

Modified: james/jspf/trunk/src/test/resources/org/apache/james/jspf/rfc4408-tests.yml
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/test/resources/org/apache/james/jspf/rfc4408-tests.yml?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/test/resources/org/apache/james/jspf/rfc4408-tests.yml (original)
+++ james/jspf/trunk/src/test/resources/org/apache/james/jspf/rfc4408-tests.yml Mon Sep 25 07:05:13 2006
@@ -8,7 +8,8 @@
 #   Craig Whitmore
 #   Frank Ellermann
 #
-# 17/07/2006 from http://www.openspf.org/svn/project/test-suite/rfc4408-tests.yml
+# 25/07/2006 from http://www.openspf.org/svn/project/test-suite/rfc4408-tests.yml
+# Changed the first test to add 10 more chars to the label (54 => 64 in length)
 ---
 description: Initial processing
 tests:
@@ -289,6 +290,68 @@
 
 ---
 description: >-
+  ALL mechanism syntax
+tests:
+  all-dot:
+    description: |
+      all              = "all"
+    comment: |-
+      At least one implementation got this wrong
+    spec: 5.1/1
+    helo: mail.example.com
+    host: 1.2.3.4
+    mailfrom: foo@e1.example.com
+    result: permerror
+  all-arg:
+    description: |
+      all              = "all"
+    comment: |-
+      At least one implementation got this wrong
+    spec: 5.1/1
+    helo: mail.example.com
+    host: 1.2.3.4
+    mailfrom: foo@e2.example.com
+    result: permerror
+  all-cidr:
+    description: |
+      all              = "all"
+    spec: 5.1/1
+    helo: mail.example.com
+    host: 1.2.3.4
+    mailfrom: foo@e3.example.com
+    result: permerror
+  all-neutral:
+    description: |
+      all              = "all"
+    spec: 5.1/1
+    helo: mail.example.com
+    host: 1.2.3.4
+    mailfrom: foo@e4.example.com
+    result: neutral
+  all-double:
+    description: |
+      all              = "all"
+    spec: 5.1/1
+    helo: mail.example.com
+    host: 1.2.3.4
+    mailfrom: foo@e5.example.com
+    result: pass
+zonedata:
+  mail.example.com:
+    - A: 1.2.3.4
+  e1.example.com:
+    - SPF: v=spf1 -all.
+  e2.example.com:
+    - SPF: v=spf1 -all:foobar
+  e3.example.com:
+    - SPF: v=spf1 -all/8
+  e4.example.com:
+    - SPF: v=spf1 ?all
+  e5.example.com:
+    - SPF: v=spf1 all -all
+
+---
+description: >-
   A mechanism syntax
 tests:
   a-cidr6:
@@ -691,6 +754,15 @@
     mailfrom: foo@e1.example.com
     result: fail
     explanation: DEFAULT
+  include-ignores-exp:
+    description: >-
+      when executing "incde", exp= from the target domain MUST NOT be used.
+    spec: 6.2/13
+    helo: mail.example.com
+    host: 1.2.3.4
+    mailfrom: foo@e7.example.com
+    result: fail
+    explanation: Correct!
   redirect-cancels-prior-exp:
     description: >-
       when executing "redirect", exp= from the original domain MUST NOT be used.
@@ -736,14 +808,18 @@
     - TXT: No-see-um
   exp2.example.com:
     - TXT: See me.
+  exp3.example.com:
+    - TXT: Correct!
   e5.example.com:
     - SPF: v=spf1 1up=foo
   e6.example.com:
     - SPF: v=spf1 =all
+  e7.example.com:
+    - SPF: v=spf1 include:e3.example.com -all exp=exp3.example.com
 
 ---
 description: |
-  check trailing dot with redirect and exp
+  check macro expansion rules
 tests:
   trailing-dot-domain:
     spec: 8.1/16
@@ -766,6 +842,45 @@
     mailfrom: test@exp.example.com
     result: fail
     explanation: This is a test.
+  invalid-macro-char:
+    spec: 8.1/19
+    description: >-
+      A '%' character not followed by a '{', '%', '-', or '_' character
+      is a syntax error.
+    helo: msgbas2x.cos.example.com
+    host: 192.168.218.40
+    mailfrom: test@e1.example.com
+    result: permerror
+  exp-only-macro-char:
+    spec: 8.1/16
+    description: >-
+      The following macro letters are allowed only in "exp" text: c, r, t
+    helo: msgbas2x.cos.example.com
+    host: 192.168.218.40
+    mailfrom: test@e2.example.com
+    result: permerror
+  exp-txt-macro-char:
+    spec: 8.1/31
+    description: >-
+      For IPv4 addresses, both the "i" and "c" macros expand
+      to the standard dotted-quad format.
+    helo: msgbas2x.cos.example.com
+    host: 192.168.218.40
+    mailfrom: test@e3.example.com
+    result: fail
+    explanation: Connections from 192.168.218.40 not authorized.
+  domain-name-truncation:
+    spec: 8.1/36
+    description: >-
+      When the result of macro expansion is used in a domain name query, if the
+      expanded domain name exceeds 253 characters, the left side is truncated
+      to fit, by removing successive domain labels until the total length does
+      not exceed 253 characters.
+    helo: msgbas2x.cos.example.com
+    host: 192.168.218.40
+    mailfrom: test@somewhat.long.exp.example.com
+    result: fail
+    explanation: Congratulations!  That was tricky.
 zonedata:
   example.com.d.spf.example.com:
     - SPF: v=spf1 redirect=a.spf.example.com
@@ -773,8 +888,8 @@
     - SPF: v=spf1 include:o.spf.example.com. ~all
   o.spf.example.com:
     - SPF: v=spf1 ip4:192.168.218.40
-  msgbas1x.cos.example.com:
-    - A: 192.168.240.36
+  msgbas2x.cos.example.com:
+    - A: 192.168.218.40
   example.com:
     - A: 192.168.90.76
     - SPF: v=spf1 redirect=%{d}.d.spf.example.com.
@@ -782,6 +897,18 @@
     - SPF: v=spf1 exp=msg.example.com. -all
   msg.example.com:
     - TXT: This is a test.
+  e1.example.com:
+    - SPF: v=spf1 -exists:%(ir).sbl.example.com ?all
+  e2.example.com:
+    - SPF: v=spf1 -all exp=%{r}.example.com
+  e3.example.com:
+    - SPF: v=spf1 -all exp=%{ir}.example.com
+  40.218.168.192.example.com:
+    - TXT: Connections from %{c} not authorized.
+  somewhat.long.exp.example.com:
+    - SPF: v=spf1 -all exp=foobar.%{o}.%{o}.%{o}.%{o}.%{o}.%{o}.%{o}.%{o}.example.com
+  somewhat.long.exp.example.com.somewhat.long.exp.example.com.somewhat.long.exp.example.com.somewhat.long.exp.example.com.somewhat.long.exp.example.com.somewhat.long.exp.example.com.somewhat.long.exp.example.com.somewhat.long.exp.example.com.example.com:
+    - TXT: Congratulations!  That was tricky.
 
 ---
 description: >-
@@ -809,16 +936,36 @@
     description: >-
       there MUST be a limit of no more than 10 MX looked up and checked.
     comment: >-
-      While the MX and PTR limits immediately follow a paragraph mandating
-      a permerror for exeeding limits, some of the SPF community feel that
-      more than 10 MX records should simply be ignored.  However, ignoring
-      the excess MX records can cause SPF results that are different for
-      each query.  A permerror is the right response.
+      The required result for this test was the subject of much
+      controversy.  Many felt that the RFC *should* have specified
+      permerror, but the concensus was that it failed to actually do so.
+      The preferred result reflects evaluating the 10 allowed MX records in the
+      order returned by the test data - or sorted via priority.
+      If testing with live DNS, the MX order may be random, and a pass
+      result would still be compliant.  The SPF result is effectively
+      random.
     spec: 10.1/7
     helo: mail.example.com
     host: 1.2.3.5
     mailfrom: foo@e4.example.com
-    result: permerror
+    result: [neutral, pass]
+  ptr-limit:
+    description: >-
+      there MUST be a limit of no more than 10 PTR looked up and checked.
+    comment: >-
+      The result of this test cannot be permerror not only because the
+      RFC doesn't specify it, but because the sender has no control over
+      the PTR records of spammers.
+      The preferred result reflects evaluating the 10 allowed PTR records in
+      the order returned by the test data.
+      If testing with live DNS, the PTR order may be random, and a pass
+      result would still be compliant.  The SPF result is effectively
+      randomized.
+    spec: 10.1/7
+    helo: mail.example.com
+    host: 1.2.3.5
+    mailfrom: foo@e5.example.com
+    result: [neutral, pass]
 zonedata:
   mail.example.com:
     - A: 1.2.3.4
@@ -842,3 +989,18 @@
     - MX: [9, mail.example.com]
     - MX: [10, e4.example.com]
     - A: 1.2.3.5
+  e5.example.com:
+    - SPF: v=spf1 ptr
+    - A: 1.2.3.5
+  5.3.2.1.in-addr.arpa:
+    - PTR: e1.example.com.
+    - PTR: e2.example.com.
+    - PTR: e3.example.com.
+    - PTR: e4.example.com.
+    - PTR: example.com.
+    - PTR: e6.example.com.
+    - PTR: e7.example.com.
+    - PTR: e8.example.com.
+    - PTR: e9.example.com.
+    - PTR: e10.example.com.
+    - PTR: e5.example.com.

Modified: james/jspf/trunk/src/test/resources/org/apache/james/jspf/tests.yml
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/test/resources/org/apache/james/jspf/tests.yml?view=diff&rev=449683&r1=449682&r2=449683
==============================================================================
--- james/jspf/trunk/src/test/resources/org/apache/james/jspf/tests.yml (original)
+++ james/jspf/trunk/src/test/resources/org/apache/james/jspf/tests.yml Mon Sep 25 07:05:13 2006
@@ -167,13 +167,13 @@
     - TXT:  v=spf1 -all exp=exp-spf24-test.foo.bar
   exp-spf24-test.foo.bar:
     - TXT:  Explanation %{r} - %{p} (%{o})
-  10.0.0.24:
+  24.0.0.10.in-addr.arpa:
     - PTR:  my.host.domain.foo.bar
   spf25-test.foo.bar:
     - TXT:  v=spf1 -all exp=exp-spf25-test.foo.bar
   exp-spf25-test.foo.bar:
     - TXT:  Explanation %{c}
-  10.0.0.25:
+  25.0.0.10.in-addr.arpa:
     - PTR:  my.host2.domain.foo.bar
   spf26-test.foo.bar:
     - TXT:  v=spf1 -all exp=exp-spf26-test.foo.bar



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