multimediacommsengine/tsrc/testdriver/siptester/src/TCmdCreateProfile.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 "TCmdCreateProfile.h"
       
    21 #include "CTcSIPProfileContainer.h"
       
    22 
       
    23 #include <sipmanagedprofile.h>
       
    24 #include <sipmanagedprofileregistry.h>
       
    25 #include "tclog.h"
       
    26 
       
    27 /**
       
    28  * INPUT:
       
    29  *   Headers:		-
       
    30  *   Parameters:	ProfileType*, IapName*, ProfileAORList*, PrivateIdentity*,
       
    31  *					ProfileName*, SigComp*, 
       
    32  *					AutoRegistration*, SecurityNegotiation*, Server*,
       
    33  *					ServerParameter*, ServerExtensionParameter*, 
       
    34  *					ExtensionParameter*, ProfileDefault*
       
    35  *   IDs:			RegistryId
       
    36  *
       
    37  * OUTPUT:
       
    38  *   Parameters:	-
       
    39  *   IDs:			-
       
    40  */
       
    41 void TCmdCreateProfile::ExecuteL()
       
    42 	{
       
    43 	// -- Setup ---------------------------------------------------------------
       
    44 	// Get selected registry
       
    45     CTcSIPProfileContainer& container = SelectProfileL();
       
    46 
       
    47 	// Create a new profile, if type parameter is not found use default 
       
    48 	// Internet, IETF
       
    49 	CSIPManagedProfile* profile = NULL;
       
    50 	CTcStructure* structure = FindStructureL( KParamProfileType, EFalse );
       
    51 	if( structure )
       
    52 	    {
       
    53 	    profile = container.ManagedProfileRegistry().CreateL( ProfileTypeInfoL( structure ) );
       
    54 	    }
       
    55 	else
       
    56 	    {
       
    57 	    TSIPProfileTypeInfo typeInfo;
       
    58 	    typeInfo.iSIPProfileClass = TSIPProfileTypeInfo::EInternet;
       
    59 	    typeInfo.iSIPProfileName = KIETF;
       
    60 	    profile = container.ManagedProfileRegistry().CreateL( typeInfo );
       
    61 	    }
       
    62 	CleanupStack::PushL( profile );
       
    63 	
       
    64 	// -- Execution -----------------------------------------------------------
       
    65 	SetProfileParamsL( profile );
       
    66 	
       
    67 	// Saving the profile
       
    68 	container.ManagedProfileRegistry().SaveL( *profile );
       
    69 
       
    70 	CleanupStack::Pop( profile );
       
    71 	
       
    72 	container.AddManagedProfileL( profile ); //store profile
       
    73 
       
    74 	// -- Response creation ---------------------------------------------------
       
    75 
       
    76 	AddProfileIdResponseL( *profile );
       
    77 	}
       
    78 
       
    79 void TCmdCreateProfile::SetProfileParamsL( CSIPManagedProfile* aProfile )
       
    80 	{
       
    81 	// Type	
       
    82 	TcLog::WriteFormat( _L8("-- Get optional structure \"ProfileType\"") );
       
    83 	CTcStructure* structure = FindStructureL( KParamProfileType, EFalse );
       
    84 	if( structure )
       
    85 		{
       
    86 		TcLog::Write( KLogOk );
       
    87 	    aProfile->SetType( ProfileTypeInfoL( structure ) );
       
    88 		}
       
    89 	else
       
    90 		{
       
    91 		TcLog::Write( KLogNotFound );
       
    92 		}
       
    93 	
       
    94 	// IapId
       
    95 	TPtrC8 iapname = ExtractTextL( KParamIAPName, EFalse );
       
    96 	if( iapname != KNullDesC8 )
       
    97 		{
       
    98 		TBuf8< KTcMaxTypeName > objectName( iapname );
       
    99 		TcLog::WriteFormat( _L8("-- Fetching IAP Id for name \"%s\""), objectName.PtrZ() );
       
   100 		TUint32 iapId = iContext.IAPIdL( iapname );
       
   101 		User::LeaveIfError( aProfile->SetParameter( KSIPAccessPointId, iapId ) );
       
   102 		TcLog::Write( KLogOk );
       
   103 		}
       
   104 
       
   105 	// AORs
       
   106 	TcLog::WriteFormat( _L8("-- Get optional array \"ProfileAORList\"") );
       
   107 	CTcArray* aorsArr = FindArrayL( KParamProfileAORs, EFalse );
       
   108 	if( aorsArr )
       
   109 		{
       
   110 		// Use first item of aorsArr
       
   111 		TPtrC8 aor = aorsArr->AsMDesCArray().MdcaPoint( 0 );
       
   112 		if( aor != KNullDesC8 )
       
   113 		    {
       
   114     		TcLog::Write( KLogOk );
       
   115     		User::LeaveIfError( aProfile->SetParameter( KSIPUserAor, aor ) );
       
   116 		    }
       
   117 		}
       
   118 	else
       
   119 		{
       
   120 		TcLog::Write( KLogNotFound );
       
   121 		}
       
   122 		
       
   123     // Headers
       
   124 	TcLog::WriteFormat( _L8("-- Get optional array \"ProfileHeadersList\"") );
       
   125 	CTcArray* headersArr = FindArrayL( KParamProfileHeaders, EFalse );
       
   126 	if( headersArr )
       
   127 		{
       
   128     	TcLog::Write( KLogOk );
       
   129     	User::LeaveIfError( aProfile->SetParameter( KSIPHeaders, headersArr->AsMDesCArray() ) );
       
   130 		}
       
   131 	else
       
   132 		{
       
   133 		TcLog::Write( KLogNotFound );
       
   134 		}
       
   135 		
       
   136 	// Header params
       
   137 	TcLog::WriteFormat( _L8("-- Get optional array \"ProfileHeaderParamsList\"") );
       
   138 	CTcArray* headerParamsArr = FindArrayL( KParamProfileHeaderParams, EFalse );
       
   139 	if( headerParamsArr && headerParamsArr->Count() > 0 )
       
   140 		{
       
   141     	TcLog::Write( KLogOk );
       
   142     	
       
   143     	TUint32 paramType( 0 );
       
   144 	    TLex8 lexer( headerParamsArr->Item( 0 ) );
       
   145 	    User::LeaveIfError( lexer.Val( paramType, EDecimal ) );
       
   146 	    
       
   147     	headerParamsArr->RemoveItem( 0 );
       
   148     	User::LeaveIfError( aProfile->SetParameter( paramType, headerParamsArr->AsMDesCArray() ) );
       
   149 		}
       
   150 	else
       
   151 		{
       
   152 		TcLog::Write( KLogNotFound );
       
   153 		}
       
   154 
       
   155 	// PrivateIdentity
       
   156 	TPtrC8 privateIdentity = ExtractTextL( KParamProfilePrivateIdentity, EFalse );
       
   157 	if( privateIdentity != KNullDesC8 )
       
   158 		{
       
   159 		User::LeaveIfError( aProfile->SetParameter( KSIPPrivateIdentity, privateIdentity ) );
       
   160 		}
       
   161 
       
   162 	// Name
       
   163 	TPtrC8 name = ExtractTextL( KParamProfileName, EFalse );
       
   164 	if( name != KNullDesC8 )
       
   165 		{
       
   166 		User::LeaveIfError( aProfile->SetParameter( KSIPProviderName, name ) );
       
   167 		}
       
   168 
       
   169 	// SigComp	
       
   170 	if( HasBooleanL( KParamProfileSigComp ) )
       
   171 	    {
       
   172     	User::LeaveIfError( aProfile->SetParameter( KSIPSigComp, 
       
   173     	                                            ExtractBooleanL( KParamProfileSigComp, EFalse ) ) );
       
   174 	    }
       
   175 
       
   176 	// AutoRegistration
       
   177 	if( HasBooleanL( KParamProfileAutoRegistration ) )
       
   178 	    {
       
   179 	    User::LeaveIfError( aProfile->SetParameter( KSIPAutoRegistration, 
       
   180 	                                                ExtractBooleanL( KParamProfileAutoRegistration, EFalse ) ) );
       
   181 	    }
       
   182 	    
       
   183 	// SecurityNegotiation
       
   184 	if( HasBooleanL( KParamProfileSecurityNegotiation ) )
       
   185 	    {
       
   186     	User::LeaveIfError( aProfile->SetParameter( KSIPSecurityNegotiation, 
       
   187     	                                            ExtractBooleanL( KParamProfileSecurityNegotiation, EFalse ) ) );
       
   188 	    }
       
   189 
       
   190 	// Server
       
   191 	do
       
   192 		{
       
   193 		structure = FindStructureL( KParamProfileServer, EFalse );
       
   194 		if( structure )
       
   195 			{
       
   196             User::LeaveIfError( aProfile->SetParameter( 
       
   197 			                        ServerL( structure ), 
       
   198 			                        KSIPServerAddress,
       
   199 			                        structure->ItemL( KParamProfileAddress )->Value() ) );
       
   200             
       
   201 			iContext.List().RemoveParameter( KParamProfileServer );
       
   202 			}
       
   203 		} while( structure );
       
   204 
       
   205 
       
   206 	// ServerParameter
       
   207 	do
       
   208 		{
       
   209 		structure = FindStructureL( KParamProfileServerParameter, EFalse );
       
   210 		if( structure )
       
   211 			{
       
   212 			User::LeaveIfError( aProfile->SetParameter( ServerL( structure ),
       
   213 										   ServerParameterL( structure ),
       
   214 										   structure->ItemL( 1 )->Value() ) );
       
   215 			iContext.List().RemoveParameter( KParamProfileServerParameter );
       
   216 			}
       
   217 		} while( structure );
       
   218 
       
   219 	// ServerExtensionParameter
       
   220 	do
       
   221 		{
       
   222 		structure = FindStructureL( KParamProfileServerExtensionParameter, EFalse );
       
   223 		if( structure )
       
   224 			{
       
   225 			CTcNameValue* item = structure->ItemL( 1 );
       
   226 			User::LeaveIfError( aProfile->SetParameter( ServerL( structure ),
       
   227 												        item->NameAsIntL(), item->Value() ) );
       
   228 			iContext.List().RemoveParameter( KParamProfileServerExtensionParameter );
       
   229 			}
       
   230 		} while( structure );
       
   231 
       
   232 	// ExtensionParameter
       
   233 	do
       
   234 		{
       
   235 		structure = FindStructureL( KParamProfileExtensionParameter, EFalse );
       
   236 		if( structure )
       
   237 			{
       
   238 			const CTcNameValue* item = structure->ItemL( 0 );
       
   239 			
       
   240 			TInt extInt( 0 );
       
   241 			TRAPD( err, extInt = item->ValueAsIntL() );
       
   242 			if ( !err )
       
   243 			    {
       
   244 			    User::LeaveIfError( 
       
   245 			        aProfile->SetParameter( item->NameAsIntL(), 
       
   246 			                                static_cast<TUint32>( extInt ) ) );
       
   247 			    }
       
   248 			else
       
   249 			    {
       
   250 			    TBool extBool( EFalse );
       
   251 			    TRAPD( err2, extBool = item->ValueAsBooleanL() );
       
   252 			    if ( !err2 )
       
   253 			        {
       
   254 			        User::LeaveIfError( aProfile->SetParameter( item->NameAsIntL(), extBool ) );
       
   255 			        }
       
   256 			    else
       
   257     			    {
       
   258     			    User::LeaveIfError( aProfile->SetParameter( item->NameAsIntL(), item->Value() ) );
       
   259     			    }
       
   260 			    }
       
   261 			    
       
   262 			iContext.List().RemoveParameter( KParamProfileExtensionParameter );
       
   263 			}
       
   264 		} while( structure );
       
   265 	
       
   266 	// Default
       
   267 	if( ExtractBooleanL( KParamProfileDefault, EFalse ) )
       
   268 	    {
       
   269 	    // Can set only to true
       
   270 	    User::LeaveIfError( aProfile->SetParameter( KSIPDefaultProfile, ETrue ) );
       
   271 	    }
       
   272 	    
       
   273 	}
       
   274 
       
   275 TBool TCmdCreateProfile::Match( const TTcIdentifier& aId )
       
   276 	{
       
   277 	return TTcSIPCommandBase::Match( aId, _L8("CreateProfile") );
       
   278 	}
       
   279 
       
   280 TTcCommandBase* TCmdCreateProfile::CreateL( MTcTestContext& aContext )
       
   281 	{
       
   282 	return new( ELeave ) TCmdCreateProfile( aContext );
       
   283 	}
       
   284 
       
   285 TUint32 TCmdCreateProfile::ServerL( CTcStructure* aStruct )
       
   286 	{
       
   287 	TUint32 server( KSIPRegistrar );
       
   288 	TPtrC8 value = aStruct->ItemL( KParamProfileServer )->Value();
       
   289 
       
   290 	if( value == KRegistrar )
       
   291 		{
       
   292 		server = KSIPRegistrar;
       
   293 		}
       
   294 	else if( value == KOutboundProxy )
       
   295 		{
       
   296 		server = KSIPOutboundProxy;
       
   297 		}
       
   298 	else
       
   299 		{
       
   300 		User::Leave( KTcErrMandatoryStructureItemNotFound );
       
   301 		}
       
   302 
       
   303 	return server;
       
   304 	}
       
   305 
       
   306 TUint32 TCmdCreateProfile::ServerParameterL( CTcStructure* aStruct )
       
   307 	{
       
   308 	TUint32 serverParameter = KSIPDigestRealm;
       
   309 	TPtrC8 value = aStruct->ItemL( 1 )->Name();
       
   310 
       
   311 	if( value == KDigestRealm )
       
   312 		{
       
   313 		serverParameter = KSIPDigestRealm;
       
   314 		}
       
   315 	else if( value == KDigestUsername )
       
   316 		{
       
   317 		serverParameter = KSIPDigestUserName;
       
   318 		}
       
   319 	else if( value == KDigestPassword )
       
   320 	    {
       
   321 	    serverParameter = KSIPDigestPassword;
       
   322 	    }
       
   323 	else
       
   324 		{
       
   325 		User::Leave( KTcErrMandatoryStructureItemNotFound );
       
   326 		}
       
   327 
       
   328 	return serverParameter;
       
   329 	}
       
   330 	
       
   331 TSIPProfileTypeInfo TCmdCreateProfile::ProfileTypeInfoL( CTcStructure* aStruct )
       
   332     {
       
   333 	TSIPProfileTypeInfo typeInfo;
       
   334 	TcLog::WriteFormat( _L8("-- Get mandatory structure item \"ProfileName\"") );
       
   335 	typeInfo.iSIPProfileName = aStruct->ItemL( KParamProfileName )->Value();
       
   336 	TcLog::Write( KLogOk );
       
   337 	
       
   338 	typeInfo.iSIPProfileClass = ProfileTypeClassL( aStruct );
       
   339 
       
   340 
       
   341 
       
   342     return typeInfo;
       
   343     }
       
   344     
       
   345 TSIPProfileTypeInfo::TSIPProfileClass 
       
   346     TCmdCreateProfile::ProfileTypeClassL( CTcStructure* aStruct )
       
   347 	{
       
   348 	TcLog::WriteFormat( _L8("-- Get mandatory structure item \"Class\"") );
       
   349 	
       
   350 	TSIPProfileTypeInfo::TSIPProfileClass typeClass = TSIPProfileTypeInfo::EInternet;
       
   351 	TPtrC8 value = aStruct->ItemL( KParamProfileClass )->Value();
       
   352 
       
   353 	if( value == KInternet )
       
   354 		{
       
   355 		typeClass = TSIPProfileTypeInfo::EInternet;
       
   356 		}
       
   357 	else if( value == KIms )
       
   358 		{
       
   359 		typeClass =  TSIPProfileTypeInfo::EIms;
       
   360 		}
       
   361 	else if( value == KOther )
       
   362 		{
       
   363 		typeClass =  TSIPProfileTypeInfo::EOther;
       
   364 		}
       
   365 	
       
   366 	else
       
   367 		{
       
   368 		User::Leave( KTcErrMandatoryStructureItemNotFound );
       
   369 		}
       
   370 	TcLog::Write( KLogOk );
       
   371 
       
   372 	return typeClass;
       
   373 	}