You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/04/05 09:21:21 UTC

svn commit: r160135 - in directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar: AbstractGrammar.java GrammarTransition.java IGrammar.java StatesEnum.java

Author: elecharny
Date: Tue Apr  5 00:21:19 2005
New Revision: 160135

URL: http://svn.apache.org/viewcvs?view=rev&rev=160135
Log:
Added a Grammar Switch capability to be able to decode sub-grammars like LdapResult

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/AbstractGrammar.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/GrammarTransition.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IGrammar.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/StatesEnum.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/AbstractGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/AbstractGrammar.java?view=diff&r1=160134&r2=160135
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/AbstractGrammar.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/AbstractGrammar.java Tue Apr  5 00:21:19 2005
@@ -45,10 +45,29 @@
     /** Table of transitions. It's a two dimension array, the first dimension
      * indice the states, the second dimension indices the Tag value, so it is 256 wide. */
     protected GrammarTransition[][] transitions;
-
+    
+    /** The grammar name */
+    protected String name;
+    
     //~ Methods ------------------------------------------------------------------------------------
 
     /**
+     * Return the grammar's name
+     */
+    public String getName()
+    {
+        return name;
+    }
+    
+    /**
+     * Set the grammar's name
+     */
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+    
+    /**
      * The main function. This is where an action is executed. If the 
      * action is null, nothing is done.
      *
@@ -59,6 +78,7 @@
     public void executeAction( IAsn1Container container ) throws DecoderException
     {
         int currentState = container.getTransition();
+        IGrammar currentGrammar = container.getGrammar();
 
         if ( currentState == -1 )
         {
@@ -67,13 +87,19 @@
 
         Tag               tag        = container.getCurrentTLV().getTag();
         byte              tagByte    = tag.getTagByte();
-
+        
+        if ((currentState & StatesEnum.GRAMMAR_SWITCH_MASK) != 0)
+        {
+            container.switchGrammar(currentState & StatesEnum.GRAMMAR_SWITCH_MASK);
+            currentState = StatesEnum.INIT_GRAMMAR_STATE;
+        }
+        
         GrammarTransition transition = transitions[currentState][tagByte & 0x00FF];
 
         if ( transition == null )
         {
             throw new DecoderException(
-                "Bad transition from state " + StatesEnum.getState( currentState ) + ", tag " +
+                "Bad transition from state " + StatesEnum.getState( container.getCurrentGrammar(), currentState ) + ", tag " +
                 StringUtils.dumpByte( tag.getTagByte() ) );
         }
 

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/GrammarTransition.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/GrammarTransition.java?view=diff&r1=160134&r2=160135
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/GrammarTransition.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/GrammarTransition.java Tue Apr  5 00:21:19 2005
@@ -91,15 +91,16 @@
     }
 
     /**
+     * @param grammar The grammar which state we want a String from
      * @return A representation of the transition as a string.
      */
