multimediacommsengine/tsrc/testdriver/siptester/src/TCmdSendRequest.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <sipclienttransaction.h>
       
    19 #include <sipconnection.h>
       
    20 #include <sipfromheader.h>
       
    21 #include <siprefresh.h>
       
    22 #include <sipregistrationbinding.h>
       
    23 #include <siprequestelements.h>
       
    24 #include <siptoheader.h>
       
    25 #include <sipstrings.h>
       
    26 #include <stringpool.h>
       
    27 #include <_sipcodecdefs.h>
       
    28 #include <sipprofile.h>
       
    29 
       
    30 #include "CTcSIPConnectionContainer.h"
       
    31 #include "TCmdSendRequest.h"
       
    32 #include "SIPConstants.h"
       
    33 
       
    34 /**
       
    35  * INPUT:
       
    36  *   Headers:		To, Contact, From*, Content-Type*, Content-Encoding*,
       
    37  *					Expires*, Security-Client*
       
    38  *   Parameters:	Content*, RemoteURI*, Refresh*
       
    39  *   IDs:			ConnectionId*, RegistrationId*, RegistryId*, ProfileId*
       
    40  *
       
    41  * OUTPUT:
       
    42  *   Parameters:	-
       
    43  *   IDs:			TransactionId
       
    44  */
       
    45 void TCmdSendRequest::ExecuteL()
       
    46 	{
       
    47 	// Select connection; either default or user specified (and existing)
       
    48 	CSIPConnection& connection = SelectConnectionL().Connection();
       
    49 
       
    50 	// Get SIP objects from registry
       
    51 	CSIPRegistrationBinding* registration = GetRegistrationL( EFalse );
       
    52 	
       
    53 	 // Get selected registry
       
    54     CTcSIPProfileContainer& container = SelectProfileL();
       
    55 
       
    56 	// Get profile from the profile registry, not mandatory
       
    57 	CSIPProfile* profile = GetProfileL( container, EFalse );
       
    58 	
       
    59 	MSIPRegistrationContext* registrationContext = 0;
       
    60 	
       
    61 	TBool fromHeaderMandatory( ETrue );
       
    62 	
       
    63 	if ( profile )
       
    64 	    {
       
    65 	    fromHeaderMandatory = EFalse;
       
    66 	    registrationContext = profile;
       
    67 	    }
       
    68     
       
    69     // Defining registration binding will override possibly defined profile	    
       
    70 	if( registration )
       
    71 		{
       
    72 		fromHeaderMandatory = EFalse;
       
    73 		registrationContext = registration;
       
    74 		}		  
       
    75 	
       
    76 	// Extract remote URI
       
    77 	CUri8* uri = ExtractRemoteURILC();
       
    78 
       
    79 	// Create SIP request elements, giving toHeader away
       
    80 	CSIPRequestElements* reqElements = CSIPRequestElements::NewL( uri );
       
    81 	CleanupStack::Pop( uri );
       
    82 	CleanupStack::PushL( reqElements );
       
    83 	
       
    84 	// Extract To header (may be either mandatory or optional)
       
    85 	CSIPToHeader* toHeader = ExtractToHeaderLC();
       
    86 	if( toHeader )
       
    87 	    {
       
    88 	    reqElements->SetToHeaderL( toHeader );
       
    89 	    CleanupStack::Pop( toHeader );
       
    90 	    }
       
    91 
       
    92 	// Set request method
       
    93 	TPtrC8 methodPtr = ExtractTextL( KParamMethod );
       
    94 	RStringF methodStr = SIPStrings::Pool().OpenFStringL(methodPtr);
       
    95 	CleanupClosePushL(methodStr);	
       
    96     reqElements->SetMethodL( methodStr );
       
    97 	
       
    98 	// Extract From header (may be either mandatory or optional)
       
    99 	CSIPFromHeader* fromHeader = ExtractFromHeaderLC( fromHeaderMandatory );
       
   100 	if( fromHeader )
       
   101 		{
       
   102 		reqElements->SetFromHeaderL( fromHeader );
       
   103 		CleanupStack::Pop( fromHeader );
       
   104 		}
       
   105 
       
   106 	// Conditionally create refresh object
       
   107 	CSIPRefresh* refresh = ExtractRefreshLC();
       
   108 
       
   109 	// Extract both headers (that are still left) and content.
       
   110 	ExtractHeadersAndContentL( reqElements->MessageElements() );
       
   111  		
       
   112 	// -- Execution -----------------------------------------------------------
       
   113 
       
   114 	// Start SIP Request transaction.
       
   115 	CSIPClientTransaction* transaction;
       
   116 	if( registrationContext )
       
   117 		{
       
   118 		if( refresh )
       
   119 			{
       
   120 			transaction = connection.SendRequestL( reqElements, *registrationContext,
       
   121 												   *refresh );
       
   122 			}
       
   123 		else
       
   124 			{
       
   125 			transaction = connection.SendRequestL( reqElements, *registrationContext );
       
   126 			}
       
   127 		}
       
   128 	else
       
   129 		{
       
   130 		if( refresh )
       
   131 			{
       
   132 			transaction = connection.SendRequestL( reqElements, *refresh );
       
   133 			}
       
   134 		else
       
   135 			{
       
   136 			transaction = connection.SendRequestL( reqElements );
       
   137 			}
       
   138 		}
       
   139 
       
   140 	if( refresh )
       
   141 		{
       
   142 		CleanupStack::Pop( refresh );
       
   143 		}
       
   144 	CleanupStack::PopAndDestroy(); // methodStr
       
   145 	CleanupStack::Pop( reqElements );
       
   146 
       
   147 	// -- Response creation ---------------------------------------------------
       
   148 
       
   149 	AddIdResponseL( KTransactionId, transaction );
       
   150 	}
       
   151 
       
   152 TBool TCmdSendRequest::Match( const TTcIdentifier& aId )
       
   153 	{
       
   154 	return TTcSIPCommandBase::Match( aId, _L8("SendRequest") );
       
   155 	}
       
   156 
       
   157 TTcCommandBase* TCmdSendRequest::CreateL( MTcTestContext& aContext )
       
   158 	{
       
   159 	return new( ELeave ) TCmdSendRequest( aContext );
       
   160 	}
       
   161