os/security/authorisation/userpromptservice/policies/test/testpolicyevaluator/source/testpolicyevaluator.cpp
Update contrib.
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 * refpolicyevaluator.cpp
20 #include "testpolicyevaluator.h"
21 #include <ecom/implementationproxy.h>
22 #include <ups/cliententity.h>
23 #include <ups/fingerprint.h>
24 #include <ups/upsdb.h>
26 using namespace UserPromptService;
28 static const TUint KTestPolicyEvaluatorImplementationId = 0x10283698;
30 CPolicyEvaluator* CTestPolicyEvaluator::CreatePolicyEvaluatorL()
32 Factory method that instantiates a new policy evaluator ECOM plug-in.
34 @return A pointer to the new reference policy evaluator object.
37 CTestPolicyEvaluator* self = new (ELeave)CTestPolicyEvaluator();
38 CleanupStack::PushL(self);
40 CleanupStack::Pop(self);
44 static const TImplementationProxy ImplementationTable[] =
46 IMPLEMENTATION_PROXY_ENTRY(KTestPolicyEvaluatorImplementationId, CTestPolicyEvaluator::CreatePolicyEvaluatorL)
49 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
54 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
55 return ImplementationTable;
59 CTestPolicyEvaluator::CTestPolicyEvaluator()
65 CActiveScheduler::Add(this);
68 CTestPolicyEvaluator::~CTestPolicyEvaluator()
78 void CTestPolicyEvaluator::ConstructL()
80 Second phase constructor, creates the message digest
83 iDigest = CMessageDigestFactory::NewDigestL(CMessageDigest::EMD5);
88 void CTestPolicyEvaluator::DoCancel()
90 // Logically should Cancel the internal outstanding requst, but
91 // currently GenerateFingerprints has already completed it.
93 // And need to complete the clients request
96 User::RequestComplete(iClientStatus, KErrCancel);
100 TInt CTestPolicyEvaluator::RunError(TInt aError)
104 User::RequestComplete(iClientStatus, aError);
109 void CTestPolicyEvaluator::RunL()
111 // This plug-in doesn't use the opaque data
112 TInt opaqueDataLen = iRequest->OpaqueData().Length();
113 if (opaqueDataLen > 0)
115 RDebug::Printf("Received %d bytes of opaque data", opaqueDataLen);
120 // Create most specific hash first i.e. HASH(destination)
121 // N.B. Normally, the destination field should be parsed so that only relevant data is hashed.
123 const TDesC& d = iRequest->Destination();
124 TPtrC8 p(reinterpret_cast<const TUint8*>(d.Ptr()), d.Length() * 2);
125 TPtrC8 h(iDigest->Hash(p));
127 CFingerprint* f = CFingerprint::NewLC(h, d);
128 iFingerprints->AppendL(f);
129 CleanupStack::Pop(f);
131 // An empty fingerprint may be used for decisions that apply to
133 f = CFingerprint::NewLC(KNullDesC8, KNullDesC);
134 iFingerprints->AppendL(f);
135 CleanupStack::Pop(f);
137 User::RequestComplete(iClientStatus, KErrNone);
140 void CTestPolicyEvaluator::SetClientEntityL()
142 Sets the name of the entity within the client process that made the request.
143 This is optional functionality designed to allow permissions to be set for scripts
144 where the scripting host process can execute a number of different scripts.
147 // This doesn't really support client entities, so for testing purposes we
148 // extract the client entity name from the opaque data.
149 _LIT8(KClientEntityTagStart, "<ce>");
150 _LIT8(KClientEntityTagEnd, "</ce>");
153 if ((startPos = iRequest->OpaqueData().FindF(KClientEntityTagStart)) != KErrNotFound)
155 startPos += KClientEntityTagStart().Length();
156 if ((endPos = iRequest->OpaqueData().FindF(KClientEntityTagEnd)) != KErrNotFound)
158 if (endPos > startPos)
160 TPtrC8 entityName = iRequest->OpaqueData().Mid(startPos, endPos - startPos);
161 iClientEntity = CClientEntity::NewL(entityName);
162 *iClientEntityPtr = iClientEntity;
168 void CTestPolicyEvaluator::GenerateFingerprints(
169 const CPromptRequest& aRequest, const CPolicy& aPolicy,
170 RPointerArray<CFingerprint>& aFingerprints, const CClientEntity*& aClientEntity,
171 const TAny*& aDialogCreatorParams, TRequestStatus& aStatus)
173 iRequest = &aRequest;
175 iFingerprints = &aFingerprints;
176 iClientEntityPtr = &aClientEntity;
177 aDialogCreatorParams = 0;
179 iClientStatus = &aStatus;
180 aStatus = KRequestPending;
182 // Kick off policy evaluator state machine
183 iStatus = KRequestPending;
184 TRequestStatus* status = &iStatus;
186 User::RequestComplete(status, KErrNone);
189 TBool CTestPolicyEvaluator::ForcePromptL(const CDecisionRecord& aDecision, TUint& aNewEvaluatorInfo)
192 aNewEvaluatorInfo = aDecision.iEvaluatorInfo + 10;