|
1 /* |
|
2 * Copyright (c) 2000 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of policymanagement components |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef INIFILEHELPER_HEADER_ |
|
21 #define INIFILEHELPER_HEADER_ |
|
22 |
|
23 // INCLUDES |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <f32file.h> |
|
27 #include <s32strm.h> |
|
28 #include "CentRepToolClientServer.h" |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 const TUint32 KBackupBitMask = 0x01000000; //from the most significiant byte the least significiant bit defines is backup on or off |
|
33 |
|
34 enum KSettingType |
|
35 { |
|
36 EIndividualSetting = 0, |
|
37 EDefaultMeta, |
|
38 ERangeMetaSetting, |
|
39 ERangeMaskSetting, |
|
40 ERangeSetting, |
|
41 EMaskSetting, |
|
42 }; |
|
43 |
|
44 enum KDefaultType |
|
45 { |
|
46 EAlwaysPass, |
|
47 EAlwaysFail |
|
48 }; |
|
49 |
|
50 |
|
51 // MACROS |
|
52 // DATA TYPES |
|
53 // FUNCTION PROTOTYPES |
|
54 // FORWARD DECLARATIONS |
|
55 // CLASS DECLARATION |
|
56 |
|
57 class CSecuritySetting : public CBase |
|
58 { |
|
59 public: |
|
60 //constructor |
|
61 CSecuritySetting(); |
|
62 |
|
63 // |
|
64 TDesC& SecurityString( TDes &aSecurityString); |
|
65 virtual TDesC& SettingDefinition( TDes &aSecurityString) = 0; //subclasses defines setting part |
|
66 |
|
67 //cap modifieng |
|
68 TInt AddSid( TUid aUid); |
|
69 TInt RemoveSid(); |
|
70 TInt AddWriteCap( TUint8 aCab); |
|
71 TInt AddReadCap( TUint8 aCab); |
|
72 |
|
73 //copy function |
|
74 void CopyCapabilities( CSecuritySetting* aSetting); |
|
75 |
|
76 //compatible functions with TSecurityPolicy Set and Package functions |
|
77 void SetWr(const TDesC8& aDes); |
|
78 void PackageWr( TDes8& aPackage) const; |
|
79 void SetRd(const TDesC8& aDes); |
|
80 void PackageRd( TDes8& aPackage) const; |
|
81 |
|
82 //streaming functions |
|
83 void ExternalizeL(RWriteStream& aStream) const; |
|
84 void InternalizeL(RReadStream& aStream); |
|
85 |
|
86 //util |
|
87 TBool ContainsSecuritySettings(); |
|
88 KSettingType Type(); |
|
89 |
|
90 TBool CheckAccess( const RMessage2& aMessage, TAccessType aAccessType); |
|
91 protected: |
|
92 TInt ReadCaps( TLex& aLex); |
|
93 TInt AddSecurityAttributes( const TDesC& aType, const TDesC& aValue); |
|
94 private: |
|
95 TInt ConvertStrToCap( const TDesC& aCab, TUint8& aCapValue, KDefaultType& aType); |
|
96 TInt ConvertStrToSid( const TDesC& aStr, TUid& iSid); |
|
97 const TPtrC8 ConvertCapToStr( TUint8 aCab, KDefaultType& aType); |
|
98 |
|
99 enum ECapTypes |
|
100 { |
|
101 EWriteCaps, |
|
102 EReadCaps |
|
103 }; |
|
104 |
|
105 void Set(const TDesC8& aDes, ECapTypes aCapType); |
|
106 void Package( TDes8& aPackage, ECapTypes aCapType) const; |
|
107 |
|
108 protected: |
|
109 KSettingType iType; |
|
110 KDefaultType iDefaultTypeWr; |
|
111 KDefaultType iDefaultTypeRd; |
|
112 |
|
113 private: |
|
114 TBool iSidExistWr; |
|
115 TUid iSidWr; |
|
116 TUint8 iCapWr[7]; |
|
117 TBool iSidExistRd; |
|
118 TUid iSidRd; |
|
119 TUint8 iCapRd[7]; |
|
120 |
|
121 friend class CSecuritySetting; |
|
122 }; |
|
123 |
|
124 class CRangeSetting : public CSecuritySetting |
|
125 { |
|
126 public: |
|
127 CRangeSetting(); |
|
128 CRangeSetting( TUint32 aRangeStart, TUint32 aRangeEnd, TUint32 aMask); |
|
129 |
|
130 static CRangeSetting* NewL( TLex& aSecurityString); |
|
131 static CRangeSetting* NewL( TUint32 aRangeStart, TUint32 aRangeEnd, TUint32 aMask); |
|
132 |
|
133 virtual TDesC& SettingDefinition( TDes &aSecurityString); |
|
134 |
|
135 TUint32 Start() const; |
|
136 TUint32 End() const; |
|
137 TUint32 Mask() const; |
|
138 |
|
139 //streaming functions |
|
140 void ExternalizeL(RWriteStream& aStream) const; |
|
141 void InternalizeL(RReadStream& aStream); |
|
142 protected: |
|
143 private: |
|
144 TDesC& RangeSettingDefinition( TDes &aSecurityString); |
|
145 TDesC& MaskSettingDefinition( TDes &aSecurityString); |
|
146 TInt ReadRangeSetting( TLex& aSecurityString); |
|
147 TInt ReadMaskSetting( TLex& aSecurityString); |
|
148 |
|
149 TUint32 iStart; |
|
150 TUint32 iEnd; |
|
151 TUint32 iMask; |
|
152 |
|
153 friend class CRepositorySession; |
|
154 friend class CRepositoryContent; |
|
155 }; |
|
156 |
|
157 class CDefaultSetting : public CSecuritySetting |
|
158 { |
|
159 public: |
|
160 //constructors |
|
161 CDefaultSetting(); |
|
162 static CDefaultSetting* NewL( TLex& aSecurityString); |
|
163 |
|
164 // |
|
165 virtual TDesC& SettingDefinition( TDes &aSecurityString); |
|
166 |
|
167 //streaming functions |
|
168 void ExternalizeL(RWriteStream& aStream) const; |
|
169 void InternalizeL(RReadStream& aStream); |
|
170 protected: |
|
171 private: |
|
172 TInt ReadSetting( TLex& aSecurityString); |
|
173 }; |
|
174 |
|
175 class CIndividualSetting : public CSecuritySetting |
|
176 { |
|
177 public: |
|
178 //constructors and destructors |
|
179 CIndividualSetting(); |
|
180 CIndividualSetting( const TUint32& aSettingId); |
|
181 ~CIndividualSetting(); |
|
182 static CIndividualSetting* NewL( TLex& aSecurityString); |
|
183 |
|
184 |
|
185 |
|
186 // |
|
187 virtual TDesC& SettingDefinition( TDes &aSecurityString); |
|
188 |
|
189 //streaming for setting data |
|
190 void ExternalizeDataL(RWriteStream& aStream) const; |
|
191 void InternalizeDataL(RReadStream& aStream); |
|
192 |
|
193 //streaming for setting data |
|
194 void ExternalizePlatSecL(RWriteStream& aStream) const; |
|
195 void InternalizePlatSecL(RReadStream& aStream); |
|
196 |
|
197 |
|
198 //compare functions |
|
199 static TInt CompareElements( CIndividualSetting const& aSetting1, CIndividualSetting const& aSetting2); |
|
200 protected: |
|
201 private: |
|
202 void ReadSettingL( TLex& aSecurityString); |
|
203 |
|
204 private: |
|
205 //type definitions |
|
206 enum TSettingType { EInt, EReal, EString, EString8, EBinaryType}; |
|
207 |
|
208 //setting values |
|
209 TPtrC iData; |
|
210 TUint32 iSettingId; |
|
211 TUint32 iMeta; |
|
212 |
|
213 union TSettingValue { TInt iIntegerValue; TReal iRealValue; HBufC8* iStringValue; } iSettingValue; |
|
214 TSettingType iSettingType; |
|
215 |
|
216 friend class CRepositorySession; |
|
217 friend class CRepositoryContent; |
|
218 }; |
|
219 |
|
220 class CRangeMeta : public CBase |
|
221 { |
|
222 public: |
|
223 CRangeMeta(); |
|
224 CRangeMeta( TUint32 aRangeStart, TUint32 aRangeEnd, TUint32 aMask, TUint32 aMeta); |
|
225 |
|
226 static CRangeMeta* NewL( TLex& aSecurityString); |
|
227 static CRangeMeta* NewL( TUint32 aRangeStart, TUint32 aRangeEnd, TUint32 aMask, TUint32 aMeta); |
|
228 |
|
229 TUint32 Start() const; |
|
230 TUint32 End() const; |
|
231 TUint32 Mask() const; |
|
232 KSettingType Type(); |
|
233 |
|
234 //streaming functions |
|
235 void ExternalizeL(RWriteStream& aStream) const; |
|
236 void InternalizeL(RReadStream& aStream); |
|
237 protected: |
|
238 private: |
|
239 TInt ReadRangeSetting( TLex& aSecurityString); |
|
240 TInt ReadMaskSetting( TLex& aSecurityString); |
|
241 |
|
242 KSettingType iType; |
|
243 |
|
244 |
|
245 TUint32 iStart; |
|
246 TUint32 iEnd; |
|
247 TUint32 iMask; |
|
248 TUint32 iMeta; |
|
249 |
|
250 friend class CRepositorySession; |
|
251 friend class CRepositoryContent; |
|
252 }; |
|
253 |
|
254 |
|
255 class TIniFileHelper |
|
256 { |
|
257 public: |
|
258 TIniFileHelper(); |
|
259 |
|
260 //read and write functions |
|
261 HBufC* ReadFileL( RFile& aFile); |
|
262 TInt StartWrite( RFile& aFile); |
|
263 TInt WriteToFile( const TDesC& aContent); |
|
264 TInt LineFeed(); |
|
265 TInt FinishWrite(); |
|
266 |
|
267 //static helper functions |
|
268 static void NextLine( TPtrC& aContent, TPtrC& aNextLine); |
|
269 static TInt ReadNumber( TInt32& aNumber, TLex& aLex); |
|
270 static TInt ReadUNumber( TUint32& aNumber, TLex& aLex); |
|
271 static TInt ReadNumber( TReal& aNumber, TLex& aLex); |
|
272 static TInt CompareElements( CRangeSetting const& aElement1, CRangeSetting const& aElement2); |
|
273 static TInt CompareElements( CRangeMeta const& aElement1, CRangeMeta const& aElement2); |
|
274 |
|
275 static TInt StringReadL( TLex& aLex, HBufC8*& aString); |
|
276 static TInt String8ReadL( TLex& aLex, HBufC8*& aString); |
|
277 static TInt BinaryReadL( TLex& aLex, HBufC8*& aString); |
|
278 |
|
279 |
|
280 private: |
|
281 //member functions |
|
282 private: |
|
283 //attributes |
|
284 RFile* iFile; |
|
285 TInt iSize; |
|
286 |
|
287 #ifdef _DEBUG |
|
288 RFs iDebugFs; |
|
289 RFile iDebugFile; |
|
290 #endif //_DEBUG |
|
291 }; |
|
292 |
|
293 |
|
294 #endif |