Author: bago
Date: Sat Apr 21 12:13:27 2007
New Revision: 531089
URL: http://svn.apache.org/viewvc?view=rev&rev=531089
Log:
Temporary example on how the AMechanism will need to change to support the
events.
WARNING: This introduces compilation errors around and changes to interfaces
that will need to be reverted later.
Added:
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/util/DNSResolver.java
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Mechanism.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
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Mechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Mechanism.java?view=diff&rev=531089&r1=531088&r2=531089
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Mechanism.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Mechanism.java
Sat Apr 21 12:13:27 2007
@@ -45,5 +45,11 @@
*/
public boolean run(SPFSession spfData) throws PermErrorException,
TempErrorException, NoneException;
+
+ /**
+ * Temporary, to evaluate impact on the redesign.
+ */
+ public boolean onDNSResponse(DNSResponse response, SPFSession spfSession)
throws PermErrorException,
+ TempErrorException, NoneException;
}
Added:
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=auto&rev=531089
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerDNSResponseListener.java
(added)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerDNSResponseListener.java
Sat Apr 21 12:13:27 2007
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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;
+
+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;
+
+public interface SPFCheckerDNSResponseListener {
+
+ /**
+ * Continue the check for SPF with the given values and the given
DNSResponse
+ *
+ * @param response
+ * The DNSResponse which should be used to run the check
+ * @param session
+ * The SPFSession which should be used to run the check
+ * @throws PermErrorException
+ * Get thrown if an error was detected
+ * @throws NoneException
+ * Get thrown if no Record was found
+ * @throws TempErrorException
+ * Get thrown if a DNS problem was detected
+ * @throws NeutralException
+ * Get thrown if the result should be neutral
+ */
+ public void onDNSResponse(DNSResponse response, SPFSession session) throws
PermErrorException, NoneException, TempErrorException, NeutralException;
+
+}
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=531089&r1=531088&r2=531089
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
Sat Apr 21 12:13:27 2007
@@ -21,11 +21,15 @@
package org.apache.james.jspf.terms;
import org.apache.james.jspf.core.Configuration;
+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.SPFSession;
+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.DNSResolver;
import org.apache.james.jspf.util.Inet6Util;
import org.apache.james.jspf.util.SPFTermsRegexps;
import org.apache.james.jspf.wiring.DNSServiceEnabled;
@@ -66,34 +70,24 @@
// get the ipAddress
try {
- if (Inet6Util.isValidIPV4Address(spfData.getIpAddress())) {
-
- IPAddr checkAddress = IPAddr.getAddress(spfData.getIpAddress(),
- getIp4cidr());
+ boolean validIPV4Address =
Inet6Util.isValidIPV4Address(spfData.getIpAddress());
+ spfData.setAttribute("AMechanism.ipv4check",
Boolean.valueOf(validIPV4Address));
+ if (validIPV4Address) {
List aRecords = getARecords(dnsService,host);
-
- // no a records just return null
if (aRecords == null) {
- return false;
- }
-
- if (checkAddressList(checkAddress, aRecords, getIp4cidr())) {
- return true;
+ return onDNSResponse(DNSResolver.lookup(dnsService, new
DNSRequest(host, DNSService.A)), spfData);
+ } else {
+ return onDNSResponse(new DNSResponse(aRecords), spfData);
}
+
} else {
- IPAddr checkAddress = IPAddr.getAddress(spfData.getIpAddress(),
- getIp6cidr());
-
- List aaaaRecords = getAAAARecords(dnsService, host);
- // no aaaa records just return false
+ List aaaaRecords = getAAAARecords(dnsService, host);
if (aaaaRecords == null) {
- return false;
- }
-
- if (checkAddressList(checkAddress, aaaaRecords, getIp6cidr()))
{
- return true;
+ return onDNSResponse(DNSResolver.lookup(dnsService, new
DNSRequest(host, DNSService.AAAA)), spfData);
+ } else {
+ return onDNSResponse(new DNSResponse(aaaaRecords),
spfData);
}
}
@@ -104,8 +98,6 @@
throw new PermErrorException("No valid ipAddress: "
+ spfData.getIpAddress());
}
- // No match found
- return false;
}
/**
@@ -205,17 +197,11 @@
*/
public List getAAAARecords(DNSService dns, String strServer)
throws PermErrorException, TempErrorException {
- List listAAAAData;
+ List listAAAAData = null;
if (IPAddr.isIPV6(strServer)) {
// Address is already an IP address, so add it to list
listAAAAData = new ArrayList();
listAAAAData.add(strServer);
- } else {
- try {
- listAAAAData = dns.getRecords(strServer, DNSService.AAAA);
- } catch (DNSService.TimeoutException e) {
- throw new TempErrorException("Timeout querying dns server");
- }
}
return listAAAAData;
}
@@ -234,16 +220,10 @@
* if the lookup result was "TRY_AGAIN"
*/
public List getARecords(DNSService dns, String strServer) throws
PermErrorException, TempErrorException {
- List listAData;
+ List listAData = null;
if (IPAddr.isIPAddr(strServer)) {
listAData = new ArrayList();
listAData.add(strServer);
- } else {
- try {
- listAData = dns.getRecords(strServer, DNSService.A);
- } catch (DNSService.TimeoutException e) {
- throw new TempErrorException("Timeout querying dns server");
- }
}
return listAData;
}
@@ -253,6 +233,46 @@
*/
public void enableDNSService(DNSService service) {
this.dnsService = service;
+ }
+
+ /**
+ * @see
org.apache.james.jspf.core.Mechanism#onDNSResponse(org.apache.james.jspf.core.SPFSession)
+ */
+ public boolean onDNSResponse(DNSResponse response, SPFSession spfSession)
+ throws PermErrorException, TempErrorException, NoneException {
+ List listAData = null;
+ try {
+ listAData = response.getResponse();
+ } catch (DNSService.TimeoutException e) {
+ throw new TempErrorException("Timeout querying dns server");
+ }
+ // no a records just return null
+ if (listAData == null) {
+ return false;
+ }
+
+ Boolean ipv4check = (Boolean)
spfSession.getAttribute("AMechanism.ipv4check");
+ if (ipv4check.booleanValue()) {
+
+ IPAddr checkAddress = IPAddr.getAddress(spfSession.getIpAddress(),
+ getIp4cidr());
+
+ if (checkAddressList(checkAddress, listAData, getIp4cidr())) {
+ return true;
+ }
+
+ } else {
+
+ IPAddr checkAddress = IPAddr.getAddress(spfSession.getIpAddress(),
+ getIp6cidr());
+
+ if (checkAddressList(checkAddress, listAData, getIp6cidr())) {
+ return true;
+ }
+
+ }
+
+ return false;
}
}
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=531089&r1=531088&r2=531089
==============================================================================
---
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
Sat Apr 21 12:13:27 2007
@@ -22,9 +22,12 @@
import org.apache.james.jspf.core.Configurable;
import org.apache.james.jspf.core.Configuration;
+import org.apache.james.jspf.core.DNSResponse;
import org.apache.james.jspf.core.Mechanism;
import org.apache.james.jspf.core.SPFSession;
+import org.apache.james.jspf.exceptions.NoneException;
import org.apache.james.jspf.exceptions.PermErrorException;
+import org.apache.james.jspf.exceptions.TempErrorException;
/**
* This class represent the all mechanism
@@ -54,6 +57,15 @@
*/
public String toString() {
return "all";
+ }
+
+ /**
+ * @see
org.apache.james.jspf.core.Mechanism#onDNSResponse(org.apache.james.jspf.core.SPFSession)
+ */
+ public boolean onDNSResponse(DNSResponse response, SPFSession spfSession)
+ throws PermErrorException, TempErrorException, NoneException {
+ // never called
+ return false;
}
}
Added:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java?view=auto&rev=531089
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
(added)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
Sat Apr 21 12:13:27 2007
@@ -0,0 +1,40 @@
+/****************************************************************
+ * 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.util;
+
+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.DNSService.TimeoutException;
+
+public class DNSResolver {
+
+ /**
+ * This is used temporarily to synchronously obtain a DNSResponse for a
DNSRequest
+ */
+ public static DNSResponse lookup(DNSService service, DNSRequest request) {
+ try {
+ return new DNSResponse(service.getRecords(request.getHostname(),
request.getRecordType()));
+ } catch (TimeoutException e) {
+ return new DNSResponse(e);
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]