os/security/authorisation/userpromptservice/server/source/upsserver/upssubsession.cpp
First public contribution.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Implements CUpsSession. See class and function definitions for
25 #include "upsserver.h"
26 #include "authoriser.h"
27 #include <ups/upserr.h>
29 namespace UserPromptService
32 CUpsSubsession* CUpsSubsession::NewL(CUpsSession &aSession, const RMessage2& aMessage)
34 Factory function allocates a new, initialized instance of CUpsSubsession.
36 @param aMessage Standard server-side handle to message.
37 @return New, initialized instance of CUpsSubsession which
38 is owned by the caller.
41 CUpsSubsession* self = new(ELeave) CUpsSubsession(aSession);
42 // Note that CUpsSubsession ulitmately derives from CObject and therefore it MUST NOT be deleted directly,
43 // instead it should be closed if we leave.
44 // nb. CUpsSession does NOT derive from CObject...
45 CleanupClosePushL(*self);
46 self->ConstructL(aMessage);
47 CleanupStack::Pop(self);
51 CUpsSubsession::CUpsSubsession(CUpsSession &aSession)
53 This private constructor prevents direct instantiation and provides
54 a single point of definition from which to call the superclass c'tor.
56 : CScsSubsession(aSession)
59 //RDebug::Printf("0x%x CUpsSubsession(session %x)\n", this, &aSession);
62 void CUpsSubsession::ConstructL(const RMessage2& aMessage)
64 Initialize this subsession object by opening a handle to the
65 thread whose identifier has been sent.
67 @param aSession Ref to session creating us
68 @param aMessage Standard server-side handle to message.
71 // ARGS: TThreadId, TProcessId
73 TPckg<TThreadId> tidBuf(iClientTid);
74 aMessage.ReadL(0, tidBuf);
76 TPckg<TProcessId> pidBuf(iClientPid);
77 aMessage.ReadL(1, pidBuf);
80 CUpsSubsession::~CUpsSubsession()
82 Close this object's handle to the SS client thread.
85 //RDebug::Printf("0x%x ~CUpsSubsession()\n", this);
90 TBool CUpsSubsession::DoServiceL(TInt aFunction, const RMessage2& aMessage)
92 Implement CScsSubsession by handling the supplied message.
94 @param aFunction Function identifier without SCS code.
95 @param aMessage Standard server-side handle to message.
96 @return ETrue means complete client request now.
99 UserPromptService::TSubsessionFunction f =
100 static_cast<UserPromptService::TSubsessionFunction>(aFunction);
101 //RDebug::Printf("0x%x CUpsSubsession::DoServiceL function %d\n", this, f);
104 case UserPromptService::ESubsessPreparePrompt:
105 PreparePromptL(aMessage);
108 case UserPromptService::ESubsessExecutePrompt:
109 ExecutePromptL(aMessage);
110 return EFalse; // If ExecutePrompt returns, instead of leaving, it must have setup an async req
113 User::Leave(KErrNotSupported);
120 void CUpsSubsession::PreparePromptL(const RMessage2& aMessage)
122 Save service, description, and opaque data for use in the
123 following execute prompt command.
126 // TIpcArgs is TServiceId aServiceId, const TDesC* aDestination, const TDesC8* aOpaqueData
128 iServiceId.iUid = aMessage.Int0();
131 TInt destinationLength = aMessage.GetDesLengthL(1);
132 iDestination.Close();
133 iDestination.CreateL(destinationLength);
134 aMessage.ReadL(1, iDestination);
137 TInt opaqueDataLength = aMessage.GetDesLengthL(2);
141 iOpaqueData.CreateL(opaqueDataLength);
142 aMessage.ReadL(2, iOpaqueData);
146 void CUpsSubsession::ExecutePromptL(const RMessage2& aMessage)
148 Create and start the CAuthoriser to process the request.
151 // TIpcArgs is OUT:TUpsDecision& aDecision, IN:TBool aServerCheckOk
153 // The authorizer object is derived from CAsyncRequest and its
154 // lifecycle is automatically managed by the SCS framework
156 // iDestination and iOpaqueData are transfered to the CAuthoriser,
157 // our handles will be closed.
158 TBool serverCheckOk = aMessage.Int1();
159 CUpsSession *session = static_cast<CUpsSession*>(&iSession);
160 RPolicyCacheCountedHandle &cacheManager = session->UpsServer()->iPolicyCache;
161 CleanupReleasePushL(cacheManager);
162 if(!cacheManager.IsOpen())
164 cacheManager.OpenL();
166 CAuthoriser *authoriser = CAuthoriser::NewL(cacheManager,
167 session, this, serverCheckOk,
168 iClientTid, iClientPid,
169 aMessage, iServiceId, iDestination, iOpaqueData);
170 CleanupStack::Pop(&cacheManager); // transfered ownership to the new CAuthoriser
171 CleanupStack::PushL(authoriser);
172 authoriser->TransferToScsFrameworkL();
173 CleanupStack::Pop(authoriser); // authoriser now owned by SCS framework
176 The authoriser is now responsible for completing the request,
177 so we must NOT leave.
179 We could start the request processing off by calling an
180 authoriser function from within a TRAP handler, but for future
181 proofing we tell the authoriser to self complete so the
182 processing all happens within the active scheduler framework
183 and the authoriser state machine. This will make it much easier
184 to completly restart request processing (if we decide to when
185 policies are changed).
187 authoriser->Wakeup();
191 } // End of namespace UserPromptService