realtimenetprots/sipfw/SIP/ServerResolver/src/CSIPNaptrOrigDomain.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name          : CSIPNaptrOrigDomain.cpp
       
    15 // Part of       : ServerResolver
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "sipstrings.h"
       
    22 #include "sipstrconsts.h"
       
    23 #include "CSIPNaptrOrigDomain.h"
       
    24 #include "CSIPQueryBase.h"
       
    25 #include "CSIPQueryNaptr.h"
       
    26 #include "CSIPQuerySrv.h"
       
    27 #include "CSIPSRVOrigDomainUDP.h"
       
    28 #include "CSIPSRVNaptrDomain.h"
       
    29 #include "MSIPServerQuery.h"
       
    30 #include "CSIPQueryData.h"
       
    31 
       
    32 // ----------------------------------------------------------------------------
       
    33 // CSIPNaptrOrigDomain::CSIPNaptrOrigDomain
       
    34 // ----------------------------------------------------------------------------
       
    35 //
       
    36 CSIPNaptrOrigDomain::CSIPNaptrOrigDomain( MSIPServerQuery& aServerQuery )
       
    37 :CSIPQueryConditionBase(), iServerQuery ( aServerQuery )
       
    38 	{
       
    39 	}
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // CSIPNaptrOrigDomain::ConstructL
       
    43 // ----------------------------------------------------------------------------
       
    44 //
       
    45 void CSIPNaptrOrigDomain::ConstructL()
       
    46 	{
       
    47 	iQueryBase = 
       
    48 		     CSIPQueryNaptr::NewL( iServerQuery.QueryData().OriginalTarget(),
       
    49 		     					   iServerQuery.QueryData().IsSipsUri() );
       
    50 	}
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CSIPNaptrOrigDomain::NewL
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 CSIPNaptrOrigDomain* CSIPNaptrOrigDomain::NewL( MSIPServerQuery& aServerQuery )
       
    57 	{
       
    58 	CSIPNaptrOrigDomain* self =
       
    59 						   new ( ELeave ) CSIPNaptrOrigDomain( aServerQuery );
       
    60 	CleanupStack::PushL( self );
       
    61 	self->ConstructL();
       
    62 	CleanupStack::Pop( self );
       
    63 	return self;
       
    64 	}
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // CSIPNaptrOrigDomain::~CSIPNaptrOrigDomain
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 CSIPNaptrOrigDomain::~CSIPNaptrOrigDomain()
       
    71 	{
       
    72 	delete iQueryBase;
       
    73 	}
       
    74 
       
    75 // ----------------------------------------------------------------------------
       
    76 // CSIPNaptrOrigDomain::QueryBase
       
    77 // ----------------------------------------------------------------------------
       
    78 //	
       
    79 CSIPQueryBase& CSIPNaptrOrigDomain::QueryBase() 
       
    80 	{
       
    81 	return *iQueryBase;
       
    82 	}
       
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // CSIPNaptrOrigDomain::HandleQueryResultL
       
    86 // ----------------------------------------------------------------------------
       
    87 //
       
    88 CSIPQueryConditionBase* CSIPNaptrOrigDomain::HandleQueryResultL( TInt aStatus ) 
       
    89 	{
       
    90 	if ( aStatus == KErrNone )
       
    91 		{		
       
    92 		CheckIfOnlyUDPResultsL();
       
    93 
       
    94 		iQueryBase->HandleQueryResultL( iServerQuery.QueryData().Resolver() );
       
    95 		if ( iQueryBase->ArrayCount() > 0 )
       
    96 			{
       
    97 			iServerQuery.QueryData().SetProtocol(
       
    98 											iQueryBase->ResultProtocolL() );
       
    99 			iServerQuery.QueryData().SetTargetL( iQueryBase->ResultTargetL() );
       
   100 			CSIPQueryConditionBase* conditionbase = 
       
   101 					     CSIPSRVNaptrDomain::NewL( iServerQuery, iQueryBase );
       
   102 			iQueryBase = NULL;
       
   103 			return conditionbase;
       
   104 			}
       
   105 		}
       
   106 	iServerQuery.QueryData().SetPort( 0 );
       
   107 	if (iServerQuery.QueryData().IsSipsUri())
       
   108 		{
       
   109 		iServerQuery.QueryData().SetProtocol(SIPStrings::StringF(
       
   110 											SipStrConsts::ETLS) );
       
   111 		}
       
   112 	else
       
   113 		{
       
   114 		iServerQuery.QueryData().SetProtocol(SIPStrings::StringF(
       
   115 											SipStrConsts::EUDP) );
       
   116 		}
       
   117 	
       
   118 	HBufC8* temp = CSIPQuerySrv::SetTargetProtocolL(
       
   119 									iServerQuery.QueryData().OriginalTarget(),
       
   120 					 				iServerQuery.QueryData().Protocol(),
       
   121 					 				iServerQuery.QueryData().IsSipsUri());
       
   122 	CleanupStack::PushL( temp );
       
   123 	iServerQuery.QueryData().SetTargetL( *temp );
       
   124 	CleanupStack::PopAndDestroy( temp );
       
   125 	return ( CSIPSRVOrigDomainUDP::NewL( iServerQuery ) );	
       
   126 	}
       
   127 
       
   128 // ----------------------------------------------------------------------------
       
   129 // CSIPNaptrOrigDomain::CheckIfOnlyUDPResultsL
       
   130 // If the result array has only records where protocol is UDP, the "force UDP"
       
   131 // flag is set to guarantee the protocol won't be changed by later stages in
       
   132 // the SIP stack.
       
   133 // Since the "force UDP" can be set only if CSIPNaptrOrigDomain query returned
       
   134 // at least one result, the further resolving phases do not change the
       
   135 // protocol.
       
   136 // ----------------------------------------------------------------------------
       
   137 //
       
   138 void CSIPNaptrOrigDomain::CheckIfOnlyUDPResultsL() const
       
   139 	{
       
   140 	__ASSERT_ALWAYS( iQueryBase, User::Leave( KErrNotFound ) );
       
   141 
       
   142 	//CSIPNaptrOrigDomain::iQueryBase is always CSIPQueryNaptr.
       
   143 	CSIPQueryNaptr& queryNaptr = static_cast<CSIPQueryNaptr&>( *iQueryBase );
       
   144 	TBool udpOnly = ( queryNaptr.ArrayCount() > 0 );
       
   145 
       
   146 	for ( TInt i = 0; i < queryNaptr.ArrayCount() && udpOnly; ++i )
       
   147 		{
       
   148 		TDnsRespNAPTR& dnsResp = queryNaptr.NAPTRRecordL( i );
       
   149 		udpOnly = ( queryNaptr.NaptrProtocol( dnsResp ) ==
       
   150 			 		SIPStrings::StringF( SipStrConsts::EUDP ) );
       
   151 		}
       
   152 
       
   153 	//There is only one query data instance for a single GetByUriL request
       
   154 	if ( udpOnly )
       
   155 		{
       
   156 		iServerQuery.QueryData().SetForceUDP();
       
   157 		}
       
   158 	}