Author: elecharny
Date: Thu Apr 14 22:42:23 2005
New Revision: 161400

URL: http://svn.apache.org/viewcvs?view=rev&rev=161400
Log:
Created the LdapResultGrammar, LdapControlGrammar and the BindResponseGrammar.
A lot of changes done in LdapMessageGrammar and BindRequestGrammar.

Added:
    
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/
    
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindRequestGrammar.java
    
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindResponseGrammar.java
    
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapControlGrammar.java
    
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java
      - copied, changed from r160136, 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageGrammar.java
    
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapResultGrammar.java

Added: 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindRequestGrammar.java
URL: 
http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindRequestGrammar.java?view=auto&rev=161400
==============================================================================
--- 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindRequestGrammar.java
 (added)
+++ 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindRequestGrammar.java
 Thu Apr 14 22:42:23 2005
@@ -0,0 +1,541 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec.grammars;
+
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ber.grammar.AbstractGrammar;
+import org.apache.asn1.ber.grammar.GrammarAction;
+import org.apache.asn1.ber.grammar.GrammarTransition;
+import org.apache.asn1.ber.grammar.IGrammar;
+import org.apache.asn1.ber.grammar.StatesEnum;
+import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.DecoderException;
+import org.apache.asn1.ldap.codec.LdapMessageContainer;
+import org.apache.asn1.ldap.codec.primitives.LdapDN;
+import org.apache.asn1.ldap.codec.primitives.LdapString;
+import org.apache.asn1.ldap.codec.utils.IntegerDecoder;
+import org.apache.asn1.ldap.pojo.BindRequestPOJO;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+import org.apache.asn1.ldap.pojo.SaslAuthenticationPOJO;
+import org.apache.asn1.ldap.pojo.SimpleAuthenticationPOJO;
+import org.apache.asn1.util.MutableString;
+import org.apache.asn1.util.pools.PoolEnum;
+import org.apache.asn1.util.pools.PoolException;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the LdapMessage. All the actions are declared in this
+ * class. As it is a singleton, these declaration are only done once.
+ * 
+ * If an action is to be added or modified, this is where the work is to be 
done !
+ * 
+ * @author <a href="mailto:[email protected]";>Apache Directory 
Project</a>
+ */
+public class BindRequestGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers 
-----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( 
BindRequestGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. BindRequestGrammar is a singleton */
+    private static IGrammar instance = new BindRequestGrammar();
+
+    //~ Methods 
------------------------------------------------------------------------------------
+
+    /**
+     * Get the instance of this grammar
+     *
+     * @return An instance on the BindRequest Grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+
+    //~ Constructors 
-------------------------------------------------------------------------------
+
+    /**
+     * Creates a new LdapMessageGrammar object.
+     */
+    private BindRequestGrammar()
+    {
+
+        name = BindRequestGrammar.class.getName();
+
+        // We have 17 differents states, so 16 transitions between states.
+        super.transitions = new 
GrammarTransition[StatesEnum.LAST_BIND_REQUEST_STATE][256];
+
+        
//============================================================================================
+        // protocolOp : Bind Request
+        
//============================================================================================
+        // We have to allocate a BindRequestPOJO
+        // LdapMessage ::= ... BindRequest ...
+        // BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Length)
+        super.transitions[StatesEnum.BIND_REQUEST_TAG][0x60]    = new 
GrammarTransition(
+                StatesEnum.BIND_REQUEST_TAG, StatesEnum.BIND_REQUEST_LENGTH, 
null );
+
+        super.transitions[StatesEnum.BIND_REQUEST_LENGTH][0x60] = new 
GrammarTransition(
+                StatesEnum.BIND_REQUEST_LENGTH, StatesEnum.BIND_REQUEST_VALUE,
+                new GrammarAction( "Init BindRequest" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+                        LdapMessagePOJO      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        checkLength( ldapMessageContainer.getLdapMessage(),
+                            ldapMessageContainer.getCurrentTLV() );
+
+                        try
+                        {
+
+                            // Now, we can allocate the BindRequest POJO
+                            BindRequestPOJO bindRequest = ( BindRequestPOJO )
+                                ldapMessageContainer.getPoolManager().allocate(
+                                    PoolEnum.BIND_REQUEST_POJO_POOL );
+
+                            // As this is a new Constructed object, we have to 
init its length
+                            TLV tlv            = 
ldapMessageContainer.getCurrentTLV();
+                            int expectedLength = tlv.getLength().getLength();
+
+                            bindRequest.setExpectedLength( expectedLength );
+                            bindRequest.setCurrentLength( 0 );
+                            bindRequest.setFather( ldapMessage );
+
+                            // And we associate it to the ldapMessage POJO
+                            ldapMessage.setProtocolOP( bindRequest );
+
+                        }
+                        catch ( PoolException pe )
+                        {
+                            throw new DecoderException(
+                                "Cannot allocate a BindRequest Pojo : " + 
pe.getMessage() );
+                        }
+                    }
+                } );
+
+        // LdapMessage ::= ... BindRequest ...
+        // BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Value)
+        // Nothing to do, the Value is empty, this is a constructed TLV. We 
now can swith to the BindRequest Grammar
+        super.transitions[StatesEnum.BIND_REQUEST_VALUE][0x60] = new 
GrammarTransition(
+                StatesEnum.BIND_REQUEST_VALUE, 
StatesEnum.BIND_REQUEST_VERSION_TAG, null );
+
+        // BindRequest ::= ... version INTEGER (1 .. 127 ), ... (Tag)
+        // Nothing to do.
+        super.transitions[StatesEnum.BIND_REQUEST_VERSION_TAG][0x02] = new 
GrammarTransition(
+                StatesEnum.BIND_REQUEST_VERSION_TAG, 
StatesEnum.BIND_REQUEST_VERSION_LENGTH, null );
+
+        // BindRequest ::= ... version INTEGER (1 .. 127 ), ... (Length)
+        // Checks the length
+        super.transitions[StatesEnum.BIND_REQUEST_VERSION_LENGTH][0x02] = new 
GrammarTransition(
+                StatesEnum.BIND_REQUEST_VERSION_LENGTH, 
StatesEnum.BIND_REQUEST_VERSION_VALUE,
+                new GrammarAction( "Store version" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+
+                        checkLength( 
ldapMessageContainer.getLdapMessage().getProtocolOp(),
+                            ldapMessageContainer.getCurrentTLV() );
+                        return;
+                    }
+                } );
+
+        // BindRequest ::= ... version INTEGER (1 .. 127 ), ... (value)
+        // Checks that the Version is in [1, 127]
+        super.transitions[StatesEnum.BIND_REQUEST_VERSION_VALUE][0x02] = new 
GrammarTransition(
+                StatesEnum.BIND_REQUEST_VERSION_VALUE, 
StatesEnum.BIND_REQUEST_NAME_TAG,
+                new GrammarAction( "Store version" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+                        BindRequestPOJO      bindRequestMessage   = ( 
BindRequestPOJO )
+                            
ldapMessageContainer.getLdapMessage().getProtocolOp();
+
+                        // The current TLV should be a integer between 1 and 
127
+                        // We get it and store it in Version
+                        TLV   tlv     = ldapMessageContainer.getCurrentTLV();
+
+                        Value value   = tlv.getValue();
+
+                        int   version = IntegerDecoder.parse( value, 1, 127 );
+
+                        bindRequestMessage.setVersion( version );
+
+                        return;
+                    }
+                } );
+
+        // BindRequest ::= ... name LDAPDN, ... (Tag)
+        // Nothing to do. The tag is supposed to be 0x04
+        super.transitions[StatesEnum.BIND_REQUEST_NAME_TAG][0x04] = new 
GrammarTransition(
+                StatesEnum.BIND_REQUEST_NAME_TAG, 
StatesEnum.BIND_REQUEST_NAME_LENGTH, null );
+
+        // BindRequest ::= ... name LDAPDN, ... (Length)
+        // We just check the length.
+        super.transitions[StatesEnum.BIND_REQUEST_NAME_LENGTH][0x04] = new 
GrammarTransition(
+                StatesEnum.BIND_REQUEST_NAME_LENGTH, 
StatesEnum.BIND_REQUEST_NAME_VALUE,
+                new GrammarAction( "Check Bind Name Length" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+                        BindRequestPOJO bindRequestMessage = ( BindRequestPOJO 
)
+                        ldapMessageContainer.getLdapMessage().getProtocolOp();
+                        
+                        TLV                  tlv                  =
+                            ldapMessageContainer.getCurrentTLV();
+
+
+                        checkLength( bindRequestMessage, tlv );
+                        
+                        // We have to handle the special case of a 0 length 
name
+                        if (tlv.getLength().getLength() == 0)
+                        {
+                            bindRequestMessage.setName( 
MutableString.EMPTY_STRING );
+                        }
+                        
+                        return;
+                    }
+                } );
+
+        // BindRequest ::= ... name LDAPDN, ... (Value)
+        // We have to store the name
+        super.transitions[StatesEnum.BIND_REQUEST_NAME_VALUE][0x04] = new 
GrammarTransition(
+                StatesEnum.BIND_REQUEST_NAME_VALUE,
+                StatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG,
+                new GrammarAction( "Store Bind Name value" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+                        BindRequestPOJO bindRequestMessage = ( BindRequestPOJO 
)
+                        ldapMessageContainer.getLdapMessage().getProtocolOp();
+
+                        // Get the Value and store it in the BindRequest
+                        TLV             tlv                = 
ldapMessageContainer.getCurrentTLV();
+
+
+                        bindRequestMessage.setName( LdapDN.parseDN(
+                                ldapMessageContainer.getPoolManager(), 
tlv.getValue().getData() ) );
+                        return;
+                    }
+                } );
+
+        // BindRequest ::= ... authentication AuthenticationChoice }
+        // AuthenticationChoice ::= CHOICE {
+        // The tag might be either 0x80 (SimpleAuthentication) or 0x83 
(SaslAuthentication)
+        
//--------------------------------------------------------------------------------------------
+        // If it's 0x80, it is a SimpleAuthentication.
+        
//--------------------------------------------------------------------------------------------
+        // Nothing to do.
+        super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG][( 
0x80 & 0x00FF )] =
+            new GrammarTransition( 
StatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG,
+                StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_LENGTH, null );
+
+        // AuthenticationChoice ::= CHOICE {
+        //        simple         [0] OCTET STRING, (Length)
+        // We just have to check the length, and to allocate an authentication 
POJO
+        
super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_LENGTH][( 0x80 
& 0x00FF )] =
+            new GrammarTransition( 
StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_LENGTH,
+                StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE,
+                new GrammarAction( "Check simple authentication length" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+                        BindRequestPOJO bindRequestMessage = ( BindRequestPOJO 
)
+                        ldapMessageContainer.getLdapMessage().getProtocolOp();
+                        
+                        TLV             tlv                = 
ldapMessageContainer.getCurrentTLV();
+
+                        checkLength( bindRequestMessage, tlv );
+
+                        // Allocate the Authentication POJO
+                        SimpleAuthenticationPOJO authentication = null;
+                        
+                        try
+                        {
+
+                            authentication = ( SimpleAuthenticationPOJO )
+                                ldapMessageContainer.getPoolManager().allocate(
+                                    PoolEnum.SIMPLE_AUTH_POJO_POOL );
+
+                            authentication.setFather( bindRequestMessage );
+
+                            bindRequestMessage.setAuthentication( 
authentication );
+                        }
+                        catch ( PoolException pe )
+                        {
+                            throw new DecoderException(
+                                "Cannot allocate a SimpleAuthentication Pojo : 
" + pe.getMessage() );
+                        }
+
+                        // We have to handle the special case of a 0 length 
simple
+                        if (tlv.getLength().getLength() == 0)
+                        {
+                            authentication.setSimple( new byte[]{} );
+                        }
+                        
+                        return;
+                    }
+                } );
+
+        // AuthenticationChoice ::= CHOICE {
+        //        simple         [0] OCTET STRING, (Value)
+        // We have to create an Authentication POJO to store the credentials.
+        // The nextState is GRAMMAR_END
+        
super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE][( 0x80 & 
0x00FF )] =
+            new GrammarTransition( 
StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE,
+                StatesEnum.GRAMMAR_END,
+                new GrammarAction( "Store Bind Simple Authentication value" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+                        
+                        BindRequestPOJO bindRequestMessage = ( BindRequestPOJO 
)
+                        ldapMessageContainer.getLdapMessage().getProtocolOp();
+                        
+                        SimpleAuthenticationPOJO simpleAuthentication = 
(SimpleAuthenticationPOJO)bindRequestMessage.getAuthentication();
+
+                        TLV           tlv    = 
ldapMessageContainer.getCurrentTLV();
+
+                        // Get the simple value
+                        // Store the simple in the authentication
+                        simpleAuthentication.setSimple( 
tlv.getValue().getData() );
+                    }
+                } );
+
+        
//--------------------------------------------------------------------------------------------
+        // If it's 0x83, it is a Sasl Credentials.
+        // AuthenticationChoice ::= CHOICE {
+        //          ...
+        //        sasl         [3] SaslCredentials }
+        //
+        // SaslCredentials ::= SEQUENCE {
+        //        mechanism     LDAPSTRING,
+        //        credentials   OCTET STRING OPTIONNAL }
+        
//--------------------------------------------------------------------------------------------
+        // AuthenticationChoice ::= CHOICE {
+        //        sasl         [3] saslCredentials, (Tag)
+        // Nothing to do. In fact, 0x83 is the mechanism tag. 
+        super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG][( 
0x83 & 0x00FF )] =
+            new GrammarTransition( 
StatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG,
+                StatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_LENGTH, null 
);
+
+        // AuthenticationChoice ::= CHOICE {
+        //        sasl         [3] saslCredentials }
+        //
+        // SaslCredentials ::= SEQUENCE {
+        //        mechanism     LDAPSTRING,  (Length)
+        //               ...
+        // We just have to check the length.
+        
super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_LENGTH][( 
0x83 & 0x00FF )] =
+            new GrammarTransition( 
StatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_LENGTH,
+                StatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE,
+                new GrammarAction( "Check sasl authentication mechanism 
length" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+                        BindRequestPOJO bindRequestMessage = ( BindRequestPOJO 
)
+                        ldapMessageContainer.getLdapMessage().getProtocolOp();
+
+                        TLV           tlv    = 
ldapMessageContainer.getCurrentTLV();
+                        
+                        checkLength( bindRequestMessage, tlv );
+
+                        // Create the SaslAuthentication POJO
+                        SaslAuthenticationPOJO authentication = null;
+
+                        try
+                        {
+                            authentication = ( SaslAuthenticationPOJO )
+                                ldapMessageContainer.getPoolManager().allocate(
+                                    PoolEnum.SASL_AUTH_POJO_POOL );
+
+                            authentication.setFather( bindRequestMessage );
+
+                            bindRequestMessage.setAuthentication( 
authentication );
+                        }
+                        catch ( PoolException pe )
+                        {
+                            throw new DecoderException(
+                                "Cannot allocate a SaslAuthentication Pojo : " 
+ pe.getMessage() );
+                        }
+
+                        // We have to handle the special case of a 0 length 
mechanism
+                        if (tlv.getLength().getLength() == 0)
+                        {
+                            authentication.setMechanism( 
MutableString.EMPTY_STRING );
+                        }
+
+                        return;
+                    }
+                } );
+
+        // AuthenticationChoice ::= CHOICE {
+        //        sasl         [3] saslCredentials }
+        //
+        // SaslCredentials ::= SEQUENCE {
+        //        mechanism     LDAPSTRING,  (Value)
+        //               ...
+        // We have to store the mechanism.
+        
super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE][( 
0x83 & 0x00FF )] =
+            new GrammarTransition( 
StatesEnum.BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE,
+                StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG,
+                new GrammarAction( "Create Bind sasl Authentication POJO" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer   ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+
+                        BindRequestPOJO        bindRequestMessage = ( 
BindRequestPOJO )
+                            
ldapMessageContainer.getLdapMessage().getProtocolOp();
+                        
+                        SaslAuthenticationPOJO saslAuthentication = 
(SaslAuthenticationPOJO)bindRequestMessage.getAuthentication();
+
+                        MutableString mechanism = LdapString.parse(
+                                ldapMessageContainer.getPoolManager(),
+                                
ldapMessageContainer.getCurrentTLV().getValue().getData() );
+                        
+                        saslAuthentication.setMechanism( mechanism );
+                        
+                        return;
+                    }
+                } );
+
+        
//--------------------------------------------------------------------------------------------
+        // SaslCredentials ::= SEQUENCE {
+        //        ...
+        //        credentials     OCTET STRING OPTIONAL } (Tag)
+        
//--------------------------------------------------------------------------------------------
+        // We may have a credential, or nothing, as it's an optional element.
+        // The tag will have one of those values :
+        //     - 0x04 if it's a credentials
+        //     - 0x80 if it's a control
+        //     - any other value is an error.
+        //
+        // It's a credential if it's 0x04
+        
super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG][0x04] 
=
+            new GrammarTransition( 
StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG,
+                StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_LENGTH, 
null );
+
+        // It's a control if it's 0x80
+        
super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG][(0x80 
& 0x00FF)] =
+            new GrammarTransition( 
StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG,
+                StatesEnum.GRAMMAR_END, null );
+        
+        // SaslCredentials ::= SEQUENCE {
+        //        ...
+        //        credentials     OCTET STRING OPTIONAL } (Length)
+        // We just have to check the length
+        
super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_LENGTH][0x04]
 =
