os/security/authorisation/userpromptservice/server/source/upsserver/upssession.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 "policycache.h"
27 #include <ups/upsdbw.h>
28 #include <scs/ipcstream.h>
29 #include <scs/nullstream.h>
30 #include "pluginmanager.h"
31 #include "viewevaluator.h"
32 #include "updateevaluator.h"
33 #include "policychangeevaluator.h"
35 namespace UserPromptService
38 CUpsSession* CUpsSession::NewL(CUpsServer &aServer)
40 Factory function allocates new instance of CUpsSession.
42 @return New, initialized instance of CUpsSession
43 which is owned by the caller.
46 CUpsSession* self = new(ELeave) CUpsSession(aServer);
47 CleanupStack::PushL(self);
48 self->ConstructL(); // CScsSession implementation
49 CleanupStack::Pop(self);
53 CUpsSession::CUpsSession(CUpsServer &aServer)
55 This private constructor prevents direct instantiation.
57 : CScsSession(aServer), iDbViewHandle(aServer.iDbHandle, this)
60 //RDebug::Printf("0x%x CUpsSession(server %x) (&iDbViewHandle %x)\n", this, &aServer, &iDbViewHandle);
63 CUpsSession::~CUpsSession()
65 The base class destructor destroys any remaining subsessions
66 or outstanding requests.
69 //RDebug::Printf("0x%x ~CUpsSession (&iDbViewHandle %x)\n", this, &iDbViewHandle);
71 iServiceConfig.Close();
73 iDbViewHandle.Close();
76 TBool CUpsSession::DoServiceL(TInt aFunction, const RMessage2& aMessage)
78 Implement CScsSession by handling the supplied message.
80 Note the subsession creation command is automatically sent to
81 DoCreateSubsessionL, and not this function.
83 @param aFunction Function identifier without SCS code.
84 @param aMessage Standard server-side handle to message. Not used.
87 TSessionFunction f = static_cast<TSessionFunction>(aFunction);
88 //RDebug::Printf("0x%x CUpsSession::DoServiceL function %d\n", this, f);
91 case EGetClientConfigLength:
93 iServiceConfig.Close();
94 UpsServer()->iPolicyCache->ServiceConfigL(aMessage.SecureId(), iServiceConfig);
96 TPckgBuf<TInt> lengthBuf;
97 lengthBuf() = iServiceConfig.Count();
98 aMessage.WriteL(0, lengthBuf);
99 return ETrue; // Complete request with KErrNone
102 case EGetClientConfigData:
104 TInt count = iServiceConfig.Count();
105 for(TInt i=0; i < count; ++i)
107 const TServiceConfig &sc = iServiceConfig[i];
108 TPtrC8 ptr((TUint8 *) &sc, sizeof(TServiceConfig));
109 aMessage.WriteL(0, ptr, i*sizeof(TServiceConfig));
111 iServiceConfig.Close();
112 return ETrue; // Complete request with KErrNone
115 case EDeleteDatabase:
116 TRAPD(err, UpsServer()->iDbHandle->DeleteDatabaseL(UpsServer()->iFs));
117 UpsServer()->iDbHandle.Close();
118 User::LeaveIfError(err);
119 return ETrue; // Complete request with KErrNone
123 if(iManagementView != 0)
125 User::Leave(KErrServerBusy);
128 CViewEvaluator *viewEvaluator = CViewEvaluator::NewLC(this, aMessage);
129 viewEvaluator->TransferToScsFrameworkL();
130 CleanupStack::Pop(viewEvaluator); // view now owned by SCS framework
133 The CViewEvaluator is now responsible for completing the request,
134 so we must NOT leave.
136 viewEvaluator->StartEvaluatingView();
137 return EFalse; // Do not complete client request - view evaulator will...
142 if((iManagementView == 0) || (iRecord == 0))
144 User::Leave(KErrAbort);
147 // Copy the record to arg 0
148 RIpcWriteStream ipcstream;
149 ipcstream.Open(aMessage, 0);
150 CleanupClosePushL(ipcstream);
152 ipcstream << *iRecord;
154 CleanupStack::PopAndDestroy(&ipcstream);
156 // Update arg 1 with the length of the next record.
157 PrefetchRecordAndWriteLengthToClientL(aMessage);
158 return ETrue; // Complete client request with KErrNone
164 return ETrue; // Complete client request with KErrNone
167 case ERemoveDecisions:
169 // Read filter from the client arg 0
170 RIpcReadStream ipcstream;
171 ipcstream.Open(aMessage, 0);
172 CleanupClosePushL(ipcstream);
173 CDecisionFilter *filter = CDecisionFilter::NewLC();
174 ipcstream >> *filter;
176 UpsServer()->iDbHandle->RemoveDecisionsL(*filter);
178 CleanupStack::PopAndDestroy(filter);
179 CleanupStack::PopAndDestroy(&ipcstream);
180 return ETrue; // Complete client request with KErrNone
183 case EUpdateDecision:
185 CUpdateEvaluator *updateEvaluator = CUpdateEvaluator::NewLC(this, aMessage);
186 updateEvaluator->TransferToScsFrameworkL();
187 CleanupStack::Pop(updateEvaluator); // view now owned by SCS framework
190 The CViewEvaluator is now responsible for completing the request,
191 so we must NOT leave.
193 updateEvaluator->StartUpdate();
194 return EFalse; // Do not complete client request - view evaulator will...
197 case EDeleteDecisionsForExe:
200 exeSid.iUid = aMessage.Int0();
202 CDecisionFilter *filter = CDecisionFilter::NewLC();
203 filter->SetClientSid(exeSid, EEqual);
205 UpsServer()->iDbHandle->RemoveDecisionsL(*filter);
207 CleanupStack::PopAndDestroy(filter);
209 return ETrue; // Complete client request with KErrNone
212 case ENotifyPluginsMayHaveChanged:
213 // Tell plugin manager to unload, and hence reload, plugins ASAP.
214 UpsServer()->iPluginManager->Unload();
215 return ETrue; // Complete client request with KErrNone
217 case ENotifyPolicyFilesChanged:
219 CPolicyChangeEvaluator *changeEvaluator = CPolicyChangeEvaluator::NewLC(UpsServer()->iPolicyCache, this, aMessage);
220 changeEvaluator->TransferToScsFrameworkL();
221 CleanupStack::Pop(changeEvaluator); // Nnow owned by SCS framework
224 The CPolicyChangeEvaluator is now responsible for completing the request,
225 so we must NOT leave.
227 changeEvaluator->StartUpdate();
229 // Release our reference to the policy cache
230 UpsServer()->iPolicyCache.Release();
232 return EFalse; // Do not complete client request - policy change evaluator will...
241 User::Leave(KErrNotSupported);
242 /*lint -unreachable */
247 CScsSubsession* CUpsSession::DoCreateSubsessionL(TInt aFunction, const RMessage2& aMessage)
249 Override CScsSession by allocating a new subsession object.
251 @param aFunction Function identifier without SCS code.
252 @param aMessage Standard server-side handle to message. Not used.
253 @return New, initialized instance of CUpsSubsession, which is
257 TSessionFunction f = static_cast<TSessionFunction>(aFunction);
261 case ESessSubsessFromThreadId:
262 // create a subsession object curried on the supplied thread ID.
263 return CUpsSubsession::NewL(*this, aMessage);
266 User::Leave(KErrNotSupported);
267 /*lint -unreachable */
268 return 0; // avoid compiler warning
272 void CUpsSession::PrefetchRecordAndWriteLengthToClientL(const RMessagePtr2& aMessage)
274 Retrieve the next record from the iManagementView and return its length to the
278 if(iManagementView == 0)
280 User::Leave(KErrEof);
283 TPckgBuf<TUint32> nextRecordLenghthBuf;
287 TRAPD(err, iRecord = iManagementView->NextDecisionL());
288 if((err != KErrNone) || (iRecord == 0))
290 nextRecordLenghthBuf() = 0;
294 RNullWriteStream nullstream;
295 nullstream << *iRecord;
296 nextRecordLenghthBuf() = nullstream.BytesWritten();
299 aMessage.WriteL(1, nextRecordLenghthBuf);
302 void CUpsSession::CleanupView()
307 delete iManagementView;
313 void CUpsSession::DbHandleAboutToBeDeleted()
315 Master DB handle is about to be deleted, so we must delete our view now.
316 This will also cause the next RUpsManageMent::NextMatchL call to leave.
321 iManagementView->Cancel();
326 } // End of namespace UserPromptService