Search in sources :

Example 46 with TLV

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

the class AbstractReadInteger method action.

/**
 * {@inheritDoc}
 */
@Override
public final void action(E container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    // The Length should not be null
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_01101_NULL_LENGTH);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
    BerValue value = tlv.getValue();
    try {
        int number = IntegerDecoder.parse(value, minValue, maxValue);
        if (IS_DEBUG) {
            LOG.debug(I18n.msg(I18n.MSG_01100_INTEGER_VALUE, number));
        }
        setIntegerValue(number, container);
    } catch (IntegerDecoderException ide) {
        LOG.error(I18n.err(I18n.ERR_01102_INVALID_INTEGER, Strings.dumpBytes(value.getData()), ide.getLocalizedMessage()));
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(ide.getMessage(), ide);
    }
}
Also used : 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 47 with TLV

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

the class CheckNotNullLength method action.

/**
 * {@inheritDoc}
 */
@Override
public void action(C container) throws DecoderException {
    TLV tlv = container.getCurrentTLV();
    // The Length should not be null
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_01101_NULL_LENGTH);
        LOG.error(msg);
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(msg);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 48 with TLV

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

the class Asn1Decoder method isTLVDecoded.

/**
 * Check if the TLV tree is fully decoded
 *
 * @param container The container
 * @return <code>true</code> if the TLV has been decoded
 */
private boolean isTLVDecoded(Asn1Container container) {
    TLV current = container.getCurrentTLV();
    TLV parent = current.getParent();
    while (parent != null) {
        if (parent.getExpectedLength() != 0) {
            return false;
        }
        parent = parent.getParent();
    }
    BerValue value = current.getValue();
    if ((value != null) && (value.getData() != null)) {
        return current.getExpectedLength() == value.getData().length;
    } else {
        return current.getExpectedLength() == 0;
    }
}
Also used : BerValue(org.apache.directory.api.asn1.ber.tlv.BerValue) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 49 with TLV

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

the class Asn1Decoder method treatValuePendingState.

/**
 * Treat a pending Value when we get more bytes in the buffer.
 *
 * @param stream The ByteBuffer containing the PDU to decode
 * @param container The container that stores the current state,
 * the result and other informations.
 * @return <code>MORE</code> if some bytes remain in the buffer when the
 * value has been decoded, <code>END</code> if whe still need to get some
 * more bytes.
 */
private boolean treatValuePendingState(ByteBuffer stream, Asn1Container container) {
    TLV currentTlv = container.getCurrentTLV();
    int length = currentTlv.getLength();
    int currentLength = currentTlv.getValue().getCurrentLength();
    int nbBytes = stream.remaining();
    if ((currentLength + nbBytes) < length) {
        currentTlv.getValue().addData(stream);
        container.setState(TLVStateEnum.VALUE_STATE_PENDING);
        return END;
    } else {
        int remaining = length - currentLength;
        byte[] data = new byte[remaining];
        stream.get(data, 0, remaining);
        currentTlv.getValue().addData(data);
        container.setState(TLVStateEnum.TLV_STATE_DONE);
        return MORE;
    }
}
Also used : TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 50 with TLV

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

the class Asn1Decoder method getParentLength.

/**
 * A debug function used to dump the expected length stack.
 *
 * @param tlv The current TLV.
 * @return A string which represent the expected length stack.
 */
private String getParentLength(TLV tlv) {
    StringBuilder buffer = new StringBuilder();
    buffer.append("TLV expected length stack : ");
    TLV currentTlv = tlv;
    while (true) {
        if (currentTlv == null) {
            buffer.append(" - null");
            break;
        } else {
            buffer.append(" - ").append(currentTlv.getExpectedLength());
        }
        currentTlv = currentTlv.getParent();
    }
    return buffer.toString();
}
Also used : 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