james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject cvs commit: james-server/src/java/org/apache/james/dnsserver DNSServer.java
Date Wed, 07 Apr 2004 18:34:12 GMT
noel        2004/04/07 11:34:12

  Modified:    src/java/org/apache/james/dnsserver Tag: branch_2_1_fcs
                        DNSServer.java
  Log:
  Changed getSMTPHostAddresses to call findMXRecords, which already knew how to return a collection
of  MX hosts or the host if there weren't any MX records defined.
  
  Changed to use InetAddress.getAllByAddress rather than invoking DNS lookup directly.  The
former is more robust, and handles CNAME RR (even if it is recommended that an MX never have
a CNAME on the RHS).
  
  Left MxSorter in place so that we can discuss fixing and keeping it, or removing it.  Comments
indicate the change(s) to fix it.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.9.4.15  +31 -4     james-server/src/java/org/apache/james/dnsserver/DNSServer.java
  
  Index: DNSServer.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/dnsserver/DNSServer.java,v
  retrieving revision 1.9.4.14
  retrieving revision 1.9.4.15
  diff -u -r1.9.4.14 -r1.9.4.15
  --- DNSServer.java	4 Apr 2004 03:52:09 -0000	1.9.4.14
  +++ DNSServer.java	7 Apr 2004 18:34:11 -0000	1.9.4.15
  @@ -369,7 +369,7 @@
        */
       public Iterator getSMTPHostAddresses(final String domainName) {
           return new Iterator() {
  -            private Iterator mxHosts = new MxSorter(domainName);
  +            private Iterator mxHosts = findMXRecords(domainName).iterator();
               private Iterator addresses = null;
   
               public boolean hasNext() {
  @@ -382,16 +382,30 @@
                    */
                   if ((addresses == null || !addresses.hasNext()) && mxHosts.hasNext())
do {
                       final String nextHostname = (String)mxHosts.next();
  +                    InetAddress[] addrs = null;
  +                    try {
  +                        addrs = InetAddress.getAllByName(nextHostname);
  +                    } catch (UnknownHostException uhe) {
  +                        // this should never happen, since we just got
  +                        // this host from mxHosts, which should have
  +                        // already done this check.
  +                        StringBuffer logBuffer = new StringBuffer(128)
  +                                                 .append("Couldn't resolve IP address for
discovered host ")
  +                                                 .append(nextHostname)
  +                                                 .append(".");
  +                        getLogger().error(logBuffer.toString());
  +                    }
  +                    final InetAddress[] ipAddresses = addrs;
  +
                       addresses = new Iterator() {
  -                        private Record[] aRecords = lookup(nextHostname, Type.A);
                           int i = 0;
   
                           public boolean hasNext() {
  -                            return aRecords != null && i < aRecords.length;
  +                            return ipAddresses != null && i < ipAddresses.length;
                           }
   
                           public Object next() {
  -                            return new org.apache.mailet.HostAddress(nextHostname, "smtp://"
+ ((ARecord)aRecords[i++]).getAddress().getHostAddress());
  +                            return new org.apache.mailet.HostAddress(nextHostname, "smtp://"
+ ipAddresses[i++].getHostAddress());
                           }
   
                           public void remove() {
  @@ -431,6 +445,19 @@
        * This behavior attempts to satisfy the requirements of RFC 2821, Section 5.
        * @since v2.2.0a16-unstable
        */
  +
  +    /**** THIS CODE IS BROKEN AND UNUSED ****/
  +
  +    /* this code was used in getSMTPHostAddresses as:
  +       private Iterator mxHosts = new MxSorter(domainName);
  +
  +       This class effectively replaces findMXRecords.  If
  +       it is to be kept, it should replace the body of that
  +       method.  The fixes would be to either implement a
  +       more robust DNS lookup, or to replace the Type.A
  +       lookup with InetAddress.getByName(), which is what
  +       findMXRecords uses.  */
  +
       private class MxSorter implements Iterator {
           private int priorListPriority = Integer.MIN_VALUE;
           private ArrayList equiPriorityList = new ArrayList();
  
  
  

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