directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r226674 - in /directory/sandbox/trunk/asn1-new-codec/src: java/org/apache/asn1/ldap/codec/ java/org/apache/asn1/ldap/codec/grammars/ java/org/apache/asn1/ldap/pojo/ test/org/apache/asn1/ldap/codec/
Date Sun, 31 Jul 2005 18:15:05 GMT
Author: elecharny
Date: Sun Jul 31 11:14:56 2005
New Revision: 226674

URL: http://svn.apache.org/viewcvs?rev=226674&view=rev
Log:
Added the encoding of CompareRequest message

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareRequest.java
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareRequestTest.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java?rev=226674&r1=226673&r2=226674&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
Sun Jul 31 11:14:56 2005
@@ -54,6 +54,7 @@
     public static final byte UNBIND_REQUEST_TAG  = 0x42;
     public static final byte DEL_REQUEST_TAG  = 0x4A;
     public static final byte ABANDON_REQUEST_TAG = 0x50;
+    public static final byte BIND_REQUEST_TAG = 0x60;
     public static final byte BIND_RESPONSE_TAG = 0x61;
     public static final byte SEARCH_RESULT_DONE_TAG = 0x65;
     public static final byte MODIFY_RESPONSE_TAG = 0x67;
@@ -61,15 +62,18 @@
     public static final byte DEL_RESPONSE_TAG = 0x6B;
     public static final byte MODIFY_DN_REQUEST_TAG = 0x6C;
     public static final byte MODIFY_DN_RESPONSE_TAG = 0x6D;
+    public static final byte COMPARE_REQUEST_TAG = 0x6E;
     public static final byte COMPARE_RESPONSE_TAG = 0x6F;
     public static final byte SEARCH_RESULT_REFERENCE_TAG = 0x73;
     public static final byte EXTENDED_REQUEST_TAG = 0x77;
     public static final byte EXTENDED_RESPONSE_TAG = 0x78;
     // The following tags are ints, because bytes above 127 are negative
     // numbers, and we can't use them as array indexes.
+    public static final int BIND_REQUEST_SIMPLE_TAG = 0x80;
     public static final int EXTENDED_REQUEST_NAME_TAG = 0x80;
     public static final int MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG = 0x80;
     public static final int EXTENDED_REQUEST_VALUE_TAG = 0x81;
+    public static final int BIND_REQUEST_SASL_TAG = 0x83;
     public static final int LDAP_RESULT_REFERRAL_SEQUENCE_TAG = 0x83;
     public static final int SERVER_SASL_CREDENTIAL_TAG = 0x87;
     public static final int EXTENDED_RESPONSE_RESPONSE_NAME_TAG = 0x8A;

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java?rev=226674&r1=226673&r2=226674&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java
Sun Jul 31 11:14:56 2005
@@ -23,6 +23,7 @@
 import org.apache.asn1.ber.grammar.GrammarTransition;
 import org.apache.asn1.ber.grammar.IGrammar;
 import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.LdapMessageContainer;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
@@ -71,13 +72,13 @@
         //============================================================================================
         // CompareRequest ::= [APPLICATION 14] SEQUENCE { (Tag)
         // Nothing to do
-        super.transitions[LdapStatesEnum.COMPARE_REQUEST_TAG][0x6E] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_TAG][LdapConstants.COMPARE_REQUEST_TAG]
= new GrammarTransition(
                 LdapStatesEnum.COMPARE_REQUEST_TAG,
                 LdapStatesEnum.COMPARE_REQUEST_VALUE, null );
 
         // CompareRequest ::= [APPLICATION 14] SEQUENCE { (Value)
         // Initialize the compare request pojo
-        super.transitions[LdapStatesEnum.COMPARE_REQUEST_VALUE][0x6E] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_VALUE][LdapConstants.COMPARE_REQUEST_TAG]
= new GrammarTransition(
                 LdapStatesEnum.COMPARE_REQUEST_VALUE, LdapStatesEnum.COMPARE_REQUEST_ENTRY_TAG,
                 new GrammarAction( "Init Compare Request" )
                 {
@@ -98,7 +99,7 @@
         //     entry           LDAPDN, (Tag)
         //     ...
         // Nothing to do
-        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ENTRY_TAG][0x04] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ENTRY_TAG][LdapConstants.OCTET_STRING_TAG]
= new GrammarTransition(
                 LdapStatesEnum.COMPARE_REQUEST_ENTRY_TAG,
                 LdapStatesEnum.COMPARE_REQUEST_ENTRY_VALUE, null );
 
@@ -106,7 +107,7 @@
         //     entry           LDAPDN, (Tag)
         //     ...
         // Store the DN to be compared
