os/security/authorisation/userpromptservice/server/source/upsserver/upssubsession.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/authorisation/userpromptservice/server/source/upsserver/upssubsession.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,192 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Implements CUpsSession. See class and function definitions for
1.19 +* more information.
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +/**
1.25 + @file
1.26 +*/
1.27 +
1.28 +#include "upsserver.h"
1.29 +#include "authoriser.h"
1.30 +#include <ups/upserr.h>
1.31 +
1.32 +namespace UserPromptService
1.33 +{
1.34 +
1.35 +CUpsSubsession* CUpsSubsession::NewL(CUpsSession &aSession, const RMessage2& aMessage)
1.36 +/**
1.37 + Factory function allocates a new, initialized instance of CUpsSubsession.
1.38 +
1.39 + @param aMessage Standard server-side handle to message.
1.40 + @return New, initialized instance of CUpsSubsession which
1.41 + is owned by the caller.
1.42 + */
1.43 + {
1.44 + CUpsSubsession* self = new(ELeave) CUpsSubsession(aSession);
1.45 + // Note that CUpsSubsession ulitmately derives from CObject and therefore it MUST NOT be deleted directly,
1.46 + // instead it should be closed if we leave.
1.47 + // nb. CUpsSession does NOT derive from CObject...
1.48 + CleanupClosePushL(*self);
1.49 + self->ConstructL(aMessage);
1.50 + CleanupStack::Pop(self);
1.51 + return self;
1.52 + }
1.53 +
1.54 +CUpsSubsession::CUpsSubsession(CUpsSession &aSession)
1.55 +/**
1.56 + This private constructor prevents direct instantiation and provides
1.57 + a single point of definition from which to call the superclass c'tor.
1.58 + */
1.59 +: CScsSubsession(aSession)
1.60 + {
1.61 + // empty.
1.62 + //RDebug::Printf("0x%x CUpsSubsession(session %x)\n", this, &aSession);
1.63 + }
1.64 +
1.65 +void CUpsSubsession::ConstructL(const RMessage2& aMessage)
1.66 +/**
1.67 + Initialize this subsession object by opening a handle to the
1.68 + thread whose identifier has been sent.
1.69 +
1.70 + @param aSession Ref to session creating us
1.71 + @param aMessage Standard server-side handle to message.
1.72 + */
1.73 + {
1.74 + // ARGS: TThreadId, TProcessId
1.75 +
1.76 + TPckg<TThreadId> tidBuf(iClientTid);
1.77 + aMessage.ReadL(0, tidBuf);
1.78 +
1.79 + TPckg<TProcessId> pidBuf(iClientPid);
1.80 + aMessage.ReadL(1, pidBuf);
1.81 + }
1.82 +
1.83 +CUpsSubsession::~CUpsSubsession()
1.84 +/**
1.85 + Close this object's handle to the SS client thread.
1.86 + */
1.87 + {
1.88 + //RDebug::Printf("0x%x ~CUpsSubsession()\n", this);
1.89 + iDestination.Close();
1.90 + iOpaqueData.Close();
1.91 + }
1.92 +
1.93 +TBool CUpsSubsession::DoServiceL(TInt aFunction, const RMessage2& aMessage)
1.94 +/**
1.95 + Implement CScsSubsession by handling the supplied message.
1.96 +
1.97 + @param aFunction Function identifier without SCS code.
1.98 + @param aMessage Standard server-side handle to message.
1.99 + @return ETrue means complete client request now.
1.100 + */
1.101 + {
1.102 + UserPromptService::TSubsessionFunction f =
1.103 + static_cast<UserPromptService::TSubsessionFunction>(aFunction);
1.104 + //RDebug::Printf("0x%x CUpsSubsession::DoServiceL function %d\n", this, f);
1.105 + switch (f)
1.106 + {
1.107 + case UserPromptService::ESubsessPreparePrompt:
1.108 + PreparePromptL(aMessage);
1.109 + break;
1.110 +
1.111 + case UserPromptService::ESubsessExecutePrompt:
1.112 + ExecutePromptL(aMessage);
1.113 + return EFalse; // If ExecutePrompt returns, instead of leaving, it must have setup an async req
1.114 + BULLSEYE_OFF
1.115 + default:
1.116 + User::Leave(KErrNotSupported);
1.117 + break;
1.118 + BULLSEYE_RESTORE
1.119 + }
1.120 + return ETrue;
1.121 + }
1.122 +
1.123 +void CUpsSubsession::PreparePromptL(const RMessage2& aMessage)
1.124 + /**
1.125 + Save service, description, and opaque data for use in the
1.126 + following execute prompt command.
1.127 + */
1.128 + {
1.129 + // TIpcArgs is TServiceId aServiceId, const TDesC* aDestination, const TDesC8* aOpaqueData
1.130 +
1.131 + iServiceId.iUid = aMessage.Int0();
1.132 +
1.133 + // Get Description
1.134 + TInt destinationLength = aMessage.GetDesLengthL(1);
1.135 + iDestination.Close();
1.136 + iDestination.CreateL(destinationLength);
1.137 + aMessage.ReadL(1, iDestination);
1.138 +
1.139 + // Get Opaque Data
1.140 + TInt opaqueDataLength = aMessage.GetDesLengthL(2);
1.141 + iOpaqueData.Close();
1.142 + if(opaqueDataLength)
1.143 + {
1.144 + iOpaqueData.CreateL(opaqueDataLength);
1.145 + aMessage.ReadL(2, iOpaqueData);
1.146 + }
1.147 + }
1.148 +
1.149 +void CUpsSubsession::ExecutePromptL(const RMessage2& aMessage)
1.150 + /**
1.151 + Create and start the CAuthoriser to process the request.
1.152 + */
1.153 + {
1.154 + // TIpcArgs is OUT:TUpsDecision& aDecision, IN:TBool aServerCheckOk
1.155 +
1.156 + // The authorizer object is derived from CAsyncRequest and its
1.157 + // lifecycle is automatically managed by the SCS framework
1.158 + //
1.159 + // iDestination and iOpaqueData are transfered to the CAuthoriser,
1.160 + // our handles will be closed.
1.161 + TBool serverCheckOk = aMessage.Int1();
1.162 + CUpsSession *session = static_cast<CUpsSession*>(&iSession);
1.163 + RPolicyCacheCountedHandle &cacheManager = session->UpsServer()->iPolicyCache;
1.164 + CleanupReleasePushL(cacheManager);
1.165 + if(!cacheManager.IsOpen())
1.166 + {
1.167 + cacheManager.OpenL();
1.168 + }
1.169 + CAuthoriser *authoriser = CAuthoriser::NewL(cacheManager,
1.170 + session, this, serverCheckOk,
1.171 + iClientTid, iClientPid,
1.172 + aMessage, iServiceId, iDestination, iOpaqueData);
1.173 + CleanupStack::Pop(&cacheManager); // transfered ownership to the new CAuthoriser
1.174 + CleanupStack::PushL(authoriser);
1.175 + authoriser->TransferToScsFrameworkL();
1.176 + CleanupStack::Pop(authoriser); // authoriser now owned by SCS framework
1.177 +
1.178 + /**
1.179 + The authoriser is now responsible for completing the request,
1.180 + so we must NOT leave.
1.181 +
1.182 + We could start the request processing off by calling an
1.183 + authoriser function from within a TRAP handler, but for future
1.184 + proofing we tell the authoriser to self complete so the
1.185 + processing all happens within the active scheduler framework
1.186 + and the authoriser state machine. This will make it much easier
1.187 + to completly restart request processing (if we decide to when
1.188 + policies are changed).
1.189 + */
1.190 + authoriser->Wakeup();
1.191 + }
1.192 +
1.193 +
1.194 +} // End of namespace UserPromptService
1.195 +// End of file