Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 95852 invoked from network); 3 Oct 2006 14:07:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Oct 2006 14:07:30 -0000 Received: (qmail 28113 invoked by uid 500); 3 Oct 2006 14:07:29 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 28040 invoked by uid 500); 3 Oct 2006 14:07:29 -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 27955 invoked by uid 99); 3 Oct 2006 14:07:28 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Oct 2006 07:07:28 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [140.211.166.113] ([140.211.166.113:50371] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id F6/7C-29668-A6E62254 for ; Tue, 03 Oct 2006 07:06:40 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id CB7721A9820; Tue, 3 Oct 2006 07:04:18 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r452504 [1/2] - /directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ Date: Tue, 03 Oct 2006 14:04:17 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061003140418.CB7721A9820@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Tue Oct 3 07:04:15 2006 New Revision: 452504 URL: http://svn.apache.org/viewvc?view=rev&rev=452504 Log: added the actions dir which has been MIA during the previous commits ... Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/AttributeDescAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlValueAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlsInitAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ErrorMessageAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAndFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitApproxMatchFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAssertionValueFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescListAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitEqualityMatchFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitExtensibleMatchFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitGreaterOrEqualFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitLessOrEqualFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitNotFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitOrFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitPresentFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitReferralsAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitSubstringsFilterAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ModifyAttributeValueAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ReferralAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ResponseAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ResponseNameAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ResultCodeAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/SearchResultAttributeValueAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ServerSASLCredsAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreAnyAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreFinalAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreMatchValueAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreReferenceAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreTypeMatchingRuleAction.java directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ValueAction.java Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/AttributeDescAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/AttributeDescAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/AttributeDescAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/AttributeDescAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to store the attribute description + * + * @author Apache Directory Project + */ +public class AttributeDescAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( AttributeDescAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public AttributeDescAction() + { + super( "Store attribute description" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + + SearchRequest searchRequest = ldapMessageContainer.getLdapMessage().getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + String attributeDescription = null; + + byte[] value = null; + + if ( tlv.getLength() == 0 ) + { + value = new byte[] + { '*' }; + } + else + { + value = tlv.getValue().getData(); + } + + attributeDescription = new String( value ); + searchRequest.addAttribute( attributeDescription ); + + // We can have an END transition + ldapMessageContainer.grammarEndAllowed( true ); + + if ( IS_DEBUG ) + { + log.debug( "Decoded Attribute Description : {}", attributeDescription ); + } + + return; + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlValueAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlValueAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlValueAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlValueAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import java.util.HashMap; +import java.util.Map; + +import javax.naming.NamingException; + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.ber.tlv.Value; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.Control; +import org.apache.directory.shared.ldap.codec.ControlDecoder; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.ManageDsaITControlDecoder; +import org.apache.directory.shared.ldap.codec.search.controls.PSearchControlDecoder; +import org.apache.directory.shared.ldap.codec.search.controls.SubEntryControlDecoder; +import org.apache.directory.shared.ldap.util.StringTools; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to set the value of a control. This is an extension point + * where different controls can be plugged in (at least eventually). For now we + * hard code controls. + * + * @author Apache Directory Project + */ +public class ControlValueAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( ControlValueAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + private static Map controlDecoders = new HashMap(); + + + public ControlValueAction() + { + super( "Sets the control value" ); + + ControlDecoder decoder; + decoder = new PSearchControlDecoder(); + controlDecoders.put( decoder.getControlType(), decoder ); + + decoder = new ManageDsaITControlDecoder(); + controlDecoders.put( decoder.getControlType(), decoder ); + + decoder = new SubEntryControlDecoder(); + controlDecoders.put( decoder.getControlType(), decoder ); + } + + + public void action( IAsn1Container container ) throws DecoderException, NamingException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + TLV tlv = ldapMessageContainer.getCurrentTLV(); + LdapMessage message = ldapMessageContainer.getLdapMessage(); + + // Get the current control + Control control = message.getCurrentControl(); + Value value = tlv.getValue(); + + ControlDecoder decoder = ( ControlDecoder ) controlDecoders.get( control.getControlType() ); + + // Store the value - have to handle the special case of a 0 length value + if ( tlv.getLength() == 0 ) + { + control.setControlValue( new byte[] + {} ); + } + else + { + Object decoded; + + if ( decoder != null ) + { + decoded = decoder.decode( value.getData() ); + } + else + { + decoded = value.getData(); + } + + control.setEncodedValue( value.getData() ); + control.setControlValue( decoded ); + } + + // We can have an END transition + ldapMessageContainer.grammarEndAllowed( true ); + + if ( IS_DEBUG ) + { + if ( control.getControlValue() instanceof byte[] ) + { + log.debug( "Control value : " + StringTools.dumpBytes( ( byte[] ) control.getControlValue() ) ); + } + else if ( control.getControlValue() instanceof String ) + { + log.debug( "Control value : " + ( String ) control.getControlValue() ); + } + else + { + log.debug( "Control value : " + control.getControlValue() ); + } + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlsInitAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlsInitAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlsInitAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ControlsInitAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize a control. + * + * @author Apache Directory Project + */ +public class ControlsInitAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( ControlsInitAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public ControlsInitAction() + { + super( "Initialize a control" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage message = ldapMessageContainer.getLdapMessage(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + int expectedLength = tlv.getLength(); + + // The Length should be null + if ( expectedLength == 0 ) + { + log.error( "The length of controls must not be null" ); + + // This will generate a PROTOCOL_ERROR + throw new DecoderException( "The length of controls must not be null" ); + } + + if ( IS_DEBUG ) + { + log.debug( "A new list of controls has been initialized" ); + } + + // We can initialize the controls array + message.initControls(); + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ErrorMessageAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ErrorMessageAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ErrorMessageAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ErrorMessageAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.LdapResponse; +import org.apache.directory.shared.ldap.codec.LdapResult; +import org.apache.directory.shared.ldap.util.StringTools; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to set the LdapResult error message. + * + * @author Apache Directory Project + */ +public class ErrorMessageAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( ErrorMessageAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public ErrorMessageAction() + { + super( "Store error message" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + LdapResponse response = ldapMessage.getLdapResponse(); + LdapResult ldapResult = response.getLdapResult(); + + // Get the Value and store it in the BindResponse + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // We have to handle the special case of a 0 length error + // message + if ( tlv.getLength() == 0 ) + { + ldapResult.setErrorMessage( "" ); + } + else + { + ldapResult.setErrorMessage( StringTools.utf8ToString( tlv.getValue().getData() ) ); + } + + // We can have an END transition + ldapMessageContainer.grammarEndAllowed( true ); + + if ( IS_DEBUG ) + { + log.debug( "The error message is : " + ldapResult.getErrorMessage() ); + } + + return; + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAndFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAndFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAndFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAndFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.AndFilter; +import org.apache.directory.shared.ldap.codec.search.Filter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the AND filter + * + * @author Apache Directory Project + */ +public class InitAndFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitAndFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitAndFilterAction() + { + super( "Initialize AND filter" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + if ( tlv.getLength() == 0 ) + { + log.error( "The And filter PDU must not be empty" ); + throw new DecoderException( "The And filter PDU must not be empty" ); + } + + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + // We can allocate the SearchRequest + Filter andFilter = new AndFilter(); + + // Set the filter + searchRequest.addCurrentFilter( andFilter ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize AND filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitApproxMatchFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitApproxMatchFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitApproxMatchFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitApproxMatchFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapConstants; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.AttributeValueAssertionFilter; +import org.apache.directory.shared.ldap.codec.search.Filter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the Approx Match filter + * + * @author Apache Directory Project + */ +public class InitApproxMatchFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitApproxMatchFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitApproxMatchFilterAction() + { + super( "Init Approx Match filter Value" ); + } + + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + // We can allocate the Attribute Value Assertion + Filter filter = new AttributeValueAssertionFilter( LdapConstants.APPROX_MATCH_FILTER ); + + searchRequest.addCurrentFilter( filter ); + + // Store the filter structure that still has to be + // fullfiled + searchRequest.setTerminalFilter( filter ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize Approx Match filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAssertionValueFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAssertionValueFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAssertionValueFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAssertionValueFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.AttributeValueAssertion; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.AttributeValueAssertionFilter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; +import org.apache.directory.shared.ldap.util.StringTools; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the Assertion Value filter + * + * @author Apache Directory Project + */ +public class InitAssertionValueFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitAssertionValueFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitAssertionValueFilterAction() + { + super( "Initialize Assertion Value filter" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // The value can be null. + Object assertionValue = StringTools.EMPTY_BYTES; + + if ( tlv.getLength() != 0 ) + { + assertionValue = tlv.getValue().getData(); + } + + AttributeValueAssertionFilter terminalFilter = ( AttributeValueAssertionFilter ) searchRequest + .getTerminalFilter(); + AttributeValueAssertion assertion = terminalFilter.getAssertion(); + + if ( ldapMessageContainer.isBinary( assertion.getAttributeDesc() ) ) + { + assertion.setAssertionValue( assertionValue ); + } + else + { + assertion.setAssertionValue( StringTools.utf8ToString( ( byte[] ) assertionValue ) ); + } + + // We now have to get back to the nearest filter which is + // not terminal. + searchRequest.unstackFilters( container ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize Assertion Value filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.AttributeValueAssertion; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.AttributeValueAssertionFilter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the AttributeDesc filter + * + * @author Apache Directory Project + */ +public class InitAttributeDescFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitAttributeDescFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitAttributeDescFilterAction() + { + super( "Initialize AttributeDesc filter" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + AttributeValueAssertion assertion = new AttributeValueAssertion(); + + if ( tlv.getLength() == 0 ) + { + log.error( "The attribute description is empty " ); + throw new DecoderException( "The type can't be null" ); + } + else + { + String type = new String( tlv.getValue().getData() ); + assertion.setAttributeDesc( type ); + + AttributeValueAssertionFilter terminalFilter = ( AttributeValueAssertionFilter ) searchRequest + .getTerminalFilter(); + terminalFilter.setAssertion( assertion ); + } + + if ( IS_DEBUG ) + { + log.debug( "Initialize AttributeDesc filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescListAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescListAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescListAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitAttributeDescListAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the AttributeDesc list + * + * @author Apache Directory Project + */ +public class InitAttributeDescListAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitAttributeDescListAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitAttributeDescListAction() + { + super( "Initialize AttributeDesc list" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + + // We can have an END transition + ldapMessageContainer.grammarEndAllowed( true ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize AttributeDesc list" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitEqualityMatchFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitEqualityMatchFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitEqualityMatchFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitEqualityMatchFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapConstants; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.AttributeValueAssertionFilter; +import org.apache.directory.shared.ldap.codec.search.Filter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the Equality Match filter + * + * @author Apache Directory Project + */ +public class InitEqualityMatchFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitEqualityMatchFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitEqualityMatchFilterAction() + { + super( "Initialize Equality Match filter" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + // We can allocate the Attribute Value Assertion + Filter filter = new AttributeValueAssertionFilter( LdapConstants.EQUALITY_MATCH_FILTER ); + + searchRequest.addCurrentFilter( filter ); + + // Store the filter structure that still has to be + // fullfiled + searchRequest.setTerminalFilter( filter ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize Equality Match filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitExtensibleMatchFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitExtensibleMatchFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitExtensibleMatchFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitExtensibleMatchFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.ExtensibleMatchFilter; +import org.apache.directory.shared.ldap.codec.search.Filter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the Extensible Match filter + * + * @author Apache Directory Project + */ +public class InitExtensibleMatchFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitExtensibleMatchFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitExtensibleMatchFilterAction() + { + super( "Init Extensible Match filter Value" ); + } + + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + // We can allocate the ExtensibleMatch Filter + Filter extensibleMatchFilter = new ExtensibleMatchFilter(); + + searchRequest.addCurrentFilter( extensibleMatchFilter ); + searchRequest.setTerminalFilter( extensibleMatchFilter ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize Extensible Match filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitGreaterOrEqualFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitGreaterOrEqualFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitGreaterOrEqualFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitGreaterOrEqualFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapConstants; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.AttributeValueAssertionFilter; +import org.apache.directory.shared.ldap.codec.search.Filter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the Greater Or Equal filter + * + * @author Apache Directory Project + */ +public class InitGreaterOrEqualFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitGreaterOrEqualFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitGreaterOrEqualFilterAction() + { + super( "Initialize Greater Or Equal filter" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + // We can allocate the Attribute Value Assertion + Filter filter = new AttributeValueAssertionFilter( LdapConstants.GREATER_OR_EQUAL_FILTER ); + + searchRequest.addCurrentFilter( filter ); + + // Store the filter structure that still has to be + // fullfiled + searchRequest.setTerminalFilter( filter ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize Greater Or Equal filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitLessOrEqualFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitLessOrEqualFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitLessOrEqualFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitLessOrEqualFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapConstants; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.AttributeValueAssertionFilter; +import org.apache.directory.shared.ldap.codec.search.Filter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the Less Or Equal filter + * + * @author Apache Directory Project + */ +public class InitLessOrEqualFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitLessOrEqualFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitLessOrEqualFilterAction() + { + super( "Initialize Less Or Equal filter" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + // We can allocate the Attribute Value Assertion + Filter filter = new AttributeValueAssertionFilter( LdapConstants.LESS_OR_EQUAL_FILTER ); + + searchRequest.addCurrentFilter( filter ); + + // Store the filter structure that still has to be + // fullfiled + searchRequest.setTerminalFilter( filter ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize Less Or Equal filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitNotFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitNotFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitNotFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitNotFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.Filter; +import org.apache.directory.shared.ldap.codec.search.NotFilter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the NOT filter + * + * @author Apache Directory Project + */ +public class InitNotFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitNotFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitNotFilterAction() + { + super( "Initialize NOT filter" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + if ( tlv.getLength() == 0 ) + { + log.error( "The Not filter PDU must not be empty" ); + throw new DecoderException( "The Not filter PDU must not be empty" ); + } + + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + // We can allocate the SearchRequest + Filter notFilter = new NotFilter(); + + // Set the filter + searchRequest.addCurrentFilter( notFilter ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize NOT filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitOrFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitOrFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitOrFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitOrFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.Filter; +import org.apache.directory.shared.ldap.codec.search.OrFilter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the OR filter + * + * @author Apache Directory Project + */ +public class InitOrFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitOrFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitOrFilterAction() + { + super( "Initialize OR filter" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + if ( tlv.getLength() == 0 ) + { + log.error( "The Or filter PDU must not be empty" ); + throw new DecoderException( "The Or filter PDU must not be empty" ); + } + + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + // We can allocate the SearchRequest + Filter orFilter = new OrFilter(); + + // Set the filter + searchRequest.addCurrentFilter( orFilter ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize OR filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitPresentFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitPresentFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitPresentFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitPresentFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.PresentFilter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; +import org.apache.directory.shared.ldap.util.StringTools; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the Present filter + * + * @author Apache Directory Project + */ +public class InitPresentFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitPresentFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitPresentFilterAction() + { + super( "Init present filter Value" ); + } + + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // We can allocate the Attribute Value Assertion + PresentFilter presentFilter = new PresentFilter(); + + // add the filter to the request filter + searchRequest.addCurrentFilter( presentFilter ); + searchRequest.setTerminalFilter( presentFilter ); + + String value = StringTools.utf8ToString( tlv.getValue().getData() ); + + if ( StringTools.isEmpty( value ) ) + { + presentFilter.setAttributeDescription( "" ); + } + else + { + // Store the value. + String type = StringTools.utf8ToString( tlv.getValue().getData() ); + presentFilter.setAttributeDescription( type ); + } + + // We now have to get back to the nearest filter which is + // not terminal. + searchRequest.unstackFilters( container ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize Present filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitReferralsAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitReferralsAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitReferralsAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitReferralsAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.LdapResponse; +import org.apache.directory.shared.ldap.codec.LdapResult; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to init referrals to a LdapTresult + * + * @author Apache Directory Project + */ +public class InitReferralsAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitReferralsAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitReferralsAction() + { + super( "Init the referrals list" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + LdapResponse response = ldapMessage.getLdapResponse(); + LdapResult ldapResult = response.getLdapResult(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // If we hae a Referrals sequence, then it should not be empty + // sasl credentials + if ( tlv.getLength() == 0 ) + { + String msg = "The Referrals must not be null"; + log.error( msg ); + + // This will generate a PROTOCOL_ERROR + throw new DecoderException( msg ); + } + + if ( IS_DEBUG) + { + log.debug( "Initialising a referrals list" ); + } + + ldapResult.initReferrals(); + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitSubstringsFilterAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitSubstringsFilterAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitSubstringsFilterAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/InitSubstringsFilterAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.search.Filter; +import org.apache.directory.shared.ldap.codec.search.SearchRequest; +import org.apache.directory.shared.ldap.codec.search.SubstringFilter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to initialize the Substrings filter + * + * @author Apache Directory Project + */ +public class InitSubstringsFilterAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( InitSubstringsFilterAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public InitSubstringsFilterAction() + { + super( "Initialize Substrings filter" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + SearchRequest searchRequest = ldapMessage.getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + int expectedLength = tlv.getLength(); + + if ( expectedLength == 0 ) + { + log.error( "The Substring filter PDU must not be empty" ); + throw new DecoderException( "The Substring filter PDU must not be empty" ); + } + + // We can allocate the SearchRequest + Filter substringFilter = new SubstringFilter(); + + searchRequest.addCurrentFilter( substringFilter ); + searchRequest.setTerminalFilter( substringFilter ); + + // As this is a new Constructed object, we have to init its + // length + + substringFilter.setExpectedLength( expectedLength ); + substringFilter.setCurrentLength( 0 ); + + if ( IS_DEBUG ) + { + log.debug( "Initialize Substrings filter" ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import javax.naming.InvalidNameException; + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.LdapResponse; +import org.apache.directory.shared.ldap.codec.LdapResult; +import org.apache.directory.shared.ldap.codec.util.LdapResultEnum; +import org.apache.directory.shared.ldap.name.LdapDN; +import org.apache.directory.shared.ldap.util.StringTools; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to set the LdapResult matched DN. + * + * @author Apache Directory Project + */ +public class MatchedDNAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( MatchedDNAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public MatchedDNAction() + { + super( "Store matched DN" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + LdapResponse response = ldapMessage.getLdapResponse(); + LdapResult ldapResult = response.getLdapResult(); + + // Get the Value and store it in the BindResponse + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // We have to handle the special case of a 0 length matched + // DN + if ( tlv.getLength() == 0 ) + { + ldapResult.setMatchedDN( LdapDN.EMPTY_LDAPDN ); + } + else + { + // A not null matchedDN is valid for resultCodes + // NoSuchObject, AliasProblem, InvalidDNSyntax and + // AliasDreferencingProblem. + int resultCode = ldapResult.getResultCode(); + + switch ( resultCode ) + { + case LdapResultEnum.NO_SUCH_OBJECT : + case LdapResultEnum.ALIAS_PROBLEM : + case LdapResultEnum.INVALID_DN_SYNTAX : + case LdapResultEnum.ALIAS_DEREFERENCING_PROBLEM : + byte[] dnBytes = tlv.getValue().getData(); + + try + { + ldapResult.setMatchedDN( new LdapDN( dnBytes ) ); + } + catch ( InvalidNameException ine ) + { + // This is for the client side. We will never decode LdapResult on the server + String msg = "Incorrect DN given : " + StringTools.utf8ToString( dnBytes ) + + " (" + StringTools.dumpBytes( dnBytes ) + + ") is invalid"; + log.error( "{} : {}", msg, ine.getMessage() ); + + throw new DecoderException( "Incorrect DN given : " + ine.getMessage() ); + } + + break; + + default : + log.warn( "The matched DN should not be set when the result code is one of NoSuchObject, AliasProblem, InvalidDNSyntax or AliasDreferencingProblem" ); + ldapResult.setMatchedDN( LdapDN.EMPTY_LDAPDN ); + } + } + + if ( IS_DEBUG ) + { + log.debug( "The matchedDN is " + ldapResult.getMatchedDN() ); + } + + return; + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ModifyAttributeValueAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ModifyAttributeValueAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ModifyAttributeValueAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ModifyAttributeValueAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.modify.ModifyRequest; +import org.apache.directory.shared.ldap.util.StringTools; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to store a Value to an modifyRequest + * + * @author Apache Directory Project + */ +public class ModifyAttributeValueAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( ModifyAttributeValueAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public ModifyAttributeValueAction() + { + super( "Stores AttributeValue" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + ModifyRequest modifyRequest = ldapMessage.getModifyRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // Store the value. It can't be null + Object value = StringTools.EMPTY_BYTES; + + if ( tlv.getLength() == 0 ) + { + modifyRequest.addAttributeValue( "" ); + } + else + { + value = tlv.getValue().getData(); + + if ( ldapMessageContainer.isBinary( modifyRequest.getCurrentAttributeType() ) ) + { + modifyRequest.addAttributeValue( value ); + } + else + { + modifyRequest.addAttributeValue( StringTools.utf8ToString( ( byte[] ) value ) ); + } + } + + // We can have an END transition + ldapMessageContainer.grammarEndAllowed( true ); + + if ( IS_DEBUG ) + { + log.debug( "Value modified : {}", value ); + } + } +} Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ReferralAction.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ReferralAction.java?view=auto&rev=452504 ============================================================================== --- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ReferralAction.java (added) +++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/ReferralAction.java Tue Oct 3 07:04:15 2006 @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.shared.ldap.codec.actions; + + +import java.util.Iterator; + +import org.apache.directory.shared.asn1.ber.IAsn1Container; +import org.apache.directory.shared.asn1.ber.grammar.GrammarAction; +import org.apache.directory.shared.asn1.ber.tlv.TLV; +import org.apache.directory.shared.asn1.codec.DecoderException; +import org.apache.directory.shared.ldap.codec.LdapMessage; +import org.apache.directory.shared.ldap.codec.LdapMessageContainer; +import org.apache.directory.shared.ldap.codec.LdapResponse; +import org.apache.directory.shared.ldap.codec.LdapResult; +import org.apache.directory.shared.ldap.codec.util.LdapResultEnum; +import org.apache.directory.shared.ldap.codec.util.LdapURL; +import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The action used to add a referral to a LdapTresult + * + * @author Apache Directory Project + */ +public class ReferralAction extends GrammarAction +{ + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( ReferralAction.class ); + + /** Speedup for logs */ + private static final boolean IS_DEBUG = log.isDebugEnabled(); + + public ReferralAction() + { + super( "Add a referral" ); + } + + /** + * The initialization action + */ + public void action( IAsn1Container container ) throws DecoderException + { + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container; + LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage(); + LdapResponse response = ldapMessage.getLdapResponse(); + LdapResult ldapResult = response.getLdapResult(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + if ( tlv.getLength() == 0 ) + { + ldapResult.addReferral( LdapURL.EMPTY_URL ); + } + else + { + if ( ldapResult.getResultCode() == LdapResultEnum.REFERRAL ) + { + try + { + ldapResult.addReferral( new LdapURL( tlv.getValue().getData() ) ); + } + catch ( LdapURLEncodingException luee ) + { + String badUrl = new String( tlv.getValue().getData() ); + log.error( "The URL " + badUrl + " is not valid : " + luee.getMessage() ); + throw new DecoderException( "Invalid URL : " + luee.getMessage() ); + } + } + else + { + log.warn( "The Referral error message is not allowed when havind an error code no equals to REFERRAL" ); + ldapResult.addReferral( LdapURL.EMPTY_URL ); + } + } + + // We can have an END transition + ldapMessageContainer.grammarEndAllowed( true ); + + if ( IS_DEBUG ) + { + Iterator urls = ldapResult.getReferrals().iterator(); + + StringBuffer sb = new StringBuffer(); + boolean isFirst = true; + + while ( urls.hasNext() ) + { + if ( isFirst ) + { + isFirst = false; + } + else + { + sb.append( ", " ); + } + + sb.append( urls.next() ); + } + + log.debug( "The referral error message is set to " + sb.toString() ); + } + } +}