Update contrib.
1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __SQLSECURITYIMPL_H__
17 #define __SQLSECURITYIMPL_H__
20 #include "SqlBufFlat.h" //RSqlBufFlat
22 //Forward declarations
23 class TSqlSecurityPolicyIterator;
26 CSqlSecurityPolicy class implements RSqlSecurityPolicy.
28 Current CSqlSecurityPolicy implementation uses a flat buffer (see RSqlBufFlat class) as a storage for the database
29 objects security policies.
30 By default the flat buffer has threee entries:
31 - entry 0 is a system entry and keeps the count of the database security entries;
32 - entry 1 is reserved for the default database security policy. This is a nameless entry;
33 - entry 2 is reserved for the database security policies: read, write and schema. This is a nameless entry;
34 The flat buffer may have more entries if database object security policies are added. In this case each flat buffer entry
35 has a 16-bit encoded database object name, kept at the end of the entry, after the database object security policy data and
36 database object name length.
37 Note: Current CSqlSecurityPolicy implementation can have no more than 13 database object security policy entries.
38 An access to the flat buffer can be obtained via CSqlSecurityPolicy::BufFlat() methods (const and non-const).
39 There are two ways to externalize (resp. internalize) CSqlSecurityPolicy data:
40 - (1) using CSqlSecurityPolicy::ExternalizeL()/CSqlSecurityPolicy::InternalizeL();
41 - (2) using CSqlSecurityPolicy::BufFlat() to get an access to the flat buffer and then externalize/internalize the buffer.
42 CSqlSecurityPolicy class has only one data member which is the flat buffer;
44 TSqlSecurityPolicyIterator class gives a convinient way to access the security policies kept inside the flat buffer.
45 The given access is a read-only.
47 @see RSqlSecurityPolicy
49 @see TSqlSecurityPolicyIterator
50 @see RSqlSecurityPolicy::TPolicyType
51 @see RSqlSecurityPolicy::TObjectType
52 @see CSqlSecurityPolicy::NewL()
53 @see CSqlSecurityPolicy::NewLC()
54 @see CSqlSecurityPolicy::SetDefaultPolicy()
55 @see CSqlSecurityPolicy::SetDbPolicy()
56 @see CSqlSecurityPolicy::SetPolicy()
57 @see CSqlSecurityPolicy::DefaultPolicy()
58 @see CSqlSecurityPolicy::DbPolicy()
59 @see CSqlSecurityPolicy::Policy()
60 @see CSqlSecurityPolicy::ExternalizeL()
61 @see CSqlSecurityPolicy::InternalizeL()
62 @see CSqlSecurityPolicy::BufFlat()
66 NONSHARABLE_CLASS(CSqlSecurityPolicy) : public CBase
68 friend class TSqlSecurityPolicyIterator;
72 static CSqlSecurityPolicy* NewL(const TSecurityPolicy& aDefaultPolicy);
73 static CSqlSecurityPolicy* NewLC(const TSecurityPolicy& aDefaultPolicy);
74 virtual ~CSqlSecurityPolicy();
75 void SetDefaultPolicy(const TSecurityPolicy& aPolicy);
76 void SetDbPolicy(RSqlSecurityPolicy::TPolicyType aPolicyType, const TSecurityPolicy& aPolicy);
77 TInt SetPolicy(RSqlSecurityPolicy::TObjectType aObjectType, const TDesC& aObjectName, RSqlSecurityPolicy::TPolicyType aPolicyType, const TSecurityPolicy& aPolicy);
78 TSecurityPolicy DefaultPolicy() const;
79 TSecurityPolicy DbPolicy(RSqlSecurityPolicy::TPolicyType aPolicyType) const;
80 TSecurityPolicy Policy(RSqlSecurityPolicy::TObjectType aObjectType, const TDesC& aObjectName, RSqlSecurityPolicy::TPolicyType aPolicyType);
82 const RSqlBufFlat& BufFlat() const;
83 RSqlBufFlat& BufFlat();
87 void ConstructL(const TSecurityPolicy& aDefaultPolicy);
88 inline static TInt PolicyType2Index(RSqlSecurityPolicy::TPolicyType aPolicyType);
89 inline static TPolicyItem* PolicyItemPtr(const RSqlBufFlat::TCell* aBegin, const RSqlBufFlat::TCell* aCurrent);
90 const TPolicyItem* FindPolicyItemPtr(RSqlSecurityPolicy::TObjectType aObjectType, const TDesC& aObjectName) const;
91 void SetCount(TInt aCount);
95 EPolicyTypeCount = 3, //Schema, Read, Write policy types
96 EMaxCount = 16, //iBufFlat max element count. The database cannot have more than EMaxCount security policies.
97 ECountIdx = 0, //The index of the policy counter
98 EDefaultPolicyIdx = 1, //The index of the default policy type in iBufFlat
99 EDbPolicyIdx = 2 //The index of the database policy type in iBufFlat
102 //The database security policies are kept in objects of TPolicyItem type.
103 //If particular TPolicyItem object represents the database security policies, then the memory layout is:
107 //If particular TPolicyItem object represents table security policies, then the memory layout is:
111 // [The length of the table name - 32-bit integer]
113 //As you can see, TPolicyItem does not have "name length" and "name" data members. If that is needed, an appropriate block of memory will be allocated for the TPolicyItem object.
114 //There SQL platform security interface currently supports only database security policies, but the implementation is capable of handling also table security policies.
117 enum {EPolicyTypeCount = 3}; //Schema, Read, Write policy types. The same as the declaration above.
118 TSecurityPolicy iPolicy[EPolicyTypeCount]; //Database object policies
119 //Database object name size will be after the end of TPolicyItem object
120 inline TInt* NameSizePtr()
122 //See the comments of the TPolicyItem structure above.
123 //coverity[overrun-local]
124 return reinterpret_cast <TInt*> (reinterpret_cast <TUint8*> (iPolicy) + sizeof(iPolicy));
126 inline TInt NameSize() const
128 //See the comments of the TPolicyItem structure above.
129 //coverity[overrun-local]
130 return *reinterpret_cast <const TInt*> (reinterpret_cast <const TUint8*> (iPolicy) + sizeof(iPolicy));
132 //Database object name will be after the end of TPolicyItem object + sizeof(TInt)
133 inline const TUint16* NamePtr() const
135 //See the comments of the TPolicyItem structure above.
136 //coverity[overrun-local]
137 return reinterpret_cast <const TUint16*>
138 (reinterpret_cast <const TUint8*> (iPolicy) + sizeof(iPolicy) + sizeof(TInt));
140 inline TUint16* NamePtr()
142 //See the comments of the TPolicyItem structure above.
143 //coverity[overrun-local]
144 return reinterpret_cast <TUint16*> (reinterpret_cast <TUint8*> (iPolicy) + sizeof(iPolicy) + sizeof(TInt));
146 inline static TInt CalcSize(TInt aNameLen)
148 return sizeof(TPolicyItem) + sizeof(TInt) + aNameLen * sizeof(TUint16);
151 RSqlBufFlat iBufFlat;
155 CSqlSecurityPolicy container read-only iterator.
160 //Valid CSqlSecurityPolicy instance.
161 CSqlSecurityPolicy* securityPolicy;
163 TSqlSecurityPolicyIterator it(*securityPolicy);
165 //The following variables will be initialized on each iteration
166 RSqlSecurityPolicy::TObjectType objectType;
168 RSqlSecurityPolicy::TPolicyType policyType;
169 TSecurityPolicy policy;
171 while(it.Next(objectType, objectName, policyType, policy))
173 //"objectType" is initialized with the object type (see RSqlSecurityPolicy::TObjectType)
174 //"objectName" is initialized with the object name (database table name)
175 //"policyType" is initialized with the policy type (see RSqlSecurityPolicy::TPolicyType)
176 //"policy" is initialized with the security policy data (see TSecurityPolicy)
177 <do something with the policy>;
182 @see CSqlSecurityPolicy
183 @see RSqlSecurityPolicy::TObjectType
184 @see RSqlSecurityPolicy::TPolicyType
189 NONSHARABLE_CLASS(TSqlSecurityPolicyIterator)
192 TSqlSecurityPolicyIterator(const CSqlSecurityPolicy& aSqlSecurityPolicy);
193 TBool Next(RSqlSecurityPolicy::TObjectType& aObjectType, TPtrC& aObjectName, RSqlSecurityPolicy::TPolicyType& aPolicyType, TSecurityPolicy& aPolicy);
196 const RSqlBufFlat::TCell* iBegin;
197 const RSqlBufFlat::TCell* iCurrent;
198 const RSqlBufFlat::TCell* iEnd;
203 #endif//__SQLSECURITYIMPL_H__