Package org.apache.directory.shared.asn1.ber.tlv

Examples of org.apache.directory.shared.asn1.ber.tlv.Value


                new GrammarAction( "Stores CancelId" )
            {
                public void action( Asn1Container container ) throws DecoderException
                {
                    CancelContainer cancelContainer = ( CancelContainer ) container;
                    Value value = cancelContainer.getCurrentTLV().getValue();
   
                    try
                    {
                        int cancelId = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );
       
                        if ( IS_DEBUG )
                        {
                            LOG.debug( "CancelId = " + cancelId );
                        }
       
                        cancelContainer.getCancel().setCancelId( cancelId );
                        cancelContainer.setGrammarEndAllowed( true );
                    }
                    catch ( IntegerDecoderException e )
                    {
                        String msg = I18n.err( I18n.ERR_04031, Strings.dumpBytes(value.getData()) );
                        LOG.error( msg );
                        throw new DecoderException( msg );
                    }
                }
            });
View Full Code Here


        // The current TLV should be a integer between 1 and 127
        // We get it and store it in Version
        TLV tlv = container.getCurrentTLV();

        Value value = tlv.getValue();

        try
        {
            int version = IntegerDecoder.parse( value, 1, 127 );

            if ( IS_DEBUG )
            {
                LOG.debug( "Ldap version ", Integer.valueOf( version ) );
            }

            bindRequestMessage.setVersion3( version == 3 );
        }
        catch ( IntegerDecoderException ide )
        {
            LOG.error( I18n
                .err( I18n.ERR_04078, Strings.dumpBytes(value.getData()), ide.getMessage() ) );

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( ide.getMessage() );
        }
    }
View Full Code Here

        SearchRequest searchRequest = container.getMessage().getDecorated();

        TLV tlv = container.getCurrentTLV();

        // We have to check that this is a correct derefAliases
        Value value = tlv.getValue();
        int derefAliases = 0;

        try
        {
            derefAliases = IntegerDecoder.parse(value, LdapConstants.NEVER_DEREF_ALIASES,
                    LdapConstants.DEREF_ALWAYS);
        }
        catch ( IntegerDecoderException ide )
        {
            String msg = I18n.err( I18n.ERR_04102, value.toString() );
            LOG.error( msg );
            throw new DecoderException( msg );
        }

        searchRequest.setDerefAliases( AliasDerefMode.getDerefMode( derefAliases ) );
View Full Code Here

        // a FF, it's a TRUE. Any other value should be an error,
        // but we could relax this constraint. So if we have
        // something
        // which is not 0, it will be interpreted as TRUE, but we
        // will generate a warning.
        Value value = tlv.getValue();

        try
        {
            control.setCritical( BooleanDecoder.parse( value ) );
        }
        catch ( BooleanDecoderException bde )
        {
            LOG.error( I18n
                .err( I18n.ERR_04100, Strings.dumpBytes(value.getData()), bde.getMessage() ) );

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( bde.getMessage() );
        }
View Full Code Here

        // a FF, it's a TRUE. Any other value should be an error,
        // but we could relax this constraint. So if we have
        // something
        // which is not 0, it will be interpreted as TRUE, but we
        // will generate a warning.
        Value value = tlv.getValue();

        try
        {
            searchRequest.setTypesOnly( BooleanDecoder.parse( value ) );
        }
        catch ( BooleanDecoderException bde )
        {
            LOG.error( I18n
                .err( I18n.ERR_04105, Strings.dumpBytes(value.getData()), bde.getMessage() ) );

            throw new DecoderException( bde.getMessage() );
        }

        if ( IS_DEBUG )
View Full Code Here

        MessageDecorator<?> message = container.getMessage();
        CodecControl<? extends Control> control = message.getCurrentControl();

        // Get the current control
        Value value = tlv.getValue();

        // Store the value - have to handle the special case of a 0 length value
        if ( tlv.getLength() == 0 )
        {
            control.setValue( StringConstants.EMPTY_BYTES );
        }
        else
        {
            control.setValue( value.getData() );

            if ( control != null )
            {
                control.decode( value.getData() );
            }
        }

        // We can have an END transition
        container.setGrammarEndAllowed( true );
