Source code formating for the attribute classes, fix buggy attribute length calculation, add attributes from _old_ TURN draft specification.

This commit is contained in:
seb 2011-06-03 14:39:08 +00:00
parent 768db27837
commit b5e2234962
36 changed files with 765 additions and 408 deletions

View File

@ -100,7 +100,7 @@ abstract class AddressAttribute extends Attribute
|| type == SOURCE_ADDRESS || type == CHANGED_ADDRESS
|| type == REFLECTED_FROM || type == XOR_MAPPED_ADDRESS
|| type == ALTERNATE_SERVER || type == XOR_PEER_ADDRESS
|| type == XOR_RELAYED_ADDRESS);
|| type == XOR_RELAYED_ADDRESS || type == DESTINATION_ADDRESS);
}
/**
@ -262,7 +262,6 @@ abstract class AddressAttribute extends Attribute
return ADDRESS_FAMILY_IPV6;
else
return ADDRESS_FAMILY_IPV4;
}
/**
@ -300,10 +299,12 @@ abstract class AddressAttribute extends Attribute
//address
byte address[] = null;
if(family == ADDRESS_FAMILY_IPV6){
if(family == ADDRESS_FAMILY_IPV6)
{
address = new byte[16];
}
else{
else
{
//ipv4
address = new byte[4];
}
@ -317,7 +318,5 @@ abstract class AddressAttribute extends Attribute
{
throw new StunException(e);
}
}
}

View File

@ -30,7 +30,6 @@ package org.ice4j.attribute;
*
* @author Sebastien Vincent
*/
public class AlternateServerAttribute extends AddressAttribute
{
/**

View File

@ -65,41 +65,182 @@ import org.ice4j.*;
public abstract class Attribute
{
/* STUN attributes */
/**
* Mapped address attribute.
*/
public static final char MAPPED_ADDRESS = 0x0001;
/**
* Response address attribute.
*/
public static final char RESPONSE_ADDRESS = 0x0002;
/**
* Change request attribute.
*/
public static final char CHANGE_REQUEST = 0x0003;
/**
* Source address attribute.
*/
public static final char SOURCE_ADDRESS = 0x0004;
/**
* Changed address attribute.
*/
public static final char CHANGED_ADDRESS = 0x0005;
/**
* Username attribute.
*/
public static final char USERNAME = 0x0006;
/**
* Password attribute.
*/
public static final char PASSWORD = 0x0007;
/**
* Message integrity attribute.
*/
public static final char MESSAGE_INTEGRITY = 0x0008;
/**
* Error code attribute.
*/
public static final char ERROR_CODE = 0x0009;
/**
* Unknown attributes attribute.
*/
public static final char UNKNOWN_ATTRIBUTES = 0x000a;
/**
* Reflected from attribute.
*/
public static final char REFLECTED_FROM = 0x000b;
/**
* Realm attribute.
*/
public static final char REALM = 0x0014;
/**
* Nonce attribute.
*/
public static final char NONCE = 0x0015;
/**
* XOR Mapped address attribute.
*/
public static final char XOR_MAPPED_ADDRESS = 0x0020;
/**
* XOR only attribute.
*/
public static final char XOR_ONLY = 0x0021;
/**
* Software attribute.
*/
public static final char SOFTWARE = 0x8022;
/**
* Alternate server attribute.
*/
public static final char ALTERNATE_SERVER = 0x8023;
/**
* Fingerprint attribute.
*/
public static final char FINGERPRINT = 0x8028;
/**
* Unknown optional attribute.
*/
public static final char UNKNOWN_OPTIONAL_ATTRIBUTE = 0x8000;
/* TURN attributes */
/**
* Channel number attribute.
*/
public static final char CHANNEL_NUMBER = 0x000c;
/**
* Lifetime attribute.
*/
public static final char LIFETIME = 0x000d;
/**
* XOR peer address attribute.
*/
public static final char XOR_PEER_ADDRESS = 0x0012;
/**
* Data attribute.
*/
public static final char DATA = 0x0013;
/**
* XOR relayed address attribute.
*/
public static final char XOR_RELAYED_ADDRESS = 0x0016;
/**
* Even port attribute.
*/
public static final char EVEN_PORT = 0x0018;
/**
* Requested transport attribute.
*/
public static final char REQUESTED_TRANSPORT = 0x0019;
/**
* Don't fragment attribute.
*/
public static final char DONT_FRAGMENT = 0x001a;
/**
* Reservation token attribute.
*/
public static final char RESERVATION_TOKEN = 0x0022;
/* Old TURN attributes */
/**
* Magic cookie attribute.
*/
public static final char MAGIC_COOKIE = 0x000f;
/**
* Destination address attribute.
*/
public static final char DESTINATION_ADDRESS = 0x0011;
/**
* Destination address attribute.
*/
public static final char REMOTE_ADDRESS = 0x0012;
/* ICE attributes */
/**
* Priority attribute.
*/
public static final char PRIORITY = 0x0024;
/**
* Use candidate attribute.
*/
public static final char USE_CANDIDATE = 0x0025;
/**
* ICE controlled attribute.
*/
public static final char ICE_CONTROLLED = 0x8029;
/**
* ICE controlling attribute.
*/
public static final char ICE_CONTROLLING = 0x802a;
/**

View File

@ -43,7 +43,9 @@ public class AttributeDecoder
//Discover attribute type
char attributeType = (char)((bytes[offset] << 8) | bytes[offset + 1]);
char attributeLength = (char)((bytes[offset + 2]<<8)|bytes[offset + 3]);
int len1 = bytes[offset + 2] & 0xff;
int len2 = bytes[offset + 3] & 0xff;
char attributeLength = (char)((len1 << 8) | len2);
if(attributeLength > bytes.length - offset )
throw new StunException( StunException.ILLEGAL_ARGUMENT,

View File

@ -30,7 +30,7 @@ public class AttributeFactory
public static ChangeRequestAttribute createChangeRequestAttribute()
{
return createChangeRequestAttribute(false, false);
};
}
/**
* Creates a ChangeRequestAttribute with the specified flag values.
@ -48,7 +48,7 @@ public class AttributeFactory
attribute.setChangePortFlag(changePort);
return attribute;
};
}
/**
* Creates a changedAddressAttribute of the specified type and with the
@ -65,8 +65,7 @@ public class AttributeFactory
attribute.setAddress(address);
return attribute;
};
}
/**
* Creates an ErrorCodeAttribute with the specified error class and number
@ -83,7 +82,7 @@ public class AttributeFactory
throws StunException
{
return createErrorCodeAttribute(errorClass, errorNumber, null);
};
}
/**
* Creates an ErrorCodeAttribute with the specified error class, number and
@ -114,7 +113,7 @@ public class AttributeFactory
: reasonPhrase);
return attribute;
};
}
/**
* Creates an ErrorCodeAttribute with the specified error code and a default
@ -129,7 +128,7 @@ public class AttributeFactory
throws StunException
{
return createErrorCodeAttribute(errorCode, null);
};
}
/**
* Creates an ErrorCodeAttribute with the specified error code and reason
@ -157,7 +156,7 @@ public class AttributeFactory
: reasonPhrase);
return attribute;
};
}
/**
* Creates a MappedAddressAttribute of the specified type and with the
@ -174,8 +173,7 @@ public class AttributeFactory
attribute.setAddress(address);
return attribute;
};
}
/**
* Creates a ReflectedFromAddressAttribute of the specified type and with
@ -192,8 +190,7 @@ public class AttributeFactory
attribute.setAddress(address);
return attribute;
};
}
/**
* Creates a ResponseFromAddressAttribute of the specified type and with the
@ -210,8 +207,7 @@ public class AttributeFactory
attribute.setAddress(address);
return attribute;
};
}
/**
* Creates a SourceFromAddressAttribute of the specified type and with the
@ -228,8 +224,7 @@ public class AttributeFactory
attribute.setAddress(address);
return attribute;
};
}
/**
* Creates an empty UnknownAttributesAttribute.
@ -241,7 +236,7 @@ public class AttributeFactory
UnknownAttributesAttribute attribute = new UnknownAttributesAttribute();
return attribute;
};
}
/**
* Creates a XorRelayedAddressAttribute of the specified type and with the
@ -299,8 +294,7 @@ public class AttributeFactory
attribute.setAddress(address, tranID);
return attribute;
};
}
/**
* Create a UsernameAttribute.
@ -357,7 +351,7 @@ public class AttributeFactory
attribute.setUsername(username);
return attribute;
};
}
/**
* Creates an empty <tt>FingerprintAttribute</tt> with a 0 check sum. Once
@ -371,7 +365,7 @@ public class AttributeFactory
FingerprintAttribute attribute = new FingerprintAttribute();
return attribute;
};
}
/**
* Create a ChannelNumberAttribute.
@ -467,7 +461,8 @@ public class AttributeFactory
public static RequestedTransportAttribute createRequestedTransportAttribute(
byte protocol)
{
RequestedTransportAttribute attribute = new RequestedTransportAttribute();
RequestedTransportAttribute attribute =
new RequestedTransportAttribute();
attribute.setRequestedTransport(protocol);
return attribute;
@ -562,4 +557,33 @@ public class AttributeFactory
return attribute;
}
/**
* Creates a MagicCookieAttribute.
*
* @return the created MagicCookieAttribute
*/
public static MagicCookieAttribute createMagicCookieAttribute()
{
MagicCookieAttribute attribute = new MagicCookieAttribute();
return attribute;
}
/**
* Creates a DestinationFromAddressAttribute of the specified type and with
* the specified address and port
*
* @param address the address value of the address attribute
* @return the newly created address attribute.
*/
public static DestinationAddressAttribute createDestinationAddressAttribute(
TransportAddress address)
{
DestinationAddressAttribute attribute =
new DestinationAddressAttribute();
attribute.setAddress(address);
return attribute;
}
}

