authorisation/userpromptservice/server/source/upsclient/rupssubsession.cpp
changeset 8 35751d3474b7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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 the License "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: 
       
    15 * RUpsSubsession implementation.	See class and function definitions
       
    16 * for more detail.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include <ups/upsclient.h>
       
    26 #include "upsclientconfig.h"
       
    27 #include "upscommon.h"
       
    28 #include <ups/upserr.h>
       
    29 
       
    30 namespace UserPromptService
       
    31 	{
       
    32 
       
    33 
       
    34 EXPORT_C RUpsSubsession::RUpsSubsession()
       
    35 /**
       
    36 	This constructor provides a single point of definition from
       
    37 	which the superclass constructor is called.
       
    38  */
       
    39 :	RScsClientSubsessionBase(),
       
    40 	iDecPtr(NULL, 0),
       
    41 	iSubsessionCreated(EFalse), iClientTid(), iClientSid(TUid::Null()), iClientPid(0), iUpsSession(0)
       
    42 	{
       
    43 	// empty.
       
    44 	}
       
    45 
       
    46 EXPORT_C TInt RUpsSubsession::Initialise(RUpsSession& aSession, const RThread& aClient)
       
    47 /**
       
    48 Saves the details required to create a subsession specific to the client thread.
       
    49 
       
    50 The actual subsession creation is defered until the subsession is required (which
       
    51 may be never if the policy says server checks are sufficient).
       
    52 
       
    53 Several RUpsSubsession objects can share a single RUpsSession.
       
    54 
       
    55 If any of the RUpsSubsession objects are to be used in a different thread to the RUpsSession, then
       
    56 ShareAuto() must be called on the RUpsSession.
       
    57 
       
    58 @see RSubSessionBase::CreateSubsession
       
    59 
       
    60 @param	aSession		Connected session to the UPS server.
       
    61 @param	aClient			SS client for whom this session is set up.
       
    62 @return					Symbian OS error code where KErrNone indicates success
       
    63 						and any other value indicates failure.
       
    64 */
       
    65 	{
       
    66 	iClientTid = aClient.Id();
       
    67 	iClientSid = aClient.SecureId();
       
    68 
       
    69 	// Need to obtain the drive letter for the exe
       
    70 	RProcess clientProcess;
       
    71 	TInt r = aClient.Process(clientProcess);
       
    72 	if(r != KErrNone)
       
    73 				{
       
    74 				return r; // Presumably it exited...
       
    75 				}
       
    76 	iClientPid = clientProcess.Id();
       
    77 	clientProcess.Close();
       
    78 	
       
    79 	iUpsSession = &aSession;
       
    80 	return KErrNone;
       
    81 	}
       
    82 
       
    83 TInt RUpsSubsession::CreateSubsession()
       
    84 /**
       
    85 	Create a subsession for a specific SS client over the supplied session.
       
    86 
       
    87 	@param	aSession		Connected session to the UPS server.
       
    88 	@param	aClient			SS client for whom this session is set up.
       
    89 	@return					Symbian OS error code where KErrNone indicates success
       
    90 							and any other value indicates failure.
       
    91 	@capability ProtServ 
       
    92  */
       
    93 	{
       
    94 	__ASSERT_ALWAYS(iUpsSession, User::Panic(KUpsClientPanicCat, EUpsClientNotInitialised));
       
    95 	TPckgBuf<TThreadId> tidBuf = iClientTid;
       
    96 	TPckgBuf<TProcessId> pidBuf = iClientPid;
       
    97 	TIpcArgs args(&tidBuf, &pidBuf);
       
    98 	return RScsClientSubsessionBase::CreateSubsession(*iUpsSession, ESessSubsessFromThreadId, args);
       
    99 	}
       
   100 
       
   101 EXPORT_C void RUpsSubsession::Authorise(TBool aServerCheckOk,
       
   102 										const TServiceId& aServiceId, const TDesC& aDestination,
       
   103 										TUpsDecision& aDecision, TRequestStatus& aStatus)
       
   104 /**
       
   105 	Determines whether the system server should perform the service requested
       
   106 	by the client application. Depending on licensee configuration this function
       
   107 	will either complete immediately if the client passed the system servers
       
   108 	security policy check. Alternatively, every request may require additional
       
   109 	authorisation by the User Prompt Service.
       
   110 	
       
   111 	@see RUpsSubsession::AuthoriseInternal
       
   112 
       
   113 	@param	aServerCheckOk	Whether the client request passed the security check
       
   114 							implemented by the system server e.g. does the client
       
   115 							have the correct capabilities for the requested service.
       
   116 	@param	aServiceId		Service which the client wants to use.
       
   117 	@param	aDestination	More information about the service, e.g. this
       
   118 							could be a telephone number is the client wanted
       
   119 							to make a call.
       
   120 	@param	aDecision		When the request completes successfully, the verdict
       
   121 							is written to this variable.
       
   122 	@param	aStatus			The server completes this request object when it
       
   123 							has finished handling the request.
       
   124 	@capability ProtServ 
       
   125  */
       
   126 	{
       
   127 	__ASSERT_ALWAYS(iUpsSession, User::Panic(KUpsClientPanicCat, EUpsClientNotInitialised));
       
   128 
       
   129 	AuthoriseInternal(aServerCheckOk, aServiceId, aDestination, KNullDesC8, aDecision, aStatus);
       
   130 	}
       
   131 
       
   132 EXPORT_C void RUpsSubsession::Authorise(TBool aServerCheckOk, 
       
   133 										const TServiceId& aServiceId, const TDesC& aDestination, 
       
   134 										const TDesC8& aOpaqueData, 
       
   135 										TUpsDecision& aDecision, TRequestStatus& aStatus)
       
   136 /**
       
   137 	Determines whether the system server should perform the service requested
       
   138 	by the client application. Depending on licensee configuration this function
       
   139 	will either complete immediately if the client passed the system servers
       
   140 	security policy check. Alternatively, every request may require additional
       
   141 	authorisation by the User Prompt Service.
       
   142 	
       
   143 	@see RUpsSubsession::AuthoriseInternal
       
   144 
       
   145 	@param	aServerCheckOk	Whether the client request passed the security check
       
   146 							implemented by the system server e.g. does the client
       
   147 							have the correct capabilities for the requested service.
       
   148 	@param	aServiceId		Service which the client wants to use.
       
   149 	@param	aDestination	More information about the service, e.g. this
       
   150 							could be a telephone number is the client wanted
       
   151 							to make a call.
       
   152 	@param	aOpaqueData		Additional information to describe the request.
       
   153 	@param	aDecision		When the request completes successfully, the verdict
       
   154 							is written to this variable.
       
   155 	@param	aStatus			The server completes this request object when it
       
   156 							has finished handling the request.
       
   157 	@capability ProtServ 
       
   158  */
       
   159 	{
       
   160 	__ASSERT_ALWAYS(iUpsSession, User::Panic(KUpsClientPanicCat, EUpsClientNotInitialised));
       
   161 
       
   162 	AuthoriseInternal(aServerCheckOk, aServiceId, aDestination, aOpaqueData, aDecision, aStatus);
       
   163 	}
       
   164 
       
   165 
       
   166 void RUpsSubsession::AuthoriseInternal(
       
   167 	TBool aServerCheckOk,
       
   168 	const TServiceId& aServiceId,
       
   169 	const TDesC& aDestination,
       
   170 	const TDesC8& aOpaqueData,
       
   171 	TUpsDecision& aDecision,
       
   172 	TRequestStatus& aStatus)
       
   173 /**
       
   174 	This helper function is called by the exported overloads of Authorise.
       
   175 	It sends the data supplied by the SS to the UPS server.
       
   176 
       
   177 	@param	aServerCheckOk	Did the system server checks pass?
       
   178 	@param	aServiceId		Service which the client wants to use.
       
   179 	@param	aDestination	More information about the service, e.g. this
       
   180 							could be a telephone number is the client wanted
       
   181 							to make a call.
       
   182 	@param	aOpaqueData		Additional information to describe the request.
       
   183 							This is KNullDesC8 if the SS used the Authorise overload
       
   184 							which did not take opaque data.
       
   185 	@param	aDecision		When the request completes successfully, the verdict
       
   186 							is written to this variable.
       
   187 	@param	aStatus			The server completes this request object when it
       
   188 							has finished handling the request.
       
   189 	@capability ProtServ 
       
   190  */
       
   191 	{
       
   192 	TBool decided = EFalse;
       
   193 	TInt err = KErrNone;	
       
   194 
       
   195 	__ASSERT_ALWAYS(iUpsSession, User::Panic(KUpsClientPanicCat, EUpsClientNotInitialised));
       
   196 	CUpsClientConfig::TQueryUpsResult result = iUpsSession->iClientConfig->QueryUps(aServerCheckOk, aServiceId, iClientSid, iClientPid);
       
   197 	switch(result)
       
   198 		{
       
   199 		case CUpsClientConfig::EAllow:
       
   200 			decided = ETrue;
       
   201 			aDecision = EUpsDecYes;
       
   202 			break;
       
   203 
       
   204 		case CUpsClientConfig::EQueryUps:
       
   205 			break;
       
   206 
       
   207 		case CUpsClientConfig::EReject:
       
   208 			decided = ETrue;
       
   209 			aDecision = EUpsDecNo;
       
   210 			break;
       
   211 		BULLSEYE_OFF
       
   212 		default:
       
   213 			break;	
       
   214 		}
       
   215 		BULLSEYE_RESTORE
       
   216 			
       
   217 	if(!decided && !iSubsessionCreated)
       
   218 		{
       
   219 		// We need to query the UPS, but have not created the subsession yet.
       
   220 		err = CreateSubsession();
       
   221 		if(err != KErrNone)
       
   222 			{
       
   223 			aDecision = EUpsDecNo;
       
   224 			decided = ETrue;
       
   225 			}
       
   226 		else
       
   227 			{
       
   228 			iSubsessionCreated = ETrue;
       
   229 			// aDecision will be set when we query the UPS
       
   230 			}
       
   231 		}
       
   232 
       
   233 	if(decided)
       
   234 		{
       
   235 		// Either do not need to query UPS, or an error occured, so complete client
       
   236 		// and return
       
   237 		aStatus = KRequestPending;
       
   238 		TRequestStatus* status = &aStatus;
       
   239 		User::RequestComplete(status, err);
       
   240 		return; // Either do not need to query UPS, or an error occured, so return
       
   241 		}
       
   242 
       
   243 	//
       
   244 	// Query UPS
       
   245 	//
       
   246 	// only three arguments can be sent to a subsession, so split
       
   247 	// this operation into two stages.
       
   248 
       
   249 	TInt r = PreparePrompt(aServiceId, aDestination, aOpaqueData);
       
   250 	if (r != KErrNone)
       
   251 		{
       
   252 		TRequestStatus* prs = &aStatus;
       
   253 		User::RequestComplete(prs, r);
       
   254 		return;
       
   255 		}
       
   256 	
       
   257 	ExecutePrompt(aServerCheckOk, aDecision, aStatus);
       
   258 	}
       
   259 
       
   260 TInt RUpsSubsession::PreparePrompt(const TServiceId& aServiceId, const TDesC& aDestination, const TDesC8& aOpaqueData)
       
   261 /**
       
   262 	Ask the UPS server to prepare to make a decision.  This will be followed
       
   263 	by a call to ExecutePrompt.
       
   264 
       
   265 	@param	aServiceId		Service which the client wants to use.
       
   266 	@param	aDestination	More information about the service, e.g. this
       
   267 							could be a telephone number is the client wanted
       
   268 							to make a call.
       
   269 	@param	aOpaqueData		Additional information to describe the request.
       
   270 							This is KNullDesC8 if the SS used the Authorise overload
       
   271 							which did not take opaque data.
       
   272 	@return					Error code with which the server completed the request.
       
   273 	@capability ProtServ 
       
   274 	@see ExecutePrompt
       
   275  */
       
   276 	{
       
   277 	TIpcArgs args(aServiceId.iUid, &aDestination, &aOpaqueData);
       
   278 	return CallSubsessionFunction(ESubsessPreparePrompt, args);
       
   279 	}
       
   280 
       
   281 void RUpsSubsession::ExecutePrompt(TBool aServerCheckOk, TUpsDecision& aDecision, TRequestStatus& aStatus)
       
   282 /**
       
   283 	Ask the UPS to execute the request which was set up with PreparePrompt.
       
   284 
       
   285 	@param	aDecision		When the request completes successfully, this argument
       
   286 							is updated with the verdict.
       
   287 	@param	aStatus			The server completes this request object when it
       
   288 							has finished handling the request.
       
   289 	@capability ProtServ 
       
   290 	@see PreparePrompt
       
   291  */
       
   292 	{
       
   293 	TUint8* decPtr = reinterpret_cast<TUint8*>(&aDecision);
       
   294 	iDecPtr.Set(decPtr, sizeof(TUpsDecision), sizeof(TUpsDecision));
       
   295 	
       
   296 	TIpcArgs args(&iDecPtr, aServerCheckOk);
       
   297 	CallSubsessionFunction(ESubsessExecutePrompt, args, aStatus);
       
   298 	}
       
   299 
       
   300 EXPORT_C void RUpsSubsession::CancelPrompt()
       
   301 /**
       
   302 	Cancel the prompt request which was launched by calling Authorise.
       
   303 
       
   304 	This function has no effect if there is no outstanding request.
       
   305 	@capability ProtServ 
       
   306  */
       
   307 	{
       
   308 	if(iSubsessionCreated)
       
   309 		{
       
   310 		CancelSubsessionFunction(ESubsessExecutePrompt);
       
   311 		}
       
   312 	}
       
   313 
       
   314 EXPORT_C void RUpsSubsession::Close()
       
   315 	/**
       
   316 	   Close and clean up this subsession object.
       
   317 	*/
       
   318 	{
       
   319 	if(iSubsessionCreated)
       
   320 		{
       
   321 		RScsClientSubsessionBase::Close();
       
   322 		}
       
   323 	}
       
   324 
       
   325 
       
   326 
       
   327 } // End of namespace UserPromptService
       
   328 
       
   329 // End of file