Remove ridiculous code duplication and string comparisons

Includes update to libjitsi/b2f593c7b3ac683a92369609b17d820ad42762ca
fix-message-formatting
Ingo Bauersachs 12 years ago
parent a193626982
commit 5cf2a26673

@ -514,21 +514,16 @@ protected void setAndAddPreferredEncryptionProtocol(
RtpDescriptionPacketExtension remoteDescription)
{
// Sets ZRTP or SDES, depending on the preferences for this account.
List<String> preferredEncryptionProtocols
List<SrtpControlType> preferredEncryptionProtocols
= getPeer()
.getProtocolProvider()
.getAccountID()
.getSortedEnabledEncryptionProtocolList();
for(String preferredEncryptionProtocol : preferredEncryptionProtocols)
for(SrtpControlType srtpControlType : preferredEncryptionProtocols)
{
String protoName
= preferredEncryptionProtocol.substring(
ProtocolProviderFactory.ENCRYPTION_PROTOCOL.length()
+ 1);
if (setAndAddPreferredEncryptionProtocol(
protoName,
srtpControlType,
mediaType,
localDescription,
remoteDescription))
@ -555,7 +550,7 @@ protected void setAndAddPreferredEncryptionProtocol(
* selected; <tt>false</tt>, otherwise
*/
protected boolean setAndAddPreferredEncryptionProtocol(
String protoName,
SrtpControlType srtpControlType,
MediaType mediaType,
RtpDescriptionPacketExtension localDescription,
RtpDescriptionPacketExtension remoteDescription)
@ -568,7 +563,7 @@ protected boolean setAndAddPreferredEncryptionProtocol(
return false;
// SDES
if(SDesControl.PROTO_NAME.equals(protoName))
if(srtpControlType == SrtpControlType.SDES)
{
addSDesAdvertisedEncryptions(
false,
@ -584,7 +579,7 @@ protected boolean setAndAddPreferredEncryptionProtocol(
}
}
// ZRTP
else if(ZrtpControl.PROTO_NAME.equals(protoName))
else if(srtpControlType == SrtpControlType.ZRTP)
{
if(setZrtpEncryptionOnDescription(
mediaType,

@ -2445,21 +2445,16 @@ private void setAndAddPreferredEncryptionProtocol(
ContentPacketExtension localContent,
ContentPacketExtension remoteContent)
{
List<String> preferredEncryptionProtocols
List<SrtpControlType> preferredEncryptionProtocols
= getPeer()
.getProtocolProvider()
.getAccountID()
.getSortedEnabledEncryptionProtocolList();
for (String preferredEncryptionProtocol : preferredEncryptionProtocols)
for (SrtpControlType srtpControlType : preferredEncryptionProtocols)
{
String protoName
= preferredEncryptionProtocol.substring(
ProtocolProviderFactory.ENCRYPTION_PROTOCOL.length()
+ 1);
// DTLS-SRTP
if (DtlsControl.PROTO_NAME.equals(protoName))
if (srtpControlType == SrtpControlType.DTLS_SRTP)
{
addDtlsAdvertisedEncryptions(
false,
@ -2486,7 +2481,7 @@ private void setAndAddPreferredEncryptionProtocol(
: JingleUtils.getRtpDescription(remoteContent);
if (setAndAddPreferredEncryptionProtocol(
protoName,
srtpControlType,
mediaType,
localDescription,
remoteDescription))

@ -1173,19 +1173,15 @@ private List<String> getRtpTransports()
* List the secure transports in the result according to the order
* of preference of their respective encryption protocols.
*/
List<String> encryptionProtocols
List<SrtpControlType> encryptionProtocols
= accountID.getSortedEnabledEncryptionProtocolList();
for (int epi = encryptionProtocols.size() - 1; epi >= 0; epi--)
{
String encryptionProtocol = encryptionProtocols.get(epi);
String protoName
= encryptionProtocol.substring(
ProtocolProviderFactory.ENCRYPTION_PROTOCOL.length()
+ 1);
SrtpControlType srtpControlType = encryptionProtocols.get(epi);
String[] protos;
if (DtlsControl.PROTO_NAME.equals(protoName))
if (srtpControlType == SrtpControlType.DTLS_SRTP)
{
protos
= new String[]
@ -1738,21 +1734,16 @@ protected void setAndAddPreferredEncryptionProtocol(
MediaDescription remoteMd)
{
// Sets ZRTP or SDES, depending on the preferences for this account.
List<String> preferredEncryptionProtocols
List<SrtpControlType> preferredEncryptionProtocols
= getPeer()
.getProtocolProvider()
.getAccountID()
.getSortedEnabledEncryptionProtocolList();
for(String preferredEncryptionProtocol : preferredEncryptionProtocols)
for(SrtpControlType srtpControlType : preferredEncryptionProtocols)
{
String protoName
= preferredEncryptionProtocol.substring(
ProtocolProviderFactory.ENCRYPTION_PROTOCOL.length()
+ 1);
// DTLS-SRTP
if (DtlsControl.PROTO_NAME.equals(protoName))
if (srtpControlType == SrtpControlType.DTLS_SRTP)
{
if(updateMediaDescriptionForDtls(mediaType, localMd, remoteMd))
{
@ -1761,7 +1752,7 @@ protected void setAndAddPreferredEncryptionProtocol(
}
}
// SDES
else if(SDesControl.PROTO_NAME.equals(protoName))
else if(srtpControlType == SrtpControlType.SDES)
{
if(updateMediaDescriptionForSDes(mediaType, localMd, remoteMd))
{
@ -1770,7 +1761,7 @@ else if(SDesControl.PROTO_NAME.equals(protoName))
}
}
// ZRTP
else if(ZrtpControl.PROTO_NAME.equals(protoName))
else if(srtpControlType == SrtpControlType.ZRTP)
{
if(updateMediaDescriptionForZrtp(mediaType, localMd, remoteMd))
{

@ -10,6 +10,8 @@
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.service.credentialsstorage.*;
import org.jitsi.service.neomedia.*;
import org.osgi.framework.*;
/**
@ -958,7 +960,7 @@ public String getSystemProtocolName()
* @return Sorts the enabled encryption protocol list given in parameter to
* match the preferences set for this account.
*/
public List<String> getSortedEnabledEncryptionProtocolList()
public List<SrtpControlType> getSortedEnabledEncryptionProtocolList()
{
Map<String, Integer> encryptionProtocols
= getIntegerPropertiesByPrefix(
@ -983,8 +985,8 @@ public List<String> getSortedEnabledEncryptionProtocolList()
true);
}
List<String> sortedEncryptionProtocols
= new ArrayList<String>(encryptionProtocols.size());
List<SrtpControlType> sortedEncryptionProtocols
= new ArrayList<SrtpControlType>(encryptionProtocols.size());
// First: add all protocol in the right order.
for (Map.Entry<String, Integer> e : encryptionProtocols.entrySet())
@ -997,20 +999,22 @@ public List<String> getSortedEnabledEncryptionProtocolList()
if (index > sortedEncryptionProtocols.size())
index = sortedEncryptionProtocols.size();
String name = e.getKey();
String name =
e.getKey()
.substring(
ProtocolProviderFactory.ENCRYPTION_PROTOCOL
.length() + 1);
sortedEncryptionProtocols.add(index, name);
sortedEncryptionProtocols.add(index,
SrtpControlType.fromString(name));
}
}
// Second: remove all disabled protocols.
int namePrefixLength
= ProtocolProviderFactory.ENCRYPTION_PROTOCOL.length() + 1;
for (Iterator<String> i = sortedEncryptionProtocols.iterator();
for (Iterator<SrtpControlType> i = sortedEncryptionProtocols.iterator();
i.hasNext();)
{
String name = i.next().substring(namePrefixLength);
String name = i.next().toString();
if (!encryptionProtocolStatus.get(
ProtocolProviderFactory.ENCRYPTION_PROTOCOL_STATUS

Loading…
Cancel
Save