View File

@ -34,7 +34,7 @@ import org.ice4j.*;
*/
public class ChangeRequestAttribute
extends org.ice4j.attribute.Attribute
extends Attribute
{
/**
* Attribute name.
@ -135,12 +135,12 @@ public class ChangeRequestAttribute
binValue[4] = 0x00;
binValue[5] = 0x00;
binValue[6] = 0x00;
binValue[7] = (byte)((getChangeIpFlag()?4:0) + (getChangePortFlag()?2:0));
binValue[7] = (byte)((getChangeIpFlag() ? 4 : 0) +
(getChangePortFlag() ? 2 : 0));
return binValue;
}
//========================= set/get methods
/**
* Sets the value of the changeIpFlag. The "change IP" flag, if true,
@ -155,7 +155,7 @@ public class ChangeRequestAttribute
}
/**
* Returns tha value of the changeIpFlag. The "change IP" flag, if true,
* Returns the value of the changeIpFlag. The "change IP" flag, if true,
* requests the server to send the Binding Response with a different IP
* address than the one the Binding Request was received on.
*
@ -201,14 +201,11 @@ public class ChangeRequestAttribute
* @param length the length of the binary array.
* @throws StunException if attrubteValue contains invalid data.
*/
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws
StunException
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
offset += 3; // first three bytes of change req att are not used
setChangeIpFlag((attributeValue[offset] & 4) > 0);
setChangePortFlag((attributeValue[offset] & 0x2) > 0);
}
}

