use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreExtendedRequestValue method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ExtendedRequestDecorator<?>> container) throws DecoderException {
// We can allocate the ExtendedRequest Object
ExtendedRequestDecorator<?> extendedRequest = container.getMessage();
// Get the Value and store it in the ExtendedRequest
TLV tlv = container.getCurrentTLV();
// value
if (tlv.getLength() == 0) {
extendedRequest.setRequestValue(Strings.EMPTY_BYTES);
} else {
extendedRequest.setRequestValue(tlv.getValue().getData());
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Extended value : {}", extendedRequest.getRequestValue());
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class AddModifyRequestAttribute method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
ModifyRequest modifyRequest = modifyRequestDecorator.getDecorated();
TLV tlv = container.getCurrentTLV();
// Store the value. It can't be null
String type;
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04083);
LOG.error(msg);
ModifyResponseImpl response = new ModifyResponseImpl(modifyRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, modifyRequest.getName(), null);
} else {
type = Strings.utf8ToString(tlv.getValue().getData());
modifyRequestDecorator.addAttributeTypeAndValues(type);
}
if (IS_DEBUG) {
LOG.debug("Modifying type : {}", type);
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreModifyRequestAttributeValue method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) {
ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Store the value. It can't be null
byte[] value = Strings.EMPTY_BYTES;
try {
if (tlv.getLength() == 0) {
modifyRequestDecorator.addAttributeValue("");
} else {
value = tlv.getValue().getData();
if (container.isBinary(modifyRequestDecorator.getCurrentAttributeType())) {
modifyRequestDecorator.addAttributeValue(value);
} else {
modifyRequestDecorator.addAttributeValue(Strings.utf8ToString((byte[]) value));
}
}
} catch (LdapException le) {
// Just swallow the exception, it can't occur here
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Value modified : {}", value);
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class CheckLengthNotNull method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
int expectedLength = tlv.getLength();
// The Length should be null
if (expectedLength == 0) {
String msg = I18n.err(I18n.ERR_04096_NULL_CONTROL_LENGTH);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class AddControl method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
// We have to handle the special case of a 0 length OID
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04097_NULL_CONTROL_OID);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
}
byte[] value = tlv.getValue().getData();
String oidValue = Strings.asciiBytesToString(value);
// The OID is encoded as a String, not an Object Id
if (!Oid.isOid(oidValue)) {
String msg = I18n.err(I18n.ERR_04098_INVALID_CONTROL_OID, oidValue);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
}
Message message = container.getMessage();
Control control = container.getLdapCodecService().newControl(oidValue);
message.addControl(control);
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Control OID : {}", oidValue);
}
}
Aggregations