use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreControlCriticality method action.
/**
* {@inheritDoc}
*/
public void action(ControlsContainer container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
// Get the current control
Control control = container.getCurrentControl();
// Store the criticality
// 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 {
control.setCritical(BooleanDecoder.parse(value));
} catch (BooleanDecoderException bde) {
LOG.error(I18n.err(I18n.ERR_04100_BAD_CONTROL_CRITICALITY, Strings.dumpBytes(value.getData()), bde.getMessage()));
// This will generate a PROTOCOL_ERROR
throw new DecoderException(bde.getMessage(), bde);
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Control criticality : {}", control.isCritical());
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreControlValue method action.
/**
* {@inheritDoc}
*/
@Override
public void action(ControlsContainer container) {
TLV tlv = container.getCurrentTLV();
CodecControl<?> control = container.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());
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Control value : {}", Strings.dumpBytes(control.getValue()));
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class SearchRequestDecorator method unstackFilters.
/**
* This method is used to clear the filter's stack for terminated elements. An element
* is considered as terminated either if :
* - it's a final element (ie an element which cannot contains a Filter)
* - its current length equals its expected length.
*
* @param container The container being decoded
*/
@SuppressWarnings("unchecked")
public void unstackFilters(Asn1Container container) {
LdapMessageContainer<MessageDecorator<Message>> ldapMessageContainer = (LdapMessageContainer<MessageDecorator<Message>>) container;
TLV tlv = ldapMessageContainer.getCurrentTLV();
TLV localParent = tlv.getParent();
Filter localFilter = terminalFilter;
// The parent has been completed, so fold it
while ((localParent != null) && (localParent.getExpectedLength() == 0)) {
int parentTlvId = localFilter.getParent() != null ? localFilter.getParent().getTlvId() : localFilter.getParentTlvId();
if (localParent.getId() != parentTlvId) {
localParent = localParent.getParent();
} else {
Filter filterParent = localFilter.getParent();
// pushed on the stack, so we need to get its parent's parent
if (localFilter instanceof PresentFilter) {
if (filterParent == null) {
// We don't have parent, get out
break;
}
filterParent = filterParent.getParent();
} else {
filterParent = filterParent.getParent();
}
if (filterParent != null) {
// The parent is a filter ; it will become the new currentFilter
// and we will loop again.
localFilter = currentFilter;
currentFilter = filterParent;
localParent = localParent.getParent();
} else {
// We can stop the recursion, we have reached the searchResult Object
break;
}
}
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreSubstringFilterType method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
SearchRequestDecorator searchRequestDecorator = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Store the value.
SubstringFilter substringFilter = (SubstringFilter) searchRequestDecorator.getTerminalFilter();
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04106);
LOG.error(msg);
throw new DecoderException(msg);
} else {
String type = Strings.utf8ToString(tlv.getValue().getData());
substringFilter.setType(type);
// We now have to get back to the nearest filter which
// is not terminal.
searchRequestDecorator.setTerminalFilter(substringFilter);
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class InitUnbindRequest method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<UnbindRequestDecorator> container) throws DecoderException {
// Create the UnbindRequest LdapMessage instance and store it in the container
UnbindRequest unbindRequestInternal = new UnbindRequestImpl();
unbindRequestInternal.setMessageId(container.getMessageId());
UnbindRequestDecorator unbindRequest = new UnbindRequestDecorator(container.getLdapCodecService(), unbindRequestInternal);
container.setMessage(unbindRequest);
TLV tlv = container.getCurrentTLV();
int expectedLength = tlv.getLength();
// The Length should be null
if (expectedLength != 0) {
LOG.error(I18n.err(I18n.ERR_04071, Integer.valueOf(expectedLength)));
// This will generate a PROTOCOL_ERROR
throw new DecoderException(I18n.err(I18n.ERR_04072));
}
// We can quit now
container.setGrammarEndAllowed(true);
}
Aggregations