mmsharing/mmshavailability/tsrc/ut_availability/src/musavacapabilitytesthelper.cpp
changeset 15 ccd8e69b5392
parent 2 b31261fd4e04
child 20 e8be2c2e049d
child 22 496ad160a278
equal deleted inserted replaced
2:b31261fd4e04 15:ccd8e69b5392
     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     requestelements->SetMethodL( SIPStrings::StringF( SipStrConsts::EOptions ) );
       
   118     
       
   119     srvtransaction->SetRequestElements( requestelements );
       
   120     CleanupStack::Pop( requestelements );
       
   121     CleanupStack::Pop( srvtransaction );
       
   122 
       
   123     return srvtransaction;
       
   124     
       
   125     }
       
   126 
       
   127 
       
   128 CSIPServerTransaction* CapabilityTestHelper::OptionsRequestL( 
       
   129                                            const TDesC8& aRequestUri,
       
   130                                            const TDesC8& aFrom,
       
   131                                            const TDesC8& aAcceptContact, 
       
   132                                            const TDesC8& aContact,
       
   133                                            const TDesC8& aAccept,
       
   134                                            const TDesC8& aUserAgent,
       
   135                                            const TDesC8& aAssertId,
       
   136                                            const TDesC8& aSdp)
       
   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     CSIPMessageElements& message = requestelements->MessageElements();
       
   237     if ( aSdp.Length() > 0 )
       
   238         {
       
   239         CSIPContentTypeHeader* contenttype = 
       
   240             CSIPContentTypeHeader::NewLC( KMUSAVASIPMediaTypeApplication,
       
   241                                          KMUSAVASIPMediaSubTypeSDP );
       
   242         HBufC8* content = aSdp.AllocLC();
       
   243         
       
   244         message.SetContentL( content, contenttype );
       
   245         CleanupStack::Pop( content );
       
   246         CleanupStack::Pop( contenttype );      
       
   247         }
       
   248     
       
   249     srvtransaction->SetRequestElements( requestelements );
       
   250     CleanupStack::Pop( requestelements );
       
   251     CleanupStack::Pop( srvtransaction );
       
   252 
       
   253     return srvtransaction;
       
   254     
       
   255     }
       
   256 CSIPClientTransaction* CapabilityTestHelper::OptionsResponseL( TUint aResponse,
       
   257                                             TInt aPhrase,
       
   258                                             const TDesC8& aFrom,
       
   259                                             const TDesC8& aContact,
       
   260                                             const TDesC8& aUserAgent,
       
   261                                             const TDesC8& aPAssertedId,
       
   262                                             const TDesC8& aSdp )
       
   263     {
       
   264         
       
   265     CSIPClientTransaction* clitransaction = 
       
   266       CSIPClientTransaction::NewL( SIPStrings::StringF( SipStrConsts::EOptions ));
       
   267     CleanupStack::PushL( clitransaction );
       
   268     
       
   269     SetResponseL( *clitransaction, aResponse, aPhrase, aFrom, aContact, 
       
   270                 aUserAgent, aPAssertedId, aSdp );
       
   271 
       
   272     CleanupStack::Pop( clitransaction );
       
   273     
       
   274     return clitransaction;
       
   275     
       
   276     
       
   277     }
       
   278 
       
   279 
       
   280 void CapabilityTestHelper::SetResponseL( CSIPClientTransaction& aTrx,
       
   281                                    TUint aResponse, 
       
   282                                    TInt aPhrase,
       
   283                                    const TDesC8& aFrom,
       
   284                                    const TDesC8& aContact,
       
   285                                    const TDesC8& aUserAgent,
       
   286                                    const TDesC8& aPAssertedId,
       
   287                                    const TDesC8& aSdp,
       
   288                                    const TDesC8& aContentType )
       
   289     {
       
   290 
       
   291     CSIPResponseElements* response = 
       
   292         CSIPResponseElements::NewLC( aResponse, 
       
   293                                      SIPStrings::StringF( aPhrase ) );
       
   294 
       
   295     CSIPMessageElements& message = response->MessageElements();
       
   296     
       
   297 //headers
       
   298 
       
   299     RPointerArray<CSIPHeaderBase> sipHdrs;
       
   300     CSIPHeaderBase::PushLC( &sipHdrs );
       
   301 
       
   302     if ( aContact.Length() > 0 )
       
   303         {
       
   304 
       
   305         RStringF value = MusAvaCapabilityContext::SIPStringL( aContact );
       
   306         CleanupClosePushL( value );
       
   307         
       
   308         TUriParser8 uriValue;
       
   309         User::LeaveIfError( uriValue.Parse( aFrom ) );
       
   310         CUri8* uri = CUri8::NewLC( uriValue );
       
   311         
       
   312         CSIPContactHeader* contact = 
       
   313             MusAvaCapabilityContext::ContactHeaderLC( *uri, value );
       
   314         sipHdrs.AppendL( contact );
       
   315         CleanupStack::Pop( contact );
       
   316         CleanupStack::PopAndDestroy( uri );
       
   317         CleanupStack::PopAndDestroy();//value
       
   318         
       
   319         }
       
   320         
       
   321     if ( aUserAgent.Length() > 0 )
       
   322         {
       
   323         
       
   324         CSIPExtensionHeader* userAgent = 
       
   325             MusAvaCapabilityContext::UserAgentHeaderLC( aUserAgent );
       
   326         sipHdrs.AppendL( userAgent );
       
   327         CleanupStack::Pop( userAgent );
       
   328         }
       
   329         
       
   330     if ( aPAssertedId.Length() > 0 )
       
   331         {
       
   332         
       
   333         CSIPExtensionHeader* pAssertedId = 
       
   334             MusAvaCapabilityContext::PAssertedIdentityHeaderLC( aPAssertedId );
       
   335         sipHdrs.AppendL( pAssertedId );
       
   336         CleanupStack::Pop( pAssertedId );
       
   337         
       
   338         }
       
   339         
       
   340     message.SetUserHeadersL( sipHdrs );
       
   341     CleanupStack::PopAndDestroy( &sipHdrs );
       
   342 
       
   343     if ( aSdp.Length() > 0 )
       
   344         {
       
   345         CSIPContentTypeHeader* contenttype = NULL;
       
   346         if ( aContentType.Length() == 0 )
       
   347             {
       
   348             contenttype = 
       
   349             CSIPContentTypeHeader::NewLC( KMUSAVASIPMediaTypeApplication,
       
   350                                          KMUSAVASIPMediaSubTypeSDP );
       
   351             }
       
   352         else
       
   353             {
       
   354             contenttype = 
       
   355             CSIPContentTypeHeader::DecodeL( aContentType );
       
   356             CleanupStack::PushL( contenttype );
       
   357 
       
   358             }
       
   359         HBufC8* content = aSdp.AllocLC();
       
   360         
       
   361         message.SetContentL( content, contenttype );
       
   362         CleanupStack::Pop( content );
       
   363         CleanupStack::Pop( contenttype );
       
   364         
       
   365         }
       
   366         
       
   367     aTrx.SetResponseElements( response );
       
   368     CleanupStack::Pop( response );
       
   369     
       
   370     }
       
   371 
       
   372 void CapabilityTestHelper::SetResponse2L(CSIPClientTransaction& aTrx,
       
   373                                    TUint aResponse, 
       
   374                                    TInt aPhrase,
       
   375                                    const TDesC8& aFrom,
       
   376                                    const TDesC8& aContact,
       
   377                                    const TDesC8& aUserAgent,
       
   378                                    const TDesC8& aPAssertedId,
       
   379                                    const TDesC8& aPAssertedId2,
       
   380                                    const TDesC8& aSdp,
       
   381                                    const TDesC8& aContentType )  
       
   382     {
       
   383     CSIPResponseElements* response = 
       
   384         CSIPResponseElements::NewLC( aResponse, 
       
   385                                      SIPStrings::StringF( aPhrase ) );
       
   386 
       
   387     CSIPMessageElements& message = response->MessageElements();
       
   388     
       
   389 //headers
       
   390 
       
   391     RPointerArray<CSIPHeaderBase> sipHdrs;
       
   392     CSIPHeaderBase::PushLC( &sipHdrs );
       
   393 
       
   394     if ( aContact.Length() > 0 )
       
   395         {
       
   396 
       
   397         RStringF value = MusAvaCapabilityContext::SIPStringL( aContact );
       
   398         CleanupClosePushL( value );
       
   399         
       
   400         TUriParser8 uriValue;
       
   401         User::LeaveIfError( uriValue.Parse( aFrom ) );
       
   402         CUri8* uri = CUri8::NewLC( uriValue );
       
   403         
       
   404         CSIPContactHeader* contact = 
       
   405             MusAvaCapabilityContext::ContactHeaderLC( *uri, value );
       
   406         sipHdrs.AppendL( contact );
       
   407         CleanupStack::Pop( contact );
       
   408         CleanupStack::PopAndDestroy( uri );
       
   409         CleanupStack::PopAndDestroy();//value
       
   410         
       
   411         }
       
   412         
       
   413     if ( aUserAgent.Length() > 0 )
       
   414         {
       
   415         
       
   416         CSIPExtensionHeader* userAgent = 
       
   417             MusAvaCapabilityContext::UserAgentHeaderLC( aUserAgent );
       
   418         sipHdrs.AppendL( userAgent );
       
   419         CleanupStack::Pop( userAgent );
       
   420         }
       
   421         
       
   422     if ( aPAssertedId.Length() > 0 )
       
   423         {
       
   424         
       
   425         CSIPExtensionHeader* pAssertedId = 
       
   426             MusAvaCapabilityContext::PAssertedIdentityHeaderLC( aPAssertedId );
       
   427         sipHdrs.AppendL( pAssertedId );
       
   428         CleanupStack::Pop( pAssertedId );
       
   429         
       
   430         }
       
   431         
       
   432     if ( aPAssertedId2.Length() > 0 )
       
   433         {
       
   434         
       
   435         CSIPExtensionHeader* pAssertedId2 = 
       
   436             MusAvaCapabilityContext::PAssertedIdentityHeaderLC( aPAssertedId2 );
       
   437         sipHdrs.AppendL( pAssertedId2 );
       
   438         CleanupStack::Pop( pAssertedId2 );
       
   439         
       
   440         }
       
   441 
       
   442     message.SetUserHeadersL( sipHdrs );
       
   443     CleanupStack::PopAndDestroy( &sipHdrs );
       
   444 
       
   445     if ( aSdp.Length() > 0 )
       
   446         {
       
   447         CSIPContentTypeHeader* contenttype = NULL;
       
   448         if ( aContentType.Length() == 0 )
       
   449             {
       
   450             contenttype = 
       
   451             CSIPContentTypeHeader::NewLC( KMUSAVASIPMediaTypeApplication,
       
   452                                          KMUSAVASIPMediaSubTypeSDP );
       
   453             }
       
   454         else
       
   455             {
       
   456             contenttype = 
       
   457             CSIPContentTypeHeader::DecodeL( aContentType );
       
   458             CleanupStack::PushL( contenttype );
       
   459 
       
   460             }
       
   461         HBufC8* content = aSdp.AllocLC();
       
   462         
       
   463         message.SetContentL( content, contenttype );
       
   464         CleanupStack::Pop( content );
       
   465         CleanupStack::Pop( contenttype );
       
   466         
       
   467         }
       
   468         
       
   469     aTrx.SetResponseElements( response );
       
   470     CleanupStack::Pop( response );
       
   471     
       
   472     }
       
   473 
       
   474 CSIPAddress* HelpFlags::iTestSipAddress = NULL;
       
   475 TBool HelpFlags::iUseTestSipAddress = EFalse;
       
   476 TBool HelpFlags::iEmptyContactHeader = EFalse;
       
   477