// -----------------------------------------------------------------------------
// CSIPExSIPIdleState::SendInviteL()
// Create and send an INVITE request to the recipient.
// -----------------------------------------------------------------------------
void CSIPExSIPIdleState::SendInviteL( 
    CSIPExSIPEngine& aEngine,
	const TDesC8& aSipUri )
	{
	// Retrieve the active profile and connection
	CSIPProfile& prof = aEngine.Profile();
	CSIPConnection& conn = aEngine.ConnectionL();

    // Create CUri8 from passed descriptor
    CUri8* uri8 = aEngine.ConvertToUri8LC( aSipUri );
    
	// Get dialog association, save for future use
	// The ownership of uri8 is transferred
	CSIPInviteDialogAssoc* dialogAssoc =
		CSIPInviteDialogAssoc::NewL( conn, uri8, prof );
	CleanupStack::Pop( uri8 );	
		
	aEngine.SetDialogAssoc( *dialogAssoc ); //Ownership is transferred!!

	// Create the necessary message elements
	CSIPMessageElements* msgElements = aEngine.CreateMessageElementsLC();

	// Send the INVITE in the dialog
	// The ownership of msgElements is transferred
	CSIPClientTransaction* tx = dialogAssoc->SendInviteL( msgElements );
	CleanupStack::Pop( msgElements );

	// Save the pointer to the transaction to the Engine
	aEngine.SetClientTx( tx );

	// Change machine state
	aEngine.SetCurrentState( iClientEstablishingState );
	}
// -----------------------------------------------------------------------------
// CSIPExSIPIdleState::InviteReceivedL()
// (other items were commented in a header).
// -----------------------------------------------------------------------------
void CSIPExSIPIdleState::InviteReceivedL( 
    CSIPExSIPEngine& aEngine,
	CSIPServerTransaction* aTransaction )
	{
	_LIT8( KLogEntry, "180 Ringing sent" );

	// Get dialog association, save for future use
	CSIPInviteDialogAssoc* dialogAssoc =
		CSIPInviteDialogAssoc::NewL( *aTransaction );
	aEngine.SetDialogAssoc( *dialogAssoc );
    
	// Create the necessary response elements and send
    CSIPResponseElements* elem =
    	CSIPResponseElements::NewLC( 
    	    180, SIPStrings::StringF( SipStrConsts::EPhraseRinging ) );
    aTransaction->SendResponseL( elem );
    CleanupStack::Pop( elem );
	aEngine.Observer()->WriteLog( KLogEntry );

	// Get the From header from the request
	const CSIPRequestElements* reqElem = aTransaction->RequestElements();
	const CSIPFromHeader* fromHeader = reqElem->FromHeader();
	
	// Change machine state
	aEngine.SetCurrentState( iServerOfferingState );

    TUint32 iapId( 0 );
	User::LeaveIfError( 
	        aEngine.Profile().GetParameter( KSIPAccessPointId, iapId ) );
	
	// Send user name from the From header to the Engine Observer 
	// as a parameter. Send also id of used IAP.
	aEngine.Observer()->InviteReceived( 
	    fromHeader->SIPAddress().Uri8().Uri().Extract( EUriUserinfo ), iapId );
	}