View File

@ -6,7 +6,6 @@
*/
package org.ice4j.attribute;
/**
* The CHANGED-ADDRESS attribute indicates the IP address and port where
* responses would have been sent from if the "change IP" and "change
@ -32,5 +31,4 @@ public class ChangedAddressAttribute extends AddressAttribute
{
super(CHANGED_ADDRESS);
}
}

View File

@ -118,14 +118,16 @@ public class ChannelNumberAttribute extends Attribute
* @param length the length of the binary array.
* @throws StunException if attrubteValue contains invalid data.
*/
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws StunException
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
if(length != 4)
{
throw new StunException("length invalid");
}
channelNumber = ((char)((attributeValue[0] << 8 ) | (attributeValue[1]&0xFF) ));
channelNumber =
((char)((attributeValue[0] << 8 ) | (attributeValue[1] & 0xFF) ));
}
/**
@ -146,4 +148,3 @@ public class ChannelNumberAttribute extends Attribute
return channelNumber;
}
}

View File

@ -51,8 +51,8 @@ public class DataAttribute
* @param length the length of the binary array.
* @throws StunException if attributeValue contains invalid data.
*/
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws
StunException
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
data = new byte[length];
System.arraycopy(attributeValue, offset, data, 0, length);
@ -65,7 +65,8 @@ public class DataAttribute
public byte[] encode()
{
char type = getAttributeType();
byte binValue[] = new byte[HEADER_LENGTH + getDataLength() + (getDataLength() % 4)];
byte binValue[] = new byte[HEADER_LENGTH + getDataLength() +
(getDataLength() % 4)];
//Type
binValue[0] = (byte)(type>>8);
@ -129,8 +130,8 @@ public class DataAttribute
}
/**
* Compares two STUN Attributes. Two attributes are considered equal when they
* have the same type length and value.
* Compares two STUN Attributes. Two attributes are considered equal when
* they have the same type length and value.
* @param obj the object to compare this attribute with.
* @return true if the attributes are equal and false otherwise.
*/
@ -153,4 +154,3 @@ public class DataAttribute
return true;
}
}

