Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 52554 invoked from network); 2 Aug 2005 22:25:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 Aug 2005 22:25:43 -0000 Received: (qmail 29829 invoked by uid 500); 2 Aug 2005 22:25:42 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 29777 invoked by uid 500); 2 Aug 2005 22:25:42 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 29764 invoked by uid 99); 2 Aug 2005 22:25:42 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Aug 2005 15:25:42 -0700 X-ASF-Spam-Status: No, hits=-9.6 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME,UPPERCASE_25_50 X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 02 Aug 2005 15:25:34 -0700 Received: (qmail 52535 invoked by uid 65534); 2 Aug 2005 22:25:41 -0000 Message-ID: <20050802222541.52534.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r227094 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapControlGrammar.java Date: Tue, 02 Aug 2005 22:25:41 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Tue Aug 2 15:25:37 2005 New Revision: 227094 URL: http://svn.apache.org/viewcvs?rev=227094&view=rev Log: Implementation of the control grammar Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapControlGrammar.java Modified: 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?rev=227094&r1=227093&r2=227094&view=diff ============================================================================== --- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapControlGrammar.java (original) +++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapControlGrammar.java Tue Aug 2 15:25:37 2005 @@ -16,9 +16,22 @@ */ package org.apache.asn1.ldap.codec.grammars; +import org.apache.asn1.DecoderException; +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.tlv.TLV; +import org.apache.asn1.ber.tlv.UniversalTag; +import org.apache.asn1.ber.tlv.Value; +import org.apache.asn1.ldap.codec.LdapConstants; +import org.apache.asn1.ldap.codec.LdapMessageContainer; +import org.apache.asn1.ldap.codec.utils.IntegerDecoder; +import org.apache.asn1.ldap.pojo.Control; +import org.apache.asn1.ldap.pojo.LdapMessage; +import org.apache.asn1.primitives.OID; +import org.apache.asn1.primitives.OctetString; import org.apache.log4j.Logger; @@ -65,5 +78,236 @@ super.transitions = new GrammarTransition[LdapStatesEnum.LAST_CONTROL_STATE][256]; + //============================================================================================ + // Controls + //============================================================================================ + // ... + // controls [0] Controls OPTIONAL } (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.CONTROLS_TAG][LdapConstants.CONTROLS_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROLS_TAG, + LdapStatesEnum.CONTROLS_VALUE, null ); + + // ... + // controls [0] Controls OPTIONAL } (Value) + // Initialize the controls pojo + super.transitions[LdapStatesEnum.CONTROLS_VALUE][LdapConstants.CONTROLS_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROLS_VALUE, LdapStatesEnum.CONTROLS_SEQUENCE_TAG, + new GrammarAction( "Init Controls" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + // We can initialize the controls array + ldapMessage.initControl(); + } + } ); + + //============================================================================================ + // Controls sequence + //============================================================================================ + // ... + // Controls ::= SEQUENCE OF Control (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.CONTROLS_SEQUENCE_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROLS_SEQUENCE_TAG, + LdapStatesEnum.CONTROLS_SEQUENCE_VALUE, null ); + + // ... + // Controls ::= SEQUENCE OF Control (Value) + // Nothing to do + super.transitions[LdapStatesEnum.CONTROLS_SEQUENCE_VALUE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROLS_SEQUENCE_VALUE, LdapStatesEnum.CONTROL_TAG, null); + + //============================================================================================ + // Control + //============================================================================================ + // Control ::= SEQUENCE { (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.CONTROL_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_TAG, + LdapStatesEnum.CONTROL_VALUE, null ); + + // Another control when critical and value are empty + super.transitions[LdapStatesEnum.CONTROL_LOOP_OR_CRITICAL_OR_VALUE_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_LOOP_OR_END_TAG, + LdapStatesEnum.CONTROL_VALUE, null ); + + // Another control when value is empty + super.transitions[LdapStatesEnum.CONTROL_LOOP_OR_VALUE_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_LOOP_OR_END_TAG, + LdapStatesEnum.CONTROL_VALUE, null ); + + // Another control after a value + super.transitions[LdapStatesEnum.CONTROL_LOOP_OR_END_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_LOOP_OR_END_TAG, + LdapStatesEnum.CONTROL_VALUE, null ); + + // Control ::= SEQUENCE { (Value) + // Create a new Control object, and store it in the controls array. + super.transitions[LdapStatesEnum.CONTROL_VALUE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_VALUE, LdapStatesEnum.CONTROL_TYPE_TAG, + new GrammarAction( "Add Control" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + // Create a new control + Control control = new Control(); + + // Add it to the ldap message + ldapMessage.addControl( control ); + } + }); + + //============================================================================================ + // ControlType + //============================================================================================ + // Control ::= SEQUENCE { + // controlType LDAPOID, (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.CONTROL_TYPE_TAG][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_TYPE_TAG, + LdapStatesEnum.CONTROL_TYPE_VALUE, null ); + + // Control ::= SEQUENCE { (Value) + // Store the value in the control object created before + super.transitions[LdapStatesEnum.CONTROL_TYPE_VALUE][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_TYPE_VALUE, LdapStatesEnum.CONTROL_LOOP_OR_CRITICAL_OR_VALUE_TAG, + new GrammarAction( "Set Control type" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // Get the current control + Control control = ldapMessage.getCurrentControl(); + + // Store the type + // We have to handle the special case of a 0 length OID + if ( tlv.getLength().getLength() == 0 ) + { + throw new DecoderException( "The name must not be null" ); + } + else + { + control.setControlType( new OID( tlv.getValue().getData() ) ); + } + } + }); + + //============================================================================================ + // Control Criticality + //============================================================================================ + // Control ::= SEQUENCE { + // ... + // criticality BOOLEAN DEFAULT FALSE, (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.CONTROL_LOOP_OR_CRITICAL_OR_VALUE_TAG][UniversalTag.BOOLEAN_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_LOOP_OR_CRITICAL_OR_VALUE_TAG, + LdapStatesEnum.CONTROL_CRITICALITY_VALUE, null ); + + // Control ::= SEQUENCE { (Value) + // ... + // criticality BOOLEAN DEFAULT FALSE, (Value) + // Store the criticality in the control object created before + super.transitions[LdapStatesEnum.CONTROL_CRITICALITY_VALUE][UniversalTag.BOOLEAN_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_CRITICALITY_VALUE, LdapStatesEnum.CONTROL_LOOP_OR_VALUE_TAG, + new GrammarAction( "Set Control criticality" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // Get the current control + Control control = ldapMessage.getCurrentControl(); + + // Store the criticality + // We get the value. If it's a 0, it's a FALSE. If it's + // a FF, it's a TRUE. Any other value should be an error, + // but we could relax this constraint. So if we have something + // which is not 0, it will be interpreted as TRUE, but we + // will generate a warning. + Value value = tlv.getValue(); + + int criticality = IntegerDecoder.parse( value, 0, 255 ); + + control.setCriticality( criticality != 0 ); + + if ( ( criticality != 0 ) && ( criticality != 255 ) ) + { + log.warn( "A boolean must be encoded with a 0x00 or a 0xFF value" ); + } + } + }); + + //============================================================================================ + // Control Value + //============================================================================================ + // Control ::= SEQUENCE { + // ... + // controlValue OCTET STRING OPTIONAL } (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.CONTROL_LOOP_OR_CRITICAL_OR_VALUE_TAG][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_LOOP_OR_CRITICAL_OR_VALUE_TAG, + LdapStatesEnum.CONTROL_VALUE_VALUE, null ); + + super.transitions[LdapStatesEnum.CONTROL_LOOP_OR_VALUE_TAG][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_LOOP_OR_VALUE_TAG, + LdapStatesEnum.CONTROL_VALUE_VALUE, null ); + + // Control ::= SEQUENCE { (Value) + // ... + // controlValue OCTET STRING OPTIONAL } (Value) + // Store the value in the control object created before + super.transitions[LdapStatesEnum.CONTROL_VALUE_VALUE][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition( + LdapStatesEnum.CONTROL_VALUE_VALUE, LdapStatesEnum.CONTROL_LOOP_OR_END_TAG, + new GrammarAction( "Set Control value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // Get the current control + Control control = ldapMessage.getCurrentControl(); + + Value value = tlv.getValue(); + + // Store the value + // We have to handle the special case of a 0 length value + if ( tlv.getLength().getLength() == 0 ) + { + control.setControlValue( OctetString.EMPTY_STRING ); + } + else + { + control.setControlValue( new OctetString( value.getData() ) ); + } + } + }); } }