directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r984272 - in /directory/shared/branches/shared-codec-merge/ldap/src: main/java/org/apache/directory/shared/ldap/codec/ main/java/org/apache/directory/shared/ldap/message/ main/java/org/apache/directory/shared/ldap/message/internal/ test/jav...
Date Wed, 11 Aug 2010 00:25:59 GMT
Author: elecharny
Date: Wed Aug 11 00:25:59 2010
New Revision: 984272

URL: http://svn.apache.org/viewvc?rev=984272&view=rev
Log:
Started to encode the BindResponse without going through the Transformer. Partial work, it
seems that server-integ now fails probably because we aren't encoding properly a BindRequest
with controls. Will be fixed tomorrow.

Modified:
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindResponseImpl.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapResultImpl.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalAbstractMessage.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalBindResponse.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalLdapResult.java
    directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalMessage.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/BindRequestImplTest.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/LdapResultImplTest.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImplTest.java
    directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImplTest.java

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapProtocolEncoder.java
Wed Aug 11 00:25:59 2010
@@ -20,9 +20,24 @@
 package org.apache.directory.shared.ldap.codec;
 
 
+import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Map;
 
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.codec.controls.CodecControl;
+import org.apache.directory.shared.ldap.message.BindResponseImpl;
+import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.message.internal.InternalBindResponse;
+import org.apache.directory.shared.ldap.message.internal.InternalLdapResult;
 import org.apache.directory.shared.ldap.message.internal.InternalMessage;
+import org.apache.directory.shared.ldap.message.internal.InternalReferral;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.apache.mina.core.buffer.IoBuffer;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
@@ -45,12 +60,419 @@ public class LdapProtocolEncoder extends
      */
     public void encode( IoSession session, Object request, ProtocolEncoderOutput out ) throws
Exception
     {
-        LdapMessageCodec ldapRequest = ( LdapMessageCodec ) LdapTransformer.transform( (
InternalMessage ) request );
-        ByteBuffer bb = ldapRequest.encode();
+        InternalMessage message = ( InternalMessage ) request;
+        ByteBuffer bb = null;
+
+        if ( message instanceof InternalBindResponse )
+        {
+            bb = encodeMessage( message );
+        }
+        else
+        {
+            LdapMessageCodec ldapRequest = ( LdapMessageCodec ) LdapTransformer.transform(
( InternalMessage ) request );
+            bb = ldapRequest.encode();
+        }
+
         bb.flip();
 
         IoBuffer buffer = IoBuffer.wrap( bb );
 
         out.write( buffer );
     }