View File

@ -0,0 +1,30 @@
/*
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
* Maintained by the SIP Communicator community (http://sip-communicator.org).
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package org.ice4j.attribute;
/**
* The DESTINATION-ADDRESS is present in Send Requests of old TURN versions.
* It specifies the address and port where the data is to be sent. It is encoded
* in the same way as MAPPED-ADDRESS.
*
* @author Sebastien Vincent
*/
public class DestinationAddressAttribute extends AddressAttribute
{
/**
* Attribute name.
*/
public static final String NAME = "DESTINATION-ADDRESS";
/**
* Constructor.
*/
DestinationAddressAttribute()
{
super(DESTINATION_ADDRESS);
}
}

View File

@ -101,7 +101,8 @@ public class DontFragmentAttribute extends Attribute
* @param length the length of the binary array.
* @throws StunException if attrubteValue contains invalid data.
*/
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws StunException
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
if(length != 0)
{

View File

@ -157,9 +157,9 @@ public class ErrorCodeAttribute extends Attribute
/**
* A convenience method that sets error class and number according to the
* specified errorCode.The class represents the hundreds digit of the error code.
* The value MUST be between 1 and 6. The number represents the response
* code modulo 100, and its value MUST be between 0 and 99.
* specified errorCode.The class represents the hundreds digit of the error
* code. The value MUST be between 1 and 6. The number represents the
* response code modulo 100, and its value MUST be between 0 and 99.
*
* @param errorCode the errorCode that this class encapsulates.
* @throws IllegalArgumentException if errorCode is not a valid error code.
@ -190,9 +190,11 @@ public class ErrorCodeAttribute extends Attribute
public void setErrorNumber(byte errorNumber)
throws IllegalArgumentException
{
if(errorNumber < 0 || errorNumber > 99)
/*
if(errorNumber < 0 || errorNumber > 9999)
throw new IllegalArgumentException(
errorNumber + " is not a valid error number!");
*/
this.errorNumber = errorNumber;
}
@ -404,6 +406,5 @@ public class ErrorCodeAttribute extends Attribute
System.arraycopy(attributeValue, offset, reasonBytes,
0, reasonBytes.length);
setReasonPhrase(new String(reasonBytes));
}
}

View File

@ -119,7 +119,8 @@ public class EvenPortAttribute extends Attribute
* @param length the length of the binary array.
* @throws StunException if attrubteValue contains invalid data.
*/
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws StunException
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
if(length != 4)
{
@ -147,4 +148,3 @@ public class EvenPortAttribute extends Attribute
return rFlag;
}
}