-    public String toString()
+    public String toString(int grammar)
     {
 
         StringBuffer sb = new StringBuffer();
 
         sb.append( "Transition <" ).append( name ).append( ", " )
-          .append( StatesEnum.getState( nextState ) ).append( ", " )
+          .append( StatesEnum.getState( grammar, nextState ) ).append( ", " )
           .append( ( ( action == null ) ? "no action" : action.toString() ) ).append( ">" );
 
         return sb.toString();

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IGrammar.java?view=diff&r1=160134&r2=160135
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IGrammar.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/IGrammar.java Tue Apr  5 00:21:19 2005
@@ -38,4 +38,14 @@
      * @throws DecoderException Thrown when an unrecoverable error occurs.
      */
     void executeAction( IAsn1Container asn1Container ) throws DecoderException;
+    
+    /**
+     * Return the grammar's name
+     */
+    String getName();
+
+    /**
+     * Set the grammar's name
+     */
+    void setName(String name);
 }

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/StatesEnum.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/StatesEnum.java?view=diff&r1=160134&r2=160135
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/StatesEnum.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/grammar/StatesEnum.java Tue Apr  5 00:21:19 2005
@@ -26,6 +26,9 @@
 {
     //~ Static fields/initializers -----------------------------------------------------------------
 
+    /** The initial state of every grammar */
+    public static int INIT_GRAMMAR_STATE = 0;
+    
     /** Initiate the counter to 0 */
     private static int INIT_STATE = 0;
 
@@ -59,118 +62,70 @@
     /** protocolOp CHOICE Value */
     public static int PROTOCOL_OP_VALUE = INIT_STATE++;
 
-    // LdapResult =============================================================
-    // LdapResult Code --------------------------------------------------------
-    /** LdapResult Code Tag */
-    public static int LDAP_RESULT_CODE_TAG = INIT_STATE++;
-
-    /** LdapResult Code Length */
-    public static int LDAP_RESULT_CODE_LENGTH = INIT_STATE++;
-
-    /** LdapResult Code Value */
-    public static int LDAP_RESULT_CODE_VALUE = INIT_STATE++;
-
-    // LdapResult Matched DN --------------------------------------------------
-    /** LdapResult Matched DN Tag */
-    public static int LDAP_RESULT_MATCHED_DN_TAG = INIT_STATE++;
-
-    /** LdapResult Matched DN Length */
-    public static int LDAP_RESULT_MATCHED_DN_LENGTH = INIT_STATE++;
-
-    /** LdapResult Matched DN Value */
-    public static int LDAP_RESULT_MATCHED_DN_VALUE = INIT_STATE++;
-
-    // LdapResult error message -----------------------------------------------
-    /** LdapResult error message Tag */
-    public static int LDAP_RESULT_ERROR_MESSAGE_TAG = INIT_STATE++;
-
-    /** LdapResult error message Length */
-    public static int LDAP_RESULT_ERROR_MESSAGE_LENGTH = INIT_STATE++;
-
-    /** LdapResult error message Value */
-    public static int LDAP_RESULT_ERROR_MESSAGE_VALUE = INIT_STATE++;
-
-    // LdapResult referral sequence -------------------------------------------
-    /** LdapResult referral sequence Tag */
-    public static int LDAP_RESULT_REFERRAL_SEQUENCE_TAG = INIT_STATE++;
-
-    /** LdapResult referral sequence Length */
-    public static int LDAP_RESULT_REFERRAL_SEQUENCE_LENGTH = INIT_STATE++;
-
-    // LdapResult referrale ---------------------------------------------------
-    /** LdapResult referral Tag */
-    public static int LDAP_RESULT_REFERRAL_TAG = INIT_STATE++;
-
-    /** LdapResult referral Length */
-    public static int LDAP_RESULT_REFERRAL_LENGTH = INIT_STATE++;
-
-    /** LdapResult referral Value */
-    public static int LDAP_RESULT_REFERRAL_VALUE = INIT_STATE++;
-
     // BindRequest ============================================================
     // Version ----------------------------------------------------------------
     /**  Version Tag */
-    public static int BIND_VERSION_TAG = INIT_STATE++;
+    public static int BIND_REQUEST_VERSION_TAG = INIT_STATE++;
 
     /** Version Length */
-    public static int BIND_VERSION_LENGTH = INIT_STATE++;
+    public static int BIND_REQUEST_VERSION_LENGTH = INIT_STATE++;
 
     /** Version Length */
-    public static int BIND_VERSION_VALUE = INIT_STATE++;
+    public static int BIND_REQUEST_VERSION_VALUE = INIT_STATE++;
 
     // Name -------------------------------------------------------------------
     /** Name Tag */
-    public static int BIND_NAME_TAG = INIT_STATE++;
+    public static int BIND_REQUEST_NAME_TAG = INIT_STATE++;
 
     /** Name Length */
-    public static int BIND_NAME_LENGTH = INIT_STATE++;
+    public static int BIND_REQUEST_NAME_LENGTH = INIT_STATE++;
 
     /** Name Value */
-    public static int BIND_NAME_VALUE = INIT_STATE++;
+    public static int BIND_REQUEST_NAME_VALUE = INIT_STATE++;
 
     // Authentication choice --------------------------------------------------
     /** Authentication choice Tag */
-    public static int BIND_AUTHENTICATION_CHOICE_TAG = INIT_STATE++;
+    public static int BIND_REQUEST_AUTHENTICATION_CHOICE_TAG = INIT_STATE++;
 
     // Authentication simple --------------------------------------------------
     /** Authentication Simple Tag */
-    //public static int BIND_AUTHENTICATION_SIMPLE_TAG = INIT_STATE++;
+    //public static int BIND_REQUEST_AUTHENTICATION_SIMPLE_TAG = INIT_STATE++;
 
     /** Authentication Simple Length */
-    public static int BIND_AUTHENTICATION_SIMPLE_LENGTH = INIT_STATE++;
+    public static int BIND_REQUEST_AUTHENTICATION_SIMPLE_LENGTH = INIT_STATE++;
 
     /** Authentication Simple Value */
-    public static int BIND_AUTHENTICATION_SIMPLE_VALUE = INIT_STATE++;
+    public static int BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE = INIT_STATE++;
 
     // Authentication sasl ----------------------------------------------------
     /** Authentication Sasl Tag */
     //public static int BIND_AUTHENTICATION_SASL_TAG = INIT_STATE++;
 
     /** Authentication Sasl Length */
-    public static int BIND_AUTHENTICATION_SASL_LENGTH = INIT_STATE++;
+    public static int BIND_REQUEST_AUTHENTICATION_SASL_LENGTH = INIT_STATE++;
 
     /** Authentication Sasl Value */
-    public static int BIND_AUTHENTICATION_SASL_VALUE = INIT_STATE++;
+    public static int BIND_REQUEST_AUTHENTICATION_SASL_VALUE = INIT_STATE++;
 
     // Authentication sasl mechanism ------------------------------------------
     /** Authentication Sasl mechanism Tag */
-    public static int BIND_AUTHENTICATION_MECHANISM_TAG = INIT_STATE++;
+    public static int BIND_REQUEST_AUTHENTICATION_MECHANISM_TAG = INIT_STATE++;
 
     /** Authentication sasl mechanism Length */
-    public static int BIND_AUTHENTICATION_MECHANISM_LENGTH = INIT_STATE++;
+    public static int BIND_REQUEST_AUTHENTICATION_MECHANISM_LENGTH = INIT_STATE++;
 
     /** Authentication sasl mechanism Value */
-    public static int BIND_AUTHENTICATION_MECHANISM_VALUE = INIT_STATE++;
+    public static int BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE = INIT_STATE++;
 
     // Authentication sasl mechanism ------------------------------------------
     /** Authentication Sasl credentials Tag */
-    public static int BIND_AUTHENTICATION_CREDENTIALS_TAG = INIT_STATE++;
+    public static int BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG = INIT_STATE++;
 
     /** Authentication sasl credentials Length */
-    public static int BIND_AUTHENTICATION_CREDENTIALS_LENGTH = INIT_STATE++;
+    public static int BIND_REQUEST_AUTHENTICATION_CREDENTIALS_LENGTH = INIT_STATE++;
 
     /** Authentication sasl credentials Value */
-    public static int BIND_AUTHENTICATION_CREDENTIALS_VALUE = INIT_STATE++;
+    public static int BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE = INIT_STATE++;
 
     // Controls ===============================================================
     /** Controls Tag */
@@ -227,6 +182,15 @@
     /**  Response Tag */
     public static int BIND_RESPONSE_TAG = INIT_STATE++;
 
+    /**  Response Length */
+    public static int BIND_RESPONSE_LENGTH = INIT_STATE++;
+
+    /**  Response Value */
+    public static int BIND_RESPONSE_VALUE = INIT_STATE++;
+
+    /**  Response message ID Tag */
+    public static int BIND_RESPONSE_MESSAGE_ID_TAG = INIT_STATE++;
+
     /** serverSaslCreds Tag */
     public static int SERVER_SASL_CREDS_TAG = INIT_STATE++;
 
@@ -236,11 +200,78 @@
     /** serverSaslCreds Length */
     public static int SERVER_SASL_CREDS_VALUE = INIT_STATE++;
 
+    /** Last state */
+    public static int LAST_LDAP_STATE = INIT_STATE; 
+    
+    
+    // LdapResult grammar states ==============================================
+    private static int LDAP_RESULT_STATE = 0;
+    
+    // LdapResult Code --------------------------------------------------------
+    /** LdapResult Code Tag */
+    public static int LDAP_RESULT_CODE_TAG = LDAP_RESULT_STATE++;
+
+    /** LdapResult Code Length */
+    public static int LDAP_RESULT_CODE_LENGTH = LDAP_RESULT_STATE++;
+
+    /** LdapResult Code Value */
+    public static int LDAP_RESULT_CODE_VALUE = LDAP_RESULT_STATE++;
+
+    // LdapResult Matched DN --------------------------------------------------
+    /** LdapResult Matched DN Tag */
+    public static int LDAP_RESULT_MATCHED_DN_TAG = LDAP_RESULT_STATE++;
+
+    /** LdapResult Matched DN Length */
+    public static int LDAP_RESULT_MATCHED_DN_LENGTH = LDAP_RESULT_STATE++;
+
+    /** LdapResult Matched DN Value */
+    public static int LDAP_RESULT_MATCHED_DN_VALUE = LDAP_RESULT_STATE++;
+
+    // LdapResult error message -----------------------------------------------
+    /** LdapResult error message Tag */
+    public static int LDAP_RESULT_ERROR_MESSAGE_TAG = LDAP_RESULT_STATE++;
+
+    /** LdapResult error message Length */
+    public static int LDAP_RESULT_ERROR_MESSAGE_LENGTH = LDAP_RESULT_STATE++;
+
+    /** LdapResult error message Value */
+    public static int LDAP_RESULT_ERROR_MESSAGE_VALUE = LDAP_RESULT_STATE++;
+
+    // LdapResult referral sequence -------------------------------------------
+    /** LdapResult referral sequence Tag */
+    public static int LDAP_RESULT_REFERRAL_SEQUENCE_TAG = LDAP_RESULT_STATE++;
+
+    /** LdapResult referral sequence Length */
+    public static int LDAP_RESULT_REFERRAL_SEQUENCE_LENGTH = LDAP_RESULT_STATE++;
+
+    // LdapResult referrale ---------------------------------------------------
+    /** LdapResult referral Tag */
+    public static int LDAP_RESULT_REFERRAL_TAG = LDAP_RESULT_STATE++;
+
+    /** LdapResult referral Length */
+    public static int LDAP_RESULT_REFERRAL_LENGTH = LDAP_RESULT_STATE++;
+
+    /** LdapResult referral Value */
+    public static int LDAP_RESULT_REFERRAL_VALUE = LDAP_RESULT_STATE++;
+
     /** The last state */
-    public static int LAST_STATE = INIT_STATE;
+    public static int LDAP_RESULT_LAST_STATE = LDAP_RESULT_STATE;
+    
+    
+    
+    /** The mask to filter between states transition and grammar switch */
+    public final static int GRAMMAR_SWITCH_MASK = 0x0F00;
+    
+    /** Ldap Grammar */
+    public final static int LDAP_GRAMMAR_SWITCH = 0x0100;
+    public final static int LDAP_GRAMMAR = 0;
+
+    /** LdapResult Grammar */
+    public final static int LDAP_RESULT_GRAMMAR_SWITCH = 0x0200;
+    public final static int LDAP_RESULT_GRAMMAR = 1;
 
     /** A string representation of all the states */
-    private static String[] StateTring =
+    private static String[] LdapString =
         new String[]
         {
     		"LDAP_MESSAGE_TAG",
@@ -266,25 +297,25 @@
 			"LDAP_RESULT_REFERRAL_TAG",
 			"LDAP_RESULT_REFERRAL_LENGTH",
 			"LDAP_RESULT_REFERRAL_VALUE",
-			"BIND_VERSION_TAG",
-			"BIND_VERSION_LENGTH",
-			"BIND_VERSION_VALUE",
-			"BIND_NAME_TAG",
-			"BIND_NAME_LENGTH",
-			"BIND_NAME_VALUE",
-			"BIND_AUTHENTICATION_CHOICE_TAG",
+			"BIND_REQUEST_VERSION_TAG",
+			"BIND_REQUEST_VERSION_LENGTH",
+			"BIND_REQUEST_VERSION_VALUE",
+			"BIND_REQUEST_NAME_TAG",
+			"BIND_REQUEST_NAME_LENGTH",
+			"BIND_REQUEST_NAME_VALUE",
+			"BIND_REQUEST_AUTHENTICATION_CHOICE_TAG",
 			//public static int BIND_AUTHENTICATION_SIMPLE_TAG",
-			"BIND_AUTHENTICATION_SIMPLE_LENGTH",
-			"BIND_AUTHENTICATION_SIMPLE_VALUE",
+			"BIND_REQUEST_AUTHENTICATION_SIMPLE_LENGTH",
+			"BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE",
 			//public static int BIND_AUTHENTICATION_SASL_TAG",
-			"BIND_AUTHENTICATION_SASL_LENGTH",
-			"BIND_AUTHENTICATION_SASL_VALUE",
-			"BIND_AUTHENTICATION_MECHANISM_TAG",
-			"BIND_AUTHENTICATION_MECHANISM_LENGTH",
-			"BIND_AUTHENTICATION_MECHANISM_VALUE",
-			"BIND_AUTHENTICATION_CREDENTIALS_TAG",
-			"BIND_AUTHENTICATION_CREDENTIALS_LENGTH",
-			"BIND_AUTHENTICATION_CREDENTIALS_VALUE",
+			"BIND_REQUEST_AUTHENTICATION_SASL_LENGTH",
+			"BIND_REQUEST_AUTHENTICATION_SASL_VALUE",
+			"BIND_REQUEST_AUTHENTICATION_MECHANISM_TAG",
+			"BIND_REQUEST_AUTHENTICATION_MECHANISM_LENGTH",
+			"BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE",
+			"BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG",
+			"BIND_REQUEST_AUTHENTICATION_CREDENTIALS_LENGTH",
+			"BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE",
 			"CONTROLS_TAG",
 			"CONTROLS_LENGTH",
 			"CONTROLS_VALUE",
@@ -307,6 +338,26 @@
 			"LAST_STATE"
         };
 
+    /** A string representation of all the LdapResult states */
+    private static String[] LdapResultString =
+        new String[]
+        {
+			"LDAP_RESULT_CODE_TAG",
+			"LDAP_RESULT_CODE_LENGTH",
+			"LDAP_RESULT_CODE_VALUE",
+			"LDAP_RESULT_MATCHED_DN_TAG",
+			"LDAP_RESULT_MATCHED_DN_LENGTH",
+			"LDAP_RESULT_MATCHED_DN_VALUE",
+			"LDAP_RESULT_ERROR_MESSAGE_TAG",
+			"LDAP_RESULT_ERROR_MESSAGE_LENGTH",
+			"LDAP_RESULT_ERROR_MESSAGE_VALUE",
+			"LDAP_RESULT_REFERRAL_SEQUENCE_TAG",
+			"LDAP_RESULT_REFERRAL_SEQUENCE_LENGTH",
+			"LDAP_RESULT_REFERRAL_TAG",
+			"LDAP_RESULT_REFERRAL_LENGTH",
+			"LDAP_RESULT_REFERRAL_VALUE",
+			"LAST_STATE"
+        };
     //~ Methods ------------------------------------------------------------------------------------
 
     /**
@@ -315,9 +366,18 @@
      * @param state The state number
      * @return The String representing the state
      */
-    public static String getState( int state )
+    public static String getState( int grammar, int state )
     {
-
-        return ( ( state == -1 ) ? "END_STATE" : StateTring[state] );
+        switch (grammar)
+        {
+            case LDAP_GRAMMAR :
+                return ( ( state == -1 ) ? "END_STATE" : LdapString[state] );
+                
+            case LDAP_RESULT_GRAMMAR :
+                return ( ( state == -1 ) ? "END_STATE" : LdapResultString[state] );
+                
+            default :
+                return "";
+        }
     }
 }