From commits-return-4889-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Mon Jun 06 22:27:43 2005 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 1133 invoked from network); 6 Jun 2005 22:27:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Jun 2005 22:27:42 -0000 Received: (qmail 16623 invoked by uid 500); 6 Jun 2005 22:27:42 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 16596 invoked by uid 500); 6 Jun 2005 22:27:41 -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 16562 invoked by uid 99); 6 Jun 2005 22:27:41 -0000 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 minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 06 Jun 2005 15:27:37 -0700 Received: (qmail 1036 invoked by uid 65534); 6 Jun 2005 22:27:24 -0000 Message-ID: <20050606222724.1034.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r185065 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchRequestGrammar.java Date: Mon, 06 Jun 2005 22:27:23 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Mon Jun 6 15:27:21 2005 New Revision: 185065 URL: http://svn.apache.org/viewcvs?rev=3D185065&view=3Drev Log: Added the very first draft of the searchRequest grammar. A lot of work need= to be done,=20 as half of the grammar is not implemented, but it's already working for a s= ubset, so, consider this commit as a backup. (it took me three days to reach this point, I don't want to loose everythin= g if my computer crash !) Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/SearchRequestGrammar.java Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap= /codec/grammars/SearchRequestGrammar.java URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/s= rc/java/org/apache/asn1/ldap/codec/grammars/SearchRequestGrammar.java?rev= =3D185065&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/SearchRequestGrammar.java (added) +++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/co= dec/grammars/SearchRequestGrammar.java Mon Jun 6 15:27:21 2005 @@ -0,0 +1,721 @@ +/* + * 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 impli= ed. + * 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.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.Value; +import org.apache.asn1.ldap.codec.LdapConstants; +import org.apache.asn1.ldap.codec.LdapMessageContainer; +import org.apache.asn1.ldap.codec.primitives.LdapDN; +import org.apache.asn1.ldap.codec.utils.IntegerDecoder; +import org.apache.asn1.ldap.pojo.LdapMessagePOJO; +import org.apache.asn1.ldap.pojo.SearchRequestPOJO; +import org.apache.asn1.util.MutableString; + +import org.apache.log4j.Logger; + + +/** + * This class implements the SearchRequest LDAP message. All the actions a= re declared in this + * class. As it is a singleton, these declaration are only done once. + *=20 + * If an action is to be added or modified, this is where the work is to b= e done ! + *=20 + * @author Apache Directory Pr= oject + */ +public class SearchRequestGrammar extends AbstractGrammar implements IGram= mar +{ + //~ Static fields/initializers ---------------------------------------= -------------------------- + + /** The logger */ + private static final Logger log =3D Logger.getLogger( SearchRequestGra= mmar.class ); + + /** Logging speed up */ + private static final boolean DEBUG =3D log.isDebugEnabled(); + + /** The instance of grammar. SearchRequestGrammar is a singleton */ + private static IGrammar instance =3D new SearchRequestGrammar(); + + //~ Constructors -----------------------------------------------------= -------------------------- + + /** + * Creates a new SearchRequestGrammar object. + */ + private SearchRequestGrammar() + { + name =3D SearchRequestGrammar.class.getName(); + statesEnum =3D LdapStatesEnum.getInstance(); + + // Initialisation of the transitions table + super.transitions =3D new GrammarTransition[LdapStatesEnum.LAST_SE= ARCH_REQUEST_STATE][256]; + + //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + // SearchRequest Message + //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + // LdapMessage ::=3D ... SearchRequest ... + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { (Tag) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TAG][0x63] =3D new= GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_TAG, LdapStatesEnum.SEARCH_R= EQUEST_LENGTH, null ); + + // LdapMessage ::=3D ... SearchRequest ... + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { ... (Length) + // We have to allocate a SearchRequestPOJO. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_LENGTH][0x63] =3D = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_LENGTH, LdapStatesEnum.SEARC= H_REQUEST_VALUE, + new GrammarAction( "Init SearchRequest" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + LdapMessagePOJO ldapMessage =3D + ldapMessageContainer.getLdapMessage(); + + checkLength( ldapMessageContainer.getLdapMessage(), + ldapMessageContainer.getCurrentTLV() ); + + // Now, we can allocate the SearchRequestPOJO + SearchRequestPOJO searchRequest =3D new SearchRequ= estPOJO(); + + // As this is a new Constructed object, we have to= init its length + TLV tlv =3D ldapMessageContainer.getCur= rentTLV(); + int expectedLength =3D tlv.getLength().getLength(); + + searchRequest.setExpectedLength( expectedLength ); + searchRequest.setCurrentLength( 0 ); + searchRequest.setFather( ldapMessage ); + + // And we associate it to the ldapMessage POJO + ldapMessage.setProtocolOP( searchRequest ); + } + } ); + + // LdapMessage ::=3D ... SearchRequest ... + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { ... (Value) + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_VALUE][0x63] =3D n= ew GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_VALUE, LdapStatesEnum.SEARCH= _REQUEST_BASE_OBJECT_TAG, + null); + + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE {=20 + // baseObject LDAPDN, (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_BASE_OBJECT_TAG][0= x04] =3D new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_BASE_OBJECT_TAG, LdapStatesE= num.SEARCH_REQUEST_BASE_OBJECT_LENGTH, + null); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE {=20 + // baseObject LDAPDN, (Length) + // ... + // We have to check the length + super.transitions[LdapStatesEnum.SEARCH_REQUEST_BASE_OBJECT_LENGTH= ][0x04] =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_BASE_OBJE= CT_LENGTH, + LdapStatesEnum.SEARCH_REQUEST_BASE_OBJECT_VALUE, + new GrammarAction( "Check base object length" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + checkLength( searchRequest, tlv ); + + // We have to handle the special case of a 0 lengt= h base object, + // which is not permitted + if ( tlv.getLength().getLength() =3D=3D 0 ) + { + throw new DecoderException("The base object mu= st not be null"); + } + + return; + } + } ); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE {=20 + // baseObject LDAPDN, (Value) + // ... + // We have a value for the base object, we will store it in the me= ssage + super.transitions[LdapStatesEnum.SEARCH_REQUEST_BASE_OBJECT_VALUE]= [0x04] =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_BASE_OBJE= CT_VALUE, + LdapStatesEnum.SEARCH_REQUEST_SCOPE_TAG, + new GrammarAction( "store base object value" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + // We have to check that this is a correct DN + MutableString baseObject =3D null; + =20 + try + { + baseObject =3D LdapDN.parseDN(tlv.getValue().g= etData()); + } + catch (DecoderException de) + { + log.error("The DN " + baseObject.toString() + = " is invalid"); + throw de; + } + =20 + searchRequest.setBaseObject(baseObject); + + return; + } + } ); + + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // scope ENUMERATED { + // baseObject (0), + // singleLevel (1), + // wholeSubtree (2) }, (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_SCOPE_TAG][0x0A] = =3D new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_SCOPE_TAG, LdapStatesEnum.SE= ARCH_REQUEST_SCOPE_LENGTH, + null); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE {=20 + // ... + // scope ENUMERATED {=20 + // baseObject (0), + // singleLevel (1), + // wholeSubtree (2) }, (Length) + // ... + // We have to check the length + super.transitions[LdapStatesEnum.SEARCH_REQUEST_SCOPE_LENGTH][0x0A= ] =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_SCOPE_LEN= GTH, + LdapStatesEnum.SEARCH_REQUEST_SCOPE_VALUE, + new GrammarAction( "Check scope length" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + checkLength( searchRequest, tlv ); + return; + } + } ); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE {=20 + // ... + // scope ENUMERATED { + // baseObject (0), + // singleLevel (1), + // wholeSubtree (2) }, (Value) + // ... + // We have a value for the scope, we will store it in the message + super.transitions[LdapStatesEnum.SEARCH_REQUEST_SCOPE_VALUE][0x0A]= =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_SCOPE_VAL= UE, + LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_TAG, + new GrammarAction( "store scope value" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + // We have to check that this is a correct scope + Value value =3D tlv.getValue(); + + int scope =3D IntegerDecoder.parse( value, LdapC= onstants.SCOPE_BASE_OBJECT, LdapConstants.SCOPE_WHOLE_SUBTREE ); + =20 + searchRequest.setScope(scope); + + return; + } + } ); + + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // derefAliases ENUMERATED { + // neverDerefAliases (0), + // derefInSearching (1), + // derefFindingBaseObj (2), + // derefAlways (3) }, (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_TAG]= [0x0A] =3D new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_TAG, LdapState= sEnum.SEARCH_REQUEST_DEREF_ALIASES_LENGTH, + null); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // derefAliases ENUMERATED { + // neverDerefAliases (0), + // derefInSearching (1), + // derefFindingBaseObj (2), + // derefAlways (3) }, (Length) + // ... + // We have to check the length + super.transitions[LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_LENG= TH][0x0A] =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_DEREF_ALI= ASES_LENGTH, + LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_VALUE, + new GrammarAction( "Check derefAliases length" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + checkLength( searchRequest, tlv ); + return; + } + } ); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // derefAliases ENUMERATED { + // neverDerefAliases (0), + // derefInSearching (1), + // derefFindingBaseObj (2), + // derefAlways (3) }, (Value) + // ... + // We have a value for the derefAliases, we will store it in the m= essage + super.transitions[LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_VALU= E][0x0A] =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_DEREF_ALI= ASES_VALUE, + LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_TAG, + new GrammarAction( "store derefAliases value" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + // We have to check that this is a correct derefAl= iases + Value value =3D tlv.getValue(); + + int derefAliases =3D IntegerDecoder.parse( value= , LdapConstants.NEVER_DEREF_ALIASES, LdapConstants.DEREF_ALWAYS ); + =20 + searchRequest.setDerefAliases( derefAliases ); + + return; + } + } ); + + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // sizeLimit INTEGER (0 .. maxInt), (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_TAG][0x= 02] =3D new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_TAG, LdapStatesEn= um.SEARCH_REQUEST_SIZE_LIMIT_LENGTH, + null); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // sizeLimit INTEGER (0 .. maxInt), (Length) + // ... + // We have to check the length + super.transitions[LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_LENGTH]= [0x02] =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMI= T_LENGTH, + LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_VALUE, + new GrammarAction( "Check sizeLimit length" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + checkLength( searchRequest, tlv ); + return; + } + } ); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // sizeLimit INTEGER (0 .. maxInt), (Value) + // ... + // We have a value for the sizeLimit, we will store it in the mess= age + super.transitions[LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_VALUE][= 0x02] =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMI= T_VALUE, + LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_TAG, + new GrammarAction( "store sizeLimit value" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + // The current TLV should be a integer + // We get it and store it in sizeLimit + Value value =3D tlv.getValue(); + + int sizeLimit =3D IntegerDecoder.parse( value, 0= , Integer.MAX_VALUE ); + + searchRequest.setSizeLimit( sizeLimit ); + + return; + } + } ); + + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // timeLimit INTEGER (0 .. maxInt), (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_TAG][0x= 02] =3D new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_TAG, LdapStatesEn= um.SEARCH_REQUEST_TIME_LIMIT_LENGTH, + null); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // timeLimit INTEGER (0 .. maxInt), (Length) + // ... + // We have to check the length + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_LENGTH]= [0x02] =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_TIME_LIMI= T_LENGTH, + LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_VALUE, + new GrammarAction( "Check timeLimit length" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + checkLength( searchRequest, tlv ); + return; + } + } ); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // timeLimit INTEGER (0 .. maxInt), (Value) + // ... + // We have a value for the timeLimit, we will store it in the mess= age + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_VALUE][= 0x02] =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_TIME_LIMI= T_VALUE, + LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_TAG, + new GrammarAction( "store timeLimit value" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + // The current TLV should be a integer + // We get it and store it in timeLimit + Value value =3D tlv.getValue(); + + int timeLimit =3D IntegerDecoder.parse( value, 0= , Integer.MAX_VALUE ); + + searchRequest.setTimeLimit( timeLimit ); + + return; + } + } ); + + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // typesOnly BOOLEAN, (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_TAG][0x= 01] =3D new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_TAG, LdapStatesEn= um.SEARCH_REQUEST_TYPES_ONLY_LENGTH, + null); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // typesOnly BOOLEAN, (Length) + // ... + // We have to check the length + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_LENGTH]= [0x01] =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_TYPES_ONL= Y_LENGTH, + LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_VALUE, + new GrammarAction( "Check typesOnly length" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + checkLength( searchRequest, tlv ); + return; + } + } ); + =20 + // SearchRequest ::=3D [APPLICATION 3] SEQUENCE { + // ... + // typesOnly BOOLEAN, (Value) + // ... + // We have a value for the typesOnly, we will store it in the mess= age. + // The next transition will deal with the Filter. As a filter coul= d contains + // sub-filter, we will initialize the filter POJO right here.=20 + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_VALUE][= 0x01] =3D + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_TYPES_ONL= Y_VALUE, + LdapStatesEnum.SEARCH_REQUEST_FILTER, + new GrammarAction( "store typesOnly value" ) + { + public void action( IAsn1Container container ) throws = DecoderException + { + + LdapMessageContainer ldapMessageContainer =3D ( Ld= apMessageContainer ) + container; + + SearchRequestPOJO searchRequest =3D + ldapMessageContainer.getLdapMessage().getSearc= hRequest(); + + TLV tlv =3D ldapMessageContainer.= getCurrentTLV(); + + // 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 ha= ve something + // which is not 0, it will be interpreted as TRUE,= but we + // will generate a warning. + Value value =3D tlv.getValue(); + + int typesOnly =3D IntegerDecoder.parse( value, 0,= 255 ); + + searchRequest.setTypesOnly( typesOnly !=3D 0 ); + + if ( ( typesOnly !=3D 0 ) && (typesOnly !=3D 255 )= )=20 + { + log.warn("A boolean must be encoded with a 0x0= 0 or a 0xFF value"); + } + =20 + // Allocate the FilterPOJO now. + // searchRequest.setFilter(new FilterPOJO()); + =20 + return; + } + } ); + + //****************************************************************= **************************** + // Here we are dealing with the Search Request filter.=20 + // If the Tag is 0xA0, then it's an and Filter + // If the Tag is 0xA1, then it's an or Filter + // If the Tag is 0xA2, then it's a not Filter + // If the Tag is 0xA3, then it's an equalityMatch Filter + // If the Tag is 0xA4, then it's a substrings Filter + // If the Tag is 0xA5, then it's a greaterOrEqual Filter + // If the Tag is 0xA6, then it's a lessOrEqual Filter + // If the Tag is 0x87, then it's a present Filter + // If the Tag is 0xA8, then it's an approxMatch Filter + // If the Tag is 0xA9, then it's an extensibleMatch Filter + //****************************************************************= **************************** + + //----------------------------------------------------------------= ---------------------------- + // And Filter Message. + //----------------------------------------------------------------= ---------------------------- + // Filter ::=3D CHOICE { + // and [0] SET OF Filter, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][0xA0] =3D = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTE= R_GRAMMAR_SWITCH, + null ); + + //----------------------------------------------------------------= ---------------------------- + // Or Filter Message. + //----------------------------------------------------------------= ---------------------------- + // Filter ::=3D CHOICE { + // ... + // or [0] SET OF Filter, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][0xA1] =3D = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTE= R_GRAMMAR_SWITCH, + null ); + + //----------------------------------------------------------------= ---------------------------- + // Not Filter Message. + //----------------------------------------------------------------= ---------------------------- + // Filter ::=3D CHOICE { + // ... + // not [2] Filter, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][0xA2] =3D = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTE= R_GRAMMAR_SWITCH, + null ); + + //----------------------------------------------------------------= ---------------------------- + // EqualityMatch Filter Message. + //----------------------------------------------------------------= ---------------------------- + // Filter ::=3D CHOICE { + // ... + // equalityMatch [3] AttributeValueAssertion, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][0xA3] =3D = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTE= R_GRAMMAR_SWITCH, + null ); + + //----------------------------------------------------------------= ---------------------------- + // Substrings Filter Message. + //----------------------------------------------------------------= ---------------------------- + // Filter ::=3D CHOICE { + // ... + // substrings [4] SubstringFilter, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][0xA4] =3D = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTE= R_GRAMMAR_SWITCH, + null ); + + //----------------------------------------------------------------= ---------------------------- + // GreaterOrEqual Filter Message. + //----------------------------------------------------------------= ---------------------------- + // Filter ::=3D CHOICE { + // ... + // greaterOrEqual [5] AttributeValueAssertion, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][0xA5] =3D = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTE= R_GRAMMAR_SWITCH, + null ); + + //----------------------------------------------------------------= ---------------------------- + // LessOrEqual Filter Message. + //----------------------------------------------------------------= ---------------------------- + // Filter ::=3D CHOICE { + // ... + // lessOrEqual [6] AttributeValueAssertion, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][0xA6] =3D = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTE= R_GRAMMAR_SWITCH, + null ); + + //----------------------------------------------------------------= ---------------------------- + // Present Filter Message. + //----------------------------------------------------------------= ---------------------------- + // Filter ::=3D CHOICE { + // ... + // present [7] AttributeDescription, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][0x87] =3D = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTE= R_GRAMMAR_SWITCH, + null ); + + //----------------------------------------------------------------= ---------------------------- + // ApproxMatch Filter Message. + //----------------------------------------------------------------= ---------------------------- + // Filter ::=3D CHOICE { + // ... + // approxMatch [8] AttributeValueAssertion, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][0xA8] =3D = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTE= R_GRAMMAR_SWITCH, + null ); + + //----------------------------------------------------------------= ---------------------------- + // ExtensibleMatch Filter Message. + //----------------------------------------------------------------= ---------------------------- + // Filter ::=3D CHOICE { + // ... + // extensibleMatch [9] MatchingRuleAssertion, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][0xA9] =3D = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTE= R_GRAMMAR_SWITCH, + null ); + + } + + //~ Methods ----------------------------------------------------------= -------------------------- + + /** + * Get the instance of this grammar + * + * @return An instance on the LdapMessage Grammar + */ + public static IGrammar getInstance() + { + return instance; + } +}