View File

@ -61,7 +61,6 @@ public class FingerprintAttribute
*/
private byte[] crc;
/**
* Creates a <tt>FingerPrintAttribute</tt> instance.
*/
@ -81,6 +80,7 @@ public class FingerprintAttribute
{
return crc;
}
/**
* Returns the length of this attribute's body.
*
@ -246,4 +246,3 @@ public class FingerprintAttribute
return xorCRC32;
}
}

View File

@ -59,8 +59,8 @@ public abstract class IceControlAttribute
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
// array used to hold the intermediate long values reconstructed from the
// attributeValue array
// array used to hold the intermediate long values reconstructed from
// the attributeValue array
// Reading in the network byte order (Big-Endian)
tieBreaker = ((attributeValue[offset++] & 0xffl) << 56)

View File

@ -14,7 +14,8 @@ import org.ice4j.*;
*
* @author Sebastien Vincent
*/
public class LifetimeAttribute extends Attribute
public class LifetimeAttribute
extends Attribute
{
/**
* Attribute name.
@ -118,15 +119,18 @@ public class LifetimeAttribute extends Attribute
* @param length the length of the binary array.
* @throws StunException if attrubteValue contains invalid data.
*/
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws StunException
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
if(length != 4)
{
throw new StunException("length invalid");
}
lifetime = ((attributeValue[0] << 24) & 0xff000000) + ((attributeValue[1] << 16) & 0x00ff0000)
+ ((attributeValue[2] << 8) & 0x0000ff00) + (attributeValue[3] & 0x000000ff);
lifetime = ((attributeValue[0] << 24) & 0xff000000) +
((attributeValue[1] << 16) & 0x00ff0000) +
((attributeValue[2] << 8) & 0x0000ff00) +
(attributeValue[3] & 0x000000ff);
}
/**
@ -147,4 +151,3 @@ public class LifetimeAttribute extends Attribute
return lifetime;
}
}

View File

@ -0,0 +1,141 @@
/*
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
* Maintained by the SIP Communicator community (http://sip-communicator.org).
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package org.ice4j.attribute;
import org.ice4j.*;
/**
* The MAGIC-COOKIE attribute.
*
* It is used with old version of TURN (Google, Live messenger variant, ...).
*
* @author Sebastien Vincent
*/
public class MagicCookieAttribute
extends Attribute
{
/**
* Attribute name.
*/
public static final String NAME = "MAGIC-COOKIE";
/**
* The length of the data contained by this attribute.
*/
public static final char DATA_LENGTH = 4;
/**
* Magic cookie value.
*/
private int value = 0x72c64bc6;
/**
* Constructor.
*/
MagicCookieAttribute()
{
super(MAGIC_COOKIE);
}
/**
* Returns the human readable name of this attribute. Attribute names do
* not really matter from the protocol point of view. They are only used
* for debugging and readability.
*
* @return this attribute's name.
*/
public String getName()
{
return NAME;
}
/**
* Returns the length of this attribute's body.
*
* @return the length of this attribute's value (8 bytes).
*/
public char getDataLength()
{
return DATA_LENGTH;
}
/**
* Compares two STUN Attributes. Attributes are considered equal when their
* type, length, and all data are the same.
*
* @param obj the object to compare this attribute with.
* @return true if the attributes are equal and false otherwise.
*/
public boolean equals(Object obj)
{
if (! (obj instanceof LifetimeAttribute)
|| obj == null)
return false;
if (obj == this)
return true;
MagicCookieAttribute att = (MagicCookieAttribute) obj;
if (att.getAttributeType() != getAttributeType()
|| att.getDataLength() != getDataLength()
/* compare data */
|| att.value != value
)
return false;
return true;
}
/**
* Returns a binary representation of this attribute.
*
* @return a binary representation of this attribute.
*/
public byte[] encode()
{
byte binValue[] = new byte[HEADER_LENGTH + DATA_LENGTH];
//Type
binValue[0] = (byte)(getAttributeType() >> 8);
binValue[1] = (byte)(getAttributeType() & 0x00FF);
//Length
binValue[2] = (byte)(getDataLength() >> 8);
binValue[3] = (byte)(getDataLength() & 0x00FF);
//Data
binValue[4] = (byte)((value >> 24) & 0xff);
binValue[5] = (byte)((value >> 16) & 0xff);
binValue[6] = (byte)((value >> 8) & 0xff);
binValue[7] = (byte)((value) & 0xff);
return binValue;
}
/**
* Sets this attribute's fields according to attributeValue array.
*
* @param attributeValue a binary array containing this attribute's field
* values and NOT containing the attribute header.
* @param offset the position where attribute values begin (most often
* offset is equal to the index of the first byte after
* length)
* @param length the length of the binary array.
* @throws StunException if attrubteValue contains invalid data.
*/
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
if(length != 4)
{
throw new StunException("length invalid");
}
value = ((attributeValue[0] << 24) & 0xff000000) +
((attributeValue[1] << 16) & 0x00ff0000) +
((attributeValue[2] << 8) & 0x0000ff00) +
(attributeValue[3] & 0x000000ff);
}
}

