natplugins/natpnatfwsdpprovider/src/nspmediastreamcontainer.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Container for NAT FW streams, class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <sdpdocument.h>
       
    19 #include <sdpconnectionfield.h>
       
    20 #include <sdpmediafield.h>
       
    21 #include "natfwcredentials.h"
       
    22 #include "natfwcandidate.h"
       
    23 #include "natfwcandidatepair.h"
       
    24 #include "nspmediastreamcontainer.h"
       
    25 #include "nspmediastream.h"
       
    26 #include "nspcontrollerif.h"
       
    27 #include "nspcontentparser.h"
       
    28 #include "nsputil.h"
       
    29 #include "nspdefs.h"
       
    30 
       
    31 const TInt KMaxLengthOfFQDN = 255;
       
    32 const TUint KDefaultTosValue = 184;
       
    33 const TUint KMaxTosValue = 255;
       
    34 
       
    35 #define FINDSTREAM_L( stream, mediafield, streamarray )\
       
    36     User::LeaveIfNull( stream = NSPUtil::FindMediaStream( mediafield, streamarray ) )
       
    37 #define FINDSTREAM( mediafield, streamarray )\
       
    38     NSPUtil::FindMediaStream( mediafield, streamarray )
       
    39 #define FINDSTREAM_NOREJECT( mediafield, streamarray )\
       
    40     ( !NSPUtil::IsReject( mediafield ) ? FINDSTREAM( mediafield, streamarray ) : NULL )
       
    41 
       
    42 #define FINDFIELD_L( field, mediastream, fieldarray )\
       
    43     User::LeaveIfNull( field = NSPUtil::FindMediaField( mediastream, fieldarray ) )
       
    44 #define FINDFIELD( mediastream, fieldarray )\
       
    45     NSPUtil::FindMediaField( mediastream, fieldarray )
       
    46 #define FINDFIELD_NOREJECT( mediastream, fieldarray )\
       
    47     ( !NSPUtil::IsReject( *FINDFIELD( mediastream, fieldarray ) ) ? FINDFIELD( mediastream, fieldarray ) : NULL )
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 // ---------------------------------------------------------------------------
       
    51 // CNSPMediaStreamContainer::CNSPMediaStreamContainer
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CNSPMediaStreamContainer::CNSPMediaStreamContainer(
       
    55         MNSPControllerIF& aController, TUint aSessionId, TUint aProtocol )
       
    56     : iController( aController ),
       
    57       iSessionId( aSessionId ),
       
    58       iProtocol( aProtocol ),
       
    59       iMediaTos( KDefaultTosValue )
       
    60     {
       
    61     }
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CNSPMediaStreamContainer::NewL
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CNSPMediaStreamContainer* CNSPMediaStreamContainer::NewL(
       
    69         MNSPControllerIF& aController, TUint aSessionId, TUint aProtocol )
       
    70     {
       
    71     CNSPMediaStreamContainer* self = CNSPMediaStreamContainer::NewLC(
       
    72             aController, aSessionId, aProtocol );
       
    73     CleanupStack::Pop( self );
       
    74     return self;
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CNSPMediaStreamContainer::NewLC
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CNSPMediaStreamContainer* CNSPMediaStreamContainer::NewLC(
       
    83         MNSPControllerIF& aController, TUint aSessionId, TUint aProtocol )
       
    84     {
       
    85     CNSPMediaStreamContainer* self =  new ( ELeave ) CNSPMediaStreamContainer(
       
    86             aController, aSessionId, aProtocol );
       
    87     CleanupStack::PushL( self );
       
    88     return self;
       
    89     }
       
    90 
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CNSPMediaStreamContainer::~CNSPMediaStreamContainer
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 CNSPMediaStreamContainer::~CNSPMediaStreamContainer()
       
    97     {
       
    98     iPendingArray.Close();
       
    99     iStreamArray.ResetAndDestroy();
       
   100     iStreamArray.Close();
       
   101     }
       
   102 
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CNSPMediaStreamContainer::ControlMediaL
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 TNatReturnStatus CNSPMediaStreamContainer::ControlMediaL( TUint aStreamId,
       
   109 		MNATFWConnectivityObserver::TNATFWConnectivityEvent aEvent,
       
   110 		TInt aError, TAny* aData )
       
   111 	{
       
   112     TNatReturnStatus status = KErrNone;
       
   113     const TInt index = FindMediaStream( aStreamId );
       
   114 	
       
   115     if ( KErrNotFound != index )
       
   116         {
       
   117         status = iStreamArray[index]->ControlMediaL( aStreamId, aEvent, aError, aData );
       
   118         const TInt collectionId = iStreamArray[index]->CollectionId();
       
   119         TNatReturnStatus cont = RemovePending( collectionId, KNatReady == status );
       
   120         status = ( KNatReady == status ? cont : status );
       
   121         }
       
   122     else
       
   123     	{
       
   124     	status = KErrNotFound;
       
   125     	}
       
   126     
       
   127     return status;
       
   128 	}
       
   129 
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CNSPMediaStreamContainer::UpdateL
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CNSPMediaStreamContainer::UpdateL( RPointerArray<CNATFWCandidate>& aRemoteCands )
       
   136     {
       
   137     __ASSERT_ALWAYS( &aRemoteCands, User::Leave( KErrArgument ) );
       
   138     iController.UpdateIceProcessingL( iSessionId, aRemoteCands );
       
   139     }
       
   140 
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CNSPMediaStreamContainer::SetRoleL
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CNSPMediaStreamContainer::SetRoleL( TNATFWIceRole aRole )
       
   147     {
       
   148     iController.SetRoleL( iSessionId, aRole );
       
   149     }
       
   150 
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CNSPMediaStreamContainer::SetInboundCredentialsL
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CNSPMediaStreamContainer::SetInboundCredentialsL()
       
   157     {
       
   158     const TInt mediastreamcount( iStreamArray.Count() );
       
   159     for ( TInt index = 0; index < mediastreamcount ; index++ )
       
   160         {
       
   161         iStreamArray[index]->SetInboundCredentialsL();
       
   162         }
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CNSPMediaStreamContainer::SetOutboundCredentialsL
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CNSPMediaStreamContainer::SetOutboundCredentialsL()
       
   171     {
       
   172     const TInt mediastreamcount( iStreamArray.Count() );
       
   173     for ( TInt index = 0; index < mediastreamcount ; index++ )
       
   174         {
       
   175         iStreamArray[index]->SetOutboundCredentialsL();
       
   176         }
       
   177     }
       
   178 
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CNSPMediaStreamContainer::ResetAndDestroyCandidates
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 void CNSPMediaStreamContainer::ResetAndDestroyCandidates()
       
   185     {
       
   186     const TInt mediastreamcount( iStreamArray.Count() );
       
   187     for ( TInt index = 0; index < mediastreamcount ; index++ )
       
   188         {
       
   189         iStreamArray[index]->ResetAndDestroyCandidates();
       
   190         }
       
   191     }
       
   192 
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CNSPMediaStreamContainer::LoadPluginL
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CNSPMediaStreamContainer::LoadPluginL( CDesC8Array& aPlugins, TInt& aPluginIndex )
       
   199     {
       
   200     __ASSERT_ALWAYS( &aPlugins, User::Leave( KErrArgument ) );
       
   201     __ASSERT_ALWAYS( &aPluginIndex, User::Leave( KErrArgument ) );
       
   202     
       
   203     iController.LoadPluginL( iSessionId, aPlugins, aPluginIndex );
       
   204     }
       
   205 
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // CNSPMediaStreamContainer::FetchCandidateL
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 void CNSPMediaStreamContainer::FetchCandidateL()
       
   212     {
       
   213     const TInt mediastreamcount( iStreamArray.Count() );
       
   214     for ( TInt index = 0; index < mediastreamcount ; index++ )
       
   215         {
       
   216         iStreamArray[index]->FetchCandidateL();
       
   217         iPendingArray.AppendL( iStreamArray[index]->CollectionId() );
       
   218         }
       
   219     }
       
   220 
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CNSPMediaStreamContainer::FetchCandidatesL
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CNSPMediaStreamContainer::FetchCandidatesL()
       
   227     {
       
   228     const TInt mediastreamcount( iStreamArray.Count() );
       
   229     for ( TInt index = 0; index < mediastreamcount ; index++ )
       
   230         {
       
   231         iStreamArray[index]->FetchCandidatesL();
       
   232         iPendingArray.AppendL( iStreamArray[index]->CollectionId() );
       
   233         }
       
   234     }
       
   235 
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CNSPMediaStreamContainer::PerformCandidateChecksL
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CNSPMediaStreamContainer::PerformCandidateChecksL(
       
   242         RPointerArray<CNATFWCandidate>& aRemoteCandidates )
       
   243     {
       
   244     __ASSERT_ALWAYS( &aRemoteCandidates, User::Leave( KErrArgument ) );
       
   245     
       
   246     const TInt mediastreamcount( iStreamArray.Count() );
       
   247     for ( TInt index = 0; index < mediastreamcount ; index++ )
       
   248         {
       
   249         iStreamArray[index]->PerformCandidateChecksL();
       
   250         iPendingArray.AppendL( iStreamArray[index]->CollectionId() );
       
   251         }
       
   252     
       
   253     iController.PerformCandidateChecksL( iSessionId, aRemoteCandidates );
       
   254     }
       
   255 
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // CNSPMediaStreamContainer::ActivateL
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 void CNSPMediaStreamContainer::ActivateL( CSdpDocument& aDoc )
       
   262     {
       
   263     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   264     
       
   265     CSdpMediaField* field = NULL;
       
   266     CSdpConnectionField* connField = aDoc.ConnectionField();
       
   267     const TDesC8& address = ( connField ? connField->Address() : KNullDesC8 );
       
   268     RPointerArray<CSdpMediaField>& mediafields = aDoc.MediaFields();
       
   269     
       
   270     const TInt mediastreamcount( iStreamArray.Count() );
       
   271     for ( TInt index = 0; index < mediastreamcount ; index++ )
       
   272         {
       
   273         field = NSPUtil::FindMediaField( *iStreamArray[index], mediafields );
       
   274         iStreamArray[index]->ActivateL( *field, address );
       
   275         iPendingArray.AppendL( iStreamArray[index]->CollectionId() );
       
   276         }
       
   277     }
       
   278 
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // CNSPMediaStreamContainer::ActivateL
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 void CNSPMediaStreamContainer::ActivateL()
       
   285     {
       
   286     const TInt mediastreamcount( iStreamArray.Count() );
       
   287     for ( TInt index = 0; index < mediastreamcount ; index++ )
       
   288         {
       
   289         iStreamArray[index]->ActivateL();
       
   290         iPendingArray.AppendL( iStreamArray[index]->CollectionId() );
       
   291         }
       
   292     }
       
   293 
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // CNSPMediaStreamContainer::DeActivateL
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 void CNSPMediaStreamContainer::DeActivateL()
       
   300     {
       
   301     const TInt mediastreamcount( iStreamArray.Count() );
       
   302     for ( TInt index = 0; index < mediastreamcount ; index++ )
       
   303         {
       
   304         iStreamArray[index]->DeActivateL();
       
   305         iPendingArray.AppendL( iStreamArray[index]->CollectionId() );
       
   306         }
       
   307     }
       
   308 
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // CNSPMediaStreamContainer::CreateStreamsL
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 TNatReturnStatus CNSPMediaStreamContainer::CreateStreamsL( CSdpDocument& aDoc )
       
   315     {
       
   316     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   317     
       
   318     const CSdpConnectionField* connField = aDoc.ConnectionField();
       
   319     const TDesC8& address = ( connField ? connField->Address() : KNullDesC8 );
       
   320     
       
   321     TNatReturnStatus status = KNatReady;
       
   322     CNSPMediaStream* stream = NULL;
       
   323     RPointerArray<CSdpMediaField>& mediafields = aDoc.MediaFields();
       
   324     
       
   325     const TInt mediafieldcount( mediafields.Count() );
       
   326     
       
   327     __ASSERT_ALWAYS( mediafieldcount != 0, User::Leave( KErrNotFound ) );
       
   328     
       
   329     for ( TInt index = 0; index < mediafieldcount; index++ )
       
   330          {
       
   331          stream = NSPUtil::FindMediaStream( *mediafields[index], iStreamArray );
       
   332          if( NSPUtil::IsReject( *mediafields[index] ) || ( stream && 
       
   333         	  stream->MediaField().Port() ==  ( *mediafields[index] ).Port() ) )
       
   334             {
       
   335             NSPLOG_STR( "No need to create stream" )
       
   336             }
       
   337 		    else 
       
   338 		        {
       
   339             if ( stream ) 
       
   340             	  { 
       
   341 			          RemoveStream( stream );
       
   342 			          }
       
   343             stream = CNSPMediaStream::NewLC( iController, *mediafields[index],
       
   344         	               iSessionId, iController.CreateUniqueId(), address,
       
   345         	               iProtocol, iMediaTos );
       
   346         	  iStreamArray.AppendL( stream );
       
   347         	  CleanupStack::Pop( stream );
       
   348         	  status = KNatAsync;
       
   349 		        }
       
   350 	        }
       
   351     
       
   352     return status;
       
   353     }
       
   354 
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // CNSPMediaStreamContainer::RemoveStreamsL
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 TNatReturnStatus CNSPMediaStreamContainer::RemoveStreamsL( CSdpDocument& aDoc )
       
   361     {
       
   362     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   363     
       
   364     TNatReturnStatus status = KNatReady;
       
   365     CSdpMediaField* field = NULL;
       
   366     RPointerArray<CSdpMediaField>& mediafields = aDoc.MediaFields();
       
   367     
       
   368     const TInt mediafieldcount( mediafields.Count() );
       
   369     
       
   370     __ASSERT_ALWAYS( mediafieldcount != 0, User::Leave( KErrNotFound ) );
       
   371     
       
   372     for ( TInt index = 0; index < iStreamArray.Count(); )
       
   373         {
       
   374         field = FINDFIELD_NOREJECT( *iStreamArray[index], mediafields );
       
   375         
       
   376         if ( !field )
       
   377             {
       
   378             delete iStreamArray[index];
       
   379             iStreamArray.Remove(index);
       
   380             iStreamArray.Compress();
       
   381             status = KNatAsync;
       
   382             }
       
   383         else
       
   384             {
       
   385             index++;
       
   386             }
       
   387         }
       
   388     
       
   389     return status;
       
   390     }
       
   391 
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // CNSPMediaStreamContainer::ModStunSolvedL
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 void CNSPMediaStreamContainer::ModStunSolvedL( CSdpDocument& aDoc )
       
   398     {
       
   399     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   400     
       
   401     TBool sessionlevel = EFalse;
       
   402     CNSPMediaStream* stream = NULL;
       
   403     CSdpConnectionField* connField = aDoc.ConnectionField();
       
   404     CSdpOriginField* originField = aDoc.OriginField();
       
   405     RPointerArray<CSdpMediaField>& mediafields = aDoc.MediaFields();
       
   406     
       
   407     const TInt mediafieldscount( mediafields.Count() );
       
   408     const TInt mediastreamscount( iStreamArray.Count() );
       
   409     
       
   410     __ASSERT_ALWAYS( mediafieldscount != 0, User::Leave( KErrNotFound ) );
       
   411     __ASSERT_ALWAYS( mediastreamscount != 0, User::Leave( KErrNotFound ) );
       
   412 
       
   413     RBuf8 addr;
       
   414     addr.CreateL( KMaxLengthOfFQDN );
       
   415     addr.CleanupClosePushL();
       
   416     
       
   417     for ( TInt index = 0; index < mediafieldscount; index++ )
       
   418         {
       
   419         stream = FINDSTREAM_NOREJECT( *mediafields[index], iStreamArray );
       
   420         
       
   421         if ( stream )
       
   422             {
       
   423             stream->ModifyStunConnL( *mediafields[index], addr );
       
   424             
       
   425             if ( !sessionlevel )
       
   426                 {
       
   427                 if ( connField )
       
   428                     {
       
   429                     NSPUtil::UpdateConnectionFieldL( *connField, addr );
       
   430                     }
       
   431                 
       
   432                 if ( originField )
       
   433                     {
       
   434                     NSPUtil::UpdateOriginFieldL( *originField, addr );
       
   435                     }
       
   436                 
       
   437                 sessionlevel = ETrue;
       
   438                 }
       
   439             }
       
   440         }
       
   441     
       
   442     CleanupStack::PopAndDestroy( &addr );
       
   443     }
       
   444 
       
   445 
       
   446 // ---------------------------------------------------------------------------
       
   447 // CNSPMediaStreamContainer::ModIceSolvedL
       
   448 // ---------------------------------------------------------------------------
       
   449 //
       
   450 void CNSPMediaStreamContainer::ModIceSolvedL( CSdpDocument& aDoc )
       
   451     {
       
   452     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   453     
       
   454     TBool sessionlevel = EFalse;
       
   455     CNSPMediaStream* stream = NULL;
       
   456     CSdpConnectionField* connField = aDoc.ConnectionField();
       
   457     CSdpOriginField* originField = aDoc.OriginField();
       
   458     RPointerArray<CSdpMediaField>& mediafields = aDoc.MediaFields();
       
   459     
       
   460     const TInt mediafieldscount( mediafields.Count() );
       
   461     const TInt mediastreamscount( iStreamArray.Count() );
       
   462     
       
   463     __ASSERT_ALWAYS( mediafieldscount != 0, User::Leave( KErrNotFound ) );
       
   464     __ASSERT_ALWAYS( mediastreamscount != 0, User::Leave( KErrNotFound ) );
       
   465     
       
   466     RBuf8 addr;
       
   467     addr.CreateL( KMaxLengthOfFQDN );
       
   468     addr.CleanupClosePushL();
       
   469     
       
   470     for ( TInt index = 0; index < mediafieldscount; index++ )
       
   471         {
       
   472         stream = FINDSTREAM_NOREJECT( *mediafields[index], iStreamArray );
       
   473         
       
   474         if ( stream )
       
   475             {
       
   476             stream->ModifyIceConnL( *mediafields[index], addr );
       
   477             
       
   478             if ( !sessionlevel )
       
   479                 {
       
   480                 if ( connField )
       
   481                     {
       
   482                     NSPUtil::UpdateConnectionFieldL( *connField, addr );
       
   483                     }
       
   484                 
       
   485                 if ( originField )
       
   486                     {
       
   487                     NSPUtil::UpdateOriginFieldL( *originField, addr );
       
   488                     }
       
   489                 
       
   490                 sessionlevel = ETrue;
       
   491                 }
       
   492             }
       
   493         }
       
   494     
       
   495     CleanupStack::PopAndDestroy( &addr );
       
   496     }
       
   497 
       
   498 
       
   499 // ---------------------------------------------------------------------------
       
   500 // CNSPMediaStreamContainer::ModLocalSolvedL
       
   501 // ---------------------------------------------------------------------------
       
   502 //
       
   503 void CNSPMediaStreamContainer::ModLocalSolvedL( CSdpDocument& aDoc )
       
   504     {
       
   505     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   506     
       
   507     TBool sessionlevel = EFalse;
       
   508     CNSPMediaStream* stream = NULL;
       
   509     CSdpConnectionField* connField = aDoc.ConnectionField();
       
   510     CSdpOriginField* originField = aDoc.OriginField();
       
   511     RPointerArray<CSdpMediaField>& mediafields = aDoc.MediaFields();
       
   512     
       
   513     const TInt mediafieldscount( mediafields.Count() );
       
   514     const TInt mediastreamscount( iStreamArray.Count() );
       
   515     
       
   516     __ASSERT_ALWAYS( mediafieldscount != 0, User::Leave( KErrNotFound ) );
       
   517     __ASSERT_ALWAYS( mediastreamscount != 0, User::Leave( KErrNotFound ) );
       
   518     
       
   519     RBuf8 addr;
       
   520     addr.CreateL( KMaxLengthOfFQDN );
       
   521     addr.CleanupClosePushL();
       
   522     
       
   523     for ( TInt index = 0; index < mediafieldscount; index++ )
       
   524         {
       
   525         stream = FINDSTREAM_NOREJECT( *mediafields[index], iStreamArray );
       
   526         
       
   527         if ( stream )
       
   528             {
       
   529             stream->ModifyLocalConnL( *mediafields[index], addr );
       
   530             
       
   531             if ( !sessionlevel )
       
   532                 {
       
   533                 if ( connField )
       
   534                     {
       
   535                     NSPUtil::UpdateConnectionFieldL( *connField, addr );
       
   536                     }
       
   537                 
       
   538                 if ( originField )
       
   539                     {
       
   540                     NSPUtil::UpdateOriginFieldL( *originField, addr );
       
   541                     }
       
   542                 
       
   543                 sessionlevel = ETrue;
       
   544                 }
       
   545             }
       
   546         else
       
   547             {
       
   548             NSPUtil::RejectL( *mediafields[index] );
       
   549             }
       
   550         }
       
   551     
       
   552     CleanupStack::PopAndDestroy( &addr );
       
   553     }
       
   554 
       
   555 
       
   556 // ---------------------------------------------------------------------------
       
   557 // CNSPMediaStreamContainer::AddIceContentL
       
   558 // ---------------------------------------------------------------------------
       
   559 //
       
   560 void CNSPMediaStreamContainer::AddIceContentL( CSdpDocument& aDoc )
       
   561     {
       
   562     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   563     
       
   564     CNSPMediaStream* stream = NULL;
       
   565     RPointerArray<CSdpMediaField>& mediafields = aDoc.MediaFields();
       
   566     
       
   567     const TInt mediafieldscount( mediafields.Count() );
       
   568     const TInt mediastreamscount( iStreamArray.Count() );
       
   569     
       
   570     __ASSERT_ALWAYS( mediafieldscount != 0, User::Leave( KErrNotFound ) );
       
   571     __ASSERT_ALWAYS( mediastreamscount != 0, User::Leave( KErrNotFound ) );
       
   572     
       
   573     for ( TInt index = 0; index < mediafieldscount; index++ )
       
   574         {
       
   575         FINDSTREAM_L( stream, *mediafields[index], iStreamArray );
       
   576         stream->AddCredentialsL( *mediafields[index] );
       
   577         stream->AddLocalCandidatesL( *mediafields[index] );
       
   578         }
       
   579     }
       
   580 
       
   581 
       
   582 // ---------------------------------------------------------------------------
       
   583 // CNSPMediaStreamContainer::AddRemoteCandidatesL
       
   584 // ---------------------------------------------------------------------------
       
   585 //
       
   586 void CNSPMediaStreamContainer::AddRemoteCandidatesL( CSdpDocument& aDoc )
       
   587     {
       
   588     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   589     
       
   590     CNSPMediaStream* stream = NULL;
       
   591     RPointerArray<CSdpMediaField>& mediafields = aDoc.MediaFields();
       
   592     
       
   593     const TInt mediafieldcount( mediafields.Count() );
       
   594     for ( TInt index = 0; index < mediafieldcount; index++ )
       
   595         {
       
   596         FINDSTREAM_L( stream, *mediafields[index], iStreamArray );
       
   597         stream->AddRemoteCandidatesL( *mediafields[index] );
       
   598         }
       
   599     }
       
   600 
       
   601 
       
   602 // ---------------------------------------------------------------------------
       
   603 // CNSPMediaStreamContainer::GetCandidatesL
       
   604 // ---------------------------------------------------------------------------
       
   605 //
       
   606 TNatReturnStatus CNSPMediaStreamContainer::GetCandidatesL( CSdpDocument& aDoc,
       
   607         RPointerArray<CNATFWCandidate>& aRemoteCandidates )
       
   608     {
       
   609     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   610     __ASSERT_ALWAYS( &aRemoteCandidates, User::Leave( KErrArgument ) );
       
   611     
       
   612     TNatReturnStatus status = KNatReady;
       
   613     CNSPMediaStream* stream = NULL;
       
   614     RPointerArray<CSdpMediaField>& mediafields = aDoc.MediaFields();
       
   615     
       
   616     const TInt mediafieldscount( mediafields.Count() );
       
   617     
       
   618     __ASSERT_ALWAYS( mediafieldscount != 0, User::Leave( KErrNotFound ) );
       
   619     __ASSERT_ALWAYS( iStreamArray.Count() != 0, User::Leave( KErrNotFound ) );
       
   620     
       
   621     for ( TInt index = 0; index < mediafieldscount; index++ )
       
   622         {
       
   623         RPointerArray<CNATFWCandidate> remotecands;
       
   624         CleanupStack::PushL( TCleanupItem( NSPUtil::CleanupArrayItem, &remotecands ) );
       
   625         stream = FINDSTREAM( *mediafields[index], iStreamArray );
       
   626         
       
   627         if ( stream )
       
   628             {
       
   629             stream->GetCandidatesL( *mediafields[index], remotecands );
       
   630             
       
   631             while ( 0 < remotecands.Count() )
       
   632                 {
       
   633                 if ( NSPUtil::IsDuplicate( *remotecands[0], aRemoteCandidates ) )
       
   634                     {
       
   635                     delete remotecands[0];
       
   636                     }
       
   637                 else
       
   638                     {
       
   639                     aRemoteCandidates.AppendL( remotecands[0] );// ownership transferred
       
   640                     status = KNatAsync;
       
   641                     }
       
   642                 
       
   643                 remotecands.Remove(0);
       
   644                 remotecands.Compress();
       
   645                 }
       
   646             }
       
   647         
       
   648         CleanupStack::PopAndDestroy(); // remotecands
       
   649         }
       
   650     
       
   651     return status;
       
   652     }
       
   653 
       
   654 
       
   655 // ---------------------------------------------------------------------------
       
   656 // CNSPMediaStreamContainer::GetCredentialsL
       
   657 // ---------------------------------------------------------------------------
       
   658 //
       
   659 TNatReturnStatus CNSPMediaStreamContainer::GetCredentialsL( CSdpDocument& aDoc,
       
   660         CNATFWCredentials& aSessionlevel )
       
   661     {
       
   662     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   663     __ASSERT_ALWAYS( &aSessionlevel, User::Leave( KErrArgument ) );
       
   664     
       
   665     TNatReturnStatus status = KNatReady;
       
   666     CNSPMediaStream* stream = NULL;
       
   667     RPointerArray<CSdpMediaField>& mediafields = aDoc.MediaFields();
       
   668     
       
   669     const TInt mediafieldscount( mediafields.Count() );
       
   670     const TInt mediastreamscount( iStreamArray.Count() );
       
   671     
       
   672     __ASSERT_ALWAYS( mediafieldscount != 0, User::Leave( KErrNotFound ) );
       
   673     __ASSERT_ALWAYS( mediastreamscount != 0, User::Leave( KErrNotFound ) );
       
   674     
       
   675     CNATFWCredentials* sessionLevel = CNATFWCredentials::NewLC();
       
   676     sessionLevel->SetDirection( CNATFWCredentials::EOutbound );
       
   677     iController.ContentParser().GetCredentialsL( aDoc, *sessionLevel );
       
   678     
       
   679     if ( !CNATFWCredentials::Compare( aSessionlevel, *sessionLevel ) )
       
   680         {
       
   681         aSessionlevel.CopyL( *sessionLevel );
       
   682         status = KNatAsync;
       
   683         }
       
   684     
       
   685     CleanupStack::PopAndDestroy( sessionLevel );
       
   686     
       
   687     for ( TInt index = 0; index < mediafieldscount; index++ )
       
   688         {
       
   689         CNATFWCredentials* mediaLevel = CNATFWCredentials::NewLC( aSessionlevel );
       
   690         iController.ContentParser().GetCredentialsL( *mediafields[index], *mediaLevel );
       
   691         CleanupStack::Pop( mediaLevel );
       
   692         
       
   693         stream = FINDSTREAM( *mediafields[index], iStreamArray );
       
   694         
       
   695         if ( stream )
       
   696             {
       
   697             stream->SetOutboundCredentials( mediaLevel ); // ownership changed.
       
   698             }
       
   699         else
       
   700             {
       
   701             delete mediaLevel;
       
   702             }
       
   703         }
       
   704     
       
   705     return status;
       
   706     }
       
   707 
       
   708 
       
   709 // ---------------------------------------------------------------------------
       
   710 // CNSPMediaStreamContainer::GetSessionConnInfoL
       
   711 // ---------------------------------------------------------------------------
       
   712 //
       
   713 TNatReturnStatus CNSPMediaStreamContainer::GetSessionConnInfoL( CSdpDocument& aDoc )
       
   714     {
       
   715     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   716     
       
   717     TNatReturnStatus status = KNatReady;
       
   718     TNatReturnStatus mediastatus = status;
       
   719     CNSPMediaStream* stream = NULL;
       
   720     CSdpConnectionField* connField = aDoc.ConnectionField();
       
   721     const TDesC8& address = ( connField ? connField->Address() : KNullDesC8 );
       
   722     RPointerArray<CSdpMediaField>& mediafields = aDoc.MediaFields();
       
   723     
       
   724     const TInt mediafieldscount( mediafields.Count() );
       
   725     const TInt mediastreamscount( iStreamArray.Count() );
       
   726     
       
   727     __ASSERT_ALWAYS( mediafieldscount != 0, User::Leave( KErrNotFound ) );
       
   728     __ASSERT_ALWAYS( mediastreamscount != 0, User::Leave( KErrNotFound ) );
       
   729 
       
   730     RBuf8 addr;
       
   731     addr.CreateL( KMaxLengthOfFQDN );
       
   732     addr.CleanupClosePushL();
       
   733     
       
   734     for ( TInt index = 0; index < mediafieldscount; index++ )
       
   735         {
       
   736         stream = FINDSTREAM( *mediafields[index], iStreamArray );
       
   737         
       
   738         if ( stream )
       
   739             {
       
   740             addr = address;
       
   741             mediastatus = stream->MediaConnInfoL( *mediafields[index], addr );
       
   742             status = ( KNatReady == status ? mediastatus : status );
       
   743             addr.Zero();
       
   744             }
       
   745         else
       
   746             {
       
   747             NSPUtil::RejectL( *mediafields[index] );
       
   748             }
       
   749         }
       
   750     
       
   751     CleanupStack::PopAndDestroy( &addr );
       
   752     return status;
       
   753     }
       
   754 
       
   755 
       
   756 // ---------------------------------------------------------------------------
       
   757 // CNSPMediaStreamContainer::CheckUpdateL
       
   758 // ---------------------------------------------------------------------------
       
   759 //
       
   760 CSdpDocument* CNSPMediaStreamContainer::CheckUpdateL( CSdpDocument& aDoc )
       
   761     {
       
   762     __ASSERT_ALWAYS( &aDoc, User::Leave( KErrArgument ) );
       
   763     
       
   764     TBool needToUpdate = EFalse;
       
   765     CSdpDocument* update = NULL;
       
   766     
       
   767     const TInt mediastreamscount( iStreamArray.Count() );
       
   768     
       
   769     __ASSERT_ALWAYS( mediastreamscount != 0, User::Leave( KErrNotFound ) );
       
   770     
       
   771     for ( TInt index = 0; index < mediastreamscount && !needToUpdate; index++ )
       
   772         {
       
   773         needToUpdate = iStreamArray[index]->NeedToUpdateL();
       
   774         }
       
   775     
       
   776     if ( needToUpdate )
       
   777         {
       
   778         ModIceSolvedL( aDoc );
       
   779         update = aDoc.CloneL();
       
   780         }
       
   781     
       
   782     return update;
       
   783     }
       
   784 
       
   785 
       
   786 // ---------------------------------------------------------------------------
       
   787 // CNSPMediaStreamContainer::SetMediaTos
       
   788 // ---------------------------------------------------------------------------
       
   789 //
       
   790 TInt CNSPMediaStreamContainer::SetMediaTos( TUint aMediaTos )
       
   791     {
       
   792     if ( KMaxTosValue >= aMediaTos )
       
   793         {
       
   794         iMediaTos = aMediaTos;
       
   795         return KErrNone;
       
   796         }
       
   797     else
       
   798         {
       
   799         return KErrArgument;
       
   800         }
       
   801     }
       
   802 
       
   803 
       
   804 // ---------------------------------------------------------------------------
       
   805 // CNSPMediaStreamContainer::MediaTos
       
   806 // ---------------------------------------------------------------------------
       
   807 //
       
   808 TUint CNSPMediaStreamContainer::MediaTos() const
       
   809     {
       
   810     return iMediaTos;
       
   811     }
       
   812 
       
   813 
       
   814 // ---------------------------------------------------------------------------
       
   815 // CNSPMediaStreamContainer::RemovePending
       
   816 // ---------------------------------------------------------------------------
       
   817 //
       
   818 TNatReturnStatus CNSPMediaStreamContainer::RemovePending(
       
   819         TUint aComponentId, TBool aRemove )
       
   820     {
       
   821     TNatReturnStatus status = KNatAsync;
       
   822     
       
   823     if ( aRemove )
       
   824         {
       
   825         const TInt index = iPendingArray.Find( aComponentId );
       
   826         
       
   827         if ( KErrNotFound != index )
       
   828             {
       
   829             iPendingArray.Remove( index );
       
   830             iPendingArray.Compress();
       
   831             status = ( iPendingArray.Count() ? KNatAsync : KNatReady );
       
   832             }
       
   833         else
       
   834             {
       
   835             status = KNatAsync;
       
   836             }
       
   837         }
       
   838     
       
   839     return status;
       
   840     }
       
   841 
       
   842 
       
   843 // ---------------------------------------------------------------------------
       
   844 // CNSPMediaStreamContainer::FindMediaStream
       
   845 // ---------------------------------------------------------------------------
       
   846 //
       
   847 TInt CNSPMediaStreamContainer::FindMediaStream( TUint aStreamId )
       
   848     {
       
   849     const TInt streamcount( iStreamArray.Count() );
       
   850     for ( TInt index = 0; index < streamcount; index++ )
       
   851         {
       
   852         if ( iStreamArray[index]->HasMediaComponent( aStreamId ) )
       
   853             {
       
   854             return index;
       
   855             }
       
   856         }
       
   857     
       
   858     return KErrNotFound;
       
   859     }
       
   860 
       
   861 
       
   862 // ---------------------------------------------------------------------------
       
   863 // CNSPMediaStreamContainer::FindCollection
       
   864 // ---------------------------------------------------------------------------
       
   865 //
       
   866 TInt CNSPMediaStreamContainer::FindCollection( TUint aCollectionId )
       
   867     {
       
   868     const TInt streamcount( iStreamArray.Count() );
       
   869     for ( TInt index = 0; index < streamcount; index++ )
       
   870         {
       
   871         if ( iStreamArray[index]->CollectionId() == aCollectionId )
       
   872             {
       
   873             return index;
       
   874             }
       
   875         }
       
   876     
       
   877     return KErrNotFound;
       
   878     }
       
   879     
       
   880     
       
   881 // ---------------------------------------------------------------------------
       
   882 // CNSPMediaStreamContainer::RemoveStream
       
   883 // ---------------------------------------------------------------------------
       
   884 //
       
   885 TInt CNSPMediaStreamContainer::RemoveStream( CNSPMediaStream* aStream )
       
   886     {
       
   887     TInt status = KErrNotFound;
       
   888     const TInt mediastreamscount( iStreamArray.Count() );
       
   889     for ( TInt index = 0; index < mediastreamscount; index++ )
       
   890          {
       
   891          if ( iStreamArray[index] == aStream ) 
       
   892              {
       
   893 			       delete iStreamArray[index];
       
   894 	           iStreamArray.Remove(index);
       
   895 	           iStreamArray.Compress();
       
   896 	           status = KErrNone;
       
   897 	           return status;
       
   898 	           }      
       
   899 		     }
       
   900     return status;
       
   901     }
       
   902 
       
   903 
       
   904 // end of file