You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/05/29 06:57:34 UTC

svn commit: rev 20576 - in incubator/directory/snickers/trunk: ber-codec/src/java/org/apache/snickers/ber/digester/rules ldap-ber-provider/src/java/org/apache/snickers/ldap ldap-ber-provider/src/test/org/apache/snickers/ldap

Author: akarasulu
Date: Fri May 28 21:57:34 2004
New Revision: 20576

Modified:
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/DeleteResponseRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ErrorMessageRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultMatchedDNRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteResponseRuleTest.java
Log:
Commit changes ...

 o documented all classes involved with the bug fix thoroughly
 o fixed problem where two rules with the same pattern were overwriting values

Note:

Rules with the same pattern are processed in parallel meaning their firings 
overlap.  For example if r1, r2 and r3 are added in that order for the same
pattern to the digester's rule base then r1.tag() is called first, r2.tag() 
second and finally r3.tag().  Then in the next firing stage r1.length(),
r2.length() and so on stage by stage.  This may cause unusual behavoir and
some form of serialization may need to be devised.  For now these rules use
a work around for dealing with the errorMessage and matchedDn rules which 
both fire on the same pattern for two different firings.



Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRule.java	(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/digester/rules/PrimitiveOctetStringRule.java	Fri May 28 21:57:34 2004
@@ -160,4 +160,55 @@
         // clean up
         isConstructed = false ;
     }
+
+
+    // -----------------------------------------------------------------------
+    // Protected Methods
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Gets the ByteAccumulator used by this octet string gathering rule.
+     *
+     * @return the accumulator used to store octets
+     */
+    protected ByteAccumulator getAccumulator()
+    {
+        return accumulator ;
+    }
+
+
+    /**
+     * Gets whether or not the current TLV for this octet string is
+     * constructed.
+     *
+     * @return true if it's constructed, false otherwise
+     */
+    protected boolean isConstructed()
+    {
+        return isConstructed ;
+    }
+
+
+    /**
+     * Gets whether or not the current TLV for this octet string is
+     * constructed.
+     *
+     * @param isConstructed true to set to constructed, false otherwise
+     */
+    protected void setConstructed( boolean isConstructed )
+    {
+        this.isConstructed = isConstructed ;
+    }
+
+
+    /**
+     * Gets the tag associated with this rule.
+     *
+     * @return the tag associated with this rule
+     */
+    protected TagEnum getTag()
+    {
+        return tag ;
+    }
 }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/DeleteResponseRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/DeleteResponseRule.java	(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/DeleteResponseRule.java	Fri May 28 21:57:34 2004
@@ -23,13 +23,16 @@
 
 
 /**
- * Put some documentation here.
+ * A digester rule used to build a DeleteResponse PDU.
  * 
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
 public class DeleteResponseRule extends ResultResponseRule
 {
+    /**
+     * Creates digester rule used to build a DeleteResponse PDU.
+     */
     public DeleteResponseRule()
     {
         super( LdapTag.DEL_RESPONSE ) ;

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ErrorMessageRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ErrorMessageRule.java	(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ErrorMessageRule.java	Fri May 28 21:57:34 2004
@@ -14,33 +14,101 @@
  *   limitations under the License.
  *
  */
-package org.apache.snickers.ldap;
+package org.apache.snickers.ldap ;
 
-import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule;
-import org.apache.ldap.common.message.BindResponse;
-import org.apache.ldap.common.message.ResultResponse;
 
-import java.nio.ByteBuffer;
+import java.nio.ByteBuffer ;
+
+import org.apache.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
+
+import org.apache.ldap.common.message.LdapResult ;
+import org.apache.ldap.common.message.ResultResponse ;
 
 
 /**
- * Put some documentation here.
+ * Digester rule used to set the error message field of an LDAPResult within a
+ * result response carring LDAP PDU list BindResponse or DelResponse.  This
+ * rule only sets the error message if it has not already been set to prevent
+ * overwriting it.  Furthermore this rule only sets the error message if the
+ * result's matchedDn has been set: this helps manage the order of rule
+ * operation since this rule and the matchedDn rule match the same pattern.
  * 
- * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
  * @version $Rev$
  */
 public class ErrorMessageRule extends PrimitiveOctetStringRule
 {
+    /** the result carried by the result containing response */
+    private LdapResult result = null ;
+    /** whether or not to process this rule firing */
+    private boolean byPass = false ;
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#tag(int,boolean,TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        ResultResponse resp = ( ResultResponse ) getDigester().peek() ;
+        result = resp.getLdapResult() ;
+
+        byPass = result.getMatchedDn() == null ||
+                result.getErrorMessage() != null ;
+
+        if ( ! byPass )
+        {
+            super.tag( id, isPrimitive, typeClass ) ;
+        }
+    }
+
+
     /* (non-Javadoc)
-    * @see org.apache.snickers.ber.Rule#finish()
+     * @see org.apache.snickers.ber.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( ! byPass )
+        {
+            super.length( length ) ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#value(java.nio.ByteBuffer)
+     */
+    public void value( ByteBuffer buf )
+    {
+        if ( ! byPass )
+        {
+            super.value( buf ) ;
+        }
+    }
+
+
+   /**
+    * Overrides the finish method without calling the parent so we can
+    * drain the accumulator here and set the value without needlessly
+    * pushing and popping the stack.
+    *
+    * @see org.apache.snickers.ber.digester.Rule#finish()
     */
     public void finish()
     {
-        super.finish() ;
+        if ( isConstructed() || byPass )
+        {
+            return ;
+        }
 
-        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        ByteBuffer buf = getAccumulator().drain( 0 ) ;
         String errorMsg = new String( BufferUtils.getArray( buf ) ) ;
-        ResultResponse resp = ( ResultResponse ) getDigester().peek() ;
-        resp.getLdapResult().setErrorMessage( errorMsg ) ;
-    }
+        result.setErrorMessage( errorMsg ) ;
+
+        // clean up
+        setConstructed( false ) ;
+        byPass = false ;
+        result = null ;
+   }
 }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralRule.java	(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ReferralRule.java	Fri May 28 21:57:34 2004
@@ -63,7 +63,7 @@
                     + " but instead got a tag id of " + id ) ;
         }
 
