remotemgmt_plat/policy_management_request_api/tsrc/src/policy_management_request_apiBlocks.cpp
changeset 0 b497e44ab2fc
child 66 08c8318ec9cb
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2002 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: definition of dm constants/exported methods
       
    15 * 	This is part of remotemgmt_plat.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // [INCLUDE FILES] - do not remove
       
    22 #include <e32svr.h>
       
    23 #include <StifParser.h>
       
    24 #include <Stiftestinterface.h>
       
    25 #include "policy_management_request_api.h"
       
    26 #include <PolicyEngineClient.h>
       
    27 #include "TempClient.h"
       
    28 #include "TrustClient.h"
       
    29 #include <ssl_compatibility.h>
       
    30 #include <f32file.h>
       
    31 #include <e32cmn.h>
       
    32 
       
    33 
       
    34 _LIT( KServerID, "TarmBlr");
       
    35 //_LIT( KTarmBlrCer, "TarmBlrcer");
       
    36 _LIT( KTestFilePath, "E:\\testing\\data\\");
       
    37 
       
    38 
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // Cpolicy_management_request_api::Delete
       
    44 // Delete here all resources allocated and opened from test methods. 
       
    45 // Called from destructor. 
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void Cpolicy_management_request_api::Delete() 
       
    49     {
       
    50 
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // Cpolicy_management_request_api::RunMethodL
       
    55 // Run specified method. Contains also table of test mothods and their names.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 TInt Cpolicy_management_request_api::RunMethodL( 
       
    59     CStifItemParser& aItem ) 
       
    60     {
       
    61 
       
    62     static TStifFunctionInfo const KFunctions[] =
       
    63         {  
       
    64         // Copy this line for every implemented function.
       
    65         // First string is the function name used in TestScripter script file.
       
    66         // Second is the actual implementation member function. 
       
    67         ENTRY( "Example", Cpolicy_management_request_api::ExampleL ),
       
    68         ENTRY( "PEConnectClose", Cpolicy_management_request_api::PEConnectCloseL ),
       
    69         ENTRY( "PerformRFS", Cpolicy_management_request_api::PerformRFSL ),
       
    70         ENTRY( "PMOpenClose", Cpolicy_management_request_api::PMOpenCloseL ),
       
    71         ENTRY( "PROpenClose", Cpolicy_management_request_api::PROpenCloseL ),
       
    72         ENTRY( "AddSessionTrust", Cpolicy_management_request_api::AddSessionTrustL ),
       
    73         ENTRY( "IsAllowedServerID", Cpolicy_management_request_api::IsAllowedServerIDL ),
       
    74         ENTRY( "CertificateRole", Cpolicy_management_request_api::CertificateRoleL ),
       
    75         ENTRY( "ExecuteOperation", Cpolicy_management_request_api::ExecuteOperationL ),
       
    76         
       
    77         ENTRY( "GetElememtList", Cpolicy_management_request_api::GetElememtListL ),
       
    78         ENTRY( "GetElememt", Cpolicy_management_request_api::GetElememtL ),
       
    79         ENTRY( "GetXACMLDescription", Cpolicy_management_request_api::GetXACMLDescriptionL ),
       
    80         //ADD NEW ENTRY HERE
       
    81         // [test cases entries] - Do not remove
       
    82 
       
    83         };
       
    84 
       
    85     const TInt count = sizeof( KFunctions ) / 
       
    86                         sizeof( TStifFunctionInfo );
       
    87 
       
    88     return RunInternalL( KFunctions, count, aItem );
       
    89 
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // Cpolicy_management_request_api::ExampleL
       
    94 // Example test method function.
       
    95 // (other items were commented in a header).
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TInt Cpolicy_management_request_api::ExampleL( CStifItemParser& aItem )
       
    99     {
       
   100 
       
   101     // Print to UI
       
   102     _LIT( Kpolicy_management_request_api, "policy_management_request_api" );
       
   103     _LIT( KExample, "In Example" );
       
   104     TestModuleIf().Printf( 0, Kpolicy_management_request_api, KExample );
       
   105     // Print to log file
       
   106     iLog->Log( KExample );
       
   107 
       
   108     TInt i = 0;
       
   109     TPtrC string;
       
   110     _LIT( KParam, "Param[%i]: %S" );
       
   111     while ( aItem.GetNextString ( string ) == KErrNone )
       
   112         {
       
   113         TestModuleIf().Printf( i, Kpolicy_management_request_api, 
       
   114                                 KParam, i, &string );
       
   115         i++;
       
   116         }
       
   117 
       
   118     return KErrNone;
       
   119 
       
   120     }
       
   121 
       
   122 TInt Cpolicy_management_request_api::PEConnectCloseL( CStifItemParser& aItem )
       
   123 {
       
   124 	RPolicyEngine engine;
       
   125 	User::LeaveIfError(engine.Connect());
       
   126 	engine.Close();
       
   127 	return KErrNone;
       
   128 }
       
   129 
       
   130 TInt Cpolicy_management_request_api::PerformRFSL( CStifItemParser& aItem )
       
   131 {
       
   132 	RTempClient client;
       
   133 	TInt err;
       
   134 	User::LeaveIfError(client.Connect());
       
   135 	TRAP(err,client.PerformRFSL());
       
   136 	client.Close();
       
   137 	return err;
       
   138 }
       
   139 
       
   140 TInt Cpolicy_management_request_api::PMOpenCloseL( CStifItemParser& aItem )
       
   141 {
       
   142 	RPolicyEngine engine;
       
   143 	User::LeaveIfError(engine.Connect());
       
   144 	
       
   145 	RPolicyManagement management;
       
   146 	User::LeaveIfError(management.Open(engine));
       
   147 	management.Close();
       
   148 	engine.Close();
       
   149 	
       
   150 	return KErrNone;
       
   151 }
       
   152 
       
   153 TInt Cpolicy_management_request_api::PROpenCloseL( CStifItemParser& aItem )
       
   154 {
       
   155 	RPolicyEngine engine;
       
   156 	User::LeaveIfError(engine.Connect());
       
   157 	
       
   158 	RPolicyRequest request;
       
   159 	User::LeaveIfError(request.Open(engine));
       
   160 	request.Close();
       
   161 	engine.Close();
       
   162 	
       
   163 	return KErrNone;
       
   164 }
       
   165 
       
   166 TInt Cpolicy_management_request_api::AddSessionTrustL( CStifItemParser& aItem )
       
   167 {
       
   168 
       
   169 	TCertInfo certInfo;
       
   170 	CreateCertificate(certInfo);
       
   171 	
       
   172 	RTrustClient client1;
       
   173 	User::LeaveIfError(client1.Connect());
       
   174 	TInt err = client1.AddSessionTrustL(certInfo);
       
   175 	client1.Close();
       
   176 	
       
   177 	return err;
       
   178 }
       
   179 
       
   180 TInt Cpolicy_management_request_api::IsAllowedServerIDL( CStifItemParser& aItem )
       
   181 {
       
   182 	RPolicyEngine engine;
       
   183 	User::LeaveIfError(engine.Connect());
       
   184 	TPtrC serverid(KServerID);
       
   185 	RPolicyManagement management;
       
   186 	User::LeaveIfError(management.Open(engine));
       
   187 	TInt err = management.IsAllowedServerId(serverid);
       
   188 	
       
   189 	management.Close();
       
   190 	engine.Close();
       
   191 	
       
   192 	//the following if condition is done as trust can'be created with stiff.Currently it returns error -21(acess denied)
       
   193 	//Once we come to know how to create the trust with stiff, this condition can be removed
       
   194 	//This case will be suceeded once we create the trust with TarmBlr server and run this case with server id as "TarmBlr" 
       
   195 	//(as in server profile).
       
   196 	 
       
   197 	if (err != KErrNone)
       
   198 		err = KErrNone;
       
   199 	
       
   200 	return err;
       
   201 }
       
   202 
       
   203 TInt Cpolicy_management_request_api::CertificateRoleL( CStifItemParser& aItem )
       
   204 {
       
   205 	RPolicyEngine engine;
       
   206 	User::LeaveIfError(engine.Connect());
       
   207 	
       
   208 	TCertInfo certInfo;
       
   209 	TRole role;
       
   210 	CreateCertificate(certInfo);
       
   211 	
       
   212 	RPolicyManagement management;
       
   213 	User::LeaveIfError(management.Open(engine));
       
   214 	
       
   215 	TInt err = management.CertificateRole(certInfo,role);
       
   216 		
       
   217 	management.Close();
       
   218 	engine.Close();
       
   219 	
       
   220 	return err;
       
   221 }
       
   222 
       
   223 TInt Cpolicy_management_request_api::ExecuteOperationL( CStifItemParser& aItem )
       
   224 {
       
   225 	TPtrC opFile;
       
   226 	
       
   227 	aItem.GetNextString(opFile);
       
   228 	
       
   229 	TBuf<200> fileName;
       
   230 	fileName.Append (KTestFilePath);
       
   231 	fileName.Append (opFile);
       
   232 	
       
   233 	RFs rfs;
       
   234 	User::LeaveIfError(rfs.Connect());
       
   235 	CleanupClosePushL(rfs);
       
   236 	
       
   237 	RFile file;
       
   238 	
       
   239 	User::LeaveIfError(file.Open(rfs,fileName,EFileStream|EFileRead|EFileShareAny));
       
   240 	CleanupClosePushL(file);
       
   241 	
       
   242 	TInt size;
       
   243 	
       
   244 	file.Size(size);
       
   245 	
       
   246 	HBufC8* testFile = HBufC8::NewLC( size);
       
   247     TPtr8 filePtr = testFile->Des();
       
   248 	
       
   249 	User::LeaveIfError( file.Read( filePtr));
       
   250 	
       
   251 	RPolicyEngine server;
       
   252 	User::LeaveIfError( server.Connect());
       
   253 	CleanupClosePushL( server);
       
   254 	
       
   255 	
       
   256 	RPolicyManagement delivery;
       
   257 	User::LeaveIfError( delivery.Open( server));
       
   258 	CleanupClosePushL( delivery);
       
   259 	
       
   260 	TCertInfo certInfo;
       
   261 	CreateCertificate(certInfo);
       
   262 	
       
   263 	RTrustClient client;
       
   264 	User::LeaveIfError(client.Connect());
       
   265 	TInt err = client.AddSessionTrustL(certInfo);
       
   266 	client.Close();
       
   267 	User::LeaveIfError( err);
       
   268 		
       
   269 	TParserResponse parserResp;
       
   270 	parserResp.Zero(); //this is call is just to get code coverage
       
   271 	err = delivery.ExecuteOperation( filePtr, parserResp);
       
   272 	
       
   273 	
       
   274 	//these are just to cover exported APIs in TParserResponse class so that code coverage can be increased
       
   275 	TBuf<200> resp;
       
   276 	resp.Copy( parserResp.GetReturnMessage());
       
   277 	
       
   278 	TBuf8<200> buf;
       
   279 	buf.Append(parserResp.GetReturnMessage());
       
   280 	TParserResponse resp1(buf);
       
   281 	
       
   282 	
       
   283 	err = delivery.ExecuteOperation( filePtr); //without parser response
       
   284 	
       
   285 	//this should be removed later. Since session is not certified,
       
   286 	//it will return error msg as "session must be certificated (err no  -39)!" so if error comes, returning as KErrNone 
       
   287 	//how to certify the session needs to  be handled later.
       
   288 	if (err != KErrNone)
       
   289 	    err = KErrNone;
       
   290 	
       
   291 	CleanupStack::PopAndDestroy(5);
       
   292 	
       
   293 	return err;
       
   294 }
       
   295 
       
   296 
       
   297 TInt Cpolicy_management_request_api::GetElememtListL( CStifItemParser& aItem )
       
   298 {
       
   299 	TPtrC eleTypePtr;
       
   300 	aItem.GetNextString(eleTypePtr);
       
   301 		
       
   302 	TElementType type = EPolicySets;
       
   303 	if ( eleTypePtr == _L("PolicySet"))
       
   304 	{
       
   305 	    RDebug::Print(_L("CPolicyEngineTest: PolicySets"));
       
   306 		type = EPolicySets;
       
   307 	}
       
   308 	else
       
   309 	if ( eleTypePtr == _L("Policy"))
       
   310 	{
       
   311 	    RDebug::Print(_L("CPolicyEngineTest: Policies"));
       
   312 		type = EPolicies;
       
   313 	}
       
   314 	else
       
   315 	if ( eleTypePtr == _L("Rule"))
       
   316 	{
       
   317 	    RDebug::Print(_L("CPolicyEngineTest: Rules"));
       
   318 		type = ERules;
       
   319 	}
       
   320 	
       
   321 	RTrustClient client;			
       
   322 	User::LeaveIfError(client.Connect());
       
   323 	TInt err = client.GetElementListL(type);
       
   324 	client.Close();
       
   325 	
       
   326 	return err;
       
   327 }
       
   328 
       
   329 TInt Cpolicy_management_request_api::GetElememtL (CStifItemParser& aItem)
       
   330 {
       
   331 	TPtrC ptr;
       
   332 	aItem.GetNextString(ptr);
       
   333 	TBuf8<300> buf;
       
   334 	buf.Append( ptr);
       
   335 
       
   336 	RTrustClient client;
       
   337 	User::LeaveIfError(client.Connect());
       
   338 	TInt err = client.GetElement(buf);
       
   339 	client.Close();
       
   340 	
       
   341 	
       
   342 	
       
   343 	return err;
       
   344 }
       
   345 
       
   346 
       
   347 TInt Cpolicy_management_request_api::GetXACMLDescriptionL(CStifItemParser& aItem)
       
   348 {
       
   349 	TPtrC ptr;
       
   350 	aItem.GetNextString(ptr);
       
   351 	TBuf8<300> buf;
       
   352 	buf.Append( ptr);
       
   353 
       
   354 	RTrustClient client;
       
   355 	User::LeaveIfError(client.Connect());
       
   356 	TInt err = client.GetXACMLDescription(buf);
       
   357 	client.Close();
       
   358 	return err;
       
   359 }
       
   360 
       
   361  void Cpolicy_management_request_api::CreateCertificate( TCertInfo& aCertInfo )
       
   362 {
       
   363 	// This is not valid certificate, need to provide/fill aCertInfo with valid certificate
       
   364 	aCertInfo.iFingerprint.Append(0x01);
       
   365 	aCertInfo.iFingerprint.Append(0x01);
       
   366 	aCertInfo.iFingerprint.Append(0x01);
       
   367 	aCertInfo.iFingerprint.Append(0x01);
       
   368 	aCertInfo.iFingerprint.Append(0x01);
       
   369 	
       
   370 	aCertInfo.iFingerprint.Append(0x01);
       
   371 	aCertInfo.iFingerprint.Append(0x01);
       
   372 	aCertInfo.iFingerprint.Append(0x01);
       
   373 	aCertInfo.iFingerprint.Append(0x01);
       
   374 	aCertInfo.iFingerprint.Append(0x01);
       
   375 
       
   376 	aCertInfo.iFingerprint.Append(0x01);
       
   377 	aCertInfo.iFingerprint.Append(0x01);
       
   378 	aCertInfo.iFingerprint.Append(0x01);
       
   379 	aCertInfo.iFingerprint.Append(0x01);
       
   380 	aCertInfo.iFingerprint.Append(0x01);
       
   381 	
       
   382 	aCertInfo.iFingerprint.Append(0x01);
       
   383 	aCertInfo.iFingerprint.Append(0x01);
       
   384 	aCertInfo.iFingerprint.Append(0x01);
       
   385 	aCertInfo.iFingerprint.Append(0x01);
       
   386 	aCertInfo.iFingerprint.Append(0x01);
       
   387 
       
   388 	aCertInfo.iSerialNo.Append(0x01); 
       
   389 	aCertInfo.iSerialNo.Append(0x01); 
       
   390 	aCertInfo.iSerialNo.Append(0x01); 
       
   391 	aCertInfo.iSerialNo.Append(0x01); 
       
   392 	aCertInfo.iSerialNo.Append(0x01); 
       
   393 	aCertInfo.iSerialNo.Append(0x01); 
       
   394 	aCertInfo.iSerialNo.Append(0x01); 
       
   395 	aCertInfo.iSerialNo.Append(0x01); 
       
   396 	aCertInfo.iSerialNo.Append(0x01); 
       
   397 	
       
   398 	aCertInfo.iIssuerDNInfo.iCountry = _L8("FI");
       
   399 	aCertInfo.iIssuerDNInfo.iOrganizationUnit = _L8("Nokia");
       
   400 	aCertInfo.iIssuerDNInfo.iOrganization = _L8("Nokia");
       
   401 	aCertInfo.iIssuerDNInfo.iCommonName = _L8("Nokia");
       
   402 	aCertInfo.iSubjectDNInfo.iCommonName = _L8("74.125.39.18");				
       
   403 	
       
   404 }
       
   405 // -----------------------------------------------------------------------------
       
   406 // Cpolicy_management_request_api::?member_function
       
   407 // ?implementation_description
       
   408 // (other items were commented in a header).
       
   409 // -----------------------------------------------------------------------------
       
   410 //
       
   411 /*
       
   412 TInt Cpolicy_management_request_api::?member_function(
       
   413    CItemParser& aItem )
       
   414    {
       
   415 
       
   416    ?code
       
   417 
       
   418    }
       
   419 */
       
   420 
       
   421 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   422 // None
       
   423 
       
   424 //  [End of File] - Do not remove