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 2006/10/03 15:49:46 UTC
svn commit: r452497 [8/9] - in /directory/trunks/shared/ldap/src:
main/java/org/apache/directory/shared/ldap/codec/
main/java/org/apache/directory/shared/ldap/codec/abandon/
main/java/org/apache/directory/shared/ldap/codec/add/
main/java/org/apache/dir...
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControl.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControl.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControl.java Tue Oct 3 06:49:43 2006
@@ -23,7 +23,7 @@
import java.nio.ByteBuffer;
import org.apache.directory.shared.asn1.Asn1Object;
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
import org.apache.directory.shared.asn1.ber.tlv.Value;
import org.apache.directory.shared.asn1.codec.EncoderException;
@@ -77,7 +77,6 @@
* </pre>
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
*/
public class EntryChangeControl extends Asn1Object
{
@@ -87,17 +86,24 @@
private int changeNumber = UNDEFINED_CHANGE_NUMBER;
+ /** The previous DN */
private LdapDN previousDn = null;
- private byte[] previousDnBytes = null;
+ /** A temporary storage for the previous DN */
+ private transient byte[] previousDnBytes = null;
+ /** The entry change global length */
private transient int eccSeqLength;
/**
- * Compute the EnryChangeControl length 0x30 L1 | +--> 0x0A 0x0(1-4)
- * [1|2|4|8] (changeType) +--> 0x04 L2 previousDN +--> 0x02 0x0(1-4)
- * [0..2^31-1] (changeNumber)
+ * Compute the EntryChangeControl length
+ *
+ * 0x30 L1
+ * |
+ * +--> 0x0A 0x0(1-4) [1|2|4|8] (changeType)
+ * [+--> 0x04 L2 previousDN]
+ * [+--> 0x02 0x0(1-4) [0..2^31-1] (changeNumber)]
*/
public int computeLength()
{
@@ -109,7 +115,7 @@
if ( previousDn != null )
{
previousDnBytes = StringTools.getBytesUtf8( previousDn.getUpName() );
- previousDnLength = 1 + Length.getNbBytes( previousDnBytes.length ) + previousDnBytes.length;
+ previousDnLength = 1 + TLV.getNbBytes( previousDnBytes.length ) + previousDnBytes.length;
}
if ( changeNumber != UNDEFINED_CHANGE_NUMBER )
@@ -119,25 +125,23 @@
eccSeqLength = changeTypesLength + previousDnLength + changeNumberLength;
- return 1 + Length.getNbBytes( eccSeqLength ) + eccSeqLength;
+ return 1 + TLV.getNbBytes( eccSeqLength ) + eccSeqLength;
}
/**
* Encodes the entry change control.
*
- * @param buffer
- * The encoded sink
+ * @param buffer The encoded sink
* @return A ByteBuffer that contains the encoded PDU
- * @throws EncoderException
- * If anything goes wrong.
+ * @throws EncoderException If anything goes wrong.
*/
public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
{
// Allocate the bytes buffer.
ByteBuffer bb = ByteBuffer.allocate( computeLength() );
bb.put( UniversalTag.SEQUENCE_TAG );
- bb.put( Length.getBytes( eccSeqLength ) );
+ bb.put( TLV.getBytes( eccSeqLength ) );
bb.put( UniversalTag.ENUMERATED_TAG );
bb.put( ( byte ) 1 );
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlContainer.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlContainer.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlContainer.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlContainer.java Tue Oct 3 06:49:43 2006
@@ -22,7 +22,6 @@
import org.apache.directory.shared.asn1.ber.AbstractContainer;
import org.apache.directory.shared.asn1.ber.IAsn1Container;
-import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
/**
@@ -41,14 +40,8 @@
public EntryChangeControlContainer()
{
super();
- currentGrammar = 0;
- grammars = new IGrammar[EntryChangeControlStatesEnum.NB_GRAMMARS];
- grammarStack = new IGrammar[1];
stateStack = new int[1];
- nbGrammars = 0;
-
- grammars[EntryChangeControlStatesEnum.EC_GRAMMAR] = EntryChangeControlGrammar.getInstance();
- grammarStack[currentGrammar] = grammars[EntryChangeControlStatesEnum.EC_GRAMMAR];
+ grammar = EntryChangeControlGrammar.getInstance();
states = EntryChangeControlStatesEnum.getInstance();
}
@@ -66,15 +59,16 @@
* Set a EntryChangeControl Object into the container. It will be completed
* by the ldapDecoder.
*
- * @param control
- * the EntryChangeControl to set.
+ * @param control the EntryChangeControl to set.
*/
public void setEntryChangeControl( EntryChangeControl control )
{
this.control = control;
}
-
+ /**
+ * Clean the container
+ */
public void clean()
{
super.clean();
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlDecoder.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlDecoder.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlDecoder.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlDecoder.java Tue Oct 3 06:49:43 2006
@@ -37,17 +37,31 @@
*/
public class EntryChangeControlDecoder extends Asn1Decoder implements ControlDecoder
{
+ /** The entry change OID */
private final static String CONTROL_TYPE_OID = "2.16.840.1.113730.3.4.7";
+ /** An instance of this decoder */
private static final Asn1Decoder decoder = new Asn1Decoder();
-
+ /**
+ * @return The Entry Change controm OID
+ */
public String getControlType()
{
return CONTROL_TYPE_OID;
}
-
+ /**
+ * Decode the entry change control
+ *
+ * @param controlBytes The bytes array which contains the encoded entry change
+ *
+ * @return A valid EntryChange object
+ *
+ * @throws DecoderException If the decoding found an error
+ * @throws NamingException It will never be throw by this method
+ */
+
public Asn1Object decode( byte[] controlBytes ) throws DecoderException, NamingException
{
ByteBuffer bb = ByteBuffer.wrap( controlBytes );
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlGrammar.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlGrammar.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlGrammar.java Tue Oct 3 06:49:43 2006
@@ -68,23 +68,17 @@
super.transitions = new GrammarTransition[EntryChangeControlStatesEnum.LAST_EC_STATE][256];
// ============================================================================================
- // Entry Change Control
+ // Transition from start state to Entry Change sequence
// ============================================================================================
- // EntryChangeNotification ::= SEQUENCE { (Tag)
- // ...
- // Nothing to do
- super.transitions[EntryChangeControlStatesEnum.EC_SEQUENCE_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
- EntryChangeControlStatesEnum.EC_SEQUENCE_TAG, EntryChangeControlStatesEnum.EC_SEQUENCE_VALUE, null );
-
- // ============================================================================================
- // Entry Change Control
- // ============================================================================================
- // EntryChangeNotification ::= SEQUENCE { (Value)
- // ...
+ // EntryChangeNotification ::= SEQUENCE {
+ // ...
+ //
// Initialization of the structure
- super.transitions[EntryChangeControlStatesEnum.EC_SEQUENCE_VALUE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
- EntryChangeControlStatesEnum.EC_SEQUENCE_VALUE, EntryChangeControlStatesEnum.CHANGE_TYPE_TAG,
- new GrammarAction( "Init EntryChangeControl" )
+ super.transitions[EntryChangeControlStatesEnum.START_STATE][UniversalTag.SEQUENCE_TAG] =
+ new GrammarTransition( EntryChangeControlStatesEnum.START_STATE,
+ EntryChangeControlStatesEnum.EC_SEQUENCE_STATE,
+ UniversalTag.SEQUENCE_TAG,
+ new GrammarAction( "Init EntryChangeControl" )
{
public void action( IAsn1Container container )
{
@@ -95,27 +89,18 @@
} );
// ============================================================================================
- // Change Type
- // ============================================================================================
- // EntryChangeNotification ::= SEQUENCE {
- // changeType ENUMERATED { (Tag) },
- // ...
- //
- // Nothing to do
- super.transitions[EntryChangeControlStatesEnum.CHANGE_TYPE_TAG][UniversalTag.ENUMERATED_TAG] = new GrammarTransition(
- EntryChangeControlStatesEnum.CHANGE_TYPE_TAG, EntryChangeControlStatesEnum.CHANGE_TYPE_VALUE, null );
-
- // ============================================================================================
- // Change Type
+ // transition from Entry Change sequence to Change Type
// ============================================================================================
// EntryChangeNotification ::= SEQUENCE {
- // changeType ENUMERATED { (Value) },
- // ...
+ // changeType ENUMERATED {
+ // ...
//
// Evaluates the changeType
-
- // Action associated with the ChangeType transition
- GrammarAction setChangeTypeAction = new GrammarAction( "Set EntryChangeControl changeType" )
+ super.transitions[EntryChangeControlStatesEnum.EC_SEQUENCE_STATE][UniversalTag.ENUMERATED_TAG] =
+ new GrammarTransition( EntryChangeControlStatesEnum.EC_SEQUENCE_STATE,
+ EntryChangeControlStatesEnum.CHANGE_TYPE_STATE,
+ UniversalTag.ENUMERATED_TAG,
+ new GrammarAction( "Set EntryChangeControl changeType" )
{
public void action( IAsn1Container container ) throws DecoderException
{
@@ -158,39 +143,23 @@
throw new DecoderException( msg );
}
}
- };
-
- // ChangeType Transition
- super.transitions[EntryChangeControlStatesEnum.CHANGE_TYPE_VALUE][UniversalTag.ENUMERATED_TAG] = new GrammarTransition(
- EntryChangeControlStatesEnum.CHANGE_TYPE_VALUE,
- EntryChangeControlStatesEnum.CHANGE_NUMBER_OR_PREVIOUS_DN_TAG, setChangeTypeAction );
+ } );
// ============================================================================================
- // Previous DN (We have a OCTET_STRING Tag)
+ // Transition from Change Type to Previous DN
// ============================================================================================
// EntryChangeNotification ::= SEQUENCE {
- // ...
- // previousDN LDAPDN OPTIONAL, (Tag)
- // ...
- //
- // Nothing to do
- super.transitions[EntryChangeControlStatesEnum.CHANGE_NUMBER_OR_PREVIOUS_DN_TAG][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition(
- EntryChangeControlStatesEnum.CHANGE_NUMBER_OR_PREVIOUS_DN_TAG,
- EntryChangeControlStatesEnum.PREVIOUS_DN_VALUE, null );
-
- // ============================================================================================
- // Previous DN
- // ============================================================================================
- // EntryChangeNotification ::= SEQUENCE {
- // ...
- // previousDN LDAPDN OPTIONAL, (Value)
- // ...
+ // ...
+ // previousDN LDAPDN OPTIONAL,
+ // ...
//
// Set the previousDN into the structure. We first check that it's a
// valid DN
-
- // Action associated with the PreviousDN transition
- GrammarAction setPreviousDnAction = new GrammarAction( "Set EntryChangeControl previousDN" )
+ super.transitions[EntryChangeControlStatesEnum.CHANGE_TYPE_STATE][UniversalTag.OCTET_STRING_TAG] =
+ new GrammarTransition( EntryChangeControlStatesEnum.CHANGE_TYPE_STATE,
+ EntryChangeControlStatesEnum.PREVIOUS_DN_STATE,
+ UniversalTag.OCTET_STRING_TAG,
+ new GrammarAction( "Set EntryChangeControl previousDN" )
{
public void action( IAsn1Container container ) throws DecoderException
{
@@ -229,47 +198,7 @@
entryChangeContainer.grammarEndAllowed( true );
}
}
- };
-
- // PreviousDN transition
- super.transitions[EntryChangeControlStatesEnum.PREVIOUS_DN_VALUE][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition(
- EntryChangeControlStatesEnum.PREVIOUS_DN_VALUE, EntryChangeControlStatesEnum.CHANGE_NUMBER_TAG,
- setPreviousDnAction );
-
- // ============================================================================================
- // Change Number from Change Type
- // ============================================================================================
- // EntryChangeNotification ::= SEQUENCE {
- // ...
- // changeNumber INTEGER OPTIONAL (Tag)
- // }
- //
- // Nothing to do
- super.transitions[EntryChangeControlStatesEnum.CHANGE_NUMBER_OR_PREVIOUS_DN_TAG][UniversalTag.INTEGER_TAG] = new GrammarTransition(
- EntryChangeControlStatesEnum.CHANGE_NUMBER_OR_PREVIOUS_DN_TAG,
- EntryChangeControlStatesEnum.CHANGE_NUMBER_VALUE, null );
-
- // ============================================================================================
- // Change Number from PreviousDN
- // ============================================================================================
- // EntryChangeNotification ::= SEQUENCE {
- // ...
- // changeNumber INTEGER OPTIONAL (Tag)
- // }
- //
- // Nothing to do
- super.transitions[EntryChangeControlStatesEnum.CHANGE_NUMBER_TAG][UniversalTag.INTEGER_TAG] = new GrammarTransition(
- EntryChangeControlStatesEnum.CHANGE_NUMBER_TAG, EntryChangeControlStatesEnum.CHANGE_NUMBER_VALUE, null );
-
- // ============================================================================================
- // Change Number
- // ============================================================================================
- // EntryChangeNotification ::= SEQUENCE {
- // ...
- // changeNumber INTEGER OPTIONAL (Value)
- // }
- //
- // Set the changeNumber into the structure
+ } );
// Change Number action
GrammarAction setChangeNumberAction = new GrammarAction( "Set EntryChangeControl changeNumber" )
@@ -302,10 +231,35 @@
}
};
- // Transition
- super.transitions[EntryChangeControlStatesEnum.CHANGE_NUMBER_VALUE][UniversalTag.INTEGER_TAG] = new GrammarTransition(
- EntryChangeControlStatesEnum.CHANGE_NUMBER_VALUE, EntryChangeControlStatesEnum.GRAMMAR_END,
- setChangeNumberAction );
+ // ============================================================================================
+ // Transition from Previous DN to Change Number
+ // ============================================================================================
+ // EntryChangeNotification ::= SEQUENCE {
+ // ...
+ // changeNumber INTEGER OPTIONAL
+ // }
+ //
+ // Set the changeNumber into the structure
+ super.transitions[EntryChangeControlStatesEnum.PREVIOUS_DN_STATE][UniversalTag.INTEGER_TAG] =
+ new GrammarTransition( EntryChangeControlStatesEnum.PREVIOUS_DN_STATE,
+ EntryChangeControlStatesEnum.CHANGE_NUMBER_STATE,
+ UniversalTag.INTEGER_TAG,
+ setChangeNumberAction );
+
+ // ============================================================================================
+ // Transition from Previous DN to Change Number
+ // ============================================================================================
+ // EntryChangeNotification ::= SEQUENCE {
+ // ...
+ // changeNumber INTEGER OPTIONAL
+ // }
+ //
+ // Set the changeNumber into the structure
+ super.transitions[EntryChangeControlStatesEnum.CHANGE_TYPE_STATE][UniversalTag.INTEGER_TAG] =
+ new GrammarTransition( EntryChangeControlStatesEnum.CHANGE_TYPE_STATE,
+ EntryChangeControlStatesEnum.CHANGE_NUMBER_STATE,
+ UniversalTag.INTEGER_TAG,
+ setChangeNumberAction );
}
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlStatesEnum.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlStatesEnum.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlStatesEnum.java Tue Oct 3 06:49:43 2006
@@ -40,58 +40,35 @@
// =========================================================================
/** Sequence Tag */
- public static int EC_SEQUENCE_TAG = 0;
+ public static int START_STATE = 0;
- /** Sequence Value */
- public static int EC_SEQUENCE_VALUE = 1;
+ /** Sequence */
+ public static int EC_SEQUENCE_STATE = 1;
- /** changeType Tag */
- public static int CHANGE_TYPE_TAG = 2;
+ /** changeType */
+ public static int CHANGE_TYPE_STATE = 2;
- /** changeType Value */
- public static int CHANGE_TYPE_VALUE = 3;
+ /** previousDN */
+ public static int PREVIOUS_DN_STATE = 3;
- /** previousDN Tag */
- public static int CHANGE_NUMBER_OR_PREVIOUS_DN_TAG = 4;
-
- /** previousDN Value */
- public static int PREVIOUS_DN_VALUE = 5;
-
- /** changeNumber Tag */
- public static int CHANGE_NUMBER_TAG = 6;
-
- /** changeNumber Value */
- public static int CHANGE_NUMBER_VALUE = 7;
+ /** changeNumber */
+ public static int CHANGE_NUMBER_STATE = 4;
/** terminal state */
- public static int LAST_EC_STATE = 8;
-
- // =========================================================================
- // Grammars declaration.
- // =========================================================================
- /** Entry change grammar */
- public static final int EC_GRAMMAR_SWITCH = 0x0100;
-
- /** Entry change grammar number */
- public static final int EC_GRAMMAR = 0;
-
- /** The total number of grammars used */
- public static final int NB_GRAMMARS = 1;
-
- // =========================================================================
- // Grammar switches debug strings
- // =========================================================================
- /** A string representation of grammars */
- private static String[] GrammarSwitchString = new String[]
- { "EC_GRAMMAR_SWITCH" };
+ public static int LAST_EC_STATE = 5;
// =========================================================================
// States debug strings
// =========================================================================
/** A string representation of all the states */
private static String[] EcString = new String[]
- { "EC_SEQUENCE_TAG", "EC_SEQUENCE_VALUE", "CHANGE_TYPE_TAG", "CHANGE_TYPE_VALUE",
- "CHANGE_NUMBER_OR_PREVIOUS_DN_TAG", "PREVIOUS_DN_VALUE", "CHANGE_NUMBER_TAG", "CHANGE_NUMBER_VALUE" };
+ {
+ "START_STATE",
+ "EC_SEQUENCE_STATE",
+ "CHANGE_TYPE_STATE",
+ "PREVIOUS_DN_STATE",
+ "CHANGE_NUMBER_STATE"
+ };
/** The instance */
private static EntryChangeControlStatesEnum instance = new EntryChangeControlStatesEnum();
@@ -125,27 +102,19 @@
/**
* Get the grammar name
*
- * @param grammar
- * The grammar code
+ * @param grammar The grammar code
* @return The grammar name
*/
public String getGrammarName( int grammar )
{
- switch ( grammar )
- {
- case EC_GRAMMAR:
- return "EC_GRAMMAR";
- default:
- return "UNKNOWN";
- }
+ return "EC_GRAMMAR";
}
/**
* Get the grammar name
*
- * @param grammar
- * The grammar class
+ * @param grammar The grammar class
* @return The grammar name
*/
public String getGrammarName( IGrammar grammar )
@@ -162,32 +131,11 @@
/**
* Get the string representing the state
*
- * @param grammar
- * The current grammar being used
- * @param state
- * The state number
+ * @param state The state number
* @return The String representing the state
*/
- public String getState( int grammar, int state )
+ public String getState( int state )
{
-
- if ( ( state & GRAMMAR_SWITCH_MASK ) != 0 )
- {
- return ( state == END_STATE ) ? "END_STATE"
- : GrammarSwitchString[( ( state & GRAMMAR_SWITCH_MASK ) >> 8 ) - 1];
- }
- else
- {
-
- switch ( grammar )
- {
-
- case EC_GRAMMAR:
- return ( ( state == GRAMMAR_END ) ? "EC_END_STATE" : EcString[state] );
-
- default:
- return "UNKNOWN";
- }
- }
+ return ( ( state == GRAMMAR_END ) ? "EC_END_STATE" : EcString[state] );
}
}
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControl.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControl.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControl.java Tue Oct 3 06:49:43 2006
@@ -23,12 +23,17 @@
import java.nio.ByteBuffer;
import org.apache.directory.shared.asn1.Asn1Object;
-import org.apache.directory.shared.asn1.ber.tlv.Length;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
import org.apache.directory.shared.asn1.ber.tlv.Value;
import org.apache.directory.shared.asn1.codec.EncoderException;
+/**
+ * A persistence search object
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
public class PSearchControl extends Asn1Object
{
/**
@@ -46,33 +51,30 @@
/**
* As changes are made to the server, the effected entries MUST be returned
- * to the client if they match the standard search cri- teria and if the
+ * to the client if they match the standard search criteria and if the
* operation that caused the change is included in the changeTypes field.
* The changeTypes field is the logical OR of one or more of these values:
- * add (1), delete (2), modify (4), modDN (8).
+ * add (1),
+ * delete (2),
+ * modify (4),
+ * modDN (8).
*/
private int changeTypes;
+
+ /** Definition of the change types */
+ public static final int CHANGE_TYPE_ADD = 1;
+ public static final int CHANGE_TYPE_DELETE = 2;
+ public static final int CHANGE_TYPE_MODIFY = 4;
+ public static final int CHANGE_TYPE_MODDN = 8;
+
+ /** Min and Max values for the possible combined change types */
+ public static final int CHANGE_TYPES_MIN = CHANGE_TYPE_ADD;
+ public static final int CHANGE_TYPES_MAX = CHANGE_TYPE_ADD | CHANGE_TYPE_DELETE | CHANGE_TYPE_MODIFY | CHANGE_TYPE_MODDN;
+ /** A temporary storage for a psearch length */
private transient int psearchSeqLength;
- /**
- * Compute the PSearchControl length 0x30 L1 | +--> 0x02 0x0(1-4)
- * [0..2^31-1] (changeTypes) +--> 0x01 0x01 [0x00 | 0xFF] (changeOnly) +-->
- * 0x01 0x01 [0x00 | 0xFF] (returnRCs)
- */
- public int computeLength()
- {
- int changeTypesLength = 1 + 1 + Value.getNbBytes( changeTypes );
- int changesOnlyLength = 1 + 1 + 1;
- int returnRCsLength = 1 + 1 + 1;
-
- psearchSeqLength = changeTypesLength + changesOnlyLength + returnRCsLength;
-
- return 1 + Length.getNbBytes( psearchSeqLength ) + psearchSeqLength;
- }
-
-
public void setChangesOnly( boolean changesOnly )
{
this.changesOnly = changesOnly;
@@ -108,22 +110,39 @@
return changeTypes;
}
+ /**
+ * Compute the PSearchControl length
+ * 0x30 L1
+ * |
+ * +--> 0x02 0x0(1-4) [0..2^31-1] (changeTypes)
+ * +--> 0x01 0x01 [0x00 | 0xFF] (changeOnly)
+ * +--> 0x01 0x01 [0x00 | 0xFF] (returnRCs)
+ */
+ public int computeLength()
+ {
+ int changeTypesLength = 1 + 1 + Value.getNbBytes( changeTypes );
+ int changesOnlyLength = 1 + 1 + 1;
+ int returnRCsLength = 1 + 1 + 1;
+
+ psearchSeqLength = changeTypesLength + changesOnlyLength + returnRCsLength;
+
+ return 1 + TLV.getNbBytes( psearchSeqLength ) + psearchSeqLength;
+ }
+
/**
* Encodes the persistent search control.
*
- * @param buffer
- * The encoded sink
+ * @param buffer The encoded sink
* @return A ByteBuffer that contains the encoded PDU
- * @throws EncoderException
- * If anything goes wrong.
+ * @throws EncoderException If anything goes wrong.
*/
public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
{
// Allocate the bytes buffer.
ByteBuffer bb = ByteBuffer.allocate( computeLength() );
bb.put( UniversalTag.SEQUENCE_TAG );
- bb.put( Length.getBytes( psearchSeqLength ) );
+ bb.put( TLV.getBytes( psearchSeqLength ) );
Value.encode( bb, changeTypes );
Value.encode( bb, changesOnly );
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlContainer.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlContainer.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlContainer.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlContainer.java Tue Oct 3 06:49:43 2006
@@ -22,7 +22,6 @@
import org.apache.directory.shared.asn1.ber.AbstractContainer;
import org.apache.directory.shared.asn1.ber.IAsn1Container;
-import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
/**
@@ -41,14 +40,8 @@
public PSearchControlContainer()
{
super();
- currentGrammar = 0;
- grammars = new IGrammar[PSearchControlStatesEnum.NB_GRAMMARS];
- grammarStack = new IGrammar[1];
stateStack = new int[1];
- nbGrammars = 0;
-
- grammars[PSearchControlStatesEnum.PSEARCH_GRAMMAR] = PSearchControlGrammar.getInstance();
- grammarStack[currentGrammar] = grammars[PSearchControlStatesEnum.PSEARCH_GRAMMAR];
+ grammar = PSearchControlGrammar.getInstance();
states = PSearchControlStatesEnum.getInstance();
}
@@ -67,15 +60,16 @@
* Set a PSearchControl Object into the container. It will be completed by
* the ldapDecoder.
*
- * @param control
- * the PSearchControl to set.
+ * @param control the PSearchControl to set.
*/
public void setPSearchControl( PSearchControl control )
{
this.control = control;
}
-
+ /**
+ * Clean the container
+ */
public void clean()
{
super.clean();
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlDecoder.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlDecoder.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlDecoder.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlDecoder.java Tue Oct 3 06:49:43 2006
@@ -37,17 +37,32 @@
*/
public class PSearchControlDecoder extends Asn1Decoder implements ControlDecoder
{
+ /** The persistence search OID */
private final static String CONTROL_TYPE_OID = "2.16.840.1.113730.3.4.3";
+ /** An instance of this decoder */
private static final Asn1Decoder decoder = new Asn1Decoder();
-
+ /**
+ * Return the persistence search OID
+ *
+ * @see org.apache.directory.shared.ldap.codec.ControlDecoder#getControlType()
+ */
public String getControlType()
{
return CONTROL_TYPE_OID;
}
-
+ /**
+ * Decode the persistence search control
+ *
+ * @param controlBytes The bytes array which contains the encoded persistence search
+ *
+ * @return A valid PersistenceSearch object
+ *
+ * @throws DecoderException If the decoding found an error
+ * @throws NamingException It will never be throw by this method
+ */
public Asn1Object decode( byte[] controlBytes ) throws DecoderException, NamingException
{
ByteBuffer bb = ByteBuffer.wrap( controlBytes );
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlGrammar.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlGrammar.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlGrammar.java Tue Oct 3 06:49:43 2006
@@ -32,7 +32,6 @@
import org.apache.directory.shared.asn1.util.BooleanDecoderException;
import org.apache.directory.shared.asn1.util.IntegerDecoder;
import org.apache.directory.shared.asn1.util.IntegerDecoderException;
-import org.apache.directory.shared.ldap.codec.LdapStatesEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,6 +40,20 @@
* This class implements the PSearchControl. All the actions are declared in
* this class. As it is a singleton, these declaration are only done once.
*
+ * The decoded grammar is the following :
+ *
+ * PersistenceSearch ::= SEQUENCE {
+ * changeTypes INTEGER, -- an OR combinaison of 0, 1, 2 and 4 --
+ * changeOnly BOOLEAN,
+ * returnECs BOOLEAN
+ * }
+ *
+ * The changeTypes field is the logical OR of one or more of these values:
+ * add (1),
+ * delete (2),
+ * modify (4),
+ * modDN (8).
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public class PSearchControlGrammar extends AbstractGrammar implements IGrammar
@@ -66,12 +79,18 @@
// Create the transitions table
super.transitions = new GrammarTransition[PSearchControlStatesEnum.LAST_PSEARCH_STATE][256];
- super.transitions[PSearchControlStatesEnum.PSEARCH_SEQUENCE_TAG][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
- PSearchControlStatesEnum.PSEARCH_SEQUENCE_TAG, PSearchControlStatesEnum.PSEARCH_SEQUENCE_VALUE, null );
-
- super.transitions[PSearchControlStatesEnum.PSEARCH_SEQUENCE_VALUE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
- PSearchControlStatesEnum.PSEARCH_SEQUENCE_VALUE, PSearchControlStatesEnum.CHANGE_TYPES_TAG,
- new GrammarAction( "Init PSearchControl" )
+ /**
+ * Transition from initial state to Psearch sequence
+ * PSearch ::= SEQUENCE OF {
+ * ...
+ *
+ * Initialize the persistence search object
+ */
+ super.transitions[PSearchControlStatesEnum.INIT_GRAMMAR_STATE][UniversalTag.SEQUENCE_TAG] =
+ new GrammarTransition( PSearchControlStatesEnum.INIT_GRAMMAR_STATE,
+ PSearchControlStatesEnum.PSEARCH_SEQUENCE_STATE,
+ UniversalTag.SEQUENCE_TAG,
+ new GrammarAction( "Init PSearchControl" )
{
public void action( IAsn1Container container )
{
@@ -81,12 +100,18 @@
}
} );
- super.transitions[PSearchControlStatesEnum.CHANGE_TYPES_TAG][UniversalTag.INTEGER_TAG] = new GrammarTransition(
- PSearchControlStatesEnum.CHANGE_TYPES_TAG, PSearchControlStatesEnum.CHANGE_TYPES_VALUE, null );
- super.transitions[PSearchControlStatesEnum.CHANGE_TYPES_VALUE][UniversalTag.INTEGER_TAG] = new GrammarTransition(
- PSearchControlStatesEnum.CHANGE_TYPES_VALUE, PSearchControlStatesEnum.CHANGES_ONLY_TAG, new GrammarAction(
- "Set PSearchControl changeTypes" )
+ /**
+ * Transition from Psearch sequence to Change types
+ * PSearch ::= SEQUENCE OF {
+ * changeTypes INTEGER, -- an OR combinaison of 0, 1, 2 and 4 --
+ * ...
+ *
+ * Stores the change types value
+ */
+ super.transitions[PSearchControlStatesEnum.PSEARCH_SEQUENCE_STATE][UniversalTag.INTEGER_TAG] =
+ new GrammarTransition( PSearchControlStatesEnum.PSEARCH_SEQUENCE_STATE, PSearchControlStatesEnum.CHANGE_TYPES_STATE, UniversalTag.INTEGER_TAG,
+ new GrammarAction( "Set PSearchControl changeTypes" )
{
public void action( IAsn1Container container ) throws DecoderException
{
@@ -95,8 +120,9 @@
try
{
- int changeTypes = IntegerDecoder.parse( value );
-
+ // Check that the value is into the allowed interval
+ int changeTypes = IntegerDecoder.parse( value, PSearchControl.CHANGE_TYPES_MIN, PSearchControl.CHANGE_TYPES_MAX );
+
if ( IS_DEBUG )
{
log.debug( "changeTypes = " + changeTypes );
@@ -113,12 +139,18 @@
}
} );
- super.transitions[PSearchControlStatesEnum.CHANGES_ONLY_TAG][UniversalTag.BOOLEAN_TAG] = new GrammarTransition(
- PSearchControlStatesEnum.CHANGES_ONLY_TAG, PSearchControlStatesEnum.CHANGES_ONLY_VALUE, null );
-
- super.transitions[PSearchControlStatesEnum.CHANGES_ONLY_VALUE][UniversalTag.BOOLEAN_TAG] = new GrammarTransition(
- PSearchControlStatesEnum.CHANGES_ONLY_VALUE, PSearchControlStatesEnum.RETURN_ECS_TAG, new GrammarAction(
- "Set PSearchControl changesOnly" )
+ /**
+ * Transition from Change types to Changes only
+ * PSearch ::= SEQUENCE OF {
+ * ...
+ * changeOnly BOOLEAN,
+ * ...
+ *
+ * Stores the change only flag
+ */
+ super.transitions[PSearchControlStatesEnum.CHANGE_TYPES_STATE][UniversalTag.BOOLEAN_TAG] =
+ new GrammarTransition( PSearchControlStatesEnum.CHANGE_TYPES_STATE, PSearchControlStatesEnum.CHANGES_ONLY_STATE, UniversalTag.BOOLEAN_TAG,
+ new GrammarAction( "Set PSearchControl changesOnly" )
{
public void action( IAsn1Container container ) throws DecoderException
{
@@ -145,12 +177,18 @@
}
} );
- super.transitions[PSearchControlStatesEnum.RETURN_ECS_TAG][UniversalTag.BOOLEAN_TAG] = new GrammarTransition(
- PSearchControlStatesEnum.RETURN_ECS_TAG, PSearchControlStatesEnum.RETURN_ECS_VALUE, null );
-
- super.transitions[PSearchControlStatesEnum.RETURN_ECS_VALUE][UniversalTag.BOOLEAN_TAG] = new GrammarTransition(
- PSearchControlStatesEnum.RETURN_ECS_VALUE, LdapStatesEnum.GRAMMAR_END, new GrammarAction(
- "Set PSearchControl returnECs" )
+ /**
+ * Transition from Change types to Changes only
+ * PSearch ::= SEQUENCE OF {
+ * ...
+ * returnECs BOOLEAN
+ * }
+ *
+ * Stores the return ECs flag
+ */
+ super.transitions[PSearchControlStatesEnum.CHANGES_ONLY_STATE][UniversalTag.BOOLEAN_TAG] =
+ new GrammarTransition( PSearchControlStatesEnum.CHANGES_ONLY_STATE, PSearchControlStatesEnum.RETURN_ECS_STATE, UniversalTag.BOOLEAN_TAG,
+ new GrammarAction( "Set PSearchControl returnECs" )
{
public void action( IAsn1Container container ) throws DecoderException
{
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlStatesEnum.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlStatesEnum.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/PSearchControlStatesEnum.java Tue Oct 3 06:49:43 2006
@@ -38,60 +38,36 @@
// =========================================================================
// Persistent search control grammar states
// =========================================================================
-
- /** Sequence Tag */
- public static int PSEARCH_SEQUENCE_TAG = 0;
+ /** Initial state */
+ public static final int START_STATE = 0;
/** Sequence Value */
- public static int PSEARCH_SEQUENCE_VALUE = 1;
-
- /** changeTypes Tag */
- public static int CHANGE_TYPES_TAG = 2;
+ public static int PSEARCH_SEQUENCE_STATE = 1;
/** changeTypes Value */
- public static int CHANGE_TYPES_VALUE = 3;
-
- /** changesOnly Tag */
- public static int CHANGES_ONLY_TAG = 4;
-
+ public static int CHANGE_TYPES_STATE = 3;
+
/** changesOnly Value */
- public static int CHANGES_ONLY_VALUE = 5;
-
- /** returnECs Tag */
- public static int RETURN_ECS_TAG = 6;
+ public static int CHANGES_ONLY_STATE = 5;
/** returnECs Value */
- public static int RETURN_ECS_VALUE = 7;
+ public static int RETURN_ECS_STATE = 7;
/** terminal state */
public static int LAST_PSEARCH_STATE = 8;
// =========================================================================
- // Grammars declaration.
- // =========================================================================
- /** PSsearch grammar */
- public static final int PSEARCH_GRAMMAR_SWITCH = 0x0100;
-
- /** PSearch grammar number */
- public static final int PSEARCH_GRAMMAR = 0;
-
- /** The total number of grammars used */
- public static final int NB_GRAMMARS = 1;
-
- // =========================================================================
- // Grammar switches debug strings
- // =========================================================================
- /** A string representation of grammars */
- private static String[] GrammarSwitchString = new String[]
- { "PSEARCH_GRAMMAR_SWITCH" };
-
- // =========================================================================
// States debug strings
// =========================================================================
/** A string representation of all the states */
private static String[] PSearchString = new String[]
- { "PSEARCH_SEQUENCE_TAG", "PSEARCH_SEQUENCE_VALUE", "CHANGE_TYPES_TAG", "CHANGE_TYPES_VALUE",
- "CHANGES_ONLY_TAG", "CHANGES_ONLY_VALUE", "RETURN_ECS_TAG", "RETURN_ECS_VALUE" };
+ {
+ "START_STATE",
+ "PSEARCH_SEQUENCE_VALUE",
+ "CHANGE_TYPES_STATE",
+ "CHANGES_ONLY_STATE",
+ "RETURN_ECS_STATE"
+ };
/** The instance */
private static PSearchControlStatesEnum instance = new PSearchControlStatesEnum();
@@ -125,27 +101,19 @@
/**
* Get the grammar name
*
- * @param grammar
- * The grammar code
+ * @param grammar The grammar code
* @return The grammar name
*/
public String getGrammarName( int grammar )
{
- switch ( grammar )
- {
- case PSEARCH_GRAMMAR:
- return "PSEARCH_GRAMMAR";
- default:
- return "UNKNOWN";
- }
+ return "PSEARCH_GRAMMAR";
}
/**
* Get the grammar name
*
- * @param grammar
- * The grammar class
+ * @param grammar The grammar class
* @return The grammar name
*/
public String getGrammarName( IGrammar grammar )
@@ -162,32 +130,11 @@
/**
* Get the string representing the state
*
- * @param grammar
- * The current grammar being used
- * @param state
- * The state number
+ * @param state The state number
* @return The String representing the state
*/
- public String getState( int grammar, int state )
+ public String getState( int state )
{
-
- if ( ( state & GRAMMAR_SWITCH_MASK ) != 0 )
- {
- return ( state == END_STATE ) ? "END_STATE"
- : GrammarSwitchString[( ( state & GRAMMAR_SWITCH_MASK ) >> 8 ) - 1];
- }
- else
- {
-
- switch ( grammar )
- {
-
- case PSEARCH_GRAMMAR:
- return ( ( state == GRAMMAR_END ) ? "PSEARCH_END_STATE" : PSearchString[state] );
-
- default:
- return "UNKNOWN";
- }
- }
+ return ( ( state == GRAMMAR_END ) ? "PSEARCH_END_STATE" : PSearchString[state] );
}
}
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControl.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControl.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControl.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControl.java Tue Oct 3 06:49:43 2006
@@ -28,7 +28,7 @@
/**
- * A searchRequest control.
+ * A searchRequest control : SubEntry
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$
@@ -52,8 +52,7 @@
/**
* Set the visibility flag
*
- * @param visibility
- * The visibility flag : true or false
+ * @param visibility The visibility flag : true or false
*/
public void setVisibility( boolean visibility )
{
@@ -73,11 +72,9 @@
/**
* Encodes the subEntry control.
*
- * @param buffer
- * The encoded sink
+ * @param buffer The encoded sink
* @return A ByteBuffer that contains the encoded PDU
- * @throws EncoderException
- * If anything goes wrong.
+ * @throws EncoderException If anything goes wrong.
*/
public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
{
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlContainer.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlContainer.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlContainer.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlContainer.java Tue Oct 3 06:49:43 2006
@@ -22,7 +22,6 @@
import org.apache.directory.shared.asn1.ber.AbstractContainer;
import org.apache.directory.shared.asn1.ber.IAsn1Container;
-import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
/**
@@ -35,20 +34,13 @@
/**
- * Creates a new SubEntryControlContainer object. We will store one grammar,
- * it's enough ...
+ * Creates a new SubEntryControlContainer object.
*/
public SubEntryControlContainer()
{
super();
- currentGrammar = 0;
- grammars = new IGrammar[SubEntryControlStatesEnum.NB_GRAMMARS];
- grammarStack = new IGrammar[1];
stateStack = new int[1];
- nbGrammars = 0;
-
- grammars[SubEntryControlStatesEnum.SUB_ENTRY_GRAMMAR] = SubEntryControlGrammar.getInstance();
- grammarStack[currentGrammar] = grammars[SubEntryControlStatesEnum.SUB_ENTRY_GRAMMAR];
+ grammar = SubEntryControlGrammar.getInstance();
states = SubEntryControlStatesEnum.getInstance();
}
@@ -58,7 +50,6 @@
*/
public SubEntryControl getSubEntryControl()
{
-
return control;
}
@@ -67,15 +58,16 @@
* Set a SubEntryControl Object into the container. It will be completed by
* the ldapDecoder.
*
- * @param control
- * the SubEntryControl to set.
+ * @param control the SubEntryControl to set.
*/
public void setSubEntryControl( SubEntryControl control )
{
this.control = control;
}
-
+ /**
+ * Clean the current container
+ */
public void clean()
{
super.clean();
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlDecoder.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlDecoder.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlDecoder.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlDecoder.java Tue Oct 3 06:49:43 2006
@@ -37,17 +37,30 @@
*/
public class SubEntryControlDecoder extends Asn1Decoder implements ControlDecoder
{
+ /** The sub entry OID */
private final static String CONTROL_TYPE_OID = "1.3.6.1.4.1.4203.1.10.1";
+ /** The sub entry decoder */
private static final Asn1Decoder decoder = new Asn1Decoder();
-
+ /**
+ * @return the sub entry OID
+ */
public String getControlType()
{
return CONTROL_TYPE_OID;
}
-
+ /**
+ * Decode the sub entry control
+ *
+ * @param controlBytes The bytes array which contains the encoded sub entry
+ *
+ * @return A valid SubEntry object
+ *
+ * @throws DecoderException If the decoding found an error
+ * @throws NamingException It will never be throw by this method
+ */
public Asn1Object decode( byte[] controlBytes ) throws DecoderException, NamingException
{
ByteBuffer bb = ByteBuffer.wrap( controlBytes );
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlGrammar.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlGrammar.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlGrammar.java Tue Oct 3 06:49:43 2006
@@ -62,13 +62,9 @@
// Create the transitions table
super.transitions = new GrammarTransition[SubEntryControlStatesEnum.LAST_SUB_ENTRY_STATE][256];
- super.transitions[SubEntryControlStatesEnum.SUB_ENTRY_VISIBILITY_TAG][UniversalTag.BOOLEAN_TAG] = new GrammarTransition(
- SubEntryControlStatesEnum.SUB_ENTRY_VISIBILITY_TAG, SubEntryControlStatesEnum.SUB_ENTRY_VISIBILITY_VALUE,
- null );
-
- super.transitions[SubEntryControlStatesEnum.SUB_ENTRY_VISIBILITY_VALUE][UniversalTag.BOOLEAN_TAG] = new GrammarTransition(
- SubEntryControlStatesEnum.SUB_ENTRY_VISIBILITY_VALUE, SubEntryControlStatesEnum.GRAMMAR_END,
- new GrammarAction( "SubEntryControl visibility" )
+ super.transitions[SubEntryControlStatesEnum.START_STATE][UniversalTag.BOOLEAN_TAG] =
+ new GrammarTransition( SubEntryControlStatesEnum.START_STATE, SubEntryControlStatesEnum.SUB_ENTRY_VISIBILITY_STATE, UniversalTag.BOOLEAN_TAG,
+ new GrammarAction( "SubEntryControl visibility" )
{
public void action( IAsn1Container container ) throws DecoderException
{
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlStatesEnum.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlStatesEnum.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/SubEntryControlStatesEnum.java Tue Oct 3 06:49:43 2006
@@ -39,40 +39,24 @@
// Sub entry control grammar states
// =========================================================================
- /** Visibility Tag */
- public static int SUB_ENTRY_VISIBILITY_TAG = 0;
+ /** Starting state */
+ public static int START_STATE = 0;
/** Visibility Value */
- public static int SUB_ENTRY_VISIBILITY_VALUE = 1;
+ public static int SUB_ENTRY_VISIBILITY_STATE = 1;
/** terminal state */
public static int LAST_SUB_ENTRY_STATE = 2;
// =========================================================================
- // Grammars declaration.
- // =========================================================================
- /** PSsearch grammar */
- public static final int SUB_ENTRY_GRAMMAR_SWITCH = 0x0100;
-
- /** PSearch grammar number */
- public static final int SUB_ENTRY_GRAMMAR = 0;
-
- /** The total number of grammars used */
- public static final int NB_GRAMMARS = 1;
-
- // =========================================================================
- // Grammar switches debug strings
- // =========================================================================
- /** A string representation of grammars */
- private static String[] GrammarSwitchString = new String[]
- { "SUB_ENTRY_GRAMMAR_SWITCH" };
-
- // =========================================================================
// States debug strings
// =========================================================================
/** A string representation of all the states */
private static String[] SubEntryString = new String[]
- { "SUB_ENTRY_VISIBILITY_TAG", "SUB_ENTRY_VISIBILITY_VALUE", };
+ {
+ "START_STATE",
+ "SUB_ENTRY_VISIBILITY_STATE"
+ };
/** The instance */
private static SubEntryControlStatesEnum instance = new SubEntryControlStatesEnum();
@@ -106,27 +90,19 @@
/**
* Get the grammar name
*
- * @param grammar
- * The grammar code
+ * @param grammar The grammar code
* @return The grammar name
*/
public String getGrammarName( int grammar )
{
- switch ( grammar )
- {
- case SUB_ENTRY_GRAMMAR:
- return "SUB_ENTRY_GRAMMAR";
- default:
- return "UNKNOWN";
- }
+ return "SUB_ENTRY_GRAMMAR";
}
/**
* Get the grammar name
*
- * @param grammar
- * The grammar class
+ * @param grammar The grammar class
* @return The grammar name
*/
public String getGrammarName( IGrammar grammar )
@@ -143,32 +119,11 @@
/**
* Get the string representing the state
*
- * @param grammar
- * The current grammar being used
- * @param state
- * The state number
+ * @param state The state number
* @return The String representing the state
*/
- public String getState( int grammar, int state )
+ public String getState( int state )
{
-
- if ( ( state & GRAMMAR_SWITCH_MASK ) != 0 )
- {
- return ( state == END_STATE ) ? "END_STATE"
- : GrammarSwitchString[( ( state & GRAMMAR_SWITCH_MASK ) >> 8 ) - 1];
- }
- else
- {
-
- switch ( grammar )
- {
-
- case SUB_ENTRY_GRAMMAR:
- return ( ( state == GRAMMAR_END ) ? "SUB_ENTRY_END_STATE" : SubEntryString[state] );
-
- default:
- return "UNKNOWN";
- }
- }
+ return ( ( state == GRAMMAR_END ) ? "SUB_ENTRY_END_STATE" : SubEntryString[state] );
}
}
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/unbind/UnBindRequest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/unbind/UnBindRequest.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/unbind/UnBindRequest.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/unbind/UnBindRequest.java Tue Oct 3 06:49:43 2006
@@ -29,8 +29,12 @@
/**
- * A UnBindRequest ldapObject. Its syntax is : UnbindRequest ::= [APPLICATION 2]
- * NULL This ldapObject is empty.
+ * A UnBindRequest ldapObject.
+ *
+ * Its syntax is :
+ * UnbindRequest ::= [APPLICATION 2] NULL
+ *
+ * This ldapObject is empty.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@@ -66,7 +70,10 @@
/**
- * Compute the UnBindRequest length UnBindRequest : 0x42 00
+ * Compute the UnBindRequest length
+ *
+ * UnBindRequest :
+ * 0x42 00
*/
public int computeLength()
{
@@ -77,8 +84,7 @@
/**
* Encode the UnbindRequest message to a PDU.
*
- * @param buffer
- * The buffer where to put the PDU
+ * @param buffer The buffer where to put the PDU
* @return The PDU.
*/
public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java Tue Oct 3 06:49:43 2006
@@ -21,7 +21,6 @@
import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.ldap.codec.util.LdapString;
import org.apache.directory.shared.ldap.filter.FilterParserImpl;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -42,19 +41,28 @@
/**
- * Decodes a LdapUrl, and checks that it complies with the RFC 2255. The grammar
- * is the following : ldapurl = scheme "://" [hostport] ["/" [dn ["?"
- * [attributes] ["?" [scope] ["?" [filter] ["?" extensions]]]]]] scheme = "ldap"
- * attributes = attrdesc *("," attrdesc) scope = "base" / "one" / "sub" dn =
- * LdapDN hostport = hostport from Section 5 of RFC 1738 attrdesc =
- * AttributeDescription from Section 4.1.5 of RFC 2251 filter = filter from
- * Section 4 of RFC 2254 extensions = extension *("," extension) extension =
- * ["!"] extype ["=" exvalue] extype = token / xtoken exvalue = LDAPString token =
- * oid from section 4.1 of RFC 2252 xtoken = ("X-" / "x-") token
+ * Decodes a LdapUrl, and checks that it complies with
+ * the RFC 2255. The grammar is the following :
+ * ldapurl = scheme "://" [hostport] ["/"
+ * [dn ["?" [attributes] ["?" [scope]
+ * ["?" [filter] ["?" extensions]]]]]]
+ * scheme = "ldap"
+ * attributes = attrdesc *("," attrdesc)
+ * scope = "base" / "one" / "sub"
+ * dn = LdapDN
+ * hostport = hostport from Section 5 of RFC 1738
+ * attrdesc = AttributeDescription from Section 4.1.5 of RFC 2251
+ * filter = filter from Section 4 of RFC 2254
+ * extensions = extension *("," extension)
+ * extension = ["!"] extype ["=" exvalue]
+ * extype = token / xtoken
+ * exvalue = LDAPString
+ * token = oid from section 4.1 of RFC 2252
+ * xtoken = ("X-" / "x-") token
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class LdapURL extends LdapString
+public class LdapURL
{
// ~ Static fields/initializers
// -----------------------------------------------------------------
@@ -95,7 +103,12 @@
/** The criticals extensions */
private HashMap criticalExtensions;
+ /** Stores the LdapURL as a String */
+ private String string;
+ /** Stores the LdapURL as a byte array */
+ private byte[] bytes;
+
// ~ Constructors
// -------------------------------------------------------------------------------
@@ -115,7 +128,11 @@
criticalExtensions = new HashMap();
}
-
+ /**
+ * Parse a LdapURL
+ * @param chars The chars containing the URL
+ * @throws LdapURLEncodingException If the URL is invalid
+ */
public void parse( char[] chars ) throws LdapURLEncodingException
{
host = null;
@@ -277,13 +294,11 @@
/**
* Create a new LdapURL from a String after having parsed it.
*
- * @param string
- * TheString that contains the LDAPURL
+ * @param string TheString that contains the LDAPURL
* @return A MutableString containing the LDAPURL
- * @throws DecoderException
- * If the String does not comply with RFC 2255
+ * @throws DecoderException If the String does not comply with RFC 2255
*/
- public LdapURL(String string) throws LdapURLEncodingException
+ public LdapURL( String string ) throws LdapURLEncodingException
{
if ( string == null )
{
@@ -306,11 +321,9 @@
/**
* Create a new LdapURL after having parsed it.
*
- * @param bytes
- * The byte buffer that contains the LDAPURL
+ * @param bytes The byte buffer that contains the LDAPURL
* @return A MutableString containing the LDAPURL
- * @throws DecoderException
- * If the byte array does not comply with RFC 2255
+ * @throws DecoderException If the byte array does not comply with RFC 2255
*/
public LdapURL(byte[] bytes) throws LdapURLEncodingException
{
@@ -350,10 +363,8 @@
* <digits> "." <digits>
* </p>
*
- * @param chars
- * The buffer to parse
- * @param pos
- * The current position in the byte buffer
+ * @param chars The buffer to parse
+ * @param pos The current position in the byte buffer
* @return The new position in the byte buffer, or -1 if the rule does not
* apply to the byte buffer TODO check that the topLabel is valid
* (it must start with an alpha)
@@ -508,10 +519,8 @@
* </p>
* The port must be between 0 and 65535.
*
- * @param chars
- * The buffer to parse
- * @param pos
- * The current position in the byte buffer
+ * @param chars The buffer to parse
+ * @param pos The current position in the byte buffer
* @return The new position in the byte buffer, or -1 if the rule does not
* apply to the byte buffer
*/
@@ -549,10 +558,8 @@
* <hostport> ::= <host> ':' <port>
* </p>
*
- * @param chars
- * The char array to parse
- * @param pos
- * The current position in the byte buffer
+ * @param chars The char array to parse
+ * @param pos The current position in the byte buffer
* @return The new position in the byte buffer, or -1 if the rule does not
* apply to the byte buffer
*/
@@ -589,14 +596,10 @@
* characters to a string. If the specified charset is not supported,
* default system encoding is used.
*
- * @param data
- * the byte array to be encoded
- * @param offset
- * the index of the first byte to encode
- * @param length
- * the number of bytes to encode
- * @param charset
- * the desired character encoding
+ * @param data the byte array to be encoded
+ * @param offset the index of the first byte to encode
+ * @param length the number of bytes to encode
+ * @param charset the desired character encoding
* @return The result of the conversion.
* @since 3.0
*/
@@ -628,10 +631,8 @@
* characters to a string. If the specified charset is not supported,
* default system encoding is used.
*
- * @param data
- * the byte array to be encoded
- * @param charset
- * the desired character encoding
+ * @param data the byte array to be encoded
+ * @param charset the desired character encoding
* @return The result of the conversion.
* @since 3.0
*/
@@ -644,8 +645,7 @@
/**
* Converts the specified string to byte array of ASCII characters.
*
- * @param data
- * the string to be encoded
+ * @param data the string to be encoded
* @return The string as a byte array.
* @since 3.0
*/
@@ -673,11 +673,9 @@
* array of original bytes. Escaped characters are converted back to their
* original representation.
*
- * @param bytes
- * array of URL safe characters
+ * @param bytes array of URL safe characters
* @return array of original bytes
- * @throws DecoderException
- * Thrown if URL decoding is unsuccessful
+ * @throws DecoderException Thrown if URL decoding is unsuccessful
*/
private static final byte[] decodeUrl( byte[] bytes ) throws UrlDecoderException
{
@@ -729,11 +727,9 @@
* From commons-httpclients. Unescape and decode a given string regarded as
* an escaped string with the default protocol charset.
*
- * @param escaped
- * a string
+ * @param escaped a string
* @return the unescaped string
- * @throws URIException
- * if the string cannot be decoded (invalid)
+ * @throws URIException if the string cannot be decoded (invalid)
* @see URI#getDefaultProtocolCharset
*/
private static String decode( String escaped ) throws URIException
@@ -754,10 +750,8 @@
* Parse a string and check that it complies with RFC 2253. Here, we will
* just call the LdapDN parser to do the job.
*
- * @param chars
- * The char array to be checked
- * @param pos
- * the starting position
+ * @param chars The char array to be checked
+ * @param pos the starting position
* @return -1 if the char array does not contains a DN
*/
private int parseDN( char[] chars, int pos )
@@ -790,10 +784,8 @@
/**
* Parse the attributes part
*
- * @param chars
- * The char array to be checked
- * @param pos
- * the starting position
+ * @param chars The char array to be checked
+ * @param pos the starting position
* @return -1 if the char array does not contains attributes
*/
private int parseAttributes( char[] chars, int pos )
@@ -900,10 +892,8 @@
/**
* Parse the filter part. We will use the FilterParserImpl class
*
- * @param chars
- * The char array to be checked
- * @param pos
- * the starting position
+ * @param chars The char array to be checked
+ * @param pos the starting position
* @return -1 if the char array does not contains a filter
*/
private int parseFilter( char[] chars, int pos )
@@ -941,10 +931,8 @@
/**
* Parse the scope part.
*
- * @param chars
- * The char array to be checked
- * @param pos
- * the starting position
+ * @param chars The char array to be checked
+ * @param pos the starting position
* @return -1 if the char array does not contains a scope
*/
private int parseScope( char[] chars, int pos )
@@ -1018,14 +1006,14 @@
/**
- * Parse extensions and critical extensions. The grammar is : extensions ::=
- * extension [ ',' extension ]* extension ::= [ '!' ] ( token | ( 'x-' |
- * 'X-' ) token ) ) [ '=' exvalue ]
+ * Parse extensions and critical extensions.
*
- * @param char
- * The char array to be checked
- * @param pos
- * the starting position
+ * The grammar is :
+ * extensions ::= extension [ ',' extension ]*
+ * extension ::= [ '!' ] ( token | ( 'x-' | 'X-' ) token ) ) [ '=' exvalue ]
+ *
+ * @param char The char array to be checked
+ * @param pos the starting position
* @return -1 if the char array does not contains valid extensions or
* critical extensions
*/
@@ -1153,15 +1141,16 @@
/**
- * Encode a String to avoid special characters *NOTE* : this is an ugly
- * function, just needed because the RFC 2255 is VERY unclear about the way
- * LDAP searches are to be encoded. Some references to RFC 1738 are made,
- * but they are really useless and inadequat.
+ * Encode a String to avoid special characters
+ *
+ * *NOTE* : this is an ugly function, just needed because the RFC 2255
+ * is VERY unclear about the way LDAP searches are to be encoded.
*
- * @param string
- * The String to encode
- * @param doubleEncode
- * Set if we need to encode the comma
+ * Some references to RFC 1738 are made, but they are really useless
+ * and inadequat.
+ *
+ * @param string The String to encode
+ * @param doubleEncode Set if we need to encode the comma
* @return An encoded string
*/
private String urlEncode( String string, boolean doubleEncode )
@@ -1423,5 +1412,29 @@
public String getScheme()
{
return scheme;
+ }
+
+ /**
+ * @return the number of bytes for this LdapURL
+ */
+ public int getNbBytes()
+ {
+ return ( bytes != null ? bytes.length : 0 );
+ }
+
+ /**
+ * @return the bytes representing this LdapURL
+ */
+ public byte[] getBytes()
+ {
+ return bytes;
+ }
+
+ /**
+ * @return the LdapURL as a String
+ */
+ public String getString()
+ {
+ return string;
}
}
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Tue Oct 3 06:49:43 2006
@@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;
import java.io.FileFilter;
+import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.regex.Pattern;
@@ -47,9 +48,9 @@
public class StringTools
{
/** The default charset, because it's not provided by JDK 1.5 */
- private static final String DEFAULT_CHARSET_JDK_1_4 = new OutputStreamWriter( new ByteArrayOutputStream() ).getEncoding();
- private static final String DEFAULT_CHARSET_JDK_1_5 = Charset.defaultCharset().name();
- private static final String JAVA_VERSION = System.getProperty( "java.version" );
+ static String defaultCharset = null;
+
+
// ~ Static fields/initializers
// -----------------------------------------------------------------
@@ -2686,21 +2687,30 @@
}
/**
+ * Get the default charset
+ *
* @return The default charset
*/
public static final String getDefaultCharsetName()
{
- if ( JAVA_VERSION.startsWith( "1.4" ) )
- {
- return DEFAULT_CHARSET_JDK_1_4;
- }
- else
- {
- return DEFAULT_CHARSET_JDK_1_5;
- }
- }
-
+ if (null == defaultCharset)
+ {
+ try
+ {
+ // Try with jdk 1.5 method, if we are using a 1.5 jdk :)
+ Method method = Charset.class.getMethod( "defaultCharset", new Class[0] );
+ defaultCharset = ((Charset) method.invoke( null, new Object[0]) ).name();
+ }
+ catch (Exception e)
+ {
+ // fall back to old method
+ defaultCharset = new OutputStreamWriter( new ByteArrayOutputStream() ).getEncoding();
+ }
+ }
+ return defaultCharset;
+ }
+
/**
* Decodes values of attributes in the DN encoded in hex into a UTF-8
* String. RFC2253 allows a DN's attribute to be encoded in hex.
@@ -2806,5 +2816,29 @@
}
return advanceBy;
+ }
+
+ /**
+ * Thansform an array of ASCII bytes to a string. the byte array should contains
+ * only values in [0, 127].
+ *
+ * @param bytes The byte array to transform
+ * @return The resulting string
+ */
+ public static String asciiBytesToString( byte[] bytes )
+ {
+ if ( (bytes == null) || (bytes.length == 0 ) )
+ {
+ return "";
+ }
+
+ char[] result = new char[bytes.length];
+
+ for ( int i = 0; i < bytes.length; i++ )
+ {
+ result[i] = (char)bytes[i];
+ }
+
+ return new String( result );
}
}
Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java (original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java Tue Oct 3 06:49:43 2006
@@ -32,7 +32,6 @@
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.bind.BindRequest;
import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
-import org.apache.directory.shared.ldap.codec.del.DelRequest;
import org.apache.directory.shared.ldap.util.StringTools;
import java.nio.ByteBuffer;
@@ -305,19 +304,20 @@
ByteBuffer stream = ByteBuffer.allocate( 0x35 );
stream.put( new byte[]
- { 0x30, 0x33, // LDAPMessage ::=SEQUENCE {
- // Length should be 0x01...
- 0x02, 0x02, 0x01, // messageID MessageID
- 0x60, 0x2E, // CHOICE { ..., bindRequest BindRequest, ...
- // BindRequest ::= APPLICATION[0] SEQUENCE {
- 0x02, 0x01, 0x03, // version INTEGER (1..127),
- 0x04, 0x1F, // name LDAPDN,
- 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
- 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0x80, 0x08, // authentication
- // AuthenticationChoice
- // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
- // ...
- 'p', 'a', 's', 's', 'w', 'o', 'r' } );
+ {
+ 0x30, 0x33, // LDAPMessage ::=SEQUENCE {
+ // Length should be 0x01...
+ 0x02, 0x02, 0x01, // messageID MessageID
+ 0x60, 0x2E, // CHOICE { ..., bindRequest BindRequest, ...
+ // BindRequest ::= APPLICATION[0] SEQUENCE {
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ 0x04, 0x1F, // name LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
+ 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ ( byte ) 0x80, 0x08, // authentication AuthenticationChoice
+ // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
+ // ...
+ 'p', 'a', 's', 's', 'w', 'o', 'r' } );
stream.flip();
@@ -331,7 +331,7 @@
}
catch ( DecoderException de )
{
- assertEquals( "Universal tag 14 is reserved", de.getMessage() );
+ assertEquals( "Bad transition !", de.getMessage() );
return;
}
catch ( NamingException ne )
@@ -394,17 +394,20 @@
}
/**
- * Test the decoding of a splitted length
+ * Test the decoding of a splitted Length.
+ *
+ * The length is 3 bytes long, but the PDU has been splitted
+ * just after the first byte
*/
- public void testDecodeSplittedLength() throws NamingException
+ public void testDecodeSplittedLength()
{
- Asn1Decoder ldapDecoder = new LdapDecoder();
- ByteBuffer stream = ByteBuffer.allocate( 0x03 );
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+ ByteBuffer stream = ByteBuffer.allocate( 3 );
stream.put( new byte[]
- {
- 0x30, (byte)0x82, 0x01 // LDAPMessage ::= SEQUENCE {
+ {
+ 0x30, (byte)0x82, 0x01,// LDAPMessage ::=SEQUENCE {
} );
stream.flip();
@@ -412,7 +415,7 @@
// Allocate a LdapMessage Container
IAsn1Container ldapMessageContainer = new LdapMessageContainer();
- // Decode a DelRequest PDU
+ // Decode a BindRequest PDU first block of data
try
{
ldapDecoder.decode( stream, ldapMessageContainer );
@@ -422,29 +425,24 @@
de.printStackTrace();
fail( de.getMessage() );
}
+ catch ( NamingException ne )
+ {
+ ne.printStackTrace();
+ fail( ne.getMessage() );
+ }
assertEquals( TLVStateEnum.LENGTH_STATE_PENDING, ldapMessageContainer.getState() );
- stream = ByteBuffer.allocate( 0x101 );
-
+ // Second block of data
+ stream = ByteBuffer.allocate( 1 );
stream.put( new byte[]
- {
- 0x00, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., delRequest DelRequest, ...
- // DelRequest ::= [APPLICATION 10] LDAPDN;
- 0x4A, (byte)0x81, (byte)0xFA,
- 'c', 'n', '=',
+ {
+ (byte)0x80 // End of the length
} );
- for ( int i = 0; i < 0xFA - 3; i++ )
- {
- stream.put( (byte)'a' );
- }
-
stream.flip();
- // Decode a DelRequest PDU
+ // Decode a BindRequest PDU second block of data
try
{
ldapDecoder.decode( stream, ldapMessageContainer );
@@ -454,15 +452,15 @@
de.printStackTrace();
fail( de.getMessage() );
}
+ catch ( NamingException ne )
+ {
+ ne.printStackTrace();
+ fail( ne.getMessage() );
+ }
- // Check the decoded DelRequest PDU
- LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
- DelRequest delRequest = message.getDelRequest();
-
- assertEquals( 1, message.getMessageId() );
- assertEquals( "cn=aaaaaaaaaaaaaaaaa", delRequest.getEntry().toString().substring( 0, 20 ) );
+ assertEquals( TLVStateEnum.LENGTH_STATE_END, ldapMessageContainer.getState() );
- // Check the length
- assertEquals( 0x104, message.computeLength() );
+ // Check the decoded length
+ assertEquals( 384, ldapMessageContainer.getCurrentTLV().getLength() );
}
}
Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java?view=diff&rev=452497&r1=452496&r2=452497
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java (original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java Tue Oct 3 06:49:43 2006
@@ -54,31 +54,32 @@
* Test the decoding of a BindRequest with Simple authentication and no
* controls
*/
- public void testDecodeBindRequestSimpleNoControls()
+ /* Not used in unit tests
+ public void testDecodeBindRequestSimpleNoControlsPerf()
{
Asn1Decoder ldapDecoder = new LdapDecoder();
ByteBuffer stream = ByteBuffer.allocate( 0x52 );
stream.put( new byte[]
- {
- 0x30, 0x50, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x60, 0x2E, // CHOICE { ..., bindRequest BindRequest, ...
- // BindRequest ::= APPLICATION[0] SEQUENCE {
- 0x02, 0x01, 0x03, // version INTEGER (1..127),
- 0x04, 0x1F, // name LDAPDN,
- 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
- 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
- ( byte ) 0x80, 0x08, // authentication AuthenticationChoice
- // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
- // ...
- 'p', 'a', 's', 's', 'w', 'o', 'r', 'd',
- ( byte ) 0xA0, 0x1B, // A control
- 0x30, 0x19,
- 0x04, 0x17,
- 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33,
- 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
- } );
+ {
+ 0x30, 0x50, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x2E, // CHOICE { ..., bindRequest BindRequest, ...
+ // BindRequest ::= APPLICATION[0] SEQUENCE {
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ 0x04, 0x1F, // name LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
+ 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ ( byte ) 0x80, 0x08, // authentication AuthenticationChoice
+ // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
+ // ...
+ 'p', 'a', 's', 's', 'w', 'o', 'r', 'd',
+ ( byte ) 0xA0, 0x1B, // A control
+ 0x30, 0x19,
+ 0x04, 0x17,
+ 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33,
+ 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
+ } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -89,6 +90,16 @@
// Decode the BindRequest PDU
try
{
+ long t0 = System.currentTimeMillis();
+ for ( int i = 0; i < 10000; i++ )
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ ( ( LdapMessageContainer ) ldapMessageContainer).clean();
+ stream.flip();
+ }
+ long t1 = System.currentTimeMillis();
+ System.out.println( "Delta = " + ( t1 - t0 ) );
+
ldapDecoder.decode( stream, ldapMessageContainer );
}
catch ( DecoderException de )
@@ -140,7 +151,7 @@
fail( ee.getMessage() );
}
}
-
+ */
/**
* Test the decoding of a BindRequest with Simple authentication and
@@ -306,8 +317,7 @@
}
catch ( DecoderException de )
{
- assertEquals( "Cannot pop the grammar BIND_REQUEST_GRAMMAR for state BIND_REQUEST_NAME_TAG", de
- .getMessage() );
+ assertEquals( "Bad transition !", de.getMessage() );
return;
}
catch ( NamingException ne )
@@ -1328,4 +1338,51 @@
fail( ee.getMessage() );
}
}
+
+ /**
+ * Test the decoding of a BindRequest with Simple authentication and no
+ * controls
+ */
+ /* No used by unit tests
+ public void testPerf() throws Exception
+ {
+ LdapDN name = new LdapDN( "uid=akarasulu,dc=example,dc=com" );
+ long t0 = System.currentTimeMillis();
+
+ for ( int i = 0; i< 10000; i++)
+ {
+ // Check the decoded BindRequest
+ LdapMessage message = new LdapMessage();
+ message.setMessageId( 1 );
+
+ BindRequest br = new BindRequest();
+ br.setMessageId( 1 );
+ br.setName( name );
+
+ Control control = new Control();
+ control.setControlType( "2.16.840.1.113730.3.4.2" );
+
+ LdapAuthentication authentication = new SimpleAuthentication();
+ ((SimpleAuthentication)authentication).setSimple( StringTools.getBytesUtf8( "password" ) );
+
+ br.addControl( control );
+ br.setAuthentication( authentication );
+ message.setProtocolOP( br );
+
+ // Check the encoding
+ try
+ {
+ message.encode( null );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+ long t1 = System.currentTimeMillis();
+ System.out.println( "Delta = " + (t1 - t0));
+ }
+ */
}