-        ResultResponse resp = ( BindResponse ) getDigester().getRoot() ;
+        ResultResponse resp = ( ResultResponse ) getDigester().getRoot() ;
         LdapResult result = ( LdapResult ) resp.getLdapResult() ;
         ReferralImpl ref = new ReferralImpl( result ) ;
         result.setReferral( ref ) ;

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultMatchedDNRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultMatchedDNRule.java	(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultMatchedDNRule.java	Fri May 28 21:57:34 2004
@@ -14,33 +14,94 @@
  *   limitations under the License.
  *
  */
-package org.apache.snickers.ldap;
+package org.apache.snickers.ldap ;
 
-import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule;
-import org.apache.ldap.common.message.BindResponse;
-import org.apache.ldap.common.message.ResultResponse;
 
-import java.nio.ByteBuffer;
+import java.nio.ByteBuffer ;
+
+import org.apache.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
+
+import org.apache.ldap.common.message.LdapResult ;
+import org.apache.ldap.common.message.ResultResponse ;
 
 
 /**
- * Put some documentation here.
- * 
+ * Digester rule used to set the matchedDn field of an LDAPResult within a
+ * result response carring LDAP PDU list BindResponse or DelResponse.  This
+ * rule only sets the matchedDN if it has not already been set to prevent
+ * overwriting it.
+ *
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
 public class ResultMatchedDNRule extends PrimitiveOctetStringRule
 {
+    /** the result carried by the result containing response */
+    private LdapResult result = null ;
+    /** whether or not to process this rule firing */
+    private boolean byPass = false ;
+
+
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        ResultResponse resp = ( ResultResponse ) getDigester().peek() ;
+        result = resp.getLdapResult() ;
+
+        byPass = result.getMatchedDn() != null ;
+
+        if ( ! byPass )
+        {
+            super.tag( id, isPrimitive, typeClass ) ;
+        }
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#length(int)
+     */
+    public void length( int length )
+    {
+        if ( ! byPass )
+        {
+            super.length( length ) ;
+        }
+    }
+
+
     /* (non-Javadoc)
-     * @see org.apache.snickers.ber.Rule#finish()
+     * @see org.apache.snickers.ber.Rule#value(java.nio.ByteBuffer)
      */
+    public void value( ByteBuffer buf )
+    {
+        if ( ! byPass )
+        {
+            super.value( buf ) ;
+        }
+    }
+
+
+   /**
+    * Overrides the finish method without calling the parent so we can
+    * drain the accumulator here and set the value without needlessly
+    * pushing and popping the stack.
+    *
+    * @see org.apache.snickers.ber.digester.Rule#finish()
+    */
     public void finish()
     {
-        super.finish() ;
+        if ( isConstructed() || byPass )
+        {
+            return ;
+        }
 
-        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        ByteBuffer buf = getAccumulator().drain( 0 ) ;
         String dn = new String( BufferUtils.getArray( buf ) ) ;
-        ResultResponse resp = ( ResultResponse ) getDigester().peek() ;
-        resp.getLdapResult().setMatchedDn( dn ) ;
-    }
+        result.setMatchedDn( dn ); ;
+
+        // clean up
+        setConstructed( false ) ;
+        byPass = false ;
+        result = null ;
+   }
 }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteResponseRuleTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteResponseRuleTest.java	(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteResponseRuleTest.java	Fri May 28 21:57:34 2004
@@ -79,17 +79,17 @@
 
         int[] pattern = new int[2] ;
 
-        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getValue() ;
-        pattern[1] = UniversalTag.INTEGER.getValue() ;
+        pattern[0] = 0x10000000 ;
+        pattern[1] = 0x02000000 ;
         digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
 
         // for the DeleteResponse and the LdapResult
-        pattern[1] = LdapTag.DEL_RESPONSE.getValue() ;
+        pattern[1] = 0x4b000000 ;
         digester.addRule( pattern, new DeleteResponseRule() ) ;
 
         pattern = new int[3] ;
-        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getValue() ;
-        pattern[1] = LdapTag.DEL_RESPONSE.getValue() ;
+        pattern[0] = 0x10000000 ;
+        pattern[1] = 0x4b000000 ;
 
         // for the resultCode
         pattern[2] = 0x0a000000 ;
@@ -107,7 +107,7 @@
         // for LDAPURLs of referral
         pattern = new int[4] ;
         pattern[0] = 0x10000000 ;
-        pattern[1] = LdapTag.DEL_RESPONSE.getValue() ;
+        pattern[1] = 0x4b000000 ;
         pattern[2] = 0x83000000 ;
         pattern[3] = 0x04000000 ;
         digester.addRule( pattern, new ReferralUrlRule() ) ;
@@ -150,7 +150,7 @@
     {
         DeleteResponse resp = build( 44 ) ;
         LdapResult result = resp.getLdapResult() ;
-        result.setErrorMessage( "testing123" ) ;
+        result.setErrorMessage( "An Error Message!" ) ;
         result.setMatchedDn( "uid=akarasulu,dc=example,dc=com" ) ;
         result.setResultCode( ResultCodeEnum.BUSY ) ;
         result.getReferral().addLdapUrl( "hello" ) ;