View File

@ -27,7 +27,6 @@ package org.ice4j.attribute;
*
* @author Emil Ivov
*/
public class MappedAddressAttribute extends AddressAttribute
{
/**
@ -35,9 +34,11 @@ public class MappedAddressAttribute extends AddressAttribute
*/
public static final String NAME = "MAPPED-ADDRESS";
/**
* Constructor.
*/
MappedAddressAttribute()
{
super(MAPPED_ADDRESS);
}
}

View File

@ -82,7 +82,6 @@ public class MessageIntegrityAttribute
*/
public static final String NAME = "MESSAGE_INTEGRITY";
/**
* The HMAC-SHA1 algorithm.
*/
@ -340,4 +339,3 @@ public class MessageIntegrityAttribute
return true;
}
}

View File

@ -12,13 +12,12 @@ import org.ice4j.*;
/**
* This class is used for representing attributes not explicitly supported by
* the stack. Such attributes will generally be kept in binary form and won't be
* subdued to any processing by the stack. One could use this class for both
* the stack. Such attributes will generally be kept in binary form and won't
* be subdued to any processing by the stack. One could use this class for both
* dealing with attributes in received messages, and generating messages
* containing attributes not explicitly supported by the stack.
*
* @author Emil Ivov
*
*/
public class OptionalAttribute
extends Attribute
@ -44,7 +43,8 @@ public class OptionalAttribute
throws StunException
{
this.attributeValue = new byte[length];
System.arraycopy(attributeValue, offset, this.attributeValue, 0, length);
System.arraycopy(attributeValue, offset, this.attributeValue, 0,
length);
}
/**
@ -114,7 +114,6 @@ public class OptionalAttribute
System.arraycopy(body, offset, this.attributeValue, 0, length);
}
/**
* Compares two STUN Attributes. Two attributes are considered equal when they
* have the same type length and value.

View File

@ -57,8 +57,8 @@ public class PriorityAttribute
throws StunException
{
// array used to hold the intermediate long values reconstructed from the
// attributeValue array
// array used to hold the intermediate long values reconstructed from
// the attributeValue array
long[] values = new long[4];
// Reading in the network byte order (Big-Endian)
@ -96,12 +96,11 @@ public class PriorityAttribute
binValue[7] = (byte)(priority & 0x000000FFL);
return binValue;
}
/**
* Compares two STUN Attributes. Two attributes are considered equal when they
* have the same type length and value.
* Compares two STUN Attributes. Two attributes are considered equal when
* they have the same type length and value.
*
* @param obj the object to compare this attribute with.
* @return true if the attributes are equal and false otherwise.
@ -173,5 +172,4 @@ public class PriorityAttribute
else
this.priority = priority;
}
}

View File

@ -11,7 +11,7 @@ import java.util.*;
import org.ice4j.*;
/**
* The REALM attribute contains a text whcih meets the grammar for
* The REALM attribute contains a text which meets the grammar for
* "realm value" as described in RFC3261 but without the double quotes.
*
* @author Sebastien Vincent
@ -46,8 +46,8 @@ public class RealmAttribute extends Attribute
* @param length the length of the binary array.
* @throws StunException if attributeValue contains invalid data.
*/
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws
StunException
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
realm = new byte[length];
System.arraycopy(attributeValue, offset, realm, 0, length);
@ -60,7 +60,8 @@ public class RealmAttribute extends Attribute
public byte[] encode()
{
char type = getAttributeType();
byte binValue[] = new byte[HEADER_LENGTH + getDataLength() + (getDataLength() % 4)];
byte binValue[] = new byte[HEADER_LENGTH + getDataLength() +
(getDataLength() % 4)];
//Type
binValue[0] = (byte)(type >> 8);
@ -144,4 +145,3 @@ public class RealmAttribute extends Attribute
return true;
}
}