+
+
+    private ByteBuffer encodeMessage( InternalMessage message ) throws EncoderException
+    {
+        int length = computeLength( message );
+
+        return encodeMessage( length, message );
+    }
+
+
+    private ByteBuffer encodeMessage( int length, InternalMessage message ) throws EncoderException
+    {
+        try
+        {
+            ByteBuffer bb = ByteBuffer.allocate( length );
+
+            try
+            {
+                // The LdapMessage Sequence
+                bb.put( UniversalTag.SEQUENCE_TAG );
+
+                // The length has been calculated by the computeLength method
+                bb.put( TLV.getBytes( message.getMessageLength() ) );
+            }
+            catch ( BufferOverflowException boe )
+            {
+                throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+            }
+
+            // The message Id
+            Value.encode( bb, message.getMessageId() );
+
+            // Add the protocolOp part
+            encodeProtocolOp( bb, message );
+
+            // Do the same thing for Controls, if any.
+            Map<String, Control> controls = message.getControls();
+
+            if ( ( controls != null ) && ( controls.size() > 0 ) )
+            {
+                // Encode the controls
+                bb.put( ( byte ) LdapConstants.CONTROLS_TAG );
+                bb.put( TLV.getBytes( message.getControlsLength() ) );
+
+                // Encode each control
+                for ( Control control : controls.values() )
+                {
+                    ( ( CodecControl ) control ).encode( bb );
+                }
+            }
+
+            return bb;
+        }
+        catch ( EncoderException ee )
+        {
+            MessageEncoderException exception = new MessageEncoderException( message.getMessageId(),
ee.getMessage() );
+
+            throw exception;
+        }
+    }
+
+
+    /**
+     * Compute the LdapMessage length LdapMessage : 
+     * 0x30 L1 
+     *   | 
+     *   +--> 0x02 0x0(1-4) [0..2^31-1] (MessageId) 
+     *   +--> protocolOp 
+     *   [+--> Controls] 
+     *   
+     * MessageId length = Length(0x02) + length(MessageId) + MessageId.length 
+     * L1 = length(ProtocolOp) 
+     * LdapMessage length = Length(0x30) + Length(L1) + MessageId length + L1
+     */
+    private int computeLength( InternalMessage message )
+    {
+        // The length of the MessageId. It's the sum of
+        // - the tag (0x02), 1 byte
+        // - the length of the Id length, 1 byte
+        // - the Id length, 1 to 4 bytes
+        int ldapMessageLength = 1 + 1 + Value.getNbBytes( message.getMessageId() );
+
+        // Get the protocolOp length
+        ldapMessageLength += computeLengthProtocolOp( message );
+        message.setMessageLength( ldapMessageLength );
+
+        Map<String, Control> controls = message.getControls();
+
+        // Do the same thing for Controls, if any.
+        if ( controls.size() > 0 )
+        {
+            // Controls :
+            // 0xA0 L3
+            //   |
+            //   +--> 0x30 L4
+            //   +--> 0x30 L5
+            //   +--> ...
+            //   +--> 0x30 Li
+            //   +--> ...
+            //   +--> 0x30 Ln
+            //
+            // L3 = Length(0x30) + Length(L5) + L5
+            // + Length(0x30) + Length(L6) + L6
+            // + ...
+            // + Length(0x30) + Length(Li) + Li
+            // + ...
+            // + Length(0x30) + Length(Ln) + Ln
+            //
+            // LdapMessageLength = LdapMessageLength + Length(0x90)
+            // + Length(L3) + L3
+            int controlsSequenceLength = 0;
+
+            // We may have more than one control. ControlsLength is L4.
+            for ( Control control : controls.values() )
+            {
+                controlsSequenceLength += ( ( CodecControl ) control ).computeLength();
+            }
+
+            // Computes the controls length
+            // 1 + Length.getNbBytes( controlsSequenceLength ) + controlsSequenceLength;
+            message.setControlsLength( controlsSequenceLength );
+
+            // Now, add the tag and the length of the controls length
+            ldapMessageLength += 1 + TLV.getNbBytes( controlsSequenceLength ) + controlsSequenceLength;
+        }
+
+        // finally, calculate the global message size :
+        // length(Tag) + Length(length) + length
+
+        return 1 + ldapMessageLength + TLV.getNbBytes( ldapMessageLength );
+    }
+
+
+    /**
+     * Compute the LdapResult length 
+     * 
+     * LdapResult : 
+     * 0x0A 01 resultCode (0..80)
+     *   0x04 L1 matchedDN (L1 = Length(matchedDN)) 
+     *   0x04 L2 errorMessage (L2 = Length(errorMessage)) 
+     *   [0x83 L3] referrals 
+     *     | 
+     *     +--> 0x04 L4 referral 
+     *     +--> 0x04 L5 referral 
+     *     +--> ... 
+     *     +--> 0x04 Li referral 
+     *     +--> ... 
+     *     +--> 0x04 Ln referral 
+     *     
+     * L1 = Length(matchedDN) 
+     * L2 = Length(errorMessage) 
+     * L3 = n*Length(0x04) + sum(Length(L4) .. Length(Ln)) + sum(L4..Ln) 
+     * L4..n = Length(0x04) + Length(Li) + Li 
+     * Length(LdapResult) = Length(0x0x0A) +
+     *      Length(0x01) + 1 + Length(0x04) + Length(L1) + L1 + Length(0x04) +
+     *      Length(L2) + L2 + Length(0x83) + Length(L3) + L3
+     */
+    public int computeLength( InternalLdapResult ldapResult )
+    {
+        int ldapResultLength = 0;
+
+        // The result code : always 3 bytes
+        ldapResultLength = 1 + 1 + 1;
+
+        // The matchedDN length
+        if ( ldapResult.getMatchedDn() == null )
+        {
+            ldapResultLength += 1 + 1;
+        }
+        else
+        {
+            byte[] matchedDNBytes = StringTools.getBytesUtf8( StringTools
+                .trimLeft( ldapResult.getMatchedDn().getName() ) );
+            ldapResultLength += 1 + TLV.getNbBytes( matchedDNBytes.length ) + matchedDNBytes.length;
+        }
+
+        // The errorMessage length
+        byte[] errorMessageBytes = StringTools.getBytesUtf8( ldapResult.getErrorMessage()
);
+        ldapResultLength += 1 + TLV.getNbBytes( errorMessageBytes.length ) + errorMessageBytes.length;
+
+        InternalReferral referral = ldapResult.getReferral();
+
+        if ( referral != null )
+        {
+            Collection<String> ldapUrls = referral.getLdapUrls();
+
+            if ( ( ldapUrls != null ) && ( ldapUrls.size() != 0 ) )
+            {
+                int referralsLength = 0;
+
+                // Each referral
+                for ( String ldapUrl : ldapUrls )
+                {
+                    byte[] ldapUrlBytes = StringTools.getBytesUtf8( ldapUrl );
+                    referralsLength += 1 + TLV.getNbBytes( ldapUrlBytes.length ) + ldapUrlBytes.length;
+                }
+
+                // The referrals
+                ldapResultLength += 1 + TLV.getNbBytes( referralsLength ) + referralsLength;
+            }
+        }
+
+        return ldapResultLength;
+    }
+
+
+    /**
+     * Compute the LdapResponse length
+     */
+    private int computeLdapResultLength( InternalLdapResult ldapResult )
+    {
+        int ldapResponseLength = 0;
+
+        if ( ldapResult != null )
+        {
+            ldapResponseLength = computeLength( ldapResult );
+        }
+
+        return ldapResponseLength;
+    }
+
+
+    /**
+     * Encode the LdapResult message to a PDU.
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encodeLdapResult( ByteBuffer buffer, InternalLdapResult ldapResult
) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
+        }
+
+        try
+        {
+            // The result code
+            buffer.put( UniversalTag.ENUMERATED_TAG );
+            buffer.put( ( byte ) 1 );
+            buffer.put( ( byte ) ldapResult.getResultCode().getValue() );
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+        }
+
+        // The matchedDN
+        Value.encode( buffer, ldapResult.getMatchedDnBytes() );
+
+        // The error message
+        Value.encode( buffer, ldapResult.getErrorMessageBytes() );
+
+        // The referrals, if any
+        InternalReferral referral = ldapResult.getReferral();
+
+        if ( referral != null )
+        {
+            Collection<String> ldapUrls = referral.getLdapUrls();
+
+            if ( ( ldapUrls != null ) && ( ldapUrls.size() != 0 ) )
+            {
+                // Encode the referrals sequence
+                // The referrals length MUST have been computed before !
+                buffer.put( ( byte ) LdapConstants.LDAP_RESULT_REFERRAL_SEQUENCE_TAG );
+                //buffer.put( TLV.getBytes( referralsLength ) );
+
+                // Each referral
+                for ( String ldapUrl : ldapUrls )
+                {
+                    // Encode the current referral
+                    //Value.encode( buffer, referral.getBytesReference() );
+                }
+            }
+        }
+
+        return buffer;
+    }
+
+
+    /**
+     * Compute the BindResponse length 
+     * 
+     * BindResponse : 
+     * <pre>
+     * 0x61 L1 
+     *   | 
+     *   +--> LdapResult
+     *   +--> [serverSaslCreds] 
+     *   
+     * L1 = Length(LdapResult) [ + Length(serverSaslCreds) ] 
+     * Length(BindResponse) = Length(0x61) + Length(L1) + L1
+     * </pre>
+     */
+    private int computeBindResponseLength( BindResponseImpl bindResponse )
+    {
+        int ldapResultLength = computeLdapResultLength( bindResponse.getLdapResult() );
+
+        int bindResponseLength = ldapResultLength;
+
+        byte[] serverSaslCreds = bindResponse.getServerSaslCreds();
+
+        if ( serverSaslCreds != null )
+        {
+            bindResponseLength += 1 + TLV.getNbBytes( serverSaslCreds.length ) + serverSaslCreds.length;
+        }
+
+        bindResponse.setBindResponseLength( bindResponseLength );
+
+        return 1 + TLV.getNbBytes( bindResponseLength ) + bindResponseLength;
+    }
+
+
+    /**
+     * Encode the BindResponse message to a PDU.
+     * 
+     * BindResponse :
+     * <pre>
+     * LdapResult.encode 
+     * [0x87 LL serverSaslCreds]
+     * </pre>
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    private void encodeBindResponse( ByteBuffer bb, BindResponseImpl bindResponse ) throws
EncoderException
+    {
+        try
+        {
+            // The BindResponse Tag
+            bb.put( LdapConstants.BIND_RESPONSE_TAG );
+            bb.put( TLV.getBytes( bindResponse.getBindResponseLength() ) );
+
+            // The LdapResult
+            encodeLdapResult( bb, bindResponse.getLdapResult() );
+
+            // The serverSaslCredential, if any
+            byte[] serverSaslCreds = bindResponse.getServerSaslCreds();
+
+            if ( serverSaslCreds != null )
+            {
+                bb.put( ( byte ) LdapConstants.SERVER_SASL_CREDENTIAL_TAG );
+
+                bb.put( TLV.getBytes( serverSaslCreds.length ) );
+
+                if ( serverSaslCreds.length != 0 )
+                {
+                    bb.put( serverSaslCreds );
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+        }
+    }
+
+
+    /**
+     * Compute the BindRequest length 
+     * 
+     * BindRequest : 
+     * <pre>
+     * 0x60 L1 
+     *   | 
+     *   +--> 0x02 0x01 (1..127) version 
+     *   +--> 0x04 L2 name 
+     *   +--> authentication 
+     *   
+     * L2 = Length(name)
+     * L3/4 = Length(authentication) 
+     * Length(BindRequest) = Length(0x60) + Length(L1) + L1 + Length(0x02) + 1 + 1 + 
+     *      Length(0x04) + Length(L2) + L2 + Length(authentication)
+     * </pre>
+     */
+    private int computeLengthProtocolOp( InternalMessage message )
+    {
+        switch ( message.getType() )
+        {
+            case BIND_RESPONSE:
+                return computeBindResponseLength( ( BindResponseImpl ) message );
+
+            default:
+                return 0;
+        }
+    }
+
+
+    private void encodeProtocolOp( ByteBuffer bb, InternalMessage message ) throws EncoderException
+    {
+        switch ( message.getType() )
+        {
+            case BIND_RESPONSE:
+                encodeBindResponse( bb, ( BindResponseImpl ) message );
+        }
+    }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindResponseImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindResponseImpl.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindResponseImpl.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/BindResponseImpl.java
Wed Aug 11 00:25:59 2010
@@ -39,6 +39,9 @@ public class BindResponseImpl extends In
     /** optional property holding SASL authentication response parameters */
     private byte[] serverSaslCreds;
 
