Skip to content

Commit

Permalink
Fix a bug which can cause an invalid header id
Browse files Browse the repository at this point in the history
Add javadocs
Some minor refactoring

git-svn-id: https://svn.apache.org/repos/asf/james/jspf/branches/asynch-jspf@536180 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
normanmaurer committed May 8, 2007
1 parent 502c4f2 commit e4b5533
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 17 deletions.
26 changes: 26 additions & 0 deletions src/main/java/org/apache/james/jspf/FutureSPFResult.java
Expand Up @@ -29,6 +29,12 @@ public FutureSPFResult() {
isReady = false;
}

/**
* Set SPFResult using the given SPFsession
*
* @param session
*
*/
public synchronized void setSPFResult(SPFSession session) {
setSPFSession(session);
isReady = true;
Expand All @@ -45,31 +51,51 @@ private synchronized void checkReady() {
}
}

/**
* @see org.apache.james.jspf.SPFResult#getExplanation()
*/
public String getExplanation() {
checkReady();
return super.getExplanation();
}

/**
* @see org.apache.james.jspf.SPFResult#getHeader()
*/
public String getHeader() {
checkReady();
return super.getHeader();
}

/**
* @see org.apache.james.jspf.SPFResult#getHeaderName()
*/
public String getHeaderName() {
checkReady();
return super.getHeaderName();
}

/**
* @see org.apache.james.jspf.SPFResult#getHeaderText()
*/
public String getHeaderText() {
checkReady();
return super.getHeaderText();
}

/**
* @see org.apache.james.jspf.SPFResult#getResult()
*/
public String getResult() {
checkReady();
return super.getResult();
}

/**
* Return true if the result was fully builded
*
* @return true or false
*/
public boolean isReady() {
return isReady;
}
Expand Down
33 changes: 19 additions & 14 deletions src/main/java/org/apache/james/jspf/SPF.java
Expand Up @@ -277,6 +277,24 @@ public SPF(DNSService dnsProbe, SPFRecordParser parser, Logger logger, MacroExpa
this.executor = executor;
}


private static final class DefaultSPFChecker implements SPFChecker {

/**
* @see org.apache.james.jspf.core.SPFChecker#checkSPF(org.apache.james.jspf.core.SPFSession)
*/
public DNSLookupContinuation checkSPF(SPFSession spfData)
throws PermErrorException, TempErrorException,
NeutralException, NoneException {
if (spfData.getCurrentResultExpanded() == null) {
String resultChar = spfData.getCurrentResult() != null ? spfData.getCurrentResult() : "";
String result = SPF1Utils.resultToName(resultChar);
spfData.setCurrentResultExpanded(result);
}
return null;
}
}

/**
* Run check for SPF with the given values.
*
Expand All @@ -300,20 +318,7 @@ public SPFResult checkSPF(String ipAddress, String mailFrom, String hostName) {
spfData.setCurrentResultExpanded(e1.getResult());
}

SPFChecker resultHandler = new SPFChecker() {

public DNSLookupContinuation checkSPF(SPFSession spfData)
throws PermErrorException, TempErrorException,
NeutralException, NoneException {
if (spfData.getCurrentResultExpanded() == null) {
String resultChar = spfData.getCurrentResult() != null ? spfData.getCurrentResult() : "";
String result = SPF1Utils.resultToName(resultChar);
spfData.setCurrentResultExpanded(result);
}
return null;
}

};
SPFChecker resultHandler = new DefaultSPFChecker();

spfData.pushChecker(resultHandler);
spfData.pushChecker(this);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/james/jspf/core/SPFSession.java
Expand Up @@ -79,7 +79,7 @@ public class SPFSession implements MacroData {
private String currentResultExpanded;

/**
* Build the SPF1Data from the given parameters
* Build the SPFSession from the given parameters
*
* @param mailFrom
* The emailaddress of the sender
Expand Down
Expand Up @@ -62,9 +62,16 @@ public synchronized IResponse removeResponse() {

}

private static int id = 1;
// Use short as id because the id header is limited to 16 bit
// From RFC1035 4.1.1. Header section format :
//
// ID A 16 bit identifier assigned by the program that
// generates any kind of query. This identifier is copied
// the corresponding reply and can be used by the requester
// to match up replies to outstanding queries.
//
private static short id;

// TODO: sooner or later we have to avoid overflow and restart.
private synchronized int nextId() {
return id++;
}
Expand Down
Expand Up @@ -38,6 +38,9 @@
*/
public final class InitialChecksPolicy implements SPFChecker {

/**
* @see org.apache.james.jspf.core.SPFChecker#checkSPF(org.apache.james.jspf.core.SPFSession)
*/
public DNSLookupContinuation checkSPF(SPFSession spfData)
throws PermErrorException, TempErrorException, NeutralException,
NoneException {
Expand Down
Expand Up @@ -26,6 +26,9 @@ public class SPFRetriever implements SPFChecker {

private static final class SPFRecordHandlerDNSResponseListener implements SPFCheckerDNSResponseListener {

/**
* @see org.apache.james.jspf.core.SPFCheckerDNSResponseListener#onDNSResponse(org.apache.james.jspf.core.DNSResponse, org.apache.james.jspf.core.SPFSession)
*/
public DNSLookupContinuation onDNSResponse(
DNSResponse response, SPFSession session)
throws PermErrorException,
Expand All @@ -50,6 +53,9 @@ public DNSLookupContinuation onDNSResponse(

private static final class SPFRetrieverDNSResponseListener implements SPFCheckerDNSResponseListener {

/**
* @see org.apache.james.jspf.core.SPFCheckerDNSResponseListener#onDNSResponse(org.apache.james.jspf.core.DNSResponse, org.apache.james.jspf.core.SPFSession)
*/
public DNSLookupContinuation onDNSResponse(
DNSResponse response, SPFSession session)
throws PermErrorException, NoneException,
Expand Down
Expand Up @@ -27,6 +27,9 @@ public class SPFStrictCheckerRetriever extends SPFRetriever {

private static final class SPFStrictSPFRecordsDNSResponseListener implements SPFCheckerDNSResponseListener {

/**
* @see org.apache.james.jspf.core.SPFCheckerDNSResponseListener#onDNSResponse(org.apache.james.jspf.core.DNSResponse, org.apache.james.jspf.core.SPFSession)
*/
public DNSLookupContinuation onDNSResponse(
DNSResponse response, SPFSession session)
throws PermErrorException,
Expand Down Expand Up @@ -55,6 +58,9 @@ public DNSLookupContinuation onDNSResponse(

private static final class SPFStrictCheckDNSResponseListener implements SPFCheckerDNSResponseListener {

/**
* @see org.apache.james.jspf.core.SPFCheckerDNSResponseListener#onDNSResponse(org.apache.james.jspf.core.DNSResponse, org.apache.james.jspf.core.SPFSession)
*/
public DNSLookupContinuation onDNSResponse(
DNSResponse response, SPFSession session)
throws PermErrorException, NoneException,
Expand Down
Expand Up @@ -40,6 +40,10 @@ public final class DefaultExplanationPolicy implements PolicyPostFilter {


private final class ExplanationChecker implements SPFChecker {

/**
* @see org.apache.james.jspf.core.SPFChecker#checkSPF(org.apache.james.jspf.core.SPFSession)
*/
public DNSLookupContinuation checkSPF(SPFSession spfData)
throws PermErrorException,
NoneException, TempErrorException,
Expand Down

0 comments on commit e4b5533

Please sign in to comment.