Search in sources :

Example 26 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.

the class InitControls method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    int expectedLength = tlv.getLength();
    // The Length can be null
    if (expectedLength != 0) {
        if (IS_DEBUG) {
            LOG.debug("A new list of controls has been initialized");
        }
    } else {
        if (IS_DEBUG) {
            LOG.debug("An empty list of controls has been initialized");
        }
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
}
Also used : TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 27 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.

the class StoreControlValue method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    MessageDecorator<?> message = container.getMessage();
    CodecControl<? extends Control> control = message.getCurrentControl();
    // Get the current control
    BerValue value = tlv.getValue();
    // Store the value - have to handle the special case of a 0 length value
    if (tlv.getLength() == 0) {
        control.setValue(Strings.EMPTY_BYTES);
    } else {
        control.setValue(value.getData());
        control.decode(value.getData());
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("Control value : " + Strings.dumpBytes(control.getValue()));
    }
}
Also used : BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 28 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.

the class StoreSearchRequestSizeLimit method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequest searchRequest = container.getMessage().getDecorated();
    TLV tlv = container.getCurrentTLV();
    // The current TLV should be a integer
    // We get it and store it in sizeLimit
    BerValue value = tlv.getValue();
    long sizeLimit = 0;
    try {
        sizeLimit = LongDecoder.parse(value, 0, Integer.MAX_VALUE);
    } catch (LongDecoderException lde) {
        String msg = I18n.err(I18n.ERR_04103, value.toString());
        LOG.error(msg);
        throw new DecoderException(msg, lde);
    }
    searchRequest.setSizeLimit(sizeLimit);
    if (IS_DEBUG) {
        LOG.debug("The sizeLimit value is set to {} objects", Long.valueOf(sizeLimit));
    }
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) LongDecoderException(org.apache.directory.api.asn1.ber.tlv.LongDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) LongDecoderException(org.apache.directory.api.asn1.ber.tlv.LongDecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 29 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.

the class StoreSearchRequestTimeLimit method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequest searchRequest = container.getMessage().getDecorated();
    TLV tlv = container.getCurrentTLV();
    // The current TLV should be a integer
    // We get it and store it in timeLimit
    BerValue value = tlv.getValue();
    int timeLimit = 0;
    try {
        timeLimit = IntegerDecoder.parse(value, 0, Integer.MAX_VALUE);
    } catch (IntegerDecoderException ide) {
        String msg = I18n.err(I18n.ERR_04104, value.toString());
        LOG.error(msg);
        throw new DecoderException(msg, ide);
    }
    searchRequest.setTimeLimit(timeLimit);
    if (IS_DEBUG) {
        LOG.debug("The timeLimit value is set to {} seconds", Integer.valueOf(timeLimit));
    }
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) IntegerDecoderException(org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 30 with TLV

use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.

the class StoreSearchRequestTypesOnly method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    SearchRequest searchRequest = container.getMessage().getDecorated();
    TLV tlv = container.getCurrentTLV();
    // We get the value. If it's a 0, it's a FALSE. If it's
    // a FF, it's a TRUE. Any other value should be an error,
    // but we could relax this constraint. So if we have
    // something
    // which is not 0, it will be interpreted as TRUE, but we
    // will generate a warning.
    BerValue 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(), bde);
    }
    if (IS_DEBUG) {
        LOG.debug("The search will return {}", searchRequest.getTypesOnly() ? "only attributs type" : "attributes types and values");
    }
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) BooleanDecoderException(org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException) DecoderException(org.apache.directory.api.asn1.DecoderException) BooleanDecoderException(org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException) BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Aggregations

TLV (org.apache.directory.api.asn1.ber.tlv.TLV)92 DecoderException (org.apache.directory.api.asn1.DecoderException)54 BerValue (org.apache.directory.api.asn1.ber.tlv.BerValue)19 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)17 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)12 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)10 Dn (org.apache.directory.api.ldap.model.name.Dn)10 IntegerDecoderException (org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException)9 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)7 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)6 BooleanDecoderException (org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException)5 Filter (org.apache.directory.api.ldap.codec.search.Filter)5 SubstringFilter (org.apache.directory.api.ldap.codec.search.SubstringFilter)5 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)5 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)5 ResultResponse (org.apache.directory.api.ldap.model.message.ResultResponse)5 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)4 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)4 AddRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator)4 ModifyRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator)4