|
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 // INCLUDES |
|
20 |
|
21 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
22 #include <devman.h> |
|
23 #include <dmtreenode.h> |
|
24 #else |
|
25 #include <nsmldmdbhandler.h> |
|
26 #endif |
|
27 |
|
28 #include "ACLStorage.h" |
|
29 #include "debug.h" |
|
30 |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 _LIT( KStorageFile, "C:\\private\\10207843\\aclnodes.ini"); |
|
35 _LIT( KStorageTempFile, "C:\\private\\10207843\\aclnodes.tmp"); |
|
36 _LIT( KStorageBackupFile, "C:\\private\\10207843\\aclnodes.bak"); |
|
37 |
|
38 |
|
39 |
|
40 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
41 _LIT8(KNSmlDmAclAddEqual, "Add="); |
|
42 _LIT8(KNSmlDmAclGetEqual, "Get="); |
|
43 _LIT8(KNSmlDmAclDeleteEqual, "Delete="); |
|
44 _LIT8(KNSmlDmAclReplaceEqual, "Replace="); |
|
45 _LIT8(KNSmlDmAclSeparator, "&"); |
|
46 _LIT8(KNSmlDmAclExecEqual, "Exec="); |
|
47 #else |
|
48 const TInt KStatusRef = 0; |
|
49 const TInt KResultRef = 1; |
|
50 #endif |
|
51 |
|
52 |
|
53 |
|
54 namespace |
|
55 { |
|
56 TBool CompareCertInfos( const TCertInfo& aCertInfo1, const TCertInfo& aCertInfo2) |
|
57 { |
|
58 |
|
59 TBool retVal = ( aCertInfo1.iSerialNo == aCertInfo2.iSerialNo ) && |
|
60 ( aCertInfo1.iFingerprint == aCertInfo2.iFingerprint ) && |
|
61 ( aCertInfo1.iIssuerDNInfo.iCommonName == aCertInfo2.iIssuerDNInfo.iCommonName ) && |
|
62 ( aCertInfo1.iIssuerDNInfo.iCountry == aCertInfo2.iIssuerDNInfo.iCountry ) && |
|
63 ( aCertInfo1.iIssuerDNInfo.iLocality == aCertInfo2.iIssuerDNInfo.iLocality ) && |
|
64 ( aCertInfo1.iIssuerDNInfo.iOrganization == aCertInfo2.iIssuerDNInfo.iOrganization ) && |
|
65 ( aCertInfo1.iIssuerDNInfo.iOrganizationUnit == aCertInfo2.iIssuerDNInfo.iOrganizationUnit ); |
|
66 |
|
67 return retVal; |
|
68 } |
|
69 |
|
70 TBool CompareCommands( const CCommand& aCommand1, const CCommand& aCommand2) |
|
71 { |
|
72 TBool match = EFalse; |
|
73 |
|
74 if ( aCommand1.iCommand == aCommand2.iCommand) |
|
75 { |
|
76 if ( aCommand1.iServerId && *aCommand1.iServerId == *aCommand2.iServerId) |
|
77 { |
|
78 match = ETrue; |
|
79 } |
|
80 else |
|
81 { |
|
82 //Compare certficates |
|
83 match = CompareCertInfos( aCommand1.iCertInfo, aCommand2.iCertInfo); |
|
84 } |
|
85 } |
|
86 |
|
87 return match; |
|
88 } |
|
89 } |
|
90 |
|
91 |
|
92 |
|
93 // ---------------------------------------------------------------------------------------- |
|
94 // CCommand::NewL() |
|
95 // ---------------------------------------------------------------------------------------- |
|
96 CCommand* CCommand::NewL( const TCertInfo& aCertInfo, const TAclCommands& aCommand) |
|
97 { |
|
98 CCommand * self = new (ELeave) CCommand(); |
|
99 self->iCertInfo = aCertInfo; |
|
100 self->iCommand = aCommand; |
|
101 |
|
102 return self; |
|
103 } |
|
104 |
|
105 |
|
106 // ---------------------------------------------------------------------------------------- |
|
107 // CCommand::NewL() |
|
108 // ---------------------------------------------------------------------------------------- |
|
109 CCommand* CCommand::NewL( const TDesC8& aServerUid, const TAclCommands& aCommand) |
|
110 { |
|
111 CCommand * self = new (ELeave) CCommand(); |
|
112 |
|
113 CleanupStack::PushL( self); |
|
114 self->iServerId = aServerUid.AllocL(); |
|
115 self->iCommand = aCommand; |
|
116 CleanupStack::Pop( self); |
|
117 |
|
118 return self; |
|
119 } |
|
120 |
|
121 |
|
122 // ---------------------------------------------------------------------------------------- |
|
123 // CCommand::NewL() |
|
124 // ---------------------------------------------------------------------------------------- |
|
125 |
|
126 void CCommand::CommandString( TDes8& aStr) |
|
127 { |
|
128 switch ( iCommand) |
|
129 { |
|
130 case EACLAdd: |
|
131 aStr.Append( KNSmlDmAclAddEqual); |
|
132 break; |
|
133 case EACLDelete: |
|
134 aStr.Append( KNSmlDmAclDeleteEqual); |
|
135 break; |
|
136 case EACLExec: |
|
137 aStr.Append( KNSmlDmAclExecEqual); |
|
138 break; |
|
139 case EACLGet: |
|
140 aStr.Append( KNSmlDmAclGetEqual); |
|
141 break; |
|
142 case EACLReplace: |
|
143 aStr.Append( KNSmlDmAclReplaceEqual); |
|
144 break; |
|
145 default: |
|
146 break; |
|
147 } |
|
148 |
|
149 aStr.Append( *iServerId); |
|
150 } |
|
151 |
|
152 // ---------------------------------------------------------------------------------------- |
|
153 // CCommand::Length() |
|
154 // ---------------------------------------------------------------------------------------- |
|
155 |
|
156 TInt CCommand::Length() |
|
157 { |
|
158 //Calculate serialized command length |
|
159 TPckg<TCertInfo> certPck( iCertInfo); |
|
160 TPckg<TAclCommands> cmdPck( iCommand); |
|
161 |
|
162 return certPck.Length() + cmdPck.Length(); |
|
163 } |
|
164 |
|
165 // ---------------------------------------------------------------------------------------- |
|
166 // CCommand::SaveStringL() |
|
167 // ---------------------------------------------------------------------------------------- |
|
168 HBufC8 * CCommand::SaveStringL() |
|
169 { |
|
170 //Create buffer for string |
|
171 HBufC8 * buf = HBufC8::NewL( Length()); |
|
172 TPtr8 ptr = buf->Des(); |
|
173 |
|
174 //create descriptor packs |
|
175 TPckg<TCertInfo> certPck( iCertInfo); |
|
176 TPckg<TAclCommands> cmdPck( iCommand); |
|
177 |
|
178 //add serialized data to buffer |
|
179 ptr.Append( certPck); |
|
180 ptr.Append( cmdPck); |
|
181 |
|
182 return buf; |
|
183 } |
|
184 |
|
185 // ---------------------------------------------------------------------------------------- |
|
186 // CCommand::LoadFromStringL() |
|
187 // ---------------------------------------------------------------------------------------- |
|
188 CCommand * CCommand::LoadFromStringL( TPtrC8& aString) |
|
189 { |
|
190 CCommand * command = new (ELeave) CCommand(); |
|
191 TPtrC8 ptr( aString); |
|
192 |
|
193 //Certificate |
|
194 TPckg<TCertInfo> certPck( command->iCertInfo); |
|
195 certPck.Copy( ptr.Ptr(), certPck.Length()); |
|
196 ptr.Set( ptr.Mid( certPck.Length())); |
|
197 |
|
198 //Commands |
|
199 TPckg<TAclCommands> cmdPck( command->iCommand); |
|
200 cmdPck.Copy( ptr.Ptr(), cmdPck.Length()); |
|
201 ptr.Set( ptr.Mid( cmdPck.Length())); |
|
202 |
|
203 return command; |
|
204 } |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 // ---------------------------------------------------------------------------------------- |
|
210 // CACLNode::CACLNode() |
|
211 // ---------------------------------------------------------------------------------------- |
|
212 CACLNode::CACLNode() |
|
213 : iURI(0) |
|
214 { |
|
215 } |
|
216 |
|
217 // ---------------------------------------------------------------------------------------- |
|
218 // CACLNode::CACLNode() |
|
219 // ---------------------------------------------------------------------------------------- |
|
220 CACLNode::~CACLNode() |
|
221 { |
|
222 delete iURI; |
|
223 iCommands.Close(); |
|
224 } |
|
225 |
|
226 |
|
227 // ---------------------------------------------------------------------------------------- |
|
228 // CACLNode::CompareElements() |
|
229 // ---------------------------------------------------------------------------------------- |
|
230 |
|
231 TInt CACLNode::CompareElements( CACLNode const& aNode1, CACLNode const& aNode2) |
|
232 { |
|
233 RDEBUG("CACLNode::CompareElements()"); |
|
234 RDEBUG8_2(" -> Node1 URI = %S", &aNode1.iURIPtr ); |
|
235 RDEBUG8_2(" -> Node2 URI = %S", &aNode2.iURIPtr ); |
|
236 TInt result = (aNode1.iURIPtr).Compare( aNode2.iURIPtr); |
|
237 RDEBUG_2(" -> comparison result = %d", result); |
|
238 return result; |
|
239 } |
|
240 |
|
241 // ---------------------------------------------------------------------------------------- |
|
242 // CACLNode::FindCorrespondingCommand() |
|
243 // ---------------------------------------------------------------------------------------- |
|
244 |
|
245 CCommand* CACLNode::FindCorrespondingCommand( const CCommand* aCommand) |
|
246 { |
|
247 CCommand* retVal = 0; |
|
248 |
|
249 //find corresponding command from command list |
|
250 for ( TInt i(0); i < iCommands.Count(); i++) |
|
251 { |
|
252 CCommand* command = iCommands[i]; |
|
253 |
|
254 if ( CompareCommands( *command, *aCommand)) |
|
255 { |
|
256 retVal = command; |
|
257 break; |
|
258 } |
|
259 } |
|
260 |
|
261 return retVal; |
|
262 } |
|
263 |
|
264 |
|
265 // ---------------------------------------------------------------------------------------- |
|
266 // CACLNode::GetNodeACLStringL() |
|
267 // ---------------------------------------------------------------------------------------- |
|
268 |
|
269 HBufC8 * CACLNode::GetNodeACLStringL() |
|
270 { |
|
271 RDEBUG("CACLNode::GetNodeACLStringL()"); |
|
272 HBufC8 * buf = HBufC8::NewL( iCommands.Count() * 21); |
|
273 TPtr8 ptr = buf->Des(); |
|
274 |
|
275 for ( TInt i(0); i < iCommands.Count();) |
|
276 { |
|
277 TBuf8<30> command; |
|
278 |
|
279 iCommands[i++]->CommandString( command); |
|
280 ptr.Append( command); |
|
281 |
|
282 if ( i != iCommands.Count() ) |
|
283 { |
|
284 ptr.Append(KNSmlDmAclSeparator); |
|
285 } |
|
286 } |
|
287 |
|
288 |
|
289 return buf; |
|
290 } |
|
291 |
|
292 |
|
293 // ---------------------------------------------------------------------------------------- |
|
294 // CACLNode::SetURIL() |
|
295 // ---------------------------------------------------------------------------------------- |
|
296 |
|
297 void CACLNode::SetURIL( const TDesC8& aURI ) |
|
298 { |
|
299 delete iURI; |
|
300 iURI = NULL; |
|
301 iURIPtr.Set( KNullDesC8); |
|
302 iURI = aURI.AllocL(); |
|
303 iURIPtr.Set( *iURI); |
|
304 } |
|
305 |
|
306 // ---------------------------------------------------------------------------------------- |
|
307 // CACLNode::ClearACL() |
|
308 // ---------------------------------------------------------------------------------------- |
|
309 |
|
310 void CACLNode::ClearACL() |
|
311 { |
|
312 //find all command which concern specific command remove them from list |
|
313 for ( TInt i(0); i < iCommands.Count(); i++) |
|
314 { |
|
315 #ifdef _DEBUG |
|
316 TBuf8<30> command; |
|
317 iCommands[i]->CommandString( command); |
|
318 RDEBUG8_2("DMUtilServer: Remove command %S", &command); |
|
319 #endif //_DEBUG |
|
320 |
|
321 delete iCommands[i]; |
|
322 iCommands.Remove( i--); |
|
323 } |
|
324 } |
|
325 |
|
326 |
|
327 |
|
328 // ---------------------------------------------------------------------------------------- |
|
329 // CACLNode::SetServerIdToACLL() |
|
330 // ---------------------------------------------------------------------------------------- |
|
331 |
|
332 |
|
333 void CACLNode::SetServerIdToACLL( const TAclCommands& aCommandType, const TDesC8& aServerId) |
|
334 { |
|
335 RDEBUG("CACLStorage::SetServerIdToACLL()"); |
|
336 //check first that command isn't already exist |
|
337 for ( TInt i(0); i < iCommands.Count(); i++) |
|
338 { |
|
339 CCommand * command = iCommands[i]; |
|
340 |
|
341 if ( (command->iCommand == aCommandType || aCommandType == EACLAll ) |
|
342 && *command->iServerId == aServerId) |
|
343 { |
|
344 return; |
|
345 } |
|
346 } |
|
347 |
|
348 //and if command is new, create new CCommand for it |
|
349 CCommand * command = CCommand::NewL( aServerId, aCommandType); |
|
350 |
|
351 CleanupStack::PushL( command); |
|
352 iCommands.AppendL( command); |
|
353 CleanupStack::Pop( command); |
|
354 |
|
355 #ifdef _DEBUG |
|
356 TBuf8<30> commandStr; |
|
357 command->CommandString( commandStr); |
|
358 RDEBUG8_2("DMUtilServer: New command %S", &commandStr); |
|
359 #endif //_DEBUG |
|
360 |
|
361 } |
|
362 |
|
363 // ---------------------------------------------------------------------------------------- |
|
364 // CACLNode::Length() |
|
365 // ---------------------------------------------------------------------------------------- |
|
366 |
|
367 TInt CACLNode::Length() |
|
368 { |
|
369 TInt testvalue; |
|
370 TPckgC<TInt> valueLength( testvalue); |
|
371 TPckgC<TACLDestination> destLength( iDestination); |
|
372 |
|
373 TInt size = valueLength.Length() * 2 + destLength.Length() + iURI->Length(); |
|
374 |
|
375 for (TInt i(0); i < iCommands.Count(); i++) |
|
376 { |
|
377 size += iCommands[i]->Length(); |
|
378 } |
|
379 RDEBUG_2("DMUtilServer: CACLNode::Length - End (returned size: %d)", size); |
|
380 |
|
381 return size; |
|
382 } |
|
383 |
|
384 // ---------------------------------------------------------------------------------------- |
|
385 // CACLNode::SaveStringL() |
|
386 // ---------------------------------------------------------------------------------------- |
|
387 |
|
388 HBufC8 * CACLNode::SaveStringL() |
|
389 { |
|
390 RDEBUG("DMUtilServer: CACLNode::SaveStringL - Start"); |
|
391 |
|
392 //create buffer for string |
|
393 HBufC8* buf = HBufC8::NewL( Length()); |
|
394 TPtr8 ptr = buf->Des(); |
|
395 |
|
396 //clearflag |
|
397 TPckgC<TInt> flagPck( iClearFlag); |
|
398 ptr.Append( flagPck); |
|
399 |
|
400 //destPack |
|
401 TPckgC<TACLDestination> destPck( iDestination); |
|
402 ptr.Append( destPck); |
|
403 |
|
404 //uri |
|
405 TInt uriLength( iURI->Length()); |
|
406 TPckgC<TInt> uriPck( uriLength); |
|
407 ptr.Append( uriPck); |
|
408 ptr.Append( *iURI); |
|
409 |
|
410 //append commands to string |
|
411 for ( TInt i(0); i < iCommands.Count(); i++) |
|
412 { |
|
413 //get command save string |
|
414 HBufC8* buf = iCommands[i]->SaveStringL(); |
|
415 ptr.Append( *buf); |
|
416 |
|
417 delete buf; |
|
418 } |
|
419 |
|
420 RDEBUG("DMUtilServer: CACLNode::SaveStringL - End"); |
|
421 return buf; |
|
422 } |
|
423 |
|
424 // ---------------------------------------------------------------------------------------- |
|
425 // CACLNode::LoadFromStringL() |
|
426 // ---------------------------------------------------------------------------------------- |
|
427 |
|
428 CACLNode * CACLNode::LoadFromStringL( TDes8& aString) |
|
429 { |
|
430 RDEBUG("DMUtilServer: CACLNode::LoadFromStringL - Start"); |
|
431 |
|
432 CACLNode * node = new (ELeave) CACLNode(); |
|
433 TPtrC8 ptr( aString); |
|
434 |
|
435 //Clear flag |
|
436 TPckg<TInt> flagPck( node->iClearFlag); |
|
437 flagPck.Copy( ptr.Ptr(), flagPck.Length()); |
|
438 ptr.Set( ptr.Mid( flagPck.Length())); |
|
439 |
|
440 |
|
441 //destPack |
|
442 TPckg<TACLDestination> destPck( node->iDestination); |
|
443 destPck.Copy( ptr.Ptr(), destPck.Length()); |
|
444 ptr.Set( ptr.Mid( destPck.Length())); |
|
445 |
|
446 //get uri length |
|
447 TInt uriLength; |
|
448 TPckg<TInt> intPck( uriLength); |
|
449 intPck.Copy( ptr.Ptr(), intPck.Length()); |
|
450 ptr.Set( ptr.Mid( intPck.Length())); |
|
451 |
|
452 //get URI and save it to node |
|
453 node->iURI = HBufC8::NewL( uriLength); |
|
454 node->iURI->Des().Copy( ptr.Ptr(), uriLength); |
|
455 node->iURIPtr.Set( *(node->iURI)); |
|
456 ptr.Set( ptr.Mid( uriLength)); |
|
457 |
|
458 TInt len( ptr.Length() ); |
|
459 while ( len ) |
|
460 { |
|
461 //Read buffer |
|
462 CCommand * command = CCommand::LoadFromStringL( ptr); |
|
463 |
|
464 //Set Pointer |
|
465 ptr.Set( ptr.Mid( command->Length())); |
|
466 len = ptr.Length(); |
|
467 //append readen command to command list |
|
468 CleanupStack::PushL( command); |
|
469 node->iCommands.AppendL( command); |
|
470 CleanupStack::Pop( command); |
|
471 } |
|
472 |
|
473 RDEBUG("DMUtilServer: CACLNode::LoadFromStringL - End"); |
|
474 |
|
475 return node; |
|
476 } |
|
477 |
|
478 |
|
479 // ---------------------------------------------------------------------------------------- |
|
480 // CACLNode::SetCertificateToACLL() |
|
481 // ---------------------------------------------------------------------------------------- |
|
482 |
|
483 void CACLNode::SetCertificateToACLL( const TACLDestination& aDestination, const TAclCommands& aCommandType, const TCertInfo& aCertInfo) |
|
484 { |
|
485 RDEBUG("DMUtilServer: CACLNode::SetCertificateToACLL - Start"); |
|
486 |
|
487 //check first that command isn't already exist |
|
488 for ( TInt i(0); i < iCommands.Count(); i++) |
|
489 { |
|
490 CCommand * command = iCommands[i]; |
|
491 |
|
492 if ( (command->iCommand == aCommandType || aCommandType == EACLAll ) |
|
493 && CompareCertInfos( command->iCertInfo, aCertInfo )) |
|
494 { |
|
495 return; |
|
496 } |
|
497 } |
|
498 |
|
499 //and if command is new, create new CCommand for it |
|
500 CCommand * command = CCommand::NewL( aCertInfo, aCommandType); |
|
501 |
|
502 CleanupStack::PushL( command); |
|
503 iCommands.AppendL( command); |
|
504 CleanupStack::Pop( command); |
|
505 |
|
506 iDestination = aDestination; |
|
507 |
|
508 |
|
509 RDEBUG("DMUtilServer: CACLNode::SetCertificateToACLL - End"); |
|
510 } |
|
511 |
|
512 // ---------------------------------------------------------------------------------------- |
|
513 // CACLNode::CreateACLL() |
|
514 // ---------------------------------------------------------------------------------------- |
|
515 |
|
516 CACLNode * CACLNode::CreateACLL( const TDesC8& aACLString) |
|
517 { |
|
518 RDEBUG("DMUtilServer: CACLNode::CreateACLL - Start"); |
|
519 |
|
520 |
|
521 //Create ACL node |
|
522 CACLNode * node = new (ELeave) CACLNode(); |
|
523 |
|
524 TPtrC8 ptr( aACLString); |
|
525 TInt err( KErrNone); |
|
526 |
|
527 //decode acl string |
|
528 while ( ptr.Length() && err == KErrNone) |
|
529 { |
|
530 //find equal mark... |
|
531 TInt index = ptr.Locate('='); |
|
532 |
|
533 //...acl is corrupted if mark not found |
|
534 if ( index == KErrNotFound) |
|
535 { |
|
536 err = KErrCorrupt; |
|
537 break; |
|
538 } |
|
539 |
|
540 //create command ptr, which includes only command string |
|
541 TPtrC8 command( ptr.Left( index + 1)); |
|
542 TAclCommands aclCommand; |
|
543 |
|
544 //remove encoded part |
|
545 ptr.Set( ptr.Mid( index + 1)); |
|
546 |
|
547 //resolve command type |
|
548 if ( command.CompareF( KNSmlDmAclAddEqual) == 0) |
|
549 { |
|
550 aclCommand = EACLAdd; |
|
551 } |
|
552 else |
|
553 if ( command.CompareF( KNSmlDmAclGetEqual) == 0) |
|
554 { |
|
555 aclCommand = EACLGet; |
|
556 } |
|
557 else |
|
558 if ( command.CompareF( KNSmlDmAclDeleteEqual) == 0) |
|
559 { |
|
560 aclCommand = EACLDelete; |
|
561 } |
|
562 else |
|
563 if ( command.CompareF( KNSmlDmAclReplaceEqual) == 0) |
|
564 { |
|
565 aclCommand = EACLReplace; |
|
566 } |
|
567 else |
|
568 if ( command.CompareF( KNSmlDmAclExecEqual) == 0) |
|
569 { |
|
570 aclCommand = EACLExec; |
|
571 } |
|
572 |
|
573 //find &-mark |
|
574 index = ptr.Locate('&'); |
|
575 |
|
576 //server ptr contains server id |
|
577 TPtrC8 server(ptr); |
|
578 if ( index != KErrNotFound) |
|
579 { |
|
580 //set server text |
|
581 server.Set( ptr.Left( index)); |
|
582 |
|
583 //remove encoded part |
|
584 ptr.Set( ptr.Mid( index + 1)); |
|
585 } |
|
586 else |
|
587 { |
|
588 ptr.Set( KNullDesC8); |
|
589 } |
|
590 |
|
591 |
|
592 //create command add it to CNode |
|
593 if ( err == KErrNone) |
|
594 { |
|
595 CCommand * command = CCommand::NewL( server, aclCommand); |
|
596 CleanupStack::PushL( command); |
|
597 node->iCommands.AppendL( command); |
|
598 CleanupStack::Pop( command); |
|
599 } |
|
600 } |
|
601 |
|
602 RDEBUG("DMUtilServer: CACLNode::CreateACLL - End"); |
|
603 return node; |
|
604 } |
|
605 |
|
606 |
|
607 |
|
608 // ---------------------------------------------------------------------------------------- |
|
609 // CACLStorage::CACLStorage() |
|
610 // ---------------------------------------------------------------------------------------- |
|
611 |
|
612 CACLStorage::CACLStorage() |
|
613 { |
|
614 } |
|
615 |
|
616 // ---------------------------------------------------------------------------------------- |
|
617 // CACLStorage::~CACLStorage() |
|
618 // ---------------------------------------------------------------------------------------- |
|
619 |
|
620 CACLStorage::~CACLStorage() |
|
621 { |
|
622 delete iCurrentServerId; |
|
623 iNodes.ResetAndDestroy(); |
|
624 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
625 // nothing |
|
626 #else |
|
627 //iDbSession.Close(); |
|
628 #endif |
|
629 } |
|
630 |
|
631 // ---------------------------------------------------------------------------------------- |
|
632 // CACLStorage::NewL()() |
|
633 // ---------------------------------------------------------------------------------------- |
|
634 |
|
635 CACLStorage* CACLStorage::NewL() |
|
636 { |
|
637 CACLStorage * self = new (ELeave) CACLStorage(); |
|
638 |
|
639 CleanupStack::PushL( self); |
|
640 self->ConstructL(); |
|
641 CleanupStack::Pop( self); |
|
642 |
|
643 return self; |
|
644 } |
|
645 |
|
646 |
|
647 // ---------------------------------------------------------------------------------------- |
|
648 // CACLStorage::ConstructL()() |
|
649 // ---------------------------------------------------------------------------------------- |
|
650 |
|
651 void CACLStorage::ConstructL() |
|
652 { |
|
653 RDEBUG("CACLStorage::ConstructL()"); |
|
654 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
655 // nothing |
|
656 #else |
|
657 |
|
658 // User::LeaveIfError( iDbSession.Connect() ); |
|
659 #endif |
|
660 iCertificateReceived = EFalse; |
|
661 LoadACLL(); |
|
662 } |
|
663 |
|
664 |
|
665 // ---------------------------------------------------------------------------------------- |
|
666 // CACLStorage::NewSession() |
|
667 // ---------------------------------------------------------------------------------------- |
|
668 void CACLStorage::NewSessionL( const TCertInfo& aCertInfo, const TDesC8& aServerID) |
|
669 { |
|
670 RDEBUG("=== CACLStorage::NewSessionL() ==="); |
|
671 delete iCurrentServerId; |
|
672 iCurrentServerId = 0; |
|
673 iCurrentServerId = aServerID.AllocL(); |
|
674 |
|
675 //set current session values |
|
676 SetCertInfo( aCertInfo ); |
|
677 |
|
678 //update ACLs |
|
679 RDEBUG("==== Starting to update ACLs ==== "); |
|
680 UpdateACLsL(); |
|
681 RDEBUG("==== Starting to update ACLs DONE ! ==== "); |
|
682 } |
|
683 |
|
684 // ---------------------------------------------------------------------------------------- |
|
685 // CACLStorage::CloseSession() |
|
686 // ---------------------------------------------------------------------------------------- |
|
687 void CACLStorage::CloseSession( ) |
|
688 { |
|
689 delete iCurrentServerId; |
|
690 iCurrentServerId = 0; |
|
691 iCertificateReceived = EFalse; |
|
692 } |
|
693 |
|
694 // ---------------------------------------------------------------------------------------- |
|
695 // CACLStorage::CertInfo() |
|
696 // ---------------------------------------------------------------------------------------- |
|
697 TInt CACLStorage::CertInfo( TCertInfo &aCertInfo ) |
|
698 { |
|
699 if( ! iCertificateReceived ) |
|
700 { |
|
701 return KErrNotFound; |
|
702 } |
|
703 |
|
704 aCertInfo = iCurrentCertificate; |
|
705 return KErrNone; |
|
706 } |
|
707 |
|
708 // ---------------------------------------------------------------------------------------- |
|
709 // CACLStorage::SetCertInfo() |
|
710 // ---------------------------------------------------------------------------------------- |
|
711 void CACLStorage::SetCertInfo( const TCertInfo &aCertInfo ) |
|
712 { |
|
713 TPckg<TCertInfo> certa( aCertInfo ); |
|
714 TPckg<TCertInfo> certb( iCurrentCertificate ); |
|
715 certb.Copy( certa ); |
|
716 |
|
717 iCertificateReceived = ETrue; |
|
718 } |
|
719 |
|
720 // ---------------------------------------------------------------------------------------- |
|
721 // CACLStorage::ServerIDL() |
|
722 // ---------------------------------------------------------------------------------------- |
|
723 HBufC8* CACLStorage::ServerIDL() |
|
724 { |
|
725 if( iCurrentServerId != 0) |
|
726 { |
|
727 return iCurrentServerId->AllocL(); |
|
728 } |
|
729 return 0; |
|
730 } |
|
731 |
|
732 // ---------------------------------------------------------------------------------------- |
|
733 // CACLStorage::NewSession() |
|
734 // ---------------------------------------------------------------------------------------- |
|
735 |
|
736 CACLNode * CACLStorage::FindNodeL( const TDesC8& aURI, TBool aCreateNewIfDoesntExist) |
|
737 { |
|
738 RDEBUG8_2("CACLStorage::FindNodeL() (%S)", &aURI); |
|
739 //Create reference element with URI |
|
740 TLinearOrder<CACLNode> linearOrder( &CACLNode::CompareElements); |
|
741 CACLNode referenceNode; |
|
742 referenceNode.iURIPtr.Set( aURI); |
|
743 |
|
744 //find element index |
|
745 TInt index = iNodes.FindInOrder( &referenceNode, linearOrder); |
|
746 |
|
747 if ( index != KErrNotFound ) |
|
748 { |
|
749 return iNodes[ index]; |
|
750 } |
|
751 |
|
752 if ( aCreateNewIfDoesntExist ) |
|
753 { |
|
754 CACLNode * newNode = new (ELeave) CACLNode(); |
|
755 CleanupStack::PushL( newNode); |
|
756 newNode->SetURIL( aURI); |
|
757 iNodes.InsertInOrderL( newNode, linearOrder); |
|
758 CleanupStack::Pop( newNode); |
|
759 |
|
760 RDEBUG8_2("CACLStorage::FindNodeL() Node not found, created (%S)", &aURI); |
|
761 |
|
762 return newNode; |
|
763 } |
|
764 |
|
765 return 0; |
|
766 } |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 |
|
772 // ---------------------------------------------------------------------------------------- |
|
773 // CACLStorage::NewSession() |
|
774 // ---------------------------------------------------------------------------------------- |
|
775 |
|
776 TInt CACLStorage::RemoveNode( const TDesC8& aURI) |
|
777 { |
|
778 RDEBUG8_2("CACLStorage::RemoveNode() (%S)", &aURI); |
|
779 //Create reference element with URI |
|
780 TLinearOrder<CACLNode> linearOrder( &CACLNode::CompareElements); |
|
781 CACLNode referenceNode; |
|
782 referenceNode.iURIPtr.Set( aURI); |
|
783 |
|
784 //find element index |
|
785 TInt index = iNodes.FindInOrder( &referenceNode, linearOrder); |
|
786 |
|
787 if ( index != KErrNotFound) |
|
788 { |
|
789 RDEBUG8_2("CACLStorage::Removed (%S)", &aURI); |
|
790 delete iNodes[ index]; |
|
791 iNodes.Remove( index); |
|
792 |
|
793 index = KErrNone; |
|
794 } |
|
795 |
|
796 return index; |
|
797 } |
|
798 |
|
799 // ---------------------------------------------------------------------------------------- |
|
800 // CACLStorage::MngSessionCertificate() |
|
801 // ---------------------------------------------------------------------------------------- |
|
802 |
|
803 TCertInfo& CACLStorage::MngSessionCertificate() |
|
804 { |
|
805 return iMngSessionCertificate; |
|
806 } |
|
807 |
|
808 // ---------------------------------------------------------------------------------------- |
|
809 // CACLStorage::RemoveACL() |
|
810 // ---------------------------------------------------------------------------------------- |
|
811 TInt CACLStorage::RemoveACL( const TDesC8& aURI, TBool aRestoreDefaults) |
|
812 { |
|
813 RDEBUG8_3("CACLStorage::RemoveACL() (%S)->(%d)", &aURI, aRestoreDefaults); |
|
814 TInt err = KErrNone; |
|
815 |
|
816 if( aRestoreDefaults ) |
|
817 { |
|
818 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
819 TRAPD( trapErr, { |
|
820 // Symbian framework used |
|
821 RDmTree dmTreeSession; |
|
822 dmTreeSession.ConnectL(); |
|
823 CleanupClosePushL( dmTreeSession ); |
|
824 |
|
825 RDmTreeNode node; |
|
826 User::LeaveIfError( dmTreeSession.OpenNodeL( aURI, node, RDmTree::EReadWrite ) ); |
|
827 CleanupClosePushL( node ); |
|
828 |
|
829 // remove the node |
|
830 node.RemoveDmPropertyL( DevMan::EACL ); |
|
831 node.Close(); |
|
832 dmTreeSession.CommitL(); |
|
833 |
|
834 CleanupStack::PopAndDestroy( &node ); |
|
835 CleanupStack::PopAndDestroy( &dmTreeSession ); |
|
836 } ); |
|
837 err = trapErr; |
|
838 |
|
839 #else |
|
840 User::LeaveIfError( iDbSession.Connect() ); |
|
841 iDbSession.UpdateAclL( aURI, KNullDesC8 ); |
|
842 iDbSession.Close(); |
|
843 #endif |
|
844 |
|
845 |
|
846 } |
|
847 |
|
848 |
|
849 if( err == KErrNone ) |
|
850 { |
|
851 RemoveNode( aURI ); |
|
852 } |
|
853 |
|
854 return err; |
|
855 } |
|
856 |
|
857 // ---------------------------------------------------------------------------------------- |
|
858 // CACLStorage::AddACLForNode() |
|
859 // ---------------------------------------------------------------------------------------- |
|
860 void CACLStorage::AddACLForNodeL( const TDesC8& aURI, const TACLDestination& aDestination, const TAclCommands& aCommandType) |
|
861 { |
|
862 //find node from storage |
|
863 CACLNode * node = FindNodeL( aURI, ETrue); |
|
864 |
|
865 CleanupStack::PushL( node); |
|
866 node->SetCertificateToACLL( aDestination, aCommandType, iMngSessionCertificate); |
|
867 CleanupStack::Pop( node); |
|
868 |
|
869 //incremental operation |
|
870 node->iClearFlag = EFalse; |
|
871 } |
|
872 |
|
873 // ---------------------------------------------------------------------------------------- |
|
874 // CACLStorage::SetACLForNode() |
|
875 // ---------------------------------------------------------------------------------------- |
|
876 void CACLStorage::SetACLForNodeL( const TDesC8& aURI, const TACLDestination& aDestination, const TAclCommands& aCommandType) |
|
877 { |
|
878 |
|
879 //find node from storage |
|
880 CACLNode * node = FindNodeL( aURI, ETrue); |
|
881 |
|
882 CleanupStack::PushL( node); |
|
883 node->SetCertificateToACLL( aDestination, aCommandType, iMngSessionCertificate); |
|
884 CleanupStack::Pop( node); |
|
885 |
|
886 //non-incremental operation |
|
887 node->iClearFlag = ETrue; |
|
888 } |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 // ---------------------------------------------------------------------------------------- |
|
894 // CACLStorage::UpdateACLs() |
|
895 // ---------------------------------------------------------------------------------------- |
|
896 |
|
897 void CACLStorage::UpdateACLsL() |
|
898 { |
|
899 RDEBUG_2(" ... starting to update ACL nodes, count: %d", iNodes.Count() ); |
|
900 for ( TInt i(0); i < iNodes.Count(); i++) |
|
901 { |
|
902 UpdateACLL( iNodes[i]); |
|
903 } |
|
904 } |
|
905 |
|
906 // ---------------------------------------------------------------------------------------- |
|
907 // CACLStorage::UpdateACLs() |
|
908 // ---------------------------------------------------------------------------------------- |
|
909 |
|
910 void CACLStorage::UpdateACLL( const CACLNode *aACLNode) |
|
911 { |
|
912 RDEBUG_2("DMUtilServer: CACLStorage::UpdateACLL - Start (%d)", aACLNode->iDestination); |
|
913 |
|
914 if ( aACLNode->iDestination == EForNode ) |
|
915 { |
|
916 UpdateACLL( aACLNode, aACLNode->iURIPtr); |
|
917 } |
|
918 else |
|
919 { |
|
920 //Create child info object |
|
921 CChildInfo::RChildNodes childs; |
|
922 |
|
923 //childinfo owns "CChildInfo::RChildNodes childs" |
|
924 CChildInfo * childinfo = new (ELeave) CChildInfo( childs); |
|
925 CleanupStack::PushL( childinfo); |
|
926 |
|
927 //get childs |
|
928 childinfo->GetChildsL( aACLNode->iURIPtr); |
|
929 |
|
930 //update all childs nodes |
|
931 for ( TInt i(0); i < childs.Count(); i++) |
|
932 { |
|
933 UpdateACLL( aACLNode, childs[i]); |
|
934 } |
|
935 |
|
936 |
|
937 //update parent also if iDestination is EForBoth |
|
938 if ( aACLNode->iDestination == EForBoth) |
|
939 { |
|
940 UpdateACLL( aACLNode, aACLNode->iURIPtr); |
|
941 } |
|
942 |
|
943 //destroy child info |
|
944 CleanupStack::PopAndDestroy( childinfo); |
|
945 } |
|
946 |
|
947 RDEBUG("DMUtilServer: CACLStorage::UpdateACL - End"); |
|
948 } |
|
949 |
|
950 // ---------------------------------------------------------------------------------------- |
|
951 // CACLStorage::UpdateACL() |
|
952 // ---------------------------------------------------------------------------------------- |
|
953 void CACLStorage::UpdateACLL( const CACLNode *aACLNode, const TDesC8& aURI) |
|
954 { |
|
955 RDEBUG8_2("DMUtilServer: CACLStorage::UpdateACL - Start: %S", &aURI ); |
|
956 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
957 RDmTree dmTreeSession; |
|
958 dmTreeSession.ConnectL(); |
|
959 CleanupClosePushL( dmTreeSession ); |
|
960 |
|
961 RDmTreeNode node; |
|
962 User::LeaveIfError( dmTreeSession.OpenNodeL( aURI, node, RDmTree::EReadWrite ) ); |
|
963 CleanupClosePushL( node ); |
|
964 |
|
965 RBuf8 buf; |
|
966 //get old ACL values from dmdbtree |
|
967 node.DmPropertyL( DevMan::EACL, buf ); |
|
968 |
|
969 RDEBUG8_3("DMUtilServer: Original ACL from DM tree node %S: %S", &aURI, &buf); |
|
970 #else |
|
971 //get old ACL values from dmdbhandler |
|
972 CBufFlat* bufBase = CBufFlat::NewL( 1); |
|
973 User::LeaveIfError( iDbSession.Connect() ); |
|
974 iDbSession.GetAclL( aURI, *bufBase, EFalse); |
|
975 iDbSession.Close(); |
|
976 |
|
977 TPtrC8 aclPtr = bufBase->Ptr( 0 ); |
|
978 |
|
979 RDEBUG8_3("DMUtilServer: Original ACL from DM tree node %S: %S", &aURI, &aclPtr); |
|
980 #endif |
|
981 |
|
982 |
|
983 |
|
984 //Create CACLNode from acl string |
|
985 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
986 CACLNode * acl = CACLNode::CreateACLL( buf ); |
|
987 #else |
|
988 CACLNode * acl = CACLNode::CreateACLL( aclPtr ); |
|
989 #endif |
|
990 CleanupStack::PushL( acl); |
|
991 |
|
992 //clear original nodes |
|
993 if ( aACLNode->iClearFlag ) |
|
994 { |
|
995 RDEBUG("DMUtilServer: Remove original ACL items"); |
|
996 acl->ClearACL(); |
|
997 } |
|
998 |
|
999 //copy commands to original ACL |
|
1000 for ( TInt i(0); i < aACLNode->iCommands.Count(); i++) |
|
1001 { |
|
1002 CCommand * command = aACLNode->iCommands[i]; |
|
1003 |
|
1004 CleanupStack::PushL( command); |
|
1005 delete command->iServerId; |
|
1006 command->iServerId = 0; |
|
1007 command->iServerId = iCurrentServerId->AllocL(); |
|
1008 CleanupStack::Pop( command); |
|
1009 |
|
1010 //find corresponding command from original acl string |
|
1011 CCommand * origCommand = acl->FindCorrespondingCommand( command); |
|
1012 |
|
1013 //if no correspondinding command exist and current session certificate is same |
|
1014 //as in command, add command to node |
|
1015 if ( !origCommand ) |
|
1016 { |
|
1017 if ( CompareCertInfos( iCurrentCertificate, command->iCertInfo)) |
|
1018 { |
|
1019 RDEBUG("DMUtilServer: Add new ACL item"); |
|
1020 acl->SetServerIdToACLL( command->iCommand, *iCurrentServerId); |
|
1021 } |
|
1022 } |
|
1023 else |
|
1024 { |
|
1025 //remove all commands which have same server id than new session (except origCommand) |
|
1026 for ( TInt i(0); i < acl->iCommands.Count(); i++) |
|
1027 { |
|
1028 if ( *iCurrentServerId == *acl->iCommands[i]->iServerId && acl->iCommands[i] != origCommand) |
|
1029 { |
|
1030 acl->iCommands.Remove(i--); |
|
1031 } |
|
1032 } |
|
1033 } |
|
1034 } |
|
1035 |
|
1036 //update ACL to CM tree |
|
1037 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
1038 HBufC8* aclStr = acl->GetNodeACLStringL(); |
|
1039 RDEBUG_2("DMUtilServer: New ACL string for node: %S", aclStr); |
|
1040 CleanupStack::PushL( aclStr ); |
|
1041 |
|
1042 node.SetDmPropertyL( DevMan::EACL, *aclStr ); |
|
1043 |
|
1044 node.Close(); |
|
1045 dmTreeSession.CommitL(); |
|
1046 |
|
1047 CleanupStack::PopAndDestroy( aclStr); |
|
1048 CleanupStack::PopAndDestroy( acl); |
|
1049 |
|
1050 CleanupStack::PopAndDestroy( &node ); |
|
1051 CleanupStack::PopAndDestroy( &dmTreeSession ); |
|
1052 #else |
|
1053 HBufC8 * aclStr = acl->GetNodeACLStringL(); |
|
1054 CleanupStack::PushL( aclStr); |
|
1055 RDEBUG8_2("DMUtilServer: New ACL string for node: %S", aclStr); |
|
1056 User::LeaveIfError( iDbSession.Connect() ); |
|
1057 iDbSession.UpdateAclL( aURI, *aclStr); |
|
1058 iDbSession.Close(); |
|
1059 CleanupStack::PopAndDestroy( aclStr); |
|
1060 |
|
1061 CleanupStack::PopAndDestroy( acl); |
|
1062 #endif |
|
1063 RDEBUG("DMUtilServer: CACLStorage::UpdateACL - End"); |
|
1064 } |
|
1065 |
|
1066 |
|
1067 // ---------------------------------------------------------------------------------------- |
|
1068 // CACLStorage::SaveACLL() |
|
1069 // ---------------------------------------------------------------------------------------- |
|
1070 |
|
1071 void CACLStorage::SaveACLL() |
|
1072 { |
|
1073 RDEBUG("DMUtilServer: Save ACL configuration!"); |
|
1074 |
|
1075 //Open rfs |
|
1076 RFs rfs; |
|
1077 CleanupClosePushL( rfs); |
|
1078 User::LeaveIfError( rfs.Connect()); |
|
1079 |
|
1080 //Open rfile |
|
1081 RFile file; |
|
1082 CleanupClosePushL( file); |
|
1083 |
|
1084 TInt err = file.Open( rfs, KStorageTempFile, EFileWrite); |
|
1085 |
|
1086 if ( err != KErrNone) |
|
1087 { |
|
1088 if ( err == KErrPathNotFound) |
|
1089 { |
|
1090 rfs.CreatePrivatePath( EDriveC); |
|
1091 } |
|
1092 |
|
1093 err = file.Create( rfs, KStorageTempFile, EFileWrite); |
|
1094 } |
|
1095 |
|
1096 User::LeaveIfError( err); |
|
1097 |
|
1098 TInt size = 0; |
|
1099 |
|
1100 //write all nodes |
|
1101 for ( TInt i(0); i < iNodes.Count(); i++) |
|
1102 { |
|
1103 RDEBUG_2(" -> node %d", i ); |
|
1104 //write node length to file |
|
1105 TInt nodeLength( iNodes[i]->Length()); |
|
1106 TPckgC<TInt> pck( nodeLength); |
|
1107 User::LeaveIfError( file.Write( pck)); |
|
1108 size += pck.Length(); |
|
1109 size += nodeLength; |
|
1110 |
|
1111 HBufC8 * saveString = iNodes[i]->SaveStringL(); |
|
1112 CleanupStack::PushL( saveString); |
|
1113 User::LeaveIfError( file.Write( *saveString)); |
|
1114 CleanupStack::PopAndDestroy( saveString); |
|
1115 } |
|
1116 |
|
1117 //Set file size |
|
1118 file.SetSize( size); |
|
1119 |
|
1120 CleanupStack::PopAndDestroy( &file); |
|
1121 |
|
1122 //Create storage file |
|
1123 CFileMan * fileMan = CFileMan::NewL( rfs); |
|
1124 CleanupStack::PushL( fileMan); |
|
1125 |
|
1126 err = file.Open( rfs, KStorageFile, EFileRead ); |
|
1127 |
|
1128 if ( err == KErrNone ) |
|
1129 { |
|
1130 file.Close(); |
|
1131 User::LeaveIfError( fileMan->Rename( KStorageFile, KStorageBackupFile, CFileMan::EOverWrite)); |
|
1132 } |
|
1133 |
|
1134 User::LeaveIfError( fileMan->Rename( KStorageTempFile, KStorageFile, CFileMan::EOverWrite)); |
|
1135 |
|
1136 if ( err == KErrNone ) |
|
1137 { |
|
1138 User::LeaveIfError( fileMan->Delete( KStorageBackupFile)); |
|
1139 } |
|
1140 |
|
1141 |
|
1142 CleanupStack::PopAndDestroy( fileMan); |
|
1143 CleanupStack::PopAndDestroy( &rfs); |
|
1144 } |
|
1145 |
|
1146 // ---------------------------------------------------------------------------------------- |
|
1147 // CACLStorage::LoadACLL() |
|
1148 // ---------------------------------------------------------------------------------------- |
|
1149 |
|
1150 void CACLStorage::LoadACLL() |
|
1151 { |
|
1152 RDEBUG("DMUtilServer: Load ACL configuration!"); |
|
1153 |
|
1154 //Open rfs |
|
1155 RFs rfs; |
|
1156 User::LeaveIfError( rfs.Connect()); |
|
1157 CleanupClosePushL( rfs); |
|
1158 |
|
1159 //Open rfile |
|
1160 RFile file; |
|
1161 CleanupClosePushL( file); |
|
1162 |
|
1163 TInt err = file.Open( rfs, KStorageBackupFile, EFileRead); |
|
1164 file.Close(); |
|
1165 |
|
1166 //backup file exist, error in previois save operation, restore backup |
|
1167 if ( err == KErrNone) |
|
1168 { |
|
1169 CFileMan * fileMan = CFileMan::NewL( rfs); |
|
1170 CleanupStack::PushL( fileMan); |
|
1171 |
|
1172 User::LeaveIfError( fileMan->Rename( KStorageBackupFile, KStorageFile, CFileMan::EOverWrite)); |
|
1173 |
|
1174 CleanupStack::PopAndDestroy( fileMan); |
|
1175 } |
|
1176 |
|
1177 //open proper storage file |
|
1178 err = file.Open( rfs, KStorageFile, EFileRead); |
|
1179 |
|
1180 if ( err == KErrNone) |
|
1181 { |
|
1182 TInt size(0); |
|
1183 User::LeaveIfError( file.Size( size)); |
|
1184 |
|
1185 while ( size > 0) |
|
1186 { |
|
1187 //read next node size |
|
1188 TInt nodeSize(0); |
|
1189 TPckg<TInt> pckg(nodeSize); |
|
1190 User::LeaveIfError( file.Read( pckg)); |
|
1191 |
|
1192 //decrase file remaining index |
|
1193 size -= nodeSize; |
|
1194 size -= pckg.Length(); |
|
1195 |
|
1196 //create buffer for next node string and read string |
|
1197 HBufC8 * nodeStr = HBufC8::NewLC( nodeSize); |
|
1198 TPtr8 ptr = nodeStr->Des(); |
|
1199 User::LeaveIfError( file.Read( ptr, nodeSize)); |
|
1200 |
|
1201 //create node from string and append it string list |
|
1202 CACLNode * node = CACLNode::LoadFromStringL( ptr); |
|
1203 CleanupStack::PushL( node); |
|
1204 iNodes.AppendL( node); |
|
1205 |
|
1206 CleanupStack::Pop( node); |
|
1207 CleanupStack::PopAndDestroy( nodeStr); |
|
1208 } |
|
1209 } |
|
1210 |
|
1211 CleanupStack::PopAndDestroy( 2, &rfs); |
|
1212 } |
|
1213 |
|
1214 |
|
1215 |
|
1216 |
|
1217 // ---------------------------------------------------------------------------------------- |
|
1218 // CChildInfo::CChildInfo() |
|
1219 // ---------------------------------------------------------------------------------------- |
|
1220 |
|
1221 CChildInfo::CChildInfo( RChildNodes& aNodes) |
|
1222 : iChilds( aNodes) |
|
1223 { |
|
1224 |
|
1225 } |
|
1226 |
|
1227 // ---------------------------------------------------------------------------------------- |
|
1228 // CChildInfo::~CChildInfo() |
|
1229 // ---------------------------------------------------------------------------------------- |
|
1230 |
|
1231 CChildInfo::~CChildInfo() |
|
1232 { |
|
1233 iChilds.Close(); |
|
1234 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
1235 // nothing |
|
1236 #else |
|
1237 delete iBuffer; |
|
1238 #endif |
|
1239 } |
|
1240 |
|
1241 // ---------------------------------------------------------------------------------------- |
|
1242 // CChildInfo::GetChildsL() |
|
1243 // ---------------------------------------------------------------------------------------- |
|
1244 |
|
1245 |
|
1246 TInt CChildInfo::GetChildsL( const TDesC8& aURI ) |
|
1247 { |
|
1248 RDEBUG8_2("DMUtilServer: CChildInfo::GetChildsL - Start (%S)", &aURI); |
|
1249 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
1250 RDmTree dmTreeSession; |
|
1251 dmTreeSession.ConnectL(); |
|
1252 CleanupClosePushL( dmTreeSession ); |
|
1253 |
|
1254 CDesC8ArrayFlat* buf = new( ELeave ) CDesC8ArrayFlat( 4 ); |
|
1255 CleanupStack::PushL( buf ); |
|
1256 |
|
1257 dmTreeSession.ChildrenL( aURI, *buf ); |
|
1258 |
|
1259 // copy, should be fixed so that this step is not needed |
|
1260 for( TInt i = 0; i < buf->Count(); i++ ) |
|
1261 { |
|
1262 iChilds.AppendL( ( *buf)[ i ] ); |
|
1263 } |
|
1264 |
|
1265 CleanupStack::PopAndDestroy( buf ); |
|
1266 CleanupStack::PopAndDestroy( &dmTreeSession ); |
|
1267 |
|
1268 |
|
1269 RDEBUG("DMUtilServer: CChildInfo::GetChildsL - End"); |
|
1270 return KErrNone; |
|
1271 #else |
|
1272 //create dmmodule |
|
1273 CNSmlDmModule* dmmodule = CNSmlDmModule::NewL( this); |
|
1274 CleanupStack::PushL( dmmodule); |
|
1275 |
|
1276 //fetch objects... |
|
1277 dmmodule->FetchObjectL( aURI, KNullDesC8, KResultRef, KStatusRef, ETrue); |
|
1278 |
|
1279 CleanupStack::PopAndDestroy( dmmodule); |
|
1280 |
|
1281 //Check errors |
|
1282 TInt error( KErrNone); |
|
1283 if ( iErr ) |
|
1284 { |
|
1285 error = KErrGeneral; |
|
1286 } |
|
1287 |
|
1288 |
|
1289 RDEBUG("DMUtilServer: CChildInfo::GetChildsL - End"); |
|
1290 return error; |
|
1291 #endif |
|
1292 } |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
1300 // nothing |
|
1301 #else |
|
1302 |
|
1303 |
|
1304 |
|
1305 // ---------------------------------------------------------------------------------------- |
|
1306 // CChildInfo::SetResultsL() |
|
1307 // ---------------------------------------------------------------------------------------- |
|
1308 |
|
1309 void CChildInfo::SetResultsL( TInt aResultsRef, |
|
1310 const CBufBase& aObject, |
|
1311 const TDesC8& /*aType*/, |
|
1312 const TDesC8& /*aFormat*/, |
|
1313 TInt /*aTotalSize*/ ) |
|
1314 { |
|
1315 RDEBUG("DMUtilServer: CChildInfo::SetResultsL - Start"); |
|
1316 |
|
1317 if ( !aObject.Size()) |
|
1318 { |
|
1319 //no child nodes |
|
1320 return; |
|
1321 } |
|
1322 |
|
1323 if ( aResultsRef != KResultRef || iErr) |
|
1324 { |
|
1325 iErr = ETrue; |
|
1326 return; |
|
1327 } |
|
1328 |
|
1329 |
|
1330 //create pointer for childlist and read it from package buffer |
|
1331 delete iBuffer; |
|
1332 iBuffer = 0; |
|
1333 |
|
1334 iBuffer = HBufC8::NewL( aObject.Size()); |
|
1335 |
|
1336 TPtr8 bufptr = iBuffer->Des(); |
|
1337 aObject.Read( 0, bufptr, aObject.Size()); |
|
1338 TPtrC8 ptr = *iBuffer; |
|
1339 |
|
1340 //separate childrens |
|
1341 while ( ptr.Length()) |
|
1342 { |
|
1343 //find separator |
|
1344 TInt index = ptr.Locate('/'); |
|
1345 |
|
1346 if ( index == KErrNotFound) |
|
1347 { |
|
1348 iChilds.AppendL( ptr); |
|
1349 } |
|
1350 else |
|
1351 { |
|
1352 ptr.Mid( index + 1); |
|
1353 iChilds.AppendL( ptr.Right( index)); |
|
1354 } |
|
1355 } |
|
1356 |
|
1357 RDEBUG("DMUtilServer: CChildInfo::SetResultsL - End"); |
|
1358 } |
|
1359 |
|
1360 // ---------------------------------------------------------------------------------------- |
|
1361 // CChildInfo::SetStatusL() |
|
1362 // ---------------------------------------------------------------------------------------- |
|
1363 |
|
1364 void CChildInfo::SetStatusL( TInt aStatusRef, TInt aStatusCode ) |
|
1365 { |
|
1366 iErr = !( aStatusRef == KStatusRef && aStatusCode == 200/*KNSmlDmStatusOK*/); |
|
1367 } |
|
1368 |
|
1369 |
|
1370 |
|
1371 #endif |
|
1372 |
|
1373 |