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 2010/09/05 10:41:59 UTC
svn commit: r992728 - in /directory/shared/trunk:
asn1/src/main/java/org/apache/directory/shared/asn1/
asn1/src/main/java/org/apache/directory/shared/asn1/ber/
i18n/src/main/java/org/apache/directory/shared/i18n/
i18n/src/main/resources/org/apache/dire...
Author: elecharny
Date: Sun Sep 5 08:41:59 2010
New Revision: 992728
URL: http://svn.apache.org/viewvc?rev=992728&view=rev
Log:
o Reviewed the files, checking for many aspects (javadoc, etc)
o Added some missing I18n messages
o Renamed some ERR_XXXXXX errors
Modified:
directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/AbstractAsn1Object.java
directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/Asn1Object.java
directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/AbstractContainer.java
directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java
directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java
directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
Modified: directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/AbstractAsn1Object.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/AbstractAsn1Object.java?rev=992728&r1=992727&r2=992728&view=diff
==============================================================================
--- directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/AbstractAsn1Object.java (original)
+++ directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/AbstractAsn1Object.java Sun Sep 5 08:41:59 2010
@@ -34,9 +34,6 @@ import org.apache.directory.shared.i18n.
*/
public abstract class AbstractAsn1Object implements Asn1Object
{
- // ~ Instance fields
- // ----------------------------------------------------------------------------
-
/** The object's current length. It is used while decoding PDUs */
private int currentLength;
@@ -44,17 +41,13 @@ public abstract class AbstractAsn1Object
private int expectedLength;
/** The encapsulating Object */
- protected AbstractAsn1Object parent;
-
+ private AbstractAsn1Object parent;
/** The identifier of the associated TLV */
private int tlvId;
- // ~ Methods
- // ------------------------------------------------------------------------------------
-
/**
- * Constructor associated with a TLV indentifier. Used when
+ * Constructor associated with a TLV identifier. Used when
* decoded a TLV, we create an association between the decode
* Asn1Object and the TLV which is the encoded form.
*
@@ -122,10 +115,8 @@ public abstract class AbstractAsn1Object
/**
* Add a length to the object
*
- * @param length
- * The length to add.
- * @throws DecoderException
- * Thrown if the current length exceed the expected length
+ * @param length The length to add.
+ * @throws DecoderException Thrown if the current length exceed the expected length
*/
public void addLength( int length ) throws DecoderException
{
@@ -141,8 +132,7 @@ public abstract class AbstractAsn1Object
/**
* Set the expected length
*
- * @param expectedLength
- * The expectedLength to set.
+ * @param expectedLength The expectedLength to set.
*/
public void setExpectedLength( int expectedLength )
{
@@ -153,8 +143,7 @@ public abstract class AbstractAsn1Object
/**
* Set the current length
*
- * @param currentLength
- * The currentLength to set.
+ * @param currentLength The currentLength to set.
*/
public void setCurrentLength( int currentLength )
{
@@ -176,8 +165,7 @@ public abstract class AbstractAsn1Object
/**
* Set the parent
*
- * @param parent
- * The parent to set.
+ * @param parent The parent to set.
*/
public void setParent( AbstractAsn1Object parent )
{
Modified: directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/Asn1Object.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/Asn1Object.java?rev=992728&r1=992727&r2=992728&view=diff
==============================================================================
--- directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/Asn1Object.java (original)
+++ directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/Asn1Object.java Sun Sep 5 08:41:59 2010
@@ -71,10 +71,8 @@ public interface Asn1Object
/**
* Add a length to the object
*
- * @param length
- * The length to add.
- * @throws DecoderException
- * Thrown if the current length exceed the expected length
+ * @param length The length to add.
+ * @throws DecoderException Thrown if the current length exceed the expected length
*/
void addLength( int length ) throws DecoderException;
@@ -82,8 +80,7 @@ public interface Asn1Object
/**
* Set the expected length
*
- * @param expectedLength
- * The expectedLength to set.
+ * @param expectedLength The expectedLength to set.
*/
void setExpectedLength( int expectedLength );
@@ -91,8 +88,7 @@ public interface Asn1Object
/**
* Set the current length
*
- * @param currentLength
- * The currentLength to set.
+ * @param currentLength The currentLength to set.
*/
void setCurrentLength( int currentLength );
Modified: directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/AbstractContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/AbstractContainer.java?rev=992728&r1=992727&r2=992728&view=diff
==============================================================================
--- directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/AbstractContainer.java (original)
+++ directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/AbstractContainer.java Sun Sep 5 08:41:59 2010
@@ -28,16 +28,13 @@ import org.apache.directory.shared.asn1.
/**
* This class is the abstract container used to store the current state of a PDU
- * being decoded. It also stores the grammars used to decode the PDU, and zll
+ * being decoded. It also stores the grammars used to decode the PDU, and all
* the informations needed to decode a PDU.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class AbstractContainer implements IAsn1Container
+public abstract class AbstractContainer implements IAsn1Container
{
- // ~ Instance fields
- // ----------------------------------------------------------------------------
-
/** All the possible grammars */
protected IGrammar grammar;
@@ -45,35 +42,32 @@ public class AbstractContainer implement
protected int[] stateStack;
/** The current state of the decoding */
- protected int state;
+ private int state;
/** The current transition */
- protected int transition;
+ private int transition;
/** The current TLV */
- protected TLV tlv;
+ private TLV tlv;
/** Store the different states for debug purpose */
protected IStates states;
/** The parent TLV */
- protected TLV parentTLV;
+ private TLV parentTLV;
/** The grammar end transition flag */
- protected boolean grammarEndAllowed;
+ private boolean grammarEndAllowed;
/** A counter for the decoded bytes */
protected int decodeBytes;
/** The maximum allowed size for a PDU. Default to MAX int value */
- protected int maxPDUSize = Integer.MAX_VALUE;
+ private int maxPDUSize = Integer.MAX_VALUE;
/** The incremental id used to tag TLVs */
private int id = 0;
- // ~ Methods
- // ------------------------------------------------------------------------------------
-
/**
* Get the current grammar
*
Modified: directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java?rev=992728&r1=992727&r2=992728&view=diff
==============================================================================
--- directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java (original)
+++ directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java Sun Sep 5 08:41:59 2010
@@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory;
/**
- * A BER TLV Tag component decoder. This decoder instanciate a Tag. The tag
+ * A BER TLV Tag component decoder. This decoder instantiate a Tag. The tag
* won't be implementations should not copy the handle to the Tag object
* delivered but should copy the data if they need it over the long term.
*
@@ -58,9 +58,6 @@ public class Asn1Decoder implements ITLV
/** This flag is used to indicate that there are no more bytes in the stream */
private static final boolean END = false;
- // ~ Instance fields
- // ----------------------------------------------------------------------------
-
/** Flag that is used to allow/disallow the indefinite form of Length */
private boolean indefiniteLengthAllowed;
@@ -71,9 +68,6 @@ public class Asn1Decoder implements ITLV
private int maxTagLength;
- // ~ Constructors
- // -------------------------------------------------------------------------------
-
/**
* A public constructor of an Asn1 Decoder.
*/
@@ -85,9 +79,6 @@ public class Asn1Decoder implements ITLV
}
- // ~ Methods
- // ------------------------------------------------------------------------------------
-
/**
* Treat the start of a TLV. It reads the tag and get its value.
*
@@ -99,10 +90,8 @@ public class Asn1Decoder implements ITLV
*/
private boolean treatTagStartState( ByteBuffer stream, IAsn1Container container )
{
-
if ( stream.hasRemaining() )
{
-
byte octet = stream.get();
TLV tlv = new TLV( container.getNewTlvId() );
@@ -127,12 +116,12 @@ public class Asn1Decoder implements ITLV
}
else
{
-
// The stream has been exhausted
return END;
}
}
+
/**
* Dump the current TLV tree
*
@@ -171,7 +160,6 @@ public class Asn1Decoder implements ITLV
private boolean isTLVDecoded( IAsn1Container container )
{
TLV current = container.getCurrentTLV();
-
TLV parent = current.getParent();
while ( parent != null )
@@ -196,6 +184,7 @@ public class Asn1Decoder implements ITLV
}
}
+
/**
* Treat the Length start. The tag has been decoded, so we have to deal with
* the LENGTH, which can be multi-bytes.
@@ -209,7 +198,6 @@ public class Asn1Decoder implements ITLV
*/
private boolean treatLengthStartState( ByteBuffer stream, IAsn1Container container ) throws DecoderException
{
-
if ( stream.hasRemaining() )
{
byte octet = stream.get();
@@ -217,7 +205,6 @@ public class Asn1Decoder implements ITLV
if ( ( octet & TLV.LENGTH_LONG_FORM ) == 0 )
{
-
// We don't have a long form. The Length of the Value part is
// given by this byte.
tlv.setLength( octet );
@@ -227,12 +214,11 @@ public class Asn1Decoder implements ITLV
}
else if ( ( octet & TLV.LENGTH_EXTENSION_RESERVED ) != TLV.LENGTH_EXTENSION_RESERVED )
{
-
int expectedLength = octet & TLV.LENGTH_SHORT_MASK;
if ( expectedLength > 4 )
{
- String msg = I18n.err( I18n.ERR_00005 );
+ String msg = I18n.err( I18n.ERR_LENGTH_OVERFLOW_00005 );
LOG.error( msg );
throw new DecoderException( msg );
}
@@ -244,7 +230,7 @@ public class Asn1Decoder implements ITLV
}
else
{
- String msg = I18n.err( I18n.ERR_00006 );
+ String msg = I18n.err( I18n.ERR_LENGTH_EXTENSION_RESERVED_00006 );
LOG.error( msg );
throw new DecoderException( msg );
}
@@ -270,16 +256,13 @@ public class Asn1Decoder implements ITLV
*/
private boolean treatLengthPendingState( ByteBuffer stream, IAsn1Container container )
{
-
if ( stream.hasRemaining() )
{
-
TLV tlv = container.getCurrentTLV();
int length = tlv.getLength();
while ( tlv.getLengthBytesRead() < tlv.getLengthNbBytes() )
{
-
byte octet = stream.get();
if ( IS_DEBUG )
@@ -364,7 +347,7 @@ public class Asn1Decoder implements ITLV
if ( tlv == null )
{
- String msg = I18n.err( I18n.ERR_00007 );
+ String msg = I18n.err( I18n.ERR_TLV_NULL_00007 );
LOG.error( msg );
throw new DecoderException( msg );
}
@@ -404,8 +387,8 @@ public class Asn1Decoder implements ITLV
{
// The expected length is lower than the Value length of the
// current TLV. This is an error...
- LOG.error( "tlv[{}, {}]", Integer.valueOf( expectedLength ), Integer.valueOf( currentLength ) );
- throw new DecoderException( I18n.err( I18n.ERR_00008, Integer.valueOf( currentLength ), Integer.valueOf( expectedLength ) ) );
+ LOG.debug( "tlv[{}, {}]", Integer.valueOf( expectedLength ), Integer.valueOf( currentLength ) );
+ throw new DecoderException( I18n.err( I18n.ERR_VALUE_LENGTH_ABOVE_EXPECTED_LENGTH_00008, Integer.valueOf( currentLength ), Integer.valueOf( expectedLength ) ) );
}
// deal with the particular case where expected length equal
@@ -526,7 +509,6 @@ public class Asn1Decoder implements ITLV
*/
private boolean treatValueStartState( ByteBuffer stream, IAsn1Container container )
{
-
TLV currentTlv = container.getCurrentTLV();
if ( TLV.isConstructed( currentTlv.getTag() ) )
@@ -537,7 +519,6 @@ public class Asn1Decoder implements ITLV
}
else
{
-
int length = currentTlv.getLength();
int nbBytes = stream.remaining();
@@ -573,7 +554,6 @@ public class Asn1Decoder implements ITLV
*/
private boolean treatValuePendingState( ByteBuffer stream, IAsn1Container container )
{
-
TLV currentTlv = container.getCurrentTLV();
int length = currentTlv.getLength();
@@ -589,7 +569,6 @@ public class Asn1Decoder implements ITLV
}
else
{
-
int remaining = length - currentLength;
byte[] data = new byte[remaining];
stream.get( data, 0, remaining );
@@ -639,11 +618,10 @@ public class Asn1Decoder implements ITLV
}
else
{
- LOG.error( I18n.err( I18n.ERR_00009 ) );
- throw new DecoderException( I18n.err( I18n.ERR_00010 ) );
+ LOG.error( I18n.err( I18n.ERR_MORE_TLV_EXPECTED_00009 ) );
+ throw new DecoderException( I18n.err( I18n.ERR_TRUNCATED_PDU_00010 ) );
}
}
-
}
else
{
@@ -664,10 +642,8 @@ public class Asn1Decoder implements ITLV
*/
private String stateToString( int state )
{
-
switch ( state )
{
-
case TLVStateEnum.TAG_STATE_START:
return "TAG_STATE_START";
@@ -714,18 +690,16 @@ public class Asn1Decoder implements ITLV
*/
public void decode( ByteBuffer stream, IAsn1Container container ) throws DecoderException
{
-
/*
* We have to deal with the current state. This is an infinite loop,
* which will stop for any of these reasons :
* - STATE_END has been reached (hopefully, the most frequent case)
* - buffer is empty (it could happen)
* - STATE_OVERFLOW : bad situation ! The PDU may be a
- * malevolous hand crafted ones, that try to "kill" our decoder. Whe
+ * malevolous hand crafted ones, that try to "kill" our decoder. We
* must log it with all information to track back this case, and punish
* the guilty !
*/
-
boolean hasRemaining = stream.hasRemaining();
// Increment the PDU size counter.
@@ -733,8 +707,7 @@ public class Asn1Decoder implements ITLV
if ( container.getDecodeBytes() > container.getMaxPDUSize() )
{
- String message = "The PDU current size (" + container.getDecodeBytes() +
- ") exceeds the maximum allowed PDU size (" + container.getMaxPDUSize() +")";
+ String message = I18n.err( I18n.ERR_PDU_SIZE_TOO_LONG_00042, container.getDecodeBytes(), container.getMaxPDUSize() );
LOG.error( message );
throw new DecoderException( message );
}
@@ -748,7 +721,6 @@ public class Asn1Decoder implements ITLV
while ( hasRemaining )
{
-
if ( IS_DEBUG )
{
LOG.debug( "--- State = {} ---", stateToString( container.getState() ) );
@@ -767,7 +739,6 @@ public class Asn1Decoder implements ITLV
switch ( container.getState() )
{
-
case TLVStateEnum.TAG_STATE_START:
// Reset the GrammarEnd flag first
container.grammarEndAllowed( false );
@@ -814,7 +785,7 @@ public class Asn1Decoder implements ITLV
case TLVStateEnum.PDU_DECODED:
// We have to deal with the case where there are
// more bytes in the buffer, but the PDU has been decoded.
- LOG.warn( "The PDU has been fully decoded but there are still bytes in the buffer." );
+ LOG.warn( I18n.err( I18n.ERR_REMAINING_BYTES_FOR_DECODED_PDU_00043 ) );
hasRemaining = false;
@@ -901,7 +872,7 @@ public class Asn1Decoder implements ITLV
* Tells if indefinite length form could be used for Length
*
* @return Returns <code>true</code> if the current decoder support
- * indefinite length
+ * indefinite length
*/
public boolean isIndefiniteLengthAllowed()
{
@@ -911,7 +882,7 @@ public class Asn1Decoder implements ITLV
/**
- * Set the maximul length for a Length
+ * Set the maximal length for a Length
*
* @param maxLengthLength The lengthLength to set.
* @throws DecoderException Thrown if the indefinite length is
@@ -919,10 +890,9 @@ public class Asn1Decoder implements ITLV
*/
public void setMaxLengthLength( int maxLengthLength ) throws DecoderException
{
-
if ( ( this.indefiniteLengthAllowed ) && ( maxLengthLength > 126 ) )
{
- throw new DecoderException( I18n.err( I18n.ERR_00011 ) );
+ throw new DecoderException( I18n.err( I18n.ERR_LENGTH_TOO_LONG_FOR_DEFINITE_FORM_00011 ) );
}
this.maxLengthLength = maxLengthLength;
Modified: directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java?rev=992728&r1=992727&r2=992728&view=diff
==============================================================================
--- directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java (original)
+++ directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java Sun Sep 5 08:41:59 2010
@@ -39,13 +39,13 @@ public enum I18n
ERR_00002( "ERR_00002" ),
ERR_00003( "ERR_00003" ),
ERR_00004( "ERR_00004" ),
- ERR_00005( "ERR_00005" ),
- ERR_00006( "ERR_00006" ),
- ERR_00007( "ERR_00007" ),
- ERR_00008( "ERR_00008" ),
- ERR_00009( "ERR_00009" ),
- ERR_00010( "ERR_00010" ),
- ERR_00011( "ERR_00011" ),
+ ERR_LENGTH_OVERFLOW_00005( "ERR_LENGTH_OVERFLOW_00005" ),
+ ERR_LENGTH_EXTENSION_RESERVED_00006( "ERR_LENGTH_EXTENSION_RESERVED_00006" ),
+ ERR_TLV_NULL_00007( "ERR_TLV_NULL_00007" ),
+ ERR_VALUE_LENGTH_ABOVE_EXPECTED_LENGTH_00008( "ERR_VALUE_LENGTH_ABOVE_EXPECTED_LENGTH_00008" ),
+ ERR_MORE_TLV_EXPECTED_00009( "ERR_MORE_TLV_EXPECTED_00009" ),
+ ERR_TRUNCATED_PDU_00010( "ERR_TRUNCATED_PDU_00010" ),
+ ERR_LENGTH_TOO_LONG_FOR_DEFINITE_FORM_00011( "ERR_LENGTH_TOO_LONG_FOR_DEFINITE_FORM_00011" ),
ERR_00012( "ERR_00012" ),
ERR_00013( "ERR_00013" ),
ERR_00014( "ERR_00014" ),
@@ -76,6 +76,8 @@ public enum I18n
ERR_00039( "ERR_00039" ),
ERR_00040( "ERR_00040" ),
ERR_00041( "ERR_00041" ),
+ ERR_PDU_SIZE_TOO_LONG_00042( "ERR_PDU_SIZE_TOO_LONG_00042" ),
+ ERR_REMAINING_BYTES_FOR_DECODED_PDU_00043( "ERR_REMAINING_BYTES_FOR_DECODED_PDU_00043" ),
// asn1-codec
ERR_01001( "ERR_01001" ),
Modified: directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
URL: http://svn.apache.org/viewvc/directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties?rev=992728&r1=992727&r2=992728&view=diff
==============================================================================
--- directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties (original)
+++ directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties Sun Sep 5 08:41:59 2010
@@ -23,13 +23,13 @@ ERR_00001=Bad transition from state {0},
ERR_00002=Bad transition !
ERR_00003=Cannot put a PDU in a null buffer !
ERR_00004=The PDU buffer size is too small !
-ERR_00005=Overflow : can't have more than 4 bytes long length
-ERR_00006=Length reserved extension used
-ERR_00007=The current container TLV is null.
-ERR_00008=The current Value length {0} is above the expected length {1}
-ERR_00009=The PDU is decoded, but we should have had more TLVs
-ERR_00010=Truncated PDU. Some elements are lacking, accordingly to the grammar
-ERR_00011=Length above 126 bytes are not allowed for a definite form Length
+ERR_LENGTH_OVERFLOW_00005=Overflow : can't have more than 4 bytes long length
+ERR_LENGTH_EXTENSION_RESERVED_00006=Length reserved extension used
+ERR_TLV_NULL_00007=The current container TLV is null.
+ERR_VALUE_LENGTH_ABOVE_EXPECTED_LENGTH_00008=The current Value length {0} is above the expected length {1}
+ERR_MORE_TLV_EXPECTED_00009=The PDU is decoded, but we should have had more TLVs
+ERR_TRUNCATED_PDU_00010=Truncated PDU. Some elements are lacking, accordingly to the grammar
+ERR_LENGTH_TOO_LONG_FOR_DEFINITE_FORM_00011=Length above 126 bytes are not allowed for a definite form Length
ERR_00012=argument not a byte array
ERR_00013=Odd number of characters.
ERR_00014=Illegal hexadecimal character {0} at index {1}
@@ -60,6 +60,9 @@ ERR_00038=The value is not in the range
ERR_00039=The value is 0 byte long. This is not allowed for a long
ERR_00040=The value is more than 4 bytes long. This is not allowed for a long
ERR_00041=Current Length is above expected Length
+ERR_PDU_SIZE_TOO_LONG_00042=The PDU current size ({1}) exceeds the maximum allowed PDU size ({2})
+ERR_REMAINING_BYTES_FOR_DECODED_PDU_00043=The PDU has been fully decoded but there are still bytes in the buffer.
+
# asn1-codec
ERR_01001=Encoded result is not a ByteBuffer: {0}