Return-Path: Delivered-To: apmail-incubator-directory-cvs-archive@www.apache.org Received: (qmail 59406 invoked from network); 30 May 2004 09:01:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 30 May 2004 09:01:37 -0000 Received: (qmail 26336 invoked by uid 500); 30 May 2004 09:01:32 -0000 Delivered-To: apmail-incubator-directory-cvs-archive@incubator.apache.org Received: (qmail 26288 invoked by uid 500); 30 May 2004 09:01:32 -0000 Mailing-List: contact directory-cvs-help@incubator.apache.org; run by ezmlm Precedence: bulk Reply-To: directory-dev@incubator.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list directory-cvs@incubator.apache.org Received: (qmail 26274 invoked by uid 99); 30 May 2004 09:01:32 -0000 Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Sun, 30 May 2004 02:01:32 -0700 Received: (qmail 59358 invoked by uid 65534); 30 May 2004 09:01:34 -0000 Date: 30 May 2004 09:01:34 -0000 Message-ID: <20040530090134.59351.qmail@minotaur.apache.org> From: akarasulu@apache.org To: directory-cvs@incubator.apache.org Subject: svn commit: rev 20646 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap test/org/apache/snickers/ldap X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: akarasulu Date: Sun May 30 02:01:33 2004 New Revision: 20646 Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedRequestOidRule.java (contents, props changed) incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedRequestPayloadRule.java (contents, props changed) incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedRequestRule.java (contents, props changed) incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/ExtendedRequestRuleTest.java (contents, props changed) Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java Log: finished and tested the extended request rules Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedRequestOidRule.java ============================================================================== --- (empty file) +++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedRequestOidRule.java Sun May 30 02:01:33 2004 @@ -0,0 +1,80 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.snickers.ldap ; + + +import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ; +import org.apache.ldap.common.message.BindRequest; +import org.apache.ldap.common.message.ExtendedRequest; + +import java.nio.ByteBuffer; + + +/** + * A BERDigester rule to set the OID of the ExtendedRequest's OID field. + * + * @author Apache Directory + * Project + * @version $Rev$ + */ +public class ExtendedRequestOidRule extends PrimitiveOctetStringRule +{ + public ExtendedRequestOidRule() + { + super( LdapTag.EXTENDED_REQUEST_NAME_TAG ) ; + } + + + /** + * Allows the super method to push a ByteBuffer onto the top of the stack + * which contains the drained contents of the superclass' ByteAccumulator. + * This ByteBuffer is popped first then used to populate the credentials. + * There is no need to copy this buffer since it will not be used again + * by the ByteAccumulator of the superclass so we should be able to use + * the byte[] based backing store if one is present. However it might + * have to be copied even then. Situations requiring a copy are when the + * buffer has a limit less than the capacity or when there is no + * accessible array to the buffer. + * + * @see org.apache.snickers.ber.digester.Rule#finish() + */ + public void finish() + { + // pushes a ByteBuffer onto the stack + super.finish() ; + + // pop the ByteBuffer the super method pushed + ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ; + // peek at the ExtendedRequest underneath whose octets we set + ExtendedRequest req = ( ExtendedRequest ) getDigester().peek() ; + + byte[] octets = null ; + if ( buf.limit() == buf.capacity() && buf.hasArray() ) + { + // use the backing store + octets = buf.array() ; + } + else + { + // copy because we don't have accessible array or data < array + octets = new byte[buf.remaining()] ; + buf.get( octets ) ; + } + + req.setOid( new String( octets ) ) ; + } +} Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedRequestPayloadRule.java ============================================================================== --- (empty file) +++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedRequestPayloadRule.java Sun May 30 02:01:33 2004 @@ -0,0 +1,81 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.snickers.ldap ; + + +import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ; +import org.apache.ldap.common.message.BindRequest; +import org.apache.ldap.common.message.ExtendedRequest; + +import java.nio.ByteBuffer; + + +/** + * A BERDigester rule to set the payload for the ExtendedRequest which is the + * ASN.1 requestValue field. + * + * @author Apache Directory + * Project + * @version $Rev$ + */ +public class ExtendedRequestPayloadRule extends PrimitiveOctetStringRule +{ + public ExtendedRequestPayloadRule() + { + super( LdapTag.EXTENDED_REQUEST_VALUE_TAG ) ; + } + + + /** + * Allows the super method to push a ByteBuffer onto the top of the stack + * which contains the drained contents of the superclass' ByteAccumulator. + * This ByteBuffer is popped first then used to populate the credentials. + * There is no need to copy this buffer since it will not be used again + * by the ByteAccumulator of the superclass so we should be able to use + * the byte[] based backing store if one is present. However it might + * have to be copied even then. Situations requiring a copy are when the + * buffer has a limit less than the capacity or when there is no + * accessible array to the buffer. + * + * @see org.apache.snickers.ber.digester.Rule#finish() + */ + public void finish() + { + // pushes a ByteBuffer onto the stack + super.finish() ; + + // pop the ByteBuffer the super method pushed + ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ; + // peek at the ExtendedRequest underneath whose octets we set + ExtendedRequest req = ( ExtendedRequest ) getDigester().peek() ; + + byte[] octets = null ; + if ( buf.limit() == buf.capacity() && buf.hasArray() ) + { + // use the backing store + octets = buf.array() ; + } + else + { + // copy because we don't have accessible array or data < array + octets = new byte[buf.remaining()] ; + buf.get( octets ) ; + } + + req.setPayload( octets ) ; + } +} Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedRequestRule.java ============================================================================== --- (empty file) +++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ExtendedRequestRule.java Sun May 30 02:01:33 2004 @@ -0,0 +1,62 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.snickers.ldap ; + + +import org.apache.snickers.ber.TypeClass ; +import org.apache.snickers.ber.digester.AbstractRule ; +import org.apache.ldap.common.message.ExtendedRequestImpl ; + + +/** + * Digester rule that instantiates ExtendedRequest objects and pushes them onto + * the object stack to be populated. + * + * @author Apache Directory + * Project + * @version $Rev$ + */ +public class ExtendedRequestRule extends AbstractRule +{ + /* (non-Javadoc) + * @see org.apache.snickers.ber.Rule#tag(int, boolean, + * org.apache.snickers.ber.TypeClass) + */ + public void tag( int id, boolean isPrimitive, TypeClass typeClass ) + { + LdapTag tag = LdapTag.getLdapTagById( id ) ; + + if ( LdapTag.EXTENDED_REQUEST != tag ) + { + throw new IllegalArgumentException( "Expected a ExtendedRequest tag" + + " id but got a " + tag ) ; + } + + ExtendedRequestImpl req = new + ExtendedRequestImpl( getDigester().popInt() ) ; + getDigester().push( req ) ; + } + + + /* (non-Javadoc) + * @see org.apache.snickers.ber.Rule#finish() + */ + public void finish() + { + getDigester().pop() ; + } +} Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java ============================================================================== --- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java (original) +++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java Sun May 30 02:01:33 2004 @@ -19,6 +19,7 @@ import org.apache.snickers.ber.digester.BERDigester ; import org.apache.snickers.ber.primitives.UniversalTag ; +import org.apache.snickers.ber.primitives.ContextSpecificTag; import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ; import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ; @@ -86,8 +87,27 @@ addCompareResponseRules( digester ) ; addDeleteRequestRules( digester ) ; addDeleteResponseRules( digester ) ; + addExtendedRequestRules( digester ) ; return digester ; + } + + + private void addExtendedRequestRules( BERDigester digester ) + { + int[] pattern = new int[2] ; + pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ; + pattern[1] = LdapTag.EXTENDED_REQUEST.getPrimitiveTag() ; + digester.addRule( pattern, new ExtendedRequestRule() ) ; + + pattern = new int[3] ; + pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ; + pattern[1] = LdapTag.EXTENDED_REQUEST.getPrimitiveTag() ; + pattern[2] = LdapTag.EXTENDED_REQUEST_NAME_TAG.getPrimitiveTag() ; + digester.addRule( pattern, new ExtendedRequestOidRule() ) ; + + pattern[2] = LdapTag.EXTENDED_REQUEST_VALUE_TAG.getPrimitiveTag() ; + digester.addRule( pattern, new ExtendedRequestPayloadRule() ) ; } Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java ============================================================================== --- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java (original) +++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java Sun May 30 02:01:33 2004 @@ -209,6 +209,16 @@ public static final ContextSpecificTag SERVER_SASL_CREDS_TAG = new ContextSpecificTag( 7, true ) ; + /** Context specific tag used for BindResponse serverSaslCreds */ + public static final ContextSpecificTag EXTENDED_REQUEST_NAME_TAG = + new ContextSpecificTag( 0, false ) ; + + /** Context specific tag used for BindResponse serverSaslCreds */ + public static final ContextSpecificTag EXTENDED_REQUEST_VALUE_TAG = + new ContextSpecificTag( 1, false ) ; + + + // ----------------------------------------------------------------------- // Members Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/ExtendedRequestRuleTest.java ============================================================================== --- (empty file) +++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/ExtendedRequestRuleTest.java Sun May 30 02:01:33 2004 @@ -0,0 +1,53 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.snickers.ldap ; + + +import org.apache.ldap.common.message.* ; +import org.apache.snickers.ldap.testutils.TestUtils ; +import org.apache.snickers.ldap.testutils.RuleTestCase ; +import org.apache.commons.lang.ArrayUtils; + + +/** + * Document this class. + * + * @author Apache Directory + * Project + * @version $Rev$ + */ +public class ExtendedRequestRuleTest extends RuleTestCase +{ + public void testCompareRequest() throws Exception + { + // build the PDU + ExtendedRequestImpl req = new ExtendedRequestImpl( 7 ) ; + req.setOid( "0.0.0.0" ) ; + byte[] payload = new byte[2] ; + payload[0] = 0x12 ; + payload[1] = 0x34 ; + req.setPayload( payload ) ; + System.out.println( "Generated ExtendedRequest for test:" ) ; + System.out.println( TestUtils.printTupleTree( req ) ) ; + + ExtendedRequest decoded = ( ExtendedRequest ) + snickersDecode( snaccEncode( req ) ) ; + assertEquals( req.getMessageId(), decoded.getMessageId() ) ; + assertEquals( req.getOid(), decoded.getOid() ) ; + assertTrue( ArrayUtils.isEquals( payload, decoded.getPayload() ) ) ; + } +}