|
1 /* |
|
2 * Copyright (c) 2005 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: header file for dm tree db handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __NSMLDMDBHANDLER_H |
|
21 #define __NSMLDMDBHANDLER_H |
|
22 |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> |
|
25 #include <d32dbms.h> |
|
26 #include <f32file.h> |
|
27 #include <s32file.h> |
|
28 #include <smldmadapter.h> |
|
29 #include <nsmldmtreedbclient.h> |
|
30 |
|
31 |
|
32 _LIT( KSmlDmModuleDbName, "NSmlDmTree.db" ); |
|
33 |
|
34 _LIT( KSmlDmModuleDbPath, "C:\\System\\data\\NSmlDmTree.db" ); |
|
35 |
|
36 _LIT(KNSmlDmServerId, "ServerId"); |
|
37 _LIT(KNSmlDmAdapterNames, "AdapterNames"); |
|
38 _LIT(KNSmlDmDDFVersions, "DDFVersions"); |
|
39 _LIT(KNSmlDmDllUids, "DllUids"); |
|
40 _LIT(KNSmlDmImplUids, "ImplUids"); |
|
41 _LIT(KNSmlDmDDFVersionTable, "DDFVersionTable"); |
|
42 |
|
43 _LIT(KNSmlDmLuidMappingTable, "LuidMappingTable"); |
|
44 _LIT(KNSmlDmAdapterId, "AdapterId"); |
|
45 _LIT(KNSmlDmMappingURI, "MappingURI"); |
|
46 _LIT(KNSmlDmMappingLuid, "MappingLuid"); |
|
47 |
|
48 _LIT(KNSmlDmAclTable, "AclTable"); |
|
49 _LIT(KNSmlDmAclURI, "AclURI"); |
|
50 _LIT(KNSmlDmAcl, "Acl"); |
|
51 |
|
52 |
|
53 _LIT8(KNSmlDmAclDefaultRoot, "Add=*&Get=*&Exec=*"); |
|
54 _LIT8(KNSmlDmAclDefault, "Add=*&Replace=*&Get=*&Delete=*&Exec=*"); |
|
55 _LIT8(KNSmlDmAclAddEqual, "Add="); |
|
56 _LIT8(KNSmlDmAclGetEqual, "Get="); |
|
57 _LIT8(KNSmlDmAclDeleteEqual, "Delete="); |
|
58 _LIT8(KNSmlDmAclReplaceEqual, "Replace="); |
|
59 _LIT8(KNSmlDmAclAddForAll, "Add=*"); |
|
60 _LIT8(KNSmlDmAclAll, "*"); |
|
61 _LIT8(KNSmlDmAclSeparator, "&"); |
|
62 _LIT8(KNSmlDmAclExecEqual, "Exec="); |
|
63 _LIT8(KNSmlDmAclServerIdSeparator, "+"); |
|
64 |
|
65 _LIT8(KNSmlDmProperty, "?prop=" ); |
|
66 _LIT8(KNSmlDmLitSeparator, "/" ); |
|
67 _LIT(KNSmlDmLitMappingSeparator16, "&" ); |
|
68 _LIT8(KNSmlDmLitAclNull, "null" ); |
|
69 |
|
70 _LIT( KSmlDmTreeDbHandlerPanic, "NSmlDmTreeDBHandler" ); |
|
71 |
|
72 const TInt KNSmlDMMappingSeparator = 0x26; //'&' |
|
73 const TInt KNSmlDMAclSeparator = 0x2b; //'+' |
|
74 const TInt KNSmlDMAclUriSeparator = 0x1e; //Record Separator |
|
75 const TInt KNSmlDMAclCommandSeparator = 0x26; //'&' |
|
76 |
|
77 // Number of elements inserted in one go |
|
78 const TInt KGranularity = 8; |
|
79 const TUint32 KNSmlAclDbId = 1; |
|
80 const TInt KNSmlDmIdLength = 10; |
|
81 |
|
82 enum TNSmlDmMapOperation |
|
83 { |
|
84 EMapNoAction, |
|
85 EMapDelete, |
|
86 EMapInsert, |
|
87 EMapUpdate, |
|
88 EMapRename |
|
89 }; |
|
90 |
|
91 enum TNSmlDmSearchMethod |
|
92 { |
|
93 ENoSearch, |
|
94 ENormalSearch, |
|
95 EUsingParents, |
|
96 EAmongChildren, |
|
97 EAmongParents |
|
98 }; |
|
99 |
|
100 |
|
101 class CNSmlDmURIMapping; |
|
102 class CNSmlDmAdapterElement; |
|
103 |
|
104 // =========================================================================== |
|
105 // CNSmlDmDbHandler |
|
106 // =========================================================================== |
|
107 |
|
108 /** |
|
109 * CNSmlDmDbHandler is interface to physical tree db database |
|
110 * |
|
111 * @since |
|
112 */ |
|
113 class CNSmlDmDbHandler : public CBase |
|
114 { |
|
115 public: |
|
116 |
|
117 /** |
|
118 * Two-phased constructor, leaves pointer to cleanup stack |
|
119 * @return Pointer to newly created module instance |
|
120 */ |
|
121 IMPORT_C static CNSmlDmDbHandler* NewLC(); |
|
122 |
|
123 /** |
|
124 * Two-phased constructor |
|
125 * @return Pointer to newly created module instance |
|
126 */ |
|
127 IMPORT_C static CNSmlDmDbHandler* NewL(); |
|
128 |
|
129 /** |
|
130 * Destructor |
|
131 */ |
|
132 IMPORT_C ~CNSmlDmDbHandler(); |
|
133 |
|
134 /** |
|
135 * Sets server id. This is not stored, this is set at the beginning |
|
136 * of session fro checkin acls |
|
137 * @param aServerId Server identifier |
|
138 */ |
|
139 IMPORT_C void SetServerL ( const TDesC8& aServerId ); |
|
140 |
|
141 //Luid mapping functions |
|
142 |
|
143 /** |
|
144 * Get mapping info from db |
|
145 * @param aAdapterId Adapter id |
|
146 * @param aURI URI for returning the mapped luid |
|
147 * @param aLuid Buffer for writing the mapped luid |
|
148 * @return Success of operation |
|
149 */ |
|
150 IMPORT_C TInt GetMappingInfoLC ( TUint32 aAdapterId, |
|
151 const TDesC8& aURI, |
|
152 HBufC8*& aLuid ); |
|
153 |
|
154 /** |
|
155 * Adds new mapping info to db |
|
156 * @param aAdapterId Adapter id |
|
157 * @param aURI URI which is mapped with luid |
|
158 * @param aLuid Luid which is mapped with URI |
|
159 * @return Success of operation |
|
160 */ |
|
161 IMPORT_C TInt AddMappingInfoL ( TUint32 aAdapterId, |
|
162 const TDesC8& aURI, |
|
163 const TDesC8& aLuid ); |
|
164 |
|
165 /** |
|
166 * Removes mapping info |
|
167 * @param aAdapterId Adapter id |
|
168 * @param aURI URI which should be deleted from mappings |
|
169 * @param aChildAlso If true, also child uries are removed |
|
170 * @return Success of operation |
|
171 */ |
|
172 IMPORT_C TInt RemoveMappingInfoL ( TUint32 aAdapterId, |
|
173 const TDesC8& aURI, |
|
174 TBool aChildAlso = ETrue ); |
|
175 |
|
176 /** |
|
177 * Renames mapping info |
|
178 * @param aAdapterId Adapter id |
|
179 * @param aURI URI which should be renamed |
|
180 * @param aObject New name, i.e. last uri segment |
|
181 * @return Success of operation |
|
182 */ |
|
183 IMPORT_C TInt RenameMappingL ( TUint32 aAdapterId, |
|
184 const TDesC8& aURI, |
|
185 const TDesC8& aObject ); |
|
186 |
|
187 /** |
|
188 * Writes mappings from memory to database |
|
189 * @return Success of operation |
|
190 */ |
|
191 IMPORT_C TInt WriteMappingInfoToDbL(); |
|
192 |
|
193 /** |
|
194 * Get list of mappings in certain level |
|
195 * @param aAdapterId Adapter id |
|
196 * @param aURI URI which should be renamed |
|
197 * @param aURISegList Reference to list where to write list of mappings |
|
198 * @return Success of operation |
|
199 */ |
|
200 IMPORT_C TInt GetURISegmentListL ( TUint32 aAdapterId, |
|
201 const TDesC8& aURI, |
|
202 CArrayFix<TSmlDmMappingInfo>& aURISegList ); |
|
203 |
|
204 /** |
|
205 * Clears the tree when child list is got from plug-in adapter |
|
206 * @param aAdapterId Adapter id |
|
207 * @param aURI URI which should be renamed |
|
208 * @param aCurrentList List of children. The mappings which are not |
|
209 * in list are removed |
|
210 */ |
|
211 IMPORT_C void UpdateMappingInfoL ( TUint32 aAdapterId, |
|
212 const TDesC8& aURI, |
|
213 CBufBase& aCurrentList ); |
|
214 |
|
215 |
|
216 //acl functions |
|
217 |
|
218 /** |
|
219 * Delete ACL which is set to URI |
|
220 * @param aURI URI from which the acl info must be deleted |
|
221 * @return Success of operation |
|
222 */ |
|
223 IMPORT_C TInt DeleteAclL(const TDesC8& aURI); |
|
224 |
|
225 /** |
|
226 * Update ACL for URI |
|
227 * @param aURI URI for updating the ACL info |
|
228 * @return Success of operation |
|
229 */ |
|
230 IMPORT_C TInt UpdateAclL(const TDesC8& aURI,const TDesC8& aACL); |
|
231 |
|
232 /** |
|
233 * Get ACL which is set for URI |
|
234 * @param aURI URI for returning the ACL info |
|
235 * @param aACL Buffer for writing the found acl |
|
236 * @param aInherited If true, the inherited value is given if the |
|
237 * ACL is not set to given URI |
|
238 * @return Success of operation |
|
239 */ |
|
240 IMPORT_C TInt GetAclL(const TDesC8& aURI, |
|
241 CBufBase& aACL,TBool aInherited = ETrue); |
|
242 |
|
243 /** |
|
244 * Write ACLs from memory to db |
|
245 */ |
|
246 IMPORT_C TInt WriteAclInfoToDbL(); |
|
247 |
|
248 /** |
|
249 * Check if current server has aacl rights for URI |
|
250 * @param aURI URI for checking ACL |
|
251 * @param aCmdType Type of command (add,..) |
|
252 * @return ETrue if access ok |
|
253 */ |
|
254 IMPORT_C TBool CheckAclL(const TDesC8& aURI, TNSmlDmCmdType aCmdType); |
|
255 |
|
256 /** |
|
257 * Set default acls to current server for certain URI |
|
258 * @param aURI URI which acl is set to default for curren server |
|
259 * @return Success of operation |
|
260 */ |
|
261 IMPORT_C TInt DefaultACLsToServerL(const TDesC8& aURI); |
|
262 |
|
263 /** |
|
264 * Erase server references from all the acls |
|
265 * @param aServerId |
|
266 * @return Success of operation |
|
267 */ |
|
268 IMPORT_C TInt EraseServerIdL(const TDesC8& aServerId); |
|
269 |
|
270 |
|
271 private: // functions |
|
272 |
|
273 void CreateDatabaseL( const TDesC& aFullName ); |
|
274 void ConstructL(); |
|
275 TInt GetAclDataFromDbL(); |
|
276 TInt RenameAclL(const TDesC8& aURI, const TDesC8& aNewURI); |
|
277 void ReadAllURIMappingsFromDbL(); |
|
278 void ReadOneLineFromDbL(); |
|
279 |
|
280 void UpdateInternalArrayL( TUint32 aAdapterId, |
|
281 const TDesC8& aURI, |
|
282 const TDesC8& aLUID, |
|
283 TNSmlDmMapOperation aOperation, |
|
284 TNSmlDmSearchMethod aMethod, |
|
285 const TDesC8& aNwUri = KNullDesC8 ); |
|
286 |
|
287 TInt SearchUriL( TUint32 aAdapterId, |
|
288 const TDesC8& aURI, |
|
289 TNSmlDmSearchMethod aSearchMethod, |
|
290 TInt& aAdIndex, |
|
291 RArray<TInt>& aUriIndex ); |
|
292 |
|
293 TInt SearchRowInDbL( TUint32 aAdapterId, const TDesC8& aURI ); |
|
294 |
|
295 void UpdateRowInDbL( TUint32 aAdapterId, |
|
296 const TDesC8& aURI, |
|
297 const TDesC8& aLUID, |
|
298 TNSmlDmMapOperation aOperation ); |
|
299 |
|
300 |
|
301 private: // data |
|
302 |
|
303 |
|
304 RFs iFsSession; |
|
305 HBufC8* iServer; |
|
306 TBool iAclUpToDate; |
|
307 |
|
308 RPointerArray<HBufC8> iAclURIs; |
|
309 RPointerArray<HBufC8> iAcls; |
|
310 |
|
311 RDbStoreDatabase iDatabase; |
|
312 CFileStore* iFileStore; |
|
313 RDbView iView; |
|
314 |
|
315 RPointerArray<CNSmlDmAdapterElement> iAdapters; |
|
316 TBool iURIMappingsReadFromDb; |
|
317 TBool iPrepareView; |
|
318 }; |
|
319 |
|
320 |
|
321 // =========================================================================== |
|
322 // CNSmlDmURIMapping |
|
323 // =========================================================================== |
|
324 /** |
|
325 * CNSmlDmURIMapping is container element for mappings when keeping them memory |
|
326 * |
|
327 * @since |
|
328 */ |
|
329 class CNSmlDmURIMapping : public CBase |
|
330 { |
|
331 public: |
|
332 /** |
|
333 * Two-phased constructor. Leaves instance to cleanup stack |
|
334 * @return Pointer to newly created module instance |
|
335 */ |
|
336 static CNSmlDmURIMapping* NewLC (); |
|
337 |
|
338 /** |
|
339 * Two-phased constructor. Leaves instance to cleanup stack |
|
340 * @param aURI Mapped URI |
|
341 * @param aLUID Mapped luid |
|
342 * @param aOperation Operation which is made to element |
|
343 * @return Pointer to newly created module instance |
|
344 */ |
|
345 static CNSmlDmURIMapping* NewLC ( const TDesC8& aURI, |
|
346 const TDesC8& aLUID, |
|
347 TNSmlDmMapOperation aOperation ); |
|
348 |
|
349 /** |
|
350 * Destructor |
|
351 */ |
|
352 ~CNSmlDmURIMapping(); |
|
353 public: |
|
354 /** |
|
355 * URI |
|
356 */ |
|
357 HBufC8* iURI; |
|
358 |
|
359 /** |
|
360 * Luid |
|
361 */ |
|
362 HBufC8* iLUID; |
|
363 |
|
364 /** |
|
365 * Operation information |
|
366 */ |
|
367 TNSmlDmMapOperation iOperation; |
|
368 private: |
|
369 void ConstructL(); |
|
370 |
|
371 void ConstructL ( const TDesC8& aURI, |
|
372 const TDesC8& aLUID, |
|
373 TNSmlDmMapOperation aOperation ); |
|
374 }; |
|
375 |
|
376 |
|
377 // =========================================================================== |
|
378 // CNSmlDmAdapterElement |
|
379 // =========================================================================== |
|
380 |
|
381 /** |
|
382 * CNSmlDmAdapterElement is container element for arraying mapping elements |
|
383 * for each adapter |
|
384 * |
|
385 * @since |
|
386 */ |
|
387 class CNSmlDmAdapterElement : public CBase |
|
388 { |
|
389 public: |
|
390 /** |
|
391 * Two-phased constructor. Leaves instance to cleanup stack |
|
392 * @param aAdapterId Adapter id |
|
393 * @return Pointer to newly created module instance |
|
394 */ |
|
395 static CNSmlDmAdapterElement* NewLC ( TUint32 aAdapterId ); |
|
396 |
|
397 /** |
|
398 * Destructor |
|
399 */ |
|
400 ~CNSmlDmAdapterElement(); |
|
401 public: |
|
402 |
|
403 /** |
|
404 * Adapter id |
|
405 */ |
|
406 TUint32 iAdapterId; |
|
407 |
|
408 /** |
|
409 * Array of mappings belongin to current adapter |
|
410 */ |
|
411 RPointerArray<CNSmlDmURIMapping> iMapArray; |
|
412 private: |
|
413 CNSmlDmAdapterElement(TUint32 aAdapterId); |
|
414 }; |
|
415 |
|
416 |
|
417 |
|
418 #endif // __NSMLDMDBHANDLER_H |