View Full Code Here

                SyncDoneValueStatesEnum.COOKIE_STATE, UniversalTag.OCTET_STRING.getValue(),
            new GrammarAction<SyncDoneValueContainer>( "Set SyncDoneValueControl cookie" )
            {
                public void action( SyncDoneValueContainer container ) throws DecoderException
                {
                    Value value = container.getCurrentTLV().getValue();

                    byte[] cookie = value.getData();

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "cookie = {}", Strings.dumpBytes(cookie) );
                    }

                    container.getSyncDoneValueControl().setCookie( cookie );

                    container.setGrammarEndAllowed( true );
                }
            } );

        GrammarAction<SyncDoneValueContainer> refreshDeletesTagAction =
            new GrammarAction<SyncDoneValueContainer>( "set SyncDoneValueControl refreshDeletes flag" )
        {
            public void action( SyncDoneValueContainer container ) throws DecoderException
            {
                Value value = container.getCurrentTLV().getValue();

                try
                {
                    boolean refreshDeletes = BooleanDecoder.parse( value );
View Full Code Here

                UniversalTag.INTEGER.getValue(),
                new GrammarAction<PagedResultsContainer>( "Set PagedSearchControl size" )
            {
                public void action( PagedResultsContainer container ) throws DecoderException
                {
                    Value value = container.getCurrentTLV().getValue();

                    try
                    {
                        // Check that the value is into the allowed interval
                        int size = IntegerDecoder.parse( value, Integer.MIN_VALUE, Integer.MAX_VALUE );
                       
                        // We allow negative value to absorb a bug in some M$ client.
                        // Those negative values will be transformed to Integer.MAX_VALUE.
                        if ( size < 0 )
                        {
                            size = Integer.MAX_VALUE;
                        }
                       
                        if ( IS_DEBUG )
                        {
                            LOG.debug( "size = " + size );
                        }

                        container.getDecorator().setSize( size );
                    }
                    catch ( IntegerDecoderException e )
                    {
                        String msg = I18n.err( I18n.ERR_04050 );
                        LOG.error( msg, e );
                        throw new DecoderException( msg );
                    }
                }
            } );

        /**
         * Transition from size to cookie
         * realSearchControlValue ::= SEQUENCE OF {
         *     ...
         *     cookie   OCTET STRING
         * }
         *    
         * Stores the cookie flag
         */
        super.transitions[ PagedResultsStates.SIZE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
            new GrammarTransition<PagedResultsContainer>( PagedResultsStates.SIZE_STATE,
                                    PagedResultsStates.COOKIE_STATE, UniversalTag.OCTET_STRING.getValue(),
                new GrammarAction<PagedResultsContainer>( "Set PagedSearchControl cookie" )
            {
                public void action( PagedResultsContainer container ) throws DecoderException
                {
                    Value value = container.getCurrentTLV().getValue();

                    if ( container.getCurrentTLV().getLength() == 0 )
                    {
                        container.getDecorator().setCookie( StringConstants.EMPTY_BYTES );
                    }
                    else
                    {
                        container.getDecorator().setCookie( value.getData() );
                    }

                    // We can have an END transition
                    container.setGrammarEndAllowed( true );
                }
View Full Code Here

                UniversalTag.INTEGER.getValue(),
                new GrammarAction<PersistentSearchContainer>( "Set PSearchControl changeTypes" )
            {
                public void action( PersistentSearchContainer container ) throws DecoderException
                {
                    Value value = container.getCurrentTLV().getValue();

                    try
                    {
                        // Check that the value is into the allowed interval
                        int changeTypes = IntegerDecoder.parse( value,
                            PersistentSearch.CHANGE_TYPES_MIN,
                            PersistentSearch.CHANGE_TYPES_MAX );
                       
                        if ( IS_DEBUG )
                        {
                            LOG.debug( "changeTypes = " + changeTypes );
                        }

                        container.getPersistentSearchDecorator().setChangeTypes( changeTypes );
                    }
                    catch ( IntegerDecoderException e )
                    {
                        String msg = I18n.err( I18n.ERR_04051 );
                        LOG.error( msg, e );
                        throw new DecoderException( msg );
                    }
                }
            } );

        /**
         * Transition from Change types to Changes only
         * PSearch ::= SEQUENCE OF {
         *     ...
         *     changeOnly   BOOLEAN,
         *     ...
         *    
         * Stores the change only flag
         */
        super.transitions[ PersistentSearchStates.CHANGE_TYPES_STATE.ordinal()][UniversalTag.BOOLEAN.getValue()] =
            new GrammarTransition<PersistentSearchContainer>( PersistentSearchStates.CHANGE_TYPES_STATE,
                                    PersistentSearchStates.CHANGES_ONLY_STATE, UniversalTag.BOOLEAN.getValue(),
                new GrammarAction<PersistentSearchContainer>( "Set PSearchControl changesOnly" )
            {
                public void action( PersistentSearchContainer container ) throws DecoderException
                {
                    Value value = container.getCurrentTLV().getValue();

                    try
                    {
                        boolean changesOnly = BooleanDecoder.parse( value );

                        if ( IS_DEBUG )
                        {
                            LOG.debug( "changesOnly = " + changesOnly );
                        }

                        container.getPersistentSearchDecorator().setChangesOnly( changesOnly );
                    }
                    catch ( BooleanDecoderException e )
                    {
                        String msg = I18n.err( I18n.ERR_04052 );
                        LOG.error( msg, e );
                        throw new DecoderException( msg );
                    }
                }
            } );

        /**
         * Transition from Change types to Changes only
         * PSearch ::= SEQUENCE OF {
         *     ...
         *     returnECs    BOOLEAN
         * }
         *    
         * Stores the return ECs flag
         */
        super.transitions[ PersistentSearchStates.CHANGES_ONLY_STATE.ordinal()][UniversalTag.BOOLEAN.getValue()] =
            new GrammarTransition<PersistentSearchContainer>( PersistentSearchStates.CHANGES_ONLY_STATE,
                                    PersistentSearchStates.RETURN_ECS_STATE, UniversalTag.BOOLEAN.getValue(),
                new GrammarAction<PersistentSearchContainer>( "Set PSearchControl returnECs" )
            {
                public void action( PersistentSearchContainer container ) throws DecoderException
                {
                    Value value = container.getCurrentTLV().getValue();

                    try
                    {
                        boolean returnECs = BooleanDecoder.parse( value );

View Full Code Here

                                    UniversalTag.ENUMERATED.getValue(),
            new GrammarAction<EntryChangeContainer>( "Set EntryChangeControl changeType" )
        {
            public void action( EntryChangeContainer container ) throws DecoderException
            {
                Value value = container.getCurrentTLV().getValue();

                try
                {
                    int change = IntegerDecoder.parse( value, 1, 8 );
                   
                    switch ( ChangeType.getChangeType( change ) )
                    {
                        case ADD:
                        case DELETE:
                        case MODDN:
                        case MODIFY:
                            ChangeType changeType = ChangeType.getChangeType( change );

                            if ( IS_DEBUG )
                            {
                                LOG.debug( "changeType = " + changeType );
                            }

                            container.getEntryChangeDecorator().setChangeType( changeType );
                            break;

                        default:
                            String msg = I18n.err( I18n.ERR_04044 );
                            LOG.error( msg );
                            throw new DecoderException( msg );
                    }

                    // We can have an END transition
                    container.setGrammarEndAllowed( true );
                }
                catch ( IntegerDecoderException e )
                {
                    String msg = I18n.err( I18n.ERR_04044 );
                    LOG.error( msg, e );
                    throw new DecoderException( msg );
                }
                catch ( IllegalArgumentException e )
                {
                    throw new DecoderException( e.getLocalizedMessage() );
                }
            }
        } );

        // ============================================================================================
        // Transition from Change Type to Previous Dn
        // ============================================================================================
        // EntryChangeNotification ::= SEQUENCE {
        //     ...
        //     previousDN LDAPDN OPTIONAL,
        //     ...
        //
        // Set the previousDN into the structure. We first check that it's a
        // valid Dn
        super.transitions[ EntryChangeStates.CHANGE_TYPE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
            new GrammarTransition<EntryChangeContainer>( EntryChangeStates.CHANGE_TYPE_STATE,
                                    EntryChangeStates.PREVIOUS_DN_STATE,
                                    UniversalTag.OCTET_STRING.getValue(),
            new GrammarAction<EntryChangeContainer>( "Set EntryChangeControl previousDN" )
        {
            public void action( EntryChangeContainer container ) throws DecoderException
            {
                ChangeType changeType = container.getEntryChangeDecorator().getChangeType();


                if ( changeType != ChangeType.MODDN )
                {
                    LOG.error( I18n.err( I18n.ERR_04045 ) );
                    throw new DecoderException( I18n.err( I18n.ERR_04046 ));
                }
                else
                {
                    Value value = container.getCurrentTLV().getValue();
                    Dn previousDn;

                    try
                    {
                        previousDn = new Dn( Strings.utf8ToString(value.getData()) );
                    }
                    catch ( LdapInvalidDnException ine )
                    {
                        LOG.error( I18n.err( I18n.ERR_04047, Strings.dumpBytes(value.getData()) ) );
                        throw new DecoderException( I18n.err( I18n.ERR_04048 ) );
                    }

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "previousDN = " + previousDn );
                    }

                    container.getEntryChangeDecorator().setPreviousDn( previousDn );

                    // We can have an END transition
                    container.setGrammarEndAllowed( true );
                }
            }
        } );

        // Change Number action
        GrammarAction<EntryChangeContainer> setChangeNumberAction = new GrammarAction<EntryChangeContainer>( "Set EntryChangeControl changeNumber" )
        {
            public void action( EntryChangeContainer container ) throws DecoderException
            {
                Value value = container.getCurrentTLV().getValue();

                try
                {
                    long changeNumber = LongDecoder.parse( value );
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.asn1.ber.tlv.Value

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.