From 66fc199998d5da21b89a8e8e02df0e81ff81704f Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov <lyubomir.marinov@jitsi.org> Date: Mon, 7 Oct 2013 15:23:29 +0300 Subject: [PATCH] Romoves the use of enum-like constants from SrtpListeners because it is a part of neomedia and may use MediaType instead. --- .../transform/sdes/SDesControlImpl.java | 11 +-- .../transform/zrtp/SecurityEventManager.java | 86 ++++++++++--------- .../transform/zrtp/ZrtpControlImpl.java | 9 +- .../service/neomedia/event/SrtpListener.java | 44 ++++++---- .../event/CallPeerSecurityMessageEvent.java | 3 +- 5 files changed, 77 insertions(+), 76 deletions(-) diff --git a/src/org/jitsi/impl/neomedia/transform/sdes/SDesControlImpl.java b/src/org/jitsi/impl/neomedia/transform/sdes/SDesControlImpl.java index 80b217a1..1c9efa1a 100644 --- a/src/org/jitsi/impl/neomedia/transform/sdes/SDesControlImpl.java +++ b/src/org/jitsi/impl/neomedia/transform/sdes/SDesControlImpl.java @@ -11,7 +11,6 @@ import java.util.*; import org.jitsi.impl.neomedia.*; -import org.jitsi.impl.neomedia.transform.zrtp.*; import org.jitsi.service.neomedia.*; import org.jitsi.service.neomedia.event.*; @@ -223,20 +222,16 @@ public void setEnabledCiphers(Iterable<String> ciphers) enabledCryptoSuites.add(c); } - public void start(MediaType type) + public void start(MediaType mediaType) { SrtpListener srtpListener = getSrtpListener(); // in srtp the started and security event is one after another in some // other security mechanisms (e.g. zrtp) there can be started and no // security one or security timeout event - int sessionType - = MediaType.AUDIO.equals(type) - ? SecurityEventManager.AUDIO_SESSION - : SecurityEventManager.VIDEO_SESSION; - srtpListener.securityNegotiationStarted(sessionType, this); + srtpListener.securityNegotiationStarted(mediaType, this); srtpListener.securityTurnedOn( - sessionType, + mediaType, selectedInAttribute.getCryptoSuite().encode(), this); } diff --git a/src/org/jitsi/impl/neomedia/transform/zrtp/SecurityEventManager.java b/src/org/jitsi/impl/neomedia/transform/zrtp/SecurityEventManager.java index 6e30e27d..1e76e1bc 100644 --- a/src/org/jitsi/impl/neomedia/transform/zrtp/SecurityEventManager.java +++ b/src/org/jitsi/impl/neomedia/transform/zrtp/SecurityEventManager.java @@ -11,6 +11,7 @@ import java.util.*; import org.jitsi.service.libjitsi.*; +import org.jitsi.service.neomedia.*; import org.jitsi.service.neomedia.event.*; import org.jitsi.service.protocol.event.*; import org.jitsi.service.resources.*; @@ -51,18 +52,6 @@ public class SecurityEventManager extends ZrtpUserCallback public static final String WARNING_NO_EXPECTED_RS_MATCH = getI18NString("impl.media.security.WARNING_NO_EXPECTED_RS_MATCH", null); - /** - * Indicates an audio session type. - */ - public static final int AUDIO_SESSION = - CallPeerSecurityStatusEvent.AUDIO_SESSION; - - /** - * Indicates a video session type. - */ - public static final int VIDEO_SESSION = - CallPeerSecurityStatusEvent.VIDEO_SESSION; - /** * The zrtp control that this manager is associated with. */ @@ -79,9 +68,9 @@ public class SecurityEventManager extends ZrtpUserCallback private boolean isDHSession = false; /** - * Type of session + * The type of this session. */ - private int sessionType; + private MediaType sessionType; /** * SAS string. @@ -112,12 +101,11 @@ public SecurityEventManager(ZrtpControlImpl zrtpControl) /** * Set the type of this session. * - * @param type the session type. The session type could be either - * AUDIO_SESSION or VIDEO_SESSION. + * @param type the <tt>MediaType</tt> of this session */ - public void setSessionType(int type) + public void setSessionType(MediaType sessionType) { - sessionType = type; + this.sessionType = sessionType; } /** @@ -143,8 +131,11 @@ public void setDHSession(boolean isDHSession) public void secureOn(String cipher) { if (logger.isDebugEnabled()) - logger.debug(sessionTypeToString(sessionType) - + ": cipher enabled: " + cipher); + { + logger.debug( + sessionTypeToString(sessionType) + ": cipher enabled: " + + cipher); + } this.cipher = cipher; } @@ -316,9 +307,13 @@ else if (msgCode instanceof ZrtpCodes.ZrtpErrorCodes) .securityMessageReceived(message, i18nMessage, severity); if (logger.isDebugEnabled()) - logger.debug(sessionTypeToString(sessionType) + ": " - + "ZRTP message: severity: " + sev + ", sub code: " + msgCode - + ", DH session: " + isDHSession + ", multi: " + multiStreams); + { + logger.debug( + sessionTypeToString(sessionType) + + ": ZRTP message: severity: " + sev + ", sub code: " + + msgCode + ", DH session: " + isDHSession + ", multi: " + + multiStreams); + } } /** @@ -335,8 +330,12 @@ public void zrtpNegotiationFailed( ZrtpCodes.MessageSeverity severity, Object msgCode = ii.next(); if (logger.isDebugEnabled()) - logger.debug(sessionTypeToString(sessionType) - + ": ZRTP key negotiation failed, sub code: " + msgCode); + { + logger.debug( + sessionTypeToString(sessionType) + + ": ZRTP key negotiation failed, sub code: " + + msgCode); + } } /** @@ -358,9 +357,12 @@ public void secureOff() public void zrtpNotSuppOther() { if (logger.isDebugEnabled()) - logger.debug(sessionTypeToString(sessionType) - + ": Other party does not support ZRTP key negotiation protocol," - + " no secure calls possible."); + { + logger.debug( + sessionTypeToString(sessionType) + + ": Other party does not support ZRTP key negotiation" + + " protocol, no secure calls possible."); + } securityListener.securityTimeout(sessionType); } @@ -372,28 +374,30 @@ public void zrtpNotSuppOther() public void confirmGoClear() { if (logger.isDebugEnabled()) - logger.debug(sessionTypeToString(sessionType) - + ": GoClear confirmation requested."); + { + logger.debug( + sessionTypeToString(sessionType) + + ": GoClear confirmation requested."); + } } /** - * Converts the <tt>sessionType</tt> into into a <tt>String</tt>. - * - * @param sessionType one of the - * <tt>CallPeerSecurityStatusEvent.XXX_SESSION</tt> fields + * Converts the <tt>sessionType</tt> into a <tt>String</tt>. * + * @param sessionType the <tt>MediaType</tt> to be converted into a + * <tt>String</tt> for the purposes of this <tt>SecurityEventManager</tt> * @return a <tt>String</tt> representation of <tt>sessionType</tt>. */ - private String sessionTypeToString(int sessionType) + private String sessionTypeToString(MediaType sessionType) { switch (sessionType) { - case AUDIO_SESSION: - return "AUDIO_SESSION"; - case VIDEO_SESSION: - return "VIDEO_SESSION"; - default: - throw new IllegalArgumentException("sessionType"); + case AUDIO: + return "AUDIO_SESSION"; + case VIDEO: + return "VIDEO_SESSION"; + default: + throw new IllegalArgumentException("sessionType"); } } diff --git a/src/org/jitsi/impl/neomedia/transform/zrtp/ZrtpControlImpl.java b/src/org/jitsi/impl/neomedia/transform/zrtp/ZrtpControlImpl.java index feb0119d..98afb060 100644 --- a/src/org/jitsi/impl/neomedia/transform/zrtp/ZrtpControlImpl.java +++ b/src/org/jitsi/impl/neomedia/transform/zrtp/ZrtpControlImpl.java @@ -347,18 +347,13 @@ public void start(MediaType mediaType) // to immediately catch ZRTP communication from other client // - after the master session has completed its key negotiation // it will start other media sessions (see SCCallback) - int sessionType - = MediaType.AUDIO.equals(mediaType) - ? SecurityEventManager.AUDIO_SESSION - : SecurityEventManager.VIDEO_SESSION; - if (masterSession) { zrtpAutoStart = true; securityEventManager.setDHSession(true); // we know that audio is considered as master for zrtp - securityEventManager.setSessionType(sessionType); + securityEventManager.setSessionType(mediaType); } else { @@ -367,7 +362,7 @@ public void start(MediaType mediaType) // and started video // initially engine has value enableZrtp = false zrtpAutoStart = transformEngine.isEnableZrtp(); - securityEventManager.setSessionType(sessionType); + securityEventManager.setSessionType(mediaType); } engine.setConnector(zrtpConnector); diff --git a/src/org/jitsi/service/neomedia/event/SrtpListener.java b/src/org/jitsi/service/neomedia/event/SrtpListener.java index 86dbe63c..660f62f6 100644 --- a/src/org/jitsi/service/neomedia/event/SrtpListener.java +++ b/src/org/jitsi/service/neomedia/event/SrtpListener.java @@ -9,9 +9,10 @@ import org.jitsi.service.neomedia.*; /** - * The <tt>ZrtpListener</tt> is meant to be used by the media stream creator, as + * The <tt>SrtpListener</tt> is meant to be used by the media stream creator, as * the name indicates in order to be notified when a security event has occurred - * that concerns ZRTP. + * that concerns a secure (media) transport i.e. <tt>SrtpControl</tt> such as + * ZRTP, SDES and DTLS-SRTP. * * @author Yana Stamcheva */ @@ -24,46 +25,51 @@ public interface SrtpListener * slave streams to establish their sessions. If this is a securityTurnedOn * event on non master stream the multiStreamData is null. * - * @param sessionType the type of the call session - audio or video. + * @param mediaType the <tt>MediaType</tt> of the call session * @param cipher the security cipher that encrypts the call * @param sender the control that initiated the event. */ - public void securityTurnedOn( int sessionType, - String cipher, - SrtpControl sender); + public void securityTurnedOn( + MediaType mediaType, + String cipher, + SrtpControl sender); /** * Indicates that the security has been turned off. * - * @param sessionType the type of the call session - audio or video. + * @param mediaType the <tt>MediaType</tt> of the call session */ - public void securityTurnedOff(int sessionType); + public void securityTurnedOff(MediaType mediaType); /** * Indicates that a security message has occurred associated with a - * failure/warning or information coming from the encryption protocol. + * failure/warning or information coming from the encryption protocol/secure + * transport. * * @param message the message. * @param i18nMessage the internationalized message * @param severity severity level */ - public void securityMessageReceived(String message, - String i18nMessage, - int severity); + public void securityMessageReceived( + String message, + String i18nMessage, + int severity); /** - * Indicates that the other party has timed out replying to our - * offer to secure the connection. + * Indicates that the other party has timed out replying to our offer to + * secure the connection. * - * @param sessionType the type of the call session - audio or video. + * @param mediaType the <tt>MediaType</tt> of the call session */ - public void securityTimeout(int sessionType); + public void securityTimeout(MediaType mediaType); /** - * Indicates that we started the process of securing the the connection. + * Indicates that we started the process of securing the connection. * - * @param sessionType the type of the call session - audio or video. + * @param mediaType the <tt>MediaType</tt> of the call session * @param sender the control that initiated the event. */ - public void securityNegotiationStarted(int sessionType, SrtpControl sender); + public void securityNegotiationStarted( + MediaType mediaType, + SrtpControl sender); } diff --git a/src/org/jitsi/service/protocol/event/CallPeerSecurityMessageEvent.java b/src/org/jitsi/service/protocol/event/CallPeerSecurityMessageEvent.java index 157fa6cb..58990da3 100644 --- a/src/org/jitsi/service/protocol/event/CallPeerSecurityMessageEvent.java +++ b/src/org/jitsi/service/protocol/event/CallPeerSecurityMessageEvent.java @@ -106,7 +106,8 @@ public String getI18nMessage() * * @return the eventSeverity */ - public int getEventSeverity() { + public int getEventSeverity() + { return eventSeverity; } } -- GitLab