+    /** The encoded bindResponse length */
+    private int bindResponseLength;
+
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -184,4 +187,21 @@ public class BindResponseImpl extends In
         return sb.toString();
     }
 
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setBindResponseLength( int bindResponseLength )
+    {
+        this.bindResponseLength = bindResponseLength;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getBindResponseLength()
+    {
+        return bindResponseLength;
+    }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapResultImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapResultImpl.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapResultImpl.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/LdapResultImpl.java
Wed Aug 11 00:25:59 2010
@@ -38,12 +38,18 @@ public class LdapResultImpl implements I
     /** Lowest matched entry Dn - defaults to empty string */
     private DN matchedDn;
 
+    /** Temporary storage of the byte[] representing the matchedDN */
+    private byte[] matchedDNBytes;
+
     /** Referral associated with this LdapResult if the errorCode is REFERRAL */
     private InternalReferral referral;
 
     /** Decriptive error message - defaults to empty string */
     private String errorMessage;
 
+    /** Temporary storage for message bytes */
+    private byte[] errorMessageBytes;
+
     /** Resultant operation error code - defaults to SUCCESS */
     private ResultCodeEnum resultCode = ResultCodeEnum.SUCCESS;
 
@@ -65,6 +71,15 @@ public class LdapResultImpl implements I
 
 
     /**
+     * {@inheritDoc}
+     */
+    public byte[] getErrorMessageBytes()
+    {
+        return errorMessageBytes;
+    }
+
+
+    /**
      * Sets the descriptive error message associated with the error code. May be
      * null for SUCCESS, COMPARETRUE, and COMPAREFALSE operations.
      * 
@@ -78,6 +93,15 @@ public class LdapResultImpl implements I
 
 
     /**
+     * {@inheritDoc}
+     */
+    public void setErrorMessage( byte[] errorMessageBytes )
+    {
+        this.errorMessageBytes = errorMessageBytes;
+    }
+
+
+    /**
      * Gets the lowest entry in the directory that was matched. For result codes
      * of noSuchObject, aliasProblem, invalidDNSyntax and
      * aliasDereferencingProblem, the matchedDN field is set to the name of the
@@ -97,11 +121,19 @@ public class LdapResultImpl implements I
 
 
     /**
+     * {@inheritDoc}
+     */
+    public byte[] getMatchedDnBytes()
+    {
+        return matchedDNBytes;
+    }
+
+
+    /**
      * Sets the lowest entry in the directory that was matched.
      * 
      * @see #getMatchedDn()
-     * @param matchedDn
-     *            the Dn of the lowest matched entry.
+     * @param matchedDn the Dn of the lowest matched entry.
      */
     public void setMatchedDn( DN matchedDn )
     {
@@ -110,6 +142,15 @@ public class LdapResultImpl implements I
 
 
     /**
+     * {@inheritDoc}
+     */
+    public void setMatchedDnBytes( byte[] matchedDNBytes )
+    {
+        this.matchedDNBytes = matchedDNBytes;
+    }
+
+
+    /**
      * Gets the result code enumeration associated with the response.
      * Corresponds to the <b> resultCode </b> field within the LDAPResult ASN.1
      * structure.

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalAbstractMessage.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalAbstractMessage.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalAbstractMessage.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalAbstractMessage.java
Wed Aug 11 00:25:59 2010
@@ -43,6 +43,9 @@ public abstract class InternalAbstractMe
     /** Map of message controls using OID Strings for keys and Control values */
     private final Map<String, Control> controls;
 
+    /** The encoded controls length */
+    private int controlsLength;
+
     /** The session unique message sequence identifier */
     private final int id;
 
@@ -55,6 +58,9 @@ public abstract class InternalAbstractMe
     /** The current control */
     private Control currentControl;
 
+    /** The encoded message length */
+    private int messageLength;
+
 
     /**
      * Completes the instantiation of a Message.
@@ -277,4 +283,40 @@ public abstract class InternalAbstractMe
             this.controls.put( c.getOid(), c );
         }
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setControlsLength( int controlsLength )
+    {
+        this.controlsLength = controlsLength;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getControlsLength()
+    {
+        return controlsLength;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setMessageLength( int messageLength )
+    {
+        this.messageLength = messageLength;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getMessageLength()
+    {
+        return messageLength;
+    }
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalBindResponse.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalBindResponse.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalBindResponse.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalBindResponse.java
Wed Aug 11 00:25:59 2010
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.shared.ldap.message.internal;
 
+
 import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
 
 
@@ -54,4 +55,17 @@ public interface InternalBindResponse ex
      *            the sasl auth. mech. specific credentials
      */
     void setServerSaslCreds( byte[] a_serverSaslCreds );
+
+
+    /**
+     * Stores the encoded length for the BindResponse
+     * @param bindResponseLength The encoded length
+     */
+    void setBindResponseLength( int bindResponseLength );
+
+
+    /**
+     * @return The encoded BindResponse's length
+     */
+    int getBindResponseLength();
 }

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalLdapResult.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalLdapResult.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalLdapResult.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalLdapResult.java
Wed Aug 11 00:25:59 2010
@@ -20,6 +20,7 @@
 
 package org.apache.directory.shared.ldap.message.internal;
 
+
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.DN;
 
@@ -79,16 +80,29 @@ public interface InternalLdapResult
 
 
     /**
+     * @return the encoded MatchedDN
+     */
+    byte[] getMatchedDnBytes();
+
+
+    /**
      * Sets the lowest entry in the directory that was matched.
      * 
      * @see #getMatchedDn()
-     * @param dn
-     *            the Dn of the lowest matched entry.
+     * @param dn the Dn of the lowest matched entry.
      */
     void setMatchedDn( DN dn );
 
 
     /**
+     * Sets the encoded value for MatchedDn
+     * 
+     * @param matchedDNBytes The encoded MatchedDN
+     */
+    void setMatchedDnBytes( byte[] matchedDNBytes );
+
+
+    /**
      * Gets the descriptive error message associated with the error code. May be
      * null for SUCCESS, COMPARETRUE, COMPAREFALSE and REFERRAL operations.
      * 
@@ -98,16 +112,28 @@ public interface InternalLdapResult
 
 
     /**
+     * @return The encoded Error message
+     */
+    byte[] getErrorMessageBytes();
+
+
+    /**
      * Sets the descriptive error message associated with the error code. May be
      * null for SUCCESS, COMPARETRUE, and COMPAREFALSE operations.
      * 
-     * @param errorMessage
-     *            the descriptive error message.
+     * @param errorMessage the descriptive error message.
      */
     void setErrorMessage( String errorMessage );
 
 
     /**
+     * Set the encoded message's bytes
+     * @param errorMessageBytes The encoded bytes
+     */
+    void setErrorMessage( byte[] errorMessageBytes );
+
+
+    /**
      * Gets whether or not this result represents a Referral. For referrals the
      * error code is set to REFERRAL and the referral property is not null.
      * 

Modified: directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalMessage.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalMessage.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalMessage.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/main/java/org/apache/directory/shared/ldap/message/internal/InternalMessage.java
Wed Aug 11 00:25:59 2010
@@ -72,6 +72,32 @@ public interface InternalMessage
 
 
     /**
+     * Stores the encoded length for the controls
+     * @param controlsLength The encoded length
+     */
+    void setControlsLength( int controlsLength );
+
+
+    /**
+     * @return The encoded Controls' length
+     */
+    int getControlsLength();
+
+
+    /**
+     * Stores the encoded length for the message
+     * @param messageLength The encoded length
+     */
+    void setMessageLength( int messageLength );
+
+
+    /**
+     * @return The encoded Message's length
+     */
+    int getMessageLength();
+
+
+    /**
      * Adds a control to this Message.
      * 
      * @param control

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/AddRequestImplTest.java
Wed Aug 11 00:25:59 2010
@@ -337,6 +337,28 @@ public class AddRequestImplTest
             {
                 return null;
             }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
         };
 
         AddRequestImpl req1 = new AddRequestImpl( 5 );

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/BindRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/BindRequestImplTest.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/BindRequestImplTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/BindRequestImplTest.java
Wed Aug 11 00:25:59 2010
@@ -358,6 +358,28 @@ public class BindRequestImplTest
             {
                 return null;
             }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
         };
 
         BindRequestImpl req1 = new BindRequestImpl( 5 );

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/CompareRequestImplTest.java
Wed Aug 11 00:25:59 2010
@@ -312,6 +312,28 @@ public class CompareRequestImplTest
             {
                 return null;
             }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
         };
 
         CompareRequestImpl req1 = new CompareRequestImpl( 5 );

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/DeleteRequestImplTest.java
Wed Aug 11 00:25:59 2010
@@ -245,6 +245,28 @@ public class DeleteRequestImplTest
             {
                 return null;
             }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
         };
 
         DeleteRequestImpl req1 = new DeleteRequestImpl( 5 );

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedRequestImplTest.java
Wed Aug 11 00:25:59 2010
@@ -288,6 +288,28 @@ public class ExtendedRequestImplTest
             {
                 return null;
             }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
         };
 
         ExtendedRequestImpl req1 = new ExtendedRequestImpl( 5 );

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ExtendedResponseImplTest.java
Wed Aug 11 00:25:59 2010
@@ -231,6 +231,28 @@ public class ExtendedResponseImplTest
             {
                 return null;
             }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
         };
 
         assertTrue( resp0.equals( resp1 ) );

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/LdapResultImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/LdapResultImplTest.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/LdapResultImplTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/LdapResultImplTest.java
Wed Aug 11 00:25:59 2010
@@ -20,21 +20,18 @@
 package org.apache.directory.shared.ldap.message;
 
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
 import org.apache.directory.shared.ldap.exception.LdapException;
-import org.apache.directory.shared.ldap.message.LdapResultImpl;
-import org.apache.directory.shared.ldap.message.ReferralImpl;
-import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.internal.InternalLdapResult;
 import org.apache.directory.shared.ldap.message.internal.InternalReferral;
 import org.apache.directory.shared.ldap.name.DN;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
 
 /**
  * Tests the methods of the LdapResultImpl class.
@@ -93,6 +90,7 @@ public class LdapResultImplTest
     public void testEqualsDiffImpl()
     {
         LdapResultImpl r0 = new LdapResultImpl();
+
         InternalLdapResult r1 = new InternalLdapResult()
         {
             public ResultCodeEnum getResultCode()
@@ -143,6 +141,28 @@ public class LdapResultImplTest
             public void setReferral( InternalReferral a_referral )
             {
             }
+
+
+            public byte[] getMatchedDnBytes()
+            {
+                return null;
+            }
+
+
+            public void setMatchedDnBytes( byte[] matchedDNBytes )
+            {
+            }
+
+
+            public byte[] getErrorMessageBytes()
+            {
+                return null;
+            }
+
+
+            public void setErrorMessage( byte[] errorMessageBytes )
+            {
+            }
         };
 
         assertTrue( "r0 equals should see other impl r1 as equal", r0.equals( r1 ) );
@@ -293,7 +313,7 @@ public class LdapResultImplTest
         r1.setErrorMessage( "blah blah blah" );
 
         r0.setMatchedDn( new DN( "dc=example,dc=com" ) );
-        r1.setMatchedDn( new DN( "dc=apache,dc=org")  );
+        r1.setMatchedDn( new DN( "dc=apache,dc=org" ) );
 
         r0.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );
         r1.setResultCode( ResultCodeEnum.TIME_LIMIT_EXCEEDED );

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyDnRequestImplTest.java
Wed Aug 11 00:25:59 2010
@@ -404,6 +404,28 @@ public class ModifyDnRequestImplTest
             {
                 return null;
             }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
         };
 
         ModifyDnRequestImpl req1 = getRequest();

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/ModifyRequestImplTest.java
Wed Aug 11 00:25:59 2010
@@ -433,6 +433,28 @@ public class ModifyRequestImplTest
             {
                 return null;
             }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
         };
 
         ModifyRequestImpl req1 = getRequest();

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImplTest.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImplTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseDoneImplTest.java
Wed Aug 11 00:25:59 2010
@@ -192,6 +192,28 @@ public class SearchResponseDoneImplTest
             {
                 return null;
             }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
         };
 
         assertTrue( resp0.equals( resp1 ) );

Modified: directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImplTest.java?rev=984272&r1=984271&r2=984272&view=diff
==============================================================================
--- directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImplTest.java
(original)
+++ directory/shared/branches/shared-codec-merge/ldap/src/test/java/org/apache/directory/shared/ldap/message/SearchResponseReferenceImplTest.java
Wed Aug 11 00:25:59 2010
@@ -169,6 +169,28 @@ public class SearchResponseReferenceImpl
             {
                 return null;
             }
+
+
+            public int getControlsLength()
+            {
+                return 0;
+            }
+
+
+            public void setControlsLength( int controlsLength )
+            {
+            }
+
+
+            public int getMessageLength()
+            {
+                return 0;
+            }
+
+
+            public void setMessageLength( int messageLength )
+            {
+            }
         };
 
         SearchResponseReferenceImpl resp1 = new SearchResponseReferenceImpl( 5 );



Mime
View raw message