mmsharing/mmshavailability/tsrc/ut_availability/src/musavacapabilitytesthelper.cpp
changeset 22 496ad160a278
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Capability Test helper
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "musavacapabilitytesthelper.h"
       
    20 
       
    21 
       
    22 
       
    23 CSIPServerTransaction* CapabilityTestHelper::OptionsRequestL( 
       
    24                                            const TDesC8& aRequestUri,
       
    25                                            const TDesC8& aFrom,
       
    26                                            const TDesC8& aAcceptContact, 
       
    27                                            const TDesC8& aContact,
       
    28                                            const TDesC8& aAccept,
       
    29                                            const TDesC8& aUserAgent )
       
    30     {
       
    31     
       
    32     CSIPServerTransaction* srvtransaction = 
       
    33         CSIPServerTransaction::NewL( SIPStrings::StringF( SipStrConsts::EOptions )); 
       
    34     CleanupStack::PushL( srvtransaction );
       
    35     
       
    36     TUriParser8 Uri;
       
    37     User::LeaveIfError( Uri.Parse( aRequestUri ) );
       
    38     
       
    39   	CUri8* uri = CUri8::NewLC( Uri );
       
    40   	
       
    41     CSIPRequestElements* requestelements = CSIPRequestElements::NewL( uri ); 
       
    42     CleanupStack::Pop( uri );
       
    43     CleanupStack::PushL( requestelements );
       
    44 
       
    45 //headers
       
    46 
       
    47     RPointerArray<CSIPHeaderBase> sipHdrs;
       
    48     CSIPHeaderBase::PushLC( &sipHdrs );
       
    49 
       
    50     if ( aAcceptContact.Length() > 0 )
       
    51         {
       
    52         
       
    53         RStringF value = MusAvaCapabilityContext::SIPStringL( aAcceptContact );
       
    54         CleanupClosePushL( value );
       
    55         
       
    56         CSIPAcceptContactHeader* acceptContact = 
       
    57             MusAvaCapabilityContext::AcceptContactHeaderLC( value );
       
    58         sipHdrs.AppendL( acceptContact );
       
    59         CleanupStack::Pop( acceptContact );
       
    60         
       
    61         CleanupStack::PopAndDestroy();//value
       
    62         
       
    63         }
       
    64         
       
    65     if ( aAccept.Length() > 0 )
       
    66         {
       
    67         CSIPAcceptHeader* accept = 
       
    68             CSIPAcceptHeader::NewLC( KMUSAVASIPMediaTypeApplication, 
       
    69                             KMUSAVASIPMediaSubTypeSDP );
       
    70         sipHdrs.AppendL( accept );
       
    71         CleanupStack::Pop( accept );
       
    72         }
       
    73         
       
    74     if ( aContact.Length() > 0 )
       
    75         {
       
    76         RStringF value = MusAvaCapabilityContext::SIPStringL( aContact );
       
    77         CleanupClosePushL( value );
       
    78         
       
    79         TUriParser8 uriValue;
       
    80         User::LeaveIfError( uriValue.Parse( aFrom ) );
       
    81         CUri8* uri = CUri8::NewLC( uriValue );
       
    82         
       
    83         CSIPContactHeader* contact = 
       
    84             MusAvaCapabilityContext::ContactHeaderLC( *uri, value );
       
    85         sipHdrs.AppendL( contact );
       
    86         CleanupStack::Pop( contact );
       
    87         CleanupStack::PopAndDestroy( uri );
       
    88 
       
    89         CleanupStack::PopAndDestroy();//value
       
    90         
       
    91         }
       
    92         
       
    93     if ( aUserAgent.Length() > 0 )
       
    94         {
       
    95         
       
    96         CSIPExtensionHeader* userAgent = 
       
    97             MusAvaCapabilityContext::UserAgentHeaderLC( aUserAgent );
       
    98         sipHdrs.AppendL( userAgent );
       
    99         CleanupStack::Pop( userAgent );
       
   100         }
       
   101         
       
   102     requestelements->MessageElements().SetUserHeadersL( sipHdrs );
       
   103     CleanupStack::PopAndDestroy( &sipHdrs );
       
   104     
       
   105 //to, from
       
   106 
       
   107     CSIPToHeader* toheader = CSIPToHeader::DecodeL( aRequestUri );
       
   108     CleanupStack::PushL( toheader );
       
   109     CSIPFromHeader* fromheader = CSIPFromHeader::DecodeL( aFrom ); 
       
   110     CleanupStack::PushL( fromheader );
       
   111     
       
   112     requestelements->SetFromHeaderL(fromheader); 
       
   113     CleanupStack::Pop( fromheader );
       
   114     requestelements->SetToHeaderL(toheader); 
       
   115     CleanupStack::Pop( toheader );
       
   116 
       
   117     
       
   118     requestelements->SetMethodL( SIPStrings::StringF( SipStrConsts::EOptions ) );
       
   119     
       
   120     srvtransaction->SetRequestElements( requestelements );
       
   121     CleanupStack::Pop( requestelements );
       
   122     CleanupStack::Pop( srvtransaction );
       
   123 
       
   124     return srvtransaction;
       
   125     
       
   126     }
       
   127 
       
   128 
       
   129 CSIPServerTransaction* CapabilityTestHelper::OptionsRequestL( 
       
   130                                            const TDesC8& aRequestUri,
       
   131                                            const TDesC8& aFrom,
       
   132                                            const TDesC8& aAcceptContact, 
       
   133                                            const TDesC8& aContact,
       
   134                                            const TDesC8& aAccept,
       
   135                                            const TDesC8& aUserAgent,
       
   136                                            const TDesC8& aAssertId )
       
   137     {
       
   138     
       
   139     CSIPServerTransaction* srvtransaction = 
       
   140         CSIPServerTransaction::NewL( SIPStrings::StringF( SipStrConsts::EOptions )); 
       
   141     CleanupStack::PushL( srvtransaction );
       
   142     
       
   143     TUriParser8 Uri;
       
   144     User::LeaveIfError( Uri.Parse( aRequestUri ) );
       
   145     
       
   146   	CUri8* uri = CUri8::NewLC( Uri );
       
   147   	
       
   148     CSIPRequestElements* requestelements = CSIPRequestElements::NewL( uri ); 
       
   149     CleanupStack::Pop( uri );
       
   150     CleanupStack::PushL( requestelements );
       
   151 
       
   152 //headers
       
   153 
       
   154     RPointerArray<CSIPHeaderBase> sipHdrs;
       
   155     CSIPHeaderBase::PushLC( &sipHdrs );
       
   156 
       
   157     if ( aAcceptContact.Length() > 0 )
       
   158         {
       
   159         
       
   160         RStringF value = MusAvaCapabilityContext::SIPStringL( aAcceptContact );
       
   161         CleanupClosePushL( value );
       
   162         
       
   163         CSIPAcceptContactHeader* acceptContact = 
       
   164             MusAvaCapabilityContext::AcceptContactHeaderLC( value );
       
   165         sipHdrs.AppendL( acceptContact );
       
   166         CleanupStack::Pop( acceptContact );
       
   167         
       
   168         CleanupStack::PopAndDestroy();//value
       
   169         
       
   170         }
       
   171         
       
   172     if ( aAccept.Length() > 0 )
       
   173         {
       
   174         CSIPAcceptHeader* accept = 
       
   175             CSIPAcceptHeader::NewLC( KMUSAVASIPMediaTypeApplication, 
       
   176                             KMUSAVASIPMediaSubTypeSDP );
       
   177         sipHdrs.AppendL( accept );
       
   178         CleanupStack::Pop( accept );
       
   179         }
       
   180         
       
   181     if ( aContact.Length() > 0 )
       
   182         {
       
   183         RStringF value = MusAvaCapabilityContext::SIPStringL( aContact );
       
   184         CleanupClosePushL( value );
       
   185         
       
   186         TUriParser8 uriValue;
       
   187         User::LeaveIfError( uriValue.Parse( aFrom ) );
       
   188         CUri8* uri = CUri8::NewLC( uriValue );
       
   189         
       
   190         CSIPContactHeader* contact = 
       
   191             MusAvaCapabilityContext::ContactHeaderLC( *uri, value );
       
   192         sipHdrs.AppendL( contact );
       
   193         CleanupStack::Pop( contact );
       
   194         CleanupStack::PopAndDestroy( uri );
       
   195 
       
   196         CleanupStack::PopAndDestroy();//value
       
   197         
       
   198         }
       
   199         
       
   200     if ( aUserAgent.Length() > 0 )
       
   201         {
       
   202         
       
   203         CSIPExtensionHeader* userAgent = 
       
   204             MusAvaCapabilityContext::UserAgentHeaderLC( aUserAgent );
       
   205         sipHdrs.AppendL( userAgent );
       
   206         CleanupStack::Pop( userAgent );
       
   207         }
       
   208 
       
   209      if ( aAssertId.Length() > 0 )
       
   210         {
       
   211         
       
   212         CSIPExtensionHeader* assertId = 
       
   213             MusAvaCapabilityContext::PAssertedIdentityHeaderLC( aAssertId );
       
   214         sipHdrs.AppendL( assertId );
       
   215         CleanupStack::Pop( assertId );
       
   216         }
       
   217         
       
   218     requestelements->MessageElements().SetUserHeadersL( sipHdrs );
       
   219     CleanupStack::PopAndDestroy( &sipHdrs );
       
   220     
       
   221 //to, from
       
   222 
       
   223     CSIPToHeader* toheader = CSIPToHeader::DecodeL( aRequestUri );
       
   224     CleanupStack::PushL( toheader );
       
   225     CSIPFromHeader* fromheader = CSIPFromHeader::DecodeL( aFrom ); 
       
   226     CleanupStack::PushL( fromheader );
       
   227     
       
   228     requestelements->SetFromHeaderL(fromheader); 
       
   229     CleanupStack::Pop( fromheader );
       
   230     requestelements->SetToHeaderL(toheader); 
       
   231     CleanupStack::Pop( toheader );
       
   232 
       
   233     
       
   234     requestelements->SetMethodL( SIPStrings::StringF( SipStrConsts::EOptions ) );
       
   235     
       
   236     srvtransaction->SetRequestElements( requestelements );
       
   237     CleanupStack::Pop( requestelements );
       
   238     CleanupStack::Pop( srvtransaction );
       
   239 
       
   240     return srvtransaction;
       
   241     
       
   242     }
       
   243 CSIPClientTransaction* CapabilityTestHelper::OptionsResponseL( TUint aResponse,
       
   244                                             TInt aPhrase,
       
   245                                             const TDesC8& aFrom,
       
   246                                             const TDesC8& aContact,
       
   247                                             const TDesC8& aUserAgent,
       
   248                                             const TDesC8& aPAssertedId,
       
   249                                             const TDesC8& aSdp )
       
   250     {
       
   251         
       
   252     CSIPClientTransaction* clitransaction = 
       
   253       CSIPClientTransaction::NewL( SIPStrings::StringF( SipStrConsts::EOptions ));
       
   254     CleanupStack::PushL( clitransaction );
       
   255     
       
   256     SetResponseL( *clitransaction, aResponse, aPhrase, aFrom, aContact, 
       
   257                 aUserAgent, aPAssertedId, aSdp );
       
   258 
       
   259     CleanupStack::Pop( clitransaction );
       
   260     
       
   261     return clitransaction;
       
   262     
       
   263     
       
   264     }
       
   265 
       
   266 
       
   267 void CapabilityTestHelper::SetResponseL( CSIPClientTransaction& aTrx,
       
   268                                    TUint aResponse, 
       
   269                                    TInt aPhrase,
       
   270                                    const TDesC8& aFrom,
       
   271                                    const TDesC8& aContact,
       
   272                                    const TDesC8& aUserAgent,
       
   273                                    const TDesC8& aPAssertedId,
       
   274                                    const TDesC8& aSdp,
       
   275                                    const TDesC8& aContentType )
       
   276     {
       
   277 
       
   278     CSIPResponseElements* response = 
       
   279         CSIPResponseElements::NewLC( aResponse, 
       
   280                                      SIPStrings::StringF( aPhrase ) );
       
   281 
       
   282     CSIPMessageElements& message = response->MessageElements();
       
   283     
       
   284 //headers
       
   285 
       
   286     RPointerArray<CSIPHeaderBase> sipHdrs;
       
   287     CSIPHeaderBase::PushLC( &sipHdrs );
       
   288 
       
   289     if ( aContact.Length() > 0 )
       
   290         {
       
   291 
       
   292         RStringF value = MusAvaCapabilityContext::SIPStringL( aContact );
       
   293         CleanupClosePushL( value );
       
   294         
       
   295         TUriParser8 uriValue;
       
   296         User::LeaveIfError( uriValue.Parse( aFrom ) );
       
   297         CUri8* uri = CUri8::NewLC( uriValue );
       
   298         
       
   299         CSIPContactHeader* contact = 
       
   300             MusAvaCapabilityContext::ContactHeaderLC( *uri, value );
       
   301         sipHdrs.AppendL( contact );
       
   302         CleanupStack::Pop( contact );
       
   303         CleanupStack::PopAndDestroy( uri );
       
   304         CleanupStack::PopAndDestroy();//value
       
   305         
       
   306         }
       
   307         
       
   308     if ( aUserAgent.Length() > 0 )
       
   309         {
       
   310         
       
   311         CSIPExtensionHeader* userAgent = 
       
   312             MusAvaCapabilityContext::UserAgentHeaderLC( aUserAgent );
       
   313         sipHdrs.AppendL( userAgent );
       
   314         CleanupStack::Pop( userAgent );
       
   315         }
       
   316         
       
   317     if ( aPAssertedId.Length() > 0 )
       
   318         {
       
   319         
       
   320         CSIPExtensionHeader* pAssertedId = 
       
   321             MusAvaCapabilityContext::PAssertedIdentityHeaderLC( aPAssertedId );
       
   322         sipHdrs.AppendL( pAssertedId );
       
   323         CleanupStack::Pop( pAssertedId );
       
   324         
       
   325         }
       
   326         
       
   327     message.SetUserHeadersL( sipHdrs );
       
   328     CleanupStack::PopAndDestroy( &sipHdrs );
       
   329 
       
   330     if ( aSdp.Length() > 0 )
       
   331         {
       
   332         CSIPContentTypeHeader* contenttype = NULL;
       
   333         if ( aContentType.Length() == 0 )
       
   334             {
       
   335             contenttype = 
       
   336             CSIPContentTypeHeader::NewLC( KMUSAVASIPMediaTypeApplication,
       
   337                                          KMUSAVASIPMediaSubTypeSDP );
       
   338             }
       
   339         else
       
   340             {
       
   341             contenttype = 
       
   342             CSIPContentTypeHeader::DecodeL( aContentType );
       
   343             CleanupStack::PushL( contenttype );
       
   344 
       
   345             }
       
   346         HBufC8* content = aSdp.AllocLC();
       
   347         
       
   348         message.SetContentL( content, contenttype );
       
   349         CleanupStack::Pop( content );
       
   350         CleanupStack::Pop( contenttype );
       
   351         
       
   352         }
       
   353         
       
   354     aTrx.SetResponseElements( response );
       
   355     CleanupStack::Pop( response );
       
   356     
       
   357     }
       
   358 
       
   359 void CapabilityTestHelper::SetResponse2L(CSIPClientTransaction& aTrx,
       
   360                                    TUint aResponse, 
       
   361                                    TInt aPhrase,
       
   362                                    const TDesC8& aFrom,
       
   363                                    const TDesC8& aContact,
       
   364                                    const TDesC8& aUserAgent,
       
   365                                    const TDesC8& aPAssertedId,
       
   366                                    const TDesC8& aPAssertedId2,
       
   367                                    const TDesC8& aSdp,
       
   368                                    const TDesC8& aContentType )  
       
   369     {
       
   370     CSIPResponseElements* response = 
       
   371         CSIPResponseElements::NewLC( aResponse, 
       
   372                                      SIPStrings::StringF( aPhrase ) );
       
   373 
       
   374     CSIPMessageElements& message = response->MessageElements();
       
   375     
       
   376 //headers
       
   377 
       
   378     RPointerArray<CSIPHeaderBase> sipHdrs;
       
   379     CSIPHeaderBase::PushLC( &sipHdrs );
       
   380 
       
   381     if ( aContact.Length() > 0 )
       
   382         {
       
   383 
       
   384         RStringF value = MusAvaCapabilityContext::SIPStringL( aContact );
       
   385         CleanupClosePushL( value );
       
   386         
       
   387         TUriParser8 uriValue;
       
   388         User::LeaveIfError( uriValue.Parse( aFrom ) );
       
   389         CUri8* uri = CUri8::NewLC( uriValue );
       
   390         
       
   391         CSIPContactHeader* contact = 
       
   392             MusAvaCapabilityContext::ContactHeaderLC( *uri, value );
       
   393         sipHdrs.AppendL( contact );
       
   394         CleanupStack::Pop( contact );
       
   395         CleanupStack::PopAndDestroy( uri );
       
   396         CleanupStack::PopAndDestroy();//value
       
   397         
       
   398         }
       
   399         
       
   400     if ( aUserAgent.Length() > 0 )
       
   401         {
       
   402         
       
   403         CSIPExtensionHeader* userAgent = 
       
   404             MusAvaCapabilityContext::UserAgentHeaderLC( aUserAgent );
       
   405         sipHdrs.AppendL( userAgent );
       
   406         CleanupStack::Pop( userAgent );
       
   407         }
       
   408         
       
   409     if ( aPAssertedId.Length() > 0 )
       
   410         {
       
   411         
       
   412         CSIPExtensionHeader* pAssertedId = 
       
   413             MusAvaCapabilityContext::PAssertedIdentityHeaderLC( aPAssertedId );
       
   414         sipHdrs.AppendL( pAssertedId );
       
   415         CleanupStack::Pop( pAssertedId );
       
   416         
       
   417         }
       
   418         
       
   419     if ( aPAssertedId2.Length() > 0 )
       
   420         {
       
   421         
       
   422         CSIPExtensionHeader* pAssertedId2 = 
       
   423             MusAvaCapabilityContext::PAssertedIdentityHeaderLC( aPAssertedId2 );
       
   424         sipHdrs.AppendL( pAssertedId2 );
       
   425         CleanupStack::Pop( pAssertedId2 );
       
   426         
       
   427         }
       
   428 
       
   429     message.SetUserHeadersL( sipHdrs );
       
   430     CleanupStack::PopAndDestroy( &sipHdrs );
       
   431 
       
   432     if ( aSdp.Length() > 0 )
       
   433         {
       
   434         CSIPContentTypeHeader* contenttype = NULL;
       
   435         if ( aContentType.Length() == 0 )
       
   436             {
       
   437             contenttype = 
       
   438             CSIPContentTypeHeader::NewLC( KMUSAVASIPMediaTypeApplication,
       
   439                                          KMUSAVASIPMediaSubTypeSDP );
       
   440             }
       
   441         else
       
   442             {
       
   443             contenttype = 
       
   444             CSIPContentTypeHeader::DecodeL( aContentType );
       
   445             CleanupStack::PushL( contenttype );
       
   446 
       
   447             }
       
   448         HBufC8* content = aSdp.AllocLC();
       
   449         
       
   450         message.SetContentL( content, contenttype );
       
   451         CleanupStack::Pop( content );
       
   452         CleanupStack::Pop( contenttype );
       
   453         
       
   454         }
       
   455         
       
   456     aTrx.SetResponseElements( response );
       
   457     CleanupStack::Pop( response );
       
   458     
       
   459     }
       
   460 
       
   461 CSIPAddress* HelpFlags::iTestSipAddress = NULL;
       
   462 TBool HelpFlags::iUseTestSipAddress = EFalse;
       
   463 TBool HelpFlags::iEmptyContactHeader = EFalse;
       
   464