directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r368661 - in /directory/trunks/asn1/src/main/java/org/apache/asn1/ber: AbstractContainer.java Asn1Decoder.java IAsn1Container.java
Date Fri, 13 Jan 2006 09:58:56 GMT
Author: elecharny
Date: Fri Jan 13 01:58:52 2006
New Revision: 368661

URL: http://svn.apache.org/viewcvs?rev=368661&view=rev
Log:
Fixed the bug DIRSNICKERS-121. I've added a flag that should be set to true if the current
transition could be the last one

Modified:
    directory/trunks/asn1/src/main/java/org/apache/asn1/ber/AbstractContainer.java
    directory/trunks/asn1/src/main/java/org/apache/asn1/ber/Asn1Decoder.java
    directory/trunks/asn1/src/main/java/org/apache/asn1/ber/IAsn1Container.java

Modified: directory/trunks/asn1/src/main/java/org/apache/asn1/ber/AbstractContainer.java
URL: http://svn.apache.org/viewcvs/directory/trunks/asn1/src/main/java/org/apache/asn1/ber/AbstractContainer.java?rev=368661&r1=368660&r2=368661&view=diff
==============================================================================
--- directory/trunks/asn1/src/main/java/org/apache/asn1/ber/AbstractContainer.java (original)
+++ directory/trunks/asn1/src/main/java/org/apache/asn1/ber/AbstractContainer.java Fri Jan
13 01:58:52 2006
@@ -64,6 +64,9 @@
 
     /** The parent TLV */
     protected TLV parentTLV;
+    
+    /** The grammar end transition flag */
+    protected boolean grammarEndAllowed;
 
     //~ Methods ------------------------------------------------------------------------------------
 
@@ -139,6 +142,25 @@
     public void setState( int state )
     {
         this.state = state;
+    }
+
+    /**
+     * Check that we can have a end state after this transition
+     * @return true if this can be the last transition
+     */
+    public boolean isGrammarEndAllowed()
+    {
+    	return grammarEndAllowed;
+    }
+    
+    /**
+     * Set the flag to allow a end transition
+     * @param endAllowed true or false, depending on the next
+     * transition being an end or not.
+     */
+    public void grammarEndAllowed( boolean grammarEndAllowed )
+    {
+    	this.grammarEndAllowed = grammarEndAllowed;
     }
 
     /**

Modified: directory/trunks/asn1/src/main/java/org/apache/asn1/ber/Asn1Decoder.java
URL: http://svn.apache.org/viewcvs/directory/trunks/asn1/src/main/java/org/apache/asn1/ber/Asn1Decoder.java?rev=368661&r1=368660&r2=368661&view=diff
==============================================================================
--- directory/trunks/asn1/src/main/java/org/apache/asn1/ber/Asn1Decoder.java (original)
+++ directory/trunks/asn1/src/main/java/org/apache/asn1/ber/Asn1Decoder.java Fri Jan 13 01:58:52
2006
@@ -18,6 +18,7 @@
 
 
 import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1.ber.grammar.IStates;
 import org.apache.asn1.ber.tlv.TLV;
 import org.apache.asn1.ber.tlv.TLVStateEnum;
 import org.apache.asn1.ber.tlv.Tag;
@@ -727,10 +728,26 @@
         container.getGrammar().executeAction( container );
 
         // Check if the PDU has been fully decoded.
-        if ( isTLVDecoded(container) )
+        if ( isTLVDecoded( container ) )
         {
-            // Change the state to DECODED
-            container.setState( TLVStateEnum.PDU_DECODED );
+        	if ( container.getState() == IStates.GRAMMAR_END )  
+        	{
+        		// Change the state to DECODED
+        		container.setState( TLVStateEnum.PDU_DECODED );
+        	}
+        	else
+        	{
+        		if ( container.isGrammarEndAllowed() )
+        		{
+            		// Change the state to DECODED
+            		container.setState( TLVStateEnum.PDU_DECODED );
+        		}
+        		else
+        		{
+        			log.error( "The PDU is decoded, but we should have had more TLVs" );
+        			throw new DecoderException( "Truncated PDU. Some elements are lacking, accordingly
to the grammar" );
+        		}
+        	}
             
         }
         else
@@ -803,7 +820,7 @@
      * 
      * @throws DecoderException Thrown if anything went wrong!
      */
-    public void decode( ByteBuffer stream, IAsn1Container container ) throws org.apache.asn1.codec.DecoderException
+    public void decode( ByteBuffer stream, IAsn1Container container ) throws DecoderException
     {
 
         /* We have to deal with the current state. This is an
@@ -844,6 +861,8 @@
             {
 
                 case TLVStateEnum.TAG_STATE_START :
+                	// Reset the GrammarEnd flag first
+                	container.grammarEndAllowed( false );
                     hasRemaining = treatTagStartState( stream, container );
 
                     break;

Modified: directory/trunks/asn1/src/main/java/org/apache/asn1/ber/IAsn1Container.java
URL: http://svn.apache.org/viewcvs/directory/trunks/asn1/src/main/java/org/apache/asn1/ber/IAsn1Container.java?rev=368661&r1=368660&r2=368661&view=diff
==============================================================================
--- directory/trunks/asn1/src/main/java/org/apache/asn1/ber/IAsn1Container.java (original)
+++ directory/trunks/asn1/src/main/java/org/apache/asn1/ber/IAsn1Container.java Fri Jan 13
01:58:52 2006
@@ -133,4 +133,17 @@
      * @param The new parent TLV 
      */
     public void setParentTLV( TLV parentTLV);
+    
+    /**
+     * Check that we can have a end state after this transition
+     * @return true if this can be the last transition
+     */
+    public boolean isGrammarEndAllowed();
+    
+    /**
+     * Set the flag to allow a end transition
+     * @param endAllowed true or false, depending on the next
+     * transition being an end or not.
+     */
+    public void grammarEndAllowed( boolean grammarEndAllowed );
 }



Mime
View raw message