multimediacommsengine/tsrc/testdriver/siptester/src/TCmdGetProfile.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 "CTcSIPContext.h"
       
    19 #include "SIPConstants.h"
       
    20 #include "TCmdGetProfile.h"
       
    21 #include "CTcSIPProfileContainer.h"
       
    22 
       
    23 #include <sipmanagedprofile.h>
       
    24 
       
    25 /**
       
    26  * INPUT:
       
    27  *   Headers:		-
       
    28  *   Parameters:	-
       
    29  *   IDs:			ProfileId, RegistryId
       
    30  *
       
    31  * OUTPUT:
       
    32  *	 Parameters:	Type, IapId, AORs, PrivateIdentity, Name, SigComp, 
       
    33  *					AutoRegistration, SecurityNegotiation, Server,
       
    34  *					ServerParameter, ServerExtensionParameter, 
       
    35  *					ExtensionParameter, Default, Enabled
       
    36  *	 IDs:			-
       
    37  */
       
    38 void TCmdGetProfile::ExecuteL()
       
    39 	{
       
    40 	// -- Setup ---------------------------------------------------------------
       
    41 
       
    42 	// Get selected registry
       
    43     CTcSIPProfileContainer& container = SelectProfileL();
       
    44 
       
    45 	// Get profile from the profile registry
       
    46 	CSIPManagedProfile& profile = GetManagedProfileL( container );
       
    47 
       
    48 	// -- Execution -----------------------------------------------------------
       
    49 
       
    50 	// -- Response creation ---------------------------------------------------
       
    51 	
       
    52 	GetProfileParamsL( container, &profile );
       
    53 	
       
    54 	}
       
    55 
       
    56 void TCmdGetProfile::GetProfileParamsL( 
       
    57     CTcSIPProfileContainer& aContainer,
       
    58     CSIPManagedProfile* aProfile )
       
    59 	{
       
    60 	__ASSERT_ALWAYS( aProfile, User::Leave( KErrArgument ) );
       
    61 	// Type
       
    62 	TSIPProfileTypeInfo type = aProfile->Type();
       
    63 	if( type.iSIPProfileName != KNullDesC8 )
       
    64 		{
       
    65 		CTcStructure* s1 = AddStructureResponseL( KParamProfileType );
       
    66 		s1->AddItemL( KParamProfileClass, type.iSIPProfileClass );
       
    67 		s1->AddItemL( KParamProfileName, type.iSIPProfileName );
       
    68 		}
       
    69 
       
    70 	// IapName
       
    71 	TUint32 iapId( 0 );
       
    72 	User::LeaveIfError( aProfile->GetParameter( KSIPAccessPointId, iapId ) );
       
    73 	AddTextResponseL( KParamIAPName, iContext.IAPNameL( iapId ) );
       
    74 
       
    75 	// AOR
       
    76     const TDesC8* aor = NULL;
       
    77 	aProfile->GetParameter( KSIPUserAor, aor );
       
    78 	if( aor && *aor != KNullDesC8 )
       
    79 	    {    
       
    80     	AddTextResponseL( KParamProfileAOR, *aor );
       
    81 	    }
       
    82 	    
       
    83 	// Registered AOR(s)
       
    84 	const MDesC8Array* aors = NULL;
       
    85 	aProfile->GetParameter( KSIPRegisteredAors, aors );
       
    86 	if( aors && aors->MdcaCount() > 0 )
       
    87 	    {    
       
    88     	AddArrayResponseL( KParamProfileAORs, *aors );
       
    89 	    }
       
    90 	    
       
    91 	// PrivateIdentity
       
    92 	const TDesC8* privateIdentity = NULL;
       
    93 	aProfile->GetParameter( KSIPPrivateIdentity, privateIdentity );
       
    94 	if( privateIdentity && *privateIdentity != KNullDesC8 )
       
    95 	    {	    
       
    96     	AddTextResponseL( KParamProfilePrivateIdentity, *privateIdentity );
       
    97 	    }
       
    98 
       
    99 	// Name
       
   100 	const TDesC8* name = NULL;
       
   101 	aProfile->GetParameter( KSIPProviderName, name );
       
   102 	if( name && *name != KNullDesC8 )
       
   103 	    {  
       
   104     	AddTextResponseL( KParamProfileName, *name );
       
   105 	    }
       
   106 
       
   107 	// SigComp
       
   108 	TBool isSigCompEnabled( EFalse );
       
   109 	aProfile->GetParameter( KSIPSigComp, isSigCompEnabled );
       
   110 	AddBooleanResponseL( KParamProfileSigComp, isSigCompEnabled );
       
   111 
       
   112 	// AutoRegistration
       
   113 	
       
   114 	TBool isAutoRegEnabled( EFalse );
       
   115 	aProfile->GetParameter( KSIPAutoRegistration, isAutoRegEnabled );
       
   116 	AddBooleanResponseL( KParamProfileAutoRegistration, isAutoRegEnabled );
       
   117 
       
   118 	// SecurityNegotiation
       
   119 	TBool isSecNegEnabled( EFalse );
       
   120 	aProfile->GetParameter( KSIPSecurityNegotiation, isSecNegEnabled );
       
   121 	AddBooleanResponseL( KParamProfileSecurityNegotiation, isSecNegEnabled );
       
   122 	
       
   123 	// NegotiatedSecMechanism
       
   124 	const TDesC8* secmech = NULL;
       
   125 	aProfile->GetParameter( KSIPNegotiatedSecurityMechanism, secmech );
       
   126 	if( secmech && *secmech != KNullDesC8 )
       
   127 	    {
       
   128     	AddTextResponseL( KParamNegotiatedSecMechanism, *secmech );
       
   129 	    }
       
   130 
       
   131 	// Server
       
   132 	const TDesC8* address = NULL;
       
   133 	
       
   134 	aProfile->GetParameter( KSIPRegistrar, KSIPServerAddress, address );
       
   135 	if( address && *address != KNullDesC8 )
       
   136 		{
       
   137 		CTcStructure* s1 = AddStructureResponseL( KParamProfileServer );
       
   138 		s1->AddItemL( KRegistrar, *address );
       
   139 		}
       
   140 	else
       
   141 		{
       
   142 		aProfile->GetParameter( KSIPOutboundProxy, KSIPServerAddress, address );
       
   143 		if( address && *address != KNullDesC8 )
       
   144 			{
       
   145 			CTcStructure* s1 = AddStructureResponseL( KParamProfileServer );
       
   146 			s1->AddItemL( KOutboundProxy, *address  );
       
   147 			}
       
   148 		}
       
   149 		
       
   150 	// ServerParameter
       
   151     ServerParameterL( KSIPRegistrar, KSIPDigestRealm, aProfile );
       
   152 	ServerParameterL( KSIPRegistrar, KSIPDigestUserName, aProfile );
       
   153 	ServerParameterL( KSIPOutboundProxy, KSIPDigestRealm, aProfile );
       
   154 	ServerParameterL( KSIPOutboundProxy, KSIPDigestUserName, aProfile );
       
   155 
       
   156 	// ServerExtensionParameter
       
   157 	CTcStructure* structure;
       
   158 	do {
       
   159 		structure = FindStructureL( KParamProfileServerExtensionParameter, EFalse );
       
   160 		if( structure )
       
   161 			{
       
   162 			TPtrC8 server = structure->ItemL( KParamProfileServer )->Value();
       
   163 			
       
   164 			const CTcNameValue* extensionParam = structure->ItemL( 1 );
       
   165 			
       
   166 			TUint32 serverType = ServerL( structure );
       
   167 
       
   168 			const TDesC8* value = NULL;
       
   169 			aProfile->GetParameter( serverType, extensionParam->NameAsIntL(), value ); 
       
   170 			if( value && *value != KNullDesC8 )
       
   171 				{
       
   172 				CTcStructure* s1 = AddStructureResponseL( KParamProfileServerExtensionParameter );
       
   173 				s1->AddItemL( KParamProfileServer, server );
       
   174 				s1->AddItemL( extensionParam->Name(), *value );
       
   175 				}
       
   176 			iContext.List().RemoveParameter( KParamProfileServerExtensionParameter );
       
   177 			}
       
   178 		} while( structure );
       
   179 
       
   180 	// ExtensionParameter
       
   181 	do {
       
   182 		structure = FindStructureL( KParamProfileExtensionParameter, EFalse );
       
   183 		if( structure )
       
   184 			{
       
   185 			const CTcNameValue* extensionParam = structure->ItemL( 0 );
       
   186 
       
   187 			const TDesC8* value = NULL;	
       
   188 			TBool boolVal( EFalse );
       
   189 			TUint32 intVal( 0 );
       
   190 			
       
   191 			if ( aProfile->GetParameter( extensionParam->NameAsIntL(), value ) != KErrNotFound )
       
   192 			    {
       
   193     			if( value && *value != KNullDesC8 )
       
   194     				{
       
   195     				CTcStructure* s1 = AddStructureResponseL( KParamProfileExtensionParameter );
       
   196     				s1->AddItemL( extensionParam->Name(), *value );
       
   197     				}
       
   198 			    }
       
   199 			else if ( aProfile->GetParameter( extensionParam->NameAsIntL(), boolVal ) != KErrNotFound )
       
   200 			    {
       
   201 			    CTcStructure* s1 = AddStructureResponseL( KParamProfileExtensionParameter );
       
   202     			s1->AddBooleanItemL( extensionParam->Name(), boolVal );
       
   203 			    }
       
   204 			else if ( aProfile->GetParameter( extensionParam->NameAsIntL(), intVal ) != KErrNotFound )
       
   205 			    {
       
   206 			    CTcStructure* s1 = AddStructureResponseL( KParamProfileExtensionParameter );
       
   207     			s1->AddItemL( extensionParam->Name(), intVal );
       
   208 			    }
       
   209 			else
       
   210 			    {
       
   211 			    }
       
   212 			
       
   213 			iContext.List().RemoveParameter( KParamProfileExtensionParameter );
       
   214 			}
       
   215 		} while( structure );
       
   216 
       
   217     // Header params
       
   218 	CTcArray* headerParamsArr = FindArrayL( KParamProfileHeaderParams, EFalse );
       
   219 	if( headerParamsArr && headerParamsArr->Count() > 0 )
       
   220 		{
       
   221     	TUint32 paramType( 0 );
       
   222 	    TLex8 lexer( headerParamsArr->Item( 0 ) );
       
   223 	    User::LeaveIfError( lexer.Val( paramType, EDecimal ) );
       
   224 	    
       
   225     	headerParamsArr->RemoveItem( 0 );
       
   226     	const MDesC8Array* arr = 0;
       
   227     	aProfile->GetParameter( paramType, arr );
       
   228     	if( arr && arr->MdcaCount() > 0 )
       
   229     	    {    
       
   230         	AddArrayResponseL( KParamProfileHeaderParams, *arr );
       
   231     	    }
       
   232 		}
       
   233 		
       
   234 	// Default
       
   235 	TBool isDefault( EFalse );
       
   236 	aProfile->GetParameter( KSIPDefaultProfile, isDefault );
       
   237 	AddBooleanResponseL( KParamProfileDefault, isDefault );
       
   238 	
       
   239 	// Enabled status
       
   240 	AddBooleanResponseL( KParamProfileEnabled, 
       
   241 	                     aContainer.ProfileRegistry().IsEnabled( *aProfile ) );
       
   242 	}
       
   243 
       
   244 
       
   245 TBool TCmdGetProfile::Match( const TTcIdentifier& aId )
       
   246 	{
       
   247 	return TTcSIPCommandBase::Match( aId, _L8("GetProfile") );
       
   248 	}
       
   249 
       
   250 TTcCommandBase* TCmdGetProfile::CreateL( MTcTestContext& aContext )
       
   251 	{
       
   252 	return new( ELeave ) TCmdGetProfile( aContext );
       
   253 	}
       
   254 
       
   255 TPtrC8 TCmdGetProfile::ServerToString( TUint32 aServer )
       
   256 	{
       
   257 	TPtrC8 value;
       
   258 	if( aServer == KSIPRegistrar )
       
   259 		{
       
   260 		value.Set( KRegistrar );
       
   261 		}
       
   262 	else if( aServer == KSIPOutboundProxy )
       
   263 		{
       
   264 		value.Set( KOutboundProxy );
       
   265 		}
       
   266 
       
   267 	return value;
       
   268 	}
       
   269 
       
   270 void TCmdGetProfile::ServerParameterL( TUint32 aServer,
       
   271 									   TUint32 aServerParameter,
       
   272 									   const CSIPProfile* aSipProfile )
       
   273 	{
       
   274 	const TDesC8* value = NULL;
       
   275 	aSipProfile->GetParameter( aServer, aServerParameter, value );
       
   276 
       
   277 	if( value && *value != KNullDesC8 )
       
   278 		{
       
   279 		CTcStructure* s1 = AddStructureResponseL( KParamProfileServerParameter );
       
   280 
       
   281 		// Set server type
       
   282 		TPtrC8 string = ServerToString( aServer );
       
   283 		if( string != KNullDesC8 )
       
   284 			{
       
   285 			s1->AddItemL( KParamProfileServer, string );
       
   286 			}
       
   287 
       
   288 		// Set server parameter
       
   289 		if( aServerParameter == KSIPDigestRealm )
       
   290 			{
       
   291 			string.Set( KDigestRealm );
       
   292 			}
       
   293 		else if( aServerParameter == KSIPDigestUserName )
       
   294 			{
       
   295 			string.Set( KDigestUsername );
       
   296 			}
       
   297 
       
   298 		s1->AddItemL( KParamProfileParameter, string );
       
   299 		s1->AddItemL( KParamProfileValue, *value );
       
   300 		}
       
   301 	}
       
   302