+            new GrammarTransition( 
StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_LENGTH,
+                StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE,
+                new GrammarAction( "Check sasl authentication credentials 
length" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+                        
+                        BindRequestPOJO        bindRequestMessage = ( 
BindRequestPOJO )
+                        ldapMessageContainer.getLdapMessage().getProtocolOp();
+
+                        TLV           tlv    = 
ldapMessageContainer.getCurrentTLV();
+                        
+                        checkLength( bindRequestMessage, tlv );
+
+                        // We have to handle the special case of a 0 length 
credentials
+                        if (tlv.getLength().getLength() == 0)
+                        {
+                            SaslAuthenticationPOJO saslAuthentication = ( 
SaslAuthenticationPOJO ) ( bindRequestMessage
+                                .getAuthentication() );
+
+                            saslAuthentication.setCredentials( new byte[]{} );
+                        }
+
+                        return;
+                    }
+                } );
+
+        // SaslCredentials ::= SEQUENCE {
+        //        ...
+        //        credentials     OCTET STRING OPTIONAL } (Value)
+        //
+        // We have to get the Credentials and store it in the 
SaslAuthenticationPOJO.
+        // Two different following states are possible :
+        // - a Controls tag (0x80)
+        // - or nothing at all (end of the BindRequest).
+        // We just have to transit to the first case, which will accept or not 
the transition.
+        // This is done by transiting to the GRAMMAR_END state
+        
super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE][0x04]
 =
