From 82cc674b55fdbd1ebb763928bcc6f49028190586 Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Fri, 4 Mar 2011 18:21:45 -0500
Subject: [PATCH] [#4969] Fix put SRTP call on hold

---
 .../src/audio/audiortp/AudioRtpFactory.cpp    |  8 +++++++-
 .../src/audio/audiortp/AudioRtpFactory.h      |  7 +++++++
 .../src/audio/audiortp/AudioSrtpSession.cpp   |  7 ++++++-
 .../src/audio/audiortp/AudioSrtpSession.h     | 19 +++++++++++++------
 4 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp
index 84d44d91ea..c88ecc6101 100644
--- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp
+++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp
@@ -46,7 +46,7 @@
 namespace sfl
 {
 
-AudioRtpFactory::AudioRtpFactory() : _rtpSession (NULL)
+AudioRtpFactory::AudioRtpFactory() : _rtpSession (NULL), remoteContext(NULL), localContext(NULL)
 {
 
 }
@@ -160,6 +160,10 @@ void AudioRtpFactory::start (AudioCodec* audiocodec)
 
         case Sdes:
 
+        	if(localContext && remoteContext) {
+        		static_cast<AudioSrtpSession *> (_rtpSession)->restoreCryptoContext(localContext, remoteContext);
+        	}
+
             if (static_cast<AudioSrtpSession *> (_rtpSession)->startRtpThread (audiocodec) != 0) {
                 throw AudioRtpFactoryException ("AudioRtpFactory: Error: Failed to start AudioSRtpSession thread");
             }
@@ -199,6 +203,8 @@ void AudioRtpFactory::stop (void)
         switch (_rtpSessionType) {
 
             case Sdes:
+            	localContext = static_cast<AudioSrtpSession *> (_rtpSession)->_localCryptoCtx;
+            	remoteContext = static_cast<AudioSrtpSession *> (_rtpSession)->_remoteCryptoCtx;
                 static_cast<AudioSrtpSession *> (_rtpSession)->stopRtpThread();
                 break;
 
diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h
index 8b5af4a0c6..65983259a4 100644
--- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h
+++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h
@@ -33,6 +33,7 @@
 
 #include <stdexcept>
 #include <cc++/thread.h>
+#include <ccrtp/CryptoContext.h>
 
 #include "sip/SdesNegotiator.h"
 #include "audio/codecs/audiocodec.h"
@@ -212,6 +213,12 @@ class AudioRtpFactory
         // Field used when initializinga udio rtp session
         // May be set manually or from config using initAudioRtpConfig
         bool _helloHashEnabled;
+
+        /** Remote srtp crypto context to be set into incoming data queue. */
+        ost::CryptoContext *remoteContext;
+
+        /** Local srtp crypto context to be set into outgoing data queue. */
+        ost::CryptoContext *localContext;
 };
 }
 #endif // __AUDIO_RTP_FACTORY_H__
diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp
index 12ceea540e..e03c5a0e46 100644
--- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp
+++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp
@@ -65,6 +65,7 @@ AudioSrtpSession::AudioSrtpSession (ManagerImpl * manager, SIPCall * sipcall) :
 
 AudioSrtpSession::~AudioSrtpSession()
 {
+	_debug("AudioSrtp: Destroy audio srtp session");
 }
 
 void AudioSrtpSession::initLocalCryptoInfo()
@@ -294,7 +295,11 @@ void AudioSrtpSession::initializeLocalCryptoContext (void)
 
 }
 
-#pragma GCC diagnostic ignored "-Wunused-value"
+void AudioSrtpSession::restoreCryptoContext(ost::CryptoContext *localContext, ost::CryptoContext *remoteContext) {
+	setInQueueCryptoContext (remoteContext);
+	setOutQueueCryptoContext (localContext);
+}
+
 char* AudioSrtpSession::encodeBase64 (unsigned char *input, int length)
 {
     BIO *b64, *bmem;
diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h
index 1a2ae15de0..f236dec7d0 100644
--- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h
+++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h
@@ -104,6 +104,19 @@ class AudioSrtpSession : public AudioRtpSession
         */
         void initLocalCryptoInfo (void);
 
+        /**
+         * Restore the cryptographic context. most likely useful to restore
+         * a call after hold action
+         */
+        void restoreCryptoContext(ost::CryptoContext *, ost::CryptoContext *);
+
+
+        /** Remote srtp crypto context to be set into incoming data queue. */
+        ost::CryptoContext* _remoteCryptoCtx;
+
+        /** Local srtp crypto context to be set into outgoing data queue. */
+        ost::CryptoContext* _localCryptoCtx;
+
     private:
 
         /**
@@ -176,12 +189,6 @@ class AudioSrtpSession : public AudioRtpSession
         /** remote master salt length in byte */
         int _remoteMasterSaltLength;
 
-        /** Remote srtp crypto context to be set into incoming data queue. */
-        ost::CryptoContext* _remoteCryptoCtx;
-
-        /** Local srtp crypto context to be set into outgoing data queue. */
-        ost::CryptoContext* _localCryptoCtx;
-
         /** Used to make sure remote crypto context not initialized wice. */
         bool _remoteOfferIsSet;
 };
-- 
GitLab