View File

@ -18,7 +18,6 @@ package org.ice4j.attribute;
*
* @author Emil Ivov
*/
public class ReflectedFromAttribute extends AddressAttribute
{
/**
@ -33,5 +32,4 @@ public class ReflectedFromAttribute extends AddressAttribute
{
super(REFLECTED_FROM);
}
}

View File

@ -0,0 +1,30 @@
/*
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
* Maintained by the SIP Communicator community (http://sip-communicator.org).
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package org.ice4j.attribute;
/**
* The REMOTE-ADDRESS is present in Data Indication of old TURN versions.
* It specifies the address and port where the data is sent. It is encoded
* in the same way as MAPPED-ADDRESS.
*
* @author Sebastien Vincent
*/
public class RemoteAddressAttribute extends AddressAttribute
{
/**
* Attribute name.
*/
public static final String NAME = "REMOTE-ADDRESS";
/**
* Constructor.
*/
RemoteAddressAttribute()
{
super(REMOTE_ADDRESS);
}
}

View File

@ -124,7 +124,8 @@ public class RequestedTransportAttribute extends Attribute
* @param length the length of the binary array.
* @throws StunException if attrubteValue contains invalid data.
*/
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws StunException
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
if(length != 4)
{
@ -152,4 +153,3 @@ public class RequestedTransportAttribute extends Attribute
return transportProtocol;
}
}

View File

@ -47,8 +47,8 @@ extends Attribute
* @param length the length of the binary array.
* @throws StunException if attributeValue contains invalid reservationToken.
*/
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws
StunException
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
if(length != 8)
{
@ -93,8 +93,8 @@ extends Attribute
}
/**
* Returns a (cloned) byte array containg the reservationToken value of the reservationToken
* attribute.
* Returns a (cloned) byte array containing the reservationToken value of
* the reservationToken attribute.
* @return the binary array containing the reservationToken.
*/
public byte[] getReservationToken()
@ -108,8 +108,8 @@ extends Attribute
}
/**
* Copies the specified binary array into the the reservationToken value of the reservationToken
* attribute.
* Copies the specified binary array into the the reservationToken value of
* the reservationToken attribute.
* @param reservationToken the binary array containing the reservationToken.
*/
public void setReservationToken(byte[] reservationToken)
@ -121,7 +121,8 @@ extends Attribute
}
this.reservationToken = new byte[reservationToken.length];
System.arraycopy(reservationToken, 0, this.reservationToken, 0, reservationToken.length);
System.arraycopy(reservationToken, 0, this.reservationToken, 0,
reservationToken.length);
}
/**
@ -134,12 +135,11 @@ extends Attribute
}
/**
* Compares two STUN Attributes. Two attributes are considered equal when they
* have the same type length and value.
* Compares two STUN Attributes. Two attributes are considered equal when
* they have the same type length and value.
* @param obj the object to compare this attribute with.
* @return true if the attributes are equal and false otherwise.
*/
public boolean equals(Object obj)
{
if (! (obj instanceof ReservationTokenAttribute)
@ -158,4 +158,3 @@ extends Attribute
return true;
}
}

View File