+            new GrammarTransition( 
StatesEnum.BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE,
+                StatesEnum.GRAMMAR_END,
+                new GrammarAction( "Store Bind sasl Authentication credentials 
value" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+
+                        BindRequestPOJO        bindRequestMessage = ( 
BindRequestPOJO )
+                        ldapMessageContainer.getLdapMessage().getProtocolOp();
+                        
+                        SaslAuthenticationPOJO saslAuthentication = ( 
SaslAuthenticationPOJO ) ( bindRequestMessage
+                                .getAuthentication() );
+
+                        // Get the Value and store it in the BindRequest
+                        TLV           tlv         = 
ldapMessageContainer.getCurrentTLV();
+
+                        saslAuthentication.setCredentials( 
tlv.getValue().getData() );
+                        return;
+                    }
+                } );
+    }
+}

Added: 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindResponseGrammar.java
URL: 
http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindResponseGrammar.java?view=auto&rev=161400
==============================================================================
--- 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindResponseGrammar.java
 (added)
+++ 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/BindResponseGrammar.java
 Thu Apr 14 22:42:23 2005
@@ -0,0 +1,227 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec.grammars;
+
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ber.grammar.AbstractGrammar;
+import org.apache.asn1.ber.grammar.GrammarAction;
+import org.apache.asn1.ber.grammar.GrammarTransition;
+import org.apache.asn1.ber.grammar.IGrammar;
+import org.apache.asn1.ber.grammar.StatesEnum;
+import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.codec.DecoderException;
+import org.apache.asn1.ldap.codec.LdapMessageContainer;
+import org.apache.asn1.ldap.pojo.BindResponsePOJO;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+import org.apache.asn1.util.pools.PoolEnum;
+import org.apache.asn1.util.pools.PoolException;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the LdapMessage. All the actions are declared in this
+ * class. As it is a singleton, these declaration are only done once.
+ * 
+ * If an action is to be added or modified, this is where the work is to be 
done !
+ * 
+ * @author <a href="mailto:[email protected]";>Apache Directory 
Project</a>
+ */
+public class BindResponseGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers 
-----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( 
BindResponseGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. LdapMessage is a singleton */
+    private static IGrammar instance = new BindResponseGrammar();
+
+    //~ Constructors 
-------------------------------------------------------------------------------
+
+    /**
+     * Creates a new LdapMessageGrammar object.
+     */
+    private BindResponseGrammar()
+    {
+        name = BindResponseGrammar.class.getName();
+
+        // We have 17 differents states, so 16 transitions between states.
+        super.transitions = new 
GrammarTransition[StatesEnum.LAST_LDAP_STATE][256];
+
+        
//============================================================================================
+        // BindResponse Message
+        
//============================================================================================
+        // BindResponse ::= APPLICATION 1] SEQUENCE {
+        //     COMPONENTS OF LDAPResult,
+        //     ...
+        // Nothing to do
+        super.transitions[StatesEnum.BIND_RESPONSE_TAG][0x61] = new 
GrammarTransition(
+                StatesEnum.BIND_RESPONSE_TAG, StatesEnum.BIND_RESPONSE_LENGTH, 
null );
+
+        // We have to allocate a BindRequestPOJO
+        // LdapMessage ::= ... BindResponse ...
+        // BindResponse ::= [APPLICATION 1] SEQUENCE { ... (Length)
+        super.transitions[StatesEnum.BIND_RESPONSE_LENGTH][0x61] = new 
GrammarTransition(
+                StatesEnum.BIND_RESPONSE_LENGTH, 
StatesEnum.BIND_RESPONSE_VALUE,
+                new GrammarAction( "Init BindReponse" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+                        LdapMessagePOJO      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        checkLength( ldapMessageContainer.getLdapMessage(),
+                            ldapMessageContainer.getCurrentTLV() );
+
+                        try
+                        {
+
+                            // Now, we can allocate the BindRequest POJO
+                            BindResponsePOJO bindResponse = ( BindResponsePOJO 
)
+                                ldapMessageContainer.getPoolManager().allocate(
+                                    PoolEnum.BIND_RESPONSE_POJO_POOL );
+
+                            // As this is a new Constructed object, we have to 
init its length
+                            TLV tlv            = 
ldapMessageContainer.getCurrentTLV();
+                            int expectedLength = tlv.getLength().getLength();
+                            bindResponse.setExpectedLength( expectedLength );
+                            bindResponse.setCurrentLength( 0 );
+                            bindResponse.setFather( ldapMessage );
+
+                            // And we associate it to the ldapMessage POJO
+                            ldapMessage.setProtocolOP( bindResponse );
+
+                        }
+                        catch ( PoolException pe )
+                        {
+                            throw new DecoderException(
+                                "Cannot allocate a BindResponse Pojo : " + 
pe.getMessage() );
+                        }
+                    }
+                } );
+
+        // LdapMessage ::= ... BindResponse ...
+        // BindResponse ::= [APPLICATION 1] SEQUENCE { ... (Value)
+        // The first Tag will be the LDAPResult Tag (0x0A). So we have to 
switch the grammar.
+        super.transitions[StatesEnum.BIND_RESPONSE_VALUE][0x61] = new 
GrammarTransition(
+                StatesEnum.BIND_RESPONSE_VALUE, 
StatesEnum.BIND_RESPONSE_LDAP_RESULT, null );
+
+        // LdapMessage ::= ... BindResponse ...
+        // BindResponse ::= [APPLICATION 1] SEQUENCE { ... (Value)
+        // The first Tag will be the LDAPResult Tag (0x0A). So we have to 
switch the grammar.
+        super.transitions[StatesEnum.BIND_RESPONSE_LDAP_RESULT][0x0A] = new 
GrammarTransition(
+                StatesEnum.BIND_RESPONSE_LDAP_RESULT, 
StatesEnum.LDAP_RESULT_GRAMMAR_SWITCH, null );
+
+        // BindResponse ::= APPLICATION 1] SEQUENCE {
+        //     ...
+        //    serverSaslCreds   [7] OCTET STRING OPTIONAL } (Tag)
+        // It's a server sasl credential if the tag is 0x87
+        // Otherwise, if the tag is 0x80, it's a control
+        
super.transitions[StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_TAG][0x87] =
+            new GrammarTransition( 
StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_TAG,
+                StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_LENGTH, null );
+
+        // It's a control if it's 0x80. We have to quit this grammar.
+        super.transitions[StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_TAG][( 
0x80 & 0x00FF )] =
+            new GrammarTransition( 
StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_TAG,
+                StatesEnum.GRAMMAR_END, null );
+
+        // BindResponse ::= APPLICATION 1] SEQUENCE {
+        //     ...
+        //    serverSaslCreds   [7] OCTET STRING OPTIONAL } (Length)
+        // We have to check the length
+        
super.transitions[StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_LENGTH][0x87] =
+            new GrammarTransition( 
StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_LENGTH,
+                StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_VALUE,
+                new GrammarAction( "Check server sasl credentials length" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+
+                        BindResponsePOJO     bindResponseMessage = ( 
BindResponsePOJO )
+                            
ldapMessageContainer.getLdapMessage().getProtocolOp();
+
+                        TLV                  tlv = 
ldapMessageContainer.getCurrentTLV();
+
+                        checkLength( bindResponseMessage, tlv );
+
+                        // We have to handle the special case of a 0 length 
server sasl credentials
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            bindResponseMessage.setServerSaslCreds( new byte[] 
{} );
+                        }
+
+                        return;
+                    }
+                } );
+
+        // BindResponse ::= APPLICATION 1] SEQUENCE {
+        //     ...
+        //    serverSaslCreds   [7] OCTET STRING OPTIONAL } (Length)
+        //
+        // We have to get the server sasl Credentials and store it in the 
BindResponse POJO.
+        // Two different following states are possible :
+        // - a Controls tag (0x80)
+        // - nothing at all (end of the BindResponse).
+        // We just have to transit to the first case, which will accept or not 
the transition.
+        // This is done by transiting to the GRAMMAR_END state
+        
super.transitions[StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_VALUE][0x87] =
+            new GrammarTransition( 
StatesEnum.BIND_RESPONSE_SERVER_SASL_CREDS_VALUE,
+                StatesEnum.GRAMMAR_END,
+                new GrammarAction( "Store server sasl credentials value" )
+                {
+                    public void action( IAsn1Container container ) throws 
DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
+                            container;
+
+                        BindResponsePOJO     bindResponseMessage = ( 
BindResponsePOJO )
+                            
ldapMessageContainer.getLdapMessage().getProtocolOp();
+
+                        // Get the Value and store it in the BindRequest
+                        TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+                        bindResponseMessage.setServerSaslCreds( 
tlv.getValue().getData() );
+                        return;
+                    }
+                } );
+
+    }
+
+    //~ Methods 
------------------------------------------------------------------------------------
+
+    /**
+     * Get the instance of this grammar
+     *
+     * @return An instance on the LdapMessage Grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}

Added: 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapControlGrammar.java
URL: 
http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapControlGrammar.java?view=auto&rev=161400
==============================================================================
--- 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapControlGrammar.java
 (added)
+++ 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapControlGrammar.java
 Thu Apr 14 22:42:23 2005
@@ -0,0 +1,69 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec.grammars;
+
+import org.apache.asn1.ber.grammar.AbstractGrammar;
+import org.apache.asn1.ber.grammar.GrammarTransition;
+import org.apache.asn1.ber.grammar.IGrammar;
+import org.apache.asn1.ber.grammar.StatesEnum;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the LdapMessage. All the actions are declared in this
+ * class. As it is a singleton, these declaration are only done once.
+ * 
+ * If an action is to be added or modified, this is where the work is to be 
done !
+ * 
+ * @author <a href="mailto:[email protected]";>Apache Directory 
Project</a>
+ */
+public class LdapControlGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers 
-----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( 
LdapControlGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. LdapControlGrammar is a singleton */
+    private static IGrammar instance = new LdapControlGrammar();
+
+    /**
+     * Get the instance of this grammar
+     *
+     * @return An instance on the LdapControl Grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+    
+    //~ Constructors 
-------------------------------------------------------------------------------
+    /**
+     * Creates a new LdapControlGrammar object.
+     */
+    private LdapControlGrammar()
+    {
+        name = LdapControlGrammar.class.getName();
+
+        super.transitions = new 
GrammarTransition[StatesEnum.CONTROL_LAST_STATE][256];
+
+    }
+}

