Adds support an implementation for the <encryption/> tags

cusax-fix
Emil Ivov 16 years ago
parent de4addf6ac
commit 486e9f5ae8

@ -0,0 +1,140 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.jingle;
import java.util.*;
import org.jivesoftware.smack.packet.*;
/**
* The element transporting encryption information during jingle session
* establishment.
*
* @author Emil Ivov
*/
public class EncryptionPacketExtension
implements PacketExtension
{
/**
* There's no namespace for the <tt>encryption</tt> element itself.
*/
public static final String NAMESPACE = "";
/**
* The name of the "encryption" element.
*/
public static final String ELEMENT_NAME = "encryption";
/**
* The name of the <tt>required</tt> attribute.
*/
public static final String REQUIRED_ARG_NAME = "required";
/**
* Indicates whether encryption is required for this session or not.
*/
private boolean required = false;
/**
* The list of <tt>crypto</tt> elements transported by this
* <tt>encryption</tt> element.
*/
private List<CryptoPacketExtension> cryptoList
= new ArrayList<CryptoPacketExtension>();
/**
* Adds a new <tt>crypto</tt> element to this encryption element.
*
* @param crypto the new <tt>crypto</tt> element to add.
*/
public void addCrypto(CryptoPacketExtension crypto)
{
cryptoList.add(crypto);
}
/**
* Returns a <b>reference</b> to the list of <tt>crypto</tt> elements that
* we have registered with this encryption element so far.
*
* @return a <b>reference</b> to the list of <tt>crypto</tt> elements that
* we have registered with this encryption element so far.
*/
public List<CryptoPacketExtension> getCryptoList()
{
return cryptoList;
}
/**
* Specifies whether encryption is required for this session or not.
*
* @param required <tt>true</tt> if encryption is required for this session
* and <tt>false</tt> otherwise.
*/
public void setRequired(boolean required)
{
this.required = required;
}
/**
* Returns <tt>true</tt> if encryption is required for this session and
* <tt>false</tt> otherwise. Default value is <tt>false</tt>.
*
* @return <tt>true</tt> if encryption is required for this session and
* <tt>false</tt> otherwise.
*/
public boolean isRequired()
{
return required;
}
/**
* Returns the name of the <tt>encryption</tt> element.
*
* @return the name of the <tt>encryption</tt> element.
*/
public String getElementName()
{
return ELEMENT_NAME;
}
/**
* Returns <tt>null</tt> since there's no encryption specific ns.
*
* @return <tt>null</tt> since there's no encryption specific ns.
*/
public String getNamespace()
{
return NAMESPACE;
}
/**
* Returns the XML representation of this <tt>description</tt> packet
* extension including all child elements.
*
* @return this packet extension as an XML <tt>String</tt>.
*/
public String toXML()
{
StringBuilder bldr = new StringBuilder(
"<" + ELEMENT_NAME+ " ");
if(isRequired())
bldr.append(REQUIRED_ARG_NAME + "='1'");
bldr.append(">");
//we need to have at least one crypto element.
for(CryptoPacketExtension crypto : cryptoList)
{
bldr.append(crypto.toXML());
}
bldr.append("</" + ELEMENT_NAME + ">");
return bldr.toString();
}
}

@ -104,7 +104,7 @@ public String getName()
/**
* Sets that value of the format parameter we are representing here.
*
* @param value the value of the format paramter we are representing here.
* @param value the value of the format parameter we are representing here.
*/
public void setValue(String value)
{
@ -112,7 +112,9 @@ public void setValue(String value)
}
/**
* @return the value
* Returns the value of the format parameter we are representing here.
*
* @return the value of the format parameter we are representing here.
*/
public String getValue()
{

@ -59,13 +59,13 @@ public class RtpDescriptionPacketExtension
* An optional encryption element that contains encryption parameters for
* this session.
*/
private PacketExtension encryptionElement;
private EncryptionPacketExtension encryption;
/**
* An optional bandwidth element that specifies the allowable or preferred
* bandwidth for use by this application type.
*/
private PacketExtension bandwidthElement;
private PacketExtension bandwidth;
/**
* Specifies the media type for the stream that this description element
@ -181,16 +181,65 @@ public String toXML()
}
//encryption element
if (encryptionElement != null)
bldr.append(encryptionElement);
if (encryption != null)
bldr.append(encryption.toXML());
//bandwidth element
if (bandwidthElement != null)
bldr.append(bandwidthElement);
if (bandwidth != null)
bldr.append(bandwidth.toXML());
bldr.append("</" + ELEMENT_NAME + ">");
return bldr.toString();
}
/**
* Sets the optional encryption element that contains encryption parameters
* for this session.
*
* @param encryption the encryption {@link PacketExtension} we'd like to add
* to this packet.
*/
public void setEncryption(EncryptionPacketExtension encryption)
{
this.encryption = encryption;
}
/**
* Returns the optional encryption element that contains encryption
* parameters for this session.
*
* @return the encryption {@link PacketExtension} added to this packet or
* <tt>null</tt> if none has been set yet.
*/
public EncryptionPacketExtension getEncryption()
{
return encryption;
}
/**
* Sets an optional bandwidth element that specifies the allowable or
* preferred bandwidth for use by this application type.
*
* @param bandwidth the max/preferred bandwidth indication that we'd like
* to add to this packet.
*/
public void setBandwidth(PacketExtension bandwidth)
{
this.bandwidth = bandwidth;
}
/**
* Returns an optional bandwidth element that specifies the allowable or
* preferred bandwidth for use by this application type.
*
* @return the max/preferred bandwidth set for this session or <tt>null</tt>
* if none has been set yet.
*/
public PacketExtension getBandwidth()
{
return bandwidth;
}
}

Loading…
Cancel
Save