You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/09/09 02:57:31 UTC

svn commit: r441710 - /directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/MessageAsn1Ber.java

Author: elecharny
Date: Fri Sep  8 17:57:30 2006
New Revision: 441710

URL: http://svn.apache.org/viewvc?view=rev&rev=441710
Log:
Fixed the encoding and length computation

Modified:
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/MessageAsn1Ber.java

Modified: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/MessageAsn1Ber.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/MessageAsn1Ber.java?view=diff&rev=441710&r1=441709&r2=441710
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/MessageAsn1Ber.java (original)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/MessageAsn1Ber.java Fri Sep  8 17:57:30 2006
@@ -22,7 +22,7 @@
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
-import org.apache.directory.shared.asn1.ber.UniversalTags;
+import org.apache.directory.shared.asn1.ber.ConstructedUniversalTags;
 import org.apache.directory.shared.asn1.ber.tlv.Length;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.ber.tlv.ValueException;
@@ -50,11 +50,14 @@
     /** A speedup for logger */
     private static final boolean IS_DEBUG = log.isDebugEnabled();
 
-    /** The LdapMessage length */
-    private transient int ldapMessageLength;
+    /** The Message length */
+    private transient int messageLength;
     
     /** The controls sequence length */
     private transient int controlsSequenceLength;
+    
+    /** The protocolOp length */
+    private transient int protocolOpLength;
 
     /**
      * 
@@ -91,7 +94,7 @@
         // - the tag (0x02), 1 byte
         // - the length of the Id length, 1 byte
         // - the Id length, 1 to 4 bytes
-        ldapMessageLength = 1 + 1 + Value.getNbBytes( getMessageId() );
+        messageLength = 1 + 1 + Value.getNbBytes( getMessageId() );
 
         // Compute Control lengths, if any.
         if ( ( getControls() != null ) && ( getControls().size() != 0 ) )
@@ -122,16 +125,16 @@
                 controlsSequenceLength += controlDecorator.computeLength();
             }
 
-            // Now, add the tag and the length of the controls length
-            ldapMessageLength += 1 + Length.getNbBytes( controlsSequenceLength ) + controlsSequenceLength;
+            // Now, add the controls length
+            messageLength += 1 + Length.getNbBytes( controlsSequenceLength ) + controlsSequenceLength;
         }
 
         if ( IS_DEBUG )
         {
-            log.debug( "Message length : {}", ldapMessageLength );
+            log.debug( "Message length : {}", messageLength );
         }
         
-        return ldapMessageLength;
+        return messageLength;
     }
     
     /**
@@ -168,11 +171,18 @@
 
         try
         {
+            // Save the current position, to be able
+            // to store controls at the right place
+            int end = buffer.position();
+            
+            // an reinitialize the position to 0
+            buffer.position( 0 );
+            
             // The LdapMessage Sequence
-            buffer.put(0,  UniversalTags.SEQUENCE_SEQUENCE_OF.getValue() );
+            buffer.put( ConstructedUniversalTags.SEQUENCE_SEQUENCE_OF.getValue() );
 
             // The length has been calculated by the computeLength method
-            buffer.put( Length.getBytes( ldapMessageLength ) );
+            buffer.put( Length.getBytes( protocolOpLength + messageLength ) );
             
             // The message Id
             Value.encode( buffer, getMessageId() );
@@ -181,6 +191,9 @@
             // but only if we have controls
             if ( ( getControls() != null ) && ( getControls().size() != 0 ) )
             {
+                // Restore the previous position
+                buffer.position( end );
+                
                 // Encode the controls
                 buffer.put( ( byte ) LdapBerTags.CONTROLS_TAG.getValue() );
                 buffer.put( Length.getBytes( controlsSequenceLength ) );
@@ -206,5 +219,16 @@
     public int getControlsSequenceLength()
     {
         return controlsSequenceLength;
+    }
+
+    /**
+     * Set the protocolOp length so that the encode method wil be able
+     * to generate the PDU
+     * 
+     * @param protocolOpLength The protoclOp length
+     */
+    public void setProtocolOpLength( int protocolOpLength )
+    {
+        this.protocolOpLength = protocolOpLength;
     }
 }