Copied: 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java
 (from r160136, 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageGrammar.java)
URL: 
http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java?view=diff&rev=161400&p1=directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageGrammar.java&r1=160136&p2=directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java&r2=161400
==============================================================================
--- 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapMessageGrammar.java
 (original)
+++ 
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java
 Thu Apr 14 22:42:23 2005
@@ -14,7 +14,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.asn1.ldap.codec;
+package org.apache.asn1.ldap.codec.grammars;
 
 import org.apache.asn1.ber.containers.IAsn1Container;
 import org.apache.asn1.ber.grammar.AbstractGrammar;
@@ -24,14 +24,10 @@
 import org.apache.asn1.ber.grammar.StatesEnum;
 import org.apache.asn1.ber.tlv.TLV;
 import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.DecoderException;
+import org.apache.asn1.ldap.codec.LdapMessageContainer;
 import org.apache.asn1.ldap.codec.utils.IntegerDecoder;
-import org.apache.asn1.ldap.pojo.AbstractPOJO;
-import org.apache.asn1.ldap.pojo.BindRequestPOJO;
-import org.apache.asn1.ldap.pojo.BindResponsePOJO;
 import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
-import org.apache.asn1.ldap.pojo.LdapPOJO;
-import org.apache.asn1.ldap.pojo.SimpleAuthenticationPOJO;
-import org.apache.asn1.util.MutableString;
 import org.apache.asn1.util.pools.PoolEnum;
 import org.apache.asn1.util.pools.PoolException;
 
