natfw/natfwicecandidatehandler/src/cicesessiondata.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006-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:    Storage for session related data.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <e32math.h>
       
    22 #include "natfwcredentials.h"
       
    23 #include "natfwcandidate.h"
       
    24 #include "natfwcandidatepair.h"
       
    25 #include "mnatfwpluginobserver.h"
       
    26 #include "cicesessiondata.h"
       
    27 #include "cicestreamcollection.h"
       
    28 #include "icecandidatehandlerdefs.h"
       
    29 #include "icecandidatehandlerlogs.h"
       
    30 
       
    31 const TUint KInitialIdentifierLength = 16;
       
    32 _LIT8( KColon, ":" );
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 CIceSessionData::CIceSessionData( TUint32 aIapId )
       
    37     :
       
    38     iIapId( aIapId )
       
    39     {
       
    40     __ICEDP( "CIceSessionData::CIceSessionData" )
       
    41     }
       
    42 
       
    43 
       
    44 void CIceSessionData::ConstructL( const TDesC8& aDomain )
       
    45     {
       
    46     __ICEDP( "CIceSessionData::ConstructL" )
       
    47     
       
    48     iTempIdentifier.CreateL( KInitialIdentifierLength );
       
    49     iDomain = aDomain.AllocL();
       
    50     }
       
    51 
       
    52 
       
    53 CIceSessionData* CIceSessionData::NewL(
       
    54         const TDesC8& aDomain, TUint32 aIapId )
       
    55     {
       
    56     __ICEDP( "CIceSessionData::NewL" )
       
    57 
       
    58     CIceSessionData* self 
       
    59         = CIceSessionData::NewLC( aDomain, aIapId );
       
    60     CleanupStack::Pop( self );
       
    61     
       
    62     return self;
       
    63     }
       
    64 
       
    65 
       
    66 CIceSessionData* CIceSessionData::NewLC(
       
    67         const TDesC8& aDomain, TUint32 aIapId )
       
    68     {
       
    69     __ICEDP( "CIceSessionData::NewLC" )
       
    70 
       
    71     CIceSessionData* self 
       
    72         = new ( ELeave ) CIceSessionData( aIapId );
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL( aDomain );
       
    75     
       
    76     return self;
       
    77     }
       
    78     
       
    79 
       
    80 CIceSessionData::~CIceSessionData()
       
    81     {
       
    82     __ICEDP( "CIceSessionData::~CIceSessionData" )
       
    83 
       
    84     iStreamCollections.ResetAndDestroy();  
       
    85     iLocalCandidateList.ResetAndDestroy();
       
    86     iRemoteCandidateList.ResetAndDestroy();
       
    87     iCredentialsList.ResetAndDestroy();
       
    88     iTempIdentifier.Close();
       
    89     delete iDomain;
       
    90     }
       
    91     
       
    92   
       
    93 // ---------------------------------------------------------------------------
       
    94 // CIceSessionData::AddPeerReflexiveCandidateL
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CIceSessionData::AddPeerReflexiveCandidateL( 
       
    98         CNATFWCandidate* aPeerCandidate, TBool aIsRemoteCand )
       
    99     {
       
   100     __ICEDP( "CIceSessionData::AddPeerReflexiveCandidateL" )
       
   101     __ASSERT_DEBUG( aPeerCandidate, User::Leave( KErrArgument ) );
       
   102     
       
   103     CleanupStack::PushL( aPeerCandidate );
       
   104     if ( aIsRemoteCand )
       
   105         {
       
   106         TInt ind( iRemoteCandidateList.Count() );
       
   107         while ( ind-- )
       
   108             {
       
   109             if ( TIceUtils::MatchAddresses( 
       
   110                     iRemoteCandidateList[ind]->TransportAddr(),
       
   111                     aPeerCandidate->TransportAddr() ) )
       
   112                 {
       
   113                 CleanupStack::PopAndDestroy( aPeerCandidate );
       
   114                 return;
       
   115                 }
       
   116             }
       
   117         
       
   118         // Assign arbitrary foundation (ICE-17, 7.2.1.3.)
       
   119         do 
       
   120             {
       
   121             const TDesC8& foundation = GenerateRandomIdentifier();
       
   122             aPeerCandidate->SetFoundationL( foundation );
       
   123             } while ( KErrNotFound != iRemoteCandidateList.Find( 
       
   124                 aPeerCandidate, CNATFWCandidate::CompareFoundations ) );
       
   125         
       
   126         iRemoteCandidateList.AppendL( aPeerCandidate );
       
   127         CleanupStack::Pop( aPeerCandidate );
       
   128         }
       
   129     else
       
   130         {
       
   131         if ( !IsRedundantCandidate( *aPeerCandidate, iLocalCandidateList ) )
       
   132             {
       
   133             AssignFoundationForCandidateL( *aPeerCandidate );
       
   134             iLocalCandidateList.AppendL( aPeerCandidate );
       
   135             CleanupStack::Pop( aPeerCandidate );
       
   136             }
       
   137         else
       
   138             {
       
   139             CleanupStack::PopAndDestroy( aPeerCandidate );
       
   140             }
       
   141         }
       
   142     }
       
   143     
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // CIceSessionData::FindLocalCandidate
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 const CNATFWCandidate* CIceSessionData::FindLocalCandidate( 
       
   150         const TInetAddr& aTransportAddr ) const
       
   151     {
       
   152     TInt count( iLocalCandidateList.Count() );
       
   153     for ( TInt i = 0; i < count; i++ )
       
   154         {
       
   155         const CNATFWCandidate* curItem = iLocalCandidateList[i];
       
   156         
       
   157         if ( TIceUtils::MatchAddresses( 
       
   158                 curItem->TransportAddr(), aTransportAddr ) )
       
   159             {
       
   160             return curItem;
       
   161             }
       
   162         }
       
   163     
       
   164     return NULL;
       
   165     }
       
   166 
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CIceSessionData::FindLocalCandidate
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 const CNATFWCandidate* CIceSessionData::FindLocalCandidate( 
       
   173         TUint aStreamCollectionId,
       
   174         TUint aComponentId,
       
   175         CNATFWCandidate::TCandidateType aType ) const
       
   176     {
       
   177     TInt count( iLocalCandidateList.Count() );
       
   178     for ( TInt i = 0; i < count; i++ )
       
   179         {
       
   180         const CNATFWCandidate* curItem = iLocalCandidateList[i];
       
   181         
       
   182         if ( curItem->StreamCollectionId() == aStreamCollectionId 
       
   183             && curItem->ComponentId() == aComponentId
       
   184             && curItem->Type() == aType )
       
   185             {
       
   186             return curItem;
       
   187             }
       
   188         }
       
   189     
       
   190     return NULL;
       
   191     }
       
   192 
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CIceSessionData::FindRemoteCandidate
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 const CNATFWCandidate* CIceSessionData::FindRemoteCandidate( 
       
   199         const TInetAddr& aTransportAddr ) const
       
   200     {
       
   201     TInt count( iRemoteCandidateList.Count() );
       
   202     for ( TInt i = 0; i < count; i++ )
       
   203         {
       
   204         const CNATFWCandidate* curItem = iRemoteCandidateList[i];
       
   205         
       
   206         if ( TIceUtils::MatchAddresses( 
       
   207                 curItem->TransportAddr(), aTransportAddr ) )
       
   208             {
       
   209             return curItem;
       
   210             }
       
   211         }
       
   212     
       
   213     return NULL;
       
   214     }
       
   215     
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // CIceSessionData::GetLocalCandidates
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 void CIceSessionData::GetLocalCandidates(
       
   222                 const TUint aStreamCollectionId,
       
   223                 const TUint aStreamId,
       
   224                 RPointerArray<CNATFWCandidate>& aLocalCandidates )
       
   225     {
       
   226     __ICEDP( "CIceSessionData::GetLocalCandidates" )
       
   227     
       
   228     for ( TInt i = 0; i < iLocalCandidateList.Count(); i++ )
       
   229         {
       
   230         if ( iLocalCandidateList[i]->StreamCollectionId() 
       
   231                 == aStreamCollectionId
       
   232             && iLocalCandidateList[i]->StreamId() == aStreamId ) 
       
   233             {
       
   234             aLocalCandidates.Append( iLocalCandidateList[i] );
       
   235             }
       
   236         }
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CIceSessionData::GetLocalCandidates
       
   241 // ---------------------------------------------------------------------------
       
   242 //    
       
   243 void CIceSessionData::GetLocalCandidates( 
       
   244         const TUint aStreamCollectionId,
       
   245         RPointerArray<CNATFWCandidate>& aLocalCandidates )
       
   246     {
       
   247     __ICEDP( "CIceSessionData::GetLocalCandidates" )
       
   248     
       
   249     for ( TInt i = 0; i < iLocalCandidateList.Count(); i++ )
       
   250         {
       
   251         if ( iLocalCandidateList[i]->StreamCollectionId() 
       
   252                 == aStreamCollectionId ) 
       
   253             {
       
   254             aLocalCandidates.Append( iLocalCandidateList[i] );
       
   255             }
       
   256         }
       
   257     }
       
   258  
       
   259 // ---------------------------------------------------------------------------
       
   260 // CIceSessionData::GetLocalCandidates
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 void CIceSessionData::GetLocalCandidates(
       
   264                      RPointerArray<CNATFWCandidate>& aLocalCandidates )
       
   265     {
       
   266     __ICEDP( "CIceSessionData::GetLocalCandidates" )
       
   267     
       
   268     for ( TInt i = 0; i < iLocalCandidateList.Count(); i++ )
       
   269         {
       
   270         aLocalCandidates.Append( iLocalCandidateList[i] );
       
   271         }
       
   272     }
       
   273 
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // CIceSessionData::DeleteCollection
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 void CIceSessionData::DeleteCollection( TUint aStreamCollectionId )
       
   280     { 
       
   281     __ICEDP( "CIceSessionData::DeleteCollection" )
       
   282     
       
   283     CIceStreamCollection* collection 
       
   284         = FindStreamCollectionById( aStreamCollectionId );
       
   285     
       
   286     if ( collection )
       
   287         {
       
   288         TInt ind( iStreamCollections.Find( collection ) );
       
   289         iStreamCollections.Remove( ind );
       
   290         delete collection;
       
   291         }
       
   292     }
       
   293 
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // CIceSessionData::AddCredentialsL
       
   297 // Existing credentials for a stream is replaced with the new one.
       
   298 // ---------------------------------------------------------------------------
       
   299 //    
       
   300 void CIceSessionData::AddCredentialsL(
       
   301         const CNATFWCredentials& aCredentials )
       
   302     {
       
   303     __ICEDP( "CIceSessionData::AddCredentialsL" )
       
   304     
       
   305     TBool existingCredentialsFound( EFalse );
       
   306     TInt credentialsInd( iCredentialsList.Count() - 1 );
       
   307     while ( !existingCredentialsFound && 0 <= credentialsInd )
       
   308         {
       
   309         CNATFWCredentials* item = iCredentialsList[credentialsInd];
       
   310         if ( item->StreamCollectionId()
       
   311                 == aCredentials.StreamCollectionId()
       
   312             && item->StreamId() == aCredentials.StreamId()
       
   313             && item->Direction() == aCredentials.Direction() )
       
   314             {
       
   315             existingCredentialsFound = ETrue;
       
   316             item->SetUsernameL( aCredentials.Username() );
       
   317             item->SetPasswordL( aCredentials.Password() );
       
   318             UpdateUserNamesL( *item );
       
   319             }
       
   320         
       
   321         credentialsInd--;
       
   322         }
       
   323     
       
   324     if ( !existingCredentialsFound )
       
   325         {
       
   326         CNATFWCredentials* newItem 
       
   327             = CNATFWCredentials::NewLC( aCredentials );
       
   328         UpdateUserNamesL( *newItem );
       
   329         iCredentialsList.AppendL( newItem );
       
   330         CleanupStack::Pop( newItem );
       
   331         }
       
   332     }
       
   333 
       
   334 
       
   335 // ---------------------------------------------------------------------------
       
   336 // CIceSessionData::Credentials
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 const RPointerArray<CNATFWCredentials>&
       
   340     CIceSessionData::Credentials() const
       
   341     {
       
   342     return iCredentialsList;
       
   343     }
       
   344 
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // CIceSessionData::Credentials
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 const CNATFWCredentials* CIceSessionData::Credentials( 
       
   351         TUint aStreamId,
       
   352         CNATFWCredentials::TUtilizationDirection aDirection ) const
       
   353     {
       
   354     TInt count( iCredentialsList.Count() );
       
   355     for ( TInt i( 0 ); i < count; ++i )
       
   356         {
       
   357         if ( iCredentialsList[i]->StreamId() == aStreamId
       
   358             && iCredentialsList[i]->Direction() == aDirection )
       
   359             {
       
   360             return iCredentialsList[i];
       
   361             }
       
   362         }
       
   363     
       
   364     return NULL;
       
   365     }
       
   366 
       
   367 
       
   368 // ---------------------------------------------------------------------------
       
   369 // CIceSessionData::AddLocalCandidateL
       
   370 // ---------------------------------------------------------------------------
       
   371 //       
       
   372 TBool CIceSessionData::AddLocalCandidateL(
       
   373         CNATFWCandidate* aLocalCandidate )
       
   374     {
       
   375     __ICEDP( "CIceSessionData::AddLocalCandidateL" )
       
   376     __ASSERT_DEBUG( aLocalCandidate, User::Leave( KErrArgument ) );
       
   377     
       
   378     CleanupStack::PushL( aLocalCandidate );
       
   379     TBool redundantCand 
       
   380         = IsRedundantCandidate( *aLocalCandidate, iLocalCandidateList );
       
   381     
       
   382     if ( !redundantCand )
       
   383         {
       
   384         AssignFoundationForCandidateL( *aLocalCandidate );
       
   385         iLocalCandidateList.AppendL( aLocalCandidate );
       
   386         CleanupStack::Pop( aLocalCandidate );
       
   387         }
       
   388     else
       
   389         {
       
   390         CleanupStack::PopAndDestroy( aLocalCandidate );
       
   391         }
       
   392     
       
   393     return redundantCand;
       
   394     }
       
   395 
       
   396 
       
   397 // ---------------------------------------------------------------------------
       
   398 // CIceSessionData::AddRemoteCandidateL
       
   399 // ---------------------------------------------------------------------------
       
   400 //       
       
   401 void CIceSessionData::AddRemoteCandidateL( CNATFWCandidate* aRemoteCandidate )
       
   402     {
       
   403     __ICEDP( "CIceSessionData::AddRemoteCandidateL" )
       
   404     CleanupStack::PushL( aRemoteCandidate );
       
   405     __ASSERT_DEBUG( NULL != aRemoteCandidate, User::Leave( KErrArgument ) );
       
   406     
       
   407     if ( IsRedundantCandidate( *aRemoteCandidate, iRemoteCandidateList ) )
       
   408         {
       
   409         CleanupStack::PopAndDestroy( aRemoteCandidate );
       
   410         }
       
   411     else
       
   412         {
       
   413         iRemoteCandidateList.AppendL( aRemoteCandidate );
       
   414         CleanupStack::Pop( aRemoteCandidate );
       
   415         }
       
   416     }
       
   417 
       
   418 
       
   419 // ---------------------------------------------------------------------------
       
   420 // CIceSessionData::AddRemoteCandidatesL
       
   421 // ---------------------------------------------------------------------------
       
   422 //               
       
   423 void CIceSessionData::AddRemoteCandidatesL( 
       
   424         RPointerArray<CNATFWCandidate>& aRemoteCandidates )
       
   425     {
       
   426     TInt numOfCandidates = aRemoteCandidates.Count();
       
   427     __ICEDP_INT1( "CIceSessionData::AddRemoteCandidatesL, COUNT:",
       
   428          numOfCandidates )
       
   429     __ASSERT_ALWAYS( 0 != numOfCandidates, User::Leave( KErrArgument ) );
       
   430     
       
   431     // check that there is not redundancy in input array
       
   432     RPointerArray<CNATFWCandidate> candidatesToComp;
       
   433     CleanupClosePushL( candidatesToComp );
       
   434     
       
   435     for ( TInt i(0); i < numOfCandidates; ++i )
       
   436         {
       
   437         candidatesToComp.AppendL( aRemoteCandidates[i] );
       
   438         }
       
   439     
       
   440     for ( TInt i(0); i < numOfCandidates; ++i )
       
   441         {
       
   442         candidatesToComp.Remove(0);
       
   443         
       
   444         if ( IsRedundantCandidate( *aRemoteCandidates[i], candidatesToComp ) )
       
   445             {
       
   446             __ICEDP( "CIceSessionData::AddRemoteCandidatesL, REDUNDANT" )
       
   447             User::Leave( KErrArgument );
       
   448             }
       
   449         }
       
   450     CleanupStack::PopAndDestroy( &candidatesToComp );
       
   451     
       
   452     // add previously unknown candidates to the list
       
   453     for ( TInt i(0); i < numOfCandidates; ++i )
       
   454         {
       
   455         if ( !IsRedundantCandidate( 
       
   456                 *aRemoteCandidates[i], iRemoteCandidateList ) )
       
   457             {
       
   458             CNATFWCandidate* candidate 
       
   459                 = CNATFWCandidate::NewLC( *aRemoteCandidates[i] );
       
   460             iRemoteCandidateList.AppendL( candidate );
       
   461             CleanupStack::Pop( candidate );
       
   462             }
       
   463         }
       
   464     }
       
   465 
       
   466 // ---------------------------------------------------------------------------
       
   467 // CIceSessionData::GetRemoteCandidatesL
       
   468 // ---------------------------------------------------------------------------
       
   469 //         
       
   470 void CIceSessionData::GetRemoteCandidatesL( 
       
   471         const TUint aStreamCollectionId,
       
   472         RPointerArray<CNATFWCandidate>& aRemoteCandidates )
       
   473     {
       
   474     __ICEDP( "CIceSessionData::GetRemoteCandidatesL" )
       
   475 
       
   476     TInt counter = iRemoteCandidateList.Count();
       
   477     for ( TInt i = 0; i < counter; ++i )
       
   478         {
       
   479         if ( iRemoteCandidateList[i]->StreamCollectionId() 
       
   480                 == aStreamCollectionId )
       
   481             {
       
   482             aRemoteCandidates.AppendL( iRemoteCandidateList[i] );
       
   483             }
       
   484         }
       
   485     }
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 // CIceSessionData::GetRemoteCandidatesL
       
   489 // ---------------------------------------------------------------------------
       
   490 //         
       
   491 void CIceSessionData::GetRemoteCandidatesL( 
       
   492                 const TUint aStreamCollectionId,
       
   493                 const TUint aComponentId,
       
   494                 RPointerArray<CNATFWCandidate>& aRemoteCandidates )
       
   495                 
       
   496     {
       
   497     __ICEDP( "CIceSessionData::GetRemoteCandidatesL" )
       
   498     
       
   499     TInt count = iRemoteCandidateList.Count();
       
   500     for ( TInt i = 0; i < count;i++ )
       
   501         {
       
   502         if ( iRemoteCandidateList[i]->StreamCollectionId() 
       
   503                 == aStreamCollectionId && 
       
   504             iRemoteCandidateList[i]->ComponentId() == aComponentId )
       
   505             {
       
   506             aRemoteCandidates.AppendL( iRemoteCandidateList[i] );
       
   507             }
       
   508         }
       
   509     }
       
   510 
       
   511 
       
   512 // ---------------------------------------------------------------------------
       
   513 // CIceSessionData::GetStreamCollectionIdsL
       
   514 // ---------------------------------------------------------------------------
       
   515 //
       
   516 void CIceSessionData::GetStreamCollectionIdsL( 
       
   517         RArray<TUint>& aStreamCollIds ) const
       
   518     {
       
   519     __ICEDP( "CIceSessionData::GetStreamCollectionIdsL" )
       
   520     
       
   521     TInt count = iStreamCollections.Count();
       
   522     for ( TInt i = 0; i < count; i++ )
       
   523          {
       
   524          aStreamCollIds.AppendL( 
       
   525             iStreamCollections[i]->StreamCollectionId() );
       
   526          }
       
   527     }
       
   528 
       
   529 
       
   530 // ---------------------------------------------------------------------------
       
   531 // CIceSessionData::CreateCollectionL
       
   532 // ---------------------------------------------------------------------------
       
   533 //    
       
   534 void CIceSessionData::CreateCollectionL( TUint aStreamCollectionId )
       
   535     {
       
   536     __ICEDP( "CIceSessionData::CreateCollectionL" )
       
   537 
       
   538     CIceStreamCollection* collection 
       
   539         = FindStreamCollectionById( aStreamCollectionId );
       
   540     
       
   541     if ( !collection )
       
   542         {
       
   543         CIceStreamCollection* newCollection 
       
   544             = CIceStreamCollection::NewLC( aStreamCollectionId );
       
   545         iStreamCollections.AppendL( newCollection );
       
   546         CleanupStack::Pop( newCollection );
       
   547         }
       
   548     }
       
   549 
       
   550 
       
   551 // ---------------------------------------------------------------------------
       
   552 // CIceSessionData::CollectionL
       
   553 // ---------------------------------------------------------------------------
       
   554 //
       
   555 CIceStreamCollection* CIceSessionData::CollectionL( 
       
   556         TUint aStreamCollectionId )
       
   557     {
       
   558     CIceStreamCollection* collection 
       
   559         = FindStreamCollectionById( aStreamCollectionId );
       
   560     __ASSERT_DEBUG( collection, User::Leave( KErrNotFound ) );
       
   561     
       
   562     return collection;
       
   563     }
       
   564 
       
   565 
       
   566 // ---------------------------------------------------------------------------
       
   567 // CIceSessionData::GetCollectionIdForComponent
       
   568 // ---------------------------------------------------------------------------
       
   569 //
       
   570 TInt CIceSessionData::GetCollectionIdForComponent( 
       
   571         TUint aStreamId, TUint& aCollectionId )
       
   572     {
       
   573     TInt count( iStreamCollections.Count() );
       
   574     
       
   575     for ( TInt i( 0 ); i < count; ++i )
       
   576         {
       
   577         if ( iStreamCollections[i]->HasMediaComponent( aStreamId ) )
       
   578             {
       
   579             aCollectionId = iStreamCollections[i]->StreamCollectionId();
       
   580             return KErrNone;
       
   581             }
       
   582         }
       
   583     
       
   584     return KErrNotFound;
       
   585     }
       
   586 
       
   587 
       
   588 // ---------------------------------------------------------------------------
       
   589 // CIceSessionData::CleanupStreamData
       
   590 // ---------------------------------------------------------------------------
       
   591 //
       
   592 void CIceSessionData::CleanupStreamData( TUint aStreamId )
       
   593     {
       
   594     __ICEDP( "CIceSessionData::CleanupStreamData" )
       
   595     
       
   596     for ( TInt i( iCredentialsList.Count() - 1 ); i >= 0; --i )
       
   597         {
       
   598         if ( iCredentialsList[i]->StreamId() == aStreamId )
       
   599             {
       
   600             delete iCredentialsList[i];
       
   601             iCredentialsList.Remove( i );
       
   602             }
       
   603         }
       
   604     
       
   605     for ( TInt i( iLocalCandidateList.Count() - 1 ); i >= 0; --i )
       
   606         {
       
   607         if ( iLocalCandidateList[i]->StreamId() == aStreamId )
       
   608             {
       
   609             delete iLocalCandidateList[i];
       
   610             iLocalCandidateList.Remove( i );
       
   611             }
       
   612         }
       
   613     
       
   614     for ( TInt i( iRemoteCandidateList.Count() - 1 ); i >= 0; --i )
       
   615         {
       
   616         if ( iRemoteCandidateList[i]->StreamId() == aStreamId )
       
   617             {
       
   618             delete iRemoteCandidateList[i];
       
   619             iRemoteCandidateList.Remove( i );
       
   620             }
       
   621         }
       
   622     
       
   623     CIceStreamCollection* collection( NULL );
       
   624     for ( TInt i( iStreamCollections.Count() - 1 ); i >= 0; --i )
       
   625         {
       
   626         collection = iStreamCollections[i];
       
   627         if ( collection->HasMediaComponent( aStreamId ) )
       
   628             {
       
   629             collection->RemoveMediaComponent( aStreamId );
       
   630             }
       
   631         }
       
   632     }
       
   633 
       
   634 
       
   635 // ---------------------------------------------------------------------------
       
   636 // CIceSessionData::RemoveLocalCandidates
       
   637 // ---------------------------------------------------------------------------
       
   638 //
       
   639 void CIceSessionData::RemoveLocalCandidates()
       
   640     {
       
   641     __ICEDP( "CIceSessionData::RemoveLocalCandidates" )
       
   642     
       
   643     iLocalCandidateList.ResetAndDestroy();
       
   644     }
       
   645  
       
   646  
       
   647 // ---------------------------------------------------------------------------
       
   648 // CIceSessionData::RemoveRemoteCandidates
       
   649 // ---------------------------------------------------------------------------
       
   650 //
       
   651 void CIceSessionData::RemoveRemoteCandidates()
       
   652     {
       
   653     __ICEDP( "CIceSessionData::RemoveRemoteCandidates" )
       
   654     
       
   655     iRemoteCandidateList.ResetAndDestroy();
       
   656     }
       
   657 
       
   658 
       
   659 // ---------------------------------------------------------------------------
       
   660 // CIceSessionData::SetRole
       
   661 // ---------------------------------------------------------------------------
       
   662 //
       
   663 void CIceSessionData::SetRole( TNATFWIceRole aRole )
       
   664     {
       
   665     __ICEDP( "CIceSessionData::SetRole" )
       
   666     ASSERT( EIceRoleControlling == aRole || EIceRoleControlled == aRole );
       
   667     
       
   668     iRole = aRole;
       
   669     }
       
   670 
       
   671 
       
   672 // ---------------------------------------------------------------------------
       
   673 // CIceSessionData::Role
       
   674 // ---------------------------------------------------------------------------
       
   675 //
       
   676 TNATFWIceRole CIceSessionData::Role() const
       
   677     {
       
   678     __ICEDP( "CIceSessionData::Role" )
       
   679     
       
   680     return iRole;
       
   681     }
       
   682 
       
   683 
       
   684 // ---------------------------------------------------------------------------
       
   685 // CIceSessionData::SetTieBreaker
       
   686 // ---------------------------------------------------------------------------
       
   687 //
       
   688 void CIceSessionData::SetTieBreaker( TUint64 aTieBreaker )
       
   689     {
       
   690     iTieBreaker = aTieBreaker;
       
   691     }
       
   692 
       
   693 
       
   694 // ---------------------------------------------------------------------------
       
   695 // CIceSessionData::TieBreaker
       
   696 // ---------------------------------------------------------------------------
       
   697 //
       
   698 TUint64 CIceSessionData::TieBreaker() const
       
   699     {
       
   700     __ICEDP( "CIceSessionData::TieBreaker" )
       
   701     
       
   702     return iTieBreaker;
       
   703     }
       
   704 
       
   705 
       
   706 // ---------------------------------------------------------------------------
       
   707 // CIceSessionData::Domain
       
   708 // ---------------------------------------------------------------------------
       
   709 //
       
   710 const TDesC8& CIceSessionData::Domain() const
       
   711     {
       
   712     return *iDomain;
       
   713     }
       
   714 
       
   715 
       
   716 // ---------------------------------------------------------------------------
       
   717 // CIceSessionData::IapId
       
   718 // ---------------------------------------------------------------------------
       
   719 //
       
   720 TUint32 CIceSessionData::IapId() const
       
   721     {
       
   722     return iIapId;
       
   723     }
       
   724 
       
   725 
       
   726 // ---------------------------------------------------------------------------
       
   727 // CIceSessionData::SetTaTimerValue
       
   728 // ---------------------------------------------------------------------------
       
   729 //
       
   730 void CIceSessionData::SetTaTimerValue( TUint aTaTimerValue )
       
   731     {
       
   732     ASSERT( aTaTimerValue != 0 );
       
   733     
       
   734     iTaTimerValue = aTaTimerValue;
       
   735     }
       
   736 
       
   737 
       
   738 // ---------------------------------------------------------------------------
       
   739 // CIceSessionData::TaTimerValue
       
   740 // ---------------------------------------------------------------------------
       
   741 //
       
   742 TUint CIceSessionData::TaTimerValue() const
       
   743     {
       
   744     ASSERT( iTaTimerValue != 0 );
       
   745     
       
   746     return iTaTimerValue;
       
   747     }
       
   748 
       
   749 
       
   750 // ---------------------------------------------------------------------------
       
   751 // CIceSessionData::IsRedundantCandidate
       
   752 // ---------------------------------------------------------------------------
       
   753 //
       
   754 TBool CIceSessionData::IsRedundantCandidate( 
       
   755         const CNATFWCandidate& aCandidate,
       
   756         const RPointerArray<CNATFWCandidate>& aCandidateArray ) const
       
   757     {
       
   758     __ICEDP( "CIceSessionData::IsRedundantCandidate" )
       
   759     
       
   760     TInt ind = aCandidateArray.Count();
       
   761     
       
   762     while ( ind-- )
       
   763         {
       
   764         CNATFWCandidate* cToComp( aCandidateArray[ind] );
       
   765         
       
   766         if ( TIceUtils::MatchAddresses( 
       
   767                 aCandidate.TransportAddr(), cToComp->TransportAddr() ) &&
       
   768              TIceUtils::MatchAddresses( 
       
   769                 aCandidate.Base(), cToComp->Base() ) )
       
   770             {
       
   771             return ETrue;
       
   772             }
       
   773         }
       
   774     
       
   775     return EFalse;    
       
   776     }
       
   777 
       
   778 
       
   779 // ---------------------------------------------------------------------------
       
   780 // CIceSessionData::AssignFoundationForCandidateL
       
   781 // Assigns foundation for local candidate.
       
   782 // ---------------------------------------------------------------------------
       
   783 //
       
   784 void CIceSessionData::AssignFoundationForCandidateL( 
       
   785         CNATFWCandidate& aCandidate )
       
   786     {
       
   787     __ICEDP( "CIceSessionData::AssignFoundationForCandidateL" )
       
   788     
       
   789     TInt ind = iLocalCandidateList.Count();
       
   790     
       
   791     while ( ind-- )
       
   792         {
       
   793         CNATFWCandidate* candToCompare( iLocalCandidateList[ind] );
       
   794         
       
   795         if ( aCandidate.Type() == candToCompare->Type() && 
       
   796              aCandidate.Base().Match( candToCompare->Base() ) &&
       
   797              aCandidate.TransportProtocol() 
       
   798                 == candToCompare->TransportProtocol() )
       
   799             {
       
   800             aCandidate.SetFoundationL( candToCompare->Foundation() );
       
   801             return;
       
   802             }
       
   803         }
       
   804     
       
   805     const TDesC8& foundation = GenerateRandomIdentifier();
       
   806     aCandidate.SetFoundationL( foundation );
       
   807     }
       
   808 
       
   809 
       
   810 // ---------------------------------------------------------------------------
       
   811 // CIceSessionData::FindStreamCollectionById
       
   812 // ---------------------------------------------------------------------------
       
   813 //
       
   814 CIceStreamCollection* 
       
   815     CIceSessionData::FindStreamCollectionById( TUint aCollectionId )
       
   816     {
       
   817     TInt ind( iStreamCollections.Count() );
       
   818     while ( ind-- )
       
   819         {
       
   820         if ( iStreamCollections[ind]->StreamCollectionId() == aCollectionId )
       
   821             {
       
   822             return iStreamCollections[ind];
       
   823             }
       
   824         }
       
   825     
       
   826     return NULL;
       
   827     }
       
   828 
       
   829 
       
   830 // ---------------------------------------------------------------------------
       
   831 // CIceSessionData::GenerateRandomIdentifier
       
   832 // ---------------------------------------------------------------------------
       
   833 //
       
   834 const TDesC8& CIceSessionData::GenerateRandomIdentifier()
       
   835     {
       
   836     TUint32 randomNum = TUint32( Math::Random() + TUint32( Math::Random() ) );
       
   837     _LIT8( KFormatString, "%u" );
       
   838     iTempIdentifier.Format( KFormatString, randomNum );
       
   839     return iTempIdentifier;
       
   840     }
       
   841 
       
   842 
       
   843 // ---------------------------------------------------------------------------
       
   844 // CIceSessionData::UpdateUserNamesL
       
   845 // Both inbound & outbound credentials are always updated.
       
   846 // ---------------------------------------------------------------------------
       
   847 //
       
   848 void CIceSessionData::UpdateUserNamesL( 
       
   849         CNATFWCredentials& aCredentials )
       
   850     {
       
   851     CNATFWCredentials::TUtilizationDirection direction =
       
   852         CNATFWCredentials::EInbound == aCredentials.Direction()
       
   853         ? CNATFWCredentials::EOutbound
       
   854         : CNATFWCredentials::EInbound;
       
   855     
       
   856     const CNATFWCredentials* counterpart 
       
   857         = Credentials( aCredentials.StreamId(), direction );
       
   858     
       
   859     if ( counterpart )
       
   860         {
       
   861         // Complete credentials with username of its counterpart
       
   862         RBuf8 newUserName;
       
   863         CleanupClosePushL( newUserName );
       
   864         newUserName.CreateL( aCredentials.Username().Size() 
       
   865             + counterpart->Username().Size()
       
   866             + KColon().Size() );
       
   867         
       
   868         TInt ind = aCredentials.Username().Find( KColon );
       
   869         KErrNotFound == ind 
       
   870             ? ind = aCredentials.Username().Size() : ind = ind;
       
   871         newUserName.Append( aCredentials.Username().Left( ind ) );
       
   872         newUserName.Append( KColon() );
       
   873         
       
   874         ind = counterpart->Username().Find( KColon() );
       
   875         KErrNotFound == ind 
       
   876             ? ind = counterpart->Username().Size() : ind = ind;
       
   877         newUserName.Append( counterpart->Username().Left( ind ) );
       
   878         aCredentials.SetUsernameL( newUserName );
       
   879         
       
   880         // Update also username of counterpart
       
   881         newUserName.Zero();
       
   882         ind = counterpart->Username().Find( KColon );
       
   883         KErrNotFound == ind 
       
   884             ? ind = counterpart->Username().Size() : ind = ind;
       
   885         newUserName.Append( counterpart->Username().Left( ind ) );
       
   886         newUserName.Append( KColon() );
       
   887 
       
   888         ind = aCredentials.Username().Find( KColon() );
       
   889         KErrNotFound == ind 
       
   890             ? ind = aCredentials.Username().Size() : ind = ind;
       
   891         newUserName.Append( aCredentials.Username().Left( ind ) );
       
   892         const_cast<CNATFWCredentials*>( counterpart )
       
   893             ->SetUsernameL( newUserName );
       
   894         
       
   895         CleanupStack::PopAndDestroy( &newUserName );
       
   896         }
       
   897     }