You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/07/27 01:43:20 UTC
svn commit: r798005 - in /directory:
apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/bind/
apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/
apacheds/trunk/core/src/main/java/org/apache/direct...
Author: elecharny
Date: Sun Jul 26 23:43:19 2009
New Revision: 798005
URL: http://svn.apache.org/viewvc?rev=798005&view=rev
Log:
Fix for DIRSERVER-1276 :
o Filters now store values as a byte[] on the client side, and accordingly to the AT on the server side
o Modified the Nodes, Evaluator, grammar ... accordingly
o Fixed the specific tests
Modified:
directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/bind/SimpleBindIT.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluator.java
directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java
directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java
directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreMatchValueAction.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/ExtensibleMatchFilter.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ApproximateNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/bind/SimpleBindIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/bind/SimpleBindIT.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/bind/SimpleBindIT.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/operations/bind/SimpleBindIT.java Sun Jul 26 23:43:19 2009
@@ -189,7 +189,7 @@
}
catch ( InvalidNameException ine )
{
- assertEquals( "Bad DN : admin", ine.getMessage() );
+ assertEquals( "No more characters available at position 5", ine.getMessage() );
}
catch ( NamingException ne )
{
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java Sun Jul 26 23:43:19 2009
@@ -30,6 +30,8 @@
import org.apache.directory.shared.ldap.NotImplementedException;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.filter.ApproximateNode;
import org.apache.directory.shared.ldap.filter.EqualityNode;
import org.apache.directory.shared.ldap.filter.ExprNode;
@@ -43,6 +45,7 @@
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.MatchingRule;
import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.util.StringTools;
/**
@@ -258,13 +261,32 @@
}
// check if AVA value exists in attribute
- if ( attr.contains( node.getValue() ) )
+ AttributeType at = attributeTypeRegistry.lookup( node.getAttribute() );
+ Value<?> value = null;
+
+ if ( at.getSyntax().isHumanReadable() )
+ {
+ if ( node.getValue() instanceof ClientBinaryValue )
+ {
+ value = new ClientStringValue( StringTools.utf8ToString( (byte[])node.getValue().get() ) );
+ }
+ else
+ {
+ value = node.getValue();
+ }
+ }
+ else
+ {
+ value = node.getValue();
+ }
+
+ if ( attr.contains( value ) )
{
return true;
}
// get the normalized AVA filter value
- Object filterValue = normalizer.normalize( node.getValue().get() );
+ Object filterValue = normalizer.normalize( value.get() );
// check if the normalized value is present
if ( filterValue instanceof String )
@@ -284,9 +306,9 @@
* a lookup to work. For each value we normalize and use the comparator
* to determine if a match exists.
*/
- for ( Value<?> value : attr )
+ for ( Value<?> val : attr )
{
- Object normValue = normalizer.normalize( value.get() );
+ Object normValue = normalizer.normalize( val.get() );
if ( 0 == comparator.compare( normValue, filterValue ) )
{
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/NormalizationInterceptor.java Sun Jul 26 23:43:19 2009
@@ -48,6 +48,9 @@
import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
import org.apache.directory.server.schema.registries.OidRegistry;
import org.apache.directory.shared.ldap.cursor.EmptyCursor;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.filter.ExprNode;
import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
import org.apache.directory.shared.ldap.name.LdapDN;
@@ -55,6 +58,7 @@
import org.apache.directory.shared.ldap.name.Rdn;
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -258,6 +262,15 @@
public boolean compare( NextInterceptor next, CompareOperationContext opContext ) throws Exception
{
opContext.getDn().normalize( attrNormalizers );
+
+ AttributeType at = opContext.getSession().getDirectoryService().getRegistries().getAttributeTypeRegistry().lookup( opContext.getOid() );
+
+ if ( at.getSyntax().isHumanReadable() && ( opContext.getValue() instanceof ClientBinaryValue ) )
+ {
+ String value = StringTools.utf8ToString( ((Value<byte[]>)opContext.getValue()).get() );
+ opContext.setValue( new ClientStringValue( value ) );
+ }
+
return next.compare( opContext );
}
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluator.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluator.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluator.java Sun Jul 26 23:43:19 2009
@@ -97,20 +97,26 @@
}
// check if AVA value exists in attribute
- if ( objectClasses.contains( node.getValue() ) )
- {
- return true;
- }
-
// If the filter value for the objectClass is an OID we need to resolve a name
String value = null;
+
if ( node.getValue() instanceof ClientStringValue )
{
value = ( String ) node.getValue().get();
+
+ if ( objectClasses.contains( value ) )
+ {
+ return true;
+ }
}
else if ( node.getValue() instanceof ClientBinaryValue )
{
- value = "#" + StringTools.toHexString( ( byte[] ) node.getValue().get() );
+ value = StringTools.utf8ToString( ( byte[] ) node.getValue().get() );
+
+ if ( objectClasses.contains( value ) )
+ {
+ return true;
+ }
}
else
{
@@ -124,6 +130,7 @@
while ( list.hasNext() )
{
String objectClass = ( String ) list.next();
+
if ( objectClasses.contains( objectClass ) )
{
return true;
Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java (original)
+++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/SearchIT.java Sun Jul 26 23:43:19 2009
@@ -46,6 +46,17 @@
import javax.naming.ldap.Control;
import javax.naming.ldap.LdapContext;
+import netscape.ldap.LDAPAsynchronousConnection;
+import netscape.ldap.LDAPAttribute;
+import netscape.ldap.LDAPAttributeSet;
+import netscape.ldap.LDAPConnection;
+import netscape.ldap.LDAPEntry;
+import netscape.ldap.LDAPException;
+import netscape.ldap.LDAPMessage;
+import netscape.ldap.LDAPSearchListener;
+import netscape.ldap.LDAPSearchResults;
+import netscape.ldap.LDAPUrl;
+
import org.apache.directory.server.core.integ.Level;
import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
import org.apache.directory.server.core.integ.annotations.CleanupLevel;
@@ -54,6 +65,7 @@
import org.apache.directory.server.ldap.LdapServer;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.message.control.SubentriesControl;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -1625,4 +1637,68 @@
result.close();
}
+ /**
+ * test an abandonned search request.
+ */
+ @Ignore
+ @Test
+ public void testAbandonnedRequest() throws Exception
+ {
+ LDAPConnection asyncCnx = new LDAPConnection();
+
+ try
+ {
+ // Use the netscape API as JNDI cannot be used to do a search without
+ // first binding.
+ //conn.connect( 3, "localhost", ldapServer.getPort(), "uid=admin,ou=system", "secret" );
+
+ asyncCnx.connect( 3, "localhost", ldapServer.getPort(), "uid=admin,ou=system", "secret" );
+
+ // First, add 1000 entries in the server
+ for ( int i = 0; i < 1000; i++ )
+ {
+ LDAPAttributeSet attrs = new LDAPAttributeSet();
+ LDAPAttribute ocls = new LDAPAttribute( "objectclass", new String[]
+ { "top", "person" } );
+ attrs.add( ocls );
+ attrs.add( new LDAPAttribute( "sn", "Bush" ) );
+ attrs.add( new LDAPAttribute( "cn", "user" + i ) );
+
+ String dn = "cn=user" + i + "," + BASE;
+ LDAPEntry kate = new LDAPEntry( dn, attrs );
+
+ asyncCnx.add( kate );
+ }
+
+ // Searches for all the entries in ou=system
+ LDAPSearchListener listener = asyncCnx.search( "ou=system", LDAPConnection.SCOPE_SUB,
+ "(ObjectClass=*)", new String[]{"*"}, false, (LDAPSearchListener)null);
+
+ // Now loop on all the elements found, and abandon after 10 elements returned
+ int count = 0;
+ LDAPMessage msg = null;
+
+ while ( (msg = listener.getResponse() ) != null )
+ {
+ count++;
+
+ if ( count == 10 )
+ {
+ //asyncCnx.abandon( msg.getMessageID() );
+ }
+ }
+
+ assertEquals( 100, count );
+ }
+ catch ( LDAPException e )
+ {
+ e.printStackTrace();
+ fail( "Should not have caught exception." );
+ }
+ finally
+ {
+ // Reset the allowAnonymousAccess flag
+ asyncCnx.disconnect();
+ }
+ }
}
Modified: directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java (original)
+++ directory/apacheds/trunk/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java Sun Jul 26 23:43:19 2009
@@ -27,7 +27,9 @@
import org.apache.directory.shared.ldap.schema.comparators.ByteArrayComparator;
import org.apache.directory.shared.ldap.schema.comparators.StringComparator;
import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
import org.apache.directory.server.xdbm.IndexEntry;
import org.apache.directory.server.xdbm.Store;
import org.apache.directory.server.xdbm.Index;
@@ -222,7 +224,16 @@
{
// Deal with a String value
String serverValue = ((Value<String>)value).getNormalizedValue();
- String nodeValue = ((Value<String>)node.getValue()).getNormalizedValue();
+ String nodeValue = null;
+
+ if ( node.getValue() instanceof ClientBinaryValue )
+ {
+ nodeValue = StringTools.utf8ToString( ((Value<byte[]>)node.getValue()).getNormalizedValue() );
+ }
+ else
+ {
+ nodeValue = ((Value<String>)node.getValue()).getNormalizedValue();
+ }
if ( comparator != null )
{
Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java (original)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java Sun Jul 26 23:43:19 2009
@@ -48,6 +48,7 @@
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.filter.ExprNode;
import org.apache.directory.shared.ldap.filter.FilterParser;
+import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.*;
import static org.junit.Assert.*;
import org.slf4j.Logger;
@@ -160,12 +161,14 @@
assertTrue( cursor.next() );
assertTrue( cursor.available() );
assertEquals( 7, ( long ) cursor.get().getId() );
- assertEquals( "apache", cursor.get().getValue() );
+ assertEquals( "apache",
+ StringTools.utf8ToString( (byte[])cursor.get().getValue() ) );
assertTrue( cursor.next() );
assertTrue( cursor.available() );
assertEquals( 9, ( long ) cursor.get().getId() );
- assertEquals( "apache", cursor.get().getValue() );
+ assertEquals( "apache",
+ StringTools.utf8ToString( (byte[])cursor.get().getValue() ) );
assertFalse( cursor.next() );
}
Modified: directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java (original)
+++ directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/request/Dsmlv2Grammar.java Sun Jul 26 23:43:19 2009
@@ -2619,11 +2619,14 @@
{
if ( ParserUtils.isBase64BinaryValue( xpp, typeValue ) )
{
- filter.setMatchValue( Base64.decode( nextText.trim().toCharArray() ) );
+ filter.setMatchValue(
+ new ClientBinaryValue(
+ Base64.decode( nextText.trim().toCharArray() ) ) );
}
else
{
- filter.setMatchValue( nextText.trim() );
+ filter.setMatchValue(
+ new ClientStringValue( nextText.trim() ) );
}
}
}
Modified: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java (original)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/shared/dsmlv2/searchRequest/SearchRequestTest.java Sun Jul 26 23:43:19 2009
@@ -40,6 +40,7 @@
import org.apache.directory.shared.ldap.codec.search.SearchRequestCodec;
import org.apache.directory.shared.ldap.codec.search.SubstringFilter;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.filter.SearchScope;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -1544,7 +1545,7 @@
ExtensibleMatchFilter extensibleMatchFilter = ( ExtensibleMatchFilter ) filter;
- assertEquals( "A Value", extensibleMatchFilter.getMatchValue() );
+ assertEquals( "A Value", extensibleMatchFilter.getMatchValue().get() );
assertEquals( false, extensibleMatchFilter.isDnAttributes() );
}
@@ -1578,7 +1579,7 @@
ExtensibleMatchFilter extensibleMatchFilter = ( ExtensibleMatchFilter ) filter;
- assertEquals( "DSMLv2.0 rocks!!", new String( ( byte[] ) extensibleMatchFilter.getMatchValue() ) );
+ assertEquals( "DSMLv2.0 rocks!!", new String( ( byte[] ) extensibleMatchFilter.getMatchValue().get() ) );
assertEquals( false, extensibleMatchFilter.isDnAttributes() );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/TwixTransformer.java Sun Jul 26 23:43:19 2009
@@ -69,6 +69,7 @@
import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.filter.AndNode;
import org.apache.directory.shared.ldap.filter.ApproximateNode;
import org.apache.directory.shared.ldap.filter.BranchNode;
@@ -558,28 +559,14 @@
attribute = filter.getType();
}
- Object value = filter.getMatchValue();
+ Value<?> value = filter.getMatchValue();
if ( filter.getMatchingRule() != null )
{
matchingRule = filter.getMatchingRule();
}
- if ( value instanceof String )
- {
- branch = new ExtensibleNode( attribute, (String)value, matchingRule, filter.isDnAttributes() );
- }
- else
- {
- if ( value != null )
- {
- branch = new ExtensibleNode( attribute, (byte[])value, matchingRule, filter.isDnAttributes() );
- }
- else
- {
- branch = new ExtensibleNode( attribute, (byte[])null, matchingRule, filter.isDnAttributes() );
- }
- }
+ branch = new ExtensibleNode( attribute, value, matchingRule, filter.isDnAttributes() );
}
return branch;
@@ -718,7 +705,7 @@
String attribute = ((ExtensibleNode)exprNode).getAttribute();
String matchingRule = ((ExtensibleNode)exprNode).getMatchingRuleId();
boolean dnAttributes = ((ExtensibleNode)exprNode).hasDnAttributes();
- Object value = ((ExtensibleNode)exprNode).getValue();
+ Value<?> value = ((ExtensibleNode)exprNode).getValue();
if ( attribute != null )
{
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreMatchValueAction.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreMatchValueAction.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreMatchValueAction.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/StoreMatchValueAction.java Sun Jul 26 23:43:19 2009
@@ -28,7 +28,7 @@
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.search.ExtensibleMatchFilter;
import org.apache.directory.shared.ldap.codec.search.SearchRequestCodec;
-import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -68,8 +68,8 @@
ExtensibleMatchFilter extensibleMatchFilter = ( ExtensibleMatchFilter ) searchRequest
.getTerminalFilter();
- String value = StringTools.utf8ToString( tlv.getValue().getData() );
- extensibleMatchFilter.setMatchValue( value );
+ byte[] value = tlv.getValue().getData();
+ extensibleMatchFilter.setMatchValue( new ClientBinaryValue( value ) );
// unstack the filters if needed
searchRequest.unstackFilters( container );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/ExtensibleMatchFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/ExtensibleMatchFilter.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/ExtensibleMatchFilter.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/ExtensibleMatchFilter.java Sun Jul 26 23:43:19 2009
@@ -27,6 +27,8 @@
import org.apache.directory.shared.asn1.ber.tlv.Value;
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.ldap.codec.LdapConstants;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -56,7 +58,7 @@
private byte[] typeBytes;
/** Matching rule value */
- private Object matchValue;
+ private org.apache.directory.shared.ldap.entry.Value<?> matchValue;
/** The dnAttributes flag */
private boolean dnAttributes = false;
@@ -138,7 +140,7 @@
*
* @return Returns the matchValue.
*/
- public Object getMatchValue()
+ public org.apache.directory.shared.ldap.entry.Value<?> getMatchValue()
{
return matchValue;
}
@@ -149,7 +151,7 @@
*
* @param matchValue The matchValue to set.
*/
- public void setMatchValue( Object matchValue )
+ public void setMatchValue( org.apache.directory.shared.ldap.entry.Value<?> matchValue )
{
this.matchValue = matchValue;
}
@@ -225,15 +227,15 @@
if ( matchValue != null )
{
- if ( matchValue instanceof String )
+ if ( matchValue instanceof ClientStringValue )
{
- int matchValueLength = StringTools.getBytesUtf8( ( String ) matchValue ).length;
+ int matchValueLength = (( ClientStringValue ) matchValue ).get().length();
extensibleMatchLength += 1 + TLV.getNbBytes( matchValueLength ) + matchValueLength;
}
else
{
- extensibleMatchLength += 1 + TLV.getNbBytes( ( ( byte[] ) matchValue ).length )
- + ( ( byte[] ) matchValue ).length;
+ int bytesLength = ( (ClientBinaryValue) matchValue ).get().length;
+ extensibleMatchLength += 1 + TLV.getNbBytes( bytesLength ) + bytesLength;
}
}
@@ -304,9 +306,9 @@
{
buffer.put( ( byte ) LdapConstants.MATCH_VALUE_TAG );
- if ( matchValue instanceof String )
+ if ( matchValue instanceof ClientStringValue )
{
- byte[] matchValueBytes = StringTools.getBytesUtf8( ( String ) matchValue );
+ byte[] matchValueBytes = StringTools.getBytesUtf8( (( ClientStringValue ) matchValue).get() );
buffer.put( TLV.getBytes( matchValueBytes.length ) );
if ( matchValueBytes.length != 0 )
@@ -316,11 +318,12 @@
}
else
{
- buffer.put( TLV.getBytes( ( ( byte[] ) matchValue ).length ) );
+ int bytesLength = ( ( ClientBinaryValue ) matchValue ).get().length;
+ buffer.put( TLV.getBytes( bytesLength ) );
- if ( ( ( byte[] ) matchValue ).length != 0 )
+ if ( bytesLength != 0 )
{
- buffer.put( ( byte[] ) matchValue );
+ buffer.put( ((ClientBinaryValue)matchValue).get() );
}
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/AbstractExprNode.java Sun Jul 26 23:43:19 2009
@@ -23,6 +23,11 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.util.StringTools;
+
/**
* Abstract implementation of a expression node.
@@ -144,17 +149,64 @@
* @param value Right hand side of "attrId=value" assertion occurring in an LDAP search filter.
* @return Escaped version of <code>value</code>
*/
- protected static String escapeFilterValue( Object value )
+ protected static Value<?> escapeFilterValue( Value<?> value )
{
StringBuilder sb = null;
String val;
- if ( !( value instanceof String ) )
+ if ( !( value instanceof ClientStringValue ) )
{
- return value.toString();
+ sb = new StringBuilder( ((ClientBinaryValue)value).getReference().length * 3 );
+
+ for ( byte b:((ClientBinaryValue)value).getReference() )
+ {
+ if ( ( b < 0x7F ) && ( b >= 0 ) )
+ {
+ switch ( b )
+ {
+ case '*' :
+ sb.append( "\\2A" );
+ break;
+
+ case '(' :
+ sb.append( "\\28" );
+ break;
+
+ case ')' :
+ sb.append( "\\29" );
+ break;
+
+ case '\\' :
+ sb.append( "\\5C" );
+ break;
+
+ case '\0' :
+ sb.append( "\\00" );
+ break;
+
+ default :
+ sb.append( (char)b );
+ }
+ }
+ else
+ {
+ sb.append( '\\' );
+ String digit = Integer.toHexString( ((byte)b) & 0x00FF );
+
+ if ( digit.length() == 1 )
+ {
+ sb.append( '0' );
+ }
+
+ sb.append( digit.toUpperCase() );
+ }
+ }
+
+ return new ClientStringValue( sb.toString() );
}
- val = ( String ) value;
+ val = ( ( ClientStringValue ) value ).get();
+
for ( int i = 0; i < val.length(); i++ )
{
char ch = val.charAt( i );
@@ -163,21 +215,26 @@
switch ( ch )
{
case '*':
- replace = "\\2a";
+ replace = "\\2A";
break;
+
case '(':
replace = "\\28";
break;
+
case ')':
replace = "\\29";
break;
+
case '\\':
- replace = "\\5c";
+ replace = "\\5C";
break;
+
case '\0':
replace = "\\00";
break;
}
+
if ( replace != null )
{
if ( sb == null )
@@ -193,7 +250,7 @@
}
}
- return ( sb == null ? val : sb.toString() );
+ return ( sb == null ? value : new ClientStringValue( sb.toString() ) );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ApproximateNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ApproximateNode.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ApproximateNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ApproximateNode.java Sun Jul 26 23:43:19 2009
@@ -58,7 +58,7 @@
{
StringBuilder buf = new StringBuilder();
- buf.append( '(' ).append( getAttribute() ).append( "~=" ).append( getValueEscaped() );
+ buf.append( '(' ).append( getAttribute() ).append( "~=" ).append( getEscapedValue() );
buf.append( super.toString() );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/EqualityNode.java Sun Jul 26 23:43:19 2009
@@ -74,7 +74,7 @@
{
StringBuilder buf = new StringBuilder();
- buf.append( '(' ).append( getAttribute() ).append( "=" ).append( getValueEscaped() );
+ buf.append( '(' ).append( getAttribute() ).append( "=" ).append( getEscapedValue() );
buf.append( super.toString() );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/ExtensibleNode.java Sun Jul 26 23:43:19 2009
@@ -22,6 +22,9 @@
import java.util.Arrays;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -34,7 +37,7 @@
public class ExtensibleNode extends LeafNode
{
/** The value of the attribute to match for */
- private byte[] value;
+ private Value<?> value;
/** The matching rules id */
private String matchingRuleId;
@@ -63,32 +66,11 @@
* @param matchingRuleId the OID of the matching rule
* @param dnAttributes the dn attributes
*/
- public ExtensibleNode(String attribute, String value, String matchingRuleId, boolean dnAttributes)
- {
- this( attribute, StringTools.getBytesUtf8( value ), matchingRuleId, dnAttributes );
- }
-
-
- /**
- * Creates a new ExtensibleNode object.
- *
- * @param attribute the attribute used for the extensible assertion
- * @param value the value to match for
- * @param matchingRuleId the OID of the matching rule
- * @param dnAttributes the dn attributes
- */
- public ExtensibleNode( String attribute, byte[] value, String matchingRuleId, boolean dnAttributes )
+ public ExtensibleNode( String attribute, Value<?> value, String matchingRuleId, boolean dnAttributes )
{
super( attribute, AssertionType.EXTENSIBLE );
- if ( value != null )
- {
- this.value = new byte[ value.length ];
- System.arraycopy( value, 0, this.value, 0, value.length );
- } else {
- this.value = null;
- }
-
+ this.value = value;
this.matchingRuleId = matchingRuleId;
this.dnAttributes = dnAttributes;
}
@@ -160,27 +142,34 @@
*
* @return the value
*/
- public final byte[] getValue()
+ public final Value<?> getValue()
+ {
+ return value;
+ }
+
+
+ /**
+ * @return representation of value, escaped for use in a filter if required
+ */
+ public Value<?> getEscapedValue()
{
- if ( value == null )
+ if ( value instanceof ClientStringValue )
{
- return null;
+ return AbstractExprNode.escapeFilterValue( value );
}
-
- final byte[] copy = new byte[ value.length ];
- System.arraycopy( value, 0, copy, 0, value.length );
- return copy;
+
+ return value;
}
-
+
/**
* Sets the value.
*
* @param value the value
*/
- public final void setValue( String value)
+ public final void setValue( Value<?> value)
{
- this.value = StringTools.getBytesUtf8( value );
+ this.value = value;
}
@@ -195,7 +184,7 @@
h = h*17 + super.hashCode();
h = h*17 + ( dnAttributes ? 1 : 0 );
h = h*17 + matchingRuleId.hashCode();
- h = h*17 + Arrays.hashCode( value );
+ h = h*17 + value.hashCode();
return h;
}
@@ -215,9 +204,7 @@
buf.append( "-EXTENSIBLE-" );
buf.append( matchingRuleId );
buf.append( "-" );
- buf.append( StringTools.utf8ToString( value ) );
- buf.append( "/" );
- buf.append( StringTools.dumpBytes( value ) );
+ buf.append( value );
buf.append( super.toString() );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/FilterParser.java Sun Jul 26 23:43:19 2009
@@ -22,8 +22,8 @@
import java.text.ParseException;
-import javax.naming.InvalidNameException;
-
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.util.AttributeUtils;
import org.apache.directory.shared.ldap.util.Position;
@@ -211,17 +211,20 @@
* HEX = '0'-'9' / 'A'-'F' / 'a'-'f'
* unicodeSubset = %x01-27 / %x2B-5B / %x5D-FFFF
*/
- private static String parseAssertionValue( String filter, Position pos, boolean preserveEscapedChars ) throws ParseException
+ private static Value<?> parseAssertionValue( String filter, Position pos, boolean preserveEscapedChars ) throws ParseException
{
int start = pos.start;
- boolean foundHex = false;
-
char c = StringTools.charAt( filter, pos.start );
+
+ // Create a buffer big enough to contain the value once converted
+ byte[] value = new byte[ filter.length() - pos.start];
+ int current = 0;
do
{
if ( StringTools.isUnicodeSubset( c ) )
{
+ value[current++] = (byte)c;
pos.start++;
}
else if ( StringTools.isCharASCII( filter, pos.start, '\\' ) )
@@ -242,8 +245,8 @@
// second hex
if ( StringTools.isHex( filter, pos.start ) )
{
+ value[current++] = StringTools.getHexValue( filter.charAt( pos.start - 1 ), filter.charAt( pos.start ) );
pos.start++;
- foundHex = true;
}
else
{
@@ -258,23 +261,21 @@
}
while ( ( c = StringTools.charAt( filter, pos.start ) ) != '\0' );
- String ret = filter.substring( start, pos.start );
- if ( !preserveEscapedChars && foundHex )
+ if ( current != 0 )
{
- try
- {
- ret = StringTools.decodeEscapedHex( ret );
- }
- catch ( InvalidNameException e )
- {
- throw new ParseException( "Unable to decode escaped hex sequences: '" + ret + "': " + e, pos.start );
- }
+ byte[] result = new byte[ current ];
+ System.arraycopy( value, 0, result, 0, current );
+
+ return new ClientBinaryValue( result );
+ }
+ else
+ {
+ return new ClientBinaryValue();
}
- return ret;
}
- private static String parseAssertionValue( String filter, Position pos ) throws ParseException
+ private static Value<?> parseAssertionValue( String filter, Position pos ) throws ParseException
{
return parseAssertionValue( filter, pos, false );
}
@@ -283,7 +284,7 @@
/**
* Parse a substring
*/
- private static ExprNode parseSubstring( String attr, String initial, String filter, Position pos )
+ private static ExprNode parseSubstring( String attr, Value<?> initial, String filter, Position pos )
throws ParseException
{
if ( StringTools.isCharASCII( filter, pos.start, '*' ) )
@@ -291,11 +292,12 @@
// We have found a '*' : this is a substring
SubstringNode node = new SubstringNode( attr );
- if ( !StringTools.isEmpty( initial ) )
+ if ( initial != null && !initial.isNull() )
{
// We have a substring starting with a value : val*...
- // Set the initial value
- node.setInitial( initial );
+ // Set the initial value. It must be a String
+ String initialStr = StringTools.utf8ToString( (byte[])initial.get() );
+ node.setInitial( initialStr );
}
pos.start++;
@@ -303,16 +305,17 @@
//
while ( true )
{
- String assertionValue = parseAssertionValue( filter, pos );
+ Value<?> assertionValue = parseAssertionValue( filter, pos );
// Is there anything else but a ')' after the value ?
if ( StringTools.isCharASCII( filter, pos.start, ')' ) )
{
// Nope : as we have had [initial] '*' (any '*' ) *,
// this is the final
- if ( !StringTools.isEmpty( assertionValue ) )
+ if ( !assertionValue.isNull() )
{
- node.setFinal( assertionValue );
+ String finalStr = StringTools.utf8ToString( (byte[])assertionValue.get() );
+ node.setFinal( finalStr );
}
return node;
@@ -322,9 +325,10 @@
// We have a '*' : it's an any
// If the value is empty, that means we have more than
// one consecutive '*' : do nothing in this case.
- if ( !StringTools.isEmpty( assertionValue ) )
+ if ( !assertionValue.isNull() )
{
- node.addAny( assertionValue );
+ String anyStr = StringTools.utf8ToString( (byte[])assertionValue.get() );
+ node.addAny( anyStr );
}
pos.start++;
@@ -374,7 +378,6 @@
if ( StringTools.isCharASCII( filter, pos.start, '*' ) )
{
// To be a present node, the next char should be a ')'
- //StringTools.trimLeft( filter, pos );
pos.start++;
if ( StringTools.isCharASCII( filter, pos.start, ')' ) )
@@ -393,18 +396,18 @@
else if ( StringTools.isCharASCII( filter, pos.start, ')' ) )
{
// An empty equality Node
- return new EqualityNode( attr, new ClientStringValue( "" ) );
+ return new EqualityNode( attr, new ClientBinaryValue() );
}
else
{
// A substring or an equality node
- String value = parseAssertionValue( filter, pos );
+ Value<?> value = parseAssertionValue( filter, pos );
// Is there anything else but a ')' after the value ?
if ( StringTools.isCharASCII( filter, pos.start, ')' ) )
{
// This is an equality node
- return new EqualityNode( attr, new ClientStringValue( value ) );
+ return new EqualityNode( attr, value );
}
return parseSubstring( attr, value, filter, pos );
@@ -430,9 +433,6 @@
LeafNode node = null;
String attr = null;
- // Relax the grammar a bit : we can have spaces
- // StringTools.trimLeft( filter, pos );
-
if ( c == '\0' )
{
throw new ParseException( "Bad char", pos.start );
@@ -448,9 +448,6 @@
// We must have an attribute
attr = AttributeUtils.parseAttribute( filter, pos, true );
- // Relax the grammar a bit : we can have spaces
- // StringTools.trimLeft( filter, pos );
-
// Now, we may have a present, substring, simple or an extensible
c = StringTools.charAt( filter, pos.start );
@@ -474,7 +471,7 @@
pos.start++;
// Parse the value and create the node
- node = new ApproximateNode( attr, new ClientStringValue( parseAssertionValue( filter, pos ) ) );
+ node = new ApproximateNode( attr, parseAssertionValue( filter, pos ) );
return node;
case '>':
@@ -490,7 +487,7 @@
pos.start++;
// Parse the value and create the node
- node = new GreaterEqNode( attr, new ClientStringValue( parseAssertionValue( filter, pos ) ) );
+ node = new GreaterEqNode( attr, parseAssertionValue( filter, pos ) );
return node;
case '<':
@@ -506,7 +503,7 @@
pos.start++;
// Parse the value and create the node
- node = new LessEqNode( attr, new ClientStringValue( parseAssertionValue( filter, pos ) ) );
+ node = new LessEqNode( attr, parseAssertionValue( filter, pos ) );
return node;
case ':':
@@ -536,31 +533,19 @@
{
BranchNode bNode = ( BranchNode ) node;
- // Relax the grammar a bit : we can have spaces
- // StringTools.trimLeft( filter, pos );
-
// We must have at least one filter
ExprNode child = parseFilterInternal( filter, pos );
// Add the child to the node children
bNode.addNode( child );
- // Relax the grammar a bit : we can have spaces
- // StringTools.trimLeft( filter, pos );
-
- // Now, iterate though all the remaining filters, if any
+ // Now, iterate recusively though all the remaining filters, if any
while ( ( child = parseFilterInternal( filter, pos ) ) != null )
{
// Add the child to the node children
bNode.addNode( child );
-
- // Relax the grammar a bit : we can have spaces
- // StringTools.trimLeft( filter, pos );
}
- // Relax the grammar a bit : we can have spaces
- // StringTools.trimLeft( filter, pos );
-
return node;
}
@@ -583,9 +568,6 @@
{
ExprNode node = null;
- // Relax the grammar a bit : we can have spaces
- // StringTools.trimLeft( filter, pos );
-
if ( pos.start == pos.length )
{
throw new ParseException( "Empty filterComp", pos.start );
@@ -633,9 +615,6 @@
*/
private static ExprNode parseFilterInternal( String filter, Position pos ) throws ParseException
{
- // relax the grammar by allowing spaces
- // StringTools.trimLeft( filter, pos );
-
// Check for the left '('
if ( !StringTools.isCharASCII( filter, pos.start, '(' ) )
{
@@ -652,9 +631,6 @@
pos.start++;
- // relax the grammar by allowing spaces
- // StringTools.trimLeft( filter, pos );
-
// parse the filter component
ExprNode node = parseFilterComp( filter, pos );
@@ -663,9 +639,6 @@
throw new ParseException( "Bad filter", pos.start );
}
- // relax the grammar by allowing spaces
- // StringTools.trimLeft( filter, pos );
-
// Check that we have a right ')'
if ( !StringTools.isCharASCII( filter, pos.start, ')' ) )
{
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/GreaterEqNode.java Sun Jul 26 23:43:19 2009
@@ -60,7 +60,7 @@
{
StringBuilder buf = new StringBuilder();
- buf.append( '(' ).append( getAttribute() ).append( ">=" ).append( getValueEscaped() );
+ buf.append( '(' ).append( getAttribute() ).append( ">=" ).append( getEscapedValue() );
buf.append( super.toString() );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LessEqNode.java Sun Jul 26 23:43:19 2009
@@ -60,7 +60,7 @@
{
StringBuilder buf = new StringBuilder();
- buf.append( '(' ).append( getAttribute() ).append( "<=" ).append( getValueEscaped() );
+ buf.append( '(' ).append( getAttribute() ).append( "<=" ).append( getEscapedValue() );
buf.append( super.toString() );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SimpleNode.java Sun Jul 26 23:43:19 2009
@@ -22,6 +22,8 @@
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
/**
@@ -85,15 +87,9 @@
/**
* @return representation of value, escaped for use in a filter if required
*/
- protected Object getValueEscaped()
+ public Value<?> getEscapedValue()
{
- Object valueEscaped = value.get();
-
- if ( valueEscaped instanceof String )
- {
- valueEscaped = AbstractExprNode.escapeFilterValue( valueEscaped );
- }
- return valueEscaped;
+ return AbstractExprNode.escapeFilterValue( value );
}
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/filter/SubstringNode.java Sun Jul 26 23:43:19 2009
@@ -26,6 +26,8 @@
import javax.naming.NamingException;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.schema.Normalizer;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -119,6 +121,15 @@
}
+ /**
+ * @return representation of the inital, escaped for use in a filter if required
+ *
+ public String getEscapedInitial()
+ {
+ return AbstractExprNode.escapeFilterValue( initialPattern );
+ }
+
+
/**
* Gets the initial fragment.
*
@@ -149,6 +160,20 @@
}
+ /**
+ * @return representation of the final, escaped for use in a filter if required
+ *
+ public Value<?> getEscapedFinal()
+ {
+ if ( finalPattern instanceof ClientStringValue )
+ {
+ return AbstractExprNode.escapeFilterValue( finalPattern );
+ }
+
+ return finalPattern;
+ }
+
+
/**
* Set the final pattern
* @param finalPattern The final pattern
@@ -159,6 +184,30 @@
}
+ /**
+ * @return representation of the any, escaped for use in a filter if required
+ *
+ public List<Value<?>> getEscapedAny()
+ {
+ if ( anyPattern != null )
+ {
+ List<Value<?>> anyEscaped = new ArrayList<Value<?>>(anyPattern.size() );
+
+ for ( Value<?> value:anyPattern )
+ {
+ if ( value instanceof ClientStringValue )
+ {
+ anyEscaped.add( AbstractExprNode.escapeFilterValue( value ) );
+ }
+ }
+
+ return anyEscaped;
+ }
+
+ return anyPattern;
+ }
+
+
/**
* Gets the list of wildcard surrounded any fragments.
*
@@ -199,6 +248,8 @@
*/
public final Pattern getRegex( Normalizer normalizer ) throws NamingException
{
+ boolean isBinary = false;
+
if ( ( anyPattern != null ) && ( anyPattern.size() > 0 ) )
{
String[] any = new String[anyPattern.size()];
@@ -285,7 +336,7 @@
if ( null != initialPattern )
{
- buf.append( AbstractExprNode.escapeFilterValue(initialPattern) ).append( '*' );
+ buf.append( AbstractExprNode.escapeFilterValue( new ClientStringValue( initialPattern ) ) ).append( '*' );
}
else
{
@@ -296,14 +347,14 @@
{
for ( String any:anyPattern )
{
- buf.append( AbstractExprNode.escapeFilterValue(any) );
+ buf.append( AbstractExprNode.escapeFilterValue( new ClientStringValue( any ) ) );
buf.append( '*' );
}
}
if ( null != finalPattern )
{
- buf.append( AbstractExprNode.escapeFilterValue(finalPattern) );
+ buf.append( AbstractExprNode.escapeFilterValue( new ClientStringValue( finalPattern ) ) );
}
buf.append( super.toString() );
Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=798005&r1=798004&r2=798005&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Sun Jul 26 23:43:19 2009
@@ -3457,6 +3457,59 @@
/**
+ * Convert an escaoed list of bytes to a byte[]
+ *
+ * @param str the string containing hex escapes
+ * @return the converted byte[]
+ */
+ public static final byte[] convertEscapedHex( String str ) throws InvalidNameException
+ {
+ if ( str == null )
+ {
+ throw new InvalidNameException( "Expected string to be non-null " +
+ "with valid index." );
+ }
+
+ int length = str.length();
+
+ if ( length == 0 )
+ {
+ throw new InvalidNameException( "Expected string to be non-empty " +
+ "with valid index." );
+ }
+
+ // create buffer and add everything before start of scan
+ byte[] buf = new byte[ str.length()/3];
+ int pos = 0;
+
+ // start scaning until we find an escaped series of bytes
+ for ( int i = 0; i < length; i++ )
+ {
+ char c = str.charAt( i );
+
+ if ( c == '\\' )
+ {
+ // we have the start of a hex escape sequence
+ if ( isHex( str, i+1 ) && isHex ( str, i+2 ) )
+ {
+ byte value = ( byte ) ( (StringTools.HEX_VALUE[str.charAt( i+1 )] << 4 ) +
+ StringTools.HEX_VALUE[str.charAt( i+2 )] );
+
+ i+=2;
+ buf[pos++] = value;
+ }
+ }
+ else
+ {
+ throw new InvalidNameException( "The DN must contain valid escaped characters." );
+ }
+ }
+
+ return buf;
+ }
+
+
+ /**
* Collects an hex sequence from a string, and returns the value
* as an integer, after having modified the initial value (the escaped
* hex value is transsformed to the byte it represents).