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/08 18:53:14 UTC
svn commit: r441568 -
/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestAsn1Ber.java
Author: elecharny
Date: Fri Sep 8 09:53:13 2006
New Revision: 441568
URL: http://svn.apache.org/viewvc?view=rev&rev=441568
Log:
Implemented correctly the computeLength() and encode() methods. The generated PDU now contains all the needed informations :
MessageId, protocolOp and controls if any.
Modified:
directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestAsn1Ber.java
Modified: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestAsn1Ber.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/bind/BindRequestAsn1Ber.java?view=diff&rev=441568&r1=441567&r2=441568
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestAsn1Ber.java (original)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestAsn1Ber.java Fri Sep 8 09:53:13 2006
@@ -29,7 +29,9 @@
import org.apache.directory.shared.ldap.codec.Encoder;
import org.apache.directory.shared.ldap.codec.EncoderException;
import org.apache.directory.shared.ldap.codec.asn1ber.messages.LdapBerTags;
+import org.apache.directory.shared.ldap.codec.asn1ber.messages.MessageAsn1Ber;
import org.apache.directory.shared.ldap.messages.Message;
+import org.apache.directory.shared.ldap.messages.MessageDecorator;
import org.apache.directory.shared.ldap.messages.bind.Authentication;
import org.apache.directory.shared.ldap.messages.bind.AuthenticationDecorator;
import org.apache.directory.shared.ldap.messages.bind.BindRequest;
@@ -52,12 +54,17 @@
/** A speedup for logger */
private static final boolean IS_DEBUG = log.isDebugEnabled();
+
+ private MessageDecorator messageDecorator;
/** The bind request length */
private transient int bindRequestLength;
- /** The authentication decorator */
- private transient AuthenticationDecorator authenticationDecorator;
+ /** The message length */
+ private transient int messageLength;
+
+ /** The protocolOp length */
+ private transient int protocolOpLength;
/**
*
@@ -79,10 +86,25 @@
{
authenticationDecorator = new SaslCredentialsAsn1Ber( authentication );
}
+
+ messageDecorator = new MessageAsn1Ber( message );
}
/**
- * Compute the BindRequest length BindRequest :
+ * Compute the BindRequest length. A BindRequest is a Message,
+ * so we must count the full LdapMessage size, including controls.
+ *
+ * 0x30 L1
+ * |
+ * +--> 0x02 0x0(1-4) [0..2^31-1] (MessageId)
+ * +--> BindRequest protocolOp
+ * [+--> Controls]
+ *
+ * MessageId length = Length(0x02) + length(MessageId) + MessageId.length
+ * L1 = length(BindRequest protocolOp)
+ * LdapMessage length = Length(0x30) + Length(L1) + MessageId length + L1
+ *
+ * BindRequest protocolOp :
* 0x60 L1
* |
* +--> 0x02 0x01 (1..127) version
@@ -97,7 +119,12 @@
*/
public int computeLength()
{
- bindRequestLength = 1 + 1 + 1; // Initialized with version
+ // First, compute the encaplusing message length
+ messageLength = ((MessageAsn1Ber)messageDecorator).computeLength();
+
+ // Now, deal with the BindRequest protocolOp
+ // Initialized with version
+ bindRequestLength = 1 + 1 + 1;
// The name
bindRequestLength += 1 + Length.getNbBytes( LdapDN.getNbBytes( getName() ) ) + LdapDN.getNbBytes( getName() );
@@ -120,7 +147,13 @@
bindRequestLength += authenticationDecorator.computeLength();
// Return the result.
- int length = 1 + Length.getNbBytes( bindRequestLength ) + bindRequestLength;
+ protocolOpLength = 1 + Length.getNbBytes( bindRequestLength ) + bindRequestLength;
+
+ // Compute the encapsulating message length, and add the protocolOp length,
+ messageLength = messageDecorator.computeLength() + protocolOpLength;
+
+ // Finally, compute the global size
+ int length = 1 + Length.getNbBytes( messageLength ) + messageLength;
if ( IS_DEBUG )
{
@@ -133,26 +166,32 @@
/**
* Encode the BindRequest message to a PDU.
*
- * 0x60 LL
- * 0x02 LL version
- * 0x04 LL name
- * authentication.encode()
- * 0x80 LL simple
- * /
- * \
- * 0x83 LL mechanism
- * [0x04 LL credential]
+ * 0x30 L1
+ * 0x02 0x0[1-4] messageId
+ * +----------------------------+
+ * | 0x60 L2 |
+ * | 0x02 L3 version |
+ * | 0x04 L4 name |
+ * | authentication.encode() |
+ * | 0x80 L5 simple |-> This part is encoded here
+ * | / |
+ * | \ |
+ * | 0x83 L6 mechanism |
+ * | [0x04 L7 credential] |
+ * +----------------------------+
+ * [0x80 L8 controls]
*
* @param buffer The buffer where to put the PDU
* @return The PDU.
*/
public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException, ValueException
{
- if ( buffer == null )
- {
- throw new EncoderException( "Cannot put a PDU in a null buffer !" );
- }
+ int length = computeLength();
+ buffer = ByteBuffer.allocate( length );
+ int protoclOpPos = length - ((MessageAsn1Ber)messageDecorator).getControlsSequenceLength() - protocolOpLength;
+ buffer.position( protoclOpPos );
+
try
{
// The BindRequest Tag