directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r226670 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindRequest.java
Date Sun, 31 Jul 2005 18:06:10 GMT
Author: elecharny
Date: Sun Jul 31 11:06:07 2005
New Revision: 226670

URL: http://svn.apache.org/viewcvs?rev=226670&view=rev
Log:
Added the encode method

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindRequest.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindRequest.java?rev=226670&r1=226669&r2=226670&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindRequest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/BindRequest.java
Sun Jul 31 11:06:07 2005
@@ -16,8 +16,14 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 
 
@@ -40,6 +46,9 @@
 
     /** The authentication used to bind the user */
     private Asn1Object authentication;
+    
+    /** The bind request length */
+    private transient int bindRequestLength;
 
     //~ Constructors -------------------------------------------------------------------------------
 
@@ -164,7 +173,7 @@
      */
     public int computeLength()
     {
-        int bindRequestLength = 1 + 1 + 1; // Initialized with version
+        bindRequestLength = 1 + 1 + 1; // Initialized with version
         
         // The name
         bindRequestLength += 1 + Length.getNbBytes( name.getLength() ) + name.getLength();
@@ -176,6 +185,55 @@
         return 1 + Length.getNbBytes( bindRequestLength ) + bindRequestLength;
     }
     
+    /**
+     * Encode the BindRequest message to a PDU.
+     * 
+     * BindRequest :
+     * 
+     * 0x60 LL
+     *   0x02 LL version
+     *   0x04 LL name
+     *   authentication.encode()
+     *     0x80 LL simple
+     *    /
+     *    \
+     *     0x83 LL mechanism
+     *     [0x04 LL credential]
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The BindRequest Tag
+            buffer.put( LdapConstants.BIND_REQUEST_TAG );
+            buffer.put( Length.getBytes( bindRequestLength ) ) ;
+
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        // The version
+        Value.encode( buffer, version );
+        
+        // The name
+        Value.encode( buffer, name );
+        
+        // The authentication
+        authentication.encode( buffer );
+
+        return buffer;
+    }
+
     /**
      * Get a String representation of a BindRequest
      *



Mime
View raw message