os/security/authorisation/userpromptservice/server/source/upsclient/upsclientserver.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 * Implements an interface to keep and access decision record fields.
26 #include <ups/upstypes.h>
27 #include <ups/upsconst.h>
29 #include <ups/upserr.h>
30 #include "upscommon.h"
32 namespace UserPromptService {
34 CDecisionRecord::CDecisionRecord()
36 Constructor for the decision record.
42 CDecisionRecord::CDecisionRecord(const TSecureId& aClientSid,const TUid& aEvaluatorId,const TUid& aServiceId,const TSecureId& aServerSid,
43 const TUint8 aResult, const TUint16& aMajorPolicyVersion, const TUint32 aEvaluatorInfo, const TUint32& aRecordId)
45 Constructor for the decision record. Assigns the ID values.
47 :iClientSid(aClientSid),iEvaluatorId(aEvaluatorId),
48 iServiceId(aServiceId),iServerSid(aServerSid),
49 iResult(aResult),iMajorPolicyVersion(aMajorPolicyVersion),
50 iRecordId(aRecordId),iEvaluatorInfo(aEvaluatorInfo)
56 CDecisionRecord::~CDecisionRecord()
58 Destructor for the decision record object
62 iClientEntity.Close();
66 EXPORT_C CDecisionRecord* CDecisionRecord::NewL(const TSecureId& aClientSid,const TUid& aEvaluatorId,const TUid& aServiceId,const TSecureId& aServerSid,
67 const TDesC8& aFingerprint,const TDesC8& aClientEntity,const TDesC& aDescription, const TUint8 aResult,
68 const TUint16& aMajorPolicyVersion, const TUint32 aEvaluatorInfo, const TUint32& aRecordId)
70 Creates a decision record object. The function leaves, if creation of the record object fails.
72 @param aClientSid Secure Id of client application
73 @param aEvaluatorId UID for the policy evaluator DLL
74 @param aServiceId UID for service e.g. sms, mms, telephony, gprs
75 @param aServerSid Secure Id for the system server that the decision applies to
76 @param aFingerprint Hash of the destination and/or opaque data. Maximum length is 32 bytes.
77 @param aClientEntity The name of the entity within the client that requested the service. Maximum length is 32 bytes.
78 @param aDescription A copy of description and/or opaque.
79 @param aResult Whether the request should be approved (=1) or denied (=0)
80 @param aMajorPolicyVersion The major version of the policy file.
81 @param aEvaluatorInfo Policy evaluator specific data
82 @param aRecordId An auto-incrementing record number.
84 @return A pointer to the newly allocated decision record object, if creation is successful.
87 CDecisionRecord* self = CDecisionRecord::NewLC(aClientSid,aEvaluatorId,aServiceId,aServerSid,aFingerprint,aClientEntity,
88 aDescription,aResult,aMajorPolicyVersion,aEvaluatorInfo,aRecordId);
89 CleanupStack::Pop(self);
94 EXPORT_C CDecisionRecord* CDecisionRecord::NewLC(const TSecureId& aClientSid,const TUid& aEvaluatorId,const TUid& aServiceId,const TSecureId& aServerSid,
95 const TDesC8& aFingerprint,const TDesC8& aClientEntity,const TDesC& aDescription, const TUint8 aResult,
96 const TUint16& aMajorPolicyVersion, const TUint32 aEvaluatorInfo, const TUint32& aRecordId)
98 Creates a decision record object. The function leaves, if creation of the record object fails.
100 @return A pointer to the newly allocated decision record object, if creation is successful.
101 The pointer is also put onto the cleanup stack.
102 @see CDecisionRecord::NewL()
105 CDecisionRecord* self = new (ELeave) CDecisionRecord(aClientSid,aEvaluatorId,aServiceId,aServerSid,aResult,
106 aMajorPolicyVersion,aEvaluatorInfo,aRecordId);
107 CleanupStack::PushL(self);
108 self->ConstructL(aFingerprint,aClientEntity,aDescription);
112 EXPORT_C CDecisionRecord* CDecisionRecord::NewLC()
114 Creates a decision record object. The function leaves, if creation of the record object fails.
116 @return A pointer to the newly allocated decision record object, if creation is successful.
117 The pointer is also put onto the cleanup stack.
120 CDecisionRecord* self = new (ELeave) CDecisionRecord();
121 CleanupStack::PushL(self);
125 void CDecisionRecord::ConstructL(const TDesC8& aFingerprint,const TDesC8& aClientEntity,const TDesC& aDescription)
127 Second phase constructor for the decision record. Sets members allocated on the heap.
128 The function leaves, if any buffer allocation fails.
129 @see CDecisionRecord::NewL()
133 iFingerprint.CreateL(aFingerprint);
135 iClientEntity.CreateL(aClientEntity);
137 iDescription.CreateL(aDescription);
142 void CDecisionRecord::ValidateL()
144 Check both the fingerprint and client entity are not too long.
145 An absent fingerprint or client entity is represent by an empty string.
148 if(iFingerprint.Length() > (TInt)KUpsMaxFingerprintLength)
150 DEBUG_PRINTF2(_L8("The fingerprint length (%d) has not been satisfied during decision construction!"),iFingerprint.Length());
151 User::Leave(KErrUpsBadFingerprintLength);
154 if(iClientEntity.Length() > (TInt)KUpsMaxClientEntityLength)
156 DEBUG_PRINTF2(_L8("The client entity length (%d) has not been satisfied during decision construction!"),iClientEntity.Length());
157 User::Leave(KErrUpsBadClientEntityLength);
161 EXPORT_C void CDecisionRecord::ExternalizeL(RWriteStream& aStream) const
163 Externalise this CDecisionRecord object to the specified stream.
166 aStream.WriteUint32L(iClientSid.iId);
167 aStream.WriteInt32L(iEvaluatorId.iUid);
168 aStream.WriteInt32L(iServiceId.iUid);
169 aStream.WriteUint32L(iServerSid.iId);
170 aStream << iFingerprint;
171 aStream << iClientEntity;
172 aStream << iDescription;
174 aStream << iMajorPolicyVersion;
175 aStream << iRecordId;
176 aStream << iEvaluatorInfo;
179 EXPORT_C void CDecisionRecord::InternalizeL(RReadStream& aStream)
181 Internalise this CDecisionRecord object from the specified stream.
184 iClientSid.iId= aStream.ReadUint32L();
185 iEvaluatorId.iUid = aStream.ReadInt32L();
186 iServiceId.iUid = aStream.ReadInt32L();
187 iServerSid.iId = aStream.ReadUint32L();
189 iFingerprint.Close();
190 iFingerprint.CreateL(aStream, KMaskDesLength8);
192 iClientEntity.Close();
193 iClientEntity.CreateL(aStream, KMaskDesLength8);
195 iDescription.Close();
196 iDescription.CreateL(aStream, KMaskDesLength16);
199 aStream >> iMajorPolicyVersion;
200 aStream >> iRecordId;
201 aStream >> iEvaluatorInfo;
206 CDecisionFilter::CDecisionFilter()
208 Constructor for an empty decision filter.
215 CDecisionFilter::CDecisionFilter(const TSecureId& aClientSid, const TUid& aEvaluatorId,
216 const TUid& aServiceId, const TSecureId& aServerSid, const TUint16& aVersion)
217 :iClientSid(aClientSid),iEvaluatorId(aEvaluatorId),iServiceId(aServiceId),
218 iServerSid(aServerSid),iMajorPolicyVersion(aVersion)
220 Constructor for the decision filter. Assigns the ID values.
223 iSetFlag[KPosClientSid] = KSetClientSid | UserPromptService::EEqual;
224 iSetFlag[KPosEvaluatorId] = KSetEvaluatorId | UserPromptService::EEqual;
225 iSetFlag[KPosServiceId] = KSetServiceId | UserPromptService::EEqual;
226 iSetFlag[KPosServerSid] = KSetServerSid | UserPromptService::EEqual;
227 iSetFlag[KPosMajorPolicyVersion] = KSetMajorPolicyVersion | UserPromptService::EEqual;
231 CDecisionFilter::~CDecisionFilter()
233 Destructor for the decision filter
237 delete iClientEntity;
241 EXPORT_C CDecisionFilter* CDecisionFilter::NewL()
243 Creates an empty filter object. The function is used to define any number of filter keys.
244 It leaves, if the creation of the filter object fails.
246 @return A pointer to the newly allocated filter object, if creation is successful.
249 CDecisionFilter* self = CDecisionFilter::NewLC();
250 CleanupStack::Pop(self);
255 EXPORT_C CDecisionFilter* CDecisionFilter::NewLC()
257 Creates an empty filter object. The function is used to define any number of filter keys.
258 It leaves, if the creation of the filter object fails.
260 @return A pointer to the newly allocated filter object, if creation is successful.
261 The pointer is also put onto the cleanup stack.
264 CDecisionFilter* self = new (ELeave) CDecisionFilter();
265 CleanupStack::PushL(self);
270 EXPORT_C CDecisionFilter* CDecisionFilter::NewL(const TSecureId& aClientSid,const TUid& aEvaluatorId,const TUid& aServiceId,const TSecureId& aServerSid,
271 const TDesC8& aFingerprint,const TDesC8& aClientEntity,const TUint16& aVersion)
273 Creates a filter object and assigns all filter keys. The function leaves, if creation of the filter object fails.
275 @param aClientSid Secure Id of client application
276 @param aEvaluatorId UID for the policy evaluator DLL
277 @param aServiceId UID for service e.g. sms, mms, telephony, gprs
278 @param aServerSid Secure Id for the system server that the decision applies to
279 @param aFingerprint Hash of the destination and/or opaque data.
280 @param aClientEntity The name of the entity within the client that requested the service.
281 @param aVersion Major version of policy file.
282 @return A pointer to the newly allocated filter object, if creation is successful.
285 CDecisionFilter* self = CDecisionFilter::NewLC(aClientSid,aEvaluatorId,aServiceId,aServerSid,aFingerprint,aClientEntity,aVersion);
286 CleanupStack::Pop(self);
291 EXPORT_C CDecisionFilter* CDecisionFilter::NewLC(const TSecureId& aClientSid,const TUid& aEvaluatorId,const TUid& aServiceId,const TSecureId& aServerSid,
292 const TDesC8& aFingerprint,const TDesC8& aClientEntity,const TUint16& aVersion)
294 Creates a filter object and assigns all filter keys. The function leaves, if creation of the filter object fails.
296 @param aClientSid Secure Id of client application
297 @param aEvaluatorId UID for the policy evaluator DLL
298 @param aServiceId UID for service e.g. sms, mms, telephony, gprs
299 @param aServerSid Secure Id for the system server that the decision applies to
300 @param aFingerprint Hash of the destination and/or opaque data.
301 @param aClientEntity The name of the entity within the client that requested the service.
302 @param aVersion Major version of policy file.
303 @return A pointer to the newly allocated filter object, if creation is successful.
304 The pointer is also put onto the cleanup stack.
307 CDecisionFilter* self = new (ELeave) CDecisionFilter(aClientSid,aEvaluatorId,aServiceId,aServerSid,aVersion);
308 CleanupStack::PushL(self);
309 self->ConstructL(aFingerprint,aClientEntity);
314 void CDecisionFilter::ConstructL(const TDesC8& aFingerprint, const TDesC8& aClientEntity)
316 Second phase constructor for the decision filter. Sets members allocated on the heap.
317 The function leaves, if any buffer allocation fails.
321 iFingerprint = aFingerprint.AllocL();
322 iSetFlag[KPosFingerprint] |= KSetFingerprint;
324 iClientEntity = aClientEntity.AllocL();
325 iSetFlag[KPosClientEntity] |= KSetClientEntity;
330 void CDecisionFilter::ValidateL()
332 Check fingerprint and client entity lengths are valid.
335 if((iSetFlag[KPosFingerprint] & KSetFingerprint) &&
336 ((iFingerprint == 0) || (iFingerprint->Length() > KUpsMaxFingerprintLength)))
338 DEBUG_PRINTF2(_L8("The fingerprint length (%d) has not been satisfied during filter construction!"),(iFingerprint) ? (iFingerprint->Length()) : (0));
339 User::Leave(KErrUpsBadFingerprintLength);
342 if((iSetFlag[KPosClientEntity] & KSetClientEntity) &&
343 ((iClientEntity == 0) || (iClientEntity->Length() > KUpsMaxClientEntityLength)))
345 DEBUG_PRINTF2(_L8("The client entity length (%d) has not been satisfied during filter construction!"),(iClientEntity) ? (iClientEntity->Length()) : (0));
346 User::Leave(KErrUpsBadClientEntityLength);
350 EXPORT_C void CDecisionFilter::SetClientSid(const TSecureId& aSid, TComparisonOp aOp)
352 Sets the Secure ID of the client application.
354 @param aUid SID for the client application
355 @param aOp Comparision operator which is used to create SQL statement.
359 iSetFlag[KPosClientSid] |= KSetClientSid;
360 iSetFlag[KPosClientSid] |= aOp;
364 EXPORT_C void CDecisionFilter::SetEvaluatorId(const TUid& aUid, TComparisonOp aOp)
366 Sets the UID of the policy evaluator DLL.
368 @param aUid UID for the policy evaluator DLL
369 @param aOp Comparision operator which is used to create SQL statement.
373 iSetFlag[KPosEvaluatorId] |= KSetEvaluatorId;
374 iSetFlag[KPosEvaluatorId] |= aOp;
378 EXPORT_C void CDecisionFilter::SetServiceId(const TUid& aUid, TComparisonOp aOp)
380 Sets the Secure ID of the service.
382 @param aUid UID for the service
383 @param aOp Comparision operator which is used to create SQL statement.
387 iSetFlag[KPosServiceId] |= KSetServiceId;
388 iSetFlag[KPosServiceId] |= aOp;
392 EXPORT_C void CDecisionFilter::SetServerSid(const TSecureId& aSid, TComparisonOp aOp)
394 Sets the Secure ID of the system server.
396 @param aUid UID for the system server
397 @param aOp Comparision operator which is used to create SQL statement.
401 iSetFlag[KPosServerSid] |= KSetServerSid;
402 iSetFlag[KPosServerSid] |= aOp;
406 EXPORT_C void CDecisionFilter::SetFingerprintL(const TDesC8& aFingerprint, TComparisonOp aOp)
408 Sets the fingerprint. A buffer is allocated on the heap and aFingerprint copied into it.
409 The function leaves, if the buffer allocation fails.
411 @param aFingerprint Hash of the destination and/or opaque data. (Maximum length is 32 bytes)
412 @param aOp Comparision operator which is used to create SQL statement.
415 //Fingerprint's length can not be longer than KUpsMaxFingerprintLength
416 if(aFingerprint.Length() > KUpsMaxFingerprintLength)
418 User::Leave(KErrUpsBadFingerprintLength);
424 iFingerprint = aFingerprint.AllocL();
425 iSetFlag[KPosFingerprint] |= KSetFingerprint;
426 iSetFlag[KPosFingerprint] |= aOp;
430 EXPORT_C void CDecisionFilter::SetClientEntityL(const TDesC8& aClientEntity, TComparisonOp aOp)
432 Sets the client entity. A buffer is allocated on the heap and aClientEntity copied into it.
433 The function leaves, if the buffer allocation fails.
435 @param aClientEntity The name of the entity within the client. (Maximum length is 32 bytes)
436 @param aOp Comparision operator which is used to create SQL statement.
439 //ClientEntity's length can not be longer than KUpsMaxClientEntityLength
440 if(aClientEntity.Length() > KUpsMaxClientEntityLength)
442 User::Leave(KErrUpsBadClientEntityLength);
445 delete iClientEntity;
448 iClientEntity = aClientEntity.AllocL();
449 iSetFlag[KPosClientEntity] |= KSetClientEntity;
450 iSetFlag[KPosClientEntity] |= aOp;
454 EXPORT_C void CDecisionFilter::SetMajorPolicyVersion(const TUint16& aVersion, TComparisonOp aOp)
456 Sets the major version of the policy file.
458 @param aVersion Major policy version.
459 @param aOp Comparision operator which is used to create SQL statement.
462 iMajorPolicyVersion = aVersion;
463 iSetFlag[KPosMajorPolicyVersion] |= KSetMajorPolicyVersion;
464 iSetFlag[KPosMajorPolicyVersion] |= aOp;
468 EXPORT_C void CDecisionFilter::SetRecordId(const TUint32& aId, TComparisonOp aOp)
470 Sets the unique Id number of the decision record which is searched.
472 @param aId A unique record Id.
473 @param aOp Comparision operator which is used to create SQL statement.
477 iSetFlag[KPosRecordId] |= KSetRecordId;
478 iSetFlag[KPosRecordId] |= aOp;
482 EXPORT_C void CDecisionFilter::SetDescriptionL(const TDesC& aDescription, const TComparisonOp aOp)
484 Sets the description field. A buffer is allocated on the heap and aDescription copied into it.
485 The function leaves, if the buffer allocation fails.
487 @param aDescription A copy of description and/or opaque. (Maximum length is 32 bytes)
488 @param aOp Comparision operator which is used to create SQL statement.
494 iDescription = aDescription.AllocL();
495 iSetFlag[KPosDescription] |= KSetDescription;
496 iSetFlag[KPosDescription] |= aOp;
500 EXPORT_C void CDecisionFilter::SetResult(const TUint8& aResult, const TComparisonOp aOp)
502 Sets the result field of the decision record which is searched.
504 @param aResult Whether the request should be approved.
505 @param aOp Comparision operator which is used to create SQL statement.
509 iSetFlag[KPosResult] |= KSetResult;
510 iSetFlag[KPosResult] |= aOp;
514 EXPORT_C void CDecisionFilter::SetEvaluatorInfo(const TUint32& aEvaluatorInfo, const TComparisonOp aOp)
516 Sets the evaluator info field of the decision record which is searched.
518 @param aEvaluatorInfo Policy evaluator specific data
519 @param aOp Comparision operator which is used to create SQL statement.
522 iEvaluatorInfo = aEvaluatorInfo;
523 iSetFlag[KPosEvaluatorInfo] |= KSetEvaluatorInfo;
524 iSetFlag[KPosEvaluatorInfo] |= aOp;
528 EXPORT_C void CDecisionFilter::ExternalizeL(RWriteStream& aStream) const
530 Externalise this CDecisionFilter object to the specified stream.
533 aStream << iClientSid.iId; // TSecureId
534 aStream << iEvaluatorId.iUid; // TUid
535 aStream << iServiceId.iUid; // TUid
536 aStream << iServerSid.iId; // TSecureId
538 aStream << ((iFingerprint) ? (*iFingerprint) : (KNullDesC8())); // HBufC8*
539 aStream << ((iClientEntity) ? (*iClientEntity) : (KNullDesC8())); // HBufC8*
541 for(int i = 0; i < KFilterKeysNumber; ++i)
543 aStream.WriteUint16L(iSetFlag[i]);// TUint16
546 aStream << iMajorPolicyVersion;// TUint16
547 aStream << iRecordId;// TUint32
549 EXPORT_C void CDecisionFilter::InternalizeL(RReadStream& aStream)
551 Internalise this CDecisionFilter object from the specified stream.
554 iClientSid.iId= aStream.ReadUint32L(); // TSecureId
555 iEvaluatorId.iUid= aStream.ReadInt32L(); // TUid
556 iServiceId.iUid= aStream.ReadInt32L(); // TUid
557 iServerSid.iId= aStream.ReadUint32L(); // TSecureId
559 // iFingerprint is always present in stream, so internalise it and then delete it if it is not setup.
562 iFingerprint = HBufC8::NewL(aStream, KMaskDesLength8);
564 // iClientEntity is always present in stream, so internalise it and then delete it if it is not setup.
565 delete iClientEntity;
567 iClientEntity = HBufC8::NewL(aStream, KMaskDesLength8);
569 for(int i = 0; i < KFilterKeysNumber; ++i)
571 iSetFlag[i] = aStream.ReadUint16L();// TUint16
574 // Delete iFingerprint if not setup
575 if((iSetFlag[KPosFingerprint] & KSetFingerprint) == 0)
581 // Delete iClientEntity if not setup
582 if((iSetFlag[KPosClientEntity] & KSetClientEntity) == 0)
584 delete iClientEntity;
588 iMajorPolicyVersion = aStream.ReadUint16L();// TUint16
589 iRecordId = aStream.ReadUint32L();// TUint32
594 } // End of UserPromptService namespace