@ -28,5 +28,4 @@ public class ResponseAddressAttribute extends AddressAttribute
{
super(RESPONSE_ADDRESS);
}
}

View File

@ -99,7 +99,7 @@ public class SoftwareAttribute
}
/**
* Returns a (cloned) byte array containg the data value of the software
* Returns a (cloned) byte array containing the data value of the software
* attribute.
* @return the binary array containing the software.
*/
@ -132,13 +132,12 @@ public class SoftwareAttribute
}
/**
* Compares two STUN Attributes. Two attributes are considered equal when they
* have the same type length and value.
* Compares two STUN Attributes. Two attributes are considered equal when
* they have the same type length and value.
*
* @param obj the object to compare this attribute with.
* @return true if the attributes are equal and false otherwise.
*/
public boolean equals(Object obj)
{
if (! (obj instanceof SoftwareAttribute)
@ -156,5 +155,4 @@ public class SoftwareAttribute
return true;
}
}

View File

@ -13,7 +13,6 @@ package org.ice4j.attribute;
*
* @author Emil Ivov
*/
public class SourceAddressAttribute extends AddressAttribute
{
/**

View File

@ -111,7 +111,6 @@ public class UnknownAttributesAttribute extends Attribute
public Iterator<Character> getAttributes()
{
return unknownAttributes.iterator();
}
/**
@ -152,7 +151,8 @@ public class UnknownAttributesAttribute extends Attribute
Iterator<Character> attributes = getAttributes();
while (attributes.hasNext()) {
while (attributes.hasNext())
{
char att = attributes.next().charValue();
binValue[offset++] = (byte)(att >> 8);
binValue[offset++] = (byte)(att & 0x00FF);
@ -168,7 +168,6 @@ public class UnknownAttributesAttribute extends Attribute
binValue[offset++] = (byte) (att & 0x00FF);
}
return binValue;
}
@ -196,7 +195,6 @@ public class UnknownAttributesAttribute extends Attribute
return false;
return true;
}
/**
@ -210,13 +208,13 @@ public class UnknownAttributesAttribute extends Attribute
* @param length the length of the binary array.
* @throws StunException if attrubteValue contains invalid data.
*/
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws
StunException
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException
{
if( (length % 2 ) != 0)
throw new StunException("Attribute IDs are 2 bytes long and the "
+"passed binary array has an odd length value.");
+ "passed binary array has an odd length " +
"value.");
char originalOffset = offset;
for(int i = offset; i < originalOffset + length; i += 2)
{

View File

@ -13,8 +13,14 @@ import org.ice4j.*;
public class UseCandidateAttribute
extends Attribute
{
/**
* Data length.
*/
private static final char DATA_LENGTH_USE_CANDIDATE = 0;
/**
* Constructor.
*/
protected UseCandidateAttribute()
{
super(USE_CANDIDATE);
@ -58,8 +64,8 @@ public class UseCandidateAttribute
}
/**
* Compares two STUN Attributes. Two attributes are considered equal when they
* have the same type, length and value.
* Compares two STUN Attributes. Two attributes are considered equal when
* they have the same type, length and value.
*
* @param obj the object to compare this attribute with.
* @return true if the attributes are equal and false otherwise.
@ -100,5 +106,4 @@ public class UseCandidateAttribute
{
return "USE-CANDIDATE";
}
}

View File

@ -151,4 +151,3 @@ public class UsernameAttribute extends Attribute
return true;
}
}

View File

@ -24,7 +24,9 @@ import org.ice4j.*;
public class XorOnlyAttribute
extends Attribute
{
/**
* Constructor.
*/
protected XorOnlyAttribute()
{
super(Attribute.XOR_ONLY);

View File

@ -29,4 +29,3 @@ public class XorPeerAddressAttribute extends XorMappedAddressAttribute
super(XOR_PEER_ADDRESS);
}
}

View File

@ -29,4 +29,3 @@ public class XorRelayedAddressAttribute extends XorMappedAddressAttribute
super(XOR_RELAYED_ADDRESS);
}
}