@@ -56,51 +52,37 @@
     /** Logging speed up  */
     private static final boolean DEBUG = log.isDebugEnabled();
 
-    /** The instance of grammar. LdapMessage is a singleton */
+    /** The instance of grammar. LdapMessageGrammar is a singleton */
     private static IGrammar instance = new LdapMessageGrammar();
-    
-    static
-    {
-        getInstance().setName("LdapMessageGrammar");
-    }
 
-    //~ Constructors 
-------------------------------------------------------------------------------
     /**
-     * DOCUMENT ME!
+     * Get the instance of this grammar
      *
-     * @return DOCUMENT ME!
+     * @return An instance on the LdapMessage Grammar
      */
     public static IGrammar getInstance()
     {
         return instance;
     }
-
-    private void checkLength(LdapPOJO ldapPOJO, TLV tlv) throws 
DecoderException
-       {
-           // Create a new expected Length
-           int expectedLength = tlv.getLength().getLength();
-           
-           int tlvLength = tlv.getSize();
-       
-           // An exception will be thrown if the current length exceed the 
expected length
-               ((AbstractPOJO)ldapPOJO).addLength(expectedLength + tlvLength);
-       }
-
+    
+    //~ Constructors 
-------------------------------------------------------------------------------
     /**
      * Creates a new LdapMessageGrammar object.
      */
     private LdapMessageGrammar()
     {
 
-        // We have 17 differents states, so 16 transitions between states.
-        super.transitions = new 
GrammarTransition[StatesEnum.LAST_LDAP_STATE][256];
+        name = LdapMessageGrammar.class.getName();
+
+        // We have 9 differents states, so 8 transitions between states.
+        super.transitions = new 
GrammarTransition[StatesEnum.LAST_LDAP_MESSAGE_STATE][256];
 
         
//============================================================================================
         // LdapMessage 
         
//============================================================================================
         // LDAPMessage --> SEQUENCE { ... (Tag)
         // We have a LDAPMessage, and the tag must be 0x30
-        super.transitions[StatesEnum.LDAP_MESSAGE_TAG][0x30] = new 
GrammarTransition( "LdapMessage Tag",
+        super.transitions[StatesEnum.LDAP_MESSAGE_TAG][0x30] = new 
GrammarTransition( StatesEnum.LDAP_MESSAGE_TAG,
                 StatesEnum.LDAP_MESSAGE_LENGTH, new GrammarAction( 
"LdapMessage Tag" )
                 {
                     public void action( IAsn1Container container ) throws 
DecoderException
@@ -128,7 +110,7 @@
 
         // LDAPMessage --> SEQUENCE { ... (Length)
         // Ok, get the LdapMessage length
-        super.transitions[StatesEnum.LDAP_MESSAGE_LENGTH][0x30] = new 
GrammarTransition( "LdapMessage Length",
+        super.transitions[StatesEnum.LDAP_MESSAGE_LENGTH][0x30] = new 
GrammarTransition( StatesEnum.LDAP_MESSAGE_LENGTH,
                 StatesEnum.LDAP_MESSAGE_VALUE, new GrammarAction( "LdapMessage 
Length" )
                 {
                     public void action( IAsn1Container container ) throws 
DecoderException
@@ -145,24 +127,25 @@
                 } );
         
         // LDAPMessage --> SEQUENCE { ... (Value)
-        // Nothing to do, it's a constructed TLV
-        super.transitions[StatesEnum.LDAP_MESSAGE_VALUE][0x30] = new 
GrammarTransition( "LdapMessage Value", StatesEnum.LDAP_MESSAGE_ID_TAG, null);
+        // Nothing to do, it's a constructed TLV. It's just a phantom 
transition ...
+        super.transitions[StatesEnum.LDAP_MESSAGE_VALUE][0x30] = new 
GrammarTransition( StatesEnum.LDAP_MESSAGE_VALUE, 
StatesEnum.LDAP_MESSAGE_ID_TAG, null);
 
-        
//============================================================================================
+        
//--------------------------------------------------------------------------------------------
         // LdapMessage Message ID 
-        
//============================================================================================
+        
//--------------------------------------------------------------------------------------------
         // LDAPMessage --> ... MessageId ...(Tag)
         // The tag must be 0x02. Nothing special to do.
-        super.transitions[StatesEnum.LDAP_MESSAGE_ID_TAG][0x02] = new 
GrammarTransition( "MessageId Tag", StatesEnum.LDAP_MESSAGE_ID_LENGTH, null);
+        super.transitions[StatesEnum.LDAP_MESSAGE_ID_TAG][0x02] = new 
GrammarTransition( StatesEnum.LDAP_MESSAGE_ID_TAG, 
StatesEnum.LDAP_MESSAGE_ID_LENGTH, null);
 
         // LDAPMessage --> ... MessageId ...(Length)
         // Checks the length
-        super.transitions[StatesEnum.LDAP_MESSAGE_ID_LENGTH][0x02] = new 
GrammarTransition( "MessageId Length", StatesEnum.LDAP_MESSAGE_ID_VALUE, 
+        super.transitions[StatesEnum.LDAP_MESSAGE_ID_LENGTH][0x02] = new 
GrammarTransition( StatesEnum.LDAP_MESSAGE_ID_LENGTH, 
StatesEnum.LDAP_MESSAGE_ID_VALUE, 
                 new GrammarAction( "Check MessageId Length " )
                 {
                     public void action( IAsn1Container container ) throws 
DecoderException
                     {
-                       
checkLength(((LdapMessageContainer)container).getLdapMessage(), 
((LdapMessageContainer)container).getCurrentTLV());
+                        LdapMessageContainer ldapMessageContainer = 
((LdapMessageContainer)container);
+                       checkLength(ldapMessageContainer.getLdapMessage(), 
ldapMessageContainer.getCurrentTLV());
 
                         return;
                     }
@@ -170,7 +153,8 @@
         
         // LDAPMessage --> ... MessageId ...(Value)
         // Checks that MessageId is in [0 .. 2147483647] and store the value 
in the LdapMessage POJO
-        super.transitions[StatesEnum.LDAP_MESSAGE_ID_VALUE][0x02] = new 
GrammarTransition( "MessageId Value", StatesEnum.PROTOCOL_OP_TAG,
+        // (2147483647 = Integer.MAX_VALUE)
+        super.transitions[StatesEnum.LDAP_MESSAGE_ID_VALUE][0x02] = new 
GrammarTransition( StatesEnum.LDAP_MESSAGE_ID_VALUE, StatesEnum.PROTOCOL_OP_TAG,
                 new GrammarAction( "Store MessageId" )
                 {
                     public void action( IAsn1Container container ) throws 
DecoderException
@@ -185,9 +169,9 @@
 
                         Value value     = tlv.getValue();
 
-                        int   messageId = IntegerDecoder.parse( value , 0, 
2147483647);
+                        int   messageId = IntegerDecoder.parse( value , 0, 
Integer.MAX_VALUE);
 
-                        if ( ( messageId < 0 ) || ( messageId > 2147483647 ) )
+                        if ( ( messageId < 0 ) || ( messageId > 
Integer.MAX_VALUE ) )
                         {
                             throw new DecoderException(
                                 "The message ID must be between (0 .. 2 147 
483 647)" );
@@ -201,304 +185,25 @@
                     }
                 } );
 
-        
//============================================================================================
-        // LdapResult 
-        
//============================================================================================
-        // LDAPResult --> SEQUENCE { 
-        //    resultCode ENUMERATED { ... (Tag)
-        // We have a LDAPResult Enumerated, the tag must be 0x0A
-        // Nothing to do
-        super.transitions[StatesEnum.LDAP_RESULT_CODE_TAG][0x0A] = new 
GrammarTransition( "LdapResult resultCode Tag",
-                StatesEnum.LDAP_RESULT_CODE_LENGTH, null);
-
-        // LDAPResult --> SEQUENCE { 
-        //    resultCode ENUMERATED { ... (Length)
-        // The length must be 1 (as the result code is between 0 and 90)
-        super.transitions[StatesEnum.LDAP_RESULT_CODE_LENGTH][0x0A] = new 
GrammarTransition( "LdapResult resultCode Length",
-                StatesEnum.LDAP_RESULT_CODE_VALUE, new GrammarAction( 
"LdapResult resultCode Length" )
-                {
-                    public void action( IAsn1Container container ) throws 
DecoderException
-                    {
-                       // We have to check that the length is 1
-                        TLV tlv = 
((LdapMessageContainer)container).getCurrentTLV();
-                        
-                           if ( tlv.getLength().getLength() != 1 )
-                           {
-                               throw new DecoderException("The LdapResult 
resultCode must be 1 byte length, got " + tlv.getLength().getLength());
-                           }
-                           
-                       
checkLength(((LdapMessageContainer)container).getLdapMessage(), tlv);
-
-                       return;
-                    }
-                } );
-        
-        // LDAPResult --> SEQUENCE { 
-        //    resultCode ENUMERATED { ... (Length)
-        // The value must be in {[0-8], [10-21], [32-35], 36, [48-54], 
[64-69], 71, 80}
-        super.transitions[StatesEnum.LDAP_RESULT_CODE_VALUE][0x0A] = new 
GrammarTransition( "LdapMessage Value", StatesEnum.LDAP_RESULT_MATCHED_DN_TAG, 
null);
-
-        
//============================================================================================
-        // protocolOp : Bind Request 
-        
//============================================================================================
-        // If the Tag is 0x60, then it's a BindRequest. Nothing to do while 
the length is not verified.
+        
//********************************************************************************************
+        // If the Tag is 0x60, then it's a BindRequest. Nothing to do while 
the length is not checked.
+        // If the Tag is 0x61, then it's a BindResponse. 
+        
//********************************************************************************************
+        
+        
//--------------------------------------------------------------------------------------------
+        // BindRequest Message.
+        
//--------------------------------------------------------------------------------------------
         // LdapMessage ::= ... BindRequest ...
         // BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Tag)
-        super.transitions[StatesEnum.PROTOCOL_OP_TAG][0x60] = new 
GrammarTransition( "BindRequest Tag", StatesEnum.PROTOCOL_OP_LENGTH, null );
-
-        // We have to allocate a BindRequestPOJO
-        // LdapMessage ::= ... BindRequest ...
-        // BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Length)
-        super.transitions[StatesEnum.PROTOCOL_OP_LENGTH][0x60] = new 
GrammarTransition( "BindRequest Length", StatesEnum.PROTOCOL_OP_VALUE, 
-                new GrammarAction( "Init BindRequest" )
-                {
-                    public void action( IAsn1Container container ) throws 
DecoderException
-                    {
-
-                       LdapMessageContainer ldapMessageContainer = 
(LdapMessageContainer)container;
-                       LdapMessagePOJO ldapMessage = 
ldapMessageContainer.getLdapMessage();
-
-                       
checkLength(((LdapMessageContainer)container).getLdapMessage(), 
((LdapMessageContainer)container).getCurrentTLV());
-                       
-                       try 
-                                               {
-                               // Now, we can allocate the BindRequest POJO
-                               LdapPOJO bindRequest = 
(LdapPOJO)ldapMessageContainer.getPoolManager().allocate(PoolEnum.BIND_REQUEST_POJO_POOL);
-                               
-                               // As this is a new Constructed object, we have 
to init its length
-                               TLV   tlv       = 
ldapMessageContainer.getCurrentTLV();
-                               int expectedLength = 
tlv.getLength().getLength();
-                               
((BindRequestPOJO)bindRequest).setExpectedLength(expectedLength);
-                               
((BindRequestPOJO)bindRequest).setCurrentLength(0);
-
-                                                       // And we associate it 
to the ldapMessage POJO
-                               ldapMessage.setProtocolOP(bindRequest);
-                               
-                       } catch (PoolException pe) 
-                                               {
-                               throw new DecoderException(
-                                    "Cannot allocate a BindRequest Pojo : " + 
pe.getMessage() );
-                       }
-                    }
-                });
-
-        // LdapMessage ::= ... BindRequest ...
-        // BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Value)
-        // Nothing to do, the Value is empty, this is a constructed TLV
-        super.transitions[StatesEnum.PROTOCOL_OP_VALUE][0x60] = new 
GrammarTransition( "BindRequest Value", StatesEnum.BIND_REQUEST_VERSION_TAG, 
null);
-
-        // BindRequest ::= ... version INTEGER (1 .. 127 ), ... (Tag)
-        // Nothing to do.
-        super.transitions[StatesEnum.BIND_REQUEST_VERSION_TAG][0x02] = new 
GrammarTransition( "Bind version Tag", StatesEnum.BIND_REQUEST_VERSION_LENGTH, 
null);
-        
-        // BindRequest ::= ... version INTEGER (1 .. 127 ), ... (Length)
-        // Checks the length
-        super.transitions[StatesEnum.BIND_REQUEST_VERSION_LENGTH][0x02] = new 
GrammarTransition( "Bind version Length", StatesEnum.BIND_REQUEST_VERSION_VALUE,
-                new GrammarAction( "Store version" )
-                {
-                    public void action( IAsn1Container container ) throws 
DecoderException
-                    {
-
-                       
checkLength(((LdapMessageContainer)container).getLdapMessage().getProtocolOp(), 
((LdapMessageContainer)container).getCurrentTLV());
-                        return;
-                    }
-                } );
-
-        // BindRequest ::= ... version INTEGER (1 .. 127 ), ... (value)
-        // Checks that the Version is in [1, 127]
-        super.transitions[StatesEnum.BIND_REQUEST_VERSION_VALUE][0x02] = new 
GrammarTransition( "Bind version Length", StatesEnum.BIND_REQUEST_NAME_TAG,
-                new GrammarAction( "Store version" )
-                {
-                    public void action( IAsn1Container container ) throws 
DecoderException
-                    {
-
-                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )
-                            container;
-                        BindRequestPOJO      bindRequestMessage   =
-                               
(BindRequestPOJO)ldapMessageContainer.getLdapMessage().getProtocolOp();
-
-                        // The current TLV should be a integer between 1 and 
127
-                        // We get it and store it in Version
-                        TLV   tlv     = ldapMessageContainer.getCurrentTLV();
-
-                        Value value   = tlv.getValue();
-
-                        int   version = IntegerDecoder.parse( value, 1, 127 );
-
-                        bindRequestMessage.setVersion( version );
-
-                        return;
-                    }
-                } );
-
-        // BindRequest ::= ... name LDAPDN, ... (Tag)
-        // Nothing to do. The tag is supposed to be 0x04
-        super.transitions[StatesEnum.BIND_REQUEST_NAME_TAG][0x04] = new 
GrammarTransition( "bind name tag", StatesEnum.BIND_REQUEST_NAME_LENGTH, null);
-        
-        // BindRequest ::= ... name LDAPDN, ... (Length)
-        // We just check the length.
-        super.transitions[StatesEnum.BIND_REQUEST_NAME_LENGTH][0x04] = new 
GrammarTransition( "bind name length", StatesEnum.BIND_REQUEST_NAME_VALUE,
-                new GrammarAction( "Check Bind Name Length" )
-                {
-                    public void action( IAsn1Container container ) throws 
DecoderException
-                    {
-                       
checkLength(((LdapMessageContainer)container).getLdapMessage().getProtocolOp(), 
((LdapMessageContainer)container).getCurrentTLV());
-                        return;
-                    }
-                } );
-
-        // BindRequest ::= ... name LDAPDN, ... (Value)
-        // We just check the length.
-        super.transitions[StatesEnum.BIND_REQUEST_NAME_VALUE][0x04] = new 
GrammarTransition( "bind name value", 
StatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG,
-                new GrammarAction( "Store Bind Name value" )
-                {
-                    public void action( IAsn1Container container ) throws 
DecoderException
-                    {
-
-                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )container;
-                        
-                           // Get the Value and store it in the BindRequest 
-                           TLV   tlv     = 
ldapMessageContainer.getCurrentTLV();
-                           
-                           MutableString name = null;
-                           
-                           try
-                           {
-                                   name = ( MutableString ) 
ldapMessageContainer.getPoolManager().allocateString(tlv.getValue().getData().length);
-                           } 
-                           catch (PoolException pe)
-                           {
-                               throw new DecoderException(
-                                           "Cannot allocate a MutableString 
for Name : " + pe.getMessage() );
-                           }
-                           
-                        name.setData(tlv.getValue().getData());
-                        
-
-                        BindRequestPOJO      bindRequestMessage   = 
(BindRequestPOJO)ldapMessageContainer.getLdapMessage().getProtocolOp();
-
-                        bindRequestMessage.setName(name);
-                        return;
-                    }
-                } );
-
-        // BindRequest ::= ... authentication AuthenticationChoice }
-        // AuthenticationChoice ::= CHOICE {
-        // The tag might be either 0x80 (SimpleAuthentication) or 0x83 
(SaslAuthentication)
-        // Here, it's 0x80, so a SimpleAuthentication. 
-        // Nothing to do.
-        super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_CHOICE_TAG][( 
0x80 & 0x00FF )] = new GrammarTransition( "Bind Simple Authentication Tag", 
StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_LENGTH, null);
-        
-        // AuthenticationChoice ::= CHOICE {
-        //             simple         [0] OCTET STRING, (Length)
-        
super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_LENGTH][( 0x80 
& 0x00FF )] = new GrammarTransition( "Bind Simple Authentication Length", 
StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE, 
-                       new GrammarAction( "Check simple authentication length" 
) 
-                {
-                    public void action( IAsn1Container container ) throws 
DecoderException
-                    {
-                       
checkLength(((LdapMessageContainer)container).getLdapMessage().getProtocolOp(), 
((LdapMessageContainer)container).getCurrentTLV());
-                        
-                        return;
-                    }
-                } );
-
-        // AuthenticationChoice ::= CHOICE {
-        //             simple         [0] OCTET STRING, (Value)
-        
super.transitions[StatesEnum.BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE][( 0x80 & 
0x00FF )] = new GrammarTransition( "Bind Simple Authentication Value", -1, 
//StatesEnum.CONTROLS_TAG, 
-                new GrammarAction( "Store Bind Simple Authentication value" )
-                {
-                    public void action( IAsn1Container container ) throws 
DecoderException
-                    {
-
-                        LdapMessageContainer ldapMessageContainer = ( 
LdapMessageContainer )container;
-                        
-                           // Get the Value and store it in the BindRequest 
-                           TLV   tlv     = 
ldapMessageContainer.getCurrentTLV();
-                           
-                           MutableString simple = null;
-                           
-                           try
-                           {
-                                   simple = ( MutableString ) 
ldapMessageContainer.getPoolManager().allocateString(tlv.getValue().getData().length);
-                           } 
-                           catch (PoolException pe)
-                           {
-                               throw new DecoderException(
-                                           "Cannot allocate a MutableString 
for simple : " + pe.getMessage() );
-                           }
-                           
-                        simple.setData(tlv.getValue().getData());
-
-                        BindRequestPOJO      bindRequestMessage   = 
(BindRequestPOJO)ldapMessageContainer.getLdapMessage().getProtocolOp();
-
-                        try 
-                                               {
-                               SimpleAuthenticationPOJO authentication = ( 
SimpleAuthenticationPOJO )
-                                                               
ldapMessageContainer.getPoolManager().allocate(
-                                                                               
PoolEnum.SIMPLE_AUTH_POJO_POOL );
-                               
-                               authentication.setSimple(simple);
-       
-                               
bindRequestMessage.setAuthentication(authentication);
-                               return;
-                                               } 
-                        catch (PoolException pe) 
-                                               {
-                               throw new DecoderException(
-                                    "Cannot allocate a SimpleAuthentication 
Pojo : " + pe.getMessage() );
-                                               }
-                    }
-                } );
+        // Nothing to do while the length is not checked.
+        super.transitions[StatesEnum.PROTOCOL_OP_TAG][0x60] = new 
GrammarTransition( StatesEnum.PROTOCOL_OP_TAG, 
StatesEnum.BIND_REQUEST_GRAMMAR_SWITCH, null );
 
-        
//============================================================================================
-        // protocolOp : Bind Response 
-        
//============================================================================================
-        // If the Tag is 0x61, then it's a BindResponse. Nothing to do while 
the length is not verified.
+        
//--------------------------------------------------------------------------------------------
+        // BindResponse Message.
+        
//--------------------------------------------------------------------------------------------
         // LdapMessage ::= ... BindResponse ...
         // BindResponse ::= [APPLICATION 1] SEQUENCE { ... (Tag)
-        super.transitions[StatesEnum.PROTOCOL_OP_TAG][0x61] = new 
GrammarTransition( "BindResponse Tag", StatesEnum.PROTOCOL_OP_LENGTH, null );
-
-        // We have to allocate a BindResponsePOJO
-        // LdapMessage ::= ... BindResponse ...
-        // BindResponse ::= [APPLICATION 1] SEQUENCE { ... (Length)
-        super.transitions[StatesEnum.PROTOCOL_OP_LENGTH][0x61] = new 
GrammarTransition( "BindResponse Length", StatesEnum.PROTOCOL_OP_VALUE, 
-                new GrammarAction( "Init BindReponse" )
-                {
-                    public void action( IAsn1Container container ) throws 
DecoderException
-                    {
-
-                       LdapMessageContainer ldapMessageContainer = 
(LdapMessageContainer)container;
-                       LdapMessagePOJO ldapMessage = 
ldapMessageContainer.getLdapMessage();
-
-                       
checkLength(((LdapMessageContainer)container).getLdapMessage(), 
((LdapMessageContainer)container).getCurrentTLV());
-                       
-                       try 
-                                               {
-                               // Now, we can allocate the BindResponse POJO
-                               LdapPOJO bindResponse= 
(LdapPOJO)ldapMessageContainer.getPoolManager().allocate(PoolEnum.BIND_RESPONSE_POJO_POOL);
-                               
-                               // As this is a new Constructed object, we have 
to init its length
-                               TLV   tlv       = 
ldapMessageContainer.getCurrentTLV();
-                               int expectedLength = 
tlv.getLength().getLength();
-                               
((BindResponsePOJO)bindResponse).setExpectedLength(expectedLength);
-                               
((BindResponsePOJO)bindResponse).setCurrentLength(0);
-
-                                                       // And we associate it 
to the ldapMessage POJO
-                               ldapMessage.setProtocolOP(bindResponse);
-                               
-                       } catch (PoolException pe) 
-                                               {
-                               throw new DecoderException(
-                                    "Cannot allocate a BindResponse Pojo : " + 
pe.getMessage() );
-                       }
-                    }
-                });
-
-        // LdapMessage ::= ... BindResponse ...
-        // BindResponse ::= [APPLICATION 1] SEQUENCE { ... (Value)
-        // Ok, we have a LdapResult to parse. As it can be used in many 
different
-        // rules, we have to decode it using another grammar 
(LdapResultGrammar).
-        super.transitions[StatesEnum.PROTOCOL_OP_VALUE][0x61] = new 
GrammarTransition( "BindResponse Value", StatesEnum.LDAP_RESULT_GRAMMAR_SWITCH, 
null);
-
+        // We have to switch to the BindResponse grammar
+        super.transitions[StatesEnum.PROTOCOL_OP_TAG][0x61] = new 
GrammarTransition( StatesEnum.PROTOCOL_OP_TAG, 
StatesEnum.BIND_RESPONSE_GRAMMAR_SWITCH, null);
     }
 }


Reply via email to