Author: bago
Date: Sun May 31 14:42:37 2009
New Revision: 780443
URL: http://svn.apache.org/viewvc?rev=780443&view=rev
Log:
DNSJava already parsed quoted TXT records correctly, so I moved the "unquote"
to the resolver instead of the SPFRetriever that now expect a single, unquoted,
string (JSPF-72)
Modified:
james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/policies/SPFRetriever.java
james/jspf/trunk/resolver/src/test/java/org/apache/james/jspf/DNSServiceXBillImplTest.java
Modified:
james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java?rev=780443&r1=780442&r2=780443&view=diff
==============================================================================
---
james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
(original)
+++
james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
Sun May 31 14:42:37 2009
@@ -39,6 +39,7 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
/**
@@ -180,6 +181,7 @@
if (rr != null && rr.length > 0) {
records = new ArrayList();
for (int i = 0; i < rr.length; i++) {
+ System.out.println(rr[i].getType());
switch (rr[i].getType()) {
case Type.A:
ARecord a = (ARecord) rr[i];
@@ -199,11 +201,31 @@
break;
case Type.TXT:
TXTRecord txt = (TXTRecord) rr[i];
- records.add(txt.rdataToString());
+ if (txt.getStrings().size() == 1) {
+ records.add(txt.getStrings().get(0));
+ } else {
+ StringBuffer sb = new StringBuffer();
+ for (Iterator it = txt.getStrings().iterator(); it
+ .hasNext();) {
+ String k = (String) it.next();
+ sb.append(k);
+ }
+ records.add(sb.toString());
+ }
break;
case Type.SPF:
SPFRecord spf = (SPFRecord) rr[i];
- records.add(spf.rdataToString());
+ if (spf.getStrings().size() == 1) {
+ records.add(spf.getStrings().get(0));
+ } else {
+ StringBuffer sb = new StringBuffer();
+ for (Iterator it = spf.getStrings().iterator(); it
+ .hasNext();) {
+ String k = (String) it.next();
+ sb.append(k);
+ }
+ records.add(sb.toString());
+ }
break;
default:
return null;
Modified:
james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/policies/SPFRetriever.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/policies/SPFRetriever.java?rev=780443&r1=780442&r2=780443&view=diff
==============================================================================
---
james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/policies/SPFRetriever.java
(original)
+++
james/jspf/trunk/resolver/src/main/java/org/apache/james/jspf/policies/SPFRetriever.java
Sun May 31 14:42:37 2009
@@ -128,14 +128,6 @@
// DO NOT trim the result!
String compare = all.next().toString();
- // 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);
- }
-
// We trim the compare value only for the comparison
if
(compare.toLowerCase().trim().startsWith(SPF1Constants.SPF_VERSION1 + " ") ||
compare.trim().equalsIgnoreCase(SPF1Constants.SPF_VERSION1)) {
if (returnValue == null) {
Modified:
james/jspf/trunk/resolver/src/test/java/org/apache/james/jspf/DNSServiceXBillImplTest.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/resolver/src/test/java/org/apache/james/jspf/DNSServiceXBillImplTest.java?rev=780443&r1=780442&r2=780443&view=diff
==============================================================================
---
james/jspf/trunk/resolver/src/test/java/org/apache/james/jspf/DNSServiceXBillImplTest.java
(original)
+++
james/jspf/trunk/resolver/src/test/java/org/apache/james/jspf/DNSServiceXBillImplTest.java
Sun May 31 14:42:37 2009
@@ -20,9 +20,13 @@
package org.apache.james.jspf;
+import org.apache.james.jspf.impl.DNSServiceXBillImpl;
+import org.xbill.DNS.DClass;
import org.xbill.DNS.Lookup;
import org.xbill.DNS.Name;
import org.xbill.DNS.Record;
+import org.xbill.DNS.SPFRecord;
+import org.xbill.DNS.TXTRecord;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
@@ -59,5 +63,19 @@
Record[] record = new Lookup(Name.root, Type.ANY).run();
if (record !=null) System.out.println(record[0]);
}
+
+ public void testMultipleStrings() throws Exception {
+ Record[] rr = new Record[] {
TXTRecord.fromString(Name.fromString("test.local."), Type.TXT, DClass.IN, 0,
"\"string \" \"concatenated\"", Name.fromString("local.")) };
+ assertEquals("string concatenated",
DNSServiceXBillImpl.convertRecordsToList(rr).get(0));
+
+ rr = new Record[] {
TXTRecord.fromString(Name.fromString("test.local."), Type.TXT, DClass.IN, 0,
"string", Name.fromString("local.")) };
+ assertEquals("string",
DNSServiceXBillImpl.convertRecordsToList(rr).get(0));
+
+ rr = new Record[] {
TXTRecord.fromString(Name.fromString("test.local."), Type.TXT, DClass.IN, 0,
"\"quoted string\"", Name.fromString("local.")) };
+ assertEquals("quoted string",
DNSServiceXBillImpl.convertRecordsToList(rr).get(0));
+
+ rr = new Record[] {
SPFRecord.fromString(Name.fromString("test.local."), Type.SPF, DClass.IN, 0,
"\"quot\" \"ed st\" \"ring\"", Name.fromString("local.")) };
+ assertEquals("quoted string",
DNSServiceXBillImpl.convertRecordsToList(rr).get(0));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]