-        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ENTRY_VALUE][0x04] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ENTRY_VALUE][LdapConstants.OCTET_STRING_TAG]
= new GrammarTransition(
                 LdapStatesEnum.COMPARE_REQUEST_ENTRY_VALUE, LdapStatesEnum.COMPARE_REQUEST_AVA_TAG,
                 new GrammarAction( "Store entry" )
                 {
@@ -141,7 +142,7 @@
         //     ava             AttributeValueAssertion }
         // AttributeValueAssertion ::= SEQUENCE { (Tag)
         // Nothing to do
-        super.transitions[LdapStatesEnum.COMPARE_REQUEST_AVA_TAG][0x30] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_AVA_TAG][LdapConstants.SEQUENCE_TAG]
= new GrammarTransition(
                 LdapStatesEnum.COMPARE_REQUEST_AVA_TAG,
                 LdapStatesEnum.COMPARE_REQUEST_AVA_VALUE, null );
 
@@ -150,14 +151,14 @@
         //     ava             AttributeValueAssertion }
         // AttributeValueAssertion ::= SEQUENCE { (Value)
         // Nothing to do
-        super.transitions[LdapStatesEnum.COMPARE_REQUEST_AVA_VALUE][0x30] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_AVA_VALUE][LdapConstants.SEQUENCE_TAG]
= new GrammarTransition(
                 LdapStatesEnum.COMPARE_REQUEST_AVA_VALUE, LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_TAG,
null);
 
         // AttributeValueAssertion ::= SEQUENCE {
         //     attributeDesc   AttributeDescription, (Tag)
         //     ...
         // Nothing to do
-        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_TAG][0x04] = new
GrammarTransition(
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_TAG][LdapConstants.OCTET_STRING_TAG]
= new GrammarTransition(
                 LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_TAG,
                 LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_VALUE, null );
 
@@ -165,7 +166,7 @@
         //     attributeDesc   AttributeDescription, (Value)
         //     ...
         // Nothing to do
-        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_VALUE][0x04] = new
GrammarTransition(
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_VALUE][LdapConstants.OCTET_STRING_TAG]
= new GrammarTransition(
                 LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_VALUE,
                 LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_TAG, 
                 new GrammarAction( "Store attribute desc" )
@@ -200,7 +201,7 @@
         //     ...
         //     assertionValue  AssertionValue } (Tag)
         // Nothing to do
-        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_TAG][0x04] = new
GrammarTransition(
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_TAG][LdapConstants.OCTET_STRING_TAG]
= new GrammarTransition(
                 LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_TAG,
                 LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_VALUE, null );
 
@@ -208,7 +209,7 @@
         //     ...
         //     assertionValue  AssertionValue } (Value)
         // Nothing to do
-        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_VALUE][0x04] = new
GrammarTransition(
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_VALUE][LdapConstants.OCTET_STRING_TAG]
= new GrammarTransition(
                 LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_VALUE,
                 LdapStatesEnum.END_STATE, 
                 new GrammarAction( "Store assertion value" )

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareRequest.java?rev=226674&r1=226673&r2=226674&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareRequest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareRequest.java
Sun Jul 31 11:14:56 2005
@@ -16,7 +16,13 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
+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;
 import org.apache.asn1.ldap.codec.primitives.LdapString;
 import org.apache.asn1.primitives.OctetString;
@@ -50,6 +56,12 @@
 
     /** The value to be compared */
     private OctetString assertionValue;
+    
+    /** The compare request length */
+    private transient int compareRequestLength;
+    
+    /** The attribute value assertion length */
+    private transient int avaLength;
 
     //~ Constructors -------------------------------------------------------------------------------
 
@@ -148,16 +160,64 @@
     {
 
         // The entry
-        int compareRequestLength = 1 + Length.getNbBytes( entry.getLength() ) + entry.getLength();
+        compareRequestLength = 1 + Length.getNbBytes( entry.getLength() ) + entry.getLength();
 
         // The attribute value assertion
-        int avaLength =
+        avaLength =
             1 + Length.getNbBytes( attributeDesc.getLength() ) + attributeDesc.getLength()
+
             1 + Length.getNbBytes( assertionValue.getLength() ) + assertionValue.getLength();
 
         compareRequestLength += 1 + Length.getNbBytes( avaLength ) + avaLength;
 
         return 1 + Length.getNbBytes( compareRequestLength ) + compareRequestLength;
+    }
+
+    /**
+     * Encode the CompareRequest message to a PDU.
+     * 
+     * CompareRequest :
+     * 
+     * 0x6E LL
+     *   0x04 LL entry
+     *   0x30 LL attributeValueAssertion
+     *     0x04 LL attributeDesc
+     *     0x04 LL assertionValue
+     * 
+     * @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 CompareRequest Tag
+            buffer.put( LdapConstants.COMPARE_REQUEST_TAG );
+            buffer.put( Length.getBytes( compareRequestLength ) ) ;
+            
+            // The entry
+            Value.encode( buffer, entry );
+
+            // The attributeValueAssertion sequence Tag
+            buffer.put( LdapConstants.SEQUENCE_TAG );
+            buffer.put( Length.getBytes( avaLength ) ) ;
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        // The attributeDesc
+        Value.encode( buffer, attributeDesc );
+        
+        // The assertionValue
+        Value.encode( buffer, assertionValue );
+
+        return buffer;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareRequestTest.java?rev=226674&r1=226673&r2=226674&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareRequestTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareRequestTest.java
Sun Jul 31 11:14:56 2005
@@ -21,10 +21,12 @@
 import javax.naming.NamingException;
 
 import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.containers.IAsn1Container;
 import org.apache.asn1.ldap.pojo.CompareRequest;
 import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.util.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
@@ -71,6 +73,7 @@
 				0x04, 0x05, 'v', 'a', 'l', 'u', 'e'
             } );
 
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a LdapMessage Container
@@ -98,6 +101,21 @@
 
         // Check the length
         Assert.assertEquals(0x3A, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
     }
 
     /**



Mime
View raw message