mmshplugins/mmshsipcrplugin/src/mussipcrplugin.cpp
branchRCL_3
changeset 22 73a1feb507fb
parent 0 f0cf47e981f9
child 23 bc78a40cd63c
--- a/mmshplugins/mmshsipcrplugin/src/mussipcrplugin.cpp	Thu Aug 19 09:51:39 2010 +0300
+++ b/mmshplugins/mmshsipcrplugin/src/mussipcrplugin.cpp	Tue Aug 31 15:12:07 2010 +0300
@@ -24,10 +24,20 @@
 #include "musmanager.h"
 #include "musuid.hrh"
 #include "musunittesting.h"
+#include "mussettings.h"
 
+#include <mussettingskeys.h>
 #include <sipstrings.h>
 #include <sipstrconsts.h>
-#include <featmgr.h>
+#include <sdpdocument.h>
+#include <sdpmediafield.h>
+#include <sdpcodecstringpool.h>
+#include <sdpcodecstringconstants.h>
+#include <sdpattributefield.h>
+
+_LIT8( KSendRecv, "sendrecv");                  // For attribute checks
+_LIT8( KRecvOnly, "recvonly");                  // For attribute checks
+_LIT8( KSendOnly, "sendonly" );                 // For attribute checks
 
 _LIT8(KCapabilities,
 "<SIP_CLIENT ALLOW_STARTING=\"YES\">\
@@ -45,6 +55,7 @@
 </SDP_LINES>\
 </SIP_CLIENT>");
 
+
 // -------------------------------------------------------------------------
 // Two-phased constructor.
 // -------------------------------------------------------------------------
@@ -69,6 +80,10 @@
     {
     MUS_LOG( "mus: [MUSSCR]  -> CMusSipCrPlugin::~CMusSipCrPlugin()" );
     delete iManager;
+    if ( iCloseStringPool )
+        {
+        SdpCodecStringPool::Close();
+        }
     MUS_LOG( "mus: [MUSSCR]  <- CMusSipCrPlugin::~CMusSipCrPlugin()" );
     }
 
@@ -90,6 +105,31 @@
     {
     MUS_LOG( "mus: [MUSSCR]  -> CMusSipCrPlugin::ConstructL()" );
     iManager = CMusManager::NewL();
+    
+    TRAPD( err, SdpCodecStringPool::OpenL() );
+    
+    switch ( err )
+        {
+        case KErrNone:
+            {
+            //close pool at destructor, not opened by others
+            iCloseStringPool = ETrue;
+            break;
+            }
+        
+        case KErrAlreadyExists:
+            {
+            //already opened, do not try to close at destructor
+            iCloseStringPool = EFalse;
+            break;
+            }
+        
+        default:
+            {
+            User::Leave( err );
+            }
+        }
+    
     MUS_LOG( "mus: [MUSSCR]  <- CMusSipCrPlugin::ConstructL()" );
     }
 
@@ -101,34 +141,16 @@
 TUid CMusSipCrPlugin::ChannelL( RStringF aMethod,
     const TDesC8& /*aRequestUri*/,
     const RPointerArray<CSIPHeaderBase>& /*aHeaders*/,
-    const TDesC8& /*aContent*/,
-    const CSIPContentTypeHeader* /*aContentType*/)
+    const TDesC8& aContent,
+    const CSIPContentTypeHeader* /*aContentType*/ )
     {
-	FeatureManager::InitializeLibL();
-    TBool support = FeatureManager::FeatureSupported( KFeatureIdMultimediaSharing );
-	FeatureManager::UnInitializeLib();
-	TUid uid;
-	uid.iUid = ( TInt ) CMusManager::ESipInviteNotDesired;
-	if ( support )
-		{
-	    uid = DoChannelL( aMethod );  
-		}
-    return uid;	
-    }
-	
-	
-// -------------------------------------------------------------------------
-// CMusSipCrPlugin::DoChannelL
-// -------------------------------------------------------------------------
-TUid CMusSipCrPlugin::DoChannelL( RStringF aMethod )
-    {
-    MUS_LOG( "mus: [MUSSCR]  -> CMusSipCrPlugin::DoChannelL()" );
-
+    MUS_LOG( "mus: [MUSSCR]  -> CMusSipCrPlugin::ChannelL()" );
+    
     if ( aMethod == SIPStrings::StringF( SipStrConsts::EOptions ) )
         {
         TUid uid;
         uid.iUid = ( TInt ) CMusManager::ESipOptions;
-        MUS_LOG1( "mus: [MUSSCR]     <- CMusSipCrPlugin::DoChannelL(): KSipOptions %d",
+        MUS_LOG1( "mus: [MUSSCR]     <- CMusSipCrPlugin::ChannelL(): KSipOptions %d",
                   uid.iUid );
         return uid;
         }
@@ -142,7 +164,7 @@
             {
             TUid uid;
             uid.iUid = ( TInt ) CMusManager::ESipInviteNotDesired;
-            MUS_LOG1( "mus: [MUSSCR]     <- CMusSipCrPlugin::DoChannelL(): \
+            MUS_LOG1( "mus: [MUSSCR]     <- CMusSipCrPlugin::ChannelL(): \
                       KNotAllowedSipInvite %d", uid.iUid );
             return uid;
             }
@@ -150,14 +172,90 @@
             {
             TUid uid;
             uid.iUid = ( TInt ) CMusManager::ESipInviteDesired;
-            MUS_LOG1( "mus: [MUSSCR]     <- CMusSipCrPlugin::DoChannelL(): \
+            TBool twoWaySupported = MultimediaSharingSettings::VideoDirectionL() == 
+                                    MusSettingsKeys::ETwoWayVideo;
+            
+            if ( ( aContent.Length() > 0 ) && twoWaySupported )
+                {
+                MUS_LOG( "mus: [MUSSCR]  2 way supported, parsing SDP..." );
+                CSdpDocument* sdpDocument = CSdpDocument::DecodeLC( aContent );
+                TBool sendRecv = CheckForSendRecvAttributeL( sdpDocument->MediaFields() );
+                if ( sendRecv )
+                    {
+                    uid.iUid = ( TInt ) CMusManager::ESipInviteDesired2WayVideo;
+                    }
+                    
+                CleanupStack::PopAndDestroy( sdpDocument );
+                }
+
+            MUS_LOG1( "mus: [MUSSCR]     <- CMusSipCrPlugin::ChannelL(): \
                       KAllowedSipInvite %d", uid.iUid );
             return uid;
             }
         }
     }
 
-
+// -------------------------------------------------------------------------
+// CMusSipCrPlugin::CheckForSendRecvAttribute
+// -------------------------------------------------------------------------
+//
+TBool CMusSipCrPlugin::CheckForSendRecvAttributeL(
+    RPointerArray<CSdpMediaField>& aFields ) const
+    {
+    MUS_LOG( "mus: [MUSSCR]  -> CMusSipCrPlugin::CheckForSendRecvAttribute()" );
+    
+    TBool sendRecv = EFalse;
+    TBool sendAttrFound = EFalse;
+    TBool videoFound = EFalse;
+    RStringF videoType = SdpCodecStringPool::StringPoolL().StringF(
+                    SdpCodecStringConstants::EMediaVideo,
+                    SdpCodecStringPool::StringTableL() );
+    const TInt fieldcount = aFields.Count();
+    
+    for ( TInt i = 0; i < fieldcount && !videoFound; i++ )
+        {
+        CSdpMediaField* mField = aFields[i];
+        
+        //only check video fields
+        videoFound = mField->Media() == videoType;
+        
+        if ( videoFound )
+            {
+            RPointerArray< CSdpAttributeField > attrList =
+                mField->AttributeFields();
+            
+            TInt attrCount = attrList.Count();
+            for (TInt j = 0; j < attrCount && !sendAttrFound; j++ )
+                {
+                CSdpAttributeField* attributeField = attrList[j];
+                RStringF attribute = attributeField->Attribute();                
+                
+                if ( KErrNotFound != attribute.DesC().FindF( KSendRecv ) )
+                    {
+                    sendRecv = ETrue;
+                    sendAttrFound = ETrue;
+                    MUS_LOG( "mus: [MUSSCR]  <sendrecv> attribute found!" );
+                    }
+                else if ( ( KErrNotFound != attribute.DesC().FindF( KSendOnly ) ) ||
+                          ( KErrNotFound != attribute.DesC().FindF( KRecvOnly ) ) )
+                    {
+                    MUS_LOG( "mus: [MUSSCR]  <sendonly>/<recvonly> attribute found!" );
+                    sendAttrFound = ETrue;
+                    }
+                }
+            
+            if ( !sendAttrFound )
+                {
+                MUS_LOG( "mus: [MUSSCR]  no send/recv related attributes found!" );
+                sendRecv = ETrue;
+                }
+            }
+        }
+    MUS_LOG1( "mus: [MUSSCR]  <- CMusSipCrPlugin::CheckForSendRecvAttribute(), \
+            sendrecv: %d", sendRecv );
+   
+    return sendRecv;
+    }
 
 // -------------------------------------------------------------------------
 // CMusSipCrPlugin::ConnectL
@@ -168,6 +266,7 @@
     MUS_LOG1( "mus: [MUSSCR]     -> CMusSipCrPlugin::ConnectL( %d )", aUid.iUid );
     if ( aUid.iUid == CMusManager::ESipOptions ||
          aUid.iUid == CMusManager::ESipInviteDesired ||
+         aUid.iUid == CMusManager::ESipInviteDesired2WayVideo ||
          aUid.iUid == CMusManager::ESipInviteNotDesired )
         {
         iManager->HandleSipRequestL(( CMusManager::TRequestType ) aUid.iUid );